diff --git a/res/raw/lottie_power_menu.json b/res/raw/lottie_long_press_power_for_assistant.json
similarity index 100%
rename from res/raw/lottie_power_menu.json
rename to res/raw/lottie_long_press_power_for_assistant.json
diff --git a/res/raw/lottie_long_press_power_for_power_menu.json b/res/raw/lottie_long_press_power_for_power_menu.json
new file mode 100644
index 00000000000..09e2f0a1199
--- /dev/null
+++ b/res/raw/lottie_long_press_power_for_power_menu.json
@@ -0,0 +1 @@
+{"v":"5.9.0","fr":60,"ip":0,"op":241,"w":412,"h":300,"nm":"Home Button_Digital Assistant_LPP","ddd":0,"assets":[{"id":"comp_0","nm":"Power menu","fr":60,"layers":[{"ddd":0,"ind":1,"ty":4,"nm":".grey200","cl":"grey200","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[24,24,0],"ix":2,"l":2},"a":{"a":0,"k":[24,24,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[1.293,1.1],[0,0],[0,-1.46],[2.58,0],[0,2.58],[-1.047,0.853],[0,0],[0,-1.826],[-3.313,0],[0,3.314]],"o":[[0,0],[1.054,0.846],[0,2.58],[-2.58,0],[0,-1.46],[0,0],[-1.294,1.1],[0,3.314],[3.314,0],[0,-1.826]],"v":[[3.887,-4.553],[2.94,-3.606],[4.667,0],[0,4.667],[-4.666,0],[-2.946,-3.613],[-3.886,-4.553],[-6,0],[0,6],[6,0]],"c":true},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ind":1,"ty":"sh","ix":2,"ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0]],"v":[[0.667,-6],[-0.666,-6],[-0.666,0.667],[0.667,0.667]],"c":true},"ix":2},"nm":"Path 2","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"mm","mm":1,"nm":"Merge Paths 1","mn":"ADBE Vector Filter - Merge","hd":false},{"ty":"fl","c":{"a":0,"k":[0.909803921569,0.917647058824,0.929411764706,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[24,24],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 1","np":6,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":900,"st":0,"bm":0},{"ddd":0,"ind":2,"ty":4,"nm":".grey800","cl":"grey800","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[24,24,0],"ix":2,"l":2},"a":{"a":0,"k":[24,24,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[-9.941,0],[0,-9.941],[9.941,0],[0,9.941]],"o":[[9.941,0],[0,9.941],[-9.941,0],[0,-9.941]],"v":[[0,-18],[18,0],[0,18],[-18,0]],"c":true},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.235294117647,0.250980392157,0.262745098039,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[24,24],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 5","np":4,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false},{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[-9.941,0],[0,-9.941],[9.941,0],[0,9.941]],"o":[[9.941,0],[0,9.941],[-9.941,0],[0,-9.941]],"v":[[0,-18],[18,0],[0,18],[-18,0]],"c":true},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.235294117647,0.250980392157,0.262745098039,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[24,68],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 4","np":4,"cix":2,"bm":0,"ix":2,"mn":"ADBE Vector Group","hd":false},{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[-9.941,0],[0,-9.941],[9.941,0],[0,9.941]],"o":[[9.941,0],[0,9.941],[-9.941,0],[0,-9.941]],"v":[[0,-18],[18,0],[0,18],[-18,0]],"c":true},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.235294117647,0.250980392157,0.262745098039,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[68,24],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 3","np":4,"cix":2,"bm":0,"ix":3,"mn":"ADBE Vector Group","hd":false},{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[-9.941,0],[0,-9.941],[9.941,0],[0,9.941]],"o":[[9.941,0],[0,9.941],[-9.941,0],[0,-9.941]],"v":[[0,-18],[18,0],[0,18],[-18,0]],"c":true},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.235294117647,0.250980392157,0.262745098039,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[68,68],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 2","np":4,"cix":2,"bm":0,"ix":4,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":900,"st":0,"bm":0},{"ddd":0,"ind":3,"ty":4,"nm":".grey900","cl":"grey900","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[46,46,0],"ix":2,"l":2},"a":{"a":0,"k":[46,46,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[-6.627,0],[0,0],[0,-6.627],[0,0],[6.627,0],[0,0],[0,6.627],[0,0]],"o":[[0,0],[6.627,0],[0,0],[0,6.627],[0,0],[-6.627,0],[0,0],[0,-6.627]],"v":[[-34,-46],[34,-46],[46,-34],[46,34],[34,46],[-34,46],[-46,34],[-46,-34]],"c":true},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.125490196078,0.129411764706,0.141176470588,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[46,46],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 6","np":4,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":900,"st":0,"bm":0}]}],"layers":[{"ddd":0,"ind":8,"ty":3,"nm":"Null 7","sr":1,"ks":{"o":{"a":0,"k":0,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[206,264.875,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[10,10,100],"ix":6,"l":2}},"ao":0,"ip":0,"op":1500,"st":0,"bm":0},{"ddd":0,"ind":15,"ty":0,"nm":"Power menu","refId":"comp_0","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":89,"s":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":120,"s":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":190,"s":[100]},{"t":210,"s":[0]}],"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":1,"k":[{"i":{"x":0,"y":1},"o":{"x":0.2,"y":0},"t":80,"s":[206,175,0],"to":[0,-4.167,0],"ti":[0,4.167,0]},{"i":{"x":0.3,"y":0.3},"o":{"x":0.167,"y":0.167},"t":120,"s":[206,150,0],"to":[0,0,0],"ti":[0,0,0]},{"i":{"x":0.999,"y":1},"o":{"x":0.3,"y":0},"t":190,"s":[206,150,0],"to":[0,4.167,0],"ti":[0,-4.167,0]},{"t":230,"s":[206,175,0]}],"ix":2,"l":2},"a":{"a":0,"k":[46,46,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"w":92,"h":92,"ip":80,"op":980,"st":80,"bm":0},{"ddd":0,"ind":30,"ty":4,"nm":".grey300","cl":"grey300","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[206,150,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[5.243,0],[0,0],[0,5.244],[0,0],[-5.243,0],[0,0],[0,-5.244]],"o":[[0,5.244],[0,0],[-5.243,0],[0,0],[0,-5.244],[0,0],[5.243,0],[0,0]],"v":[[64.188,114.112],[54.679,123.622],[-54.679,123.622],[-64.188,114.112],[-64.188,-114.112],[-54.679,-123.622],[54.679,-123.622],[64.188,-114.112]],"c":true},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ind":1,"ty":"sh","ix":2,"ks":{"a":0,"k":{"i":[[0,0],[6.554,0],[0,0],[0,-6.555],[0,0],[-6.554,0],[0,0],[0,6.555],[0,0],[0,1.313],[0,0],[1.313,0]],"o":[[0,-6.555],[0,0],[-6.554,0],[0,0],[0,6.555],[0,0],[6.554,0],[0,0],[1.313,0],[0,0],[0,-1.313],[0,0]],"v":[[66.566,-114.112],[54.679,-126],[-54.679,-126],[-66.566,-114.112],[-66.566,114.112],[-54.679,126],[54.679,126],[66.566,114.112],[66.566,-2.378],[68.943,-4.755],[68.943,-28.528],[66.566,-30.906]],"c":true},"ix":2},"nm":"Path 2","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.854901969433,0.86274510622,0.878431379795,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 2","np":3,"cix":2,"bm":0,"ix":2,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":1500,"st":0,"bm":0},{"ddd":0,"ind":31,"ty":4,"nm":".grey300","cl":"grey300","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"s":true,"x":{"a":1,"k":[{"i":{"x":[0.605],"y":[0.583]},"o":{"x":[0.36],"y":[0]},"t":40,"s":[206]},{"i":{"x":[0.635],"y":[0.851]},"o":{"x":[0.314],"y":[3.484]},"t":60,"s":[205.339]},{"i":{"x":[0.456],"y":[1]},"o":{"x":[0.665],"y":[-0.02]},"t":119.92,"s":[205.15]},{"t":139.919921875,"s":[206]}],"ix":3},"y":{"a":0,"k":150,"ix":4}},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,1.313],[0,0],[1.313,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,-1.313],[0,0],[0,0],[0,0],[1.313,0]],"v":[[68.943,-52.302],[68.943,-61.811],[66.566,-64.188],[65.456,-64.188],[65.55,-49.906],[66.566,-49.924]],"c":true},"ix":2},"nm":"Path 3","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.854901969433,0.86274510622,0.878431379795,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 1","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":1500,"st":0,"bm":0},{"ddd":0,"ind":32,"ty":4,"nm":".grey400","cl":"grey400","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[206,150,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[5.243,0],[0,0],[0,5.244],[0,0],[-5.243,0],[0,0],[0,-5.244]],"o":[[0,5.244],[0,0],[-5.243,0],[0,0],[0,-5.244],[0,0],[5.243,0],[0,0]],"v":[[64.188,114.112],[54.679,123.622],[-54.679,123.622],[-64.188,114.112],[-64.188,-114.112],[-54.679,-123.622],[54.679,-123.622],[64.188,-114.112]],"c":true},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.741176486015,0.75686275959,0.776470601559,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 1","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":1500,"st":0,"bm":0},{"ddd":0,"ind":33,"ty":4,"nm":"Gesture Tap","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[273.205,92.869,0],"ix":2,"l":2},"a":{"a":0,"k":[273.205,92.869,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,-5.226],[-5.226,0],[0,5.226],[5.226,0]],"o":[[0,5.226],[5.226,0],[0,-5.226],[-5.226,0]],"v":[[-9.463,0],[0,9.463],[9.463,0],[0,-9.463]],"c":true},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.40000000596,0.615686297417,0.964705884457,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[273.205,92.869],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":1,"k":[{"i":{"x":[0.239,0.239],"y":[0.604,0.604]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"t":35,"s":[13,13]},{"i":{"x":[0.596,0.596],"y":[1,1]},"o":{"x":[0.182,0.182],"y":[0.996,0.996]},"t":55,"s":[100,100]},{"i":{"x":[0.833,0.833],"y":[0.833,0.833]},"o":{"x":[0.793,0.793],"y":[0,0]},"t":124.92,"s":[129,129]},{"t":139.919921875,"s":[13,13]}],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 1","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false},{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,-8.26],[-8.26,0],[0,8.26],[8.26,0]],"o":[[0,8.26],[8.26,0],[0,-8.26],[-8.26,0]],"v":[[-14.957,0],[0,14.957],[14.957,0],[0,-14.957]],"c":true},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.68235296011,0.796078443527,0.980392158031,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[273.205,92.869],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":1,"k":[{"i":{"x":[0.304,0.304],"y":[0.758,0.758]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"t":30,"s":[13,13]},{"i":{"x":[0.709,0.709],"y":[0.99,0.99]},"o":{"x":[0.196,0.196],"y":[1.618,1.618]},"t":50,"s":[100,100]},{"i":{"x":[0.833,0.833],"y":[0.833,0.833]},"o":{"x":[0.609,0.609],"y":[-0.001,-0.001]},"t":125,"s":[113.775,113.775]},{"t":140,"s":[8,8]}],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 2","np":2,"cix":2,"bm":0,"ix":2,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":1500,"st":0,"bm":0}],"markers":[]}
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 42b121c65c4..9f8df7b6467 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -12743,7 +12743,7 @@
Mute
- To enable, first change \"Press and hold power button\" to the power menu.
+ To enable, first change \"Press & hold power button\" to the power menu.
Network details
@@ -13502,29 +13502,28 @@
cards & passes
-
- Press and hold power button
+
+ Press & hold power button
-
- Press and hold for the Assistant
-
- Press and hold for the power menu
-
- Press and hold disabled
+
+ Press & hold power button to access
+
+ Power menu
+
+ Digital assistant
+
+
+ Access digital assistant
+
+ Access power menu
To use, first set a screen lock
-
- Hold for Assistant
-
-
- Trigger the Assistant by holding the power button
-
-
- Power & Emergency Menu:\nPress Power and Volume up at the same time.
+
+ Power menu:\nPress the power button and the volume up button at the same time
- Prevent ringing:\nShortcut available in the volume menu.
+ Prevent ringing:\nPress a volume button for the shortcut
Press & hold duration
diff --git a/res/xml/power_menu_settings.xml b/res/xml/power_menu_settings.xml
index e5e2daa7492..48cc40c0bd4 100644
--- a/res/xml/power_menu_settings.xml
+++ b/res/xml/power_menu_settings.xml
@@ -23,19 +23,28 @@
android:key="gesture_power_menu_video"
settings:searchable="false"
settings:lottie_imageAssetsFolder="power_menu"
- settings:lottie_rawRes="@raw/lottie_power_menu"/>
+ settings:lottie_rawRes="@raw/lottie_long_press_power_for_power_menu"
+ settings:controller="com.android.settings.gestures.LongPressPowerIllustrationPreferenceController"/>
-
+
+
+
+
+
+ settings:searchable="false"
+ settings:controller="com.android.settings.gestures.LongPressPowerFooterPreferenceController"/>
diff --git a/src/com/android/settings/accessibility/ToggleScreenReaderPreferenceFragmentForSetupWizard.java b/src/com/android/settings/accessibility/ToggleScreenReaderPreferenceFragmentForSetupWizard.java
index 0af8aa17524..f9a1113c054 100644
--- a/src/com/android/settings/accessibility/ToggleScreenReaderPreferenceFragmentForSetupWizard.java
+++ b/src/com/android/settings/accessibility/ToggleScreenReaderPreferenceFragmentForSetupWizard.java
@@ -49,8 +49,6 @@ public class ToggleScreenReaderPreferenceFragmentForSetupWizard
if (mTopIntroPreference != null) {
mTopIntroPreference.setVisible(false);
}
-
- mToggleServiceSwitchPreference.applyPartnerCustomizationPaddingStyle();
}
@Override
diff --git a/src/com/android/settings/gestures/LongPressPowerButtonPreferenceController.java b/src/com/android/settings/gestures/LongPressPowerButtonPreferenceController.java
deleted file mode 100644
index 82766dba150..00000000000
--- a/src/com/android/settings/gestures/LongPressPowerButtonPreferenceController.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Copyright (C) 2021 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.gestures;
-
-import static com.android.settings.gestures.PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE;
-import static com.android.settings.gestures.PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS;
-import static com.android.settings.gestures.PowerMenuSettingsUtils.POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE;
-import static com.android.settings.gestures.PowerMenuSettingsUtils.POWER_BUTTON_LONG_PRESS_SETTING;
-
-import android.content.Context;
-import android.provider.Settings;
-
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
-import com.android.internal.annotations.VisibleForTesting;
-import com.android.settings.R;
-import com.android.settings.core.TogglePreferenceController;
-
-import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
-
-/**
- * Configures the behaviour of long press power button action.
- */
-public class LongPressPowerButtonPreferenceController extends TogglePreferenceController {
-
- private static final String KEY_CHORD_POWER_VOLUME_UP_SETTING =
- Settings.Global.KEY_CHORD_POWER_VOLUME_UP;
-
- private static final String FOOTER_HINT_KEY = "power_menu_power_volume_up_hint";
- private static final String ASSIST_SWITCH_KEY = "gesture_power_menu_long_press_for_assist";
-
- /**
- * Values used for volume key chord behaviour when Assist setting is enabled.
- *
- * Values based on config_keyChordPowerVolumeUp in
- * frameworks/base/core/res/res/values/config.xml
- */
- @VisibleForTesting
- static final int KEY_CHORD_POWER_VOLUME_UP_NO_ACTION = 0;
- @VisibleForTesting
- static final int KEY_CHORD_POWER_VOLUME_UP_MUTE_TOGGLE = 1;
- @VisibleForTesting
- static final int KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS = 2;
-
- private static final int KEY_CHORD_POWER_VOLUME_UP_DEFAULT_VALUE_RESOURCE =
- com.android.internal.R.integer.config_keyChordPowerVolumeUp;
-
- @MonotonicNonNull
- @VisibleForTesting
- Preference mFooterHint;
-
- @MonotonicNonNull
- @VisibleForTesting
- Preference mAssistSwitch;
-
- public LongPressPowerButtonPreferenceController(Context context, String key) {
- super(context, key);
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- mFooterHint = screen.findPreference(FOOTER_HINT_KEY);
- mAssistSwitch = screen.findPreference(ASSIST_SWITCH_KEY);
- refreshStateDisplay();
- }
-
- @Override
- public CharSequence getSummary() {
- final int powerButtonValue = PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext);
- if (powerButtonValue == LONG_PRESS_POWER_ASSISTANT_VALUE) {
- return mContext.getString(R.string.power_menu_summary_long_press_for_assist_enabled);
- } else if (powerButtonValue == LONG_PRESS_POWER_GLOBAL_ACTIONS) {
- return mContext.getString(
- R.string.power_menu_summary_long_press_for_assist_disabled_with_power_menu);
- } else {
- return mContext.getString(
- R.string.power_menu_summary_long_press_for_assist_disabled_no_action);
- }
- }
-
- @Override
- public int getAvailabilityStatus() {
- final boolean enabled = mContext.getResources().getBoolean(
- com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable);
- return enabled ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
- }
-
- @Override
- public boolean isChecked() {
- return PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext);
- }
-
- @Override
- public boolean setChecked(boolean isChecked) {
- if (setPowerLongPressValue(isChecked)) {
- // The key chord value is dependant on the long press setting and it always
- // toggled in tandem. POWER_BUTTON_LONG_PRESS_SETTING is always the source
- // of truth for both.
- setPowerVolumeChordValue(isChecked);
- refreshStateDisplay();
- return true;
- }
-
- return false;
- }
-
- @Override
- public int getSliceHighlightMenuRes() {
- return R.string.menu_key_system;
- }
-
- private void refreshStateDisplay() {
- if (mAssistSwitch != null) {
- mAssistSwitch.setSummary(getSummary());
- }
-
- if (mFooterHint != null) {
- String footerHintText = mContext.getString(R.string.power_menu_power_volume_up_hint);
- // If the device supports hush gesture, we need to notify the user where to find
- // the setting.
- if (mContext.getResources().getBoolean(
- com.android.internal.R.bool.config_volumeHushGestureEnabled)) {
- footerHintText = footerHintText + "\n\n" + mContext.getString(
- R.string.power_menu_power_prevent_ringing_hint);
- }
-
- mFooterHint.setSummary(footerHintText);
- mFooterHint.setVisible(isPowerMenuKeyChordEnabled(mContext));
- }
- }
-
- private static boolean isPowerMenuKeyChordEnabled(Context context) {
- return Settings.Global.getInt(context.getContentResolver(),
- KEY_CHORD_POWER_VOLUME_UP_SETTING,
- context.getResources().getInteger(
- com.android.internal.R.integer.config_keyChordPowerVolumeUp))
- == KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS;
- }
-
- private boolean setPowerLongPressValue(boolean isChecked) {
- if (isChecked) {
- return Settings.Global.putInt(mContext.getContentResolver(),
- POWER_BUTTON_LONG_PRESS_SETTING, LONG_PRESS_POWER_ASSISTANT_VALUE);
- }
-
- // We need to determine the right disabled value based on the device default
- // for long-press power.
-
- // If the default is to start the assistant, then the fallback is GlobalActions.
- final int defaultPowerButtonValue = mContext.getResources().getInteger(
- POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE);
- if (defaultPowerButtonValue == LONG_PRESS_POWER_ASSISTANT_VALUE) {
- return Settings.Global.putInt(mContext.getContentResolver(),
- POWER_BUTTON_LONG_PRESS_SETTING, LONG_PRESS_POWER_GLOBAL_ACTIONS);
- }
-
- // If the default is something different than Assist, we use that default.
- return Settings.Global.putInt(mContext.getContentResolver(),
- POWER_BUTTON_LONG_PRESS_SETTING, defaultPowerButtonValue);
- }
-
- /**
- * Updates {@link Settings.Global.KEY_CHORD_POWER_VOLUME_UP} based on the changed value of
- * {@link #POWER_BUTTON_LONG_PRESS_SETTING}. If power button is used for Assist, key chord
- * should show the power menu.
- */
- private boolean setPowerVolumeChordValue(boolean isPowerButtonLongPressChecked) {
- if (isPowerButtonLongPressChecked) {
- return Settings.Global.putInt(mContext.getContentResolver(),
- KEY_CHORD_POWER_VOLUME_UP_SETTING, KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS);
- }
-
- // We restore key chord to the default value.
- int keyChordDefaultValue = mContext.getResources().getInteger(
- KEY_CHORD_POWER_VOLUME_UP_DEFAULT_VALUE_RESOURCE);
- return Settings.Global.putInt(mContext.getContentResolver(),
- KEY_CHORD_POWER_VOLUME_UP_SETTING, keyChordDefaultValue);
- }
-
-}
diff --git a/src/com/android/settings/gestures/LongPressPowerFooterPreferenceController.java b/src/com/android/settings/gestures/LongPressPowerFooterPreferenceController.java
new file mode 100644
index 00000000000..b4f6def4a4b
--- /dev/null
+++ b/src/com/android/settings/gestures/LongPressPowerFooterPreferenceController.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2022 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.gestures;
+
+import android.content.Context;
+import android.net.Uri;
+import android.text.TextUtils;
+
+import androidx.lifecycle.Lifecycle;
+import androidx.lifecycle.LifecycleObserver;
+import androidx.lifecycle.OnLifecycleEvent;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+
+/** Configures the behaviour of long press power footer. */
+public class LongPressPowerFooterPreferenceController extends BasePreferenceController
+ implements PowerMenuSettingsUtils.SettingsStateCallback, LifecycleObserver {
+
+ private Preference mPreference;
+ private final PowerMenuSettingsUtils mUtils;
+
+ public LongPressPowerFooterPreferenceController(Context context, String key) {
+ super(context, key);
+ mUtils = new PowerMenuSettingsUtils(context);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+
+ CharSequence footerHintText = mContext.getString(R.string.power_menu_power_volume_up_hint);
+ // If the device supports hush gesture, we need to tell the user where to find the setting.
+ if (mContext.getResources()
+ .getBoolean(com.android.internal.R.bool.config_volumeHushGestureEnabled)) {
+ footerHintText =
+ TextUtils.concat(
+ footerHintText,
+ "\n\n",
+ mContext.getString(R.string.power_menu_power_prevent_ringing_hint));
+ }
+
+ preference.setSummary(footerHintText);
+ preference.setVisible(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext));
+ }
+
+ @Override
+ public void onChange(Uri uri) {
+ if (mPreference != null) {
+ updateState(mPreference);
+ }
+ }
+
+ /** @OnLifecycleEvent(Lifecycle.Event.ON_START) */
+ @OnLifecycleEvent(Lifecycle.Event.ON_START)
+ public void onStart() {
+ mUtils.registerObserver(this);
+ }
+
+ /** @OnLifecycleEvent(Lifecycle.Event.ON_STOP) */
+ @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
+ public void onStop() {
+ mUtils.unregisterObserver();
+ }
+}
diff --git a/src/com/android/settings/gestures/LongPressPowerForAssistantPreferenceController.java b/src/com/android/settings/gestures/LongPressPowerForAssistantPreferenceController.java
new file mode 100644
index 00000000000..4a0ad74a7ef
--- /dev/null
+++ b/src/com/android/settings/gestures/LongPressPowerForAssistantPreferenceController.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2022 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.gestures;
+
+import android.content.Context;
+import android.net.Uri;
+
+import androidx.lifecycle.Lifecycle;
+import androidx.lifecycle.LifecycleObserver;
+import androidx.lifecycle.OnLifecycleEvent;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.widget.SelectorWithWidgetPreference;
+
+/**
+ * Configures the behaviour of the radio selector to configure long press power button to Assistant.
+ */
+public class LongPressPowerForAssistantPreferenceController extends BasePreferenceController
+ implements PowerMenuSettingsUtils.SettingsStateCallback,
+ SelectorWithWidgetPreference.OnClickListener,
+ LifecycleObserver {
+
+ private SelectorWithWidgetPreference mPreference;
+ private final PowerMenuSettingsUtils mUtils;
+
+ public LongPressPowerForAssistantPreferenceController(Context context, String key) {
+ super(context, key);
+ mUtils = new PowerMenuSettingsUtils(context);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)
+ ? AVAILABLE
+ : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(getPreferenceKey());
+ if (mPreference != null) {
+ mPreference.setOnClickListener(this);
+ }
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ if (preference instanceof SelectorWithWidgetPreference) {
+ ((SelectorWithWidgetPreference) preference)
+ .setChecked(
+ PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext));
+ }
+ }
+
+ @Override
+ public void onRadioButtonClicked(SelectorWithWidgetPreference preference) {
+ PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
+ if (mPreference != null) {
+ updateState(mPreference);
+ }
+ }
+
+ @Override
+ public void onChange(Uri uri) {
+ if (mPreference != null) {
+ updateState(mPreference);
+ }
+ }
+
+ /** @OnLifecycleEvent(Lifecycle.Event.ON_START) */
+ @OnLifecycleEvent(Lifecycle.Event.ON_START)
+ public void onStart() {
+ mUtils.registerObserver(this);
+ }
+
+ /** @OnLifecycleEvent(Lifecycle.Event.ON_STOP) */
+ @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
+ public void onStop() {
+ mUtils.unregisterObserver();
+ }
+}
diff --git a/src/com/android/settings/gestures/LongPressPowerForPowerMenuPreferenceController.java b/src/com/android/settings/gestures/LongPressPowerForPowerMenuPreferenceController.java
new file mode 100644
index 00000000000..c11f0e4fec7
--- /dev/null
+++ b/src/com/android/settings/gestures/LongPressPowerForPowerMenuPreferenceController.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2022 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.gestures;
+
+import android.content.Context;
+import android.net.Uri;
+
+import androidx.lifecycle.Lifecycle;
+import androidx.lifecycle.LifecycleObserver;
+import androidx.lifecycle.OnLifecycleEvent;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.widget.SelectorWithWidgetPreference;
+
+/**
+ * Configures the behaviour of the radio selector to configure long press power button to Power
+ * Menu.
+ */
+public class LongPressPowerForPowerMenuPreferenceController extends BasePreferenceController
+ implements PowerMenuSettingsUtils.SettingsStateCallback,
+ SelectorWithWidgetPreference.OnClickListener,
+ LifecycleObserver {
+
+ private SelectorWithWidgetPreference mPreference;
+ private final PowerMenuSettingsUtils mUtils;
+
+ public LongPressPowerForPowerMenuPreferenceController(Context context, String key) {
+ super(context, key);
+ mUtils = new PowerMenuSettingsUtils(context);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)
+ ? AVAILABLE
+ : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(getPreferenceKey());
+ if (mPreference != null) {
+ mPreference.setOnClickListener(this);
+ }
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ if (preference instanceof SelectorWithWidgetPreference) {
+ ((SelectorWithWidgetPreference) preference)
+ .setChecked(
+ !PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext));
+ }
+ }
+
+ @Override
+ public void onRadioButtonClicked(SelectorWithWidgetPreference preference) {
+ PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
+ if (mPreference != null) {
+ updateState(mPreference);
+ }
+ }
+
+ @Override
+ public void onChange(Uri uri) {
+ if (mPreference != null) {
+ updateState(mPreference);
+ }
+ }
+
+ /** @OnLifecycleEvent(Lifecycle.Event.ON_START) */
+ @OnLifecycleEvent(Lifecycle.Event.ON_START)
+ public void onStart() {
+ mUtils.registerObserver(this);
+ }
+
+ /** @OnLifecycleEvent(Lifecycle.Event.ON_STOP) */
+ @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
+ public void onStop() {
+ mUtils.unregisterObserver();
+ }
+}
diff --git a/src/com/android/settings/gestures/LongPressPowerIllustrationPreferenceController.java b/src/com/android/settings/gestures/LongPressPowerIllustrationPreferenceController.java
new file mode 100644
index 00000000000..b3db9e78b16
--- /dev/null
+++ b/src/com/android/settings/gestures/LongPressPowerIllustrationPreferenceController.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2022 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.gestures;
+
+import android.content.Context;
+import android.net.Uri;
+
+import androidx.lifecycle.Lifecycle;
+import androidx.lifecycle.LifecycleObserver;
+import androidx.lifecycle.OnLifecycleEvent;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.widget.IllustrationPreference;
+
+/** Configures the behaviour of long press power illustration. */
+public class LongPressPowerIllustrationPreferenceController extends BasePreferenceController
+ implements PowerMenuSettingsUtils.SettingsStateCallback, LifecycleObserver {
+
+ private IllustrationPreference mIllustrationPreference;
+ private final PowerMenuSettingsUtils mUtils;
+
+ public LongPressPowerIllustrationPreferenceController(Context context, String key) {
+ super(context, key);
+ mUtils = new PowerMenuSettingsUtils(context);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mIllustrationPreference = screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+
+ ((IllustrationPreference) preference)
+ .setLottieAnimationResId(
+ PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)
+ ? R.raw.lottie_long_press_power_for_assistant
+ : R.raw.lottie_long_press_power_for_power_menu);
+ }
+
+ @Override
+ public void onChange(Uri uri) {
+ if (mIllustrationPreference != null) {
+ updateState(mIllustrationPreference);
+ }
+ }
+
+ /** @OnLifecycleEvent(Lifecycle.Event.ON_START) */
+ @OnLifecycleEvent(Lifecycle.Event.ON_START)
+ public void onStart() {
+ mUtils.registerObserver(this);
+ }
+
+ /** @OnLifecycleEvent(Lifecycle.Event.ON_STOP) */
+ @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
+ public void onStop() {
+ mUtils.unregisterObserver();
+ }
+}
diff --git a/src/com/android/settings/gestures/LongPressPowerSensitivityPreferenceController.java b/src/com/android/settings/gestures/LongPressPowerSensitivityPreferenceController.java
index a1d681cd475..6df4d72c8b0 100644
--- a/src/com/android/settings/gestures/LongPressPowerSensitivityPreferenceController.java
+++ b/src/com/android/settings/gestures/LongPressPowerSensitivityPreferenceController.java
@@ -17,37 +17,28 @@
package com.android.settings.gestures;
import android.content.Context;
-import android.database.ContentObserver;
-import android.os.Handler;
+import android.net.Uri;
import android.provider.Settings;
import androidx.annotation.Nullable;
+import androidx.lifecycle.Lifecycle;
+import androidx.lifecycle.LifecycleObserver;
+import androidx.lifecycle.OnLifecycleEvent;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.core.SliderPreferenceController;
import com.android.settings.widget.LabeledSeekBarPreference;
-import com.android.settingslib.core.lifecycle.LifecycleObserver;
-import com.android.settingslib.core.lifecycle.events.OnStart;
-import com.android.settingslib.core.lifecycle.events.OnStop;
/** Handles changes to the long press power button sensitivity slider. */
-public class LongPressPowerSensitivityPreferenceController extends
- SliderPreferenceController implements
- LifecycleObserver, OnStart, OnStop {
-
- private final ContentObserver mPowerButtonObserver = new ContentObserver(Handler.getMain()) {
- @Override
- public void onChange(boolean selfChange) {
- if (mPreference != null) {
- updateState(mPreference);
- }
- }
- };
+public class LongPressPowerSensitivityPreferenceController extends SliderPreferenceController
+ implements PowerMenuSettingsUtils.SettingsStateCallback, LifecycleObserver {
@Nullable
private final int[] mSensitivityValues;
+ private final PowerMenuSettingsUtils mUtils;
+
@Nullable
private LabeledSeekBarPreference mPreference;
@@ -55,18 +46,19 @@ public class LongPressPowerSensitivityPreferenceController extends
super(context, preferenceKey);
mSensitivityValues = context.getResources().getIntArray(
com.android.internal.R.array.config_longPressOnPowerDurationSettings);
+ mUtils = new PowerMenuSettingsUtils(context);
}
- @Override
+ /** @OnLifecycleEvent(Lifecycle.Event.ON_START) */
+ @OnLifecycleEvent(Lifecycle.Event.ON_START)
public void onStart() {
- mContext.getContentResolver().registerContentObserver(
- Settings.Global.getUriFor(PowerMenuSettingsUtils.POWER_BUTTON_LONG_PRESS_SETTING),
- false, mPowerButtonObserver);
+ mUtils.registerObserver(this);
}
- @Override
+ /** @OnLifecycleEvent(Lifecycle.Event.ON_STOP) */
+ @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
public void onStop() {
- mContext.getContentResolver().unregisterContentObserver(mPowerButtonObserver);
+ mUtils.unregisterObserver();
}
@Override
@@ -86,21 +78,19 @@ public class LongPressPowerSensitivityPreferenceController extends
public void updateState(Preference preference) {
super.updateState(preference);
final LabeledSeekBarPreference pref = (LabeledSeekBarPreference) preference;
- pref.setEnabled(
- isAvailable() && PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext));
+ pref.setVisible(
+ PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)
+ && getAvailabilityStatus() == AVAILABLE);
pref.setProgress(getSliderPosition());
}
@Override
public int getAvailabilityStatus() {
- if (mSensitivityValues == null || mSensitivityValues.length < 2) {
+ if (mSensitivityValues == null
+ || mSensitivityValues.length < 2
+ || !PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)) {
return UNSUPPORTED_ON_DEVICE;
}
-
- if (!PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)) {
- return DISABLED_DEPENDENT_SETTING;
- }
-
return AVAILABLE;
}
@@ -120,6 +110,13 @@ public class LongPressPowerSensitivityPreferenceController extends
mSensitivityValues[position]);
}
+ @Override
+ public void onChange(Uri uri) {
+ if (mPreference != null) {
+ updateState(mPreference);
+ }
+ }
+
@Override
public int getMax() {
if (mSensitivityValues == null || mSensitivityValues.length == 0) {
diff --git a/src/com/android/settings/gestures/PowerMenuPreferenceController.java b/src/com/android/settings/gestures/PowerMenuPreferenceController.java
index b4f97aa3ff2..599dd18b9d3 100644
--- a/src/com/android/settings/gestures/PowerMenuPreferenceController.java
+++ b/src/com/android/settings/gestures/PowerMenuPreferenceController.java
@@ -16,9 +16,6 @@
package com.android.settings.gestures;
-import static com.android.settings.gestures.PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE;
-import static com.android.settings.gestures.PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS;
-
import android.content.Context;
import com.android.settings.R;
@@ -32,25 +29,17 @@ public class PowerMenuPreferenceController extends BasePreferenceController {
@Override
public CharSequence getSummary() {
- final int powerButtonValue = PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext);
- if (powerButtonValue == LONG_PRESS_POWER_ASSISTANT_VALUE) {
- return mContext.getText(R.string.power_menu_summary_long_press_for_assist_enabled);
- } else if (powerButtonValue == LONG_PRESS_POWER_GLOBAL_ACTIONS) {
- return mContext.getText(
- R.string.power_menu_summary_long_press_for_assist_disabled_with_power_menu);
+ if (PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)) {
+ return mContext.getText(R.string.power_menu_summary_long_press_for_assistant);
} else {
- return mContext.getText(
- R.string.power_menu_summary_long_press_for_assist_disabled_no_action);
+ return mContext.getText(R.string.power_menu_summary_long_press_for_power_menu);
}
}
@Override
public int getAvailabilityStatus() {
- return isAssistInvocationAvailable() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
- }
-
- private boolean isAssistInvocationAvailable() {
- return mContext.getResources().getBoolean(
- com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable);
+ return PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)
+ ? AVAILABLE
+ : UNSUPPORTED_ON_DEVICE;
}
}
diff --git a/src/com/android/settings/gestures/PowerMenuSettingsUtils.java b/src/com/android/settings/gestures/PowerMenuSettingsUtils.java
index 444b7c1e565..b1103811749 100644
--- a/src/com/android/settings/gestures/PowerMenuSettingsUtils.java
+++ b/src/com/android/settings/gestures/PowerMenuSettingsUtils.java
@@ -16,53 +16,163 @@
package com.android.settings.gestures;
+import android.content.ContentResolver;
import android.content.Context;
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.os.Handler;
+import android.os.Looper;
import android.provider.Settings;
/** Common code for long press power settings shared between controllers. */
final class PowerMenuSettingsUtils {
- /**
- * Setting storing the current behaviour of long press power.
- */
- public static final String POWER_BUTTON_LONG_PRESS_SETTING =
+ /** Setting storing the current behaviour of long press power. */
+ private static final String POWER_BUTTON_LONG_PRESS_SETTING =
Settings.Global.POWER_BUTTON_LONG_PRESS;
+ /** Setting storing the current behaviour of key chord power + volume up. */
+ private static final String KEY_CHORD_POWER_VOLUME_UP_SETTING =
+ Settings.Global.KEY_CHORD_POWER_VOLUME_UP;
+
/**
- * Value used for long press power button behaviour when the Assist setting is disabled.
+ * Value used for long press power button behaviour when long press power for Assistant is
+ * disabled.
*
- * If this value matches Assist setting, then it falls back to Global Actions panel or
- * power menu, depending on their respective settings.
+ *
If this value matches long press power for Assistant, then it falls back to Global Actions
+ * panel (i.e., the Power Menu), depending on their respective settings.
*/
- public static final int POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE =
+ private static final int POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE =
com.android.internal.R.integer.config_longPressOnPowerBehavior;
/**
- * Values used for long press power button behaviour when Assist setting is enabled.
- *
- * {@link com.android.server.policy.PhoneWindowManager#LONG_PRESS_POWER_GLOBAL_ACTIONS} for
- * source of the value.
+ * Value used for key chord power + volume up behaviour when long press power for Assistant is
+ * disabled.
*/
- static final int LONG_PRESS_POWER_NO_ACTION = 0;
- static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
- static final int LONG_PRESS_POWER_ASSISTANT_VALUE = 5; // Settings.Secure.ASSISTANT
+ private static final int KEY_CHORD_POWER_VOLUME_UP_DEFAULT_VALUE_RESOURCE =
+ com.android.internal.R.integer.config_keyChordPowerVolumeUp;
+
+ private static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; // a.k.a., Power Menu
+ private static final int LONG_PRESS_POWER_ASSISTANT_VALUE = 5; // Settings.Secure.ASSISTANT
+
+ private static final int KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS = 2;
+
+ private static final Uri POWER_BUTTON_LONG_PRESS_URI =
+ Settings.Global.getUriFor(POWER_BUTTON_LONG_PRESS_SETTING);
/**
- * @return current value of power button behaviour.
+ * @return true if long press power for assistant is currently enabled.
*/
- public static int getPowerButtonSettingValue(Context context) {
- return Settings.Global.getInt(context.getContentResolver(),
+ public static boolean isLongPressPowerForAssistantEnabled(Context context) {
+ int longPressPowerSettingValue = Settings.Global.getInt(
+ context.getContentResolver(),
POWER_BUTTON_LONG_PRESS_SETTING,
context.getResources().getInteger(POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE));
+ return longPressPowerSettingValue == LONG_PRESS_POWER_ASSISTANT_VALUE;
}
/**
- * @return true if long press power for assist is currently enabled.
+ * @return true if long press power for assistant setting is available on the device.
*/
- public static boolean isLongPressPowerForAssistEnabled(Context context) {
- return getPowerButtonSettingValue(context) == LONG_PRESS_POWER_ASSISTANT_VALUE;
+ public static boolean isLongPressPowerSettingAvailable(Context context) {
+ if (!context.getResources().getBoolean(
+ com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable)) {
+ return false;
+ }
+
+ int defaultLongPressPowerSettingValue =
+ context.getResources().getInteger(POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE);
+ switch (defaultLongPressPowerSettingValue) {
+ case LONG_PRESS_POWER_GLOBAL_ACTIONS:
+ case LONG_PRESS_POWER_ASSISTANT_VALUE:
+ // We support switching between Power Menu and Digital Assistant.
+ return true;
+ default:
+ // All other combinations are not supported.
+ return false;
+ }
}
- private PowerMenuSettingsUtils() {
+ public static boolean setLongPressPowerForAssistant(Context context) {
+ if (Settings.Global.putInt(
+ context.getContentResolver(),
+ POWER_BUTTON_LONG_PRESS_SETTING,
+ LONG_PRESS_POWER_ASSISTANT_VALUE)) {
+ // Make power + volume up buttons to open the power menu
+ Settings.Global.putInt(
+ context.getContentResolver(),
+ KEY_CHORD_POWER_VOLUME_UP_SETTING,
+ KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS);
+ return true;
+ }
+ return false;
+ }
+
+ public static boolean setLongPressPowerForPowerMenu(Context context) {
+ if (Settings.Global.putInt(
+ context.getContentResolver(),
+ POWER_BUTTON_LONG_PRESS_SETTING,
+ LONG_PRESS_POWER_GLOBAL_ACTIONS)) {
+ // We restore power + volume up buttons to the default action.
+ int keyChordDefaultValue =
+ context.getResources()
+ .getInteger(KEY_CHORD_POWER_VOLUME_UP_DEFAULT_VALUE_RESOURCE);
+ Settings.Global.putInt(
+ context.getContentResolver(),
+ KEY_CHORD_POWER_VOLUME_UP_SETTING,
+ keyChordDefaultValue);
+ return true;
+ }
+ return false;
+ }
+
+ private final Context mContext;
+ private final SettingsObserver mSettingsObserver;
+
+ PowerMenuSettingsUtils(Context context) {
+ mContext = context;
+ mSettingsObserver = new SettingsObserver(new Handler(Looper.getMainLooper()));
+ }
+
+ /**
+ * Registers callback for observing SettingsProvider state.
+ *
+ * @param callback for state changes
+ */
+ public void registerObserver(SettingsStateCallback callback) {
+ mSettingsObserver.setCallback(callback);
+ final ContentResolver resolver = mContext.getContentResolver();
+ resolver.registerContentObserver(POWER_BUTTON_LONG_PRESS_URI, true, mSettingsObserver);
+ }
+
+ /** Unregisters callback for observing SettingsProvider state. */
+ public void unregisterObserver() {
+ final ContentResolver resolver = mContext.getContentResolver();
+ resolver.unregisterContentObserver(mSettingsObserver);
+ }
+
+ /** An interface for when SettingsProvider key state changes. */
+ public interface SettingsStateCallback {
+ /** Callback method for SettingsProvider key state changes. */
+ void onChange(Uri uri);
+ }
+
+ private static final class SettingsObserver extends ContentObserver {
+ private SettingsStateCallback mCallback;
+
+ SettingsObserver(Handler handler) {
+ super(handler);
+ }
+
+ private void setCallback(SettingsStateCallback callback) {
+ mCallback = callback;
+ }
+
+ @Override
+ public void onChange(boolean selfChange, Uri uri) {
+ if (mCallback != null) {
+ mCallback.onChange(uri);
+ }
+ }
}
}
diff --git a/src/com/android/settings/notification/AppBubbleListPreferenceController.java b/src/com/android/settings/notification/AppBubbleListPreferenceController.java
index bf7fcc03756..6ebb376b5c1 100644
--- a/src/com/android/settings/notification/AppBubbleListPreferenceController.java
+++ b/src/com/android/settings/notification/AppBubbleListPreferenceController.java
@@ -51,7 +51,7 @@ public class AppBubbleListPreferenceController extends AppConversationListPrefer
private static final String KEY = "bubble_conversations";
public AppBubbleListPreferenceController(Context context, NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY);
}
@Override
@@ -80,25 +80,25 @@ public class AppBubbleListPreferenceController extends AppConversationListPrefer
}
@Override
- public boolean isAvailable() {
+ public int getAvailabilityStatus() {
// copy rather than inherit super's isAvailable because apps can link to this page
// as part of onboarding, before they send a valid conversation notification
if (mAppRow == null) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mAppRow.banned) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mChannel != null) {
if (mBackend.onlyHasDefaultChannel(mAppRow.pkg, mAppRow.uid)
|| NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId())) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
}
if (mAppRow.bubblePreference == BUBBLE_PREFERENCE_NONE) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
- return true;
+ return AVAILABLE;
}
@VisibleForTesting
diff --git a/src/com/android/settings/notification/app/AddToHomeScreenPreferenceController.java b/src/com/android/settings/notification/app/AddToHomeScreenPreferenceController.java
index e5afd9d3db0..12b807534f9 100644
--- a/src/com/android/settings/notification/app/AddToHomeScreenPreferenceController.java
+++ b/src/com/android/settings/notification/app/AddToHomeScreenPreferenceController.java
@@ -32,7 +32,7 @@ public class AddToHomeScreenPreferenceController extends NotificationPreferenceC
private static final String KEY = "add_to_home";
public AddToHomeScreenPreferenceController(Context context, NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY);
}
@Override
@@ -41,11 +41,11 @@ public class AddToHomeScreenPreferenceController extends NotificationPreferenceC
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable()) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
- return mConversationInfo != null;
+ return mConversationInfo != null ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/AllowSoundPreferenceController.java b/src/com/android/settings/notification/app/AllowSoundPreferenceController.java
index 0664c544bec..99d08734c96 100644
--- a/src/com/android/settings/notification/app/AllowSoundPreferenceController.java
+++ b/src/com/android/settings/notification/app/AllowSoundPreferenceController.java
@@ -40,7 +40,7 @@ public class AllowSoundPreferenceController extends NotificationPreferenceContro
public AllowSoundPreferenceController(Context context,
NotificationSettings.DependentFieldListener dependentFieldListener,
NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY_IMPORTANCE);
mDependentFieldListener = dependentFieldListener;
}
@@ -50,11 +50,14 @@ public class AllowSoundPreferenceController extends NotificationPreferenceContro
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable()) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
- return mChannel != null && NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId());
+ if (mChannel != null && NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId())) {
+ return AVAILABLE;
+ }
+ return CONDITIONALLY_UNAVAILABLE;
}
diff --git a/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java b/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java
index 92cd911843a..6c2c0c3cf77 100644
--- a/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java
+++ b/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java
@@ -64,7 +64,7 @@ public class AppChannelsBypassingDndPreferenceController extends NotificationPre
public AppChannelsBypassingDndPreferenceController(
Context context,
NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY);
}
@Override
@@ -110,8 +110,8 @@ public class AppChannelsBypassingDndPreferenceController extends NotificationPre
}
@Override
- public boolean isAvailable() {
- return mAppRow != null;
+ public int getAvailabilityStatus() {
+ return mAppRow != null ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/AppConversationListPreferenceController.java b/src/com/android/settings/notification/app/AppConversationListPreferenceController.java
index dd44a13f7c8..e7b23788968 100644
--- a/src/com/android/settings/notification/app/AppConversationListPreferenceController.java
+++ b/src/com/android/settings/notification/app/AppConversationListPreferenceController.java
@@ -49,7 +49,12 @@ public class AppConversationListPreferenceController extends NotificationPrefere
protected PreferenceCategory mPreference;
public AppConversationListPreferenceController(Context context, NotificationBackend backend) {
- super(context, backend);
+ this(context, backend, KEY);
+ }
+
+ public AppConversationListPreferenceController(Context context, NotificationBackend backend,
+ String key) {
+ super(context, backend, key);
}
@Override
@@ -58,21 +63,24 @@ public class AppConversationListPreferenceController extends NotificationPrefere
}
@Override
- public boolean isAvailable() {
+ public int getAvailabilityStatus() {
if (mAppRow == null) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mAppRow.banned) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mChannel != null) {
if (mBackend.onlyHasDefaultChannel(mAppRow.pkg, mAppRow.uid)
|| NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId())) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
}
- return mBackend.hasSentValidMsg(mAppRow.pkg, mAppRow.uid) || mBackend.isInInvalidMsgState(
- mAppRow.pkg, mAppRow.uid);
+ if (mBackend.hasSentValidMsg(mAppRow.pkg, mAppRow.uid) || mBackend.isInInvalidMsgState(
+ mAppRow.pkg, mAppRow.uid)) {
+ return AVAILABLE;
+ }
+ return CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/AppLinkPreferenceController.java b/src/com/android/settings/notification/app/AppLinkPreferenceController.java
index 043ae698f54..ecf9670cba9 100644
--- a/src/com/android/settings/notification/app/AppLinkPreferenceController.java
+++ b/src/com/android/settings/notification/app/AppLinkPreferenceController.java
@@ -32,7 +32,7 @@ public class AppLinkPreferenceController extends NotificationPreferenceControlle
private static final String KEY_APP_LINK = "app_link";
public AppLinkPreferenceController(Context context) {
- super(context, null);
+ super(context, null, KEY_APP_LINK);
}
@Override
@@ -41,11 +41,11 @@ public class AppLinkPreferenceController extends NotificationPreferenceControlle
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable()) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
- return mAppRow.settingsIntent != null;
+ return mAppRow.settingsIntent != null ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/BadgePreferenceController.java b/src/com/android/settings/notification/app/BadgePreferenceController.java
index 108fa1d7a07..f94dfb513ae 100644
--- a/src/com/android/settings/notification/app/BadgePreferenceController.java
+++ b/src/com/android/settings/notification/app/BadgePreferenceController.java
@@ -38,7 +38,7 @@ public class BadgePreferenceController extends NotificationPreferenceController
public BadgePreferenceController(Context context,
NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY_BADGE);
}
@Override
@@ -47,25 +47,29 @@ public class BadgePreferenceController extends NotificationPreferenceController
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable()) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mAppRow == null && mChannel == null) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (Settings.Secure.getInt(mContext.getContentResolver(),
NOTIFICATION_BADGING, SYSTEM_WIDE_ON) == SYSTEM_WIDE_OFF) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mChannel != null) {
if (isDefaultChannel()) {
- return true;
+ return AVAILABLE;
} else {
- return mAppRow == null ? false : mAppRow.showBadge;
+ return mAppRow == null
+ ? CONDITIONALLY_UNAVAILABLE
+ : mAppRow.showBadge
+ ? AVAILABLE
+ : CONDITIONALLY_UNAVAILABLE;
}
}
- return true;
+ return AVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/BlockPreferenceController.java b/src/com/android/settings/notification/app/BlockPreferenceController.java
index f4e213298a7..ea3eaeb3353 100644
--- a/src/com/android/settings/notification/app/BlockPreferenceController.java
+++ b/src/com/android/settings/notification/app/BlockPreferenceController.java
@@ -42,7 +42,7 @@ public class BlockPreferenceController extends NotificationPreferenceController
public BlockPreferenceController(Context context,
NotificationSettings.DependentFieldListener dependentFieldListener,
NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY_BLOCK);
mDependentFieldListener = dependentFieldListener;
}
@@ -52,14 +52,14 @@ public class BlockPreferenceController extends NotificationPreferenceController
}
@Override
- public boolean isAvailable() {
+ public int getAvailabilityStatus() {
if (mAppRow == null) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mPreferenceFilter != null && !isIncludedInFilter()) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
- return true;
+ return AVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java b/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java
index ad3a10cf381..da67afeeb33 100644
--- a/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java
+++ b/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java
@@ -32,15 +32,15 @@ public class BubbleCategoryPreferenceController extends NotificationPreferenceCo
static final int ON = 1;
public BubbleCategoryPreferenceController(Context context) {
- super(context, null);
+ super(context, null, KEY);
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable()) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
- return areBubblesEnabled();
+ return areBubblesEnabled() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java b/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java
index 0b9529b10b5..ed1c9b53079 100644
--- a/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java
+++ b/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java
@@ -32,15 +32,15 @@ public class BubbleLinkPreferenceController extends NotificationPreferenceContro
static final int ON = 1;
public BubbleLinkPreferenceController(Context context) {
- super(context, null);
+ super(context, null, KEY);
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable()) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
- return areBubblesEnabled();
+ return areBubblesEnabled() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/BubblePreferenceController.java b/src/com/android/settings/notification/app/BubblePreferenceController.java
index 351b4635bb6..516a45e482d 100644
--- a/src/com/android/settings/notification/app/BubblePreferenceController.java
+++ b/src/com/android/settings/notification/app/BubblePreferenceController.java
@@ -56,7 +56,7 @@ public class BubblePreferenceController extends NotificationPreferenceController
public BubblePreferenceController(Context context, @Nullable FragmentManager fragmentManager,
NotificationBackend backend, boolean isAppPage,
@Nullable NotificationSettings.DependentFieldListener listener) {
- super(context, backend);
+ super(context, backend, KEY);
mFragmentManager = fragmentManager;
mIsAppPage = isAppPage;
mListener = listener;
@@ -68,21 +68,24 @@ public class BubblePreferenceController extends NotificationPreferenceController
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable()) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
if (!mIsAppPage && !isEnabled()) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mChannel != null) {
if (isDefaultChannel()) {
- return true;
+ return AVAILABLE;
} else {
- return mAppRow != null && mAppRow.bubblePreference != BUBBLE_PREFERENCE_NONE;
+ if (mAppRow != null && mAppRow.bubblePreference != BUBBLE_PREFERENCE_NONE) {
+ return AVAILABLE;
+ }
+ return CONDITIONALLY_UNAVAILABLE;
}
}
- return true;
+ return AVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java b/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java
index 51370b16bef..abbe89e6fa8 100644
--- a/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java
+++ b/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java
@@ -42,28 +42,31 @@ public class BubbleSummaryPreferenceController extends NotificationPreferenceCon
static final int ON = 1;
public BubbleSummaryPreferenceController(Context context, NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY);
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable()) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mAppRow == null) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mChannel != null) {
if (!isGloballyEnabled()) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (isDefaultChannel()) {
- return true;
+ return AVAILABLE;
} else {
- return mAppRow != null;
+ return mAppRow != null ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
}
- return isGloballyEnabled() && mBackend.hasSentValidBubble(mAppRow.pkg, mAppRow.uid);
+ if (isGloballyEnabled() && mBackend.hasSentValidBubble(mAppRow.pkg, mAppRow.uid)) {
+ return AVAILABLE;
+ }
+ return CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/ChannelListPreferenceController.java b/src/com/android/settings/notification/app/ChannelListPreferenceController.java
index 8db3b21f4be..8d079114a9e 100644
--- a/src/com/android/settings/notification/app/ChannelListPreferenceController.java
+++ b/src/com/android/settings/notification/app/ChannelListPreferenceController.java
@@ -28,6 +28,7 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
+import android.util.Slog;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -39,16 +40,19 @@ import androidx.preference.SwitchPreference;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.applications.AppInfoBase;
+import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.PrimarySwitchPreference;
import com.android.settingslib.RestrictedSwitchPreference;
+import com.android.settingslib.utils.ThreadUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-public class ChannelListPreferenceController extends NotificationPreferenceController {
+public class ChannelListPreferenceController extends NotificationPreferenceController
+ implements BasePreferenceController.UiBlocker {
private static final String KEY = "channels";
private static final String KEY_GENERAL_CATEGORY = "categories";
@@ -59,7 +63,7 @@ public class ChannelListPreferenceController extends NotificationPreferenceContr
private PreferenceCategory mPreference;
public ChannelListPreferenceController(Context context, NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY);
}
@Override
@@ -68,20 +72,20 @@ public class ChannelListPreferenceController extends NotificationPreferenceContr
}
@Override
- public boolean isAvailable() {
+ public int getAvailabilityStatus() {
if (mAppRow == null) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mAppRow.banned) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mChannel != null) {
if (mBackend.onlyHasDefaultChannel(mAppRow.pkg, mAppRow.uid)
|| NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId())) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
}
- return true;
+ return AVAILABLE;
}
@Override
@@ -91,24 +95,17 @@ public class ChannelListPreferenceController extends NotificationPreferenceContr
@Override
public void updateState(Preference preference) {
- mPreference = (PreferenceCategory) preference;
- // Load channel settings
- new AsyncTask() {
- @Override
- protected Void doInBackground(Void... unused) {
+ mPreference = (PreferenceCategory) preference;
+ // Load channel settings
+ ThreadUtils.postOnBackgroundThread(() -> {
mChannelGroupList = mBackend.getGroups(mAppRow.pkg, mAppRow.uid).getList();
Collections.sort(mChannelGroupList, CHANNEL_GROUP_COMPARATOR);
- return null;
- }
-
- @Override
- protected void onPostExecute(Void unused) {
- if (mContext == null) {
- return;
- }
+ ThreadUtils.getUiThreadHandler().getLooper().prepare();
updateFullList(mPreference, mChannelGroupList);
- }
- }.execute();
+ ThreadUtils.postOnMainThread(() -> {
+ showPreferences();
+ });
+ });
}
/**
@@ -144,6 +141,12 @@ public class ChannelListPreferenceController extends NotificationPreferenceContr
}
}
+ private void showPreferences() {
+ if (mUiBlockListener != null) {
+ mUiBlockListener.onBlockerWorkFinished(this);
+ }
+ }
+
/**
* Looks for the category for the given group's key at the expected index, if that doesn't
* match, it checks all groups, and if it can't find that group anywhere, it creates it.
diff --git a/src/com/android/settings/notification/app/ConversationDemotePreferenceController.java b/src/com/android/settings/notification/app/ConversationDemotePreferenceController.java
index 02f639c3157..ba7ca358b8b 100644
--- a/src/com/android/settings/notification/app/ConversationDemotePreferenceController.java
+++ b/src/com/android/settings/notification/app/ConversationDemotePreferenceController.java
@@ -37,7 +37,7 @@ public class ConversationDemotePreferenceController extends NotificationPreferen
public ConversationDemotePreferenceController(Context context,
SettingsPreferenceFragment hostFragment,
NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY);
mHostFragment = hostFragment;
}
@@ -47,14 +47,17 @@ public class ConversationDemotePreferenceController extends NotificationPreferen
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable()) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mAppRow == null || mChannel == null) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
- return !TextUtils.isEmpty(mChannel.getConversationId()) && !mChannel.isDemoted();
+ if (!TextUtils.isEmpty(mChannel.getConversationId()) && !mChannel.isDemoted()) {
+ return AVAILABLE;
+ }
+ return CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java b/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java
index f99a56aabda..56de88b324a 100644
--- a/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java
+++ b/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java
@@ -45,7 +45,7 @@ public class ConversationHeaderPreferenceController extends NotificationPreferen
private boolean mStarted = false;
public ConversationHeaderPreferenceController(Context context, DashboardFragment fragment) {
- super(context, null);
+ super(context, null, PREF_KEY_APP_HEADER);
mFragment = fragment;
}
@@ -55,8 +55,8 @@ public class ConversationHeaderPreferenceController extends NotificationPreferen
}
@Override
- public boolean isAvailable() {
- return mAppRow != null;
+ public int getAvailabilityStatus() {
+ return mAppRow != null ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/ConversationPriorityPreferenceController.java b/src/com/android/settings/notification/app/ConversationPriorityPreferenceController.java
index ae169282484..46bc3c0c840 100644
--- a/src/com/android/settings/notification/app/ConversationPriorityPreferenceController.java
+++ b/src/com/android/settings/notification/app/ConversationPriorityPreferenceController.java
@@ -34,7 +34,7 @@ public class ConversationPriorityPreferenceController extends NotificationPrefer
public ConversationPriorityPreferenceController(Context context,
NotificationBackend backend, NotificationSettings.DependentFieldListener listener) {
- super(context, backend);
+ super(context, backend, KEY);
mDependentFieldListener = listener;
}
@@ -44,14 +44,14 @@ public class ConversationPriorityPreferenceController extends NotificationPrefer
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable()) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mAppRow == null || mChannel == null) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
- return true;
+ return AVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java b/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java
index 24c3d2ff6a1..a5ef569d620 100644
--- a/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java
+++ b/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java
@@ -37,7 +37,7 @@ public class ConversationPromotePreferenceController extends NotificationPrefere
public ConversationPromotePreferenceController(Context context,
SettingsPreferenceFragment hostFragment,
NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY);
mHostFragment = hostFragment;
}
@@ -47,14 +47,17 @@ public class ConversationPromotePreferenceController extends NotificationPrefere
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable()) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mAppRow == null || mChannel == null) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
- return !TextUtils.isEmpty(mChannel.getConversationId()) && mChannel.isDemoted();
+ if (!TextUtils.isEmpty(mChannel.getConversationId()) && mChannel.isDemoted()) {
+ return AVAILABLE;
+ }
+ return CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/DeletedChannelsPreferenceController.java b/src/com/android/settings/notification/app/DeletedChannelsPreferenceController.java
index 77a692f1488..cd160df1fd4 100644
--- a/src/com/android/settings/notification/app/DeletedChannelsPreferenceController.java
+++ b/src/com/android/settings/notification/app/DeletedChannelsPreferenceController.java
@@ -30,7 +30,7 @@ public class DeletedChannelsPreferenceController extends NotificationPreferenceC
private static final String KEY_DELETED = "deleted";
public DeletedChannelsPreferenceController(Context context, NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY_DELETED);
}
@Override
@@ -39,16 +39,19 @@ public class DeletedChannelsPreferenceController extends NotificationPreferenceC
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable()) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
// only visible on app screen
if (mChannel != null || hasValidGroup()) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
- return mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid) > 0;
+ if (mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid) > 0) {
+ return AVAILABLE;
+ }
+ return CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/DescriptionPreferenceController.java b/src/com/android/settings/notification/app/DescriptionPreferenceController.java
index 0a5bb2f9260..413a876cec9 100644
--- a/src/com/android/settings/notification/app/DescriptionPreferenceController.java
+++ b/src/com/android/settings/notification/app/DescriptionPreferenceController.java
@@ -29,7 +29,7 @@ public class DescriptionPreferenceController extends NotificationPreferenceContr
private static final String KEY_DESC = "desc";
public DescriptionPreferenceController(Context context) {
- super(context, null);
+ super(context, null, KEY_DESC);
}
@Override
@@ -38,20 +38,20 @@ public class DescriptionPreferenceController extends NotificationPreferenceContr
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable()) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mChannel == null && !hasValidGroup()) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mChannel != null && !TextUtils.isEmpty(mChannel.getDescription())) {
- return true;
+ return AVAILABLE;
}
if (hasValidGroup() && !TextUtils.isEmpty(mChannelGroup.getDescription())) {
- return true;
+ return AVAILABLE;
}
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/DndPreferenceController.java b/src/com/android/settings/notification/app/DndPreferenceController.java
index b65928aa915..811eeb4ec79 100644
--- a/src/com/android/settings/notification/app/DndPreferenceController.java
+++ b/src/com/android/settings/notification/app/DndPreferenceController.java
@@ -31,7 +31,7 @@ public class DndPreferenceController extends NotificationPreferenceController
private static final String KEY_BYPASS_DND = "bypass_dnd";
public DndPreferenceController(Context context, NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY_BYPASS_DND);
}
@Override
@@ -40,11 +40,11 @@ public class DndPreferenceController extends NotificationPreferenceController
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable() || mChannel == null) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE || mChannel == null) {
+ return CONDITIONALLY_UNAVAILABLE;
}
- return true;
+ return AVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/HeaderPreferenceController.java b/src/com/android/settings/notification/app/HeaderPreferenceController.java
index 7379d55395b..c4b0e598dff 100644
--- a/src/com/android/settings/notification/app/HeaderPreferenceController.java
+++ b/src/com/android/settings/notification/app/HeaderPreferenceController.java
@@ -45,7 +45,7 @@ public class HeaderPreferenceController extends NotificationPreferenceController
private boolean mStarted = false;
public HeaderPreferenceController(Context context, DashboardFragment fragment) {
- super(context, null);
+ super(context, null, PREF_KEY_APP_HEADER);
mFragment = fragment;
}
@@ -55,8 +55,8 @@ public class HeaderPreferenceController extends NotificationPreferenceController
}
@Override
- public boolean isAvailable() {
- return mAppRow != null;
+ public int getAvailabilityStatus() {
+ return mAppRow != null ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/HighImportancePreferenceController.java b/src/com/android/settings/notification/app/HighImportancePreferenceController.java
index d60668b9abe..98dc8a760e2 100644
--- a/src/com/android/settings/notification/app/HighImportancePreferenceController.java
+++ b/src/com/android/settings/notification/app/HighImportancePreferenceController.java
@@ -37,7 +37,7 @@ public class HighImportancePreferenceController extends NotificationPreferenceCo
public HighImportancePreferenceController(Context context,
NotificationSettings.DependentFieldListener dependentFieldListener,
NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY_IMPORTANCE);
mDependentFieldListener = dependentFieldListener;
}
@@ -47,17 +47,19 @@ public class HighImportancePreferenceController extends NotificationPreferenceCo
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable()) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mChannel == null) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (isDefaultChannel()) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
- return mChannel.getImportance() >= IMPORTANCE_DEFAULT;
+ return mChannel.getImportance() >= IMPORTANCE_DEFAULT
+ ? AVAILABLE
+ : CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/ImportancePreferenceController.java b/src/com/android/settings/notification/app/ImportancePreferenceController.java
index 3c32ca4b0bc..31ddac39373 100644
--- a/src/com/android/settings/notification/app/ImportancePreferenceController.java
+++ b/src/com/android/settings/notification/app/ImportancePreferenceController.java
@@ -38,7 +38,7 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
public ImportancePreferenceController(Context context,
NotificationSettings.DependentFieldListener dependentFieldListener,
NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY_IMPORTANCE);
mDependentFieldListener = dependentFieldListener;
}
@@ -48,14 +48,14 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable()) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mChannel == null) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
- return !isDefaultChannel();
+ return !isDefaultChannel() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceController.java b/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceController.java
index b937e80e0d6..bb2c58b728b 100644
--- a/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceController.java
+++ b/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceController.java
@@ -31,7 +31,7 @@ public class InvalidConversationInfoPreferenceController extends NotificationPre
public InvalidConversationInfoPreferenceController(Context context,
NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY);
}
@Override
@@ -40,17 +40,19 @@ public class InvalidConversationInfoPreferenceController extends NotificationPre
}
@Override
- public boolean isAvailable() {
+ public int getAvailabilityStatus() {
if (mAppRow == null) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mAppRow.banned) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mPreferenceFilter != null && !isIncludedInFilter()) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
- return mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid);
+ return mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid)
+ ? AVAILABLE
+ : CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/InvalidConversationPreferenceController.java b/src/com/android/settings/notification/app/InvalidConversationPreferenceController.java
index 5c502dccbe0..219ccbcea85 100644
--- a/src/com/android/settings/notification/app/InvalidConversationPreferenceController.java
+++ b/src/com/android/settings/notification/app/InvalidConversationPreferenceController.java
@@ -31,7 +31,7 @@ public class InvalidConversationPreferenceController extends NotificationPrefere
private static final String KEY = "invalid_conversation_switch";
public InvalidConversationPreferenceController(Context context, NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY);
}
@Override
@@ -40,17 +40,19 @@ public class InvalidConversationPreferenceController extends NotificationPrefere
}
@Override
- public boolean isAvailable() {
+ public int getAvailabilityStatus() {
if (mAppRow == null) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mAppRow.banned) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mPreferenceFilter != null && !isIncludedInFilter()) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
- return mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid);
+ return mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid)
+ ? AVAILABLE
+ : CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/LightsPreferenceController.java b/src/com/android/settings/notification/app/LightsPreferenceController.java
index d096922e348..f7f92442c9b 100644
--- a/src/com/android/settings/notification/app/LightsPreferenceController.java
+++ b/src/com/android/settings/notification/app/LightsPreferenceController.java
@@ -33,7 +33,7 @@ public class LightsPreferenceController extends NotificationPreferenceController
private static final String KEY_LIGHTS = "lights";
public LightsPreferenceController(Context context, NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY_LIGHTS);
}
@Override
@@ -42,16 +42,18 @@ public class LightsPreferenceController extends NotificationPreferenceController
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable()) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mChannel == null) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
- return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT)
- && canPulseLight()
- && !isDefaultChannel();
+ if (checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) && canPulseLight()
+ && !isDefaultChannel()) {
+ return AVAILABLE;
+ }
+ return CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/MinImportancePreferenceController.java b/src/com/android/settings/notification/app/MinImportancePreferenceController.java
index f8257636615..b2c0862b8f8 100644
--- a/src/com/android/settings/notification/app/MinImportancePreferenceController.java
+++ b/src/com/android/settings/notification/app/MinImportancePreferenceController.java
@@ -37,7 +37,7 @@ public class MinImportancePreferenceController extends NotificationPreferenceCon
public MinImportancePreferenceController(Context context,
NotificationSettings.DependentFieldListener dependentFieldListener,
NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY_IMPORTANCE);
mDependentFieldListener = dependentFieldListener;
}
@@ -47,17 +47,17 @@ public class MinImportancePreferenceController extends NotificationPreferenceCon
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable()) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mChannel == null) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (isDefaultChannel()) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
- return mChannel.getImportance() <= IMPORTANCE_LOW;
+ return mChannel.getImportance() <= IMPORTANCE_LOW ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/NotificationPreferenceController.java b/src/com/android/settings/notification/app/NotificationPreferenceController.java
index fb19d9d6b4c..271a83d76f8 100644
--- a/src/com/android/settings/notification/app/NotificationPreferenceController.java
+++ b/src/com/android/settings/notification/app/NotificationPreferenceController.java
@@ -17,26 +17,24 @@
package com.android.settings.notification.app;
import static android.app.NotificationManager.IMPORTANCE_NONE;
-import static android.os.UserHandle.USER_SYSTEM;
import android.annotation.Nullable;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.content.Context;
-import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ShortcutInfo;
import android.graphics.drawable.Drawable;
import android.os.UserManager;
-import android.provider.Settings;
import android.util.Log;
+import android.util.Slog;
import androidx.preference.Preference;
+import com.android.settings.core.BasePreferenceController;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedLockUtils;
-import com.android.settingslib.core.AbstractPreferenceController;
import java.util.Comparator;
import java.util.List;
@@ -46,7 +44,7 @@ import java.util.Objects;
* Parent class for preferences appearing on notification setting pages at the app,
* notification channel group, or notification channel level.
*/
-public abstract class NotificationPreferenceController extends AbstractPreferenceController {
+public abstract class NotificationPreferenceController extends BasePreferenceController {
private static final String TAG = "ChannelPrefContr";
@Nullable
protected NotificationChannel mChannel;
@@ -71,8 +69,11 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
boolean overrideCanBlockValue;
boolean overrideCanConfigureValue;
- public NotificationPreferenceController(Context context, NotificationBackend backend) {
- super(context);
+ boolean mLoadedChannelState;
+
+ public NotificationPreferenceController(Context context, NotificationBackend backend,
+ String key) {
+ super(context, key);
mContext = context;
mNm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
mBackend = backend;
@@ -81,28 +82,30 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
}
/**
- * Returns true if field's parent object is not blocked.
+ * Returns available if field's parent object is not blocked.
*/
@Override
- public boolean isAvailable() {
+ public int getAvailabilityStatus() {
if (mAppRow == null) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mAppRow.banned) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mChannelGroup != null) {
if (mChannelGroup.isBlocked()) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
}
if (mChannel != null) {
if (mPreferenceFilter != null && !isIncludedInFilter()) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
+ }
+ if(mChannel.getImportance() == IMPORTANCE_NONE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
- return mChannel.getImportance() != IMPORTANCE_NONE;
}
- return true;
+ return AVAILABLE;
}
protected void onResume(NotificationBackend.AppRow appRow,
diff --git a/src/com/android/settings/notification/app/NotificationSettings.java b/src/com/android/settings/notification/app/NotificationSettings.java
index 192a0ee9fc7..5750167c271 100644
--- a/src/com/android/settings/notification/app/NotificationSettings.java
+++ b/src/com/android/settings/notification/app/NotificationSettings.java
@@ -41,6 +41,7 @@ import android.os.UserHandle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
+import android.util.Slog;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
@@ -129,15 +130,52 @@ abstract public class NotificationSettings extends DashboardFragment {
}
}
+ mUserId = UserHandle.getUserId(mUid);
mPkgInfo = findPackageInfo(mPkg, mUid);
+ }
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ if (mIntent == null && mArgs == null) {
+ toastAndFinish("no intent");
+ return;
+ }
+
+ if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) {
+ toastAndFinish("Missing package or uid or packageinfo");
+ return;
+ }
+
+ startListeningToPackageRemove();
+ }
+
+ @Override
+ public void onDestroy() {
+ stopListeningToPackageRemove();
+ super.onDestroy();
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) {
+ toastAndFinish("Missing package or uid or packageinfo");
+ return;
+ }
+ mPkgInfo = findPackageInfo(mPkg, mUid);
if (mPkgInfo != null) {
- mUserId = UserHandle.getUserId(mUid);
mSuspendedAppsAdmin = RestrictedLockUtilsInternal.checkIfApplicationIsSuspended(
mContext, mPkg, mUserId);
- loadChannel();
loadAppRow();
+ if (mAppRow == null) {
+ toastAndFinish("Can't load package");
+ return;
+ }
+ loadChannel();
+ loadConversation();
loadChannelGroup();
loadPreferencesFilter();
collectConfigActivities();
@@ -157,55 +195,6 @@ abstract public class NotificationSettings extends DashboardFragment {
}
}
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- if (mIntent == null && mArgs == null) {
- Log.w(TAG, "No intent");
- toastAndFinish();
- return;
- }
-
- if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) {
- Log.w(TAG, "Missing package or uid or packageinfo");
- toastAndFinish();
- return;
- }
-
- startListeningToPackageRemove();
- }
-
- @Override
- public void onDestroy() {
- stopListeningToPackageRemove();
- super.onDestroy();
- }
-
- @Override
- public void onResume() {
- super.onResume();
- if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null || mAppRow == null) {
- Log.w(TAG, "Missing package or uid or packageinfo");
- finish();
- return;
- }
- // Reload app, channel, etc onResume in case they've changed. A little wasteful if we've
- // just done onAttach but better than making every preference controller reload all
- // the data
- loadAppRow();
- if (mAppRow == null) {
- Log.w(TAG, "Can't load package");
- finish();
- return;
- }
- loadChannel();
- loadConversation();
- loadChannelGroup();
- loadPreferencesFilter();
- collectConfigActivities();
- }
-
protected void animatePanel() {
if (mPreferenceFilter != null) {
mLayoutView = getActivity().findViewById(R.id.main_content);
@@ -307,7 +296,8 @@ abstract public class NotificationSettings extends DashboardFragment {
}
}
- protected void toastAndFinish() {
+ protected void toastAndFinish(String msg) {
+ Log.w(TAG, msg);
Toast.makeText(mContext, R.string.app_not_found_dlg_text, Toast.LENGTH_SHORT).show();
getActivity().finish();
}
diff --git a/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java b/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java
index 0c7cd2361e2..46625c3101a 100644
--- a/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java
+++ b/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java
@@ -30,7 +30,7 @@ public class NotificationsOffPreferenceController extends NotificationPreference
private static final String KEY_BLOCKED_DESC = "block_desc";
public NotificationsOffPreferenceController(Context context) {
- super(context, null);
+ super(context, null, KEY_BLOCKED_DESC);
}
@Override
@@ -39,16 +39,20 @@ public class NotificationsOffPreferenceController extends NotificationPreference
}
@Override
- public boolean isAvailable() {
+ public int getAvailabilityStatus() {
if (mAppRow == null) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mPreferenceFilter != null && !isIncludedInFilter()) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
// Available only when other controllers are unavailable - this UI replaces the UI that
// would give more detailed notification controls.
- return !super.isAvailable();
+ if (super.getAvailabilityStatus() == AVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
+ } else {
+ return AVAILABLE;
+ }
}
@Override
diff --git a/src/com/android/settings/notification/app/SoundPreferenceController.java b/src/com/android/settings/notification/app/SoundPreferenceController.java
index b23b4fc86cb..335b44226ce 100644
--- a/src/com/android/settings/notification/app/SoundPreferenceController.java
+++ b/src/com/android/settings/notification/app/SoundPreferenceController.java
@@ -47,7 +47,7 @@ public class SoundPreferenceController extends NotificationPreferenceController
public SoundPreferenceController(Context context, SettingsPreferenceFragment hostFragment,
NotificationSettings.DependentFieldListener dependentFieldListener,
NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY_SOUND);
mFragment = hostFragment;
mListener = dependentFieldListener;
}
@@ -58,14 +58,17 @@ public class SoundPreferenceController extends NotificationPreferenceController
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable()) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mChannel == null) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
- return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) && !isDefaultChannel();
+ if (checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) && !isDefaultChannel()) {
+ return AVAILABLE;
+ }
+ return CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/VibrationPreferenceController.java b/src/com/android/settings/notification/app/VibrationPreferenceController.java
index 34d1a543b56..f91999f074d 100644
--- a/src/com/android/settings/notification/app/VibrationPreferenceController.java
+++ b/src/com/android/settings/notification/app/VibrationPreferenceController.java
@@ -34,7 +34,7 @@ public class VibrationPreferenceController extends NotificationPreferenceControl
private final Vibrator mVibrator;
public VibrationPreferenceController(Context context, NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY_VIBRATE);
mVibrator = context.getSystemService(Vibrator.class);
}
@@ -44,14 +44,15 @@ public class VibrationPreferenceController extends NotificationPreferenceControl
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable() || mChannel == null) {
- return false;
- }
- return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT)
- && !isDefaultChannel()
- && mVibrator != null
- && mVibrator.hasVibrator();
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE || mChannel == null) {
+ return CONDITIONALLY_UNAVAILABLE;
+ }
+ if (checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) && !isDefaultChannel()
+ && mVibrator != null && mVibrator.hasVibrator()) {
+ return AVAILABLE;
+ }
+ return CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/app/VisibilityPreferenceController.java b/src/com/android/settings/notification/app/VisibilityPreferenceController.java
index a2a1d76b71c..3f33267a749 100644
--- a/src/com/android/settings/notification/app/VisibilityPreferenceController.java
+++ b/src/com/android/settings/notification/app/VisibilityPreferenceController.java
@@ -48,7 +48,7 @@ public class VisibilityPreferenceController extends NotificationPreferenceContro
public VisibilityPreferenceController(Context context, LockPatternUtils utils,
NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, KEY_VISIBILITY_OVERRIDE);
mLockPatternUtils = utils;
}
@@ -58,14 +58,18 @@ public class VisibilityPreferenceController extends NotificationPreferenceContro
}
@Override
- public boolean isAvailable() {
- if (!super.isAvailable()) {
- return false;
+ public int getAvailabilityStatus() {
+ if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
+ return CONDITIONALLY_UNAVAILABLE;
}
if (mChannel == null || mAppRow.banned) {
- return false;
+ return CONDITIONALLY_UNAVAILABLE;
}
- return checkCanBeVisible(NotificationManager.IMPORTANCE_LOW) && isLockScreenSecure();
+ if (checkCanBeVisible(NotificationManager.IMPORTANCE_LOW) && isLockScreenSecure()) {
+ return AVAILABLE;
+ }
+
+ return CONDITIONALLY_UNAVAILABLE;
}
@Override
diff --git a/src/com/android/settings/notification/zen/ZenModeAutomationSettings.java b/src/com/android/settings/notification/zen/ZenModeAutomationSettings.java
index 31a4ba78550..4f18e5d7e02 100644
--- a/src/com/android/settings/notification/zen/ZenModeAutomationSettings.java
+++ b/src/com/android/settings/notification/zen/ZenModeAutomationSettings.java
@@ -50,16 +50,6 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase {
private String[] mDeleteDialogRuleIds;
private boolean[] mDeleteDialogChecked;
- @Override
- public void onAttach(Context context) {
- super.onAttach(context);
- Bundle bundle = getArguments();
- if (bundle != null && bundle.containsKey(DELETE)) {
- mBackend.removeZenRule(bundle.getString(DELETE));
- bundle.remove(DELETE);
- }
- }
-
@Override
protected List createPreferenceControllers(Context context) {
ZenServiceListing serviceListing = new ZenServiceListing(getContext(), CONFIG);
diff --git a/src/com/android/settings/notification/zen/ZenRuleButtonsPreferenceController.java b/src/com/android/settings/notification/zen/ZenRuleButtonsPreferenceController.java
index 3b7cde09cf0..023a770808d 100644
--- a/src/com/android/settings/notification/zen/ZenRuleButtonsPreferenceController.java
+++ b/src/com/android/settings/notification/zen/ZenRuleButtonsPreferenceController.java
@@ -103,8 +103,7 @@ public class ZenRuleButtonsPreferenceController extends AbstractZenModePreferenc
new ZenDeleteRuleDialog.PositiveClickListener() {
@Override
public void onOk(String id) {
- Bundle bundle = new Bundle();
- bundle.putString(ZenModeAutomationSettings.DELETE, id);
+ mBackend.removeZenRule(id);
mMetricsFeatureProvider.action(mContext,
SettingsEnums.ACTION_ZEN_DELETE_RULE_OK);
new SubSettingLauncher(mContext)
@@ -112,7 +111,6 @@ public class ZenRuleButtonsPreferenceController extends AbstractZenModePreferenc
.setDestination(ZenModeAutomationSettings.class.getName())
.setSourceMetricsCategory(MetricsProto.MetricsEvent
.NOTIFICATION_ZEN_MODE_AUTOMATION)
- .setArguments(bundle)
.launch();
}
});
diff --git a/src/com/android/settings/widget/SettingsMainSwitchPreference.java b/src/com/android/settings/widget/SettingsMainSwitchPreference.java
index ce91c9e693c..9fd8d06460e 100644
--- a/src/com/android/settings/widget/SettingsMainSwitchPreference.java
+++ b/src/com/android/settings/widget/SettingsMainSwitchPreference.java
@@ -22,7 +22,6 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
-import android.view.ViewGroup;
import android.widget.Switch;
import androidx.core.content.res.TypedArrayUtils;
@@ -35,8 +34,6 @@ import com.android.settingslib.RestrictedPreferenceHelper;
import com.android.settingslib.core.instrumentation.SettingsJankMonitor;
import com.android.settingslib.widget.OnMainSwitchChangeListener;
-import com.google.android.setupdesign.util.LayoutStyler;
-
import java.util.ArrayList;
import java.util.List;
@@ -52,7 +49,6 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements
new ArrayList<>();
private final List mSwitchChangeListeners = new ArrayList<>();
- private boolean mApplyPartnerCustomizationPaddingStyle;
private SettingsMainSwitchBar mMainSwitchBar;
private CharSequence mTitle;
private EnforcedAdmin mEnforcedAdmin;
@@ -100,12 +96,6 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements
} else {
mMainSwitchBar.hide();
}
-
- if (mApplyPartnerCustomizationPaddingStyle) {
- // TODO(b/232494666): Replace all margins of the root view with the padding
- final ViewGroup parentView = (ViewGroup) mMainSwitchBar.getParent();
- LayoutStyler.applyPartnerCustomizationLayoutPaddingStyle(parentView);
- }
}
private void init(Context context, AttributeSet attrs) {
@@ -253,14 +243,6 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements
}
}
- /**
- * Apples the padding style of the partner's customization. It's used in the SetupWizard.
- */
- public void applyPartnerCustomizationPaddingStyle() {
- mApplyPartnerCustomizationPaddingStyle = true;
- notifyChanged();
- }
-
private void initMainSwitchBar() {
if (mMainSwitchBar != null) {
mMainSwitchBar.setTitle(mTitle);
diff --git a/tests/robotests/src/com/android/settings/gestures/LongPressPowerButtonPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/LongPressPowerButtonPreferenceControllerTest.java
deleted file mode 100644
index 5637e961c4e..00000000000
--- a/tests/robotests/src/com/android/settings/gestures/LongPressPowerButtonPreferenceControllerTest.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Copyright (C) 2021 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.gestures;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.app.Application;
-import android.content.res.Resources;
-import android.provider.Settings;
-
-import androidx.annotation.StringRes;
-import androidx.preference.Preference;
-import androidx.test.core.app.ApplicationProvider;
-
-import com.android.settings.R;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.MockitoAnnotations;
-import org.mockito.stubbing.Answer;
-import org.robolectric.RobolectricTestRunner;
-
-@RunWith(RobolectricTestRunner.class)
-public class LongPressPowerButtonPreferenceControllerTest {
-
- private static final String KEY_LONG_PRESS_POWER_BUTTON =
- "gesture_power_menu_long_press_for_assist";
-
- private Application mContext;
- private Resources mResources;
- private LongPressPowerButtonPreferenceController mController;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mContext = spy(ApplicationProvider.getApplicationContext());
- mResources = mock(Resources.class);
- when(mContext.getResources()).thenReturn(mResources);
- when(mResources.getString(anyInt())).thenAnswer((Answer) invocation -> {
- int id = invocation.getArgument(0);
- return getString(id);
- });
- when(mResources.getBoolean(
- com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
- .thenReturn(true);
- mController = new LongPressPowerButtonPreferenceController(mContext,
- KEY_LONG_PRESS_POWER_BUTTON);
- mController.mAssistSwitch = mock(Preference.class);
- mController.mFooterHint = mock(Preference.class);
- }
-
- @Test
- public void isAvailable_configIsTrue_shouldReturnTrue() {
- when(mResources.getBoolean(
- com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
- .thenReturn(true);
-
- assertThat(mController.isAvailable()).isTrue();
- }
-
- @Test
- public void isAvailable_configIsFalse_shouldReturnFalse() {
- when(mResources.getBoolean(
- com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
- .thenReturn(false);
-
- assertThat(mController.isAvailable()).isFalse();
- }
-
- @Test
- public void preferenceChecked_powerMenuHintTextShown() {
- mController.onPreferenceChange(null, true);
-
- verify(mController.mFooterHint).setSummary(
- getString(
- R.string.power_menu_power_volume_up_hint));
- verify(mController.mFooterHint).setVisible(true);
- }
-
-
- @Test
- public void preferenceUnchecked_keyChordEnabled_powerMenuHintTextShown() {
- when(mResources.getInteger(
- com.android.internal.R.integer.config_keyChordPowerVolumeUp))
- .thenReturn(
- LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS);
-
- mController.onPreferenceChange(null, false);
-
- verify(mController.mFooterHint).setSummary(
- getString(
- R.string.power_menu_power_volume_up_hint));
- verify(mController.mFooterHint).setVisible(true);
- }
-
- @Test
- public void preferenceChecked_hushGestureEnabled_powerMenuHintTextIncludesHushHint() {
- when(mResources.getBoolean(
- com.android.internal.R.bool.config_volumeHushGestureEnabled))
- .thenReturn(true);
-
- mController.onPreferenceChange(null, true);
-
- verify(mController.mFooterHint).setSummary(
- getString(
- R.string.power_menu_power_volume_up_hint) + "\n\n"
- + getString(
- R.string.power_menu_power_prevent_ringing_hint));
- verify(mController.mFooterHint).setVisible(true);
- }
-
-
- @Test
- public void preferenceUnchecked_keyChordDisabled_powerMenuHintTextHidden() {
- mController.onPreferenceChange(null, false);
- when(mResources.getInteger(
- com.android.internal.R.integer.config_keyChordPowerVolumeUp))
- .thenReturn(
- LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION);
-
- verify(mController.mFooterHint).setVisible(false);
- }
-
- @Test
- public void preferenceChecked_longPressPowerSettingSetToAssistant() {
- mController.onPreferenceChange(null, true);
-
- assertThat(Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
- PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE);
- assertThat(Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.KEY_CHORD_POWER_VOLUME_UP, -1)).isEqualTo(
- LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS);
- }
-
- @Test
- public void preferenceUnchecked_longPressPowerSettingSetToDefaultValue() {
- when(mResources.getInteger(
- com.android.internal.R.integer.config_longPressOnPowerBehavior))
- .thenReturn(
- PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS);
-
- mController.onPreferenceChange(null, false);
-
- assertThat(Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
- PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS);
- assertThat(Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.KEY_CHORD_POWER_VOLUME_UP, -1)).isEqualTo(
- LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION);
- verify(mController.mAssistSwitch).setSummary(
- getString(
- R.string.power_menu_summary_long_press_for_assist_disabled_with_power_menu));
- }
-
- @Test
- public void preferenceUnchecked_muteChordDefault_longPressPowerSettingSetToDefaultValue() {
- // Value out of range chosen deliberately.
- when(mResources.getInteger(
- com.android.internal.R.integer.config_longPressOnPowerBehavior))
- .thenReturn(8);
- when(mResources.getInteger(
- com.android.internal.R.integer.config_keyChordPowerVolumeUp))
- .thenReturn(
- LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_MUTE_TOGGLE);
-
- mController.onPreferenceChange(null, false);
-
- assertThat(Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(8);
- assertThat(Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.KEY_CHORD_POWER_VOLUME_UP, -1)).isEqualTo(
- LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_MUTE_TOGGLE);
- }
-
- @Test
- public void preferenceUnchecked_assistDefault_setNoAction() {
- // Ensure that the Assistant is the default behavior for LPP.
- when(mResources.getInteger(
- com.android.internal.R.integer.config_longPressOnPowerBehavior))
- .thenReturn(
- PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE);
-
- mController.onPreferenceChange(null, false);
-
- assertThat(Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
- PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS);
- assertThat(Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.KEY_CHORD_POWER_VOLUME_UP, -1)).isEqualTo(
- LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION);
- verify(mController.mAssistSwitch).setSummary(getString(
- R.string.power_menu_summary_long_press_for_assist_disabled_with_power_menu));
- }
-
- private String getString(@StringRes int id) {
- return ApplicationProvider.getApplicationContext().getString(id);
- }
-}
diff --git a/tests/robotests/src/com/android/settings/gestures/LongPressPowerFooterPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/LongPressPowerFooterPreferenceControllerTest.java
new file mode 100644
index 00000000000..e1cd53ea82b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/gestures/LongPressPowerFooterPreferenceControllerTest.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2022 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.gestures;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.app.Application;
+import android.content.res.Resources;
+import android.text.TextUtils;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.R;
+import com.android.settingslib.widget.FooterPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+@RunWith(RobolectricTestRunner.class)
+public class LongPressPowerFooterPreferenceControllerTest {
+
+ private Application mContext;
+ private Resources mResources;
+ private Preference mPreference;
+ private LongPressPowerFooterPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ mResources = spy(mContext.getResources());
+ when(mContext.getResources()).thenReturn(mResources);
+ mPreference = new FooterPreference(mContext);
+ mController = new LongPressPowerFooterPreferenceController(mContext, "test_key");
+
+ PreferenceScreen mScreen = mock(PreferenceScreen.class);
+ when(mScreen.findPreference("test_key")).thenReturn(mPreference);
+ mController.displayPreference(mScreen);
+ }
+
+ @Test
+ public void updateState_longPressPowerForPowerMenu_hidesPreference() {
+ PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.isVisible()).isFalse();
+ }
+
+ @Test
+ public void updateState_longPressPowerForAssistant_showsPreference() {
+ PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.isVisible()).isTrue();
+ }
+
+ @Test
+ public void updateState_notEligible_showsPreference() {
+ PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.isVisible()).isTrue();
+ }
+
+ @Test
+ public void updateState_hushGestureEnabled_includesPreventRingingHint() {
+ when(mResources.getBoolean(com.android.internal.R.bool.config_volumeHushGestureEnabled))
+ .thenReturn(true);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.getSummary().toString())
+ .isEqualTo(
+ TextUtils.concat(
+ mContext.getString(R.string.power_menu_power_volume_up_hint),
+ "\n\n",
+ mContext.getString(
+ R.string.power_menu_power_prevent_ringing_hint)));
+ }
+
+ @Test
+ public void updateState_hushGestureDisabled_doesNotIncludePreventRingingHint() {
+ when(mResources.getBoolean(com.android.internal.R.bool.config_volumeHushGestureEnabled))
+ .thenReturn(false);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.getSummary().toString())
+ .isEqualTo(mContext.getString(R.string.power_menu_power_volume_up_hint));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/gestures/LongPressPowerForAssistantPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/LongPressPowerForAssistantPreferenceControllerTest.java
new file mode 100644
index 00000000000..e210077e30d
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/gestures/LongPressPowerForAssistantPreferenceControllerTest.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2022 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.gestures;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.app.Application;
+import android.content.res.Resources;
+
+import androidx.preference.PreferenceScreen;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.widget.SelectorWithWidgetPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+@RunWith(RobolectricTestRunner.class)
+public class LongPressPowerForAssistantPreferenceControllerTest {
+
+ private Application mContext;
+ private Resources mResources;
+ private SelectorWithWidgetPreference mPreference;
+ private LongPressPowerForAssistantPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ mResources = spy(mContext.getResources());
+ mPreference = new SelectorWithWidgetPreference(mContext);
+ mController = new LongPressPowerForAssistantPreferenceController(mContext, "test_key");
+
+ when(mContext.getResources()).thenReturn(mResources);
+ when(mResources.getBoolean(
+ com.android.internal.R.bool
+ .config_longPressOnPowerForAssistantSettingAvailable))
+ .thenReturn(true);
+ when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
+ .thenReturn(5); // Default to Assistant
+
+ PreferenceScreen mScreen = mock(PreferenceScreen.class);
+ when(mScreen.findPreference("test_key")).thenReturn(mPreference);
+ mController.displayPreference(mScreen);
+ mController.onStart();
+ }
+
+ @Test
+ public void initialState_longPressPowerForPowerMenu_preferenceNotChecked() {
+ PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.isChecked()).isFalse();
+ }
+
+ @Test
+ public void initialState_longPressPowerForAssistant_preferenceChecked() {
+ PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.isChecked()).isTrue();
+ }
+
+ @Test
+ public void getAvailabilityStatus_longPressPowerSettingAvailable_returnsAvailable() {
+ assertThat(mController.getAvailabilityStatus())
+ .isEqualTo(BasePreferenceController.AVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_longPressPowerSettingNotAvailable_returnsNotAvailable() {
+ when(mResources.getBoolean(
+ com.android.internal.R.bool
+ .config_longPressOnPowerForAssistantSettingAvailable))
+ .thenReturn(false);
+
+ assertThat(mController.getAvailabilityStatus())
+ .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
+ }
+
+ @Test
+ public void onClick_updatesSettingsValue_checksPreference() {
+ // Initial state: preference not checked
+ PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
+ mController.updateState(mPreference);
+ assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isFalse();
+ assertThat(mPreference.isChecked()).isFalse();
+
+ mPreference.performClick();
+
+ assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isTrue();
+ assertThat(mPreference.isChecked()).isTrue();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/gestures/LongPressPowerForPowerMenuPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/LongPressPowerForPowerMenuPreferenceControllerTest.java
new file mode 100644
index 00000000000..ea6557b2a3d
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/gestures/LongPressPowerForPowerMenuPreferenceControllerTest.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2022 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.gestures;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.app.Application;
+import android.content.res.Resources;
+
+import androidx.preference.PreferenceScreen;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.widget.SelectorWithWidgetPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+@RunWith(RobolectricTestRunner.class)
+public class LongPressPowerForPowerMenuPreferenceControllerTest {
+
+ private Application mContext;
+ private Resources mResources;
+ private SelectorWithWidgetPreference mPreference;
+ private LongPressPowerForPowerMenuPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ mResources = spy(mContext.getResources());
+ mPreference = new SelectorWithWidgetPreference(mContext);
+ mController = new LongPressPowerForPowerMenuPreferenceController(mContext, "test_key");
+
+ when(mContext.getResources()).thenReturn(mResources);
+ when(mResources.getBoolean(
+ com.android.internal.R.bool
+ .config_longPressOnPowerForAssistantSettingAvailable))
+ .thenReturn(true);
+ when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
+ .thenReturn(5); // Default to Assistant
+
+ PreferenceScreen mScreen = mock(PreferenceScreen.class);
+ when(mScreen.findPreference("test_key")).thenReturn(mPreference);
+ mController.displayPreference(mScreen);
+ mController.onStart();
+ }
+
+ @Test
+ public void initialState_longPressPowerForPowerMenu_preferenceChecked() {
+ PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.isChecked()).isTrue();
+ }
+
+ @Test
+ public void initialState_longPressPowerForAssistant_preferenceNotChecked() {
+ PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.isChecked()).isFalse();
+ }
+
+ @Test
+ public void getAvailabilityStatus_longPressPowerSettingAvailable_returnsAvailable() {
+ assertThat(mController.getAvailabilityStatus())
+ .isEqualTo(BasePreferenceController.AVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_longPressPowerSettingNotAvailable_returnsNotAvailable() {
+ when(mResources.getBoolean(
+ com.android.internal.R.bool
+ .config_longPressOnPowerForAssistantSettingAvailable))
+ .thenReturn(false);
+
+ assertThat(mController.getAvailabilityStatus())
+ .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
+ }
+
+ @Test
+ public void onClick_updatesSettingsValue_checksPreference() {
+ // Initial state: preference not checked
+ PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
+ mController.updateState(mPreference);
+ assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isTrue();
+ assertThat(mPreference.isChecked()).isFalse();
+
+ mPreference.performClick();
+
+ assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isFalse();
+ assertThat(mPreference.isChecked()).isTrue();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/gestures/LongPressPowerIllustrationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/LongPressPowerIllustrationPreferenceControllerTest.java
new file mode 100644
index 00000000000..37a4c0bba4e
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/gestures/LongPressPowerIllustrationPreferenceControllerTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2022 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.gestures;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import android.app.Application;
+
+import androidx.preference.PreferenceScreen;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.R;
+import com.android.settingslib.widget.IllustrationPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+@RunWith(RobolectricTestRunner.class)
+public class LongPressPowerIllustrationPreferenceControllerTest {
+
+ private Application mContext;
+ private IllustrationPreference mPreference;
+ private LongPressPowerIllustrationPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ mContext = ApplicationProvider.getApplicationContext();
+ mPreference = new IllustrationPreference(mContext);
+ mController = new LongPressPowerIllustrationPreferenceController(mContext, "test_key");
+
+ PreferenceScreen mScreen = mock(PreferenceScreen.class);
+ when(mScreen.findPreference("test_key")).thenReturn(mPreference);
+ mController.displayPreference(mScreen);
+ }
+
+ @Test
+ public void updateState_longPressPowerForPowerMenu_showsPowerMenuAnimation() {
+ PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.getLottieAnimationResId())
+ .isEqualTo(R.raw.lottie_long_press_power_for_power_menu);
+ }
+
+ @Test
+ public void updateState_longPressPowerForAssistant_showsAssistantAnimation() {
+ PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.getLottieAnimationResId())
+ .isEqualTo(R.raw.lottie_long_press_power_for_assistant);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/gestures/LongPressPowerSensitivityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/LongPressPowerSensitivityPreferenceControllerTest.java
index 9c99092849d..d1c09223b2d 100644
--- a/tests/robotests/src/com/android/settings/gestures/LongPressPowerSensitivityPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/LongPressPowerSensitivityPreferenceControllerTest.java
@@ -26,14 +26,20 @@ import android.app.Application;
import android.content.res.Resources;
import android.provider.Settings;
+import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
+import com.android.settings.widget.LabeledSeekBarPreference;
+import com.android.settingslib.testutils.shadow.ShadowInteractionJankMonitor;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
+@Config(shadows = {ShadowInteractionJankMonitor.class})
public class LongPressPowerSensitivityPreferenceControllerTest {
private static final String KEY_LONG_PRESS_SENSITIVITY =
@@ -43,7 +49,9 @@ public class LongPressPowerSensitivityPreferenceControllerTest {
private Application mContext;
private Resources mResources;
+ private LabeledSeekBarPreference mPreference;
private LongPressPowerSensitivityPreferenceController mController;
+ private PreferenceScreen mScreen;
@Before
public void setUp() {
@@ -52,11 +60,22 @@ public class LongPressPowerSensitivityPreferenceControllerTest {
when(mContext.getResources()).thenReturn(mResources);
when(mResources.getIntArray(
- com.android.internal.R.array.config_longPressOnPowerDurationSettings))
+ com.android.internal.R.array.config_longPressOnPowerDurationSettings))
.thenReturn(SENSITIVITY_VALUES);
+ when(mResources.getBoolean(
+ com.android.internal.R.bool
+ .config_longPressOnPowerForAssistantSettingAvailable))
+ .thenReturn(true);
+ when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
+ .thenReturn(5); // Default to Assistant
+ mPreference = new LabeledSeekBarPreference(mContext, null);
mController = new LongPressPowerSensitivityPreferenceController(mContext,
KEY_LONG_PRESS_SENSITIVITY);
+
+ mScreen = mock(PreferenceScreen.class);
+ when(mScreen.findPreference(KEY_LONG_PRESS_SENSITIVITY)).thenReturn(mPreference);
+ mController.displayPreference(mScreen);
}
@Test
@@ -98,46 +117,64 @@ public class LongPressPowerSensitivityPreferenceControllerTest {
}
@Test
- public void longPressForAssistEnabled_isAvailable() {
- Settings.Global.putInt(mContext.getContentResolver(),
- Settings.Global.POWER_BUTTON_LONG_PRESS,
- PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE);
+ public void longPressForAssistant_isVisible() {
+ PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
- assertThat(mController.getAvailabilityStatus()).isEqualTo(
- LongPressPowerSensitivityPreferenceController.AVAILABLE);
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.isVisible()).isTrue();
}
@Test
- public void longPressForAssistDisabled_isNotAvailableDueToDependentSetting() {
- Settings.Global.putInt(mContext.getContentResolver(),
- Settings.Global.POWER_BUTTON_LONG_PRESS,
- PowerMenuSettingsUtils.LONG_PRESS_POWER_NO_ACTION);
+ public void longPressForPowerMenu_isHidden() {
+ PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
- assertThat(mController.getAvailabilityStatus()).isEqualTo(
- LongPressPowerSensitivityPreferenceController.DISABLED_DEPENDENT_SETTING);
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.isVisible()).isFalse();
}
@Test
- public void sensitivityValuesAreNull_notAvailable() {
+ public void longPressPowerSettingNotAvailable_notAvailable_isHidden() {
+ when(mResources.getBoolean(
+ com.android.internal.R.bool
+ .config_longPressOnPowerForAssistantSettingAvailable))
+ .thenReturn(false);
+
+ mController.updateState(mPreference);
+
+ assertThat(mController.getAvailabilityStatus())
+ .isEqualTo(LongPressPowerSensitivityPreferenceController.UNSUPPORTED_ON_DEVICE);
+ assertThat(mPreference.isVisible()).isFalse();
+ }
+
+ @Test
+ public void sensitivityValuesAreNull_notAvailable_isHidden() {
when(mResources.getIntArray(
com.android.internal.R.array.config_longPressOnPowerDurationSettings))
.thenReturn(null);
mController = new LongPressPowerSensitivityPreferenceController(mContext,
KEY_LONG_PRESS_SENSITIVITY);
+ mController.displayPreference(mScreen);
+ mController.updateState(mPreference);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
LongPressPowerSensitivityPreferenceController.UNSUPPORTED_ON_DEVICE);
+ assertThat(mPreference.isVisible()).isFalse();
}
@Test
- public void sensitivityValuesArrayTooShort_notAvailable() {
+ public void sensitivityValuesArrayTooShort_notAvailable_isHidden() {
when(mResources.getIntArray(
com.android.internal.R.array.config_longPressOnPowerDurationSettings))
.thenReturn(new int[]{200});
mController = new LongPressPowerSensitivityPreferenceController(mContext,
KEY_LONG_PRESS_SENSITIVITY);
+ mController.displayPreference(mScreen);
+ mController.updateState(mPreference);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
LongPressPowerSensitivityPreferenceController.UNSUPPORTED_ON_DEVICE);
+ assertThat(mPreference.isVisible()).isFalse();
}
}
diff --git a/tests/robotests/src/com/android/settings/gestures/PowerMenuPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/PowerMenuPreferenceControllerTest.java
index 1a82a139922..0dc16ccded7 100644
--- a/tests/robotests/src/com/android/settings/gestures/PowerMenuPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/PowerMenuPreferenceControllerTest.java
@@ -18,20 +18,21 @@ package com.android.settings.gestures;
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.res.Resources;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class PowerMenuPreferenceControllerTest {
@@ -41,35 +42,75 @@ public class PowerMenuPreferenceControllerTest {
private static final String KEY_GESTURE_POWER_MENU = "gesture_power_menu";
-
@Before
public void setUp() {
- mContext = spy(RuntimeEnvironment.application);
- mResources = mock(Resources.class);
- when(mResources.getBoolean(
- com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
- .thenReturn(true);
- when(mContext.getResources()).thenReturn(mResources);
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ mResources = spy(mContext.getResources());
mController = new PowerMenuPreferenceController(mContext, KEY_GESTURE_POWER_MENU);
+
+ when(mContext.getResources()).thenReturn(mResources);
+ when(mResources.getBoolean(
+ com.android.internal.R.bool
+ .config_longPressOnPowerForAssistantSettingAvailable))
+ .thenReturn(true);
+ when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
+ .thenReturn(1); // Default to power menu
}
@Test
- public void getAvailabilityStatus_assistAvailable_available() {
+ public void getAvailabilityStatus_settingsAvailable_returnsAvailable() {
when(mResources.getBoolean(
- com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
- .thenReturn(true);
+ com.android.internal.R.bool
+ .config_longPressOnPowerForAssistantSettingAvailable))
+ .thenReturn(true);
+ when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
+ .thenReturn(1); // Default to power menu
- assertThat(mController.getAvailabilityStatus()).isEqualTo(
- BasePreferenceController.AVAILABLE);
+ assertThat(mController.getAvailabilityStatus())
+ .isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
- public void getAvailabilityStatus_assistUnavailable_unavailable() {
+ public void getAvailabilityStatus_settingsNotAvailable_returnsNotAvailable() {
when(mResources.getBoolean(
- com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
- .thenReturn(false);
+ com.android.internal.R.bool
+ .config_longPressOnPowerForAssistantSettingAvailable))
+ .thenReturn(false);
+ when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
+ .thenReturn(1); // Default to power menu
- assertThat(mController.getAvailabilityStatus()).isEqualTo(
- BasePreferenceController.UNSUPPORTED_ON_DEVICE);
+ assertThat(mController.getAvailabilityStatus())
+ .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_longPressPowerSettingNotAvailable_returnsNotAvailable() {
+ when(mResources.getBoolean(
+ com.android.internal.R.bool
+ .config_longPressOnPowerForAssistantSettingAvailable))
+ .thenReturn(true);
+ when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
+ .thenReturn(3); // Default to power off (unsupported setup)
+
+ assertThat(mController.getAvailabilityStatus())
+ .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
+ }
+
+ @Test
+ public void getSummary_longPressPowerToAssistant_returnsNotAvailable() {
+ PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
+
+ assertThat(mController.getSummary().toString())
+ .isEqualTo(
+ mContext.getString(R.string.power_menu_summary_long_press_for_assistant));
+ }
+
+ @Test
+ public void getSummary_longPressPowerToPowerMenu_returnsNotAvailable() {
+ PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
+
+ assertThat(mController.getSummary().toString())
+ .isEqualTo(
+ mContext.getString(R.string.power_menu_summary_long_press_for_power_menu));
}
}
diff --git a/tests/robotests/src/com/android/settings/gestures/PowerMenuSettingsUtilsTest.java b/tests/robotests/src/com/android/settings/gestures/PowerMenuSettingsUtilsTest.java
index 25f03207284..3f16b63e71c 100644
--- a/tests/robotests/src/com/android/settings/gestures/PowerMenuSettingsUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/PowerMenuSettingsUtilsTest.java
@@ -44,48 +44,123 @@ public class PowerMenuSettingsUtilsTest {
mContext = spy(ApplicationProvider.getApplicationContext());
mResources = mock(Resources.class);
when(mContext.getResources()).thenReturn(mResources);
+
+ when(mResources.getBoolean(
+ com.android.internal.R.bool
+ .config_longPressOnPowerForAssistantSettingAvailable))
+ .thenReturn(true);
}
@Test
- public void longPressBehaviourValuePresent_returnsValue() {
- when(mResources.getInteger(
- com.android.internal.R.integer.config_longPressOnPowerBehavior))
- .thenReturn(0);
- Settings.Global.putInt(mContext.getContentResolver(),
- Settings.Global.POWER_BUTTON_LONG_PRESS, 1);
-
- assertThat(PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext)).isEqualTo(1);
+ public void isLongPressPowerForAssistantEnabled_valueSetToAssistant_returnsTrue() {
+ Settings.Global.putInt(
+ mContext.getContentResolver(), Settings.Global.POWER_BUTTON_LONG_PRESS, 5);
+ assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isTrue();
}
@Test
- public void longPressBehaviourValueNotPresent_returnsDefault() {
- when(mResources.getInteger(
- com.android.internal.R.integer.config_longPressOnPowerBehavior))
- .thenReturn(2);
-
- assertThat(PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext)).isEqualTo(2);
+ public void isLongPressPowerForAssistantEnabled_valueNotSetToAssistant_returnsFalse() {
+ Settings.Global.putInt(
+ mContext.getContentResolver(), Settings.Global.POWER_BUTTON_LONG_PRESS, 3);
+ assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isFalse();
}
@Test
- public void longPressBehaviourValueSetToAssistant_isAssistEnabledReturnsTrue() {
- Settings.Global.putInt(mContext.getContentResolver(),
- Settings.Global.POWER_BUTTON_LONG_PRESS, 5);
- assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)).isTrue();
+ public void isLongPressPowerForAssistantEnabled_valueNotSet_defaultToAssistant_returnsTrue() {
+ when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
+ .thenReturn(5);
+
+ assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isTrue();
}
@Test
- public void longPressBehaviourValueNotSetToAssistant_isAssistEnabledReturnsFalse() {
- Settings.Global.putInt(mContext.getContentResolver(),
- Settings.Global.POWER_BUTTON_LONG_PRESS, 3);
- assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)).isFalse();
+ public void isLongPressPowerForAssistantEnabled_valueNotSet_defaultToPowerMenu_returnsFalse() {
+ when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
+ .thenReturn(1);
+
+ assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistantEnabled(mContext)).isFalse();
}
@Test
- public void longPressBehaviourDefaultSetToAssistant_isAssistEnabledReturnsFalse() {
- when(mResources.getInteger(
- com.android.internal.R.integer.config_longPressOnPowerBehavior))
+ public void isLongPressPowerSettingAvailable_defaultToAssistant_returnsTrue() {
+ when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
+ .thenReturn(5);
+ assertThat(PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)).isTrue();
+ }
+
+ @Test
+ public void isLongPressPowerSettingAvailable_defaultToPowerMenu_returnsTrue() {
+ when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
+ .thenReturn(1);
+ assertThat(PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)).isTrue();
+ }
+
+ @Test
+ public void isLongPressPowerSettingAvailable_defaultToPowerOff_returnsFalse() {
+ // Power off is the unsupported option in long press power settings
+ when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
.thenReturn(3);
+ assertThat(PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)).isFalse();
+ }
- assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)).isFalse();
+ @Test
+ public void isLongPressPowerSettingAvailable_settingDisabled_returnsFalse() {
+ // Disable the setting
+ when(mResources.getBoolean(
+ com.android.internal.R.bool
+ .config_longPressOnPowerForAssistantSettingAvailable))
+ .thenReturn(false);
+ when(mResources.getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior))
+ .thenReturn(1);
+
+ assertThat(PowerMenuSettingsUtils.isLongPressPowerSettingAvailable(mContext)).isFalse();
+ }
+
+ @Test
+ public void setLongPressPowerForAssistant_updatesValue() throws Exception {
+ boolean result = PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
+
+ assertThat(result).isTrue();
+ assertThat(
+ Settings.Global.getInt(
+ mContext.getContentResolver(),
+ Settings.Global.POWER_BUTTON_LONG_PRESS))
+ .isEqualTo(5);
+ }
+
+ @Test
+ public void setLongPressPowerForAssistant_updatesKeyChordValueToPowerMenu() throws Exception {
+ PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
+ assertThat(
+ Settings.Global.getInt(
+ mContext.getContentResolver(),
+ Settings.Global.KEY_CHORD_POWER_VOLUME_UP))
+ .isEqualTo(2);
+ }
+
+ @Test
+ public void setLongPressPowerForPowerMenu_updatesValue() throws Exception {
+ boolean result = PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
+
+ assertThat(result).isTrue();
+ assertThat(
+ Settings.Global.getInt(
+ mContext.getContentResolver(),
+ Settings.Global.POWER_BUTTON_LONG_PRESS))
+ .isEqualTo(1);
+ }
+
+ @Test
+ public void setLongPressPowerForPowerMenu_updatesKeyChordValueToDefault() throws Exception {
+ when(mResources.getInteger(com.android.internal.R.integer.config_keyChordPowerVolumeUp))
+ .thenReturn(1);
+
+ PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
+
+ assertThat(
+ Settings.Global.getInt(
+ mContext.getContentResolver(),
+ Settings.Global.KEY_CHORD_POWER_VOLUME_UP))
+ .isEqualTo(1);
}
}
diff --git a/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java
index b2f1673f317..bf529e67568 100644
--- a/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java
@@ -426,7 +426,7 @@ public class NotificationPreferenceControllerTest {
private final class TestPreferenceController extends NotificationPreferenceController {
private TestPreferenceController(Context context, NotificationBackend backend) {
- super(context, backend);
+ super(context, backend, "key");
}
@Override