Snap for 4696032 from a62df616f9
to pi-release
Change-Id: Ieecef95e84d12234f67b1a8496a5cf905f26d02a
This commit is contained in:
@@ -525,7 +525,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="64"
|
||||
line="62"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -541,7 +541,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="65"
|
||||
line="63"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -557,7 +557,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="66"
|
||||
line="64"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -573,7 +573,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="67"
|
||||
line="65"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -589,7 +589,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="69"
|
||||
line="67"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -605,7 +605,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="72"
|
||||
line="70"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -621,7 +621,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="74"
|
||||
line="72"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -637,7 +637,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="75"
|
||||
line="73"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -653,7 +653,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="78"
|
||||
line="76"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -669,7 +669,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="79"
|
||||
line="77"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -685,7 +685,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="80"
|
||||
line="78"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -701,7 +701,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="81"
|
||||
line="79"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -717,7 +717,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="82"
|
||||
line="80"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -733,7 +733,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="85"
|
||||
line="83"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -749,7 +749,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="86"
|
||||
line="84"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -765,7 +765,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="87"
|
||||
line="85"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -781,7 +781,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="88"
|
||||
line="86"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -797,7 +797,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="89"
|
||||
line="87"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -813,7 +813,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="90"
|
||||
line="88"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -829,7 +829,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="91"
|
||||
line="89"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -845,7 +845,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="92"
|
||||
line="90"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -861,7 +861,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="93"
|
||||
line="91"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -877,7 +877,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="94"
|
||||
line="92"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -893,23 +893,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="95"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
message="Avoid using hardcoded color"
|
||||
category="Correctness"
|
||||
priority="4"
|
||||
summary="Using hardcoded color"
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" <color name="importance_secondary_slider_color">#858383</color>"
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="98"
|
||||
line="93"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -925,7 +909,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="100"
|
||||
line="95"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -941,7 +925,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="103"
|
||||
line="98"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -957,7 +941,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="105"
|
||||
line="100"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -973,7 +957,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="108"
|
||||
line="103"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -989,7 +973,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="111"
|
||||
line="106"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -1005,7 +989,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="114"
|
||||
line="109"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -1021,7 +1005,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="117"
|
||||
line="112"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -1037,7 +1021,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="118"
|
||||
line="113"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -1053,7 +1037,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="121"
|
||||
line="116"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -1069,7 +1053,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="122"
|
||||
line="117"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -1085,7 +1069,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="123"
|
||||
line="118"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -1101,7 +1085,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="124"
|
||||
line="119"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -1117,7 +1101,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="125"
|
||||
line="120"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -1133,7 +1117,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="126"
|
||||
line="121"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -1149,7 +1133,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="127"
|
||||
line="122"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -1165,7 +1149,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="128"
|
||||
line="123"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -1181,7 +1165,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="129"
|
||||
line="124"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -1197,7 +1181,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="130"
|
||||
line="125"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -1213,7 +1197,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="131"
|
||||
line="126"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -1229,7 +1213,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="132"
|
||||
line="127"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -1243,6 +1227,22 @@
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" <color name="homepage_generic_icon_background">#1A73E8</color>"
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="128"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
message="Avoid using hardcoded color"
|
||||
category="Correctness"
|
||||
priority="4"
|
||||
summary="Using hardcoded color"
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" <color name="battery_good_color_light">#43a047</color> <!-- Material Green 600 -->"
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="133"
|
||||
@@ -1257,11 +1257,75 @@
|
||||
priority="4"
|
||||
summary="Using hardcoded color"
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" android:background="@color/condition_card_background""
|
||||
errorLine1=" <color name="battery_maybe_color_light">#ef6c00</color> <!-- Material Orange 800 -->"
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="134"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
message="Avoid using hardcoded color"
|
||||
category="Correctness"
|
||||
priority="4"
|
||||
summary="Using hardcoded color"
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" <color name="battery_bad_color_light">#f44336</color> <!-- Material Red 500 -->"
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/layout/condition_tile.xml"
|
||||
line="22"
|
||||
file="res/values/colors.xml"
|
||||
line="135"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
message="Avoid using hardcoded color"
|
||||
category="Correctness"
|
||||
priority="4"
|
||||
summary="Using hardcoded color"
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" <color name="battery_good_color_dark">#4caf50</color> <!-- Material Green 500 -->"
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="136"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
message="Avoid using hardcoded color"
|
||||
category="Correctness"
|
||||
priority="4"
|
||||
summary="Using hardcoded color"
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" <color name="battery_maybe_color_dark">#fdd835</color> <!-- Material Yellow 600 -->"
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="137"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
message="Avoid using hardcoded color"
|
||||
category="Correctness"
|
||||
priority="4"
|
||||
summary="Using hardcoded color"
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" <color name="battery_bad_color_dark">#f44336</color> <!-- Material Red 500 -->"
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="138"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
@@ -2173,7 +2237,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/layout/running_processes_header.xml"
|
||||
line="55"
|
||||
line="56"
|
||||
column="13"/>
|
||||
</issue>
|
||||
|
||||
@@ -2189,7 +2253,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/layout/running_processes_header.xml"
|
||||
line="145"
|
||||
line="146"
|
||||
column="13"/>
|
||||
</issue>
|
||||
|
||||
@@ -2337,22 +2401,6 @@
|
||||
column="17"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
message="Avoid using hardcoded color"
|
||||
category="Correctness"
|
||||
priority="4"
|
||||
summary="Using hardcoded color"
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" android:background="@color/suggestion_condition_background">"
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/layout/search_panel.xml"
|
||||
line="28"
|
||||
column="9"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
@@ -2417,6 +2465,22 @@
|
||||
column="9"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
message="Avoid using hardcoded color"
|
||||
category="Correctness"
|
||||
priority="4"
|
||||
summary="Using hardcoded color"
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" <string name="sync_plug" msgid="3905078969081888738">""<font fgcolor="#ffffffff">"Welcome to Google sync!"</font>" \nA Google approach to syncing data to allow access to your contacts, appointments, and more from wherever you are."</string>"
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values-en-rXC/strings.xml"
|
||||
line="2535"
|
||||
column="168"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
@@ -2429,7 +2493,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values-en-rAU/strings.xml"
|
||||
line="2395"
|
||||
line="2536"
|
||||
column="64"/>
|
||||
</issue>
|
||||
|
||||
@@ -2445,7 +2509,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values-en-rCA/strings.xml"
|
||||
line="2395"
|
||||
line="2536"
|
||||
column="64"/>
|
||||
</issue>
|
||||
|
||||
@@ -2461,7 +2525,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values-en-rGB/strings.xml"
|
||||
line="2395"
|
||||
line="2536"
|
||||
column="64"/>
|
||||
</issue>
|
||||
|
||||
@@ -2477,26 +2541,10 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values-en-rIN/strings.xml"
|
||||
line="2395"
|
||||
line="2536"
|
||||
column="64"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
message="Avoid using hardcoded color"
|
||||
category="Correctness"
|
||||
priority="4"
|
||||
summary="Using hardcoded color"
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" <string name="sync_plug" msgid="3905078969081888738">""<font fgcolor="#ffffffff">"Welcome to Google sync!"</font>" \nA Google approach to syncing data to allow access to your contacts, appointments, and more from wherever you are."</string>"
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values-en-rXC/strings.xml"
|
||||
line="2396"
|
||||
column="168"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
@@ -2509,7 +2557,7 @@
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/strings.xml"
|
||||
line="5638"
|
||||
line="5899"
|
||||
column="36"/>
|
||||
</issue>
|
||||
|
||||
@@ -2541,7 +2589,7 @@
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/styles.xml"
|
||||
line="442"
|
||||
line="436"
|
||||
column="44"/>
|
||||
</issue>
|
||||
|
||||
@@ -2557,7 +2605,7 @@
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/styles.xml"
|
||||
line="448"
|
||||
line="442"
|
||||
column="44"/>
|
||||
</issue>
|
||||
|
||||
@@ -2573,7 +2621,7 @@
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/styles.xml"
|
||||
line="449"
|
||||
line="443"
|
||||
column="44"/>
|
||||
</issue>
|
||||
|
||||
@@ -2589,7 +2637,7 @@
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/styles.xml"
|
||||
line="472"
|
||||
line="461"
|
||||
column="41"/>
|
||||
</issue>
|
||||
|
||||
@@ -2605,7 +2653,7 @@
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/themes.xml"
|
||||
line="33"
|
||||
line="31"
|
||||
column="40"/>
|
||||
</issue>
|
||||
|
||||
@@ -2621,7 +2669,7 @@
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/themes.xml"
|
||||
line="52"
|
||||
line="49"
|
||||
column="40"/>
|
||||
</issue>
|
||||
|
||||
@@ -2637,7 +2685,7 @@
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/themes.xml"
|
||||
line="70"
|
||||
line="67"
|
||||
column="40"/>
|
||||
</issue>
|
||||
|
||||
@@ -2653,7 +2701,7 @@
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/themes.xml"
|
||||
line="89"
|
||||
line="85"
|
||||
column="40"/>
|
||||
</issue>
|
||||
|
||||
@@ -2669,7 +2717,7 @@
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/themes.xml"
|
||||
line="107"
|
||||
line="103"
|
||||
column="40"/>
|
||||
</issue>
|
||||
|
||||
@@ -2685,7 +2733,7 @@
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/themes.xml"
|
||||
line="126"
|
||||
line="121"
|
||||
column="40"/>
|
||||
</issue>
|
||||
|
||||
@@ -2701,7 +2749,7 @@
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/themes.xml"
|
||||
line="200"
|
||||
line="197"
|
||||
column="43"/>
|
||||
</issue>
|
||||
|
||||
@@ -2717,7 +2765,7 @@
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/themes.xml"
|
||||
line="201"
|
||||
line="198"
|
||||
column="42"/>
|
||||
</issue>
|
||||
|
||||
@@ -2733,10 +2781,58 @@
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/themes.xml"
|
||||
line="202"
|
||||
line="199"
|
||||
column="45"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
message="Avoid using hardcoded color"
|
||||
category="Correctness"
|
||||
priority="4"
|
||||
summary="Using hardcoded color"
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" <item name="batteryGoodColor">@color/battery_good_color_light</item>"
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/themes.xml"
|
||||
line="240"
|
||||
column="39"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
message="Avoid using hardcoded color"
|
||||
category="Correctness"
|
||||
priority="4"
|
||||
summary="Using hardcoded color"
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" <item name="batteryMaybeColor">@color/battery_maybe_color_light</item>"
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/themes.xml"
|
||||
line="241"
|
||||
column="40"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
message="Avoid using hardcoded color"
|
||||
category="Correctness"
|
||||
priority="4"
|
||||
summary="Using hardcoded color"
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" <item name="batteryBadColor">@color/battery_bad_color_light</item>"
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/themes.xml"
|
||||
line="242"
|
||||
column="38"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
@@ -2749,7 +2845,7 @@
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/themes.xml"
|
||||
line="279"
|
||||
line="280"
|
||||
column="47"/>
|
||||
</issue>
|
||||
|
||||
@@ -2765,7 +2861,7 @@
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/themes.xml"
|
||||
line="347"
|
||||
line="348"
|
||||
column="45"/>
|
||||
</issue>
|
||||
|
||||
@@ -2781,7 +2877,7 @@
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/themes.xml"
|
||||
line="348"
|
||||
line="349"
|
||||
column="49"/>
|
||||
</issue>
|
||||
|
||||
@@ -2797,7 +2893,7 @@
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/themes.xml"
|
||||
line="356"
|
||||
line="357"
|
||||
column="45"/>
|
||||
</issue>
|
||||
|
||||
@@ -2813,7 +2909,7 @@
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/themes.xml"
|
||||
line="357"
|
||||
line="358"
|
||||
column="49"/>
|
||||
</issue>
|
||||
|
||||
|
@@ -18,9 +18,6 @@
|
||||
-->
|
||||
<resources>
|
||||
<item type="id" name="preference_highlighted" />
|
||||
<item type="id" name="job_anomaly_clean_up" />
|
||||
<item type="id" name="job_anomaly_config_update"/>
|
||||
<item type="id" name="job_anomaly_detection" />
|
||||
|
||||
<item type="id" name="lock_none" />
|
||||
<item type="id" name="lock_pin" />
|
||||
|
22
res/values/integers.xml
Normal file
22
res/values/integers.xml
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2018 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<resources>
|
||||
<!-- Reserve all the job ids in settings -->
|
||||
<integer name="job_anomaly_clean_up">100</integer>
|
||||
<integer name="job_anomaly_config_update">101</integer>
|
||||
<integer name="job_anomaly_detection">102</integer>
|
||||
</resources>
|
@@ -5711,9 +5711,6 @@
|
||||
<string name="admin_disabled_other_options">Other options are disabled by your admin</string>
|
||||
<string name="admin_more_details">More details</string>
|
||||
|
||||
<!-- Name to assign to a Network Access Point that was saved without a name -->
|
||||
<string name="untitled_apn">Untitled</string>
|
||||
|
||||
<string name="sound_category_sound_title">General</string>
|
||||
<string name="notification_log_title">Notification log</string>
|
||||
|
||||
|
@@ -14,14 +14,17 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:key="magnification_preference_screen_title"
|
||||
android:title="@string/accessibility_screen_magnification_title">
|
||||
<Preference
|
||||
android:fragment="com.android.settings.accessibility.ToggleScreenMagnificationPreferenceFragment"
|
||||
android:key="screen_magnification_gestures_preference_screen"
|
||||
android:title="@string/accessibility_screen_magnification_gestures_title"/>
|
||||
android:title="@string/accessibility_screen_magnification_gestures_title"
|
||||
settings:controller="com.android.settings.accessibility.MagnificationGesturesPreferenceController"/>
|
||||
<Preference
|
||||
android:fragment="com.android.settings.accessibility.ToggleScreenMagnificationPreferenceFragment"
|
||||
android:key="screen_magnification_navbar_preference_screen"
|
||||
android:title="@string/accessibility_screen_magnification_navbar_title"/>
|
||||
android:title="@string/accessibility_screen_magnification_navbar_title"
|
||||
settings:controller="com.android.settings.accessibility.MagnificationNavbarPreferenceController"/>
|
||||
</PreferenceScreen>
|
||||
|
@@ -18,7 +18,8 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:key="network_and_internet_screen"
|
||||
android:title="@string/network_dashboard_title">
|
||||
android:title="@string/network_dashboard_title"
|
||||
settings:initialExpandedChildrenCount="5">
|
||||
|
||||
<com.android.settings.widget.MasterSwitchPreference
|
||||
android:fragment="com.android.settings.wifi.WifiSettings"
|
||||
@@ -58,20 +59,11 @@
|
||||
settings:userRestriction="no_config_tethering"
|
||||
settings:useAdminDisabledSummary="true" />
|
||||
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
android:fragment="com.android.settings.vpn2.VpnSettings"
|
||||
android:key="vpn_settings"
|
||||
android:title="@string/vpn_settings_title"
|
||||
android:icon="@drawable/ic_vpn_key"
|
||||
android:order="0"
|
||||
android:summary="@string/summary_placeholder"
|
||||
settings:userRestriction="no_config_vpn"
|
||||
settings:useAdminDisabledSummary="true" />
|
||||
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
android:key="manage_mobile_plan"
|
||||
android:title="@string/manage_mobile_plan_title"
|
||||
android:persistent="false"
|
||||
android:order="0"
|
||||
settings:userRestriction="no_config_mobile_networks"
|
||||
settings:useAdminDisabledSummary="true" />
|
||||
|
||||
@@ -88,4 +80,22 @@
|
||||
android:key="proxy_settings"
|
||||
android:title="@string/proxy_settings_title" />
|
||||
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
android:fragment="com.android.settings.vpn2.VpnSettings"
|
||||
android:key="vpn_settings"
|
||||
android:title="@string/vpn_settings_title"
|
||||
android:icon="@drawable/ic_vpn_key"
|
||||
android:order="10"
|
||||
android:summary="@string/summary_placeholder"
|
||||
settings:userRestriction="no_config_vpn"
|
||||
settings:useAdminDisabledSummary="true" />
|
||||
|
||||
<com.android.settings.network.PrivateDnsModeDialogPreference
|
||||
android:key="private_dns_settings"
|
||||
android:title="@string/select_private_dns_configuration_title"
|
||||
android:order="15"
|
||||
android:dialogTitle="@string/select_private_dns_configuration_dialog_title"
|
||||
android:dialogLayout="@layout/private_dns_mode_dialog"
|
||||
android:positiveButtonText="@string/save" />
|
||||
|
||||
</PreferenceScreen>
|
@@ -18,11 +18,9 @@ package com.android.settings;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
@@ -52,17 +50,17 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.internal.telephony.PhoneConstants;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static android.content.Context.TELEPHONY_SERVICE;
|
||||
|
||||
/**
|
||||
* TODO: After loading all changes, please move this to network package.
|
||||
* TODO(b/77339683): After loading all changes, please move this to network package.
|
||||
*/
|
||||
public class ApnEditor extends SettingsPreferenceFragment
|
||||
implements OnPreferenceChangeListener, OnKeyListener {
|
||||
@@ -70,7 +68,6 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
private final static String TAG = ApnEditor.class.getSimpleName();
|
||||
private final static boolean VDBG = false; // STOPSHIP if true
|
||||
|
||||
private final static String SAVED_POS = "pos";
|
||||
private final static String KEY_AUTH_TYPE = "auth_type";
|
||||
private final static String KEY_PROTOCOL = "apn_protocol";
|
||||
private final static String KEY_ROAMING_PROTOCOL = "apn_roaming_protocol";
|
||||
@@ -83,37 +80,57 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
private static final int MENU_SAVE = Menu.FIRST + 1;
|
||||
private static final int MENU_CANCEL = Menu.FIRST + 2;
|
||||
|
||||
private static String sNotSet;
|
||||
private EditTextPreference mName;
|
||||
private EditTextPreference mApn;
|
||||
private EditTextPreference mProxy;
|
||||
private EditTextPreference mPort;
|
||||
private EditTextPreference mUser;
|
||||
private EditTextPreference mServer;
|
||||
private EditTextPreference mPassword;
|
||||
private EditTextPreference mMmsc;
|
||||
private EditTextPreference mMcc;
|
||||
private EditTextPreference mMnc;
|
||||
private EditTextPreference mMmsProxy;
|
||||
private EditTextPreference mMmsPort;
|
||||
private ListPreference mAuthType;
|
||||
private EditTextPreference mApnType;
|
||||
private ListPreference mProtocol;
|
||||
private ListPreference mRoamingProtocol;
|
||||
private SwitchPreference mCarrierEnabled;
|
||||
private MultiSelectListPreference mBearerMulti;
|
||||
private ListPreference mMvnoType;
|
||||
private EditTextPreference mMvnoMatchData;
|
||||
@VisibleForTesting
|
||||
static String sNotSet;
|
||||
@VisibleForTesting
|
||||
EditTextPreference mName;
|
||||
@VisibleForTesting
|
||||
EditTextPreference mApn;
|
||||
@VisibleForTesting
|
||||
EditTextPreference mProxy;
|
||||
@VisibleForTesting
|
||||
EditTextPreference mPort;
|
||||
@VisibleForTesting
|
||||
EditTextPreference mUser;
|
||||
@VisibleForTesting
|
||||
EditTextPreference mServer;
|
||||
@VisibleForTesting
|
||||
EditTextPreference mPassword;
|
||||
@VisibleForTesting
|
||||
EditTextPreference mMmsc;
|
||||
@VisibleForTesting
|
||||
EditTextPreference mMcc;
|
||||
@VisibleForTesting
|
||||
EditTextPreference mMnc;
|
||||
@VisibleForTesting
|
||||
EditTextPreference mMmsProxy;
|
||||
@VisibleForTesting
|
||||
EditTextPreference mMmsPort;
|
||||
@VisibleForTesting
|
||||
ListPreference mAuthType;
|
||||
@VisibleForTesting
|
||||
EditTextPreference mApnType;
|
||||
@VisibleForTesting
|
||||
ListPreference mProtocol;
|
||||
@VisibleForTesting
|
||||
ListPreference mRoamingProtocol;
|
||||
@VisibleForTesting
|
||||
SwitchPreference mCarrierEnabled;
|
||||
@VisibleForTesting
|
||||
MultiSelectListPreference mBearerMulti;
|
||||
@VisibleForTesting
|
||||
ListPreference mMvnoType;
|
||||
@VisibleForTesting
|
||||
EditTextPreference mMvnoMatchData;
|
||||
|
||||
@VisibleForTesting
|
||||
ApnData mApnData;
|
||||
|
||||
private String mCurMnc;
|
||||
private String mCurMcc;
|
||||
|
||||
private Uri mUri;
|
||||
private Cursor mCursor;
|
||||
private boolean mNewApn;
|
||||
private boolean mFirstTime;
|
||||
private int mSubId;
|
||||
private Resources mRes;
|
||||
private TelephonyManager mTelephonyManager;
|
||||
private int mBearerInitialVal = 0;
|
||||
private String mMvnoTypeStr;
|
||||
@@ -121,6 +138,7 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
private String[] mReadOnlyApnTypes;
|
||||
private String[] mReadOnlyApnFields;
|
||||
private boolean mReadOnlyApn;
|
||||
private Uri mCarrierUri;
|
||||
|
||||
/**
|
||||
* Standard projection for the interesting columns of a normal note.
|
||||
@@ -154,22 +172,27 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
};
|
||||
|
||||
private static final int ID_INDEX = 0;
|
||||
private static final int NAME_INDEX = 1;
|
||||
private static final int APN_INDEX = 2;
|
||||
@VisibleForTesting
|
||||
static final int NAME_INDEX = 1;
|
||||
@VisibleForTesting
|
||||
static final int APN_INDEX = 2;
|
||||
private static final int PROXY_INDEX = 3;
|
||||
private static final int PORT_INDEX = 4;
|
||||
private static final int USER_INDEX = 5;
|
||||
private static final int SERVER_INDEX = 6;
|
||||
private static final int PASSWORD_INDEX = 7;
|
||||
private static final int MMSC_INDEX = 8;
|
||||
private static final int MCC_INDEX = 9;
|
||||
private static final int MNC_INDEX = 10;
|
||||
@VisibleForTesting
|
||||
static final int MCC_INDEX = 9;
|
||||
@VisibleForTesting
|
||||
static final int MNC_INDEX = 10;
|
||||
private static final int MMSPROXY_INDEX = 12;
|
||||
private static final int MMSPORT_INDEX = 13;
|
||||
private static final int AUTH_TYPE_INDEX = 14;
|
||||
private static final int TYPE_INDEX = 15;
|
||||
private static final int PROTOCOL_INDEX = 16;
|
||||
private static final int CARRIER_ENABLED_INDEX = 17;
|
||||
@VisibleForTesting
|
||||
static final int CARRIER_ENABLED_INDEX = 17;
|
||||
private static final int BEARER_INDEX = 18;
|
||||
private static final int BEARER_BITMASK_INDEX = 19;
|
||||
private static final int ROAMING_PROTOCOL_INDEX = 20;
|
||||
@@ -178,7 +201,6 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
private static final int EDITED_INDEX = 23;
|
||||
private static final int USER_EDITABLE_INDEX = 24;
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
@@ -207,14 +229,11 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
mMvnoType = (ListPreference) findPreference(KEY_MVNO_TYPE);
|
||||
mMvnoMatchData = (EditTextPreference) findPreference("mvno_match_data");
|
||||
|
||||
mRes = getResources();
|
||||
|
||||
final Intent intent = getIntent();
|
||||
final String action = intent.getAction();
|
||||
mSubId = intent.getIntExtra(ApnSettings.SUB_ID,
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
|
||||
mFirstTime = icicle == null;
|
||||
mReadOnlyApn = false;
|
||||
mReadOnlyApnTypes = null;
|
||||
mReadOnlyApnFields = null;
|
||||
@@ -236,61 +255,47 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
Uri uri = null;
|
||||
if (action.equals(Intent.ACTION_EDIT)) {
|
||||
Uri uri = intent.getData();
|
||||
uri = intent.getData();
|
||||
if (!uri.isPathPrefixMatch(Telephony.Carriers.CONTENT_URI)) {
|
||||
Log.e(TAG, "Edit request not for carrier table. Uri: " + uri);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
mUri = uri;
|
||||
} else if (action.equals(Intent.ACTION_INSERT)) {
|
||||
if (mFirstTime || icicle.getInt(SAVED_POS) == 0) {
|
||||
Uri uri = intent.getData();
|
||||
if (!uri.isPathPrefixMatch(Telephony.Carriers.CONTENT_URI)) {
|
||||
Log.e(TAG, "Insert request not for carrier table. Uri: " + uri);
|
||||
mCarrierUri = intent.getData();
|
||||
if (!mCarrierUri.isPathPrefixMatch(Telephony.Carriers.CONTENT_URI)) {
|
||||
Log.e(TAG, "Insert request not for carrier table. Uri: " + mCarrierUri);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put(Telephony.Carriers.EDITED, Telephony.Carriers.USER_EDITED);
|
||||
mUri = getContentResolver().insert(uri, contentValues);
|
||||
} else {
|
||||
mUri = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI,
|
||||
icicle.getInt(SAVED_POS));
|
||||
}
|
||||
mNewApn = true;
|
||||
mMvnoTypeStr = intent.getStringExtra(ApnSettings.MVNO_TYPE);
|
||||
mMvnoMatchDataStr = intent.getStringExtra(ApnSettings.MVNO_MATCH_DATA);
|
||||
// If we were unable to create a new note, then just finish
|
||||
// this activity. A RESULT_CANCELED will be sent back to the
|
||||
// original activity if they requested a result.
|
||||
if (mUri == null) {
|
||||
Log.w(TAG, "Failed to insert new telephony provider into "
|
||||
+ getIntent().getData());
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
// The new entry was created, so assume all will end well and
|
||||
// set the result to be returned.
|
||||
setResult(RESULT_OK, (new Intent()).setAction(mUri.toString()));
|
||||
|
||||
} else {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
mCursor = getActivity().managedQuery(mUri, sProjection, null, null);
|
||||
mCursor.moveToFirst();
|
||||
// Creates an ApnData to store the apn data temporary, so that we don't need the cursor to
|
||||
// get the apn data. The uri is null if the action is ACTION_INSERT, that mean there is no
|
||||
// record in the database, so create a empty ApnData to represent a empty row of database.
|
||||
if (uri != null) {
|
||||
mApnData = getApnDataFromUri(uri);
|
||||
} else {
|
||||
mApnData = new ApnData(sProjection.length);
|
||||
}
|
||||
|
||||
mTelephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
|
||||
|
||||
Log.d(TAG, "onCreate: EDITED " + mCursor.getInt(EDITED_INDEX));
|
||||
boolean isUserEdited = mApnData.getInteger(EDITED_INDEX, Telephony.Carriers.USER_EDITED)
|
||||
== Telephony.Carriers.USER_EDITED;
|
||||
|
||||
Log.d(TAG, "onCreate: EDITED " + isUserEdited);
|
||||
// if it's not a USER_EDITED apn, check if it's read-only
|
||||
if (mCursor.getInt(EDITED_INDEX) != Telephony.Carriers.USER_EDITED &&
|
||||
(mCursor.getInt(USER_EDITABLE_INDEX) == 0 ||
|
||||
apnTypesMatch(mReadOnlyApnTypes, mCursor.getString(TYPE_INDEX)))) {
|
||||
if (!isUserEdited && (mApnData.getInteger(USER_EDITABLE_INDEX, 1) == 0
|
||||
|| apnTypesMatch(mReadOnlyApnTypes, mApnData.getString(TYPE_INDEX)))) {
|
||||
Log.d(TAG, "onCreate: apnTypesMatch; read-only APN");
|
||||
mReadOnlyApn = true;
|
||||
disableAllFields();
|
||||
@@ -302,12 +307,7 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
getPreferenceScreen().getPreference(i).setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
fillUi();
|
||||
fillUI(icicle == null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -462,50 +462,23 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
return MetricsEvent.APN_EDITOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (mUri == null && mNewApn) {
|
||||
// The URI could have been deleted when activity is paused,
|
||||
// therefore, it needs to be restored.
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put(Telephony.Carriers.EDITED, Telephony.Carriers.USER_EDITED);
|
||||
mUri = getContentResolver().insert(getIntent().getData(), contentValues);
|
||||
if (mUri == null) {
|
||||
Log.w(TAG, "Failed to insert new telephony provider into "
|
||||
+ getIntent().getData());
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
mCursor = getActivity().managedQuery(mUri, sProjection, null, null);
|
||||
mCursor.moveToFirst();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
private void fillUi() {
|
||||
if (mFirstTime) {
|
||||
mFirstTime = false;
|
||||
@VisibleForTesting
|
||||
void fillUI(boolean firstTime) {
|
||||
if (firstTime) {
|
||||
// Fill in all the values from the db in both text editor and summary
|
||||
mName.setText(mCursor.getString(NAME_INDEX));
|
||||
mApn.setText(mCursor.getString(APN_INDEX));
|
||||
mProxy.setText(mCursor.getString(PROXY_INDEX));
|
||||
mPort.setText(mCursor.getString(PORT_INDEX));
|
||||
mUser.setText(mCursor.getString(USER_INDEX));
|
||||
mServer.setText(mCursor.getString(SERVER_INDEX));
|
||||
mPassword.setText(mCursor.getString(PASSWORD_INDEX));
|
||||
mMmsProxy.setText(mCursor.getString(MMSPROXY_INDEX));
|
||||
mMmsPort.setText(mCursor.getString(MMSPORT_INDEX));
|
||||
mMmsc.setText(mCursor.getString(MMSC_INDEX));
|
||||
mMcc.setText(mCursor.getString(MCC_INDEX));
|
||||
mMnc.setText(mCursor.getString(MNC_INDEX));
|
||||
mApnType.setText(mCursor.getString(TYPE_INDEX));
|
||||
mName.setText(mApnData.getString(NAME_INDEX));
|
||||
mApn.setText(mApnData.getString(APN_INDEX));
|
||||
mProxy.setText(mApnData.getString(PROXY_INDEX));
|
||||
mPort.setText(mApnData.getString(PORT_INDEX));
|
||||
mUser.setText(mApnData.getString(USER_INDEX));
|
||||
mServer.setText(mApnData.getString(SERVER_INDEX));
|
||||
mPassword.setText(mApnData.getString(PASSWORD_INDEX));
|
||||
mMmsProxy.setText(mApnData.getString(MMSPROXY_INDEX));
|
||||
mMmsPort.setText(mApnData.getString(MMSPORT_INDEX));
|
||||
mMmsc.setText(mApnData.getString(MMSC_INDEX));
|
||||
mMcc.setText(mApnData.getString(MCC_INDEX));
|
||||
mMnc.setText(mApnData.getString(MNC_INDEX));
|
||||
mApnType.setText(mApnData.getString(TYPE_INDEX));
|
||||
if (mNewApn) {
|
||||
String numeric = mTelephonyManager.getSimOperator(mSubId);
|
||||
// MCC is first 3 chars and then in 2 - 3 chars of MNC
|
||||
@@ -521,20 +494,20 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
mCurMcc = mcc;
|
||||
}
|
||||
}
|
||||
int authVal = mCursor.getInt(AUTH_TYPE_INDEX);
|
||||
int authVal = mApnData.getInteger(AUTH_TYPE_INDEX, -1);
|
||||
if (authVal != -1) {
|
||||
mAuthType.setValueIndex(authVal);
|
||||
} else {
|
||||
mAuthType.setValue(null);
|
||||
}
|
||||
|
||||
mProtocol.setValue(mCursor.getString(PROTOCOL_INDEX));
|
||||
mRoamingProtocol.setValue(mCursor.getString(ROAMING_PROTOCOL_INDEX));
|
||||
mCarrierEnabled.setChecked(mCursor.getInt(CARRIER_ENABLED_INDEX)==1);
|
||||
mBearerInitialVal = mCursor.getInt(BEARER_INDEX);
|
||||
mProtocol.setValue(mApnData.getString(PROTOCOL_INDEX));
|
||||
mRoamingProtocol.setValue(mApnData.getString(ROAMING_PROTOCOL_INDEX));
|
||||
mCarrierEnabled.setChecked(mApnData.getInteger(CARRIER_ENABLED_INDEX, 1) == 1);
|
||||
mBearerInitialVal = mApnData.getInteger(BEARER_INDEX, 0);
|
||||
|
||||
HashSet<String> bearers = new HashSet<String>();
|
||||
int bearerBitmask = mCursor.getInt(BEARER_BITMASK_INDEX);
|
||||
int bearerBitmask = mApnData.getInteger(BEARER_BITMASK_INDEX, 0);
|
||||
if (bearerBitmask == 0) {
|
||||
if (mBearerInitialVal == 0) {
|
||||
bearers.add("" + 0);
|
||||
@@ -556,9 +529,9 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
}
|
||||
mBearerMulti.setValues(bearers);
|
||||
|
||||
mMvnoType.setValue(mCursor.getString(MVNO_TYPE_INDEX));
|
||||
mMvnoType.setValue(mApnData.getString(MVNO_TYPE_INDEX));
|
||||
mMvnoMatchData.setEnabled(false);
|
||||
mMvnoMatchData.setText(mCursor.getString(MVNO_MATCH_DATA_INDEX));
|
||||
mMvnoMatchData.setText(mApnData.getString(MVNO_MATCH_DATA_INDEX));
|
||||
if (mNewApn && mMvnoTypeStr != null && mMvnoMatchDataStr != null) {
|
||||
mMvnoType.setValue(mMvnoTypeStr);
|
||||
mMvnoMatchData.setText(mMvnoMatchDataStr);
|
||||
@@ -584,7 +557,7 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
int authValIndex = Integer.parseInt(authVal);
|
||||
mAuthType.setValueIndex(authValIndex);
|
||||
|
||||
String []values = mRes.getStringArray(R.array.apn_auth_entries);
|
||||
String[] values = getResources().getStringArray(R.array.apn_auth_entries);
|
||||
mAuthType.setSummary(values[authValIndex]);
|
||||
} else {
|
||||
mAuthType.setSummary(sNotSet);
|
||||
@@ -617,7 +590,7 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
if (protocolIndex == -1) {
|
||||
return null;
|
||||
} else {
|
||||
String[] values = mRes.getStringArray(R.array.apn_protocol_entries);
|
||||
String[] values = getResources().getStringArray(R.array.apn_protocol_entries);
|
||||
try {
|
||||
return values[protocolIndex];
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
@@ -631,7 +604,7 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
if (mBearerIndex == -1) {
|
||||
return null;
|
||||
} else {
|
||||
String[] values = mRes.getStringArray(R.array.bearer_entries);
|
||||
String[] values = getResources().getStringArray(R.array.bearer_entries);
|
||||
try {
|
||||
return values[mBearerIndex];
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
@@ -641,7 +614,7 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
private String bearerMultiDescription(Set<String> raw) {
|
||||
String[] values = mRes.getStringArray(R.array.bearer_entries);
|
||||
String[] values = getResources().getStringArray(R.array.bearer_entries);
|
||||
StringBuilder retVal = new StringBuilder();
|
||||
boolean first = true;
|
||||
for (String bearer : raw) {
|
||||
@@ -671,7 +644,7 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
if (mvnoIndex == -1) {
|
||||
return null;
|
||||
} else {
|
||||
String[] values = mRes.getStringArray(R.array.mvno_type_entries);
|
||||
String[] values = getResources().getStringArray(R.array.mvno_type_entries);
|
||||
boolean mvnoMatchDataUneditable =
|
||||
mReadOnlyApn || (mReadOnlyApnFields != null
|
||||
&& Arrays.asList(mReadOnlyApnFields)
|
||||
@@ -703,7 +676,7 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
int index = Integer.parseInt((String) newValue);
|
||||
mAuthType.setValueIndex(index);
|
||||
|
||||
String[] values = mRes.getStringArray(R.array.apn_auth_entries);
|
||||
String[] values = getResources().getStringArray(R.array.apn_auth_entries);
|
||||
mAuthType.setSummary(values[index]);
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
@@ -766,21 +739,20 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
switch (item.getItemId()) {
|
||||
case MENU_DELETE:
|
||||
deleteApn();
|
||||
finish();
|
||||
return true;
|
||||
case MENU_SAVE:
|
||||
if (validateAndSave(false)) {
|
||||
if (validateAndSaveApnData()) {
|
||||
finish();
|
||||
}
|
||||
return true;
|
||||
case MENU_CANCEL:
|
||||
if (mNewApn) {
|
||||
getContentResolver().delete(mUri, null, null);
|
||||
}
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
@@ -790,11 +762,20 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
view.requestFocus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to save the apn data when pressed the back button. An error message will be displayed if
|
||||
* the apn data is invalid.
|
||||
*
|
||||
* TODO(b/77339593): Try to keep the same behavior between back button and up navigate button.
|
||||
* We will save the valid apn data to the database when pressed the back button, but discard all
|
||||
* user changed when pressed the up navigate button.
|
||||
*/
|
||||
@Override
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
if (event.getAction() != KeyEvent.ACTION_DOWN) return false;
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_BACK: {
|
||||
if (validateAndSave(false)) {
|
||||
if (validateAndSaveApnData()) {
|
||||
finish();
|
||||
}
|
||||
return true;
|
||||
@@ -803,62 +784,70 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle icicle) {
|
||||
super.onSaveInstanceState(icicle);
|
||||
if (validateAndSave(true)) {
|
||||
icicle.putInt(SAVED_POS, mCursor.getInt(ID_INDEX));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add key, value to cv and compare the value against the value at index in mCursor. Return true
|
||||
* if values are different. assumeDiff indicates if values can be assumed different in which
|
||||
* case no comparison is needed.
|
||||
* @return true if value is different from the value at index in mCursor
|
||||
* Add key, value to {@code cv} and compare the value against the value at index in
|
||||
* {@link #mApnData}.
|
||||
*
|
||||
* <p>
|
||||
* The key, value will not add to {@code cv} if value is null.
|
||||
*
|
||||
* @return true if values are different. {@code assumeDiff} indicates if values can be assumed
|
||||
* different in which case no comparison is needed.
|
||||
*/
|
||||
boolean setStringValueAndCheckIfDiff(ContentValues cv, String key, String value,
|
||||
boolean assumeDiff, int index) {
|
||||
cv.put(key, value);
|
||||
String valueFromCursor = mCursor.getString(index);
|
||||
boolean setStringValueAndCheckIfDiff(
|
||||
ContentValues cv, String key, String value, boolean assumeDiff, int index) {
|
||||
String valueFromLocalCache = mApnData.getString(index);
|
||||
if (VDBG) {
|
||||
Log.d(TAG, "setStringValueAndCheckIfDiff: assumeDiff: " + assumeDiff
|
||||
+ " key: " + key
|
||||
+ " value: '" + value
|
||||
+ "' valueFromCursor: '" + valueFromCursor + "'");
|
||||
+ "' valueFromDb: '" + valueFromLocalCache + "'");
|
||||
}
|
||||
return assumeDiff
|
||||
|| !((TextUtils.isEmpty(value) && TextUtils.isEmpty(valueFromCursor))
|
||||
|| (value != null && value.equals(valueFromCursor)));
|
||||
boolean isDiff = assumeDiff
|
||||
|| !((TextUtils.isEmpty(value) && TextUtils.isEmpty(valueFromLocalCache))
|
||||
|| (value != null && value.equals(valueFromLocalCache)));
|
||||
|
||||
if (isDiff && value != null) {
|
||||
cv.put(key, value);
|
||||
}
|
||||
return isDiff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add key, value to cv and compare the value against the value at index in mCursor. Return true
|
||||
* if values are different. assumeDiff indicates if values can be assumed different in which
|
||||
* case no comparison is needed.
|
||||
* @return true if value is different from the value at index in mCursor
|
||||
* Add key, value to {@code cv} and compare the value against the value at index in
|
||||
* {@link #mApnData}.
|
||||
*
|
||||
* @return true if values are different. {@code assumeDiff} indicates if values can be assumed
|
||||
* different in which case no comparison is needed.
|
||||
*/
|
||||
boolean setIntValueAndCheckIfDiff(ContentValues cv, String key, int value,
|
||||
boolean assumeDiff, int index) {
|
||||
cv.put(key, value);
|
||||
int valueFromCursor = mCursor.getInt(index);
|
||||
boolean setIntValueAndCheckIfDiff(
|
||||
ContentValues cv, String key, int value, boolean assumeDiff, int index) {
|
||||
Integer valueFromLocalCache = mApnData.getInteger(index);
|
||||
if (VDBG) {
|
||||
Log.d(TAG, "setIntValueAndCheckIfDiff: assumeDiff: " + assumeDiff
|
||||
+ " key: " + key
|
||||
+ " value: '" + value
|
||||
+ "' valueFromCursor: '" + valueFromCursor + "'");
|
||||
+ "' valueFromDb: '" + valueFromLocalCache + "'");
|
||||
}
|
||||
return assumeDiff || value != valueFromCursor;
|
||||
|
||||
boolean isDiff = assumeDiff || value != valueFromLocalCache;
|
||||
if (isDiff) {
|
||||
cv.put(key, value);
|
||||
}
|
||||
return isDiff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the key fields' validity and save if valid.
|
||||
* @param force save even if the fields are not valid, if the app is
|
||||
* being suspended
|
||||
* @return true if there's no error
|
||||
* Validates the apn data and save it to the database if it's valid.
|
||||
*
|
||||
* <p>
|
||||
* A dialog with error message will be displayed if the APN data is invalid.
|
||||
*
|
||||
* @return true if there is no error
|
||||
*/
|
||||
private boolean validateAndSave(boolean force) {
|
||||
// nothing to do if it's a read only APN
|
||||
@VisibleForTesting
|
||||
boolean validateAndSaveApnData() {
|
||||
// Nothing to do if it's a read only APN
|
||||
if (mReadOnlyApn) {
|
||||
return true;
|
||||
}
|
||||
@@ -868,21 +857,9 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
String mcc = checkNotSet(mMcc.getText());
|
||||
String mnc = checkNotSet(mMnc.getText());
|
||||
|
||||
if (getErrorMsg() != null && !force) {
|
||||
ErrorDialog.showError(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mCursor.moveToFirst()) {
|
||||
Log.w(TAG,
|
||||
"Could not go to the first row in the Cursor when saving data.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// If it's a new APN and a name or apn haven't been entered, then erase the entry
|
||||
if (force && mNewApn && name.length() < 1 && apn.length() < 1) {
|
||||
getContentResolver().delete(mUri, null, null);
|
||||
mUri = null;
|
||||
String errorMsg = validateApnData();
|
||||
if (errorMsg != null) {
|
||||
showError();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -890,12 +867,9 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
// call update() if it's a new APN. If not, check if any field differs from the db value;
|
||||
// if any diff is found update() should be called
|
||||
boolean callUpdate = mNewApn;
|
||||
|
||||
// Add a dummy name "Untitled", if the user exits the screen without adding a name but
|
||||
// entered other information worth keeping.
|
||||
callUpdate = setStringValueAndCheckIfDiff(values,
|
||||
Telephony.Carriers.NAME,
|
||||
name.length() < 1 ? getResources().getString(R.string.untitled_apn) : name,
|
||||
name,
|
||||
callUpdate,
|
||||
NAME_INDEX);
|
||||
|
||||
@@ -1054,15 +1028,38 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
values.put(Telephony.Carriers.EDITED, Telephony.Carriers.USER_EDITED);
|
||||
|
||||
if (callUpdate) {
|
||||
getContentResolver().update(mUri, values, null, null);
|
||||
final Uri uri = mApnData.getUri() == null ? mCarrierUri : mApnData.getUri();
|
||||
updateApnDataToDatabase(uri, values);
|
||||
} else {
|
||||
if (VDBG) Log.d(TAG, "validateAndSave: not calling update()");
|
||||
if (VDBG) Log.d(TAG, "validateAndSaveApnData: not calling update()");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private String getErrorMsg() {
|
||||
private void updateApnDataToDatabase(Uri uri, ContentValues values) {
|
||||
ThreadUtils.postOnBackgroundThread(() -> {
|
||||
if (uri.equals(mCarrierUri)) {
|
||||
// Add a new apn to the database
|
||||
final Uri newUri = getContentResolver().insert(mCarrierUri, values);
|
||||
if (newUri == null) {
|
||||
Log.e(TAG, "Can't add a new apn to database " + mCarrierUri);
|
||||
}
|
||||
} else {
|
||||
// Update the existing apn
|
||||
getContentResolver().update(
|
||||
uri, values, null /* where */, null /* selection Args */);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates whether the apn data is valid.
|
||||
*
|
||||
* @return An error message if the apn data is invalid, otherwise return null.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
String validateApnData() {
|
||||
String errorMsg = null;
|
||||
|
||||
String name = checkNotSet(mName.getText());
|
||||
@@ -1070,14 +1067,14 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
String mcc = checkNotSet(mMcc.getText());
|
||||
String mnc = checkNotSet(mMnc.getText());
|
||||
|
||||
if (name.length() < 1) {
|
||||
errorMsg = mRes.getString(R.string.error_name_empty);
|
||||
} else if (apn.length() < 1) {
|
||||
errorMsg = mRes.getString(R.string.error_apn_empty);
|
||||
} else if (mcc.length() != 3) {
|
||||
errorMsg = mRes.getString(R.string.error_mcc_not3);
|
||||
} else if ((mnc.length() & 0xFFFE) != 2) {
|
||||
errorMsg = mRes.getString(R.string.error_mnc_not23);
|
||||
if (TextUtils.isEmpty(name)) {
|
||||
errorMsg = getResources().getString(R.string.error_name_empty);
|
||||
} else if (TextUtils.isEmpty(apn)) {
|
||||
errorMsg = getResources().getString(R.string.error_apn_empty);
|
||||
} else if (mcc == null || mcc.length() != 3) {
|
||||
errorMsg = getResources().getString(R.string.error_mcc_not3);
|
||||
} else if ((mnc == null || (mnc.length() & 0xFFFE) != 2)) {
|
||||
errorMsg = getResources().getString(R.string.error_mnc_not23);
|
||||
}
|
||||
|
||||
if (errorMsg == null) {
|
||||
@@ -1088,13 +1085,13 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (String type : mReadOnlyApnTypes) {
|
||||
stringBuilder.append(type).append(", ");
|
||||
Log.d(TAG, "getErrorMsg: appending type: " + type);
|
||||
Log.d(TAG, "validateApnData: appending type: " + type);
|
||||
}
|
||||
// remove last ", "
|
||||
if (stringBuilder.length() >= 2) {
|
||||
stringBuilder.delete(stringBuilder.length() - 2, stringBuilder.length());
|
||||
}
|
||||
errorMsg = String.format(mRes.getString(R.string.error_adding_apn_type),
|
||||
errorMsg = String.format(getResources().getString(R.string.error_adding_apn_type),
|
||||
stringBuilder);
|
||||
}
|
||||
}
|
||||
@@ -1102,9 +1099,16 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void showError() {
|
||||
ErrorDialog.showError(this);
|
||||
}
|
||||
|
||||
private void deleteApn() {
|
||||
getContentResolver().delete(mUri, null, null);
|
||||
finish();
|
||||
if (mApnData.getUri() != null) {
|
||||
getContentResolver().delete(mApnData.getUri(), null, null);
|
||||
mApnData = new ApnData(sProjection.length);
|
||||
}
|
||||
}
|
||||
|
||||
private String starify(String value) {
|
||||
@@ -1119,20 +1123,21 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@link #sNotSet} if the given string {@code value} is null or empty. The string
|
||||
* {@link #sNotSet} typically used as the default display when an entry in the preference is
|
||||
* null or empty.
|
||||
*/
|
||||
private String checkNull(String value) {
|
||||
if (value == null || value.length() == 0) {
|
||||
return sNotSet;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
return TextUtils.isEmpty(value) ? sNotSet : value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns null if the given string {@code value} equals to {@link #sNotSet}. This method
|
||||
* should be used when convert a string value from preference to database.
|
||||
*/
|
||||
private String checkNotSet(String value) {
|
||||
if (value == null || value.equals(sNotSet)) {
|
||||
return "";
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
return sNotSet.equals(value) ? null : value;
|
||||
}
|
||||
|
||||
private String getUserEnteredApnType() {
|
||||
@@ -1176,7 +1181,7 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
String msg = ((ApnEditor) getTargetFragment()).getErrorMsg();
|
||||
String msg = ((ApnEditor) getTargetFragment()).validateApnData();
|
||||
|
||||
return new AlertDialog.Builder(getContext())
|
||||
.setTitle(R.string.error_title)
|
||||
@@ -1191,10 +1196,19 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
public static class InvalidTypeException extends RuntimeException {
|
||||
InvalidTypeException(String msg) {
|
||||
super(msg);
|
||||
private ApnData getApnDataFromUri(Uri uri) {
|
||||
ApnData apnData;
|
||||
try (Cursor cursor = getActivity().managedQuery(
|
||||
uri, sProjection, null /* selection */, null /* sortOrder */)) {
|
||||
cursor.moveToFirst();
|
||||
apnData = new ApnData(uri, cursor);
|
||||
}
|
||||
|
||||
if (apnData == null) {
|
||||
Log.d(TAG, "Can't get apnData from Uri " + uri);
|
||||
}
|
||||
|
||||
return apnData;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -1243,34 +1257,17 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
mUri = uri;
|
||||
}
|
||||
|
||||
Integer getInteger(int index) throws InvalidTypeException {
|
||||
if (!isValidTypeOrNull(mData[index], Integer.class)) {
|
||||
throwInvalidTypeException(Integer.class, mData[index].getClass());
|
||||
}
|
||||
Integer getInteger(int index) {
|
||||
return (Integer) mData[index];
|
||||
}
|
||||
|
||||
Integer getInteger(int index, Integer defaultValue) throws InvalidTypeException {
|
||||
Integer getInteger(int index, Integer defaultValue) {
|
||||
Integer val = getInteger(index);
|
||||
return val == null ? defaultValue : val;
|
||||
}
|
||||
|
||||
String getString(int index) throws InvalidTypeException {
|
||||
if (!isValidTypeOrNull(mData[index], String.class)) {
|
||||
throwInvalidTypeException(String.class, mData[index].getClass());
|
||||
}
|
||||
String getString(int index) {
|
||||
return (String) mData[index];
|
||||
}
|
||||
|
||||
private boolean isValidTypeOrNull(Object obj, Class expectedClass) {
|
||||
return obj == null || expectedClass.isInstance(obj);
|
||||
}
|
||||
|
||||
private void throwInvalidTypeException(Class<?> expectedClass, Class<?> actualClass) {
|
||||
throw new InvalidTypeException(
|
||||
String.format(
|
||||
"Type mismatched, want %s, but is %s", expectedClass, actualClass));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -94,7 +94,6 @@ import com.android.internal.app.UnlaunchableAppActivity;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Iterator;
|
||||
@@ -874,7 +873,7 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
* @param packageName package to check about
|
||||
*/
|
||||
public static boolean isProfileOrDeviceOwner(UserManager userManager,
|
||||
DevicePolicyManagerWrapper devicePolicyManager, String packageName) {
|
||||
DevicePolicyManager devicePolicyManager, String packageName) {
|
||||
List<UserInfo> userInfos = userManager.getUsers();
|
||||
if (devicePolicyManager.isDeviceOwnerAppOnAnyUser(packageName)) {
|
||||
return true;
|
||||
|
@@ -813,8 +813,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
if (!MagnificationPreferenceFragment.isApplicable(context.getResources())) {
|
||||
preference.setFragment(ToggleScreenMagnificationPreferenceFragment.class.getName());
|
||||
final Bundle extras = preference.getExtras();
|
||||
MagnificationPreferenceFragment.populateMagnificationGesturesPreferenceExtras(extras,
|
||||
context);
|
||||
MagnificationGesturesPreferenceController
|
||||
.populateMagnificationGesturesPreferenceExtras(extras, context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -156,8 +156,8 @@ public class AccessibilitySettingsForSetupWizard extends SettingsPreferenceFragm
|
||||
preference.setFragment(
|
||||
ToggleScreenMagnificationPreferenceFragmentForSetupWizard.class.getName());
|
||||
final Bundle extras = preference.getExtras();
|
||||
MagnificationPreferenceFragment.populateMagnificationGesturesPreferenceExtras(extras,
|
||||
context);
|
||||
MagnificationGesturesPreferenceController
|
||||
.populateMagnificationGesturesPreferenceExtras(extras, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the
|
||||
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
public class MagnificationGesturesPreferenceController extends BasePreferenceController {
|
||||
|
||||
private boolean mIsFromSUW = false;
|
||||
|
||||
public MagnificationGesturesPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
public void setIsFromSUW(boolean fromSUW) {
|
||||
mIsFromSUW = fromSUW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (getPreferenceKey().equals(preference.getKey())) {
|
||||
Bundle extras = preference.getExtras();
|
||||
populateMagnificationGesturesPreferenceExtras(extras, mContext);
|
||||
extras.putBoolean(AccessibilitySettings.EXTRA_LAUNCHED_FROM_SUW, mIsFromSUW);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
int resId = 0;
|
||||
if (mIsFromSUW) {
|
||||
resId = R.string.accessibility_screen_magnification_short_summary;
|
||||
} else {
|
||||
final boolean enabled = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 0) == 1;
|
||||
resId = (enabled ? R.string.accessibility_feature_state_on :
|
||||
R.string.accessibility_feature_state_off);
|
||||
}
|
||||
return mContext.getString(resId);
|
||||
}
|
||||
|
||||
static void populateMagnificationGesturesPreferenceExtras(Bundle extras, Context context) {
|
||||
extras.putString(AccessibilitySettings.EXTRA_PREFERENCE_KEY,
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED);
|
||||
extras.putString(AccessibilitySettings.EXTRA_TITLE, context.getString(
|
||||
R.string.accessibility_screen_magnification_gestures_title));
|
||||
extras.putInt(AccessibilitySettings.EXTRA_TITLE_RES,
|
||||
R.string.accessibility_screen_magnification_gestures_title);
|
||||
extras.putCharSequence(AccessibilitySettings.EXTRA_SUMMARY, context.getResources().getText(
|
||||
R.string.accessibility_screen_magnification_summary));
|
||||
extras.putBoolean(AccessibilitySettings.EXTRA_CHECKED,
|
||||
Settings.Secure.getInt(context.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 0) == 1);
|
||||
extras.putInt(AccessibilitySettings.EXTRA_VIDEO_RAW_RESOURCE_ID,
|
||||
R.raw.accessibility_screen_magnification);
|
||||
}
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the
|
||||
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
public class MagnificationNavbarPreferenceController extends BasePreferenceController {
|
||||
|
||||
private boolean mIsFromSUW = false;
|
||||
|
||||
public MagnificationNavbarPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
public void setIsFromSUW(boolean fromSUW) {
|
||||
mIsFromSUW = fromSUW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (getPreferenceKey().equals(preference.getKey())) {
|
||||
Bundle extras = preference.getExtras();
|
||||
extras.putString(AccessibilitySettings.EXTRA_PREFERENCE_KEY,
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED);
|
||||
extras.putString(AccessibilitySettings.EXTRA_TITLE, mContext.getString(
|
||||
R.string.accessibility_screen_magnification_navbar_title));
|
||||
extras.putInt(AccessibilitySettings.EXTRA_TITLE_RES,
|
||||
R.string.accessibility_screen_magnification_navbar_title);
|
||||
extras.putCharSequence(AccessibilitySettings.EXTRA_SUMMARY,
|
||||
mContext.getResources().getText(
|
||||
R.string.accessibility_screen_magnification_navbar_summary));
|
||||
extras.putBoolean(AccessibilitySettings.EXTRA_CHECKED,
|
||||
Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, 0)
|
||||
== 1);
|
||||
extras.putBoolean(AccessibilitySettings.EXTRA_LAUNCHED_FROM_SUW, mIsFromSUW);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return MagnificationPreferenceFragment.isApplicable(mContext.getResources())
|
||||
? AVAILABLE
|
||||
: DISABLED_UNSUPPORTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
int resId = 0;
|
||||
if (mIsFromSUW) {
|
||||
resId = R.string.accessibility_screen_magnification_navbar_short_summary;
|
||||
} else {
|
||||
final boolean enabled = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, 0) == 1;
|
||||
resId = (enabled ? R.string.accessibility_feature_state_on :
|
||||
R.string.accessibility_feature_state_off);
|
||||
}
|
||||
return mContext.getText(resId);
|
||||
}
|
||||
}
|
@@ -29,40 +29,39 @@ import android.view.View;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class MagnificationPreferenceFragment extends SettingsPreferenceFragment implements
|
||||
Indexable {
|
||||
public final class MagnificationPreferenceFragment extends DashboardFragment {
|
||||
|
||||
private static final String TAG = "MagnificationPreferenceFragment";
|
||||
|
||||
// Settings App preference keys
|
||||
private static final String PREFERENCE_TITLE_KEY = "magnification_preference_screen_title";
|
||||
private static final String MAGNIFICATION_GESTURES_PREFERENCE_SCREEN_KEY =
|
||||
"screen_magnification_gestures_preference_screen";
|
||||
private static final String MAGNIFICATION_NAVBAR_PREFERENCE_SCREEN_KEY =
|
||||
"screen_magnification_navbar_preference_screen";
|
||||
|
||||
// Pseudo ComponentName used to represent navbar magnification in Settings.Secure.
|
||||
private static final String MAGNIFICATION_COMPONENT_ID =
|
||||
"com.android.server.accessibility.MagnificationController";
|
||||
|
||||
private Preference mMagnificationGesturesPreference;
|
||||
private Preference mMagnificationNavbarPreference;
|
||||
|
||||
private boolean mLaunchedFromSuw = false;
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle bundle, String s) {
|
||||
addPreferencesFromResource(R.xml.accessibility_magnification_settings);
|
||||
mMagnificationGesturesPreference = findPreference(
|
||||
MAGNIFICATION_GESTURES_PREFERENCE_SCREEN_KEY);
|
||||
mMagnificationNavbarPreference = findPreference(MAGNIFICATION_NAVBAR_PREFERENCE_SCREEN_KEY);
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.ACCESSIBILITY_SCREEN_MAGNIFICATION_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,28 +70,21 @@ public final class MagnificationPreferenceFragment extends SettingsPreferenceFra
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.accessibility_magnification_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
final Bundle args = getArguments();
|
||||
if ((args != null) && args.containsKey(AccessibilitySettings.EXTRA_LAUNCHED_FROM_SUW)) {
|
||||
mLaunchedFromSuw = args.getBoolean(AccessibilitySettings.EXTRA_LAUNCHED_FROM_SUW);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
getActivity().setTitle(R.string.accessibility_screen_magnification_title);
|
||||
updateFeatureSummary(Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
|
||||
mMagnificationGesturesPreference);
|
||||
updateFeatureSummary(Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
|
||||
mMagnificationNavbarPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.ACCESSIBILITY_SCREEN_MAGNIFICATION_SETTINGS;
|
||||
use(MagnificationGesturesPreferenceController.class)
|
||||
.setIsFromSUW(mLaunchedFromSuw);
|
||||
use(MagnificationNavbarPreferenceController.class)
|
||||
.setIsFromSUW(mLaunchedFromSuw);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,57 +94,9 @@ public final class MagnificationPreferenceFragment extends SettingsPreferenceFra
|
||||
preference.setFragment(
|
||||
ToggleScreenMagnificationPreferenceFragmentForSetupWizard.class.getName());
|
||||
}
|
||||
if (mMagnificationGesturesPreference == preference) {
|
||||
handleMagnificationGesturesPreferenceScreenClick();
|
||||
super.onPreferenceTreeClick(mMagnificationGesturesPreference);
|
||||
return true;
|
||||
} else if (mMagnificationNavbarPreference == preference) {
|
||||
handleMagnificationNavbarPreferenceScreenClick();
|
||||
super.onPreferenceTreeClick(mMagnificationNavbarPreference);
|
||||
return true;
|
||||
}
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
}
|
||||
|
||||
private void updateFeatureSummary(String prefKey, Preference pref) {
|
||||
if (!mLaunchedFromSuw) {
|
||||
final boolean enabled = Settings.Secure.getInt(getContentResolver(), prefKey, 0) == 1;
|
||||
pref.setSummary(enabled ? R.string.accessibility_feature_state_on
|
||||
: R.string.accessibility_feature_state_off);
|
||||
} else {
|
||||
if (Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED.equals(prefKey)) {
|
||||
pref.setSummary(R.string.accessibility_screen_magnification_short_summary);
|
||||
} else if (Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED.equals(
|
||||
prefKey)) {
|
||||
pref.setSummary(R.string.accessibility_screen_magnification_navbar_short_summary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleMagnificationGesturesPreferenceScreenClick() {
|
||||
Bundle extras = mMagnificationGesturesPreference.getExtras();
|
||||
populateMagnificationGesturesPreferenceExtras(extras, getContext());
|
||||
extras.putBoolean(AccessibilitySettings.EXTRA_LAUNCHED_FROM_SUW, mLaunchedFromSuw);
|
||||
}
|
||||
|
||||
private void handleMagnificationNavbarPreferenceScreenClick() {
|
||||
Bundle extras = mMagnificationNavbarPreference.getExtras();
|
||||
extras.putString(AccessibilitySettings.EXTRA_PREFERENCE_KEY,
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED);
|
||||
extras.putString(AccessibilitySettings.EXTRA_TITLE, getString(
|
||||
R.string.accessibility_screen_magnification_navbar_title));
|
||||
extras.putInt(AccessibilitySettings.EXTRA_TITLE_RES,
|
||||
R.string.accessibility_screen_magnification_navbar_title);
|
||||
extras.putCharSequence(AccessibilitySettings.EXTRA_SUMMARY,
|
||||
getActivity().getResources().getText(
|
||||
R.string.accessibility_screen_magnification_navbar_summary));
|
||||
extras.putBoolean(AccessibilitySettings.EXTRA_CHECKED,
|
||||
Settings.Secure.getInt(getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, 0)
|
||||
== 1);
|
||||
extras.putBoolean(AccessibilitySettings.EXTRA_LAUNCHED_FROM_SUW, mLaunchedFromSuw);
|
||||
}
|
||||
|
||||
static CharSequence getConfigurationWarningStringForSecureSettingsKey(String key,
|
||||
Context context) {
|
||||
if (!Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED.equals(key)) {
|
||||
@@ -187,22 +131,6 @@ public final class MagnificationPreferenceFragment extends SettingsPreferenceFra
|
||||
return null;
|
||||
}
|
||||
|
||||
static void populateMagnificationGesturesPreferenceExtras(Bundle extras, Context context) {
|
||||
extras.putString(AccessibilitySettings.EXTRA_PREFERENCE_KEY,
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED);
|
||||
extras.putString(AccessibilitySettings.EXTRA_TITLE, context.getString(
|
||||
R.string.accessibility_screen_magnification_gestures_title));
|
||||
extras.putInt(AccessibilitySettings.EXTRA_TITLE_RES,
|
||||
R.string.accessibility_screen_magnification_gestures_title);
|
||||
extras.putCharSequence(AccessibilitySettings.EXTRA_SUMMARY, context.getResources().getText(
|
||||
R.string.accessibility_screen_magnification_summary));
|
||||
extras.putBoolean(AccessibilitySettings.EXTRA_CHECKED,
|
||||
Settings.Secure.getInt(context.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 0) == 1);
|
||||
extras.putInt(AccessibilitySettings.EXTRA_VIDEO_RAW_RESOURCE_ID,
|
||||
R.raw.accessibility_screen_magnification);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if this fragment should be shown, {@code false} otherwise. This
|
||||
* fragment is shown in the case that more than one magnification mode is available.
|
||||
|
@@ -25,7 +25,6 @@ import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.Fragment;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
@@ -37,13 +36,11 @@ import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
@@ -58,19 +55,10 @@ public class RemoveAccountPreferenceController extends AbstractPreferenceControl
|
||||
private Account mAccount;
|
||||
private Fragment mParentFragment;
|
||||
private UserHandle mUserHandle;
|
||||
private DevicePolicyManagerWrapper mDpm;
|
||||
|
||||
public RemoveAccountPreferenceController(Context context, Fragment parent) {
|
||||
this(context, parent, new DevicePolicyManagerWrapper(
|
||||
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE)));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
RemoveAccountPreferenceController(Context context, Fragment parent,
|
||||
DevicePolicyManagerWrapper dpm) {
|
||||
super(context);
|
||||
mParentFragment = parent;
|
||||
mDpm = dpm;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -47,7 +47,6 @@ import com.android.settings.applications.manageapplications.ManageApplications;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
||||
@@ -75,7 +74,7 @@ public abstract class AppInfoBase extends SettingsPreferenceFragment
|
||||
protected String mPackageName;
|
||||
|
||||
protected IUsbManager mUsbManager;
|
||||
protected DevicePolicyManagerWrapper mDpm;
|
||||
protected DevicePolicyManager mDpm;
|
||||
protected UserManager mUserManager;
|
||||
protected PackageManager mPm;
|
||||
|
||||
@@ -94,8 +93,7 @@ public abstract class AppInfoBase extends SettingsPreferenceFragment
|
||||
.getApplicationFeatureProvider(activity);
|
||||
mState = ApplicationsState.getInstance(activity.getApplication());
|
||||
mSession = mState.newSession(this, getLifecycle());
|
||||
mDpm = new DevicePolicyManagerWrapper(
|
||||
(DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE));
|
||||
mDpm = (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
mUserManager = (UserManager) activity.getSystemService(Context.USER_SERVICE);
|
||||
mPm = activity.getPackageManager();
|
||||
IBinder b = ServiceManager.getService(Context.USB_SERVICE);
|
||||
@@ -176,6 +174,7 @@ public abstract class AppInfoBase extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
protected abstract boolean refreshUi();
|
||||
|
||||
protected abstract AlertDialog createDialog(int id, int errorCode);
|
||||
|
||||
@Override
|
||||
|
@@ -22,7 +22,6 @@ import android.os.Build;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settings.wrapper.IPackageManagerWrapper;
|
||||
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||
|
||||
@@ -34,11 +33,11 @@ public abstract class AppWithAdminGrantedPermissionsCounter extends AppCounter {
|
||||
|
||||
private final String[] mPermissions;
|
||||
private final IPackageManagerWrapper mPackageManagerService;
|
||||
private final DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
private final DevicePolicyManager mDevicePolicyManager;
|
||||
|
||||
public AppWithAdminGrantedPermissionsCounter(Context context, String[] permissions,
|
||||
PackageManagerWrapper packageManager, IPackageManagerWrapper packageManagerService,
|
||||
DevicePolicyManagerWrapper devicePolicyManager) {
|
||||
DevicePolicyManager devicePolicyManager) {
|
||||
super(context, packageManager);
|
||||
mPermissions = permissions;
|
||||
mPackageManagerService = packageManagerService;
|
||||
@@ -52,7 +51,7 @@ public abstract class AppWithAdminGrantedPermissionsCounter extends AppCounter {
|
||||
}
|
||||
|
||||
public static boolean includeInCount(String[] permissions,
|
||||
DevicePolicyManagerWrapper devicePolicyManager, PackageManagerWrapper packageManager,
|
||||
DevicePolicyManager devicePolicyManager, PackageManagerWrapper packageManager,
|
||||
IPackageManagerWrapper packageManagerService, ApplicationInfo info) {
|
||||
if (info.targetSdkVersion >= Build.VERSION_CODES.M) {
|
||||
// The app uses run-time permissions. Check whether one or more of the permissions were
|
||||
|
@@ -16,9 +16,10 @@
|
||||
|
||||
package com.android.settings.applications;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.os.UserManager;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
|
||||
import com.android.settings.wrapper.IPackageManagerWrapper;
|
||||
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||
|
||||
@@ -29,11 +30,11 @@ import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||
public abstract class AppWithAdminGrantedPermissionsLister extends AppLister {
|
||||
private final String[] mPermissions;
|
||||
private final IPackageManagerWrapper mPackageManagerService;
|
||||
private final DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
private final DevicePolicyManager mDevicePolicyManager;
|
||||
|
||||
public AppWithAdminGrantedPermissionsLister(String[] permissions,
|
||||
PackageManagerWrapper packageManager, IPackageManagerWrapper packageManagerService,
|
||||
DevicePolicyManagerWrapper devicePolicyManager, UserManager userManager) {
|
||||
DevicePolicyManager devicePolicyManager, UserManager userManager) {
|
||||
super(packageManager, userManager);
|
||||
mPermissions = permissions;
|
||||
mPackageManagerService = packageManagerService;
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.applications;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ComponentInfo;
|
||||
@@ -26,7 +27,6 @@ import android.os.RemoteException;
|
||||
import android.os.UserManager;
|
||||
import android.util.ArraySet;
|
||||
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settings.wrapper.IPackageManagerWrapper;
|
||||
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||
|
||||
@@ -39,11 +39,11 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
|
||||
private final Context mContext;
|
||||
private final PackageManagerWrapper mPm;
|
||||
private final IPackageManagerWrapper mPms;
|
||||
private final DevicePolicyManagerWrapper mDpm;
|
||||
private final DevicePolicyManager mDpm;
|
||||
private final UserManager mUm;
|
||||
|
||||
public ApplicationFeatureProviderImpl(Context context, PackageManagerWrapper pm,
|
||||
IPackageManagerWrapper pms, DevicePolicyManagerWrapper dpm) {
|
||||
IPackageManagerWrapper pms, DevicePolicyManager dpm) {
|
||||
mContext = context.getApplicationContext();
|
||||
mPm = pm;
|
||||
mPms = pms;
|
||||
@@ -150,7 +150,7 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
|
||||
CurrentUserAndManagedProfileAppWithAdminGrantedPermissionsCounter(Context context,
|
||||
String[] permissions, PackageManagerWrapper packageManager,
|
||||
IPackageManagerWrapper packageManagerService,
|
||||
DevicePolicyManagerWrapper devicePolicyManager, NumberOfAppsCallback callback) {
|
||||
DevicePolicyManager devicePolicyManager, NumberOfAppsCallback callback) {
|
||||
super(context, permissions, packageManager, packageManagerService, devicePolicyManager);
|
||||
mCallback = callback;
|
||||
}
|
||||
@@ -182,7 +182,7 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
|
||||
|
||||
CurrentUserAppWithAdminGrantedPermissionsLister(String[] permissions,
|
||||
PackageManagerWrapper packageManager, IPackageManagerWrapper packageManagerService,
|
||||
DevicePolicyManagerWrapper devicePolicyManager, UserManager userManager,
|
||||
DevicePolicyManager devicePolicyManager, UserManager userManager,
|
||||
ListOfAppsCallback callback) {
|
||||
super(permissions, packageManager, packageManagerService, devicePolicyManager,
|
||||
userManager);
|
||||
|
@@ -44,7 +44,6 @@ import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.ActionButtonPreference;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
||||
@@ -67,7 +66,7 @@ public class AppActionButtonPreferenceController extends BasePreferenceControlle
|
||||
private final ApplicationFeatureProvider mApplicationFeatureProvider;
|
||||
|
||||
private int mUserId;
|
||||
private DevicePolicyManagerWrapper mDpm;
|
||||
private DevicePolicyManager mDpm;
|
||||
private UserManager mUserManager;
|
||||
private PackageManager mPm;
|
||||
|
||||
@@ -112,8 +111,7 @@ public class AppActionButtonPreferenceController extends BasePreferenceControlle
|
||||
mPm = mContext.getPackageManager();
|
||||
}
|
||||
if (mDpm == null) {
|
||||
mDpm = new DevicePolicyManagerWrapper(
|
||||
(DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE));
|
||||
mDpm = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
}
|
||||
if (mUserManager == null) {
|
||||
mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||
|
@@ -55,7 +55,6 @@ import com.android.settings.applications.manageapplications.ManageApplications;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
@@ -122,7 +121,7 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
private int mUserId;
|
||||
private String mPackageName;
|
||||
|
||||
private DevicePolicyManagerWrapper mDpm;
|
||||
private DevicePolicyManager mDpm;
|
||||
private UserManager mUserManager;
|
||||
private PackageManager mPm;
|
||||
|
||||
@@ -198,8 +197,7 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
super.onCreate(icicle);
|
||||
mFinishing = false;
|
||||
final Activity activity = getActivity();
|
||||
mDpm = new DevicePolicyManagerWrapper(
|
||||
(DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE));
|
||||
mDpm = (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
mUserManager = (UserManager) activity.getSystemService(Context.USER_SERVICE);
|
||||
mPm = activity.getPackageManager();
|
||||
|
||||
|
@@ -109,7 +109,7 @@ public class AppMemoryPreferenceController extends BasePreferenceController
|
||||
}
|
||||
|
||||
return DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)
|
||||
? AVAILABLE : DISABLED_DEPENDENT_SETTING;
|
||||
? AVAILABLE : DISABLED_UNSUPPORTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -40,7 +40,6 @@ import com.android.settings.R;
|
||||
import com.android.settings.applications.AppInfoBase;
|
||||
import com.android.settings.notification.EmptyTextSettings;
|
||||
import com.android.settings.widget.AppPreference;
|
||||
import com.android.settings.wrapper.UserManagerWrapper;
|
||||
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||
|
||||
import java.text.Collator;
|
||||
@@ -88,7 +87,7 @@ public class PictureInPictureSettings extends EmptyTextSettings {
|
||||
|
||||
private Context mContext;
|
||||
private PackageManagerWrapper mPackageManager;
|
||||
private UserManagerWrapper mUserManager;
|
||||
private UserManager mUserManager;
|
||||
private IconDrawableFactory mIconDrawableFactory;
|
||||
|
||||
/**
|
||||
@@ -119,7 +118,7 @@ public class PictureInPictureSettings extends EmptyTextSettings {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
public PictureInPictureSettings(PackageManagerWrapper pm, UserManagerWrapper um) {
|
||||
public PictureInPictureSettings(PackageManagerWrapper pm, UserManager um) {
|
||||
mPackageManager = pm;
|
||||
mUserManager = um;
|
||||
}
|
||||
@@ -130,7 +129,7 @@ public class PictureInPictureSettings extends EmptyTextSettings {
|
||||
|
||||
mContext = getActivity();
|
||||
mPackageManager = new PackageManagerWrapper(mContext.getPackageManager());
|
||||
mUserManager = new UserManagerWrapper(mContext.getSystemService(UserManager.class));
|
||||
mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||
mIconDrawableFactory = IconDrawableFactory.newInstance(mContext);
|
||||
}
|
||||
|
||||
|
@@ -22,11 +22,10 @@ import android.hardware.usb.UsbManager;
|
||||
import android.hardware.usb.UsbPort;
|
||||
import android.hardware.usb.UsbPortStatus;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.wrapper.UserManagerWrapper;
|
||||
|
||||
/**
|
||||
* Provides access to underlying system USB functionality.
|
||||
*/
|
||||
@@ -50,17 +49,17 @@ public class UsbBackend {
|
||||
private UsbPortStatus mPortStatus;
|
||||
|
||||
public UsbBackend(Context context) {
|
||||
this(context, new UserManagerWrapper(UserManager.get(context)));
|
||||
this(context, (UserManager) context.getSystemService(Context.USER_SERVICE));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public UsbBackend(Context context, UserManagerWrapper userManagerWrapper) {
|
||||
public UsbBackend(Context context, UserManager userManager) {
|
||||
mUsbManager = context.getSystemService(UsbManager.class);
|
||||
|
||||
mFileTransferRestricted = userManagerWrapper.isUsbFileTransferRestricted();
|
||||
mFileTransferRestrictedBySystem = userManagerWrapper.isUsbFileTransferRestrictedBySystem();
|
||||
mTetheringRestricted = userManagerWrapper.isUsbTetheringRestricted();
|
||||
mTetheringRestrictedBySystem = userManagerWrapper.isUsbTetheringRestrictedBySystem();
|
||||
mFileTransferRestricted = isUsbFileTransferRestricted(userManager);
|
||||
mFileTransferRestrictedBySystem = isUsbFileTransferRestrictedBySystem(userManager);
|
||||
mTetheringRestricted = isUsbTetheringRestricted(userManager);
|
||||
mTetheringRestrictedBySystem = isUsbTetheringRestrictedBySystem(userManager);
|
||||
|
||||
mMidiSupported = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI);
|
||||
ConnectivityManager cm =
|
||||
@@ -172,6 +171,24 @@ public class UsbBackend {
|
||||
return Integer.parseInt(role);
|
||||
}
|
||||
|
||||
private static boolean isUsbFileTransferRestricted(UserManager userManager) {
|
||||
return userManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER);
|
||||
}
|
||||
|
||||
private static boolean isUsbTetheringRestricted(UserManager userManager) {
|
||||
return userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING);
|
||||
}
|
||||
|
||||
private static boolean isUsbFileTransferRestrictedBySystem(UserManager userManager) {
|
||||
return userManager.hasBaseUserRestriction(
|
||||
UserManager.DISALLOW_USB_FILE_TRANSFER, UserHandle.of(UserHandle.myUserId()));
|
||||
}
|
||||
|
||||
private static boolean isUsbTetheringRestrictedBySystem(UserManager userManager) {
|
||||
return userManager.hasBaseUserRestriction(
|
||||
UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.of(UserHandle.myUserId()));
|
||||
}
|
||||
|
||||
private boolean areFunctionDisallowed(long functions) {
|
||||
return (mFileTransferRestricted && ((functions & UsbManager.FUNCTION_MTP) != 0
|
||||
|| (functions & UsbManager.FUNCTION_PTP) != 0))
|
||||
|
@@ -22,7 +22,6 @@ import com.android.settings.search.ResultPayload;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
import com.android.settings.slices.SliceData;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -30,6 +29,10 @@ import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
/**
|
||||
* Abstract class to consolidate utility between preference controllers and act as an interface
|
||||
* for Slices. The abstract classes that inherit from this class will act as the direct interfaces
|
||||
@@ -39,6 +42,12 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
|
||||
|
||||
private static final String TAG = "SettingsPrefController";
|
||||
|
||||
/**
|
||||
* Denotes the availability of the Setting.
|
||||
* <p>
|
||||
* Used both explicitly and by the convenience methods {@link #isAvailable()} and
|
||||
* {@link #isSupported()}.
|
||||
*/
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({AVAILABLE, DISABLED_UNSUPPORTED, DISABLED_FOR_USER, DISABLED_DEPENDENT_SETTING,
|
||||
UNAVAILABLE_UNKNOWN})
|
||||
@@ -52,21 +61,42 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
|
||||
|
||||
/**
|
||||
* The setting is not supported by the device.
|
||||
* <p>
|
||||
* There is no guarantee that the setting page exists, and any links to the Setting should take
|
||||
* you to the home page of Settings.
|
||||
*/
|
||||
public static final int DISABLED_UNSUPPORTED = 1;
|
||||
|
||||
/**
|
||||
* The setting cannot be changed by the current user.
|
||||
* <p>
|
||||
* Links to the Setting should take you to the page of the Setting, even if it cannot be
|
||||
* changed.
|
||||
*/
|
||||
public static final int DISABLED_FOR_USER = 2;
|
||||
|
||||
/**
|
||||
* The setting has a dependency in the Settings App which is currently blocking access.
|
||||
* <p>
|
||||
* It must be possible for the Setting to be enabled by changing the configuration of the device
|
||||
* settings. That is, a setting that cannot be changed because of the state of another setting.
|
||||
* This should not be used for a setting that would be hidden from the UI entirely.
|
||||
* <p>
|
||||
* Correct use: Intensity of night display should be {@link #DISABLED_DEPENDENT_SETTING} when
|
||||
* night display is off.
|
||||
* Incorrect use: Mobile Data is {@link #DISABLED_DEPENDENT_SETTING} when there is no
|
||||
* data-enabled sim.
|
||||
* <p>
|
||||
* Links to the Setting should take you to the page of the Setting, even if it cannot be
|
||||
* changed.
|
||||
*/
|
||||
public static final int DISABLED_DEPENDENT_SETTING = 3;
|
||||
|
||||
/**
|
||||
* A catch-all case for internal errors and inexplicable unavailability.
|
||||
* <p>
|
||||
* There is no guarantee that the setting page exists, and any links to the Setting should take
|
||||
* you to the home page of Settings.
|
||||
*/
|
||||
public static final int UNAVAILABLE_UNKNOWN = 4;
|
||||
|
||||
@@ -134,9 +164,25 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
|
||||
return mPreferenceKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} when the controller can be changed on the device.
|
||||
*
|
||||
* <p>
|
||||
* Will return true for {@link #AVAILABLE} and {@link #DISABLED_DEPENDENT_SETTING}.
|
||||
* <p>
|
||||
* When the availability status returned by {@link #getAvailabilityStatus()} is
|
||||
* {@link #DISABLED_DEPENDENT_SETTING}, then the setting will be disabled by default in the
|
||||
* DashboardFragment, and it is up to the {@link BasePreferenceController} to enable the
|
||||
* preference at the right time.
|
||||
*
|
||||
* TODO (mfritze) Build a dependency mechanism to allow a controller to easily define the
|
||||
* dependent setting.
|
||||
*/
|
||||
@Override
|
||||
public final boolean isAvailable() {
|
||||
return getAvailabilityStatus() == AVAILABLE;
|
||||
final int availabilityStatus = getAvailabilityStatus();
|
||||
return (availabilityStatus == AVAILABLE) ||
|
||||
(availabilityStatus == DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,6 +196,21 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
|
||||
return getAvailabilityStatus() != DISABLED_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays preference in this controller.
|
||||
*/
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
if (getAvailabilityStatus() == DISABLED_DEPENDENT_SETTING) {
|
||||
// Disable preference if it depends on another setting.
|
||||
final Preference preference = screen.findPreference(getPreferenceKey());
|
||||
if (preference != null) {
|
||||
preference.setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the UI type supported by the controller.
|
||||
*/
|
||||
|
@@ -47,7 +47,6 @@ import com.android.settings.deviceinfo.storage.VolumeSizesLoader;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settings.wrapper.UserManagerWrapper;
|
||||
import com.android.settingslib.applications.StorageStatsSource;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.deviceinfo.PrivateStorageInfo;
|
||||
@@ -185,8 +184,7 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
mVolume, new StorageManagerVolumeProvider(sm));
|
||||
controllers.add(mPreferenceController);
|
||||
|
||||
UserManagerWrapper userManager =
|
||||
new UserManagerWrapper(context.getSystemService(UserManager.class));
|
||||
final UserManager userManager = context.getSystemService(UserManager.class);
|
||||
mSecondaryUsers = SecondaryUserController.getSecondaryUserControllers(context, userManager);
|
||||
controllers.addAll(mSecondaryUsers);
|
||||
|
||||
@@ -235,8 +233,7 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
public List<AbstractPreferenceController> createPreferenceControllers(
|
||||
Context context) {
|
||||
final StorageManager sm = context.getSystemService(StorageManager.class);
|
||||
final UserManagerWrapper userManager =
|
||||
new UserManagerWrapper(context.getSystemService(UserManager.class));
|
||||
final UserManager userManager = context.getSystemService(UserManager.class);
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new StorageSummaryDonutPreferenceController(context));
|
||||
controllers.add(new StorageItemPreferenceController(context, null /* host */,
|
||||
@@ -251,9 +248,8 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
@Override
|
||||
public Loader<SparseArray<StorageAsyncLoader.AppsStorageResult>> onCreateLoader(int id,
|
||||
Bundle args) {
|
||||
Context context = getContext();
|
||||
return new StorageAsyncLoader(context,
|
||||
new UserManagerWrapper(context.getSystemService(UserManager.class)),
|
||||
final Context context = getContext();
|
||||
return new StorageAsyncLoader(context, context.getSystemService(UserManager.class),
|
||||
mVolume.fsUuid,
|
||||
new StorageStatsSource(context),
|
||||
new PackageManagerWrapper(context.getPackageManager()));
|
||||
|
@@ -34,7 +34,6 @@ import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.deviceinfo.storage.StorageAsyncLoader;
|
||||
import com.android.settings.deviceinfo.storage.StorageAsyncLoader.AppsStorageResult;
|
||||
import com.android.settings.deviceinfo.storage.StorageItemPreferenceController;
|
||||
import com.android.settings.wrapper.UserManagerWrapper;
|
||||
import com.android.settingslib.applications.StorageStatsSource;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
|
||||
@@ -114,9 +113,9 @@ public class StorageProfileFragment extends DashboardFragment
|
||||
|
||||
@Override
|
||||
public Loader<SparseArray<AppsStorageResult>> onCreateLoader(int id, Bundle args) {
|
||||
Context context = getContext();
|
||||
final Context context = getContext();
|
||||
return new StorageAsyncLoader(context,
|
||||
new UserManagerWrapper(context.getSystemService(UserManager.class)),
|
||||
context.getSystemService(UserManager.class),
|
||||
mVolume.fsUuid,
|
||||
new StorageStatsSource(context),
|
||||
new PackageManagerWrapper(context.getPackageManager()));
|
||||
|
@@ -19,6 +19,7 @@ package com.android.settings.deviceinfo.storage;
|
||||
import android.content.Context;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.UserManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
@@ -29,7 +30,6 @@ import android.util.SparseArray;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.deviceinfo.StorageItemPreference;
|
||||
import com.android.settings.wrapper.UserManagerWrapper;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -61,7 +61,7 @@ public class SecondaryUserController extends AbstractPreferenceController implem
|
||||
* @param userManager UserManagerWrapper for figuring out which controllers to add.
|
||||
*/
|
||||
public static List<AbstractPreferenceController> getSecondaryUserControllers(
|
||||
Context context, UserManagerWrapper userManager) {
|
||||
Context context, UserManager userManager) {
|
||||
List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
UserInfo primaryUser = userManager.getPrimaryUser();
|
||||
boolean addedUser = false;
|
||||
@@ -74,8 +74,7 @@ public class SecondaryUserController extends AbstractPreferenceController implem
|
||||
|
||||
if (info == null || Utils.isProfileOf(primaryUser, info)) {
|
||||
controllers.add(
|
||||
new UserProfileController(
|
||||
context, info, userManager, USER_PROFILE_INSERTION_LOCATION));
|
||||
new UserProfileController(context, info, USER_PROFILE_INSERTION_LOCATION));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@@ -26,11 +26,11 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.ArraySet;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.android.settings.wrapper.UserManagerWrapper;
|
||||
import com.android.settingslib.applications.StorageStatsSource;
|
||||
import com.android.settingslib.utils.AsyncLoader;
|
||||
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||
@@ -46,7 +46,7 @@ import java.util.List;
|
||||
*/
|
||||
public class StorageAsyncLoader
|
||||
extends AsyncLoader<SparseArray<StorageAsyncLoader.AppsStorageResult>> {
|
||||
private UserManagerWrapper mUserManager;
|
||||
private UserManager mUserManager;
|
||||
private static final String TAG = "StorageAsyncLoader";
|
||||
|
||||
private String mUuid;
|
||||
@@ -54,7 +54,7 @@ public class StorageAsyncLoader
|
||||
private PackageManagerWrapper mPackageManager;
|
||||
private ArraySet<String> mSeenPackages;
|
||||
|
||||
public StorageAsyncLoader(Context context, UserManagerWrapper userManager,
|
||||
public StorageAsyncLoader(Context context, UserManager userManager,
|
||||
String uuid, StorageStatsSource source, PackageManagerWrapper pm) {
|
||||
super(context);
|
||||
mUserManager = userManager;
|
||||
|
@@ -32,7 +32,6 @@ import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.deviceinfo.StorageItemPreference;
|
||||
import com.android.settings.deviceinfo.StorageProfileFragment;
|
||||
import com.android.settings.wrapper.UserManagerWrapper;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
/**
|
||||
@@ -44,16 +43,13 @@ public class UserProfileController extends AbstractPreferenceController implemen
|
||||
UserIconLoader.UserIconHandler {
|
||||
private static final String PREFERENCE_KEY_BASE = "pref_profile_";
|
||||
private StorageItemPreference mStoragePreference;
|
||||
private UserManagerWrapper mUserManager;
|
||||
private UserInfo mUser;
|
||||
private long mTotalSizeBytes;
|
||||
private final int mPreferenceOrder;
|
||||
|
||||
public UserProfileController(
|
||||
Context context, UserInfo info, UserManagerWrapper userManager, int preferenceOrder) {
|
||||
public UserProfileController(Context context, UserInfo info, int preferenceOrder) {
|
||||
super(context);
|
||||
mUser = Preconditions.checkNotNull(info);
|
||||
mUserManager = userManager;
|
||||
mPreferenceOrder = preferenceOrder;
|
||||
}
|
||||
|
||||
|
@@ -15,6 +15,7 @@ package com.android.settings.display;
|
||||
|
||||
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
@@ -25,7 +26,6 @@ import android.util.Log;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TimeoutListPreference;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
@@ -61,7 +61,8 @@ public class TimeoutPreferenceController extends AbstractPreferenceController im
|
||||
final long currentTimeout = Settings.System.getLong(mContext.getContentResolver(),
|
||||
SCREEN_OFF_TIMEOUT, FALLBACK_SCREEN_TIMEOUT_VALUE);
|
||||
timeoutListPreference.setValue(String.valueOf(currentTimeout));
|
||||
final DevicePolicyManagerWrapper dpm = DevicePolicyManagerWrapper.from(mContext);
|
||||
final DevicePolicyManager dpm =
|
||||
(DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
if (dpm != null) {
|
||||
final RestrictedLockUtils.EnforcedAdmin admin =
|
||||
RestrictedLockUtils.checkIfMaximumTimeToLockIsSet(mContext);
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -32,7 +33,6 @@ import android.view.View;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.vpn2.VpnUtils;
|
||||
import com.android.settings.wrapper.ConnectivityManagerWrapper;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||
|
||||
import java.util.Date;
|
||||
@@ -41,7 +41,7 @@ import java.util.List;
|
||||
public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFeatureProvider {
|
||||
|
||||
private final Context mContext;
|
||||
private final DevicePolicyManagerWrapper mDpm;
|
||||
private final DevicePolicyManager mDpm;
|
||||
private final PackageManagerWrapper mPm;
|
||||
private final UserManager mUm;
|
||||
private final ConnectivityManagerWrapper mCm;
|
||||
@@ -49,7 +49,7 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
|
||||
|
||||
private static final int MY_USER_ID = UserHandle.myUserId();
|
||||
|
||||
public EnterprisePrivacyFeatureProviderImpl(Context context, DevicePolicyManagerWrapper dpm,
|
||||
public EnterprisePrivacyFeatureProviderImpl(Context context, DevicePolicyManager dpm,
|
||||
PackageManagerWrapper pm, UserManager um, ConnectivityManagerWrapper cm,
|
||||
Resources resources) {
|
||||
mContext = context.getApplicationContext();
|
||||
|
@@ -54,7 +54,6 @@ import com.android.settings.fuelgauge.anomaly.AnomalyUtils;
|
||||
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
@@ -116,7 +115,7 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
|
||||
private AppButtonsPreferenceController mAppButtonsPreferenceController;
|
||||
private BackgroundActivityPreferenceController mBackgroundActivityPreferenceController;
|
||||
|
||||
private DevicePolicyManagerWrapper mDpm;
|
||||
private DevicePolicyManager mDpm;
|
||||
private UserManager mUserManager;
|
||||
private PackageManager mPackageManager;
|
||||
private List<Anomaly> mAnomalies;
|
||||
@@ -167,7 +166,8 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
|
||||
.launch();
|
||||
}
|
||||
|
||||
private static @UserIdInt int getUserIdToLaunchAdvancePowerUsageDetail(BatterySipper bs) {
|
||||
private static @UserIdInt
|
||||
int getUserIdToLaunchAdvancePowerUsageDetail(BatterySipper bs) {
|
||||
if (bs.drainType == BatterySipper.DrainType.USER) {
|
||||
return ActivityManager.getCurrentUser();
|
||||
}
|
||||
@@ -206,8 +206,7 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
|
||||
super.onAttach(activity);
|
||||
|
||||
mState = ApplicationsState.getInstance(getActivity().getApplication());
|
||||
mDpm = new DevicePolicyManagerWrapper(
|
||||
(DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE));
|
||||
mDpm = (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
mUserManager = (UserManager) activity.getSystemService(Context.USER_SERVICE);
|
||||
mPackageManager = activity.getPackageManager();
|
||||
mBatteryUtils = BatteryUtils.getInstance(getContext());
|
||||
|
@@ -19,6 +19,7 @@ package com.android.settings.fuelgauge;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.Fragment;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
@@ -50,7 +51,6 @@ import com.android.settings.Utils;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.ActionButtonPreference;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
@@ -102,7 +102,7 @@ public class AppButtonsPreferenceController extends AbstractPreferenceController
|
||||
private final int mRequestRemoveDeviceAdmin;
|
||||
|
||||
private ApplicationsState.Session mSession;
|
||||
private DevicePolicyManagerWrapper mDpm;
|
||||
private DevicePolicyManager mDpm;
|
||||
private UserManager mUserManager;
|
||||
private PackageManager mPm;
|
||||
private SettingsActivity mActivity;
|
||||
@@ -118,7 +118,7 @@ public class AppButtonsPreferenceController extends AbstractPreferenceController
|
||||
|
||||
public AppButtonsPreferenceController(SettingsActivity activity, Fragment fragment,
|
||||
Lifecycle lifecycle, String packageName, ApplicationsState state,
|
||||
DevicePolicyManagerWrapper dpm, UserManager userManager,
|
||||
DevicePolicyManager dpm, UserManager userManager,
|
||||
PackageManager packageManager, int requestUninstall, int requestRemoveDeviceAdmin) {
|
||||
super(activity);
|
||||
|
||||
|
@@ -30,7 +30,6 @@ import com.android.settings.fuelgauge.batterytip.BatteryTipDialogFragment;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
|
||||
@@ -48,7 +47,7 @@ public class BackgroundActivityPreferenceController extends AbstractPreferenceCo
|
||||
private final UserManager mUserManager;
|
||||
private final int mUid;
|
||||
@VisibleForTesting
|
||||
DevicePolicyManagerWrapper mDpm;
|
||||
DevicePolicyManager mDpm;
|
||||
@VisibleForTesting
|
||||
BatteryUtils mBatteryUtils;
|
||||
private InstrumentedPreferenceFragment mFragment;
|
||||
@@ -66,8 +65,7 @@ public class BackgroundActivityPreferenceController extends AbstractPreferenceCo
|
||||
super(context);
|
||||
mPowerWhitelistBackend = backend;
|
||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
mDpm = new DevicePolicyManagerWrapper(
|
||||
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE));
|
||||
mDpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
|
||||
mUid = uid;
|
||||
mFragment = fragment;
|
||||
|
@@ -42,12 +42,17 @@ public class AnomalyCleanupJobService extends JobService {
|
||||
|
||||
final ComponentName component = new ComponentName(context, AnomalyCleanupJobService.class);
|
||||
final JobInfo.Builder jobBuilder =
|
||||
new JobInfo.Builder(R.id.job_anomaly_clean_up, component)
|
||||
new JobInfo.Builder(R.integer.job_anomaly_clean_up, component)
|
||||
.setPeriodic(CLEAN_UP_FREQUENCY_MS)
|
||||
.setRequiresDeviceIdle(true)
|
||||
.setRequiresCharging(true);
|
||||
.setRequiresCharging(true)
|
||||
.setPersisted(true);
|
||||
final JobInfo pending = jobScheduler.getPendingJob(R.integer.job_anomaly_clean_up);
|
||||
|
||||
if (jobScheduler.schedule(jobBuilder.build()) != JobScheduler.RESULT_SUCCESS) {
|
||||
// Don't schedule it if it already exists, to make sure it runs periodically even after
|
||||
// reboot
|
||||
if (pending == null && jobScheduler.schedule(jobBuilder.build())
|
||||
!= JobScheduler.RESULT_SUCCESS) {
|
||||
Log.i(TAG, "Anomaly clean up job service schedule failed.");
|
||||
}
|
||||
}
|
||||
|
@@ -52,12 +52,17 @@ public class AnomalyConfigJobService extends JobService {
|
||||
|
||||
final ComponentName component = new ComponentName(context, AnomalyConfigJobService.class);
|
||||
final JobInfo.Builder jobBuilder =
|
||||
new JobInfo.Builder(R.id.job_anomaly_config_update, component)
|
||||
new JobInfo.Builder(R.integer.job_anomaly_config_update, component)
|
||||
.setPeriodic(CONFIG_UPDATE_FREQUENCY_MS)
|
||||
.setRequiresDeviceIdle(true)
|
||||
.setRequiresCharging(true);
|
||||
.setRequiresCharging(true)
|
||||
.setPersisted(true);
|
||||
final JobInfo pending = jobScheduler.getPendingJob(R.integer.job_anomaly_config_update);
|
||||
|
||||
if (jobScheduler.schedule(jobBuilder.build()) != JobScheduler.RESULT_SUCCESS) {
|
||||
// Don't schedule it if it already exists, to make sure it runs periodically even after
|
||||
// reboot
|
||||
if (pending == null && jobScheduler.schedule(jobBuilder.build())
|
||||
!= JobScheduler.RESULT_SUCCESS) {
|
||||
Log.i(TAG, "Anomaly config update job service schedule failed.");
|
||||
}
|
||||
}
|
||||
|
@@ -70,7 +70,7 @@ public class AnomalyDetectionJobService extends JobService {
|
||||
final ComponentName component = new ComponentName(context,
|
||||
AnomalyDetectionJobService.class);
|
||||
final JobInfo.Builder jobBuilder =
|
||||
new JobInfo.Builder(R.id.job_anomaly_detection, component)
|
||||
new JobInfo.Builder(R.integer.job_anomaly_detection, component)
|
||||
.setOverrideDeadline(MAX_DELAY_MS);
|
||||
|
||||
if (jobScheduler.enqueue(jobBuilder.build(), new JobWorkItem(intent))
|
||||
|
@@ -49,10 +49,8 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
||||
|
||||
private static final String TAG = "NetworkDashboardFrag";
|
||||
private static final int MENU_NETWORK_RESET = Menu.FIRST;
|
||||
private static final int MENU_PRIVATE_DNS = Menu.FIRST + 1;
|
||||
|
||||
private NetworkResetActionMenuController mNetworkResetController;
|
||||
private PrivateDnsMenuController mPrivateDnsMenuController;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
@@ -73,8 +71,6 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
mNetworkResetController = new NetworkResetActionMenuController(context, MENU_NETWORK_RESET);
|
||||
mPrivateDnsMenuController = new PrivateDnsMenuController(getFragmentManager(),
|
||||
MENU_PRIVATE_DNS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,7 +82,6 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
mNetworkResetController.buildMenuItem(menu);
|
||||
mPrivateDnsMenuController.buildMenuItem(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,6 +104,8 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
||||
new MobileNetworkPreferenceController(context);
|
||||
final VpnPreferenceController vpnPreferenceController =
|
||||
new VpnPreferenceController(context);
|
||||
final PrivateDnsPreferenceController privateDnsPreferenceController =
|
||||
new PrivateDnsPreferenceController(context);
|
||||
|
||||
if (lifecycle != null) {
|
||||
lifecycle.addObserver(airplaneModePreferenceController);
|
||||
@@ -116,6 +113,7 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
||||
lifecycle.addObserver(wifiPreferenceController);
|
||||
lifecycle.addObserver(mobileNetworkPreferenceController);
|
||||
lifecycle.addObserver(vpnPreferenceController);
|
||||
lifecycle.addObserver(privateDnsPreferenceController);
|
||||
}
|
||||
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
@@ -126,6 +124,7 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
||||
controllers.add(new ProxyPreferenceController(context));
|
||||
controllers.add(mobilePlanPreferenceController);
|
||||
controllers.add(wifiPreferenceController);
|
||||
controllers.add(privateDnsPreferenceController);
|
||||
return controllers;
|
||||
}
|
||||
|
||||
|
@@ -20,19 +20,18 @@ import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OPPORTUNISTIC;
|
||||
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.LayoutInflater;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
@@ -41,8 +40,9 @@ import android.widget.TextView;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.utils.AnnotationSpan;
|
||||
import com.android.settingslib.CustomDialogPreference;
|
||||
import com.android.settingslib.HelpUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -51,7 +51,7 @@ import java.util.Map;
|
||||
/**
|
||||
* Dialog to set the private dns
|
||||
*/
|
||||
public class PrivateDnsModeDialogFragment extends InstrumentedDialogFragment implements
|
||||
public class PrivateDnsModeDialogPreference extends CustomDialogPreference implements
|
||||
DialogInterface.OnClickListener, RadioGroup.OnCheckedChangeListener, TextWatcher {
|
||||
|
||||
public static final String ANNOTATION_URL = "url";
|
||||
@@ -77,41 +77,44 @@ public class PrivateDnsModeDialogFragment extends InstrumentedDialogFragment imp
|
||||
@VisibleForTesting
|
||||
RadioGroup mRadioGroup;
|
||||
@VisibleForTesting
|
||||
Button mSaveButton;
|
||||
@VisibleForTesting
|
||||
String mMode;
|
||||
|
||||
public static void show(FragmentManager fragmentManager) {
|
||||
if (fragmentManager.findFragmentByTag(TAG) == null) {
|
||||
final PrivateDnsModeDialogFragment fragment = new PrivateDnsModeDialogFragment();
|
||||
fragment.show(fragmentManager, TAG);
|
||||
public PrivateDnsModeDialogPreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public PrivateDnsModeDialogPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public PrivateDnsModeDialogPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public PrivateDnsModeDialogPreference(Context context, AttributeSet attrs, int defStyleAttr,
|
||||
int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
private final AnnotationSpan.LinkInfo mUrlLinkInfo = new AnnotationSpan.LinkInfo(
|
||||
ANNOTATION_URL, (widget) -> {
|
||||
final Context context = widget.getContext();
|
||||
final Intent intent = HelpUtils.getHelpIntent(context,
|
||||
context.getString(R.string.help_uri_private_dns),
|
||||
context.getClass().getName());
|
||||
if (intent != null) {
|
||||
try {
|
||||
widget.startActivityForResult(intent, 0);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Log.w(TAG, "Activity was not found for intent, " + intent.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
protected void onBindDialogView(View view) {
|
||||
final Context context = getContext();
|
||||
|
||||
final AlertDialog dialog = new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.select_private_dns_configuration_title)
|
||||
.setView(buildPrivateDnsView(context))
|
||||
.setPositiveButton(R.string.save, this)
|
||||
.setNegativeButton(R.string.dlg_cancel, null)
|
||||
.create();
|
||||
|
||||
dialog.setOnShowListener(dialogInterface -> {
|
||||
mSaveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
||||
updateDialogInfo();
|
||||
});
|
||||
return dialog;
|
||||
}
|
||||
|
||||
private View buildPrivateDnsView(final Context context) {
|
||||
final ContentResolver contentResolver = context.getContentResolver();
|
||||
mMode = Settings.Global.getString(contentResolver, MODE_KEY);
|
||||
final View view = LayoutInflater.from(context).inflate(R.layout.private_dns_mode_dialog,
|
||||
null);
|
||||
|
||||
mEditText = view.findViewById(R.id.private_dns_mode_provider_hostname);
|
||||
mEditText.addTextChangedListener(this);
|
||||
mEditText.setText(Settings.Global.getString(contentResolver, HOSTNAME_KEY));
|
||||
@@ -131,26 +134,20 @@ public class PrivateDnsModeDialogFragment extends InstrumentedDialogFragment imp
|
||||
helpTextView.setText(AnnotationSpan.linkify(
|
||||
context.getText(R.string.private_dns_help_message), linkInfo));
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
final Context context = getContext();
|
||||
if (mMode.equals(PRIVATE_DNS_MODE_PROVIDER_HOSTNAME)) {
|
||||
// Only clickable if hostname is valid, so we could save it safely
|
||||
Settings.Global.putString(getContext().getContentResolver(), HOSTNAME_KEY,
|
||||
Settings.Global.putString(context.getContentResolver(), HOSTNAME_KEY,
|
||||
mEditText.getText().toString());
|
||||
}
|
||||
|
||||
mMetricsFeatureProvider.action(getContext(),
|
||||
FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context,
|
||||
MetricsProto.MetricsEvent.ACTION_PRIVATE_DNS_MODE, mMode);
|
||||
Settings.Global.putString(getContext().getContentResolver(), MODE_KEY, mMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.DIALOG_PRIVATE_DNS;
|
||||
Settings.Global.putString(context.getContentResolver(), MODE_KEY, mMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,9 +176,7 @@ public class PrivateDnsModeDialogFragment extends InstrumentedDialogFragment imp
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (mSaveButton != null) {
|
||||
mSaveButton.setEnabled(isWeaklyValidatedHostname(mEditText.getText().toString()));
|
||||
}
|
||||
updateDialogInfo();
|
||||
}
|
||||
|
||||
private boolean isWeaklyValidatedHostname(String hostname) {
|
||||
@@ -193,17 +188,24 @@ public class PrivateDnsModeDialogFragment extends InstrumentedDialogFragment imp
|
||||
return hostname.matches(WEAK_HOSTNAME_REGEX);
|
||||
}
|
||||
|
||||
private Button getSaveButton() {
|
||||
final AlertDialog dialog = (AlertDialog) getDialog();
|
||||
if (dialog == null) {
|
||||
return null;
|
||||
}
|
||||
return dialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
||||
}
|
||||
|
||||
private void updateDialogInfo() {
|
||||
final boolean modeProvider = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME.equals(mMode);
|
||||
if (mEditText != null) {
|
||||
mEditText.setEnabled(modeProvider);
|
||||
}
|
||||
if (mSaveButton != null) {
|
||||
mSaveButton.setEnabled(
|
||||
modeProvider
|
||||
final Button saveButton = getSaveButton();
|
||||
if (saveButton != null) {
|
||||
saveButton.setEnabled(modeProvider
|
||||
? isWeaklyValidatedHostname(mEditText.getText().toString())
|
||||
: true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -16,29 +16,28 @@
|
||||
|
||||
package com.android.settings.network;
|
||||
|
||||
import android.app.FragmentManager;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
|
||||
public class PrivateDnsMenuController {
|
||||
private final FragmentManager mFragmentManager;
|
||||
private final int mMenuId;
|
||||
public class PrivateDnsPreferenceController extends BasePreferenceController
|
||||
implements PreferenceControllerMixin, LifecycleObserver {
|
||||
private static final String KEY_PRIVATE_DNS_SETTINGS = "private_dns_settings";
|
||||
|
||||
public PrivateDnsMenuController(FragmentManager fragmentManager, int menuId) {
|
||||
mFragmentManager = fragmentManager;
|
||||
mMenuId = menuId;
|
||||
public PrivateDnsPreferenceController(Context context) {
|
||||
super(context, KEY_PRIVATE_DNS_SETTINGS);
|
||||
}
|
||||
|
||||
public void buildMenuItem(Menu menu) {
|
||||
if (menu != null) {
|
||||
MenuItem item = menu.add(0 /* groupId */, mMenuId, 0 /* order */,
|
||||
R.string.select_private_dns_configuration_title);
|
||||
item.setOnMenuItemClickListener(target -> {
|
||||
PrivateDnsModeDialogFragment.show(mFragmentManager);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_PRIVATE_DNS_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
}
|
@@ -180,13 +180,11 @@ public class VpnPreferenceController extends AbstractPreferenceController
|
||||
mNetworkCallback = new ConnectivityManager.NetworkCallback() {
|
||||
@Override
|
||||
public void onAvailable(Network network) {
|
||||
Log.d(TAG, "onAvailable " + network.netId);
|
||||
updateSummary();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLost(Network network) {
|
||||
Log.d(TAG, "onLost " + network.netId);
|
||||
updateSummary();
|
||||
}
|
||||
};
|
||||
|
@@ -52,7 +52,6 @@ import com.android.settings.slices.SlicesFeatureProviderImpl;
|
||||
import com.android.settings.users.UserFeatureProvider;
|
||||
import com.android.settings.users.UserFeatureProviderImpl;
|
||||
import com.android.settings.wrapper.ConnectivityManagerWrapper;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settings.wrapper.IPackageManagerWrapper;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||
@@ -114,8 +113,8 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
||||
mApplicationFeatureProvider = new ApplicationFeatureProviderImpl(context,
|
||||
new PackageManagerWrapper(context.getPackageManager()),
|
||||
new IPackageManagerWrapper(AppGlobals.getPackageManager()),
|
||||
new DevicePolicyManagerWrapper((DevicePolicyManager) context
|
||||
.getSystemService(Context.DEVICE_POLICY_SERVICE)));
|
||||
(DevicePolicyManager) context
|
||||
.getSystemService(Context.DEVICE_POLICY_SERVICE));
|
||||
}
|
||||
return mApplicationFeatureProvider;
|
||||
}
|
||||
@@ -132,8 +131,7 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
||||
public EnterprisePrivacyFeatureProvider getEnterprisePrivacyFeatureProvider(Context context) {
|
||||
if (mEnterprisePrivacyFeatureProvider == null) {
|
||||
mEnterprisePrivacyFeatureProvider = new EnterprisePrivacyFeatureProviderImpl(context,
|
||||
new DevicePolicyManagerWrapper((DevicePolicyManager) context
|
||||
.getSystemService(Context.DEVICE_POLICY_SERVICE)),
|
||||
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE),
|
||||
new PackageManagerWrapper(context.getPackageManager()),
|
||||
UserManager.get(context),
|
||||
new ConnectivityManagerWrapper((ConnectivityManager) context
|
||||
|
@@ -32,7 +32,6 @@ import com.android.settings.TimeoutListPreference;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.security.trustagent.TrustAgentManager;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
@@ -44,14 +43,14 @@ public class LockAfterTimeoutPreferenceController extends AbstractPreferenceCont
|
||||
private final int mUserId;
|
||||
private final LockPatternUtils mLockPatternUtils;
|
||||
private final TrustAgentManager mTrustAgentManager;
|
||||
private final DevicePolicyManagerWrapper mDPM;
|
||||
private final DevicePolicyManager mDPM;
|
||||
|
||||
public LockAfterTimeoutPreferenceController(Context context, int userId,
|
||||
LockPatternUtils lockPatternUtils) {
|
||||
super(context);
|
||||
mUserId = userId;
|
||||
mLockPatternUtils = lockPatternUtils;
|
||||
mDPM = DevicePolicyManagerWrapper.from(context);
|
||||
mDPM = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
mTrustAgentManager = FeatureFactory.getFactory(context)
|
||||
.getSecurityFeatureProvider().getTrustAgentManager();
|
||||
}
|
||||
|
@@ -27,7 +27,6 @@ import android.support.annotation.VisibleForTesting;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.wrapper.WallpaperManagerWrapper;
|
||||
|
||||
public class WallpaperSuggestionActivity extends Activity {
|
||||
|
||||
@@ -61,9 +60,16 @@ public class WallpaperSuggestionActivity extends Activity {
|
||||
|
||||
@VisibleForTesting
|
||||
public static boolean isSuggestionComplete(Context context) {
|
||||
final WallpaperManagerWrapper manager = new WallpaperManagerWrapper(context);
|
||||
return manager.isWallpaperServiceEnabled() ? manager.getWallpaperId(
|
||||
WallpaperManager.FLAG_SYSTEM) > 0 : false;
|
||||
if (!isWallpaperServiceEnabled(context)) {
|
||||
return true;
|
||||
}
|
||||
final WallpaperManager manager = (WallpaperManager) context.getSystemService(
|
||||
WALLPAPER_SERVICE);
|
||||
return manager.getWallpaperId(WallpaperManager.FLAG_SYSTEM) > 0;
|
||||
}
|
||||
|
||||
private static boolean isWallpaperServiceEnabled(Context context) {
|
||||
return context.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_enableWallpaperService);
|
||||
}
|
||||
}
|
||||
|
@@ -43,7 +43,7 @@ public class PreferenceCategoryController extends BasePreferenceController {
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (mChildren == null || mChildren.isEmpty()) {
|
||||
return DISABLED_DEPENDENT_SETTING;
|
||||
return DISABLED_UNSUPPORTED;
|
||||
}
|
||||
// Category is available if any child is available
|
||||
for (AbstractPreferenceController controller : mChildren) {
|
||||
@@ -51,7 +51,7 @@ public class PreferenceCategoryController extends BasePreferenceController {
|
||||
return AVAILABLE;
|
||||
}
|
||||
}
|
||||
return DISABLED_DEPENDENT_SETTING;
|
||||
return DISABLED_UNSUPPORTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
@@ -25,7 +26,6 @@ import android.net.wifi.WifiConfiguration;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||
|
||||
public class WifiUtils {
|
||||
@@ -69,7 +69,8 @@ public class WifiUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
final DevicePolicyManagerWrapper dpm = DevicePolicyManagerWrapper.from(context);
|
||||
final DevicePolicyManager dpm =
|
||||
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
final PackageManagerWrapper pm = new PackageManagerWrapper(context.getPackageManager());
|
||||
|
||||
// Check if device has DPM capability. If it has and dpm is still null, then we
|
||||
|
@@ -1,229 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wrapper;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class replicates a subset of the android.app.admin.DevicePolicyManager (DPM). The
|
||||
* class exists so that we can use a thin wrapper around the DPM in production code and a mock
|
||||
* in tests. We cannot directly mock or shadow the DPM, because some of the methods we rely on are
|
||||
* newer than the API version supported by Robolectric.
|
||||
*/
|
||||
public class DevicePolicyManagerWrapper {
|
||||
private final DevicePolicyManager mDpm;
|
||||
|
||||
public DevicePolicyManagerWrapper(DevicePolicyManager dpm) {
|
||||
mDpm = dpm;
|
||||
}
|
||||
|
||||
public static @Nullable DevicePolicyManagerWrapper from(Context context) {
|
||||
DevicePolicyManager dpm =
|
||||
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
return dpm == null ? null : new DevicePolicyManagerWrapper(dpm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getActiveAdminsAsUser()}.
|
||||
*
|
||||
* @see DevicePolicyManager#getActiveAdminsAsUser
|
||||
*/
|
||||
public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
|
||||
return mDpm.getActiveAdminsAsUser(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getMaximumFailedPasswordsForWipe()}.
|
||||
*
|
||||
* @see DevicePolicyManager#getMaximumFailedPasswordsForWipe
|
||||
*/
|
||||
public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
|
||||
return mDpm.getMaximumFailedPasswordsForWipe(admin, userHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getDeviceOwnerComponentOnCallingUser()}.
|
||||
*
|
||||
* @see DevicePolicyManager#getDeviceOwnerComponentOnCallingUser
|
||||
*/
|
||||
public ComponentName getDeviceOwnerComponentOnCallingUser() {
|
||||
return mDpm.getDeviceOwnerComponentOnCallingUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getDeviceOwnerComponentOnAnyUser()}.
|
||||
*
|
||||
* @see DevicePolicyManager#getDeviceOwnerComponentOnAnyUser
|
||||
*/
|
||||
public ComponentName getDeviceOwnerComponentOnAnyUser() {
|
||||
return mDpm.getDeviceOwnerComponentOnAnyUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getProfileOwnerAsUser()}.
|
||||
*
|
||||
* @see DevicePolicyManager#getProfileOwnerAsUser
|
||||
*/
|
||||
public @Nullable ComponentName getProfileOwnerAsUser(final int userId) {
|
||||
return mDpm.getProfileOwnerAsUser(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getDeviceOwnerNameOnAnyUser()}.
|
||||
*
|
||||
* @see DevicePolicyManager#getDeviceOwnerNameOnAnyUser
|
||||
*/
|
||||
public CharSequence getDeviceOwnerOrganizationName() {
|
||||
return mDpm.getDeviceOwnerOrganizationName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getPermissionGrantState()}.
|
||||
*
|
||||
* @see DevicePolicyManager#getPermissionGrantState
|
||||
*/
|
||||
public int getPermissionGrantState(@Nullable ComponentName admin, String packageName,
|
||||
String permission) {
|
||||
return mDpm.getPermissionGrantState(admin, packageName, permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.isSecurityLoggingEnabled()}.
|
||||
*
|
||||
* @see DevicePolicyManager#isSecurityLoggingEnabled
|
||||
*/
|
||||
public boolean isSecurityLoggingEnabled(@Nullable ComponentName admin) {
|
||||
return mDpm.isSecurityLoggingEnabled(admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.isNetworkLoggingEnabled()}.
|
||||
*
|
||||
* @see DevicePolicyManager#isNetworkLoggingEnabled
|
||||
*/
|
||||
public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
|
||||
return mDpm.isNetworkLoggingEnabled(admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getLastSecurityLogRetrievalTime()}.
|
||||
*
|
||||
* @see DevicePolicyManager#getLastSecurityLogRetrievalTime
|
||||
*/
|
||||
public long getLastSecurityLogRetrievalTime() {
|
||||
return mDpm.getLastSecurityLogRetrievalTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getLastBugReportRequestTime()}.
|
||||
*
|
||||
* @see DevicePolicyManager#getLastBugReportRequestTime
|
||||
*/
|
||||
public long getLastBugReportRequestTime() {
|
||||
return mDpm.getLastBugReportRequestTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getLastNetworkLogRetrievalTime()}.
|
||||
*
|
||||
* @see DevicePolicyManager#getLastNetworkLogRetrievalTime
|
||||
*/
|
||||
public long getLastNetworkLogRetrievalTime() {
|
||||
return mDpm.getLastNetworkLogRetrievalTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.isCurrentInputMethodSetByOwner()}.
|
||||
*
|
||||
* @see DevicePolicyManager#isCurrentInputMethodSetByOwner
|
||||
*/
|
||||
public boolean isCurrentInputMethodSetByOwner() {
|
||||
return mDpm.isCurrentInputMethodSetByOwner();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getOwnerInstalledCaCerts()}.
|
||||
*
|
||||
* @see DevicePolicyManager#getOwnerInstalledCaCerts
|
||||
*/
|
||||
public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) {
|
||||
return mDpm.getOwnerInstalledCaCerts(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.isDeviceOwnerAppOnAnyUser()}.
|
||||
*
|
||||
* @see DevicePolicyManager#isDeviceOwnerAppOnAnyUser
|
||||
*/
|
||||
public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
|
||||
return mDpm.isDeviceOwnerAppOnAnyUser(packageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.packageHasActiveAdmins()}.
|
||||
*
|
||||
* @see DevicePolicyManager#packageHasActiveAdmins
|
||||
*/
|
||||
public boolean packageHasActiveAdmins(String packageName) {
|
||||
return mDpm.packageHasActiveAdmins(packageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.isUninstallInQueue()}.
|
||||
*
|
||||
* @see DevicePolicyManager#isUninstallInQueue
|
||||
*/
|
||||
public boolean isUninstallInQueue(String packageName) {
|
||||
return mDpm.isUninstallInQueue(packageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.createAdminSupportIntent()}.
|
||||
*
|
||||
* @see DevicePolicyManager#createAdminSupportIntent(String)
|
||||
*/
|
||||
public Intent createAdminSupportIntent(@NonNull String restriction) {
|
||||
return mDpm.createAdminSupportIntent(restriction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager#getDeviceOwnerUserId()}.
|
||||
*
|
||||
* @see DevicePolicyManager#getDeviceOwnerUserId()
|
||||
*/
|
||||
public int getDeviceOwnerUserId() {
|
||||
return mDpm.getDeviceOwnerUserId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager#getMaximumTimeToLock()}.
|
||||
*
|
||||
* @see DevicePolicyManager#getMaximumTimeToLock(ComponentName, int)
|
||||
*/
|
||||
public long getMaximumTimeToLock(@Nullable ComponentName admin, @UserIdInt int userHandle) {
|
||||
return mDpm.getMaximumTimeToLock(admin, userHandle);
|
||||
}
|
||||
}
|
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wrapper;
|
||||
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class replicates a subset of the android.os.UserManager. The class
|
||||
* exists so that we can use a thin wrapper around the UserManager in production code and a mock in
|
||||
* tests. We cannot directly mock or shadow the UserManager, because some of the methods we rely on
|
||||
* are newer than the API version supported by Robolectric or are hidden.
|
||||
*/
|
||||
public class UserManagerWrapper {
|
||||
private UserManager mUserManager;
|
||||
|
||||
public UserManagerWrapper(UserManager userManager) {
|
||||
mUserManager = userManager;
|
||||
}
|
||||
|
||||
public UserInfo getPrimaryUser() {
|
||||
return mUserManager.getPrimaryUser();
|
||||
}
|
||||
|
||||
public List<UserInfo> getUsers() {
|
||||
return mUserManager.getUsers();
|
||||
}
|
||||
|
||||
public List<UserInfo> getProfiles(int userHandle) {
|
||||
return mUserManager.getProfiles(userHandle);
|
||||
}
|
||||
|
||||
public boolean isUsbFileTransferRestricted() {
|
||||
return mUserManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER);
|
||||
}
|
||||
|
||||
public boolean isUsbTetheringRestricted() {
|
||||
return mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING);
|
||||
}
|
||||
|
||||
public boolean isUsbFileTransferRestrictedBySystem() {
|
||||
return mUserManager.hasBaseUserRestriction(
|
||||
UserManager.DISALLOW_USB_FILE_TRANSFER, UserHandle.of(UserHandle.myUserId()));
|
||||
}
|
||||
|
||||
public boolean isUsbTetheringRestrictedBySystem() {
|
||||
return mUserManager.hasBaseUserRestriction(
|
||||
UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.of(UserHandle.myUserId()));
|
||||
}
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wrapper;
|
||||
|
||||
import android.app.WallpaperManager;
|
||||
import android.content.Context;
|
||||
|
||||
public class WallpaperManagerWrapper {
|
||||
|
||||
private final WallpaperManager mWallpaperManager;
|
||||
private final boolean mWallpaperServiceEnabled;
|
||||
|
||||
public WallpaperManagerWrapper(Context context) {
|
||||
mWallpaperServiceEnabled = context.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_enableWallpaperService);
|
||||
mWallpaperManager = mWallpaperServiceEnabled ? (WallpaperManager) context.getSystemService(
|
||||
Context.WALLPAPER_SERVICE) : null;
|
||||
}
|
||||
|
||||
public boolean isWallpaperServiceEnabled() {
|
||||
return mWallpaperServiceEnabled;
|
||||
}
|
||||
|
||||
public int getWallpaperId(int which) {
|
||||
if (!mWallpaperServiceEnabled) {
|
||||
throw new RuntimeException("This device does not have wallpaper service enabled.");
|
||||
}
|
||||
return mWallpaperManager.getWallpaperId(which);
|
||||
}
|
||||
}
|
@@ -16,27 +16,73 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.support.v14.preference.MultiSelectListPreference;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.EditTextPreference;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.settings.ApnEditor.ApnData;
|
||||
import com.android.settings.ApnEditor.InvalidTypeException;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class ApnEditorTest {
|
||||
|
||||
private static final Object[] APN_DATA = new Object[] {
|
||||
0, /* ID */
|
||||
"apn_name" /* apn name */,
|
||||
"apn.com" /* apn */,
|
||||
"" /* proxy */,
|
||||
"" /* port */,
|
||||
"" /* username */,
|
||||
"" /* server */,
|
||||
"" /* password */,
|
||||
"" /* MMSC */,
|
||||
"123" /* MCC */,
|
||||
"456" /* MNC */,
|
||||
"123456" /* operator numeric */,
|
||||
"" /* MMS proxy */,
|
||||
"" /* MMS port */,
|
||||
0 /* Authentication type */,
|
||||
"default,supl,ia" /* APN type */,
|
||||
"IPv6" /* APN protocol */,
|
||||
1 /* APN enable/disable */,
|
||||
0 /* Bearer */,
|
||||
0 /* Bearer BITMASK*/,
|
||||
"IPv4" /* APN roaming protocol */,
|
||||
"None" /* MVNO type */,
|
||||
"", /* MVNO value */
|
||||
};
|
||||
|
||||
private static final int CURSOR_INTEGER_INDEX = 0;
|
||||
private static final int CURSOR_STRING_INDEX = 1;
|
||||
|
||||
@@ -45,10 +91,331 @@ public class ApnEditorTest {
|
||||
@Mock
|
||||
private Cursor mCursor;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<Uri> mUriCaptor;
|
||||
|
||||
private ApnEditor mApnEditorUT;
|
||||
private Activity mActivity;
|
||||
private Resources mResources;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mActivity = spy(Robolectric.setupActivity(Activity.class));
|
||||
mResources = mActivity.getResources();
|
||||
mApnEditorUT = spy(new ApnEditor());
|
||||
|
||||
doReturn(mActivity).when(mApnEditorUT).getActivity();
|
||||
doReturn(mResources).when(mApnEditorUT).getResources();
|
||||
doNothing().when(mApnEditorUT).finish();
|
||||
doNothing().when(mApnEditorUT).showError();
|
||||
|
||||
setMockPreference(mActivity);
|
||||
mApnEditorUT.mApnData = new FakeApnData(APN_DATA);
|
||||
mApnEditorUT.sNotSet = "Not Set";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetStringValue_valueChanged_shouldSetValue() {
|
||||
// GIVEN an APN value which is different than the APN value in database
|
||||
final String apnKey = "apn";
|
||||
final String apnValue = "testing.com";
|
||||
final ContentValues cv = new ContentValues();
|
||||
|
||||
// WHEN try to check and set the apn value
|
||||
final boolean isDiff = mApnEditorUT.setStringValueAndCheckIfDiff(
|
||||
cv, apnKey, apnValue, false /* assumeDiff */, ApnEditor.APN_INDEX);
|
||||
|
||||
// THEN the APN value is different than the one in database, and it has been stored in the
|
||||
// given ContentValues
|
||||
assertThat(isDiff).isTrue();
|
||||
assertThat(apnValue).isEqualTo(cv.getAsString(apnKey));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetStringValue_valueNotChanged_shouldNotSetValue() {
|
||||
// GIVEN an APN value which is same as the APN value in database
|
||||
final String apnKey = "apn";
|
||||
final String apnValue = (String) APN_DATA[ApnEditor.APN_INDEX];
|
||||
final ContentValues cv = new ContentValues();
|
||||
|
||||
// WHEN try to check and set the apn value
|
||||
final boolean isDiff = mApnEditorUT.setStringValueAndCheckIfDiff(
|
||||
cv, apnKey, apnValue, false /* assumeDiff */, ApnEditor.APN_INDEX);
|
||||
|
||||
// THEN the APN value is same as the one in database, and the new APN value is not stored
|
||||
// in the given ContentValues
|
||||
assertThat(isDiff).isFalse();
|
||||
assertThat(cv.get(apnKey)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetStringValue_nullValue_shouldNotSetValue_shouldNotSetValue() {
|
||||
// GIVEN a null APN value
|
||||
final String apnKey = "apn";
|
||||
final String apnValue = null;
|
||||
final ContentValues cv = new ContentValues();
|
||||
|
||||
// WHEN try to check and set the apn value
|
||||
final boolean isDiff = mApnEditorUT.setStringValueAndCheckIfDiff(
|
||||
cv, apnKey, apnValue, false /* assumeDiff */, ApnEditor.APN_INDEX);
|
||||
|
||||
// THEN the APN value is different than the one in database, but the null value is not
|
||||
// stored in the given ContentValues
|
||||
assertThat(isDiff).isTrue();
|
||||
assertThat(cv.get(apnKey)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetIntValue_valueChanged_shouldSetValue() {
|
||||
// GIVEN a value indicated whether the apn is enabled, and it's different than the value in
|
||||
// the database
|
||||
final String apnEnabledKey = "apn_enabled";
|
||||
final int apnEnabledValue = 0;
|
||||
final ContentValues cv = new ContentValues();
|
||||
|
||||
// WHEN try to check and set the apn enabled
|
||||
final boolean isDiff = mApnEditorUT.setIntValueAndCheckIfDiff(
|
||||
cv,
|
||||
apnEnabledKey,
|
||||
apnEnabledValue,
|
||||
false /* assumeDiff */,
|
||||
ApnEditor.CARRIER_ENABLED_INDEX);
|
||||
|
||||
// THEN the apn enabled field is different than the one in database, and it has been stored
|
||||
// in the given ContentValues
|
||||
assertThat(isDiff).isTrue();
|
||||
assertThat(cv.getAsInteger(apnEnabledKey)).isEqualTo(apnEnabledValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetIntValue_valueNotChanged_shouldNotSetValue() {
|
||||
// GIVEN a value indicated whether the apn is enabled, and it's same as the one in the
|
||||
// database
|
||||
final String apnEnabledKey = "apn_enabled";
|
||||
final int apnEnabledValue = (int) APN_DATA[ApnEditor.CARRIER_ENABLED_INDEX];
|
||||
final ContentValues cv = new ContentValues();
|
||||
|
||||
// WHEN try to check and set the apn enabled
|
||||
final boolean isDiff = mApnEditorUT.setIntValueAndCheckIfDiff(
|
||||
cv,
|
||||
apnEnabledKey,
|
||||
apnEnabledValue,
|
||||
false /* assumeDiff */,
|
||||
ApnEditor.CARRIER_ENABLED_INDEX);
|
||||
|
||||
// THEN the apn enabled field is same as the one in the database, and the filed is not
|
||||
// stored in the given ContentValues
|
||||
assertThat(isDiff).isFalse();
|
||||
assertThat(cv.get(apnEnabledKey)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateApnData_validData_shouldReturnNull() {
|
||||
// GIVEN a valid apn data
|
||||
mApnEditorUT.mApnData = new FakeApnData(APN_DATA);
|
||||
mApnEditorUT.fillUI(true /* firstTime */);
|
||||
|
||||
// WHEN validate the apn data
|
||||
final String errMsg = mApnEditorUT.validateApnData();
|
||||
|
||||
// THEN the error message should be null
|
||||
assertThat(errMsg).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateApn_apnNameNotSet_shouldReturnErrorMessage() {
|
||||
// GIVEN a apn data without the apn name
|
||||
final FakeApnData apnData = new FakeApnData(APN_DATA);
|
||||
apnData.mData[ApnEditor.NAME_INDEX] = "";
|
||||
mApnEditorUT.mApnData = apnData;
|
||||
mApnEditorUT.fillUI(true /* firstTime */);
|
||||
|
||||
// THEN validate the apn data
|
||||
final String errMsg = mApnEditorUT.validateApnData();
|
||||
|
||||
// THEN the error message indicated the apn name not set is returned
|
||||
assertThat(errMsg).isEqualTo(mResources.getString(R.string.error_name_empty));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateApnData_apnNotSet_shouldReturnErrorMessage() {
|
||||
// GIVEN a apn data without the apn
|
||||
final FakeApnData apnData = new FakeApnData(APN_DATA);
|
||||
apnData.mData[ApnEditor.APN_INDEX] = "";
|
||||
mApnEditorUT.mApnData = apnData;
|
||||
mApnEditorUT.fillUI(true /* firstTime */);
|
||||
|
||||
// THEN validate the apn data
|
||||
final String errMsg = mApnEditorUT.validateApnData();
|
||||
|
||||
// THEN the error message indicated the apn not set is returned
|
||||
assertThat(errMsg).isEqualTo(mResources.getString(R.string.error_apn_empty));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateApnData_mccInvalid_shouldReturnErrorMessage() {
|
||||
// GIVEN a apn data with invalid mcc
|
||||
final FakeApnData apnData = new FakeApnData(APN_DATA);
|
||||
// The length of the mcc should be 3
|
||||
apnData.mData[ApnEditor.MCC_INDEX] = "1324";
|
||||
mApnEditorUT.mApnData = apnData;
|
||||
mApnEditorUT.fillUI(true /* firstTime */);
|
||||
|
||||
// WHEN validate the apn data
|
||||
final String errMsg = mApnEditorUT.validateApnData();
|
||||
|
||||
// THEN the error message indicated the mcc invalid is returned
|
||||
assertThat(errMsg).isEqualTo(mResources.getString(R.string.error_mcc_not3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateApnData_mncInvalid_shouldReturnErrorMessage() {
|
||||
// GIVEN an apn data with invalid mnc
|
||||
final FakeApnData apnData = new FakeApnData(APN_DATA);
|
||||
// The length of the mnc should be 2 or 3
|
||||
apnData.mData[ApnEditor.MNC_INDEX] = "1324";
|
||||
mApnEditorUT.mApnData = apnData;
|
||||
mApnEditorUT.fillUI(true /* firstTime */);
|
||||
|
||||
// WHEN validate the apn data
|
||||
final String errMsg = mApnEditorUT.validateApnData();
|
||||
|
||||
// THEN the error message indicated the mnc invalid is returned
|
||||
assertThat(errMsg).isEqualTo(mResources.getString(R.string.error_mnc_not23));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveApnData_pressBackButtonWithValidApnData_shouldSaveApnData() {
|
||||
// GIVEN a valid apn data
|
||||
mApnEditorUT.mApnData = new FakeApnData(APN_DATA);
|
||||
mApnEditorUT.fillUI(true /* firstTime */);
|
||||
|
||||
// WHEN press the back button
|
||||
final KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
|
||||
mApnEditorUT.onKey(new View(mActivity), KeyEvent.KEYCODE_BACK, event);
|
||||
|
||||
// THEN the apn data is saved and the apn editor is closed
|
||||
verify(mApnEditorUT).validateAndSaveApnData();
|
||||
verify(mApnEditorUT).finish();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveApnData_pressSaveButtonWithValidApnData_shouldSaveApnData() {
|
||||
// GIVEN a valid apn data
|
||||
mApnEditorUT.mApnData = new FakeApnData(APN_DATA);
|
||||
mApnEditorUT.fillUI(true /* firstTime */);
|
||||
|
||||
// WHEN press the save button
|
||||
MenuItem item = Mockito.mock(MenuItem.class);
|
||||
// Menu.FIRST + 1 indicated the SAVE option in ApnEditor
|
||||
doReturn(Menu.FIRST + 1).when(item).getItemId();
|
||||
mApnEditorUT.onOptionsItemSelected(item);
|
||||
|
||||
// THEN the apn data is saved and the apn editor is closed
|
||||
verify(mApnEditorUT).validateAndSaveApnData();
|
||||
verify(mApnEditorUT).finish();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveApnData_apnDataInvalid_shouldNotSaveApnData() {
|
||||
// GIVEN an invalid apn data
|
||||
final FakeApnData apnData = new FakeApnData(APN_DATA);
|
||||
// The valid apn data should contains a non-empty apn name
|
||||
apnData.mData[ApnEditor.NAME_INDEX] = "";
|
||||
mApnEditorUT.mApnData = apnData;
|
||||
mApnEditorUT.fillUI(true /* firstTime */);
|
||||
|
||||
// WHEN press the save button
|
||||
final MenuItem item = Mockito.mock(MenuItem.class);
|
||||
// Menu.FIRST + 1 indicated the SAVE option in ApnEditor
|
||||
doReturn(Menu.FIRST + 1).when(item).getItemId();
|
||||
mApnEditorUT.onOptionsItemSelected(item);
|
||||
|
||||
// THEN the error dialog is shown
|
||||
verify(mApnEditorUT).validateAndSaveApnData();
|
||||
verify(mApnEditorUT).showError();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteApnData_shouldDeleteData() {
|
||||
// GIVEN a valid apn data correspond a row in database
|
||||
final Uri apnUri = Uri.parse("content://telephony/carriers/1");
|
||||
mApnEditorUT.mApnData = new FakeApnData(APN_DATA, apnUri);
|
||||
mApnEditorUT.fillUI(true /* firstTime */);
|
||||
ContentResolver mockContentResolver = Mockito.mock(ContentResolver.class);
|
||||
doReturn(mockContentResolver).when(mActivity).getContentResolver();
|
||||
|
||||
// WHEN press the save button
|
||||
final MenuItem item = Mockito.mock(MenuItem.class);
|
||||
// Menu.FIRST indicated the DELETE option in ApnEditor
|
||||
doReturn(Menu.FIRST).when(item).getItemId();
|
||||
mApnEditorUT.onOptionsItemSelected(item);
|
||||
|
||||
// THEN the apn data is deleted and the apn editor is closed
|
||||
verify(mockContentResolver).delete(mUriCaptor.capture(), any(), any());
|
||||
assertThat(apnUri).isEqualTo(mUriCaptor.getValue());
|
||||
verify(mApnEditorUT).finish();
|
||||
}
|
||||
|
||||
@Test(expected = ClassCastException.class)
|
||||
public void testApnData_invalidIntegerType_throwsInvalidTypeException() {
|
||||
// GIVEN a ApnData constructed from cursor
|
||||
initCursor();
|
||||
final ApnData data = new ApnData(mApnUri, mCursor);
|
||||
|
||||
// WHEN get a string from an integer column
|
||||
// THEN the InvalidTypeException is threw
|
||||
data.getString(CURSOR_INTEGER_INDEX);
|
||||
}
|
||||
|
||||
@Test(expected = ClassCastException.class)
|
||||
public void testApnData_invalidStringType_throwsInvalidTypeException() {
|
||||
// GIVEN a ApnData constructed from cursor
|
||||
initCursor();
|
||||
final ApnData data = new ApnData(mApnUri, mCursor);
|
||||
|
||||
// WHEN get a integer from a string column
|
||||
// THEN the InvalidTypeException is threw
|
||||
data.getInteger(CURSOR_STRING_INDEX);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApnData_validIntegerType_returnCorrectValue() {
|
||||
// GIVEN a ApnData constructed from cursor
|
||||
initCursor();
|
||||
final ApnData data = new ApnData(mApnUri, mCursor);
|
||||
|
||||
// WHEN get integer from an integer column
|
||||
final int val = data.getInteger(CURSOR_INTEGER_INDEX);
|
||||
|
||||
// THEN the integer is returned correctly
|
||||
assertThat(val).isEqualTo(mCursor.getInt(CURSOR_INTEGER_INDEX));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApnData_validStringType_returnCorrectValue() {
|
||||
// GIVEN a ApnData constructed from cursor
|
||||
initCursor();
|
||||
final ApnData data = new ApnData(mApnUri, mCursor);
|
||||
|
||||
// WHEN get string from a string column
|
||||
final String str = data.getString(CURSOR_STRING_INDEX);
|
||||
|
||||
// THEN the integer is returned correctly
|
||||
assertThat(str).isEqualTo(mCursor.getString(CURSOR_STRING_INDEX));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApnData_nullValueColumn_returnNull() {
|
||||
// GIVEN a empty ApnData
|
||||
final ApnData data = new ApnData(3);
|
||||
|
||||
// WHEN get string value from a null column
|
||||
final String str = data.getString(0);
|
||||
|
||||
// THEN the null value is returned
|
||||
assertThat(str).isNull();
|
||||
}
|
||||
|
||||
private void initCursor() {
|
||||
@@ -59,59 +426,38 @@ public class ApnEditorTest {
|
||||
doReturn(Cursor.FIELD_TYPE_STRING).when(mCursor).getType(CURSOR_STRING_INDEX);
|
||||
}
|
||||
|
||||
@Test(expected = InvalidTypeException.class)
|
||||
public void testApnData_invalidIntegerType_throwsInvalidTypeException() {
|
||||
// GIVEN a ApnData constructed from cursor
|
||||
ApnData data = new ApnData(mApnUri, mCursor);
|
||||
|
||||
// WHEN get a string from an integer column
|
||||
// THEN the InvalidTypeException is threw
|
||||
data.getString(CURSOR_INTEGER_INDEX);
|
||||
private void setMockPreference(Context context) {
|
||||
mApnEditorUT.mName = new EditTextPreference(context);
|
||||
mApnEditorUT.mApn = new EditTextPreference(context);
|
||||
mApnEditorUT.mProxy = new EditTextPreference(context);
|
||||
mApnEditorUT.mPort = new EditTextPreference(context);
|
||||
mApnEditorUT.mUser = new EditTextPreference(context);
|
||||
mApnEditorUT.mServer = new EditTextPreference(context);
|
||||
mApnEditorUT.mPassword = new EditTextPreference(context);
|
||||
mApnEditorUT.mMmsc = new EditTextPreference(context);
|
||||
mApnEditorUT.mMcc = new EditTextPreference(context);
|
||||
mApnEditorUT.mMnc = new EditTextPreference(context);
|
||||
mApnEditorUT.mMmsProxy = new EditTextPreference(context);
|
||||
mApnEditorUT.mMmsPort = new EditTextPreference(context);
|
||||
mApnEditorUT.mAuthType = new ListPreference(context);
|
||||
mApnEditorUT.mApnType = new EditTextPreference(context);
|
||||
mApnEditorUT.mProtocol = new ListPreference(context);
|
||||
mApnEditorUT.mRoamingProtocol = new ListPreference(context);
|
||||
mApnEditorUT.mCarrierEnabled = new SwitchPreference(context);
|
||||
mApnEditorUT.mBearerMulti = new MultiSelectListPreference(context);
|
||||
mApnEditorUT.mMvnoType = new ListPreference(context);
|
||||
mApnEditorUT.mMvnoMatchData = new EditTextPreference(context);
|
||||
}
|
||||
|
||||
@Test(expected = InvalidTypeException.class)
|
||||
public void testApnData_invalidStringType_throwsInvalidTypeException() {
|
||||
// GIVEN a ApnData constructed from cursor
|
||||
ApnData data = new ApnData(mApnUri, mCursor);
|
||||
|
||||
// WHEN get a integer from a string column
|
||||
// THEN the InvalidTypeException is threw
|
||||
data.getInteger(CURSOR_STRING_INDEX);
|
||||
private final class FakeApnData extends ApnData {
|
||||
FakeApnData(Object[] data) {
|
||||
super(data.length);
|
||||
System.arraycopy(data, 0, mData, 0, data.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApnData_validIntegerType_returnCorrectValue() {
|
||||
// GIVEN a ApnData constructed from cursor
|
||||
ApnData data = new ApnData(mApnUri, mCursor);
|
||||
|
||||
// WHEN get integer from an integer column
|
||||
int val = data.getInteger(CURSOR_INTEGER_INDEX);
|
||||
|
||||
// THEN the integer is returned correctly
|
||||
assertEquals(mCursor.getInt(CURSOR_INTEGER_INDEX), val);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApnData_validStringType_returnCorrectValue() {
|
||||
// GIVEN a ApnData constructed from cursor
|
||||
ApnData data = new ApnData(mApnUri, mCursor);
|
||||
|
||||
// WHEN get string from a string column
|
||||
String str = data.getString(CURSOR_STRING_INDEX);
|
||||
|
||||
// THEN the integer is returned correctly
|
||||
assertEquals(mCursor.getString(CURSOR_STRING_INDEX), str);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApnData_nullValueColumn_returnNull() {
|
||||
// GIVEN a empty ApnData
|
||||
ApnData data = new ApnData(3);
|
||||
|
||||
// WHEN get string value from a null column
|
||||
String str = data.getString(0);
|
||||
|
||||
// THEN the null value is returned
|
||||
assertNull(str);
|
||||
FakeApnData(Object[] data, Uri uri) {
|
||||
this(data);
|
||||
mUri = uri;
|
||||
}
|
||||
}
|
||||
}
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
@@ -28,6 +27,7 @@ import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
@@ -48,7 +48,6 @@ import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -74,7 +73,7 @@ public class UtilsTest {
|
||||
@Mock
|
||||
private ConnectivityManager connectivityManager;
|
||||
@Mock
|
||||
private DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
private DevicePolicyManager mDevicePolicyManager;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
|
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class MagnificationGesturesPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private MagnificationGesturesPreferenceController mController;
|
||||
private Preference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new MagnificationGesturesPreferenceController(mContext, "pref_key");
|
||||
mPreference = new Preference(mContext);
|
||||
mController.updateState(mPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAlwaysAvailable() {
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_shouldRefreshSummary() {
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 1);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(mContext.getString(R.string.accessibility_feature_state_on));
|
||||
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 0);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(mContext.getString(R.string.accessibility_feature_state_off));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_shouldRefreshSummarySuw() {
|
||||
mController.setIsFromSUW(true);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(mContext.getString(R.string.
|
||||
accessibility_screen_magnification_short_summary));
|
||||
}
|
||||
}
|
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.android.settings.search.ResultPayload.Availability.AVAILABLE;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class MagnificationNavbarPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private MagnificationNavbarPreferenceController mController;
|
||||
private Preference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mController = new MagnificationNavbarPreferenceController(mContext, "test_key");
|
||||
mPreference = new Preference(mContext);
|
||||
mController.updateState(mPreference);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowMagnificationPreferenceFragment.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowMagnificationPreferenceFragment.class)
|
||||
public void isAvailable_unsupported_shouldNotBeAvailable() {
|
||||
ShadowMagnificationPreferenceFragment.setApplicable(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isNotEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowMagnificationPreferenceFragment.class)
|
||||
public void isAvailable_supported_shouldBeAvailable() {
|
||||
ShadowMagnificationPreferenceFragment.setApplicable(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_shouldRefreshSummary() {
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, 1);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(mContext.getText(R.string.accessibility_feature_state_on));
|
||||
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, 0);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(mContext.getText(R.string.accessibility_feature_state_off));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_shouldRefreshSummarySuw() {
|
||||
mController.setIsFromSUW(true);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(mContext.getString(R.string.
|
||||
accessibility_screen_magnification_navbar_short_summary));
|
||||
}
|
||||
|
||||
@Implements(MagnificationPreferenceFragment.class)
|
||||
public static class ShadowMagnificationPreferenceFragment {
|
||||
private static boolean sIsApplicable;
|
||||
|
||||
@Resetter
|
||||
static void reset() {
|
||||
sIsApplicable = false;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
static boolean isApplicable(Resources res) {
|
||||
return sIsApplicable;
|
||||
}
|
||||
|
||||
static void setApplicable(boolean applicable) {
|
||||
sIsApplicable = applicable;
|
||||
}
|
||||
}
|
||||
}
|
@@ -50,10 +50,6 @@ import com.android.settings.testutils.shadow.ShadowAccountManager;
|
||||
import com.android.settings.testutils.shadow.ShadowContentResolver;
|
||||
import com.android.settings.testutils.shadow.ShadowDevicePolicyManager;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -64,9 +60,11 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(
|
||||
shadows = {
|
||||
@Config(shadows = {
|
||||
ShadowUserManager.class,
|
||||
ShadowDevicePolicyManager.class
|
||||
})
|
||||
@@ -78,8 +76,6 @@ public class RemoveAccountPreferenceControllerTest {
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private AccountManager mAccountManager;
|
||||
@Mock
|
||||
private DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
@Mock
|
||||
private PreferenceFragment mFragment;
|
||||
@Mock
|
||||
private PreferenceManager mPreferenceManager;
|
||||
@@ -108,7 +104,7 @@ public class RemoveAccountPreferenceControllerTest {
|
||||
.thenReturn(new AuthenticatorDescription[0]);
|
||||
when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(new Account[0]);
|
||||
mController = new RemoveAccountPreferenceController(RuntimeEnvironment.application,
|
||||
mFragment, mDevicePolicyManager);
|
||||
mFragment);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -37,7 +37,6 @@ import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settings.wrapper.IPackageManagerWrapper;
|
||||
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||
|
||||
@@ -84,7 +83,7 @@ public final class AppWithAdminGrantedPermissionsCounterTest {
|
||||
@Mock
|
||||
private IPackageManagerWrapper mPackageManagerService;
|
||||
@Mock
|
||||
private DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
private DevicePolicyManager mDevicePolicyManager;
|
||||
|
||||
private int mAppCount = -1;
|
||||
private ApplicationInfo mApp1;
|
||||
|
@@ -34,7 +34,6 @@ import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settings.wrapper.IPackageManagerWrapper;
|
||||
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||
|
||||
@@ -81,7 +80,7 @@ public final class AppWithAdminGrantedPermissionsListerTest {
|
||||
@Mock
|
||||
private IPackageManagerWrapper mPackageManagerService;
|
||||
@Mock
|
||||
private DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
private DevicePolicyManager mDevicePolicyManager;
|
||||
|
||||
private List<UserAppInfo> mAppList = Collections.emptyList();
|
||||
|
||||
|
@@ -33,7 +33,6 @@ import android.os.UserManager;
|
||||
|
||||
import com.android.settings.testutils.ApplicationTestUtils;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settings.wrapper.IPackageManagerWrapper;
|
||||
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||
|
||||
@@ -75,7 +74,7 @@ public final class ApplicationFeatureProviderImplTest {
|
||||
@Mock
|
||||
private IPackageManagerWrapper mPackageManagerService;
|
||||
@Mock
|
||||
private DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
private DevicePolicyManager mDevicePolicyManager;
|
||||
|
||||
private ApplicationFeatureProvider mProvider;
|
||||
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.applications.appinfo;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
@@ -28,6 +27,7 @@ import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -47,7 +47,6 @@ import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.widget.ActionButtonPreference;
|
||||
import com.android.settings.widget.ActionButtonPreferenceTest;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
@@ -74,7 +73,7 @@ public class AppActionButtonPreferenceControllerTest {
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
private DevicePolicyManager mDevicePolicyManager;
|
||||
@Mock
|
||||
private AppInfoDashboardFragment mFragment;
|
||||
@Mock
|
||||
|
@@ -17,7 +17,8 @@
|
||||
package com.android.settings.applications.appinfo;
|
||||
|
||||
import static com.android.settings.applications.appinfo.AppInfoDashboardFragment.ARG_PACKAGE_NAME;
|
||||
import static com.android.settings.applications.appinfo.AppInfoDashboardFragment.UNINSTALL_ALL_USERS_MENU;
|
||||
import static com.android.settings.applications.appinfo.AppInfoDashboardFragment
|
||||
.UNINSTALL_ALL_USERS_MENU;
|
||||
import static com.android.settings.applications.appinfo.AppInfoDashboardFragment.UNINSTALL_UPDATES;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -31,6 +32,7 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
@@ -45,7 +47,6 @@ import android.view.MenuItem;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
||||
import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
|
||||
@@ -75,7 +76,7 @@ public final class AppInfoDashboardFragmentTest {
|
||||
@Mock
|
||||
private SettingsActivity mActivity;
|
||||
@Mock
|
||||
private DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
private DevicePolicyManager mDevicePolicyManager;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
|
||||
|
@@ -110,7 +110,7 @@ public class AppMemoryPreferenceControllerTest {
|
||||
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING);
|
||||
.isEqualTo(BasePreferenceController.DISABLED_UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -25,12 +25,13 @@ import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserManager;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.wrapper.UserManagerWrapper;
|
||||
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -52,7 +53,7 @@ public class PictureInPictureSettingsTest {
|
||||
@Mock
|
||||
private PackageManagerWrapper mPackageManager;
|
||||
@Mock
|
||||
private UserManagerWrapper mUserManager;
|
||||
private UserManager mUserManager;
|
||||
private ArrayList<PackageInfo> mPrimaryUserPackages;
|
||||
private ArrayList<PackageInfo> mProfileUserPackages;
|
||||
|
||||
|
@@ -18,6 +18,8 @@ package com.android.settings.connecteddevice.usb;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -27,9 +29,10 @@ import android.hardware.usb.UsbManager;
|
||||
import android.hardware.usb.UsbPort;
|
||||
import android.hardware.usb.UsbPortStatus;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.wrapper.UserManagerWrapper;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -45,7 +48,7 @@ public class UsbBackendTest {
|
||||
@Mock
|
||||
private UsbManager mUsbManager;
|
||||
@Mock
|
||||
private UserManagerWrapper mUserManagerWrapper;
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private ConnectivityManager mConnectivityManager;
|
||||
@Mock
|
||||
@@ -68,7 +71,7 @@ public class UsbBackendTest {
|
||||
|
||||
@Test
|
||||
public void setDataRole_allRolesSupported_shouldSetDataRole() {
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManager);
|
||||
|
||||
when(mUsbPortStatus
|
||||
.isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE))
|
||||
@@ -91,7 +94,7 @@ public class UsbBackendTest {
|
||||
|
||||
@Test
|
||||
public void setDataRole_notAllRolesSupported_shouldSetDataAndPowerRole() {
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManager);
|
||||
|
||||
when(mUsbPortStatus
|
||||
.isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE))
|
||||
@@ -109,7 +112,7 @@ public class UsbBackendTest {
|
||||
|
||||
@Test
|
||||
public void setPowerRole_allRolesSupported_shouldSetPowerRole() {
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManager);
|
||||
|
||||
when(mUsbPortStatus
|
||||
.isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE))
|
||||
@@ -133,7 +136,7 @@ public class UsbBackendTest {
|
||||
|
||||
@Test
|
||||
public void setPowerRole_notAllRolesSupported_shouldSetDataAndPowerRole() {
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManager);
|
||||
|
||||
when(mUsbPortStatus
|
||||
.isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE))
|
||||
@@ -151,20 +154,26 @@ public class UsbBackendTest {
|
||||
|
||||
@Test
|
||||
public void areFunctionsSupported_fileTransferDisallowed_shouldReturnFalse() {
|
||||
when(mUserManagerWrapper.isUsbFileTransferRestricted()).thenReturn(true);
|
||||
when(mUserManagerWrapper.isUsbFileTransferRestrictedBySystem()).thenReturn(true);
|
||||
when(mUserManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER))
|
||||
.thenReturn(true);
|
||||
when(mUserManager.hasBaseUserRestriction(
|
||||
eq(UserManager.DISALLOW_USB_FILE_TRANSFER), any(UserHandle.class)))
|
||||
.thenReturn(true);
|
||||
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManager);
|
||||
|
||||
assertThat(usbBackend.areFunctionsSupported(UsbManager.FUNCTION_MTP)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void areFunctionsSupported_fileTransferAllowed_shouldReturnTrue() {
|
||||
when(mUserManagerWrapper.isUsbFileTransferRestricted()).thenReturn(false);
|
||||
when(mUserManagerWrapper.isUsbFileTransferRestrictedBySystem()).thenReturn(false);
|
||||
when(mUserManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER))
|
||||
.thenReturn(false);
|
||||
when(mUserManager.hasBaseUserRestriction(
|
||||
eq(UserManager.DISALLOW_USB_FILE_TRANSFER), any(UserHandle.class)))
|
||||
.thenReturn(false);
|
||||
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
|
||||
final UsbBackend usbBackend = new UsbBackend(mContext, mUserManager);
|
||||
|
||||
assertThat(usbBackend.areFunctionsSupported(UsbManager.FUNCTION_MTP)).isTrue();
|
||||
}
|
||||
|
@@ -21,27 +21,37 @@ import static com.android.settings.core.BasePreferenceController.DISABLED_FOR_US
|
||||
import static com.android.settings.core.BasePreferenceController.DISABLED_UNSUPPORTED;
|
||||
import static com.android.settings.core.BasePreferenceController.UNAVAILABLE_UNKNOWN;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.slices.SliceData;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class BasePreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private BasePreferenceController mPreferenceController;
|
||||
private final String KEY = "fake_key";
|
||||
|
||||
private Context mContext;
|
||||
private FakeBasePreferenceController mPreferenceController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPreferenceController = new FakeBasePreferenceController(mContext, KEY);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,70 +67,70 @@ public class BasePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void isAvailable_availableStatusAvailable_returnsTrue() {
|
||||
when(mPreferenceController.getAvailabilityStatus()).thenReturn(AVAILABLE);
|
||||
mPreferenceController.setAvailability(AVAILABLE);
|
||||
|
||||
assertThat(mPreferenceController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_availableStatusUnsupported_returnsFalse() {
|
||||
when(mPreferenceController.getAvailabilityStatus()).thenReturn(DISABLED_UNSUPPORTED);
|
||||
mPreferenceController.setAvailability(DISABLED_UNSUPPORTED);
|
||||
|
||||
assertThat(mPreferenceController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_availableStatusDisabled_returnsFalse() {
|
||||
when(mPreferenceController.getAvailabilityStatus()).thenReturn(DISABLED_FOR_USER);
|
||||
public void isAvailable_availableStatusDisabledForUser_returnsFalse() {
|
||||
mPreferenceController.setAvailability(DISABLED_FOR_USER);
|
||||
|
||||
assertThat(mPreferenceController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_availableStatusBlockedDependent_returnsFalse() {
|
||||
when(mPreferenceController.getAvailabilityStatus()).thenReturn(DISABLED_DEPENDENT_SETTING);
|
||||
mPreferenceController.setAvailability(DISABLED_DEPENDENT_SETTING);
|
||||
|
||||
assertThat(mPreferenceController.isAvailable()).isFalse();
|
||||
assertThat(mPreferenceController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_availableStatusUnavailable_returnsFalse() {
|
||||
when(mPreferenceController.getAvailabilityStatus()).thenReturn(UNAVAILABLE_UNKNOWN);
|
||||
mPreferenceController.setAvailability(UNAVAILABLE_UNKNOWN);
|
||||
|
||||
assertThat(mPreferenceController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSupported_availableStatusAvailable_returnsTrue() {
|
||||
when(mPreferenceController.getAvailabilityStatus()).thenReturn(AVAILABLE);
|
||||
mPreferenceController.setAvailability(AVAILABLE);
|
||||
|
||||
assertThat(mPreferenceController.isSupported()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSupported_availableStatusUnsupported_returnsFalse() {
|
||||
when(mPreferenceController.getAvailabilityStatus()).thenReturn(DISABLED_UNSUPPORTED);
|
||||
mPreferenceController.setAvailability(DISABLED_UNSUPPORTED);
|
||||
|
||||
assertThat(mPreferenceController.isSupported()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSupported_availableStatusDisabled_returnsTrue() {
|
||||
when(mPreferenceController.getAvailabilityStatus()).thenReturn(DISABLED_FOR_USER);
|
||||
public void isSupported_availableStatusDisabledForUser_returnsTrue() {
|
||||
mPreferenceController.setAvailability(DISABLED_FOR_USER);
|
||||
|
||||
assertThat(mPreferenceController.isSupported()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSupported_availableStatusDependentSetting_returnsTrue() {
|
||||
when(mPreferenceController.getAvailabilityStatus()).thenReturn(DISABLED_DEPENDENT_SETTING);
|
||||
mPreferenceController.setAvailability(DISABLED_DEPENDENT_SETTING);
|
||||
|
||||
assertThat(mPreferenceController.isSupported()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSupported_availableStatusUnavailable_returnsTrue() {
|
||||
when(mPreferenceController.getAvailabilityStatus()).thenReturn(UNAVAILABLE_UNKNOWN);
|
||||
mPreferenceController.setAvailability(UNAVAILABLE_UNKNOWN);
|
||||
|
||||
assertThat(mPreferenceController.isSupported()).isTrue();
|
||||
}
|
||||
@@ -129,4 +139,48 @@ public class BasePreferenceControllerTest {
|
||||
public void getSliceType_shouldReturnIntent() {
|
||||
assertThat(mPreferenceController.getSliceType()).isEqualTo(SliceData.SliceType.INTENT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void settingAvailable_disabledOnDisplayPreference_preferenceEnabled() {
|
||||
final PreferenceScreen screen = mock(PreferenceScreen.class);
|
||||
final Preference preference = new Preference(mContext);
|
||||
preference.setEnabled(true);
|
||||
when(screen.findPreference(anyString())).thenReturn(preference);
|
||||
|
||||
mPreferenceController.displayPreference(screen);
|
||||
|
||||
assertThat(preference.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disabledDependentSetting_disabledOnDisplayPreference_preferenceDisabled() {
|
||||
final PreferenceScreen screen = mock(PreferenceScreen.class);
|
||||
final Preference preference = new Preference(mContext);
|
||||
preference.setEnabled(true);
|
||||
when(screen.findPreference(anyString())).thenReturn(preference);
|
||||
mPreferenceController.setAvailability(DISABLED_DEPENDENT_SETTING);
|
||||
|
||||
mPreferenceController.displayPreference(screen);
|
||||
|
||||
assertThat(preference.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
private class FakeBasePreferenceController extends BasePreferenceController {
|
||||
|
||||
public int mAvailable;
|
||||
|
||||
public FakeBasePreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mAvailable = AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mAvailable;
|
||||
}
|
||||
|
||||
public void setAvailability(int availability) {
|
||||
mAvailable = availability;
|
||||
}
|
||||
}
|
||||
}
|
@@ -26,13 +26,13 @@ import static org.mockito.Mockito.when;
|
||||
import android.content.Context;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.wrapper.UserManagerWrapper;
|
||||
import com.android.settingslib.applications.StorageStatsSource;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.drawable.UserIconDrawable;
|
||||
@@ -54,7 +54,7 @@ public class SecondaryUserControllerTest {
|
||||
private static final String TEST_NAME = "Fred";
|
||||
private static final String TARGET_PREFERENCE_GROUP_KEY = "pref_secondary_users";
|
||||
@Mock
|
||||
private UserManagerWrapper mUserManager;
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
|
@@ -35,7 +35,6 @@ import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SubSettings;
|
||||
import com.android.settings.deviceinfo.StorageProfileFragment;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.wrapper.UserManagerWrapper;
|
||||
import com.android.settingslib.applications.StorageStatsSource;
|
||||
import com.android.settingslib.drawable.UserIconDrawable;
|
||||
|
||||
@@ -52,8 +51,6 @@ public class UserProfileControllerTest {
|
||||
|
||||
private static final String TEST_NAME = "Fred";
|
||||
|
||||
@Mock
|
||||
private UserManagerWrapper mUserManager;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
@@ -66,7 +63,7 @@ public class UserProfileControllerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mPrimaryProfile = new UserInfo();
|
||||
mController = new UserProfileController(mContext, mPrimaryProfile, mUserManager, 0);
|
||||
mController = new UserProfileController(mContext, mPrimaryProfile, 0);
|
||||
when(mScreen.getContext()).thenReturn(mContext);
|
||||
mPrimaryProfile.name = TEST_NAME;
|
||||
mPrimaryProfile.id = 10;
|
||||
|
@@ -33,7 +33,7 @@ import android.provider.Settings;
|
||||
|
||||
import com.android.settings.TimeoutListPreference;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowDevicePolicyManagerWrapper;
|
||||
import com.android.settings.testutils.shadow.ShadowDevicePolicyManager;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -50,7 +50,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowDevicePolicyManagerWrapper.class)
|
||||
@Config(shadows = ShadowDevicePolicyManager.class)
|
||||
public class TimeoutPreferenceControllerTest {
|
||||
|
||||
private static final int TIMEOUT = 30;
|
||||
@@ -93,7 +93,7 @@ public class TimeoutPreferenceControllerTest {
|
||||
final int profileUserId = UserHandle.myUserId();
|
||||
final long timeout = 10000;
|
||||
when(mUserManager.getProfiles(profileUserId)).thenReturn(Collections.emptyList());
|
||||
ShadowDevicePolicyManagerWrapper.setMaximumTimeToLock(profileUserId, timeout);
|
||||
ShadowDevicePolicyManager.getShadow().setMaximumTimeToLock(profileUserId, timeout);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
verify(mPreference).removeUnusableTimeouts(timeout, null);
|
||||
@@ -104,7 +104,7 @@ public class TimeoutPreferenceControllerTest {
|
||||
final int profileUserId = UserHandle.myUserId();
|
||||
final long timeout = 100;
|
||||
when(mUserManager.getProfiles(profileUserId)).thenReturn(Collections.emptyList());
|
||||
ShadowDevicePolicyManagerWrapper.setMaximumTimeToLock(profileUserId, timeout);
|
||||
ShadowDevicePolicyManager.getShadow().setMaximumTimeToLock(profileUserId, timeout);
|
||||
|
||||
int userId = UserHandle.myUserId();
|
||||
List<UserManager.EnforcingUser> enforcingUsers = new ArrayList<>();
|
||||
|
@@ -139,9 +139,7 @@ public class ActionDisabledByAdminDialogHelperTest {
|
||||
|
||||
@Test
|
||||
public void testSetAdminSupportDetails() {
|
||||
final DevicePolicyManager dpm = RuntimeEnvironment.application.getSystemService(
|
||||
DevicePolicyManager.class);
|
||||
final ShadowDevicePolicyManager dpmShadow = Shadow.extract(dpm);
|
||||
final ShadowDevicePolicyManager dpmShadow = ShadowDevicePolicyManager.getShadow();
|
||||
final UserManager userManager = RuntimeEnvironment.application.getSystemService(
|
||||
UserManager.class);
|
||||
final ShadowUserManager userManagerShadow = Shadow.extract(userManager);
|
||||
@@ -165,9 +163,7 @@ public class ActionDisabledByAdminDialogHelperTest {
|
||||
|
||||
@Test
|
||||
public void testSetAdminSupportDetailsNotAdmin() {
|
||||
final DevicePolicyManager dpm = RuntimeEnvironment.application.getSystemService(
|
||||
DevicePolicyManager.class);
|
||||
final ShadowDevicePolicyManager dpmShadow = Shadow.extract(dpm);
|
||||
final ShadowDevicePolicyManager dpmShadow = ShadowDevicePolicyManager.getShadow();
|
||||
final UserManager userManager = RuntimeEnvironment.application.getSystemService(
|
||||
UserManager.class);
|
||||
final ShadowUserManager userManagerShadow = Shadow.extract(userManager);
|
||||
|
@@ -21,6 +21,7 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
@@ -36,7 +37,6 @@ import android.text.SpannableStringBuilder;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.wrapper.ConnectivityManagerWrapper;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -68,7 +68,7 @@ public class EnterprisePrivacyFeatureProviderImplTest {
|
||||
private List<UserInfo> mProfiles = new ArrayList<>();
|
||||
|
||||
private @Mock Context mContext;
|
||||
private @Mock DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
private @Mock DevicePolicyManager mDevicePolicyManager;
|
||||
private @Mock PackageManagerWrapper mPackageManagerWrapper;
|
||||
private @Mock PackageManager mPackageManager;
|
||||
private @Mock UserManager mUserManager;
|
||||
|
@@ -34,6 +34,7 @@ import static org.mockito.Mockito.when;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.Application;
|
||||
import android.app.Fragment;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
@@ -46,7 +47,6 @@ import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.widget.ActionButtonPreference;
|
||||
import com.android.settings.widget.ActionButtonPreferenceTest;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
|
||||
@@ -87,7 +87,7 @@ public class AppButtonsPreferenceControllerTest {
|
||||
@Mock
|
||||
private PackageManager mPackageManger;
|
||||
@Mock
|
||||
private DevicePolicyManagerWrapper mDpm;
|
||||
private DevicePolicyManager mDpm;
|
||||
@Mock
|
||||
private ActivityManager mAm;
|
||||
@Mock
|
||||
|
@@ -38,7 +38,6 @@ import com.android.settings.R;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.testutils.shadow.ShadowFragment;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -74,7 +73,7 @@ public class BackgroundActivityPreferenceControllerTest {
|
||||
@Mock
|
||||
private DevicePolicyManager mDevicePolicyManager;
|
||||
@Mock
|
||||
private DevicePolicyManagerWrapper mDevicePolicyManagerWrapper;
|
||||
private DevicePolicyManager mDevicePolicyManagerWrapper;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private AdvancedPowerUsageDetail mFragment;
|
||||
@Mock
|
||||
|
@@ -18,10 +18,16 @@ package com.android.settings.fuelgauge.batterytip;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.RuntimeEnvironment.application;
|
||||
|
||||
import android.app.job.JobInfo;
|
||||
import android.app.job.JobScheduler;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
@@ -30,6 +36,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.shadows.ShadowJobScheduler;
|
||||
|
||||
@@ -38,23 +45,39 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class AnomalyCleanupJobServiceTest {
|
||||
private Context mContext;
|
||||
private JobScheduler mJobScheduler;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mJobScheduler = spy(mContext.getSystemService(JobScheduler.class));
|
||||
when(mContext.getSystemService(JobScheduler.class)).thenReturn(mJobScheduler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScheduleCleanUp() {
|
||||
AnomalyCleanupJobService.scheduleCleanUp(application);
|
||||
AnomalyCleanupJobService.scheduleCleanUp(mContext);
|
||||
|
||||
ShadowJobScheduler shadowJobScheduler =
|
||||
Shadows.shadowOf(application.getSystemService(JobScheduler.class));
|
||||
Shadows.shadowOf(mContext.getSystemService(JobScheduler.class));
|
||||
List<JobInfo> pendingJobs = shadowJobScheduler.getAllPendingJobs();
|
||||
assertEquals(1, pendingJobs.size());
|
||||
JobInfo pendingJob = pendingJobs.get(0);
|
||||
assertThat(pendingJob.getId()).isEqualTo(R.id.job_anomaly_clean_up);
|
||||
assertThat(pendingJob.getId()).isEqualTo(R.integer.job_anomaly_clean_up);
|
||||
assertThat(pendingJob.getIntervalMillis()).isEqualTo(TimeUnit.DAYS.toMillis(1));
|
||||
assertThat(pendingJob.isRequireDeviceIdle()).isTrue();
|
||||
assertThat(pendingJob.isRequireCharging()).isTrue();
|
||||
assertThat(pendingJob.isPersisted()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScheduleCleanUp_invokeTwice_onlyScheduleOnce() {
|
||||
AnomalyCleanupJobService.scheduleCleanUp(mContext);
|
||||
AnomalyCleanupJobService.scheduleCleanUp(mContext);
|
||||
|
||||
verify(mJobScheduler, times(1)).schedule(any());
|
||||
}
|
||||
}
|
||||
|
@@ -25,7 +25,9 @@ import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.RuntimeEnvironment.application;
|
||||
|
||||
import android.app.StatsManager;
|
||||
@@ -43,6 +45,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.shadows.ShadowJobScheduler;
|
||||
|
||||
@@ -57,12 +60,18 @@ public class AnomalyConfigJobServiceTest {
|
||||
@Mock
|
||||
private StatsManager mStatsManager;
|
||||
|
||||
private Context mContext;
|
||||
private JobScheduler mJobScheduler;
|
||||
private AnomalyConfigJobService mJobService;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mJobScheduler = spy(mContext.getSystemService(JobScheduler.class));
|
||||
when(mContext.getSystemService(JobScheduler.class)).thenReturn(mJobScheduler);
|
||||
|
||||
mJobService = spy(new AnomalyConfigJobService());
|
||||
doReturn(application.getSharedPreferences(AnomalyConfigJobService.PREF_DB,
|
||||
Context.MODE_PRIVATE)).when(mJobService).getSharedPreferences(anyString(),
|
||||
@@ -71,18 +80,27 @@ public class AnomalyConfigJobServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScheduleCleanUp() {
|
||||
AnomalyConfigJobService.scheduleConfigUpdate(application);
|
||||
public void testScheduleConfigUpdate() {
|
||||
AnomalyConfigJobService.scheduleConfigUpdate(mContext);
|
||||
|
||||
ShadowJobScheduler shadowJobScheduler =
|
||||
Shadows.shadowOf(application.getSystemService(JobScheduler.class));
|
||||
Shadows.shadowOf(mContext.getSystemService(JobScheduler.class));
|
||||
List<JobInfo> pendingJobs = shadowJobScheduler.getAllPendingJobs();
|
||||
assertEquals(1, pendingJobs.size());
|
||||
JobInfo pendingJob = pendingJobs.get(0);
|
||||
assertThat(pendingJob.getId()).isEqualTo(R.id.job_anomaly_config_update);
|
||||
assertThat(pendingJob.getId()).isEqualTo(R.integer.job_anomaly_config_update);
|
||||
assertThat(pendingJob.getIntervalMillis()).isEqualTo(TimeUnit.DAYS.toMillis(1));
|
||||
assertThat(pendingJob.isRequireDeviceIdle()).isTrue();
|
||||
assertThat(pendingJob.isRequireCharging()).isTrue();
|
||||
assertThat(pendingJob.isPersisted()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScheduleConfigUpdate_invokeTwice_onlyScheduleOnce() {
|
||||
AnomalyConfigJobService.scheduleConfigUpdate(mContext);
|
||||
AnomalyConfigJobService.scheduleConfigUpdate(mContext);
|
||||
|
||||
verify(mJobScheduler, times(1)).schedule(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -113,7 +113,7 @@ public class AnomalyDetectionJobServiceTest {
|
||||
assertThat(pendingJobs).hasSize(1);
|
||||
|
||||
JobInfo pendingJob = pendingJobs.get(0);
|
||||
assertThat(pendingJob.getId()).isEqualTo(R.id.job_anomaly_detection);
|
||||
assertThat(pendingJob.getId()).isEqualTo(R.integer.job_anomaly_detection);
|
||||
assertThat(pendingJob.getMaxExecutionDelayMillis())
|
||||
.isEqualTo(TimeUnit.MINUTES.toMillis(30));
|
||||
}
|
||||
|
@@ -76,9 +76,7 @@ public class NetworkDashboardFragmentTest {
|
||||
public void testPrepareActionBar_networkResetShouldBeCreated() {
|
||||
final NetworkResetActionMenuController resetController =
|
||||
mock(NetworkResetActionMenuController.class);
|
||||
final PrivateDnsMenuController privateDnsController = mock(PrivateDnsMenuController.class);
|
||||
ReflectionHelpers.setField(mFragment, "mNetworkResetController", resetController);
|
||||
ReflectionHelpers.setField(mFragment, "mPrivateDnsMenuController", privateDnsController);
|
||||
|
||||
mFragment.onCreateOptionsMenu(null, null);
|
||||
|
||||
|
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.network;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.FragmentManager;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class PrivateDnsMenuControllerTest {
|
||||
private static final int MENU_ID = 0;
|
||||
|
||||
private PrivateDnsMenuController mController;
|
||||
@Mock
|
||||
private Menu mMenu;
|
||||
@Mock
|
||||
private MenuItem mMenuItem;
|
||||
@Mock
|
||||
private FragmentManager mFragmentManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mController = new PrivateDnsMenuController(mFragmentManager, MENU_ID);
|
||||
when(mMenu.add(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(mMenuItem);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildMenuItem_available_shouldAddToMenu() {
|
||||
mController.buildMenuItem(mMenu);
|
||||
|
||||
verify(mMenu).add(0 /* groupId */, MENU_ID, 0 /* order */,
|
||||
R.string.select_private_dns_configuration_title);
|
||||
verify(mMenuItem).setOnMenuItemClickListener(any(MenuItem.OnMenuItemClickListener.class));
|
||||
}
|
||||
}
|
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.network;
|
||||
|
||||
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OFF;
|
||||
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OPPORTUNISTIC;
|
||||
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowHelpUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowHelpUtils.class)
|
||||
public class PrivateDnsModeDialogFragmentTest {
|
||||
|
||||
private static final String HOST_NAME = "192.168.1.1";
|
||||
private static final String INVALID_HOST_NAME = "...,";
|
||||
|
||||
private Context mContext;
|
||||
private PrivateDnsModeDialogFragment mFragment;
|
||||
private Button mSaveButton;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mSaveButton = new Button(mContext);
|
||||
|
||||
mFragment = spy(new PrivateDnsModeDialogFragment());
|
||||
doReturn(mContext).when(mFragment).getContext();
|
||||
mFragment.onCreateDialog(null);
|
||||
mFragment.mSaveButton = mSaveButton;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCheckedChanged_dnsModeOff_disableEditText() {
|
||||
mFragment.onCheckedChanged(null, R.id.private_dns_mode_off);
|
||||
|
||||
assertThat(mFragment.mMode).isEqualTo(PRIVATE_DNS_MODE_OFF);
|
||||
assertThat(mFragment.mEditText.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCheckedChanged_dnsModeOpportunistic_disableEditText() {
|
||||
mFragment.onCheckedChanged(null, R.id.private_dns_mode_opportunistic);
|
||||
|
||||
assertThat(mFragment.mMode).isEqualTo(PRIVATE_DNS_MODE_OPPORTUNISTIC);
|
||||
assertThat(mFragment.mEditText.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCheckedChanged_dnsModeProvider_enableEditText() {
|
||||
mFragment.onCheckedChanged(null, R.id.private_dns_mode_provider);
|
||||
|
||||
assertThat(mFragment.mMode).isEqualTo(PRIVATE_DNS_MODE_PROVIDER_HOSTNAME);
|
||||
assertThat(mFragment.mEditText.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCreateDialog_containsCorrectData() {
|
||||
Settings.Global.putString(mContext.getContentResolver(),
|
||||
PrivateDnsModeDialogFragment.MODE_KEY, PRIVATE_DNS_MODE_OPPORTUNISTIC);
|
||||
Settings.Global.putString(mContext.getContentResolver(),
|
||||
PrivateDnsModeDialogFragment.HOSTNAME_KEY, HOST_NAME);
|
||||
|
||||
mFragment.onCreateDialog(null);
|
||||
|
||||
assertThat(mFragment.mEditText.getText().toString()).isEqualTo(HOST_NAME);
|
||||
assertThat(mFragment.mRadioGroup.getCheckedRadioButtonId()).isEqualTo(
|
||||
R.id.private_dns_mode_opportunistic);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCheckedChanged_switchMode_saveButtonHasCorrectState() {
|
||||
// Set invalid hostname
|
||||
mFragment.mEditText.setText(INVALID_HOST_NAME);
|
||||
|
||||
mFragment.onCheckedChanged(null, R.id.private_dns_mode_opportunistic);
|
||||
assertThat(mSaveButton.isEnabled()).isTrue();
|
||||
|
||||
mFragment.onCheckedChanged(null, R.id.private_dns_mode_provider);
|
||||
assertThat(mSaveButton.isEnabled()).isFalse();
|
||||
|
||||
mFragment.onCheckedChanged(null, R.id.private_dns_mode_off);
|
||||
assertThat(mSaveButton.isEnabled()).isTrue();
|
||||
}
|
||||
}
|
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.network;
|
||||
|
||||
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OFF;
|
||||
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OPPORTUNISTIC;
|
||||
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.CustomDialogPreference.CustomPreferenceDialogFragment;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class PrivateDnsModeDialogPreferenceTest {
|
||||
|
||||
private static final String HOST_NAME = "dns.example.com";
|
||||
private static final String INVALID_HOST_NAME = "...,";
|
||||
|
||||
private PrivateDnsModeDialogPreference mPreference;
|
||||
|
||||
private Context mContext;
|
||||
private Button mSaveButton;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mSaveButton = new Button(mContext);
|
||||
|
||||
final CustomPreferenceDialogFragment fragment = mock(CustomPreferenceDialogFragment.class);
|
||||
final AlertDialog dialog = mock(AlertDialog.class);
|
||||
when(fragment.getDialog()).thenReturn(dialog);
|
||||
when(dialog.getButton(anyInt())).thenReturn(mSaveButton);
|
||||
|
||||
mPreference = new PrivateDnsModeDialogPreference(mContext);
|
||||
ReflectionHelpers.setField(mPreference, "mFragment", fragment);
|
||||
|
||||
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
final View view = inflater.inflate(R.layout.private_dns_mode_dialog,
|
||||
new LinearLayout(mContext), false);
|
||||
|
||||
mPreference.onBindDialogView(view);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCheckedChanged_dnsModeOff_disableEditText() {
|
||||
mPreference.onCheckedChanged(null, R.id.private_dns_mode_off);
|
||||
|
||||
assertThat(mPreference.mMode).isEqualTo(PRIVATE_DNS_MODE_OFF);
|
||||
assertThat(mPreference.mEditText.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCheckedChanged_dnsModeOpportunistic_disableEditText() {
|
||||
mPreference.onCheckedChanged(null, R.id.private_dns_mode_opportunistic);
|
||||
|
||||
assertThat(mPreference.mMode).isEqualTo(PRIVATE_DNS_MODE_OPPORTUNISTIC);
|
||||
assertThat(mPreference.mEditText.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCheckedChanged_dnsModeProvider_enableEditText() {
|
||||
mPreference.onCheckedChanged(null, R.id.private_dns_mode_provider);
|
||||
|
||||
assertThat(mPreference.mMode).isEqualTo(PRIVATE_DNS_MODE_PROVIDER_HOSTNAME);
|
||||
assertThat(mPreference.mEditText.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnBindDialogView_containsCorrectData() {
|
||||
Settings.Global.putString(mContext.getContentResolver(),
|
||||
PrivateDnsModeDialogPreference.MODE_KEY, PRIVATE_DNS_MODE_OPPORTUNISTIC);
|
||||
Settings.Global.putString(mContext.getContentResolver(),
|
||||
PrivateDnsModeDialogPreference.HOSTNAME_KEY, HOST_NAME);
|
||||
|
||||
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
final View view = inflater.inflate(R.layout.private_dns_mode_dialog,
|
||||
new LinearLayout(mContext), false);
|
||||
mPreference.onBindDialogView(view);
|
||||
|
||||
assertThat(mPreference.mEditText.getText().toString()).isEqualTo(HOST_NAME);
|
||||
assertThat(mPreference.mRadioGroup.getCheckedRadioButtonId()).isEqualTo(
|
||||
R.id.private_dns_mode_opportunistic);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCheckedChanged_switchMode_saveButtonHasCorrectState() {
|
||||
// Set invalid hostname
|
||||
mPreference.mEditText.setText(INVALID_HOST_NAME);
|
||||
|
||||
mPreference.onCheckedChanged(null, R.id.private_dns_mode_opportunistic);
|
||||
assertThat(mSaveButton.isEnabled()).isTrue();
|
||||
|
||||
mPreference.onCheckedChanged(null, R.id.private_dns_mode_provider);
|
||||
assertThat(mSaveButton.isEnabled()).isFalse();
|
||||
|
||||
mPreference.onCheckedChanged(null, R.id.private_dns_mode_off);
|
||||
assertThat(mSaveButton.isEnabled()).isTrue();
|
||||
}
|
||||
}
|
@@ -34,7 +34,7 @@ import com.android.settings.TimeoutListPreference;
|
||||
import com.android.settings.security.trustagent.TrustAgentManager;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowDevicePolicyManagerWrapper;
|
||||
import com.android.settings.testutils.shadow.ShadowDevicePolicyManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -47,7 +47,7 @@ import org.robolectric.annotation.Config;
|
||||
import java.util.Collections;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowDevicePolicyManagerWrapper.class)
|
||||
@Config(shadows = ShadowDevicePolicyManager.class)
|
||||
public class LockAfterTimeoutPreferenceControllerTest {
|
||||
|
||||
private static final int TEST_USER_ID = 0;
|
||||
@@ -124,7 +124,7 @@ public class LockAfterTimeoutPreferenceControllerTest {
|
||||
when(mPreference.getEntryValues()).thenReturn(new CharSequence[] {"10000"});
|
||||
|
||||
Settings.System.putInt(mContext.getContentResolver(), SCREEN_OFF_TIMEOUT, displayTimeout);
|
||||
ShadowDevicePolicyManagerWrapper.setMaximumTimeToLock(userId, adminTimeout);
|
||||
ShadowDevicePolicyManager.getShadow().setMaximumTimeToLock(userId, adminTimeout);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
|
@@ -2,33 +2,35 @@ package com.android.settings.testutils.shadow;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.shadow.api.Shadow;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import org.robolectric.shadow.api.Shadow;
|
||||
|
||||
/**
|
||||
* This shadow if using {@link ShadowDevicePolicyManagerWrapper} is not possible.
|
||||
*/
|
||||
@Implements(DevicePolicyManager.class)
|
||||
public class ShadowDevicePolicyManager extends org.robolectric.shadows.ShadowDevicePolicyManager {
|
||||
|
||||
private final Map<Integer, Long> mProfileTimeouts = new HashMap<>();
|
||||
private Map<Integer, CharSequence> mSupportMessagesMap = new HashMap<>();
|
||||
private boolean mIsAdminActiveAsUser = false;
|
||||
ComponentName mDeviceOwnerComponentName;
|
||||
private int mDeviceOwnerUserId = -1;
|
||||
|
||||
public void setShortSupportMessageForUser(ComponentName admin, int userHandle, String message) {
|
||||
mSupportMessagesMap.put(Objects.hash(admin, userHandle), message);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
|
||||
public @Nullable
|
||||
CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
|
||||
int userHandle) {
|
||||
return mSupportMessagesMap.get(Objects.hash(admin, userHandle));
|
||||
}
|
||||
@@ -38,20 +40,39 @@ public class ShadowDevicePolicyManager extends org.robolectric.shadows.ShadowDev
|
||||
return mIsAdminActiveAsUser;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public int getDeviceOwnerUserId() {
|
||||
return mDeviceOwnerUserId;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public long getMaximumTimeToLock(ComponentName admin, @UserIdInt int userHandle) {
|
||||
return mProfileTimeouts.getOrDefault(userHandle, 0L);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public ComponentName getDeviceOwnerComponentOnAnyUser() {
|
||||
return mDeviceOwnerComponentName;
|
||||
}
|
||||
|
||||
public void setIsAdminActiveAsUser(boolean active) {
|
||||
mIsAdminActiveAsUser = active;
|
||||
}
|
||||
|
||||
public void setDeviceOwnerUserId(int id) {
|
||||
mDeviceOwnerUserId = id;
|
||||
}
|
||||
|
||||
public void setMaximumTimeToLock(@UserIdInt int userHandle, Long timeout) {
|
||||
mProfileTimeouts.put(userHandle, timeout);
|
||||
}
|
||||
|
||||
public void setDeviceOwnerComponentOnAnyUser(ComponentName admin) {
|
||||
mDeviceOwnerComponentName = admin;
|
||||
}
|
||||
|
||||
public static ShadowDevicePolicyManager getShadow() {
|
||||
return (ShadowDevicePolicyManager) Shadow.extract(
|
||||
RuntimeEnvironment.application.getSystemService(DevicePolicyManager.class));
|
||||
}
|
||||
|
||||
public ComponentName getDeviceOwnerComponentOnAnyUser() {
|
||||
return mDeviceOwnerComponentName;
|
||||
}
|
||||
|
||||
public void setDeviceOwnerComponentOnAnyUser(ComponentName admin) {
|
||||
mDeviceOwnerComponentName = admin;
|
||||
}
|
||||
}
|
||||
|
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.testutils.shadow;
|
||||
|
||||
import android.annotation.UserIdInt;
|
||||
import android.content.ComponentName;
|
||||
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Shadow for {@link DevicePolicyManagerWrapper} to allow stubbing hidden methods.
|
||||
*/
|
||||
@Implements(DevicePolicyManagerWrapper.class)
|
||||
public class ShadowDevicePolicyManagerWrapper {
|
||||
private static ComponentName deviceOComponentName = null;
|
||||
private static int deviceOwnerUserId = -1;
|
||||
private static final Map<Integer, Long> profileTimeouts = new HashMap<>();
|
||||
|
||||
@Implementation
|
||||
public ComponentName getDeviceOwnerComponentOnAnyUser() {
|
||||
return deviceOComponentName;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public int getDeviceOwnerUserId() {
|
||||
return deviceOwnerUserId;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public long getMaximumTimeToLock(ComponentName admin, @UserIdInt int userHandle) {
|
||||
return profileTimeouts.getOrDefault(userHandle, 0L);
|
||||
}
|
||||
|
||||
public static void setDeviceOComponentName(ComponentName deviceOComponentName) {
|
||||
ShadowDevicePolicyManagerWrapper.deviceOComponentName = deviceOComponentName;
|
||||
}
|
||||
|
||||
public static void setDeviceOwnerUserId(int deviceOwnerUserId) {
|
||||
ShadowDevicePolicyManagerWrapper.deviceOwnerUserId = deviceOwnerUserId;
|
||||
}
|
||||
|
||||
public static void setMaximumTimeToLock(@UserIdInt int userHandle, Long timeout) {
|
||||
profileTimeouts.put(userHandle, timeout);
|
||||
}
|
||||
}
|
@@ -20,15 +20,15 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.app.WallpaperManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import com.android.settings.SubSettings;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.wrapper.WallpaperManagerWrapper;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -40,6 +40,7 @@ import org.robolectric.android.controller.ActivityController;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
import org.robolectric.shadows.ShadowActivity;
|
||||
import org.robolectric.shadows.ShadowPackageManager;
|
||||
|
||||
@@ -59,6 +60,11 @@ public class WallpaperSuggestionActivityTest {
|
||||
mController = Robolectric.buildActivity(WallpaperSuggestionActivity.class);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowWallpaperManager.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launch_primarySuggestionActivityDoesNotExist_shouldFallback() {
|
||||
ShadowPackageManager packageManager =
|
||||
@@ -74,32 +80,34 @@ public class WallpaperSuggestionActivityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wallpaperServiceEnabled_no_shouldReturnFalse() {
|
||||
public void wallpaperServiceEnabled_no_shouldReturnTrue() {
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mResources.getBoolean(com.android.internal.R.bool.config_enableWallpaperService))
|
||||
.thenReturn(false);
|
||||
|
||||
assertThat(WallpaperSuggestionActivity.isSuggestionComplete(mContext)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = WallpaperSuggestionActivityTest.ShadowWallpaperManagerWrapper.class)
|
||||
public void hasWallpaperSet_no_shouldReturnFalse() {
|
||||
ShadowWallpaperManagerWrapper.setWallpaperId(0);
|
||||
|
||||
assertThat(WallpaperSuggestionActivity.isSuggestionComplete(mContext)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = WallpaperSuggestionActivityTest.ShadowWallpaperManagerWrapper.class)
|
||||
public void hasWallpaperSet_yes_shouldReturnTrue() {
|
||||
ShadowWallpaperManagerWrapper.setWallpaperId(100);
|
||||
|
||||
assertThat(WallpaperSuggestionActivity.isSuggestionComplete(mContext)).isTrue();
|
||||
}
|
||||
|
||||
@Implements(WallpaperManagerWrapper.class)
|
||||
public static class ShadowWallpaperManagerWrapper {
|
||||
@Test
|
||||
@Config(shadows = ShadowWallpaperManager.class)
|
||||
public void hasWallpaperSet_no_shouldReturnFalse() {
|
||||
ShadowWallpaperManager.setWallpaperId(0);
|
||||
|
||||
assertThat(WallpaperSuggestionActivity.isSuggestionComplete(RuntimeEnvironment.application))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowWallpaperManager.class)
|
||||
public void hasWallpaperSet_yes_shouldReturnTrue() {
|
||||
ShadowWallpaperManager.setWallpaperId(100);
|
||||
|
||||
assertThat(WallpaperSuggestionActivity.isSuggestionComplete(RuntimeEnvironment.application))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Implements(WallpaperManager.class)
|
||||
public static class ShadowWallpaperManager {
|
||||
|
||||
private static int sWallpaperId;
|
||||
|
||||
@@ -107,13 +115,11 @@ public class WallpaperSuggestionActivityTest {
|
||||
sWallpaperId = id;
|
||||
}
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
sWallpaperId = 0;
|
||||
}
|
||||
|
||||
public void __constructor__(Context context) {
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public boolean isWallpaperServiceEnabled() {
|
||||
return true;
|
||||
|
@@ -63,7 +63,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowBidiFormatter;
|
||||
import com.android.settings.testutils.shadow.ShadowDevicePolicyManagerWrapper;
|
||||
import com.android.settings.testutils.shadow.ShadowDevicePolicyManager;
|
||||
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
|
||||
import com.android.settings.testutils.shadow.ShadowPackageManagerWrapper;
|
||||
import com.android.settings.widget.ActionButtonPreference;
|
||||
@@ -96,7 +96,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {
|
||||
ShadowDevicePolicyManagerWrapper.class,
|
||||
ShadowDevicePolicyManager.class,
|
||||
ShadowEntityHeaderController.class,
|
||||
ShadowPackageManagerWrapper.class,
|
||||
ShadowBidiFormatter.class
|
||||
@@ -693,8 +693,8 @@ public class WifiDetailPreferenceControllerTest {
|
||||
mockWifiConfig.creatorUid = doUid;
|
||||
ComponentName doComponent = new ComponentName(doPackage, "some.Class");
|
||||
ShadowPackageManagerWrapper.setPackageUidAsUser(doPackage, doUserId, doUid);
|
||||
ShadowDevicePolicyManagerWrapper.setDeviceOComponentName(doComponent);
|
||||
ShadowDevicePolicyManagerWrapper.setDeviceOwnerUserId(doUserId);
|
||||
ShadowDevicePolicyManager.getShadow().setDeviceOwnerComponentOnAnyUser(doComponent);
|
||||
ShadowDevicePolicyManager.getShadow().setDeviceOwnerUserId(doUserId);
|
||||
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN, 1);
|
||||
@@ -840,6 +840,7 @@ public class WifiDetailPreferenceControllerTest {
|
||||
verify(mockAccessPoint, times(2)).getLevel();
|
||||
verify(mockIconInjector, times(1)).getIcon(anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefreshRssiViews_shouldUpdateOnLevelChange() {
|
||||
displayAndResume();
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.deviceinfo.storage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
@@ -31,11 +30,11 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.net.TrafficStats;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.android.settings.wrapper.UserManagerWrapper;
|
||||
import com.android.settingslib.applications.StorageStatsSource;
|
||||
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||
|
||||
@@ -65,7 +64,7 @@ public class StorageAsyncLoaderTest {
|
||||
@Mock
|
||||
private PackageManagerWrapper mPackageManager;
|
||||
@Mock
|
||||
private UserManagerWrapper mUserManager;
|
||||
private UserManager mUserManager;
|
||||
private List<ApplicationInfo> mInfo = new ArrayList<>();
|
||||
private List<UserInfo> mUsers;
|
||||
|
||||
|
Reference in New Issue
Block a user