Merge "Use binder thread by default for IImsConfig AIDL Interface"
diff --git a/Android.bp b/Android.bp
index 3d0188a..2740ccc 100644
--- a/Android.bp
+++ b/Android.bp
@@ -102,6 +102,7 @@
         ":android.hardware.keymaster-V4-java-source",
         ":android.hardware.security.keymint-V3-java-source",
         ":android.hardware.security.secureclock-V1-java-source",
+        ":android.hardware.thermal-V1-java-source",
         ":android.hardware.tv.tuner-V2-java-source",
         ":android.security.apc-java-source",
         ":android.security.authorization-java-source",
@@ -404,6 +405,7 @@
         "framework-permission-aidl-java",
         "spatializer-aidl-java",
         "audiopolicy-types-aidl-java",
+        "sounddose-aidl-java",
     ],
 }
 
diff --git a/apct-tests/perftests/rubidium/Android.bp b/apct-tests/perftests/rubidium/Android.bp
index ba2b442..ebd228f 100644
--- a/apct-tests/perftests/rubidium/Android.bp
+++ b/apct-tests/perftests/rubidium/Android.bp
@@ -32,6 +32,7 @@
         "collector-device-lib-platform",
         "compatibility-device-util-axt",
         "platform-test-annotations",
+        "framework-adservices-lib",
         "adservices-service-core",
         "androidx.core_core",
     ],
diff --git a/apct-tests/perftests/rubidium/assets/rubidium_bidding_logic_compiled.js b/apct-tests/perftests/rubidium/assets/rubidium_bidding_logic_compiled.js
new file mode 100644
index 0000000..3f853f1
--- /dev/null
+++ b/apct-tests/perftests/rubidium/assets/rubidium_bidding_logic_compiled.js
@@ -0,0 +1,72 @@
+/*
+
+ Copyright The Closure Library Authors.
+ SPDX-License-Identifier: Apache-2.0
+*/
+'use strict';function ba(a){var b=0;return function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}}}var ca="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){if(a==Array.prototype||a==Object.prototype)return a;a[b]=c.value;return a};
+function da(a){a=["object"==typeof globalThis&&globalThis,a,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var b=0;b<a.length;++b){var c=a[b];if(c&&c.Math==Math)return c}throw Error("Cannot find global object");}var fa=da(this);function m(a,b){if(b)a:{var c=fa;a=a.split(".");for(var d=0;d<a.length-1;d++){var f=a[d];if(!(f in c))break a;c=c[f]}a=a[a.length-1];d=c[a];b=b(d);b!=d&&null!=b&&ca(c,a,{configurable:!0,writable:!0,value:b})}}
+m("Symbol",function(a){function b(e){if(this instanceof b)throw new TypeError("Symbol is not a constructor");return new c(d+(e||"")+"_"+f++,e)}function c(e,h){this.h=e;ca(this,"description",{configurable:!0,writable:!0,value:h})}if(a)return a;c.prototype.toString=function(){return this.h};var d="jscomp_symbol_"+(1E9*Math.random()>>>0)+"_",f=0;return b});
+m("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var b="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),c=0;c<b.length;c++){var d=fa[b[c]];"function"===typeof d&&"function"!=typeof d.prototype[a]&&ca(d.prototype,a,{configurable:!0,writable:!0,value:function(){return ia(ba(this))}})}return a});function ia(a){a={next:a};a[Symbol.iterator]=function(){return this};return a}
+function p(a){var b="undefined"!=typeof Symbol&&Symbol.iterator&&a[Symbol.iterator];return b?b.call(a):{next:ba(a)}}function ja(a){if(!(a instanceof Array)){a=p(a);for(var b,c=[];!(b=a.next()).done;)c.push(b.value);a=c}return a}var la="function"==typeof Object.create?Object.create:function(a){function b(){}b.prototype=a;return new b},ma;
+if("function"==typeof Object.setPrototypeOf)ma=Object.setPrototypeOf;else{var na;a:{var oa={a:!0},qa={};try{qa.__proto__=oa;na=qa.a;break a}catch(a){}na=!1}ma=na?function(a,b){a.__proto__=b;if(a.__proto__!==b)throw new TypeError(a+" is not extensible");return a}:null}var ra=ma;
+function q(a,b){a.prototype=la(b.prototype);a.prototype.constructor=a;if(ra)ra(a,b);else for(var c in b)if("prototype"!=c)if(Object.defineProperties){var d=Object.getOwnPropertyDescriptor(b,c);d&&Object.defineProperty(a,c,d)}else a[c]=b[c];a.Ia=b.prototype}function sa(){for(var a=Number(this),b=[],c=a;c<arguments.length;c++)b[c-a]=arguments[c];return b}function ta(a,b){return Object.prototype.hasOwnProperty.call(a,b)}
+m("WeakMap",function(a){function b(k){this.h=(g+=Math.random()+1).toString();if(k){k=p(k);for(var l;!(l=k.next()).done;)l=l.value,this.set(l[0],l[1])}}function c(){}function d(k){var l=typeof k;return"object"===l&&null!==k||"function"===l}function f(k){if(!ta(k,h)){var l=new c;ca(k,h,{value:l})}}function e(k){var l=Object[k];l&&(Object[k]=function(n){if(n instanceof c)return n;Object.isExtensible(n)&&f(n);return l(n)})}if(function(){if(!a||!Object.seal)return!1;try{var k=Object.seal({}),l=Object.seal({}),
+n=new a([[k,2],[l,3]]);if(2!=n.get(k)||3!=n.get(l))return!1;n.delete(k);n.set(l,4);return!n.has(k)&&4==n.get(l)}catch(t){return!1}}())return a;var h="$jscomp_hidden_"+Math.random();e("freeze");e("preventExtensions");e("seal");var g=0;b.prototype.set=function(k,l){if(!d(k))throw Error("Invalid WeakMap key");f(k);if(!ta(k,h))throw Error("WeakMap key fail: "+k);k[h][this.h]=l;return this};b.prototype.get=function(k){return d(k)&&ta(k,h)?k[h][this.h]:void 0};b.prototype.has=function(k){return d(k)&&ta(k,
+h)&&ta(k[h],this.h)};b.prototype.delete=function(k){return d(k)&&ta(k,h)&&ta(k[h],this.h)?delete k[h][this.h]:!1};return b});
+m("Map",function(a){function b(){var g={};return g.C=g.next=g.head=g}function c(g,k){var l=g.h;return ia(function(){if(l){for(;l.head!=g.h;)l=l.C;for(;l.next!=l.head;)return l=l.next,{done:!1,value:k(l)};l=null}return{done:!0,value:void 0}})}function d(g,k){var l=k&&typeof k;"object"==l||"function"==l?e.has(k)?l=e.get(k):(l=""+ ++h,e.set(k,l)):l="p_"+k;var n=g.u[l];if(n&&ta(g.u,l))for(g=0;g<n.length;g++){var t=n[g];if(k!==k&&t.key!==t.key||k===t.key)return{id:l,list:n,index:g,m:t}}return{id:l,list:n,
+index:-1,m:void 0}}function f(g){this.u={};this.h=b();this.size=0;if(g){g=p(g);for(var k;!(k=g.next()).done;)k=k.value,this.set(k[0],k[1])}}if(function(){if(!a||"function"!=typeof a||!a.prototype.entries||"function"!=typeof Object.seal)return!1;try{var g=Object.seal({x:4}),k=new a(p([[g,"s"]]));if("s"!=k.get(g)||1!=k.size||k.get({x:4})||k.set({x:4},"t")!=k||2!=k.size)return!1;var l=k.entries(),n=l.next();if(n.done||n.value[0]!=g||"s"!=n.value[1])return!1;n=l.next();return n.done||4!=n.value[0].x||
+"t"!=n.value[1]||!l.next().done?!1:!0}catch(t){return!1}}())return a;var e=new WeakMap;f.prototype.set=function(g,k){g=0===g?0:g;var l=d(this,g);l.list||(l.list=this.u[l.id]=[]);l.m?l.m.value=k:(l.m={next:this.h,C:this.h.C,head:this.h,key:g,value:k},l.list.push(l.m),this.h.C.next=l.m,this.h.C=l.m,this.size++);return this};f.prototype.delete=function(g){g=d(this,g);return g.m&&g.list?(g.list.splice(g.index,1),g.list.length||delete this.u[g.id],g.m.C.next=g.m.next,g.m.next.C=g.m.C,g.m.head=null,this.size--,
+!0):!1};f.prototype.clear=function(){this.u={};this.h=this.h.C=b();this.size=0};f.prototype.has=function(g){return!!d(this,g).m};f.prototype.get=function(g){return(g=d(this,g).m)&&g.value};f.prototype.entries=function(){return c(this,function(g){return[g.key,g.value]})};f.prototype.keys=function(){return c(this,function(g){return g.key})};f.prototype.values=function(){return c(this,function(g){return g.value})};f.prototype.forEach=function(g,k){for(var l=this.entries(),n;!(n=l.next()).done;)n=n.value,
+g.call(k,n[1],n[0],this)};f.prototype[Symbol.iterator]=f.prototype.entries;var h=0;return f});m("Number.isNaN",function(a){return a?a:function(b){return"number"===typeof b&&isNaN(b)}});function ua(a,b){a instanceof String&&(a+="");var c=0,d=!1,f={next:function(){if(!d&&c<a.length){var e=c++;return{value:b(e,a[e]),done:!1}}d=!0;return{done:!0,value:void 0}}};f[Symbol.iterator]=function(){return f};return f}m("Array.prototype.values",function(a){return a?a:function(){return ua(this,function(b,c){return c})}});
+m("Set",function(a){function b(c){this.h=new Map;if(c){c=p(c);for(var d;!(d=c.next()).done;)this.add(d.value)}this.size=this.h.size}if(function(){if(!a||"function"!=typeof a||!a.prototype.entries||"function"!=typeof Object.seal)return!1;try{var c=Object.seal({x:4}),d=new a(p([c]));if(!d.has(c)||1!=d.size||d.add(c)!=d||1!=d.size||d.add({x:4})!=d||2!=d.size)return!1;var f=d.entries(),e=f.next();if(e.done||e.value[0]!=c||e.value[1]!=c)return!1;e=f.next();return e.done||e.value[0]==c||4!=e.value[0].x||
+e.value[1]!=e.value[0]?!1:f.next().done}catch(h){return!1}}())return a;b.prototype.add=function(c){c=0===c?0:c;this.h.set(c,c);this.size=this.h.size;return this};b.prototype.delete=function(c){c=this.h.delete(c);this.size=this.h.size;return c};b.prototype.clear=function(){this.h.clear();this.size=0};b.prototype.has=function(c){return this.h.has(c)};b.prototype.entries=function(){return this.h.entries()};b.prototype.values=function(){return this.h.values()};b.prototype.keys=b.prototype.values;b.prototype[Symbol.iterator]=
+b.prototype.values;b.prototype.forEach=function(c,d){var f=this;this.h.forEach(function(e){return c.call(d,e,e,f)})};return b});m("globalThis",function(a){return a||fa});m("Object.is",function(a){return a?a:function(b,c){return b===c?0!==b||1/b===1/c:b!==b&&c!==c}});m("Array.prototype.includes",function(a){return a?a:function(b,c){var d=this;d instanceof String&&(d=String(d));var f=d.length;c=c||0;for(0>c&&(c=Math.max(c+f,0));c<f;c++){var e=d[c];if(e===b||Object.is(e,b))return!0}return!1}});
+m("String.prototype.includes",function(a){return a?a:function(b,c){if(null==this)throw new TypeError("The 'this' value for String.prototype.includes must not be null or undefined");if(b instanceof RegExp)throw new TypeError("First argument to String.prototype.includes must not be a regular expression");return-1!==this.indexOf(b,c||0)}});m("Object.values",function(a){return a?a:function(b){var c=[],d;for(d in b)ta(b,d)&&c.push(b[d]);return c}});
+function va(a){var b=typeof a;return"object"==b&&null!=a||"function"==b};var wa={};var xa=Array.prototype.map?function(a,b){return Array.prototype.map.call(a,b,void 0)}:function(a,b){for(var c=a.length,d=Array(c),f="string"===typeof a?a.split(""):a,e=0;e<c;e++)e in f&&(d[e]=b.call(void 0,f[e],e,a));return d};var ya={},za=null;function Aa(a,b){void 0===b&&(b=0);Ba();b=ya[b];for(var c=Array(Math.floor(a.length/3)),d=b[64]||"",f=0,e=0;f<a.length-2;f+=3){var h=a[f],g=a[f+1],k=a[f+2],l=b[h>>2];h=b[(h&3)<<4|g>>4];g=b[(g&15)<<2|k>>6];k=b[k&63];c[e++]=l+h+g+k}l=0;k=d;switch(a.length-f){case 2:l=a[f+1],k=b[(l&15)<<2]||d;case 1:a=a[f],c[e]=b[a>>2]+b[(a&3)<<4|l>>4]+k+d}return c.join("")}
+function Ca(a){var b=a.length,c=3*b/4;c%3?c=Math.floor(c):-1!="=.".indexOf(a[b-1])&&(c=-1!="=.".indexOf(a[b-2])?c-2:c-1);var d=new Uint8Array(c),f=0;Da(a,function(e){d[f++]=e});return f!==c?d.subarray(0,f):d}
+function Da(a,b){function c(k){for(;d<a.length;){var l=a.charAt(d++),n=za[l];if(null!=n)return n;if(!/^[\s\xa0]*$/.test(l))throw Error("Unknown base64 encoding at char: "+l);}return k}Ba();for(var d=0;;){var f=c(-1),e=c(0),h=c(64),g=c(64);if(64===g&&-1===f)break;b(f<<2|e>>4);64!=h&&(b(e<<4&240|h>>2),64!=g&&b(h<<6&192|g))}}
+function Ba(){if(!za){za={};for(var a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),b=["+/=","+/","-_=","-_.","-_"],c=0;5>c;c++){var d=a.concat(b[c].split(""));ya[c]=d;for(var f=0;f<d.length;f++){var e=d[f];void 0===za[e]&&(za[e]=f)}}}};var Ea="undefined"!==typeof Uint8Array;function Fa(a){return null==a||Ga(a)?a:"string"===typeof a?Ca(a):null}function Ga(a){return Ea&&null!=a&&a instanceof Uint8Array}var Ha={};var Ia;function Qa(a){if(a!==Ha)throw Error("illegal external caller");}function Ra(a,b){Qa(b);this.aa=a;if(null!=a&&0===a.length)throw Error("ByteString should be constructed with non-empty values");}function Sa(){return Ia||(Ia=new Ra(null,Ha))}function Ta(a){var b=a.aa;return null==b?"":"string"===typeof b?b:a.aa=Aa(b)};var r="function"===typeof Symbol&&"symbol"===typeof Symbol()?Symbol():void 0;function u(a,b){if(r)return a[r]|=b;if(void 0!==a.A)return a.A|=b;Object.defineProperties(a,{A:{value:b,configurable:!0,writable:!0,enumerable:!1}});return b}function Ua(a,b){r?a[r]&&(a[r]&=~b):void 0!==a.A&&(a.A&=~b)}function v(a){var b;r?b=a[r]:b=a.A;return null==b?0:b}function Va(a,b){r?a[r]=b:void 0!==a.A?a.A=b:Object.defineProperties(a,{A:{value:b,configurable:!0,writable:!0,enumerable:!1}})}
+function $a(a){u(a,1);return a}function w(a){return!!(v(a)&2)}function ab(a){u(a,16);return a}function bb(a,b){Va(b,(a|0)&-51)}function cb(a,b){Va(b,(a|18)&-41)};var db={};function eb(a){return null!==a&&"object"===typeof a&&!Array.isArray(a)&&a.constructor===Object}function fb(a){a instanceof Ra&&(Qa(Ha),a=a.aa||"");return a}var gb,hb=[];Va(hb,23);gb=Object.freeze(hb);function ib(a){if(w(a.i))throw Error("Cannot mutate an immutable Message");}function jb(a){var b=a.length;(b=b?a[b-1]:void 0)&&eb(b)?b.g=1:(b={},a.push((b.g=1,b)))};function kb(a){return a}function lb(a){return a};function mb(a,b){a=a||{};b=b||{};var c={},d;for(d in a)c[d]=0;for(var f in b)c[f]=0;for(var e in c)if(!nb(a[e],b[e]))return!1;return!0}function ob(a){return a&&"object"===typeof a?a.i||a:a}
+function nb(a,b){a=fb(a);b=fb(b);a=ob(a);b=ob(b);if(a==b)return!0;if(Ea){var c=Ga(a),d=Ga(b);if(c||d){if(!c)if("string"===typeof a)a=Fa(a);else return!1;if(d)d=b;else if("string"===typeof b)d=Fa(b);else return!1;if(a.length!==d.length)return!1;for(b=0;b<a.length;b++)if(a[b]!==d[b])return!1;return!0}}if(null==a&&Array.isArray(b)&&v(b)&1&&!b.length||null==b&&Array.isArray(a)&&v(a)&1&&!a.length)return!0;if(!va(a)||!va(b))return"number"===typeof a&&isNaN(a)||"number"===typeof b&&isNaN(b)?String(a)==String(b):
+!1;if(a.constructor!=b.constructor)return!1;if(a.constructor===Array){d=a;c=a=void 0;for(var f=Math.max(d.length,b.length),e=0;e<f;e++){var h=d[e],g=b[e];h&&h.constructor==Object&&(a=h,h=void 0);g&&g.constructor==Object&&(c=g,g=void 0);if(!nb(h,g))return!1}return a||c?(a=a||{},c=c||{},mb(a,c)):!0}if(a.constructor===Object)return mb(a,b);throw Error("Invalid type in JSPB array");};var pb;function qb(a){switch(typeof a){case "number":return isFinite(a)?a:String(a);case "object":if(a)if(Array.isArray(a)){if(0!==(v(a)&128))return a=Array.prototype.slice.call(a),jb(a),a}else{if(Ga(a))return Aa(a);if(a instanceof Ra)return Ta(a)}}return a};function rb(a,b,c,d){if(null!=a){if(Array.isArray(a))a=sb(a,b,c,void 0!==d);else if(eb(a)){var f={},e;for(e in a)f[e]=rb(a[e],b,c,d);a=f}else a=b(a,d);return a}}function sb(a,b,c,d){var f=v(a);d=d?!!(f&16):void 0;a=Array.prototype.slice.call(a);for(var e=0;e<a.length;e++)a[e]=rb(a[e],b,c,d);c(f,a);return a}function tb(a){return a.Y===db?a.toJSON():qb(a)}function ub(a,b){a&128&&jb(b)};function vb(a){return a.h||(a.h=a.i[a.u+a.H]={})}function x(a,b,c){return-1===b?null:b>=a.u?a.h?a.h[b]:void 0:c&&a.h&&(c=a.h[b],null!=c)?c:a.i[b+a.H]}function wb(a,b,c,d){ib(a);return y(a,b,c,d)}function y(a,b,c,d){a.V&&(a.V=void 0);if(b>=a.u||d)return vb(a)[b]=c,a;a.i[b+a.H]=c;(c=a.h)&&b in c&&delete c[b];return a}
+function xb(a,b,c,d,f){var e=x(a,b,d);Array.isArray(e)||(e=gb);var h=v(e);h&1||$a(e);if(f)h&2||u(e,2),c&1||Object.freeze(e);else{f=!(c&2);var g=h&2;c&1||!g?f&&h&16&&!g&&Ua(e,16):(e=$a(Array.prototype.slice.call(e)),y(a,b,e,d))}return e}function yb(a,b){return xb(a,b,0,!1,w(a.i))}
+function B(a,b,c,d){var f=w(a.i),e=xb(a,b,1,d,f),h=v(e);if(!(h&4)){Object.isFrozen(e)&&(e=$a(e.slice()),y(a,b,e,d));for(var g=0,k=0;g<e.length;g++){var l=c(e[g]);null!=l&&(e[k++]=l)}k<g&&(e.length=k);u(e,5);f&&(u(e,2),Object.freeze(e))}!f&&(h&2||Object.isFrozen(e))&&(e=Array.prototype.slice.call(e),u(e,5),zb(a,b,e,d));return e}function Ub(a){return null==a?a:"string"===typeof a?a?new Ra(a,Ha):Sa():a.constructor===Ra?a:Ga(a)?a.length?new Ra(new Uint8Array(a),Ha):Sa():void 0}
+function E(a,b){a=x(a,b);return null==a?0:a}function zb(a,b,c,d){if(null==c)c=gb;else{var f=v(c);1!==(f&1)&&(Object.isFrozen(c)&&(c=Array.prototype.slice.call(c)),Va(c,f|1))}return wb(a,b,c,d)}function G(a,b,c,d){ib(a);c!==d?y(a,b,c):y(a,b,void 0,!1);return a}var Vb=Symbol(void 0);function Wb(a,b,c,d){var f=x(a,c,d);var e=!1;var h=null==f||"object"!==typeof f||(e=Array.isArray(f))||f.Y!==db?e?new b(f):void 0:f;h!==f&&null!=h&&(y(a,c,h,d),u(h.i,v(a.i)&-33));return h}
+function H(a,b,c){if(a=Wb(a,b,c,!1))b=a;else if(a=b[Vb])b=a;else{a=new b;if(wa!==wa)throw Error("requires a valid immutable API token");w(a.i)||((c=a.V)&&nb(c.i,a.i)?a=c:(c=Xb(a,!0),u(c.i,2),a=a.V=c));b=b[Vb]=a}return b}function J(a,b,c){var d=void 0===d?!1:d;b=Wb(a,b,c,d);if(null==b)return b;if(!w(a.i)){var f=Yb(b);f!==b&&(b=f,y(a,c,b,d))}return b}
+function Zb(a,b,c,d,f){a.o||(a.o={});var e=a.o[c],h=xb(a,c,3,void 0,f);if(e)f||(Object.isFrozen(e)?d||(e=Array.prototype.slice.call(e),a.o[c]=e):d&&Object.freeze(e));else{e=[];var g=!!(v(a.i)&16),k=w(h);!f&&k&&(h=$a(Array.prototype.slice.call(h)),y(a,c,h));for(var l=k,n=0;n<h.length;n++){var t=h[n];var I=b;var A=g,F=!1;F=void 0===F?!1:F;A=void 0===A?!1:A;I=Array.isArray(t)?new I(A?ab(t):t):F?new I:void 0;void 0!==I&&(l=l||w(t),e.push(I),k&&u(I.i,2))}a.o[c]=e;a=h;Object.isFrozen(a)||(b=v(a)|33,Va(a,
+l?b&-9:b|8));(f||d&&k)&&u(e,2);(f||d)&&Object.freeze(e)}return e}function K(a,b,c){var d=w(a.i);b=Zb(a,b,c,d,d);a=xb(a,c,3,void 0,d);if(!(d||v(a)&8)){for(d=0;d<b.length;d++){c=b[d];var f=Yb(c);c!==f&&(b[d]=f,a[d]=b[d].i)}u(a,8)}return b}function M(a,b,c){ib(a);null==c&&(c=void 0);return y(a,b,c)}function $b(a,b,c,d){ib(a);if(null!=c){var f=$a([]);for(var e=!1,h=0;h<c.length;h++)f[h]=c[h].i,e=e||w(f[h]);a.o||(a.o={});a.o[b]=c;c=f;e?Ua(c,8):u(c,8)}else a.o&&(a.o[b]=void 0),f=gb;return y(a,b,f,d)}
+function ac(a,b,c,d){ib(a);var f=Zb(a,c,b,!1,!1);c=null!=d?d:new c;a=xb(a,b,2,void 0,!1);f.push(c);a.push(c.i);w(c.i)&&Ua(a,8);return c}function N(a,b){return P(x(a,b),"0")}function P(a,b){return null==a?b:a}function R(a,b){a=x(a,b);return P(null==a?a:!!a,!1)}function S(a,b){a=x(a,b);return P(null==a?a:+a,0)}function T(a,b){return P(x(a,b),0)};function bc(a){var b=v(a);if(b&2)return a;a=xa(a,cc);cb(b,a);Object.freeze(a);return a}function dc(a,b,c){c=void 0===c?cb:c;if(null!=a){if(Ea&&a instanceof Uint8Array)return a.length?new Ra(new Uint8Array(a),Ha):Sa();if(Array.isArray(a)){var d=v(a);if(d&2)return a;if(b&&!(d&32)&&(d&16||0===d))return Va(a,d|2),a;a=sb(a,dc,c,!0);b=v(a);b&4&&b&2&&Object.freeze(a);return a}return a.Y===db?cc(a):a}}function cc(a){if(w(a.i))return a;a=Xb(a,!0);u(a.i,2);return a}
+function Xb(a,b){var c=a.i,d=ab([]),f=a.constructor.h;f&&d.push(f);0!==(v(c)&128)&&jb(d);b=b||w(a.i)?cb:bb;f=a.constructor;pb=d;d=new f(d);pb=void 0;a.ca&&(d.ca=a.ca.slice());f=!!(v(c)&16);for(var e=0;e<c.length;e++){var h=c[e];if(e===c.length-1&&eb(h))for(var g in h){var k=+g;if(Number.isNaN(k))vb(d)[k]=h[k];else{var l=h[g],n=a.o&&a.o[k];n?$b(d,k,bc(n),!0):wb(d,k,dc(l,f,b),!0)}}else k=e-a.H,(l=a.o&&a.o[k])?$b(d,k,bc(l),!1):wb(d,k,dc(h,f,b),!1)}return d}
+function Yb(a){if(!w(a.i))return a;var b=Xb(a,!1);b.V=a;return b};function V(a,b,c){null==a&&(a=pb);pb=void 0;var d=this.constructor.u||0,f=0<d,e=this.constructor.h,h=!1;if(null==a){a=e?[e]:[];var g=!0;Va(a,48)}else{if(!Array.isArray(a))throw Error();if(e&&e!==a[0])throw Error();var k=u(a,0),l=k;if(g=0!==(16&l))(h=0!==(32&l))||(l|=32);if(f)if(128&l)d=0;else{if(0<a.length){var n=a[a.length-1];if(eb(n)&&"g"in n){d=0;l|=128;delete n.g;var t=!0,I;for(I in n){t=!1;break}t&&a.pop()}}}else if(128&l)throw Error();k!==l&&Va(a,l)}this.H=(e?0:-1)-d;this.o=void 0;this.i=a;
+a:{e=this.i.length;d=e-1;if(e&&(e=this.i[d],eb(e))){this.h=e;this.u=d-this.H;break a}void 0!==b&&-1<b?(this.u=Math.max(b,d+1-this.H),this.h=void 0):this.u=Number.MAX_VALUE}if(!f&&this.h&&"g"in this.h)throw Error('Unexpected "g" flag in sparse object of message that is not a group type.');if(c){b=g&&!h&&!0;f=this.u;var A;for(g=0;g<c.length;g++)h=c[g],h<f?(h+=this.H,(d=a[h])?ec(d,b):a[h]=gb):(A||(A=vb(this)),(d=A[h])?ec(d,b):A[h]=gb)}}V.prototype.toJSON=function(){return sb(this.i,tb,ub)};
+function ec(a,b){if(Array.isArray(a)){var c=v(a),d=1;!b||c&2||(d|=16);(c&d)!==d&&Va(a,c|d)}}V.prototype.Y=db;V.prototype.toString=function(){return this.i.toString()};var fc=void 0;function gc(a){var b=fc;fc=void 0;if(!Array.isArray(a))throw b=b?b()+"\n":"",Error(b+String(a));return a};function hc(a){return JSON.stringify([a.map(function(b){var c={};return[(c[b.ta]=b.message.toJSON(),c)]})])};function ic(a){this.h=a}ic.prototype.sa=function(){var a=encodeURIComponent;var b=hc(sa.apply(0,arguments));for(var c=[],d=0,f=0;f<b.length;f++){var e=b.charCodeAt(f);255<e&&(c[d++]=e&255,e>>=8);c[d++]=e}b=Aa(c,3);a=a(b);this.h("https://pagead2.googlesyndication.com/pagead/ping?e=3&d="+a)};function jc(a){V.call(this,a)}q(jc,V);function kc(a){V.call(this,a)}q(kc,V);function lc(a){V.call(this,a,-1,mc)}q(lc,V);var mc=[6];function nc(a){V.call(this,a,-1,oc)}q(nc,V);var oc=[2,3,4];function pc(a){V.call(this,a,-1,qc)}q(pc,V);var qc=[2];function rc(a){V.call(this,a,-1,sc)}q(rc,V);var sc=[1,3,10,7,8];function tc(a){V.call(this,a)}q(tc,V);function uc(a){V.call(this,a,-1,vc)}q(uc,V);var vc=[3];function wc(a){V.call(this,a,-1,xc)}q(wc,V);var xc=[3];function yc(a){V.call(this,a,-1,zc)}q(yc,V);var zc=[2,3,5];function Ac(a){V.call(this,a,-1,Bc)}q(Ac,V);function Cc(a){V.call(this,a,-1,Dc)}q(Cc,V);function Ec(a){V.call(this,a,-1,Fc)}q(Ec,V);var Bc=[1,2],Dc=[3,4,9],Fc=[3,4,5,6,7];function Gc(a){V.call(this,a,-1,Hc)}q(Gc,V);var Hc=[15];function Ic(a){V.call(this,a)}q(Ic,V);function Jc(a){V.call(this,a,-1,Kc)}q(Jc,V);var Kc=[1];function Lc(a){V.call(this,a)}q(Lc,V);function Mc(a){V.call(this,a)}q(Mc,V);function Nc(a){V.call(this,a,-1,Oc)}q(Nc,V);var Oc=[9,10,11,12,13,14,15,17];function Pc(a){V.call(this,a,-1,Qc)}q(Pc,V);var Qc=[1];function Zd(a){V.call(this,a)}q(Zd,V);function $d(a){V.call(this,a,-1,ae)}q($d,V);function W(a){return J(a,be,3)}function ce(a){V.call(this,a,-1,de)}q(ce,V);function ee(a){V.call(this,a)}q(ee,V);function be(a){V.call(this,a)}q(be,V);function fe(a){V.call(this,a)}q(fe,V);function ge(a){V.call(this,a)}q(ge,V);function he(a){var b=new ge;return G(b,1,a,0)}function ie(a){V.call(this,a,-1,je)}q(ie,V);function ke(a){V.call(this,a)}q(ke,V);var ae=[2],de=[1,2,3],je=[1,3];function le(a){V.call(this,a,-1,me)}q(le,V);var me=[10];function ne(a){a.sa.apply(a,ja(sa.apply(1,arguments).map(function(b){return{ta:9,message:b}})))};function oe(a,b){return!b||0>=b?a:Math.min(a,b)}function X(a,b,c){return b?b:c?c:a?1:0}function pe(a,b){return a&&0<a.length?a:b&&0<b.length?b:[]}function qe(a){a=null==a?void 0:E(a,9);return void 0===a?!1:[61,51,52].includes(a)};function re(a,b){if(!b||0>=b)return{j:0,B:2};var c=null==a?void 0:J(a,ie,18),d,f=null==a?void 0:null==(d=W(a))?void 0:J(d,ie,11);d=null==a?void 0:J(a,fe,7);if(!c&&!f){var e;f=null==a?void 0:null==(e=W(a))?void 0:J(e,fe,4);e=X(!0,null==d?void 0:S(d,1),null==f?void 0:S(f,1));a=X(!1,null==d?void 0:S(d,2),null==f?void 0:S(f,2));c=X(!1,null==d?void 0:S(d,3),null==f?void 0:S(f,3));var h,g;d=X(!1,null==d?void 0:null==(h=J(d,ge,5))?void 0:S(h,1),null==f?void 0:null==(g=J(f,ge,5))?void 0:S(g,1));h=new fe;
+g=G(h,1,e,0);g=G(g,2,a,0);g=G(g,3,c,0);f=he(d);M(g,5,f);return{j:b*e*(1-1/(1+Math.exp(-a*(Math.log(b/1E6)-d-c)))),B:1,J:4,ba:h}}if(c||f){e=X(!1,null==c?void 0:S(c,2),null==f?void 0:S(f,2));a=pe(null==c?void 0:B(c,3,Number),null==f?void 0:B(f,3,Number));c=pe(null==c?void 0:yb(c,1),null==f?void 0:yb(f,1));h=[];g=p(c);for(f=g.next();!f.done;f=g.next())switch(f.value){case 1:h.push(1E-6*b);break;case 2:var k=f=void 0,l=null==(f=d)?void 0:null==(k=J(f,ge,5))?void 0:S(k,1);h.push("number"===typeof l?Math.exp(l):
+0)}d=se(a,h);1===d.B?(b=new ie,b=zb(b,3,a),b=zb(b,1,c),b=G(b,2,e,0),d.ba=b,b=d):b=0>=e||1<e?d:{j:b*e,B:d.B,J:9}}else b={j:0,B:3};return b}
+function se(a,b){if(0===a.length||0>a[0])return{j:0,B:5};var c=b.length;if(a.length!==1+2*(1+c))return{j:0,B:6};for(var d=c+2,f=a[1],e=a[d],h=0;h<c;h++){var g=1+h;if(0>=b[h]){if(1E-9>Math.abs(a[1+g])&&1E-9>Math.abs(a[d+g]))continue;return{j:0,B:4}}var k=Math.log(b[h]);f+=a[1+g]*k;e+=a[d+g]*k}return{j:1E9*Math.exp(-.5*(-(f+e)+Math.sqrt((f-e)*(f-e)+4*a[0]))),B:1,J:8}};function te(a,b){var c=null==a?void 0:J(a,fe,6),d,f=null==a?void 0:null==(d=W(a))?void 0:J(d,fe,3);if(!b||0>=b)return{j:0,J:1};if(1===(null==a?void 0:T(a,17)))return{j:b,J:2};var e;if(!(null==a?0:null==(e=W(a))?0:R(e,2)))return{j:.85*b,J:2};d=X(!0,null==c?void 0:S(c,4),null==f?void 0:S(f,4));e=X(!0,null==c?void 0:S(c,1),null==f?void 0:S(f,1));var h=X(!1,null==c?void 0:S(c,2),null==f?void 0:S(f,2)),g=X(!1,null==c?void 0:S(c,3),null==f?void 0:S(f,3)),k,l,n=X(!1,null==c?void 0:null==(k=J(c,ge,5))?void 0:
+S(k,1),null==f?void 0:null==(l=J(f,ge,5))?void 0:S(l,1));l=X(!1,null==c?void 0:S(c,9),null==f?void 0:S(f,9));k=new fe;var t=G(k,1,e,0);t=G(t,2,h,0);t=G(t,3,g,0);t=G(t,4,d,0);t=G(t,9,l,0);var I=he(n);M(t,5,I);t=3;d=d*b*e*(1-1/(1+Math.exp(-h*(Math.log(d*b/1E6)-n-g))));d<l*b&&(d=l*b,t=6);e=1E6*(null==a?NaN:S(a,8));var A;c=null!=(A=null==c?void 0:S(c,8))?A:0;var F;if((null==a?0:null==(F=W(a))?0:R(F,6))&&d<e&&e<b){var O;a=null!=(O=null==f?void 0:S(f,7))?O:0;d=e+a*(0===c?Math.log(b/e):(b-e)/(c-e))*1E6;
+t=7}return{j:d,J:t,ba:k}};function ue(a,b){if(!(0<B(a,2,Number).length&&B(a,2,Number).length===yb(a,3).length&&B(a,2,Number).length===B(a,4,Number).length))return 0;for(var c=0,d=0,f=1,e=p(yb(a,3)),h=e.next();!h.done;h=e.next()){var g=0;switch(h.value){case 1:g=B(a,2,Number)[d]*(b.M?Math.pow(b.M,B(a,4,Number)[d]):0);break;case 2:c=g=B(a,2,Number)[d]*(b.X?Math.pow(b.X,B(a,4,Number)[d]):0);break;case 3:g=B(a,2,Number)[d]}if(0===g)return 0;f*=g;d+=1}0<S(a,7)&&(f=Math.min(f,S(a,7)*c*1E3));return 1E6*f}
+function ve(a,b){var c=0;b&&(0<K(b,nc,7).length?c=ue(K(b,nc,7)[0],a):0<K(b,nc,8).length&&(c=ue(K(b,nc,8)[0],a)));return c};var we={Ga:0,Ca:1,xa:2,za:3,ya:4,Da:5,Ea:6,Ha:7,Ba:8,va:9,Fa:10,Aa:11,wa:12};function xe(a,b,c){if(E(a,2)!==E(b,2))return c;var d=!1;switch(E(a,2)){case 1:a:{var f,e=new Set(null!=(f=yb(a,3))?f:[]);b=p(yb(b,3));for(f=b.next();!f.done;f=b.next())if(e.has(f.value)){d=!0;break a}d=!1}break;case 0:a:{f=new Set(null!=(e=B(a,4,lb,!1))?e:[]);b=p(B(b,4,lb,!1));for(e=b.next();!e.done;e=b.next())if(f.has(e.value)){d=!0;break a}d=!1}break;case 2:b=new ye(b);d=(f=J(a,yc,5))?ze(b,f):!1;break;case 3:a:{f=new Set;e=p(B(a,9,Ub));for(d=e.next();!d.done;d=e.next())f.add(Ta(d.value));if(0===
+f.size)d=!0;else{b=p(B(b,6,Ub));for(e=b.next();!e.done;e=b.next())if(f.has(Ta(e.value))){d=!0;break a}d=!1}}break;case 4:d=Ae(a,b)}return R(a,6)?d?null:c:d?c:null}
+function Ae(a,b){a=J(a,uc,10);if(void 0===a)return!1;var c=K(b,wc,7);if(0===c.length)return!1;b=!0;c=p(c);for(var d=c.next();!d.done;d=c.next())if(d=d.value,T(d,1)===T(a,1)&&T(d,2)===T(a,2)){b&&(b=!1);var f=yb(d,3);if(0===f.length)return!1;d=!0;f=p(f);for(var e=f.next();!e.done;e=f.next()){e=e.value;var h=Math.floor(e/32),g=yb(a,3);if(!(h>=g.length||0!==(g[h]>>>e%32)%2)){d=!1;break}}if(d)return!0}return b}
+function ze(a,b){var c=E(b,1),d=K(b,tc,3),f=K(b,yc,2);switch(c){case 2:c=d.every(function(e){return Be(a,e)})&&f.every(function(e){return ze(a,e)});break;case 1:c=d.some(function(e){return Be(a,e)})||f.some(function(e){return ze(a,e)});break;default:throw Error("unexpected value "+c+"!");}return R(b,4)?!c:c}function ye(a){this.h=new Map;a=p(K(a,tc,5));for(var b=a.next();!b.done;b=a.next()){var c=b.value;b=P(x(c,1),0);c=P(x(c,2),0);var d=this.h.get(b);d||(d=new Set,this.h.set(b,d));d.add(c)}}
+function Be(a,b){var c=P(x(b,2),0);return(a=a.h.get(P(x(b,1),0)))?a.has(c):!1};function Ce(a,b){a=p((null==b?void 0:b.get(a))||[]);for(b=a.next();!b.done;b=a.next())if(b=b.value,b.count+1>b.ra)return!1;return!0};function De(a){a=a.split("!");for(var b="-1",c=0;c<a.length;c++)a[c].match(/^\dm\d+/)?c+=+a[c].substring(2):a[c].match(/^\d{2}m\d+/)?c+=+a[c].substring(3):a[c].match(/^1j\d+/)&&(b=a[c].substring(2));return b}
+function Ee(a,b){if(!a.pa)return 1;var c,d=null==(c=a.da)?void 0:c.some(function(h){var g;return null==(g=b.ga)?void 0:g.includes(h,0)}),f;c=null!=(f=b.interestGroupName)?f:void 0;if(void 0===c)return 10;f=De(c);if("-1"===f)return 11;var e;a=null==(e=a.da)?void 0:e.includes(f,0);return d&&!a?10:1};function Fe(a,b){return null==a.Z?!0:!a.Z.some(function(c){var d;return null==(d=b.ga)?void 0:d.includes(c,0)})};function Ge(a,b){return He(0,(null==a?void 0:K(a,pc,1))||[],(null==b?void 0:K(b,pc,1))||[])}function Ie(a,b){return He(1,(null==a?void 0:K(a,pc,2))||[],(null==b?void 0:K(b,pc,3))||[])}function Je(a,b){return He(1,(null==a?void 0:K(a,pc,3))||[],(null==b?void 0:K(b,pc,3))||[])}
+function He(a,b,c){var d=0,f=new Map;b=p(b);for(var e=b.next();!e.done;e=b.next())d=e.value,f.set(P(x(d,1),""),d),d=S(d,3);b=null;c=p(c);for(e=c.next();!e.done;e=c.next()){var h=e.value;d=S(h,3);if(e=f.get(P(x(h,1),""))){a:{b=a;e=B(e,2,Number);h=B(h,2,Number);if(e.length===h.length){for(var g=0,k=0;k<e.length;k++)g+=e[k]*h[k];e=g}else e=void 0;if(void 0!==e)switch(b){case 0:b=1/(1+Math.exp(-1*e));break a;case 1:b=Math.exp(e);break a}b=void 0}if(void 0!==b)return b;b=d}}var l;return null!=(l=b)?l:
+d};function Ke(a,b,c){"0"===a||c.has(a)||c.set(a,b.filter(function(d){return 0<T(d,3)}).map(function(d){var f=T(d,3);switch(E(d,1)){case 6:d=60*T(d,2);break;case 1:d=3600*T(d,2);break;case 2:d=86400*T(d,2);break;case 3:d=604800*T(d,2);break;case 4:d=2592E3*T(d,2);break;case 5:d=null;break;default:f=d=0}return{fa:d,ra:f,count:0}}))}function Le(a,b,c){if(b=c.get(b))for(b=p(b),c=b.next();!c.done;c=b.next())c=c.value,(null===c.fa||T(a,1)<=c.fa)&&c.count++};function Me(a){V.call(this,a,-1,Ne)}q(Me,V);var Ne=[1];var Oe={ad:{},bid:0,render:"",allowComponentAuction:!0};function Pe(){new Me;return function(a,b,c,d,f){return Qe(a,c,d,f)}}
+function Qe(a,b,c,d){b=b?new $d(gc(b)):void 0;var f,e;if(!b||!(K(b,ee,2).length||(null==(f=W(b))?0:R(f,1))||(null==(e=W(b))?0:R(e,5))))return Oe;f=new Jc(gc(a.userBiddingSignals));e=a.ads.map(function(g){return{renderUrl:g.renderUrl,metadata:new jc(gc(g.metadata))}});c=c[a.name]?new Pc(gc(c[a.name])):void 0;var h=d.prevWins.map(function(g){var k=new kc;k=G(k,1,g[0],0);g=new jc(gc(g[1].metadata));return M(k,2,g)});return Re(a.name,f,e,d,h,c,b)}
+function Re(a,b,c,d,f,e,h){var g=null,k=null,l=null;if(h&&(R(H(h,Zd,12),1)||R(H(h,Zd,12),2))){var n=new le;var t=G(n,2,0,0);var I=G(t,5,a,"");var A=G(I,7,!1,!1);var F=M(A,8,h);g=G(F,9,P(x(h,4),""),"");var O=globalThis.forDebuggingOnly;R(H(h,Zd,12),1)&&(k=new ic(O.reportAdAuctionWin));R(H(h,Zd,12),2)&&(l=new ic(O.reportAdAuctionLoss));if(R(H(h,Zd,12),5)){var Wa=M(g,6,b),ea=new lc;var Xa=G(ea,1,d.topWindowHostname,"");var Y=G(Xa,2,d.seller,"");var Q=G(Y,3,d.topLevelSeller,"");var We=G(Q,4,d.joinCount,
+0);var Xe=G(We,5,d.bidCount,0);var Ye=$b(Xe,6,f);var Ze=G(Ye,7,d.dataVersion,0);M(Wa,11,Ze);e&&M(g,3,e)}}var Ya=g,Rc,D={ea:null!=(Rc=null==h?void 0:W(h))?Rc:void 0,T:new Map,N:new Map,O:new Map,P:new Map,W:new Map,interestGroupName:null!=a?a:void 0,ua:E(b,2),ia:d.joinCount},ka=new Map;if(e){for(var Sc=p(K(e,Nc,1)),Ab=Sc.next();!Ab.done;Ab=Sc.next()){var L=Ab.value,$e=Se(N(L,1),N(L,2),N(L,3));ka.set($e,L);Ke(N(L,2),K(L,Lc,9),D.T);Ke(N(L,1),K(L,Lc,10),D.N);Ke(N(L,6),K(L,Lc,11),D.O);Ke(N(L,7),K(L,Lc,
+12),D.P);Ke(N(L,8),K(L,Lc,13),D.W)}for(var Tc=p(f),Bb=Tc.next();!Bb.done;Bb=Tc.next()){var Z=Bb.value;D.T&&Le(Z,N(H(Z,jc,2),2),D.T);D.N&&Le(Z,N(H(Z,jc,2),1),D.N);D.O&&Le(Z,N(H(Z,jc,2),4),D.O);D.P&&Le(Z,N(H(Z,jc,2),5),D.P);D.W&&Le(Z,N(H(Z,jc,2),6),D.W)}}var Uc=new Map;if(h)for(var Vc=p(K(h,ee,2)),Cb=Vc.next();!Cb.done;Cb=Vc.next()){var Db=Cb.value,af=Se(N(Db,1),N(Db,2),"");Uc.set(af,S(Db,3))}for(var Wc=[],Xc=p(c),Eb=Xc.next();!Eb.done;Eb=Xc.next()){var U=Eb.value,z={renderUrl:U.renderUrl,D:N(U.metadata,
+1),G:N(U.metadata,2),L:N(U.metadata,3),S:N(U.metadata,4),R:N(U.metadata,5),U:N(U.metadata,6),ja:N(U.metadata,7),ka:N(U.metadata,8),la:N(U.metadata,9),ma:N(U.metadata,10),l:0,I:0},pa=Se(z.D,z.G,z.L);z.K=Uc.get(Se(z.D,z.G,""));if(!z.K){var Yc=void 0,Zc=void 0,$c=void 0,ad=void 0;if(!(null==(Yc=h)?0:null==(Zc=W(Yc))?0:R(Zc,1))&&!(null==($c=h)?0:null==(ad=W($c))?0:R(ad,5))){Ya&&Te(Ya,z,5,1);continue}else if(!ka.get(pa)){Ya&&Te(Ya,z,6,1);continue}var bd=void 0,cd=void 0;z.v=null!=(cd=null==(bd=ka.get(pa))?
+void 0:J(bd,rc,4))?cd:void 0}var dd=void 0,ed=void 0;z.F=null!=(ed=null==(dd=ka.get(pa))?void 0:J(dd,Ac,5))?ed:void 0;var fd=void 0,gd=void 0,hd=null!=(gd=null==(fd=ka.get(pa))?void 0:K(fd,Mc,17))?gd:void 0;if(hd)for(var id=p(hd),Fb=id.next();!Fb.done;Fb=id.next()){var Ja=Fb.value;if(z.ja===N(Ja,1)&&z.ka===N(Ja,2)&&z.la===N(Ja,3)&&z.ma===N(Ja,4)){z.F||(z.F=new Ac);var Gb=J(Ja,Ac,5);if(Gb){for(var jd=p(K(Gb,Cc,1)),Hb=jd.next();!Hb.done;Hb=jd.next())ac(z.F,1,Cc,Hb.value);for(var kd=p(K(Gb,Ec,2)),Ib=
+kd.next();!Ib.done;Ib=kd.next())ac(z.F,2,Ec,Ib.value)}}}var ld=void 0,md=void 0;z.Z=null!=(md=null==(ld=ka.get(pa))?void 0:B(ld,14,kb))?md:void 0;var nd=void 0,od=void 0;z.da=null!=(od=null==(nd=ka.get(pa))?void 0:B(nd,15,kb))?od:void 0;var pd=void 0,qd=void 0;z.pa=null!=(qd=null==(pd=ka.get(pa))?void 0:R(pd,16))?qd:!1;Wc.push(z)}var Jb=null==h?void 0:J(h,Ac,5);if(Jb){for(var rd=new Map,sd=new Map,td=p(K(Jb,Cc,1)),Kb=td.next();!Kb.done;Kb=td.next()){var ud=Kb.value;rd.set(E(ud,1),ud)}for(var vd=p(K(Jb,
+Ec,2)),Lb=vd.next();!Lb.done;Lb=vd.next()){var wd=Lb.value;sd.set(E(wd,1),wd)}D.na=rd;D.oa=sd}var xd;D.ga=null!=(xd=B(b,1,kb))?xd:void 0;var ha={ads:Wc,signals:D};var Za=ha.signals;if(1!==Za.ua)var Mb=!0;else{var yd;if(null!=(yd=Za.ea)&&R(yd,8)){var zd;Mb=Za.ia<(null==(zd=Za.ea)?void 0:T(zd,9))?!1:!0}else Mb=!1}var Nb=Mb?1:8;if(1!==Nb&&null!==g)for(var Ad=p(ha.ads),Ob=Ad.next();!Ob.done;Ob=Ad.next())Te(g,Ob.value,Nb,2);var Bd=Oe,Cd=ha;if(1===Nb){for(var aa=g,Dd=null==h?void 0:W(h),Ed=[],Fd=new Map,
+Gd=p(ha.ads),Pb=Gd.next();!Pb.done;Pb=Gd.next()){var C=Pb.value,Hd=void 0;if(void 0!==Dd&&(null==(Hd=Dd)?0:R(Hd,10))&&(C.renderUrl.includes("/td/adfetch/dv3")||qe(C.v)))aa&&Te(aa,C,12,3);else{var Ka=ha.signals;if(!Ce(C.G,Ka.T)||!Ce(C.D,Ka.N)||C.S&&!Ce(C.S,Ka.O)||C.R&&!Ce(C.R,Ka.P)||C.U&&!Ce(C.U,Ka.W))aa&&Te(aa,C,3,3);else{if(C.F){var Id=ha.signals,Jd=Id.na,Kd=Id.oa,Ld=C.F;if(Jd&&Kd&&Ld)a:{for(var bf=Jd,cf=Kd,Md=Ld,Nd=p(K(Md,Cc,1)),Qb=Nd.next();!Qb.done;Qb=Nd.next()){var La=Qb.value,Ma=E(La,1),Rb=
+cf.get(Ma);if(Rb){var Na=null;if(R(La,7)){var Oa=Fd.get(Ma),Od=!0,Pd=P(x(La,8),0);if(void 0===Oa)Oa=new Map,Fd.set(Ma,Oa);else{var Sb=Oa.get(Pd);if(Sb){var Pa=Sb;break a}null===Sb&&(Od=!1)}Od&&(Na=xe(La,Rb,Ma),Oa.set(Pd,Na))}else Na=xe(La,Rb,Ma);if(Na){Pa=Na;break a}}}for(var Qd=p(K(Md,Ec,2)),Tb=Qd.next();!Tb.done;Tb=Qd.next()){var Rd=Tb.value,Sd=E(Rd,1),Td=bf.get(Sd);if(Td){var Ud=xe(Td,Rd,Sd);if(Ud){Pa=Ud;break a}}}Pa=null}else Pa=null;var Vd=Pa;if(Vd){aa&&Te(aa,C,4,3,Vd);continue}}if(Fe(C,ha.signals)){var Wd=
+Ee(C,ha.signals);1!==Wd?aa&&Te(aa,C,Wd,3):Ed.push(C)}else aa&&Te(aa,C,7,3)}}}Cd={ads:Ed,signals:ha.signals};Bd=Ue(Cd,g,h).ha}if(void 0!==h&&null!==g){if(k){var Xd=g,ef=k;G(Xd,2,1,0);ne(ef,Xd)}if(l){var Yd=g,ff=l;G(Yd,2,2,0);ne(ff,Yd)}}return Bd}
+function Te(a,b,c,d,f){a=ac(a,10,Ic);d=G(a,3,d,0);var e;var h=new Gc;h=G(h,1,b.renderUrl,"");h=G(h,2,b.D,"");h=G(h,3,b.G,"");h=G(h,4,b.L,"");h=G(h,12,b.l,0);h=G(h,13,b.I,0);var g=null!=(e=b.qa)?e:!1;e=G(h,16,g,!1);void 0!==b.S&&G(e,5,b.S,"");void 0!==b.R&&G(e,6,b.R,"");void 0!==b.U&&G(e,7,b.U,"");void 0!==b.v&&M(e,8,b.v);void 0!==b.X&&G(e,9,b.X,0);void 0!==b.M&&G(e,10,b.M,0);void 0!==b.K&&G(e,11,b.K,0);void 0!==b.F&&M(e,14,b.F);var k;b=p(null!=(k=b.Z)?k:[]);for(h=b.next();!h.done;h=b.next())k=e,h=
+h.value,ib(k),xb(k,15,2,!1,!1).push(h);M(d,1,e);void 0!==f&&G(a,5,f,0);Object.values(we).includes(c)&&G(a,2,c,0)}
+function Ue(a,b,c){for(var d=[],f=[],e=p(a.ads),h=e.next();!h.done;h=e.next())if(h=h.value,null!=h.K)h.l=h.K,h.qa=!0,d.push(h);else{var g=void 0,k=void 0;if(null==(g=c)?0:null==(k=W(g))?0:R(k,1))qe(h.v)?(g=void 0,h.M=Je(null==(g=c)?void 0:J(g,ce,1),h.v)):(g=void 0,h.X=Ge(null==(g=c)?void 0:J(g,ce,1),h.v),g=void 0,h.M=Ie(null==(g=c)?void 0:J(g,ce,1),h.v)),h.l=ve(h,h.v),h.l||(k=g=void 0,h.l=null!=(k=null==(g=h.v)?void 0:S(g,6))?k:0);else if(k=g=void 0,null==(g=c)?0:null==(k=W(g))?0:R(k,5))k=g=void 0,
+h.l=null!=(k=null==(g=h.v)?void 0:S(g,6))?k:0;k=g=void 0;if(null==(g=c)?0:null==(k=W(g))?0:R(k,7)){var l=k=g=void 0,n=void 0,t=void 0,I=void 0;if(h.D===(null==(g=c)?void 0:null==(k=J(g,ke,16))?void 0:N(k,2))&&h.G===(null==(l=c)?void 0:null==(n=J(l,ke,16))?void 0:N(n,3))&&a.signals.interestGroupName===(null==(t=c)?void 0:null==(I=J(t,ke,16))?void 0:P(x(I,1),""))){if(k=g=void 0,null==(g=c)?0:null==(k=J(g,ke,16))?0:R(k,7))l=k=g=void 0,n=null!=(l=null==(g=c)?void 0:null==(k=J(g,ke,16))?void 0:S(k,5))?
+l:0,h.l=0===n?1:n}else h.l=0}f.push(h)}d={renderUrl:"",D:"",G:"",L:"",l:0,I:0};var A,F;if((null==c?0:null==(A=W(c))?0:R(A,7))&&(null==c?0:null==(F=J(c,ke,16))?0:R(F,7)))c=a.ads.reduce(function(Y,Q){return Y.l<Q.l?Q:Y},d),c.I=c.l;else{A=a.ads.reduce(function(Y,Q){return!qe(Q.v)&&Y.l<Q.l?Q:Y},d);d=a.ads.reduce(function(Y,Q){return qe(Q.v)&&Y.l<Q.l?Q:Y},d);F=te(c,null==A?void 0:A.l);var O,Wa;F.j=oe(F.j,null==c?void 0:null==(O=W(c))?void 0:null==(Wa=J(O,fe,3))?void 0:S(Wa,6));O=re(c,null==d?void 0:d.l);
+var ea,Xa;O.j=oe(O.j,null==c?void 0:null==(ea=W(c))?void 0:null==(Xa=J(ea,fe,4))?void 0:S(Xa,6));F.j>O.j?(c=A,c.I=F.j):(c=d,c.I=O.j)}if(b)for(a=p(a.ads),h=a.next();!h.done;h=a.next())ea=h.value,Te(b,ea,Se(ea.D,ea.G,ea.L)===Se(c.D,c.G,c.L)?1:9,4);return{ha:{ad:{},bid:c.I/1E6,render:c.renderUrl,allowComponentAuction:!0},debugInfo:void 0}}function Se(a,b,c){return a.concat("+",b,"+",c)};function Ve(a,b,c,d,f){a={renderUrl:a.render_uri,metadata:a.metadata.metadata};f={owner:f.owner,name:f.name,biddingLogicUrl:"",userBiddingSignals:f.user_bidding_signals.signals,ads:[a]};a={topWindowHostname:"",seller:"",joinCount:0,bidCount:0,prevWins:[[0,a]]};b=Pe()(f,b,c.signals,d,a);c="";"string"===typeof b.render?c=b.render:(d=b.render,0<d.length&&(c=d[0]));return{status:0,ad:{render_uri:c,metadata:b.ad},bid:b.bid}};var df=globalThis;df.generateBid=function(a,b,c,d,f,e){return Ve(a,b,c,d,e)};df.generateBidIterative=function(a,b,c,d,f,e){f=(new Date).getTime();var h=[];a=p(a);for(var g=a.next();!g.done;g=a.next())g=Ve(g.value,b,c,d,e),h.push(g);return{responses:h,status:0,duration:(new Date).getTime()-f}};
diff --git a/apct-tests/perftests/rubidium/assets/rubidium_scoring_logic_compiled.js b/apct-tests/perftests/rubidium/assets/rubidium_scoring_logic_compiled.js
new file mode 100644
index 0000000..406a45d
--- /dev/null
+++ b/apct-tests/perftests/rubidium/assets/rubidium_scoring_logic_compiled.js
@@ -0,0 +1,59 @@
+/*
+
+ Copyright The Closure Library Authors.
+ SPDX-License-Identifier: Apache-2.0
+*/
+'use strict';function aa(a){var b=0;return function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}}}var ba="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){if(a==Array.prototype||a==Object.prototype)return a;a[b]=c.value;return a};
+function ca(a){a=["object"==typeof globalThis&&globalThis,a,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var b=0;b<a.length;++b){var c=a[b];if(c&&c.Math==Math)return c}throw Error("Cannot find global object");}var ea=ca(this);function n(a,b){if(b)a:{var c=ea;a=a.split(".");for(var d=0;d<a.length-1;d++){var f=a[d];if(!(f in c))break a;c=c[f]}a=a[a.length-1];d=c[a];b=b(d);b!=d&&null!=b&&ba(c,a,{configurable:!0,writable:!0,value:b})}}
+n("Symbol",function(a){function b(e){if(this instanceof b)throw new TypeError("Symbol is not a constructor");return new c(d+(e||"")+"_"+f++,e)}function c(e,g){this.h=e;ba(this,"description",{configurable:!0,writable:!0,value:g})}if(a)return a;c.prototype.toString=function(){return this.h};var d="jscomp_symbol_"+(1E9*Math.random()>>>0)+"_",f=0;return b});
+n("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var b="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),c=0;c<b.length;c++){var d=ea[b[c]];"function"===typeof d&&"function"!=typeof d.prototype[a]&&ba(d.prototype,a,{configurable:!0,writable:!0,value:function(){return fa(aa(this))}})}return a});function fa(a){a={next:a};a[Symbol.iterator]=function(){return this};return a}
+function p(a){var b="undefined"!=typeof Symbol&&Symbol.iterator&&a[Symbol.iterator];return b?b.call(a):{next:aa(a)}}function ha(a){if(!(a instanceof Array)){a=p(a);for(var b,c=[];!(b=a.next()).done;)c.push(b.value);a=c}return a}var ia="function"==typeof Object.create?Object.create:function(a){function b(){}b.prototype=a;return new b},ja;
+if("function"==typeof Object.setPrototypeOf)ja=Object.setPrototypeOf;else{var ka;a:{var la={a:!0},ma={};try{ma.__proto__=la;ka=ma.a;break a}catch(a){}ka=!1}ja=ka?function(a,b){a.__proto__=b;if(a.__proto__!==b)throw new TypeError(a+" is not extensible");return a}:null}var na=ja;
+function r(a,b){a.prototype=ia(b.prototype);a.prototype.constructor=a;if(na)na(a,b);else for(var c in b)if("prototype"!=c)if(Object.defineProperties){var d=Object.getOwnPropertyDescriptor(b,c);d&&Object.defineProperty(a,c,d)}else a[c]=b[c];a.la=b.prototype}function oa(){for(var a=Number(this),b=[],c=a;c<arguments.length;c++)b[c-a]=arguments[c];return b}function t(a,b){return Object.prototype.hasOwnProperty.call(a,b)}
+n("WeakMap",function(a){function b(k){this.h=(h+=Math.random()+1).toString();if(k){k=p(k);for(var l;!(l=k.next()).done;)l=l.value,this.set(l[0],l[1])}}function c(){}function d(k){var l=typeof k;return"object"===l&&null!==k||"function"===l}function f(k){if(!t(k,g)){var l=new c;ba(k,g,{value:l})}}function e(k){var l=Object[k];l&&(Object[k]=function(m){if(m instanceof c)return m;Object.isExtensible(m)&&f(m);return l(m)})}if(function(){if(!a||!Object.seal)return!1;try{var k=Object.seal({}),l=Object.seal({}),
+m=new a([[k,2],[l,3]]);if(2!=m.get(k)||3!=m.get(l))return!1;m.delete(k);m.set(l,4);return!m.has(k)&&4==m.get(l)}catch(q){return!1}}())return a;var g="$jscomp_hidden_"+Math.random();e("freeze");e("preventExtensions");e("seal");var h=0;b.prototype.set=function(k,l){if(!d(k))throw Error("Invalid WeakMap key");f(k);if(!t(k,g))throw Error("WeakMap key fail: "+k);k[g][this.h]=l;return this};b.prototype.get=function(k){return d(k)&&t(k,g)?k[g][this.h]:void 0};b.prototype.has=function(k){return d(k)&&t(k,
+g)&&t(k[g],this.h)};b.prototype.delete=function(k){return d(k)&&t(k,g)&&t(k[g],this.h)?delete k[g][this.h]:!1};return b});
+n("Map",function(a){function b(){var h={};return h.v=h.next=h.head=h}function c(h,k){var l=h.h;return fa(function(){if(l){for(;l.head!=h.h;)l=l.v;for(;l.next!=l.head;)return l=l.next,{done:!1,value:k(l)};l=null}return{done:!0,value:void 0}})}function d(h,k){var l=k&&typeof k;"object"==l||"function"==l?e.has(k)?l=e.get(k):(l=""+ ++g,e.set(k,l)):l="p_"+k;var m=h.i[l];if(m&&t(h.i,l))for(h=0;h<m.length;h++){var q=m[h];if(k!==k&&q.key!==q.key||k===q.key)return{id:l,list:m,index:h,l:q}}return{id:l,list:m,
+index:-1,l:void 0}}function f(h){this.i={};this.h=b();this.size=0;if(h){h=p(h);for(var k;!(k=h.next()).done;)k=k.value,this.set(k[0],k[1])}}if(function(){if(!a||"function"!=typeof a||!a.prototype.entries||"function"!=typeof Object.seal)return!1;try{var h=Object.seal({x:4}),k=new a(p([[h,"s"]]));if("s"!=k.get(h)||1!=k.size||k.get({x:4})||k.set({x:4},"t")!=k||2!=k.size)return!1;var l=k.entries(),m=l.next();if(m.done||m.value[0]!=h||"s"!=m.value[1])return!1;m=l.next();return m.done||4!=m.value[0].x||
+"t"!=m.value[1]||!l.next().done?!1:!0}catch(q){return!1}}())return a;var e=new WeakMap;f.prototype.set=function(h,k){h=0===h?0:h;var l=d(this,h);l.list||(l.list=this.i[l.id]=[]);l.l?l.l.value=k:(l.l={next:this.h,v:this.h.v,head:this.h,key:h,value:k},l.list.push(l.l),this.h.v.next=l.l,this.h.v=l.l,this.size++);return this};f.prototype.delete=function(h){h=d(this,h);return h.l&&h.list?(h.list.splice(h.index,1),h.list.length||delete this.i[h.id],h.l.v.next=h.l.next,h.l.next.v=h.l.v,h.l.head=null,this.size--,
+!0):!1};f.prototype.clear=function(){this.i={};this.h=this.h.v=b();this.size=0};f.prototype.has=function(h){return!!d(this,h).l};f.prototype.get=function(h){return(h=d(this,h).l)&&h.value};f.prototype.entries=function(){return c(this,function(h){return[h.key,h.value]})};f.prototype.keys=function(){return c(this,function(h){return h.key})};f.prototype.values=function(){return c(this,function(h){return h.value})};f.prototype.forEach=function(h,k){for(var l=this.entries(),m;!(m=l.next()).done;)m=m.value,
+h.call(k,m[1],m[0],this)};f.prototype[Symbol.iterator]=f.prototype.entries;var g=0;return f});n("Number.isNaN",function(a){return a?a:function(b){return"number"===typeof b&&isNaN(b)}});function pa(a,b){a instanceof String&&(a+="");var c=0,d=!1,f={next:function(){if(!d&&c<a.length){var e=c++;return{value:b(e,a[e]),done:!1}}d=!0;return{done:!0,value:void 0}}};f[Symbol.iterator]=function(){return f};return f}n("Array.prototype.values",function(a){return a?a:function(){return pa(this,function(b,c){return c})}});
+n("Set",function(a){function b(c){this.h=new Map;if(c){c=p(c);for(var d;!(d=c.next()).done;)this.add(d.value)}this.size=this.h.size}if(function(){if(!a||"function"!=typeof a||!a.prototype.entries||"function"!=typeof Object.seal)return!1;try{var c=Object.seal({x:4}),d=new a(p([c]));if(!d.has(c)||1!=d.size||d.add(c)!=d||1!=d.size||d.add({x:4})!=d||2!=d.size)return!1;var f=d.entries(),e=f.next();if(e.done||e.value[0]!=c||e.value[1]!=c)return!1;e=f.next();return e.done||e.value[0]==c||4!=e.value[0].x||
+e.value[1]!=e.value[0]?!1:f.next().done}catch(g){return!1}}())return a;b.prototype.add=function(c){c=0===c?0:c;this.h.set(c,c);this.size=this.h.size;return this};b.prototype.delete=function(c){c=this.h.delete(c);this.size=this.h.size;return c};b.prototype.clear=function(){this.h.clear();this.size=0};b.prototype.has=function(c){return this.h.has(c)};b.prototype.entries=function(){return this.h.entries()};b.prototype.values=function(){return this.h.values()};b.prototype.keys=b.prototype.values;b.prototype[Symbol.iterator]=
+b.prototype.values;b.prototype.forEach=function(c,d){var f=this;this.h.forEach(function(e){return c.call(d,e,e,f)})};return b});n("globalThis",function(a){return a||ea});n("Object.values",function(a){return a?a:function(b){var c=[],d;for(d in b)t(b,d)&&c.push(b[d]);return c}});n("Object.is",function(a){return a?a:function(b,c){return b===c?0!==b||1/b===1/c:b!==b&&c!==c}});
+n("Array.prototype.includes",function(a){return a?a:function(b,c){var d=this;d instanceof String&&(d=String(d));var f=d.length;c=c||0;for(0>c&&(c=Math.max(c+f,0));c<f;c++){var e=d[c];if(e===b||Object.is(e,b))return!0}return!1}});
+n("String.prototype.includes",function(a){return a?a:function(b,c){if(null==this)throw new TypeError("The 'this' value for String.prototype.includes must not be null or undefined");if(b instanceof RegExp)throw new TypeError("First argument to String.prototype.includes must not be a regular expression");return-1!==this.indexOf(b,c||0)}});function qa(a){var b=typeof a;return"object"==b&&null!=a||"function"==b};var ra={};var sa=Array.prototype.map?function(a,b){return Array.prototype.map.call(a,b,void 0)}:function(a,b){for(var c=a.length,d=Array(c),f="string"===typeof a?a.split(""):a,e=0;e<c;e++)e in f&&(d[e]=b.call(void 0,f[e],e,a));return d};var ta={},u=null;function ua(a,b){void 0===b&&(b=0);va();b=ta[b];for(var c=Array(Math.floor(a.length/3)),d=b[64]||"",f=0,e=0;f<a.length-2;f+=3){var g=a[f],h=a[f+1],k=a[f+2],l=b[g>>2];g=b[(g&3)<<4|h>>4];h=b[(h&15)<<2|k>>6];k=b[k&63];c[e++]=l+g+h+k}l=0;k=d;switch(a.length-f){case 2:l=a[f+1],k=b[(l&15)<<2]||d;case 1:a=a[f],c[e]=b[a>>2]+b[(a&3)<<4|l>>4]+k+d}return c.join("")}
+function wa(a){var b=a.length,c=3*b/4;c%3?c=Math.floor(c):-1!="=.".indexOf(a[b-1])&&(c=-1!="=.".indexOf(a[b-2])?c-2:c-1);var d=new Uint8Array(c),f=0;xa(a,function(e){d[f++]=e});return f!==c?d.subarray(0,f):d}
+function xa(a,b){function c(k){for(;d<a.length;){var l=a.charAt(d++),m=u[l];if(null!=m)return m;if(!/^[\s\xa0]*$/.test(l))throw Error("Unknown base64 encoding at char: "+l);}return k}va();for(var d=0;;){var f=c(-1),e=c(0),g=c(64),h=c(64);if(64===h&&-1===f)break;b(f<<2|e>>4);64!=g&&(b(e<<4&240|g>>2),64!=h&&b(g<<6&192|h))}}
+function va(){if(!u){u={};for(var a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),b=["+/=","+/","-_=","-_.","-_"],c=0;5>c;c++){var d=a.concat(b[c].split(""));ta[c]=d;for(var f=0;f<d.length;f++){var e=d[f];void 0===u[e]&&(u[e]=f)}}}};var ya="undefined"!==typeof Uint8Array;function za(a){return null==a||v(a)?a:"string"===typeof a?wa(a):null}function v(a){return ya&&null!=a&&a instanceof Uint8Array}var w={};var Aa;function Ba(a){if(a!==w)throw Error("illegal external caller");}function x(a,b){Ba(b);this.H=a;if(null!=a&&0===a.length)throw Error("ByteString should be constructed with non-empty values");}function Ca(){return Aa||(Aa=new x(null,w))}function Da(a){var b=a.H;return null==b?"":"string"===typeof b?b:a.H=ua(b)};var y="function"===typeof Symbol&&"symbol"===typeof Symbol()?Symbol():void 0;function z(a,b){if(y)return a[y]|=b;if(void 0!==a.u)return a.u|=b;Object.defineProperties(a,{u:{value:b,configurable:!0,writable:!0,enumerable:!1}});return b}function Ea(a,b){y?a[y]&&(a[y]&=~b):void 0!==a.u&&(a.u&=~b)}function A(a){var b;y?b=a[y]:b=a.u;return null==b?0:b}function B(a,b){y?a[y]=b:void 0!==a.u?a.u=b:Object.defineProperties(a,{u:{value:b,configurable:!0,writable:!0,enumerable:!1}})}
+function C(a){z(a,1);return a}function E(a){return!!(A(a)&2)}function Fa(a){z(a,16);return a}function Ga(a,b){B(b,(a|0)&-51)}function Ha(a,b){B(b,(a|18)&-41)};var F={};function H(a){return null!==a&&"object"===typeof a&&!Array.isArray(a)&&a.constructor===Object}var Ia;function Ja(a){a instanceof x&&(Ba(w),a=a.H||"");return a}var I,Ka=[];B(Ka,23);I=Object.freeze(Ka);function J(a){if(E(a.j))throw Error("Cannot mutate an immutable Message");}function La(a){var b=a.length;(b=b?a[b-1]:void 0)&&H(b)?b.g=1:(b={},a.push((b.g=1,b)))};function Ma(a){return a}function Na(a){return a};function Oa(a,b){a=a||{};b=b||{};var c={},d;for(d in a)c[d]=0;for(var f in b)c[f]=0;for(var e in c)if(!Pa(a[e],b[e]))return!1;return!0}function Qa(a){return a&&"object"===typeof a?a.j||a:a}
+function Pa(a,b){a=Ja(a);b=Ja(b);a=Qa(a);b=Qa(b);if(a==b)return!0;if(ya){var c=v(a),d=v(b);if(c||d){if(!c)if("string"===typeof a)a=za(a);else return!1;if(d)d=b;else if("string"===typeof b)d=za(b);else return!1;if(a.length!==d.length)return!1;for(b=0;b<a.length;b++)if(a[b]!==d[b])return!1;return!0}}if(null==a&&Array.isArray(b)&&A(b)&1&&!b.length||null==b&&Array.isArray(a)&&A(a)&1&&!a.length)return!0;if(!qa(a)||!qa(b))return"number"===typeof a&&isNaN(a)||"number"===typeof b&&isNaN(b)?String(a)==String(b):
+!1;if(a.constructor!=b.constructor)return!1;if(a.constructor===Array){d=a;c=a=void 0;for(var f=Math.max(d.length,b.length),e=0;e<f;e++){var g=d[e],h=b[e];g&&g.constructor==Object&&(a=g,g=void 0);h&&h.constructor==Object&&(c=h,h=void 0);if(!Pa(g,h))return!1}return a||c?(a=a||{},c=c||{},Oa(a,c)):!0}if(a.constructor===Object)return Oa(a,b);throw Error("Invalid type in JSPB array");};var K;function Ra(a){switch(typeof a){case "number":return isFinite(a)?a:String(a);case "object":if(a)if(Array.isArray(a)){if(0!==(A(a)&128))return a=Array.prototype.slice.call(a),La(a),a}else{if(v(a))return ua(a);if(a instanceof x)return Da(a)}}return a};function Sa(a,b,c,d){if(null!=a){if(Array.isArray(a))a=Ta(a,b,c,void 0!==d);else if(H(a)){var f={},e;for(e in a)f[e]=Sa(a[e],b,c,d);a=f}else a=b(a,d);return a}}function Ta(a,b,c,d){var f=A(a);d=d?!!(f&16):void 0;a=Array.prototype.slice.call(a);for(var e=0;e<a.length;e++)a[e]=Sa(a[e],b,c,d);c(f,a);return a}function Ua(a){return a.F===F?a.toJSON():Ra(a)}function Va(a){if(!a)return a;if("object"===typeof a){if(v(a))return new Uint8Array(a);if(a.F===F)return Wa(a)}return a}
+function Xa(a,b){a&128&&La(b)};function Ya(a){return a.h||(a.h=a.j[a.i+a.A]={})}function L(a,b,c){return-1===b?null:b>=a.i?a.h?a.h[b]:void 0:c&&a.h&&(c=a.h[b],null!=c)?c:a.j[b+a.A]}function M(a,b,c,d){a.o&&(a.o=void 0);if(b>=a.i||d)return Ya(a)[b]=c,a;a.j[b+a.A]=c;(c=a.h)&&b in c&&delete c[b];return a}
+function Za(a,b,c,d,f){var e=L(a,b,d);Array.isArray(e)||(e=I);var g=A(e);g&1||C(e);if(f)g&2||z(e,2),c&1||Object.freeze(e);else{f=!(c&2);var h=g&2;c&1||!h?f&&g&16&&!h&&Ea(e,16):(e=C(Array.prototype.slice.call(e)),M(a,b,e,d))}return e}function O(a,b){return Za(a,b,0,!1,E(a.j))}
+function P(a,b,c,d){var f=E(a.j),e=Za(a,b,1,d,f),g=A(e);if(!(g&4)){Object.isFrozen(e)&&(e=C(e.slice()),M(a,b,e,d));for(var h=0,k=0;h<e.length;h++){var l=c(e[h]);null!=l&&(e[k++]=l)}k<h&&(e.length=k);z(e,5);f&&(z(e,2),Object.freeze(e))}!f&&(g&2||Object.isFrozen(e))&&(e=Array.prototype.slice.call(e),z(e,5),c=e,null==c?c=I:(f=A(c),1!==(f&1)&&(Object.isFrozen(c)&&(c=Array.prototype.slice.call(c)),B(c,f|1))),J(a),M(a,b,c,d));return e}
+function $a(a){return null==a?a:"string"===typeof a?a?new x(a,w):Ca():a.constructor===x?a:v(a)?a.length?new x(new Uint8Array(a),w):Ca():void 0}function Q(a,b){a=L(a,b);return null==a?0:a}function R(a,b,c,d){J(a);c!==d?M(a,b,c):M(a,b,void 0,!1);return a}var ab=Symbol(void 0);function bb(a,b,c,d){var f=L(a,c,d);var e=!1;var g=null==f||"object"!==typeof f||(e=Array.isArray(f))||f.F!==F?e?new b(f):void 0:f;g!==f&&null!=g&&(M(a,c,g,d),z(g.j,A(a.j)&-33));return g}
+function S(a,b,c){if(a=bb(a,b,c,!1))b=a;else if(a=b[ab])b=a;else{a=new b;if(ra!==ra)throw Error("requires a valid immutable API token");E(a.j)||((c=a.o)&&Pa(c.j,a.j)?a=c:(c=cb(a,!0),z(c.j,2),a=a.o=c));b=b[ab]=a}return b}function T(a,b,c){var d=void 0===d?!1:d;b=bb(a,b,c,d);if(null==b)return b;if(!E(a.j)){var f=db(b);f!==b&&(b=f,M(a,c,b,d))}return b}
+function eb(a,b,c,d,f,e){a.m||(a.m={});var g=a.m[c],h=Za(a,c,3,d,e);if(g)e||(Object.isFrozen(g)?f||(g=Array.prototype.slice.call(g),a.m[c]=g):f&&Object.freeze(g));else{g=[];var k=!!(A(a.j)&16),l=E(h);!e&&l&&(h=C(Array.prototype.slice.call(h)),M(a,c,h,d));d=l;for(var m=0;m<h.length;m++){var q=h[m];var G=b;var D=k,N=!1;N=void 0===N?!1:N;D=void 0===D?!1:D;G=Array.isArray(q)?new G(D?Fa(q):q):N?new G:void 0;void 0!==G&&(d=d||E(q),g.push(G),l&&z(G.j,2))}a.m[c]=g;a=h;Object.isFrozen(a)||(b=A(a)|33,B(a,d?
+b&-9:b|8));(e||f&&l)&&z(g,2);(e||f)&&Object.freeze(g)}return g}function U(a,b,c,d){var f=E(a.j);b=eb(a,b,c,d,f,f);a=Za(a,c,3,d,f);if(!(f||A(a)&8)){for(f=0;f<b.length;f++)c=b[f],d=db(c),c!==d&&(b[f]=d,a[f]=b[f].j);z(a,8)}return b}function fb(a,b,c){J(a);null==c&&(c=void 0);return M(a,b,c)}function gb(a,b,c,d){J(a);if(null!=c){var f=C([]);for(var e=!1,g=0;g<c.length;g++)f[g]=c[g].j,e=e||E(f[g]);a.m||(a.m={});a.m[b]=c;c=f;e?Ea(c,8):z(c,8)}else a.m&&(a.m[b]=void 0),f=I;M(a,b,f,d)}
+function V(a,b){return null==a?b:a}function W(a,b){a=L(a,b);return V(null==a?a:!!a,!1)};function hb(a){var b=A(a);if(b&2)return a;a=sa(a,ib);Ha(b,a);Object.freeze(a);return a}function jb(a,b,c){c=void 0===c?Ha:c;if(null!=a){if(ya&&a instanceof Uint8Array)return a.length?new x(new Uint8Array(a),w):Ca();if(Array.isArray(a)){var d=A(a);if(d&2)return a;if(b&&!(d&32)&&(d&16||0===d))return B(a,d|2),a;a=Ta(a,jb,c,!0);b=A(a);b&4&&b&2&&Object.freeze(a);return a}return a.F===F?ib(a):a}}function ib(a){if(E(a.j))return a;a=cb(a,!0);z(a.j,2);return a}
+function cb(a,b){var c=a.j,d=Fa([]),f=a.constructor.h;f&&d.push(f);0!==(A(c)&128)&&La(d);b=b||E(a.j)?Ha:Ga;f=a.constructor;K=d;d=new f(d);K=void 0;a.C&&(d.C=a.C.slice());f=!!(A(c)&16);for(var e=0;e<c.length;e++){var g=c[e];if(e===c.length-1&&H(g))for(var h in g){var k=+h;if(Number.isNaN(k))Ya(d)[k]=g[k];else{var l=g[h],m=a.m&&a.m[k];m?gb(d,k,hb(m),!0):(l=jb(l,f,b),J(d),M(d,k,l,!0))}}else k=e-a.A,(l=a.m&&a.m[k])?gb(d,k,hb(l),!1):(g=jb(g,f,b),J(d),M(d,k,g,!1))}return d}
+function db(a){if(!E(a.j))return a;var b=cb(a,!1);b.o=a;return b};function X(a,b,c){null==a&&(a=K);K=void 0;var d=this.constructor.i||0,f=0<d,e=this.constructor.h,g=!1;if(null==a){a=e?[e]:[];var h=!0;B(a,48)}else{if(!Array.isArray(a))throw Error();if(e&&e!==a[0])throw Error();var k=z(a,0),l=k;if(h=0!==(16&l))(g=0!==(32&l))||(l|=32);if(f)if(128&l)d=0;else{if(0<a.length){var m=a[a.length-1];if(H(m)&&"g"in m){d=0;l|=128;delete m.g;var q=!0,G;for(G in m){q=!1;break}q&&a.pop()}}}else if(128&l)throw Error();k!==l&&B(a,l)}this.A=(e?0:-1)-d;this.m=void 0;this.j=a;a:{e=
+this.j.length;d=e-1;if(e&&(e=this.j[d],H(e))){this.h=e;this.i=d-this.A;break a}void 0!==b&&-1<b?(this.i=Math.max(b,d+1-this.A),this.h=void 0):this.i=Number.MAX_VALUE}if(!f&&this.h&&"g"in this.h)throw Error('Unexpected "g" flag in sparse object of message that is not a group type.');if(c){b=h&&!g&&!0;f=this.i;var D;for(h=0;h<c.length;h++)g=c[h],g<f?(g+=this.A,(d=a[g])?kb(d,b):a[g]=I):(D||(D=Ya(this)),(d=D[g])?kb(d,b):D[g]=I)}}X.prototype.toJSON=function(){var a=this.j;return Ia?a:Ta(a,Ua,Xa)};
+function Wa(a){var b=Ta(a.j,Va,Ga);Fa(b);K=b;b=new a.constructor(b);K=void 0;lb(b,a);return b}function kb(a,b){if(Array.isArray(a)){var c=A(a),d=1;!b||c&2||(d|=16);(c&d)!==d&&B(a,c|d)}}X.prototype.F=F;X.prototype.toString=function(){return this.j.toString()};function mb(a,b){return Ra(b)}
+function lb(a,b){b.C&&(a.C=b.C.slice());var c=b.m;if(c){var d=b.h,f;for(f in c)if(b=c[f]){var e=!(!d||!d[f]),g=+f;if(Array.isArray(b)){if(b.length)for(e=U(a,b[0].constructor,g,e),g=0;g<Math.min(e.length,b.length);g++)lb(e[g],b[g])}else throw a=typeof b,Error("unexpected object: type: "+("object"!=a?a:b?Array.isArray(b)?"array":a:"null")+": "+b);}}};var nb=void 0;function ob(a){var b=nb;nb=void 0;if(!Array.isArray(a))throw b=b?b()+"\n":"",Error(b+String(a));return a};function pb(a){return JSON.stringify([a.map(function(b){var c={};return[(c[b.L]=b.message.toJSON(),c)]})])};function qb(a){this.h=a}qb.prototype.K=function(){var a=encodeURIComponent;var b=pb(oa.apply(0,arguments));for(var c=[],d=0,f=0;f<b.length;f++){var e=b.charCodeAt(f);255<e&&(c[d++]=e&255,e>>=8);c[d++]=e}b=ua(c,3);a=a(b);this.h("https://pagead2.googlesyndication.com/pagead/ping?e=3&d="+a)};function rb(a){X.call(this,a)}r(rb,X);function sb(a){X.call(this,a,-1,tb)}r(sb,X);var tb=[3];function ub(a){X.call(this,a,-1,vb)}r(ub,X);var vb=[3];function wb(a){X.call(this,a,-1,xb)}r(wb,X);var xb=[2,3,5];function yb(a){X.call(this,a,-1,zb)}r(yb,X);function Ab(a){X.call(this,a,-1,Bb)}r(Ab,X);function Cb(a){X.call(this,a,-1,Db)}r(Cb,X);var zb=[1,2],Bb=[3,4,9],Db=[3,4,5,6,7];function Y(a){X.call(this,a)}r(Y,X);function Eb(a){X.call(this,a,-1,Fb)}r(Eb,X);var Fb=[1,2,3];function Gb(a){X.call(this,a,-1,Hb)}r(Gb,X);var Hb=[1];function Ib(a){X.call(this,a,-1,Jb)}r(Ib,X);var Jb=[1];function Kb(a){X.call(this,a,-1,Lb)}r(Kb,X);var Lb=[1];function Mb(a){X.call(this,a,-1,Nb)}r(Mb,X);var Nb=[1];function Z(a){X.call(this,a)}r(Z,X);function Ob(a){X.call(this,a,-1,Pb)}r(Ob,X);function Qb(a){X.call(this,a)}r(Qb,X);var Pb=[1];function Rb(a){X.call(this,a)}r(Rb,X);function Sb(a){X.call(this,a)}r(Sb,X);function Tb(a){X.call(this,a)}r(Tb,X);function Ub(a){X.call(this,a)}r(Ub,X);function Vb(a){X.call(this,a,-1,Wb)}r(Vb,X);var Wb=[1];function Xb(a){X.call(this,a,-1,Yb)}r(Xb,X);var Yb=[1,2];function Zb(a){X.call(this,a,-1,$b)}r(Zb,X);var $b=[1];function ac(a){X.call(this,a,-1,bc)}r(ac,X);var bc=[2,3,6,10];function cc(a){X.call(this,a)}r(cc,X);function dc(a,b){return R(a,1,b,"")}function ec(a,b){return fb(a,2,b)};var fc={ja:0,V:1,X:2,ca:3,Z:4,Y:5,aa:6,ba:7,da:8,ea:12,U:9,N:10,W:11};var gc={ka:0,ha:1,S:2,T:3,fa:4,M:5,ia:6,ga:7,P:8,O:9,R:10};function hc(a){X.call(this,a,-1,ic)}r(hc,X);function jc(a,b){fb(a,8,b)}function kc(a){X.call(this,a,-1,lc)}r(kc,X);function mc(a,b){return R(a,2,b,"")}function nc(a,b){return R(a,3,b,"")}var ic=[9],lc=[6];function oc(a){a.K.apply(a,ha(oa.apply(1,arguments).map(function(b){return{L:10,message:b}})))};function pc(a){X.call(this,a,-1,qc)}r(pc,X);var qc=[1];function rc(a,b,c){if(Q(a,2)!==Q(b,2))return c;var d=!1;switch(Q(a,2)){case 1:a:{var f,e=new Set(null!=(f=O(a,3))?f:[]);b=p(O(b,3));for(f=b.next();!f.done;f=b.next())if(e.has(f.value)){d=!0;break a}d=!1}break;case 0:a:{f=new Set(null!=(e=P(a,4,Na,!1))?e:[]);b=p(P(b,4,Na,!1));for(e=b.next();!e.done;e=b.next())if(f.has(e.value)){d=!0;break a}d=!1}break;case 2:b=new sc(b);d=(f=T(a,wb,5))?tc(b,f):!1;break;case 3:a:{f=new Set;e=p(P(a,9,$a));for(d=e.next();!d.done;d=e.next())f.add(Da(d.value));if(0===f.size)d=
+!0;else{b=p(P(b,6,$a));for(e=b.next();!e.done;e=b.next())if(f.has(Da(e.value))){d=!0;break a}d=!1}}break;case 4:d=uc(a,b)}return W(a,6)?d?null:c:d?c:null}
+function uc(a,b){a=T(a,sb,10);if(void 0===a)return!1;var c=U(b,ub,7);if(0===c.length)return!1;b=!0;c=p(c);for(var d=c.next();!d.done;d=c.next())if(d=d.value,V(L(d,1),0)===V(L(a,1),0)&&V(L(d,2),0)===V(L(a,2),0)){b&&(b=!1);var f=O(d,3);if(0===f.length)return!1;d=!0;f=p(f);for(var e=f.next();!e.done;e=f.next()){e=e.value;var g=Math.floor(e/32),h=O(a,3);if(!(g>=h.length||0!==(h[g]>>>e%32)%2)){d=!1;break}}if(d)return!0}return b}
+function tc(a,b){var c=Q(b,1),d=U(b,rb,3),f=U(b,wb,2);switch(c){case 2:c=d.every(function(e){return vc(a,e)})&&f.every(function(e){return tc(a,e)});break;case 1:c=d.some(function(e){return vc(a,e)})||f.some(function(e){return tc(a,e)});break;default:throw Error("unexpected value "+c+"!");}return W(b,4)?!c:c}function sc(a){this.h=new Map;a=p(U(a,rb,5));for(var b=a.next();!b.done;b=a.next()){var c=b.value;b=V(L(c,1),0);c=V(L(c,2),0);var d=this.h.get(b);d||(d=new Set,this.h.set(b,d));d.add(c)}}
+function vc(a,b){var c=V(L(b,2),0);return(a=a.h.get(V(L(b,1),0)))?a.has(c):!1};function wc(a,b){switch(a){case 2:return 187;case 3:return 138;case 4:return xc(b);case 5:return 80;case 6:return 7;case 7:return 2;case 8:return 7;default:return 4}}function xc(a){switch(a){case 2:return 12;case 3:return 14;case 4:return 15;case 5:return 219;case 6:return 82;case 7:return 80;case 8:return 71;case 9:return 16;default:return 4}};function yc(a){return"https://googleads.g.doubleclick.net"===a||"https://td.doubleclick.net"===a};function zc(a,b,c,d,f){this.J=a;this.postRevshareBidCpmUsdMicros=b;this.sellerSignals=c;this.h=d;this.D=f;this.o=new Map;if(W(S(c,Y,12),1)||W(S(c,Y,12),2))a=new hc,this.i=R(a,7,V(L(this.sellerSignals,2),""),"")}zc.prototype.reject=function(a,b){b=void 0===b?0:b;var c,d,f,e,g={ru:null!=(f=null==(c=this.h)?void 0:c.renderUrl)?f:"",igo:null!=(e=null==(d=this.h)?void 0:d.interestGroupOwner)?e:"",s:a,r:b};Ac(this,a,b);return{desirability:0,postRevshareBidCpmUsdMicros:0,debugInfo:this.D?g:void 0,debugEventMessage:this.debugEventMessage}};
+zc.prototype.accept=function(){var a,b,c,d,f={ru:null!=(c=null==(a=this.h)?void 0:a.renderUrl)?c:"",igo:null!=(d=null==(b=this.h)?void 0:b.interestGroupOwner)?d:"",s:1,r:1};Ac(this,1,1);return{desirability:this.postRevshareBidCpmUsdMicros,postRevshareBidCpmUsdMicros:this.postRevshareBidCpmUsdMicros,debugInfo:this.D?f:void 0,debugEventMessage:this.debugEventMessage}};
+function Ac(a,b,c){if(void 0!==a.i){var d=nc(mc(new kc,a.h.interestGroupOwner),a.h.renderUrl);yc(a.h.interestGroupOwner)||R(d,8,a.J,0);fb(a.i,4,d);W(S(a.sellerSignals,Y,12),5)&&(jc(fb(a.i,11,a.sellerSignals),ec(dc(new cc,a.h.renderUrl),a.I)),a.o.forEach(function(h,k){var l;null!=(l=a.i)&&(k=ec(dc(new cc,k),h),J(l),h=eb(l,cc,9,void 0,!1,!1),k=null!=k?k:new cc,l=Za(l,9,2,void 0,!1),h.push(k),l.push(k.j),E(k.j)&&Ea(l,8))}));if(Object.values(gc).includes(b)){var f;null!=(f=a.i)&&R(f,6,b,0)}if(Object.values(fc).includes(c)){var e;
+null!=(e=a.i)&&R(e,5,c,0)}if(1!==b||1!==c){var g;null!=(g=a.i)&&R(g,10,wc(b,c),0)}}}ea.Object.defineProperties(zc.prototype,{debugEventMessage:{configurable:!0,enumerable:!0,get:function(){var a;return null==(a=this.i)?void 0:Wa(a)}}});function Bc(a){var b;this.i=null!=(b=null==a?void 0:V(L(a,4),0))?b:0}Bc.prototype.h=function(a){if(!this.i)return 1;var b;return(null==(b=T(a,Vb,9))?0:O(b,1).includes(this.i))?2:1};function Cc(a,b){return 0===a.size?!1:void 0===b||0===b.length?!0:b.some(function(c){return a.has(c)})}function Dc(a){a=S(S(a,Z,2),Eb,1);this.i=new Set(O(a,1));this.o=W(a,4);this.D=W(a,5)}Dc.prototype.h=function(a){var b;if(Cc(this.i,null==(b=T(a,Xb,1))?void 0:O(b,1)))return 4;a=T(a,Xb,1);return!this.D||a&&!W(a,4)?!this.o||a&&!W(a,3)?1:3:4};function Ec(a){this.i=W(S(S(a,Z,2),Gb,3),2);this.o=new Set(O(S(S(a,Z,2),Gb,3),1))}Ec.prototype.h=function(a){var b=this;return this.i?1:void 0===bb(a,Zb,7,!1)||O(T(a,Zb,7),1).every(function(c){return b.o.has(c)})?1:5};function Fc(a){var b,c,d;this.i=new Set(null!=(d=null==a?void 0:null==(b=T(a,Z,2))?void 0:null==(c=T(b,Ib,4))?void 0:P(c,1,Na,!1))?d:[])}Fc.prototype.h=function(a){var b=this;return 0===this.i.size?1:0===P(a,10,Na,!1).length||P(a,10,Na,!1).some(function(c){return!b.i.has(c)})?6:1};function Gc(a){var b,c;this.i=null!=(c=null==a?void 0:null==(b=T(a,Ob,3))?void 0:U(b,Qb,1))?c:[]}Gc.prototype.h=function(a,b){if(null==b)return 7;if(0===this.i.length)return 1;a=p(this.i);for(var c=a.next();!c.done;c=a.next())if(c=c.value,null!=V(L(c,2),0)&&b<V(L(c,2),0))return 7;return 1};function Hc(a){var b,c,d;this.i=new Set(null!=(d=null==a?void 0:null==(b=T(a,Z,2))?void 0:null==(c=T(b,Kb,2))?void 0:P(c,1,Ma))?d:[])}Hc.prototype.h=function(a){var b=this;return 0!==this.i.size&&P(a,6,Ma).some(function(c){return b.i.has(c)})?8:1};function Ic(a){a=S(S(a,Z,2),Mb,5);this.i=W(a,2);this.o=new Set(O(a,1))}Ic.prototype.h=function(a){var b=this;return this.i?1:O(S(a,Zb,7),1).every(function(c){return b.o.has(c)})?1:9};function Jc(){new pc;return function(a,b,c,d,f){a=new Sb(ob(c.sellerSignals));b=Kc(b,a,d,f,W(a,8)||W(a,22));W(a,8)&&b.debugInfo&&console.log(b.debugInfo);if(W(a,22)&&b.debugInfo){d=b.debugInfo.s;c=b.debugInfo.r;var e,g,h={renderUrl:null!=(e=null==f?void 0:f.renderUrl)?e:"",interestGroupOwner:null!=(g=null==f?void 0:f.interestGroupOwner)?g:"",accepted:!0};if(1!==d||1!==c)h.accepted=!1,h.externalBidStatus=wc(d,c);console.log("Logging debug info of scoreAd().\n",h)}b.debugEventMessage&&(e=b.debugEventMessage,
+g=globalThis.forDebuggingOnly,W(S(a,Y,12),1)&&g.reportAdAuctionWin&&Lc(a,e,g.reportAdAuctionWin,1),W(S(a,Y,12),2)&&g.reportAdAuctionLoss&&Lc(a,e,g.reportAdAuctionLoss,2));return f.topLevelSeller?{desirability:b.desirability,bid:b.postRevshareBidCpmUsdMicros?b.postRevshareBidCpmUsdMicros/1E6:void 0,allowComponentAuction:!0}:{desirability:b.desirability,allowComponentAuction:!0}}}
+function Lc(a,b,c,d){R(b,2,d,0);d=T(b,kc,4);if(W(a,23)&&d&&!yc(V(L(d,2),""))){a=encodeURIComponent;a:{Ia=!0;try{var f=JSON.stringify(b.toJSON(),mb);break a}finally{Ia=!1}f=void 0}c("https://googleads.g.doubleclick.net/td/rdl?tdr="+a(f))}else oc(new qb(c),b)}
+function Mc(a,b){var c,d=null==(c=a.sellerSignals)?void 0:T(c,yb,3),f=null==b?void 0:T(b,yb,11);if(d&&f){c=new Map;for(var e=new Map,g=p(U(d,Ab,1)),h=g.next();!h.done;h=g.next())h=h.value,c.set(Q(h,1),h);d=p(U(d,Cb,2));for(g=d.next();!g.done;g=d.next())g=g.value,e.set(Q(g,1),g);d=new Map;if(g=c&&e&&f)a:{g=p(U(f,Ab,1));for(h=g.next();!h.done;h=g.next()){h=h.value;var k=Q(h,1),l=e.get(k);if(l){var m=null;if(W(h,7)){var q=d.get(k),G=!0,D=V(L(h,8),0);if(void 0===q)q=new Map,d.set(k,q);else{var N=q.get(D);
+if(N){g=N;break a}null===N&&(G=!1)}G&&(m=rc(h,l,k),q.set(D,m))}else m=rc(h,l,k);if(m){g=m;break a}}}f=p(U(f,Cb,2));for(e=f.next();!e.done;e=f.next())if(e=e.value,d=Q(e,1),g=c.get(d))if(e=rc(g,e,d)){g=e;break a}g=null}if(g)return{G:2,B:0}}a:{c=a.postRevshareBidCpmUsdMicros;var da;a=null!=(da=T(a.sellerSignals,Rb,1))?da:new Rb;da=p([new Bc(a),new Dc(a),new Ec(a),new Fc(a),new Gc(a),new Hc(a),new Ic(a)]);for(a=da.next();!a.done;a=da.next())if(a=a.value.h(b,c),1!==a){b=a;break a}b=1}return 1!==b?{G:4,
+B:b}:{G:0,B:1}}
+function Kc(a,b,c,d,f){var e=!!d.componentSeller,g=1E6*a,h=S(S(b,Tb,5),Ub,1);h=L(h,1);h=g*(V(null==h?h:+h,0)||1);a=new zc(a,h,b,d,f);if(d.topLevelSeller&&"https://pubads.g.doubleclick.net"!==d.topLevelSeller)return a.reject(9);var k;f=BigInt((null==(k=T(b,Tb,5))?void 0:V(L(k,2),"0"))||0);if(h<f)return a.reject(5);var l;b=BigInt((null==(l=T(b,Tb,5))?void 0:V(L(l,3),"0"))||0);if(0<b&&g>b)return a.reject(3);if(e)return a.accept();if(!d.renderUrl)return a.reject(7,11);e=null==c?void 0:c.renderUrl;if(null==
+e||!e[d.renderUrl])return a.reject(6,10);var m;e=new ac(ob(null!=(m=null==e?void 0:e[d.renderUrl])?m:[]));a.I=e;m=Mc(a,a.I);if(1!==m.B)return a.reject(m.G,m.B);var q;if(null==(q=d.adComponents)?0:q.length){q=!1;d=p(d.adComponents);for(m=d.next();!m.done;m=d.next())if(m=m.value,l=g=e=void 0,b=null!=(l=null==(e=c)?void 0:null==(g=e.adComponentRenderUrls)?void 0:g[m])?l:[],e=ob(b),e.length&&(q=!0,e=new ac(e),a.o.set(m,e),e=Mc(a,e),1!==e.B))return c=a.reject(e.G,e.B),c.debugInfo&&(c.debugInfo.acru=m),
+c;if(!q)return a.reject(8,12)}return a.accept()};function Nc(a,b,c,d,f){var e=a.metadata.metadata;c={seller:c.seller,decisionLogicUrl:c.decision_logic_uri,trustedScoringSignalsUrl:c.trusted_scoring_signal_uri,interestGroupBuyers:c.custom_audience_buyers,auctionSignals:f,sellerExperimentGroupId:void 0,sellerSignals:d.signals,perBuyerSignals:c.per_buyer_signals};a={topWindowHostname:"",interestGroupOwner:"",renderUrl:a.render_uri,biddingDurationMsec:0};b=Jc()(e,b,c,f,a);return{status:0,score:"number"===typeof b?b:b.desirability}};var Oc=globalThis;Oc.scoreAd=function(a,b,c,d,f){return Nc(a,b,c,d,f)};Oc.scoreAdIterative=function(a,b,c,d){var f=[],e=(new Date).getTime();a=p(a);for(var g=a.next();!g.done;g=a.next())g=g.value,g=Nc(g.ad,g.bid,b,c,d),f.push(g);return{responses:f,status:0,duration:(new Date).getTime()-e}};
diff --git a/apct-tests/perftests/rubidium/src/android/rubidium/js/JSScriptEnginePerfTests.java b/apct-tests/perftests/rubidium/src/android/rubidium/js/JSScriptEnginePerfTests.java
index 33b2bea..0b35101 100644
--- a/apct-tests/perftests/rubidium/src/android/rubidium/js/JSScriptEnginePerfTests.java
+++ b/apct-tests/perftests/rubidium/src/android/rubidium/js/JSScriptEnginePerfTests.java
@@ -17,6 +17,7 @@
 package android.rubidium.js;
 
 import static com.android.adservices.service.js.JSScriptArgument.arrayArg;
+import static com.android.adservices.service.js.JSScriptArgument.jsonArg;
 import static com.android.adservices.service.js.JSScriptArgument.numericArg;
 import static com.android.adservices.service.js.JSScriptArgument.recordArg;
 import static com.android.adservices.service.js.JSScriptArgument.stringArg;
@@ -26,8 +27,14 @@
 
 import static org.junit.Assume.assumeTrue;
 
+import android.adservices.adselection.AdSelectionConfig;
+import android.adservices.adselection.AdWithBid;
+import android.adservices.common.AdData;
+import android.adservices.common.AdSelectionSignals;
+import android.adservices.common.AdTechIdentifier;
 import android.annotation.SuppressLint;
 import android.content.Context;
+import android.net.Uri;
 import android.perftests.utils.BenchmarkState;
 import android.perftests.utils.PerfStatusReporter;
 import android.util.Log;
@@ -37,6 +44,12 @@
 import androidx.test.filters.MediumTest;
 import androidx.test.runner.AndroidJUnit4;
 
+import com.android.adservices.data.adselection.CustomAudienceSignals;
+import com.android.adservices.service.adselection.AdDataArgument;
+import com.android.adservices.service.adselection.AdSelectionConfigArgument;
+import com.android.adservices.service.adselection.AdWithBidArgument;
+import com.android.adservices.service.adselection.CustomAudienceBiddingSignalsArgument;
+import com.android.adservices.service.adselection.CustomAudienceScoringSignalsArgument;
 import com.android.adservices.service.js.IsolateSettings;
 import com.android.adservices.service.js.JSScriptArgument;
 import com.android.adservices.service.js.JSScriptArrayArgument;
@@ -46,9 +59,11 @@
 import com.android.adservices.service.profiling.Profiler;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.util.concurrent.ListenableFuture;
 
 import org.json.JSONArray;
+import org.json.JSONObject;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
@@ -58,14 +73,23 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
+import java.time.Clock;
+import java.time.Duration;
+import java.time.Instant;
+import java.time.ZoneOffset;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Locale;
+import java.util.Map;
 import java.util.Objects;
 import java.util.Random;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 
 /** To run the unit tests for this class, run "atest RubidiumPerfTests:JSScriptEnginePerfTests" */
 @MediumTest
@@ -78,8 +102,12 @@
     private static final JSScriptEngine sJSScriptEngine =
             JSScriptEngine.getInstanceForTesting(
                     sContext, Profiler.createInstance(JSScriptEngine.TAG));
-
-    @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+    private static final Clock CLOCK = Clock.fixed(Instant.now(), ZoneOffset.UTC);
+    private static final Instant ACTIVATION_TIME = CLOCK.instant();
+    private static final Instant EXPIRATION_TIME = CLOCK.instant().plus(Duration.ofDays(1));
+    private static final AdSelectionSignals CONTEXTUAL_SIGNALS = AdSelectionSignals.EMPTY;
+    @Rule
+    public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
 
     @Before
     public void before() throws Exception {
@@ -162,6 +190,56 @@
         runParametrizedTurtledoveScript(75);
     }
 
+    @Test
+    public void evaluate_rubidiumGenerateBid_parametrized_1Ad() throws Exception {
+        runParameterizedRubidiumGenerateBid(1);
+    }
+
+    @Test
+    public void evaluate_rubidiumGenerateBid_parametrized_10Ads() throws Exception {
+        runParameterizedRubidiumGenerateBid(10);
+    }
+
+    @Test
+    public void evaluate_rubidiumGenerateBid_parametrized_25Ads() throws Exception {
+        runParameterizedRubidiumGenerateBid(25);
+    }
+
+    @Test
+    public void evaluate_rubidiumGenerateBid_parametrized_50Ads() throws Exception {
+        runParameterizedRubidiumGenerateBid(50);
+    }
+
+    @Test
+    public void evaluate_rubidiumGenerateBid_parametrized_75Ads() throws Exception {
+        runParameterizedRubidiumGenerateBid(75);
+    }
+
+    @Test
+    public void evaluate_rubidiumScoreAd_parametrized_1Ad() throws Exception {
+        runParameterizedRubidiumScoreAd(1);
+    }
+
+    @Test
+    public void evaluate_rubidiumScoreAd_parametrized_10Ads() throws Exception {
+        runParameterizedRubidiumScoreAd(10);
+    }
+
+    @Test
+    public void evaluate_rubidiumScoreAd_parametrized_25Ads() throws Exception {
+        runParameterizedRubidiumScoreAd(25);
+    }
+
+    @Test
+    public void evaluate_rubidiumScoreAd_parametrized_50Ads() throws Exception {
+        runParameterizedRubidiumScoreAd(50);
+    }
+
+    @Test
+    public void evaluate_rubidiumScoreAd_parametrized_75Ads() throws Exception {
+        runParameterizedRubidiumScoreAd(75);
+    }
+
     @SuppressLint("DefaultLocale")
     private void runParametrizedTurtledoveScript(int numAds) throws Exception {
         BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
@@ -190,7 +268,7 @@
                             "(%s: %d)",
                             JSScriptEngineLogConstants.WEBVIEW_EXECUTION_TIME, webviewExecTime);
             // The listener picks up logs from JSScriptEngine, so simulate logging from there.
-            Log.d("JSScriptEngine", webviewExecTimeLog);
+            Log.d(TAG, webviewExecTimeLog);
         }
     }
 
@@ -202,7 +280,9 @@
                         ImmutableList.of(
                                 stringArg(
                                         "renderUrl",
-                                        "https://googleads.g.doubleclick.net/ads/simple-ad.html?adg_id=52836427830&cr_id=310927197297&cv_id=4"),
+                                        "https://googleads.g.doubleclick.net/ads/simple-ad"
+                                                + ".html?adg_id=52836427830&cr_id=310927197297"
+                                                + "&cv_id=4"),
                                 stringArrayArg(
                                         "metadata",
                                         ImmutableList.of(
@@ -350,4 +430,171 @@
     private String readAsset(@NonNull String assetName) throws IOException {
         return new String(readBinaryAsset(assetName), StandardCharsets.UTF_8);
     }
+
+    public void runParameterizedRubidiumGenerateBid(int numOfAds) throws Exception {
+        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+        state.pauseTiming();
+        List<AdData> adDataList = getSampleAdDataList(numOfAds, "https://ads.example/");
+        ImmutableList.Builder<JSScriptArgument> adDataListArgument = new ImmutableList.Builder<>();
+        for (AdData adData : adDataList) {
+            adDataListArgument.add(AdDataArgument.asScriptArgument("ignored", adData));
+        }
+        AdSelectionSignals perBuyerSignals = generatePerBuyerSignals(numOfAds);
+        AdSelectionSignals auctionSignals = AdSelectionSignals.fromString("{\"auctionSignal1"
+                + "\":\"auctionValue1\",\"auctionSignal2\":\"auctionValue2\"}");
+
+        AdTechIdentifier buyer = AdTechIdentifier.fromString("https://example-dsp.com");
+        AdSelectionSignals trustedBiddingSignals = AdSelectionSignals.fromString("{\"key1"
+                + "\":\"tbs1\",\"key2\":{}}");
+        CustomAudienceSignals customAudienceSignals = getSampleCustomAudienceSignals(buyer,
+                "shoes-running");
+
+        ImmutableList<JSScriptArgument> args = ImmutableList.<JSScriptArgument>builder()
+                .add(arrayArg("ads", adDataListArgument.build()))
+                .add(jsonArg("auctionSignals", auctionSignals))
+                .add(jsonArg("perBuyerSignals", perBuyerSignals))
+                .add(jsonArg("trustedBiddingSignals", trustedBiddingSignals))
+                .add(jsonArg("contextualSignals", CONTEXTUAL_SIGNALS))
+                .add(CustomAudienceBiddingSignalsArgument.asScriptArgument(
+                        "customAudienceBiddingSignal", customAudienceSignals))
+                .build();
+        InputStream testJsInputStream = sContext.getAssets().open(
+                "rubidium_bidding_logic_compiled.js");
+        String jsTestFile = new String(testJsInputStream.readAllBytes(), StandardCharsets.UTF_8);
+        //logging time taken to call JS
+        state.resumeTiming();
+        while (state.keepRunning()) {
+            String res = callJSEngine(jsTestFile, args, "generateBidIterative");
+            JSONObject jsonObject = new JSONObject(res);
+            long webviewExecTime = jsonObject.getLong("duration");
+            String webviewExecTimeLog =
+                    String.format(Locale.ENGLISH,
+                            "(%s: %d)",
+                            JSScriptEngineLogConstants.WEBVIEW_EXECUTION_TIME,
+                            webviewExecTime);
+            // The listener picks up logs from JSScriptEngine, so simulate logging from there.
+            Log.d(TAG, webviewExecTimeLog);
+        }
+    }
+
+    public void runParameterizedRubidiumScoreAd(int numOfAds) throws Exception {
+        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+        state.pauseTiming();
+        String adRenderUrl = "https://rtb.example/creative";
+        List<AdWithBid> adWithBidList = getSampleAdDataWithBidList(numOfAds, adRenderUrl);
+        ImmutableList.Builder<JSScriptArgument> adWithBidArrayArgument =
+                new ImmutableList.Builder<>();
+        for (AdWithBid adWithBid : adWithBidList) {
+            adWithBidArrayArgument.add(AdWithBidArgument.asScriptArgument("adWithBid", adWithBid));
+        }
+        AdTechIdentifier seller = AdTechIdentifier.fromString("www.example-ssp.com");
+        AdSelectionSignals sellerSignals = AdSelectionSignals.fromString("{\"signals\":[]}");
+        String trustedScoringSignalJson = String.format(Locale.ENGLISH,
+                "{\"renderUrl\":{\"%s\":[]}}", adRenderUrl);
+        AdSelectionSignals trustedScoringSignalsJson = AdSelectionSignals.fromString(
+                trustedScoringSignalJson);
+
+        AdTechIdentifier buyer1 = AdTechIdentifier.fromString("https://example-dsp.com");
+        AdSelectionSignals buyer1Signals = AdSelectionSignals.fromString("{\"https://example-dsp"
+                + ".com:1\":\"value1\",\"https://example-dsp.com:2\":\"value2\"}");
+        Map<AdTechIdentifier, AdSelectionSignals> perBuyerSignals = ImmutableMap.of(buyer1,
+                buyer1Signals);
+
+        AdSelectionConfig adSelectionConfig = getSampleAdSelectionConfig(seller, sellerSignals,
+                perBuyerSignals);
+        CustomAudienceSignals customAudienceSignals = getSampleCustomAudienceSignals(buyer1,
+                "shoes-running");
+
+        ImmutableList<JSScriptArgument> args = ImmutableList.<JSScriptArgument>builder()
+                .add(arrayArg("adsWithBids", adWithBidArrayArgument.build()))
+                .add(AdSelectionConfigArgument.asScriptArgument(adSelectionConfig,
+                        "adSelectionConfig"))
+                .add(jsonArg("sellerSignals", sellerSignals))
+                .add(jsonArg("trustedScoringSignals", trustedScoringSignalsJson))
+                .add(jsonArg("contextualSignals", CONTEXTUAL_SIGNALS))
+                .add(CustomAudienceScoringSignalsArgument.asScriptArgument(
+                        "customAudienceScoringSignal", customAudienceSignals))
+                .build();
+        InputStream testJsInputStream = sContext.getAssets().open(
+                "rubidium_scoring_logic_compiled.js");
+        String jsTestFile = new String(testJsInputStream.readAllBytes(), StandardCharsets.UTF_8);
+        //logging time taken to call JS
+        state.resumeTiming();
+        while (state.keepRunning()) {
+            String res = callJSEngine(jsTestFile, args, "scoreAdIterative");
+            JSONObject jsonObject = new JSONObject(res);
+            long webviewExecTime = jsonObject.getLong("duration");
+            String webviewExecTimeLog =
+                    String.format(Locale.ENGLISH,
+                            "(%s: %d)",
+                            JSScriptEngineLogConstants.WEBVIEW_EXECUTION_TIME,
+                            webviewExecTime);
+            // The listener picks up logs from JSScriptEngine, so simulate logging from there.
+            Log.d(TAG, webviewExecTimeLog);
+        }
+    }
+
+    private List<AdWithBid> getSampleAdDataWithBidList(int size, String baseUri) {
+        double initialBid = 1.23;
+        return IntStream.rangeClosed(1, size).mapToObj(iterator -> {
+            Uri renderUri = Uri.parse(String.format(Locale.ENGLISH, "%s%d", baseUri, iterator));
+            String metaDataJson = String.format(Locale.ENGLISH, "{\"metadata\":[\"%d\",\"123\"]}",
+                    iterator);
+            AdData adData = new AdData.Builder().setRenderUri(renderUri).setMetadata(
+                    metaDataJson).build();
+            return new AdWithBid(adData, initialBid + iterator);
+        }).collect(Collectors.toCollection(ArrayList::new));
+    }
+
+    private List<AdData> getSampleAdDataList(int size, String baseUri) {
+        return IntStream.rangeClosed(1, size).mapToObj(iterator -> {
+            Uri renderUri = Uri.parse(String.format(Locale.ENGLISH, "%s%d", baseUri, iterator));
+            String metaDataJson = String.format(Locale.ENGLISH, "{\"metadata\":[\"%d\",\"123\"]}",
+                    iterator);
+            return new AdData.Builder().setRenderUri(renderUri).setMetadata(
+                    metaDataJson).build();
+        }).collect(Collectors.toCollection(ArrayList::new));
+    }
+
+    private CustomAudienceSignals getSampleCustomAudienceSignals(AdTechIdentifier buyer,
+            String name) {
+        String owner = "www.example-dsp.com";
+        AdSelectionSignals userBiddingSignals = AdSelectionSignals.fromString("{\"signals\":[]}");
+        return new CustomAudienceSignals.Builder()
+                .setOwner(owner)
+                .setBuyer(buyer)
+                .setActivationTime(ACTIVATION_TIME)
+                .setExpirationTime(EXPIRATION_TIME)
+                .setUserBiddingSignals(userBiddingSignals)
+                .setName(name)
+                .build();
+    }
+
+    private AdSelectionConfig getSampleAdSelectionConfig(AdTechIdentifier seller,
+            AdSelectionSignals sellerSignals,
+            Map<AdTechIdentifier, AdSelectionSignals> perBuyerSignals) {
+        Uri decisionLogicUri = Uri.parse("https://www.example-ssp.com/decide.js");
+        Uri trustedScoringSignalsUri = Uri.parse("https://www.example-ssp.com/signals");
+        List<AdTechIdentifier> buyers = ImmutableList.copyOf(
+                new ArrayList<>(perBuyerSignals.keySet()));
+        return new AdSelectionConfig.Builder()
+                .setSeller(seller)
+                .setDecisionLogicUri(decisionLogicUri)
+                .setCustomAudienceBuyers(buyers)
+                .setAdSelectionSignals(AdSelectionSignals.EMPTY)
+                .setSellerSignals(sellerSignals)
+                .setPerBuyerSignals(perBuyerSignals)
+                .setTrustedScoringSignalsUri(trustedScoringSignalsUri)
+                .build();
+    }
+
+    private AdSelectionSignals generatePerBuyerSignals(int size) {
+        String signalArrayFormat = "[\"%d\",\"123\",%d]";
+        String signalArray = IntStream.rangeClosed(1, size)
+                .mapToObj(i -> String.format(Locale.ENGLISH, signalArrayFormat, i, i))
+                .collect(Collectors.joining(", ", "[", "]"));
+        return AdSelectionSignals.fromString(
+                String.format(Locale.ENGLISH, "{\"signals\":[null,%s,[null]]}",
+                        signalArray));
+    }
 }
diff --git a/apct-tests/perftests/settingsprovider/Android.bp b/apct-tests/perftests/settingsprovider/Android.bp
new file mode 100644
index 0000000..43ec0e0
--- /dev/null
+++ b/apct-tests/perftests/settingsprovider/Android.bp
@@ -0,0 +1,39 @@
+package {
+    // See: http://go/android-license-faq
+    // A large-scale-change added 'default_applicable_licenses' to import
+    // all of the 'license_kinds' from "frameworks_base_license"
+    // to get the below license kinds:
+    //   SPDX-license-identifier-Apache-2.0
+    default_applicable_licenses: ["frameworks_base_license"],
+}
+
+android_test {
+    name: "SettingsProviderPerfTests",
+
+    srcs: [
+        "src/**/*.java",
+        "src/**/*.kt",
+    ],
+
+    static_libs: [
+        "platform-compat-test-rules",
+        "androidx.appcompat_appcompat",
+        "androidx.test.rules",
+        "androidx.test.ext.junit",
+        "androidx.annotation_annotation",
+        "apct-perftests-utils",
+        "collector-device-lib-platform",
+        "cts-install-lib-java",
+        "services.core",
+    ],
+
+    libs: ["android.test.base"],
+
+    platform_apis: true,
+
+    test_suites: ["device-tests"],
+
+    data: [":perfetto_artifacts"],
+
+    certificate: "platform",
+}
diff --git a/apct-tests/perftests/settingsprovider/AndroidManifest.xml b/apct-tests/perftests/settingsprovider/AndroidManifest.xml
new file mode 100644
index 0000000..9509c83
--- /dev/null
+++ b/apct-tests/perftests/settingsprovider/AndroidManifest.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+        package="com.android.perftests.settingsprovider">
+
+    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
+    <uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
+    <uses-permission android:name="android.permission.WRITE_DEVICE_CONFIG" />
+
+    <application>
+        <uses-library android:name="android.test.runner" />
+    </application>
+
+    <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
+            android:targetPackage="com.android.perftests.settingsprovider"/>
+
+</manifest>
diff --git a/apct-tests/perftests/settingsprovider/OWNERS b/apct-tests/perftests/settingsprovider/OWNERS
new file mode 100644
index 0000000..86ae581
--- /dev/null
+++ b/apct-tests/perftests/settingsprovider/OWNERS
@@ -0,0 +1 @@
+include /PACKAGE_MANAGER_OWNERS
diff --git a/apct-tests/perftests/settingsprovider/src/android/provider/SettingsProviderPerfTest.java b/apct-tests/perftests/settingsprovider/src/android/provider/SettingsProviderPerfTest.java
new file mode 100644
index 0000000..e31162f
--- /dev/null
+++ b/apct-tests/perftests/settingsprovider/src/android/provider/SettingsProviderPerfTest.java
@@ -0,0 +1,120 @@
+/*
+ * 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 android.provider;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(AndroidJUnit4.class)
+public final class SettingsProviderPerfTest {
+    private static final String NAMESPACE = "test@namespace";
+    private static final String SETTING_NAME1 = "test:setting1";
+    private static final String SETTING_NAME2 = "test-setting2";
+
+    private final ContentResolver mContentResolver;
+
+    @Rule
+    public final PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+    public SettingsProviderPerfTest() {
+        final Context context = InstrumentationRegistry.getInstrumentation().getContext();
+        mContentResolver = context.getContentResolver();
+    }
+
+    @Before
+    public void setUp() {
+        Settings.Secure.putString(mContentResolver, SETTING_NAME1, "1");
+        Settings.Config.putString(NAMESPACE, SETTING_NAME1, "1", true);
+        Settings.Config.putString(NAMESPACE, SETTING_NAME2, "2", true);
+    }
+
+    @After
+    public void destroy() {
+        Settings.Secure.putString(mContentResolver, SETTING_NAME1, "null");
+        Settings.Config.deleteString(NAMESPACE, SETTING_NAME1);
+        Settings.Config.deleteString(NAMESPACE, SETTING_NAME2);
+    }
+
+    @Test
+    public void testSettingsValueConsecutiveRead() {
+        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+        int i = 0;
+        while (state.keepRunning()) {
+            state.pauseTiming();
+            // Writing to setting2 should not invalidate setting1's cache
+            Settings.Secure.putString(mContentResolver, SETTING_NAME2, Integer.toString(i));
+            i++;
+            state.resumeTiming();
+            Settings.Secure.getString(mContentResolver, SETTING_NAME1);
+        }
+    }
+
+    @Test
+    public void testSettingsValueConsecutiveReadAfterWrite() {
+        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+        int i = 0;
+        while (state.keepRunning()) {
+            state.pauseTiming();
+            // Triggering the invalidation of setting1's cache
+            Settings.Secure.putString(mContentResolver, SETTING_NAME1, Integer.toString(i));
+            i++;
+            state.resumeTiming();
+            Settings.Secure.getString(mContentResolver, SETTING_NAME1);
+        }
+    }
+
+    @Test
+    public void testSettingsNamespaceConsecutiveRead() {
+        final List<String> names = new ArrayList<>();
+        names.add(SETTING_NAME1);
+        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+        while (state.keepRunning()) {
+            Settings.Config.getStrings(mContentResolver, NAMESPACE, names);
+        }
+    }
+
+    @Test
+    public void testSettingsNamespaceConsecutiveReadAfterWrite() {
+        final List<String> names = new ArrayList<>();
+        names.add(SETTING_NAME1);
+        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+        int i = 0;
+        while (state.keepRunning()) {
+            state.pauseTiming();
+            // Triggering the invalidation of the list's cache
+            Settings.Config.putString(NAMESPACE, SETTING_NAME2, Integer.toString(i), true);
+            i++;
+            state.resumeTiming();
+            Settings.Config.getStrings(mContentResolver, NAMESPACE, names);
+        }
+    }
+}
diff --git a/apex/jobscheduler/framework/java/android/app/AlarmManager.java b/apex/jobscheduler/framework/java/android/app/AlarmManager.java
index dade7c3..53e81c7 100644
--- a/apex/jobscheduler/framework/java/android/app/AlarmManager.java
+++ b/apex/jobscheduler/framework/java/android/app/AlarmManager.java
@@ -27,7 +27,6 @@
 import android.annotation.SystemService;
 import android.annotation.TestApi;
 import android.compat.annotation.ChangeId;
-import android.compat.annotation.Disabled;
 import android.compat.annotation.EnabledSince;
 import android.compat.annotation.UnsupportedAppUsage;
 import android.content.Context;
@@ -285,11 +284,10 @@
      * The permission {@link Manifest.permission#SCHEDULE_EXACT_ALARM} will be denied, unless the
      * user explicitly allows it from Settings.
      *
-     * TODO (b/226439802): Either enable it in the next SDK or replace it with a better alternative.
      * @hide
      */
     @ChangeId
-    @Disabled
+    @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
     public static final long SCHEDULE_EXACT_ALARM_DENIED_BY_DEFAULT = 226439802L;
 
     @UnsupportedAppUsage
diff --git a/apex/jobscheduler/framework/java/android/app/JobSchedulerImpl.java b/apex/jobscheduler/framework/java/android/app/JobSchedulerImpl.java
index 2d3201a..4242cf8 100644
--- a/apex/jobscheduler/framework/java/android/app/JobSchedulerImpl.java
+++ b/apex/jobscheduler/framework/java/android/app/JobSchedulerImpl.java
@@ -158,7 +158,10 @@
             android.Manifest.permission.INTERACT_ACROSS_USERS_FULL})
     @Override
     public void registerUserVisibleJobObserver(@NonNull IUserVisibleJobObserver observer) {
-        // TODO(255767350): implement
+        try {
+            mBinder.registerUserVisibleJobObserver(observer);
+        } catch (RemoteException e) {
+        }
     }
 
     @RequiresPermission(allOf = {
@@ -166,7 +169,10 @@
             android.Manifest.permission.INTERACT_ACROSS_USERS_FULL})
     @Override
     public void unregisterUserVisibleJobObserver(@NonNull IUserVisibleJobObserver observer) {
-        // TODO(255767350): implement
+        try {
+            mBinder.unregisterUserVisibleJobObserver(observer);
+        } catch (RemoteException e) {
+        }
     }
 
     @RequiresPermission(allOf = {
@@ -174,6 +180,9 @@
             android.Manifest.permission.INTERACT_ACROSS_USERS_FULL})
     @Override
     public void stopUserVisibleJobsForUser(@NonNull String packageName, int userId) {
-        // TODO(255767350): implement
+        try {
+            mBinder.stopUserVisibleJobsForUser(packageName, userId);
+        } catch (RemoteException e) {
+        }
     }
 }
diff --git a/apex/jobscheduler/framework/java/android/app/job/IJobScheduler.aidl b/apex/jobscheduler/framework/java/android/app/job/IJobScheduler.aidl
index bf29dc9..c87a2af 100644
--- a/apex/jobscheduler/framework/java/android/app/job/IJobScheduler.aidl
+++ b/apex/jobscheduler/framework/java/android/app/job/IJobScheduler.aidl
@@ -16,6 +16,7 @@
 
 package android.app.job;
 
+import android.app.job.IUserVisibleJobObserver;
 import android.app.job.JobInfo;
 import android.app.job.JobSnapshot;
 import android.app.job.JobWorkItem;
@@ -38,4 +39,10 @@
     boolean hasRunLongJobsPermission(String packageName, int userId);
     List<JobInfo> getStartedJobs();
     ParceledListSlice getAllJobSnapshots();
+    @EnforcePermission(allOf={"MANAGE_ACTIVITY_TASKS", "INTERACT_ACROSS_USERS_FULL"})
+    void registerUserVisibleJobObserver(in IUserVisibleJobObserver observer);
+    @EnforcePermission(allOf={"MANAGE_ACTIVITY_TASKS", "INTERACT_ACROSS_USERS_FULL"})
+    void unregisterUserVisibleJobObserver(in IUserVisibleJobObserver observer);
+    @EnforcePermission(allOf={"MANAGE_ACTIVITY_TASKS", "INTERACT_ACROSS_USERS_FULL"})
+    void stopUserVisibleJobsForUser(String packageName, int userId);
 }
diff --git a/apex/jobscheduler/framework/java/android/app/job/JobInfo.java b/apex/jobscheduler/framework/java/android/app/job/JobInfo.java
index 9caf99e..19ab5bc 100644
--- a/apex/jobscheduler/framework/java/android/app/job/JobInfo.java
+++ b/apex/jobscheduler/framework/java/android/app/job/JobInfo.java
@@ -30,6 +30,7 @@
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.annotation.RequiresPermission;
+import android.app.Notification;
 import android.compat.Compatibility;
 import android.compat.annotation.ChangeId;
 import android.compat.annotation.EnabledAfter;
@@ -403,6 +404,13 @@
     public static final int FLAG_DATA_TRANSFER = 1 << 5;
 
     /**
+     * Whether it's a user initiated job or not.
+     *
+     * @hide
+     */
+    public static final int FLAG_USER_INITIATED = 1 << 6;
+
+    /**
      * @hide
      */
     public static final int CONSTRAINT_FLAG_CHARGING = 1 << 0;
@@ -738,6 +746,14 @@
     }
 
     /**
+     * @see JobInfo.Builder#setUserInitiated(boolean)
+     * @hide
+     */
+    public boolean isUserInitiated() {
+        return (flags & FLAG_USER_INITIATED) != 0;
+    }
+
+    /**
      * @see JobInfo.Builder#setImportantWhileForeground(boolean)
      */
     public boolean isImportantWhileForeground() {
@@ -1849,15 +1865,8 @@
          *
          * <p>
          * For user-initiated transfers that must be started immediately, call
-         * {@link #setExpedited(boolean) setExpedited(true)}. Otherwise, the system may defer the
-         * job to a more opportune time. Using {@link #setExpedited(boolean) setExpedited(true)}
-         * with this API will only be allowed for foreground apps and when the user has clearly
-         * interacted with the app. {@link #setExpedited(boolean) setExpedited(true)} will return
-         * {@link JobScheduler#RESULT_FAILURE} for a data transfer job if the app is in the
-         * background. Apps that successfully schedule data transfer jobs with
-         * {@link #setExpedited(boolean) setExpedited(true)} will not have quotas applied to them,
-         * though they may still be stopped for system health or constraint reasons. The system will
-         * also give a user the ability to stop a data transfer job via the Task Manager.
+         * {@link #setUserInitiated(boolean) setUserInitiated(true)}. Otherwise, the system may
+         * defer the job to a more opportune time.
          *
          * <p>
          * If you want to perform more than one data transfer job, consider enqueuing multiple
@@ -1877,6 +1886,50 @@
         }
 
         /**
+         * Indicates that this job is being scheduled to fulfill an explicit user request.
+         * As such, user-initiated jobs can only be scheduled when the app is in the foreground
+         * or in a state where launching an activity is allowed, as defined
+         * <a href=
+         * "https://developer.android.com/guide/components/activities/background-starts#exceptions">
+         * here</a>. Attempting to schedule one outside of these conditions will throw a
+         * {@link SecurityException}.
+         *
+         * <p>
+         * This should <b>NOT</b> be used for automatic features.
+         *
+         * <p>
+         * All user-initiated jobs must have an associated notification, set via
+         * {@link JobService#setNotification(JobParameters, int, Notification, int)}, and will be
+         * shown in the Task Manager when running.
+         *
+         * <p>
+         * These jobs will not be subject to quotas and will be started immediately once scheduled
+         * if all constraints are met and the device system health allows for additional tasks.
+         *
+         * @see JobInfo#isUserInitiated()
+         * @hide
+         */
+        @NonNull
+        public Builder setUserInitiated(boolean userInitiated) {
+            if (userInitiated) {
+                mFlags |= FLAG_USER_INITIATED;
+                if (mPriority == PRIORITY_DEFAULT) {
+                    // The default priority for UIJs is MAX, but only change this if .setPriority()
+                    // hasn't been called yet.
+                    mPriority = PRIORITY_MAX;
+                }
+            } else {
+                if (mPriority == PRIORITY_MAX && (mFlags & FLAG_USER_INITIATED) != 0) {
+                    // Reset the priority for the job, but only change this if .setPriority()
+                    // hasn't been called yet.
+                    mPriority = PRIORITY_DEFAULT;
+                }
+                mFlags &= (~FLAG_USER_INITIATED);
+            }
+            return this;
+        }
+
+        /**
          * Setting this to true indicates that this job is important while the scheduling app
          * is in the foreground or on the temporary whitelist for background restrictions.
          * This means that the system will relax doze restrictions on this job during this time.
@@ -2086,10 +2139,12 @@
         }
 
         final boolean isExpedited = (flags & FLAG_EXPEDITED) != 0;
+        final boolean isUserInitiated = (flags & FLAG_USER_INITIATED) != 0;
         switch (mPriority) {
             case PRIORITY_MAX:
-                if (!isExpedited) {
-                    throw new IllegalArgumentException("Only expedited jobs can have max priority");
+                if (!(isExpedited || isUserInitiated)) {
+                    throw new IllegalArgumentException(
+                            "Only expedited or user-initiated jobs can have max priority");
                 }
                 break;
             case PRIORITY_HIGH:
@@ -2118,14 +2173,20 @@
             if (isPeriodic) {
                 throw new IllegalArgumentException("An expedited job cannot be periodic");
             }
+            if ((flags & FLAG_DATA_TRANSFER) != 0) {
+                throw new IllegalArgumentException(
+                        "An expedited job cannot also be a data transfer job");
+            }
+            if (isUserInitiated) {
+                throw new IllegalArgumentException("An expedited job cannot be user-initiated");
+            }
             if (mPriority != PRIORITY_MAX && mPriority != PRIORITY_HIGH) {
                 throw new IllegalArgumentException(
                         "An expedited job must be high or max priority. Don't use expedited jobs"
                                 + " for unimportant tasks.");
             }
-            if (((constraintFlags & ~CONSTRAINT_FLAG_STORAGE_NOT_LOW) != 0
-                    || (flags & ~(FLAG_EXPEDITED | FLAG_EXEMPT_FROM_APP_STANDBY
-                                    | FLAG_DATA_TRANSFER)) != 0)) {
+            if ((constraintFlags & ~CONSTRAINT_FLAG_STORAGE_NOT_LOW) != 0
+                    || (flags & ~(FLAG_EXPEDITED | FLAG_EXEMPT_FROM_APP_STANDBY)) != 0) {
                 throw new IllegalArgumentException(
                         "An expedited job can only have network and storage-not-low constraints");
             }
@@ -2152,6 +2213,33 @@
                         "A data transfer job must specify a valid network type");
             }
         }
+
+        if (isUserInitiated) {
+            if (hasEarlyConstraint) {
+                throw new IllegalArgumentException("A user-initiated job cannot have a time delay");
+            }
+            if (hasLateConstraint) {
+                throw new IllegalArgumentException("A user-initiated job cannot have a deadline");
+            }
+            if (isPeriodic) {
+                throw new IllegalArgumentException("A user-initiated job cannot be periodic");
+            }
+            if ((flags & FLAG_PREFETCH) != 0) {
+                throw new IllegalArgumentException(
+                        "A user-initiated job cannot also be a prefetch job");
+            }
+            if (mPriority != PRIORITY_MAX) {
+                throw new IllegalArgumentException("A user-initiated job must be max priority.");
+            }
+            if ((constraintFlags & CONSTRAINT_FLAG_DEVICE_IDLE) != 0) {
+                throw new IllegalArgumentException(
+                        "A user-initiated job cannot have a device-idle constraint");
+            }
+            if (triggerContentUris != null && triggerContentUris.length > 0) {
+                throw new IllegalArgumentException(
+                        "Can't call addTriggerContentUri() on a user-initiated job");
+            }
+        }
     }
 
     /**
diff --git a/apex/jobscheduler/framework/java/android/app/job/JobParameters.java b/apex/jobscheduler/framework/java/android/app/job/JobParameters.java
index ed72530..0205430 100644
--- a/apex/jobscheduler/framework/java/android/app/job/JobParameters.java
+++ b/apex/jobscheduler/framework/java/android/app/job/JobParameters.java
@@ -98,6 +98,12 @@
      */
     public static final int INTERNAL_STOP_REASON_SUCCESSFUL_FINISH =
             JobProtoEnums.INTERNAL_STOP_REASON_SUCCESSFUL_FINISH; // 10.
+    /**
+     * The user stopped the job via some UI (eg. Task Manager).
+     * @hide
+     */
+    public static final int INTERNAL_STOP_REASON_USER_UI_STOP =
+            JobProtoEnums.INTERNAL_STOP_REASON_USER_UI_STOP; // 11.
 
     /**
      * All the stop reason codes. This should be regarded as an immutable array at runtime.
@@ -121,6 +127,7 @@
             INTERNAL_STOP_REASON_DATA_CLEARED,
             INTERNAL_STOP_REASON_RTC_UPDATED,
             INTERNAL_STOP_REASON_SUCCESSFUL_FINISH,
+            INTERNAL_STOP_REASON_USER_UI_STOP,
     };
 
     /**
@@ -141,6 +148,7 @@
             case INTERNAL_STOP_REASON_DATA_CLEARED: return "data_cleared";
             case INTERNAL_STOP_REASON_RTC_UPDATED: return "rtc_updated";
             case INTERNAL_STOP_REASON_SUCCESSFUL_FINISH: return "successful_finish";
+            case INTERNAL_STOP_REASON_USER_UI_STOP: return "user_ui_stop";
             default: return "unknown:" + reasonCode;
         }
     }
@@ -230,7 +238,7 @@
     public static final int STOP_REASON_APP_STANDBY = 12;
     /**
      * The user stopped the job. This can happen either through force-stop, adb shell commands,
-     * or uninstalling.
+     * uninstalling, or some other UI.
      */
     public static final int STOP_REASON_USER = 13;
     /** The system is doing some processing that requires stopping this job. */
diff --git a/apex/jobscheduler/framework/java/android/app/job/JobService.java b/apex/jobscheduler/framework/java/android/app/job/JobService.java
index e88e979..6279959 100644
--- a/apex/jobscheduler/framework/java/android/app/job/JobService.java
+++ b/apex/jobscheduler/framework/java/android/app/job/JobService.java
@@ -416,6 +416,11 @@
      * JobScheduler will not remember this notification after the job has finished running,
      * so apps must call this every time the job is started (if required or desired).
      *
+     * <p>
+     * If separate jobs use the same notification ID with this API, the most recently provided
+     * notification will be shown to the user, and the
+     * {@code jobEndNotificationPolicy} of the last job to stop will be applied.
+     *
      * @param params                   The parameters identifying this job, as supplied to
      *                                 the job in the {@link #onStartJob(JobParameters)} callback.
      * @param notificationId           The ID for this notification, as per
diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java b/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java
index 47f6890..651853b 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java
@@ -193,6 +193,7 @@
     }
 
     private final Object mLock;
+    private final JobNotificationCoordinator mNotificationCoordinator;
     private final JobSchedulerService mService;
     private final Context mContext;
     private final Handler mHandler;
@@ -418,6 +419,7 @@
         mLock = mService.getLock();
         mContext = service.getTestableContext();
         mInjector = injector;
+        mNotificationCoordinator = new JobNotificationCoordinator();
 
         mHandler = JobSchedulerBackgroundThread.getHandler();
 
@@ -451,7 +453,8 @@
                 ServiceManager.getService(BatteryStats.SERVICE_NAME));
         for (int i = 0; i < STANDARD_CONCURRENCY_LIMIT; i++) {
             mIdleContexts.add(
-                    mInjector.createJobServiceContext(mService, this, batteryStats,
+                    mInjector.createJobServiceContext(mService, this,
+                            mNotificationCoordinator, batteryStats,
                             mService.mJobPackageTracker, mContext.getMainLooper()));
         }
     }
@@ -758,8 +761,8 @@
             if (js != null) {
                 mWorkCountTracker.incrementRunningJobCount(jsc.getRunningJobWorkType());
                 assignment.workType = jsc.getRunningJobWorkType();
-                if (js.startedAsExpeditedJob && js.lastEvaluatedBias == JobInfo.BIAS_TOP_APP) {
-                    info.numRunningTopEj++;
+                if (js.startedWithImmediacyPrivilege) {
+                    info.numRunningImmediacyPrivileged++;
                 }
             }
 
@@ -826,11 +829,9 @@
                 continue;
             }
 
-            final boolean isTopEj = nextPending.shouldTreatAsExpeditedJob()
-                    && nextPending.lastEvaluatedBias == JobInfo.BIAS_TOP_APP;
+            final boolean hasImmediacyPrivilege = hasImmediacyPrivilegeLocked(nextPending);
             if (DEBUG && isSimilarJobRunningLocked(nextPending)) {
-                Slog.w(TAG, "Already running similar " + (isTopEj ? "TOP-EJ" : "job")
-                        + " to: " + nextPending);
+                Slog.w(TAG, "Already running similar job to: " + nextPending);
             }
 
             // Factoring minChangedWaitingTimeMs into the min waiting time effectively limits
@@ -873,23 +874,25 @@
                     final JobStatus runningJob = assignment.context.getRunningJobLocked();
                     // Maybe stop the job if it has had its day in the sun. Only allow replacing
                     // for one of the following conditions:
-                    // 1. We're putting in the current TOP app's EJ
+                    // 1. We're putting in a job that has the privilege of running immediately
                     // 2. There aren't too many jobs running AND the current job started when the
                     //    app was in the background
                     // 3. There aren't too many jobs running AND the current job started when the
                     //    app was on TOP, but the app has since left TOP
                     // 4. There aren't too many jobs running AND the current job started when the
-                    //    app was on TOP, the app is still TOP, but there are too many TOP+EJs
+                    //    app was on TOP, the app is still TOP, but there are too many
+                    //    immediacy-privileged jobs
                     //    running (because we don't want them to starve out other apps and the
                     //    current job has already run for the minimum guaranteed time).
                     // 5. This new job could be waiting for too long for a slot to open up
-                    boolean canReplace = isTopEj; // Case 1
+                    boolean canReplace = hasImmediacyPrivilege; // Case 1
                     if (!canReplace && !isInOverage) {
                         final int currentJobBias = mService.evaluateJobBiasLocked(runningJob);
                         canReplace = runningJob.lastEvaluatedBias < JobInfo.BIAS_TOP_APP // Case 2
                                 || currentJobBias < JobInfo.BIAS_TOP_APP // Case 3
                                 // Case 4
-                                || info.numRunningTopEj > .5 * mWorkTypeConfig.getMaxTotal();
+                                || info.numRunningImmediacyPrivileged
+                                        > (mWorkTypeConfig.getMaxTotal() / 2);
                     }
                     if (!canReplace && mMaxWaitTimeBypassEnabled) { // Case 5
                         if (nextPending.shouldTreatAsExpeditedJob()) {
@@ -916,7 +919,7 @@
                     }
                 }
             }
-            if (selectedContext == null && (!isInOverage || isTopEj)) {
+            if (selectedContext == null && (!isInOverage || hasImmediacyPrivilege)) {
                 int lowestBiasSeen = Integer.MAX_VALUE;
                 long newMinPreferredUidOnlyWaitingTimeMs = Long.MAX_VALUE;
                 for (int p = preferredUidOnly.size() - 1; p >= 0; --p) {
@@ -959,12 +962,13 @@
                     info.minPreferredUidOnlyWaitingTimeMs = newMinPreferredUidOnlyWaitingTimeMs;
                 }
             }
-            // Make sure to run EJs for the TOP app immediately.
-            if (isTopEj) {
+            // Make sure to run jobs with special privilege immediately.
+            if (hasImmediacyPrivilege) {
                 if (selectedContext != null
                         && selectedContext.context.getRunningJobLocked() != null) {
-                    // We're "replacing" a currently running job, but we want TOP EJs to start
-                    // immediately, so we'll start the EJ on a fresh available context and
+                    // We're "replacing" a currently running job, but we want immediacy-privileged
+                    // jobs to start immediately, so we'll start the privileged jobs on a fresh
+                    // available context and
                     // stop this currently running job to replace in two steps.
                     changed.add(selectedContext);
                     projectedRunningCount--;
@@ -1026,6 +1030,7 @@
                     projectedRunningCount--;
                 }
                 if (selectedContext.newJob != null) {
+                    selectedContext.newJob.startedWithImmediacyPrivilege = hasImmediacyPrivilege;
                     projectedRunningCount++;
                     minChangedWaitingTimeMs = Math.min(minChangedWaitingTimeMs,
                             mService.getMinJobExecutionGuaranteeMs(selectedContext.newJob));
@@ -1100,6 +1105,18 @@
         mActivePkgStats.forEach(mPackageStatsStagingCountClearer);
     }
 
+    @VisibleForTesting
+    @GuardedBy("mLock")
+    boolean hasImmediacyPrivilegeLocked(@NonNull JobStatus job) {
+        // EJs & user-initiated jobs for the TOP app should run immediately.
+        // However, even for user-initiated jobs, if the app has not recently been in TOP or BAL
+        // state, we don't give the immediacy privilege so that we can try and maintain
+        // reasonably concurrency behavior.
+        return job.lastEvaluatedBias == JobInfo.BIAS_TOP_APP
+                // TODO(): include BAL state for user-initiated jobs
+                && (job.shouldTreatAsExpeditedJob() || job.shouldTreatAsUserInitiated());
+    }
+
     @GuardedBy("mLock")
     void onUidBiasChangedLocked(int prevBias, int newBias) {
         if (prevBias != JobInfo.BIAS_TOP_APP && newBias != JobInfo.BIAS_TOP_APP) {
@@ -1184,6 +1201,22 @@
     }
 
     @GuardedBy("mLock")
+    void stopUserVisibleJobsLocked(int userId, @NonNull String packageName,
+            @JobParameters.StopReason int reason, int internalReasonCode) {
+        for (int i = mActiveServices.size() - 1; i >= 0; --i) {
+            final JobServiceContext jsc = mActiveServices.get(i);
+            final JobStatus jobStatus = jsc.getRunningJobLocked();
+
+            if (jobStatus != null && userId == jobStatus.getSourceUserId()
+                    && jobStatus.getSourcePackageName().equals(packageName)
+                    && jobStatus.isUserVisibleJob()) {
+                jsc.cancelExecutingJobLocked(reason, internalReasonCode,
+                        JobParameters.getInternalReasonCodeDescription(internalReasonCode));
+            }
+        }
+    }
+
+    @GuardedBy("mLock")
     void stopNonReadyActiveJobsLocked() {
         for (int i = 0; i < mActiveServices.size(); i++) {
             JobServiceContext serviceContext = mActiveServices.get(i);
@@ -1342,7 +1375,7 @@
         mActiveServices.remove(worker);
         if (mIdleContexts.size() < MAX_RETAINED_OBJECTS) {
             // Don't need to save all new contexts, but keep some extra around in case we need
-            // extras for another TOP+EJ overage.
+            // extras for another immediacy privileged overage.
             mIdleContexts.add(worker);
         } else {
             mNumDroppedContexts++;
@@ -1384,7 +1417,8 @@
             }
             if (respectConcurrencyLimit) {
                 worker.clearPreferredUid();
-                // We're over the limit (because the TOP app scheduled a lot of EJs), but we should
+                // We're over the limit (because there were a lot of immediacy-privileged jobs
+                // scheduled), but we should
                 // be able to stop the other jobs soon so don't start running anything new until we
                 // get back below the limit.
                 noteConcurrency();
@@ -1608,17 +1642,17 @@
                 }
             } else if (mWorkCountTracker.getPendingJobCount(WORK_TYPE_EJ) > 0) {
                 return "blocking " + workTypeToString(WORK_TYPE_EJ) + " queue";
-            } else if (js.startedAsExpeditedJob && js.lastEvaluatedBias == JobInfo.BIAS_TOP_APP) {
-                // Try not to let TOP + EJ starve out other apps.
-                int topEjCount = 0;
+            } else if (js.startedWithImmediacyPrivilege) {
+                // Try not to let jobs with immediacy privilege starve out other apps.
+                int immediacyPrivilegeCount = 0;
                 for (int r = mRunningJobs.size() - 1; r >= 0; --r) {
                     JobStatus j = mRunningJobs.valueAt(r);
-                    if (j.startedAsExpeditedJob && j.lastEvaluatedBias == JobInfo.BIAS_TOP_APP) {
-                        topEjCount++;
+                    if (j.startedWithImmediacyPrivilege) {
+                        immediacyPrivilegeCount++;
                     }
                 }
-                if (topEjCount > .5 * mWorkTypeConfig.getMaxTotal()) {
-                    return "prevent top EJ dominance";
+                if (immediacyPrivilegeCount > mWorkTypeConfig.getMaxTotal() / 2) {
+                    return "prevent immediacy privilege dominance";
                 }
             }
             // No other pending EJs. Return null so we don't let regular jobs preempt an EJ.
@@ -1669,9 +1703,43 @@
         return foundSome;
     }
 
+    /**
+     * Returns the estimated network bytes if the job is running. Returns {@code null} if the job
+     * isn't running.
+     */
+    @Nullable
+    @GuardedBy("mLock")
+    Pair<Long, Long> getEstimatedNetworkBytesLocked(String pkgName, int uid, int jobId) {
+        for (int i = 0; i < mActiveServices.size(); i++) {
+            final JobServiceContext jc = mActiveServices.get(i);
+            final JobStatus js = jc.getRunningJobLocked();
+            if (js != null && js.matches(uid, jobId) && js.getSourcePackageName().equals(pkgName)) {
+                return jc.getEstimatedNetworkBytes();
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Returns the transferred network bytes if the job is running. Returns {@code null} if the job
+     * isn't running.
+     */
+    @Nullable
+    @GuardedBy("mLock")
+    Pair<Long, Long> getTransferredNetworkBytesLocked(String pkgName, int uid, int jobId) {
+        for (int i = 0; i < mActiveServices.size(); i++) {
+            final JobServiceContext jc = mActiveServices.get(i);
+            final JobStatus js = jc.getRunningJobLocked();
+            if (js != null && js.matches(uid, jobId) && js.getSourcePackageName().equals(pkgName)) {
+                return jc.getTransferredNetworkBytes();
+            }
+        }
+        return null;
+    }
+
     @NonNull
     private JobServiceContext createNewJobServiceContext() {
-        return mInjector.createJobServiceContext(mService, this,
+        return mInjector.createJobServiceContext(mService, this, mNotificationCoordinator,
                 IBatteryStats.Stub.asInterface(
                         ServiceManager.getService(BatteryStats.SERVICE_NAME)),
                 mService.mJobPackageTracker, mContext.getMainLooper());
@@ -2547,11 +2615,11 @@
     @VisibleForTesting
     static final class AssignmentInfo {
         public long minPreferredUidOnlyWaitingTimeMs;
-        public int numRunningTopEj;
+        public int numRunningImmediacyPrivileged;
 
         void clear() {
             minPreferredUidOnlyWaitingTimeMs = 0;
-            numRunningTopEj = 0;
+            numRunningImmediacyPrivileged = 0;
         }
     }
 
@@ -2596,10 +2664,11 @@
     static class Injector {
         @NonNull
         JobServiceContext createJobServiceContext(JobSchedulerService service,
-                JobConcurrencyManager concurrencyManager, IBatteryStats batteryStats,
+                JobConcurrencyManager concurrencyManager,
+                JobNotificationCoordinator notificationCoordinator, IBatteryStats batteryStats,
                 JobPackageTracker tracker, Looper looper) {
-            return new JobServiceContext(service, concurrencyManager, batteryStats,
-                    tracker, looper);
+            return new JobServiceContext(service, concurrencyManager, notificationCoordinator,
+                    batteryStats, tracker, looper);
         }
     }
 }
diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobNotificationCoordinator.java b/apex/jobscheduler/service/java/com/android/server/job/JobNotificationCoordinator.java
new file mode 100644
index 0000000..ce5ade5
--- /dev/null
+++ b/apex/jobscheduler/service/java/com/android/server/job/JobNotificationCoordinator.java
@@ -0,0 +1,144 @@
+/*
+ * 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.server.job;
+
+import static android.app.job.JobService.JOB_END_NOTIFICATION_POLICY_DETACH;
+import static android.app.job.JobService.JOB_END_NOTIFICATION_POLICY_REMOVE;
+
+import android.annotation.NonNull;
+import android.app.Notification;
+import android.app.job.JobService;
+import android.content.pm.UserPackage;
+import android.os.UserHandle;
+import android.util.ArrayMap;
+import android.util.ArraySet;
+import android.util.Slog;
+import android.util.SparseSetArray;
+
+import com.android.server.LocalServices;
+import com.android.server.notification.NotificationManagerInternal;
+
+class JobNotificationCoordinator {
+    private static final String TAG = "JobNotificationCoordinator";
+
+    /**
+     * Mapping of UserPackage -> {notificationId -> List<JobServiceContext>} to track which jobs
+     * are associated with each app's notifications.
+     */
+    private final ArrayMap<UserPackage, SparseSetArray<JobServiceContext>> mCurrentAssociations =
+            new ArrayMap<>();
+    /**
+     * Set of NotificationDetails for each running job.
+     */
+    private final ArrayMap<JobServiceContext, NotificationDetails> mNotificationDetails =
+            new ArrayMap<>();
+
+    private static final class NotificationDetails {
+        @NonNull
+        public final UserPackage userPackage;
+        public final int notificationId;
+        public final int appPid;
+        public final int appUid;
+        @JobService.JobEndNotificationPolicy
+        public final int jobEndNotificationPolicy;
+
+        NotificationDetails(@NonNull UserPackage userPackage, int appPid, int appUid,
+                int notificationId,
+                @JobService.JobEndNotificationPolicy int jobEndNotificationPolicy) {
+            this.userPackage = userPackage;
+            this.notificationId = notificationId;
+            this.appPid = appPid;
+            this.appUid = appUid;
+            this.jobEndNotificationPolicy = jobEndNotificationPolicy;
+        }
+    }
+
+    private final NotificationManagerInternal mNotificationManagerInternal;
+
+    JobNotificationCoordinator() {
+        mNotificationManagerInternal = LocalServices.getService(NotificationManagerInternal.class);
+    }
+
+    void enqueueNotification(@NonNull JobServiceContext hostingContext, @NonNull String packageName,
+            int callingPid, int callingUid, int notificationId, @NonNull Notification notification,
+            @JobService.JobEndNotificationPolicy int jobEndNotificationPolicy) {
+        validateNotification(packageName, callingUid, notification, jobEndNotificationPolicy);
+        final NotificationDetails oldDetails = mNotificationDetails.get(hostingContext);
+        if (oldDetails != null && oldDetails.notificationId != notificationId) {
+            // App is switching notification IDs. Remove association with the old one.
+            removeNotificationAssociation(hostingContext);
+        }
+        final int userId = UserHandle.getUserId(callingUid);
+        // TODO(260848384): ensure apps can't cancel the notification for user-initiated job
+        //       eg., by calling NotificationManager.cancel/All or deleting the notification channel
+        mNotificationManagerInternal.enqueueNotification(
+                packageName, packageName, callingUid, callingPid, /* tag */ null,
+                notificationId, notification, userId);
+        final UserPackage userPackage = UserPackage.of(userId, packageName);
+        final NotificationDetails details = new NotificationDetails(
+                userPackage, callingPid, callingUid, notificationId, jobEndNotificationPolicy);
+        SparseSetArray<JobServiceContext> appNotifications = mCurrentAssociations.get(userPackage);
+        if (appNotifications == null) {
+            appNotifications = new SparseSetArray<>();
+            mCurrentAssociations.put(userPackage, appNotifications);
+        }
+        appNotifications.add(notificationId, hostingContext);
+        mNotificationDetails.put(hostingContext, details);
+    }
+
+    void removeNotificationAssociation(@NonNull JobServiceContext hostingContext) {
+        final NotificationDetails details = mNotificationDetails.remove(hostingContext);
+        if (details == null) {
+            return;
+        }
+        final SparseSetArray<JobServiceContext> associations =
+                mCurrentAssociations.get(details.userPackage);
+        if (associations == null || !associations.remove(details.notificationId, hostingContext)) {
+            Slog.wtf(TAG, "Association data structures not in sync");
+            return;
+        }
+        ArraySet<JobServiceContext> associatedContexts = associations.get(details.notificationId);
+        if (associatedContexts == null || associatedContexts.isEmpty()) {
+            // No more jobs using this notification. Apply the final job stop policy.
+            if (details.jobEndNotificationPolicy == JOB_END_NOTIFICATION_POLICY_REMOVE) {
+                final String packageName = details.userPackage.packageName;
+                mNotificationManagerInternal.cancelNotification(
+                        packageName, packageName, details.appUid, details.appPid, /* tag */ null,
+                        details.notificationId, UserHandle.getUserId(details.appUid));
+            }
+        }
+    }
+
+    private void validateNotification(@NonNull String packageName, int callingUid,
+            @NonNull Notification notification,
+            @JobService.JobEndNotificationPolicy int jobEndNotificationPolicy) {
+        if (notification == null) {
+            throw new NullPointerException("notification");
+        }
+        if (notification.getSmallIcon() == null) {
+            throw new IllegalArgumentException("small icon required");
+        }
+        if (null == mNotificationManagerInternal.getNotificationChannel(
+                packageName, callingUid, notification.getChannelId())) {
+            throw new IllegalArgumentException("invalid notification channel");
+        }
+        if (jobEndNotificationPolicy != JOB_END_NOTIFICATION_POLICY_DETACH
+                && jobEndNotificationPolicy != JOB_END_NOTIFICATION_POLICY_REMOVE) {
+            throw new IllegalArgumentException("invalid job end notification policy");
+        }
+    }
+}
diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java
index 9fb2af7..e9b9660 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java
@@ -16,11 +16,14 @@
 
 package com.android.server.job;
 
+import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
+import static android.Manifest.permission.MANAGE_ACTIVITY_TASKS;
 import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
 import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER;
 import static android.text.format.DateUtils.HOUR_IN_MILLIS;
 import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
 
+import android.annotation.EnforcePermission;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.annotation.UserIdInt;
@@ -31,6 +34,7 @@
 import android.app.IUidObserver;
 import android.app.compat.CompatChanges;
 import android.app.job.IJobScheduler;
+import android.app.job.IUserVisibleJobObserver;
 import android.app.job.JobInfo;
 import android.app.job.JobParameters;
 import android.app.job.JobProtoEnums;
@@ -38,6 +42,7 @@
 import android.app.job.JobService;
 import android.app.job.JobSnapshot;
 import android.app.job.JobWorkItem;
+import android.app.job.UserVisibleJobSummary;
 import android.app.usage.UsageStatsManager;
 import android.app.usage.UsageStatsManagerInternal;
 import android.compat.annotation.ChangeId;
@@ -68,6 +73,7 @@
 import android.os.Message;
 import android.os.ParcelFileDescriptor;
 import android.os.Process;
+import android.os.RemoteCallbackList;
 import android.os.RemoteException;
 import android.os.SystemClock;
 import android.os.UserHandle;
@@ -80,6 +86,7 @@
 import android.util.ArraySet;
 import android.util.IndentingPrintWriter;
 import android.util.Log;
+import android.util.Pair;
 import android.util.Slog;
 import android.util.SparseArray;
 import android.util.SparseBooleanArray;
@@ -248,6 +255,8 @@
     static final int MSG_UID_IDLE = 7;
     static final int MSG_CHECK_CHANGED_JOB_LIST = 8;
     static final int MSG_CHECK_MEDIA_EXEMPTION = 9;
+    static final int MSG_INFORM_OBSERVER_OF_ALL_USER_VISIBLE_JOBS = 10;
+    static final int MSG_INFORM_OBSERVERS_OF_USER_VISIBLE_JOB_CHANGE = 11;
 
     /** List of controllers that will notify this service of updates to jobs. */
     final List<StateController> mControllers;
@@ -258,6 +267,8 @@
     private final List<RestrictingController> mRestrictiveControllers;
     /** Need direct access to this for testing. */
     private final StorageController mStorageController;
+    /** Needed to get estimated transfer time. */
+    private final ConnectivityController mConnectivityController;
     /** Need directly for sending uid state changes */
     private final DeviceIdleJobsController mDeviceIdleJobsController;
     /** Needed to get next estimated launch time. */
@@ -279,6 +290,9 @@
     @GuardedBy("mLock")
     private final SparseArray<String> mCloudMediaProviderPackages = new SparseArray<>();
 
+    private final RemoteCallbackList<IUserVisibleJobObserver> mUserVisibleJobObservers =
+            new RemoteCallbackList<>();
+
     private final CountQuotaTracker mQuotaTracker;
     private static final String QUOTA_TRACKER_SCHEDULE_PERSISTED_TAG = ".schedulePersisted()";
     private static final String QUOTA_TRACKER_SCHEDULE_LOGGED =
@@ -453,6 +467,13 @@
                         case Constants.KEY_RUNTIME_MIN_GUARANTEE_MS:
                         case Constants.KEY_RUNTIME_MIN_EJ_GUARANTEE_MS:
                         case Constants.KEY_RUNTIME_MIN_HIGH_PRIORITY_GUARANTEE_MS:
+                        case Constants.KEY_RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS:
+                        case Constants.KEY_RUNTIME_DATA_TRANSFER_LIMIT_MS:
+                        case Constants.KEY_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS:
+                        case Constants.KEY_RUNTIME_USER_INITIATED_LIMIT_MS:
+                        case Constants.KEY_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_BUFFER_FACTOR:
+                        case Constants.KEY_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS:
+                        case Constants.KEY_RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS:
                             if (!runtimeUpdated) {
                                 mConstants.updateRuntimeConstantsLocked();
                                 runtimeUpdated = true;
@@ -544,6 +565,21 @@
         private static final String KEY_RUNTIME_MIN_EJ_GUARANTEE_MS = "runtime_min_ej_guarantee_ms";
         private static final String KEY_RUNTIME_MIN_HIGH_PRIORITY_GUARANTEE_MS =
                 "runtime_min_high_priority_guarantee_ms";
+        private static final String KEY_RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS =
+                "runtime_min_data_transfer_guarantee_ms";
+        private static final String KEY_RUNTIME_DATA_TRANSFER_LIMIT_MS =
+                "runtime_data_transfer_limit_ms";
+        private static final String KEY_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS =
+                "runtime_min_user_initiated_guarantee_ms";
+        private static final String KEY_RUNTIME_USER_INITIATED_LIMIT_MS =
+                "runtime_user_initiated_limit_ms";
+        private static final String
+                KEY_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_BUFFER_FACTOR =
+                "runtime_min_user_initiated_data_transfer_guarantee_buffer_factor";
+        private static final String KEY_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS =
+                "runtime_min_user_initiated_data_transfer_guarantee_ms";
+        private static final String KEY_RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS =
+                "runtime_user_initiated_data_transfer_limit_ms";
 
         private static final String KEY_PERSIST_IN_SPLIT_FILES = "persist_in_split_files";
 
@@ -573,6 +609,20 @@
         public static final long DEFAULT_RUNTIME_MIN_EJ_GUARANTEE_MS = 3 * MINUTE_IN_MILLIS;
         @VisibleForTesting
         static final long DEFAULT_RUNTIME_MIN_HIGH_PRIORITY_GUARANTEE_MS = 5 * MINUTE_IN_MILLIS;
+        public static final long DEFAULT_RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS =
+                DEFAULT_RUNTIME_MIN_GUARANTEE_MS;
+        public static final long DEFAULT_RUNTIME_DATA_TRANSFER_LIMIT_MS =
+                DEFAULT_RUNTIME_FREE_QUOTA_MAX_LIMIT_MS;
+        public static final long DEFAULT_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS =
+                Math.max(10 * MINUTE_IN_MILLIS, DEFAULT_RUNTIME_MIN_GUARANTEE_MS);
+        public static final long DEFAULT_RUNTIME_USER_INITIATED_LIMIT_MS =
+                Math.max(60 * MINUTE_IN_MILLIS, DEFAULT_RUNTIME_FREE_QUOTA_MAX_LIMIT_MS);
+        public static final float
+                DEFAULT_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_BUFFER_FACTOR = 1.35f;
+        public static final long DEFAULT_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS =
+                Math.max(10 * MINUTE_IN_MILLIS, DEFAULT_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS);
+        public static final long DEFAULT_RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS =
+                Math.max(Long.MAX_VALUE, DEFAULT_RUNTIME_USER_INITIATED_LIMIT_MS);
         static final boolean DEFAULT_PERSIST_IN_SPLIT_FILES = true;
         private static final boolean DEFAULT_USE_TARE_POLICY = false;
 
@@ -689,6 +739,49 @@
                 DEFAULT_RUNTIME_MIN_HIGH_PRIORITY_GUARANTEE_MS;
 
         /**
+         * The minimum amount of time we try to guarantee normal data transfer jobs will run for.
+         */
+        public long RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS =
+                DEFAULT_RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS;
+
+        /**
+         * The maximum amount of time we will let a normal data transfer job run for. This will only
+         * apply if there are no other limits that apply to the specific data transfer job.
+         */
+        public long RUNTIME_DATA_TRANSFER_LIMIT_MS = DEFAULT_RUNTIME_DATA_TRANSFER_LIMIT_MS;
+
+        /**
+         * The minimum amount of time we try to guarantee normal user-initiated jobs will run for.
+         */
+        public long RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS =
+                DEFAULT_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS;
+
+        /**
+         * The maximum amount of time we will let a user-initiated job run for. This will only
+         * apply if there are no other limits that apply to the specific user-initiated job.
+         */
+        public long RUNTIME_USER_INITIATED_LIMIT_MS = DEFAULT_RUNTIME_USER_INITIATED_LIMIT_MS;
+
+        /**
+         * A factor to apply to estimated transfer durations for user-initiated data transfer jobs
+         * so that we give some extra time for unexpected situations. This will be at least 1 and
+         * so can just be multiplied with the original value to get the final value.
+         */
+        public float RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_BUFFER_FACTOR =
+                DEFAULT_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_BUFFER_FACTOR;
+
+        /**
+         * The minimum amount of time we try to guarantee user-initiated data transfer jobs
+         * will run for.
+         */
+        public long RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS =
+                DEFAULT_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS;
+
+        /** The maximum amount of time we will let a user-initiated data transfer job run for. */
+        public long RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS =
+                DEFAULT_RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS;
+
+        /**
          * Whether to persist jobs in split files (by UID). If false, all persisted jobs will be
          * saved in a single file.
          */
@@ -790,7 +883,14 @@
                     DeviceConfig.NAMESPACE_JOB_SCHEDULER,
                     KEY_RUNTIME_FREE_QUOTA_MAX_LIMIT_MS,
                     KEY_RUNTIME_MIN_GUARANTEE_MS, KEY_RUNTIME_MIN_EJ_GUARANTEE_MS,
-                    KEY_RUNTIME_MIN_HIGH_PRIORITY_GUARANTEE_MS);
+                    KEY_RUNTIME_MIN_HIGH_PRIORITY_GUARANTEE_MS,
+                    KEY_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_BUFFER_FACTOR,
+                    KEY_RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS,
+                    KEY_RUNTIME_DATA_TRANSFER_LIMIT_MS,
+                    KEY_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS,
+                    KEY_RUNTIME_USER_INITIATED_LIMIT_MS,
+                    KEY_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS,
+                    KEY_RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS);
 
             // Make sure min runtime for regular jobs is at least 10 minutes.
             RUNTIME_MIN_GUARANTEE_MS = Math.max(10 * MINUTE_IN_MILLIS,
@@ -808,6 +908,49 @@
             RUNTIME_FREE_QUOTA_MAX_LIMIT_MS = Math.max(RUNTIME_MIN_GUARANTEE_MS,
                     properties.getLong(KEY_RUNTIME_FREE_QUOTA_MAX_LIMIT_MS,
                             DEFAULT_RUNTIME_FREE_QUOTA_MAX_LIMIT_MS));
+            // Make sure min runtime is at least as long as regular jobs.
+            RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS = Math.max(RUNTIME_MIN_GUARANTEE_MS,
+                    properties.getLong(
+                            KEY_RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS,
+                            DEFAULT_RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS));
+            // Max limit should be at least the min guarantee AND the free quota.
+            RUNTIME_DATA_TRANSFER_LIMIT_MS = Math.max(RUNTIME_FREE_QUOTA_MAX_LIMIT_MS,
+                    Math.max(RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS,
+                            properties.getLong(
+                                    KEY_RUNTIME_DATA_TRANSFER_LIMIT_MS,
+                                    DEFAULT_RUNTIME_DATA_TRANSFER_LIMIT_MS)));
+            // Make sure min runtime is at least as long as regular jobs.
+            RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS = Math.max(RUNTIME_MIN_GUARANTEE_MS,
+                    properties.getLong(
+                            KEY_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS,
+                            DEFAULT_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS));
+            // Max limit should be at least the min guarantee AND the free quota.
+            RUNTIME_USER_INITIATED_LIMIT_MS = Math.max(RUNTIME_FREE_QUOTA_MAX_LIMIT_MS,
+                    Math.max(RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS,
+                            properties.getLong(
+                                    KEY_RUNTIME_USER_INITIATED_LIMIT_MS,
+                                    DEFAULT_RUNTIME_USER_INITIATED_LIMIT_MS)));
+            // The buffer factor should be at least 1 (so we don't decrease the time).
+            RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_BUFFER_FACTOR = Math.max(1,
+                    properties.getFloat(
+                            KEY_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_BUFFER_FACTOR,
+                            DEFAULT_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_BUFFER_FACTOR
+                    ));
+            // Make sure min runtime is at least as long as other user-initiated jobs.
+            RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS = Math.max(
+                    RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS,
+                    properties.getLong(
+                            KEY_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS,
+                            DEFAULT_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS));
+            // Data transfer requires RUN_LONG_JOBS permission, so the upper limit will be higher
+            // than other jobs.
+            // Max limit should be the min guarantee and the max of other user-initiated jobs.
+            RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS = Math.max(
+                    RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS,
+                    Math.max(RUNTIME_USER_INITIATED_LIMIT_MS,
+                            properties.getLong(
+                                    KEY_RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS,
+                                    DEFAULT_RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS)));
         }
 
         private boolean updateTareSettingsLocked(boolean isTareEnabled) {
@@ -856,6 +999,20 @@
                     RUNTIME_MIN_HIGH_PRIORITY_GUARANTEE_MS).println();
             pw.print(KEY_RUNTIME_FREE_QUOTA_MAX_LIMIT_MS, RUNTIME_FREE_QUOTA_MAX_LIMIT_MS)
                     .println();
+            pw.print(KEY_RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS,
+                    RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS).println();
+            pw.print(KEY_RUNTIME_DATA_TRANSFER_LIMIT_MS,
+                    RUNTIME_DATA_TRANSFER_LIMIT_MS).println();
+            pw.print(KEY_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS,
+                    RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS).println();
+            pw.print(KEY_RUNTIME_USER_INITIATED_LIMIT_MS,
+                    RUNTIME_USER_INITIATED_LIMIT_MS).println();
+            pw.print(KEY_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_BUFFER_FACTOR,
+                    RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_BUFFER_FACTOR).println();
+            pw.print(KEY_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS,
+                    RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS).println();
+            pw.print(KEY_RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS,
+                    RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS).println();
 
             pw.print(KEY_PERSIST_IN_SPLIT_FILES, PERSIST_IN_SPLIT_FILES).println();
 
@@ -1501,6 +1658,14 @@
         }
     }
 
+    private void stopUserVisibleJobsInternal(@NonNull String packageName, int userId) {
+        synchronized (mLock) {
+            mConcurrencyManager.stopUserVisibleJobsLocked(userId, packageName,
+                    JobParameters.STOP_REASON_USER,
+                    JobParameters.INTERNAL_STOP_REASON_USER_UI_STOP);
+        }
+    }
+
     private final Consumer<JobStatus> mCancelJobDueToUserRemovalConsumer = (toRemove) -> {
         // There's no guarantee that the process has been stopped by the time we get
         // here, but since this is a user-initiated action, it should be fine to just
@@ -1839,9 +2004,9 @@
         final FlexibilityController flexibilityController =
                 new FlexibilityController(this, mPrefetchController);
         mControllers.add(flexibilityController);
-        final ConnectivityController connectivityController =
+        mConnectivityController =
                 new ConnectivityController(this, flexibilityController);
-        mControllers.add(connectivityController);
+        mControllers.add(mConnectivityController);
         mControllers.add(new TimeController(this));
         final IdleController idleController = new IdleController(this, flexibilityController);
         mControllers.add(idleController);
@@ -1857,16 +2022,16 @@
         mDeviceIdleJobsController = new DeviceIdleJobsController(this);
         mControllers.add(mDeviceIdleJobsController);
         mQuotaController =
-                new QuotaController(this, backgroundJobsController, connectivityController);
+                new QuotaController(this, backgroundJobsController, mConnectivityController);
         mControllers.add(mQuotaController);
         mControllers.add(new ComponentController(this));
         mTareController =
-                new TareController(this, backgroundJobsController, connectivityController);
+                new TareController(this, backgroundJobsController, mConnectivityController);
         mControllers.add(mTareController);
 
         mRestrictiveControllers = new ArrayList<>();
         mRestrictiveControllers.add(batteryController);
-        mRestrictiveControllers.add(connectivityController);
+        mRestrictiveControllers.add(mConnectivityController);
         mRestrictiveControllers.add(idleController);
 
         // Create restrictions
@@ -2159,6 +2324,7 @@
         }
         delayMillis =
                 Math.min(delayMillis, JobInfo.MAX_BACKOFF_DELAY_MILLIS);
+        // TODO(255767350): demote all jobs to regular for user stops so they don't keep privileges
         JobStatus newJob = new JobStatus(failureToReschedule,
                 elapsedNowMillis + delayMillis,
                 JobStatus.NO_LATEST_RUNTIME, numFailures, numSystemStops,
@@ -2509,6 +2675,52 @@
                         args.recycle();
                         break;
                     }
+
+                    case MSG_INFORM_OBSERVER_OF_ALL_USER_VISIBLE_JOBS: {
+                        final IUserVisibleJobObserver observer =
+                                (IUserVisibleJobObserver) message.obj;
+                        synchronized (mLock) {
+                            for (int i = mConcurrencyManager.mActiveServices.size() - 1; i >= 0;
+                                    --i) {
+                                JobServiceContext context =
+                                        mConcurrencyManager.mActiveServices.get(i);
+                                final JobStatus jobStatus = context.getRunningJobLocked();
+                                if (jobStatus != null && jobStatus.isUserVisibleJob()) {
+                                    try {
+                                        observer.onUserVisibleJobStateChanged(
+                                                jobStatus.getUserVisibleJobSummary(),
+                                                /* isRunning */ true);
+                                    } catch (RemoteException e) {
+                                        // Will be unregistered automatically by
+                                        // RemoteCallbackList's dead-object tracking,
+                                        // so don't need to remove it here.
+                                        break;
+                                    }
+                                }
+                            }
+                        }
+                        break;
+                    }
+
+                    case MSG_INFORM_OBSERVERS_OF_USER_VISIBLE_JOB_CHANGE: {
+                        final SomeArgs args = (SomeArgs) message.obj;
+                        final JobServiceContext context = (JobServiceContext) args.arg1;
+                        final JobStatus jobStatus = (JobStatus) args.arg2;
+                        final UserVisibleJobSummary summary = jobStatus.getUserVisibleJobSummary();
+                        final boolean isRunning = args.argi1 == 1;
+                        for (int i = mUserVisibleJobObservers.beginBroadcast() - 1; i >= 0; --i) {
+                            try {
+                                mUserVisibleJobObservers.getBroadcastItem(i)
+                                        .onUserVisibleJobStateChanged(summary, isRunning);
+                            } catch (RemoteException e) {
+                                // Will be unregistered automatically by RemoteCallbackList's
+                                // dead-object tracking, so nothing we need to do here.
+                            }
+                        }
+                        mUserVisibleJobObservers.finishBroadcast();
+                        args.recycle();
+                        break;
+                    }
                 }
                 maybeRunPendingJobsLocked();
             }
@@ -2639,8 +2851,8 @@
                 }
 
                 final boolean shouldForceBatchJob;
-                if (job.shouldTreatAsExpeditedJob()) {
-                    // Never batch expedited jobs, even for RESTRICTED apps.
+                if (job.shouldTreatAsExpeditedJob() || job.shouldTreatAsUserInitiated()) {
+                    // Never batch expedited or user-initiated jobs, even for RESTRICTED apps.
                     shouldForceBatchJob = false;
                 } else if (job.getEffectiveStandbyBucket() == RESTRICTED_INDEX) {
                     // Restricted jobs must always be batched
@@ -2962,7 +3174,30 @@
     /** Returns the minimum amount of time we should let this job run before timing out. */
     public long getMinJobExecutionGuaranteeMs(JobStatus job) {
         synchronized (mLock) {
-            if (job.shouldTreatAsExpeditedJob()) {
+            final boolean shouldTreatAsDataTransfer = job.getJob().isDataTransfer()
+                    && checkRunLongJobsPermission(job.getSourceUid(), job.getSourcePackageName());
+            if (job.shouldTreatAsUserInitiated()) {
+                if (shouldTreatAsDataTransfer) {
+                    final long estimatedTransferTimeMs =
+                            mConnectivityController.getEstimatedTransferTimeMs(job);
+                    if (estimatedTransferTimeMs == ConnectivityController.UNKNOWN_TIME) {
+                        return mConstants.RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS;
+                    }
+                    // Try to give the job at least as much time as we think the transfer will take,
+                    // but cap it at the maximum limit
+                    final long factoredTransferTimeMs = (long) (estimatedTransferTimeMs
+                            * mConstants
+                            .RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_BUFFER_FACTOR);
+                    return Math.min(mConstants.RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS,
+                            Math.max(factoredTransferTimeMs,
+                                    mConstants.RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS
+                            ));
+                }
+                return mConstants.RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS;
+            } else if (shouldTreatAsDataTransfer) {
+                // For now, don't increase a bg data transfer's minimum guarantee.
+                return mConstants.RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS;
+            } else if (job.shouldTreatAsExpeditedJob()) {
                 // Don't guarantee RESTRICTED jobs more than 5 minutes.
                 return job.getEffectiveStandbyBucket() != RESTRICTED_INDEX
                         ? mConstants.RUNTIME_MIN_EJ_GUARANTEE_MS
@@ -2978,6 +3213,25 @@
     /** Returns the maximum amount of time this job could run for. */
     public long getMaxJobExecutionTimeMs(JobStatus job) {
         synchronized (mLock) {
+            final boolean allowLongerJob;
+            final boolean isDataTransfer = job.getJob().isDataTransfer();
+            if (isDataTransfer || job.shouldTreatAsUserInitiated()) {
+                allowLongerJob =
+                        checkRunLongJobsPermission(job.getSourceUid(), job.getSourcePackageName());
+            } else {
+                allowLongerJob = false;
+            }
+            if (job.shouldTreatAsUserInitiated()) {
+                if (isDataTransfer && allowLongerJob) {
+                    return mConstants.RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS;
+                }
+                if (allowLongerJob) {
+                    return mConstants.RUNTIME_USER_INITIATED_LIMIT_MS;
+                }
+                return mConstants.RUNTIME_FREE_QUOTA_MAX_LIMIT_MS;
+            } else if (isDataTransfer && allowLongerJob) {
+                return mConstants.RUNTIME_DATA_TRANSFER_LIMIT_MS;
+            }
             return Math.min(mConstants.RUNTIME_FREE_QUOTA_MAX_LIMIT_MS,
                     mConstants.USE_TARE_POLICY
                             ? mTareController.getMaxJobExecutionTimeMsLocked(job)
@@ -3022,6 +3276,16 @@
         return adjustJobBias(bias, job);
     }
 
+    void informObserversOfUserVisibleJobChange(JobServiceContext context, JobStatus jobStatus,
+            boolean isRunning) {
+        SomeArgs args = SomeArgs.obtain();
+        args.arg1 = context;
+        args.arg2 = jobStatus;
+        args.argi1 = isRunning ? 1 : 0;
+        mHandler.obtainMessage(MSG_INFORM_OBSERVERS_OF_USER_VISIBLE_JOB_CHANGE, args)
+                .sendToTarget();
+    }
+
     private final class BatteryStateTracker extends BroadcastReceiver {
         /**
          * Track whether we're "charging", where charging means that we're ready to commit to
@@ -3627,13 +3891,6 @@
             return checkRunLongJobsPermission(uid, packageName);
         }
 
-        private boolean checkRunLongJobsPermission(int packageUid, String packageName) {
-            // Returns true if both the appop and permission are granted.
-            return PermissionChecker.checkPermissionForPreflight(getContext(),
-                    android.Manifest.permission.RUN_LONG_JOBS, PermissionChecker.PID_UNKNOWN,
-                    packageUid, packageName) == PermissionChecker.PERMISSION_GRANTED;
-        }
-
         /**
          * "dumpsys" infrastructure
          */
@@ -3744,6 +4001,38 @@
                 return new ParceledListSlice<>(snapshots);
             }
         }
+
+        @Override
+        @EnforcePermission(allOf = {MANAGE_ACTIVITY_TASKS, INTERACT_ACROSS_USERS_FULL})
+        public void registerUserVisibleJobObserver(@NonNull IUserVisibleJobObserver observer) {
+            super.registerUserVisibleJobObserver_enforcePermission();
+            if (observer == null) {
+                throw new NullPointerException("observer");
+            }
+            mUserVisibleJobObservers.register(observer);
+            mHandler.obtainMessage(MSG_INFORM_OBSERVER_OF_ALL_USER_VISIBLE_JOBS, observer)
+                    .sendToTarget();
+        }
+
+        @Override
+        @EnforcePermission(allOf = {MANAGE_ACTIVITY_TASKS, INTERACT_ACROSS_USERS_FULL})
+        public void unregisterUserVisibleJobObserver(@NonNull IUserVisibleJobObserver observer) {
+            super.unregisterUserVisibleJobObserver_enforcePermission();
+            if (observer == null) {
+                throw new NullPointerException("observer");
+            }
+            mUserVisibleJobObservers.unregister(observer);
+        }
+
+        @Override
+        @EnforcePermission(allOf = {MANAGE_ACTIVITY_TASKS, INTERACT_ACROSS_USERS_FULL})
+        public void stopUserVisibleJobsForUser(@NonNull String packageName, int userId) {
+            super.stopUserVisibleJobsForUser_enforcePermission();
+            if (packageName == null) {
+                throw new NullPointerException("packageName");
+            }
+            JobSchedulerService.this.stopUserVisibleJobsInternal(packageName, userId);
+        }
     }
 
     // Shell command infrastructure: run the given job immediately
@@ -3880,13 +4169,131 @@
         }
     }
 
+    int getEstimatedNetworkBytes(PrintWriter pw, String pkgName, int userId, int jobId,
+            int byteOption) {
+        try {
+            final int uid = AppGlobals.getPackageManager().getPackageUid(pkgName, 0,
+                    userId != UserHandle.USER_ALL ? userId : UserHandle.USER_SYSTEM);
+            if (uid < 0) {
+                pw.print("unknown(");
+                pw.print(pkgName);
+                pw.println(")");
+                return JobSchedulerShellCommand.CMD_ERR_NO_PACKAGE;
+            }
+
+            synchronized (mLock) {
+                final JobStatus js = mJobs.getJobByUidAndJobId(uid, jobId);
+                if (DEBUG) {
+                    Slog.d(TAG, "get-estimated-network-bytes " + uid + "/" + jobId + ": " + js);
+                }
+                if (js == null) {
+                    pw.print("unknown("); UserHandle.formatUid(pw, uid);
+                    pw.print("/jid"); pw.print(jobId); pw.println(")");
+                    return JobSchedulerShellCommand.CMD_ERR_NO_JOB;
+                }
+
+                final long downloadBytes;
+                final long uploadBytes;
+                final Pair<Long, Long> bytes =
+                        mConcurrencyManager.getEstimatedNetworkBytesLocked(pkgName, uid, jobId);
+                if (bytes == null) {
+                    downloadBytes = js.getEstimatedNetworkDownloadBytes();
+                    uploadBytes = js.getEstimatedNetworkUploadBytes();
+                } else {
+                    downloadBytes = bytes.first;
+                    uploadBytes = bytes.second;
+                }
+                if (byteOption == JobSchedulerShellCommand.BYTE_OPTION_DOWNLOAD) {
+                    pw.println(downloadBytes);
+                } else {
+                    pw.println(uploadBytes);
+                }
+                pw.println();
+            }
+        } catch (RemoteException e) {
+            // can't happen
+        }
+        return 0;
+    }
+
+    int getTransferredNetworkBytes(PrintWriter pw, String pkgName, int userId, int jobId,
+            int byteOption) {
+        try {
+            final int uid = AppGlobals.getPackageManager().getPackageUid(pkgName, 0,
+                    userId != UserHandle.USER_ALL ? userId : UserHandle.USER_SYSTEM);
+            if (uid < 0) {
+                pw.print("unknown(");
+                pw.print(pkgName);
+                pw.println(")");
+                return JobSchedulerShellCommand.CMD_ERR_NO_PACKAGE;
+            }
+
+            synchronized (mLock) {
+                final JobStatus js = mJobs.getJobByUidAndJobId(uid, jobId);
+                if (DEBUG) {
+                    Slog.d(TAG, "get-transferred-network-bytes " + uid + "/" + jobId + ": " + js);
+                }
+                if (js == null) {
+                    pw.print("unknown("); UserHandle.formatUid(pw, uid);
+                    pw.print("/jid"); pw.print(jobId); pw.println(")");
+                    return JobSchedulerShellCommand.CMD_ERR_NO_JOB;
+                }
+
+                final long downloadBytes;
+                final long uploadBytes;
+                final Pair<Long, Long> bytes =
+                        mConcurrencyManager.getTransferredNetworkBytesLocked(pkgName, uid, jobId);
+                if (bytes == null) {
+                    downloadBytes = 0;
+                    uploadBytes = 0;
+                } else {
+                    downloadBytes = bytes.first;
+                    uploadBytes = bytes.second;
+                }
+                if (byteOption == JobSchedulerShellCommand.BYTE_OPTION_DOWNLOAD) {
+                    pw.println(downloadBytes);
+                } else {
+                    pw.println(uploadBytes);
+                }
+                pw.println();
+            }
+        } catch (RemoteException e) {
+            // can't happen
+        }
+        return 0;
+    }
+
+    private boolean checkRunLongJobsPermission(int packageUid, String packageName) {
+        // Returns true if both the appop and permission are granted.
+        return PermissionChecker.checkPermissionForPreflight(getTestableContext(),
+                android.Manifest.permission.RUN_LONG_JOBS, PermissionChecker.PID_UNKNOWN,
+                packageUid, packageName) == PermissionChecker.PERMISSION_GRANTED;
+    }
+
+    @VisibleForTesting
+    protected ConnectivityController getConnectivityController() {
+        return mConnectivityController;
+    }
+
+    @VisibleForTesting
+    protected QuotaController getQuotaController() {
+        return mQuotaController;
+    }
+
+    @VisibleForTesting
+    protected TareController getTareController() {
+        return mTareController;
+    }
+
     // Shell command infrastructure
     int getJobState(PrintWriter pw, String pkgName, int userId, int jobId) {
         try {
             final int uid = AppGlobals.getPackageManager().getPackageUid(pkgName, 0,
                     userId != UserHandle.USER_ALL ? userId : UserHandle.USER_SYSTEM);
             if (uid < 0) {
-                pw.print("unknown("); pw.print(pkgName); pw.println(")");
+                pw.print("unknown(");
+                pw.print(pkgName);
+                pw.println(")");
                 return JobSchedulerShellCommand.CMD_ERR_NO_PACKAGE;
             }
 
diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerShellCommand.java b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerShellCommand.java
index 27268d2..36ba8dd 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerShellCommand.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerShellCommand.java
@@ -32,6 +32,9 @@
     public static final int CMD_ERR_NO_JOB = -1001;
     public static final int CMD_ERR_CONSTRAINTS = -1002;
 
+    static final int BYTE_OPTION_DOWNLOAD = 0;
+    static final int BYTE_OPTION_UPLOAD = 1;
+
     JobSchedulerService mInternal;
     IPackageManager mPM;
 
@@ -59,10 +62,18 @@
                     return getBatteryCharging(pw);
                 case "get-battery-not-low":
                     return getBatteryNotLow(pw);
+                case "get-estimated-download-bytes":
+                    return getEstimatedNetworkBytes(pw, BYTE_OPTION_DOWNLOAD);
+                case "get-estimated-upload-bytes":
+                    return getEstimatedNetworkBytes(pw, BYTE_OPTION_UPLOAD);
                 case "get-storage-seq":
                     return getStorageSeq(pw);
                 case "get-storage-not-low":
                     return getStorageNotLow(pw);
+                case "get-transferred-download-bytes":
+                    return getTransferredNetworkBytes(pw, BYTE_OPTION_DOWNLOAD);
+                case "get-transferred-upload-bytes":
+                    return getTransferredNetworkBytes(pw, BYTE_OPTION_UPLOAD);
                 case "get-job-state":
                     return getJobState(pw);
                 case "heartbeat":
@@ -304,6 +315,43 @@
         return 0;
     }
 
+    private int getEstimatedNetworkBytes(PrintWriter pw, int byteOption) throws Exception {
+        checkPermission("get estimated bytes");
+
+        int userId = UserHandle.USER_SYSTEM;
+
+        String opt;
+        while ((opt = getNextOption()) != null) {
+            switch (opt) {
+                case "-u":
+                case "--user":
+                    userId = UserHandle.parseUserArg(getNextArgRequired());
+                    break;
+
+                default:
+                    pw.println("Error: unknown option '" + opt + "'");
+                    return -1;
+            }
+        }
+
+        if (userId == UserHandle.USER_CURRENT) {
+            userId = ActivityManager.getCurrentUser();
+        }
+
+        final String pkgName = getNextArgRequired();
+        final String jobIdStr = getNextArgRequired();
+        final int jobId = Integer.parseInt(jobIdStr);
+
+        final long ident = Binder.clearCallingIdentity();
+        try {
+            int ret = mInternal.getEstimatedNetworkBytes(pw, pkgName, userId, jobId, byteOption);
+            printError(ret, pkgName, userId, jobId);
+            return ret;
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
     private int getStorageSeq(PrintWriter pw) {
         int seq = mInternal.getStorageSeq();
         pw.println(seq);
@@ -316,8 +364,45 @@
         return 0;
     }
 
+    private int getTransferredNetworkBytes(PrintWriter pw, int byteOption) throws Exception {
+        checkPermission("get transferred bytes");
+
+        int userId = UserHandle.USER_SYSTEM;
+
+        String opt;
+        while ((opt = getNextOption()) != null) {
+            switch (opt) {
+                case "-u":
+                case "--user":
+                    userId = UserHandle.parseUserArg(getNextArgRequired());
+                    break;
+
+                default:
+                    pw.println("Error: unknown option '" + opt + "'");
+                    return -1;
+            }
+        }
+
+        if (userId == UserHandle.USER_CURRENT) {
+            userId = ActivityManager.getCurrentUser();
+        }
+
+        final String pkgName = getNextArgRequired();
+        final String jobIdStr = getNextArgRequired();
+        final int jobId = Integer.parseInt(jobIdStr);
+
+        final long ident = Binder.clearCallingIdentity();
+        try {
+            int ret = mInternal.getTransferredNetworkBytes(pw, pkgName, userId, jobId, byteOption);
+            printError(ret, pkgName, userId, jobId);
+            return ret;
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
     private int getJobState(PrintWriter pw) throws Exception {
-        checkPermission("force timeout jobs");
+        checkPermission("get job state");
 
         int userId = UserHandle.USER_SYSTEM;
 
@@ -473,10 +558,30 @@
         pw.println("    Return whether the battery is currently considered to be charging.");
         pw.println("  get-battery-not-low");
         pw.println("    Return whether the battery is currently considered to not be low.");
+        pw.println("  get-estimated-download-bytes [-u | --user USER_ID] PACKAGE JOB_ID");
+        pw.println("    Return the most recent estimated download bytes for the job.");
+        pw.println("    Options:");
+        pw.println("      -u or --user: specify which user's job is to be run; the default is");
+        pw.println("         the primary or system user");
+        pw.println("  get-estimated-upload-bytes [-u | --user USER_ID] PACKAGE JOB_ID");
+        pw.println("    Return the most recent estimated upload bytes for the job.");
+        pw.println("    Options:");
+        pw.println("      -u or --user: specify which user's job is to be run; the default is");
+        pw.println("         the primary or system user");
         pw.println("  get-storage-seq");
         pw.println("    Return the last storage update sequence number that was received.");
         pw.println("  get-storage-not-low");
         pw.println("    Return whether storage is currently considered to not be low.");
+        pw.println("  get-transferred-download-bytes [-u | --user USER_ID] PACKAGE JOB_ID");
+        pw.println("    Return the most recent transferred download bytes for the job.");
+        pw.println("    Options:");
+        pw.println("      -u or --user: specify which user's job is to be run; the default is");
+        pw.println("         the primary or system user");
+        pw.println("  get-transferred-upload-bytes [-u | --user USER_ID] PACKAGE JOB_ID");
+        pw.println("    Return the most recent transferred upload bytes for the job.");
+        pw.println("    Options:");
+        pw.println("      -u or --user: specify which user's job is to be run; the default is");
+        pw.println("         the primary or system user");
         pw.println("  get-job-state [-u | --user USER_ID] PACKAGE JOB_ID");
         pw.println("    Return the current state of a job, may be any combination of:");
         pw.println("      pending: currently on the pending list, waiting to be active");
@@ -493,5 +598,4 @@
         pw.println("    Trigger wireless charging dock state.  Active by default.");
         pw.println();
     }
-
 }
diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobServiceContext.java b/apex/jobscheduler/service/java/com/android/server/job/JobServiceContext.java
index b20eedc..0dcfd24 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/JobServiceContext.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/JobServiceContext.java
@@ -17,8 +17,6 @@
 package com.android.server.job;
 
 import static android.app.job.JobInfo.getPriorityString;
-import static android.app.job.JobService.JOB_END_NOTIFICATION_POLICY_DETACH;
-import static android.app.job.JobService.JOB_END_NOTIFICATION_POLICY_REMOVE;
 
 import static com.android.server.job.JobConcurrencyManager.WORK_TYPE_NONE;
 import static com.android.server.job.JobSchedulerService.sElapsedRealtimeClock;
@@ -51,6 +49,7 @@
 import android.os.UserHandle;
 import android.util.EventLog;
 import android.util.IndentingPrintWriter;
+import android.util.Pair;
 import android.util.Slog;
 import android.util.TimeUtils;
 
@@ -61,7 +60,6 @@
 import com.android.server.EventLogTags;
 import com.android.server.LocalServices;
 import com.android.server.job.controllers.JobStatus;
-import com.android.server.notification.NotificationManagerInternal;
 import com.android.server.tare.EconomicPolicy;
 import com.android.server.tare.EconomyManagerInternal;
 import com.android.server.tare.JobSchedulerEconomicPolicy;
@@ -113,6 +111,7 @@
     /** Make callbacks to {@link JobSchedulerService} to inform on job completion status. */
     private final JobCompletedListener mCompletedListener;
     private final JobConcurrencyManager mJobConcurrencyManager;
+    private final JobNotificationCoordinator mNotificationCoordinator;
     private final JobSchedulerService mService;
     /** Used for service binding, etc. */
     private final Context mContext;
@@ -121,7 +120,6 @@
     private final EconomyManagerInternal mEconomyManagerInternal;
     private final JobPackageTracker mJobPackageTracker;
     private final PowerManager mPowerManager;
-    private final NotificationManagerInternal mNotificationManagerInternal;
     private PowerManager.WakeLock mWakeLock;
 
     // Execution state.
@@ -174,10 +172,10 @@
     /** The absolute maximum amount of time the job can run */
     private long mMaxExecutionTimeMillis;
 
-    private int mNotificationId;
-    private Notification mNotification;
-    private int mNotificationPid;
-    private int mNotificationJobStopPolicy;
+    private long mEstimatedDownloadBytes;
+    private long mEstimatedUploadBytes;
+    private long mTransferredDownloadBytes;
+    private long mTransferredUploadBytes;
 
     /**
      * The stop reason for a pending cancel. If there's not pending cancel, then the value should be
@@ -254,16 +252,17 @@
     }
 
     JobServiceContext(JobSchedulerService service, JobConcurrencyManager concurrencyManager,
+            JobNotificationCoordinator notificationCoordinator,
             IBatteryStats batteryStats, JobPackageTracker tracker, Looper looper) {
         mContext = service.getContext();
         mLock = service.getLock();
         mService = service;
         mBatteryStats = batteryStats;
         mEconomyManagerInternal = LocalServices.getService(EconomyManagerInternal.class);
-        mNotificationManagerInternal = LocalServices.getService(NotificationManagerInternal.class);
         mJobPackageTracker = tracker;
         mCallbackHandler = new JobServiceHandler(looper);
         mJobConcurrencyManager = concurrencyManager;
+        mNotificationCoordinator = notificationCoordinator;
         mCompletedListener = service;
         mPowerManager = mContext.getSystemService(PowerManager.class);
         mAvailable = true;
@@ -313,6 +312,9 @@
             mMinExecutionGuaranteeMillis = mService.getMinJobExecutionGuaranteeMs(job);
             mMaxExecutionTimeMillis =
                     Math.max(mService.getMaxJobExecutionTimeMs(job), mMinExecutionGuaranteeMillis);
+            mEstimatedDownloadBytes = job.getEstimatedNetworkDownloadBytes();
+            mEstimatedUploadBytes = job.getEstimatedNetworkUploadBytes();
+            mTransferredDownloadBytes = mTransferredUploadBytes = 0;
 
             final long whenDeferred = job.getWhenStandbyDeferred();
             if (whenDeferred > 0) {
@@ -531,6 +533,16 @@
         return false;
     }
 
+    @GuardedBy("mLock")
+    Pair<Long, Long> getEstimatedNetworkBytes() {
+        return Pair.create(mEstimatedDownloadBytes, mEstimatedUploadBytes);
+    }
+
+    @GuardedBy("mLock")
+    Pair<Long, Long> getTransferredNetworkBytes() {
+        return Pair.create(mTransferredDownloadBytes, mTransferredUploadBytes);
+    }
+
     void doJobFinished(JobCallback cb, int jobId, boolean reschedule) {
         final long ident = Binder.clearCallingIdentity();
         try {
@@ -548,14 +560,26 @@
         }
     }
 
-    private void doAcknowledgeGetTransferredDownloadBytesMessage(JobCallback jobCallback, int jobId,
+    private void doAcknowledgeGetTransferredDownloadBytesMessage(JobCallback cb, int jobId,
             int workId, @BytesLong long transferredBytes) {
         // TODO(255393346): Make sure apps call this appropriately and monitor for abuse
+        synchronized (mLock) {
+            if (!verifyCallerLocked(cb)) {
+                return;
+            }
+            mTransferredDownloadBytes = transferredBytes;
+        }
     }
 
-    private void doAcknowledgeGetTransferredUploadBytesMessage(JobCallback jobCallback, int jobId,
+    private void doAcknowledgeGetTransferredUploadBytesMessage(JobCallback cb, int jobId,
             int workId, @BytesLong long transferredBytes) {
         // TODO(255393346): Make sure apps call this appropriately and monitor for abuse
+        synchronized (mLock) {
+            if (!verifyCallerLocked(cb)) {
+                return;
+            }
+            mTransferredUploadBytes = transferredBytes;
+        }
     }
 
     void doAcknowledgeStopMessage(JobCallback cb, int jobId, boolean reschedule) {
@@ -610,6 +634,30 @@
         }
     }
 
+    private void doUpdateEstimatedNetworkBytes(JobCallback cb, int jobId,
+            @Nullable JobWorkItem item, long downloadBytes, long uploadBytes) {
+        // TODO(255393346): Make sure apps call this appropriately and monitor for abuse
+        synchronized (mLock) {
+            if (!verifyCallerLocked(cb)) {
+                return;
+            }
+            mEstimatedDownloadBytes = downloadBytes;
+            mEstimatedUploadBytes = uploadBytes;
+        }
+    }
+
+    private void doUpdateTransferredNetworkBytes(JobCallback cb, int jobId,
+            @Nullable JobWorkItem item, long downloadBytes, long uploadBytes) {
+        // TODO(255393346): Make sure apps call this appropriately and monitor for abuse
+        synchronized (mLock) {
+            if (!verifyCallerLocked(cb)) {
+                return;
+            }
+            mTransferredDownloadBytes = downloadBytes;
+            mTransferredUploadBytes = uploadBytes;
+        }
+    }
+
     private void doSetNotification(JobCallback cb, int jodId, int notificationId,
             Notification notification, int jobEndNotificationPolicy) {
         final int callingPid = Binder.getCallingPid();
@@ -624,45 +672,16 @@
                     Slog.wtfStack(TAG, "Calling UID isn't the same as running job's UID...");
                     throw new SecurityException("Can't post notification on behalf of another app");
                 }
-                if (notification == null) {
-                    throw new NullPointerException("notification");
-                }
-                if (notification.getSmallIcon() == null) {
-                    throw new IllegalArgumentException("small icon required");
-                }
                 final String callingPkgName = mRunningJob.getServiceComponent().getPackageName();
-                if (null == mNotificationManagerInternal.getNotificationChannel(
-                        callingPkgName, callingUid, notification.getChannelId())) {
-                    throw new IllegalArgumentException("invalid notification channel");
-                }
-                if (jobEndNotificationPolicy != JOB_END_NOTIFICATION_POLICY_DETACH
-                        && jobEndNotificationPolicy != JOB_END_NOTIFICATION_POLICY_REMOVE) {
-                    throw new IllegalArgumentException("invalid job end notification policy");
-                }
-                // TODO(260848384): ensure apps can't cancel the notification for user-initiated job
-                mNotificationManagerInternal.enqueueNotification(
-                        callingPkgName, callingPkgName, callingUid, callingPid, /* tag */ null,
-                        notificationId, notification, UserHandle.getUserId(callingUid));
-                mNotificationId = notificationId;
-                mNotification = notification;
-                mNotificationPid = callingPid;
-                mNotificationJobStopPolicy = jobEndNotificationPolicy;
+                mNotificationCoordinator.enqueueNotification(this, callingPkgName,
+                        callingPid, callingUid, notificationId,
+                        notification, jobEndNotificationPolicy);
             }
         } finally {
             Binder.restoreCallingIdentity(ident);
         }
     }
 
-    private void doUpdateTransferredNetworkBytes(JobCallback jobCallback, int jobId,
-            @Nullable JobWorkItem item, long downloadBytes, long uploadBytes) {
-        // TODO(255393346): Make sure apps call this appropriately and monitor for abuse
-    }
-
-    private void doUpdateEstimatedNetworkBytes(JobCallback jobCallback, int jobId,
-            @Nullable JobWorkItem item, long downloadBytes, long uploadBytes) {
-        // TODO(255393346): Make sure apps call this appropriately and monitor for abuse
-    }
-
     /**
      * We acquire/release a wakelock on onServiceConnected/unbindService. This mirrors the work
      * we intend to send to the client - we stop sending work when the service is unbound so until
@@ -944,6 +963,9 @@
                     return;
                 }
                 scheduleOpTimeOutLocked();
+                if (mRunningJob.isUserVisibleJob()) {
+                    mService.informObserversOfUserVisibleJobChange(this, mRunningJob, true);
+                }
                 break;
             default:
                 Slog.e(TAG, "Handling started job but job wasn't starting! Was "
@@ -1176,13 +1198,7 @@
                     JobSchedulerEconomicPolicy.ACTION_JOB_TIMEOUT,
                     String.valueOf(mRunningJob.getJobId()));
         }
-        if (mNotification != null
-                && mNotificationJobStopPolicy == JOB_END_NOTIFICATION_POLICY_REMOVE) {
-            final String callingPkgName = completedJob.getServiceComponent().getPackageName();
-            mNotificationManagerInternal.cancelNotification(
-                    callingPkgName, callingPkgName, completedJob.getUid(), mNotificationPid,
-                    /* tag */ null, mNotificationId, UserHandle.getUserId(completedJob.getUid()));
-        }
+        mNotificationCoordinator.removeNotificationAssociation(this);
         if (mWakeLock != null) {
             mWakeLock.release();
         }
@@ -1200,8 +1216,10 @@
         mPendingStopReason = JobParameters.STOP_REASON_UNDEFINED;
         mPendingInternalStopReason = 0;
         mPendingDebugStopReason = null;
-        mNotification = null;
         removeOpTimeOutLocked();
+        if (completedJob.isUserVisibleJob()) {
+            mService.informObserversOfUserVisibleJobChange(this, completedJob, false);
+        }
         mCompletedListener.onJobCompletedLocked(completedJob, internalStopReason, reschedule);
         mJobConcurrencyManager.onJobCompletedLocked(this, completedJob, workType);
     }
diff --git a/apex/jobscheduler/service/java/com/android/server/job/controllers/ConnectivityController.java b/apex/jobscheduler/service/java/com/android/server/job/controllers/ConnectivityController.java
index 16dd1672..3610b0a 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/controllers/ConnectivityController.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/controllers/ConnectivityController.java
@@ -42,7 +42,6 @@
 import android.text.format.DateUtils;
 import android.util.ArrayMap;
 import android.util.ArraySet;
-import android.util.DataUnit;
 import android.util.IndentingPrintWriter;
 import android.util.Log;
 import android.util.Pools;
@@ -82,6 +81,8 @@
     private static final boolean DEBUG = JobSchedulerService.DEBUG
             || Log.isLoggable(TAG, Log.DEBUG);
 
+    public static final long UNKNOWN_TIME = -1L;
+
     // The networking stack has a hard limit so we can't make this configurable.
     private static final int MAX_NETWORK_CALLBACKS = 125;
     /**
@@ -148,11 +149,13 @@
             //   2. Waiting connectivity jobs would be ready with connectivity
             //   3. An existing network satisfies a waiting connectivity job's requirements
             //   4. TOP proc state
-            //   5. Existence of treat-as-EJ EJs (not just requested EJs)
-            //   6. FGS proc state
-            //   7. EJ enqueue time
-            //   8. Any other important job priorities/proc states
-            //   9. Enqueue time
+            //   5. Existence of treat-as-UI UIJs (not just requested UIJs)
+            //   6. Existence of treat-as-EJ EJs (not just requested EJs)
+            //   7. FGS proc state
+            //   8. UIJ enqueue time
+            //   9. EJ enqueue time
+            //   10. Any other important job priorities/proc states
+            //   11. Enqueue time
             // TODO: maybe consider number of jobs
             // TODO: consider IMPORTANT_WHILE_FOREGROUND bit
             final int runningPriority = prioritizeExistenceOver(0,
@@ -180,8 +183,13 @@
             if (topPriority != 0) {
                 return topPriority;
             }
-            // They're either both TOP or both not TOP. Prioritize the app that has runnable EJs
+            // They're either both TOP or both not TOP. Prioritize the app that has runnable UIJs
             // pending.
+            final int uijPriority = prioritizeExistenceOver(0, us1.numUIJs, us2.numUIJs);
+            if (uijPriority != 0) {
+                return uijPriority;
+            }
+            // Still equivalent. Prioritize the app that has runnable EJs pending.
             final int ejPriority = prioritizeExistenceOver(0, us1.numEJs, us2.numEJs);
             if (ejPriority != 0) {
                 return ejPriority;
@@ -194,6 +202,12 @@
             if (fgsPriority != 0) {
                 return fgsPriority;
             }
+            // Order them by UIJ enqueue time to help provide low UIJ latency.
+            if (us1.earliestUIJEnqueueTime < us2.earliestUIJEnqueueTime) {
+                return -1;
+            } else if (us1.earliestUIJEnqueueTime > us2.earliestUIJEnqueueTime) {
+                return 1;
+            }
             // Order them by EJ enqueue time to help provide low EJ latency.
             if (us1.earliestEJEnqueueTime < us2.earliestEJEnqueueTime) {
                 return -1;
@@ -413,7 +427,7 @@
         final UidStats uidStats =
                 getUidStats(jobStatus.getSourceUid(), jobStatus.getSourcePackageName(), true);
 
-        if (jobStatus.shouldTreatAsExpeditedJob()) {
+        if (jobStatus.shouldTreatAsExpeditedJob() && jobStatus.shouldTreatAsUserInitiated()) {
             if (!jobStatus.isConstraintSatisfied(JobStatus.CONSTRAINT_CONNECTIVITY)) {
                 // Don't request a direct hole through any of the firewalls. Instead, mark the
                 // constraint as satisfied if the network is available, and the job will get
@@ -570,9 +584,8 @@
             // If we don't know the bandwidth, all we can do is hope the job finishes the minimum
             // chunk in time.
             if (bandwidthDown > 0) {
-                // Divide by 8 to convert bits to bytes.
-                final long estimatedMillis = ((minimumChunkBytes * DateUtils.SECOND_IN_MILLIS)
-                        / (DataUnit.KIBIBYTES.toBytes(bandwidthDown) / 8));
+                final long estimatedMillis =
+                        calculateTransferTimeMs(minimumChunkBytes, bandwidthDown);
                 if (estimatedMillis > maxJobExecutionTimeMs) {
                     // If we'd never finish the minimum chunk before the timeout, we'd be insane!
                     Slog.w(TAG, "Minimum chunk " + minimumChunkBytes + " bytes over "
@@ -585,9 +598,8 @@
             final long bandwidthUp = capabilities.getLinkUpstreamBandwidthKbps();
             // If we don't know the bandwidth, all we can do is hope the job finishes in time.
             if (bandwidthUp > 0) {
-                // Divide by 8 to convert bits to bytes.
-                final long estimatedMillis = ((minimumChunkBytes * DateUtils.SECOND_IN_MILLIS)
-                        / (DataUnit.KIBIBYTES.toBytes(bandwidthUp) / 8));
+                final long estimatedMillis =
+                        calculateTransferTimeMs(minimumChunkBytes, bandwidthUp);
                 if (estimatedMillis > maxJobExecutionTimeMs) {
                     // If we'd never finish the minimum chunk before the timeout, we'd be insane!
                     Slog.w(TAG, "Minimum chunk " + minimumChunkBytes + " bytes over " + bandwidthUp
@@ -615,9 +627,7 @@
             final long bandwidth = capabilities.getLinkDownstreamBandwidthKbps();
             // If we don't know the bandwidth, all we can do is hope the job finishes in time.
             if (bandwidth > 0) {
-                // Divide by 8 to convert bits to bytes.
-                final long estimatedMillis = ((downloadBytes * DateUtils.SECOND_IN_MILLIS)
-                        / (DataUnit.KIBIBYTES.toBytes(bandwidth) / 8));
+                final long estimatedMillis = calculateTransferTimeMs(downloadBytes, bandwidth);
                 if (estimatedMillis > maxJobExecutionTimeMs) {
                     // If we'd never finish before the timeout, we'd be insane!
                     Slog.w(TAG, "Estimated " + downloadBytes + " download bytes over " + bandwidth
@@ -633,9 +643,7 @@
             final long bandwidth = capabilities.getLinkUpstreamBandwidthKbps();
             // If we don't know the bandwidth, all we can do is hope the job finishes in time.
             if (bandwidth > 0) {
-                // Divide by 8 to convert bits to bytes.
-                final long estimatedMillis = ((uploadBytes * DateUtils.SECOND_IN_MILLIS)
-                        / (DataUnit.KIBIBYTES.toBytes(bandwidth) / 8));
+                final long estimatedMillis = calculateTransferTimeMs(uploadBytes, bandwidth);
                 if (estimatedMillis > maxJobExecutionTimeMs) {
                     // If we'd never finish before the timeout, we'd be insane!
                     Slog.w(TAG, "Estimated " + uploadBytes + " upload bytes over " + bandwidth
@@ -649,6 +657,48 @@
         return false;
     }
 
+    /**
+     * Return the estimated amount of time this job will be transferring data,
+     * based on the current network speed.
+     */
+    public long getEstimatedTransferTimeMs(JobStatus jobStatus) {
+        final long downloadBytes = jobStatus.getEstimatedNetworkDownloadBytes();
+        final long uploadBytes = jobStatus.getEstimatedNetworkUploadBytes();
+        if (downloadBytes == JobInfo.NETWORK_BYTES_UNKNOWN
+                && uploadBytes == JobInfo.NETWORK_BYTES_UNKNOWN) {
+            return UNKNOWN_TIME;
+        }
+        if (jobStatus.network == null) {
+            // This job doesn't have a network assigned.
+            return UNKNOWN_TIME;
+        }
+        NetworkCapabilities capabilities = getNetworkCapabilities(jobStatus.network);
+        if (capabilities == null) {
+            return UNKNOWN_TIME;
+        }
+        final long estimatedDownloadTimeMs = calculateTransferTimeMs(downloadBytes,
+                capabilities.getLinkDownstreamBandwidthKbps());
+        final long estimatedUploadTimeMs = calculateTransferTimeMs(uploadBytes,
+                capabilities.getLinkUpstreamBandwidthKbps());
+        if (estimatedDownloadTimeMs == UNKNOWN_TIME) {
+            return estimatedUploadTimeMs;
+        } else if (estimatedUploadTimeMs == UNKNOWN_TIME) {
+            return estimatedDownloadTimeMs;
+        }
+        return estimatedDownloadTimeMs + estimatedUploadTimeMs;
+    }
+
+    @VisibleForTesting
+    static long calculateTransferTimeMs(long transferBytes, long bandwidthKbps) {
+        if (transferBytes == JobInfo.NETWORK_BYTES_UNKNOWN || bandwidthKbps <= 0) {
+            return UNKNOWN_TIME;
+        }
+        return (transferBytes * DateUtils.SECOND_IN_MILLIS)
+                // Multiply by 1000 to convert kilobits to bits.
+                // Divide by 8 to convert bits to bytes.
+                / (bandwidthKbps * 1000 / 8);
+    }
+
     private static boolean isCongestionDelayed(JobStatus jobStatus, Network network,
             NetworkCapabilities capabilities, Constants constants) {
         // If network is congested, and job is less than 50% through the
@@ -899,10 +949,12 @@
             if (us.lastUpdatedElapsed + MIN_STATS_UPDATE_INTERVAL_MS < nowElapsed) {
                 us.earliestEnqueueTime = Long.MAX_VALUE;
                 us.earliestEJEnqueueTime = Long.MAX_VALUE;
+                us.earliestUIJEnqueueTime = Long.MAX_VALUE;
                 us.numReadyWithConnectivity = 0;
                 us.numRequestedNetworkAvailable = 0;
                 us.numRegular = 0;
                 us.numEJs = 0;
+                us.numUIJs = 0;
 
                 for (int j = 0; j < jobs.size(); ++j) {
                     JobStatus job = jobs.valueAt(j);
@@ -919,10 +971,15 @@
                         if (job.shouldTreatAsExpeditedJob() || job.startedAsExpeditedJob) {
                             us.earliestEJEnqueueTime =
                                     Math.min(us.earliestEJEnqueueTime, job.enqueueTime);
+                        } else if (job.shouldTreatAsUserInitiated()) {
+                            us.earliestUIJEnqueueTime =
+                                    Math.min(us.earliestUIJEnqueueTime, job.enqueueTime);
                         }
                     }
                     if (job.shouldTreatAsExpeditedJob() || job.startedAsExpeditedJob) {
                         us.numEJs++;
+                    } else if (job.shouldTreatAsUserInitiated()) {
+                        us.numUIJs++;
                     } else {
                         us.numRegular++;
                     }
@@ -1429,8 +1486,10 @@
         public int numRequestedNetworkAvailable;
         public int numEJs;
         public int numRegular;
+        public int numUIJs;
         public long earliestEnqueueTime;
         public long earliestEJEnqueueTime;
+        public long earliestUIJEnqueueTime;
         public long lastUpdatedElapsed;
 
         private UidStats(int uid) {
@@ -1448,6 +1507,7 @@
             pw.print("#reg", numRegular);
             pw.print("earliestEnqueue", earliestEnqueueTime);
             pw.print("earliestEJEnqueue", earliestEJEnqueueTime);
+            pw.print("earliestUIJEnqueue", earliestUIJEnqueueTime);
             pw.print("updated=");
             TimeUtils.formatDuration(lastUpdatedElapsed - nowElapsed, pw);
             pw.println("}");
diff --git a/apex/jobscheduler/service/java/com/android/server/job/controllers/JobStatus.java b/apex/jobscheduler/service/java/com/android/server/job/controllers/JobStatus.java
index af8e727..251a4da 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/controllers/JobStatus.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/controllers/JobStatus.java
@@ -29,11 +29,13 @@
 import static com.android.server.job.controllers.FlexibilityController.SYSTEM_WIDE_FLEXIBLE_CONSTRAINTS;
 
 import android.annotation.ElapsedRealtimeLong;
+import android.annotation.NonNull;
 import android.app.AppGlobals;
 import android.app.job.JobInfo;
 import android.app.job.JobParameters;
 import android.app.job.JobScheduler;
 import android.app.job.JobWorkItem;
+import android.app.job.UserVisibleJobSummary;
 import android.content.ClipData;
 import android.content.ComponentName;
 import android.net.Network;
@@ -386,6 +388,8 @@
      */
     public boolean startedAsExpeditedJob = false;
 
+    public boolean startedWithImmediacyPrivilege = false;
+
     // If non-null, this is work that has been enqueued for the job.
     public ArrayList<JobWorkItem> pendingWork;
 
@@ -454,6 +458,12 @@
      */
     private boolean mExpeditedTareApproved;
 
+    /**
+     * Summary describing this job. Lazily created in {@link #getUserVisibleJobSummary()}
+     * since not every job will need it.
+     */
+    private UserVisibleJobSummary mUserVisibleJobSummary;
+
     /////// Booleans that track if a job is ready to run. They should be updated whenever dependent
     /////// states change.
 
@@ -1337,6 +1347,34 @@
     }
 
     /**
+     * @return true if the job was scheduled as a user-initiated job and it hasn't been downgraded
+     * for any reason.
+     */
+    public boolean shouldTreatAsUserInitiated() {
+        // TODO(248386641): implement
+        return false;
+    }
+
+    /**
+     * Return a summary that uniquely identifies the underlying job.
+     */
+    @NonNull
+    public UserVisibleJobSummary getUserVisibleJobSummary() {
+        if (mUserVisibleJobSummary == null) {
+            mUserVisibleJobSummary = new UserVisibleJobSummary(
+                    callingUid, getSourceUserId(), getSourcePackageName(), getJobId());
+        }
+        return mUserVisibleJobSummary;
+    }
+
+    /**
+     * @return true if this is a job whose execution should be made visible to the user.
+     */
+    public boolean isUserVisibleJob() {
+        return shouldTreatAsUserInitiated();
+    }
+
+    /**
      * @return true if the job is exempted from Doze restrictions and therefore allowed to run
      * in Doze.
      */
@@ -1344,12 +1382,14 @@
         return appHasDozeExemption
                 || (getFlags() & JobInfo.FLAG_WILL_BE_FOREGROUND) != 0
                 || ((shouldTreatAsExpeditedJob() || startedAsExpeditedJob)
+                || shouldTreatAsUserInitiated()
                 && (mDynamicConstraints & CONSTRAINT_DEVICE_NOT_DOZING) == 0);
     }
 
     boolean canRunInBatterySaver() {
         return (getInternalFlags() & INTERNAL_FLAG_HAS_FOREGROUND_EXEMPTION) != 0
                 || ((shouldTreatAsExpeditedJob() || startedAsExpeditedJob)
+                || shouldTreatAsUserInitiated()
                 && (mDynamicConstraints & CONSTRAINT_BACKGROUND_NOT_RESTRICTED) == 0);
     }
 
diff --git a/apex/jobscheduler/service/java/com/android/server/job/controllers/QuotaController.java b/apex/jobscheduler/service/java/com/android/server/job/controllers/QuotaController.java
index d8206ad..404186d 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/controllers/QuotaController.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/controllers/QuotaController.java
@@ -641,6 +641,9 @@
             mTopStartedJobs.add(jobStatus);
             // Top jobs won't count towards quota so there's no need to involve the Timer.
             return;
+        } else if (jobStatus.shouldTreatAsUserInitiated()) {
+            // User-initiated jobs won't count towards quota.
+            return;
         }
 
         final int userId = jobStatus.getSourceUserId();
@@ -892,7 +895,8 @@
         //   1. it was started while the app was in the TOP state
         //   2. the app is currently in the foreground
         //   3. the app overall is within its quota
-        return isTopStartedJobLocked(jobStatus)
+        return jobStatus.shouldTreatAsUserInitiated()
+                || isTopStartedJobLocked(jobStatus)
                 || isUidInForeground(jobStatus.getSourceUid())
                 || isWithinQuotaLocked(
                 jobStatus.getSourceUserId(), jobStatus.getSourcePackageName(), standbyBucket);
@@ -2116,6 +2120,13 @@
         }
 
         void startTrackingJobLocked(@NonNull JobStatus jobStatus) {
+            if (jobStatus.shouldTreatAsUserInitiated()) {
+                if (DEBUG) {
+                    Slog.v(TAG, "Timer ignoring " + jobStatus.toShortString()
+                            + " because it's user-initiated");
+                }
+                return;
+            }
             if (isTopStartedJobLocked(jobStatus)) {
                 // We intentionally don't pay attention to fg state changes after a TOP job has
                 // started.
diff --git a/apex/jobscheduler/service/java/com/android/server/job/controllers/TareController.java b/apex/jobscheduler/service/java/com/android/server/job/controllers/TareController.java
index cafb02d..de065b2 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/controllers/TareController.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/controllers/TareController.java
@@ -313,6 +313,11 @@
     @GuardedBy("mLock")
     public void maybeStartTrackingJobLocked(JobStatus jobStatus, JobStatus lastJob) {
         final long nowElapsed = sElapsedRealtimeClock.millis();
+        if (jobStatus.shouldTreatAsUserInitiated()) {
+            // User-initiated jobs should always be allowed to run.
+            jobStatus.setTareWealthConstraintSatisfied(nowElapsed, true);
+            return;
+        }
         jobStatus.setTareWealthConstraintSatisfied(nowElapsed, hasEnoughWealthLocked(jobStatus));
         setExpeditedTareApproved(jobStatus, nowElapsed,
                 jobStatus.isRequestedExpeditedJob() && canAffordExpeditedBillLocked(jobStatus));
@@ -326,6 +331,11 @@
     @Override
     @GuardedBy("mLock")
     public void prepareForExecutionLocked(JobStatus jobStatus) {
+        if (jobStatus.shouldTreatAsUserInitiated()) {
+            // TODO(202954395): consider noting execution with the EconomyManager even though it
+            //                  won't affect this job
+            return;
+        }
         final int userId = jobStatus.getSourceUserId();
         final String pkgName = jobStatus.getSourcePackageName();
         ArrayMap<ActionBill, ArraySet<JobStatus>> billToJobMap =
@@ -355,6 +365,9 @@
     @Override
     @GuardedBy("mLock")
     public void unprepareFromExecutionLocked(JobStatus jobStatus) {
+        if (jobStatus.shouldTreatAsUserInitiated()) {
+            return;
+        }
         final int userId = jobStatus.getSourceUserId();
         final String pkgName = jobStatus.getSourcePackageName();
         // If this method is called, then jobStatus.madeActive was never updated, so don't use it
@@ -384,6 +397,9 @@
     @Override
     @GuardedBy("mLock")
     public void maybeStopTrackingJobLocked(JobStatus jobStatus, JobStatus incomingJob) {
+        if (jobStatus.shouldTreatAsUserInitiated()) {
+            return;
+        }
         final int userId = jobStatus.getSourceUserId();
         final String pkgName = jobStatus.getSourcePackageName();
         if (!mTopStartedJobs.remove(jobStatus) && jobStatus.madeActive > 0) {
@@ -637,6 +653,10 @@
         if (!mIsEnabled) {
             return true;
         }
+        if (jobStatus.shouldTreatAsUserInitiated()) {
+            // Always allow user-initiated jobs.
+            return true;
+        }
         if (mService.getUidBias(jobStatus.getSourceUid()) == JobInfo.BIAS_TOP_APP
                 || isTopStartedJobLocked(jobStatus)) {
             // Jobs for the top app should always be allowed to run, and any jobs started while
diff --git a/apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java b/apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java
index 830031e..85b762d 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java
@@ -91,12 +91,23 @@
         }
         final int priority = job.getEffectivePriority();
         if (mThermalStatus >= HIGHER_PRIORITY_THRESHOLD) {
-            // For moderate throttling, only let expedited jobs and high priority regular jobs that
-            // haven't been running for a long time run.
-            return !job.shouldTreatAsExpeditedJob()
-                    && !(priority == JobInfo.PRIORITY_HIGH
-                        && mService.isCurrentlyRunningLocked(job)
-                        && !mService.isJobInOvertimeLocked(job));
+            // For moderate throttling:
+            // Only let expedited & user-initiated jobs run if:
+            // 1. They haven't previously run
+            // 2. They're already running and aren't yet in overtime
+            // Only let high priority jobs run if:
+            //   They are already running and aren't yet in overtime
+            // Don't let any other job run.
+            if (job.shouldTreatAsExpeditedJob() || job.shouldTreatAsUserInitiated()) {
+                return job.getNumPreviousAttempts() > 0
+                        || (mService.isCurrentlyRunningLocked(job)
+                                && mService.isJobInOvertimeLocked(job));
+            }
+            if (priority == JobInfo.PRIORITY_HIGH) {
+                return !mService.isCurrentlyRunningLocked(job)
+                        || mService.isJobInOvertimeLocked(job);
+            }
+            return true;
         }
         if (mThermalStatus >= LOW_PRIORITY_THRESHOLD) {
             // For light throttling, throttle all min priority jobs and all low priority jobs that
diff --git a/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java b/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java
index b1c8b51..6869936 100644
--- a/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java
+++ b/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java
@@ -111,6 +111,7 @@
 import android.util.SparseBooleanArray;
 import android.util.SparseIntArray;
 import android.util.SparseLongArray;
+import android.util.SparseSetArray;
 import android.util.TimeUtils;
 import android.view.Display;
 import android.widget.Toast;
@@ -463,6 +464,12 @@
     private final Map<String, String> mAppStandbyProperties = new ArrayMap<>();
 
     /**
+     * Set of apps that were restored via backup & restore, per user, that need their
+     * standby buckets to be adjusted when installed.
+     */
+    private final SparseSetArray<String> mAppsToRestoreToRare = new SparseSetArray<>();
+
+    /**
      * List of app-ids of system packages, populated on boot, when system services are ready.
      */
     private final ArrayList<Integer> mSystemPackagesAppIds = new ArrayList<>();
@@ -1663,18 +1670,29 @@
         final int reason = REASON_MAIN_DEFAULT | REASON_SUB_DEFAULT_APP_RESTORED;
         final long nowElapsed = mInjector.elapsedRealtime();
         for (String packageName : restoredApps) {
-            // If the package is not installed, don't allow the bucket to be set.
+            // If the package is not installed, don't allow the bucket to be set. Instead, add it
+            // to a list of all packages whose buckets need to be adjusted when installed.
             if (!mInjector.isPackageInstalled(packageName, 0, userId)) {
-                Slog.e(TAG, "Tried to restore bucket for uninstalled app: " + packageName);
+                Slog.i(TAG, "Tried to restore bucket for uninstalled app: " + packageName);
+                mAppsToRestoreToRare.add(userId, packageName);
                 continue;
             }
 
-            final int standbyBucket = getAppStandbyBucket(packageName, userId, nowElapsed, false);
-            // Only update the standby bucket to RARE if the app is still in the NEVER bucket.
-            if (standbyBucket == STANDBY_BUCKET_NEVER) {
-                setAppStandbyBucket(packageName, userId, STANDBY_BUCKET_RARE, reason,
-                        nowElapsed, false);
-            }
+            restoreAppToRare(packageName, userId, nowElapsed, reason);
+        }
+        // Clear out the list of restored apps that need to have their standby buckets adjusted
+        // if they still haven't been installed eight hours after restore.
+        // Note: if the device reboots within these first 8 hours, this list will be lost since it's
+        // not persisted - this is the expected behavior for now and may be updated in the future.
+        mHandler.postDelayed(() -> mAppsToRestoreToRare.remove(userId), 8 * ONE_HOUR);
+    }
+
+    /** Adjust the standby bucket of the given package for the user to RARE. */
+    private void restoreAppToRare(String pkgName, int userId, long nowElapsed, int reason) {
+        final int standbyBucket = getAppStandbyBucket(pkgName, userId, nowElapsed, false);
+        // Only update the standby bucket to RARE if the app is still in the NEVER bucket.
+        if (standbyBucket == STANDBY_BUCKET_NEVER) {
+            setAppStandbyBucket(pkgName, userId, STANDBY_BUCKET_RARE, reason, nowElapsed, false);
         }
     }
 
@@ -2169,15 +2187,24 @@
                 }
                 // component-level enable/disable can affect bucketing, so we always
                 // reevaluate that for any PACKAGE_CHANGED
-                mHandler.obtainMessage(MSG_CHECK_PACKAGE_IDLE_STATE, userId, -1, pkgName)
-                    .sendToTarget();
+                if (Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
+                    mHandler.obtainMessage(MSG_CHECK_PACKAGE_IDLE_STATE, userId, -1, pkgName)
+                            .sendToTarget();
+                }
             }
             if ((Intent.ACTION_PACKAGE_REMOVED.equals(action) ||
                     Intent.ACTION_PACKAGE_ADDED.equals(action))) {
                 if (intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
                     maybeUnrestrictBuggyApp(pkgName, userId);
-                } else {
+                } else if (!Intent.ACTION_PACKAGE_ADDED.equals(action)) {
                     clearAppIdleForPackage(pkgName, userId);
+                } else {
+                    // Package was just added and it's not being replaced.
+                    if (mAppsToRestoreToRare.contains(userId, pkgName)) {
+                        restoreAppToRare(pkgName, userId, mInjector.elapsedRealtime(),
+                                REASON_MAIN_DEFAULT | REASON_SUB_DEFAULT_APP_RESTORED);
+                        mAppsToRestoreToRare.remove(userId, pkgName);
+                    }
                 }
             }
             synchronized (mSystemExemptionAppOpMode) {
diff --git a/api/Android.bp b/api/Android.bp
index b0ce9af..318748e 100644
--- a/api/Android.bp
+++ b/api/Android.bp
@@ -118,9 +118,11 @@
     ],
     system_server_classpath: [
         "service-art",
+        "service-configinfrastructure",
         "service-healthconnect",
         "service-media-s",
         "service-permission",
+        "service-rkp",
         "service-sdksandbox",
     ],
 }
diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp
index c4d90c6..80512f7 100644
--- a/cmds/bootanimation/BootAnimation.cpp
+++ b/cmds/bootanimation/BootAnimation.cpp
@@ -1112,6 +1112,11 @@
 
         int nextReadPos;
 
+        if (strlen(l) == 0) {
+            s = ++endl;
+            continue;
+        }
+
         int topLineNumbers = sscanf(l, "%d %d %d %d", &width, &height, &fps, &progress);
         if (topLineNumbers == 3 || topLineNumbers == 4) {
             // SLOGD("> w=%d, h=%d, fps=%d, progress=%d", width, height, fps, progress);
diff --git a/core/api/current.txt b/core/api/current.txt
index 434b60d..877e2d6 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -176,6 +176,8 @@
     field public static final String REQUEST_COMPANION_PROFILE_APP_STREAMING = "android.permission.REQUEST_COMPANION_PROFILE_APP_STREAMING";
     field public static final String REQUEST_COMPANION_PROFILE_AUTOMOTIVE_PROJECTION = "android.permission.REQUEST_COMPANION_PROFILE_AUTOMOTIVE_PROJECTION";
     field public static final String REQUEST_COMPANION_PROFILE_COMPUTER = "android.permission.REQUEST_COMPANION_PROFILE_COMPUTER";
+    field public static final String REQUEST_COMPANION_PROFILE_GLASSES = "android.permission.REQUEST_COMPANION_PROFILE_GLASSES";
+    field public static final String REQUEST_COMPANION_PROFILE_NEARBY_DEVICE_STREAMING = "android.permission.REQUEST_COMPANION_PROFILE_NEARBY_DEVICE_STREAMING";
     field public static final String REQUEST_COMPANION_PROFILE_WATCH = "android.permission.REQUEST_COMPANION_PROFILE_WATCH";
     field public static final String REQUEST_COMPANION_RUN_IN_BACKGROUND = "android.permission.REQUEST_COMPANION_RUN_IN_BACKGROUND";
     field public static final String REQUEST_COMPANION_SELF_MANAGED = "android.permission.REQUEST_COMPANION_SELF_MANAGED";
@@ -1042,7 +1044,6 @@
     field public static final int max = 16843062; // 0x1010136
     field public static final int maxAspectRatio = 16844128; // 0x1010560
     field public static final int maxButtonHeight = 16844029; // 0x10104fd
-    field public static final int maxConcurrentSessionsCount;
     field public static final int maxDate = 16843584; // 0x1010340
     field public static final int maxEms = 16843095; // 0x1010157
     field public static final int maxHeight = 16843040; // 0x1010120
@@ -4149,6 +4150,8 @@
     method @Deprecated public android.app.FragmentManager getFragmentManager();
     method public android.content.Intent getIntent();
     method @Nullable public Object getLastNonConfigurationInstance();
+    method @Nullable public String getLaunchedFromPackage();
+    method public int getLaunchedFromUid();
     method @NonNull public android.view.LayoutInflater getLayoutInflater();
     method @Deprecated public android.app.LoaderManager getLoaderManager();
     method @NonNull public String getLocalClassName();
@@ -4291,6 +4294,7 @@
     method @Deprecated public final void removeDialog(int);
     method public void reportFullyDrawn();
     method public android.view.DragAndDropPermissions requestDragAndDropPermissions(android.view.DragEvent);
+    method public void requestFullscreenMode(@NonNull int, @Nullable android.os.OutcomeReceiver<java.lang.Void,java.lang.Throwable>);
     method public final void requestPermissions(@NonNull String[], int);
     method public final void requestShowKeyboardShortcuts();
     method @Deprecated public boolean requestVisibleBehind(boolean);
@@ -4377,6 +4381,8 @@
     field public static final int DEFAULT_KEYS_SEARCH_LOCAL = 3; // 0x3
     field public static final int DEFAULT_KEYS_SHORTCUT = 2; // 0x2
     field protected static final int[] FOCUSED_STATE_SET;
+    field public static final int FULLSCREEN_MODE_REQUEST_ENTER = 1; // 0x1
+    field public static final int FULLSCREEN_MODE_REQUEST_EXIT = 0; // 0x0
     field public static final int RESULT_CANCELED = 0; // 0x0
     field public static final int RESULT_FIRST_USER = 1; // 0x1
     field public static final int RESULT_OK = -1; // 0xffffffff
@@ -4618,6 +4624,7 @@
     method public android.app.ActivityOptions setLaunchDisplayId(int);
     method public android.app.ActivityOptions setLockTaskEnabled(boolean);
     method public void setPendingIntentBackgroundActivityLaunchAllowed(boolean);
+    method @NonNull public android.app.ActivityOptions setShareIdentityEnabled(boolean);
     method @NonNull public android.app.ActivityOptions setSplashScreenStyle(int);
     method public android.os.Bundle toBundle();
     method public void update(android.app.ActivityOptions);
@@ -7283,8 +7290,10 @@
     method public android.content.Intent getCropAndSetWallpaperIntent(android.net.Uri);
     method public int getDesiredMinimumHeight();
     method public int getDesiredMinimumWidth();
-    method @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) public android.graphics.drawable.Drawable getDrawable();
-    method @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) public android.graphics.drawable.Drawable getFastDrawable();
+    method @Nullable @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) public android.graphics.drawable.Drawable getDrawable();
+    method @Nullable @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) public android.graphics.drawable.Drawable getDrawable(int);
+    method @Nullable @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) public android.graphics.drawable.Drawable getFastDrawable();
+    method @Nullable @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) public android.graphics.drawable.Drawable getFastDrawable(int);
     method public static android.app.WallpaperManager getInstance(android.content.Context);
     method @Nullable public android.app.WallpaperColors getWallpaperColors(int);
     method @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) public android.os.ParcelFileDescriptor getWallpaperFile(int);
@@ -7294,8 +7303,10 @@
     method public boolean hasResourceWallpaper(@RawRes int);
     method public boolean isSetWallpaperAllowed();
     method public boolean isWallpaperSupported();
-    method public android.graphics.drawable.Drawable peekDrawable();
-    method @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) public android.graphics.drawable.Drawable peekFastDrawable();
+    method @Nullable public android.graphics.drawable.Drawable peekDrawable();
+    method @Nullable public android.graphics.drawable.Drawable peekDrawable(int);
+    method @Nullable @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) public android.graphics.drawable.Drawable peekFastDrawable();
+    method @Nullable @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) public android.graphics.drawable.Drawable peekFastDrawable(int);
     method public void removeOnColorsChangedListener(@NonNull android.app.WallpaperManager.OnColorsChangedListener);
     method public void sendWallpaperCommand(android.os.IBinder, String, int, int, int, android.os.Bundle);
     method @RequiresPermission(android.Manifest.permission.SET_WALLPAPER) public void setBitmap(android.graphics.Bitmap) throws java.io.IOException;
@@ -7475,7 +7486,7 @@
     method public boolean getBluetoothContactSharingDisabled(@NonNull android.content.ComponentName);
     method public boolean getCameraDisabled(@Nullable android.content.ComponentName);
     method @Deprecated @Nullable public String getCertInstallerPackage(@NonNull android.content.ComponentName) throws java.lang.SecurityException;
-    method @Nullable public java.util.Set<java.lang.String> getCrossProfileCalendarPackages(@NonNull android.content.ComponentName);
+    method @Deprecated @Nullable public java.util.Set<java.lang.String> getCrossProfileCalendarPackages(@NonNull android.content.ComponentName);
     method public boolean getCrossProfileCallerIdDisabled(@NonNull android.content.ComponentName);
     method public boolean getCrossProfileContactsSearchDisabled(@NonNull android.content.ComponentName);
     method @NonNull public java.util.Set<java.lang.String> getCrossProfilePackages(@NonNull android.content.ComponentName);
@@ -7624,7 +7635,7 @@
     method @Deprecated public void setCertInstallerPackage(@NonNull android.content.ComponentName, @Nullable String) throws java.lang.SecurityException;
     method public void setCommonCriteriaModeEnabled(@NonNull android.content.ComponentName, boolean);
     method public void setConfiguredNetworksLockdownState(@NonNull android.content.ComponentName, boolean);
-    method public void setCrossProfileCalendarPackages(@NonNull android.content.ComponentName, @Nullable java.util.Set<java.lang.String>);
+    method @Deprecated public void setCrossProfileCalendarPackages(@NonNull android.content.ComponentName, @Nullable java.util.Set<java.lang.String>);
     method public void setCrossProfileCallerIdDisabled(@NonNull android.content.ComponentName, boolean);
     method public void setCrossProfileContactsSearchDisabled(@NonNull android.content.ComponentName, boolean);
     method public void setCrossProfilePackages(@NonNull android.content.ComponentName, @NonNull java.util.Set<java.lang.String>);
@@ -8014,6 +8025,9 @@
     field public static final int TAG_MEDIA_UNMOUNT = 210014; // 0x3345e
     field public static final int TAG_OS_SHUTDOWN = 210010; // 0x3345a
     field public static final int TAG_OS_STARTUP = 210009; // 0x33459
+    field public static final int TAG_PACKAGE_INSTALLED = 210041; // 0x33479
+    field public static final int TAG_PACKAGE_UNINSTALLED = 210043; // 0x3347b
+    field public static final int TAG_PACKAGE_UPDATED = 210042; // 0x3347a
     field public static final int TAG_PASSWORD_CHANGED = 210036; // 0x33474
     field public static final int TAG_PASSWORD_COMPLEXITY_REQUIRED = 210035; // 0x33473
     field public static final int TAG_PASSWORD_COMPLEXITY_SET = 210017; // 0x33461
@@ -9052,6 +9066,8 @@
     field @RequiresPermission(android.Manifest.permission.REQUEST_COMPANION_PROFILE_APP_STREAMING) public static final String DEVICE_PROFILE_APP_STREAMING = "android.app.role.COMPANION_DEVICE_APP_STREAMING";
     field @RequiresPermission(android.Manifest.permission.REQUEST_COMPANION_PROFILE_AUTOMOTIVE_PROJECTION) public static final String DEVICE_PROFILE_AUTOMOTIVE_PROJECTION = "android.app.role.SYSTEM_AUTOMOTIVE_PROJECTION";
     field @RequiresPermission(android.Manifest.permission.REQUEST_COMPANION_PROFILE_COMPUTER) public static final String DEVICE_PROFILE_COMPUTER = "android.app.role.COMPANION_DEVICE_COMPUTER";
+    field @RequiresPermission(android.Manifest.permission.REQUEST_COMPANION_PROFILE_GLASSES) public static final String DEVICE_PROFILE_GLASSES = "android.app.role.COMPANION_DEVICE_GLASSES";
+    field @RequiresPermission(android.Manifest.permission.REQUEST_COMPANION_PROFILE_NEARBY_DEVICE_STREAMING) public static final String DEVICE_PROFILE_NEARBY_DEVICE_STREAMING = "android.app.role.COMPANION_DEVICE_NEARBY_DEVICE_STREAMING";
     field public static final String DEVICE_PROFILE_WATCH = "android.app.role.COMPANION_DEVICE_WATCH";
   }
 
@@ -9171,8 +9187,8 @@
 
   public final class VirtualDeviceManager {
     method @NonNull public java.util.List<android.companion.virtual.VirtualDevice> getVirtualDevices();
-    field public static final int DEFAULT_DEVICE_ID = 0; // 0x0
-    field public static final int INVALID_DEVICE_ID = -1; // 0xffffffff
+    field public static final int DEVICE_ID_DEFAULT = 0; // 0x0
+    field public static final int DEVICE_ID_INVALID = -1; // 0xffffffff
   }
 
 }
@@ -10579,6 +10595,7 @@
     field public static final String EXTRA_MIME_TYPES = "android.intent.extra.MIME_TYPES";
     field public static final String EXTRA_NOT_UNKNOWN_SOURCE = "android.intent.extra.NOT_UNKNOWN_SOURCE";
     field public static final String EXTRA_ORIGINATING_URI = "android.intent.extra.ORIGINATING_URI";
+    field public static final String EXTRA_PACKAGES = "android.intent.extra.PACKAGES";
     field public static final String EXTRA_PACKAGE_NAME = "android.intent.extra.PACKAGE_NAME";
     field public static final String EXTRA_PERMISSION_GROUP_NAME = "android.intent.extra.PERMISSION_GROUP_NAME";
     field public static final String EXTRA_PHONE_NUMBER = "android.intent.extra.PHONE_NUMBER";
@@ -11708,9 +11725,12 @@
     method public void unregisterSessionCallback(@NonNull android.content.pm.PackageInstaller.SessionCallback);
     method public void updateSessionAppIcon(int, @Nullable android.graphics.Bitmap);
     method public void updateSessionAppLabel(int, @Nullable CharSequence);
+    method public void waitForInstallConstraints(@NonNull java.util.List<java.lang.String>, @NonNull android.content.pm.PackageInstaller.InstallConstraints, @NonNull android.content.IntentSender, long);
     field public static final String ACTION_SESSION_COMMITTED = "android.content.pm.action.SESSION_COMMITTED";
     field public static final String ACTION_SESSION_DETAILS = "android.content.pm.action.SESSION_DETAILS";
     field public static final String ACTION_SESSION_UPDATED = "android.content.pm.action.SESSION_UPDATED";
+    field public static final String EXTRA_INSTALL_CONSTRAINTS = "android.content.pm.extra.INSTALL_CONSTRAINTS";
+    field public static final String EXTRA_INSTALL_CONSTRAINTS_RESULT = "android.content.pm.extra.INSTALL_CONSTRAINTS_RESULT";
     field public static final String EXTRA_OTHER_PACKAGE_NAME = "android.content.pm.extra.OTHER_PACKAGE_NAME";
     field public static final String EXTRA_PACKAGE_NAME = "android.content.pm.extra.PACKAGE_NAME";
     field public static final String EXTRA_PRE_APPROVAL = "android.content.pm.extra.PRE_APPROVAL";
@@ -12493,7 +12513,7 @@
     field @RequiresPermission(allOf={android.Manifest.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE}, anyOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.CHANGE_NETWORK_STATE, android.Manifest.permission.CHANGE_WIFI_STATE, android.Manifest.permission.CHANGE_WIFI_MULTICAST_STATE, android.Manifest.permission.NFC, android.Manifest.permission.TRANSMIT_IR}, conditional=true) public static final int FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE = 16; // 0x10
     field @Deprecated @RequiresPermission(value=android.Manifest.permission.FOREGROUND_SERVICE_DATA_SYNC, conditional=true) public static final int FOREGROUND_SERVICE_TYPE_DATA_SYNC = 1; // 0x1
     field @RequiresPermission(android.Manifest.permission.FOREGROUND_SERVICE_FILE_MANAGEMENT) public static final int FOREGROUND_SERVICE_TYPE_FILE_MANAGEMENT = 4096; // 0x1000
-    field @RequiresPermission(allOf={android.Manifest.permission.FOREGROUND_SERVICE_HEALTH}, anyOf={android.Manifest.permission.ACTIVITY_RECOGNITION, android.Manifest.permission.BODY_SENSORS, android.Manifest.permission.HIGH_SAMPLING_RATE_SENSORS}, conditional=true) public static final int FOREGROUND_SERVICE_TYPE_HEALTH = 256; // 0x100
+    field @RequiresPermission(allOf={android.Manifest.permission.FOREGROUND_SERVICE_HEALTH}, anyOf={android.Manifest.permission.ACTIVITY_RECOGNITION, android.Manifest.permission.BODY_SENSORS, android.Manifest.permission.HIGH_SAMPLING_RATE_SENSORS}) public static final int FOREGROUND_SERVICE_TYPE_HEALTH = 256; // 0x100
     field @RequiresPermission(allOf={android.Manifest.permission.FOREGROUND_SERVICE_LOCATION}, anyOf={android.Manifest.permission.ACCESS_COARSE_LOCATION, android.Manifest.permission.ACCESS_FINE_LOCATION}, conditional=true) public static final int FOREGROUND_SERVICE_TYPE_LOCATION = 8; // 0x8
     field public static final int FOREGROUND_SERVICE_TYPE_MANIFEST = -1; // 0xffffffff
     field @RequiresPermission(value=android.Manifest.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK, conditional=true) public static final int FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK = 2; // 0x2
@@ -13044,6 +13064,14 @@
 
 package android.credentials {
 
+  public class ClearCredentialStateException extends java.lang.Exception {
+    ctor public ClearCredentialStateException(@NonNull String, @Nullable String);
+    ctor public ClearCredentialStateException(@NonNull String, @Nullable String, @Nullable Throwable);
+    ctor public ClearCredentialStateException(@NonNull String, @Nullable Throwable);
+    ctor public ClearCredentialStateException(@NonNull String);
+    field @NonNull public final String errorType;
+  }
+
   public final class ClearCredentialStateRequest implements android.os.Parcelable {
     ctor public ClearCredentialStateRequest(@NonNull android.os.Bundle);
     method public int describeContents();
@@ -13052,6 +13080,14 @@
     field @NonNull public static final android.os.Parcelable.Creator<android.credentials.ClearCredentialStateRequest> CREATOR;
   }
 
+  public class CreateCredentialException extends java.lang.Exception {
+    ctor public CreateCredentialException(@NonNull String, @Nullable String);
+    ctor public CreateCredentialException(@NonNull String, @Nullable String, @Nullable Throwable);
+    ctor public CreateCredentialException(@NonNull String, @Nullable Throwable);
+    ctor public CreateCredentialException(@NonNull String);
+    field @NonNull public final String errorType;
+  }
+
   public final class CreateCredentialRequest implements android.os.Parcelable {
     ctor public CreateCredentialRequest(@NonNull String, @NonNull android.os.Bundle, @NonNull android.os.Bundle, boolean);
     method public int describeContents();
@@ -13081,24 +13117,24 @@
   }
 
   public final class CredentialManager {
-    method public void clearCredentialState(@NonNull android.credentials.ClearCredentialStateRequest, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<java.lang.Void,android.credentials.CredentialManagerException>);
-    method public void executeCreateCredential(@NonNull android.credentials.CreateCredentialRequest, @NonNull android.app.Activity, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.credentials.CreateCredentialResponse,android.credentials.CredentialManagerException>);
-    method public void executeGetCredential(@NonNull android.credentials.GetCredentialRequest, @NonNull android.app.Activity, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.credentials.GetCredentialResponse,android.credentials.CredentialManagerException>);
+    method public void clearCredentialState(@NonNull android.credentials.ClearCredentialStateRequest, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<java.lang.Void,android.credentials.ClearCredentialStateException>);
+    method public void executeCreateCredential(@NonNull android.credentials.CreateCredentialRequest, @NonNull android.app.Activity, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.credentials.CreateCredentialResponse,android.credentials.CreateCredentialException>);
+    method public void executeGetCredential(@NonNull android.credentials.GetCredentialRequest, @NonNull android.app.Activity, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.credentials.GetCredentialResponse,android.credentials.GetCredentialException>);
   }
 
-  public class CredentialManagerException extends java.lang.Exception {
-    ctor public CredentialManagerException(int, @Nullable String);
-    ctor public CredentialManagerException(int, @Nullable String, @Nullable Throwable);
-    ctor public CredentialManagerException(int, @Nullable Throwable);
-    ctor public CredentialManagerException(int);
-    field public static final int ERROR_UNKNOWN = 0; // 0x0
-    field public final int errorCode;
+  public class GetCredentialException extends java.lang.Exception {
+    ctor public GetCredentialException(@NonNull String, @Nullable String);
+    ctor public GetCredentialException(@NonNull String, @Nullable String, @Nullable Throwable);
+    ctor public GetCredentialException(@NonNull String, @Nullable Throwable);
+    ctor public GetCredentialException(@NonNull String);
+    field @NonNull public final String errorType;
   }
 
   public final class GetCredentialOption implements android.os.Parcelable {
-    ctor public GetCredentialOption(@NonNull String, @NonNull android.os.Bundle, boolean);
+    ctor public GetCredentialOption(@NonNull String, @NonNull android.os.Bundle, @NonNull android.os.Bundle, boolean);
     method public int describeContents();
-    method @NonNull public android.os.Bundle getData();
+    method @NonNull public android.os.Bundle getCandidateQueryData();
+    method @NonNull public android.os.Bundle getCredentialRetrievalData();
     method @NonNull public String getType();
     method public boolean requireSystemProvider();
     method public void writeToParcel(@NonNull android.os.Parcel, int);
@@ -17826,6 +17862,7 @@
     field @NonNull public static final android.hardware.camera2.CameraCharacteristics.Key<java.lang.Integer> SENSOR_MAX_ANALOG_SENSITIVITY;
     field @NonNull public static final android.hardware.camera2.CameraCharacteristics.Key<android.graphics.Rect[]> SENSOR_OPTICAL_BLACK_REGIONS;
     field @NonNull public static final android.hardware.camera2.CameraCharacteristics.Key<java.lang.Integer> SENSOR_ORIENTATION;
+    field @NonNull public static final android.hardware.camera2.CameraCharacteristics.Key<java.lang.Integer> SENSOR_READOUT_TIMESTAMP;
     field @NonNull public static final android.hardware.camera2.CameraCharacteristics.Key<java.lang.Integer> SENSOR_REFERENCE_ILLUMINANT1;
     field @NonNull public static final android.hardware.camera2.CameraCharacteristics.Key<java.lang.Byte> SENSOR_REFERENCE_ILLUMINANT2;
     field @NonNull public static final android.hardware.camera2.CameraCharacteristics.Key<int[]> SHADING_AVAILABLE_MODES;
@@ -17909,6 +17946,7 @@
     method public int capture(@NonNull android.hardware.camera2.CaptureRequest, @NonNull java.util.concurrent.Executor, @NonNull android.hardware.camera2.CameraExtensionSession.ExtensionCaptureCallback) throws android.hardware.camera2.CameraAccessException;
     method public void close() throws android.hardware.camera2.CameraAccessException;
     method @NonNull public android.hardware.camera2.CameraDevice getDevice();
+    method @Nullable public android.util.Pair<java.lang.Long,java.lang.Long> getRealtimeStillCaptureLatency() throws android.hardware.camera2.CameraAccessException;
     method public int setRepeatingRequest(@NonNull android.hardware.camera2.CaptureRequest, @NonNull java.util.concurrent.Executor, @NonNull android.hardware.camera2.CameraExtensionSession.ExtensionCaptureCallback) throws android.hardware.camera2.CameraAccessException;
     method public void stopRepeating() throws android.hardware.camera2.CameraAccessException;
   }
@@ -18194,6 +18232,8 @@
     field public static final int SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN = 0; // 0x0
     field public static final int SENSOR_PIXEL_MODE_DEFAULT = 0; // 0x0
     field public static final int SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION = 1; // 0x1
+    field public static final int SENSOR_READOUT_TIMESTAMP_HARDWARE = 1; // 0x1
+    field public static final int SENSOR_READOUT_TIMESTAMP_NOT_SUPPORTED = 0; // 0x0
     field public static final int SENSOR_REFERENCE_ILLUMINANT1_CLOUDY_WEATHER = 10; // 0xa
     field public static final int SENSOR_REFERENCE_ILLUMINANT1_COOL_WHITE_FLUORESCENT = 14; // 0xe
     field public static final int SENSOR_REFERENCE_ILLUMINANT1_D50 = 23; // 0x17
@@ -18307,6 +18347,7 @@
     field @NonNull public static final android.os.Parcelable.Creator<android.hardware.camera2.CaptureRequest> CREATOR;
     field @NonNull public static final android.hardware.camera2.CaptureRequest.Key<java.lang.Integer> DISTORTION_CORRECTION_MODE;
     field @NonNull public static final android.hardware.camera2.CaptureRequest.Key<java.lang.Integer> EDGE_MODE;
+    field @NonNull public static final android.hardware.camera2.CaptureRequest.Key<java.lang.Integer> EXTENSION_STRENGTH;
     field @NonNull public static final android.hardware.camera2.CaptureRequest.Key<java.lang.Integer> FLASH_MODE;
     field @NonNull public static final android.hardware.camera2.CaptureRequest.Key<java.lang.Integer> HOT_PIXEL_MODE;
     field @NonNull public static final android.hardware.camera2.CaptureRequest.Key<android.location.Location> JPEG_GPS_LOCATION;
@@ -18399,6 +18440,8 @@
     field @NonNull public static final android.hardware.camera2.CaptureResult.Key<java.lang.Float> CONTROL_ZOOM_RATIO;
     field @NonNull public static final android.hardware.camera2.CaptureResult.Key<java.lang.Integer> DISTORTION_CORRECTION_MODE;
     field @NonNull public static final android.hardware.camera2.CaptureResult.Key<java.lang.Integer> EDGE_MODE;
+    field @NonNull public static final android.hardware.camera2.CaptureResult.Key<java.lang.Integer> EXTENSION_CURRENT_TYPE;
+    field @NonNull public static final android.hardware.camera2.CaptureResult.Key<java.lang.Integer> EXTENSION_STRENGTH;
     field @NonNull public static final android.hardware.camera2.CaptureResult.Key<java.lang.Integer> FLASH_MODE;
     field @NonNull public static final android.hardware.camera2.CaptureResult.Key<java.lang.Integer> FLASH_STATE;
     field @NonNull public static final android.hardware.camera2.CaptureResult.Key<java.lang.Integer> HOT_PIXEL_MODE;
@@ -20206,7 +20249,7 @@
 
   public final class AltitudeConverter {
     ctor public AltitudeConverter();
-    method @WorkerThread public void addMslAltitude(@NonNull android.content.Context, @NonNull android.location.Location) throws java.io.IOException;
+    method @WorkerThread public void addMslAltitudeToLocation(@NonNull android.content.Context, @NonNull android.location.Location) throws java.io.IOException;
   }
 
 }
@@ -20486,6 +20529,7 @@
     field public static final int ENCODING_DOLBY_MAT = 19; // 0x13
     field public static final int ENCODING_DOLBY_TRUEHD = 14; // 0xe
     field public static final int ENCODING_DRA = 28; // 0x1c
+    field public static final int ENCODING_DSD = 31; // 0x1f
     field public static final int ENCODING_DTS = 7; // 0x7
     field public static final int ENCODING_DTS_HD = 8; // 0x8
     field public static final int ENCODING_DTS_HD_MA = 29; // 0x1d
@@ -20525,10 +20569,12 @@
     method public int abandonAudioFocusRequest(@NonNull android.media.AudioFocusRequest);
     method public void addOnCommunicationDeviceChangedListener(@NonNull java.util.concurrent.Executor, @NonNull android.media.AudioManager.OnCommunicationDeviceChangedListener);
     method public void addOnModeChangedListener(@NonNull java.util.concurrent.Executor, @NonNull android.media.AudioManager.OnModeChangedListener);
+    method public void addOnPreferredMixerAttributesChangedListener(@NonNull java.util.concurrent.Executor, @NonNull android.media.AudioManager.OnPreferredMixerAttributesChangedListener);
     method public void adjustStreamVolume(int, int, int);
     method public void adjustSuggestedStreamVolume(int, int, int);
     method public void adjustVolume(int, int);
     method public void clearCommunicationDevice();
+    method @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_SETTINGS) public boolean clearPreferredMixerAttributes(@NonNull android.media.AudioAttributes, @NonNull android.media.AudioDeviceInfo);
     method public void dispatchMediaKeyEvent(android.view.KeyEvent);
     method public int generateAudioSessionId();
     method @NonNull public java.util.List<android.media.AudioPlaybackConfiguration> getActivePlaybackConfigurations();
@@ -20546,6 +20592,7 @@
     method public int getMode();
     method public String getParameters(String);
     method @Deprecated public static int getPlaybackOffloadSupport(@NonNull android.media.AudioFormat, @NonNull android.media.AudioAttributes);
+    method @Nullable public android.media.AudioMixerAttributes getPreferredMixerAttributes(@NonNull android.media.AudioAttributes, @NonNull android.media.AudioDeviceInfo);
     method public String getProperty(String);
     method public int getRingerMode();
     method @Deprecated public int getRouting(int);
@@ -20554,6 +20601,7 @@
     method public int getStreamMinVolume(int);
     method public int getStreamVolume(int);
     method public float getStreamVolumeDb(int, int, int);
+    method @NonNull public java.util.List<android.media.AudioMixerAttributes> getSupportedMixerAttributes(@NonNull android.media.AudioDeviceInfo);
     method @Deprecated public int getVibrateSetting(int);
     method @Deprecated public boolean isBluetoothA2dpOn();
     method public boolean isBluetoothScoAvailableOffCall();
@@ -20581,6 +20629,7 @@
     method @Deprecated public boolean registerRemoteController(android.media.RemoteController);
     method public void removeOnCommunicationDeviceChangedListener(@NonNull android.media.AudioManager.OnCommunicationDeviceChangedListener);
     method public void removeOnModeChangedListener(@NonNull android.media.AudioManager.OnModeChangedListener);
+    method public void removeOnPreferredMixerAttributesChangedListener(@NonNull android.media.AudioManager.OnPreferredMixerAttributesChangedListener);
     method @Deprecated public int requestAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener, int, int);
     method public int requestAudioFocus(@NonNull android.media.AudioFocusRequest);
     method public void setAllowedCapturePolicy(int);
@@ -20591,6 +20640,7 @@
     method public void setMicrophoneMute(boolean);
     method public void setMode(int);
     method public void setParameters(String);
+    method @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_SETTINGS) public boolean setPreferredMixerAttributes(@NonNull android.media.AudioAttributes, @NonNull android.media.AudioDeviceInfo, @NonNull android.media.AudioMixerAttributes);
     method public void setRingerMode(int);
     method @Deprecated public void setRouting(int, int, int);
     method @Deprecated public void setSpeakerphoneOn(boolean);
@@ -20746,6 +20796,10 @@
     method public void onModeChanged(int);
   }
 
+  public static interface AudioManager.OnPreferredMixerAttributesChangedListener {
+    method public void onPreferredMixerAttributesChanged(@NonNull android.media.AudioAttributes, @NonNull android.media.AudioDeviceInfo, @Nullable android.media.AudioMixerAttributes);
+  }
+
   public final class AudioMetadata {
     method @NonNull public static android.media.AudioMetadataMap createMap();
   }
@@ -20781,6 +20835,22 @@
     method @IntRange(from=0) public int size();
   }
 
+  public final class AudioMixerAttributes implements android.os.Parcelable {
+    method public int describeContents();
+    method @NonNull public android.media.AudioFormat getFormat();
+    method public int getMixerBehavior();
+    method public void writeToParcel(@NonNull android.os.Parcel, int);
+    field @NonNull public static final android.os.Parcelable.Creator<android.media.AudioMixerAttributes> CREATOR;
+    field public static final int MIXER_BEHAVIOR_BIT_PERFECT = 1; // 0x1
+    field public static final int MIXER_BEHAVIOR_DEFAULT = 0; // 0x0
+  }
+
+  public static final class AudioMixerAttributes.Builder {
+    ctor public AudioMixerAttributes.Builder(@NonNull android.media.AudioFormat);
+    method @NonNull public android.media.AudioMixerAttributes build();
+    method @NonNull public android.media.AudioMixerAttributes.Builder setMixerBehavior(int);
+  }
+
   public final class AudioPlaybackCaptureConfiguration {
     method @NonNull public int[] getExcludeUids();
     method @NonNull public int[] getExcludeUsages();
@@ -24000,6 +24070,8 @@
     method @NonNull public String getRouteId();
     method public void writeToParcel(@NonNull android.os.Parcel, int);
     field @NonNull public static final android.os.Parcelable.Creator<android.media.RouteListingPreference.Item> CREATOR;
+    field public static final int DISABLE_REASON_AD = 3; // 0x3
+    field public static final int DISABLE_REASON_DOWNLOADED_CONTENT = 2; // 0x2
     field public static final int DISABLE_REASON_NONE = 0; // 0x0
     field public static final int DISABLE_REASON_SUBSCRIPTION_REQUIRED = 1; // 0x1
     field public static final int FLAG_ONGOING_SESSION = 1; // 0x1
@@ -25392,11 +25464,21 @@
 
   public abstract static class MediaProjection.Callback {
     ctor public MediaProjection.Callback();
+    method public void onCapturedContentResize(int, int);
     method public void onStop();
   }
 
+  public final class MediaProjectionConfig implements android.os.Parcelable {
+    method @NonNull public static android.media.projection.MediaProjectionConfig createConfigForDisplay(@IntRange(from=android.view.Display.DEFAULT_DISPLAY, to=android.view.Display.DEFAULT_DISPLAY) int);
+    method @NonNull public static android.media.projection.MediaProjectionConfig createConfigForUserChoice();
+    method public int describeContents();
+    method public void writeToParcel(@NonNull android.os.Parcel, int);
+    field @NonNull public static final android.os.Parcelable.Creator<android.media.projection.MediaProjectionConfig> CREATOR;
+  }
+
   public final class MediaProjectionManager {
-    method public android.content.Intent createScreenCaptureIntent();
+    method @NonNull public android.content.Intent createScreenCaptureIntent();
+    method @NonNull public android.content.Intent createScreenCaptureIntent(@NonNull android.media.projection.MediaProjectionConfig);
     method public android.media.projection.MediaProjection getMediaProjection(int, @NonNull android.content.Intent);
   }
 
@@ -26725,6 +26807,7 @@
     method public boolean onKeyUp(int, @NonNull android.view.KeyEvent);
     method public void onMediaViewSizeChanged(@Px int, @Px int);
     method public void onRecordingStarted(@NonNull String);
+    method public void onRecordingStopped(@NonNull String);
     method public abstract void onRelease();
     method public void onResetInteractiveApp();
     method public abstract boolean onSetSurface(@Nullable android.view.Surface);
@@ -26751,6 +26834,7 @@
     method @CallSuper public void requestCurrentTvInputId();
     method @CallSuper public void requestSigning(@NonNull String, @NonNull String, @NonNull String, @NonNull byte[]);
     method @CallSuper public void requestStartRecording(@Nullable android.net.Uri);
+    method @CallSuper public void requestStopRecording(@NonNull String);
     method @CallSuper public void requestStreamVolume();
     method @CallSuper public void requestTrackInfoList();
     method @CallSuper public void sendPlaybackCommandRequest(@NonNull String, @Nullable android.os.Bundle);
@@ -26783,6 +26867,7 @@
     method @Nullable public android.media.tv.interactive.TvInteractiveAppView.OnUnhandledInputEventListener getOnUnhandledInputEventListener();
     method public void notifyError(@NonNull String, @NonNull android.os.Bundle);
     method public void notifyRecordingStarted(@NonNull String);
+    method public void notifyRecordingStopped(@NonNull String);
     method public void onAttachedToWindow();
     method public void onDetachedFromWindow();
     method public void onLayout(boolean, int, int, int, int);
@@ -26825,6 +26910,7 @@
     method public void onRequestCurrentTvInputId(@NonNull String);
     method public void onRequestSigning(@NonNull String, @NonNull String, @NonNull String, @NonNull String, @NonNull byte[]);
     method public void onRequestStartRecording(@NonNull String, @Nullable android.net.Uri);
+    method public void onRequestStopRecording(@NonNull String, @NonNull String);
     method public void onRequestStreamVolume(@NonNull String);
     method public void onRequestTrackInfoList(@NonNull String);
     method public void onSetVideoBounds(@NonNull String, @NonNull android.graphics.Rect);
@@ -27791,6 +27877,7 @@
   public final class VcnConfig implements android.os.Parcelable {
     method public int describeContents();
     method @NonNull public java.util.Set<android.net.vcn.VcnGatewayConnectionConfig> getGatewayConnectionConfigs();
+    method @NonNull public java.util.Set<java.lang.Integer> getRestrictedUnderlyingNetworkTransports();
     method public void writeToParcel(@NonNull android.os.Parcel, int);
     field @NonNull public static final android.os.Parcelable.Creator<android.net.vcn.VcnConfig> CREATOR;
   }
@@ -27799,6 +27886,7 @@
     ctor public VcnConfig.Builder(@NonNull android.content.Context);
     method @NonNull public android.net.vcn.VcnConfig.Builder addGatewayConnectionConfig(@NonNull android.net.vcn.VcnGatewayConnectionConfig);
     method @NonNull public android.net.vcn.VcnConfig build();
+    method @NonNull public android.net.vcn.VcnConfig.Builder setRestrictedUnderlyingNetworkTransports(@NonNull java.util.Set<java.lang.Integer>);
   }
 
   public final class VcnGatewayConnectionConfig {
@@ -27807,13 +27895,17 @@
     method @IntRange(from=0x500) public int getMaxMtu();
     method @NonNull public long[] getRetryIntervalsMillis();
     method @NonNull public java.util.List<android.net.vcn.VcnUnderlyingNetworkTemplate> getVcnUnderlyingNetworkPriorities();
+    method public boolean hasGatewayOption(int);
+    field public static final int VCN_GATEWAY_OPTION_ENABLE_DATA_STALL_RECOVERY_WITH_MOBILITY = 0; // 0x0
   }
 
   public static final class VcnGatewayConnectionConfig.Builder {
     ctor public VcnGatewayConnectionConfig.Builder(@NonNull String, @NonNull android.net.ipsec.ike.IkeTunnelConnectionParams);
     method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder addExposedCapability(int);
+    method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder addGatewayOption(int);
     method @NonNull public android.net.vcn.VcnGatewayConnectionConfig build();
     method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder removeExposedCapability(int);
+    method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder removeGatewayOption(int);
     method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder setMaxMtu(@IntRange(from=0x500) int);
     method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder setRetryIntervalsMillis(@NonNull long[]);
     method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder setVcnUnderlyingNetworkPriorities(@NonNull java.util.List<android.net.vcn.VcnUnderlyingNetworkTemplate>);
@@ -36207,7 +36299,7 @@
     field public static final String PARENTAL_CONTROL_LAST_UPDATE = "parental_control_last_update";
     field public static final String PARENTAL_CONTROL_REDIRECT_URL = "parental_control_redirect_url";
     field public static final String RTT_CALLING_MODE = "rtt_calling_mode";
-    field public static final String SECURE_FRP_MODE = "secure_frp_mode";
+    field @Deprecated public static final String SECURE_FRP_MODE = "secure_frp_mode";
     field public static final String SELECTED_INPUT_METHOD_SUBTYPE = "selected_input_method_subtype";
     field public static final String SETTINGS_CLASSNAME = "settings_classname";
     field public static final String SKIP_FIRST_USE_HINTS = "skip_first_use_hints";
@@ -38203,6 +38295,11 @@
     ctor public AlreadyPersonalizedException(@NonNull String, @NonNull Throwable);
   }
 
+  public final class AuthenticationKeyMetadata {
+    method @NonNull public java.time.Instant getExpirationDate();
+    method @IntRange(from=0) public int getUsageCount();
+  }
+
   public class CipherSuiteNotSupportedException extends android.security.identity.IdentityCredentialException {
     ctor public CipherSuiteNotSupportedException(@NonNull String);
     ctor public CipherSuiteNotSupportedException(@NonNull String, @NonNull Throwable);
@@ -38233,6 +38330,7 @@
   public abstract class CredentialDataResult {
     method @Nullable public abstract byte[] getDeviceMac();
     method @NonNull public abstract byte[] getDeviceNameSpaces();
+    method @Nullable public byte[] getDeviceSignature();
     method @NonNull public abstract android.security.identity.CredentialDataResult.Entries getDeviceSignedEntries();
     method @NonNull public abstract android.security.identity.CredentialDataResult.Entries getIssuerSignedEntries();
     method @NonNull public abstract byte[] getStaticAuthenticationData();
@@ -38269,13 +38367,15 @@
     method @NonNull public byte[] delete(@NonNull byte[]);
     method @Deprecated @NonNull public abstract byte[] encryptMessageToReader(@NonNull byte[]);
     method @NonNull public abstract java.util.Collection<java.security.cert.X509Certificate> getAuthKeysNeedingCertification();
-    method @NonNull public abstract int[] getAuthenticationDataUsageCount();
+    method @Deprecated @NonNull public abstract int[] getAuthenticationDataUsageCount();
+    method @NonNull public java.util.List<android.security.identity.AuthenticationKeyMetadata> getAuthenticationKeyMetadata();
     method @NonNull public abstract java.util.Collection<java.security.cert.X509Certificate> getCredentialKeyCertificateChain();
     method @Deprecated @NonNull public abstract android.security.identity.ResultData getEntries(@Nullable byte[], @NonNull java.util.Map<java.lang.String,java.util.Collection<java.lang.String>>, @Nullable byte[], @Nullable byte[]) throws android.security.identity.EphemeralPublicKeyNotFoundException, android.security.identity.InvalidReaderSignatureException, android.security.identity.InvalidRequestMessageException, android.security.identity.NoAuthenticationKeyAvailableException, android.security.identity.SessionTranscriptMismatchException;
     method @NonNull public byte[] proveOwnership(@NonNull byte[]);
     method @Deprecated public abstract void setAllowUsingExhaustedKeys(boolean);
     method @Deprecated public void setAllowUsingExpiredKeys(boolean);
-    method public abstract void setAvailableAuthenticationKeys(int, int);
+    method @Deprecated public abstract void setAvailableAuthenticationKeys(int, int);
+    method public void setAvailableAuthenticationKeys(@IntRange(from=0) int, @IntRange(from=1) int, @IntRange(from=0) long);
     method @Deprecated public abstract void setReaderEphemeralPublicKey(@NonNull java.security.PublicKey) throws java.security.InvalidKeyException;
     method @Deprecated public abstract void storeStaticAuthenticationData(@NonNull java.security.cert.X509Certificate, @NonNull byte[]) throws android.security.identity.UnknownAuthenticationKeyException;
     method public void storeStaticAuthenticationData(@NonNull java.security.cert.X509Certificate, @NonNull java.time.Instant, @NonNull byte[]) throws android.security.identity.UnknownAuthenticationKeyException;
@@ -39448,6 +39548,40 @@
     method @NonNull public android.service.credentials.BeginCreateCredentialResponse.Builder setRemoteCreateEntry(@Nullable android.service.credentials.CreateEntry);
   }
 
+  public final class BeginGetCredentialOption implements android.os.Parcelable {
+    ctor public BeginGetCredentialOption(@NonNull String, @NonNull android.os.Bundle);
+    method public int describeContents();
+    method @NonNull public android.os.Bundle getCandidateQueryData();
+    method @NonNull public String getType();
+    method public void writeToParcel(@NonNull android.os.Parcel, int);
+    field @NonNull public static final android.os.Parcelable.Creator<android.service.credentials.BeginGetCredentialOption> CREATOR;
+  }
+
+  public final class BeginGetCredentialsRequest implements android.os.Parcelable {
+    method public int describeContents();
+    method @NonNull public java.util.List<android.service.credentials.BeginGetCredentialOption> getBeginGetCredentialOptions();
+    method @NonNull public String getCallingPackage();
+    method public void writeToParcel(@NonNull android.os.Parcel, int);
+    field @NonNull public static final android.os.Parcelable.Creator<android.service.credentials.BeginGetCredentialsRequest> CREATOR;
+  }
+
+  public static final class BeginGetCredentialsRequest.Builder {
+    ctor public BeginGetCredentialsRequest.Builder(@NonNull String);
+    method @NonNull public android.service.credentials.BeginGetCredentialsRequest.Builder addBeginGetCredentialOption(@NonNull android.service.credentials.BeginGetCredentialOption);
+    method @NonNull public android.service.credentials.BeginGetCredentialsRequest build();
+    method @NonNull public android.service.credentials.BeginGetCredentialsRequest.Builder setBeginGetCredentialOptions(@NonNull java.util.List<android.service.credentials.BeginGetCredentialOption>);
+  }
+
+  public final class BeginGetCredentialsResponse implements android.os.Parcelable {
+    method @NonNull public static android.service.credentials.BeginGetCredentialsResponse createWithAuthentication(@NonNull android.service.credentials.Action);
+    method @NonNull public static android.service.credentials.BeginGetCredentialsResponse createWithResponseContent(@NonNull android.service.credentials.CredentialsResponseContent);
+    method public int describeContents();
+    method @Nullable public android.service.credentials.Action getAuthenticationAction();
+    method @Nullable public android.service.credentials.CredentialsResponseContent getCredentialsResponseContent();
+    method public void writeToParcel(@NonNull android.os.Parcel, int);
+    field @NonNull public static final android.os.Parcelable.Creator<android.service.credentials.BeginGetCredentialsResponse> CREATOR;
+  }
+
   public final class CreateCredentialRequest implements android.os.Parcelable {
     ctor public CreateCredentialRequest(@NonNull String, @NonNull String, @NonNull android.os.Bundle);
     method public int describeContents();
@@ -39469,8 +39603,7 @@
 
   public final class CredentialEntry implements android.os.Parcelable {
     method public int describeContents();
-    method @Nullable public android.credentials.Credential getCredential();
-    method @Nullable public android.app.PendingIntent getPendingIntent();
+    method @NonNull public android.app.PendingIntent getPendingIntent();
     method @NonNull public android.app.slice.Slice getSlice();
     method @NonNull public String getType();
     method public boolean isAutoSelectAllowed();
@@ -39480,7 +39613,6 @@
 
   public static final class CredentialEntry.Builder {
     ctor public CredentialEntry.Builder(@NonNull String, @NonNull android.app.slice.Slice, @NonNull android.app.PendingIntent);
-    ctor public CredentialEntry.Builder(@NonNull String, @NonNull android.app.slice.Slice, @NonNull android.credentials.Credential);
     method @NonNull public android.service.credentials.CredentialEntry build();
     method @NonNull public android.service.credentials.CredentialEntry.Builder setAutoSelectAllowed(@NonNull boolean);
   }
@@ -39497,14 +39629,16 @@
   public abstract class CredentialProviderService extends android.app.Service {
     ctor public CredentialProviderService();
     method public abstract void onBeginCreateCredential(@NonNull android.service.credentials.BeginCreateCredentialRequest, @NonNull android.os.CancellationSignal, @NonNull android.os.OutcomeReceiver<android.service.credentials.BeginCreateCredentialResponse,android.service.credentials.CredentialProviderException>);
+    method public abstract void onBeginGetCredentials(@NonNull android.service.credentials.BeginGetCredentialsRequest, @NonNull android.os.CancellationSignal, @NonNull android.os.OutcomeReceiver<android.service.credentials.BeginGetCredentialsResponse,android.service.credentials.CredentialProviderException>);
     method @NonNull public final android.os.IBinder onBind(@NonNull android.content.Intent);
-    method public abstract void onGetCredentials(@NonNull android.service.credentials.GetCredentialsRequest, @NonNull android.os.CancellationSignal, @NonNull android.os.OutcomeReceiver<android.service.credentials.GetCredentialsResponse,android.service.credentials.CredentialProviderException>);
     field public static final String CAPABILITY_META_DATA_KEY = "android.credentials.capabilities";
+    field public static final String EXTRA_CREATE_CREDENTIAL_EXCEPTION = "android.service.credentials.extra.CREATE_CREDENTIAL_EXCEPTION";
     field public static final String EXTRA_CREATE_CREDENTIAL_REQUEST = "android.service.credentials.extra.CREATE_CREDENTIAL_REQUEST";
-    field public static final String EXTRA_CREATE_CREDENTIAL_RESULT = "android.service.credentials.extra.CREATE_CREDENTIAL_RESULT";
-    field public static final String EXTRA_CREDENTIAL_RESULT = "android.service.credentials.extra.CREDENTIAL_RESULT";
-    field public static final String EXTRA_ERROR = "android.service.credentials.extra.ERROR";
-    field public static final String EXTRA_GET_CREDENTIALS_CONTENT_RESULT = "android.service.credentials.extra.GET_CREDENTIALS_CONTENT_RESULT";
+    field public static final String EXTRA_CREATE_CREDENTIAL_RESPONSE = "android.service.credentials.extra.CREATE_CREDENTIAL_RESPONSE";
+    field public static final String EXTRA_CREDENTIALS_RESPONSE_CONTENT = "android.service.credentials.extra.CREDENTIALS_RESPONSE_CONTENT";
+    field public static final String EXTRA_GET_CREDENTIAL_EXCEPTION = "android.service.credentials.extra.GET_CREDENTIAL_EXCEPTION";
+    field public static final String EXTRA_GET_CREDENTIAL_REQUEST = "android.service.credentials.extra.GET_CREDENTIAL_REQUEST";
+    field public static final String EXTRA_GET_CREDENTIAL_RESPONSE = "android.service.credentials.extra.GET_CREDENTIAL_RESPONSE";
     field public static final String SERVICE_INTERFACE = "android.service.credentials.CredentialProviderService";
   }
 
@@ -39527,29 +39661,19 @@
     method @NonNull public android.service.credentials.CredentialsResponseContent.Builder setRemoteCredentialEntry(@Nullable android.service.credentials.CredentialEntry);
   }
 
-  public final class GetCredentialsRequest implements android.os.Parcelable {
+  public final class GetCredentialRequest implements android.os.Parcelable {
     method public int describeContents();
     method @NonNull public String getCallingPackage();
     method @NonNull public java.util.List<android.credentials.GetCredentialOption> getGetCredentialOptions();
     method public void writeToParcel(@NonNull android.os.Parcel, int);
-    field @NonNull public static final android.os.Parcelable.Creator<android.service.credentials.GetCredentialsRequest> CREATOR;
+    field @NonNull public static final android.os.Parcelable.Creator<android.service.credentials.GetCredentialRequest> CREATOR;
   }
 
-  public static final class GetCredentialsRequest.Builder {
-    ctor public GetCredentialsRequest.Builder(@NonNull String);
-    method @NonNull public android.service.credentials.GetCredentialsRequest.Builder addGetCredentialOption(@NonNull android.credentials.GetCredentialOption);
-    method @NonNull public android.service.credentials.GetCredentialsRequest build();
-    method @NonNull public android.service.credentials.GetCredentialsRequest.Builder setGetCredentialOptions(@NonNull java.util.List<android.credentials.GetCredentialOption>);
-  }
-
-  public final class GetCredentialsResponse implements android.os.Parcelable {
-    method @NonNull public static android.service.credentials.GetCredentialsResponse createWithAuthentication(@NonNull android.service.credentials.Action);
-    method @NonNull public static android.service.credentials.GetCredentialsResponse createWithResponseContent(@NonNull android.service.credentials.CredentialsResponseContent);
-    method public int describeContents();
-    method @Nullable public android.service.credentials.Action getAuthenticationAction();
-    method @Nullable public android.service.credentials.CredentialsResponseContent getCredentialsResponseContent();
-    method public void writeToParcel(@NonNull android.os.Parcel, int);
-    field @NonNull public static final android.os.Parcelable.Creator<android.service.credentials.GetCredentialsResponse> CREATOR;
+  public static final class GetCredentialRequest.Builder {
+    ctor public GetCredentialRequest.Builder(@NonNull String);
+    method @NonNull public android.service.credentials.GetCredentialRequest.Builder addGetCredentialOption(@NonNull android.credentials.GetCredentialOption);
+    method @NonNull public android.service.credentials.GetCredentialRequest build();
+    method @NonNull public android.service.credentials.GetCredentialRequest.Builder setGetCredentialOptions(@NonNull java.util.List<android.credentials.GetCredentialOption>);
   }
 
 }
@@ -41925,11 +42049,15 @@
   }
 
   public class CarrierConfigManager {
-    method @Nullable @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public android.os.PersistableBundle getConfig();
+    method @Deprecated @Nullable @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public android.os.PersistableBundle getConfig();
+    method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.READ_PHONE_STATE, "carrier privileges"}) public android.os.PersistableBundle getConfig(@NonNull java.lang.String...);
     method @Nullable @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public android.os.PersistableBundle getConfigByComponentForSubId(@NonNull String, int);
-    method @Nullable @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public android.os.PersistableBundle getConfigForSubId(int);
+    method @Deprecated @Nullable @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public android.os.PersistableBundle getConfigForSubId(int);
+    method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.READ_PHONE_STATE, "carrier privileges"}) public android.os.PersistableBundle getConfigForSubId(int, @NonNull java.lang.String...);
     method public static boolean isConfigForIdentifiedCarrier(android.os.PersistableBundle);
     method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void notifyConfigChangedForSubId(int);
+    method public void registerCarrierConfigChangeListener(@NonNull java.util.concurrent.Executor, @NonNull android.telephony.CarrierConfigManager.CarrierConfigChangeListener);
+    method public void unregisterCarrierConfigChangeListener(@NonNull android.telephony.CarrierConfigManager.CarrierConfigChangeListener);
     field public static final String ACTION_CARRIER_CONFIG_CHANGED = "android.telephony.action.CARRIER_CONFIG_CHANGED";
     field public static final int CARRIER_NR_AVAILABILITY_NSA = 1; // 0x1
     field public static final int CARRIER_NR_AVAILABILITY_SA = 2; // 0x2
@@ -42259,6 +42387,10 @@
     field public static final String KEY_PREFIX = "bsf.";
   }
 
+  public static interface CarrierConfigManager.CarrierConfigChangeListener {
+    method public void onCarrierConfigChanged(int, int, int, int);
+  }
+
   public static final class CarrierConfigManager.Gps {
     field public static final String KEY_PERSIST_LPP_MODE_BOOL = "gps.persist_lpp_mode_bool";
     field public static final String KEY_PREFIX = "gps.";
@@ -42813,6 +42945,7 @@
     method public int getSsRsrp();
     method public int getSsRsrq();
     method public int getSsSinr();
+    method @IntRange(from=0, to=1282) public int getTimingAdvanceMicros();
     method public void writeToParcel(android.os.Parcel, int);
     field @NonNull public static final android.os.Parcelable.Creator<android.telephony.CellSignalStrengthNr> CREATOR;
   }
@@ -45350,6 +45483,7 @@
 package android.telephony.ims.stub {
 
   public class ImsRegistrationImplBase {
+    field public static final int REGISTRATION_TECH_3G = 4; // 0x4
     field public static final int REGISTRATION_TECH_CROSS_SIM = 2; // 0x2
     field public static final int REGISTRATION_TECH_IWLAN = 1; // 0x1
     field public static final int REGISTRATION_TECH_LTE = 0; // 0x0
@@ -49470,6 +49604,7 @@
     field public static final int KEYCODE_PROG_YELLOW = 185; // 0xb9
     field public static final int KEYCODE_Q = 45; // 0x2d
     field public static final int KEYCODE_R = 46; // 0x2e
+    field public static final int KEYCODE_RECENT_APPS = 312; // 0x138
     field public static final int KEYCODE_REFRESH = 285; // 0x11d
     field public static final int KEYCODE_RIGHT_BRACKET = 72; // 0x48
     field public static final int KEYCODE_RO = 217; // 0xd9
@@ -52551,8 +52686,10 @@
   }
 
   public final class WindowMetrics {
-    ctor public WindowMetrics(@NonNull android.graphics.Rect, @NonNull android.view.WindowInsets);
+    ctor @Deprecated public WindowMetrics(@NonNull android.graphics.Rect, @NonNull android.view.WindowInsets);
+    ctor public WindowMetrics(@NonNull android.graphics.Rect, @NonNull android.view.WindowInsets, float);
     method @NonNull public android.graphics.Rect getBounds();
+    method public float getDensity();
     method @NonNull public android.view.WindowInsets getWindowInsets();
   }
 
@@ -52666,12 +52803,14 @@
     method public void addAudioDescriptionRequestedChangeListener(@NonNull java.util.concurrent.Executor, @NonNull android.view.accessibility.AccessibilityManager.AudioDescriptionRequestedChangeListener);
     method public boolean addTouchExplorationStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener);
     method public void addTouchExplorationStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener, @Nullable android.os.Handler);
+    method public void addUiContrastChangeListener(@NonNull java.util.concurrent.Executor, @NonNull android.view.accessibility.AccessibilityManager.UiContrastChangeListener);
     method @ColorInt public int getAccessibilityFocusColor();
     method public int getAccessibilityFocusStrokeWidth();
     method @Deprecated public java.util.List<android.content.pm.ServiceInfo> getAccessibilityServiceList();
     method public java.util.List<android.accessibilityservice.AccessibilityServiceInfo> getEnabledAccessibilityServiceList(int);
     method public java.util.List<android.accessibilityservice.AccessibilityServiceInfo> getInstalledAccessibilityServiceList();
     method public int getRecommendedTimeoutMillis(int, int);
+    method @FloatRange(from=-1.0F, to=1.0f) public float getUiContrast();
     method public void interrupt();
     method public static boolean isAccessibilityButtonSupported();
     method public boolean isAudioDescriptionRequested();
@@ -52683,6 +52822,7 @@
     method public boolean removeAccessibilityStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener);
     method public boolean removeAudioDescriptionRequestedChangeListener(@NonNull android.view.accessibility.AccessibilityManager.AudioDescriptionRequestedChangeListener);
     method public boolean removeTouchExplorationStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener);
+    method public void removeUiContrastChangeListener(@NonNull android.view.accessibility.AccessibilityManager.UiContrastChangeListener);
     method public void sendAccessibilityEvent(android.view.accessibility.AccessibilityEvent);
     field public static final int FLAG_CONTENT_CONTROLS = 4; // 0x4
     field public static final int FLAG_CONTENT_ICONS = 1; // 0x1
@@ -52705,6 +52845,10 @@
     method public void onTouchExplorationStateChanged(boolean);
   }
 
+  public static interface AccessibilityManager.UiContrastChangeListener {
+    method public void onUiContrastChanged(@FloatRange(from=-1.0F, to=1.0f) float);
+  }
+
   public class AccessibilityNodeInfo implements android.os.Parcelable {
     ctor public AccessibilityNodeInfo();
     ctor public AccessibilityNodeInfo(@NonNull android.view.View);
@@ -54445,6 +54589,8 @@
     method @NonNull public android.text.SegmentFinder getGraphemeSegmentFinder();
     method @NonNull public android.text.SegmentFinder getLineSegmentFinder();
     method @NonNull public android.graphics.Matrix getMatrix();
+    method public int getOffsetForPosition(float, float);
+    method @Nullable public int[] getRangeForRect(@NonNull android.graphics.RectF, @NonNull android.text.SegmentFinder, @NonNull android.text.Layout.TextInclusionStrategy);
     method public int getStart();
     method @NonNull public android.text.SegmentFinder getWordSegmentFinder();
     method public void writeToParcel(@NonNull android.os.Parcel, int);
diff --git a/core/api/module-lib-current.txt b/core/api/module-lib-current.txt
index 3efb0c6..314fd03 100644
--- a/core/api/module-lib-current.txt
+++ b/core/api/module-lib-current.txt
@@ -99,6 +99,10 @@
 
   public class ApplicationInfo extends android.content.pm.PackageItemInfo implements android.os.Parcelable {
     method @NonNull public java.util.List<android.content.pm.SharedLibraryInfo> getSharedLibraryInfos();
+    field public static final int HIDDEN_API_ENFORCEMENT_DEFAULT = -1; // 0xffffffff
+    field public static final int HIDDEN_API_ENFORCEMENT_DISABLED = 0; // 0x0
+    field public static final int HIDDEN_API_ENFORCEMENT_ENABLED = 2; // 0x2
+    field public static final int HIDDEN_API_ENFORCEMENT_JUST_WARN = 1; // 0x1
   }
 
   public abstract class PackageManager {
@@ -418,41 +422,6 @@
     method @NonNull @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) public static java.util.Map<java.lang.String,java.util.List<android.content.ContentValues>> queryRawContactEntity(@NonNull android.content.ContentResolver, long);
   }
 
-  public final class DeviceConfig {
-    field public static final String NAMESPACE_ACTIVITY_MANAGER_COMPONENT_ALIAS = "activity_manager_ca";
-    field public static final String NAMESPACE_ALARM_MANAGER = "alarm_manager";
-    field public static final String NAMESPACE_APP_CLONING = "app_cloning";
-    field public static final String NAMESPACE_APP_STANDBY = "app_standby";
-    field public static final String NAMESPACE_ARC_APP_COMPAT = "arc_app_compat";
-    field public static final String NAMESPACE_CONFIGURATION = "configuration";
-    field public static final String NAMESPACE_CONNECTIVITY_THERMAL_POWER_MANAGER = "connectivity_thermal_power_manager";
-    field public static final String NAMESPACE_CONTACTS_PROVIDER = "contacts_provider";
-    field public static final String NAMESPACE_DEVICE_IDLE = "device_idle";
-    field public static final String NAMESPACE_DEVICE_POLICY_MANAGER = "device_policy_manager";
-    field public static final String NAMESPACE_GAME_OVERLAY = "game_overlay";
-    field public static final String NAMESPACE_INTELLIGENCE_CONTENT_SUGGESTIONS = "intelligence_content_suggestions";
-    field public static final String NAMESPACE_INTERACTION_JANK_MONITOR = "interaction_jank_monitor";
-    field public static final String NAMESPACE_LATENCY_TRACKER = "latency_tracker";
-    field public static final String NAMESPACE_MEMORY_SAFETY_NATIVE = "memory_safety_native";
-    field public static final String NAMESPACE_MGLRU_NATIVE = "mglru_native";
-    field public static final String NAMESPACE_REMOTE_KEY_PROVISIONING_NATIVE = "remote_key_provisioning_native";
-    field public static final String NAMESPACE_ROTATION_RESOLVER = "rotation_resolver";
-    field public static final String NAMESPACE_SETTINGS_STATS = "settings_stats";
-    field public static final String NAMESPACE_SETTINGS_UI = "settings_ui";
-    field public static final String NAMESPACE_TARE = "tare";
-    field public static final String NAMESPACE_VENDOR_SYSTEM_NATIVE = "vendor_system_native";
-    field public static final String NAMESPACE_VENDOR_SYSTEM_NATIVE_BOOT = "vendor_system_native_boot";
-    field public static final String NAMESPACE_VIRTUALIZATION_FRAMEWORK_NATIVE = "virtualization_framework_native";
-    field public static final String NAMESPACE_VOICE_INTERACTION = "voice_interaction";
-    field public static final String NAMESPACE_WEAR = "wear";
-    field public static final String NAMESPACE_WIDGET = "widget";
-    field public static final String NAMESPACE_WINDOW_MANAGER = "window_manager";
-  }
-
-  public static class DeviceConfig.Properties {
-    ctor public DeviceConfig.Properties(@NonNull String, @Nullable java.util.Map<java.lang.String,java.lang.String>);
-  }
-
   public final class Settings {
     field public static final int RESET_MODE_PACKAGE_DEFAULTS = 1; // 0x1
     field public static final int RESET_MODE_TRUSTED_DEFAULTS = 4; // 0x4
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index eb2d2ca..566ac45 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -352,6 +352,7 @@
     field public static final String USE_COLORIZED_NOTIFICATIONS = "android.permission.USE_COLORIZED_NOTIFICATIONS";
     field public static final String USE_RESERVED_DISK = "android.permission.USE_RESERVED_DISK";
     field public static final String UWB_PRIVILEGED = "android.permission.UWB_PRIVILEGED";
+    field public static final String WAKEUP_SURFACE_FLINGER = "android.permission.WAKEUP_SURFACE_FLINGER";
     field public static final String WHITELIST_AUTO_REVOKE_PERMISSIONS = "android.permission.WHITELIST_AUTO_REVOKE_PERMISSIONS";
     field public static final String WHITELIST_RESTRICTED_PERMISSIONS = "android.permission.WHITELIST_RESTRICTED_PERMISSIONS";
     field public static final String WIFI_ACCESS_COEX_UNSAFE_CHANNELS = "android.permission.WIFI_ACCESS_COEX_UNSAFE_CHANNELS";
@@ -548,6 +549,8 @@
     method @Nullable public static String opToPermission(@NonNull String);
     method @RequiresPermission("android.permission.MANAGE_APP_OPS_MODES") public void setMode(@NonNull String, int, @Nullable String, int);
     method @RequiresPermission("android.permission.MANAGE_APP_OPS_MODES") public void setUidMode(@NonNull String, int, int);
+    method @RequiresPermission(value="android.permission.WATCH_APPOPS", conditional=true) public void startWatchingNoted(@NonNull String[], @NonNull android.app.AppOpsManager.OnOpNotedListener);
+    method public void stopWatchingNoted(@NonNull android.app.AppOpsManager.OnOpNotedListener);
     field public static final int HISTORY_FLAGS_ALL = 3; // 0x3
     field public static final int HISTORY_FLAG_AGGREGATE = 1; // 0x1
     field public static final int HISTORY_FLAG_DISCRETE = 2; // 0x2
@@ -735,6 +738,10 @@
     field @NonNull public static final android.os.Parcelable.Creator<android.app.AppOpsManager.HistoricalUidOps> CREATOR;
   }
 
+  public static interface AppOpsManager.OnOpNotedListener {
+    method public void onOpNoted(@NonNull String, int, @NonNull String, @Nullable String, int, int);
+  }
+
   public static final class AppOpsManager.OpEntry implements android.os.Parcelable {
     method public int describeContents();
     method @NonNull public java.util.Map<java.lang.String,android.app.AppOpsManager.AttributedOpEntry> getAttributedOpEntries();
@@ -826,7 +833,6 @@
     method public int describeContents();
     method public int getFpsOverride();
     method public float getScalingFactor();
-    method @NonNull public android.app.GameModeConfiguration.Builder toBuilder();
     method public void writeToParcel(@NonNull android.os.Parcel, int);
     field @NonNull public static final android.os.Parcelable.Creator<android.app.GameModeConfiguration> CREATOR;
     field public static final int FPS_OVERRIDE_NONE = 0; // 0x0
@@ -834,6 +840,7 @@
 
   public static final class GameModeConfiguration.Builder {
     ctor public GameModeConfiguration.Builder();
+    ctor public GameModeConfiguration.Builder(@NonNull android.app.GameModeConfiguration);
     method @NonNull public android.app.GameModeConfiguration build();
     method @NonNull public android.app.GameModeConfiguration.Builder setFpsOverride(int);
     method @NonNull public android.app.GameModeConfiguration.Builder setScalingFactor(float);
@@ -845,7 +852,7 @@
     method public int getActiveGameMode();
     method @NonNull public int[] getAvailableGameModes();
     method @Nullable public android.app.GameModeConfiguration getGameModeConfiguration(int);
-    method @NonNull public int[] getOptedInGameModes();
+    method @NonNull public int[] getOverriddenGameModes();
     method public boolean isDownscalingAllowed();
     method public boolean isFpsOverrideAllowed();
     method public void writeToParcel(@NonNull android.os.Parcel, int);
@@ -860,7 +867,7 @@
     method @NonNull public android.app.GameModeInfo.Builder setDownscalingAllowed(boolean);
     method @NonNull public android.app.GameModeInfo.Builder setFpsOverrideAllowed(boolean);
     method @NonNull public android.app.GameModeInfo.Builder setGameModeConfiguration(int, @NonNull android.app.GameModeConfiguration);
-    method @NonNull public android.app.GameModeInfo.Builder setOptedInGameModes(@NonNull int[]);
+    method @NonNull public android.app.GameModeInfo.Builder setOverriddenGameModes(@NonNull int[]);
   }
 
   public abstract class InstantAppResolverService extends android.app.Service {
@@ -2993,6 +3000,7 @@
     method @Deprecated @NonNull @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public android.hardware.input.VirtualKeyboard createVirtualKeyboard(@NonNull android.hardware.display.VirtualDisplay, @NonNull String, int, int);
     method @NonNull @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public android.hardware.input.VirtualMouse createVirtualMouse(@NonNull android.hardware.input.VirtualMouseConfig);
     method @Deprecated @NonNull @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public android.hardware.input.VirtualMouse createVirtualMouse(@NonNull android.hardware.display.VirtualDisplay, @NonNull String, int, int);
+    method @NonNull @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public android.hardware.input.VirtualNavigationTouchpad createVirtualNavigationTouchpad(@NonNull android.hardware.input.VirtualNavigationTouchpadConfig);
     method @NonNull @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public android.hardware.input.VirtualTouchscreen createVirtualTouchscreen(@NonNull android.hardware.input.VirtualTouchscreenConfig);
     method @Deprecated @NonNull @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public android.hardware.input.VirtualTouchscreen createVirtualTouchscreen(@NonNull android.hardware.display.VirtualDisplay, @NonNull String, int, int);
     method public int getDeviceId();
@@ -3285,6 +3293,7 @@
     field public static final String ACTION_QUERY_PACKAGE_RESTART = "android.intent.action.QUERY_PACKAGE_RESTART";
     field public static final String ACTION_RESOLVE_INSTANT_APP_PACKAGE = "android.intent.action.RESOLVE_INSTANT_APP_PACKAGE";
     field @RequiresPermission(android.Manifest.permission.REVIEW_ACCESSIBILITY_SERVICES) public static final String ACTION_REVIEW_ACCESSIBILITY_SERVICES = "android.intent.action.REVIEW_ACCESSIBILITY_SERVICES";
+    field @RequiresPermission(android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS) public static final String ACTION_REVIEW_APP_DATA_SHARING_UPDATES = "android.intent.action.REVIEW_APP_DATA_SHARING_UPDATES";
     field @RequiresPermission(android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS) public static final String ACTION_REVIEW_ONGOING_PERMISSION_USAGE = "android.intent.action.REVIEW_ONGOING_PERMISSION_USAGE";
     field public static final String ACTION_REVIEW_PERMISSIONS = "android.intent.action.REVIEW_PERMISSIONS";
     field @RequiresPermission(android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS) public static final String ACTION_REVIEW_PERMISSION_HISTORY = "android.intent.action.REVIEW_PERMISSION_HISTORY";
@@ -3312,7 +3321,6 @@
     field public static final String EXTRA_INSTANT_APP_TOKEN = "android.intent.extra.INSTANT_APP_TOKEN";
     field public static final String EXTRA_LONG_VERSION_CODE = "android.intent.extra.LONG_VERSION_CODE";
     field public static final String EXTRA_ORIGINATING_UID = "android.intent.extra.ORIGINATING_UID";
-    field public static final String EXTRA_PACKAGES = "android.intent.extra.PACKAGES";
     field public static final String EXTRA_PERMISSION_NAME = "android.intent.extra.PERMISSION_NAME";
     field public static final String EXTRA_REASON = "android.intent.extra.REASON";
     field public static final String EXTRA_REMOTE_CALLBACK = "android.intent.extra.REMOTE_CALLBACK";
@@ -3772,6 +3780,7 @@
     field @Deprecated public static final int PROTECTION_FLAG_DOCUMENTER = 262144; // 0x40000
     field public static final int PROTECTION_FLAG_INCIDENT_REPORT_APPROVER = 1048576; // 0x100000
     field public static final int PROTECTION_FLAG_KNOWN_SIGNER = 134217728; // 0x8000000
+    field public static final int PROTECTION_FLAG_MODULE = 4194304; // 0x400000
     field public static final int PROTECTION_FLAG_OEM = 16384; // 0x4000
     field public static final int PROTECTION_FLAG_RECENTS = 33554432; // 0x2000000
     field public static final int PROTECTION_FLAG_RETAIL_DEMO = 16777216; // 0x1000000
@@ -4776,6 +4785,24 @@
     method @NonNull public android.hardware.input.VirtualMouseScrollEvent.Builder setYAxisMovement(@FloatRange(from=-1.0F, to=1.0f) float);
   }
 
+  public class VirtualNavigationTouchpad implements java.io.Closeable {
+    method @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public void close();
+    method @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public void sendTouchEvent(@NonNull android.hardware.input.VirtualTouchEvent);
+  }
+
+  public final class VirtualNavigationTouchpadConfig extends android.hardware.input.VirtualInputDeviceConfig implements android.os.Parcelable {
+    method public int describeContents();
+    method public int getHeight();
+    method public int getWidth();
+    method public void writeToParcel(@NonNull android.os.Parcel, int);
+    field @NonNull public static final android.os.Parcelable.Creator<android.hardware.input.VirtualNavigationTouchpadConfig> CREATOR;
+  }
+
+  public static final class VirtualNavigationTouchpadConfig.Builder extends android.hardware.input.VirtualInputDeviceConfig.Builder<android.hardware.input.VirtualNavigationTouchpadConfig.Builder> {
+    ctor public VirtualNavigationTouchpadConfig.Builder(@IntRange(from=1) int, @IntRange(from=1) int);
+    method @NonNull public android.hardware.input.VirtualNavigationTouchpadConfig build();
+  }
+
   public final class VirtualTouchEvent implements android.os.Parcelable {
     method public int describeContents();
     method public int getAction();
@@ -5267,11 +5294,12 @@
     method public void writeToParcel(android.os.Parcel, int);
     field @NonNull public static final android.os.Parcelable.Creator<android.hardware.radio.ProgramSelector> CREATOR;
     field public static final int IDENTIFIER_TYPE_AMFM_FREQUENCY = 1; // 0x1
+    field public static final int IDENTIFIER_TYPE_DAB_DMB_SID_EXT = 14; // 0xe
     field public static final int IDENTIFIER_TYPE_DAB_ENSEMBLE = 6; // 0x6
     field public static final int IDENTIFIER_TYPE_DAB_FREQUENCY = 8; // 0x8
     field public static final int IDENTIFIER_TYPE_DAB_SCID = 7; // 0x7
-    field public static final int IDENTIFIER_TYPE_DAB_SIDECC = 5; // 0x5
-    field public static final int IDENTIFIER_TYPE_DAB_SID_EXT = 5; // 0x5
+    field @Deprecated public static final int IDENTIFIER_TYPE_DAB_SIDECC = 5; // 0x5
+    field @Deprecated public static final int IDENTIFIER_TYPE_DAB_SID_EXT = 5; // 0x5
     field public static final int IDENTIFIER_TYPE_DRMO_FREQUENCY = 10; // 0xa
     field @Deprecated public static final int IDENTIFIER_TYPE_DRMO_MODULATION = 11; // 0xb
     field public static final int IDENTIFIER_TYPE_DRMO_SERVICE_ID = 9; // 0x9
@@ -5308,7 +5336,7 @@
     field @NonNull public static final android.os.Parcelable.Creator<android.hardware.radio.ProgramSelector.Identifier> CREATOR;
   }
 
-  @IntDef(prefix={"IDENTIFIER_TYPE_"}, value={android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_INVALID, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_AMFM_FREQUENCY, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_RDS_PI, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_HD_STATION_ID_EXT, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_HD_SUBCHANNEL, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_HD_STATION_NAME, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_DAB_SID_EXT, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_DAB_SIDECC, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_DAB_ENSEMBLE, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_DAB_SCID, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_DAB_FREQUENCY, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_DRMO_SERVICE_ID, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_DRMO_FREQUENCY, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_DRMO_MODULATION, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_SXM_SERVICE_ID, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_SXM_CHANNEL}) @IntRange(from=android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_VENDOR_START, to=android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_VENDOR_END) @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) public static @interface ProgramSelector.IdentifierType {
+  @IntDef(prefix={"IDENTIFIER_TYPE_"}, value={android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_INVALID, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_AMFM_FREQUENCY, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_RDS_PI, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_HD_STATION_ID_EXT, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_HD_SUBCHANNEL, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_HD_STATION_NAME, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_DAB_SID_EXT, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_DAB_SIDECC, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_DAB_ENSEMBLE, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_DAB_SCID, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_DAB_FREQUENCY, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_DRMO_SERVICE_ID, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_DRMO_FREQUENCY, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_DRMO_MODULATION, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_SXM_SERVICE_ID, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_SXM_CHANNEL, android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_DAB_DMB_SID_EXT}) @IntRange(from=android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_VENDOR_START, to=android.hardware.radio.ProgramSelector.IDENTIFIER_TYPE_VENDOR_END) @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) public static @interface ProgramSelector.IdentifierType {
   }
 
   @Deprecated @IntDef(prefix={"PROGRAM_TYPE_"}, value={android.hardware.radio.ProgramSelector.PROGRAM_TYPE_INVALID, android.hardware.radio.ProgramSelector.PROGRAM_TYPE_AM, android.hardware.radio.ProgramSelector.PROGRAM_TYPE_FM, android.hardware.radio.ProgramSelector.PROGRAM_TYPE_AM_HD, android.hardware.radio.ProgramSelector.PROGRAM_TYPE_FM_HD, android.hardware.radio.ProgramSelector.PROGRAM_TYPE_DAB, android.hardware.radio.ProgramSelector.PROGRAM_TYPE_DRMO, android.hardware.radio.ProgramSelector.PROGRAM_TYPE_SXM}) @IntRange(from=android.hardware.radio.ProgramSelector.PROGRAM_TYPE_VENDOR_START, to=android.hardware.radio.ProgramSelector.PROGRAM_TYPE_VENDOR_END) @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) public static @interface ProgramSelector.ProgramType {
@@ -5523,30 +5551,31 @@
 
   public abstract class RadioTuner {
     ctor public RadioTuner();
-    method public abstract int cancel();
-    method public abstract void cancelAnnouncement();
-    method public abstract void close();
-    method @Deprecated public abstract int getConfiguration(android.hardware.radio.RadioManager.BandConfig[]);
-    method @Nullable public android.hardware.radio.ProgramList getDynamicProgramList(@Nullable android.hardware.radio.ProgramList.Filter);
-    method public abstract boolean getMute();
-    method @NonNull public java.util.Map<java.lang.String,java.lang.String> getParameters(@NonNull java.util.List<java.lang.String>);
-    method @Deprecated public abstract int getProgramInformation(android.hardware.radio.RadioManager.ProgramInfo[]);
-    method @Deprecated @NonNull public abstract java.util.List<android.hardware.radio.RadioManager.ProgramInfo> getProgramList(@Nullable java.util.Map<java.lang.String,java.lang.String>);
-    method public abstract boolean hasControl();
-    method @Deprecated public abstract boolean isAnalogForced();
-    method @Deprecated public abstract boolean isAntennaConnected();
-    method public boolean isConfigFlagSet(int);
-    method public boolean isConfigFlagSupported(int);
-    method public abstract int scan(int, boolean);
-    method @Deprecated public abstract void setAnalogForced(boolean);
-    method public void setConfigFlag(int, boolean);
-    method @Deprecated public abstract int setConfiguration(android.hardware.radio.RadioManager.BandConfig);
-    method public abstract int setMute(boolean);
-    method @NonNull public java.util.Map<java.lang.String,java.lang.String> setParameters(@NonNull java.util.Map<java.lang.String,java.lang.String>);
-    method public abstract boolean startBackgroundScan();
-    method public abstract int step(int, boolean);
-    method @Deprecated public abstract int tune(int, int);
-    method public abstract void tune(@NonNull android.hardware.radio.ProgramSelector);
+    method @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract int cancel();
+    method @Deprecated @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract void cancelAnnouncement();
+    method @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract void close();
+    method @Deprecated @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract int getConfiguration(android.hardware.radio.RadioManager.BandConfig[]);
+    method @Nullable @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public android.hardware.radio.ProgramList getDynamicProgramList(@Nullable android.hardware.radio.ProgramList.Filter);
+    method @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract boolean getMute();
+    method @NonNull @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public java.util.Map<java.lang.String,java.lang.String> getParameters(@NonNull java.util.List<java.lang.String>);
+    method @Deprecated @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract int getProgramInformation(android.hardware.radio.RadioManager.ProgramInfo[]);
+    method @Deprecated @NonNull @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract java.util.List<android.hardware.radio.RadioManager.ProgramInfo> getProgramList(@Nullable java.util.Map<java.lang.String,java.lang.String>);
+    method @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract boolean hasControl();
+    method @Deprecated @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract boolean isAnalogForced();
+    method @Deprecated @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract boolean isAntennaConnected();
+    method @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public boolean isConfigFlagSet(int);
+    method @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public boolean isConfigFlagSupported(int);
+    method @Deprecated @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract int scan(int, boolean);
+    method @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public int seek(int, boolean);
+    method @Deprecated @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract void setAnalogForced(boolean);
+    method @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public void setConfigFlag(int, boolean);
+    method @Deprecated @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract int setConfiguration(android.hardware.radio.RadioManager.BandConfig);
+    method @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract int setMute(boolean);
+    method @NonNull @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public java.util.Map<java.lang.String,java.lang.String> setParameters(@NonNull java.util.Map<java.lang.String,java.lang.String>);
+    method @Deprecated @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract boolean startBackgroundScan();
+    method @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract int step(int, boolean);
+    method @Deprecated @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract int tune(int, int);
+    method @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RADIO) public abstract void tune(@NonNull android.hardware.radio.ProgramSelector);
     field public static final int DIRECTION_DOWN = 1; // 0x1
     field public static final int DIRECTION_UP = 0; // 0x0
     field @Deprecated public static final int ERROR_BACKGROUND_SCAN_FAILED = 6; // 0x6
@@ -5556,6 +5585,14 @@
     field @Deprecated public static final int ERROR_HARDWARE_FAILURE = 0; // 0x0
     field @Deprecated public static final int ERROR_SCAN_TIMEOUT = 3; // 0x3
     field @Deprecated public static final int ERROR_SERVER_DIED = 1; // 0x1
+    field public static final int TUNER_RESULT_CANCELED = 6; // 0x6
+    field public static final int TUNER_RESULT_INTERNAL_ERROR = 1; // 0x1
+    field public static final int TUNER_RESULT_INVALID_ARGUMENTS = 2; // 0x2
+    field public static final int TUNER_RESULT_INVALID_STATE = 3; // 0x3
+    field public static final int TUNER_RESULT_NOT_SUPPORTED = 4; // 0x4
+    field public static final int TUNER_RESULT_OK = 0; // 0x0
+    field public static final int TUNER_RESULT_TIMEOUT = 5; // 0x5
+    field public static final int TUNER_RESULT_UNKNOWN_ERROR = 7; // 0x7
   }
 
   public abstract static class RadioTuner.Callback {
@@ -5563,6 +5600,7 @@
     method public void onAntennaState(boolean);
     method public void onBackgroundScanAvailabilityChange(boolean);
     method public void onBackgroundScanComplete();
+    method public void onConfigFlagUpdated(int, boolean);
     method @Deprecated public void onConfigurationChanged(android.hardware.radio.RadioManager.BandConfig);
     method public void onControlChanged(boolean);
     method public void onEmergencyAnnouncement(boolean);
@@ -5803,8 +5841,9 @@
   }
 
   public final class Country implements android.os.Parcelable {
+    ctor public Country(@NonNull String, int);
     method public int describeContents();
-    method @NonNull public String getCountryIso();
+    method @NonNull public String getCountryCode();
     method public int getSource();
     method public void writeToParcel(@NonNull android.os.Parcel, int);
     field public static final int COUNTRY_SOURCE_LOCALE = 3; // 0x3
@@ -5815,13 +5854,8 @@
   }
 
   public class CountryDetector {
-    method public void addCountryListener(@NonNull android.location.CountryListener, @Nullable android.os.Looper);
-    method @Nullable public android.location.Country detectCountry();
-    method public void removeCountryListener(@NonNull android.location.CountryListener);
-  }
-
-  public interface CountryListener {
-    method public void onCountryDetected(@NonNull android.location.Country);
+    method public void registerCountryDetectorCallback(@NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<android.location.Country>);
+    method public void unregisterCountryDetectorCallback(@NonNull java.util.function.Consumer<android.location.Country>);
   }
 
   public final class GnssCapabilities implements android.os.Parcelable {
@@ -6249,6 +6283,7 @@
     method @Deprecated @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public boolean unregisterGnssBatchedLocationCallback(@NonNull android.location.BatchedLocationCallback);
     field public static final String ACTION_ADAS_GNSS_ENABLED_CHANGED = "android.location.action.ADAS_GNSS_ENABLED_CHANGED";
     field public static final String EXTRA_ADAS_GNSS_ENABLED = "android.location.extra.ADAS_GNSS_ENABLED";
+    field @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public static final String GPS_HARDWARE_PROVIDER = "gps_hardware";
   }
 
   public final class LocationRequest implements android.os.Parcelable {
@@ -6388,6 +6423,7 @@
     method public void setAllowed(boolean);
     method public void setProperties(@NonNull android.location.provider.ProviderProperties);
     field public static final String ACTION_FUSED_PROVIDER = "com.android.location.service.FusedLocationProvider";
+    field public static final String ACTION_GNSS_PROVIDER = "android.location.provider.action.GNSS_PROVIDER";
     field public static final String ACTION_NETWORK_PROVIDER = "com.android.location.service.v3.NetworkLocationProvider";
   }
 
@@ -9698,6 +9734,8 @@
   }
 
   public class Environment {
+    method @NonNull public static java.io.File getDataCePackageDirectoryForUser(@NonNull java.util.UUID, @NonNull android.os.UserHandle, @NonNull String);
+    method @NonNull public static java.io.File getDataDePackageDirectoryForUser(@NonNull java.util.UUID, @NonNull android.os.UserHandle, @NonNull String);
     method @NonNull public static java.util.Collection<java.io.File> getInternalMediaDirectories();
     method @NonNull public static java.io.File getOdmDirectory();
     method @NonNull public static java.io.File getOemDirectory();
@@ -10224,7 +10262,7 @@
     method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.GET_ACCOUNTS_PRIVILEGED}) public android.graphics.Bitmap getUserIcon();
     method @Deprecated @android.os.UserManager.UserRestrictionSource @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.QUERY_USERS}) public int getUserRestrictionSource(String, android.os.UserHandle);
     method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.QUERY_USERS}) public java.util.List<android.os.UserManager.EnforcingUser> getUserRestrictionSources(String, android.os.UserHandle);
-    method @RequiresPermission(allOf={android.Manifest.permission.READ_PHONE_STATE, android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional=true) public int getUserSwitchability();
+    method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS}) public int getUserSwitchability();
     method @NonNull @RequiresPermission(anyOf={"android.permission.INTERACT_ACROSS_USERS", "android.permission.MANAGE_USERS"}) public java.util.Set<android.os.UserHandle> getVisibleUsers();
     method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public boolean hasRestrictedProfiles();
     method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional=true) public boolean hasUserRestrictionForUser(@NonNull String, @NonNull android.os.UserHandle);
@@ -10706,121 +10744,6 @@
     method @RequiresPermission("android.contacts.permission.MANAGE_SIM_ACCOUNTS") public static void removeSimAccounts(@NonNull android.content.ContentResolver, int);
   }
 
-  public final class DeviceConfig {
-    method public static void addOnPropertiesChangedListener(@NonNull String, @NonNull java.util.concurrent.Executor, @NonNull android.provider.DeviceConfig.OnPropertiesChangedListener);
-    method @RequiresPermission(android.Manifest.permission.WRITE_DEVICE_CONFIG) public static boolean deleteProperty(@NonNull String, @NonNull String);
-    method @RequiresPermission(android.Manifest.permission.READ_DEVICE_CONFIG) public static boolean getBoolean(@NonNull String, @NonNull String, boolean);
-    method @RequiresPermission(android.Manifest.permission.READ_DEVICE_CONFIG) public static float getFloat(@NonNull String, @NonNull String, float);
-    method @RequiresPermission(android.Manifest.permission.READ_DEVICE_CONFIG) public static int getInt(@NonNull String, @NonNull String, int);
-    method @RequiresPermission(android.Manifest.permission.READ_DEVICE_CONFIG) public static long getLong(@NonNull String, @NonNull String, long);
-    method @NonNull @RequiresPermission(android.Manifest.permission.READ_DEVICE_CONFIG) public static android.provider.DeviceConfig.Properties getProperties(@NonNull String, @NonNull java.lang.String...);
-    method @RequiresPermission(android.Manifest.permission.READ_DEVICE_CONFIG) public static String getProperty(@NonNull String, @NonNull String);
-    method @NonNull public static java.util.List<java.lang.String> getPublicNamespaces();
-    method @RequiresPermission(android.Manifest.permission.READ_DEVICE_CONFIG) public static String getString(@NonNull String, @NonNull String, @Nullable String);
-    method @RequiresPermission(android.Manifest.permission.WRITE_DEVICE_CONFIG) public static int getSyncDisabledMode();
-    method public static void removeOnPropertiesChangedListener(@NonNull android.provider.DeviceConfig.OnPropertiesChangedListener);
-    method @RequiresPermission(android.Manifest.permission.WRITE_DEVICE_CONFIG) public static void resetToDefaults(int, @Nullable String);
-    method @RequiresPermission(android.Manifest.permission.WRITE_DEVICE_CONFIG) public static boolean setProperties(@NonNull android.provider.DeviceConfig.Properties) throws android.provider.DeviceConfig.BadConfigException;
-    method @RequiresPermission(android.Manifest.permission.WRITE_DEVICE_CONFIG) public static boolean setProperty(@NonNull String, @NonNull String, @Nullable String, boolean);
-    method @RequiresPermission(android.Manifest.permission.WRITE_DEVICE_CONFIG) public static void setSyncDisabledMode(int);
-    field public static final String NAMESPACE_ACTIVITY_MANAGER = "activity_manager";
-    field public static final String NAMESPACE_ACTIVITY_MANAGER_NATIVE_BOOT = "activity_manager_native_boot";
-    field public static final String NAMESPACE_ADSERVICES = "adservices";
-    field public static final String NAMESPACE_AMBIENT_CONTEXT_MANAGER_SERVICE = "ambient_context_manager_service";
-    field public static final String NAMESPACE_ANDROID = "android";
-    field public static final String NAMESPACE_APPSEARCH = "appsearch";
-    field public static final String NAMESPACE_APP_COMPAT = "app_compat";
-    field public static final String NAMESPACE_APP_COMPAT_OVERRIDES = "app_compat_overrides";
-    field public static final String NAMESPACE_APP_HIBERNATION = "app_hibernation";
-    field public static final String NAMESPACE_ATTENTION_MANAGER_SERVICE = "attention_manager_service";
-    field public static final String NAMESPACE_AUTOFILL = "autofill";
-    field public static final String NAMESPACE_BACKUP_AND_RESTORE = "backup_and_restore";
-    field public static final String NAMESPACE_BATTERY_SAVER = "battery_saver";
-    field public static final String NAMESPACE_BIOMETRICS = "biometrics";
-    field public static final String NAMESPACE_BLOBSTORE = "blobstore";
-    field public static final String NAMESPACE_BLUETOOTH = "bluetooth";
-    field public static final String NAMESPACE_CAPTIVEPORTALLOGIN = "captive_portal_login";
-    field public static final String NAMESPACE_CLIPBOARD = "clipboard";
-    field public static final String NAMESPACE_CONNECTIVITY = "connectivity";
-    field public static final String NAMESPACE_CONSTRAIN_DISPLAY_APIS = "constrain_display_apis";
-    field public static final String NAMESPACE_CONTENT_CAPTURE = "content_capture";
-    field @Deprecated public static final String NAMESPACE_DEX_BOOT = "dex_boot";
-    field public static final String NAMESPACE_DISPLAY_MANAGER = "display_manager";
-    field public static final String NAMESPACE_GAME_DRIVER = "game_driver";
-    field public static final String NAMESPACE_HDMI_CONTROL = "hdmi_control";
-    field public static final String NAMESPACE_INPUT_METHOD_MANAGER = "input_method_manager";
-    field public static final String NAMESPACE_INPUT_NATIVE_BOOT = "input_native_boot";
-    field public static final String NAMESPACE_INTELLIGENCE_ATTENTION = "intelligence_attention";
-    field public static final String NAMESPACE_JOB_SCHEDULER = "jobscheduler";
-    field public static final String NAMESPACE_LMKD_NATIVE = "lmkd_native";
-    field public static final String NAMESPACE_LOCATION = "location";
-    field public static final String NAMESPACE_MEDIA = "media";
-    field public static final String NAMESPACE_MEDIA_NATIVE = "media_native";
-    field public static final String NAMESPACE_NEARBY = "nearby";
-    field public static final String NAMESPACE_NETD_NATIVE = "netd_native";
-    field public static final String NAMESPACE_NNAPI_NATIVE = "nnapi_native";
-    field public static final String NAMESPACE_ON_DEVICE_PERSONALIZATION = "on_device_personalization";
-    field public static final String NAMESPACE_OTA = "ota";
-    field public static final String NAMESPACE_PACKAGE_MANAGER_SERVICE = "package_manager_service";
-    field public static final String NAMESPACE_PERMISSIONS = "permissions";
-    field public static final String NAMESPACE_PRIVACY = "privacy";
-    field public static final String NAMESPACE_PROFCOLLECT_NATIVE_BOOT = "profcollect_native_boot";
-    field public static final String NAMESPACE_REBOOT_READINESS = "reboot_readiness";
-    field public static final String NAMESPACE_ROLLBACK = "rollback";
-    field public static final String NAMESPACE_ROLLBACK_BOOT = "rollback_boot";
-    field public static final String NAMESPACE_RUNTIME = "runtime";
-    field public static final String NAMESPACE_RUNTIME_NATIVE = "runtime_native";
-    field public static final String NAMESPACE_RUNTIME_NATIVE_BOOT = "runtime_native_boot";
-    field public static final String NAMESPACE_SCHEDULER = "scheduler";
-    field public static final String NAMESPACE_SDK_SANDBOX = "sdk_sandbox";
-    field public static final String NAMESPACE_SELECTION_TOOLBAR = "selection_toolbar";
-    field public static final String NAMESPACE_STATSD_JAVA = "statsd_java";
-    field public static final String NAMESPACE_STATSD_JAVA_BOOT = "statsd_java_boot";
-    field public static final String NAMESPACE_STATSD_NATIVE = "statsd_native";
-    field public static final String NAMESPACE_STATSD_NATIVE_BOOT = "statsd_native_boot";
-    field @Deprecated public static final String NAMESPACE_STORAGE = "storage";
-    field public static final String NAMESPACE_STORAGE_NATIVE_BOOT = "storage_native_boot";
-    field public static final String NAMESPACE_SURFACE_FLINGER_NATIVE_BOOT = "surface_flinger_native_boot";
-    field public static final String NAMESPACE_SWCODEC_NATIVE = "swcodec_native";
-    field public static final String NAMESPACE_SYSTEMUI = "systemui";
-    field public static final String NAMESPACE_SYSTEM_TIME = "system_time";
-    field public static final String NAMESPACE_TELEPHONY = "telephony";
-    field public static final String NAMESPACE_TETHERING = "tethering";
-    field public static final String NAMESPACE_TEXTCLASSIFIER = "textclassifier";
-    field public static final String NAMESPACE_TRANSPARENCY_METADATA = "transparency_metadata";
-    field public static final String NAMESPACE_UWB = "uwb";
-    field public static final String NAMESPACE_WEARABLE_SENSING = "wearable_sensing";
-    field public static final String NAMESPACE_WINDOW_MANAGER_NATIVE_BOOT = "window_manager_native_boot";
-  }
-
-  public static class DeviceConfig.BadConfigException extends java.lang.Exception {
-    ctor public DeviceConfig.BadConfigException();
-  }
-
-  public static interface DeviceConfig.OnPropertiesChangedListener {
-    method public void onPropertiesChanged(@NonNull android.provider.DeviceConfig.Properties);
-  }
-
-  public static class DeviceConfig.Properties {
-    method public boolean getBoolean(@NonNull String, boolean);
-    method public float getFloat(@NonNull String, float);
-    method public int getInt(@NonNull String, int);
-    method @NonNull public java.util.Set<java.lang.String> getKeyset();
-    method public long getLong(@NonNull String, long);
-    method @NonNull public String getNamespace();
-    method @Nullable public String getString(@NonNull String, @Nullable String);
-  }
-
-  public static final class DeviceConfig.Properties.Builder {
-    ctor public DeviceConfig.Properties.Builder(@NonNull String);
-    method @NonNull public android.provider.DeviceConfig.Properties build();
-    method @NonNull public android.provider.DeviceConfig.Properties.Builder setBoolean(@NonNull String, boolean);
-    method @NonNull public android.provider.DeviceConfig.Properties.Builder setFloat(@NonNull String, float);
-    method @NonNull public android.provider.DeviceConfig.Properties.Builder setInt(@NonNull String, int);
-    method @NonNull public android.provider.DeviceConfig.Properties.Builder setLong(@NonNull String, long);
-    method @NonNull public android.provider.DeviceConfig.Properties.Builder setString(@NonNull String, @Nullable String);
-  }
-
   public final class DocumentsContract {
     method @NonNull public static android.net.Uri buildDocumentUriAsUser(@NonNull String, @NonNull String, @NonNull android.os.UserHandle);
     method public static boolean isManageMode(@NonNull android.net.Uri);
@@ -10990,6 +10913,7 @@
     field public static final String INSTALL_CARRIER_APP_NOTIFICATION_SLEEP_MILLIS = "install_carrier_app_notification_sleep_millis";
     field public static final String OTA_DISABLE_AUTOMATIC_UPDATE = "ota_disable_automatic_update";
     field public static final String REQUIRE_PASSWORD_TO_DECRYPT = "require_password_to_decrypt";
+    field public static final String SECURE_FRP_MODE = "secure_frp_mode";
     field public static final String TETHER_OFFLOAD_DISABLED = "tether_offload_disabled";
     field public static final String TETHER_SUPPORTED = "tether_supported";
     field public static final String THEATER_MODE_ON = "theater_mode_on";
@@ -15616,6 +15540,16 @@
     method public void onPublishStateChange(int);
   }
 
+  public interface RegistrationManager {
+    field public static final int SUGGESTED_ACTION_NONE = 0; // 0x0
+    field public static final int SUGGESTED_ACTION_TRIGGER_PLMN_BLOCK = 1; // 0x1
+    field public static final int SUGGESTED_ACTION_TRIGGER_PLMN_BLOCK_WITH_TIMEOUT = 2; // 0x2
+  }
+
+  public static class RegistrationManager.RegistrationCallback {
+    method public void onUnregistered(@NonNull android.telephony.ims.ImsReasonInfo, int);
+  }
+
   public final class RtpHeaderExtension implements android.os.Parcelable {
     ctor public RtpHeaderExtension(@IntRange(from=1, to=14) int, @NonNull byte[]);
     method public int describeContents();
@@ -15834,9 +15768,12 @@
     method public void onFeatureRemoved();
     method public boolean queryCapabilityConfiguration(int, int);
     method @NonNull public final android.telephony.ims.feature.MmTelFeature.MmTelCapabilities queryCapabilityStatus();
+    method public final void setCallAudioHandler(int);
     method public void setTerminalBasedCallWaitingStatus(boolean);
     method public void setUiTtyMode(int, @Nullable android.os.Message);
     method public int shouldProcessCall(@NonNull String[]);
+    field public static final int AUDIO_HANDLER_ANDROID = 0; // 0x0
+    field public static final int AUDIO_HANDLER_BASEBAND = 1; // 0x1
     field public static final String EXTRA_IS_UNKNOWN_CALL = "android.telephony.ims.feature.extra.IS_UNKNOWN_CALL";
     field public static final String EXTRA_IS_USSD = "android.telephony.ims.feature.extra.IS_USSD";
     field public static final int PROCESS_CALL_CSFB = 1; // 0x1
@@ -16012,6 +15949,7 @@
     ctor public ImsRegistrationImplBase();
     ctor public ImsRegistrationImplBase(@NonNull java.util.concurrent.Executor);
     method public final void onDeregistered(android.telephony.ims.ImsReasonInfo);
+    method public final void onDeregistered(@Nullable android.telephony.ims.ImsReasonInfo, int);
     method public final void onRegistered(int);
     method public final void onRegistered(@NonNull android.telephony.ims.ImsRegistrationAttributes);
     method public final void onRegistering(int);
@@ -16029,6 +15967,7 @@
     method public void acknowledgeSms(int, @IntRange(from=0, to=65535) int, int, @NonNull byte[]);
     method public void acknowledgeSmsReport(int, @IntRange(from=0, to=65535) int, int);
     method public String getSmsFormat();
+    method public void onMemoryAvailable(int);
     method public void onReady();
     method @Deprecated public final void onSendSmsResult(int, @IntRange(from=0, to=65535) int, int, int) throws java.lang.RuntimeException;
     method public final void onSendSmsResultError(int, @IntRange(from=0, to=65535) int, int, int, int) throws java.lang.RuntimeException;
diff --git a/core/api/system-lint-baseline.txt b/core/api/system-lint-baseline.txt
index 47588d9..025e862 100644
--- a/core/api/system-lint-baseline.txt
+++ b/core/api/system-lint-baseline.txt
@@ -3,10 +3,6 @@
     Method should return Collection<CharSequence> (or subclass) instead of raw array; was `java.lang.CharSequence[]`
 
 
-ExecutorRegistration: android.location.CountryDetector#addCountryListener(android.location.CountryListener, android.os.Looper):
-    Registration methods should have overload that accepts delivery Executor: `addCountryListener`
-
-
 GenericException: android.app.prediction.AppPredictor#finalize():
     Methods must not throw generic exceptions (`java.lang.Throwable`)
 GenericException: android.hardware.location.ContextHubClient#finalize():
@@ -131,8 +127,6 @@
     SAM-compatible parameters (such as parameter 1, "pw", in android.content.pm.PackageItemInfo.dumpFront) should be last to improve Kotlin interoperability; see https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions
 SamShouldBeLast: android.content.pm.ResolveInfo#dump(android.util.Printer, String):
     SAM-compatible parameters (such as parameter 1, "pw", in android.content.pm.ResolveInfo.dump) should be last to improve Kotlin interoperability; see https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions
-SamShouldBeLast: android.location.CountryDetector#addCountryListener(android.location.CountryListener, android.os.Looper):
-    SAM-compatible parameters (such as parameter 1, "listener", in android.location.CountryDetector.addCountryListener) should be last to improve Kotlin interoperability; see https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions
 SamShouldBeLast: android.location.Location#dump(android.util.Printer, String):
     SAM-compatible parameters (such as parameter 1, "pw", in android.location.Location.dump) should be last to improve Kotlin interoperability; see https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions
 SamShouldBeLast: android.location.LocationManager#addNmeaListener(android.location.OnNmeaMessageListener, android.os.Handler):
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index 43d4530..5e02e72 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -38,6 +38,7 @@
     field public static final String READ_CELL_BROADCASTS = "android.permission.READ_CELL_BROADCASTS";
     field public static final String READ_PRIVILEGED_PHONE_STATE = "android.permission.READ_PRIVILEGED_PHONE_STATE";
     field public static final String RECORD_BACKGROUND_AUDIO = "android.permission.RECORD_BACKGROUND_AUDIO";
+    field public static final String REMAP_MODIFIER_KEYS = "android.permission.REMAP_MODIFIER_KEYS";
     field public static final String REMOVE_TASKS = "android.permission.REMOVE_TASKS";
     field public static final String REQUEST_UNIQUE_ID_ATTESTATION = "android.permission.REQUEST_UNIQUE_ID_ATTESTATION";
     field public static final String RESET_APP_ERRORS = "android.permission.RESET_APP_ERRORS";
@@ -512,7 +513,7 @@
     method @RequiresPermission(android.Manifest.permission.FORCE_DEVICE_POLICY_MANAGER_LOGS) public long forceSecurityLogs();
     method public void forceUpdateUserSetupComplete(int);
     method @NonNull public java.util.Set<java.lang.String> getDefaultCrossProfilePackages();
-    method public int getDeviceOwnerType(@NonNull android.content.ComponentName);
+    method @Deprecated public int getDeviceOwnerType(@NonNull android.content.ComponentName);
     method @Nullable public String getDevicePolicyManagementRoleHolderUpdaterPackage();
     method @NonNull public java.util.Set<java.lang.String> getDisallowedSystemApps(@NonNull android.content.ComponentName, int, @NonNull String);
     method public long getLastBugReportRequestTime();
@@ -1157,6 +1158,7 @@
   public final class CameraManager {
     method public String[] getCameraIdListNoLazy() throws android.hardware.camera2.CameraAccessException;
     method @RequiresPermission(allOf={android.Manifest.permission.SYSTEM_CAMERA, android.Manifest.permission.CAMERA}) public void openCamera(@NonNull String, int, @NonNull java.util.concurrent.Executor, @NonNull android.hardware.camera2.CameraDevice.StateCallback) throws android.hardware.camera2.CameraAccessException;
+    field public static final long OVERRIDE_FRONT_CAMERA_APP_COMPAT = 250678880L; // 0xef10e60L
   }
 
   public abstract static class CameraManager.AvailabilityCallback {
@@ -1294,8 +1296,11 @@
 
   public final class InputManager {
     method public void addUniqueIdAssociation(@NonNull String, @NonNull String);
+    method @RequiresPermission(android.Manifest.permission.REMAP_MODIFIER_KEYS) public void clearAllModifierKeyRemappings();
     method @Nullable public String getCurrentKeyboardLayoutForInputDevice(@NonNull android.hardware.input.InputDeviceIdentifier);
     method @NonNull public java.util.List<java.lang.String> getKeyboardLayoutDescriptorsForInputDevice(@NonNull android.view.InputDevice);
+    method @NonNull @RequiresPermission(android.Manifest.permission.REMAP_MODIFIER_KEYS) public java.util.Map<java.lang.Integer,java.lang.Integer> getModifierKeyRemapping();
+    method @RequiresPermission(android.Manifest.permission.REMAP_MODIFIER_KEYS) public void remapModifierKey(int, int);
     method @RequiresPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT) public void removeKeyboardLayoutForInputDevice(@NonNull android.hardware.input.InputDeviceIdentifier, @NonNull String);
     method public void removeUniqueIdAssociation(@NonNull String);
     method @RequiresPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT) public void setCurrentKeyboardLayoutForInputDevice(@NonNull android.hardware.input.InputDeviceIdentifier, @NonNull String);
@@ -2066,7 +2071,7 @@
 
   public class StorageManager {
     method public long computeStorageCacheBytes(@NonNull java.io.File);
-    method @NonNull public static java.util.UUID convert(@NonNull String);
+    method @NonNull public static java.util.UUID convert(@Nullable String);
     method @NonNull public static String convert(@NonNull java.util.UUID);
     method @Nullable public String getCloudMediaProvider();
     method public boolean isAppIoBlocked(@NonNull java.util.UUID, int, int, int);
@@ -2633,6 +2638,8 @@
 
   public final class SmsManager {
     method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public int checkSmsShortCodeDestination(String, String);
+    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void clearStorageMonitorMemoryStatusOverride();
+    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setStorageMonitorMemoryStatusOverride(boolean);
     field public static final int SMS_CATEGORY_FREE_SHORT_CODE = 1; // 0x1
     field public static final int SMS_CATEGORY_NOT_SHORT_CODE = 0; // 0x0
     field public static final int SMS_CATEGORY_POSSIBLE_PREMIUM_SHORT_CODE = 3; // 0x3
@@ -2923,7 +2930,7 @@
     method public static String actionToString(int);
     method public final void setDisplayId(int);
     field public static final int FLAG_IS_ACCESSIBILITY_EVENT = 2048; // 0x800
-    field public static final int LAST_KEYCODE = 311; // 0x137
+    field public static final int LAST_KEYCODE = 312; // 0x138
   }
 
   public final class KeyboardShortcutGroup implements android.os.Parcelable {
@@ -2937,6 +2944,7 @@
   }
 
   public final class MotionEvent extends android.view.InputEvent implements android.os.Parcelable {
+    method public int getDisplayId();
     method public void setActionButton(int);
     method public void setButtonState(int);
     method public void setDisplayId(int);
@@ -3429,14 +3437,20 @@
 
   public class TaskFragmentOrganizer extends android.window.WindowOrganizer {
     ctor public TaskFragmentOrganizer(@NonNull java.util.concurrent.Executor);
+    method public void applyTransaction(@NonNull android.window.WindowContainerTransaction, int, boolean);
     method @NonNull public java.util.concurrent.Executor getExecutor();
     method @NonNull public android.window.TaskFragmentOrganizerToken getOrganizerToken();
+    method public void onTransactionHandled(@NonNull android.os.IBinder, @NonNull android.window.WindowContainerTransaction, int, boolean);
     method public void onTransactionReady(@NonNull android.window.TaskFragmentTransaction);
     method @CallSuper public void registerOrganizer();
     method @CallSuper public void unregisterOrganizer();
     field public static final String KEY_ERROR_CALLBACK_OP_TYPE = "operation_type";
     field public static final String KEY_ERROR_CALLBACK_TASK_FRAGMENT_INFO = "task_fragment_info";
     field public static final String KEY_ERROR_CALLBACK_THROWABLE = "fragment_throwable";
+    field public static final int TASK_FRAGMENT_TRANSIT_CHANGE = 6; // 0x6
+    field public static final int TASK_FRAGMENT_TRANSIT_CLOSE = 2; // 0x2
+    field public static final int TASK_FRAGMENT_TRANSIT_NONE = 0; // 0x0
+    field public static final int TASK_FRAGMENT_TRANSIT_OPEN = 1; // 0x1
   }
 
   public final class TaskFragmentOrganizerToken implements android.os.Parcelable {
@@ -3558,8 +3572,8 @@
 
   public class WindowOrganizer {
     ctor public WindowOrganizer();
-    method @RequiresPermission(value=android.Manifest.permission.MANAGE_ACTIVITY_TASKS, conditional=true) public int applySyncTransaction(@NonNull android.window.WindowContainerTransaction, @NonNull android.window.WindowContainerTransactionCallback);
-    method @RequiresPermission(value=android.Manifest.permission.MANAGE_ACTIVITY_TASKS, conditional=true) public void applyTransaction(@NonNull android.window.WindowContainerTransaction);
+    method @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) public int applySyncTransaction(@NonNull android.window.WindowContainerTransaction, @NonNull android.window.WindowContainerTransactionCallback);
+    method @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) public void applyTransaction(@NonNull android.window.WindowContainerTransaction);
   }
 
   @UiContext public abstract class WindowProviderService extends android.app.Service {
diff --git a/core/java/Android.bp b/core/java/Android.bp
index 128e3de..738e2de 100644
--- a/core/java/Android.bp
+++ b/core/java/Android.bp
@@ -368,6 +368,20 @@
     },
 }
 
+// Build Rust bindings for remote provisioning. Needed by keystore2.
+aidl_interface {
+    name: "android.security.rkp_aidl",
+    unstable: true,
+    srcs: [
+        "android/security/rkp/*.aidl",
+    ],
+    backend: {
+        rust: {
+            enabled: true,
+        },
+    },
+}
+
 aidl_interface {
     name: "android.debug_aidl",
     unstable: true,
diff --git a/core/java/android/animation/Animator.java b/core/java/android/animation/Animator.java
index a9d14df..8142ee5 100644
--- a/core/java/android/animation/Animator.java
+++ b/core/java/android/animation/Animator.java
@@ -23,6 +23,7 @@
 import android.content.pm.ActivityInfo.Config;
 import android.content.res.ConstantState;
 import android.os.Build;
+import android.util.LongArray;
 
 import java.util.ArrayList;
 
@@ -559,9 +560,36 @@
     }
 
     /**
-     * Internal use only.
+     * Internal use only. Changes the value of the animator as if currentPlayTime has passed since
+     * the start of the animation. Therefore, currentPlayTime includes the start delay, and any
+     * repetition. lastPlayTime is similar and is used to calculate how many repeats have been
+     * done between the two times.
      */
-    void animateBasedOnPlayTime(long currentPlayTime, long lastPlayTime, boolean inReverse) {}
+    void animateValuesInRange(long currentPlayTime, long lastPlayTime) {}
+
+    /**
+     * Internal use only. This animates any animation that has ended since lastPlayTime.
+     * If an animation hasn't been finished, no change will be made.
+     */
+    void animateSkipToEnds(long currentPlayTime, long lastPlayTime) {}
+
+    /**
+     * Internal use only. Adds all start times (after delay) to and end times to times.
+     * The value must include offset.
+     */
+    void getStartAndEndTimes(LongArray times, long offset) {
+        long startTime = offset + getStartDelay();
+        if (times.indexOf(startTime) < 0) {
+            times.add(startTime);
+        }
+        long duration = getTotalDuration();
+        if (duration != DURATION_INFINITE) {
+            long endTime = duration + offset;
+            if (times.indexOf(endTime) < 0) {
+                times.add(endTime);
+            }
+        }
+    }
 
     /**
      * <p>An animation listener receives notifications from an animation.
diff --git a/core/java/android/animation/AnimatorSet.java b/core/java/android/animation/AnimatorSet.java
index bc8db02..54aaafc 100644
--- a/core/java/android/animation/AnimatorSet.java
+++ b/core/java/android/animation/AnimatorSet.java
@@ -23,9 +23,11 @@
 import android.util.AndroidRuntimeException;
 import android.util.ArrayMap;
 import android.util.Log;
+import android.util.LongArray;
 import android.view.animation.Animation;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -181,6 +183,11 @@
      */
     private long mPauseTime = -1;
 
+    /**
+     * The start and stop times of all descendant animators.
+     */
+    private long[] mChildStartAndStopTimes;
+
     // This is to work around a bug in b/34736819. This needs to be removed once app team
     // fixes their side.
     private AnimatorListenerAdapter mAnimationEndListener = new AnimatorListenerAdapter() {
@@ -779,26 +786,25 @@
 
     @Override
     void skipToEndValue(boolean inReverse) {
-        if (!isInitialized()) {
-            throw new UnsupportedOperationException("Children must be initialized.");
-        }
-
         // This makes sure the animation events are sorted an up to date.
         initAnimation();
+        initChildren();
 
         // Calling skip to the end in the sequence that they would be called in a forward/reverse
         // run, such that the sequential animations modifying the same property would have
         // the right value in the end.
         if (inReverse) {
             for (int i = mEvents.size() - 1; i >= 0; i--) {
-                if (mEvents.get(i).mEvent == AnimationEvent.ANIMATION_DELAY_ENDED) {
-                    mEvents.get(i).mNode.mAnimation.skipToEndValue(true);
+                AnimationEvent event = mEvents.get(i);
+                if (event.mEvent == AnimationEvent.ANIMATION_DELAY_ENDED) {
+                    event.mNode.mAnimation.skipToEndValue(true);
                 }
             }
         } else {
             for (int i = 0; i < mEvents.size(); i++) {
-                if (mEvents.get(i).mEvent == AnimationEvent.ANIMATION_END) {
-                    mEvents.get(i).mNode.mAnimation.skipToEndValue(false);
+                AnimationEvent event = mEvents.get(i);
+                if (event.mEvent == AnimationEvent.ANIMATION_END) {
+                    event.mNode.mAnimation.skipToEndValue(false);
                 }
             }
         }
@@ -814,72 +820,181 @@
      * {@link android.view.animation.Animation.AnimationListener#onAnimationRepeat(Animation)},
      * as needed, based on the last play time and current play time.
      */
-    @Override
-    void animateBasedOnPlayTime(long currentPlayTime, long lastPlayTime, boolean inReverse) {
-        if (currentPlayTime < 0 || lastPlayTime < 0) {
+    private void animateBasedOnPlayTime(
+            long currentPlayTime,
+            long lastPlayTime,
+            boolean inReverse
+    ) {
+        if (currentPlayTime < 0 || lastPlayTime < -1) {
             throw new UnsupportedOperationException("Error: Play time should never be negative.");
         }
         // TODO: take into account repeat counts and repeat callback when repeat is implemented.
-        // Clamp currentPlayTime and lastPlayTime
 
-        // TODO: Make this more efficient
-
-        // Convert the play times to the forward direction.
         if (inReverse) {
-            if (getTotalDuration() == DURATION_INFINITE) {
-                throw new UnsupportedOperationException("Cannot reverse AnimatorSet with infinite"
-                        + " duration");
+            long duration = getTotalDuration();
+            if (duration == DURATION_INFINITE) {
+                throw new UnsupportedOperationException(
+                        "Cannot reverse AnimatorSet with infinite duration"
+                );
             }
-            long duration = getTotalDuration() - mStartDelay;
+            // Convert the play times to the forward direction.
             currentPlayTime = Math.min(currentPlayTime, duration);
             currentPlayTime = duration - currentPlayTime;
             lastPlayTime = duration - lastPlayTime;
-            inReverse = false;
         }
 
-        ArrayList<Node> unfinishedNodes = new ArrayList<>();
-        // Assumes forward playing from here on.
-        for (int i = 0; i < mEvents.size(); i++) {
-            AnimationEvent event = mEvents.get(i);
-            if (event.getTime() > currentPlayTime || event.getTime() == DURATION_INFINITE) {
-                break;
-            }
+        long[] startEndTimes = ensureChildStartAndEndTimes();
+        int index = findNextIndex(lastPlayTime, startEndTimes);
+        int endIndex = findNextIndex(currentPlayTime, startEndTimes);
 
-            // This animation started prior to the current play time, and won't finish before the
-            // play time, add to the unfinished list.
-            if (event.mEvent == AnimationEvent.ANIMATION_DELAY_ENDED) {
-                if (event.mNode.mEndTime == DURATION_INFINITE
-                        || event.mNode.mEndTime > currentPlayTime) {
-                    unfinishedNodes.add(event.mNode);
+        // Change values at the start/end times so that values are set in the right order.
+        // We don't want an animator that would finish before another to override the value
+        // set by another animator that finishes earlier.
+        if (currentPlayTime >= lastPlayTime) {
+            while (index < endIndex) {
+                long playTime = startEndTimes[index];
+                if (lastPlayTime != playTime) {
+                    animateSkipToEnds(playTime, lastPlayTime);
+                    animateValuesInRange(playTime, lastPlayTime);
+                    lastPlayTime = playTime;
+                }
+                index++;
+            }
+        } else {
+            while (index > endIndex) {
+                index--;
+                long playTime = startEndTimes[index];
+                if (lastPlayTime != playTime) {
+                    animateSkipToEnds(playTime, lastPlayTime);
+                    animateValuesInRange(playTime, lastPlayTime);
+                    lastPlayTime = playTime;
                 }
             }
-            // For animations that do finish before the play time, end them in the sequence that
-            // they would in a normal run.
-            if (event.mEvent == AnimationEvent.ANIMATION_END) {
-                // Skip to the end of the animation.
-                event.mNode.mAnimation.skipToEndValue(false);
+        }
+        if (currentPlayTime != lastPlayTime) {
+            animateSkipToEnds(currentPlayTime, lastPlayTime);
+            animateValuesInRange(currentPlayTime, lastPlayTime);
+        }
+    }
+
+    /**
+     * Looks through startEndTimes for playTime. If it is in startEndTimes, the index after
+     * is returned. Otherwise, it returns the index at which it would be placed if it were
+     * to be inserted.
+     */
+    private int findNextIndex(long playTime, long[] startEndTimes) {
+        int index = Arrays.binarySearch(startEndTimes, playTime);
+        if (index < 0) {
+            index = -index - 1;
+        } else {
+            index++;
+        }
+        return index;
+    }
+
+    @Override
+    void animateSkipToEnds(long currentPlayTime, long lastPlayTime) {
+        initAnimation();
+
+        if (lastPlayTime > currentPlayTime) {
+            for (int i = mEvents.size() - 1; i >= 0; i--) {
+                AnimationEvent event = mEvents.get(i);
+                Node node = event.mNode;
+                if (event.mEvent == AnimationEvent.ANIMATION_END
+                        && node.mStartTime != DURATION_INFINITE
+                ) {
+                    Animator animator = node.mAnimation;
+                    long start = node.mStartTime + animator.getStartDelay();
+                    long end = node.mTotalDuration == DURATION_INFINITE
+                            ? Long.MAX_VALUE : node.mEndTime;
+                    if (currentPlayTime <= start && start < lastPlayTime) {
+                        animator.animateSkipToEnds(
+                                start - node.mStartTime,
+                                lastPlayTime - node.mStartTime
+                        );
+                    } else if (start <= currentPlayTime && currentPlayTime <= end) {
+                        animator.animateSkipToEnds(
+                                currentPlayTime - node.mStartTime,
+                                lastPlayTime - node.mStartTime
+                        );
+                    }
+                }
+            }
+        } else {
+            int eventsSize = mEvents.size();
+            for (int i = 0; i < eventsSize; i++) {
+                AnimationEvent event = mEvents.get(i);
+                Node node = event.mNode;
+                if (event.mEvent == AnimationEvent.ANIMATION_DELAY_ENDED
+                        && node.mStartTime != DURATION_INFINITE
+                ) {
+                    Animator animator = node.mAnimation;
+                    long start = node.mStartTime + animator.getStartDelay();
+                    long end = node.mTotalDuration == DURATION_INFINITE
+                            ? Long.MAX_VALUE : node.mEndTime;
+                    if (lastPlayTime < end && end <= currentPlayTime) {
+                        animator.animateSkipToEnds(
+                                end - node.mStartTime,
+                                lastPlayTime - node.mStartTime
+                        );
+                    } else if (start <= currentPlayTime && currentPlayTime <= end) {
+                        animator.animateSkipToEnds(
+                                currentPlayTime - node.mStartTime,
+                                lastPlayTime - node.mStartTime
+                        );
+                    }
+                }
             }
         }
+    }
 
-        // Seek unfinished animation to the right time.
-        for (int i = 0; i < unfinishedNodes.size(); i++) {
-            Node node = unfinishedNodes.get(i);
-            long playTime = getPlayTimeForNode(currentPlayTime, node, inReverse);
-            if (!inReverse) {
-                playTime -= node.mAnimation.getStartDelay();
-            }
-            node.mAnimation.animateBasedOnPlayTime(playTime, lastPlayTime, inReverse);
-        }
+    @Override
+    void animateValuesInRange(long currentPlayTime, long lastPlayTime) {
+        initAnimation();
 
-        // Seek not yet started animations.
-        for (int i = 0; i < mEvents.size(); i++) {
+        int eventsSize = mEvents.size();
+        for (int i = 0; i < eventsSize; i++) {
             AnimationEvent event = mEvents.get(i);
-            if (event.getTime() > currentPlayTime
-                    && event.mEvent == AnimationEvent.ANIMATION_DELAY_ENDED) {
-                event.mNode.mAnimation.skipToEndValue(true);
+            Node node = event.mNode;
+            if (event.mEvent == AnimationEvent.ANIMATION_DELAY_ENDED
+                    && node.mStartTime != DURATION_INFINITE
+            ) {
+                Animator animator = node.mAnimation;
+                long start = node.mStartTime + animator.getStartDelay();
+                long end = node.mTotalDuration == DURATION_INFINITE
+                        ? Long.MAX_VALUE : node.mEndTime;
+                if (start < currentPlayTime && currentPlayTime < end) {
+                    animator.animateValuesInRange(
+                            currentPlayTime - node.mStartTime,
+                            Math.max(-1, lastPlayTime - node.mStartTime)
+                    );
+                }
             }
         }
+    }
 
+    private long[] ensureChildStartAndEndTimes() {
+        if (mChildStartAndStopTimes == null) {
+            LongArray startAndEndTimes = new LongArray();
+            getStartAndEndTimes(startAndEndTimes, 0);
+            long[] times = startAndEndTimes.toArray();
+            Arrays.sort(times);
+            mChildStartAndStopTimes = times;
+        }
+        return mChildStartAndStopTimes;
+    }
+
+    @Override
+    void getStartAndEndTimes(LongArray times, long offset) {
+        int eventsSize = mEvents.size();
+        for (int i = 0; i < eventsSize; i++) {
+            AnimationEvent event = mEvents.get(i);
+            if (event.mEvent == AnimationEvent.ANIMATION_DELAY_ENDED
+                    && event.mNode.mStartTime != DURATION_INFINITE
+            ) {
+                event.mNode.mAnimation.getStartAndEndTimes(times, offset + event.mNode.mStartTime);
+            }
+        }
     }
 
     @Override
@@ -899,10 +1014,6 @@
         return mChildrenInitialized;
     }
 
-    private void skipToStartValue(boolean inReverse) {
-        skipToEndValue(!inReverse);
-    }
-
     /**
      * Sets the position of the animation to the specified point in time. This time should
      * be between 0 and the total duration of the animation, including any repetition. If
@@ -926,23 +1037,25 @@
         if ((getTotalDuration() != DURATION_INFINITE && playTime > getTotalDuration() - mStartDelay)
                 || playTime < 0) {
             throw new UnsupportedOperationException("Error: Play time should always be in between"
-                    + "0 and duration.");
+                    + " 0 and duration.");
         }
 
         initAnimation();
 
         if (!isStarted() || isPaused()) {
-            if (mReversing) {
+            if (mReversing && !isStarted()) {
                 throw new UnsupportedOperationException("Error: Something went wrong. mReversing"
                         + " should not be set when AnimatorSet is not started.");
             }
+            long lastPlayTime = mSeekState.getPlayTime();
             if (!mSeekState.isActive()) {
                 findLatestEventIdForTime(0);
-                // Set all the values to start values.
                 initChildren();
+                // Set all the values to start values.
+                skipToEndValue(!mReversing);
                 mSeekState.setPlayTime(0, mReversing);
             }
-            animateBasedOnPlayTime(playTime, 0, mReversing);
+            animateBasedOnPlayTime(playTime, lastPlayTime, mReversing);
             mSeekState.setPlayTime(playTime, mReversing);
         } else {
             // If the animation is running, just set the seek time and wait until the next frame
@@ -981,10 +1094,16 @@
     private void initChildren() {
         if (!isInitialized()) {
             mChildrenInitialized = true;
-            // Forcefully initialize all children based on their end time, so that if the start
-            // value of a child is dependent on a previous animation, the animation will be
-            // initialized after the the previous animations have been advanced to the end.
-            skipToEndValue(false);
+
+            // We have to initialize all the start values so that they are based on the previous
+            // values.
+            long[] times = ensureChildStartAndEndTimes();
+
+            long previousTime = -1;
+            for (long time : times) {
+                animateBasedOnPlayTime(time, previousTime, false);
+                previousTime = time;
+            }
         }
     }
 
@@ -1058,7 +1177,7 @@
         for (int i = 0; i < mPlayingSet.size(); i++) {
             Node node = mPlayingSet.get(i);
             if (!node.mEnded) {
-                pulseFrame(node, getPlayTimeForNode(unscaledPlayTime, node));
+                pulseFrame(node, getPlayTimeForNodeIncludingDelay(unscaledPlayTime, node));
             }
         }
 
@@ -1129,7 +1248,7 @@
                     pulseFrame(node, 0);
                 } else if (event.mEvent == AnimationEvent.ANIMATION_DELAY_ENDED && !node.mEnded) {
                     // end event:
-                    pulseFrame(node, getPlayTimeForNode(playTime, node));
+                    pulseFrame(node, getPlayTimeForNodeIncludingDelay(playTime, node));
                 }
             }
         } else {
@@ -1150,7 +1269,7 @@
                     pulseFrame(node, 0);
                 } else if (event.mEvent == AnimationEvent.ANIMATION_END && !node.mEnded) {
                     // start event:
-                    pulseFrame(node, getPlayTimeForNode(playTime, node));
+                    pulseFrame(node, getPlayTimeForNodeIncludingDelay(playTime, node));
                 }
             }
         }
@@ -1172,11 +1291,15 @@
         }
     }
 
-    private long getPlayTimeForNode(long overallPlayTime, Node node) {
-        return getPlayTimeForNode(overallPlayTime, node, mReversing);
+    private long getPlayTimeForNodeIncludingDelay(long overallPlayTime, Node node) {
+        return getPlayTimeForNodeIncludingDelay(overallPlayTime, node, mReversing);
     }
 
-    private long getPlayTimeForNode(long overallPlayTime, Node node, boolean inReverse) {
+    private long getPlayTimeForNodeIncludingDelay(
+            long overallPlayTime,
+            Node node,
+            boolean inReverse
+    ) {
         if (inReverse) {
             overallPlayTime = getTotalDuration() - overallPlayTime;
             return node.mEndTime - overallPlayTime;
@@ -1198,26 +1321,8 @@
         }
         // Set the child animators to the right end:
         if (mShouldResetValuesAtStart) {
-            if (isInitialized()) {
-                skipToEndValue(!mReversing);
-            } else if (mReversing) {
-                // Reversing but haven't initialized all the children yet.
-                initChildren();
-                skipToEndValue(!mReversing);
-            } else {
-                // If not all children are initialized and play direction is forward
-                for (int i = mEvents.size() - 1; i >= 0; i--) {
-                    if (mEvents.get(i).mEvent == AnimationEvent.ANIMATION_DELAY_ENDED) {
-                        Animator anim = mEvents.get(i).mNode.mAnimation;
-                        // Only reset the animations that have been initialized to start value,
-                        // so that if they are defined without a start value, they will get the
-                        // values set at the right time (i.e. the next animation run)
-                        if (anim.isInitialized()) {
-                            anim.skipToEndValue(true);
-                        }
-                    }
-                }
-            }
+            initChildren();
+            skipToEndValue(!mReversing);
         }
 
         if (mReversing || mStartDelay == 0 || mSeekState.isActive()) {
@@ -1922,11 +2027,11 @@
         }
 
         void setPlayTime(long playTime, boolean inReverse) {
-            // TODO: This can be simplified.
-
             // Clamp the play time
             if (getTotalDuration() != DURATION_INFINITE) {
                 mPlayTime = Math.min(playTime, getTotalDuration() - mStartDelay);
+            } else {
+                mPlayTime = playTime;
             }
             mPlayTime = Math.max(0, mPlayTime);
             mSeekingInReverse = inReverse;
diff --git a/core/java/android/animation/ValueAnimator.java b/core/java/android/animation/ValueAnimator.java
index 6ab7ae6..d41c03d 100644
--- a/core/java/android/animation/ValueAnimator.java
+++ b/core/java/android/animation/ValueAnimator.java
@@ -324,8 +324,9 @@
             listenerCopy = new ArrayList<>(sDurationScaleChangeListeners);
         }
 
-        for (WeakReference<DurationScaleChangeListener> listenerRef : listenerCopy) {
-            final DurationScaleChangeListener listener = listenerRef.get();
+        int listenersSize = listenerCopy.size();
+        for (int i = 0; i < listenersSize; i++) {
+            final DurationScaleChangeListener listener = listenerCopy.get(i).get();
             if (listener != null) {
                 listener.onChanged(durationScale);
             }
@@ -624,7 +625,7 @@
     public void setValues(PropertyValuesHolder... values) {
         int numValues = values.length;
         mValues = values;
-        mValuesMap = new HashMap<String, PropertyValuesHolder>(numValues);
+        mValuesMap = new HashMap<>(numValues);
         for (int i = 0; i < numValues; ++i) {
             PropertyValuesHolder valuesHolder = values[i];
             mValuesMap.put(valuesHolder.getPropertyName(), valuesHolder);
@@ -658,9 +659,11 @@
     @CallSuper
     void initAnimation() {
         if (!mInitialized) {
-            int numValues = mValues.length;
-            for (int i = 0; i < numValues; ++i) {
-                mValues[i].init();
+            if (mValues != null) {
+                int numValues = mValues.length;
+                for (int i = 0; i < numValues; ++i) {
+                    mValues[i].init();
+                }
             }
             mInitialized = true;
         }
@@ -1209,10 +1212,14 @@
                 // If it's not yet running, then start listeners weren't called. Call them now.
                 notifyStartListeners();
             }
-            ArrayList<AnimatorListener> tmpListeners =
-                    (ArrayList<AnimatorListener>) mListeners.clone();
-            for (AnimatorListener listener : tmpListeners) {
-                listener.onAnimationCancel(this);
+            int listenersSize = mListeners.size();
+            if (listenersSize > 0) {
+                ArrayList<AnimatorListener> tmpListeners =
+                        (ArrayList<AnimatorListener>) mListeners.clone();
+                for (int i = 0; i < listenersSize; i++) {
+                    AnimatorListener listener = tmpListeners.get(i);
+                    listener.onAnimationCancel(this);
+                }
             }
         }
         endAnimation();
@@ -1452,12 +1459,19 @@
      * will be called.
      */
     @Override
-    void animateBasedOnPlayTime(long currentPlayTime, long lastPlayTime, boolean inReverse) {
-        if (currentPlayTime < 0 || lastPlayTime < 0) {
+    void animateValuesInRange(long currentPlayTime, long lastPlayTime) {
+        if (currentPlayTime < mStartDelay || lastPlayTime < -1) {
             throw new UnsupportedOperationException("Error: Play time should never be negative.");
         }
 
         initAnimation();
+        long duration = getTotalDuration();
+        if (duration >= 0) {
+            lastPlayTime = Math.min(duration, lastPlayTime);
+        }
+        lastPlayTime -= mStartDelay;
+        currentPlayTime -= mStartDelay;
+
         // Check whether repeat callback is needed only when repeat count is non-zero
         if (mRepeatCount > 0) {
             int iteration = (int) (currentPlayTime / mDuration);
@@ -1478,15 +1492,27 @@
         }
 
         if (mRepeatCount != INFINITE && currentPlayTime >= (mRepeatCount + 1) * mDuration) {
-            skipToEndValue(inReverse);
+            throw new IllegalStateException("Can't animate a value outside of the duration");
         } else {
             // Find the current fraction:
             float fraction = currentPlayTime / (float) mDuration;
-            fraction = getCurrentIterationFraction(fraction, inReverse);
+            fraction = getCurrentIterationFraction(fraction, false);
             animateValue(fraction);
         }
     }
 
+    @Override
+    void animateSkipToEnds(long currentPlayTime, long lastPlayTime) {
+        if (currentPlayTime <= mStartDelay && lastPlayTime > mStartDelay) {
+            skipToEndValue(true);
+        } else {
+            long duration = getTotalDuration();
+            if (duration >= 0 && currentPlayTime >= duration && lastPlayTime < duration) {
+                skipToEndValue(false);
+            }
+        }
+    }
+
     /**
      * Internal use only.
      * Skips the animation value to end/start, depending on whether the play direction is forward
@@ -1641,6 +1667,9 @@
             Trace.traceCounter(Trace.TRACE_TAG_VIEW, getNameForTrace() + hashCode(),
                     (int) (fraction * 1000));
         }
+        if (mValues == null) {
+            return;
+        }
         fraction = mInterpolator.getInterpolation(fraction);
         mCurrentFraction = fraction;
         int numValues = mValues.length;
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index 30ff052..b9eb443 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -83,6 +83,7 @@
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.Looper;
+import android.os.OutcomeReceiver;
 import android.os.Parcelable;
 import android.os.PersistableBundle;
 import android.os.Process;
@@ -987,6 +988,17 @@
     /** @hide */
     boolean mIsInPictureInPictureMode;
 
+    /** @hide */
+    @IntDef(prefix = { "FULLSCREEN_REQUEST_" }, value = {
+            FULLSCREEN_MODE_REQUEST_EXIT,
+            FULLSCREEN_MODE_REQUEST_ENTER
+    })
+    public @interface FullscreenModeRequest {}
+
+    public static final int FULLSCREEN_MODE_REQUEST_EXIT = 0;
+
+    public static final int FULLSCREEN_MODE_REQUEST_ENTER = 1;
+
     private boolean mShouldDockBigOverlays;
 
     private UiTranslationController mUiTranslationController;
@@ -3001,6 +3013,36 @@
     }
 
     /**
+     * Request to put the a freeform activity into fullscreen. This will only be allowed if the
+     * activity is on a freeform display, such as a desktop device. The requester has to be the
+     * top-most activity and the request should be a response to a user input. When getting
+     * fullscreen and receiving corresponding {@link #onConfigurationChanged(Configuration)} and
+     * {@link #onMultiWindowModeChanged(boolean, Configuration)}, the activity should relayout
+     * itself and the system bars' visibilities can be controlled as usual fullscreen apps.
+     *
+     * Calling it again with the exit request can restore the activity to the previous status.
+     * This will only happen when it got into fullscreen through this API.
+     *
+     * If an app wants to be in fullscreen always, it should claim as not being resizable
+     * by setting
+     * <a href="https://developer.android.com/guide/topics/large-screens/multi-window-support#resizeableActivity">
+     * {@code android:resizableActivity="false"}</a> instead of calling this API.
+     *
+     * @param request Can be {@link #FULLSCREEN_MODE_REQUEST_ENTER} or
+     *                {@link #FULLSCREEN_MODE_REQUEST_EXIT} to indicate this request is to get
+     *                fullscreen or get restored.
+     * @param approvalCallback Optional callback, use {@code null} when not necessary. When the
+     *                         request is approved or rejected, the callback will be triggered. This
+     *                         will happen before any configuration change. The callback will be
+     *                         dispatched on the main thread.
+     */
+    public void requestFullscreenMode(@NonNull @FullscreenModeRequest int request,
+            @Nullable OutcomeReceiver<Void, Throwable> approvalCallback) {
+        FullscreenRequestHandler.requestFullscreenMode(
+                request, approvalCallback, mCurrentConfig, getActivityToken());
+    }
+
+    /**
      * Specifies a preference to dock big overlays like the expanded picture-in-picture on TV
      * (see {@link PictureInPictureParams.Builder#setExpandedAspectRatio}). Docking puts the
      * big overlay side-by-side next to this activity, so that both windows are fully visible to
@@ -6612,16 +6654,64 @@
     }
 
     /**
-     * Returns the uid who started this activity.
-     * @hide
+     * Returns the uid of the app that initially launched this activity.
+     *
+     * <p>In order to receive the launching app's uid, at least one of the following has to
+     * be met:
+     * <ul>
+     *     <li>The app must call {@link ActivityOptions#setShareIdentityEnabled(boolean)} with a
+     *     value of {@code true} and launch this activity with the resulting {@code
+     *     ActivityOptions}.
+     *     <li>The launched activity has the same uid as the launching app.
+     *     <li>The launched activity is running in a package that is signed with the same key
+     *     used to sign the platform (typically only system packages such as Settings will
+     *     meet this requirement).
+     * </ul>.
+     * These are the same requirements for {@link #getLaunchedFromPackage()}; if any of these are
+     * met, then these methods can be used to obtain the uid and package name of the launching
+     * app. If none are met, then {@link Process#INVALID_UID} is returned.
+     *
+     * <p>Note, even if the above conditions are not met, the launching app's identity may
+     * still be available from {@link #getCallingPackage()} if this activity was started with
+     * {@code Activity#startActivityForResult} to allow validation of the result's recipient.
+     *
+     * @return the uid of the launching app or {@link Process#INVALID_UID} if the current
+     * activity cannot access the identity of the launching app
+     *
+     * @see ActivityOptions#setShareIdentityEnabled(boolean)
+     * @see #getLaunchedFromPackage()
      */
     public int getLaunchedFromUid() {
         return ActivityClient.getInstance().getLaunchedFromUid(getActivityToken());
     }
 
     /**
-     * Returns the package who started this activity.
-     * @hide
+     * Returns the package name of the app that initially launched this activity.
+     *
+     * <p>In order to receive the launching app's package name, at least one of the following has
+     * to be met:
+     * <ul>
+     *     <li>The app must call {@link ActivityOptions#setShareIdentityEnabled(boolean)} with a
+     *     value of {@code true} and launch this activity with the resulting
+     *     {@code ActivityOptions}.
+     *     <li>The launched activity has the same uid as the launching app.
+     *     <li>The launched activity is running in a package that is signed with the same key
+     *     used to sign the platform (typically only system packages such as Settings will
+     *     meet this requirement).
+     * </ul>.
+     * These are the same requirements for {@link #getLaunchedFromUid()}; if any of these are
+     * met, then these methods can be used to obtain the uid and package name of the launching
+     * app. If none are met, then {@code null} is returned.
+     *
+     * <p>Note, even if the above conditions are not met, the launching app's identity may
+     * still be available from {@link #getCallingPackage()} if this activity was started with
+     * {@code Activity#startActivityForResult} to allow validation of the result's recipient.
+     *
+     * @return the package name of the launching app or null if the current activity
+     * cannot access the identity of the launching app
+     *
+     * @see ActivityOptions#setShareIdentityEnabled(boolean)
+     * @see #getLaunchedFromUid()
      */
     @Nullable
     public String getLaunchedFromPackage() {
diff --git a/core/java/android/app/ActivityClient.java b/core/java/android/app/ActivityClient.java
index 324b8e7..ce99119 100644
--- a/core/java/android/app/ActivityClient.java
+++ b/core/java/android/app/ActivityClient.java
@@ -24,6 +24,7 @@
 import android.content.res.Resources;
 import android.os.Bundle;
 import android.os.IBinder;
+import android.os.IRemoteCallback;
 import android.os.PersistableBundle;
 import android.os.RemoteException;
 import android.util.Singleton;
@@ -372,6 +373,14 @@
         }
     }
 
+    void requestMultiwindowFullscreen(IBinder token, int request, IRemoteCallback callback) {
+        try {
+            getActivityClientController().requestMultiwindowFullscreen(token, request, callback);
+        } catch (RemoteException e) {
+            e.rethrowFromSystemServer();
+        }
+    }
+
     void startLockTaskModeByToken(IBinder token) {
         try {
             getActivityClientController().startLockTaskModeByToken(token);
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
index 83963fd..2d6eaf1 100644
--- a/core/java/android/app/ActivityManager.java
+++ b/core/java/android/app/ActivityManager.java
@@ -5305,6 +5305,38 @@
     }
 
     /**
+     * Delays delivering broadcasts to the specified package.
+     *
+     * <p> When {@code delayedDurationMs} is {@code 0}, it will clears any previously
+     * set forced delays.
+     *
+     * @hide
+     */
+    @RequiresPermission(android.Manifest.permission.DUMP)
+    public void forceDelayBroadcastDelivery(@NonNull String targetPackage,
+            @IntRange(from = 0) long delayedDurationMs) {
+        try {
+            getService().forceDelayBroadcastDelivery(targetPackage, delayedDurationMs);
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
+    /**
+     * Checks if the "modern" broadcast queue is enabled.
+     *
+     * @hide
+     */
+    @RequiresPermission(android.Manifest.permission.DUMP)
+    public boolean isModernBroadcastQueueEnabled() {
+        try {
+            return getService().isModernBroadcastQueueEnabled();
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
+    /**
      * @return The reason code of whether or not the given UID should be exempted from background
      * restrictions here.
      *
diff --git a/core/java/android/app/ActivityManagerInternal.java b/core/java/android/app/ActivityManagerInternal.java
index f62190a..c51e8ae 100644
--- a/core/java/android/app/ActivityManagerInternal.java
+++ b/core/java/android/app/ActivityManagerInternal.java
@@ -902,4 +902,9 @@
      */
     public abstract void registerNetworkPolicyUidObserver(@NonNull IUidObserver observer,
             int which, int cutpoint, @NonNull String callingPackage);
+
+    /**
+     * Return all client package names of a service.
+     */
+    public abstract ArraySet<String> getClientPackages(String servicePackageName);
 }
diff --git a/core/java/android/app/ActivityOptions.java b/core/java/android/app/ActivityOptions.java
index 52ef7fb..1b92312 100644
--- a/core/java/android/app/ActivityOptions.java
+++ b/core/java/android/app/ActivityOptions.java
@@ -202,6 +202,12 @@
     private static final String KEY_LOCK_TASK_MODE = "android:activity.lockTaskMode";
 
     /**
+     * Whether the launching app's identity should be available to the launched activity.
+     * @see #setShareIdentityEnabled(boolean)
+     */
+    private static final String KEY_SHARE_IDENTITY = "android:activity.shareIdentity";
+
+    /**
      * The display id the activity should be launched into.
      * @see #setLaunchDisplayId(int)
      * @hide
@@ -457,6 +463,7 @@
     private int mLaunchTaskId = -1;
     private int mPendingIntentLaunchFlags;
     private boolean mLockTaskMode = false;
+    private boolean mShareIdentity = false;
     private boolean mDisallowEnterPictureInPictureWhileLaunching;
     private boolean mApplyActivityFlagsForBubbles;
     private boolean mTaskAlwaysOnTop;
@@ -1238,6 +1245,7 @@
                 break;
         }
         mLockTaskMode = opts.getBoolean(KEY_LOCK_TASK_MODE, false);
+        mShareIdentity = opts.getBoolean(KEY_SHARE_IDENTITY, false);
         mLaunchDisplayId = opts.getInt(KEY_LAUNCH_DISPLAY_ID, INVALID_DISPLAY);
         mCallerDisplayId = opts.getInt(KEY_CALLER_DISPLAY_ID, INVALID_DISPLAY);
         mLaunchTaskDisplayArea = opts.getParcelable(KEY_LAUNCH_TASK_DISPLAY_AREA_TOKEN, android.window.WindowContainerToken.class);
@@ -1488,6 +1496,20 @@
     }
 
     /**
+     * Returns whether the launching app has opted-in to sharing its identity with the launched
+     * activity.
+     *
+     * @see #setShareIdentityEnabled(boolean)
+     * @see Activity#getLaunchedFromUid()
+     * @see Activity#getLaunchedFromPackage()
+     *
+     * @hide
+     */
+    public boolean getShareIdentity() {
+        return mShareIdentity;
+    }
+
+    /**
      * Gets whether the activity want to be launched as other theme for the splash screen.
      * @hide
      */
@@ -1560,6 +1582,33 @@
     }
 
     /**
+     * Sets whether the identity of the launching app should be shared with the activity.
+     *
+     * <p>Use this option when starting an activity that needs to know the identity of the
+     * launching app; with this set to {@code true}, the activity will have access to the launching
+     * app's package name and uid.
+     *
+     * <p>Defaults to {@code false} if not set.
+     *
+     * <p>Note, even if the launching app does not explicitly enable sharing of its identity, if
+     * the activity is started with {@code Activity#startActivityForResult}, then {@link
+     * Activity#getCallingPackage()} will still return the launching app's package name to
+     * allow validation of the result's recipient. Also, an activity running within a package
+     * signed by the same key used to sign the platform (some system apps such as Settings will
+     * be signed with the platform's key) will have access to the launching app's identity.
+     *
+     * @param shareIdentity whether the launching app's identity should be shared with the activity
+     * @return {@code this} {@link ActivityOptions} instance.
+     * @see Activity#getLaunchedFromPackage()
+     * @see Activity#getLaunchedFromUid()
+     */
+    @NonNull
+    public ActivityOptions setShareIdentityEnabled(boolean shareIdentity) {
+        mShareIdentity = shareIdentity;
+        return this;
+    }
+
+    /**
      * Gets the id of the display where activity should be launched.
      * @return The id of the display where activity should be launched,
      *         {@link android.view.Display#INVALID_DISPLAY} if not set.
@@ -2039,6 +2088,7 @@
                 break;
         }
         mLockTaskMode = otherOptions.mLockTaskMode;
+        mShareIdentity = otherOptions.mShareIdentity;
         mAnimSpecs = otherOptions.mAnimSpecs;
         mAnimationFinishedListener = otherOptions.mAnimationFinishedListener;
         mSpecsFuture = otherOptions.mSpecsFuture;
@@ -2123,6 +2173,9 @@
         if (mLockTaskMode) {
             b.putBoolean(KEY_LOCK_TASK_MODE, mLockTaskMode);
         }
+        if (mShareIdentity) {
+            b.putBoolean(KEY_SHARE_IDENTITY, mShareIdentity);
+        }
         if (mLaunchDisplayId != INVALID_DISPLAY) {
             b.putInt(KEY_LAUNCH_DISPLAY_ID, mLaunchDisplayId);
         }
diff --git a/core/java/android/app/ActivityTaskManager.java b/core/java/android/app/ActivityTaskManager.java
index 7cfca97..be8f48d 100644
--- a/core/java/android/app/ActivityTaskManager.java
+++ b/core/java/android/app/ActivityTaskManager.java
@@ -62,6 +62,12 @@
     public static final int INVALID_TASK_ID = -1;
 
     /**
+     * Invalid windowing mode.
+     * @hide
+     */
+    public static final int INVALID_WINDOWING_MODE = -1;
+
+    /**
      * Input parameter to {@link IActivityTaskManager#resizeTask} which indicates
      * that the resize doesn't need to preserve the window, and can be skipped if bounds
      * is unchanged. This mode is used by window manager in most cases.
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 31cbe28..a4c9f8c 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -1020,6 +1020,12 @@
         int flags;
     }
 
+    // A list of receivers and an index into the receiver to be processed next.
+    static final class ReceiverList {
+        List<ReceiverInfo> receivers;
+        int index;
+    }
+
     private class ApplicationThread extends IApplicationThread.Stub {
         private static final String DB_CONNECTION_INFO_HEADER = "  %8s %8s %14s %5s %5s %5s  %s";
         private static final String DB_CONNECTION_INFO_FORMAT = "  %8s %8s %14s %5d %5d %5d  %s";
@@ -1036,6 +1042,21 @@
             sendMessage(H.RECEIVER, r);
         }
 
+        public final void scheduleReceiverList(List<ReceiverInfo> info) throws RemoteException {
+            for (int i = 0; i < info.size(); i++) {
+                ReceiverInfo r = info.get(i);
+                if (r.registered) {
+                    scheduleRegisteredReceiver(r.receiver, r.intent,
+                            r.resultCode, r.data, r.extras, r.ordered, r.sticky,
+                            r.sendingUser, r.processState);
+                } else {
+                    scheduleReceiver(r.intent, r.activityInfo, r.compatInfo,
+                            r.resultCode, r.data, r.extras, r.sync,
+                            r.sendingUser, r.processState);
+                }
+            }
+        }
+
         public final void scheduleCreateBackupAgent(ApplicationInfo app,
                 int backupMode, int userId, @BackupDestination int backupDestination) {
             CreateBackupAgentData d = new CreateBackupAgentData();
diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java
index d5879fb..563f6d4 100644
--- a/core/java/android/app/AppOpsManager.java
+++ b/core/java/android/app/AppOpsManager.java
@@ -6844,22 +6844,52 @@
     }
 
     /**
-     * Callback for notification of an op being noted.
+     * Callback for notification of an app-op being noted.
      *
      * @hide
      */
+    @SystemApi
     public interface OnOpNotedListener {
         /**
-         * Called when an op was noted.
-         * @param code The op code.
+         * Called when an app-op is noted.
+         *
+         * @param op The operation that was noted.
          * @param uid The UID performing the operation.
          * @param packageName The package performing the operation.
          * @param attributionTag The attribution tag performing the operation.
          * @param flags The flags of this op
          * @param result The result of the note.
          */
-        void onOpNoted(int code, int uid, String packageName, String attributionTag,
-                @OpFlags int flags, @Mode int result);
+        void onOpNoted(@NonNull String op, int uid, @NonNull String packageName,
+                @Nullable String attributionTag, @OpFlags int flags, @Mode int result);
+    }
+
+    /**
+     * Callback for notification of an app-op being noted to be used within platform code.
+     *
+     * This allows being notified using raw op codes instead of string op names.
+     *
+     * @hide
+     */
+    public interface OnOpNotedInternalListener extends OnOpNotedListener {
+        /**
+         * Called when an app-op is noted.
+         *
+         * @param code The code of the operation that was noted.
+         * @param uid The UID performing the operation.
+         * @param packageName The package performing the operation.
+         * @param attributionTag The attribution tag performing the operation.
+         * @param flags The flags of this op
+         * @param result The result of the note.
+         */
+        void onOpNoted(int code, int uid, @NonNull String packageName,
+                @Nullable String attributionTag, @OpFlags int flags, @Mode int result);
+
+        @Override
+        default void onOpNoted(@NonNull String op, int uid, @NonNull String packageName,
+                @Nullable String attributionTag, @OpFlags int flags, @Mode int result) {
+            onOpNoted(strOpToOp(op), uid, packageName, attributionTag, flags, result);
+        }
     }
 
     /**
@@ -7654,13 +7684,42 @@
      * @param ops The ops to watch.
      * @param callback Where to report changes.
      *
-     * @see #startWatchingActive(int[], OnOpActiveChangedListener)
-     * @see #startWatchingStarted(int[], OnOpStartedListener)
      * @see #stopWatchingNoted(OnOpNotedListener)
      * @see #noteOp(String, int, String, String, String)
      *
      * @hide
      */
+    @SystemApi
+    @RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true)
+    public void startWatchingNoted(@NonNull String[] ops, @NonNull OnOpNotedListener callback) {
+        final int[] intOps = new int[ops.length];
+        for (int i = 0; i < ops.length; i++) {
+            intOps[i] = strOpToOp(ops[i]);
+        }
+        startWatchingNoted(intOps, callback);
+    }
+
+    /**
+     * Start watching for noted app ops. An app op may be immediate or long running.
+     * Immediate ops are noted while long running ones are started and stopped. This
+     * method allows registering a listener to be notified when an app op is noted. If
+     * an op is being noted by any package you will get a callback. To change the
+     * watched ops for a registered callback you need to unregister and register it again.
+     *
+     * <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission
+     * you can watch changes only for your UID.
+     *
+     * This allows observing noted ops by their raw op codes instead of string op names.
+     *
+     * @param ops The ops to watch.
+     * @param callback Where to report changes.
+     *
+     * @see #startWatchingActive(int[], OnOpActiveChangedListener)
+     * @see #startWatchingStarted(int[], OnOpStartedListener)
+     * @see #startWatchingNoted(String[], OnOpNotedListener)
+     *
+     * @hide
+     */
     @RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true)
     public void startWatchingNoted(@NonNull int[] ops, @NonNull OnOpNotedListener callback) {
         IAppOpsNotedCallback cb;
@@ -7673,7 +7732,10 @@
                 @Override
                 public void opNoted(int op, int uid, String packageName, String attributionTag,
                         int flags, int mode) {
-                    callback.onOpNoted(op, uid, packageName, attributionTag, flags, mode);
+                    if (sAppOpInfos[op].name != null) {
+                        callback.onOpNoted(sAppOpInfos[op].name, uid, packageName, attributionTag,
+                                flags, mode);
+                    }
                 }
             };
             mNotedWatchers.put(callback, cb);
@@ -7689,11 +7751,12 @@
      * Stop watching for noted app ops. An app op may be immediate or long running.
      * Unregistering a non-registered callback has no effect.
      *
-     * @see #startWatchingNoted(int[], OnOpNotedListener)
+     * @see #startWatchingNoted(String[], OnOpNotedListener)
      * @see #noteOp(String, int, String, String, String)
      *
      * @hide
      */
+    @SystemApi
     public void stopWatchingNoted(@NonNull OnOpNotedListener callback) {
         synchronized (mNotedWatchers) {
             final IAppOpsNotedCallback cb = mNotedWatchers.remove(callback);
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index 042bdd7..39f7153 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -243,7 +243,7 @@
     @UnsupportedAppUsage
     private @NonNull Resources mResources;
     private @Nullable Display mDisplay; // may be null if invalid display or not initialized yet.
-    private int mDeviceId = VirtualDeviceManager.DEFAULT_DEVICE_ID;
+    private int mDeviceId = VirtualDeviceManager.DEVICE_ID_DEFAULT;
 
     /**
      * If set to {@code true} the resources for this context will be configured for mDisplay which
@@ -2699,8 +2699,8 @@
 
     @Override
     public @NonNull Context createDeviceContext(int deviceId) {
-        boolean validDeviceId = deviceId == VirtualDeviceManager.DEFAULT_DEVICE_ID;
-        if (deviceId > VirtualDeviceManager.DEFAULT_DEVICE_ID) {
+        boolean validDeviceId = deviceId == VirtualDeviceManager.DEVICE_ID_DEFAULT;
+        if (deviceId > VirtualDeviceManager.DEVICE_ID_DEFAULT) {
             VirtualDeviceManager vdm = getSystemService(VirtualDeviceManager.class);
             if (vdm != null) {
                 List<VirtualDevice> virtualDevices = vdm.getVirtualDevices();
diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java
index de0f752..411d157 100644
--- a/core/java/android/app/Dialog.java
+++ b/core/java/android/app/Dialog.java
@@ -458,8 +458,7 @@
                 && WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)) {
             // Add onBackPressed as default back behavior.
             mDefaultBackCallback = this::onBackPressed;
-            getOnBackInvokedDispatcher().registerOnBackInvokedCallback(
-                    OnBackInvokedDispatcher.PRIORITY_DEFAULT, mDefaultBackCallback);
+            getOnBackInvokedDispatcher().registerSystemOnBackInvokedCallback(mDefaultBackCallback);
             mDefaultBackCallback = null;
         }
     }
diff --git a/core/java/android/app/ForegroundServiceTypePolicy.java b/core/java/android/app/ForegroundServiceTypePolicy.java
index e99e360..877177c 100644
--- a/core/java/android/app/ForegroundServiceTypePolicy.java
+++ b/core/java/android/app/ForegroundServiceTypePolicy.java
@@ -56,7 +56,6 @@
 import android.hardware.usb.UsbAccessory;
 import android.hardware.usb.UsbDevice;
 import android.hardware.usb.UsbManager;
-import android.healthconnect.HealthConnectManager;
 import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.permission.PermissionCheckerManager;
@@ -73,7 +72,6 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Optional;
-import java.util.Set;
 
 /**
  * This class enforces the policies around the foreground service types.
@@ -994,45 +992,6 @@
         }
     }
 
-    static class HealthConnectPermission extends RegularPermission {
-        private @Nullable String[] mPermissionNames;
-
-        HealthConnectPermission() {
-            super("Health Connect");
-        }
-
-        @Override
-        @SuppressLint("AndroidFrameworkRequiresPermission")
-        @PackageManager.PermissionResult
-        public int checkPermission(@NonNull Context context, int callerUid, int callerPid,
-                String packageName, boolean allowWhileInUse) {
-            final String[] perms = getPermissions(context);
-            for (String perm : perms) {
-                if (checkPermission(context, perm, callerUid, callerPid,
-                        packageName, allowWhileInUse) == PERMISSION_GRANTED) {
-                    return PERMISSION_GRANTED;
-                }
-            }
-            return PERMISSION_DENIED;
-        }
-
-        @Override
-        void addToList(@NonNull Context context, @NonNull ArrayList<String> list) {
-            final String[] perms = getPermissions(context);
-            for (String perm : perms) {
-                list.add(perm);
-            }
-        }
-
-        private @NonNull String[] getPermissions(@NonNull Context context) {
-            if (mPermissionNames != null) {
-                return mPermissionNames;
-            }
-            final Set<String> healthPerms = HealthConnectManager.getHealthPermissions(context);
-            return mPermissionNames = healthPerms.toArray(new String[healthPerms.size()]);
-        }
-    }
-
     /**
      * The default policy for the foreground service types.
      *
diff --git a/core/java/android/app/FullscreenRequestHandler.java b/core/java/android/app/FullscreenRequestHandler.java
new file mode 100644
index 0000000..52f461d
--- /dev/null
+++ b/core/java/android/app/FullscreenRequestHandler.java
@@ -0,0 +1,123 @@
+/*
+ * 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 android.app;
+
+import static android.app.Activity.FULLSCREEN_MODE_REQUEST_ENTER;
+import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
+import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
+
+import android.annotation.IntDef;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.content.res.Configuration;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.os.IRemoteCallback;
+import android.os.OutcomeReceiver;
+
+/**
+ * @hide
+ */
+public class FullscreenRequestHandler {
+    @IntDef(prefix = { "RESULT_" }, value = {
+            RESULT_APPROVED,
+            RESULT_FAILED_NOT_IN_FREEFORM,
+            RESULT_FAILED_NOT_IN_FULLSCREEN_WITH_HISTORY,
+            RESULT_FAILED_NOT_DEFAULT_FREEFORM,
+            RESULT_FAILED_NOT_TOP_FOCUSED
+    })
+    public @interface RequestResult {}
+
+    public static final int RESULT_APPROVED = 0;
+    public static final int RESULT_FAILED_NOT_IN_FREEFORM = 1;
+    public static final int RESULT_FAILED_NOT_IN_FULLSCREEN_WITH_HISTORY = 2;
+    public static final int RESULT_FAILED_NOT_DEFAULT_FREEFORM = 3;
+    public static final int RESULT_FAILED_NOT_TOP_FOCUSED = 4;
+
+    public static final String REMOTE_CALLBACK_RESULT_KEY = "result";
+
+    static void requestFullscreenMode(@NonNull @Activity.FullscreenModeRequest int request,
+            @Nullable OutcomeReceiver<Void, Throwable> approvalCallback, Configuration config,
+            IBinder token) {
+        int earlyCheck = earlyCheckRequestMatchesWindowingMode(
+                request, config.windowConfiguration.getWindowingMode());
+        if (earlyCheck != RESULT_APPROVED) {
+            if (approvalCallback != null) {
+                notifyFullscreenRequestResult(approvalCallback, earlyCheck);
+            }
+            return;
+        }
+        try {
+            if (approvalCallback != null) {
+                ActivityClient.getInstance().requestMultiwindowFullscreen(token, request,
+                        new IRemoteCallback.Stub() {
+                            @Override
+                            public void sendResult(Bundle res) {
+                                notifyFullscreenRequestResult(
+                                        approvalCallback, res.getInt(REMOTE_CALLBACK_RESULT_KEY));
+                            }
+                        });
+            } else {
+                ActivityClient.getInstance().requestMultiwindowFullscreen(token, request, null);
+            }
+        } catch (Throwable e) {
+            if (approvalCallback != null) {
+                approvalCallback.onError(e);
+            }
+        }
+    }
+
+    private static void notifyFullscreenRequestResult(
+            OutcomeReceiver<Void, Throwable> callback, int result) {
+        Throwable e = null;
+        switch (result) {
+            case RESULT_FAILED_NOT_IN_FREEFORM:
+                e = new IllegalStateException("The window is not a freeform window, the request "
+                        + "to get into fullscreen cannot be approved.");
+                break;
+            case RESULT_FAILED_NOT_IN_FULLSCREEN_WITH_HISTORY:
+                e = new IllegalStateException("The window is not in fullscreen by calling the "
+                        + "requestFullscreenMode API before, such that cannot be restored.");
+                break;
+            case RESULT_FAILED_NOT_DEFAULT_FREEFORM:
+                e = new IllegalStateException("The window is not launched in freeform by default.");
+                break;
+            case RESULT_FAILED_NOT_TOP_FOCUSED:
+                e = new IllegalStateException("The window is not the top focused window.");
+                break;
+            default:
+                callback.onResult(null);
+                break;
+        }
+        if (e != null) {
+            callback.onError(e);
+        }
+    }
+
+    private static int earlyCheckRequestMatchesWindowingMode(int request, int windowingMode) {
+        if (request == FULLSCREEN_MODE_REQUEST_ENTER) {
+            if (windowingMode != WINDOWING_MODE_FREEFORM) {
+                return RESULT_FAILED_NOT_IN_FREEFORM;
+            }
+        } else {
+            if (windowingMode != WINDOWING_MODE_FULLSCREEN) {
+                return RESULT_FAILED_NOT_IN_FULLSCREEN_WITH_HISTORY;
+            }
+        }
+        return RESULT_APPROVED;
+    }
+}
diff --git a/core/java/android/app/GameManager.java b/core/java/android/app/GameManager.java
index 2f51b17..c6fa064 100644
--- a/core/java/android/app/GameManager.java
+++ b/core/java/android/app/GameManager.java
@@ -287,6 +287,7 @@
      * <p>
      * The caller must have {@link android.Manifest.permission#MANAGE_GAME_MODE}.
      *
+     * @param packageName The package name of the game to update
      * @param gameModeConfig The configuration to use for game mode interventions
      * @hide
      */
diff --git a/core/java/android/app/GameModeConfiguration.java b/core/java/android/app/GameModeConfiguration.java
index b081e82..d8be814 100644
--- a/core/java/android/app/GameModeConfiguration.java
+++ b/core/java/android/app/GameModeConfiguration.java
@@ -62,10 +62,16 @@
      */
     @SystemApi
     public static final class Builder {
-        /** Constructs a new Builder for a game mode’s configuration */
+        /** Constructs a new Builder for a game mode’s configuration. */
         public Builder() {
         }
 
+        /** Constructs a new builder by copying from an existing game mode configuration. */
+        public Builder(@NonNull GameModeConfiguration configuration) {
+            mFpsOverride = configuration.mFpsOverride;
+            mScalingFactor = configuration.mScalingFactor;
+        }
+
         /**
          * Sets the scaling factor used for game resolution downscaling.
          * <br>
@@ -156,16 +162,6 @@
         return mFpsOverride;
     }
 
-    /**
-     * Converts and returns the game mode config as a new builder.
-     */
-    @NonNull
-    public GameModeConfiguration.Builder toBuilder() {
-        return new GameModeConfiguration.Builder()
-                .setFpsOverride(mFpsOverride)
-                .setScalingFactor(mScalingFactor);
-    }
-
     @Override
     public boolean equals(Object obj) {
         if (obj == this) {
diff --git a/core/java/android/app/GameModeInfo.java b/core/java/android/app/GameModeInfo.java
index 31255c2..7dcb3909 100644
--- a/core/java/android/app/GameModeInfo.java
+++ b/core/java/android/app/GameModeInfo.java
@@ -87,12 +87,12 @@
         }
 
         /**
-         * Sets the opted-in game modes.
+         * Sets the overridden game modes.
          */
         @NonNull
-        public GameModeInfo.Builder setOptedInGameModes(
-                @NonNull @GameManager.GameMode int[] optedInGameModes) {
-            mOptedInGameModes = optedInGameModes;
+        public GameModeInfo.Builder setOverriddenGameModes(
+                @NonNull @GameManager.GameMode int[] overriddenGameModes) {
+            mOverriddenGameModes = overriddenGameModes;
             return this;
         }
 
@@ -140,12 +140,12 @@
          */
         @NonNull
         public GameModeInfo build() {
-            return new GameModeInfo(mActiveGameMode, mAvailableGameModes, mOptedInGameModes,
+            return new GameModeInfo(mActiveGameMode, mAvailableGameModes, mOverriddenGameModes,
                     mIsDownscalingAllowed, mIsFpsOverrideAllowed, mConfigMap);
         }
 
         private @GameManager.GameMode int[] mAvailableGameModes = new int[]{};
-        private @GameManager.GameMode int[] mOptedInGameModes = new int[]{};
+        private @GameManager.GameMode int[] mOverriddenGameModes = new int[]{};
         private @GameManager.GameMode int mActiveGameMode;
         private boolean mIsDownscalingAllowed;
         private boolean mIsFpsOverrideAllowed;
@@ -164,11 +164,11 @@
 
     private GameModeInfo(@GameManager.GameMode int activeGameMode,
             @NonNull @GameManager.GameMode int[] availableGameModes,
-            @NonNull @GameManager.GameMode int[] optedInGameModes, boolean isDownscalingAllowed,
+            @NonNull @GameManager.GameMode int[] overriddenGameModes, boolean isDownscalingAllowed,
             boolean isFpsOverrideAllowed, @NonNull Map<Integer, GameModeConfiguration> configMap) {
         mActiveGameMode = activeGameMode;
         mAvailableGameModes = Arrays.copyOf(availableGameModes, availableGameModes.length);
-        mOptedInGameModes = Arrays.copyOf(optedInGameModes, optedInGameModes.length);
+        mOverriddenGameModes = Arrays.copyOf(overriddenGameModes, overriddenGameModes.length);
         mIsDownscalingAllowed = isDownscalingAllowed;
         mIsFpsOverrideAllowed = isFpsOverrideAllowed;
         mConfigMap = configMap;
@@ -179,7 +179,7 @@
     public GameModeInfo(Parcel in) {
         mActiveGameMode = in.readInt();
         mAvailableGameModes = in.createIntArray();
-        mOptedInGameModes = in.createIntArray();
+        mOverriddenGameModes = in.createIntArray();
         mIsDownscalingAllowed = in.readBoolean();
         mIsFpsOverrideAllowed = in.readBoolean();
         mConfigMap = new ArrayMap<>();
@@ -198,8 +198,8 @@
      * Gets the collection of {@link GameManager.GameMode} that can be applied to the game.
      * <p>
      * Available games include all game modes that are either supported by the OEM in device
-     * config, or opted in by the game developers in game mode config XML, plus the default enabled
-     * modes for any game including {@link GameManager#GAME_MODE_STANDARD} and
+     * config, or overridden by the game developers in game mode config XML, plus the default
+     * enabled modes for any game including {@link GameManager#GAME_MODE_STANDARD} and
      * {@link GameManager#GAME_MODE_CUSTOM}.
      * <p>
      * Also see {@link GameModeInfo}.
@@ -210,19 +210,19 @@
     }
 
     /**
-     * Gets the collection of {@link GameManager.GameMode} that are opted in by the game.
+     * Gets the collection of {@link GameManager.GameMode} that are overridden by the game.
      * <p>
      * Also see {@link GameModeInfo}.
      */
     @NonNull
-    public @GameManager.GameMode int[] getOptedInGameModes() {
-        return Arrays.copyOf(mOptedInGameModes, mOptedInGameModes.length);
+    public @GameManager.GameMode int[] getOverriddenGameModes() {
+        return Arrays.copyOf(mOverriddenGameModes, mOverriddenGameModes.length);
     }
 
     /**
      * Gets the current game mode configuration of a game mode.
      * <p>
-     * The game mode can be null if it's opted in by the game itself, or not configured in device
+     * The game mode can be null if it's overridden by the game itself, or not configured in device
      * config nor set by the user as custom game mode configuration.
      */
     public @Nullable GameModeConfiguration getGameModeConfiguration(
@@ -250,7 +250,7 @@
 
 
     private final @GameManager.GameMode int[] mAvailableGameModes;
-    private final @GameManager.GameMode int[] mOptedInGameModes;
+    private final @GameManager.GameMode int[] mOverriddenGameModes;
     private final @GameManager.GameMode int mActiveGameMode;
     private final boolean mIsDownscalingAllowed;
     private final boolean mIsFpsOverrideAllowed;
@@ -265,7 +265,7 @@
     public void writeToParcel(@NonNull Parcel dest, int flags) {
         dest.writeInt(mActiveGameMode);
         dest.writeIntArray(mAvailableGameModes);
-        dest.writeIntArray(mOptedInGameModes);
+        dest.writeIntArray(mOverriddenGameModes);
         dest.writeBoolean(mIsDownscalingAllowed);
         dest.writeBoolean(mIsFpsOverrideAllowed);
         dest.writeMap(mConfigMap);
diff --git a/core/java/android/app/IActivityClientController.aidl b/core/java/android/app/IActivityClientController.aidl
index 8b655b9..286b84c 100644
--- a/core/java/android/app/IActivityClientController.aidl
+++ b/core/java/android/app/IActivityClientController.aidl
@@ -24,6 +24,7 @@
 import android.content.Intent;
 import android.content.res.Configuration;
 import android.os.Bundle;
+import android.os.IRemoteCallback;
 import android.os.PersistableBundle;
 import android.view.RemoteAnimationDefinition;
 import android.window.SizeConfigurationBuckets;
@@ -102,6 +103,8 @@
     void setPictureInPictureParams(in IBinder token, in PictureInPictureParams params);
     oneway void setShouldDockBigOverlays(in IBinder token, in boolean shouldDockBigOverlays);
     void toggleFreeformWindowingMode(in IBinder token);
+    oneway void requestMultiwindowFullscreen(in IBinder token, in int request,
+            in IRemoteCallback callback);
 
     oneway void startLockTaskModeByToken(in IBinder token);
     oneway void stopLockTaskModeByToken(in IBinder token);
diff --git a/core/java/android/app/IActivityManager.aidl b/core/java/android/app/IActivityManager.aidl
index 040111c..938f1f6 100644
--- a/core/java/android/app/IActivityManager.aidl
+++ b/core/java/android/app/IActivityManager.aidl
@@ -771,6 +771,14 @@
     /** Blocks until all broadcast queues become idle. */
     void waitForBroadcastIdle();
 
+    /** Delays delivering broadcasts to the specified package. */
+    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.DUMP)")
+    void forceDelayBroadcastDelivery(in String targetPackage, long delayedDurationMs);
+
+    /** Checks if the modern broadcast queue is enabled. */
+    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.DUMP)")
+    boolean isModernBroadcastQueueEnabled();
+
     /**
      * @return The reason code of whether or not the given UID should be exempted from background
      * restrictions here.
diff --git a/core/java/android/app/IApplicationThread.aidl b/core/java/android/app/IApplicationThread.aidl
index 595c7f7..3984fee 100644
--- a/core/java/android/app/IApplicationThread.aidl
+++ b/core/java/android/app/IApplicationThread.aidl
@@ -20,6 +20,7 @@
 import android.app.IInstrumentationWatcher;
 import android.app.IUiAutomationConnection;
 import android.app.ProfilerInfo;
+import android.app.ReceiverInfo;
 import android.app.ResultInfo;
 import android.app.servertransaction.ClientTransaction;
 import android.content.AutofillOptions;
@@ -66,6 +67,9 @@
             in CompatibilityInfo compatInfo,
             int resultCode, in String data, in Bundle extras, boolean sync,
             int sendingUser, int processState);
+
+    void scheduleReceiverList(in List<ReceiverInfo> info);
+
     @UnsupportedAppUsage
     void scheduleCreateService(IBinder token, in ServiceInfo info,
             in CompatibilityInfo compatInfo, int processState);
diff --git a/core/java/android/app/ReceiverInfo.aidl b/core/java/android/app/ReceiverInfo.aidl
new file mode 100644
index 0000000..d90eee7
--- /dev/null
+++ b/core/java/android/app/ReceiverInfo.aidl
@@ -0,0 +1,60 @@
+/**
+ * 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 android.app;
+
+import android.content.IIntentReceiver;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.res.CompatibilityInfo;
+import android.os.Bundle;
+
+/**
+ * Collect the information needed for manifest and registered receivers into a single structure
+ * that can be the element of a list.  All fields are already parcelable.
+ * @hide
+ */
+parcelable ReceiverInfo {
+    /**
+     * Fields common to registered and manifest receivers.
+     */
+    Intent intent;
+    String data;
+    Bundle extras;
+    int sendingUser;
+    int processState;
+    int resultCode;
+
+    /**
+     * True if this instance represents a registered receiver and false if this instance
+     * represents a manifest receiver.
+     */
+    boolean registered;
+
+    /**
+     * Fields used only for registered receivers.
+     */
+    IIntentReceiver receiver;
+    boolean ordered;
+    boolean sticky;
+
+    /**
+     * Fields used only for manifest receivers.
+     */
+    ActivityInfo activityInfo;
+    CompatibilityInfo compatInfo;
+    boolean sync;
+}
diff --git a/core/java/android/app/ResourcesManager.java b/core/java/android/app/ResourcesManager.java
index 32217610..7e6386e 100644
--- a/core/java/android/app/ResourcesManager.java
+++ b/core/java/android/app/ResourcesManager.java
@@ -41,6 +41,7 @@
 import android.util.ArrayMap;
 import android.util.ArraySet;
 import android.util.DisplayMetrics;
+import android.util.IndentingPrintWriter;
 import android.util.Log;
 import android.util.Pair;
 import android.util.Slog;
@@ -51,7 +52,6 @@
 
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.util.ArrayUtils;
-import com.android.internal.util.IndentingPrintWriter;
 
 import java.io.IOException;
 import java.io.PrintWriter;
@@ -173,6 +173,7 @@
 
     /**
      * The ApkAssets that are being referenced in the wild that we can reuse.
+     * Used as a lock for itself as well.
      */
     private final ArrayMap<ApkKey, WeakReference<ApkAssets>> mCachedApkAssets = new ArrayMap<>();
 
@@ -286,42 +287,43 @@
      * try as hard as possible to release any open FDs.
      */
     public void invalidatePath(String path) {
+        final List<ResourcesImpl> implsToFlush = new ArrayList<>();
         synchronized (mLock) {
-            int count = 0;
-
             for (int i = mResourceImpls.size() - 1; i >= 0; i--) {
                 final ResourcesKey key = mResourceImpls.keyAt(i);
                 if (key.isPathReferenced(path)) {
-                    ResourcesImpl impl = mResourceImpls.removeAt(i).get();
-                    if (impl != null) {
-                        impl.flushLayoutCache();
+                    ResourcesImpl resImpl = mResourceImpls.removeAt(i).get();
+                    if (resImpl != null) {
+                        implsToFlush.add(resImpl);
                     }
-                    count++;
                 }
             }
-
-            Log.i(TAG, "Invalidated " + count + " asset managers that referenced " + path);
-
+        }
+        for (int i = 0; i < implsToFlush.size(); i++) {
+            implsToFlush.get(i).flushLayoutCache();
+        }
+        final List<ApkAssets> assetsToClose = new ArrayList<>();
+        synchronized (mCachedApkAssets) {
             for (int i = mCachedApkAssets.size() - 1; i >= 0; i--) {
                 final ApkKey key = mCachedApkAssets.keyAt(i);
                 if (key.path.equals(path)) {
                     final WeakReference<ApkAssets> apkAssetsRef = mCachedApkAssets.removeAt(i);
-                    if (apkAssetsRef == null) {
-                        continue;
-                    }
-                    final ApkAssets apkAssets = apkAssetsRef.get();
+                    final ApkAssets apkAssets = apkAssetsRef != null ? apkAssetsRef.get() : null;
                     if (apkAssets != null) {
-                        apkAssets.close();
+                        assetsToClose.add(apkAssets);
                     }
                 }
             }
         }
+        for (int i = 0; i < assetsToClose.size(); i++) {
+            assetsToClose.get(i).close();
+        }
+        Log.i(TAG,
+                "Invalidated " + implsToFlush.size() + " asset managers that referenced " + path);
     }
 
     public Configuration getConfiguration() {
-        synchronized (mLock) {
-            return mResConfiguration;
-        }
+        return mResConfiguration;
     }
 
     @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
@@ -406,14 +408,12 @@
      * @param resources The {@link Resources} backing the display adjustments.
      */
     public Display getAdjustedDisplay(final int displayId, Resources resources) {
-        synchronized (mLock) {
-            final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance();
-            if (dm == null) {
-                // may be null early in system startup
-                return null;
-            }
-            return dm.getCompatibleDisplay(displayId, resources);
+        final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance();
+        if (dm == null) {
+            // may be null early in system startup
+            return null;
         }
+        return dm.getCompatibleDisplay(displayId, resources);
     }
 
     /**
@@ -451,7 +451,7 @@
 
         // Optimistically check if this ApkAssets exists somewhere else.
         final WeakReference<ApkAssets> apkAssetsRef;
-        synchronized (mLock) {
+        synchronized (mCachedApkAssets) {
             apkAssetsRef = mCachedApkAssets.get(key);
         }
         if (apkAssetsRef != null) {
@@ -474,7 +474,7 @@
             apkAssets = ApkAssets.loadFromPath(key.path, flags);
         }
 
-        synchronized (mLock) {
+        synchronized (mCachedApkAssets) {
             mCachedApkAssets.put(key, new WeakReference<>(apkAssets));
         }
 
@@ -586,28 +586,33 @@
      * @hide
      */
     public void dump(String prefix, PrintWriter printWriter) {
+        final int references;
+        final int resImpls;
         synchronized (mLock) {
-            IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, "  ");
-            for (int i = 0; i < prefix.length() / 2; i++) {
-                pw.increaseIndent();
-            }
-
-            pw.println("ResourcesManager:");
-            pw.increaseIndent();
-            pw.print("total apks: ");
-            pw.println(countLiveReferences(mCachedApkAssets.values()));
-
-            pw.print("resources: ");
-
-            int references = countLiveReferences(mResourceReferences);
+            int refs = countLiveReferences(mResourceReferences);
             for (ActivityResources activityResources : mActivityResourceReferences.values()) {
-                references += activityResources.countLiveReferences();
+                refs += activityResources.countLiveReferences();
             }
-            pw.println(references);
-
-            pw.print("resource impls: ");
-            pw.println(countLiveReferences(mResourceImpls.values()));
+            references = refs;
+            resImpls = countLiveReferences(mResourceImpls.values());
         }
+        final int liveAssets;
+        synchronized (mCachedApkAssets) {
+            liveAssets = countLiveReferences(mCachedApkAssets.values());
+        }
+
+        final var pw = new IndentingPrintWriter(printWriter, "  ");
+        for (int i = 0; i < prefix.length() / 2; i++) {
+            pw.increaseIndent();
+        }
+        pw.println("ResourcesManager:");
+        pw.increaseIndent();
+        pw.print("total apks: ");
+        pw.println(liveAssets);
+        pw.print("resources: ");
+        pw.println(references);
+        pw.print("resource impls: ");
+        pw.println(resImpls);
     }
 
     private Configuration generateConfig(@NonNull ResourcesKey key) {
diff --git a/core/java/android/app/StatusBarManager.java b/core/java/android/app/StatusBarManager.java
index a035375..f63f406 100644
--- a/core/java/android/app/StatusBarManager.java
+++ b/core/java/android/app/StatusBarManager.java
@@ -234,7 +234,10 @@
 
     /**
      * Session flag for {@link #registerSessionListener} indicating the listener
-     * is interested in sessions on the keygaurd
+     * is interested in sessions on the keygaurd.
+     * Keyguard Session Boundaries:
+     *     START_SESSION: device starts going to sleep OR the keyguard is newly shown
+     *     END_SESSION: device starts going to sleep OR keyguard is no longer showing
      * @hide
      */
     public static final int SESSION_KEYGUARD = 1 << 0;
diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java
index f5d657c..84b404d 100644
--- a/core/java/android/app/WallpaperManager.java
+++ b/core/java/android/app/WallpaperManager.java
@@ -807,9 +807,33 @@
      *     is not able to access the wallpaper.
      */
     @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE)
+    @Nullable
     public Drawable getDrawable() {
+        return getDrawable(FLAG_SYSTEM);
+    }
+
+    /**
+     * Retrieve the requested wallpaper; if
+     * no wallpaper is set, the requested built-in static wallpaper is returned.
+     * This is returned as an
+     * abstract Drawable that you can install in a View to display whatever
+     * wallpaper the user has currently set.
+     * <p>
+     * This method can return null if the requested wallpaper is not available, if
+     * wallpapers are not supported in the current user, or if the calling app is not
+     * permitted to access the requested wallpaper.
+     *
+     * @param which The {@code FLAG_*} identifier of a valid wallpaper type.  Throws
+     *     IllegalArgumentException if an invalid wallpaper is requested.
+     * @return Returns a Drawable object that will draw the requested wallpaper,
+     *     or {@code null} if the requested wallpaper does not exist or if the calling application
+     *     is not able to access the wallpaper.
+     */
+    @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE)
+    @Nullable
+    public Drawable getDrawable(@SetWallpaperFlags int which) {
         final ColorManagementProxy cmProxy = getColorManagementProxy();
-        Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, true, FLAG_SYSTEM, cmProxy);
+        Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, true, which, cmProxy);
         if (bm != null) {
             Drawable dr = new BitmapDrawable(mContext.getResources(), bm);
             dr.setDither(false);
@@ -1035,11 +1059,28 @@
      * wallpaper the user has currently set.
      *
      * @return Returns a Drawable object that will draw the wallpaper or a
-     * null pointer if these is none.
+     * null pointer if wallpaper is unset.
      */
+    @Nullable
     public Drawable peekDrawable() {
+        return peekDrawable(FLAG_SYSTEM);
+    }
+
+    /**
+     * Retrieve the requested wallpaper; if there is no wallpaper set,
+     * a null pointer is returned. This is returned as an
+     * abstract Drawable that you can install in a View to display whatever
+     * wallpaper the user has currently set.
+     *
+     * @param which The {@code FLAG_*} identifier of a valid wallpaper type.  Throws
+     *     IllegalArgumentException if an invalid wallpaper is requested.
+     * @return Returns a Drawable object that will draw the wallpaper or a null pointer if
+     * wallpaper is unset.
+     */
+    @Nullable
+    public Drawable peekDrawable(@SetWallpaperFlags int which) {
         final ColorManagementProxy cmProxy = getColorManagementProxy();
-        Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, false, FLAG_SYSTEM, cmProxy);
+        Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, false, which, cmProxy);
         if (bm != null) {
             Drawable dr = new BitmapDrawable(mContext.getResources(), bm);
             dr.setDither(false);
@@ -1062,9 +1103,31 @@
      * @return Returns a Drawable object that will draw the wallpaper.
      */
     @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE)
+    @Nullable
     public Drawable getFastDrawable() {
+        return getFastDrawable(FLAG_SYSTEM);
+    }
+
+    /**
+     * Like {@link #getFastDrawable(int)}, but the returned Drawable has a number
+     * of limitations to reduce its overhead as much as possible. It will
+     * never scale the wallpaper (only centering it if the requested bounds
+     * do match the bitmap bounds, which should not be typical), doesn't
+     * allow setting an alpha, color filter, or other attributes, etc.  The
+     * bounds of the returned drawable will be initialized to the same bounds
+     * as the wallpaper, so normally you will not need to touch it.  The
+     * drawable also assumes that it will be used in a context running in
+     * the same density as the screen (not in density compatibility mode).
+     *
+     * @param which The {@code FLAG_*} identifier of a valid wallpaper type.  Throws
+     *     IllegalArgumentException if an invalid wallpaper is requested.
+     * @return Returns a Drawable object that will draw the wallpaper.
+     */
+    @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE)
+    @Nullable
+    public Drawable getFastDrawable(@SetWallpaperFlags int which) {
         final ColorManagementProxy cmProxy = getColorManagementProxy();
-        Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, true, FLAG_SYSTEM, cmProxy);
+        Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, true, which, cmProxy);
         if (bm != null) {
             return new FastBitmapDrawable(bm);
         }
@@ -1079,9 +1142,25 @@
      * wallpaper or a null pointer if these is none.
      */
     @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE)
+    @Nullable
     public Drawable peekFastDrawable() {
+        return peekFastDrawable(FLAG_SYSTEM);
+    }
+
+    /**
+     * Like {@link #getFastDrawable()}, but if there is no wallpaper set,
+     * a null pointer is returned.
+     *
+     * @param which The {@code FLAG_*} identifier of a valid wallpaper type.  Throws
+     *     IllegalArgumentException if an invalid wallpaper is requested.
+     * @return Returns an optimized Drawable object that will draw the
+     * wallpaper or a null pointer if these is none.
+     */
+    @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE)
+    @Nullable
+    public Drawable peekFastDrawable(@SetWallpaperFlags int which) {
         final ColorManagementProxy cmProxy = getColorManagementProxy();
-        Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, false, FLAG_SYSTEM, cmProxy);
+        Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, false, which, cmProxy);
         if (bm != null) {
             return new FastBitmapDrawable(bm);
         }
diff --git a/core/java/android/app/admin/DevicePolicyCache.java b/core/java/android/app/admin/DevicePolicyCache.java
index da62375..4a329a9 100644
--- a/core/java/android/app/admin/DevicePolicyCache.java
+++ b/core/java/android/app/admin/DevicePolicyCache.java
@@ -61,7 +61,6 @@
      */
     public abstract boolean canAdminGrantSensorsPermissionsForUser(@UserIdInt int userHandle);
 
-
     /**
      * Empty implementation.
      */
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index ecea1bb..128a872 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -165,6 +165,17 @@
 @SuppressLint("UseIcu")
 public class DevicePolicyManager {
 
+    /** @hide */
+    public static final String DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_FLAG =
+            "deprecate_usermanagerinternal_devicepolicy";
+    /** @hide */
+    public static final boolean DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_DEFAULT = true;
+    /** @hide */
+    public static final String ADD_ISFINANCED_DEVICE_FLAG =
+            "add-isfinanced-device";
+    /** @hide */
+    public static final boolean ADD_ISFINANCED_FEVICE_DEFAULT = true;
+
     private static String TAG = "DevicePolicyManager";
 
     private final Context mContext;
@@ -3907,34 +3918,46 @@
     public static @interface MtePolicy {}
 
     /**
-     * Set MTE policy for device. MTE_ENABLED does not necessarily enable MTE if set on a device
-     * that does not support MTE.
-     *
-     * The default policy is MTE_NOT_CONTROLLED_BY_POLICY.
-     *
-     * Memory Tagging Extension (MTE) is a CPU extension that allows to protect against certain
+     * Called by a device owner or profile owner of an organization-owned device to set the Memory
+     * Tagging Extension (MTE) policy. MTE is a CPU extension that allows to protect against certain
      * classes of security problems at a small runtime performance cost overhead.
      *
-     * @param policy the policy to be set
+     * <p>The MTE policy can only be set to {@link #MTE_DISABLED} if called by a device owner.
+     * Otherwise a {@link SecurityException} will be thrown.
+     *
+     * @throws SecurityException if caller is not device owner or profile owner of org-owned device
+     *     or if called on a parent instance
+     * @param policy the MTE policy to be set
      */
     public void setMtePolicy(@MtePolicy int policy) {
-        // TODO(b/244290023): implement
-        // This is SecurityException to temporarily make ParentProfileTest happy.
-        // This is not used.
-        throw new SecurityException("not implemented");
+        throwIfParentInstance("setMtePolicy");
+        if (mService != null) {
+            try {
+                mService.setMtePolicy(policy);
+            } catch (RemoteException e) {
+                throw e.rethrowFromSystemServer();
+            }
+        }
     }
 
     /**
-     * Get currently set MTE policy. This is not necessarily the same as the state of MTE on the
-     * device, as the device might not support MTE.
+     * Called by a device owner, a profile owner of an organization-owned device or the system to
+     * get the Memory Tagging Extension (MTE) policy
      *
-     * @return the currently set policy
+     * @throws SecurityException if caller is not device owner or profile owner of org-owned device
+     *                           or system uid, or if called on a parent instance
+     * @return the currently set MTE policy
      */
     public @MtePolicy int getMtePolicy() {
-        // TODO(b/244290023): implement
-        // This is SecurityException to temporarily make ParentProfileTest happy.
-        // This is not used.
-        throw new SecurityException("not implemented");
+        throwIfParentInstance("setMtePolicy");
+        if (mService != null) {
+            try {
+                return mService.getMtePolicy();
+            } catch (RemoteException e) {
+                throw e.rethrowFromSystemServer();
+            }
+        }
+        return MTE_NOT_CONTROLLED_BY_POLICY;
     }
 
     // TODO: Expose this as SystemAPI once we add the query API
@@ -14449,7 +14472,9 @@
      * @throws SecurityException if {@code admin} is not a profile owner
      *
      * @see #getCrossProfileCalendarPackages(ComponentName)
+     * @deprecated Use {@link #setCrossProfilePackages(ComponentName, Set)}.
      */
+    @Deprecated
     public void setCrossProfileCalendarPackages(@NonNull ComponentName admin,
             @Nullable Set<String> packageNames) {
         throwIfParentInstance("setCrossProfileCalendarPackages");
@@ -14475,7 +14500,9 @@
      * @throws SecurityException if {@code admin} is not a profile owner
      *
      * @see #setCrossProfileCalendarPackages(ComponentName, Set)
+     * @deprecated Use {@link #setCrossProfilePackages(ComponentName, Set)}.
      */
+    @Deprecated
     public @Nullable Set<String> getCrossProfileCalendarPackages(@NonNull ComponentName admin) {
         throwIfParentInstance("getCrossProfileCalendarPackages");
         if (mService != null) {
@@ -15415,10 +15442,13 @@
      *
      * @throws IllegalStateException When admin is not the device owner or there is no device owner.
      *
+     * @deprecated Use type-specific APIs (e.g. {@link #isFinancedDevice}).
      * @hide
      */
     @TestApi
     @DeviceOwnerType
+    @Deprecated
+    // TODO(b/259908270): remove
     public int getDeviceOwnerType(@NonNull ComponentName admin) {
         throwIfParentInstance("getDeviceOwnerType");
         if (mService != null) {
@@ -15432,6 +15462,20 @@
     }
 
     /**
+     * {@code true} if this device is financed.
+     * @hide
+     */
+    @RequiresPermission(anyOf = {
+            android.Manifest.permission.MANAGE_USERS,
+            android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS
+    })
+    public boolean isFinancedDevice() {
+        return isDeviceManaged()
+                && getDeviceOwnerType(getDeviceOwnerComponentOnAnyUser())
+                == DEVICE_OWNER_TYPE_FINANCED;
+    }
+
+    /**
      * Called by device owner or profile owner of an organization-owned managed profile to
      * enable or disable USB data signaling for the device. When disabled, USB data connections
      * (except from charging functions) are prohibited.
diff --git a/core/java/android/app/admin/DevicePolicyManagerInternal.java b/core/java/android/app/admin/DevicePolicyManagerInternal.java
index b6f0916..840f3a3 100644
--- a/core/java/android/app/admin/DevicePolicyManagerInternal.java
+++ b/core/java/android/app/admin/DevicePolicyManagerInternal.java
@@ -269,4 +269,14 @@
      * {@link #supportsResetOp(int)} is true.
      */
     public abstract void resetOp(int op, String packageName, @UserIdInt int userId);
+
+    /**
+     * Returns whether new "turn off work" behavior is enabled via feature flag.
+     */
+    public abstract boolean isKeepProfilesRunningEnabled();
+
+    /**
+     * True if either the entire device or the user is organization managed.
+     */
+    public abstract boolean isUserOrganizationManaged(@UserIdInt int userId);
 }
diff --git a/core/java/android/app/admin/DeviceStateCache.java b/core/java/android/app/admin/DeviceStateCache.java
index 7619aa2..d1d130d 100644
--- a/core/java/android/app/admin/DeviceStateCache.java
+++ b/core/java/android/app/admin/DeviceStateCache.java
@@ -15,6 +15,8 @@
  */
 package android.app.admin;
 
+import android.annotation.UserIdInt;
+
 import com.android.server.LocalServices;
 
 /**
@@ -43,6 +45,11 @@
     public abstract boolean isDeviceProvisioned();
 
     /**
+     * True if either the entire device or the user is organization managed.
+     */
+    public abstract boolean isUserOrganizationManaged(@UserIdInt int userHandle);
+
+    /**
      * Empty implementation.
      */
     private static class EmptyDeviceStateCache extends DeviceStateCache {
@@ -52,5 +59,10 @@
         public boolean isDeviceProvisioned() {
             return false;
         }
+
+        @Override
+        public boolean isUserOrganizationManaged(int userHandle) {
+            return false;
+        }
     }
 }
diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl
index 8a40265..5383dca 100644
--- a/core/java/android/app/admin/IDevicePolicyManager.aidl
+++ b/core/java/android/app/admin/IDevicePolicyManager.aidl
@@ -571,4 +571,7 @@
 
     void setApplicationExemptions(String packageName, in int[]exemptions);
     int[] getApplicationExemptions(String packageName);
+
+    void setMtePolicy(int flag);
+    int getMtePolicy();
 }
diff --git a/core/java/android/app/admin/SecurityLog.java b/core/java/android/app/admin/SecurityLog.java
index 904db5f..ca2e97e 100644
--- a/core/java/android/app/admin/SecurityLog.java
+++ b/core/java/android/app/admin/SecurityLog.java
@@ -96,6 +96,9 @@
             TAG_WIFI_DISCONNECTION,
             TAG_BLUETOOTH_CONNECTION,
             TAG_BLUETOOTH_DISCONNECTION,
+            TAG_PACKAGE_INSTALLED,
+            TAG_PACKAGE_UPDATED,
+            TAG_PACKAGE_UNINSTALLED,
     })
     public @interface SecurityLogTag {}
 
@@ -563,6 +566,39 @@
             SecurityLogTags.SECURITY_BLUETOOTH_DISCONNECTION;
 
     /**
+     * Indicates that a package is installed.
+     * The log entry contains the following information about the
+     * event, encapsulated in an {@link Object} array and accessible via
+     * {@link SecurityEvent#getData()}:
+     * <li> [0] Name of the package being installed ({@code String})
+     * <li> [1] Package version code ({@code Long})
+     * <li> [2] UserId of the user that installed this package ({@code Integer})
+     */
+    public static final int TAG_PACKAGE_INSTALLED = SecurityLogTags.SECURITY_PACKAGE_INSTALLED;
+
+    /**
+     * Indicates that a package is updated.
+     * The log entry contains the following information about the
+     * event, encapsulated in an {@link Object} array and accessible via
+     * {@link SecurityEvent#getData()}:
+     * <li> [0] Name of the package being updated ({@code String})
+     * <li> [1] Package version code ({@code Long})
+     * <li> [2] UserId of the user that updated this package ({@code Integer})
+     */
+    public static final int TAG_PACKAGE_UPDATED = SecurityLogTags.SECURITY_PACKAGE_UPDATED;
+
+    /**
+     * Indicates that a package is uninstalled.
+     * The log entry contains the following information about the
+     * event, encapsulated in an {@link Object} array and accessible via
+     * {@link SecurityEvent#getData()}:
+     * <li> [0] Name of the package being uninstalled ({@code String})
+     * <li> [1] Package version code ({@code Long})
+     * <li> [2] UserId of the user that uninstalled this package ({@code Integer})
+     */
+    public static final int TAG_PACKAGE_UNINSTALLED = SecurityLogTags.SECURITY_PACKAGE_UNINSTALLED;
+
+    /**
      * Event severity level indicating that the event corresponds to normal workflow.
      */
     public static final int LEVEL_INFO = 1;
@@ -772,6 +808,9 @@
                     break;
                 case SecurityLog.TAG_CERT_AUTHORITY_INSTALLED:
                 case SecurityLog.TAG_CERT_AUTHORITY_REMOVED:
+                case SecurityLog.TAG_PACKAGE_INSTALLED:
+                case SecurityLog.TAG_PACKAGE_UPDATED:
+                case SecurityLog.TAG_PACKAGE_UNINSTALLED:
                     try {
                         userId = getIntegerData(2);
                     } catch (Exception e) {
diff --git a/core/java/android/app/admin/SecurityLogTags.logtags b/core/java/android/app/admin/SecurityLogTags.logtags
index b06e5a5..e4af8dd 100644
--- a/core/java/android/app/admin/SecurityLogTags.logtags
+++ b/core/java/android/app/admin/SecurityLogTags.logtags
@@ -44,4 +44,7 @@
 210037 security_wifi_connection                 (bssid|3),(event_type|3),(reason|3)
 210038 security_wifi_disconnection              (bssid|3),(reason|3)
 210039 security_bluetooth_connection            (addr|3),(success|1),(reason|3)
-210040 security_bluetooth_disconnection         (addr|3),(reason|3)
\ No newline at end of file
+210040 security_bluetooth_disconnection         (addr|3),(reason|3)
+210041 security_package_installed               (package_name|3),(version_code|1),(user_id|1)
+210042 security_package_updated                 (package_name|3),(version_code|1),(user_id|1)
+210043 security_package_uninstalled             (package_name|3),(version_code|1),(user_id|1)
\ No newline at end of file
diff --git a/core/java/android/app/time/TimeState.java b/core/java/android/app/time/TimeState.java
index c209cde..1d9add2 100644
--- a/core/java/android/app/time/TimeState.java
+++ b/core/java/android/app/time/TimeState.java
@@ -29,11 +29,13 @@
 /**
  * A snapshot of the system time state.
  *
- * <p>{@code mUnixEpochTime} contains a snapshot of the system clock time and elapsed realtime clock
+ * <p>{@code unixEpochTime} contains a snapshot of the system clock time and elapsed realtime clock
  * time.
  *
- * <p>{@code mUserShouldConfirmTime} is {@code true} if the system has low confidence in the system
- * clock time.
+ * <p>{@code userShouldConfirmTime} is {@code true} if the system automatic time detection logic
+ * suggests that the user be asked to confirm the {@code unixEpochTime} value is correct via {@link
+ * TimeManager#confirmTime}. If it is not correct, the value can usually be changed via {@link
+ * TimeManager#setManualTime}.
  *
  * @hide
  */
diff --git a/core/java/android/app/time/TimeZoneState.java b/core/java/android/app/time/TimeZoneState.java
index beb6dc6..0febc34 100644
--- a/core/java/android/app/time/TimeZoneState.java
+++ b/core/java/android/app/time/TimeZoneState.java
@@ -32,8 +32,10 @@
  * <p>{@code id} contains the system's time zone ID setting, e.g. "America/Los_Angeles". This
  * will usually agree with {@code TimeZone.getDefault().getID()} but it can be empty in rare cases.
  *
- * <p>{@code userShouldConfirmId} is {@code true} if the system has low confidence in the current
- * time zone.
+ * <p>{@code userShouldConfirmId} is {@code true} if the system automatic time zone detection logic
+ * suggests that the user be asked to confirm the {@code id} value is correct via {@link
+ * TimeManager#confirmTimeZone}. If it is not correct, the value can usually be changed via {@link
+ * TimeManager#setManualTimeZone}.
  *
  * @hide
  */
diff --git a/core/java/android/app/time/UnixEpochTime.java b/core/java/android/app/time/UnixEpochTime.java
index 3a35f3c..61cbc5e 100644
--- a/core/java/android/app/time/UnixEpochTime.java
+++ b/core/java/android/app/time/UnixEpochTime.java
@@ -16,6 +16,7 @@
 
 package android.app.time;
 
+import android.annotation.CurrentTimeMillisLong;
 import android.annotation.ElapsedRealtimeLong;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
@@ -42,7 +43,7 @@
 @SystemApi
 public final class UnixEpochTime implements Parcelable {
     @ElapsedRealtimeLong private final long mElapsedRealtimeMillis;
-    private final long mUnixEpochTimeMillis;
+    @CurrentTimeMillisLong private final long mUnixEpochTimeMillis;
 
     public UnixEpochTime(@ElapsedRealtimeLong long elapsedRealtimeMillis,
             long unixEpochTimeMillis) {
@@ -91,11 +92,13 @@
     }
 
     /** Returns the elapsed realtime clock value. See {@link UnixEpochTime} for more information. */
-    public @ElapsedRealtimeLong long getElapsedRealtimeMillis() {
+    @ElapsedRealtimeLong
+    public long getElapsedRealtimeMillis() {
         return mElapsedRealtimeMillis;
     }
 
     /** Returns the unix epoch time value. See {@link UnixEpochTime} for more information. */
+    @CurrentTimeMillisLong
     public long getUnixEpochTimeMillis() {
         return mUnixEpochTimeMillis;
     }
diff --git a/core/java/android/companion/AssociationRequest.java b/core/java/android/companion/AssociationRequest.java
index 3325d1e..2e969f8 100644
--- a/core/java/android/companion/AssociationRequest.java
+++ b/core/java/android/companion/AssociationRequest.java
@@ -73,6 +73,21 @@
     public static final String DEVICE_PROFILE_WATCH = "android.app.role.COMPANION_DEVICE_WATCH";
 
     /**
+     * Device profile: glasses.
+     *
+     * If specified, the current request may have a modified UI to highlight that the device being
+     * set up is a glasses device, and some extra permissions may be granted to the app
+     * as a result.
+     *
+     * Using it requires declaring uses-permission
+     * {@link android.Manifest.permission#REQUEST_COMPANION_PROFILE_GLASSES} in the manifest.
+     *
+     * @see AssociationRequest.Builder#setDeviceProfile
+     */
+    @RequiresPermission(Manifest.permission.REQUEST_COMPANION_PROFILE_GLASSES)
+    public static final String DEVICE_PROFILE_GLASSES = "android.app.role.COMPANION_DEVICE_GLASSES";
+
+    /**
      * Device profile: a virtual display capable of rendering Android applications, and sending back
      * input events.
      *
@@ -87,6 +102,20 @@
             "android.app.role.COMPANION_DEVICE_APP_STREAMING";
 
     /**
+     * Device profile: a virtual device capable of rendering content from an Android host to a
+     * nearby device.
+     *
+     * Only applications that have been granted
+     * {@link android.Manifest.permission#REQUEST_COMPANION_PROFILE_NEARBY_DEVICE_STREAMING}
+     * are allowed to request to be associated with such devices.
+     *
+     * @see AssociationRequest.Builder#setDeviceProfile
+     */
+    @RequiresPermission(Manifest.permission.REQUEST_COMPANION_PROFILE_NEARBY_DEVICE_STREAMING)
+    public static final String DEVICE_PROFILE_NEARBY_DEVICE_STREAMING =
+            "android.app.role.COMPANION_DEVICE_NEARBY_DEVICE_STREAMING";
+
+    /**
      * Device profile: Android Automotive Projection
      *
      * Only applications that have been granted
@@ -116,7 +145,8 @@
     /** @hide */
     @Retention(RetentionPolicy.SOURCE)
     @StringDef(value = { DEVICE_PROFILE_WATCH, DEVICE_PROFILE_COMPUTER,
-            DEVICE_PROFILE_AUTOMOTIVE_PROJECTION, DEVICE_PROFILE_APP_STREAMING })
+            DEVICE_PROFILE_AUTOMOTIVE_PROJECTION, DEVICE_PROFILE_APP_STREAMING,
+            DEVICE_PROFILE_GLASSES, DEVICE_PROFILE_NEARBY_DEVICE_STREAMING })
     public @interface DeviceProfile {}
 
     /**
diff --git a/core/java/android/companion/virtual/IVirtualDevice.aidl b/core/java/android/companion/virtual/IVirtualDevice.aidl
index 5c47ea2..f17d186 100644
--- a/core/java/android/companion/virtual/IVirtualDevice.aidl
+++ b/core/java/android/companion/virtual/IVirtualDevice.aidl
@@ -33,6 +33,7 @@
 import android.hardware.input.VirtualMouseScrollEvent;
 import android.hardware.input.VirtualTouchEvent;
 import android.hardware.input.VirtualTouchscreenConfig;
+import android.hardware.input.VirtualNavigationTouchpadConfig;
 import android.os.ResultReceiver;
 
 /**
@@ -84,6 +85,10 @@
     void createVirtualTouchscreen(
             in VirtualTouchscreenConfig config,
             IBinder token);
+    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE)")
+    void createVirtualNavigationTouchpad(
+            in VirtualNavigationTouchpadConfig config,
+            IBinder token);
     void unregisterInputDevice(IBinder token);
     int getInputDeviceId(IBinder token);
     boolean sendDpadKeyEvent(IBinder token, in VirtualKeyEvent event);
diff --git a/core/java/android/companion/virtual/IVirtualDeviceManager.aidl b/core/java/android/companion/virtual/IVirtualDeviceManager.aidl
index 7d6336a..6e784b2 100644
--- a/core/java/android/companion/virtual/IVirtualDeviceManager.aidl
+++ b/core/java/android/companion/virtual/IVirtualDeviceManager.aidl
@@ -51,6 +51,11 @@
      */
     List<VirtualDevice> getVirtualDevices();
 
+   /**
+     * Returns the ID of the device which owns the display with the given ID.
+     */
+    int getDeviceIdForDisplayId(int displayId);
+
     /**
      * Returns the device policy for the given virtual device and policy type.
      */
diff --git a/core/java/android/companion/virtual/VirtualDevice.java b/core/java/android/companion/virtual/VirtualDevice.java
index 9e95d47..f3f43354 100644
--- a/core/java/android/companion/virtual/VirtualDevice.java
+++ b/core/java/android/companion/virtual/VirtualDevice.java
@@ -38,9 +38,9 @@
      * @hide
      */
     public VirtualDevice(int id, @Nullable String name) {
-        if (id <= VirtualDeviceManager.DEFAULT_DEVICE_ID) {
+        if (id <= VirtualDeviceManager.DEVICE_ID_DEFAULT) {
             throw new IllegalArgumentException("VirtualDevice ID mist be greater than "
-                    + VirtualDeviceManager.DEFAULT_DEVICE_ID);
+                    + VirtualDeviceManager.DEVICE_ID_DEFAULT);
         }
         mId = id;
         mName = name;
diff --git a/core/java/android/companion/virtual/VirtualDeviceManager.java b/core/java/android/companion/virtual/VirtualDeviceManager.java
index 0e6cfb1..dba7c8e 100644
--- a/core/java/android/companion/virtual/VirtualDeviceManager.java
+++ b/core/java/android/companion/virtual/VirtualDeviceManager.java
@@ -29,11 +29,14 @@
 import android.companion.AssociationInfo;
 import android.companion.virtual.audio.VirtualAudioDevice;
 import android.companion.virtual.audio.VirtualAudioDevice.AudioConfigurationChangeCallback;
+import android.companion.virtual.camera.VirtualCameraDevice;
+import android.companion.virtual.camera.VirtualCameraInput;
 import android.companion.virtual.sensor.VirtualSensor;
 import android.companion.virtual.sensor.VirtualSensorConfig;
 import android.content.ComponentName;
 import android.content.Context;
 import android.graphics.Point;
+import android.hardware.camera2.CameraCharacteristics;
 import android.hardware.display.DisplayManager;
 import android.hardware.display.DisplayManager.VirtualDisplayFlag;
 import android.hardware.display.DisplayManagerGlobal;
@@ -46,6 +49,8 @@
 import android.hardware.input.VirtualKeyboardConfig;
 import android.hardware.input.VirtualMouse;
 import android.hardware.input.VirtualMouseConfig;
+import android.hardware.input.VirtualNavigationTouchpad;
+import android.hardware.input.VirtualNavigationTouchpadConfig;
 import android.hardware.input.VirtualTouchscreen;
 import android.hardware.input.VirtualTouchscreenConfig;
 import android.os.Binder;
@@ -88,12 +93,12 @@
     /**
      * The default device ID, which is the ID of the primary (non-virtual) device.
      */
-    public static final int DEFAULT_DEVICE_ID = 0;
+    public static final int DEVICE_ID_DEFAULT = 0;
 
     /**
      * Invalid device ID.
      */
-    public static final int INVALID_DEVICE_ID = -1;
+    public static final int DEVICE_ID_INVALID = -1;
 
     /**
      * Broadcast Action: A Virtual Device was removed.
@@ -231,6 +236,23 @@
     }
 
     /**
+     * Returns the ID of the device which owns the display with the given ID.
+     *
+     * @hide
+     */
+    public int getDeviceIdForDisplayId(int displayId) {
+        if (mService == null) {
+            Log.w(TAG, "Failed to retrieve virtual devices; no virtual device manager service.");
+            return DEVICE_ID_DEFAULT;
+        }
+        try {
+            return mService.getDeviceIdForDisplayId(displayId);
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
+    /**
      * A virtual device has its own virtual display, audio output, microphone, and camera etc. The
      * creator of a virtual device can take the output from the virtual display and stream it over
      * to another device, and inject input events that are received from the remote device.
@@ -276,9 +298,11 @@
                     }
                 };
         @Nullable
-        private VirtualAudioDevice mVirtualAudioDevice;
+        private VirtualCameraDevice mVirtualCameraDevice;
         @NonNull
-        private List<VirtualSensor> mVirtualSensors = new ArrayList<>();
+        private final List<VirtualSensor> mVirtualSensors = new ArrayList<>();
+        @Nullable
+        private VirtualAudioDevice mVirtualAudioDevice;
 
         @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE)
         private VirtualDevice(
@@ -638,6 +662,30 @@
         }
 
         /**
+         * Creates a virtual touchpad in navigation mode.
+         *
+         * A touchpad in navigation mode means that its events are interpreted as navigation events
+         * (up, down, etc) instead of using them to update a cursor's absolute position. If the
+         * events are not consumed they are converted to DPAD events.
+         *
+         * @param config the configurations of the virtual navigation touchpad.
+         */
+        @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE)
+        @NonNull
+        public VirtualNavigationTouchpad createVirtualNavigationTouchpad(
+                 @NonNull VirtualNavigationTouchpadConfig config) {
+            try {
+                final IBinder token = new Binder(
+                        "android.hardware.input.VirtualNavigationTouchpad:"
+                            + config.getInputDeviceName());
+                mVirtualDevice.createVirtualNavigationTouchpad(config, token);
+                return new VirtualNavigationTouchpad(mVirtualDevice, token);
+            } catch (RemoteException e) {
+                throw e.rethrowFromSystemServer();
+            }
+        }
+
+        /**
          * Creates a virtual touchscreen.
          *
          * @param display         the display that the events inputted through this device should
@@ -699,6 +747,34 @@
         }
 
         /**
+         * Creates a new virtual camera. If a virtual camera was already created, it will be closed.
+         *
+         * @param cameraName name of the virtual camera.
+         * @param characteristics camera characteristics.
+         * @param virtualCameraInput callback that provides input to camera.
+         * @param executor Executor on which camera input will be sent into system. Don't
+         *         use the Main Thread for this executor.
+         * @return newly created camera;
+         *
+         * @hide
+         */
+        @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE)
+        @NonNull
+        public VirtualCameraDevice createVirtualCameraDevice(
+                @NonNull String cameraName,
+                @NonNull CameraCharacteristics characteristics,
+                @NonNull VirtualCameraInput virtualCameraInput,
+                @NonNull Executor executor) {
+            if (mVirtualCameraDevice != null) {
+                mVirtualCameraDevice.close();
+            }
+            int deviceId = getDeviceId();
+            mVirtualCameraDevice = new VirtualCameraDevice(
+                    deviceId, cameraName, characteristics, virtualCameraInput, executor);
+            return mVirtualCameraDevice;
+        }
+
+        /**
          * Sets the visibility of the pointer icon for this VirtualDevice's associated displays.
          *
          * @param showPointerIcon True if the pointer should be shown; false otherwise. The default
@@ -726,11 +802,11 @@
 
         private String getVirtualDisplayName() {
             try {
-                // Currently this just use the association ID, which means all of the virtual
-                // displays created using the same virtual device will have the same name. The name
-                // should only be used for informational purposes, and not for identifying the
-                // display in code.
-                return "VirtualDevice_" + mVirtualDevice.getAssociationId();
+                // Currently this just use the device ID, which means all of the virtual displays
+                // created using the same virtual device will have the same name. The name should
+                // only be used for informational purposes, and not for identifying the display in
+                // code.
+                return "VirtualDevice_" + mVirtualDevice.getDeviceId();
             } catch (RemoteException e) {
                 throw e.rethrowFromSystemServer();
             }
diff --git a/core/java/android/companion/virtual/camera/VirtualCameraDevice.java b/core/java/android/companion/virtual/camera/VirtualCameraDevice.java
new file mode 100644
index 0000000..a7eba87
--- /dev/null
+++ b/core/java/android/companion/virtual/camera/VirtualCameraDevice.java
@@ -0,0 +1,82 @@
+/*
+ * 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 android.companion.virtual.camera;
+
+import android.hardware.camera2.CameraCharacteristics;
+
+import androidx.annotation.NonNull;
+
+import java.util.Locale;
+import java.util.Objects;
+import java.util.concurrent.Executor;
+
+/**
+ * Virtual camera that is used to send image data into system.
+ *
+ * @hide
+ */
+public final class VirtualCameraDevice implements AutoCloseable {
+
+    @NonNull
+    private final String mCameraDeviceName;
+    @NonNull
+    private final CameraCharacteristics mCameraCharacteristics;
+    @NonNull
+    private final VirtualCameraOutput mCameraOutput;
+    private boolean mCameraRegistered = false;
+
+    /**
+     * VirtualCamera device constructor.
+     *
+     * @param virtualDeviceId ID of virtual device to which camera will be added.
+     * @param cameraName must be unique for each camera per virtual device.
+     * @param characteristics of camera that will be passed into system in order to describe
+     *         camera.
+     * @param virtualCameraInput component that provides image data.
+     * @param executor on which to collect image data and pass it into system.
+     */
+    public VirtualCameraDevice(int virtualDeviceId, @NonNull String cameraName,
+            @NonNull CameraCharacteristics characteristics,
+            @NonNull VirtualCameraInput virtualCameraInput, @NonNull Executor executor) {
+        Objects.requireNonNull(cameraName);
+        mCameraCharacteristics = Objects.requireNonNull(characteristics);
+        mCameraDeviceName = generateCameraDeviceName(virtualDeviceId, cameraName);
+        mCameraOutput = new VirtualCameraOutput(virtualCameraInput, executor);
+        registerCamera();
+    }
+
+    private static String generateCameraDeviceName(int deviceId, @NonNull String cameraName) {
+        return String.format(Locale.ENGLISH, "%d_%s", deviceId, Objects.requireNonNull(cameraName));
+    }
+
+    @Override
+    public void close() {
+        if (!mCameraRegistered) {
+            return;
+        }
+
+        mCameraOutput.closeStream();
+    }
+
+    private void registerCamera() {
+        if (mCameraRegistered) {
+            return;
+        }
+
+        mCameraRegistered = true;
+    }
+}
diff --git a/core/java/android/companion/virtual/camera/VirtualCameraInput.java b/core/java/android/companion/virtual/camera/VirtualCameraInput.java
new file mode 100644
index 0000000..690a64b
--- /dev/null
+++ b/core/java/android/companion/virtual/camera/VirtualCameraInput.java
@@ -0,0 +1,54 @@
+/*
+ * 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 android.companion.virtual.camera;
+
+import android.annotation.NonNull;
+import android.hardware.camera2.params.InputConfiguration;
+
+import java.io.InputStream;
+
+/***
+ *  Used for sending image data into virtual camera.
+ *  <p>
+ *  The system will call {@link  #openStream(InputConfiguration)} to signal when you
+ *  should start sending Camera image data.
+ *  When Camera is no longer needed, or there is change in configuration
+ *  {@link #closeStream()} will be called. At that time finish sending current
+ *  image data and then close the stream.
+ *  <p>
+ *  If Camera image data is needed again, {@link #openStream(InputConfiguration)} will be
+ *  called by the system.
+ *
+ * @hide
+ */
+public interface VirtualCameraInput {
+
+    /**
+     * Opens a new image stream for the provided {@link InputConfiguration}.
+     *
+     * @param inputConfiguration image data configuration.
+     * @return image data stream.
+     */
+    @NonNull
+    InputStream openStream(@NonNull InputConfiguration inputConfiguration);
+
+    /**
+     * Stop sending image data and close {@link InputStream} provided in {@link
+     * #openStream(InputConfiguration)}. Do nothing if there is currently no active stream.
+     */
+    void closeStream();
+}
diff --git a/core/java/android/companion/virtual/camera/VirtualCameraOutput.java b/core/java/android/companion/virtual/camera/VirtualCameraOutput.java
new file mode 100644
index 0000000..fa1c3ad
--- /dev/null
+++ b/core/java/android/companion/virtual/camera/VirtualCameraOutput.java
@@ -0,0 +1,197 @@
+/*
+ * 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 android.companion.virtual.camera;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.hardware.camera2.params.InputConfiguration;
+import android.os.ParcelFileDescriptor;
+import android.util.Log;
+
+import com.android.internal.annotations.VisibleForTesting;
+
+import java.io.FileDescriptor;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Objects;
+import java.util.concurrent.Executor;
+
+/**
+ * Component for providing Camera data to the system.
+ * <p>
+ * {@link #getStreamDescriptor(InputConfiguration)} will be called by the system when Camera should
+ * start sending image data. Camera data will continue to be sent into {@link ParcelFileDescriptor}
+ * until {@link #closeStream()} is called by the system, at which point {@link ParcelFileDescriptor}
+ * will be closed.
+ *
+ * @hide
+ */
+@VisibleForTesting
+public class VirtualCameraOutput {
+
+    private static final String TAG = "VirtualCameraDeviceImpl";
+
+    @NonNull
+    private final VirtualCameraInput mVirtualCameraInput;
+    @NonNull
+    private final Executor mExecutor;
+    @Nullable
+    private VirtualCameraStream mCameraStream;
+
+    @VisibleForTesting
+    public VirtualCameraOutput(@NonNull VirtualCameraInput cameraInput,
+            @NonNull Executor executor) {
+        mVirtualCameraInput = Objects.requireNonNull(cameraInput);
+        mExecutor = Objects.requireNonNull(executor);
+    }
+
+    /**
+     * Get a read Descriptor on which Camera HAL will receive data. At any point in time there can
+     * exist a maximum of one active {@link ParcelFileDescriptor}.
+     * Calling this method with a different {@link InputConfiguration} is going to close the
+     * previously created file descriptor.
+     *
+     * @param imageConfiguration for which to create the {@link ParcelFileDescriptor}.
+     * @return Newly created ParcelFileDescriptor if stream param is different from previous or if
+     *         this is first time call. Will return null if there was an error during Descriptor
+     *         creation process.
+     */
+    @Nullable
+    @VisibleForTesting
+    public ParcelFileDescriptor getStreamDescriptor(
+            @NonNull InputConfiguration imageConfiguration) {
+        Objects.requireNonNull(imageConfiguration);
+
+        // Reuse same descriptor if stream is the same, otherwise create a new one.
+        try {
+            if (mCameraStream == null) {
+                mCameraStream = new VirtualCameraStream(imageConfiguration, mExecutor);
+            } else if (!mCameraStream.isSameConfiguration(imageConfiguration)) {
+                mCameraStream.close();
+                mCameraStream = new VirtualCameraStream(imageConfiguration, mExecutor);
+            }
+        } catch (IOException exception) {
+            Log.e(TAG, "Unable to open file descriptor.", exception);
+            return null;
+        }
+
+        InputStream imageStream = mVirtualCameraInput.openStream(imageConfiguration);
+        mCameraStream.startSending(imageStream);
+        return mCameraStream.getDescriptor();
+    }
+
+    /**
+     * Closes currently opened stream. If there is no stream, do nothing.
+     */
+    @VisibleForTesting
+    public void closeStream() {
+        mVirtualCameraInput.closeStream();
+        if (mCameraStream != null) {
+            mCameraStream.close();
+            mCameraStream = null;
+        }
+
+        try {
+            mVirtualCameraInput.closeStream();
+        } catch (Exception e) {
+            Log.e(TAG, "Error during closing stream.", e);
+        }
+    }
+
+    private static class VirtualCameraStream implements AutoCloseable {
+
+        private static final String TAG = "VirtualCameraStream";
+        private static final int BUFFER_SIZE = 1024;
+
+        private static final int SENDING_STATE_INITIAL = 0;
+        private static final int SENDING_STATE_IN_PROGRESS = 1;
+        private static final int SENDING_STATE_CLOSED = 2;
+
+        @NonNull
+        private final InputConfiguration mImageConfiguration;
+        @NonNull
+        private final Executor mExecutor;
+        @Nullable
+        private final ParcelFileDescriptor mReadDescriptor;
+        @Nullable
+        private final ParcelFileDescriptor mWriteDescriptor;
+        private int mSendingState;
+
+        VirtualCameraStream(@NonNull InputConfiguration imageConfiguration,
+                @NonNull Executor executor) throws IOException {
+            mSendingState = SENDING_STATE_INITIAL;
+            mImageConfiguration = Objects.requireNonNull(imageConfiguration);
+            mExecutor = Objects.requireNonNull(executor);
+            ParcelFileDescriptor[] parcels = ParcelFileDescriptor.createPipe();
+            mReadDescriptor = parcels[0];
+            mWriteDescriptor = parcels[1];
+        }
+
+        boolean isSameConfiguration(@NonNull InputConfiguration imageConfiguration) {
+            return mImageConfiguration == Objects.requireNonNull(imageConfiguration);
+        }
+
+        @Nullable
+        ParcelFileDescriptor getDescriptor() {
+            return mReadDescriptor;
+        }
+
+        public void startSending(@NonNull InputStream inputStream) {
+            Objects.requireNonNull(inputStream);
+
+            if (mSendingState != SENDING_STATE_INITIAL) {
+                return;
+            }
+
+            mSendingState = SENDING_STATE_IN_PROGRESS;
+            mExecutor.execute(() -> sendData(inputStream));
+        }
+
+        @Override
+        public void close() {
+            mSendingState = SENDING_STATE_CLOSED;
+            try {
+                mReadDescriptor.close();
+            } catch (IOException e) {
+                Log.e(TAG, "Unable to close read descriptor.", e);
+            }
+            try {
+                mWriteDescriptor.close();
+            } catch (IOException e) {
+                Log.e(TAG, "Unable to close write descriptor.", e);
+            }
+        }
+
+        private void sendData(@NonNull InputStream inputStream) {
+            Objects.requireNonNull(inputStream);
+
+            byte[] buffer = new byte[BUFFER_SIZE];
+            FileDescriptor fd = mWriteDescriptor.getFileDescriptor();
+            try (FileOutputStream outputStream = new FileOutputStream(fd)) {
+                while (mSendingState == SENDING_STATE_IN_PROGRESS) {
+                    int bytesRead = inputStream.read(buffer, 0, BUFFER_SIZE);
+                    if (bytesRead < 1) continue;
+
+                    outputStream.write(buffer, 0, bytesRead);
+                }
+            } catch (IOException e) {
+                Log.e(TAG, "Error while sending camera data.", e);
+            }
+        }
+    }
+}
diff --git a/core/java/android/content/ContentProvider.java b/core/java/android/content/ContentProvider.java
index da486ee..5a153ce 100644
--- a/core/java/android/content/ContentProvider.java
+++ b/core/java/android/content/ContentProvider.java
@@ -21,6 +21,11 @@
 import static android.os.Process.myUserHandle;
 import static android.os.Trace.TRACE_TAG_DATABASE;
 
+import static com.android.internal.util.FrameworkStatsLog.GET_TYPE_ACCESSED_WITHOUT_PERMISSION;
+import static com.android.internal.util.FrameworkStatsLog.GET_TYPE_ACCESSED_WITHOUT_PERMISSION__LOCATION__PROVIDER_CHECK_URI_PERMISSION;
+import static com.android.internal.util.FrameworkStatsLog.GET_TYPE_ACCESSED_WITHOUT_PERMISSION__LOCATION__PROVIDER_ERROR;
+import static com.android.internal.util.FrameworkStatsLog.GET_TYPE_ACCESSED_WITHOUT_PERMISSION__LOCATION__PROVIDER_FRAMEWORK_PERMISSION;
+
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.annotation.SystemApi;
@@ -58,6 +63,7 @@
 import android.util.SparseBooleanArray;
 
 import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.util.FrameworkStatsLog;
 
 import java.io.File;
 import java.io.FileDescriptor;
@@ -300,7 +306,11 @@
             uri = maybeGetUriWithoutUserId(uri);
             traceBegin(TRACE_TAG_DATABASE, "getType: ", uri.getAuthority());
             try {
-                return mInterface.getType(uri);
+                final String type = mInterface.getType(uri);
+                if (type != null) {
+                    logGetTypeData(Binder.getCallingUid(), uri, type);
+                }
+                return type;
             } catch (RemoteException e) {
                 throw e.rethrowAsRuntimeException();
             } finally {
@@ -308,6 +318,48 @@
             }
         }
 
+        // Utility function to log the getTypeData calls
+        private void logGetTypeData(int callingUid, Uri uri, String type) {
+            final int enumFrameworkPermission =
+                    GET_TYPE_ACCESSED_WITHOUT_PERMISSION__LOCATION__PROVIDER_FRAMEWORK_PERMISSION;
+            final int enumCheckUriPermission =
+                    GET_TYPE_ACCESSED_WITHOUT_PERMISSION__LOCATION__PROVIDER_CHECK_URI_PERMISSION;
+            final int enumError = GET_TYPE_ACCESSED_WITHOUT_PERMISSION__LOCATION__PROVIDER_ERROR;
+
+            try {
+                final AttributionSource attributionSource = new AttributionSource.Builder(
+                        callingUid).build();
+                try {
+                    if (enforceReadPermission(attributionSource, uri)
+                            != PermissionChecker.PERMISSION_GRANTED) {
+                        FrameworkStatsLog.write(GET_TYPE_ACCESSED_WITHOUT_PERMISSION,
+                                enumFrameworkPermission,
+                                callingUid, uri.getAuthority(), type);
+                    } else {
+                        final ProviderInfo cpi = mContext.getPackageManager()
+                                .resolveContentProvider(uri.getAuthority(),
+                                PackageManager.ComponentInfoFlags.of(PackageManager.GET_META_DATA));
+                        if (cpi.forceUriPermissions
+                                && mInterface.checkUriPermission(uri,
+                                callingUid, Intent.FLAG_GRANT_READ_URI_PERMISSION)
+                                != PermissionChecker.PERMISSION_GRANTED) {
+                            FrameworkStatsLog.write(GET_TYPE_ACCESSED_WITHOUT_PERMISSION,
+                                    enumCheckUriPermission,
+                                    callingUid, uri.getAuthority(), type);
+                        }
+                    }
+                } catch (SecurityException e) {
+                    FrameworkStatsLog.write(GET_TYPE_ACCESSED_WITHOUT_PERMISSION,
+                            enumFrameworkPermission,
+                            callingUid, uri.getAuthority(), type);
+                }
+            } catch (Exception e) {
+                FrameworkStatsLog.write(GET_TYPE_ACCESSED_WITHOUT_PERMISSION,
+                        enumError,
+                        callingUid, uri.getAuthority(), type);
+            }
+        }
+
         @Override
         public void getTypeAsync(Uri uri, RemoteCallback callback) {
             final Bundle result = new Bundle();
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index 9f9fd3c..382e2bb 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -5937,6 +5937,14 @@
     public static final String FILE_INTEGRITY_SERVICE = "file_integrity";
 
     /**
+     * Binder service for remote key provisioning.
+     *
+     * @see android.frameworks.rkp.IRemoteProvisioning
+     * @hide
+     */
+    public static final String REMOTE_PROVISIONING_SERVICE = "remote_provisioning";
+
+    /**
      * Use with {@link #getSystemService(String)} to retrieve a
      * {@link android.hardware.lights.LightsManager} for controlling device lights.
      *
@@ -6895,7 +6903,7 @@
      * <p>
      * Applications that run on virtual devices may use this method to access the default device
      * capabilities and functionality (by passing
-     * {@link android.companion.virtual.VirtualDeviceManager#DEFAULT_DEVICE_ID}. Similarly,
+     * {@link android.companion.virtual.VirtualDeviceManager#DEVICE_ID_DEFAULT}. Similarly,
      * applications running on the default device may access the functionality of virtual devices.
      * </p>
      * @param deviceId The ID of the device to associate with this context.
@@ -7237,7 +7245,7 @@
      * determine whether they are running on a virtual device and identify that device.
      *
      * The device ID of the host device is
-     * {@link android.companion.virtual.VirtualDeviceManager#DEFAULT_DEVICE_ID}
+     * {@link android.companion.virtual.VirtualDeviceManager#DEVICE_ID_DEFAULT}
      *
      * @return the ID of the device this context is associated with.
      * @see #createDeviceContext(int)
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 86a672f..8aa0454 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -2422,6 +2422,30 @@
     public static final String ACTION_SAFETY_CENTER =
             "android.intent.action.SAFETY_CENTER";
 
+    /**
+     * Activity action: Launch the UI to view recent updates that installed apps have made to their
+     * data sharing policy in their safety labels.
+     *
+     * <p>
+     * Input: Nothing.
+     * </p>
+     * <p>
+     * Output: Nothing.
+     * </p>
+     *
+     * <p class="note">
+     * This intent action requires the {@link android.Manifest.permission#GRANT_RUNTIME_PERMISSIONS}
+     * permission.
+     * </p>
+     *
+     * @hide
+     */
+    @SystemApi
+    @RequiresPermission(Manifest.permission.GRANT_RUNTIME_PERMISSIONS)
+    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
+    public static final String ACTION_REVIEW_APP_DATA_SHARING_UPDATES =
+            "android.intent.action.REVIEW_APP_DATA_SHARING_UPDATES";
+
     // ---------------------------------------------------------------------
     // ---------------------------------------------------------------------
     // Standard intent broadcast actions (see action variable).
@@ -6093,9 +6117,8 @@
     public static final String EXTRA_UID = "android.intent.extra.UID";
 
     /**
-     * @hide String array of package names.
+     * String array of package names.
      */
-    @SystemApi
     public static final String EXTRA_PACKAGES = "android.intent.extra.PACKAGES";
 
     /**
diff --git a/core/java/android/content/om/TEST_MAPPING b/core/java/android/content/om/TEST_MAPPING
index 6185cf6..a9aaf1a 100644
--- a/core/java/android/content/om/TEST_MAPPING
+++ b/core/java/android/content/om/TEST_MAPPING
@@ -12,6 +12,9 @@
       "name": "OverlayDeviceTests"
     },
     {
+      "name": "SelfTargetingOverlayDeviceTests"
+    },
+    {
       "name": "OverlayHostTests"
     },
     {
@@ -35,6 +38,9 @@
         },
         {
           "include-filter": "android.content.om.cts"
+        },
+        {
+          "include-filter": "android.content.res.loader.cts"
         }
       ]
     }
diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java
index 2c28268..84811ea 100644
--- a/core/java/android/content/pm/ApplicationInfo.java
+++ b/core/java/android/content/pm/ApplicationInfo.java
@@ -1528,12 +1528,14 @@
      * the application, e.g. the target SDK version.
      * @hide
      */
+    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
     public static final int HIDDEN_API_ENFORCEMENT_DEFAULT = -1;
     /**
      * No API enforcement; the app can access the entire internal private API. Only for use by
      * system apps.
      * @hide
      */
+    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
     public static final int HIDDEN_API_ENFORCEMENT_DISABLED = 0;
     /**
      * No API enforcement, but enable the detection logic and warnings. Observed behaviour is the
@@ -1541,11 +1543,13 @@
      * APIs are accessed.
      * @hide
      * */
+    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
     public static final int HIDDEN_API_ENFORCEMENT_JUST_WARN = 1;
     /**
      * Dark grey list enforcement. Enforces the dark grey and black lists
      * @hide
      */
+    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
     public static final int HIDDEN_API_ENFORCEMENT_ENABLED = 2;
 
     private static final int HIDDEN_API_ENFORCEMENT_MIN = HIDDEN_API_ENFORCEMENT_DEFAULT;
diff --git a/core/java/android/content/pm/IPackageInstaller.aidl b/core/java/android/content/pm/IPackageInstaller.aidl
index 1e928bd..115d4b0 100644
--- a/core/java/android/content/pm/IPackageInstaller.aidl
+++ b/core/java/android/content/pm/IPackageInstaller.aidl
@@ -69,4 +69,7 @@
     void setSilentUpdatesThrottleTime(long throttleTimeInSeconds);
     void checkInstallConstraints(String installerPackageName, in List<String> packageNames,
             in PackageInstaller.InstallConstraints constraints, in RemoteCallback callback);
+    void waitForInstallConstraints(String installerPackageName, in List<String> packageNames,
+            in PackageInstaller.InstallConstraints constraints, in IntentSender callback,
+            long timeout);
 }
diff --git a/core/java/android/content/pm/PackageInstaller.java b/core/java/android/content/pm/PackageInstaller.java
index 1f01ae9..f17d8fa 100644
--- a/core/java/android/content/pm/PackageInstaller.java
+++ b/core/java/android/content/pm/PackageInstaller.java
@@ -30,6 +30,7 @@
 import android.Manifest;
 import android.annotation.CallbackExecutor;
 import android.annotation.CurrentTimeMillisLong;
+import android.annotation.DurationMillisLong;
 import android.annotation.IntDef;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
@@ -248,6 +249,24 @@
      */
     public static final String EXTRA_STORAGE_PATH = "android.content.pm.extra.STORAGE_PATH";
 
+    /**
+     * The {@link InstallConstraints} object.
+     *
+     * @see Intent#getParcelableExtra(String, Class)
+     * @see #waitForInstallConstraints(List, InstallConstraints, IntentSender, long)
+     */
+    public static final String EXTRA_INSTALL_CONSTRAINTS =
+            "android.content.pm.extra.INSTALL_CONSTRAINTS";
+
+    /**
+     * The {@link InstallConstraintsResult} object.
+     *
+     * @see Intent#getParcelableExtra(String, Class)
+     * @see #waitForInstallConstraints(List, InstallConstraints, IntentSender, long)
+     */
+    public static final String EXTRA_INSTALL_CONSTRAINTS_RESULT =
+            "android.content.pm.extra.INSTALL_CONSTRAINTS_RESULT";
+
     /** {@hide} */
     @Deprecated
     public static final String EXTRA_PACKAGE_NAMES = "android.content.pm.extra.PACKAGE_NAMES";
@@ -885,6 +904,32 @@
     }
 
     /**
+     * Similar to {@link #checkInstallConstraints(List, InstallConstraints, Executor, Consumer)},
+     * but the callback is invoked only when the constraints are satisfied or after timeout.
+     *
+     * @param callback Called when the constraints are satisfied or after timeout.
+     *                 Intents sent to this callback contain:
+     *                 {@link Intent#EXTRA_PACKAGES} for the input package names,
+     *                 {@link #EXTRA_INSTALL_CONSTRAINTS} for the input constraints,
+     *                 {@link #EXTRA_INSTALL_CONSTRAINTS_RESULT} for the result.
+     * @param timeoutMillis The maximum time to wait, in milliseconds until the constraints are
+     *                      satisfied. Valid range is from 0 to one week. {@code 0} means the
+     *                      callback will be invoked immediately no matter constraints are
+     *                      satisfied or not.
+     */
+    public void waitForInstallConstraints(@NonNull List<String> packageNames,
+            @NonNull InstallConstraints constraints,
+            @NonNull IntentSender callback,
+            @DurationMillisLong long timeoutMillis) {
+        try {
+            mInstaller.waitForInstallConstraints(
+                    mInstallerPackageName, packageNames, constraints, callback, timeoutMillis);
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
+    /**
      * Events for observing session lifecycle.
      * <p>
      * A typical session lifecycle looks like this:
@@ -3807,7 +3852,7 @@
      * Note the constraints are applied transitively. If app Foo is used by app Bar (via shared
      * library or bounded service), the constraints will also be applied to Bar.
      */
-    @DataClass(genParcelable = true, genHiddenConstructor = true)
+    @DataClass(genParcelable = true, genHiddenConstructor = true, genEqualsHashCode=true)
     public static final class InstallConstraints implements Parcelable {
         /**
          * Preset constraints suitable for gentle update.
@@ -3968,6 +4013,41 @@
 
         @Override
         @DataClass.Generated.Member
+        public boolean equals(@Nullable Object o) {
+            // You can override field equality logic by defining either of the methods like:
+            // boolean fieldNameEquals(InstallConstraints other) { ... }
+            // boolean fieldNameEquals(FieldType otherValue) { ... }
+
+            if (this == o) return true;
+            if (o == null || getClass() != o.getClass()) return false;
+            @SuppressWarnings("unchecked")
+            InstallConstraints that = (InstallConstraints) o;
+            //noinspection PointlessBooleanExpression
+            return true
+                    && mRequireDeviceIdle == that.mRequireDeviceIdle
+                    && mRequireAppNotForeground == that.mRequireAppNotForeground
+                    && mRequireAppNotInteracting == that.mRequireAppNotInteracting
+                    && mRequireAppNotTopVisible == that.mRequireAppNotTopVisible
+                    && mRequireNotInCall == that.mRequireNotInCall;
+        }
+
+        @Override
+        @DataClass.Generated.Member
+        public int hashCode() {
+            // You can override field hashCode logic by defining methods like:
+            // int fieldNameHashCode() { ... }
+
+            int _hash = 1;
+            _hash = 31 * _hash + Boolean.hashCode(mRequireDeviceIdle);
+            _hash = 31 * _hash + Boolean.hashCode(mRequireAppNotForeground);
+            _hash = 31 * _hash + Boolean.hashCode(mRequireAppNotInteracting);
+            _hash = 31 * _hash + Boolean.hashCode(mRequireAppNotTopVisible);
+            _hash = 31 * _hash + Boolean.hashCode(mRequireNotInCall);
+            return _hash;
+        }
+
+        @Override
+        @DataClass.Generated.Member
         public void writeToParcel(@NonNull Parcel dest, int flags) {
             // You can override field parcelling by defining methods like:
             // void parcelFieldName(Parcel dest, int flags) { ... }
@@ -4023,10 +4103,10 @@
         };
 
         @DataClass.Generated(
-                time = 1668650523752L,
+                time = 1670207178734L,
                 codegenVersion = "1.0.23",
                 sourceFile = "frameworks/base/core/java/android/content/pm/PackageInstaller.java",
-                inputSignatures = "public static final @android.annotation.NonNull android.content.pm.PackageInstaller.InstallConstraints GENTLE_UPDATE\nprivate final  boolean mRequireDeviceIdle\nprivate final  boolean mRequireAppNotForeground\nprivate final  boolean mRequireAppNotInteracting\nprivate final  boolean mRequireAppNotTopVisible\nprivate final  boolean mRequireNotInCall\nclass InstallConstraints extends java.lang.Object implements [android.os.Parcelable]\nprivate  boolean mRequireDeviceIdle\nprivate  boolean mRequireAppNotForeground\nprivate  boolean mRequireAppNotInteracting\nprivate  boolean mRequireAppNotTopVisible\nprivate  boolean mRequireNotInCall\npublic @android.annotation.SuppressLint @android.annotation.NonNull android.content.pm.PackageInstaller.InstallConstraints.Builder requireDeviceIdle()\npublic @android.annotation.SuppressLint @android.annotation.NonNull android.content.pm.PackageInstaller.InstallConstraints.Builder requireAppNotForeground()\npublic @android.annotation.SuppressLint @android.annotation.NonNull android.content.pm.PackageInstaller.InstallConstraints.Builder requireAppNotInteracting()\npublic @android.annotation.SuppressLint @android.annotation.NonNull android.content.pm.PackageInstaller.InstallConstraints.Builder requireAppNotTopVisible()\npublic @android.annotation.SuppressLint @android.annotation.NonNull android.content.pm.PackageInstaller.InstallConstraints.Builder requireNotInCall()\npublic @android.annotation.NonNull android.content.pm.PackageInstaller.InstallConstraints build()\nclass Builder extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genParcelable=true, genHiddenConstructor=true)")
+                inputSignatures = "public static final @android.annotation.NonNull android.content.pm.PackageInstaller.InstallConstraints GENTLE_UPDATE\nprivate final  boolean mRequireDeviceIdle\nprivate final  boolean mRequireAppNotForeground\nprivate final  boolean mRequireAppNotInteracting\nprivate final  boolean mRequireAppNotTopVisible\nprivate final  boolean mRequireNotInCall\nclass InstallConstraints extends java.lang.Object implements [android.os.Parcelable]\nprivate  boolean mRequireDeviceIdle\nprivate  boolean mRequireAppNotForeground\nprivate  boolean mRequireAppNotInteracting\nprivate  boolean mRequireAppNotTopVisible\nprivate  boolean mRequireNotInCall\npublic @android.annotation.SuppressLint @android.annotation.NonNull android.content.pm.PackageInstaller.InstallConstraints.Builder requireDeviceIdle()\npublic @android.annotation.SuppressLint @android.annotation.NonNull android.content.pm.PackageInstaller.InstallConstraints.Builder requireAppNotForeground()\npublic @android.annotation.SuppressLint @android.annotation.NonNull android.content.pm.PackageInstaller.InstallConstraints.Builder requireAppNotInteracting()\npublic @android.annotation.SuppressLint @android.annotation.NonNull android.content.pm.PackageInstaller.InstallConstraints.Builder requireAppNotTopVisible()\npublic @android.annotation.SuppressLint @android.annotation.NonNull android.content.pm.PackageInstaller.InstallConstraints.Builder requireNotInCall()\npublic @android.annotation.NonNull android.content.pm.PackageInstaller.InstallConstraints build()\nclass Builder extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genParcelable=true, genHiddenConstructor=true, genEqualsHashCode=true)")
         @Deprecated
         private void __metadata() {}
 
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index 88b5e02..ec490d1 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -3849,7 +3849,10 @@
 
     /**
      * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
-     * The device supports running activities on secondary displays.
+     * The device supports running activities on secondary displays. Displays here
+     * refers to both physical and virtual displays. Disabling this feature can impact
+     * support for application projection use-cases and support for virtual devices
+     * on the device.
      */
     @SdkConstant(SdkConstantType.FEATURE)
     public static final String FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS
diff --git a/core/java/android/content/pm/PermissionInfo.java b/core/java/android/content/pm/PermissionInfo.java
index 61fc6f6..4fa80d7 100644
--- a/core/java/android/content/pm/PermissionInfo.java
+++ b/core/java/android/content/pm/PermissionInfo.java
@@ -250,6 +250,16 @@
 
     /**
      * Additional flag for {@link #protectionLevel}, corresponding
+     * to the <code>module</code> value of
+     * {@link android.R.attr#protectionLevel}.
+     *
+     * @hide
+     */
+    @SystemApi
+    public static final int PROTECTION_FLAG_MODULE = 0x400000;
+
+    /**
+     * Additional flag for {@link #protectionLevel}, corresponding
      * to the <code>companion</code> value of
      * {@link android.R.attr#protectionLevel}.
      *
@@ -320,6 +330,7 @@
             PROTECTION_FLAG_RECENTS,
             PROTECTION_FLAG_ROLE,
             PROTECTION_FLAG_KNOWN_SIGNER,
+            PROTECTION_FLAG_MODULE,
     })
     @Retention(RetentionPolicy.SOURCE)
     public @interface ProtectionFlags {}
@@ -593,6 +604,9 @@
         if ((level & PermissionInfo.PROTECTION_FLAG_KNOWN_SIGNER) != 0) {
             protLevel.append("|knownSigner");
         }
+        if ((level & PermissionInfo.PROTECTION_FLAG_MODULE) != 0) {
+            protLevel.append(("|module"));
+        }
         return protLevel.toString();
     }
 
diff --git a/core/java/android/content/pm/ServiceInfo.java b/core/java/android/content/pm/ServiceInfo.java
index fc2c532..6453ab0 100644
--- a/core/java/android/content/pm/ServiceInfo.java
+++ b/core/java/android/content/pm/ServiceInfo.java
@@ -308,9 +308,7 @@
      * permissions:
      * {@link android.Manifest.permission#ACTIVITY_RECOGNITION},
      * {@link android.Manifest.permission#BODY_SENSORS},
-     * {@link android.Manifest.permission#HIGH_SAMPLING_RATE_SENSORS},
-     * or one of the {@code "android.permission.health.*"} permissions defined in the
-     * {@link android.healthconnect.HealthPermissions}.
+     * {@link android.Manifest.permission#HIGH_SAMPLING_RATE_SENSORS}.
      */
     @RequiresPermission(
             allOf = {
@@ -320,8 +318,7 @@
                 Manifest.permission.ACTIVITY_RECOGNITION,
                 Manifest.permission.BODY_SENSORS,
                 Manifest.permission.HIGH_SAMPLING_RATE_SENSORS,
-            },
-            conditional = true
+            }
     )
     public static final int FOREGROUND_SERVICE_TYPE_HEALTH = 1 << 8;
 
diff --git a/core/java/android/content/pm/UserProperties.java b/core/java/android/content/pm/UserProperties.java
index fd35378..fb61b37 100644
--- a/core/java/android/content/pm/UserProperties.java
+++ b/core/java/android/content/pm/UserProperties.java
@@ -46,6 +46,8 @@
     private static final String ATTR_SHOW_IN_SETTINGS = "showInSettings";
     private static final String ATTR_INHERIT_DEVICE_POLICY = "inheritDevicePolicy";
     private static final String ATTR_USE_PARENTS_CONTACTS = "useParentsContacts";
+    private static final String ATTR_UPDATE_CROSS_PROFILE_INTENT_FILTERS_ON_OTA =
+            "updateCrossProfileIntentFiltersOnOTA";
 
     /** Index values of each property (to indicate whether they are present in this object). */
     @IntDef(prefix = "INDEX_", value = {
@@ -54,6 +56,7 @@
             INDEX_SHOW_IN_SETTINGS,
             INDEX_INHERIT_DEVICE_POLICY,
             INDEX_USE_PARENTS_CONTACTS,
+            INDEX_UPDATE_CROSS_PROFILE_INTENT_FILTERS_ON_OTA
     })
     @Retention(RetentionPolicy.SOURCE)
     private @interface PropertyIndex {
@@ -63,6 +66,7 @@
     private static final int INDEX_SHOW_IN_SETTINGS = 2;
     private static final int INDEX_INHERIT_DEVICE_POLICY = 3;
     private static final int INDEX_USE_PARENTS_CONTACTS = 4;
+    private static final int INDEX_UPDATE_CROSS_PROFILE_INTENT_FILTERS_ON_OTA = 5;
     /** A bit set, mapping each PropertyIndex to whether it is present (1) or absent (0). */
     private long mPropertiesPresent = 0;
 
@@ -199,6 +203,7 @@
             // Add items that require exposeAllFields to be true (strictest permission level).
             setStartWithParent(orig.getStartWithParent());
             setInheritDevicePolicy(orig.getInheritDevicePolicy());
+            setUpdateCrossProfileIntentFiltersOnOTA(orig.getUpdateCrossProfileIntentFiltersOnOTA());
         }
         if (hasManagePermission) {
             // Add items that require MANAGE_USERS or stronger.
@@ -354,6 +359,34 @@
      */
     private boolean mUseParentsContacts;
 
+    /**
+     * Returns true if user needs to update default
+     * {@link com.android.server.pm.CrossProfileIntentFilter} with its parents during an OTA update
+     * @hide
+     */
+    public boolean getUpdateCrossProfileIntentFiltersOnOTA() {
+        if (isPresent(INDEX_UPDATE_CROSS_PROFILE_INTENT_FILTERS_ON_OTA)) {
+            return mUpdateCrossProfileIntentFiltersOnOTA;
+        }
+        if (mDefaultProperties != null) {
+            return mDefaultProperties.mUpdateCrossProfileIntentFiltersOnOTA;
+        }
+        throw new SecurityException("You don't have permission to query "
+                + "updateCrossProfileIntentFiltersOnOTA");
+    }
+
+    /** @hide */
+    public void setUpdateCrossProfileIntentFiltersOnOTA(boolean val) {
+        this.mUpdateCrossProfileIntentFiltersOnOTA = val;
+        setPresent(INDEX_UPDATE_CROSS_PROFILE_INTENT_FILTERS_ON_OTA);
+    }
+
+    /*
+     Indicate if {@link com.android.server.pm.CrossProfileIntentFilter}s need to be updated during
+     OTA update between user-parent
+     */
+    private boolean mUpdateCrossProfileIntentFiltersOnOTA;
+
     @Override
     public String toString() {
         // Please print in increasing order of PropertyIndex.
@@ -364,6 +397,8 @@
                 + ", mShowInSettings=" + getShowInSettings()
                 + ", mInheritDevicePolicy=" + getInheritDevicePolicy()
                 + ", mUseParentsContacts=" + getUseParentsContacts()
+                + ", mUpdateCrossProfileIntentFiltersOnOTA="
+                + getUpdateCrossProfileIntentFiltersOnOTA()
                 + "}";
     }
 
@@ -380,6 +415,8 @@
         pw.println(prefix + "    mShowInSettings=" + getShowInSettings());
         pw.println(prefix + "    mInheritDevicePolicy=" + getInheritDevicePolicy());
         pw.println(prefix + "    mUseParentsContacts=" + getUseParentsContacts());
+        pw.println(prefix + "    mUpdateCrossProfileIntentFiltersOnOTA="
+                + getUpdateCrossProfileIntentFiltersOnOTA());
     }
 
     /**
@@ -428,6 +465,9 @@
                 case ATTR_USE_PARENTS_CONTACTS:
                     setUseParentsContacts(parser.getAttributeBoolean(i));
                     break;
+                case ATTR_UPDATE_CROSS_PROFILE_INTENT_FILTERS_ON_OTA:
+                    setUpdateCrossProfileIntentFiltersOnOTA(parser.getAttributeBoolean(i));
+                    break;
                 default:
                     Slog.w(LOG_TAG, "Skipping unknown property " + attributeName);
             }
@@ -462,6 +502,11 @@
             serializer.attributeBoolean(null, ATTR_USE_PARENTS_CONTACTS,
                     mUseParentsContacts);
         }
+        if (isPresent(INDEX_UPDATE_CROSS_PROFILE_INTENT_FILTERS_ON_OTA)) {
+            serializer.attributeBoolean(null,
+                    ATTR_UPDATE_CROSS_PROFILE_INTENT_FILTERS_ON_OTA,
+                    mUpdateCrossProfileIntentFiltersOnOTA);
+        }
     }
 
     // For use only with an object that has already had any permission-lacking fields stripped out.
@@ -473,6 +518,7 @@
         dest.writeInt(mShowInSettings);
         dest.writeInt(mInheritDevicePolicy);
         dest.writeBoolean(mUseParentsContacts);
+        dest.writeBoolean(mUpdateCrossProfileIntentFiltersOnOTA);
     }
 
     /**
@@ -488,6 +534,7 @@
         mShowInSettings = source.readInt();
         mInheritDevicePolicy = source.readInt();
         mUseParentsContacts = source.readBoolean();
+        mUpdateCrossProfileIntentFiltersOnOTA = source.readBoolean();
     }
 
     @Override
@@ -517,6 +564,7 @@
         private @ShowInSettings int mShowInSettings = SHOW_IN_SETTINGS_WITH_PARENT;
         private @InheritDevicePolicy int mInheritDevicePolicy = INHERIT_DEVICE_POLICY_NO;
         private boolean mUseParentsContacts = false;
+        private boolean mUpdateCrossProfileIntentFiltersOnOTA = false;
 
         public Builder setShowInLauncher(@ShowInLauncher int showInLauncher) {
             mShowInLauncher = showInLauncher;
@@ -546,6 +594,13 @@
             return this;
         }
 
+        /** Sets the value for {@link #mUpdateCrossProfileIntentFiltersOnOTA} */
+        public Builder setUpdateCrossProfileIntentFiltersOnOTA(boolean
+                updateCrossProfileIntentFiltersOnOTA) {
+            mUpdateCrossProfileIntentFiltersOnOTA = updateCrossProfileIntentFiltersOnOTA;
+            return this;
+        }
+
         /** Builds a UserProperties object with *all* values populated. */
         public UserProperties build() {
             return new UserProperties(
@@ -553,7 +608,8 @@
                     mStartWithParent,
                     mShowInSettings,
                     mInheritDevicePolicy,
-                    mUseParentsContacts);
+                    mUseParentsContacts,
+                    mUpdateCrossProfileIntentFiltersOnOTA);
         }
     } // end Builder
 
@@ -563,7 +619,7 @@
             boolean startWithParent,
             @ShowInSettings int showInSettings,
             @InheritDevicePolicy int inheritDevicePolicy,
-            boolean useParentsContacts) {
+            boolean useParentsContacts, boolean updateCrossProfileIntentFiltersOnOTA) {
 
         mDefaultProperties = null;
         setShowInLauncher(showInLauncher);
@@ -571,5 +627,6 @@
         setShowInSettings(showInSettings);
         setInheritDevicePolicy(inheritDevicePolicy);
         setUseParentsContacts(useParentsContacts);
+        setUpdateCrossProfileIntentFiltersOnOTA(updateCrossProfileIntentFiltersOnOTA);
     }
 }
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java
index fb1fcf8..d6934bc 100644
--- a/core/java/android/content/res/Resources.java
+++ b/core/java/android/content/res/Resources.java
@@ -43,6 +43,7 @@
 import android.annotation.XmlRes;
 import android.app.Application;
 import android.compat.annotation.UnsupportedAppUsage;
+import android.content.Context;
 import android.content.pm.ActivityInfo;
 import android.content.pm.ActivityInfo.Config;
 import android.content.res.loader.ResourcesLoader;
@@ -2181,17 +2182,19 @@
     }
 
     /**
-     * Return the current display metrics that are in effect for this resource
+     * Returns the current display metrics that are in effect for this resource
      * object. The returned object should be treated as read-only.
      *
      * <p>Note that the reported value may be different than the window this application is
      * interested in.</p>
      *
-     * <p>Best practices are to obtain metrics from {@link WindowManager#getCurrentWindowMetrics()}
-     * for window bounds, {@link Display#getRealMetrics(DisplayMetrics)} for display bounds and
-     * obtain density from {@link Configuration#densityDpi}. The value obtained from this API may be
-     * wrong if the {@link Resources} is from the context which is different than the window is
-     * attached such as {@link Application#getResources()}.
+     * <p>The best practices is to obtain metrics from
+     * {@link WindowManager#getCurrentWindowMetrics()} for window bounds. The value obtained from
+     * this API may be wrong if {@link Context#getResources()} is from
+     * non-{@link android.annotation.UiContext}.
+     * For example, use the {@link DisplayMetrics} obtained from {@link Application#getResources()}
+     * to build {@link android.app.Activity} UI elements especially when the
+     * {@link android.app.Activity} is in the multi-window mode or on the secondary {@link Display}.
      * <p/>
      *
      * @return The resource's current display metrics.
diff --git a/core/java/android/credentials/ClearCredentialStateException.java b/core/java/android/credentials/ClearCredentialStateException.java
new file mode 100644
index 0000000..a6b76a7
--- /dev/null
+++ b/core/java/android/credentials/ClearCredentialStateException.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 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 android.credentials;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.os.CancellationSignal;
+import android.os.OutcomeReceiver;
+
+import com.android.internal.util.Preconditions;
+
+import java.util.concurrent.Executor;
+
+/**
+ * Represents an error encountered during the
+ * {@link CredentialManager#clearCredentialState(ClearCredentialStateRequest,
+ * CancellationSignal, Executor, OutcomeReceiver)} operation.
+ */
+public class ClearCredentialStateException extends Exception {
+
+    @NonNull
+    public final String errorType;
+
+    /**
+     * Constructs a {@link ClearCredentialStateException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public ClearCredentialStateException(@NonNull String errorType, @Nullable String message) {
+        this(errorType, message, null);
+    }
+
+    /**
+     * Constructs a {@link ClearCredentialStateException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public ClearCredentialStateException(
+            @NonNull String errorType, @Nullable String message, @Nullable Throwable cause) {
+        super(message, cause);
+        this.errorType = Preconditions.checkStringNotEmpty(errorType,
+                "errorType must not be empty");
+    }
+
+    /**
+     * Constructs a {@link ClearCredentialStateException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public ClearCredentialStateException(@NonNull String errorType, @Nullable Throwable cause) {
+        this(errorType, null, cause);
+    }
+
+    /**
+     * Constructs a {@link ClearCredentialStateException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public ClearCredentialStateException(@NonNull String errorType) {
+        this(errorType, null, null);
+    }
+}
diff --git a/core/java/android/credentials/CreateCredentialException.java b/core/java/android/credentials/CreateCredentialException.java
new file mode 100644
index 0000000..87af208
--- /dev/null
+++ b/core/java/android/credentials/CreateCredentialException.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 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 android.credentials;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.app.Activity;
+import android.os.CancellationSignal;
+import android.os.OutcomeReceiver;
+
+import com.android.internal.util.Preconditions;
+
+import java.util.concurrent.Executor;
+
+/**
+ * Represents an error encountered during the
+ * {@link CredentialManager#executeCreateCredential(CreateCredentialRequest,
+ * Activity, CancellationSignal, Executor, OutcomeReceiver)} operation.
+ */
+public class CreateCredentialException extends Exception {
+
+    @NonNull
+    public final String errorType;
+
+    /**
+     * Constructs a {@link CreateCredentialException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public CreateCredentialException(@NonNull String errorType, @Nullable String message) {
+        this(errorType, message, null);
+    }
+
+    /**
+     * Constructs a {@link CreateCredentialException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public CreateCredentialException(
+            @NonNull String errorType, @Nullable String message, @Nullable Throwable cause) {
+        super(message, cause);
+        this.errorType = Preconditions.checkStringNotEmpty(errorType,
+                "errorType must not be empty");
+    }
+
+    /**
+     * Constructs a {@link CreateCredentialException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public CreateCredentialException(@NonNull String errorType, @Nullable Throwable cause) {
+        this(errorType, null, cause);
+    }
+
+    /**
+     * Constructs a {@link CreateCredentialException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public CreateCredentialException(@NonNull String errorType) {
+        this(errorType, null, null);
+    }
+}
diff --git a/core/java/android/credentials/CreateCredentialRequest.java b/core/java/android/credentials/CreateCredentialRequest.java
index 4589039..be887a5 100644
--- a/core/java/android/credentials/CreateCredentialRequest.java
+++ b/core/java/android/credentials/CreateCredentialRequest.java
@@ -52,7 +52,7 @@
     private final Bundle mCandidateQueryData;
 
     /**
-     * Determines whether or not the request must only be fulfilled by a system provider.
+     * Determines whether the request must only be fulfilled by a system provider.
      */
     private final boolean mRequireSystemProvider;
 
diff --git a/core/java/android/credentials/CredentialManager.java b/core/java/android/credentials/CredentialManager.java
index 1efac6c..49e8495 100644
--- a/core/java/android/credentials/CredentialManager.java
+++ b/core/java/android/credentials/CredentialManager.java
@@ -21,6 +21,7 @@
 import android.annotation.CallbackExecutor;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
+import android.annotation.RequiresPermission;
 import android.annotation.SystemService;
 import android.app.Activity;
 import android.app.PendingIntent;
@@ -32,6 +33,7 @@
 import android.os.RemoteException;
 import android.util.Log;
 
+import java.util.List;
 import java.util.concurrent.Executor;
 
 /**
@@ -40,9 +42,9 @@
  * <p>Note that an application should call the Jetpack CredentialManager apis instead of directly
  * calling these framework apis.
  *
- * <p>The CredentialManager apis launch framework UI flows for a user to
- * register a new credential or to consent to a saved credential from supported credential
- * providers, which can then be used to authenticate to the app.
+ * <p>The CredentialManager apis launch framework UI flows for a user to register a new credential
+ * or to consent to a saved credential from supported credential providers, which can then be used
+ * to authenticate to the app.
  */
 @SystemService(Context.CREDENTIAL_SERVICE)
 public final class CredentialManager {
@@ -76,8 +78,7 @@
             @NonNull Activity activity,
             @Nullable CancellationSignal cancellationSignal,
             @CallbackExecutor @NonNull Executor executor,
-            @NonNull OutcomeReceiver<
-                    GetCredentialResponse, CredentialManagerException> callback) {
+            @NonNull OutcomeReceiver<GetCredentialResponse, GetCredentialException> callback) {
         requireNonNull(request, "request must not be null");
         requireNonNull(activity, "activity must not be null");
         requireNonNull(executor, "executor must not be null");
@@ -90,10 +91,11 @@
 
         ICancellationSignal cancelRemote = null;
         try {
-            cancelRemote = mService.executeGetCredential(
-                    request,
-                    new GetCredentialTransport(activity, executor, callback),
-                    mContext.getOpPackageName());
+            cancelRemote =
+                    mService.executeGetCredential(
+                            request,
+                            new GetCredentialTransport(activity, executor, callback),
+                            mContext.getOpPackageName());
         } catch (RemoteException e) {
             e.rethrowFromSystemServer();
         }
@@ -106,8 +108,8 @@
     /**
      * Launches the necessary flows to register an app credential for the user.
      *
-     * <p>The execution can potentially launch UI flows to collect user consent to creating
-     * or storing the new credential, etc.
+     * <p>The execution can potentially launch UI flows to collect user consent to creating or
+     * storing the new credential, etc.
      *
      * @param request the request specifying type(s) of credentials to get from the user
      * @param activity the activity used to launch any UI needed
@@ -120,8 +122,8 @@
             @NonNull Activity activity,
             @Nullable CancellationSignal cancellationSignal,
             @CallbackExecutor @NonNull Executor executor,
-            @NonNull OutcomeReceiver<
-                    CreateCredentialResponse, CredentialManagerException> callback) {
+            @NonNull
+                    OutcomeReceiver<CreateCredentialResponse, CreateCredentialException> callback) {
         requireNonNull(request, "request must not be null");
         requireNonNull(activity, "activity must not be null");
         requireNonNull(executor, "executor must not be null");
@@ -134,9 +136,11 @@
 
         ICancellationSignal cancelRemote = null;
         try {
-            cancelRemote = mService.executeCreateCredential(request,
-                    new CreateCredentialTransport(activity, executor, callback),
-                    mContext.getOpPackageName());
+            cancelRemote =
+                    mService.executeCreateCredential(
+                            request,
+                            new CreateCredentialTransport(activity, executor, callback),
+                            mContext.getOpPackageName());
         } catch (RemoteException e) {
             e.rethrowFromSystemServer();
         }
@@ -149,10 +153,10 @@
     /**
      * Clears the current user credential state from all credential providers.
      *
-     * You should invoked this api after your user signs out of your app to notify all credential
+     * <p>You should invoked this api after your user signs out of your app to notify all credential
      * providers that any stored credential session for the given app should be cleared.
      *
-     * A credential provider may have stored an active credential session and use it to limit
+     * <p>A credential provider may have stored an active credential session and use it to limit
      * sign-in options for future get-credential calls. For example, it may prioritize the active
      * credential over any other available credential. When your user explicitly signs out of your
      * app and in order to get the holistic sign-in options the next time, you should call this API
@@ -167,7 +171,7 @@
             @NonNull ClearCredentialStateRequest request,
             @Nullable CancellationSignal cancellationSignal,
             @CallbackExecutor @NonNull Executor executor,
-            @NonNull OutcomeReceiver<Void, CredentialManagerException> callback) {
+            @NonNull OutcomeReceiver<Void, ClearCredentialStateException> callback) {
         requireNonNull(executor, "executor must not be null");
         requireNonNull(callback, "callback must not be null");
 
@@ -178,9 +182,11 @@
 
         ICancellationSignal cancelRemote = null;
         try {
-            cancelRemote = mService.clearCredentialState(request,
-                    new ClearCredentialStateTransport(executor, callback),
-                    mContext.getOpPackageName());
+            cancelRemote =
+                    mService.clearCredentialState(
+                            request,
+                            new ClearCredentialStateTransport(executor, callback),
+                            mContext.getOpPackageName());
         } catch (RemoteException e) {
             e.rethrowFromSystemServer();
         }
@@ -190,16 +196,87 @@
         }
     }
 
+    /**
+     * Gets a list of all user configurable credential providers registered on the system. This API
+     * is intended for browsers and settings apps.
+     *
+     * @param cancellationSignal an optional signal that allows for cancelling this call
+     * @param executor the callback will take place on this {@link Executor}
+     * @param callback the callback invoked when the request succeeds or fails
+     * @hide
+     */
+    @RequiresPermission(
+            allOf = {
+                android.Manifest.permission.LIST_ENABLED_CREDENTIAL_PROVIDERS,
+                android.Manifest.permission.QUERY_ALL_PACKAGES
+            })
+    public void listEnabledProviders(
+            @Nullable CancellationSignal cancellationSignal,
+            @CallbackExecutor @NonNull Executor executor,
+            @NonNull
+                    OutcomeReceiver<ListEnabledProvidersResponse, ListEnabledProvidersException>
+                            callback) {
+        requireNonNull(executor, "executor must not be null");
+        requireNonNull(callback, "callback must not be null");
+
+        if (cancellationSignal != null && cancellationSignal.isCanceled()) {
+            Log.w(TAG, "listEnabledProviders already canceled");
+            return;
+        }
+
+        ICancellationSignal cancelRemote = null;
+        try {
+            cancelRemote =
+                    mService.listEnabledProviders(
+                            new ListEnabledProvidersTransport(executor, callback));
+        } catch (RemoteException e) {
+            e.rethrowFromSystemServer();
+        }
+
+        if (cancellationSignal != null && cancelRemote != null) {
+            cancellationSignal.setRemote(cancelRemote);
+        }
+    }
+
+    /**
+     * Sets a list of all user configurable credential providers registered on the system. This API
+     * is intended for settings apps.
+     *
+     * @param providers the list of enabled providers
+     * @param userId the user ID to configure credential manager for
+     * @param executor the callback will take place on this {@link Executor}
+     * @param callback the callback invoked when the request succeeds or fails
+     * @hide
+     */
+    @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)
+    public void setEnabledProviders(
+            @NonNull List<String> providers,
+            int userId,
+            @CallbackExecutor @NonNull Executor executor,
+            @NonNull OutcomeReceiver<Void, SetEnabledProvidersException> callback) {
+        requireNonNull(executor, "executor must not be null");
+        requireNonNull(callback, "callback must not be null");
+        requireNonNull(providers, "providers must not be null");
+
+        try {
+            mService.setEnabledProviders(
+                    providers, userId, new SetEnabledProvidersTransport(executor, callback));
+        } catch (RemoteException e) {
+            e.rethrowFromSystemServer();
+        }
+    }
+
     private static class GetCredentialTransport extends IGetCredentialCallback.Stub {
         // TODO: listen for cancellation to release callback.
 
         private final Activity mActivity;
         private final Executor mExecutor;
-        private final OutcomeReceiver<
-                GetCredentialResponse, CredentialManagerException> mCallback;
+        private final OutcomeReceiver<GetCredentialResponse, GetCredentialException> mCallback;
 
-        private GetCredentialTransport(Activity activity, Executor executor,
-                OutcomeReceiver<GetCredentialResponse, CredentialManagerException> callback) {
+        private GetCredentialTransport(
+                Activity activity,
+                Executor executor,
+                OutcomeReceiver<GetCredentialResponse, GetCredentialException> callback) {
             mActivity = activity;
             mExecutor = executor;
             mCallback = callback;
@@ -210,8 +287,10 @@
             try {
                 mActivity.startIntentSender(pendingIntent.getIntentSender(), null, 0, 0, 0);
             } catch (IntentSender.SendIntentException e) {
-                Log.e(TAG, "startIntentSender() failed for intent:"
-                        + pendingIntent.getIntentSender(), e);
+                Log.e(
+                        TAG,
+                        "startIntentSender() failed for intent:" + pendingIntent.getIntentSender(),
+                        e);
                 // TODO: propagate the error.
             }
         }
@@ -222,9 +301,9 @@
         }
 
         @Override
-        public void onError(int errorCode, String message) {
+        public void onError(String errorType, String message) {
             mExecutor.execute(
-                    () -> mCallback.onError(new CredentialManagerException(errorCode, message)));
+                    () -> mCallback.onError(new GetCredentialException(errorType, message)));
         }
     }
 
@@ -233,11 +312,13 @@
 
         private final Activity mActivity;
         private final Executor mExecutor;
-        private final OutcomeReceiver<
-                CreateCredentialResponse, CredentialManagerException> mCallback;
+        private final OutcomeReceiver<CreateCredentialResponse, CreateCredentialException>
+                mCallback;
 
-        private CreateCredentialTransport(Activity activity, Executor executor,
-                OutcomeReceiver<CreateCredentialResponse, CredentialManagerException> callback) {
+        private CreateCredentialTransport(
+                Activity activity,
+                Executor executor,
+                OutcomeReceiver<CreateCredentialResponse, CreateCredentialException> callback) {
             mActivity = activity;
             mExecutor = executor;
             mCallback = callback;
@@ -248,8 +329,10 @@
             try {
                 mActivity.startIntentSender(pendingIntent.getIntentSender(), null, 0, 0, 0);
             } catch (IntentSender.SendIntentException e) {
-                Log.e(TAG, "startIntentSender() failed for intent:"
-                        + pendingIntent.getIntentSender(), e);
+                Log.e(
+                        TAG,
+                        "startIntentSender() failed for intent:" + pendingIntent.getIntentSender(),
+                        e);
                 // TODO: propagate the error.
             }
         }
@@ -260,21 +343,20 @@
         }
 
         @Override
-        public void onError(int errorCode, String message) {
+        public void onError(String errorType, String message) {
             mExecutor.execute(
-                    () -> mCallback.onError(new CredentialManagerException(errorCode, message)));
+                    () -> mCallback.onError(new CreateCredentialException(errorType, message)));
         }
     }
 
-    private static class ClearCredentialStateTransport
-            extends IClearCredentialStateCallback.Stub {
+    private static class ClearCredentialStateTransport extends IClearCredentialStateCallback.Stub {
         // TODO: listen for cancellation to release callback.
 
         private final Executor mExecutor;
-        private final OutcomeReceiver<Void, CredentialManagerException> mCallback;
+        private final OutcomeReceiver<Void, ClearCredentialStateException> mCallback;
 
-        private ClearCredentialStateTransport(Executor executor,
-                OutcomeReceiver<Void, CredentialManagerException> callback) {
+        private ClearCredentialStateTransport(
+                Executor executor, OutcomeReceiver<Void, ClearCredentialStateException> callback) {
             mExecutor = executor;
             mCallback = callback;
         }
@@ -285,9 +367,64 @@
         }
 
         @Override
-        public void onError(int errorCode, String message) {
+        public void onError(String errorType, String message) {
             mExecutor.execute(
-                    () -> mCallback.onError(new CredentialManagerException(errorCode, message)));
+                    () -> mCallback.onError(new ClearCredentialStateException(errorType, message)));
+        }
+    }
+
+    private static class ListEnabledProvidersTransport extends IListEnabledProvidersCallback.Stub {
+        // TODO: listen for cancellation to release callback.
+
+        private final Executor mExecutor;
+        private final OutcomeReceiver<ListEnabledProvidersResponse, ListEnabledProvidersException>
+                mCallback;
+
+        private ListEnabledProvidersTransport(
+                Executor executor,
+                OutcomeReceiver<ListEnabledProvidersResponse, ListEnabledProvidersException>
+                        callback) {
+            mExecutor = executor;
+            mCallback = callback;
+        }
+
+        @Override
+        public void onResponse(ListEnabledProvidersResponse response) {
+            mExecutor.execute(() -> mCallback.onResult(response));
+        }
+
+        @Override
+        public void onError(String errorType, String message) {
+            mExecutor.execute(
+                    () -> mCallback.onError(new ListEnabledProvidersException(errorType, message)));
+          }
+    }
+
+    private static class SetEnabledProvidersTransport extends ISetEnabledProvidersCallback.Stub {
+        // TODO: listen for cancellation to release callback.
+
+        private final Executor mExecutor;
+        private final OutcomeReceiver<Void, SetEnabledProvidersException> mCallback;
+
+        private SetEnabledProvidersTransport(
+                Executor executor, OutcomeReceiver<Void, SetEnabledProvidersException> callback) {
+            mExecutor = executor;
+            mCallback = callback;
+        }
+
+        public void onResponse(Void result) {
+            mExecutor.execute(() -> mCallback.onResult(result));
+        }
+
+        @Override
+        public void onResponse() {
+            mExecutor.execute(() -> mCallback.onResult(null));
+        }
+
+        @Override
+        public void onError(String errorType, String message) {
+            mExecutor.execute(
+                    () -> mCallback.onError(new SetEnabledProvidersException(errorType, message)));
         }
     }
 }
diff --git a/core/java/android/credentials/CredentialManagerException.java b/core/java/android/credentials/CredentialManagerException.java
deleted file mode 100644
index 8369649..0000000
--- a/core/java/android/credentials/CredentialManagerException.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 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 android.credentials;
-
-import android.annotation.Nullable;
-
-/** Exception class for CredentialManager operations. */
-public class CredentialManagerException extends Exception {
-    /** Indicates that an unknown error was encountered. */
-    public static final int ERROR_UNKNOWN = 0;
-
-    /**
-     * The given CredentialManager operation is cancelled by the user.
-     *
-     * @hide
-     */
-    public static final int ERROR_USER_CANCELLED = 1;
-
-    /**
-     * No appropriate provider is found to support the target credential type(s).
-     *
-     * @hide
-     */
-    public static final int ERROR_PROVIDER_NOT_FOUND = 2;
-
-    public final int errorCode;
-
-    public CredentialManagerException(int errorCode, @Nullable String message) {
-        super(message);
-        this.errorCode = errorCode;
-    }
-
-    public CredentialManagerException(
-            int errorCode, @Nullable String message, @Nullable Throwable cause) {
-        super(message, cause);
-        this.errorCode = errorCode;
-    }
-
-    public CredentialManagerException(int errorCode, @Nullable Throwable cause) {
-        super(cause);
-        this.errorCode = errorCode;
-    }
-
-    public CredentialManagerException(int errorCode) {
-        super();
-        this.errorCode = errorCode;
-    }
-}
diff --git a/core/java/android/credentials/GetCredentialException.java b/core/java/android/credentials/GetCredentialException.java
new file mode 100644
index 0000000..4d80237
--- /dev/null
+++ b/core/java/android/credentials/GetCredentialException.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 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 android.credentials;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.app.Activity;
+import android.os.CancellationSignal;
+import android.os.OutcomeReceiver;
+
+import com.android.internal.util.Preconditions;
+
+import java.util.concurrent.Executor;
+
+/**
+ * Represents an error encountered during the
+ * {@link CredentialManager#executeGetCredential(GetCredentialRequest,
+ * Activity, CancellationSignal, Executor, OutcomeReceiver)} operation.
+ */
+public class GetCredentialException extends Exception {
+
+    @NonNull
+    public final String errorType;
+
+    /**
+     * Constructs a {@link GetCredentialException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public GetCredentialException(@NonNull String errorType, @Nullable String message) {
+        this(errorType, message, null);
+    }
+
+    /**
+     * Constructs a {@link GetCredentialException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public GetCredentialException(
+            @NonNull String errorType, @Nullable String message, @Nullable Throwable cause) {
+        super(message, cause);
+        this.errorType = Preconditions.checkStringNotEmpty(errorType,
+                "errorType must not be empty");
+    }
+
+    /**
+     * Constructs a {@link GetCredentialException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public GetCredentialException(@NonNull String errorType, @Nullable Throwable cause) {
+        this(errorType, null, cause);
+    }
+
+    /**
+     * Constructs a {@link GetCredentialException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public GetCredentialException(@NonNull String errorType) {
+        this(errorType, null, null);
+    }
+}
diff --git a/core/java/android/credentials/GetCredentialOption.java b/core/java/android/credentials/GetCredentialOption.java
index ed93dae..47731dd 100644
--- a/core/java/android/credentials/GetCredentialOption.java
+++ b/core/java/android/credentials/GetCredentialOption.java
@@ -38,13 +38,20 @@
     private final String mType;
 
     /**
-     * The request data.
+     * The full request data.
      */
     @NonNull
-    private final Bundle mData;
+    private final Bundle mCredentialRetrievalData;
 
     /**
-     * Determines whether or not the request must only be fulfilled by a system provider.
+     * The partial request data that will be sent to the provider during the initial credential
+     * candidate query stage.
+     */
+    @NonNull
+    private final Bundle mCandidateQueryData;
+
+    /**
+     * Determines whether the request must only be fulfilled by a system provider.
      */
     private final boolean mRequireSystemProvider;
 
@@ -57,11 +64,27 @@
     }
 
     /**
-     * Returns the request data.
+     * Returns the full request data.
      */
     @NonNull
-    public Bundle getData() {
-        return mData;
+    public Bundle getCredentialRetrievalData() {
+        return mCredentialRetrievalData;
+    }
+
+    /**
+     * Returns the partial request data that will be sent to the provider during the initial
+     * credential candidate query stage.
+     *
+     * For security reason, a provider will receive the request data in two stages. First it gets
+     * this partial request that do not contain sensitive user information; it uses this
+     * information to provide credential candidates that the [@code CredentialManager] will show to
+     * the user. Next, the full request data, {@link #getCredentialRetrievalData()}, will be sent to
+     * a provider only if the user further grants the consent by choosing a candidate from the
+     * provider.
+     */
+    @NonNull
+    public Bundle getCandidateQueryData() {
+        return mCandidateQueryData;
     }
 
     /**
@@ -75,7 +98,8 @@
     @Override
     public void writeToParcel(@NonNull Parcel dest, int flags) {
         dest.writeString8(mType);
-        dest.writeBundle(mData);
+        dest.writeBundle(mCredentialRetrievalData);
+        dest.writeBundle(mCandidateQueryData);
         dest.writeBoolean(mRequireSystemProvider);
     }
 
@@ -88,7 +112,8 @@
     public String toString() {
         return "GetCredentialOption {"
                 + "type=" + mType
-                + ", data=" + mData
+                + ", requestData=" + mCredentialRetrievalData
+                + ", candidateQueryData=" + mCandidateQueryData
                 + ", requireSystemProvider=" + mRequireSystemProvider
                 + "}";
     }
@@ -96,44 +121,52 @@
     /**
      * Constructs a {@link GetCredentialOption}.
      *
-     * @param type the requested credential type
-     * @param data the request data
-     * @param requireSystemProvider whether or not the request must only be fulfilled by a system
-     *                              provider
-     *
+     * @param type                    the requested credential type
+     * @param credentialRetrievalData the request data
+     * @param candidateQueryData      the partial request data that will be sent to the provider
+     *                                during the initial credential candidate query stage
+     * @param requireSystemProvider   whether the request must only be fulfilled by a system
+     *                                provider
      * @throws IllegalArgumentException If type is empty.
      */
     public GetCredentialOption(
             @NonNull String type,
-            @NonNull Bundle data,
+            @NonNull Bundle credentialRetrievalData,
+            @NonNull Bundle candidateQueryData,
             boolean requireSystemProvider) {
         mType = Preconditions.checkStringNotEmpty(type, "type must not be empty");
-        mData = requireNonNull(data, "data must not be null");
+        mCredentialRetrievalData = requireNonNull(credentialRetrievalData,
+                "requestData must not be null");
+        mCandidateQueryData = requireNonNull(candidateQueryData,
+                "candidateQueryData must not be null");
         mRequireSystemProvider = requireSystemProvider;
     }
 
     private GetCredentialOption(@NonNull Parcel in) {
         String type = in.readString8();
         Bundle data = in.readBundle();
+        Bundle candidateQueryData = in.readBundle();
         boolean requireSystemProvider = in.readBoolean();
 
         mType = type;
         AnnotationValidations.validate(NonNull.class, null, mType);
-        mData = data;
-        AnnotationValidations.validate(NonNull.class, null, mData);
+        mCredentialRetrievalData = data;
+        AnnotationValidations.validate(NonNull.class, null, mCredentialRetrievalData);
+        mCandidateQueryData = candidateQueryData;
+        AnnotationValidations.validate(NonNull.class, null, mCandidateQueryData);
         mRequireSystemProvider = requireSystemProvider;
     }
 
     public static final @NonNull Parcelable.Creator<GetCredentialOption> CREATOR =
             new Parcelable.Creator<GetCredentialOption>() {
-        @Override
-        public GetCredentialOption[] newArray(int size) {
-            return new GetCredentialOption[size];
-        }
+                @Override
+                public GetCredentialOption[] newArray(int size) {
+                    return new GetCredentialOption[size];
+                }
 
-        @Override
-        public GetCredentialOption createFromParcel(@NonNull Parcel in) {
-            return new GetCredentialOption(in);
-        }
-    };
+                @Override
+                public GetCredentialOption createFromParcel(@NonNull Parcel in) {
+                    return new GetCredentialOption(in);
+                }
+            };
 }
diff --git a/core/java/android/credentials/IClearCredentialStateCallback.aidl b/core/java/android/credentials/IClearCredentialStateCallback.aidl
index f8b7ae44..e18e0871 100644
--- a/core/java/android/credentials/IClearCredentialStateCallback.aidl
+++ b/core/java/android/credentials/IClearCredentialStateCallback.aidl
@@ -23,5 +23,5 @@
  */
 interface IClearCredentialStateCallback {
     oneway void onSuccess();
-    oneway void onError(int errorCode, String message);
+    oneway void onError(String errorType, String message);
 }
\ No newline at end of file
diff --git a/core/java/android/credentials/ICreateCredentialCallback.aidl b/core/java/android/credentials/ICreateCredentialCallback.aidl
index 87fd36f..f6890a9 100644
--- a/core/java/android/credentials/ICreateCredentialCallback.aidl
+++ b/core/java/android/credentials/ICreateCredentialCallback.aidl
@@ -27,5 +27,5 @@
 interface ICreateCredentialCallback {
     oneway void onPendingIntent(in PendingIntent pendingIntent);
     oneway void onResponse(in CreateCredentialResponse response);
-    oneway void onError(int errorCode, String message);
+    oneway void onError(String errorType, String message);
 }
\ No newline at end of file
diff --git a/core/java/android/credentials/ICredentialManager.aidl b/core/java/android/credentials/ICredentialManager.aidl
index c5497bd..c3ca03d 100644
--- a/core/java/android/credentials/ICredentialManager.aidl
+++ b/core/java/android/credentials/ICredentialManager.aidl
@@ -16,12 +16,16 @@
 
 package android.credentials;
 
+import java.util.List;
+
 import android.credentials.ClearCredentialStateRequest;
 import android.credentials.CreateCredentialRequest;
 import android.credentials.GetCredentialRequest;
 import android.credentials.IClearCredentialStateCallback;
 import android.credentials.ICreateCredentialCallback;
 import android.credentials.IGetCredentialCallback;
+import android.credentials.IListEnabledProvidersCallback;
+import android.credentials.ISetEnabledProvidersCallback;
 import android.os.ICancellationSignal;
 
 /**
@@ -36,4 +40,8 @@
     @nullable ICancellationSignal executeCreateCredential(in CreateCredentialRequest request, in ICreateCredentialCallback callback, String callingPackage);
 
     @nullable ICancellationSignal clearCredentialState(in ClearCredentialStateRequest request, in IClearCredentialStateCallback callback, String callingPackage);
+
+    @nullable ICancellationSignal listEnabledProviders(in IListEnabledProvidersCallback callback);
+
+    void setEnabledProviders(in List<String> providers, in int userId, in ISetEnabledProvidersCallback callback);
 }
diff --git a/core/java/android/credentials/IGetCredentialCallback.aidl b/core/java/android/credentials/IGetCredentialCallback.aidl
index da152ba..6d1182a 100644
--- a/core/java/android/credentials/IGetCredentialCallback.aidl
+++ b/core/java/android/credentials/IGetCredentialCallback.aidl
@@ -27,5 +27,5 @@
 interface IGetCredentialCallback {
     oneway void onPendingIntent(in PendingIntent pendingIntent);
     oneway void onResponse(in GetCredentialResponse response);
-    oneway void onError(int errorCode, String message);
+    oneway void onError(String errorType, String message);
 }
\ No newline at end of file
diff --git a/core/java/android/credentials/IListEnabledProvidersCallback.aidl b/core/java/android/credentials/IListEnabledProvidersCallback.aidl
new file mode 100644
index 0000000..3a8e25ed
--- /dev/null
+++ b/core/java/android/credentials/IListEnabledProvidersCallback.aidl
@@ -0,0 +1,29 @@
+/*
+ * Copyright 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 android.credentials;
+
+import android.credentials.ListEnabledProvidersResponse;
+
+/**
+ * Listener for an listEnabledProviders request.
+ *
+ * @hide
+ */
+interface IListEnabledProvidersCallback {
+    oneway void onResponse(in ListEnabledProvidersResponse response);
+    oneway void onError(String errorType, String message);
+}
\ No newline at end of file
diff --git a/services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt b/core/java/android/credentials/ISetEnabledProvidersCallback.aidl
similarity index 65%
copy from services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt
copy to core/java/android/credentials/ISetEnabledProvidersCallback.aidl
index 528680e7..3044278 100644
--- a/services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt
+++ b/core/java/android/credentials/ISetEnabledProvidersCallback.aidl
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright 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.
@@ -14,11 +14,14 @@
  * limitations under the License.
  */
 
-package com.android.server.permission.access.external
+package android.credentials;
 
-class RoSystemProperties {
-    companion object {
-        const val CONTROL_PRIVAPP_PERMISSIONS_DISABLE = false
-        const val CONTROL_PRIVAPP_PERMISSIONS_ENFORCE = false
-    }
-}
+/**
+ * Listener for an setEnabledProviders request.
+ *
+ * @hide
+ */
+interface ISetEnabledProvidersCallback {
+    oneway void onResponse();
+    oneway void onError(String errorType, String message);
+}
\ No newline at end of file
diff --git a/core/java/android/credentials/ListEnabledProvidersException.java b/core/java/android/credentials/ListEnabledProvidersException.java
new file mode 100644
index 0000000..c12c656
--- /dev/null
+++ b/core/java/android/credentials/ListEnabledProvidersException.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 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 android.credentials;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.os.CancellationSignal;
+import android.os.OutcomeReceiver;
+
+import com.android.internal.util.Preconditions;
+
+/**
+ * Represents an error encountered during the {@link
+ * CredentialManager#listEnabledProviders(CancellationSignal Executor, OutcomeReceiver)} operation.
+ *
+ * @hide
+ */
+public class ListEnabledProvidersException extends Exception {
+
+    @NonNull public final String errorType;
+
+    /**
+     * Constructs a {@link ListEnabledProvidersException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public ListEnabledProvidersException(@NonNull String errorType, @Nullable String message) {
+        this(errorType, message, null);
+    }
+
+    /**
+     * Constructs a {@link ListEnabledProvidersException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public ListEnabledProvidersException(
+            @NonNull String errorType, @Nullable String message, @Nullable Throwable cause) {
+        super(message, cause);
+        this.errorType =
+                Preconditions.checkStringNotEmpty(errorType, "errorType must not be empty");
+    }
+
+    /**
+     * Constructs a {@link ListEnabledProvidersException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public ListEnabledProvidersException(@NonNull String errorType, @Nullable Throwable cause) {
+        this(errorType, null, cause);
+    }
+
+    /**
+     * Constructs a {@link ListEnabledProvidersException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public ListEnabledProvidersException(@NonNull String errorType) {
+        this(errorType, null, null);
+    }
+}
diff --git a/services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt b/core/java/android/credentials/ListEnabledProvidersResponse.aidl
similarity index 65%
copy from services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt
copy to core/java/android/credentials/ListEnabledProvidersResponse.aidl
index 528680e7..759bf48 100644
--- a/services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt
+++ b/core/java/android/credentials/ListEnabledProvidersResponse.aidl
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright 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.
@@ -14,11 +14,6 @@
  * limitations under the License.
  */
 
-package com.android.server.permission.access.external
+package android.credentials;
 
-class RoSystemProperties {
-    companion object {
-        const val CONTROL_PRIVAPP_PERMISSIONS_DISABLE = false
-        const val CONTROL_PRIVAPP_PERMISSIONS_ENFORCE = false
-    }
-}
+parcelable ListEnabledProvidersResponse;
\ No newline at end of file
diff --git a/core/java/android/credentials/ListEnabledProvidersResponse.java b/core/java/android/credentials/ListEnabledProvidersResponse.java
new file mode 100644
index 0000000..532adf7
--- /dev/null
+++ b/core/java/android/credentials/ListEnabledProvidersResponse.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 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 android.credentials;
+
+import android.annotation.NonNull;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import com.android.internal.util.Preconditions;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Response from Credential Manager listing the providers that are enabled and available to the
+ * user.
+ *
+ * @hide
+ */
+public final class ListEnabledProvidersResponse implements Parcelable {
+
+    /** List of providers. */
+    @NonNull private final List<String> mProviders;
+
+    /**
+     * Creates a {@link ListEnabledProvidersResponse} with a list of providers.
+     *
+     * @throws NullPointerException If args are null.
+     */
+    public static @NonNull ListEnabledProvidersResponse create(@NonNull List<String> providers) {
+        Objects.requireNonNull(providers, "providers must not be null");
+        Preconditions.checkCollectionElementsNotNull(providers, /* valueName= */ "providers");
+        return new ListEnabledProvidersResponse(providers);
+    }
+
+    private ListEnabledProvidersResponse(@NonNull List<String> providers) {
+        mProviders = providers;
+    }
+
+    private ListEnabledProvidersResponse(@NonNull Parcel in) {
+        mProviders = in.createStringArrayList();
+    }
+
+    public static final @NonNull Creator<ListEnabledProvidersResponse> CREATOR =
+            new Creator<ListEnabledProvidersResponse>() {
+                @Override
+                public ListEnabledProvidersResponse createFromParcel(Parcel in) {
+                    return new ListEnabledProvidersResponse(in);
+                }
+
+                @Override
+                public ListEnabledProvidersResponse[] newArray(int size) {
+                    return new ListEnabledProvidersResponse[size];
+                }
+            };
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public void writeToParcel(@NonNull Parcel dest, int flags) {
+        dest.writeStringList(mProviders);
+    }
+
+    /** Returns the list of flattened Credential Manager provider component names as strings. */
+    public @NonNull List<String> getProviderComponentNames() {
+        return mProviders;
+    }
+}
diff --git a/core/java/android/credentials/SetEnabledProvidersException.java b/core/java/android/credentials/SetEnabledProvidersException.java
new file mode 100644
index 0000000..6178f349
--- /dev/null
+++ b/core/java/android/credentials/SetEnabledProvidersException.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 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 android.credentials;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.os.CancellationSignal;
+import android.os.OutcomeReceiver;
+
+import com.android.internal.util.Preconditions;
+
+/**
+ * Represents an error encountered during the {@link
+ * CredentialManager#setEnabledProviders(CancellationSignal Executor, OutcomeReceiver)} operation.
+ *
+ * @hide
+ */
+public class SetEnabledProvidersException extends Exception {
+
+    @NonNull public final String errorType;
+
+    /**
+     * Constructs a {@link SetEnabledProvidersException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public SetEnabledProvidersException(@NonNull String errorType, @Nullable String message) {
+        this(errorType, message, null);
+    }
+
+    /**
+     * Constructs a {@link SetEnabledProvidersException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public SetEnabledProvidersException(
+            @NonNull String errorType, @Nullable String message, @Nullable Throwable cause) {
+        super(message, cause);
+        this.errorType =
+                Preconditions.checkStringNotEmpty(errorType, "errorType must not be empty");
+    }
+
+    /**
+     * Constructs a {@link SetEnabledProvidersException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public SetEnabledProvidersException(@NonNull String errorType, @Nullable Throwable cause) {
+        this(errorType, null, cause);
+    }
+
+    /**
+     * Constructs a {@link SetEnabledProvidersException}.
+     *
+     * @throws IllegalArgumentException If errorType is empty.
+     */
+    public SetEnabledProvidersException(@NonNull String errorType) {
+        this(errorType, null, null);
+    }
+}
diff --git a/services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt b/core/java/android/credentials/SetEnabledProvidersRequest.aidl
similarity index 65%
copy from services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt
copy to core/java/android/credentials/SetEnabledProvidersRequest.aidl
index 528680e7..271f58f 100644
--- a/services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt
+++ b/core/java/android/credentials/SetEnabledProvidersRequest.aidl
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright 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.
@@ -14,11 +14,6 @@
  * limitations under the License.
  */
 
-package com.android.server.permission.access.external
+package android.credentials;
 
-class RoSystemProperties {
-    companion object {
-        const val CONTROL_PRIVAPP_PERMISSIONS_DISABLE = false
-        const val CONTROL_PRIVAPP_PERMISSIONS_ENFORCE = false
-    }
-}
+parcelable SetEnabledProvidersRequest;
\ No newline at end of file
diff --git a/core/java/android/credentials/SetEnabledProvidersRequest.java b/core/java/android/credentials/SetEnabledProvidersRequest.java
new file mode 100644
index 0000000..d1136ba0
--- /dev/null
+++ b/core/java/android/credentials/SetEnabledProvidersRequest.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 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 android.credentials;
+
+import android.annotation.NonNull;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import com.android.internal.util.Preconditions;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Sets the enabled list of credential manager providers.
+ *
+ * @hide
+ */
+public final class SetEnabledProvidersRequest implements Parcelable {
+
+    /** List of providers. */
+    @NonNull private final List<String> mProviders;
+
+    /**
+     * Creates a {@link SetEnabledProvidersRequest} with a list of providers. The list is made up of
+     * strings that are flattened component names of the service that is the credman provider.
+     *
+     * @throws NullPointerException If args are null.
+     */
+    public SetEnabledProvidersRequest(@NonNull List<String> providers) {
+        Objects.requireNonNull(providers, "providers must not be null");
+        Preconditions.checkCollectionElementsNotNull(providers, /* valueName= */ "providers");
+        mProviders = providers;
+    }
+
+    private SetEnabledProvidersRequest(@NonNull Parcel in) {
+        mProviders = in.createStringArrayList();
+    }
+
+    public static final @NonNull Creator<SetEnabledProvidersRequest> CREATOR =
+            new Creator<SetEnabledProvidersRequest>() {
+                @Override
+                public SetEnabledProvidersRequest createFromParcel(Parcel in) {
+                    return new SetEnabledProvidersRequest(in);
+                }
+
+                @Override
+                public SetEnabledProvidersRequest[] newArray(int size) {
+                    return new SetEnabledProvidersRequest[size];
+                }
+            };
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public void writeToParcel(@NonNull Parcel dest, int flags) {
+        dest.writeStringList(mProviders);
+    }
+
+    /** Returns the list of flattened Credential Manager provider component names as strings. */
+    public @NonNull List<String> getProviderComponentNames() {
+        return mProviders;
+    }
+}
diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java
index 3bdd39f..5291d2b 100644
--- a/core/java/android/hardware/Camera.java
+++ b/core/java/android/hardware/Camera.java
@@ -29,12 +29,14 @@
 import android.annotation.SdkConstant.SdkConstantType;
 import android.app.ActivityThread;
 import android.app.AppOpsManager;
+import android.app.compat.CompatChanges;
 import android.compat.annotation.UnsupportedAppUsage;
 import android.content.Context;
 import android.graphics.ImageFormat;
 import android.graphics.Point;
 import android.graphics.Rect;
 import android.graphics.SurfaceTexture;
+import android.hardware.camera2.CameraManager;
 import android.media.AudioAttributes;
 import android.media.IAudioService;
 import android.os.Build;
@@ -45,6 +47,7 @@
 import android.os.Process;
 import android.os.RemoteException;
 import android.os.ServiceManager;
+import android.os.SystemProperties;
 import android.renderscript.Allocation;
 import android.renderscript.Element;
 import android.renderscript.RSIllegalArgumentException;
@@ -281,6 +284,14 @@
      */
     public native static int getNumberOfCameras();
 
+    private static final boolean sLandscapeToPortrait =
+            SystemProperties.getBoolean(CameraManager.LANDSCAPE_TO_PORTRAIT_PROP, false);
+
+    private static boolean shouldOverrideToPortrait() {
+        return CompatChanges.isChangeEnabled(CameraManager.OVERRIDE_FRONT_CAMERA_APP_COMPAT)
+                && sLandscapeToPortrait;
+    }
+
     /**
      * Returns the information about a particular camera.
      * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1.
@@ -290,7 +301,9 @@
      *    low-level failure).
      */
     public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) {
-        _getCameraInfo(cameraId, cameraInfo);
+        boolean overrideToPortrait = shouldOverrideToPortrait();
+
+        _getCameraInfo(cameraId, overrideToPortrait, cameraInfo);
         IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
         IAudioService audioService = IAudioService.Stub.asInterface(b);
         try {
@@ -303,7 +316,8 @@
             Log.e(TAG, "Audio service is unavailable for queries");
         }
     }
-    private native static void _getCameraInfo(int cameraId, CameraInfo cameraInfo);
+    private native static void _getCameraInfo(int cameraId, boolean overrideToPortrait,
+            CameraInfo cameraInfo);
 
     /**
      * Information about a camera
@@ -484,8 +498,9 @@
             mEventHandler = null;
         }
 
+        boolean overrideToPortrait = shouldOverrideToPortrait();
         return native_setup(new WeakReference<Camera>(this), cameraId,
-                ActivityThread.currentOpPackageName());
+                ActivityThread.currentOpPackageName(), overrideToPortrait);
     }
 
     /** used by Camera#open, Camera#open(int) */
@@ -555,7 +570,8 @@
     }
 
     @UnsupportedAppUsage
-    private native int native_setup(Object cameraThis, int cameraId, String packageName);
+    private native int native_setup(Object cameraThis, int cameraId, String packageName,
+            boolean overrideToPortrait);
 
     private native final void native_release();
 
diff --git a/core/java/android/hardware/SystemSensorManager.java b/core/java/android/hardware/SystemSensorManager.java
index 18118f5..9388ae3 100644
--- a/core/java/android/hardware/SystemSensorManager.java
+++ b/core/java/android/hardware/SystemSensorManager.java
@@ -17,7 +17,7 @@
 package android.hardware;
 
 import static android.companion.virtual.VirtualDeviceManager.ACTION_VIRTUAL_DEVICE_REMOVED;
-import static android.companion.virtual.VirtualDeviceManager.DEFAULT_DEVICE_ID;
+import static android.companion.virtual.VirtualDeviceManager.DEVICE_ID_DEFAULT;
 import static android.companion.virtual.VirtualDeviceManager.EXTRA_VIRTUAL_DEVICE_ID;
 import static android.companion.virtual.VirtualDeviceParams.DEVICE_POLICY_DEFAULT;
 import static android.companion.virtual.VirtualDeviceParams.POLICY_TYPE_SENSORS;
@@ -135,7 +135,7 @@
     private final boolean mIsPackageDebuggable;
     private final Context mContext;
     private final long mNativeInstance;
-    private final VirtualDeviceManager mVdm;
+    private VirtualDeviceManager mVdm;
 
     private Optional<Boolean> mHasHighSamplingRateSensorsPermission = Optional.empty();
 
@@ -154,7 +154,6 @@
         mContext = context;
         mNativeInstance = nativeCreate(context.getOpPackageName());
         mIsPackageDebuggable = (0 != (appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE));
-        mVdm = mContext.getSystemService(VirtualDeviceManager.class);
 
         // initialize the sensor list
         for (int index = 0;; ++index) {
@@ -170,8 +169,7 @@
     @Override
     public List<Sensor> getSensorList(int type) {
         final int deviceId = mContext.getDeviceId();
-        if (deviceId == DEFAULT_DEVICE_ID || mVdm == null
-                || mVdm.getDevicePolicy(deviceId, POLICY_TYPE_SENSORS) == DEVICE_POLICY_DEFAULT) {
+        if (isDeviceSensorPolicyDefault(deviceId)) {
             return super.getSensorList(type);
         }
 
@@ -207,8 +205,7 @@
     @Override
     protected List<Sensor> getFullSensorList() {
         final int deviceId = mContext.getDeviceId();
-        if (deviceId == DEFAULT_DEVICE_ID || mVdm == null
-                || mVdm.getDevicePolicy(deviceId, POLICY_TYPE_SENSORS) == DEVICE_POLICY_DEFAULT) {
+        if (isDeviceSensorPolicyDefault(deviceId)) {
             return mFullSensorsList;
         }
 
@@ -533,7 +530,7 @@
                     if (intent.getAction().equals(ACTION_VIRTUAL_DEVICE_REMOVED)) {
                         synchronized (mFullRuntimeSensorListByDevice) {
                             final int deviceId = intent.getIntExtra(
-                                    EXTRA_VIRTUAL_DEVICE_ID, DEFAULT_DEVICE_ID);
+                                    EXTRA_VIRTUAL_DEVICE_ID, DEVICE_ID_DEFAULT);
                             List<Sensor> removedSensors =
                                     mFullRuntimeSensorListByDevice.removeReturnOld(deviceId);
                             if (removedSensors != null) {
@@ -1136,6 +1133,17 @@
                 parameter.type, parameter.floatValues, parameter.intValues) == 0;
     }
 
+    private boolean isDeviceSensorPolicyDefault(int deviceId) {
+        if (deviceId == DEVICE_ID_DEFAULT) {
+            return true;
+        }
+        if (mVdm == null) {
+            mVdm = mContext.getSystemService(VirtualDeviceManager.class);
+        }
+        return mVdm == null
+                || mVdm.getDevicePolicy(deviceId, POLICY_TYPE_SENSORS) == DEVICE_POLICY_DEFAULT;
+    }
+
     /**
      * Checks if a sensor should be capped according to HIGH_SAMPLING_RATE_SENSORS
      * permission.
diff --git a/core/java/android/hardware/camera2/CameraCharacteristics.java b/core/java/android/hardware/camera2/CameraCharacteristics.java
index 1ee2423..6e72b5f 100644
--- a/core/java/android/hardware/camera2/CameraCharacteristics.java
+++ b/core/java/android/hardware/camera2/CameraCharacteristics.java
@@ -4613,7 +4613,6 @@
      * <p>This key is available on all devices.</p>
      * @see #SENSOR_READOUT_TIMESTAMP_NOT_SUPPORTED
      * @see #SENSOR_READOUT_TIMESTAMP_HARDWARE
-     * @hide
      */
     @PublicKey
     @NonNull
@@ -5572,4 +5571,6 @@
 
 
 
+
+
 }
diff --git a/core/java/android/hardware/camera2/CameraExtensionSession.java b/core/java/android/hardware/camera2/CameraExtensionSession.java
index 6f895d5..b0fafea 100644
--- a/core/java/android/hardware/camera2/CameraExtensionSession.java
+++ b/core/java/android/hardware/camera2/CameraExtensionSession.java
@@ -18,6 +18,11 @@
 
 import android.annotation.IntRange;
 import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.hardware.camera2.impl.PublicKey;
+import android.hardware.camera2.utils.TypeReference;
+import android.util.Pair;
+import android.util.Range;
 
 import java.util.concurrent.Executor;
 
@@ -424,6 +429,28 @@
     }
 
     /**
+     * Return the realtime still {@link #capture} latency.
+     *
+     * <p>The pair will be in milliseconds with the first value indicating the capture latency from
+     * the {@link ExtensionCaptureCallback#onCaptureStarted} until
+     * {@link ExtensionCaptureCallback#onCaptureProcessStarted}
+     * and the second value containing the estimated post-processing latency from
+     * {@link ExtensionCaptureCallback#onCaptureProcessStarted} until the processed frame returns
+     * to the client.</p>
+     *
+     * <p>The estimations will take into account the current environment conditions, the camera
+     * state and will include the time spent processing the multi-frame capture request along with
+     * any additional time for encoding of the processed buffer if necessary.</p>
+     *
+     * @return The realtime still capture latency,
+     * or {@code null} if the estimation is not supported.
+     */
+    @Nullable
+    public Pair<Long, Long> getRealtimeStillCaptureLatency() throws CameraAccessException {
+        throw new UnsupportedOperationException("Subclasses must override this method");
+    }
+
+    /**
      * Close this capture session asynchronously.
      *
      * <p>Closing a session frees up the target output Surfaces of the session
diff --git a/core/java/android/hardware/camera2/CameraManager.java b/core/java/android/hardware/camera2/CameraManager.java
index f858227..ce191e8 100644
--- a/core/java/android/hardware/camera2/CameraManager.java
+++ b/core/java/android/hardware/camera2/CameraManager.java
@@ -23,6 +23,10 @@
 import android.annotation.SystemApi;
 import android.annotation.SystemService;
 import android.annotation.TestApi;
+import android.app.compat.CompatChanges;
+import android.compat.annotation.ChangeId;
+import android.compat.annotation.EnabledSince;
+import android.compat.annotation.Overridable;
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.graphics.Point;
@@ -104,6 +108,24 @@
     private final boolean mHasOpenCloseListenerPermission;
 
     /**
+     * Force camera output to be rotated to portrait orientation on landscape cameras.
+     * Many apps do not handle this situation and display stretched images otherwise.
+     * @hide
+     */
+    @ChangeId
+    @Overridable
+    @EnabledSince(targetSdkVersion = android.os.Build.VERSION_CODES.TIRAMISU)
+    @TestApi
+    public static final long OVERRIDE_FRONT_CAMERA_APP_COMPAT = 250678880L;
+
+    /**
+     * System property for allowing the above
+     * @hide
+     */
+    public static final String LANDSCAPE_TO_PORTRAIT_PROP =
+            "camera.enable_landscape_to_portrait";
+
+    /**
      * @hide
      */
     public CameraManager(Context context) {
@@ -526,7 +548,8 @@
             for (String physicalCameraId : physicalCameraIds) {
                 CameraMetadataNative physicalCameraInfo =
                         cameraService.getCameraCharacteristics(physicalCameraId,
-                                mContext.getApplicationInfo().targetSdkVersion);
+                                mContext.getApplicationInfo().targetSdkVersion,
+                                /*overrideToPortrait*/false);
                 StreamConfiguration[] configs = physicalCameraInfo.get(
                         CameraCharacteristics.
                                 SCALER_PHYSICAL_CAMERA_MULTI_RESOLUTION_STREAM_CONFIGURATIONS);
@@ -585,8 +608,9 @@
             try {
                 Size displaySize = getDisplaySize();
 
+                boolean overrideToPortrait = shouldOverrideToPortrait();
                 CameraMetadataNative info = cameraService.getCameraCharacteristics(cameraId,
-                        mContext.getApplicationInfo().targetSdkVersion);
+                        mContext.getApplicationInfo().targetSdkVersion, overrideToPortrait);
                 try {
                     info.setCameraId(Integer.parseInt(cameraId));
                 } catch (NumberFormatException e) {
@@ -703,9 +727,12 @@
                         ICameraService.ERROR_DISCONNECTED,
                         "Camera service is currently unavailable");
                 }
+
+                boolean overrideToPortrait = shouldOverrideToPortrait();
                 cameraUser = cameraService.connectDevice(callbacks, cameraId,
-                    mContext.getOpPackageName(),  mContext.getAttributionTag(), uid,
-                    oomScoreOffset, mContext.getApplicationInfo().targetSdkVersion);
+                    mContext.getOpPackageName(), mContext.getAttributionTag(), uid,
+                    oomScoreOffset, mContext.getApplicationInfo().targetSdkVersion,
+                    overrideToPortrait);
             } catch (ServiceSpecificException e) {
                 if (e.errorCode == ICameraService.ERROR_DEPRECATED_HAL) {
                     throw new AssertionError("Should've gone down the shim path");
@@ -1133,6 +1160,11 @@
         return CameraManagerGlobal.get().getTorchStrengthLevel(cameraId);
     }
 
+    private static boolean shouldOverrideToPortrait() {
+        return CompatChanges.isChangeEnabled(OVERRIDE_FRONT_CAMERA_APP_COMPAT)
+                && CameraManagerGlobal.sLandscapeToPortrait;
+    }
+
     /**
      * A callback for camera devices becoming available or unavailable to open.
      *
@@ -1579,6 +1611,9 @@
         public static final boolean sCameraServiceDisabled =
                 SystemProperties.getBoolean("config.disable_cameraservice", false);
 
+        public static final boolean sLandscapeToPortrait =
+                SystemProperties.getBoolean(LANDSCAPE_TO_PORTRAIT_PROP, false);
+
         public static CameraManagerGlobal get() {
             return gCameraManager;
         }
diff --git a/core/java/android/hardware/camera2/CameraMetadata.java b/core/java/android/hardware/camera2/CameraMetadata.java
index 44f8b1b..b2428b1 100644
--- a/core/java/android/hardware/camera2/CameraMetadata.java
+++ b/core/java/android/hardware/camera2/CameraMetadata.java
@@ -1695,7 +1695,6 @@
      * <p>This camera device doesn't support readout timestamp and onReadoutStarted
      * callback.</p>
      * @see CameraCharacteristics#SENSOR_READOUT_TIMESTAMP
-     * @hide
      */
     public static final int SENSOR_READOUT_TIMESTAMP_NOT_SUPPORTED = 0;
 
@@ -1705,7 +1704,6 @@
      * readout timestamp is generated by the camera hardware and it has the same accuracy
      * and timing characteristics of the start-of-exposure time.</p>
      * @see CameraCharacteristics#SENSOR_READOUT_TIMESTAMP
-     * @hide
      */
     public static final int SENSOR_READOUT_TIMESTAMP_HARDWARE = 1;
 
diff --git a/core/java/android/hardware/camera2/CaptureRequest.java b/core/java/android/hardware/camera2/CaptureRequest.java
index ea3e4a8..43bfdcc 100644
--- a/core/java/android/hardware/camera2/CaptureRequest.java
+++ b/core/java/android/hardware/camera2/CaptureRequest.java
@@ -4154,6 +4154,38 @@
     public static final Key<Integer> DISTORTION_CORRECTION_MODE =
             new Key<Integer>("android.distortionCorrection.mode", int.class);
 
+    /**
+     * <p>Strength of the extension post-processing effect</p>
+     * <p>This control allows Camera extension clients to configure the strength of the applied
+     * extension effect. Strength equal to 0 means that the extension must not apply any
+     * post-processing and return a regular captured frame. Strength equal to 100 is the
+     * default level of post-processing applied when the control is not supported or not set
+     * by the client. Values between 0 and 100 will have different effect depending on the
+     * extension type as described below:</p>
+     * <ul>
+     * <li>{@link android.hardware.camera2.CameraExtensionCharacteristics#EXTENSION_BOKEH BOKEH} -
+     * the strength is expected to control the amount of blur.</li>
+     * <li>{@link android.hardware.camera2.CameraExtensionCharacteristics#EXTENSION_HDR HDR} and
+     * {@link android.hardware.camera2.CameraExtensionCharacteristics#EXTENSION_NIGHT NIGHT} -
+     * the strength can control the amount of images fused and the brightness of the final image.</li>
+     * <li>{@link android.hardware.camera2.CameraExtensionCharacteristics#EXTENSION_FACE_RETOUCH FACE_RETOUCH} -
+     * the strength value will control the amount of cosmetic enhancement and skin
+     * smoothing.</li>
+     * </ul>
+     * <p>The control will be supported if the capture request key is part of the list generated by
+     * {@link android.hardware.camera2.CameraExtensionCharacteristics#getAvailableCaptureRequestKeys }.
+     * The control is only defined and available to clients sending capture requests via
+     * {@link android.hardware.camera2.CameraExtensionSession }.
+     * The default value is 100.</p>
+     * <p><b>Range of valid values:</b><br>
+     * 0 - 100</p>
+     * <p><b>Optional</b> - The value for this key may be {@code null} on some devices.</p>
+     */
+    @PublicKey
+    @NonNull
+    public static final Key<Integer> EXTENSION_STRENGTH =
+            new Key<Integer>("android.extension.strength", int.class);
+
     /*~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~
      * End generated code
      *~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~O@*/
@@ -4163,4 +4195,6 @@
 
 
 
+
+
 }
diff --git a/core/java/android/hardware/camera2/CaptureResult.java b/core/java/android/hardware/camera2/CaptureResult.java
index 285c933..fb52cc6 100644
--- a/core/java/android/hardware/camera2/CaptureResult.java
+++ b/core/java/android/hardware/camera2/CaptureResult.java
@@ -5576,6 +5576,62 @@
     public static final Key<Integer> DISTORTION_CORRECTION_MODE =
             new Key<Integer>("android.distortionCorrection.mode", int.class);
 
+    /**
+     * <p>Contains the extension type of the currently active extension</p>
+     * <p>The capture result will only be supported and included by camera extension
+     * {@link android.hardware.camera2.CameraExtensionSession sessions}.
+     * In case the extension session was configured to use
+     * {@link android.hardware.camera2.CameraExtensionCharacteristics#EXTENSION_AUTOMATIC AUTO},
+     * then the extension type value will indicate the currently active extension like
+     * {@link android.hardware.camera2.CameraExtensionCharacteristics#EXTENSION_HDR HDR},
+     * {@link android.hardware.camera2.CameraExtensionCharacteristics#EXTENSION_NIGHT NIGHT} etc.
+     * , and will never return
+     * {@link android.hardware.camera2.CameraExtensionCharacteristics#EXTENSION_AUTOMATIC AUTO}.
+     * In case the extension session was configured to use an extension different from
+     * {@link android.hardware.camera2.CameraExtensionCharacteristics#EXTENSION_AUTOMATIC AUTO},
+     * then the result type will always match with the configured extension type.</p>
+     * <p><b>Range of valid values:</b><br>
+     * Extension type value listed in
+     * {@link android.hardware.camera2.CameraExtensionCharacteristics }</p>
+     * <p><b>Optional</b> - The value for this key may be {@code null} on some devices.</p>
+     */
+    @PublicKey
+    @NonNull
+    public static final Key<Integer> EXTENSION_CURRENT_TYPE =
+            new Key<Integer>("android.extension.currentType", int.class);
+
+    /**
+     * <p>Strength of the extension post-processing effect</p>
+     * <p>This control allows Camera extension clients to configure the strength of the applied
+     * extension effect. Strength equal to 0 means that the extension must not apply any
+     * post-processing and return a regular captured frame. Strength equal to 100 is the
+     * default level of post-processing applied when the control is not supported or not set
+     * by the client. Values between 0 and 100 will have different effect depending on the
+     * extension type as described below:</p>
+     * <ul>
+     * <li>{@link android.hardware.camera2.CameraExtensionCharacteristics#EXTENSION_BOKEH BOKEH} -
+     * the strength is expected to control the amount of blur.</li>
+     * <li>{@link android.hardware.camera2.CameraExtensionCharacteristics#EXTENSION_HDR HDR} and
+     * {@link android.hardware.camera2.CameraExtensionCharacteristics#EXTENSION_NIGHT NIGHT} -
+     * the strength can control the amount of images fused and the brightness of the final image.</li>
+     * <li>{@link android.hardware.camera2.CameraExtensionCharacteristics#EXTENSION_FACE_RETOUCH FACE_RETOUCH} -
+     * the strength value will control the amount of cosmetic enhancement and skin
+     * smoothing.</li>
+     * </ul>
+     * <p>The control will be supported if the capture request key is part of the list generated by
+     * {@link android.hardware.camera2.CameraExtensionCharacteristics#getAvailableCaptureRequestKeys }.
+     * The control is only defined and available to clients sending capture requests via
+     * {@link android.hardware.camera2.CameraExtensionSession }.
+     * The default value is 100.</p>
+     * <p><b>Range of valid values:</b><br>
+     * 0 - 100</p>
+     * <p><b>Optional</b> - The value for this key may be {@code null} on some devices.</p>
+     */
+    @PublicKey
+    @NonNull
+    public static final Key<Integer> EXTENSION_STRENGTH =
+            new Key<Integer>("android.extension.strength", int.class);
+
     /*~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~
      * End generated code
      *~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~O@*/
@@ -5585,4 +5641,6 @@
 
 
 
+
+
 }
diff --git a/core/java/android/hardware/camera2/extension/IImageCaptureExtenderImpl.aidl b/core/java/android/hardware/camera2/extension/IImageCaptureExtenderImpl.aidl
index 615536b..360f809 100644
--- a/core/java/android/hardware/camera2/extension/IImageCaptureExtenderImpl.aidl
+++ b/core/java/android/hardware/camera2/extension/IImageCaptureExtenderImpl.aidl
@@ -19,6 +19,7 @@
 
 import android.hardware.camera2.extension.CaptureStageImpl;
 import android.hardware.camera2.extension.ICaptureProcessorImpl;
+import android.hardware.camera2.extension.LatencyPair;
 import android.hardware.camera2.extension.LatencyRange;
 import android.hardware.camera2.extension.Size;
 import android.hardware.camera2.extension.SizeList;
@@ -43,4 +44,5 @@
     CameraMetadataNative getAvailableCaptureRequestKeys();
     CameraMetadataNative getAvailableCaptureResultKeys();
     boolean isCaptureProcessProgressAvailable();
+    @nullable LatencyPair getRealtimeCaptureLatency();
 }
diff --git a/core/java/android/hardware/camera2/extension/ISessionProcessorImpl.aidl b/core/java/android/hardware/camera2/extension/ISessionProcessorImpl.aidl
index 0eca5a7..e0f1b64 100644
--- a/core/java/android/hardware/camera2/extension/ISessionProcessorImpl.aidl
+++ b/core/java/android/hardware/camera2/extension/ISessionProcessorImpl.aidl
@@ -19,6 +19,8 @@
 import android.hardware.camera2.extension.CameraSessionConfig;
 import android.hardware.camera2.extension.ICaptureCallback;
 import android.hardware.camera2.extension.IRequestProcessorImpl;
+import android.hardware.camera2.extension.LatencyPair;
+import android.hardware.camera2.extension.LatencyRange;
 import android.hardware.camera2.extension.OutputSurface;
 
 /** @hide */
@@ -34,4 +36,5 @@
     int startCapture(in ICaptureCallback callback);
     void setParameters(in CaptureRequest captureRequest);
     int startTrigger(in CaptureRequest captureRequest, in ICaptureCallback callback);
+    @nullable LatencyPair getRealtimeCaptureLatency();
 }
diff --git a/core/java/android/hardware/camera2/extension/LatencyPair.aidl b/core/java/android/hardware/camera2/extension/LatencyPair.aidl
new file mode 100644
index 0000000..5174f1d
--- /dev/null
+++ b/core/java/android/hardware/camera2/extension/LatencyPair.aidl
@@ -0,0 +1,23 @@
+/**
+ * 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 android.hardware.camera2.extension;
+
+/** @hide */
+parcelable LatencyPair
+{
+    long first;
+    long second;
+}
diff --git a/core/java/android/hardware/camera2/impl/CameraAdvancedExtensionSessionImpl.java b/core/java/android/hardware/camera2/impl/CameraAdvancedExtensionSessionImpl.java
index 3a8dc03..42c4411 100644
--- a/core/java/android/hardware/camera2/impl/CameraAdvancedExtensionSessionImpl.java
+++ b/core/java/android/hardware/camera2/impl/CameraAdvancedExtensionSessionImpl.java
@@ -43,6 +43,7 @@
 import android.hardware.camera2.extension.IRequestCallback;
 import android.hardware.camera2.extension.IRequestProcessorImpl;
 import android.hardware.camera2.extension.ISessionProcessorImpl;
+import android.hardware.camera2.extension.LatencyPair;
 import android.hardware.camera2.extension.OutputConfigId;
 import android.hardware.camera2.extension.OutputSurface;
 import android.hardware.camera2.extension.ParcelCaptureResult;
@@ -61,6 +62,8 @@
 import android.os.HandlerThread;
 import android.os.RemoteException;
 import android.util.Log;
+import android.util.Pair;
+import android.util.Range;
 import android.util.Size;
 import android.view.Surface;
 
@@ -329,6 +332,28 @@
     }
 
     @Override
+    public Pair<Long, Long> getRealtimeStillCaptureLatency() throws CameraAccessException {
+        synchronized (mInterfaceLock) {
+            if (!mInitialized) {
+                throw new IllegalStateException("Uninitialized component");
+            }
+
+            try {
+                LatencyPair latency = mSessionProcessor.getRealtimeCaptureLatency();
+                if (latency != null) {
+                    return new Pair<>(latency.first, latency.second);
+                }
+
+                return null;
+            } catch (RemoteException e) {
+                Log.e(TAG, "Failed to query realtime latency! Extension service does not "
+                        + "respond");
+                throw new CameraAccessException(CameraAccessException.CAMERA_ERROR);
+            }
+        }
+    }
+
+    @Override
     public int setRepeatingRequest(@NonNull CaptureRequest request, @NonNull Executor executor,
             @NonNull ExtensionCaptureCallback listener) throws CameraAccessException {
         int seqId = -1;
diff --git a/core/java/android/hardware/camera2/impl/CameraExtensionSessionImpl.java b/core/java/android/hardware/camera2/impl/CameraExtensionSessionImpl.java
index 389c214..259bd7b 100644
--- a/core/java/android/hardware/camera2/impl/CameraExtensionSessionImpl.java
+++ b/core/java/android/hardware/camera2/impl/CameraExtensionSessionImpl.java
@@ -43,6 +43,7 @@
 import android.hardware.camera2.extension.IPreviewExtenderImpl;
 import android.hardware.camera2.extension.IProcessResultImpl;
 import android.hardware.camera2.extension.IRequestUpdateProcessorImpl;
+import android.hardware.camera2.extension.LatencyPair;
 import android.hardware.camera2.extension.ParcelImage;
 import android.hardware.camera2.params.DynamicRangeProfiles;
 import android.hardware.camera2.params.ExtensionSessionConfiguration;
@@ -59,6 +60,7 @@
 import android.util.Log;
 import android.util.LongSparseArray;
 import android.util.Pair;
+import android.util.Range;
 import android.util.Size;
 import android.view.Surface;
 
@@ -466,6 +468,28 @@
     }
 
     @Override
+    public Pair<Long, Long> getRealtimeStillCaptureLatency() throws CameraAccessException {
+        synchronized (mInterfaceLock) {
+            if (!mInitialized) {
+                throw new IllegalStateException("Uninitialized component");
+            }
+
+            try {
+                LatencyPair latency = mImageExtender.getRealtimeCaptureLatency();
+                if (latency != null) {
+                    return new Pair<>(latency.first, latency.second);
+                }
+
+                return null;
+            } catch (RemoteException e) {
+                Log.e(TAG, "Failed to query realtime latency! Extension service does not "
+                        + "respond");
+                throw new CameraAccessException(CameraAccessException.CAMERA_ERROR);
+            }
+        }
+    }
+
+    @Override
     public int setRepeatingRequest(@NonNull CaptureRequest request,
                                    @NonNull Executor executor,
                                    @NonNull ExtensionCaptureCallback listener)
diff --git a/core/java/android/hardware/display/AmbientBrightnessDayStats.java b/core/java/android/hardware/display/AmbientBrightnessDayStats.java
index 8aff911..2816706 100644
--- a/core/java/android/hardware/display/AmbientBrightnessDayStats.java
+++ b/core/java/android/hardware/display/AmbientBrightnessDayStats.java
@@ -208,7 +208,7 @@
     }
 
     private int getBucketIndex(float ambientBrightness) {
-        if (ambientBrightness < mBucketBoundaries[0]) {
+        if (ambientBrightness < mBucketBoundaries[0] || Float.isNaN(ambientBrightness)) {
             return -1;
         }
         int low = 0;
diff --git a/core/java/android/hardware/display/AmbientDisplayConfiguration.java b/core/java/android/hardware/display/AmbientDisplayConfiguration.java
index 8c71b36..47541ca 100644
--- a/core/java/android/hardware/display/AmbientDisplayConfiguration.java
+++ b/core/java/android/hardware/display/AmbientDisplayConfiguration.java
@@ -40,6 +40,7 @@
     private static final String TAG = "AmbientDisplayConfig";
     private final Context mContext;
     private final boolean mAlwaysOnByDefault;
+    private final boolean mPickupGestureEnabledByDefault;
 
     /** Copied from android.provider.Settings.Secure since these keys are hidden. */
     private static final String[] DOZE_SETTINGS = {
@@ -65,6 +66,8 @@
     public AmbientDisplayConfiguration(Context context) {
         mContext = context;
         mAlwaysOnByDefault = mContext.getResources().getBoolean(R.bool.config_dozeAlwaysOnEnabled);
+        mPickupGestureEnabledByDefault =
+                mContext.getResources().getBoolean(R.bool.config_dozePickupGestureEnabled);
     }
 
     /** @hide */
@@ -95,7 +98,8 @@
 
     /** @hide */
     public boolean pickupGestureEnabled(int user) {
-        return boolSettingDefaultOn(Settings.Secure.DOZE_PICK_UP_GESTURE, user)
+        return boolSetting(Settings.Secure.DOZE_PICK_UP_GESTURE, user,
+                mPickupGestureEnabledByDefault ? 1 : 0)
                 && dozePickupSensorAvailable();
     }
 
diff --git a/core/java/android/hardware/display/DisplayManagerInternal.java b/core/java/android/hardware/display/DisplayManagerInternal.java
index 829908f..7409187 100644
--- a/core/java/android/hardware/display/DisplayManagerInternal.java
+++ b/core/java/android/hardware/display/DisplayManagerInternal.java
@@ -439,9 +439,6 @@
         // 1 (brighter). Set to Float.NaN if there's no override.
         public float screenAutoBrightnessAdjustmentOverride;
 
-        // If true, enables automatic brightness control.
-        public boolean useAutoBrightness;
-
         // If true, scales the brightness to a fraction of desired (as defined by
         // screenLowPowerBrightnessFactor).
         public boolean lowPowerMode;
@@ -471,7 +468,6 @@
             policy = POLICY_BRIGHT;
             useProximitySensor = false;
             screenBrightnessOverride = PowerManager.BRIGHTNESS_INVALID_FLOAT;
-            useAutoBrightness = false;
             screenAutoBrightnessAdjustmentOverride = Float.NaN;
             screenLowPowerBrightnessFactor = 0.5f;
             blockScreenOn = false;
@@ -491,7 +487,6 @@
             policy = other.policy;
             useProximitySensor = other.useProximitySensor;
             screenBrightnessOverride = other.screenBrightnessOverride;
-            useAutoBrightness = other.useAutoBrightness;
             screenAutoBrightnessAdjustmentOverride = other.screenAutoBrightnessAdjustmentOverride;
             screenLowPowerBrightnessFactor = other.screenLowPowerBrightnessFactor;
             blockScreenOn = other.blockScreenOn;
@@ -513,7 +508,6 @@
                     && useProximitySensor == other.useProximitySensor
                     && floatEquals(screenBrightnessOverride,
                             other.screenBrightnessOverride)
-                    && useAutoBrightness == other.useAutoBrightness
                     && floatEquals(screenAutoBrightnessAdjustmentOverride,
                             other.screenAutoBrightnessAdjustmentOverride)
                     && screenLowPowerBrightnessFactor
@@ -539,7 +533,6 @@
             return "policy=" + policyToString(policy)
                     + ", useProximitySensor=" + useProximitySensor
                     + ", screenBrightnessOverride=" + screenBrightnessOverride
-                    + ", useAutoBrightness=" + useAutoBrightness
                     + ", screenAutoBrightnessAdjustmentOverride="
                     + screenAutoBrightnessAdjustmentOverride
                     + ", screenLowPowerBrightnessFactor=" + screenLowPowerBrightnessFactor
diff --git a/core/java/android/hardware/input/IInputManager.aidl b/core/java/android/hardware/input/IInputManager.aidl
index b26c0a2..6314cab 100644
--- a/core/java/android/hardware/input/IInputManager.aidl
+++ b/core/java/android/hardware/input/IInputManager.aidl
@@ -120,8 +120,24 @@
             in InputMethodInfo imeInfo, in InputMethodSubtype imeSubtype,
             String keyboardLayoutDescriptor);
 
-    String[] getKeyboardLayoutListForInputDevice(in InputDeviceIdentifier identifier, int userId,
-            in InputMethodInfo imeInfo, in InputMethodSubtype imeSubtype);
+    KeyboardLayout[] getKeyboardLayoutListForInputDevice(in InputDeviceIdentifier identifier,
+            int userId, in InputMethodInfo imeInfo, in InputMethodSubtype imeSubtype);
+
+    // Modifier key remapping APIs.
+    @EnforcePermission("REMAP_MODIFIER_KEYS")
+    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
+            + "android.Manifest.permission.REMAP_MODIFIER_KEYS)")
+    void remapModifierKey(int fromKey, int toKey);
+
+    @EnforcePermission("REMAP_MODIFIER_KEYS")
+    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
+            + "android.Manifest.permission.REMAP_MODIFIER_KEYS)")
+    void clearAllModifierKeyRemappings();
+
+    @EnforcePermission("REMAP_MODIFIER_KEYS")
+    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
+            + "android.Manifest.permission.REMAP_MODIFIER_KEYS)")
+    Map getModifierKeyRemapping();
 
     // Registers an input devices changed listener.
     void registerInputDevicesChangedListener(IInputDevicesChangedListener listener);
diff --git a/core/java/android/hardware/input/InputManager.java b/core/java/android/hardware/input/InputManager.java
index cea3fa1..2eeae46 100644
--- a/core/java/android/hardware/input/InputManager.java
+++ b/core/java/android/hardware/input/InputManager.java
@@ -78,6 +78,7 @@
 import java.lang.annotation.RetentionPolicy;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.Objects;
 import java.util.concurrent.Executor;
 
@@ -253,6 +254,31 @@
     })
     public @interface SwitchState {}
 
+    /** @hide */
+    @Retention(RetentionPolicy.SOURCE)
+    @IntDef(prefix = { "REMAPPABLE_MODIFIER_KEY_" }, value = {
+            RemappableModifierKey.REMAPPABLE_MODIFIER_KEY_CTRL_LEFT,
+            RemappableModifierKey.REMAPPABLE_MODIFIER_KEY_CTRL_RIGHT,
+            RemappableModifierKey.REMAPPABLE_MODIFIER_KEY_META_LEFT,
+            RemappableModifierKey.REMAPPABLE_MODIFIER_KEY_META_RIGHT,
+            RemappableModifierKey.REMAPPABLE_MODIFIER_KEY_ALT_LEFT,
+            RemappableModifierKey.REMAPPABLE_MODIFIER_KEY_ALT_RIGHT,
+            RemappableModifierKey.REMAPPABLE_MODIFIER_KEY_SHIFT_LEFT,
+            RemappableModifierKey.REMAPPABLE_MODIFIER_KEY_SHIFT_RIGHT,
+            RemappableModifierKey.REMAPPABLE_MODIFIER_KEY_CAPS_LOCK,
+    })
+    public @interface RemappableModifierKey {
+        int REMAPPABLE_MODIFIER_KEY_CTRL_LEFT = KeyEvent.KEYCODE_CTRL_LEFT;
+        int REMAPPABLE_MODIFIER_KEY_CTRL_RIGHT = KeyEvent.KEYCODE_CTRL_RIGHT;
+        int REMAPPABLE_MODIFIER_KEY_META_LEFT = KeyEvent.KEYCODE_META_LEFT;
+        int REMAPPABLE_MODIFIER_KEY_META_RIGHT = KeyEvent.KEYCODE_META_RIGHT;
+        int REMAPPABLE_MODIFIER_KEY_ALT_LEFT = KeyEvent.KEYCODE_ALT_LEFT;
+        int REMAPPABLE_MODIFIER_KEY_ALT_RIGHT = KeyEvent.KEYCODE_ALT_RIGHT;
+        int REMAPPABLE_MODIFIER_KEY_SHIFT_LEFT = KeyEvent.KEYCODE_SHIFT_LEFT;
+        int REMAPPABLE_MODIFIER_KEY_SHIFT_RIGHT = KeyEvent.KEYCODE_SHIFT_RIGHT;
+        int REMAPPABLE_MODIFIER_KEY_CAPS_LOCK = KeyEvent.KEYCODE_CAPS_LOCK;
+    }
+
     /**
      * Switch State: Unknown.
      *
@@ -854,6 +880,60 @@
     }
 
     /**
+     * Remaps modifier keys. Remapping a modifier key to itself will clear any previous remappings
+     * for that key.
+     *
+     * @param fromKey The modifier key getting remapped.
+     * @param toKey The modifier key that it is remapped to.
+     *
+     * @hide
+     */
+    @TestApi
+    @RequiresPermission(Manifest.permission.REMAP_MODIFIER_KEYS)
+    public void remapModifierKey(@RemappableModifierKey int fromKey,
+            @RemappableModifierKey int toKey) {
+        try {
+            mIm.remapModifierKey(fromKey, toKey);
+        } catch (RemoteException ex) {
+            throw ex.rethrowFromSystemServer();
+        }
+    }
+
+    /**
+     * Clears all existing modifier key remappings
+     *
+     * @hide
+     */
+    @TestApi
+    @RequiresPermission(Manifest.permission.REMAP_MODIFIER_KEYS)
+    public void clearAllModifierKeyRemappings() {
+        try {
+            mIm.clearAllModifierKeyRemappings();
+        } catch (RemoteException ex) {
+            throw ex.rethrowFromSystemServer();
+        }
+    }
+
+    /**
+     * Provides the current modifier key remapping
+     *
+     * @return a {fromKey, toKey} map that contains the existing modifier key remappings..
+     * {@link RemappableModifierKey}
+     *
+     * @hide
+     */
+    @TestApi
+    @NonNull
+    @RequiresPermission(Manifest.permission.REMAP_MODIFIER_KEYS)
+    public Map<Integer, Integer> getModifierKeyRemapping() {
+        try {
+            return mIm.getModifierKeyRemapping();
+        } catch (RemoteException ex) {
+            throw ex.rethrowFromSystemServer();
+        }
+    }
+
+    /**
      * Gets the TouchCalibration applied to the specified input device's coordinates.
      *
      * @param inputDeviceDescriptor The input device descriptor.
@@ -906,7 +986,7 @@
     @Nullable
     public String getKeyboardLayoutForInputDevice(@NonNull InputDeviceIdentifier identifier,
             @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
-            @NonNull InputMethodSubtype imeSubtype) {
+            @Nullable InputMethodSubtype imeSubtype) {
         try {
             return mIm.getKeyboardLayoutForInputDevice(identifier, userId, imeInfo, imeSubtype);
         } catch (RemoteException ex) {
@@ -934,7 +1014,7 @@
     @RequiresPermission(Manifest.permission.SET_KEYBOARD_LAYOUT)
     public void setKeyboardLayoutForInputDevice(@NonNull InputDeviceIdentifier identifier,
             @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
-            @NonNull InputMethodSubtype imeSubtype, @NonNull String keyboardLayoutDescriptor) {
+            @Nullable InputMethodSubtype imeSubtype, @NonNull String keyboardLayoutDescriptor) {
         if (identifier == null) {
             throw new IllegalArgumentException("identifier must not be null");
         }
@@ -951,8 +1031,8 @@
     }
 
     /**
-     * Gets all keyboard layout descriptors that are enabled for the specified input device, userId,
-     * imeInfo and imeSubtype.
+     * Gets all keyboard layouts that are enabled for the specified input device, userId, imeInfo
+     * and imeSubtype.
      *
      * @param identifier The identifier for the input device.
      * @param userId user profile ID
@@ -962,9 +1042,9 @@
      *
      * @hide
      */
-    public String[] getKeyboardLayoutListForInputDevice(InputDeviceIdentifier identifier,
+    public KeyboardLayout[] getKeyboardLayoutListForInputDevice(InputDeviceIdentifier identifier,
             @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
-            @NonNull InputMethodSubtype imeSubtype) {
+            @Nullable InputMethodSubtype imeSubtype) {
         if (identifier == null) {
             throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
         }
@@ -1964,6 +2044,217 @@
     }
 
     /**
+     * Whether there is a gesture-compatible touchpad connected to the device.
+     * @hide
+     */
+    public boolean areTouchpadGesturesAvailable(@NonNull Context context) {
+        // TODO: implement the right logic
+        return true;
+    }
+
+    /**
+     * Gets the touchpad pointer speed.
+     *
+     * The returned value only applies to gesture-compatible touchpads.
+     *
+     * @param context The application context.
+     * @return The pointer speed as a value between {@link #MIN_POINTER_SPEED} and
+     * {@link #MAX_POINTER_SPEED}, or the default value {@link #DEFAULT_POINTER_SPEED}.
+     *
+     * @hide
+     */
+    public int getTouchpadPointerSpeed(@NonNull Context context) {
+        int speed = DEFAULT_POINTER_SPEED;
+        // TODO: obtain the actual speed from the settings
+        return speed;
+    }
+
+    /**
+     * Sets the touchpad pointer speed, and saves it in the settings.
+     *
+     * The new speed will only apply to gesture-compatible touchpads.
+     *
+     * @param context The application context.
+     * @param speed The pointer speed as a value between {@link #MIN_POINTER_SPEED} and
+     * {@link #MAX_POINTER_SPEED}, or the default value {@link #DEFAULT_POINTER_SPEED}.
+     *
+     * @hide
+     */
+    public void setTouchpadPointerSpeed(@NonNull Context context, int speed) {
+        if (speed < MIN_POINTER_SPEED || speed > MAX_POINTER_SPEED) {
+            throw new IllegalArgumentException("speed out of range");
+        }
+
+        // TODO: set the right setting
+    }
+
+    /**
+     * Changes the touchpad pointer speed temporarily, but does not save the setting.
+     *
+     * The new speed will only apply to gesture-compatible touchpads.
+     * Requires {@link android.Manifest.permission.SET_POINTER_SPEED}.
+     *
+     * @param speed The pointer speed as a value between {@link #MIN_POINTER_SPEED} and
+     * {@link #MAX_POINTER_SPEED}, or the default value {@link #DEFAULT_POINTER_SPEED}.
+     *
+     * @hide
+     */
+    public void tryTouchpadPointerSpeed(int speed) {
+        if (speed < MIN_POINTER_SPEED || speed > MAX_POINTER_SPEED) {
+            throw new IllegalArgumentException("speed out of range");
+        }
+
+        // TODO: set the touchpad pointer speed on the gesture library
+    }
+
+    /**
+     * Returns true if the touchpad should use pointer acceleration.
+     *
+     * The returned value only applies to gesture-compatible touchpads.
+     *
+     * @param context The application context.
+     * @return Whether the touchpad should use pointer acceleration.
+     *
+     * @hide
+     */
+    public boolean useTouchpadPointerAcceleration(@NonNull Context context) {
+        // TODO: obtain the actual behavior from the settings
+        return true;
+    }
+
+    /**
+     * Sets the pointer acceleration behavior for the touchpad.
+     *
+     * The new behavior is only applied to gesture-compatible touchpads.
+     *
+     * @param context The application context.
+     * @param enabled Will enable pointer acceleration if true, disable it if false
+     *
+     * @hide
+     */
+    public void setTouchpadPointerAcceleration(@NonNull Context context, boolean enabled) {
+        // TODO: set the right setting
+    }
+
+    /**
+     * Returns true if moving two fingers upwards on the touchpad should
+     * scroll down, which is known as natural scrolling.
+     *
+     * The returned value only applies to gesture-compatible touchpads.
+     *
+     * @param context The application context.
+     * @return Whether the touchpad should use natural scrolling.
+     *
+     * @hide
+     */
+    public boolean useTouchpadNaturalScrolling(@NonNull Context context) {
+        // TODO: obtain the actual behavior from the settings
+        return true;
+    }
+
+    /**
+     * Sets the natural scroll behavior for the touchpad.
+     *
+     * If natural scrolling is enabled, moving two fingers upwards on the
+     * touchpad will scroll down.
+     *
+     * @param context The application context.
+     * @param enabled Will enable natural scroll if true, disable it if false
+     *
+     * @hide
+     */
+    public void setTouchpadNaturalScrolling(@NonNull Context context, boolean enabled) {
+        // TODO: set the right setting
+    }
+
+    /**
+     * Returns true if the touchpad should use tap to click.
+     *
+     * The returned value only applies to gesture-compatible touchpads.
+     *
+     * @param context The application context.
+     * @return Whether the touchpad should use tap to click.
+     *
+     * @hide
+     */
+    public boolean useTouchpadTapToClick(@NonNull Context context) {
+        // TODO: obtain the actual behavior from the settings
+        return true;
+    }
+
+    /**
+     * Sets the tap to click behavior for the touchpad.
+     *
+     * The new behavior is only applied to gesture-compatible touchpads.
+     *
+     * @param context The application context.
+     * @param enabled Will enable tap to click if true, disable it if false
+     *
+     * @hide
+     */
+    public void setTouchpadTapToClick(@NonNull Context context, boolean enabled) {
+        // TODO: set the right setting
+    }
+
+    /**
+     * Returns true if the touchpad should use tap dragging.
+     *
+     * The returned value only applies to gesture-compatible touchpads.
+     *
+     * @param context The application context.
+     * @return Whether the touchpad should use tap dragging.
+     *
+     * @hide
+     */
+    public boolean useTouchpadTapDragging(@NonNull Context context) {
+        // TODO: obtain the actual behavior from the settings
+        return true;
+    }
+
+    /**
+     * Sets the tap dragging behavior for the touchpad.
+     *
+     * The new behavior is only applied to gesture-compatible touchpads.
+     *
+     * @param context The application context.
+     * @param enabled Will enable tap dragging if true, disable it if false
+     *
+     * @hide
+     */
+    public void setTouchpadTapDragging(@NonNull Context context, boolean enabled) {
+        // TODO: set the right setting
+    }
+
+    /**
+     * Returns true if the touchpad should use the right click zone.
+     *
+     * The returned value only applies to gesture-compatible touchpads.
+     *
+     * @param context The application context.
+     * @return Whether the touchpad should use the right click zone.
+     *
+     * @hide
+     */
+    public boolean useTouchpadRightClickZone(@NonNull Context context) {
+        // TODO: obtain the actual behavior from the settings
+        return true;
+    }
+
+    /**
+     * Sets the right click zone behavior for the touchpad.
+     *
+     * The new behavior is only applied to gesture-compatible touchpads.
+     *
+     * @param context The application context.
+     * @param enabled Will enable the right click zone if true, disable it if false
+     *
+     * @hide
+     */
+    public void setTouchpadRightClickZone(@NonNull Context context, boolean enabled) {
+        // TODO: set the right setting
+    }
+
+    /**
      * A callback used to be notified about battery state changes for an input device. The
      * {@link #onBatteryStateChanged(int, long, BatteryState)} method will be called once after the
      * listener is successfully registered to provide the initial battery state of the device.
diff --git a/core/java/android/hardware/input/VirtualNavigationTouchpad.java b/core/java/android/hardware/input/VirtualNavigationTouchpad.java
new file mode 100644
index 0000000..2854034
--- /dev/null
+++ b/core/java/android/hardware/input/VirtualNavigationTouchpad.java
@@ -0,0 +1,60 @@
+/*
+ * 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 android.hardware.input;
+
+import android.annotation.NonNull;
+import android.annotation.RequiresPermission;
+import android.annotation.SystemApi;
+import android.companion.virtual.IVirtualDevice;
+import android.os.IBinder;
+import android.os.RemoteException;
+
+/**
+ * A virtual navigation touchpad representing a touch-based input mechanism on a remote device.
+ *
+ * <p>This registers an InputDevice that is interpreted like a physically-connected device and
+ * dispatches received events to it.
+ *
+ * <p>The virtual touchpad will be in navigation mode. Motion results in focus traversal in the same
+ * manner as D-Pad navigation if the events are not consumed.
+ *
+ * @see android.view.InputDevice#SOURCE_TOUCH_NAVIGATION
+ *
+ * @hide
+ */
+@SystemApi
+public class VirtualNavigationTouchpad extends VirtualInputDevice {
+
+    /** @hide */
+    public VirtualNavigationTouchpad(IVirtualDevice virtualDevice, IBinder token) {
+        super(virtualDevice, token);
+    }
+
+    /**
+     * Sends a touch event to the system.
+     *
+     * @param event the event to send
+     */
+    @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE)
+    public void sendTouchEvent(@NonNull VirtualTouchEvent event) {
+        try {
+            mVirtualDevice.sendTouchEvent(mToken, event);
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+    }
+}
diff --git a/services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt b/core/java/android/hardware/input/VirtualNavigationTouchpadConfig.aidl
similarity index 71%
rename from services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt
rename to core/java/android/hardware/input/VirtualNavigationTouchpadConfig.aidl
index 528680e7..d912491 100644
--- a/services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt
+++ b/core/java/android/hardware/input/VirtualNavigationTouchpadConfig.aidl
@@ -14,11 +14,6 @@
  * limitations under the License.
  */
 
-package com.android.server.permission.access.external
+package android.hardware.input;
 
-class RoSystemProperties {
-    companion object {
-        const val CONTROL_PRIVAPP_PERMISSIONS_DISABLE = false
-        const val CONTROL_PRIVAPP_PERMISSIONS_ENFORCE = false
-    }
-}
+parcelable VirtualNavigationTouchpadConfig;
diff --git a/core/java/android/hardware/input/VirtualNavigationTouchpadConfig.java b/core/java/android/hardware/input/VirtualNavigationTouchpadConfig.java
new file mode 100644
index 0000000..f2805bb
--- /dev/null
+++ b/core/java/android/hardware/input/VirtualNavigationTouchpadConfig.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 android.hardware.input;
+
+import android.annotation.IntRange;
+import android.annotation.NonNull;
+import android.annotation.SystemApi;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * Configurations to create virtual navigation touchpad.
+ *
+ * @hide
+ */
+@SystemApi
+public final class VirtualNavigationTouchpadConfig extends VirtualInputDeviceConfig
+        implements Parcelable {
+
+    /** The touchpad height. */
+    private final int mHeight;
+    /** The touchpad width. */
+    private final int mWidth;
+
+    private VirtualNavigationTouchpadConfig(@NonNull Builder builder) {
+        super(builder);
+        mHeight = builder.mHeight;
+        mWidth = builder.mWidth;
+    }
+
+    private VirtualNavigationTouchpadConfig(@NonNull Parcel in) {
+        super(in);
+        mHeight = in.readInt();
+        mWidth = in.readInt();
+    }
+
+    /** Returns the touchpad height. */
+    public int getHeight() {
+        return mHeight;
+    }
+
+    /** Returns the touchpad width. */
+    public int getWidth() {
+        return mWidth;
+    }
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public void writeToParcel(@NonNull Parcel dest, int flags) {
+        super.writeToParcel(dest, flags);
+        dest.writeInt(mHeight);
+        dest.writeInt(mWidth);
+    }
+
+    @NonNull
+    public static final Creator<VirtualNavigationTouchpadConfig> CREATOR =
+            new Creator<VirtualNavigationTouchpadConfig>() {
+                @Override
+                public VirtualNavigationTouchpadConfig createFromParcel(Parcel in) {
+                    return new VirtualNavigationTouchpadConfig(in);
+                }
+
+                @Override
+                public VirtualNavigationTouchpadConfig[] newArray(int size) {
+                    return new VirtualNavigationTouchpadConfig[size];
+                }
+            };
+
+    /**
+     * Builder for creating a {@link VirtualNavigationTouchpadConfig}.
+     */
+    public static final class Builder extends VirtualInputDeviceConfig.Builder<Builder> {
+
+        private final int mHeight;
+        private final int mWidth;
+
+        public Builder(@IntRange(from = 1) int touchpadHeight,
+                @IntRange(from = 1) int touchpadWidth) {
+            if (touchpadHeight <= 0 || touchpadWidth <= 0) {
+                throw new IllegalArgumentException(
+                        "Cannot create a virtual navigation touchpad, touchpad dimensions must be "
+                                + "positive. Got: (" + touchpadHeight + ", "
+                                + touchpadWidth + ")");
+            }
+            mHeight = touchpadHeight;
+            mWidth = touchpadWidth;
+        }
+
+        /**
+         * Builds the {@link VirtualNavigationTouchpadConfig} instance.
+         */
+        @NonNull
+        public VirtualNavigationTouchpadConfig build() {
+            return new VirtualNavigationTouchpadConfig(this);
+        }
+    }
+}
diff --git a/core/java/android/hardware/radio/IRadioService.aidl b/core/java/android/hardware/radio/IRadioService.aidl
index 9349cf7..c7131a7 100644
--- a/core/java/android/hardware/radio/IRadioService.aidl
+++ b/core/java/android/hardware/radio/IRadioService.aidl
@@ -31,7 +31,7 @@
     List<RadioManager.ModuleProperties> listModules();
 
     ITuner openTuner(int moduleId, in RadioManager.BandConfig bandConfig, boolean withAudio,
-            in ITunerCallback callback);
+            in ITunerCallback callback, int targetSdkVersion);
 
     ICloseHandle addAnnouncementListener(in int[] enabledTypes,
             in IAnnouncementListener listener);
diff --git a/core/java/android/hardware/radio/ITuner.aidl b/core/java/android/hardware/radio/ITuner.aidl
index 7bf234b..e68c3cc 100644
--- a/core/java/android/hardware/radio/ITuner.aidl
+++ b/core/java/android/hardware/radio/ITuner.aidl
@@ -49,7 +49,7 @@
     /**
      * @throws IllegalStateException if called out of sequence
      */
-    void scan(boolean directionDown, boolean skipSubChannel);
+    void seek(boolean directionDown, boolean skipSubChannel);
 
     /**
      * @throws IllegalArgumentException if invalid arguments are passed
diff --git a/core/java/android/hardware/radio/ITunerCallback.aidl b/core/java/android/hardware/radio/ITunerCallback.aidl
index f98947b..13092cc 100644
--- a/core/java/android/hardware/radio/ITunerCallback.aidl
+++ b/core/java/android/hardware/radio/ITunerCallback.aidl
@@ -24,6 +24,13 @@
 /** {@hide} */
 oneway interface ITunerCallback {
     void onError(int status);
+
+    /**
+     * Callback called when tuning operations, such as tune, step, seek, failed.
+     *
+     * @param result Tuning result of {@link RadioTuner#TunerResultType} type.
+     * @param selector Program selector used for the tuning operation.
+     */
     void onTuneFailed(int result, in ProgramSelector selector);
     void onConfigurationChanged(in RadioManager.BandConfig config);
     void onCurrentProgramInfoChanged(in RadioManager.ProgramInfo info);
@@ -36,6 +43,18 @@
     void onProgramListUpdated(in ProgramList.Chunk chunk);
 
     /**
+     * Callback for passing updates to config flags from {@link IRadioService} to
+     * {@link RadioTuner}.
+     *
+     * @param flag Config flag (defined in {@link RadioManager.ConfigFlag}) updated
+     * @param value Updated value for the config flag
+     */
+    void onConfigFlagUpdated(int flag, boolean value);
+
+    /**
+     * Callback for passing updates to vendor-specific parameter values from
+     * {@link IRadioService} to {@link RadioTuner}.
+     *
      * @param parameters Vendor-specific key-value pairs
      */
     void onParametersUpdated(in Map<String, String> parameters);
diff --git a/core/java/android/hardware/radio/ProgramSelector.java b/core/java/android/hardware/radio/ProgramSelector.java
index 8a92135..7faa285 100644
--- a/core/java/android/hardware/radio/ProgramSelector.java
+++ b/core/java/android/hardware/radio/ProgramSelector.java
@@ -167,7 +167,10 @@
     public static final int IDENTIFIER_TYPE_HD_STATION_NAME = 10004;
     /**
      * @see {@link IDENTIFIER_TYPE_DAB_SID_EXT}
+     *
+     * @deprecated use {@link #IDENTIFIER_TYPE_DAB_DMB_SID_EXT} instead
      */
+    @Deprecated
     public static final int IDENTIFIER_TYPE_DAB_SIDECC = 5;
     /**
      * 28bit compound primary identifier for Digital Audio Broadcasting.
@@ -183,7 +186,10 @@
      *
      * The remaining bits should be set to zeros when writing on the chip side
      * and ignored when read.
+     *
+     * @deprecated use {@link #IDENTIFIER_TYPE_DAB_DMB_SID_EXT} instead
      */
+    @Deprecated
     public static final int IDENTIFIER_TYPE_DAB_SID_EXT = IDENTIFIER_TYPE_DAB_SIDECC;
     /** 16bit */
     public static final int IDENTIFIER_TYPE_DAB_ENSEMBLE = 6;
@@ -197,7 +203,7 @@
     public static final int IDENTIFIER_TYPE_DRMO_FREQUENCY = 10;
     /**
      * 1: AM, 2:FM
-     * @deprecated use {@link IDENTIFIER_TYPE_DRMO_FREQUENCY} instead
+     * @deprecated use {@link #IDENTIFIER_TYPE_DRMO_FREQUENCY} instead
      */
     @Deprecated
     public static final int IDENTIFIER_TYPE_DRMO_MODULATION = 11;
@@ -206,6 +212,23 @@
     /** 0-999 range */
     public static final int IDENTIFIER_TYPE_SXM_CHANNEL = 13;
     /**
+     * 44bit compound primary identifier for Digital Audio Broadcasting and
+     * Digital Multimedia Broadcasting.
+     *
+     * <p>Consists of (from the LSB):
+     * - 32bit: SId;
+     * - 8bit: ECC code;
+     * - 4bit: SCIdS.
+     *
+     * <p>SCIdS (Service Component Identifier within the Service) value
+     * of 0 represents the main service, while 1 and above represents
+     * secondary services.
+     *
+     * The remaining bits should be set to zeros when writing on the chip side
+     * and ignored when read.
+     */
+    public static final int IDENTIFIER_TYPE_DAB_DMB_SID_EXT = 14;
+    /**
      * Primary identifier for vendor-specific radio technology.
      * The value format is determined by a vendor.
      *
@@ -219,12 +242,12 @@
      */
     public static final int IDENTIFIER_TYPE_VENDOR_END = PROGRAM_TYPE_VENDOR_END;
     /**
-     * @deprecated use {@link IDENTIFIER_TYPE_VENDOR_START} instead
+     * @deprecated use {@link #IDENTIFIER_TYPE_VENDOR_START} instead
      */
     @Deprecated
     public static final int IDENTIFIER_TYPE_VENDOR_PRIMARY_START = IDENTIFIER_TYPE_VENDOR_START;
     /**
-     * @deprecated use {@link IDENTIFIER_TYPE_VENDOR_END} instead
+     * @deprecated use {@link #IDENTIFIER_TYPE_VENDOR_END} instead
      */
     @Deprecated
     public static final int IDENTIFIER_TYPE_VENDOR_PRIMARY_END = IDENTIFIER_TYPE_VENDOR_END;
@@ -245,6 +268,7 @@
         IDENTIFIER_TYPE_DRMO_MODULATION,
         IDENTIFIER_TYPE_SXM_SERVICE_ID,
         IDENTIFIER_TYPE_SXM_CHANNEL,
+        IDENTIFIER_TYPE_DAB_DMB_SID_EXT,
     })
     @IntRange(from = IDENTIFIER_TYPE_VENDOR_START, to = IDENTIFIER_TYPE_VENDOR_END)
     @Retention(RetentionPolicy.SOURCE)
@@ -285,7 +309,7 @@
      * Type of a radio technology.
      *
      * @return program type.
-     * @deprecated use {@link getPrimaryId} instead
+     * @deprecated use {@link #getPrimaryId} instead
      */
     @Deprecated
     public @ProgramType int getProgramType() {
diff --git a/core/java/android/hardware/radio/RadioManager.java b/core/java/android/hardware/radio/RadioManager.java
index 9a217f9..f072e3b 100644
--- a/core/java/android/hardware/radio/RadioManager.java
+++ b/core/java/android/hardware/radio/RadioManager.java
@@ -82,6 +82,24 @@
     /** Method return status: time out before operation completion */
     public static final int STATUS_TIMED_OUT = -110;
 
+    /**
+     *  Radio operation status types
+     *
+     * @hide
+     */
+    @IntDef(prefix = { "STATUS_" }, value = {
+            STATUS_OK,
+            STATUS_ERROR,
+            STATUS_PERMISSION_DENIED,
+            STATUS_NO_INIT,
+            STATUS_BAD_VALUE,
+            STATUS_DEAD_OBJECT,
+            STATUS_INVALID_OPERATION,
+            STATUS_TIMED_OUT,
+    })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface RadioStatusType{}
+
 
     // keep in sync with radio_class_t in /system/core/incluse/system/radio.h
     /** Radio module class supporting FM (including HD radio) and AM */
@@ -330,6 +348,7 @@
          * program list.
          * @return the number of audio sources available.
          */
+        @RadioStatusType
         public int getNumAudioSources() {
             return mNumAudioSources;
         }
@@ -1724,6 +1743,7 @@
      * </ul>
      */
     @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
+    @RadioStatusType
     public int listModules(List<ModuleProperties> modules) {
         if (modules == null) {
             Log.e(TAG, "the output list must not be empty");
@@ -1776,7 +1796,7 @@
         ITuner tuner;
         TunerCallbackAdapter halCallback = new TunerCallbackAdapter(callback, handler);
         try {
-            tuner = mService.openTuner(moduleId, config, withAudio, halCallback);
+            tuner = mService.openTuner(moduleId, config, withAudio, halCallback, mTargetSdkVersion);
         } catch (RemoteException | IllegalArgumentException | IllegalStateException ex) {
             Log.e(TAG, "Failed to open tuner", ex);
             return null;
@@ -1853,6 +1873,7 @@
 
     @NonNull private final Context mContext;
     @NonNull private final IRadioService mService;
+    private final int mTargetSdkVersion;
 
     /**
      * @hide
@@ -1869,5 +1890,6 @@
     public RadioManager(Context context, IRadioService service) {
         mContext = context;
         mService = service;
+        mTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion;
     }
 }
diff --git a/core/java/android/hardware/radio/RadioTuner.java b/core/java/android/hardware/radio/RadioTuner.java
index 969db96..9b2bcde 100644
--- a/core/java/android/hardware/radio/RadioTuner.java
+++ b/core/java/android/hardware/radio/RadioTuner.java
@@ -16,14 +16,20 @@
 
 package android.hardware.radio;
 
+import android.Manifest;
+import android.annotation.IntDef;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
+import android.annotation.RequiresPermission;
 import android.annotation.SystemApi;
 import android.graphics.Bitmap;
 import android.os.Handler;
 
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.Executor;
 
 /**
  * RadioTuner interface provides methods to control a radio tuner on the device: selecting and
@@ -43,16 +49,21 @@
     public static final int DIRECTION_DOWN    = 1;
 
     /**
-     * Close the tuner interface. The {@link Callback} callback will not be called
-     * anymore and associated resources will be released.
-     * Must be called when the tuner is not needed to make hardware resources available to others.
+     * Close the tuner interface.
+     *
+     * <p>The {@link Callback} callback will not be called anymore and associated resources will be
+     * released. Must be called when the tuner is not needed to make hardware resources available
+     * to others.
      * */
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
     public abstract void close();
 
     /**
      * Set the active band configuration for this module.
-     * Must be a valid configuration obtained via buildConfig() from a valid BandDescriptor listed
-     * in the ModuleProperties of the module with the specified ID.
+     *
+     * <p>Must be a valid configuration obtained via buildConfig() from a valid BandDescriptor
+     * listed in the ModuleProperties of the module with the specified ID.
+     *
      * @param config The desired band configuration (FmBandConfig or AmBandConfig).
      * @return
      * <ul>
@@ -67,10 +78,13 @@
      * @deprecated Only applicable for HAL 1.x.
      */
     @Deprecated
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
+    @RadioManager.RadioStatusType
     public abstract int setConfiguration(RadioManager.BandConfig config);
 
     /**
      * Get current configuration.
+     *
      * @param config a BandConfig array of lengh 1 where the configuration is returned.
      * @return
      * <ul>
@@ -86,11 +100,15 @@
      * @deprecated Only applicable for HAL 1.x.
      */
     @Deprecated
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
+    @RadioManager.RadioStatusType
     public abstract int getConfiguration(RadioManager.BandConfig[] config);
 
 
     /**
-     * Set mute state. When muted, the radio tuner audio source is not available for playback on
+     * Set mute state.
+     *
+     * <p>When muted, the radio tuner audio source is not available for playback on
      * any audio device. when unmuted, the radio tuner audio source is output as a media source
      * and renderd over the audio device selected for media use case.
      * The radio tuner audio source is muted by default when the tuner is first attached.
@@ -107,6 +125,8 @@
      *  service fails, </li>
      * </ul>
      */
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
+    @RadioManager.RadioStatusType
     public abstract int setMute(boolean mute);
 
     /**
@@ -115,13 +135,19 @@
      * @return {@code true} if the radio tuner audio source is muted or a problem occured
      * retrieving the mute state, {@code false} otherwise.
      */
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
     public abstract boolean getMute();
 
     /**
      * Step up or down by one channel spacing.
-     * The operation is asynchronous and {@link Callback}
-     * onProgramInfoChanged() will be called when step completes or
-     * onError() when cancelled or timeout.
+     *
+     * <p>The operation is asynchronous and {@link Callback#onProgramInfoChanged}
+     * will be called when step completes or {@link Callback#onTuneFailed}
+     * when timeout or canceled.
+     *
+     * <p>When this operation is called by users other than current user or system user, it is
+     * ignored silently.
+     *
      * @param direction {@link #DIRECTION_UP} or {@link #DIRECTION_DOWN}.
      * @param skipSubChannel indicates to skip sub channels when the configuration currently
      * selected supports sub channel (e.g HD Radio). N/A otherwise.
@@ -136,13 +162,50 @@
      *  service fails, </li>
      * </ul>
      */
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
+    @RadioManager.RadioStatusType
     public abstract int step(int direction, boolean skipSubChannel);
 
     /**
      * Scan up or down to next valid station.
-     * The operation is asynchronous and {@link Callback}
-     * onProgramInfoChanged() will be called when scan completes or
-     * onError() when cancelled or timeout.
+     *
+     * <p>The operation is asynchronous and {@link Callback#onProgramInfoChanged}
+     * will be called when scan completes or {@link Callback#onTuneFailed}
+     * when timeout or canceled.
+     *
+     * <p>When this operation is called by users other than current user or system user, it is
+     * ignored silently.
+     *
+     * @param direction {@link #DIRECTION_UP} or {@link #DIRECTION_DOWN}.
+     * @param skipSubChannel indicates to skip sub channels when the configuration currently
+     * selected supports sub channel (e.g HD Radio). N/A otherwise.
+     * @return
+     * <ul>
+     *  <li>{@link RadioManager#STATUS_OK} in case of success, </li>
+     *  <li>{@link RadioManager#STATUS_ERROR} in case of unspecified error, </li>
+     *  <li>{@link RadioManager#STATUS_NO_INIT} if the native service cannot be reached, </li>
+     *  <li>{@link RadioManager#STATUS_BAD_VALUE} if parameters are invalid, </li>
+     *  <li>{@link RadioManager#STATUS_INVALID_OPERATION} if the call is out of sequence, </li>
+     *  <li>{@link RadioManager#STATUS_DEAD_OBJECT} if the binder transaction to the native
+     *  service fails, </li>
+     * </ul>
+     * @deprecated Use {@link #seek(int, boolean)} instead.
+     */
+    @Deprecated
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
+    @RadioManager.RadioStatusType
+    public abstract int scan(int direction, boolean skipSubChannel);
+
+    /**
+     * Seek up or down to next valid station.
+     *
+     * <p>The operation is asynchronous and {@link Callback#onProgramInfoChanged}
+     * will be called when seek completes or {@link Callback#onTuneFailed}
+     * when timeout or canceled.
+     *
+     * <p>When this operation is called by users other than current user or system user, it is
+     * ignore silently.
+     *
      * @param direction {@link #DIRECTION_UP} or {@link #DIRECTION_DOWN}.
      * @param skipSubChannel indicates to skip sub channels when the configuration currently
      * selected supports sub channel (e.g HD Radio). N/A otherwise.
@@ -157,13 +220,22 @@
      *  service fails, </li>
      * </ul>
      */
-    public abstract int scan(int direction, boolean skipSubChannel);
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
+    @RadioManager.RadioStatusType
+    public int seek(int direction, boolean skipSubChannel) {
+        throw new UnsupportedOperationException("Seeking is not supported");
+    }
 
     /**
      * Tune to a specific frequency.
-     * The operation is asynchronous and {@link Callback}
-     * onProgramInfoChanged() will be called when tune completes or
-     * onError() when cancelled or timeout.
+     *
+     * <p>The operation is asynchronous and {@link Callback#onProgramInfoChanged}
+     * will be called when tune completes or {@link Callback#onTuneFailed}
+     * when timeout or canceled.
+     *
+     * <p>When this operation is called by users other than current user or system user, it is
+     * ignored silently.
+     *
      * @param channel the specific channel or frequency to tune to.
      * @param subChannel the specific sub-channel to tune to. N/A if the selected configuration
      * does not support cub channels.
@@ -177,25 +249,37 @@
      *  <li>{@link RadioManager#STATUS_DEAD_OBJECT} if the binder transaction to the native
      *  service fails, </li>
      * </ul>
-     * @deprecated Use {@link tune(ProgramSelector)} instead.
+     * @deprecated Use {@link #tune(ProgramSelector)} instead.
      */
     @Deprecated
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
+    @RadioManager.RadioStatusType
     public abstract int tune(int channel, int subChannel);
 
     /**
      * Tune to a program.
      *
-     * The operation is asynchronous and {@link Callback} onProgramInfoChanged() will be called
-     * when tune completes or onError() when cancelled or on timeout.
+     * <p>The operation is asynchronous and {@link Callback#onProgramInfoChanged}
+     * will be called when tune completes or {@link Callback#onTuneFailed}
+     * when timeout or canceled.
+     *
+     * <p>When this operation is called by users other than current user or system user, it is
+     * ignored silently.
      *
      * @throws IllegalArgumentException if the provided selector is invalid
      */
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
     public abstract void tune(@NonNull ProgramSelector selector);
 
     /**
      * Cancel a pending scan or tune operation.
-     * If an operation is pending, {@link Callback} onError() will be called with
+     *
+     * <p>If an operation is pending, {@link Callback#onTuneFailed} will be called with
      * {@link #ERROR_CANCELLED}.
+     *
+     * <p>When this operation is called by users other than current user or system
+     * user, it is ignored silently.
+     *
      * @return
      * <ul>
      *  <li>{@link RadioManager#STATUS_OK} in case of success, </li>
@@ -207,21 +291,27 @@
      *  service fails, </li>
      * </ul>
      */
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
+    @RadioManager.RadioStatusType
     public abstract int cancel();
 
     /**
      * Cancels traffic or emergency announcement.
      *
-     * If there was no announcement to cancel, no action is taken.
+     * <p>If there was no announcement to cancel, no action is taken.
      *
-     * There is a race condition between calling cancelAnnouncement and the actual announcement
+     * <p>There is a race condition between calling cancelAnnouncement and the actual announcement
      * being finished, so onTrafficAnnouncement / onEmergencyAnnouncement callback should be
      * tracked with proper locking.
+     * @deprecated Only applicable for HAL 1.x.
      */
+    @Deprecated
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
     public abstract void cancelAnnouncement();
 
     /**
      * Get current station information.
+     *
      * @param info a ProgramInfo array of lengh 1 where the information is returned.
      * @return
      * <ul>
@@ -233,23 +323,27 @@
      *  <li>{@link RadioManager#STATUS_DEAD_OBJECT} if the binder transaction to the native
      *  service fails, </li>
      * </ul>
-     * @deprecated Use {@link onProgramInfoChanged} callback instead.
+     * @deprecated Use {@link Callback#onProgramInfoChanged(RadioManager.ProgramInfo)} callback
+     * instead.
      */
     @Deprecated
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
+    @RadioManager.RadioStatusType
     public abstract int getProgramInformation(RadioManager.ProgramInfo[] info);
 
     /**
      * Retrieves a {@link Bitmap} for the given image ID or null,
      * if the image was missing from the tuner.
      *
-     * This involves doing a call to the tuner, so the bitmap should be cached
+     * <p>This involves doing a call to the tuner, so the bitmap should be cached
      * on the application side.
      *
-     * If the method returns null for non-zero ID, it means the image was
+     * <p>If the method returns null for non-zero ID, it means the image was
      * updated on the tuner side. There is a race conditon between fetching
      * image for an old ID and tuner updating the image (and cleaning up the
      * old image). In such case, a new ProgramInfo with updated image id will
-     * be sent with a {@link onProgramInfoChanged} callback.
+     * be sent with a {@link Callback#onProgramInfoChanged(RadioManager.ProgramInfo)}
+     * callback.
      *
      * @param id The image identifier, retrieved with
      *           {@link RadioMetadata#getBitmapId(String)}.
@@ -258,14 +352,16 @@
      * @hide This API is not thoroughly elaborated yet
      */
     @SuppressWarnings("HiddenAbstractMethod")
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
     public abstract @Nullable Bitmap getMetadataImage(int id);
 
     /**
      * Initiates a background scan to update internally cached program list.
      *
-     * It may not be necessary to initiate the scan explicitly - the scan MAY be performed on boot.
+     * <p>It may not be necessary to initiate the scan explicitly - the scan MAY be performed on
+     * boot.
      *
-     * The operation is asynchronous and {@link Callback} backgroundScanComplete or onError will
+     * <p>The operation is asynchronous and {@link Callback} backgroundScanComplete or onError will
      * be called if the return value of this call was {@code true}. As result of this call
      * programListChanged may be triggered (if the scanned list differs).
      *
@@ -273,13 +369,16 @@
      * is unavailable; ie. temporarily due to ongoing foreground playback in single-tuner device
      * or permanently if the feature is not supported
      * (see ModuleProperties#isBackgroundScanningSupported()).
+     * @deprecated Only applicable for HAL 1.x.
      */
+    @Deprecated
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
     public abstract boolean startBackgroundScan();
 
     /**
      * Get the list of discovered radio stations.
      *
-     * To get the full list, set filter to null or empty map.
+     * <p>To get the full list, set filter to null or empty map.
      * Keys must be prefixed with unique vendor Java-style namespace,
      * eg. 'com.somecompany.parameter1'.
      *
@@ -288,24 +387,27 @@
      * @throws IllegalStateException if the scan is in progress or has not been started,
      *         startBackgroundScan() call may fix it.
      * @throws IllegalArgumentException if the vendorFilter argument is not valid.
-     * @deprecated Use {@link getDynamicProgramList} instead.
+     * @deprecated Use {@link #getDynamicProgramList(ProgramList.Filter)} instead.
      */
     @Deprecated
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
     public abstract @NonNull List<RadioManager.ProgramInfo>
             getProgramList(@Nullable Map<String, String> vendorFilter);
 
     /**
      * Get the dynamic list of discovered radio stations.
      *
-     * The list object is updated asynchronously; to get the updates register
-     * with {@link ProgramList#addListCallback}.
+     * <p>The list object is updated asynchronously; to get the updates register
+     * with {@link ProgramList#registerListCallback(ProgramList.ListCallback)}
+     * or {@link ProgramList#registerListCallback(Executor, ProgramList.ListCallback)}.
      *
-     * When the returned object is no longer used, it must be closed.
+     * <p>When the returned object is no longer used, it must be closed.
      *
      * @param filter filter for the list, or null to get the full list.
      * @return the dynamic program list object, close it after use
      *         or {@code null} if program list is not supported by the tuner
      */
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
     public @Nullable ProgramList getDynamicProgramList(@Nullable ProgramList.Filter filter) {
         return null;
     }
@@ -316,26 +418,28 @@
      * @throws IllegalStateException if the switch is not supported at current
      *         configuration.
      * @return {@code true} if analog is forced, {@code false} otherwise.
-     * @deprecated Use {@link isConfigFlagSet(int)} instead.
+     * @deprecated Use {@link #isConfigFlagSet(int)} instead.
      */
     @Deprecated
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
     public abstract boolean isAnalogForced();
 
     /**
      * Forces the analog playback for the supporting radio technology.
      *
-     * User may disable digital playback for FM HD Radio or hybrid FM/DAB with
+     * <p>User may disable digital playback for FM HD Radio or hybrid FM/DAB with
      * this option. This is purely user choice, ie. does not reflect digital-
      * analog handover managed from the HAL implementation side.
      *
-     * Some radio technologies may not support this, ie. DAB.
+     * <p>Some radio technologies may not support this, ie. DAB.
      *
      * @param isForced {@code true} to force analog, {@code false} for a default behaviour.
      * @throws IllegalStateException if the switch is not supported at current
      *         configuration.
-     * @deprecated Use {@link setConfigFlag(int, boolean)} instead.
+     * @deprecated Use {@link #setConfigFlag(int, boolean)}  instead.
      */
     @Deprecated
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
     public abstract void setAnalogForced(boolean isForced);
 
     /**
@@ -344,6 +448,7 @@
      * @param flag Flag to check.
      * @return True, if the flag is supported.
      */
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
     public boolean isConfigFlagSupported(@RadioManager.ConfigFlag int flag) {
         return false;
     }
@@ -351,29 +456,34 @@
     /**
      * Fetches the current setting of a given config flag.
      *
-     * The success/failure result is consistent with isConfigFlagSupported.
+     * <p>The success/failure result is consistent with isConfigFlagSupported.
      *
      * @param flag Flag to fetch.
      * @return The current value of the flag.
      * @throws IllegalStateException if the flag is not applicable right now.
      * @throws UnsupportedOperationException if the flag is not supported at all.
      */
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
     public boolean isConfigFlagSet(@RadioManager.ConfigFlag int flag) {
-        throw new UnsupportedOperationException();
+        throw new UnsupportedOperationException("isConfigFlagSet is not supported");
     }
 
     /**
      * Sets the config flag.
      *
-     * The success/failure result is consistent with isConfigFlagSupported.
+     * <p>The success/failure result is consistent with isConfigFlagSupported.
+     *
+     * <p>When this operation is called by users other than current user or system user,
+     * it is ignored silently.
      *
      * @param flag Flag to set.
      * @param value The new value of a given flag.
      * @throws IllegalStateException if the flag is not applicable right now.
      * @throws UnsupportedOperationException if the flag is not supported at all.
      */
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
     public void setConfigFlag(@RadioManager.ConfigFlag int flag, boolean value) {
-        throw new UnsupportedOperationException();
+        throw new UnsupportedOperationException("Setting config flag is not supported");
     }
 
     /**
@@ -381,30 +491,37 @@
      * The framework does not interpret the parameters, they are passed
      * in an opaque manner between a vendor application and HAL.
      *
-     * Framework does not make any assumptions on the keys or values, other than
+     * <p>Framework does not make any assumptions on the keys or values, other than
      * ones stated in VendorKeyValue documentation (a requirement of key
      * prefixes).
-     * See VendorKeyValue at hardware/interfaces/broadcastradio/2.0/types.hal.
+     * See VendorKeyValue at hardware/interfaces/broadcastradio/2.0/types.hal for
+     * HIDL 2.0 HAL or
+     * hardware/interfaces/broadcastradio/aidl/android/hardware/broadcastradio/VendorKeyValue.aidl
+     * for AIDL HAL.
      *
-     * For each pair in the result map, the key will be one of the keys
+     * <p>For each pair in the result map, the key will be one of the keys
      * contained in the input (possibly with wildcards expanded), and the value
      * will be a vendor-specific result status (such as "OK" or an error code).
      * The implementation may choose to return an empty map, or only return
      * a status for a subset of the provided inputs, at its discretion.
      *
-     * Application and HAL must not use keys with unknown prefix. In particular,
+     * <p>Application and HAL must not use keys with unknown prefix. In particular,
      * it must not place a key-value pair in results vector for unknown key from
      * parameters vector - instead, an unknown key should simply be ignored.
      * In other words, results vector may contain a subset of parameter keys
      * (however, the framework doesn't enforce a strict subset - the only
      * formal requirement is vendor domain prefix for keys).
      *
+     * <p>When this operation is called by users other than current user or system user,
+     * it is ignored silently.
+     *
      * @param parameters Vendor-specific key-value pairs.
      * @return Operation completion status for parameters being set.
      */
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
     public @NonNull Map<String, String>
             setParameters(@NonNull Map<String, String> parameters) {
-        throw new UnsupportedOperationException();
+        throw new UnsupportedOperationException("Setting parameters is not supported");
     }
 
     /**
@@ -412,23 +529,24 @@
      * The framework does not interpret the parameters, they are passed
      * in an opaque manner between a vendor application and HAL.
      *
-     * Framework does not cache set/get requests, so it's possible for
+     * <p>Framework does not cache set/get requests, so it's possible for
      * getParameter to return a different value than previous setParameter call.
      *
-     * The syntax and semantics of keys are up to the vendor (as long as prefix
+     * <p>The syntax and semantics of keys are up to the vendor (as long as prefix
      * rules are obeyed). For instance, vendors may include some form of
      * wildcard support. In such case, result vector may be of different size
      * than requested keys vector. However, wildcards are not recognized by
      * framework and they are passed as-is to the HAL implementation.
      *
-     * Unknown keys must be ignored and not placed into results vector.
+     * <p>Unknown keys must be ignored and not placed into results vector.
      *
      * @param keys Parameter keys to fetch.
      * @return Vendor-specific key-value pairs.
      */
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
     public @NonNull Map<String, String>
             getParameters(@NonNull List<String> keys) {
-        throw new UnsupportedOperationException();
+        throw new UnsupportedOperationException("Getting parameters is not supported");
     }
 
     /**
@@ -436,14 +554,16 @@
      * Only valid if a configuration has been applied.
      * @return {@code true} if the antenna is connected, {@code false} otherwise.
      *
-     * @deprecated Use {@link onAntennaState} callback instead
+     * @deprecated Use {@link Callback#onAntennaState(boolean)} callback instead
      */
     @Deprecated
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
     public abstract boolean isAntennaConnected();
 
     /**
      * Indicates if this client actually controls the tuner.
-     * Control is always granted after
+     *
+     * <p>Control is always granted after
      * {@link RadioManager#openTuner(int,
      * RadioManager.BandConfig, boolean, Callback, Handler)}
      * returns a non null tuner interface.
@@ -451,48 +571,102 @@
      * When this happens, {@link Callback#onControlChanged(boolean)} is received.
      * The client can either wait for control to be returned (which is indicated by the same
      * callback) or close and reopen the tuner interface.
+     *
      * @return {@code true} if this interface controls the tuner,
      * {@code false} otherwise or if a problem occured retrieving the state.
      */
+    @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
     public abstract boolean hasControl();
 
     /** Indicates a failure of radio IC or driver.
-     * The application must close and re open the tuner
-     * @deprecated See {@link onError} callback.
+     *
+     * <p>The application must close and re open the tuner
+     *
+     * @deprecated See {@link RadioTuner.Callback#onError(int)} callback.
      */
     @Deprecated
     public static final int ERROR_HARDWARE_FAILURE = 0;
     /** Indicates a failure of the radio service.
-     * The application must close and re open the tuner
-     * @deprecated See {@link onError} callback.
+     *
+     * <p>The application must close and re open the tuner
+     * @deprecated See {@link RadioTuner.Callback#onError(int)} callback.
      */
     @Deprecated
     public static final  int ERROR_SERVER_DIED = 1;
     /** A pending seek or tune operation was cancelled
-     * @deprecated See {@link onError} callback.
+     * @deprecated See {@link RadioTuner.Callback#onError(int)} callback.
      */
     @Deprecated
     public static final  int ERROR_CANCELLED = 2;
     /** A pending seek or tune operation timed out
-     * @deprecated See {@link onError} callback.
+     * @deprecated See {@link RadioTuner.Callback#onError(int)} callback.
      */
     @Deprecated
     public static final  int ERROR_SCAN_TIMEOUT = 3;
     /** The requested configuration could not be applied
-     * @deprecated See {@link onError} callback.
+     * @deprecated See {@link RadioTuner.Callback#onError(int)} callback.
      */
     @Deprecated
     public static final  int ERROR_CONFIG = 4;
     /** Background scan was interrupted due to hardware becoming temporarily unavailable.
-     * @deprecated See {@link onError} callback.
+     * @deprecated See {@link RadioTuner.Callback#onError(int)} callback.
      */
     @Deprecated
     public static final int ERROR_BACKGROUND_SCAN_UNAVAILABLE = 5;
     /** Background scan failed due to other error, ie. HW failure.
-     * @deprecated See {@link onError} callback.
+     * @deprecated See {@link RadioTuner.Callback#onError(int)} callback.
      */
     @Deprecated
     public static final int ERROR_BACKGROUND_SCAN_FAILED = 6;
+    /** Result when a tune, seek, or step operation runs without error.
+     */
+    public static final int TUNER_RESULT_OK = 0;
+    /** Result when internal error occurs in HAL.
+     * See {@link RadioTuner.Callback#onTuneFailed(int, ProgramSelector)} callback.
+     */
+    public static final int TUNER_RESULT_INTERNAL_ERROR = 1;
+    /** Result used when the input argument for the method is invalid.
+     * See {@link RadioTuner.Callback#onTuneFailed(int, ProgramSelector)} callback.
+     */
+    public static final int TUNER_RESULT_INVALID_ARGUMENTS = 2;
+    /** Result when HAL is of invalid state.
+     * See {@link RadioTuner.Callback#onTuneFailed(int, ProgramSelector)} callback.
+     */
+    public static final int TUNER_RESULT_INVALID_STATE = 3;
+    /** Result when the operation is not supported.
+     * See {@link RadioTuner.Callback#onTuneFailed(int, ProgramSelector)} callback.
+     */
+    public static final int TUNER_RESULT_NOT_SUPPORTED = 4;
+    /** Result when a tune, seek, or step operation is timeout
+     * See {@link RadioTuner.Callback#onTuneFailed(int, ProgramSelector)} callback.
+     */
+    public static final int TUNER_RESULT_TIMEOUT = 5;
+    /** Result when a tune, seek, or step operation is canceled before processed.
+     * See {@link RadioTuner.Callback#onTuneFailed(int, ProgramSelector)} callback.
+     */
+    public static final int TUNER_RESULT_CANCELED = 6;
+    /** Result when a tune, seek, or step operation fails due to unknown error.
+     * See {@link RadioTuner.Callback#onTuneFailed(int, ProgramSelector)} callback.
+     */
+    public static final int TUNER_RESULT_UNKNOWN_ERROR = 7;
+
+    /**
+     *  Tuning operation result types
+     *
+     * @hide
+     */
+    @IntDef(prefix = { "TUNER_RESULT_" }, value = {
+            TUNER_RESULT_OK,
+            TUNER_RESULT_INTERNAL_ERROR,
+            TUNER_RESULT_INVALID_ARGUMENTS,
+            TUNER_RESULT_INVALID_STATE,
+            TUNER_RESULT_NOT_SUPPORTED,
+            TUNER_RESULT_TIMEOUT,
+            TUNER_RESULT_CANCELED,
+            TUNER_RESULT_UNKNOWN_ERROR,
+    })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface TunerResultType{}
 
     /**
      * Callback provided by the client application when opening a {@link RadioTuner}
@@ -506,8 +680,9 @@
          * {@link #ERROR_CANCELLED}, {@link #ERROR_SCAN_TIMEOUT},
          * {@link #ERROR_CONFIG}
          *
-         * @deprecated Use {@link onTuneFailed} for tune, scan and step;
-         *             other use cases (configuration, background scan) are already deprecated.
+         * @deprecated Use {@link RadioTuner.Callback#onTuneFailed(int, ProgramSelector)} for
+         *             tune, scan and step; other use cases (configuration, background scan)
+         *             are already deprecated.
          */
         public void onError(int status) {}
 
@@ -518,7 +693,7 @@
          * @param selector ProgramSelector argument of tune that failed;
          *                 null for scan and step.
          */
-        public void onTuneFailed(int result, @Nullable ProgramSelector selector) {}
+        public void onTuneFailed(@TunerResultType int result, @Nullable ProgramSelector selector) {}
 
         /**
          * onConfigurationChanged() is called upon successful completion of
@@ -533,7 +708,7 @@
         /**
          * Called when program info (including metadata) for the current program has changed.
          *
-         * It happens either upon successful completion of {@link RadioTuner#step(int, boolean)},
+         * <p>It happens either upon successful completion of {@link RadioTuner#step(int, boolean)},
          * {@link RadioTuner#scan(int, boolean)}, {@link RadioTuner#tune(int, int)}; when
          * a switching to alternate frequency occurs; or when metadata is updated.
          */
@@ -589,16 +764,29 @@
         /**
          * Called when available program list changed.
          *
-         * Use {@link RadioTuner#getProgramList(String)} to get an actual list.
+         * Use {@link RadioTuner#getProgramList(Map)} to get an actual list.
          */
         public void onProgramListChanged() {}
 
         /**
+         * Called when config flags are updated asynchronously due to internal events
+         * in broadcast radio HAL.
+         *
+         * {@link RadioTuner#setConfigFlag(int, boolean)} must not trigger this
+         * callback.
+         *
+         * @param flag Config flag updated
+         * @param value Value of the updated config flag
+         */
+        public void onConfigFlagUpdated(@RadioManager.ConfigFlag int flag, boolean value) {}
+
+        /**
          * Generic callback for passing updates to vendor-specific parameter values.
-         * The framework does not interpret the parameters, they are passed
+         *
+         * <p>The framework does not interpret the parameters, they are passed
          * in an opaque manner between a vendor application and HAL.
          *
-         * It's up to the HAL implementation if and how to implement this callback,
+         * <p>It's up to the HAL implementation if and how to implement this callback,
          * as long as it obeys the prefix rule. In particular, only selected keys
          * may be notified this way. However, setParameters must not trigger
          * this callback, while an internal event can change parameters
diff --git a/core/java/android/hardware/radio/TunerAdapter.java b/core/java/android/hardware/radio/TunerAdapter.java
index 4a18333..bdbca91 100644
--- a/core/java/android/hardware/radio/TunerAdapter.java
+++ b/core/java/android/hardware/radio/TunerAdapter.java
@@ -154,7 +154,7 @@
     @Override
     public int scan(int direction, boolean skipSubChannel) {
         try {
-            mTuner.scan(/* directionDown= */ direction == RadioTuner.DIRECTION_DOWN,
+            mTuner.seek(/* directionDown= */ direction == RadioTuner.DIRECTION_DOWN,
                     skipSubChannel);
         } catch (IllegalStateException e) {
             Log.e(TAG, "Can't scan", e);
@@ -167,6 +167,21 @@
     }
 
     @Override
+    public int seek(int direction, boolean skipSubChannel) {
+        try {
+            mTuner.seek(/* directionDown= */ direction == RadioTuner.DIRECTION_DOWN,
+                    skipSubChannel);
+        } catch (IllegalStateException e) {
+            Log.e(TAG, "Can't seek", e);
+            return RadioManager.STATUS_INVALID_OPERATION;
+        } catch (RemoteException e) {
+            Log.e(TAG, "Service died", e);
+            return RadioManager.STATUS_DEAD_OBJECT;
+        }
+        return RadioManager.STATUS_OK;
+    }
+
+    @Override
     public int tune(int channel, int subChannel) {
         try {
             int band;
diff --git a/core/java/android/hardware/radio/TunerCallbackAdapter.java b/core/java/android/hardware/radio/TunerCallbackAdapter.java
index b9782a8..22f5902 100644
--- a/core/java/android/hardware/radio/TunerCallbackAdapter.java
+++ b/core/java/android/hardware/radio/TunerCallbackAdapter.java
@@ -246,6 +246,11 @@
     }
 
     @Override
+    public void onConfigFlagUpdated(@RadioManager.ConfigFlag int flag, boolean value) {
+        mHandler.post(() -> mCallback.onConfigFlagUpdated(flag, value));
+    }
+
+    @Override
     public void onParametersUpdated(Map<String, String> parameters) {
         mHandler.post(() -> mCallback.onParametersUpdated(parameters));
     }
diff --git a/core/java/android/net/vcn/VcnConfig.java b/core/java/android/net/vcn/VcnConfig.java
index fd3fe37..dcf0026 100644
--- a/core/java/android/net/vcn/VcnConfig.java
+++ b/core/java/android/net/vcn/VcnConfig.java
@@ -15,16 +15,23 @@
  */
 package android.net.vcn;
 
+import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
+import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
+
 import static com.android.internal.annotations.VisibleForTesting.Visibility;
+import static com.android.server.vcn.util.PersistableBundleUtils.INTEGER_DESERIALIZER;
+import static com.android.server.vcn.util.PersistableBundleUtils.INTEGER_SERIALIZER;
 
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.content.Context;
+import android.net.NetworkCapabilities;
 import android.net.NetworkRequest;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.os.PersistableBundle;
 import android.util.ArraySet;
+import android.util.Log;
 
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.util.Preconditions;
@@ -32,6 +39,7 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Iterator;
 import java.util.Objects;
 import java.util.Set;
 
@@ -46,22 +54,36 @@
 public final class VcnConfig implements Parcelable {
     @NonNull private static final String TAG = VcnConfig.class.getSimpleName();
 
+    private static final Set<Integer> ALLOWED_TRANSPORTS = new ArraySet<>();
+
+    static {
+        ALLOWED_TRANSPORTS.add(TRANSPORT_WIFI);
+        ALLOWED_TRANSPORTS.add(TRANSPORT_CELLULAR);
+    }
+
     private static final String PACKAGE_NAME_KEY = "mPackageName";
     @NonNull private final String mPackageName;
 
     private static final String GATEWAY_CONNECTION_CONFIGS_KEY = "mGatewayConnectionConfigs";
     @NonNull private final Set<VcnGatewayConnectionConfig> mGatewayConnectionConfigs;
 
+    private static final Set<Integer> RESTRICTED_TRANSPORTS_DEFAULT =
+            Collections.singleton(TRANSPORT_WIFI);
+    private static final String RESTRICTED_TRANSPORTS_KEY = "mRestrictedTransports";
+    @NonNull private final Set<Integer> mRestrictedTransports;
+
     private static final String IS_TEST_MODE_PROFILE_KEY = "mIsTestModeProfile";
     private final boolean mIsTestModeProfile;
 
     private VcnConfig(
             @NonNull String packageName,
             @NonNull Set<VcnGatewayConnectionConfig> gatewayConnectionConfigs,
+            @NonNull Set<Integer> restrictedTransports,
             boolean isTestModeProfile) {
         mPackageName = packageName;
         mGatewayConnectionConfigs =
                 Collections.unmodifiableSet(new ArraySet<>(gatewayConnectionConfigs));
+        mRestrictedTransports = Collections.unmodifiableSet(new ArraySet<>(restrictedTransports));
         mIsTestModeProfile = isTestModeProfile;
 
         validate();
@@ -82,6 +104,20 @@
                 new ArraySet<>(
                         PersistableBundleUtils.toList(
                                 gatewayConnectionConfigsBundle, VcnGatewayConnectionConfig::new));
+
+        final PersistableBundle restrictedTransportsBundle =
+                in.getPersistableBundle(RESTRICTED_TRANSPORTS_KEY);
+        if (restrictedTransportsBundle == null) {
+            // RESTRICTED_TRANSPORTS_KEY was added in U and does not exist in VcnConfigs created in
+            // older platforms
+            mRestrictedTransports = RESTRICTED_TRANSPORTS_DEFAULT;
+        } else {
+            mRestrictedTransports =
+                    new ArraySet<Integer>(
+                            PersistableBundleUtils.toList(
+                                    restrictedTransportsBundle, INTEGER_DESERIALIZER));
+        }
+
         mIsTestModeProfile = in.getBoolean(IS_TEST_MODE_PROFILE_KEY);
 
         validate();
@@ -91,6 +127,19 @@
         Objects.requireNonNull(mPackageName, "packageName was null");
         Preconditions.checkCollectionNotEmpty(
                 mGatewayConnectionConfigs, "gatewayConnectionConfigs was empty");
+
+        final Iterator<Integer> iterator = mRestrictedTransports.iterator();
+        while (iterator.hasNext()) {
+            final int transport = iterator.next();
+            if (!ALLOWED_TRANSPORTS.contains(transport)) {
+                iterator.remove();
+                Log.w(
+                        TAG,
+                        "Found invalid transport "
+                                + transport
+                                + " which might be from a new version of VcnConfig");
+            }
+        }
     }
 
     /**
@@ -110,6 +159,16 @@
     }
 
     /**
+     * Retrieve the transports that will be restricted by the VCN.
+     *
+     * @see Builder#setRestrictedUnderlyingNetworkTransports(Set)
+     */
+    @NonNull
+    public Set<Integer> getRestrictedUnderlyingNetworkTransports() {
+        return Collections.unmodifiableSet(mRestrictedTransports);
+    }
+
+    /**
      * Returns whether or not this VcnConfig is restricted to test networks.
      *
      * @hide
@@ -134,6 +193,12 @@
                         new ArrayList<>(mGatewayConnectionConfigs),
                         VcnGatewayConnectionConfig::toPersistableBundle);
         result.putPersistableBundle(GATEWAY_CONNECTION_CONFIGS_KEY, gatewayConnectionConfigsBundle);
+
+        final PersistableBundle restrictedTransportsBundle =
+                PersistableBundleUtils.fromList(
+                        new ArrayList<>(mRestrictedTransports), INTEGER_SERIALIZER);
+        result.putPersistableBundle(RESTRICTED_TRANSPORTS_KEY, restrictedTransportsBundle);
+
         result.putBoolean(IS_TEST_MODE_PROFILE_KEY, mIsTestModeProfile);
 
         return result;
@@ -141,7 +206,8 @@
 
     @Override
     public int hashCode() {
-        return Objects.hash(mPackageName, mGatewayConnectionConfigs, mIsTestModeProfile);
+        return Objects.hash(
+                mPackageName, mGatewayConnectionConfigs, mRestrictedTransports, mIsTestModeProfile);
     }
 
     @Override
@@ -153,6 +219,7 @@
         final VcnConfig rhs = (VcnConfig) other;
         return mPackageName.equals(rhs.mPackageName)
                 && mGatewayConnectionConfigs.equals(rhs.mGatewayConnectionConfigs)
+                && mRestrictedTransports.equals(rhs.mRestrictedTransports)
                 && mIsTestModeProfile == rhs.mIsTestModeProfile;
     }
 
@@ -189,12 +256,15 @@
         @NonNull
         private final Set<VcnGatewayConnectionConfig> mGatewayConnectionConfigs = new ArraySet<>();
 
+        @NonNull private final Set<Integer> mRestrictedTransports = new ArraySet<>();
+
         private boolean mIsTestModeProfile = false;
 
         public Builder(@NonNull Context context) {
             Objects.requireNonNull(context, "context was null");
 
             mPackageName = context.getOpPackageName();
+            mRestrictedTransports.addAll(RESTRICTED_TRANSPORTS_DEFAULT);
         }
 
         /**
@@ -225,6 +295,36 @@
             return this;
         }
 
+        private void validateRestrictedTransportsOrThrow(Set<Integer> restrictedTransports) {
+            Objects.requireNonNull(restrictedTransports, "transports was null");
+
+            for (int transport : restrictedTransports) {
+                if (!ALLOWED_TRANSPORTS.contains(transport)) {
+                    throw new IllegalArgumentException("Invalid transport " + transport);
+                }
+            }
+        }
+
+        /**
+         * Sets transports that will be restricted by the VCN.
+         *
+         * @param transports transports that will be restricted by VCN. Networks that include any
+         *     of the transports will be marked as restricted. Only {@link
+         *     NetworkCapabilities#TRANSPORT_WIFI} and {@link
+         *     NetworkCapabilities#TRANSPORT_CELLULAR} are allowed. {@link
+         *     NetworkCapabilities#TRANSPORT_WIFI} is marked restricted by default.
+         * @return this {@link Builder} instance, for chaining
+         * @throws IllegalArgumentException if the input contains unsupported transport types.
+         */
+        @NonNull
+        public Builder setRestrictedUnderlyingNetworkTransports(@NonNull Set<Integer> transports) {
+            validateRestrictedTransportsOrThrow(transports);
+
+            mRestrictedTransports.clear();
+            mRestrictedTransports.addAll(transports);
+            return this;
+        }
+
         /**
          * Restricts this VcnConfig to matching with test networks (only).
          *
@@ -248,7 +348,11 @@
          */
         @NonNull
         public VcnConfig build() {
-            return new VcnConfig(mPackageName, mGatewayConnectionConfigs, mIsTestModeProfile);
+            return new VcnConfig(
+                    mPackageName,
+                    mGatewayConnectionConfigs,
+                    mRestrictedTransports,
+                    mIsTestModeProfile);
         }
     }
 }
diff --git a/core/java/android/net/vcn/VcnGatewayConnectionConfig.java b/core/java/android/net/vcn/VcnGatewayConnectionConfig.java
index 2339656..b8850f4 100644
--- a/core/java/android/net/vcn/VcnGatewayConnectionConfig.java
+++ b/core/java/android/net/vcn/VcnGatewayConnectionConfig.java
@@ -42,6 +42,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Objects;
 import java.util.Set;
@@ -130,6 +131,30 @@
             })
     public @interface VcnSupportedCapability {}
 
+    /**
+     * Perform mobility update to attempt recovery from suspected data stalls.
+     *
+     * <p>If set, the gatway connection will monitor the data stall detection of the VCN network.
+     * When there is a suspected data stall, the gateway connection will attempt recovery by
+     * performing a mobility update on the underlying IKE session.
+     */
+    public static final int VCN_GATEWAY_OPTION_ENABLE_DATA_STALL_RECOVERY_WITH_MOBILITY = 0;
+
+    /** @hide */
+    @Retention(RetentionPolicy.SOURCE)
+    @IntDef(
+            prefix = {"VCN_GATEWAY_OPTION_"},
+            value = {
+                VCN_GATEWAY_OPTION_ENABLE_DATA_STALL_RECOVERY_WITH_MOBILITY,
+            })
+    public @interface VcnGatewayOption {}
+
+    private static final Set<Integer> ALLOWED_GATEWAY_OPTIONS = new ArraySet<>();
+
+    static {
+        ALLOWED_GATEWAY_OPTIONS.add(VCN_GATEWAY_OPTION_ENABLE_DATA_STALL_RECOVERY_WITH_MOBILITY);
+    }
+
     private static final int DEFAULT_MAX_MTU = 1500;
 
     /**
@@ -201,6 +226,9 @@
     private static final String RETRY_INTERVAL_MS_KEY = "mRetryIntervalsMs";
     @NonNull private final long[] mRetryIntervalsMs;
 
+    private static final String GATEWAY_OPTIONS_KEY = "mGatewayOptions";
+    @NonNull private final Set<Integer> mGatewayOptions;
+
     /** Builds a VcnGatewayConnectionConfig with the specified parameters. */
     private VcnGatewayConnectionConfig(
             @NonNull String gatewayConnectionName,
@@ -208,12 +236,14 @@
             @NonNull Set<Integer> exposedCapabilities,
             @NonNull List<VcnUnderlyingNetworkTemplate> underlyingNetworkTemplates,
             @NonNull long[] retryIntervalsMs,
-            @IntRange(from = MIN_MTU_V6) int maxMtu) {
+            @IntRange(from = MIN_MTU_V6) int maxMtu,
+            @NonNull Set<Integer> gatewayOptions) {
         mGatewayConnectionName = gatewayConnectionName;
         mTunnelConnectionParams = tunnelConnectionParams;
         mExposedCapabilities = new TreeSet(exposedCapabilities);
         mRetryIntervalsMs = retryIntervalsMs;
         mMaxMtu = maxMtu;
+        mGatewayOptions = Collections.unmodifiableSet(new HashSet(gatewayOptions));
 
         mUnderlyingNetworkTemplates = new ArrayList<>(underlyingNetworkTemplates);
         if (mUnderlyingNetworkTemplates.isEmpty()) {
@@ -256,6 +286,20 @@
                             VcnUnderlyingNetworkTemplate::fromPersistableBundle);
         }
 
+        final PersistableBundle gatewayOptionsBundle = in.getPersistableBundle(GATEWAY_OPTIONS_KEY);
+
+        if (gatewayOptionsBundle == null) {
+            // GATEWAY_OPTIONS_KEY was added in Android U. Thus VcnGatewayConnectionConfig created
+            // on old platforms will not have this data and will be assigned with the default value
+            mGatewayOptions = Collections.emptySet();
+        } else {
+            mGatewayOptions =
+                    new HashSet<>(
+                            PersistableBundleUtils.toList(
+                                    gatewayOptionsBundle,
+                                    PersistableBundleUtils.INTEGER_DESERIALIZER));
+        }
+
         mRetryIntervalsMs = in.getLongArray(RETRY_INTERVAL_MS_KEY);
         mMaxMtu = in.getInt(MAX_MTU_KEY);
 
@@ -279,6 +323,10 @@
 
         Preconditions.checkArgument(
                 mMaxMtu >= MIN_MTU_V6, "maxMtu must be at least IPv6 min MTU (1280)");
+
+        for (int option : mGatewayOptions) {
+            validateGatewayOption(option);
+        }
     }
 
     private static void checkValidCapability(int capability) {
@@ -315,6 +363,12 @@
         }
     }
 
+    private static void validateGatewayOption(int option) {
+        if (!ALLOWED_GATEWAY_OPTIONS.contains(option)) {
+            throw new IllegalArgumentException("Invalid vcn gateway option: " + option);
+        }
+    }
+
     /**
      * Returns the configured Gateway Connection name.
      *
@@ -399,6 +453,19 @@
     }
 
     /**
+     * Checks if the given VCN gateway option is enabled.
+     *
+     * @param option the option to check.
+     * @throws IllegalArgumentException if the provided option is invalid.
+     * @see Builder#addGatewayOption(int)
+     * @see Builder#removeGatewayOption(int)
+     */
+    public boolean hasGatewayOption(@VcnGatewayOption int option) {
+        validateGatewayOption(option);
+        return mGatewayOptions.contains(option);
+    }
+
+    /**
      * Converts this config to a PersistableBundle.
      *
      * @hide
@@ -418,11 +485,16 @@
                 PersistableBundleUtils.fromList(
                         mUnderlyingNetworkTemplates,
                         VcnUnderlyingNetworkTemplate::toPersistableBundle);
+        final PersistableBundle gatewayOptionsBundle =
+                PersistableBundleUtils.fromList(
+                        new ArrayList<>(mGatewayOptions),
+                        PersistableBundleUtils.INTEGER_SERIALIZER);
 
         result.putString(GATEWAY_CONNECTION_NAME_KEY, mGatewayConnectionName);
         result.putPersistableBundle(TUNNEL_CONNECTION_PARAMS_KEY, tunnelConnectionParamsBundle);
         result.putPersistableBundle(EXPOSED_CAPABILITIES_KEY, exposedCapsBundle);
         result.putPersistableBundle(UNDERLYING_NETWORK_TEMPLATES_KEY, networkTemplatesBundle);
+        result.putPersistableBundle(GATEWAY_OPTIONS_KEY, gatewayOptionsBundle);
         result.putLongArray(RETRY_INTERVAL_MS_KEY, mRetryIntervalsMs);
         result.putInt(MAX_MTU_KEY, mMaxMtu);
 
@@ -437,7 +509,8 @@
                 mExposedCapabilities,
                 mUnderlyingNetworkTemplates,
                 Arrays.hashCode(mRetryIntervalsMs),
-                mMaxMtu);
+                mMaxMtu,
+                mGatewayOptions);
     }
 
     @Override
@@ -452,7 +525,8 @@
                 && mExposedCapabilities.equals(rhs.mExposedCapabilities)
                 && mUnderlyingNetworkTemplates.equals(rhs.mUnderlyingNetworkTemplates)
                 && Arrays.equals(mRetryIntervalsMs, rhs.mRetryIntervalsMs)
-                && mMaxMtu == rhs.mMaxMtu;
+                && mMaxMtu == rhs.mMaxMtu
+                && mGatewayOptions.equals(rhs.mGatewayOptions);
     }
 
     /**
@@ -470,6 +544,8 @@
         @NonNull private long[] mRetryIntervalsMs = DEFAULT_RETRY_INTERVALS_MS;
         private int mMaxMtu = DEFAULT_MAX_MTU;
 
+        @NonNull private final Set<Integer> mGatewayOptions = new ArraySet<>();
+
         // TODO: (b/175829816) Consider VCN-exposed capabilities that may be transport dependent.
         //       Consider the case where the VCN might only expose MMS on WiFi, but defer to MMS
         //       when on Cell.
@@ -628,6 +704,34 @@
         }
 
         /**
+         * Enables the specified VCN gateway option.
+         *
+         * @param option the option to be enabled
+         * @return this {@link Builder} instance, for chaining
+         * @throws IllegalArgumentException if the provided option is invalid
+         */
+        @NonNull
+        public Builder addGatewayOption(@VcnGatewayOption int option) {
+            validateGatewayOption(option);
+            mGatewayOptions.add(option);
+            return this;
+        }
+
+        /**
+         * Resets (disables) the specified VCN gateway option.
+         *
+         * @param option the option to be disabled
+         * @return this {@link Builder} instance, for chaining
+         * @throws IllegalArgumentException if the provided option is invalid
+         */
+        @NonNull
+        public Builder removeGatewayOption(@VcnGatewayOption int option) {
+            validateGatewayOption(option);
+            mGatewayOptions.remove(option);
+            return this;
+        }
+
+        /**
          * Builds and validates the VcnGatewayConnectionConfig.
          *
          * @return an immutable VcnGatewayConnectionConfig instance
@@ -640,7 +744,8 @@
                     mExposedCapabilities,
                     mUnderlyingNetworkTemplates,
                     mRetryIntervalsMs,
-                    mMaxMtu);
+                    mMaxMtu,
+                    mGatewayOptions);
         }
     }
 }
diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java
index f545c30..0c7f529 100644
--- a/core/java/android/nfc/NfcAdapter.java
+++ b/core/java/android/nfc/NfcAdapter.java
@@ -30,6 +30,7 @@
 import android.compat.annotation.UnsupportedAppUsage;
 import android.content.Context;
 import android.content.IntentFilter;
+import android.content.pm.IPackageManager;
 import android.content.pm.PackageManager;
 import android.net.Uri;
 import android.nfc.tech.MifareClassic;
@@ -525,6 +526,66 @@
     }
 
     /**
+     * Helper to check if this device has FEATURE_NFC_BEAM, but without using
+     * a context.
+     * Equivalent to
+     * context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC_BEAM)
+     */
+    private static boolean hasBeamFeature() {
+        IPackageManager pm = ActivityThread.getPackageManager();
+        if (pm == null) {
+            Log.e(TAG, "Cannot get package manager, assuming no Android Beam feature");
+            return false;
+        }
+        try {
+            return pm.hasSystemFeature(PackageManager.FEATURE_NFC_BEAM, 0);
+        } catch (RemoteException e) {
+            Log.e(TAG, "Package manager query failed, assuming no Android Beam feature", e);
+            return false;
+        }
+    }
+
+    /**
+     * Helper to check if this device has FEATURE_NFC, but without using
+     * a context.
+     * Equivalent to
+     * context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)
+     */
+    private static boolean hasNfcFeature() {
+        IPackageManager pm = ActivityThread.getPackageManager();
+        if (pm == null) {
+            Log.e(TAG, "Cannot get package manager, assuming no NFC feature");
+            return false;
+        }
+        try {
+            return pm.hasSystemFeature(PackageManager.FEATURE_NFC, 0);
+        } catch (RemoteException e) {
+            Log.e(TAG, "Package manager query failed, assuming no NFC feature", e);
+            return false;
+        }
+    }
+
+    /**
+     * Helper to check if this device is NFC HCE capable, by checking for
+     * FEATURE_NFC_HOST_CARD_EMULATION and/or FEATURE_NFC_HOST_CARD_EMULATION_NFCF,
+     * but without using a context.
+     */
+    private static boolean hasNfcHceFeature() {
+        IPackageManager pm = ActivityThread.getPackageManager();
+        if (pm == null) {
+            Log.e(TAG, "Cannot get package manager, assuming no NFC feature");
+            return false;
+        }
+        try {
+            return pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION, 0)
+                || pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION_NFCF, 0);
+        } catch (RemoteException e) {
+            Log.e(TAG, "Package manager query failed, assuming no NFC feature", e);
+            return false;
+        }
+    }
+
+    /**
      * Return list of Secure Elements which support off host card emulation.
      *
      * @return List<String> containing secure elements on the device which supports
@@ -533,21 +594,23 @@
      * @hide
      */
     public @NonNull List<String> getSupportedOffHostSecureElements() {
-        if (mContext == null) {
-            throw new UnsupportedOperationException("You need a context on NfcAdapter to use the "
-                    + " getSupportedOffHostSecureElements APIs");
-        }
         List<String> offHostSE = new ArrayList<String>();
-        PackageManager pm = mContext.getPackageManager();
+        IPackageManager pm = ActivityThread.getPackageManager();
         if (pm == null) {
             Log.e(TAG, "Cannot get package manager, assuming no off-host CE feature");
             return offHostSE;
         }
-        if (pm.hasSystemFeature(PackageManager.FEATURE_NFC_OFF_HOST_CARD_EMULATION_UICC)) {
-            offHostSE.add("SIM");
-        }
-        if (pm.hasSystemFeature(PackageManager.FEATURE_NFC_OFF_HOST_CARD_EMULATION_ESE)) {
-            offHostSE.add("eSE");
+        try {
+            if (pm.hasSystemFeature(PackageManager.FEATURE_NFC_OFF_HOST_CARD_EMULATION_UICC, 0)) {
+                offHostSE.add("SIM");
+            }
+            if (pm.hasSystemFeature(PackageManager.FEATURE_NFC_OFF_HOST_CARD_EMULATION_ESE, 0)) {
+                offHostSE.add("eSE");
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "Package manager query failed, assuming no off-host CE feature", e);
+            offHostSE.clear();
+            return offHostSE;
         }
         return offHostSE;
     }
@@ -559,19 +622,10 @@
      */
     @UnsupportedAppUsage
     public static synchronized NfcAdapter getNfcAdapter(Context context) {
-        if (context == null) {
-            if (sNullContextNfcAdapter == null) {
-                sNullContextNfcAdapter = new NfcAdapter(null);
-            }
-            return sNullContextNfcAdapter;
-        }
         if (!sIsInitialized) {
-            PackageManager pm = context.getPackageManager();
-            sHasNfcFeature = pm.hasSystemFeature(PackageManager.FEATURE_NFC);
-            sHasBeamFeature = pm.hasSystemFeature(PackageManager.FEATURE_NFC_BEAM);
-            boolean hasHceFeature =
-                    pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
-                    || pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION_NFCF);
+            sHasNfcFeature = hasNfcFeature();
+            sHasBeamFeature = hasBeamFeature();
+            boolean hasHceFeature = hasNfcHceFeature();
             /* is this device meant to have NFC */
             if (!sHasNfcFeature && !hasHceFeature) {
                 Log.v(TAG, "this device does not have NFC support");
@@ -607,6 +661,12 @@
 
             sIsInitialized = true;
         }
+        if (context == null) {
+            if (sNullContextNfcAdapter == null) {
+                sNullContextNfcAdapter = new NfcAdapter(null);
+            }
+            return sNullContextNfcAdapter;
+        }
         NfcAdapter adapter = sNfcAdapters.get(context);
         if (adapter == null) {
             adapter = new NfcAdapter(context);
@@ -617,12 +677,8 @@
 
     /** get handle to NFC service interface */
     private static INfcAdapter getServiceInterface() {
-        if (!sHasNfcFeature) {
-            /* NFC is not supported */
-            return null;
-        }
         /* get a handle to NFC service */
-        IBinder b = ServiceManager.waitForService("nfc");
+        IBinder b = ServiceManager.getService("nfc");
         if (b == null) {
             return null;
         }
@@ -652,15 +708,6 @@
                     "context not associated with any application (using a mock context?)");
         }
 
-        synchronized (NfcAdapter.class) {
-            if (!sIsInitialized) {
-                PackageManager pm = context.getPackageManager();
-                sHasNfcFeature = pm.hasSystemFeature(PackageManager.FEATURE_NFC);
-            }
-            if (!sHasNfcFeature) {
-                return null;
-            }
-        }
         if (getServiceInterface() == null) {
             // NFC is not available
             return null;
diff --git a/core/java/android/nfc/cardemulation/CardEmulation.java b/core/java/android/nfc/cardemulation/CardEmulation.java
index 6a42091..0b56d19 100644
--- a/core/java/android/nfc/cardemulation/CardEmulation.java
+++ b/core/java/android/nfc/cardemulation/CardEmulation.java
@@ -22,9 +22,11 @@
 import android.annotation.SdkConstant;
 import android.annotation.SdkConstant.SdkConstantType;
 import android.app.Activity;
+import android.app.ActivityThread;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
+import android.content.pm.IPackageManager;
 import android.content.pm.PackageManager;
 import android.nfc.INfcCardEmulation;
 import android.nfc.NfcAdapter;
@@ -156,13 +158,18 @@
             throw new UnsupportedOperationException();
         }
         if (!sIsInitialized) {
-            PackageManager pm = context.getPackageManager();
+            IPackageManager pm = ActivityThread.getPackageManager();
             if (pm == null) {
                 Log.e(TAG, "Cannot get PackageManager");
                 throw new UnsupportedOperationException();
             }
-            if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
-                Log.e(TAG, "This device does not support card emulation");
+            try {
+                if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION, 0)) {
+                    Log.e(TAG, "This device does not support card emulation");
+                    throw new UnsupportedOperationException();
+                }
+            } catch (RemoteException e) {
+                Log.e(TAG, "PackageManager query failed.");
                 throw new UnsupportedOperationException();
             }
             sIsInitialized = true;
diff --git a/core/java/android/nfc/cardemulation/NfcFCardEmulation.java b/core/java/android/nfc/cardemulation/NfcFCardEmulation.java
index 48bbf5b6..3c92455 100644
--- a/core/java/android/nfc/cardemulation/NfcFCardEmulation.java
+++ b/core/java/android/nfc/cardemulation/NfcFCardEmulation.java
@@ -17,8 +17,10 @@
 package android.nfc.cardemulation;
 
 import android.app.Activity;
+import android.app.ActivityThread;
 import android.content.ComponentName;
 import android.content.Context;
+import android.content.pm.IPackageManager;
 import android.content.pm.PackageManager;
 import android.nfc.INfcFCardEmulation;
 import android.nfc.NfcAdapter;
@@ -68,13 +70,18 @@
             throw new UnsupportedOperationException();
         }
         if (!sIsInitialized) {
-            PackageManager pm = context.getPackageManager();
+            IPackageManager pm = ActivityThread.getPackageManager();
             if (pm == null) {
                 Log.e(TAG, "Cannot get PackageManager");
                 throw new UnsupportedOperationException();
             }
-            if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION_NFCF)) {
-                Log.e(TAG, "This device does not support NFC-F card emulation");
+            try {
+                if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION_NFCF, 0)) {
+                    Log.e(TAG, "This device does not support NFC-F card emulation");
+                    throw new UnsupportedOperationException();
+                }
+            } catch (RemoteException e) {
+                Log.e(TAG, "PackageManager query failed.");
                 throw new UnsupportedOperationException();
             }
             sIsInitialized = true;
diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java
index 7a55a5c..2a4c861 100644
--- a/core/java/android/os/BatteryStats.java
+++ b/core/java/android/os/BatteryStats.java
@@ -44,6 +44,7 @@
 import android.util.MutableBoolean;
 import android.util.Pair;
 import android.util.Printer;
+import android.util.Slog;
 import android.util.SparseArray;
 import android.util.SparseDoubleArray;
 import android.util.SparseIntArray;
@@ -52,6 +53,7 @@
 import android.view.Display;
 
 import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.os.BatteryStatsHistoryIterator;
 
 import com.google.android.collect.Lists;
 
@@ -650,8 +652,11 @@
             return Uid.PROCESS_STATE_NONEXISTENT;
         } else if (procState == ActivityManager.PROCESS_STATE_TOP) {
             return Uid.PROCESS_STATE_TOP;
-        } else if (ActivityManager.isForegroundService(procState)) {
-            // State when app has put itself in the foreground.
+        } else if (procState == ActivityManager.PROCESS_STATE_BOUND_TOP) {
+            return Uid.PROCESS_STATE_BACKGROUND;
+        } else if (procState == ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) {
+            return Uid.PROCESS_STATE_FOREGROUND_SERVICE;
+        } else if (procState == ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE) {
             return Uid.PROCESS_STATE_FOREGROUND_SERVICE;
         } else if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) {
             // Persistent and other foreground states go here.
@@ -2395,9 +2400,6 @@
 
     public abstract int getHistoryUsedSize();
 
-    @UnsupportedAppUsage
-    public abstract boolean startIteratingHistoryLocked();
-
     public abstract int getHistoryStringPoolSize();
 
     public abstract int getHistoryStringPoolBytes();
@@ -2406,10 +2408,11 @@
 
     public abstract int getHistoryTagPoolUid(int index);
 
-    @UnsupportedAppUsage
-    public abstract boolean getNextHistoryLocked(HistoryItem out);
-
-    public abstract void finishIteratingHistoryLocked();
+    /**
+     * Returns a BatteryStatsHistoryIterator. Battery history will remain immutable until the
+     * {@link BatteryStatsHistoryIterator#close()} method is invoked.
+     */
+    public abstract BatteryStatsHistoryIterator iterateBatteryStatsHistory();
 
     /**
      * Returns the number of times the device has been started.
@@ -7448,80 +7451,88 @@
 
     private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
         final HistoryPrinter hprinter = new HistoryPrinter();
-        final HistoryItem rec = new HistoryItem();
         long lastTime = -1;
         long baseTime = -1;
         boolean printed = false;
         HistoryEventTracker tracker = null;
-        while (getNextHistoryLocked(rec)) {
-            lastTime = rec.time;
-            if (baseTime < 0) {
-                baseTime = lastTime;
-            }
-            if (rec.time >= histStart) {
-                if (histStart >= 0 && !printed) {
-                    if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
-                            || rec.cmd == HistoryItem.CMD_RESET
-                            || rec.cmd == HistoryItem.CMD_START
-                            || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
-                        printed = true;
-                        hprinter.printNextItem(pw, rec, baseTime, checkin,
-                                (flags&DUMP_VERBOSE) != 0);
-                        rec.cmd = HistoryItem.CMD_UPDATE;
-                    } else if (rec.currentTime != 0) {
-                        printed = true;
-                        byte cmd = rec.cmd;
-                        rec.cmd = HistoryItem.CMD_CURRENT_TIME;
-                        hprinter.printNextItem(pw, rec, baseTime, checkin,
-                                (flags&DUMP_VERBOSE) != 0);
-                        rec.cmd = cmd;
+        try (BatteryStatsHistoryIterator iterator = iterateBatteryStatsHistory()) {
+            HistoryItem rec;
+            while ((rec = iterator.next()) != null) {
+                try {
+                    lastTime = rec.time;
+                    if (baseTime < 0) {
+                        baseTime = lastTime;
                     }
-                    if (tracker != null) {
-                        if (rec.cmd != HistoryItem.CMD_UPDATE) {
-                            hprinter.printNextItem(pw, rec, baseTime, checkin,
-                                    (flags&DUMP_VERBOSE) != 0);
-                            rec.cmd = HistoryItem.CMD_UPDATE;
-                        }
-                        int oldEventCode = rec.eventCode;
-                        HistoryTag oldEventTag = rec.eventTag;
-                        rec.eventTag = new HistoryTag();
-                        for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
-                            HashMap<String, SparseIntArray> active
-                                    = tracker.getStateForEvent(i);
-                            if (active == null) {
-                                continue;
+                    if (rec.time >= histStart) {
+                        if (histStart >= 0 && !printed) {
+                            if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
+                                    || rec.cmd == HistoryItem.CMD_RESET
+                                    || rec.cmd == HistoryItem.CMD_START
+                                    || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
+                                printed = true;
+                                hprinter.printNextItem(pw, rec, baseTime, checkin,
+                                        (flags & DUMP_VERBOSE) != 0);
+                                rec.cmd = HistoryItem.CMD_UPDATE;
+                            } else if (rec.currentTime != 0) {
+                                printed = true;
+                                byte cmd = rec.cmd;
+                                rec.cmd = HistoryItem.CMD_CURRENT_TIME;
+                                hprinter.printNextItem(pw, rec, baseTime, checkin,
+                                        (flags & DUMP_VERBOSE) != 0);
+                                rec.cmd = cmd;
                             }
-                            for (HashMap.Entry<String, SparseIntArray> ent
-                                    : active.entrySet()) {
-                                SparseIntArray uids = ent.getValue();
-                                for (int j=0; j<uids.size(); j++) {
-                                    rec.eventCode = i;
-                                    rec.eventTag.string = ent.getKey();
-                                    rec.eventTag.uid = uids.keyAt(j);
-                                    rec.eventTag.poolIdx = uids.valueAt(j);
+                            if (tracker != null) {
+                                if (rec.cmd != HistoryItem.CMD_UPDATE) {
                                     hprinter.printNextItem(pw, rec, baseTime, checkin,
-                                            (flags&DUMP_VERBOSE) != 0);
-                                    rec.wakeReasonTag = null;
-                                    rec.wakelockTag = null;
+                                            (flags & DUMP_VERBOSE) != 0);
+                                    rec.cmd = HistoryItem.CMD_UPDATE;
                                 }
+                                int oldEventCode = rec.eventCode;
+                                HistoryTag oldEventTag = rec.eventTag;
+                                rec.eventTag = new HistoryTag();
+                                for (int i = 0; i < HistoryItem.EVENT_COUNT; i++) {
+                                    Map<String, SparseIntArray> active =
+                                            tracker.getStateForEvent(i);
+                                    if (active == null) {
+                                        continue;
+                                    }
+                                    for (Map.Entry<String, SparseIntArray> ent :
+                                            active.entrySet()) {
+                                        SparseIntArray uids = ent.getValue();
+                                        for (int j = 0; j < uids.size(); j++) {
+                                            rec.eventCode = i;
+                                            rec.eventTag.string = ent.getKey();
+                                            rec.eventTag.uid = uids.keyAt(j);
+                                            rec.eventTag.poolIdx = uids.valueAt(j);
+                                            hprinter.printNextItem(pw, rec, baseTime, checkin,
+                                                    (flags & DUMP_VERBOSE) != 0);
+                                            rec.wakeReasonTag = null;
+                                            rec.wakelockTag = null;
+                                        }
+                                    }
+                                }
+                                rec.eventCode = oldEventCode;
+                                rec.eventTag = oldEventTag;
+                                tracker = null;
                             }
                         }
-                        rec.eventCode = oldEventCode;
-                        rec.eventTag = oldEventTag;
-                        tracker = null;
+                        hprinter.printNextItem(pw, rec, baseTime, checkin,
+                                (flags & DUMP_VERBOSE) != 0);
+                    } else if (false/* && rec.eventCode != HistoryItem.EVENT_NONE */) {
+                        // This is an attempt to aggregate the previous state and generate
+                        // fake events to reflect that state at the point where we start
+                        // printing real events.  It doesn't really work right, so is turned off.
+                        if (tracker == null) {
+                            tracker = new HistoryEventTracker();
+                        }
+                        tracker.updateState(rec.eventCode, rec.eventTag.string,
+                                rec.eventTag.uid, rec.eventTag.poolIdx);
                     }
+                } catch (Throwable t) {
+                    t.printStackTrace(pw);
+                    Slog.wtf(TAG, "Corrupted battery history", t);
+                    break;
                 }
-                hprinter.printNextItem(pw, rec, baseTime, checkin,
-                        (flags&DUMP_VERBOSE) != 0);
-            } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
-                // This is an attempt to aggregate the previous state and generate
-                // fake events to reflect that state at the point where we start
-                // printing real events.  It doesn't really work right, so is turned off.
-                if (tracker == null) {
-                    tracker = new HistoryEventTracker();
-                }
-                tracker.updateState(rec.eventCode, rec.eventTag.string,
-                        rec.eventTag.uid, rec.eventTag.poolIdx);
             }
         }
         if (histStart >= 0) {
@@ -7592,25 +7603,19 @@
         if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
             final long historyTotalSize = getHistoryTotalSize();
             final long historyUsedSize = getHistoryUsedSize();
-            if (startIteratingHistoryLocked()) {
-                try {
-                    pw.print("Battery History (");
-                    pw.print((100*historyUsedSize)/historyTotalSize);
-                    pw.print("% used, ");
-                    printSizeValue(pw, historyUsedSize);
-                    pw.print(" used of ");
-                    printSizeValue(pw, historyTotalSize);
-                    pw.print(", ");
-                    pw.print(getHistoryStringPoolSize());
-                    pw.print(" strings using ");
-                    printSizeValue(pw, getHistoryStringPoolBytes());
-                    pw.println("):");
-                    dumpHistoryLocked(pw, flags, histStart, false);
-                    pw.println();
-                } finally {
-                    finishIteratingHistoryLocked();
-                }
-            }
+            pw.print("Battery History (");
+            pw.print((100 * historyUsedSize) / historyTotalSize);
+            pw.print("% used, ");
+            printSizeValue(pw, historyUsedSize);
+            pw.print(" used of ");
+            printSizeValue(pw, historyTotalSize);
+            pw.print(", ");
+            pw.print(getHistoryStringPoolSize());
+            pw.print(" strings using ");
+            printSizeValue(pw, getHistoryStringPoolBytes());
+            pw.println("):");
+            dumpHistoryLocked(pw, flags, histStart, false);
+            pw.println();
         }
 
         if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
@@ -7767,28 +7772,24 @@
                 getEndPlatformVersion());
 
         if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) {
-            if (startIteratingHistoryLocked()) {
-                try {
-                    for (int i=0; i<getHistoryStringPoolSize(); i++) {
-                        pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
-                        pw.print(HISTORY_STRING_POOL); pw.print(',');
-                        pw.print(i);
-                        pw.print(",");
-                        pw.print(getHistoryTagPoolUid(i));
-                        pw.print(",\"");
-                        String str = getHistoryTagPoolString(i);
-                        if (str != null) {
-                            str = str.replace("\\", "\\\\");
-                            str = str.replace("\"", "\\\"");
-                            pw.print(str);
-                        }
-                        pw.print("\"");
-                        pw.println();
-                    }
-                    dumpHistoryLocked(pw, flags, histStart, true);
-                } finally {
-                    finishIteratingHistoryLocked();
+            for (int i = 0; i < getHistoryStringPoolSize(); i++) {
+                pw.print(BATTERY_STATS_CHECKIN_VERSION);
+                pw.print(',');
+                pw.print(HISTORY_STRING_POOL);
+                pw.print(',');
+                pw.print(i);
+                pw.print(",");
+                pw.print(getHistoryTagPoolUid(i));
+                pw.print(",\"");
+                String str = getHistoryTagPoolString(i);
+                if (str != null) {
+                    str = str.replace("\\", "\\\\");
+                    str = str.replace("\"", "\\\"");
+                    pw.print(str);
                 }
+                pw.print("\"");
+                pw.println();
+                dumpHistoryLocked(pw, flags, histStart, true);
             }
         }
 
@@ -8328,17 +8329,12 @@
     }
 
     private void dumpProtoHistoryLocked(ProtoOutputStream proto, int flags, long histStart) {
-        if (!startIteratingHistoryLocked()) {
-            return;
-        }
-
         proto.write(BatteryStatsServiceDumpHistoryProto.REPORT_VERSION, CHECKIN_VERSION);
         proto.write(BatteryStatsServiceDumpHistoryProto.PARCEL_VERSION, getParcelVersion());
         proto.write(BatteryStatsServiceDumpHistoryProto.START_PLATFORM_VERSION,
                 getStartPlatformVersion());
         proto.write(BatteryStatsServiceDumpHistoryProto.END_PLATFORM_VERSION,
                 getEndPlatformVersion());
-        try {
             long token;
             // History string pool (HISTORY_STRING_POOL)
             for (int i = 0; i < getHistoryStringPoolSize(); ++i) {
@@ -8350,14 +8346,15 @@
                 proto.end(token);
             }
 
-            // History data (HISTORY_DATA)
-            final HistoryPrinter hprinter = new HistoryPrinter();
-            final HistoryItem rec = new HistoryItem();
-            long lastTime = -1;
-            long baseTime = -1;
-            boolean printed = false;
-            HistoryEventTracker tracker = null;
-            while (getNextHistoryLocked(rec)) {
+        // History data (HISTORY_DATA)
+        final HistoryPrinter hprinter = new HistoryPrinter();
+        long lastTime = -1;
+        long baseTime = -1;
+        boolean printed = false;
+        HistoryEventTracker tracker = null;
+        try (BatteryStatsHistoryIterator iterator = iterateBatteryStatsHistory()) {
+            HistoryItem rec;
+            while ((rec = iterator.next()) != null) {
                 lastTime = rec.time;
                 if (baseTime < 0) {
                     baseTime = lastTime;
@@ -8424,8 +8421,6 @@
                 proto.write(BatteryStatsServiceDumpHistoryProto.CSV_LINES,
                         "NEXT: " + (lastTime + 1));
             }
-        } finally {
-            finishIteratingHistoryLocked();
         }
     }
 
diff --git a/core/java/android/os/CoolingDevice.java b/core/java/android/os/CoolingDevice.java
index 4babd4b..4ddcd9d 100644
--- a/core/java/android/os/CoolingDevice.java
+++ b/core/java/android/os/CoolingDevice.java
@@ -19,7 +19,7 @@
 import android.annotation.IntDef;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
-import android.hardware.thermal.V2_0.CoolingType;
+import android.hardware.thermal.CoolingType;
 
 import com.android.internal.util.Preconditions;
 
@@ -52,11 +52,16 @@
             TYPE_MODEM,
             TYPE_NPU,
             TYPE_COMPONENT,
+            TYPE_TPU,
+            TYPE_POWER_AMPLIFIER,
+            TYPE_DISPLAY,
+            TYPE_SPEAKER
     })
     @Retention(RetentionPolicy.SOURCE)
     public @interface Type {}
 
-    /** Keep in sync with hardware/interfaces/thermal/2.0/types.hal */
+    /** Keep in sync with hardware/interfaces/thermal/aidl/android/hardware/thermal
+     * /ThrottlingSeverity.aidl */
     /** Fan for active cooling */
     public static final int TYPE_FAN = CoolingType.FAN;
     /** Battery charging cooling deivice */
@@ -67,10 +72,18 @@
     public static final int TYPE_GPU = CoolingType.GPU;
     /** Modem cooling deivice */
     public static final int TYPE_MODEM = CoolingType.MODEM;
-    /** NPU/TPU cooling deivice */
+    /** NPU cooling deivice */
     public static final int TYPE_NPU = CoolingType.NPU;
     /** Generic passive cooling deivice */
     public static final int TYPE_COMPONENT = CoolingType.COMPONENT;
+    /** TPU cooling deivice */
+    public static final int TYPE_TPU = CoolingType.TPU;
+    /** Power amplifier cooling device */
+    public static final int TYPE_POWER_AMPLIFIER = CoolingType.POWER_AMPLIFIER;
+    /** Display cooling device */
+    public static final int TYPE_DISPLAY = CoolingType.DISPLAY;
+    /** Speaker cooling device */
+    public static final int TYPE_SPEAKER = CoolingType.SPEAKER;
 
     /**
      * Verify a valid cooling device type.
@@ -78,7 +91,7 @@
      * @return true if a cooling device type is valid otherwise false.
      */
     public static boolean isValidType(@Type int type) {
-        return type >= TYPE_FAN && type <= TYPE_COMPONENT;
+        return type >= TYPE_FAN && type <= TYPE_SPEAKER;
     }
 
     public CoolingDevice(long value, @Type int type, @NonNull String name) {
diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java
index 399f11b..a31c2e6 100644
--- a/core/java/android/os/Debug.java
+++ b/core/java/android/os/Debug.java
@@ -1956,7 +1956,21 @@
     /** @hide */
     public static final int MEMINFO_UNEVICTABLE = 18;
     /** @hide */
-    public static final int MEMINFO_COUNT = 19;
+    public static final int MEMINFO_AVAILABLE = 19;
+    /** @hide */
+    public static final int MEMINFO_ACTIVE_ANON = 20;
+    /** @hide */
+    public static final int MEMINFO_INACTIVE_ANON = 21;
+    /** @hide */
+    public static final int MEMINFO_ACTIVE_FILE = 22;
+    /** @hide */
+    public static final int MEMINFO_INACTIVE_FILE = 23;
+    /** @hide */
+    public static final int MEMINFO_CMA_TOTAL = 24;
+    /** @hide */
+    public static final int MEMINFO_CMA_FREE = 25;
+    /** @hide */
+    public static final int MEMINFO_COUNT = 26;
 
     /**
      * Retrieves /proc/meminfo.  outSizes is filled with fields
diff --git a/core/java/android/os/Environment.java b/core/java/android/os/Environment.java
index ffa9507..536ef31 100644
--- a/core/java/android/os/Environment.java
+++ b/core/java/android/os/Environment.java
@@ -18,6 +18,7 @@
 
 import android.Manifest;
 import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.annotation.SuppressLint;
 import android.annotation.SystemApi;
 import android.annotation.TestApi;
@@ -44,6 +45,7 @@
 import java.util.Collection;
 import java.util.List;
 import java.util.Objects;
+import java.util.UUID;
 
 /**
  * Provides access to environment variables.
@@ -551,12 +553,37 @@
     }
 
     /** {@hide} */
-    public static File getDataUserCePackageDirectory(String volumeUuid, int userId,
-            String packageName) {
+    @NonNull
+    public static File getDataUserCePackageDirectory(@Nullable String volumeUuid, int userId,
+            @NonNull String packageName) {
         // TODO: keep consistent with installd
         return new File(getDataUserCeDirectory(volumeUuid, userId), packageName);
     }
 
+    /**
+     * Retrieve the credential encrypted data directory for a specific package of a specific user.
+     * This is equivalent to {@link ApplicationInfo#credentialProtectedDataDir}, exposed because
+     * fetching a full {@link ApplicationInfo} instance may be expensive if all the caller needs
+     * is this directory.
+     *
+     * @param storageUuid The storage volume for this directory, usually retrieved from a
+     * {@link StorageManager} API or {@link ApplicationInfo#storageUuid}.
+     * @param user The user this directory is for.
+     * @param packageName The app this directory is for.
+     *
+     * @see ApplicationInfo#credentialProtectedDataDir
+     * @return A file to the directory.
+     *
+     * @hide
+     */
+    @SystemApi
+    @NonNull
+    public static File getDataCePackageDirectoryForUser(@NonNull UUID storageUuid,
+            @NonNull UserHandle user, @NonNull String packageName) {
+        var volumeUuid = StorageManager.convert(storageUuid);
+        return getDataUserCePackageDirectory(volumeUuid, user.getIdentifier(), packageName);
+    }
+
     /** {@hide} */
     public static File getDataUserDeDirectory(String volumeUuid) {
         return new File(getDataDirectory(volumeUuid), DIR_USER_DE);
@@ -568,13 +595,38 @@
     }
 
     /** {@hide} */
-    public static File getDataUserDePackageDirectory(String volumeUuid, int userId,
-            String packageName) {
+    @NonNull
+    public static File getDataUserDePackageDirectory(@Nullable String volumeUuid, int userId,
+            @NonNull String packageName) {
         // TODO: keep consistent with installd
         return new File(getDataUserDeDirectory(volumeUuid, userId), packageName);
     }
 
     /**
+     * Retrieve the device encrypted data directory for a specific package of a specific user. This
+     * is equivalent to {@link ApplicationInfo#deviceProtectedDataDir}, exposed because fetching a
+     * full {@link ApplicationInfo} instance may be expensive if all the caller needs is this
+     * directory.
+     *
+     * @param storageUuid The storage volume for this directory, usually retrieved from a
+     * {@link StorageManager} API or {@link ApplicationInfo#storageUuid}.
+     * @param user The user this directory is for.
+     * @param packageName The app this directory is for.
+     *
+     * @see ApplicationInfo#deviceProtectedDataDir
+     * @return A file to the directory.
+     *
+     * @hide
+     */
+    @SystemApi
+    @NonNull
+    public static File getDataDePackageDirectoryForUser(@NonNull UUID storageUuid,
+            @NonNull UserHandle user, @NonNull String packageName) {
+        var volumeUuid = StorageManager.convert(storageUuid);
+        return getDataUserDePackageDirectory(volumeUuid, user.getIdentifier(), packageName);
+    }
+
+    /**
      * Return preloads directory.
      * <p>This directory may contain pre-loaded content such as
      * {@link #getDataPreloadsDemoDirectory() demo videos} and
diff --git a/core/java/android/os/IUserManager.aidl b/core/java/android/os/IUserManager.aidl
index d31540a..c2ddf45 100644
--- a/core/java/android/os/IUserManager.aidl
+++ b/core/java/android/os/IUserManager.aidl
@@ -79,6 +79,7 @@
     String getUserAccount(int userId);
     void setUserAccount(int userId, String accountName);
     long getUserCreationTime(int userId);
+    int getUserSwitchability(int userId);
     boolean isUserSwitcherEnabled(boolean showEvenIfNotActionable, int mUserId);
     boolean isRestricted(int userId);
     boolean canHaveRestrictedProfile(int userId);
diff --git a/core/java/android/os/Looper.java b/core/java/android/os/Looper.java
index a529ac6..712d328 100644
--- a/core/java/android/os/Looper.java
+++ b/core/java/android/os/Looper.java
@@ -177,12 +177,15 @@
         final long traceTag = me.mTraceTag;
         long slowDispatchThresholdMs = me.mSlowDispatchThresholdMs;
         long slowDeliveryThresholdMs = me.mSlowDeliveryThresholdMs;
-        if (thresholdOverride > 0) {
+
+        final boolean hasOverride = thresholdOverride >= 0;
+        if (hasOverride) {
             slowDispatchThresholdMs = thresholdOverride;
             slowDeliveryThresholdMs = thresholdOverride;
         }
-        final boolean logSlowDelivery = (slowDeliveryThresholdMs > 0) && (msg.when > 0);
-        final boolean logSlowDispatch = (slowDispatchThresholdMs > 0);
+        final boolean logSlowDelivery = (slowDeliveryThresholdMs > 0 || hasOverride)
+                && (msg.when > 0);
+        final boolean logSlowDispatch = (slowDispatchThresholdMs > 0 || hasOverride);
 
         final boolean needStartTime = logSlowDelivery || logSlowDispatch;
         final boolean needEndTime = logSlowDispatch;
@@ -283,7 +286,7 @@
                 SystemProperties.getInt("log.looper."
                         + Process.myUid() + "."
                         + Thread.currentThread().getName()
-                        + ".slow", 0);
+                        + ".slow", -1);
 
         me.mSlowDeliveryDetected = false;
 
diff --git a/core/java/android/os/OWNERS b/core/java/android/os/OWNERS
index 5c5af2a..e9a3254 100644
--- a/core/java/android/os/OWNERS
+++ b/core/java/android/os/OWNERS
@@ -71,6 +71,9 @@
 # Tracing
 per-file Trace.java = file:/TRACE_OWNERS
 
+# PatternMatcher
+per-file PatternMatcher* = file:/PACKAGE_MANAGER_OWNERS
+
 # PermissionEnforcer
 per-file PermissionEnforcer.java = tweek@google.com, brufino@google.com
 
diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java
index 9bc7ffd..dc62f8c 100644
--- a/core/java/android/os/PowerManager.java
+++ b/core/java/android/os/PowerManager.java
@@ -533,10 +533,7 @@
             BRIGHTNESS_CONSTRAINT_TYPE_MAXIMUM,
             BRIGHTNESS_CONSTRAINT_TYPE_DEFAULT,
             BRIGHTNESS_CONSTRAINT_TYPE_DIM,
-            BRIGHTNESS_CONSTRAINT_TYPE_DOZE,
-            BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM_VR,
-            BRIGHTNESS_CONSTRAINT_TYPE_MAXIMUM_VR,
-            BRIGHTNESS_CONSTRAINT_TYPE_DEFAULT_VR
+            BRIGHTNESS_CONSTRAINT_TYPE_DOZE
     })
     @Retention(RetentionPolicy.SOURCE)
     public @interface BrightnessConstraint{}
@@ -571,24 +568,6 @@
     public static final int BRIGHTNESS_CONSTRAINT_TYPE_DOZE = 4;
 
     /**
-     * Brightness constraint type: minimum allowed value.
-     * @hide
-     */
-    public static final int BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM_VR = 5;
-
-    /**
-     * Brightness constraint type: minimum allowed value.
-     * @hide
-     */
-    public static final int BRIGHTNESS_CONSTRAINT_TYPE_MAXIMUM_VR = 6;
-
-    /**
-     * Brightness constraint type: minimum allowed value.
-     * @hide
-     */
-    public static final int BRIGHTNESS_CONSTRAINT_TYPE_DEFAULT_VR = 7;
-
-    /**
      * @hide
      */
     @IntDef(prefix = { "WAKE_REASON_" }, value = {
@@ -1211,35 +1190,6 @@
     }
 
     /**
-     * Gets the minimum supported screen brightness setting for VR Mode.
-     * @hide
-     */
-    public int getMinimumScreenBrightnessForVrSetting() {
-        return mContext.getResources().getInteger(
-                com.android.internal.R.integer.config_screenBrightnessForVrSettingMinimum);
-    }
-
-    /**
-     * Gets the maximum supported screen brightness setting for VR Mode.
-     * The screen may be allowed to become dimmer than this value but
-     * this is the maximum value that can be set by the user.
-     * @hide
-     */
-    public int getMaximumScreenBrightnessForVrSetting() {
-        return mContext.getResources().getInteger(
-                com.android.internal.R.integer.config_screenBrightnessForVrSettingMaximum);
-    }
-
-    /**
-     * Gets the default screen brightness for VR setting.
-     * @hide
-     */
-    public int getDefaultScreenBrightnessForVrSetting() {
-        return mContext.getResources().getInteger(
-                com.android.internal.R.integer.config_screenBrightnessForVrSettingDefault);
-    }
-
-    /**
      * Gets a float screen brightness setting.
      * @hide
      */
diff --git a/core/java/android/os/TEST_MAPPING b/core/java/android/os/TEST_MAPPING
index 3a56662..cc54266 100644
--- a/core/java/android/os/TEST_MAPPING
+++ b/core/java/android/os/TEST_MAPPING
@@ -84,6 +84,15 @@
           "include-filter": "android.os.cts.SharedMemoryTest"
         }
       ]
+    },
+    {
+      "file_patterns": ["Environment[^/]*\\.java"],
+      "name": "FrameworksCoreTests",
+      "options": [
+        {
+          "include-filter": "android.os.EnvironmentTest"
+        }
+      ]
     }
   ],
   "postsubmit": [
diff --git a/core/java/android/os/Temperature.java b/core/java/android/os/Temperature.java
index 55785f3..a138431 100644
--- a/core/java/android/os/Temperature.java
+++ b/core/java/android/os/Temperature.java
@@ -19,8 +19,8 @@
 import android.annotation.IntDef;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
-import android.hardware.thermal.V2_0.TemperatureType;
-import android.hardware.thermal.V2_0.ThrottlingSeverity;
+import android.hardware.thermal.TemperatureType;
+import android.hardware.thermal.ThrottlingSeverity;
 
 import com.android.internal.util.Preconditions;
 
@@ -54,7 +54,8 @@
     @Retention(RetentionPolicy.SOURCE)
     public @interface ThrottlingStatus {}
 
-    /** Keep in sync with hardware/interfaces/thermal/2.0/types.hal */
+    /** Keep in sync with hardware/interfaces/thermal/aidl/android/hardware/thermal
+     * /ThrottlingSeverity.aidl */
     public static final int THROTTLING_NONE = ThrottlingSeverity.NONE;
     public static final int THROTTLING_LIGHT = ThrottlingSeverity.LIGHT;
     public static final int THROTTLING_MODERATE = ThrottlingSeverity.MODERATE;
@@ -75,11 +76,16 @@
             TYPE_BCL_CURRENT,
             TYPE_BCL_PERCENTAGE,
             TYPE_NPU,
+            TYPE_TPU,
+            TYPE_DISPLAY,
+            TYPE_MODEM,
+            TYPE_SOC
     })
     @Retention(RetentionPolicy.SOURCE)
     public @interface Type {}
 
-    /** Keep in sync with hardware/interfaces/thermal/2.0/types.hal */
+    /** Keep in sync with hardware/interfaces/thermal/aidl/android/hardware/thermal
+     * /TemperatureType.aidl */
     public static final int TYPE_UNKNOWN = TemperatureType.UNKNOWN;
     public static final int TYPE_CPU = TemperatureType.CPU;
     public static final int TYPE_GPU = TemperatureType.GPU;
@@ -91,6 +97,10 @@
     public static final int TYPE_BCL_CURRENT = TemperatureType.BCL_CURRENT;
     public static final int TYPE_BCL_PERCENTAGE = TemperatureType.BCL_PERCENTAGE;
     public static final int TYPE_NPU = TemperatureType.NPU;
+    public static final int TYPE_TPU = TemperatureType.TPU;
+    public static final int TYPE_DISPLAY = TemperatureType.DISPLAY;
+    public static final int TYPE_MODEM = TemperatureType.MODEM;
+    public static final int TYPE_SOC = TemperatureType.SOC;
 
     /**
      * Verify a valid Temperature type.
@@ -98,7 +108,7 @@
      * @return true if a Temperature type is valid otherwise false.
      */
     public static boolean isValidType(@Type int type) {
-        return type >= TYPE_UNKNOWN && type <= TYPE_NPU;
+        return type >= TYPE_UNKNOWN && type <= TYPE_SOC;
     }
 
     /**
diff --git a/core/java/android/os/UidBatteryConsumer.java b/core/java/android/os/UidBatteryConsumer.java
index 4a6772d..103452d 100644
--- a/core/java/android/os/UidBatteryConsumer.java
+++ b/core/java/android/os/UidBatteryConsumer.java
@@ -50,8 +50,7 @@
     }
 
     /**
-     * The state of an application when it is either running a foreground (top) activity
-     * or a foreground service.
+     * The state of an application when it is either running a foreground (top) activity.
      */
     public static final int STATE_FOREGROUND = 0;
 
@@ -63,7 +62,8 @@
      * {@link android.app.ActivityManager#PROCESS_STATE_TRANSIENT_BACKGROUND},
      * {@link android.app.ActivityManager#PROCESS_STATE_BACKUP},
      * {@link android.app.ActivityManager#PROCESS_STATE_SERVICE},
-     * {@link android.app.ActivityManager#PROCESS_STATE_RECEIVER}.
+     * {@link android.app.ActivityManager#PROCESS_STATE_RECEIVER},
+     * {@link android.app.ActivityManager#PROCESS_STATE_FOREGROUND_SERVICE}.
      */
     public static final int STATE_BACKGROUND = 1;
 
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index 07c4b44..5f2f710 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -59,7 +59,6 @@
 import android.graphics.drawable.Drawable;
 import android.location.LocationManager;
 import android.provider.Settings;
-import android.telecom.TelecomManager;
 import android.util.AndroidException;
 import android.util.ArraySet;
 import android.util.Log;
@@ -1748,7 +1747,7 @@
     public static final int SWITCHABILITY_STATUS_SYSTEM_USER_LOCKED = 1 << 2;
 
     /**
-     * Result returned in {@link #getUserSwitchability()} indicating user swichability.
+     * Result returned in {@link #getUserSwitchability()} indicating user switchability.
      * @hide
      */
     @Retention(RetentionPolicy.SOURCE)
@@ -2128,20 +2127,16 @@
      * @hide
      */
     @Deprecated
-    @RequiresPermission(allOf = {
-            Manifest.permission.READ_PHONE_STATE,
-            Manifest.permission.MANAGE_USERS}, // Can be INTERACT_ACROSS_USERS instead.
-            conditional = true)
+    @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS,
+            android.Manifest.permission.INTERACT_ACROSS_USERS})
     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
     @UserHandleAware
     public boolean canSwitchUsers() {
-        boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt(
-                mContext.getContentResolver(),
-                Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0;
-        boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM);
-        boolean isUserSwitchDisallowed = hasUserRestrictionForUser(DISALLOW_USER_SWITCH, mUserId);
-        return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall()
-                && !isUserSwitchDisallowed;
+        try {
+            return mService.getUserSwitchability(mUserId) == SWITCHABILITY_STATUS_OK;
+        } catch (RemoteException re) {
+            throw re.rethrowFromSystemServer();
+        }
     }
 
     /**
@@ -2156,9 +2151,8 @@
      * @hide
      */
     @SystemApi
-    @RequiresPermission(allOf = {Manifest.permission.READ_PHONE_STATE,
-            android.Manifest.permission.MANAGE_USERS,
-            android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true)
+    @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS,
+            android.Manifest.permission.INTERACT_ACROSS_USERS})
     @UserHandleAware(enabledSinceTargetSdkVersion = Build.VERSION_CODES.TIRAMISU)
     public @UserSwitchabilityResult int getUserSwitchability() {
         return getUserSwitchability(UserHandle.of(getContextUserIfAppropriate()));
@@ -2175,31 +2169,14 @@
      * @return A {@link UserSwitchabilityResult} flag indicating if the user is switchable.
      * @hide
      */
-    @RequiresPermission(allOf = {Manifest.permission.READ_PHONE_STATE,
-            android.Manifest.permission.MANAGE_USERS,
-            android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true)
+    @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS,
+            android.Manifest.permission.INTERACT_ACROSS_USERS})
     public @UserSwitchabilityResult int getUserSwitchability(UserHandle userHandle) {
-        int flags = SWITCHABILITY_STATUS_OK;
-        if (inCall()) {
-            flags |= SWITCHABILITY_STATUS_USER_IN_CALL;
+        try {
+            return mService.getUserSwitchability(userHandle.getIdentifier());
+        } catch (RemoteException re) {
+            throw re.rethrowFromSystemServer();
         }
-        if (hasUserRestrictionForUser(DISALLOW_USER_SWITCH, userHandle)) {
-            flags |= SWITCHABILITY_STATUS_USER_SWITCH_DISALLOWED;
-        }
-
-        // System User is always unlocked in Headless System User Mode, so ignore this flag
-        if (!isHeadlessSystemUserMode()) {
-            final boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt(
-                    mContext.getContentResolver(),
-                    Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0;
-            final boolean systemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM);
-
-            if (!allowUserSwitchingWhenSystemUserLocked && !systemUserUnlocked) {
-                flags |= SWITCHABILITY_STATUS_SYSTEM_USER_LOCKED;
-            }
-        }
-
-        return flags;
     }
 
     /**
@@ -5614,11 +5591,6 @@
         }
     }
 
-    private boolean inCall() {
-        final TelecomManager telecomManager = mContext.getSystemService(TelecomManager.class);
-        return telecomManager != null && telecomManager.isInCall();
-    }
-
     /* Cache key for anything that assumes that userIds cannot be re-used without rebooting. */
     private static final String CACHE_KEY_STATIC_USER_PROPERTIES = "cache_key.static_user_props";
 
diff --git a/core/java/android/os/incremental/IncrementalManager.java b/core/java/android/os/incremental/IncrementalManager.java
index 9c8ee56..8004143 100644
--- a/core/java/android/os/incremental/IncrementalManager.java
+++ b/core/java/android/os/incremental/IncrementalManager.java
@@ -25,6 +25,9 @@
 import android.content.pm.IPackageLoadingProgressCallback;
 import android.os.RemoteCallbackList;
 import android.os.RemoteException;
+import android.system.ErrnoException;
+import android.system.Os;
+import android.system.StructStat;
 import android.util.Slog;
 import android.util.SparseArray;
 
@@ -146,15 +149,29 @@
     @Nullable
     public IncrementalStorage createStorage(@NonNull String path,
             @NonNull IncrementalStorage linkedStorage, @CreateMode int createMode) {
+        int id = -1;
         try {
-            final int id = mService.createLinkedStorage(
+            // Incremental service mounts its newly created storage on top of the supplied path,
+            // ensure that the original mode remains the same after mounting.
+            StructStat st = Os.stat(path);
+            id = mService.createLinkedStorage(
                     path, linkedStorage.getId(), createMode);
             if (id < 0) {
                 return null;
             }
+            Os.chmod(path, st.st_mode & 07777);
             return new IncrementalStorage(mService, id);
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
+        } catch (ErrnoException e) {
+            if (id >= 0) {
+                try {
+                    mService.deleteStorage(id);
+                } catch (RemoteException re) {
+                    throw re.rethrowFromSystemServer();
+                }
+            }
+            throw new RuntimeException(e);
         }
     }
 
diff --git a/core/java/android/os/storage/StorageManager.java b/core/java/android/os/storage/StorageManager.java
index 7899420..a72ccad 100644
--- a/core/java/android/os/storage/StorageManager.java
+++ b/core/java/android/os/storage/StorageManager.java
@@ -2742,7 +2742,8 @@
 
     /** {@hide} */
     @TestApi
-    public static @NonNull UUID convert(@NonNull String uuid) {
+    public static @NonNull UUID convert(@Nullable String uuid) {
+        // UUID_PRIVATE_INTERNAL is null, so this accepts nullable input
         if (Objects.equals(uuid, UUID_PRIVATE_INTERNAL)) {
             return UUID_DEFAULT;
         } else if (Objects.equals(uuid, UUID_PRIMARY_PHYSICAL)) {
diff --git a/core/java/android/provider/DeviceConfig.java b/core/java/android/provider/DeviceConfig.java
deleted file mode 100644
index 7df9290..0000000
--- a/core/java/android/provider/DeviceConfig.java
+++ /dev/null
@@ -1,1566 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.provider;
-
-import static android.Manifest.permission.READ_DEVICE_CONFIG;
-import static android.Manifest.permission.WRITE_DEVICE_CONFIG;
-
-import android.annotation.CallbackExecutor;
-import android.annotation.NonNull;
-import android.annotation.Nullable;
-import android.annotation.RequiresPermission;
-import android.annotation.SuppressLint;
-import android.annotation.SystemApi;
-import android.database.ContentObserver;
-import android.net.Uri;
-import android.provider.Settings.Config.SyncDisabledMode;
-import android.provider.Settings.ResetMode;
-import android.util.ArrayMap;
-import android.util.Log;
-import android.util.Pair;
-
-import com.android.internal.annotations.GuardedBy;
-import com.android.internal.util.Preconditions;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.Executor;
-
-/**
- * Device level configuration parameters which can be tuned by a separate configuration service.
- * Namespaces that end in "_native" such as {@link #NAMESPACE_NETD_NATIVE} are intended to be used
- * by native code and should be pushed to system properties to make them accessible.
- *
- * @hide
- */
-@SystemApi
-public final class DeviceConfig {
-    /**
-     * Namespace for activity manager related features. These features will be applied
-     * immediately upon change.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_ACTIVITY_MANAGER = "activity_manager";
-
-    /**
-     * Namespace for activity manager, specific to the "component alias" feature. We needed a
-     * different namespace in order to avoid phonetype from resetting it.
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_ACTIVITY_MANAGER_COMPONENT_ALIAS = "activity_manager_ca";
-
-    /**
-     * Namespace for all activity manager related features that are used at the native level.
-     * These features are applied at reboot.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_ACTIVITY_MANAGER_NATIVE_BOOT =
-            "activity_manager_native_boot";
-
-    /**
-     * Namespace for AlarmManager configurations.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_ALARM_MANAGER = "alarm_manager";
-
-    /**
-     * Namespace for all app compat related features.  These features will be applied
-     * immediately upon change.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_APP_COMPAT = "app_compat";
-
-    /**
-     * Namespace for all app hibernation related features.
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_APP_HIBERNATION = "app_hibernation";
-
-    /**
-     * Namespace for all AppSearch related features.
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_APPSEARCH = "appsearch";
-
-    /**
-     * Namespace for app standby configurations.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_APP_STANDBY = "app_standby";
-
-    /**
-     * Namespace for all App Cloning related features.
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_APP_CLONING = "app_cloning";
-
-    /**
-     * Namespace for AttentionManagerService related features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_ATTENTION_MANAGER_SERVICE = "attention_manager_service";
-
-    /**
-     * Namespace for autofill feature that provides suggestions across all apps when
-     * the user interacts with input fields.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_AUTOFILL = "autofill";
-
-    /**
-     * Namespace for battery saver feature.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_BATTERY_SAVER = "battery_saver";
-
-    /**
-     * Namespace for blobstore feature that allows apps to share data blobs.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_BLOBSTORE = "blobstore";
-
-    /**
-     * Namespace for all Bluetooth related features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_BLUETOOTH = "bluetooth";
-
-    /**
-     * Namespace for features relating to clipboard.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_CLIPBOARD = "clipboard";
-
-    /**
-     * Namespace for all networking connectivity related features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_CONNECTIVITY = "connectivity";
-
-    /**
-     * Namespace for CaptivePortalLogin module.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_CAPTIVEPORTALLOGIN = "captive_portal_login";
-
-    /**
-     * Namespace for Tethering module.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_TETHERING = "tethering";
-
-
-    /**
-     * Namespace for Nearby module.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_NEARBY = "nearby";
-
-    /**
-     * Namespace for content capture feature used by on-device machine intelligence
-     * to provide suggestions in a privacy-safe manner.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_CONTENT_CAPTURE = "content_capture";
-
-    /**
-     * Namespace for device idle configurations.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_DEVICE_IDLE = "device_idle";
-
-    /**
-     * Namespace for how dex runs. The feature requires a reboot to reach a clean state.
-     *
-     * @deprecated No longer used
-     * @hide
-     */
-    @Deprecated
-    @SystemApi
-    public static final String NAMESPACE_DEX_BOOT = "dex_boot";
-
-    /**
-     * Namespace for display manager related features. The names to access the properties in this
-     * namespace should be defined in {@link android.hardware.display.DisplayManager}.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_DISPLAY_MANAGER = "display_manager";
-
-    /**
-     * Namespace for all Game Driver features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_GAME_DRIVER = "game_driver";
-
-    /**
-     * Namespace for all HDMI Control features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_HDMI_CONTROL = "hdmi_control";
-
-    /**
-     * Namespace for all input-related features that are used at the native level.
-     * These features are applied at reboot.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_INPUT_NATIVE_BOOT = "input_native_boot";
-
-    /**
-     * Namespace for attention-based features provided by on-device machine intelligence.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_INTELLIGENCE_ATTENTION = "intelligence_attention";
-
-    /**
-     * Definitions for properties related to Content Suggestions.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_INTELLIGENCE_CONTENT_SUGGESTIONS =
-            "intelligence_content_suggestions";
-
-    /**
-     * Namespace for JobScheduler configurations.
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_JOB_SCHEDULER = "jobscheduler";
-
-    /**
-     * Namespace for all lmkd related features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_LMKD_NATIVE = "lmkd_native";
-
-    /**
-     * Namespace for all location related features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_LOCATION = "location";
-
-    /**
-     * Namespace for all media related features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_MEDIA = "media";
-
-    /**
-     * Namespace for all media native related features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_MEDIA_NATIVE = "media_native";
-
-    /**
-     * Namespace for all Kernel Multi-Gen LRU feature.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_MGLRU_NATIVE = "mglru_native";
-
-    /**
-     * Namespace for all netd related features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_NETD_NATIVE = "netd_native";
-
-    /**
-     * Namespace for all Android NNAPI related features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_NNAPI_NATIVE = "nnapi_native";
-
-    /**
-     * Namespace for all OnDevicePersonalization related feature.
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_ON_DEVICE_PERSONALIZATION = "on_device_personalization";
-
-    /**
-     * Namespace for features related to the Package Manager Service.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_PACKAGE_MANAGER_SERVICE = "package_manager_service";
-
-    /**
-     * Namespace for features related to the Profcollect native Service.
-     * These features are applied at reboot.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_PROFCOLLECT_NATIVE_BOOT = "profcollect_native_boot";
-
-    /**
-     * Namespace for features related to Reboot Readiness detection.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_REBOOT_READINESS = "reboot_readiness";
-
-    /**
-     * Namespace for Remote Key Provisioning related features.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_REMOTE_KEY_PROVISIONING_NATIVE =
-            "remote_key_provisioning_native";
-
-    /**
-     * Namespace for Rollback flags that are applied immediately.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_ROLLBACK = "rollback";
-
-    /**
-     * Namespace for Rollback flags that are applied after a reboot.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_ROLLBACK_BOOT = "rollback_boot";
-
-    /**
-     * Namespace for Rotation Resolver Manager Service.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_ROTATION_RESOLVER = "rotation_resolver";
-
-    /**
-     * Namespace for all runtime related features that don't require a reboot to become active.
-     * There are no feature flags using NAMESPACE_RUNTIME.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_RUNTIME = "runtime";
-
-    /**
-     * Namespace for all runtime related features that require system properties for accessing
-     * the feature flags from C++ or Java language code. One example is the app image startup
-     * cache feature use_app_image_startup_cache.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_RUNTIME_NATIVE = "runtime_native";
-
-    /**
-     * Namespace for all runtime native boot related features. Boot in this case refers to the
-     * fact that the properties only take affect after rebooting the device.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_RUNTIME_NATIVE_BOOT = "runtime_native_boot";
-
-    /**
-     * Namespace for system scheduler related features. These features will be applied
-     * immediately upon change.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_SCHEDULER = "scheduler";
-
-    /**
-     * Namespace for all SdkSandbox related features.
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_SDK_SANDBOX = "sdk_sandbox";
-
-    /**
-     * Namespace for settings statistics features.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_SETTINGS_STATS = "settings_stats";
-
-    /**
-     * Namespace for all statsd java features that can be applied immediately.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_STATSD_JAVA = "statsd_java";
-
-    /**
-     * Namespace for all statsd java features that are applied on boot.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_STATSD_JAVA_BOOT = "statsd_java_boot";
-
-    /**
-     * Namespace for all statsd native features that can be applied immediately.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_STATSD_NATIVE = "statsd_native";
-
-    /**
-     * Namespace for all statsd native features that are applied on boot.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_STATSD_NATIVE_BOOT = "statsd_native_boot";
-
-    /**
-     * Namespace for storage-related features.
-     *
-     * @deprecated Replace storage namespace with storage_native_boot.
-     * @hide
-     */
-    @Deprecated
-    @SystemApi
-    public static final String NAMESPACE_STORAGE = "storage";
-
-    /**
-     * Namespace for storage-related features, including native and boot.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_STORAGE_NATIVE_BOOT = "storage_native_boot";
-
-    /**
-     * Namespace for all AdServices related features.
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_ADSERVICES = "adservices";
-
-    /**
-     * Namespace for all SurfaceFlinger features that are used at the native level.
-     * These features are applied on boot or after reboot.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_SURFACE_FLINGER_NATIVE_BOOT =
-            "surface_flinger_native_boot";
-
-    /**
-     * Namespace for swcodec native related features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_SWCODEC_NATIVE = "swcodec_native";
-
-
-    /**
-     * Namespace for System UI related features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_SYSTEMUI = "systemui";
-
-    /**
-     * Namespace for system time and time zone detection related features / behavior.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_SYSTEM_TIME = "system_time";
-
-    /**
-     * Namespace for TARE configurations.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_TARE = "tare";
-
-    /**
-     * Telephony related properties.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_TELEPHONY = "telephony";
-
-    /**
-     * Namespace for TextClassifier related features.
-     *
-     * @hide
-     * @see android.provider.Settings.Global.TEXT_CLASSIFIER_CONSTANTS
-     */
-    @SystemApi
-    public static final String NAMESPACE_TEXTCLASSIFIER = "textclassifier";
-
-    /**
-     * Namespace for contacts provider related features.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_CONTACTS_PROVIDER = "contacts_provider";
-
-    /**
-     * Namespace for settings ui related features
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_SETTINGS_UI = "settings_ui";
-
-    /**
-     * Namespace for android related features, i.e. for flags that affect not just a single
-     * component, but the entire system.
-     *
-     * The keys for this namespace are defined in {@link AndroidDeviceConfig}.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_ANDROID = "android";
-
-    /**
-     * Namespace for window manager related features.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_WINDOW_MANAGER = "window_manager";
-
-    /**
-     * Namespace for window manager features accessible by native code and
-     * loaded once per boot.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_WINDOW_MANAGER_NATIVE_BOOT = "window_manager_native_boot";
-
-    /**
-     * Definitions for selection toolbar related functions.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_SELECTION_TOOLBAR = "selection_toolbar";
-
-    /**
-     * Definitions for voice interaction related functions.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_VOICE_INTERACTION = "voice_interaction";
-
-    /**
-     * Namespace for DevicePolicyManager related features.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_DEVICE_POLICY_MANAGER =
-            "device_policy_manager";
-
-    /**
-     * List of namespaces which can be read without READ_DEVICE_CONFIG permission
-     *
-     * @hide
-     */
-    @NonNull
-    private static final List<String> PUBLIC_NAMESPACES =
-            Arrays.asList(NAMESPACE_TEXTCLASSIFIER, NAMESPACE_RUNTIME, NAMESPACE_STATSD_JAVA,
-                    NAMESPACE_STATSD_JAVA_BOOT, NAMESPACE_SELECTION_TOOLBAR, NAMESPACE_AUTOFILL,
-                    NAMESPACE_DEVICE_POLICY_MANAGER, NAMESPACE_CONTENT_CAPTURE);
-    /**
-     * Privacy related properties definitions.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_PRIVACY = "privacy";
-
-    /**
-     * Namespace for biometrics related features
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_BIOMETRICS = "biometrics";
-
-    /**
-     * Permission related properties definitions.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_PERMISSIONS = "permissions";
-
-    /**
-     * Namespace for ota related features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_OTA = "ota";
-
-    /**
-     * Namespace for all widget related features.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_WIDGET = "widget";
-
-    /**
-     * Namespace for connectivity thermal power manager features.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_CONNECTIVITY_THERMAL_POWER_MANAGER =
-            "connectivity_thermal_power_manager";
-
-    /**
-     * Namespace for configuration related features.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_CONFIGURATION = "configuration";
-
-    /**
-     * LatencyTracker properties definitions.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_LATENCY_TRACKER = "latency_tracker";
-
-    /**
-     * InteractionJankMonitor properties definitions.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    @SuppressLint("IntentName")
-    public static final String NAMESPACE_INTERACTION_JANK_MONITOR = "interaction_jank_monitor";
-
-    /**
-     * Namespace for game overlay related features.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_GAME_OVERLAY = "game_overlay";
-
-    /**
-     * Namespace for Android Virtualization Framework related features accessible by native code.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_VIRTUALIZATION_FRAMEWORK_NATIVE =
-            "virtualization_framework_native";
-
-    /**
-     * Namespace for Constrain Display APIs related features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_CONSTRAIN_DISPLAY_APIS = "constrain_display_apis";
-
-    /**
-     * Namespace for App Compat Overrides related features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_APP_COMPAT_OVERRIDES = "app_compat_overrides";
-
-    /**
-     * Namespace for all ultra wideband (uwb) related features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_UWB = "uwb";
-
-    /**
-     * Namespace for AmbientContextEventManagerService related features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_AMBIENT_CONTEXT_MANAGER_SERVICE =
-            "ambient_context_manager_service";
-
-    /**
-     * Namespace for WearableSensingManagerService related features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_WEARABLE_SENSING =
-            "wearable_sensing";
-
-    /**
-     * Namespace for Vendor System Native related features.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_VENDOR_SYSTEM_NATIVE = "vendor_system_native";
-
-    /**
-     * Namespace for Vendor System Native Boot related features.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_VENDOR_SYSTEM_NATIVE_BOOT = "vendor_system_native_boot";
-
-    /**
-     * Namespace for memory safety related features (e.g. MTE)
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_MEMORY_SAFETY_NATIVE = "memory_safety_native";
-
-    /**
-     * Namespace for wear OS platform features.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_WEAR = "wear";
-
-    /**
-     * Namespace for features relating to MBA transparency metadata.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_TRANSPARENCY_METADATA = "transparency_metadata";
-
-    /**
-     * Namespace for the input method manager platform features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_INPUT_METHOD_MANAGER = "input_method_manager";
-
-    /**
-     * Namespace for backup and restore service related features.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static final String NAMESPACE_BACKUP_AND_RESTORE = "backup_and_restore";
-
-    /**
-     * Namespace for ARC App Compat related features.
-     *
-     * @hide
-     */
-    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-    public static final String NAMESPACE_ARC_APP_COMPAT = "arc_app_compat";
-
-    private static final Object sLock = new Object();
-    @GuardedBy("sLock")
-    private static ArrayMap<OnPropertiesChangedListener, Pair<String, Executor>> sListeners =
-            new ArrayMap<>();
-    @GuardedBy("sLock")
-    private static Map<String, Pair<ContentObserver, Integer>> sNamespaces = new HashMap<>();
-    private static final String TAG = "DeviceConfig";
-
-    // Should never be invoked
-    private DeviceConfig() {
-    }
-
-    /**
-     * Look up the value of a property for a particular namespace.
-     *
-     * @param namespace The namespace containing the property to look up.
-     * @param name      The name of the property to look up.
-     * @return the corresponding value, or null if not present.
-     * @hide
-     */
-    @SystemApi
-    @RequiresPermission(READ_DEVICE_CONFIG)
-    public static String getProperty(@NonNull String namespace, @NonNull String name) {
-        // Fetch all properties for the namespace at once and cache them in the local process, so we
-        // incur the cost of the IPC less often. Lookups happen much more frequently than updates,
-        // and we want to optimize the former.
-        return getProperties(namespace, name).getString(name, null);
-    }
-
-    /**
-     * Look up the values of multiple properties for a particular namespace. The lookup is atomic,
-     * such that the values of these properties cannot change between the time when the first is
-     * fetched and the time when the last is fetched.
-     * <p>
-     * Each call to {@link #setProperties(Properties)} is also atomic and ensures that either none
-     * or all of the change is picked up here, but never only part of it.
-     *
-     * @param namespace The namespace containing the properties to look up.
-     * @param names     The names of properties to look up, or empty to fetch all properties for the
-     *                  given namespace.
-     * @return {@link Properties} object containing the requested properties. This reflects the
-     *     state of these properties at the time of the lookup, and is not updated to reflect any
-     *     future changes. The keyset of this Properties object will contain only the intersection
-     *     of properties already set and properties requested via the names parameter. Properties
-     *     that are already set but were not requested will not be contained here. Properties that
-     *     are not set, but were requested will not be contained here either.
-     * @hide
-     */
-    @SystemApi
-    @NonNull
-    @RequiresPermission(READ_DEVICE_CONFIG)
-    public static Properties getProperties(@NonNull String namespace, @NonNull String ... names) {
-        return new Properties(namespace,
-                Settings.Config.getStrings(namespace, Arrays.asList(names)));
-    }
-
-    /**
-     * Look up the String value of a property for a particular namespace.
-     *
-     * @param namespace    The namespace containing the property to look up.
-     * @param name         The name of the property to look up.
-     * @param defaultValue The value to return if the property does not exist or has no non-null
-     *                     value.
-     * @return the corresponding value, or defaultValue if none exists.
-     * @hide
-     */
-    @SystemApi
-    @RequiresPermission(READ_DEVICE_CONFIG)
-    public static String getString(@NonNull String namespace, @NonNull String name,
-            @Nullable String defaultValue) {
-        String value = getProperty(namespace, name);
-        return value != null ? value : defaultValue;
-    }
-
-    /**
-     * Look up the boolean value of a property for a particular namespace.
-     *
-     * @param namespace The namespace containing the property to look up.
-     * @param name      The name of the property to look up.
-     * @param defaultValue The value to return if the property does not exist or has no non-null
-     *                     value.
-     * @return the corresponding value, or defaultValue if none exists.
-     * @hide
-     */
-    @SystemApi
-    @RequiresPermission(READ_DEVICE_CONFIG)
-    public static boolean getBoolean(@NonNull String namespace, @NonNull String name,
-            boolean defaultValue) {
-        String value = getProperty(namespace, name);
-        return value != null ? Boolean.parseBoolean(value) : defaultValue;
-    }
-
-    /**
-     * Look up the int value of a property for a particular namespace.
-     *
-     * @param namespace The namespace containing the property to look up.
-     * @param name      The name of the property to look up.
-     * @param defaultValue The value to return if the property does not exist, has no non-null
-     *                     value, or fails to parse into an int.
-     * @return the corresponding value, or defaultValue if either none exists or it does not parse.
-     * @hide
-     */
-    @SystemApi
-    @RequiresPermission(READ_DEVICE_CONFIG)
-    public static int getInt(@NonNull String namespace, @NonNull String name, int defaultValue) {
-        String value = getProperty(namespace, name);
-        if (value == null) {
-            return defaultValue;
-        }
-        try {
-            return Integer.parseInt(value);
-        } catch (NumberFormatException e) {
-            Log.e(TAG, "Parsing integer failed for " + namespace + ":" + name);
-            return defaultValue;
-        }
-    }
-
-    /**
-     * Look up the long value of a property for a particular namespace.
-     *
-     * @param namespace The namespace containing the property to look up.
-     * @param name      The name of the property to look up.
-     * @param defaultValue The value to return if the property does not exist, has no non-null
-     *                     value, or fails to parse into a long.
-     * @return the corresponding value, or defaultValue if either none exists or it does not parse.
-     * @hide
-     */
-    @SystemApi
-    @RequiresPermission(READ_DEVICE_CONFIG)
-    public static long getLong(@NonNull String namespace, @NonNull String name, long defaultValue) {
-        String value = getProperty(namespace, name);
-        if (value == null) {
-            return defaultValue;
-        }
-        try {
-            return Long.parseLong(value);
-        } catch (NumberFormatException e) {
-            Log.e(TAG, "Parsing long failed for " + namespace + ":" + name);
-            return defaultValue;
-        }
-    }
-
-    /**
-     * Look up the float value of a property for a particular namespace.
-     *
-     * @param namespace The namespace containing the property to look up.
-     * @param name      The name of the property to look up.
-     * @param defaultValue The value to return if the property does not exist, has no non-null
-     *                     value, or fails to parse into a float.
-     * @return the corresponding value, or defaultValue if either none exists or it does not parse.
-     * @hide
-     */
-    @SystemApi
-    @RequiresPermission(READ_DEVICE_CONFIG)
-    public static float getFloat(@NonNull String namespace, @NonNull String name,
-            float defaultValue) {
-        String value = getProperty(namespace, name);
-        if (value == null) {
-            return defaultValue;
-        }
-        try {
-            return Float.parseFloat(value);
-        } catch (NumberFormatException e) {
-            Log.e(TAG, "Parsing float failed for " + namespace + ":" + name);
-            return defaultValue;
-        }
-    }
-
-    /**
-     * Create a new property with the provided name and value in the provided namespace, or
-     * update the value of such a property if it already exists. The same name can exist in multiple
-     * namespaces and might have different values in any or all namespaces.
-     * <p>
-     * The method takes an argument indicating whether to make the value the default for this
-     * property.
-     * <p>
-     * All properties stored for a particular scope can be reverted to their default values
-     * by passing the namespace to {@link #resetToDefaults(int, String)}.
-     *
-     * @param namespace   The namespace containing the property to create or update.
-     * @param name        The name of the property to create or update.
-     * @param value       The value to store for the property.
-     * @param makeDefault Whether to make the new value the default one.
-     * @return {@code true} if the value was set, {@code false} if the storage implementation throws
-     * errors.
-     * @hide
-     * @see #resetToDefaults(int, String).
-     */
-    @SystemApi
-    @RequiresPermission(WRITE_DEVICE_CONFIG)
-    public static boolean setProperty(@NonNull String namespace, @NonNull String name,
-            @Nullable String value, boolean makeDefault) {
-        return Settings.Config.putString(namespace, name, value, makeDefault);
-    }
-
-    /**
-     * Set all of the properties for a specific namespace. Pre-existing properties will be updated
-     * and new properties will be added if necessary. Any pre-existing properties for the specific
-     * namespace which are not part of the provided {@link Properties} object will be deleted from
-     * the namespace. These changes are all applied atomically, such that no calls to read or reset
-     * these properties can happen in the middle of this update.
-     * <p>
-     * Each call to {@link #getProperties(String, String...)} is also atomic and ensures that either
-     * none or all of this update is picked up, but never only part of it.
-     *
-     * @param properties the complete set of properties to set for a specific namespace.
-     * @throws BadConfigException if the provided properties are banned by RescueParty.
-     * @return {@code true} if the values were set, {@code false} otherwise.
-     * @hide
-     */
-    @SystemApi
-    @RequiresPermission(WRITE_DEVICE_CONFIG)
-    public static boolean setProperties(@NonNull Properties properties) throws BadConfigException {
-        return Settings.Config.setStrings(properties.getNamespace(),
-                properties.mMap);
-    }
-
-    /**
-     * Delete a property with the provided name and value in the provided namespace
-     *
-     * @param namespace   The namespace containing the property to delete.
-     * @param name        The name of the property to delete.
-     * @return {@code true} if the property was deleted or it did not exist in the first place.
-     * Return {@code false} if the storage implementation throws errors.
-     * @hide
-     */
-    @SystemApi
-    @RequiresPermission(WRITE_DEVICE_CONFIG)
-    public static boolean deleteProperty(@NonNull String namespace, @NonNull String name) {
-        return Settings.Config.deleteString(namespace, name);
-    }
-
-    /**
-     * Reset properties to their default values by removing the underlying values.
-     * <p>
-     * The method accepts an optional namespace parameter. If provided, only properties set within
-     * that namespace will be reset. Otherwise, all properties will be reset.
-     * <p>
-     * Note: This method should only be used by {@link com.android.server.RescueParty}. It was
-     * designed to be used in the event of boot or crash loops caused by flag changes. It does not
-     * revert flag values to defaults - instead it removes the property entirely which causes the
-     * consumer of the flag to use hardcoded defaults upon retrieval.
-     * <p>
-     * To clear values for a namespace without removing the underlying properties, construct a
-     * {@link Properties} object with the caller's namespace and either an empty flag map, or some
-     * snapshot of flag values. Then use {@link #setProperties(Properties)} to remove all flags
-     * under the namespace, or set them to the values in the snapshot.
-     * <p>
-     * To revert values for testing, one should mock DeviceConfig using
-     * {@link com.android.server.testables.TestableDeviceConfig} where possible. Otherwise, fallback
-     * to using {@link #setProperties(Properties)} as outlined above.
-     *
-     * @param resetMode The reset mode to use.
-     * @param namespace Optionally, the specific namespace which resets will be limited to.
-     * @hide
-     * @see #setProperty(String, String, String, boolean)
-     */
-    @SystemApi
-    @RequiresPermission(WRITE_DEVICE_CONFIG)
-    public static void resetToDefaults(@ResetMode int resetMode, @Nullable String namespace) {
-        Settings.Config.resetToDefaults(resetMode, namespace);
-    }
-
-    /**
-     * Disables or re-enables bulk modifications ({@link #setProperties(Properties)}) to device
-     * config values. This is intended for use during tests to prevent a sync operation clearing
-     * config values which could influence the outcome of the tests, i.e. by changing behavior.
-     *
-     * @param syncDisabledMode the mode to use, see {@link Settings.Config#SYNC_DISABLED_MODE_NONE},
-     *     {@link Settings.Config#SYNC_DISABLED_MODE_PERSISTENT} and {@link
-     *     Settings.Config#SYNC_DISABLED_MODE_UNTIL_REBOOT}
-     *
-     * @see #getSyncDisabledMode()
-     * @hide
-     */
-    @SystemApi
-    @RequiresPermission(WRITE_DEVICE_CONFIG)
-    public static void setSyncDisabledMode(@SyncDisabledMode int syncDisabledMode) {
-        Settings.Config.setSyncDisabledMode(syncDisabledMode);
-    }
-
-    /**
-     * Returns the current mode of sync disabling.
-     *
-     * @see #setSyncDisabledMode(int)
-     * @hide
-     */
-    @SystemApi
-    @RequiresPermission(WRITE_DEVICE_CONFIG)
-    public static @SyncDisabledMode int getSyncDisabledMode() {
-        return Settings.Config.getSyncDisabledMode();
-    }
-
-    /**
-     * Add a listener for property changes.
-     * <p>
-     * This listener will be called whenever properties in the specified namespace change. Callbacks
-     * will be made on the specified executor. Future calls to this method with the same listener
-     * will replace the old namespace and executor. Remove the listener entirely by calling
-     * {@link #removeOnPropertiesChangedListener(OnPropertiesChangedListener)}.
-     *
-     * @param namespace                   The namespace containing properties to monitor.
-     * @param executor                    The executor which will be used to run callbacks.
-     * @param onPropertiesChangedListener The listener to add.
-     * @hide
-     * @see #removeOnPropertiesChangedListener(OnPropertiesChangedListener)
-     */
-    @SystemApi
-    public static void addOnPropertiesChangedListener(
-            @NonNull String namespace,
-            @NonNull @CallbackExecutor Executor executor,
-            @NonNull OnPropertiesChangedListener onPropertiesChangedListener) {
-        synchronized (sLock) {
-            Pair<String, Executor> oldNamespace = sListeners.get(onPropertiesChangedListener);
-            if (oldNamespace == null) {
-                // Brand new listener, add it to the list.
-                sListeners.put(onPropertiesChangedListener, new Pair<>(namespace, executor));
-                incrementNamespace(namespace);
-            } else if (namespace.equals(oldNamespace.first)) {
-                // Listener is already registered for this namespace, update executor just in case.
-                sListeners.put(onPropertiesChangedListener, new Pair<>(namespace, executor));
-            } else {
-                // Update this listener from an old namespace to the new one.
-                decrementNamespace(sListeners.get(onPropertiesChangedListener).first);
-                sListeners.put(onPropertiesChangedListener, new Pair<>(namespace, executor));
-                incrementNamespace(namespace);
-            }
-        }
-    }
-
-    /**
-     * Remove a listener for property changes. The listener will receive no further notification of
-     * property changes.
-     *
-     * @param onPropertiesChangedListener The listener to remove.
-     * @hide
-     * @see #addOnPropertiesChangedListener(String, Executor, OnPropertiesChangedListener)
-     */
-    @SystemApi
-    public static void removeOnPropertiesChangedListener(
-            @NonNull OnPropertiesChangedListener onPropertiesChangedListener) {
-        Preconditions.checkNotNull(onPropertiesChangedListener);
-        synchronized (sLock) {
-            if (sListeners.containsKey(onPropertiesChangedListener)) {
-                decrementNamespace(sListeners.get(onPropertiesChangedListener).first);
-                sListeners.remove(onPropertiesChangedListener);
-            }
-        }
-    }
-
-    /**
-     * Increment the count used to represent the number of listeners subscribed to the given
-     * namespace. If this is the first (i.e. incrementing from 0 to 1) for the given namespace, a
-     * ContentObserver is registered.
-     *
-     * @param namespace The namespace to increment the count for.
-     */
-    @GuardedBy("sLock")
-    private static void incrementNamespace(@NonNull String namespace) {
-        Preconditions.checkNotNull(namespace);
-        Pair<ContentObserver, Integer> namespaceCount = sNamespaces.get(namespace);
-        if (namespaceCount != null) {
-            sNamespaces.put(namespace, new Pair<>(namespaceCount.first, namespaceCount.second + 1));
-        } else {
-            // This is a new namespace, register a ContentObserver for it.
-            ContentObserver contentObserver = new ContentObserver(null) {
-                @Override
-                public void onChange(boolean selfChange, Uri uri) {
-                    if (uri != null) {
-                        handleChange(uri);
-                    }
-                }
-            };
-            Settings.Config
-                    .registerContentObserver(namespace, true, contentObserver);
-            sNamespaces.put(namespace, new Pair<>(contentObserver, 1));
-        }
-    }
-
-    /**
-     * Decrement the count used to represent the number of listeners subscribed to the given
-     * namespace. If this is the final decrement call (i.e. decrementing from 1 to 0) for the given
-     * namespace, the ContentObserver that had been tracking it will be removed.
-     *
-     * @param namespace The namespace to decrement the count for.
-     */
-    @GuardedBy("sLock")
-    private static void decrementNamespace(@NonNull String namespace) {
-        Preconditions.checkNotNull(namespace);
-        Pair<ContentObserver, Integer> namespaceCount = sNamespaces.get(namespace);
-        if (namespaceCount == null) {
-            // This namespace is not registered and does not need to be decremented
-            return;
-        } else if (namespaceCount.second > 1) {
-            sNamespaces.put(namespace, new Pair<>(namespaceCount.first, namespaceCount.second - 1));
-        } else {
-            // Decrementing a namespace to zero means we no longer need its ContentObserver.
-            Settings.Config.unregisterContentObserver(namespaceCount.first);
-            sNamespaces.remove(namespace);
-        }
-    }
-
-    private static void handleChange(@NonNull Uri uri) {
-        Preconditions.checkNotNull(uri);
-        List<String> pathSegments = uri.getPathSegments();
-        // pathSegments(0) is "config"
-        final String namespace = pathSegments.get(1);
-        Properties.Builder propBuilder = new Properties.Builder(namespace);
-        try {
-            Properties allProperties = getProperties(namespace);
-            for (int i = 2; i < pathSegments.size(); ++i) {
-                String key = pathSegments.get(i);
-                propBuilder.setString(key, allProperties.getString(key, null));
-            }
-        } catch (SecurityException e) {
-            // Silently failing to not crash binder or listener threads.
-            Log.e(TAG, "OnPropertyChangedListener update failed: permission violation.");
-            return;
-        }
-        Properties properties = propBuilder.build();
-
-        synchronized (sLock) {
-            for (int i = 0; i < sListeners.size(); i++) {
-                if (namespace.equals(sListeners.valueAt(i).first)) {
-                    final OnPropertiesChangedListener listener = sListeners.keyAt(i);
-                    sListeners.valueAt(i).second.execute(() -> {
-                        listener.onPropertiesChanged(properties);
-                    });
-                }
-            }
-        }
-    }
-
-    /**
-     * Returns list of namespaces that can be read without READ_DEVICE_CONFIG_PERMISSION;
-     * @hide
-     */
-    @SystemApi
-    public static @NonNull List<String> getPublicNamespaces() {
-        return PUBLIC_NAMESPACES;
-    }
-
-    /**
-     * Interface for monitoring changes to properties. Implementations will receive callbacks when
-     * properties change, including a {@link Properties} object which contains a single namespace
-     * and all of the properties which changed for that namespace. This includes properties which
-     * were added, updated, or deleted. This is not necessarily a complete list of all properties
-     * belonging to the namespace, as properties which don't change are omitted.
-     * <p>
-     * Override {@link #onPropertiesChanged(Properties)} to handle callbacks for changes.
-     *
-     * @hide
-     */
-    @SystemApi
-    public interface OnPropertiesChangedListener {
-        /**
-         * Called when one or more properties have changed, providing a Properties object with all
-         * of the changed properties. This object will contain only properties which have changed,
-         * not the complete set of all properties belonging to the namespace.
-         *
-         * @param properties Contains the complete collection of properties which have changed for a
-         *                   single namespace. This includes only those which were added, updated,
-         *                   or deleted.
-         */
-        void onPropertiesChanged(@NonNull Properties properties);
-    }
-
-    /**
-     * Thrown by {@link #setProperties(Properties)} when a configuration is rejected. This
-     * happens if RescueParty has identified a bad configuration and reset the namespace.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static class BadConfigException extends Exception {}
-
-    /**
-     * A mapping of properties to values, as well as a single namespace which they all belong to.
-     *
-     * @hide
-     */
-    @SystemApi
-    public static class Properties {
-        private final String mNamespace;
-        private final HashMap<String, String> mMap;
-        private Set<String> mKeyset;
-
-        /**
-         * Create a mapping of properties to values and the namespace they belong to.
-         *
-         * @param namespace The namespace these properties belong to.
-         * @param keyValueMap A map between property names and property values.
-         * @hide
-         */
-        @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
-        public Properties(@NonNull String namespace, @Nullable Map<String, String> keyValueMap) {
-            Preconditions.checkNotNull(namespace);
-            mNamespace = namespace;
-            mMap = new HashMap();
-            if (keyValueMap != null) {
-                mMap.putAll(keyValueMap);
-            }
-        }
-
-        /**
-         * @return the namespace all properties within this instance belong to.
-         */
-        @NonNull
-        public String getNamespace() {
-            return mNamespace;
-        }
-
-        /**
-         * @return the non-null set of property names.
-         */
-        @NonNull
-        public Set<String> getKeyset() {
-            if (mKeyset == null) {
-                mKeyset = Collections.unmodifiableSet(mMap.keySet());
-            }
-            return mKeyset;
-        }
-
-        /**
-         * Look up the String value of a property.
-         *
-         * @param name         The name of the property to look up.
-         * @param defaultValue The value to return if the property has not been defined.
-         * @return the corresponding value, or defaultValue if none exists.
-         */
-        @Nullable
-        public String getString(@NonNull String name, @Nullable String defaultValue) {
-            Preconditions.checkNotNull(name);
-            String value = mMap.get(name);
-            return value != null ? value : defaultValue;
-        }
-
-        /**
-         * Look up the boolean value of a property.
-         *
-         * @param name         The name of the property to look up.
-         * @param defaultValue The value to return if the property has not been defined.
-         * @return the corresponding value, or defaultValue if none exists.
-         */
-        public boolean getBoolean(@NonNull String name, boolean defaultValue) {
-            Preconditions.checkNotNull(name);
-            String value = mMap.get(name);
-            return value != null ? Boolean.parseBoolean(value) : defaultValue;
-        }
-
-        /**
-         * Look up the int value of a property.
-         *
-         * @param name         The name of the property to look up.
-         * @param defaultValue The value to return if the property has not been defined or fails to
-         *                     parse into an int.
-         * @return the corresponding value, or defaultValue if no valid int is available.
-         */
-        public int getInt(@NonNull String name, int defaultValue) {
-            Preconditions.checkNotNull(name);
-            String value = mMap.get(name);
-            if (value == null) {
-                return defaultValue;
-            }
-            try {
-                return Integer.parseInt(value);
-            } catch (NumberFormatException e) {
-                Log.e(TAG, "Parsing int failed for " + name);
-                return defaultValue;
-            }
-        }
-
-        /**
-         * Look up the long value of a property.
-         *
-         * @param name         The name of the property to look up.
-         * @param defaultValue The value to return if the property has not been defined. or fails to
-         *                     parse into a long.
-         * @return the corresponding value, or defaultValue if no valid long is available.
-         */
-        public long getLong(@NonNull String name, long defaultValue) {
-            Preconditions.checkNotNull(name);
-            String value = mMap.get(name);
-            if (value == null) {
-                return defaultValue;
-            }
-            try {
-                return Long.parseLong(value);
-            } catch (NumberFormatException e) {
-                Log.e(TAG, "Parsing long failed for " + name);
-                return defaultValue;
-            }
-        }
-
-        /**
-         * Look up the int value of a property.
-         *
-         * @param name         The name of the property to look up.
-         * @param defaultValue The value to return if the property has not been defined. or fails to
-         *                     parse into a float.
-         * @return the corresponding value, or defaultValue if no valid float is available.
-         */
-        public float getFloat(@NonNull String name, float defaultValue) {
-            Preconditions.checkNotNull(name);
-            String value = mMap.get(name);
-            if (value == null) {
-                return defaultValue;
-            }
-            try {
-                return Float.parseFloat(value);
-            } catch (NumberFormatException e) {
-                Log.e(TAG, "Parsing float failed for " + name);
-                return defaultValue;
-            }
-        }
-
-        /**
-         * Builder class for the construction of {@link Properties} objects.
-         */
-        public static final class Builder {
-            @NonNull
-            private final String mNamespace;
-            @NonNull
-            private final Map<String, String> mKeyValues = new HashMap<>();
-
-            /**
-             * Create a new Builders for the specified namespace.
-             * @param namespace non null namespace.
-             */
-            public Builder(@NonNull String namespace) {
-                mNamespace = namespace;
-            }
-
-            /**
-             * Add a new property with the specified key and value.
-             * @param name non null name of the property.
-             * @param value nullable string value of the property.
-             * @return this Builder object
-             */
-            @NonNull
-            public Builder setString(@NonNull String name, @Nullable String value) {
-                mKeyValues.put(name, value);
-                return this;
-            }
-
-            /**
-             * Add a new property with the specified key and value.
-             * @param name non null name of the property.
-             * @param value nullable string value of the property.
-             * @return this Builder object
-             */
-            @NonNull
-            public Builder setBoolean(@NonNull String name, boolean value) {
-                mKeyValues.put(name, Boolean.toString(value));
-                return this;
-            }
-
-            /**
-             * Add a new property with the specified key and value.
-             * @param name non null name of the property.
-             * @param value int value of the property.
-             * @return this Builder object
-             */
-            @NonNull
-            public Builder setInt(@NonNull String name, int value) {
-                mKeyValues.put(name, Integer.toString(value));
-                return this;
-            }
-
-            /**
-             * Add a new property with the specified key and value.
-             * @param name non null name of the property.
-             * @param value long value of the property.
-             * @return this Builder object
-             */
-            @NonNull
-            public Builder setLong(@NonNull String name, long value) {
-                mKeyValues.put(name, Long.toString(value));
-                return this;
-            }
-
-            /**
-             * Add a new property with the specified key and value.
-             * @param name non null name of the property.
-             * @param value float value of the property.
-             * @return this Builder object
-             */
-            @NonNull
-            public Builder setFloat(@NonNull String name, float value) {
-                mKeyValues.put(name, Float.toString(value));
-                return this;
-            }
-
-            /**
-             * Create a new {@link Properties} object.
-             * @return non null Properties.
-             */
-            @NonNull
-            public Properties build() {
-                return new Properties(mNamespace, mKeyValues);
-            }
-        }
-    }
-
-}
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 03846db..90aca14 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -4638,21 +4638,6 @@
         public static final String SCREEN_BRIGHTNESS = "screen_brightness";
 
         /**
-         * The screen backlight brightness between 0 and 255.
-         * @hide
-         */
-        @Readable
-        public static final String SCREEN_BRIGHTNESS_FOR_VR = "screen_brightness_for_vr";
-
-        /**
-         * The screen backlight brightness between 0.0f and 1.0f.
-         * @hide
-         */
-        @Readable
-        public static final String SCREEN_BRIGHTNESS_FOR_VR_FLOAT =
-                "screen_brightness_for_vr_float";
-
-        /**
          * The screen backlight brightness between 0.0f and 1.0f.
          * @hide
          */
@@ -5637,8 +5622,6 @@
             PUBLIC_SETTINGS.add(SCREEN_OFF_TIMEOUT);
             PUBLIC_SETTINGS.add(SCREEN_BRIGHTNESS);
             PUBLIC_SETTINGS.add(SCREEN_BRIGHTNESS_FLOAT);
-            PUBLIC_SETTINGS.add(SCREEN_BRIGHTNESS_FOR_VR);
-            PUBLIC_SETTINGS.add(SCREEN_BRIGHTNESS_FOR_VR_FLOAT);
             PUBLIC_SETTINGS.add(SCREEN_BRIGHTNESS_MODE);
             PUBLIC_SETTINGS.add(MODE_RINGER_STREAMS_AFFECTED);
             PUBLIC_SETTINGS.add(MUTE_STREAMS_AFFECTED);
@@ -6227,6 +6210,7 @@
             MOVED_TO_GLOBAL.add(Settings.Global.DEFAULT_DNS_SERVER);
             MOVED_TO_GLOBAL.add(Settings.Global.PREFERRED_NETWORK_MODE);
             MOVED_TO_GLOBAL.add(Settings.Global.WEBVIEW_DATA_REDUCTION_PROXY_KEY);
+            MOVED_TO_GLOBAL.add(Settings.Global.SECURE_FRP_MODE);
         }
 
         /** @hide */
@@ -7089,7 +7073,10 @@
          * device is removed from this mode.
          * <p>
          * Type: int (0 for false, 1 for true)
+         *
+         * @deprecated Use Global.SECURE_FRP_MODE
          */
+        @Deprecated
         @Readable
         public static final String SECURE_FRP_MODE = "secure_frp_mode";
 
@@ -9370,6 +9357,14 @@
         public static final int DOCK_SETUP_PAUSED = 2;
 
         /**
+         * Indicates that the user has been prompted to start dock setup.
+         * One of the possible states for {@link #DOCK_SETUP_STATE}.
+         *
+         * @hide
+         */
+        public static final int DOCK_SETUP_PROMPTED = 3;
+
+        /**
          * Indicates that the user has completed dock setup.
          * One of the possible states for {@link #DOCK_SETUP_STATE}.
          *
@@ -9383,6 +9378,7 @@
                 DOCK_SETUP_NOT_STARTED,
                 DOCK_SETUP_STARTED,
                 DOCK_SETUP_PAUSED,
+                DOCK_SETUP_PROMPTED,
                 DOCK_SETUP_COMPLETED
         })
         public @interface DockSetupState {
@@ -11905,7 +11901,21 @@
         public static final String DEVICE_PROVISIONED = "device_provisioned";
 
         /**
-         * Whether bypassing the device policy management role holder qualifcation is allowed,
+         * Indicates whether the device is under restricted secure FRP mode.
+         * Secure FRP mode is enabled when the device is under FRP. On solving of FRP challenge,
+         * device is removed from this mode.
+         * <p>
+         * Type: int (0 for false, 1 for true)
+         *
+         * @hide
+         */
+        @SystemApi
+        @Readable
+        @SuppressLint("NoSettingsProvider")
+        public static final String SECURE_FRP_MODE = "secure_frp_mode";
+
+        /**
+         * Whether bypassing the device policy management role holder qualification is allowed,
          * (0 = false, 1 = true).
          *
          * @hide
diff --git a/core/java/android/security/rkp/IGetKeyCallback.aidl b/core/java/android/security/rkp/IGetKeyCallback.aidl
new file mode 100644
index 0000000..85ceae62
--- /dev/null
+++ b/core/java/android/security/rkp/IGetKeyCallback.aidl
@@ -0,0 +1,49 @@
+/*
+ * 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 android.security.rkp;
+
+import android.security.rkp.RemotelyProvisionedKey;
+
+/**
+ * Callback interface for receiving remotely provisioned keys from a
+ * {@link IRegistration}.
+ *
+ * @hide
+ */
+oneway interface IGetKeyCallback {
+    /**
+     * Called in response to {@link IRegistration.getKey}, indicating
+     * a remotely-provisioned key is available.
+     *
+     * @param key The key that was received from the remote provisioning service.
+     */
+    void onSuccess(in RemotelyProvisionedKey key);
+
+    /**
+     * Called when the key request has been successfully cancelled.
+     * @see IRegistration.cancelGetKey
+     */
+    void onCancel();
+
+    /**
+     * Called when an error has occurred while trying to get a remotely provisioned key.
+     *
+     * @param error A description of what failed, suitable for logging.
+     */
+    void onError(String error);
+}
+
diff --git a/core/java/android/security/rkp/IGetRegistrationCallback.aidl b/core/java/android/security/rkp/IGetRegistrationCallback.aidl
new file mode 100644
index 0000000..e375a6f
--- /dev/null
+++ b/core/java/android/security/rkp/IGetRegistrationCallback.aidl
@@ -0,0 +1,49 @@
+/*
+ * 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 android.security.rkp;
+
+import android.security.rkp.IRegistration;
+
+/**
+ * Callback interface for receiving a remote provisioning registration.
+ * {@link IRegistration}.
+ *
+ * @hide
+ */
+oneway interface IGetRegistrationCallback {
+    /**
+     * Called in response to {@link IRemoteProvisioning.getRegistration}.
+     *
+     * @param registration an IRegistration that is used to fetch remotely
+     * provisioned keys for the given IRemotelyProvisionedComponent.
+     */
+    void onSuccess(in IRegistration registration);
+
+    /**
+     * Called when the get registration request has been successfully cancelled.
+     * @see IRemoteProvisioning.cancelGetRegistration
+     */
+    void onCancel();
+
+    /**
+     * Called when an error has occurred while trying to get a registration.
+     *
+     * @param error A description of what failed, suitable for logging.
+     */
+    void onError(String error);
+}
+
diff --git a/core/java/android/security/rkp/IRegistration.aidl b/core/java/android/security/rkp/IRegistration.aidl
new file mode 100644
index 0000000..6522a45
--- /dev/null
+++ b/core/java/android/security/rkp/IRegistration.aidl
@@ -0,0 +1,85 @@
+/*
+ * 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 android.security.rkp;
+
+import android.security.rkp.IGetKeyCallback;
+
+/**
+ * This interface is associated with the registration of an
+ * IRemotelyProvisionedComponent. Each component has a unique set of keys
+ * and certificates that are provisioned to the device for attestation. An
+ * IRegistration binder is created by calling
+ * {@link IRemoteProvisioning#getRegistration()}.
+ *
+ * This interface is used to query for available keys and certificates for the
+ * registered component.
+ *
+ * @hide
+ */
+oneway interface IRegistration {
+    /**
+     * Fetch a remotely provisioned key for the given keyId. Keys are unique
+     * per caller/keyId/registration tuple. This ensures that no two
+     * applications are able to correlate keys to uniquely identify a
+     * device/user. Callers receive their key via {@code callback}.
+     *
+     * If a key is available, this call immediately invokes {@code callback}.
+     *
+     * If no keys are immediately available, then this function contacts the
+     * remote provisioning server to provision a key. After provisioning is
+     * completed, the key is passed to {@code callback}.
+     *
+     * @param keyId This is a client-chosen key identifier, used to
+     * differentiate between keys for varying client-specific use-cases. For
+     * example, keystore2 passes the UID of the applications that call it as
+     * the keyId value here, so that each of keystore2's clients gets a unique
+     * key.
+     * @param callback Receives the result of the call. A callback must only
+     * be used with one {@code getKey} call at a time.
+     */
+    void getKey(int keyId, IGetKeyCallback callback);
+
+    /**
+     * Cancel an active request for a remotely provisioned key, as initiated via
+     * {@link getKey}. Upon cancellation, {@code callback.onCancel} will be invoked.
+     */
+    void cancelGetKey(IGetKeyCallback callback);
+
+    /**
+     * Replace an obsolete key blob with an upgraded key blob.
+     * In certain cases, such as security patch level upgrade, keys become "old".
+     * In these cases, the component which supports operations with the remotely
+     * provisioned key blobs must support upgrading the blobs to make them "new"
+     * and usable on the updated system.
+     *
+     * For an example of a remotely provisioned component that has an upgrade
+     * mechanism, see the documentation for IKeyMintDevice.upgradeKey.
+     *
+     * Once a key has been upgraded, the IRegistration where the key is stored
+     * needs to be told about the new blob. After calling storeUpgradedKey,
+     * getKey will return the new key blob instead of the old one.
+     *
+     * Note that this function does NOT extend the lifetime of key blobs. The
+     * certificate for the key is unchanged, and the key will still expire at
+     * the same time it would have if storeUpgradedKey had never been called.
+     *
+     * @param oldKeyBlob The old key blob to be replaced by {@code newKeyBlob}.
+     *
+     * @param newKeyblob The new blob to replace {@code oldKeyBlob}.
+     */
+    void storeUpgradedKey(in byte[] oldKeyBlob, in byte[] newKeyBlob);
+}
diff --git a/core/java/android/security/rkp/IRemoteProvisioning.aidl b/core/java/android/security/rkp/IRemoteProvisioning.aidl
new file mode 100644
index 0000000..23d8159
--- /dev/null
+++ b/core/java/android/security/rkp/IRemoteProvisioning.aidl
@@ -0,0 +1,68 @@
+/*
+ * 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 android.security.rkp;
+
+import android.security.rkp.IRegistration;
+import android.security.rkp.IGetRegistrationCallback;
+
+/**
+ * {@link IRemoteProvisioning} is the interface provided to use the remote key
+ * provisioning functionality from the Remote Key Provisioning Daemon (RKPD).
+ * This would be the first service that RKPD clients would interact with. The
+ * intent is for the clients to get the {@link IRegistration} object from this
+ * interface and use it for actual remote provisioning work.
+ *
+ * @hide
+ */
+oneway interface IRemoteProvisioning {
+    /**
+     * Takes a remotely provisioned component service name and gets a
+     * registration bound to that service and the caller's UID.
+     *
+     * @param irpcName The name of the {@code IRemotelyProvisionedComponent}
+     * for which remotely provisioned keys should be managed.
+     * @param callback Receives the result of the call. A callback must only
+     * be used with one {@code getRegistration} call at a time.
+     *
+     * Notes:
+     * - This function will attempt to get the service named by irpcName. This
+     *   implies that a lazy/dynamic aidl service will be instantiated, and this
+     *   function blocks until the service is up. Upon return, any binder tokens
+     *   are dropped, allowing the lazy/dynamic service to shutdown.
+     * - The created registration object is unique per caller. If two different
+     *   UIDs call getRegistration with the same irpcName, they will receive
+     *   different registrations. This prevents two different applications from
+     *   being able to see the same keys.
+     * - This function is idempotent per calling UID. Additional calls to
+     *   getRegistration with the same parameters, from the same caller, will have
+     *   no side effects.
+     * - A callback may only be associated with one getRegistration call at a time.
+     *   If the callback is used multiple times, this API will return an error.
+     *
+     * @see IRegistration#getKey()
+     * @see IRemotelyProvisionedComponent
+     *
+     */
+    void getRegistration(String irpcName, IGetRegistrationCallback callback);
+
+    /**
+     * Cancel any active {@link getRegistration} call associated with the given
+     * callback. If no getRegistration call is currently active, this function is
+     * a noop.
+     */
+    void cancelGetRegistration(IGetRegistrationCallback callback);
+}
diff --git a/core/java/android/security/rkp/OWNERS b/core/java/android/security/rkp/OWNERS
new file mode 100644
index 0000000..fd43089
--- /dev/null
+++ b/core/java/android/security/rkp/OWNERS
@@ -0,0 +1,5 @@
+# Bug component: 1084908
+
+jbires@google.com
+sethmo@google.com
+vikramgaur@google.com
diff --git a/core/java/android/security/rkp/RemotelyProvisionedKey.aidl b/core/java/android/security/rkp/RemotelyProvisionedKey.aidl
new file mode 100644
index 0000000..207f18f
--- /dev/null
+++ b/core/java/android/security/rkp/RemotelyProvisionedKey.aidl
@@ -0,0 +1,44 @@
+/*
+ * Copyright 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 android.security.rkp;
+
+/**
+ * A {@link RemotelyProvisionedKey} holds an attestation key and the
+ * corresponding remotely provisioned certificate chain.
+ *
+ * @hide
+ */
+@RustDerive(Eq=true, PartialEq=true)
+parcelable RemotelyProvisionedKey {
+    /**
+     * The remotely-provisioned key that may be used to sign attestations. The
+     * format of this key is opaque, and need only be understood by the
+     * IRemotelyProvisionedComponent that generated it.
+     *
+     * Any private key material contained within this blob must be encrypted.
+     *
+     * @see IRemotelyProvisionedComponent
+     */
+    byte[] keyBlob;
+
+    /**
+     * Sequence of DER-encoded X.509 certificates that make up the attestation
+     * key's certificate chain. This is the binary encoding for a chain that is
+     * supported by Java's CertificateFactory.generateCertificates API.
+     */
+    byte[] encodedCertChain;
+}
diff --git a/core/java/android/service/controls/ControlsProviderService.java b/core/java/android/service/controls/ControlsProviderService.java
index d2a4ae2..9396a88 100644
--- a/core/java/android/service/controls/ControlsProviderService.java
+++ b/core/java/android/service/controls/ControlsProviderService.java
@@ -69,6 +69,18 @@
             "android.service.controls.META_DATA_PANEL_ACTIVITY";
 
     /**
+     * Boolean extra containing the value of
+     * {@link android.provider.Settings.Secure#LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS}.
+     *
+     * This is passed with the intent when the panel specified by {@link #META_DATA_PANEL_ACTIVITY}
+     * is launched.
+     *
+     * @hide
+     */
+    public static final String EXTRA_LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS =
+            "android.service.controls.EXTRA_LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS";
+
+    /**
      * @hide
      */
     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
diff --git a/core/java/android/service/credentials/Action.java b/core/java/android/service/credentials/Action.java
index 7757081..42dd528 100644
--- a/core/java/android/service/credentials/Action.java
+++ b/core/java/android/service/credentials/Action.java
@@ -42,7 +42,7 @@
      * level authentication before displaying any content etc.
      *
      * <p> See details on usage of {@code Action} for various actionable entries in
-     * {@link BeginCreateCredentialResponse} and {@link GetCredentialsResponse}.
+     * {@link BeginCreateCredentialResponse} and {@link BeginGetCredentialsResponse}.
      *
      * @param slice the display content to be displayed on the UI, along with this action
      * @param pendingIntent the intent to be invoked when the user selects this action
diff --git a/core/java/android/service/credentials/BeginCreateCredentialResponse.java b/core/java/android/service/credentials/BeginCreateCredentialResponse.java
index 022678e..8ca3a1a 100644
--- a/core/java/android/service/credentials/BeginCreateCredentialResponse.java
+++ b/core/java/android/service/credentials/BeginCreateCredentialResponse.java
@@ -127,7 +127,7 @@
          *
          * <p> Once the remote credential flow is complete, the {@link android.app.Activity}
          * result should be set to {@link android.app.Activity#RESULT_OK} and an extra with the
-         * {@link CredentialProviderService#EXTRA_CREATE_CREDENTIAL_RESULT} key should be populated
+         * {@link CredentialProviderService#EXTRA_CREATE_CREDENTIAL_RESPONSE} key should be populated
          * with a {@link android.credentials.CreateCredentialResponse} object.
          */
         public @NonNull Builder setRemoteCreateEntry(@Nullable CreateEntry remoteCreateEntry) {
diff --git a/core/java/android/service/credentials/BeginGetCredentialOption.java b/core/java/android/service/credentials/BeginGetCredentialOption.java
new file mode 100644
index 0000000..c82b445
--- /dev/null
+++ b/core/java/android/service/credentials/BeginGetCredentialOption.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright 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 android.service.credentials;
+
+import static java.util.Objects.requireNonNull;
+
+import android.annotation.NonNull;
+import android.os.Bundle;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import com.android.internal.util.AnnotationValidations;
+import com.android.internal.util.Preconditions;
+
+/**
+ * A specific type of credential request to be sent to the provider during the query phase of
+ * a get flow. This request contains limited parameters needed to populate a list of
+ * {@link CredentialEntry} on the {@link BeginGetCredentialsResponse}.
+ */
+public final class BeginGetCredentialOption implements Parcelable {
+
+    /**
+     * The requested credential type.
+     */
+    @NonNull
+    private final String mType;
+
+    /**
+     * The request candidateQueryData.
+     */
+    @NonNull
+    private final Bundle mCandidateQueryData;
+
+    /**
+     * Returns the requested credential type.
+     */
+    @NonNull
+    public String getType() {
+        return mType;
+    }
+
+    /**
+     * Returns the request candidate query data, denoting a set of parameters
+     * that can be used to populate a candidate list of credentials, as
+     * {@link CredentialEntry} on {@link BeginGetCredentialsResponse}. This list
+     * of entries is then presented to the user on a selector.
+     *
+     * <p>This data does not contain any sensitive parameters, and will be sent
+     * to all eligible providers.
+     * The complete set of parameters will only be set on the {@link android.app.PendingIntent}
+     * set on the {@link CredentialEntry} that is selected by the user.
+     */
+    @NonNull
+    public Bundle getCandidateQueryData() {
+        return mCandidateQueryData;
+    }
+
+    @Override
+    public void writeToParcel(@NonNull Parcel dest, int flags) {
+        dest.writeString8(mType);
+        dest.writeBundle(mCandidateQueryData);
+    }
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public String toString() {
+        return "GetCredentialOption {"
+                + "type=" + mType
+                + ", candidateQueryData=" + mCandidateQueryData
+                + "}";
+    }
+
+    /**
+     * Constructs a {@link BeginGetCredentialOption}.
+     *
+     * @param type the requested credential type
+     * @param candidateQueryData the request candidateQueryData
+     *
+     * @throws IllegalArgumentException If type is empty.
+     */
+    public BeginGetCredentialOption(
+            @NonNull String type,
+            @NonNull Bundle candidateQueryData) {
+        mType = Preconditions.checkStringNotEmpty(type, "type must not be empty");
+        mCandidateQueryData = requireNonNull(
+                candidateQueryData, "candidateQueryData must not be null");
+    }
+
+    private BeginGetCredentialOption(@NonNull Parcel in) {
+        String type = in.readString8();
+        Bundle candidateQueryData = in.readBundle();
+
+        mType = type;
+        AnnotationValidations.validate(NonNull.class, null, mType);
+        mCandidateQueryData = candidateQueryData;
+        AnnotationValidations.validate(NonNull.class, null, mCandidateQueryData);
+    }
+
+    public static final @NonNull Creator<BeginGetCredentialOption> CREATOR =
+            new Creator<BeginGetCredentialOption>() {
+                @Override
+                public BeginGetCredentialOption[] newArray(int size) {
+                    return new BeginGetCredentialOption[size];
+                }
+
+                @Override
+                public BeginGetCredentialOption createFromParcel(@NonNull Parcel in) {
+                    return new BeginGetCredentialOption(in);
+                }
+            };
+}
diff --git a/core/java/android/service/credentials/BeginGetCredentialsRequest.aidl b/core/java/android/service/credentials/BeginGetCredentialsRequest.aidl
new file mode 100644
index 0000000..5e1fe8ab
--- /dev/null
+++ b/core/java/android/service/credentials/BeginGetCredentialsRequest.aidl
@@ -0,0 +1,3 @@
+package android.service.credentials;
+
+parcelable BeginGetCredentialsRequest;
\ No newline at end of file
diff --git a/core/java/android/service/credentials/BeginGetCredentialsRequest.java b/core/java/android/service/credentials/BeginGetCredentialsRequest.java
new file mode 100644
index 0000000..795840b
--- /dev/null
+++ b/core/java/android/service/credentials/BeginGetCredentialsRequest.java
@@ -0,0 +1,175 @@
+/*
+ * 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 android.service.credentials;
+
+import android.annotation.NonNull;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.credentials.GetCredentialOption;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import com.android.internal.util.AnnotationValidations;
+import com.android.internal.util.Preconditions;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Query stage request for getting user's credentials from a given credential provider.
+ *
+ * <p>This request contains a list of {@link GetCredentialOption} that have parameters
+ * to be used to query credentials, and return a list of {@link CredentialEntry} to be set
+ * on the {@link BeginGetCredentialsResponse}. This list is then shown to the user on a selector.
+ *
+ * If a {@link PendingIntent} is set on a {@link CredentialEntry}, and the user selects that
+ * entry, a {@link GetCredentialRequest} with all parameters needed to get the actual
+ * {@link android.credentials.Credential} will be sent as part of the {@link Intent} fired
+ * through the {@link PendingIntent}.
+ */
+public final class BeginGetCredentialsRequest implements Parcelable {
+    /** Calling package of the app requesting for credentials. */
+    @NonNull private final String mCallingPackage;
+
+    /**
+     * List of credential options. Each {@link BeginGetCredentialOption} object holds parameters to
+     * be used for populating a list of {@link CredentialEntry} for a specific type of credential.
+     *
+     * This request does not reveal sensitive parameters. Complete list of parameters
+     * is retrieved through the {@link PendingIntent} set on each {@link CredentialEntry}
+     * on {@link CredentialsResponseContent} set on {@link BeginGetCredentialsResponse},
+     * when the user selects one of these entries.
+     */
+    @NonNull private final List<BeginGetCredentialOption> mBeginGetCredentialOptions;
+
+    private BeginGetCredentialsRequest(@NonNull String callingPackage,
+            @NonNull List<BeginGetCredentialOption> getBeginCredentialOptions) {
+        this.mCallingPackage = callingPackage;
+        this.mBeginGetCredentialOptions = getBeginCredentialOptions;
+    }
+
+    private BeginGetCredentialsRequest(@NonNull Parcel in) {
+        mCallingPackage = in.readString8();
+        List<BeginGetCredentialOption> getBeginCredentialOptions = new ArrayList<>();
+        in.readTypedList(getBeginCredentialOptions, BeginGetCredentialOption.CREATOR);
+        mBeginGetCredentialOptions = getBeginCredentialOptions;
+        AnnotationValidations.validate(NonNull.class, null, mBeginGetCredentialOptions);
+    }
+
+    public static final @NonNull Creator<BeginGetCredentialsRequest> CREATOR =
+            new Creator<BeginGetCredentialsRequest>() {
+                @Override
+                public BeginGetCredentialsRequest createFromParcel(Parcel in) {
+                    return new BeginGetCredentialsRequest(in);
+                }
+
+                @Override
+                public BeginGetCredentialsRequest[] newArray(int size) {
+                    return new BeginGetCredentialsRequest[size];
+                }
+            };
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public void writeToParcel(@NonNull Parcel dest, int flags) {
+        dest.writeString8(mCallingPackage);
+        dest.writeTypedList(mBeginGetCredentialOptions);
+    }
+
+    /**
+     * Returns the calling package of the app requesting credentials.
+     */
+    public @NonNull String getCallingPackage() {
+        return mCallingPackage;
+    }
+
+    /**
+     * Returns the list of type specific credential options to list credentials for in
+     * {@link BeginGetCredentialsResponse}.
+     */
+    public @NonNull List<BeginGetCredentialOption> getBeginGetCredentialOptions() {
+        return mBeginGetCredentialOptions;
+    }
+
+    /**
+     * Builder for {@link BeginGetCredentialsRequest}.
+     */
+    public static final class Builder {
+        private String mCallingPackage;
+        private List<BeginGetCredentialOption> mBeginGetCredentialOptions = new ArrayList<>();
+
+        /**
+         * Creates a new builder.
+         * @param callingPackage the calling package of the app requesting credentials
+         *
+         * @throws IllegalArgumentException If {@code callingPackage} is null or empty.
+         */
+        public Builder(@NonNull String callingPackage) {
+            mCallingPackage = Preconditions.checkStringNotEmpty(callingPackage);
+        }
+
+        /**
+         * Sets the list of credential options.
+         *
+         * @throws NullPointerException If {@code getBeginCredentialOptions} itself or any of its
+         * elements is null.
+         * @throws IllegalArgumentException If {@code getBeginCredentialOptions} is empty.
+         */
+        public @NonNull Builder setBeginGetCredentialOptions(
+                @NonNull List<BeginGetCredentialOption> getBeginCredentialOptions) {
+            Preconditions.checkCollectionNotEmpty(getBeginCredentialOptions,
+                    "getBeginCredentialOptions");
+            Preconditions.checkCollectionElementsNotNull(getBeginCredentialOptions,
+                    "getBeginCredentialOptions");
+            mBeginGetCredentialOptions = getBeginCredentialOptions;
+            return this;
+        }
+
+        /**
+         * Adds a single {@link BeginGetCredentialOption} object to the list of credential options.
+         *
+         * @throws NullPointerException If {@code beginGetCredentialOption} is null.
+         */
+        public @NonNull Builder addBeginGetCredentialOption(
+                @NonNull BeginGetCredentialOption beginGetCredentialOption) {
+            Objects.requireNonNull(beginGetCredentialOption,
+                    "beginGetCredentialOption must not be null");
+            mBeginGetCredentialOptions.add(beginGetCredentialOption);
+            return this;
+        }
+
+        /**
+         * Builds a new {@link BeginGetCredentialsRequest} instance.
+         *
+         * @throws NullPointerException If {@code beginGetCredentialOptions} is null.
+         * @throws IllegalArgumentException If {@code beginGetCredentialOptions} is empty, or if
+         * {@code callingPackage} is null or empty.
+         */
+        public @NonNull BeginGetCredentialsRequest build() {
+            Preconditions.checkStringNotEmpty(mCallingPackage,
+                    "Must set the calling package");
+            Preconditions.checkCollectionNotEmpty(mBeginGetCredentialOptions,
+                    "beginGetCredentialOptions");
+            return new BeginGetCredentialsRequest(mCallingPackage, mBeginGetCredentialOptions);
+        }
+    }
+}
diff --git a/core/java/android/service/credentials/BeginGetCredentialsResponse.aidl b/core/java/android/service/credentials/BeginGetCredentialsResponse.aidl
new file mode 100644
index 0000000..ca69bca
--- /dev/null
+++ b/core/java/android/service/credentials/BeginGetCredentialsResponse.aidl
@@ -0,0 +1,3 @@
+package android.service.credentials;
+
+parcelable BeginGetCredentialsResponse;
\ No newline at end of file
diff --git a/core/java/android/service/credentials/GetCredentialsResponse.java b/core/java/android/service/credentials/BeginGetCredentialsResponse.java
similarity index 74%
rename from core/java/android/service/credentials/GetCredentialsResponse.java
rename to core/java/android/service/credentials/BeginGetCredentialsResponse.java
index 5263141..2cda560 100644
--- a/core/java/android/service/credentials/GetCredentialsResponse.java
+++ b/core/java/android/service/credentials/BeginGetCredentialsResponse.java
@@ -27,7 +27,7 @@
  * Response from a credential provider, containing credential entries and other associated
  * data to be shown on the account selector UI.
  */
-public final class GetCredentialsResponse implements Parcelable {
+public final class BeginGetCredentialsResponse implements Parcelable {
     /** Content to be used for the UI. */
     private final @Nullable CredentialsResponseContent mCredentialsResponseContent;
 
@@ -38,14 +38,15 @@
     private final @Nullable Action mAuthenticationAction;
 
     /**
-     * Creates a {@link GetCredentialsResponse} instance with an authentication {@link Action} set.
-     * Providers must use this method when no content can be shown before authentication.
+     * Creates a {@link BeginGetCredentialsResponse} instance with an authentication
+     * {@link Action} set. Providers must use this method when no content can be shown
+     * before authentication.
      *
      * <p> When the user selects this {@code authenticationAction}, the system invokes the
      * corresponding {@code pendingIntent}. Once the authentication flow is complete,
      * the {@link android.app.Activity} result should be set
      * to {@link android.app.Activity#RESULT_OK} and the
-     * {@link CredentialProviderService#EXTRA_GET_CREDENTIALS_CONTENT_RESULT} extra should be set
+     * {@link CredentialProviderService#EXTRA_CREDENTIALS_RESPONSE_CONTENT} extra should be set
      * with a fully populated {@link CredentialsResponseContent} object.
      * the authentication action activity is launched, and the user is authenticated, providers
      * should create another response with {@link CredentialsResponseContent} using
@@ -54,48 +55,49 @@
      *
      * @throws NullPointerException If {@code authenticationAction} is null.
      */
-    public static @NonNull GetCredentialsResponse createWithAuthentication(
+    public static @NonNull BeginGetCredentialsResponse createWithAuthentication(
             @NonNull Action authenticationAction) {
         Objects.requireNonNull(authenticationAction,
                 "authenticationAction must not be null");
-        return new GetCredentialsResponse(null, authenticationAction);
+        return new BeginGetCredentialsResponse(null, authenticationAction);
     }
 
     /**
-     * Creates a {@link GetCredentialsRequest} instance with content to be shown on the UI.
+     * Creates a {@link BeginGetCredentialsRequest} instance with content to be shown on the UI.
      * Providers must use this method when there is content to be shown without top level
      * authentication required, including credential entries, action entries or a remote entry,
      *
      * @throws NullPointerException If {@code credentialsResponseContent} is null.
      */
-    public static @NonNull GetCredentialsResponse createWithResponseContent(
+    public static @NonNull BeginGetCredentialsResponse createWithResponseContent(
             @NonNull CredentialsResponseContent credentialsResponseContent) {
         Objects.requireNonNull(credentialsResponseContent,
                 "credentialsResponseContent must not be null");
-        return new GetCredentialsResponse(credentialsResponseContent, null);
+        return new BeginGetCredentialsResponse(credentialsResponseContent, null);
     }
 
-    private GetCredentialsResponse(@Nullable CredentialsResponseContent credentialsResponseContent,
+    private BeginGetCredentialsResponse(@Nullable CredentialsResponseContent
+            credentialsResponseContent,
             @Nullable Action authenticationAction) {
         mCredentialsResponseContent = credentialsResponseContent;
         mAuthenticationAction = authenticationAction;
     }
 
-    private GetCredentialsResponse(@NonNull Parcel in) {
+    private BeginGetCredentialsResponse(@NonNull Parcel in) {
         mCredentialsResponseContent = in.readTypedObject(CredentialsResponseContent.CREATOR);
         mAuthenticationAction = in.readTypedObject(Action.CREATOR);
     }
 
-    public static final @NonNull Creator<GetCredentialsResponse> CREATOR =
-            new Creator<GetCredentialsResponse>() {
+    public static final @NonNull Creator<BeginGetCredentialsResponse> CREATOR =
+            new Creator<BeginGetCredentialsResponse>() {
                 @Override
-                public GetCredentialsResponse createFromParcel(Parcel in) {
-                    return new GetCredentialsResponse(in);
+                public BeginGetCredentialsResponse createFromParcel(Parcel in) {
+                    return new BeginGetCredentialsResponse(in);
                 }
 
                 @Override
-                public GetCredentialsResponse[] newArray(int size) {
-                    return new GetCredentialsResponse[size];
+                public BeginGetCredentialsResponse[] newArray(int size) {
+                    return new BeginGetCredentialsResponse[size];
                 }
             };
 
diff --git a/core/java/android/service/credentials/CredentialEntry.java b/core/java/android/service/credentials/CredentialEntry.java
index 941db02b..3c399d2 100644
--- a/core/java/android/service/credentials/CredentialEntry.java
+++ b/core/java/android/service/credentials/CredentialEntry.java
@@ -17,10 +17,9 @@
 package android.service.credentials;
 
 import android.annotation.NonNull;
-import android.annotation.Nullable;
 import android.app.PendingIntent;
 import android.app.slice.Slice;
-import android.credentials.Credential;
+import android.credentials.GetCredentialResponse;
 import android.os.Parcel;
 import android.os.Parcelable;
 
@@ -41,32 +40,23 @@
     private final @NonNull Slice mSlice;
 
     /** The pending intent to be invoked when this credential entry is selected. */
-    private final @Nullable PendingIntent mPendingIntent;
-
-    /**
-     * The underlying credential to be returned to the app when the user selects
-     * this credential entry.
-     */
-    private final @Nullable Credential mCredential;
+    private final @NonNull PendingIntent mPendingIntent;
 
     /** A flag denoting whether auto-select is enabled for this entry. */
     private final @NonNull boolean mAutoSelectAllowed;
 
     private CredentialEntry(@NonNull String type, @NonNull Slice slice,
-            @Nullable PendingIntent pendingIntent, @Nullable Credential credential,
-            @NonNull boolean autoSeletAllowed) {
+            @NonNull PendingIntent pendingIntent, @NonNull boolean autoSelectAllowed) {
         mType = type;
         mSlice = slice;
         mPendingIntent = pendingIntent;
-        mCredential = credential;
-        mAutoSelectAllowed = autoSeletAllowed;
+        mAutoSelectAllowed = autoSelectAllowed;
     }
 
     private CredentialEntry(@NonNull Parcel in) {
         mType = in.readString8();
         mSlice = in.readTypedObject(Slice.CREATOR);
         mPendingIntent = in.readTypedObject(PendingIntent.CREATOR);
-        mCredential = in.readTypedObject(Credential.CREATOR);
         mAutoSelectAllowed = in.readBoolean();
     }
 
@@ -93,7 +83,6 @@
         dest.writeString8(mType);
         dest.writeTypedObject(mSlice, flags);
         dest.writeTypedObject(mPendingIntent, flags);
-        dest.writeTypedObject(mCredential, flags);
         dest.writeBoolean(mAutoSelectAllowed);
     }
 
@@ -114,18 +103,11 @@
     /**
      * Returns the pending intent to be invoked if the user selects this entry.
      */
-    public @Nullable PendingIntent getPendingIntent() {
+    public @NonNull PendingIntent getPendingIntent() {
         return mPendingIntent;
     }
 
     /**
-     * Returns the credential associated with this entry.
-     */
-    public @Nullable Credential getCredential() {
-        return mCredential;
-    }
-
-    /**
      * Returns whether this entry can be auto selected if it is the only option for the user.
      */
     public boolean isAutoSelectAllowed() {
@@ -138,8 +120,7 @@
     public static final class Builder {
         private String mType;
         private Slice mSlice;
-        private PendingIntent mPendingIntent = null;
-        private Credential mCredential = null;
+        private PendingIntent mPendingIntent;
         private boolean mAutoSelectAllowed = false;
 
         /**
@@ -152,8 +133,8 @@
          * Once the activity fulfills the required user engagement, the
          * {@link android.app.Activity} result should be set to
          * {@link android.app.Activity#RESULT_OK}, and the
-         * {@link CredentialProviderService#EXTRA_CREDENTIAL_RESULT} must be set with a
-         * {@link Credential} object.
+         * {@link CredentialProviderService#EXTRA_GET_CREDENTIAL_RESPONSE} must be set with a
+         * {@link GetCredentialResponse} object.
          *
          * @param type the type of credential underlying this credential entry
          * @param slice the content to be displayed with this entry on the UI
@@ -179,26 +160,6 @@
         }
 
         /**
-         * Creates a builder for a {@link CredentialEntry} that contains a {@link Credential},
-         * and does not require further action.
-         * @param type the type of credential underlying this credential entry
-         * @param slice the content to be displayed with this entry on the UI
-         * @param credential the credential to be returned to the client app, when this entry is
-         *                   selected by the user
-         *
-         * @throws IllegalArgumentException If {@code type} is null or empty.
-         * @throws NullPointerException If {@code slice}, or {@code credential} is null.
-         */
-        public Builder(@NonNull String type, @NonNull Slice slice, @NonNull Credential credential) {
-            mType = Preconditions.checkStringNotEmpty(type, "type must not be "
-                    + "null, or empty");
-            mSlice = Objects.requireNonNull(slice,
-                    "slice must not be null");
-            mCredential = Objects.requireNonNull(credential,
-                    "credential must not be null");
-        }
-
-        /**
          * Sets whether the entry is allowed to be auto selected by the framework.
          * The default value is set to false.
          *
@@ -219,12 +180,9 @@
          * is set, or if both are set.
          */
         public @NonNull CredentialEntry build() {
-            Preconditions.checkState(((mPendingIntent != null && mCredential == null)
-                            || (mPendingIntent == null && mCredential != null)),
-                    "Either pendingIntent or credential must be set, and both cannot"
-                            + "be set at the same time");
-            return new CredentialEntry(mType, mSlice, mPendingIntent,
-                    mCredential, mAutoSelectAllowed);
+            Preconditions.checkState(mPendingIntent != null,
+                    "pendingIntent must not be null");
+            return new CredentialEntry(mType, mSlice, mPendingIntent, mAutoSelectAllowed);
         }
     }
 }
diff --git a/core/java/android/service/credentials/CredentialProviderService.java b/core/java/android/service/credentials/CredentialProviderService.java
index 32646e6..416ddf1 100644
--- a/core/java/android/service/credentials/CredentialProviderService.java
+++ b/core/java/android/service/credentials/CredentialProviderService.java
@@ -21,6 +21,7 @@
 import android.annotation.CallSuper;
 import android.annotation.NonNull;
 import android.annotation.SdkConstant;
+import android.app.PendingIntent;
 import android.app.Service;
 import android.content.Intent;
 import android.os.CancellationSignal;
@@ -45,12 +46,23 @@
      * returned as part of the {@link BeginCreateCredentialResponse}
      *
      * <p>
-     * Type: {@link android.credentials.CreateCredentialRequest}
+     * Type: {@link android.service.credentials.CreateCredentialRequest}
      */
     public static final String EXTRA_CREATE_CREDENTIAL_REQUEST =
             "android.service.credentials.extra.CREATE_CREDENTIAL_REQUEST";
 
     /**
+     * Intent extra: The {@link GetCredentialRequest} attached with
+     * the {@code pendingIntent} that is invoked when the user selects a {@link CredentialEntry}
+     * returned as part of the {@link BeginGetCredentialsResponse}
+     *
+     * <p>
+     * Type: {@link GetCredentialRequest}
+     */
+    public static final String EXTRA_GET_CREDENTIAL_REQUEST =
+            "android.service.credentials.extra.GET_CREDENTIAL_REQUEST";
+
+    /**
      * Intent extra: The result of a create flow operation, to be set on finish of the
      * {@link android.app.Activity} invoked through the {@code pendingIntent} set on
      * a {@link CreateEntry}.
@@ -58,8 +70,8 @@
      * <p>
      * Type: {@link android.credentials.CreateCredentialResponse}
      */
-    public static final String EXTRA_CREATE_CREDENTIAL_RESULT =
-            "android.service.credentials.extra.CREATE_CREDENTIAL_RESULT";
+    public static final String EXTRA_CREATE_CREDENTIAL_RESPONSE =
+            "android.service.credentials.extra.CREATE_CREDENTIAL_RESPONSE";
 
     /**
      * Intent extra: The result of a get credential flow operation, to be set on finish of the
@@ -67,33 +79,48 @@
      * a {@link CredentialEntry}.
      *
      * <p>
-     * Type: {@link android.credentials.Credential}
+     * Type: {@link android.credentials.GetCredentialResponse}
      */
-    public static final String EXTRA_CREDENTIAL_RESULT =
-            "android.service.credentials.extra.CREDENTIAL_RESULT";
+    public static final String EXTRA_GET_CREDENTIAL_RESPONSE =
+            "android.service.credentials.extra.GET_CREDENTIAL_RESPONSE";
 
     /**
      * Intent extra: The result of an authentication flow, to be set on finish of the
      * {@link android.app.Activity} invoked through the {@link android.app.PendingIntent} set on
-     * a {@link GetCredentialsResponse}. This result should contain the actual content, including
-     * credential entries and action entries, to be shown on the selector.
+     * a {@link BeginGetCredentialsResponse}. This result should contain the actual content,
+     * including credential entries and action entries, to be shown on the selector.
      *
      * <p>
      * Type: {@link CredentialsResponseContent}
      */
-    public static final String EXTRA_GET_CREDENTIALS_CONTENT_RESULT =
-            "android.service.credentials.extra.GET_CREDENTIALS_CONTENT_RESULT";
+    public static final String EXTRA_CREDENTIALS_RESPONSE_CONTENT =
+            "android.service.credentials.extra.CREDENTIALS_RESPONSE_CONTENT";
 
     /**
-     * Intent extra: The error result of any {@link android.app.PendingIntent} flow, to be set
-     * on finish of the corresponding {@link android.app.Activity}. This result should contain an
-     * error code, representing the error encountered by the provider.
+     * Intent extra: The failure exception set at the final stage of a get flow.
+     * This exception is set at the finishing result of the {@link android.app.Activity}
+     * invoked by the {@link PendingIntent} , when a user selects the {@link CredentialEntry}
+     * that contained the {@link PendingIntent} in question.
+     *
+     * <p>The result must be set through {@link android.app.Activity#setResult} as an intent extra
      *
      * <p>
-     * Type: {@link String}
+     * Type: {@link android.credentials.GetCredentialException}
      */
-    public static final String EXTRA_ERROR =
-            "android.service.credentials.extra.ERROR";
+    public static final String EXTRA_GET_CREDENTIAL_EXCEPTION =
+            "android.service.credentials.extra.GET_CREDENTIAL_EXCEPTION";
+
+    /**
+     * Intent extra: The failure exception set at the final stage of a create flow.
+     * This exception is set at the finishing result of the {@link android.app.Activity}
+     * invoked by the {@link PendingIntent} , when a user selects the {@link CreateEntry}
+     * that contained the {@link PendingIntent} in question.
+     *
+     * <p>
+     * Type: {@link android.credentials.CreateCredentialException}
+     */
+    public static final String EXTRA_CREATE_CREDENTIAL_EXCEPTION =
+            "android.service.credentials.extra.CREATE_CREDENTIAL_EXCEPTION";
 
     private static final String TAG = "CredProviderService";
 
@@ -128,20 +155,21 @@
 
     private final ICredentialProviderService mInterface = new ICredentialProviderService.Stub() {
         @Override
-        public ICancellationSignal onGetCredentials(GetCredentialsRequest request,
-                IGetCredentialsCallback callback) {
+        public ICancellationSignal onBeginGetCredentials(BeginGetCredentialsRequest request,
+                IBeginGetCredentialsCallback callback) {
             Objects.requireNonNull(request);
             Objects.requireNonNull(callback);
 
             ICancellationSignal transport = CancellationSignal.createTransport();
 
             mHandler.sendMessage(obtainMessage(
-                    CredentialProviderService::onGetCredentials,
+                    CredentialProviderService::onBeginGetCredentials,
                     CredentialProviderService.this, request,
                     CancellationSignal.fromTransport(transport),
-                    new OutcomeReceiver<GetCredentialsResponse, CredentialProviderException>() {
+                    new OutcomeReceiver<BeginGetCredentialsResponse,
+                            CredentialProviderException>() {
                         @Override
-                        public void onResult(GetCredentialsResponse result) {
+                        public void onResult(BeginGetCredentialsResponse result) {
                             try {
                                 callback.onSuccess(result);
                             } catch (RemoteException e) {
@@ -200,14 +228,29 @@
     /**
      * Called by the android system to retrieve user credentials from the connected provider
      * service.
-     * @param request the credential request for the provider to handle
+     *
+     *
+     *
+     * <p>This API denotes a query stage request for getting user's credentials from a given
+     * credential provider. The request contains a list of
+     * {@link android.credentials.GetCredentialOption} that have parameters to be used for
+     * populating candidate credentials, as a list of {@link CredentialEntry} to be set
+     * on the {@link BeginGetCredentialsResponse}. This list is then shown to the user on a
+     * selector.
+     *
+     * <p>If a {@link PendingIntent} is set on a {@link CredentialEntry}, and the user selects that
+     * entry, a {@link GetCredentialRequest} with all parameters needed to get the actual
+     * {@link android.credentials.Credential} will be sent as part of the {@link Intent} fired
+     * through the {@link PendingIntent}.
+     * @param request the request for the provider to handle
      * @param cancellationSignal signal for providers to listen to any cancellation requests from
      *                           the android system
      * @param callback object used to relay the response of the credentials request
      */
-    public abstract void onGetCredentials(@NonNull GetCredentialsRequest request,
+    public abstract void onBeginGetCredentials(@NonNull BeginGetCredentialsRequest request,
             @NonNull CancellationSignal cancellationSignal,
-            @NonNull OutcomeReceiver<GetCredentialsResponse, CredentialProviderException> callback);
+            @NonNull OutcomeReceiver<
+                    BeginGetCredentialsResponse, CredentialProviderException> callback);
 
     /**
      * Called by the android system to create a credential.
diff --git a/core/java/android/service/credentials/CredentialsResponseContent.java b/core/java/android/service/credentials/CredentialsResponseContent.java
index 32cab50..c2f28cb 100644
--- a/core/java/android/service/credentials/CredentialsResponseContent.java
+++ b/core/java/android/service/credentials/CredentialsResponseContent.java
@@ -29,7 +29,7 @@
 
 /**
  * The content to be displayed on the account selector UI, including credential entries,
- * actions etc. Returned as part of {@link GetCredentialsResponse}
+ * actions etc. Returned as part of {@link BeginGetCredentialsResponse}
  */
 public final class CredentialsResponseContent implements Parcelable {
     /** List of credential entries to be displayed on the UI. */
@@ -124,7 +124,7 @@
          *
          * <p> Once the remote credential flow is complete, the {@link android.app.Activity}
          * result should be set to {@link android.app.Activity#RESULT_OK} and an extra with the
-         * {@link CredentialProviderService#EXTRA_CREDENTIAL_RESULT} key should be populated
+         * {@link CredentialProviderService#EXTRA_GET_CREDENTIAL_RESPONSE} key should be populated
          * with a {@link android.credentials.Credential} object.
          */
         public @NonNull Builder setRemoteCredentialEntry(@Nullable CredentialEntry
@@ -188,7 +188,7 @@
         }
 
         /**
-         * Builds a {@link GetCredentialsResponse} instance.
+         * Builds a {@link CredentialsResponseContent} instance.
          *
          * @throws IllegalStateException if {@code credentialEntries}, {@code actions}
          * and {@code remoteCredentialEntry} are all null or empty.
diff --git a/core/java/android/service/credentials/GetCredentialsRequest.java b/core/java/android/service/credentials/GetCredentialRequest.java
similarity index 83%
rename from core/java/android/service/credentials/GetCredentialsRequest.java
rename to core/java/android/service/credentials/GetCredentialRequest.java
index 9052b54..1d6c83b 100644
--- a/core/java/android/service/credentials/GetCredentialsRequest.java
+++ b/core/java/android/service/credentials/GetCredentialRequest.java
@@ -21,6 +21,7 @@
 import android.os.Parcel;
 import android.os.Parcelable;
 
+import com.android.internal.util.AnnotationValidations;
 import com.android.internal.util.Preconditions;
 
 import java.util.ArrayList;
@@ -30,7 +31,7 @@
 /**
  * Request for getting user's credentials from a given credential provider.
  */
-public final class GetCredentialsRequest implements Parcelable {
+public final class GetCredentialRequest implements Parcelable {
     /** Calling package of the app requesting for credentials. */
     private final @NonNull String mCallingPackage;
 
@@ -40,29 +41,30 @@
      */
     private final @NonNull List<GetCredentialOption> mGetCredentialOptions;
 
-    private GetCredentialsRequest(@NonNull String callingPackage,
+    private GetCredentialRequest(@NonNull String callingPackage,
             @NonNull List<GetCredentialOption> getCredentialOptions) {
         this.mCallingPackage = callingPackage;
         this.mGetCredentialOptions = getCredentialOptions;
     }
 
-    private GetCredentialsRequest(@NonNull Parcel in) {
+    private GetCredentialRequest(@NonNull Parcel in) {
         mCallingPackage = in.readString8();
         List<GetCredentialOption> getCredentialOptions = new ArrayList<>();
         in.readTypedList(getCredentialOptions, GetCredentialOption.CREATOR);
         mGetCredentialOptions = getCredentialOptions;
+        AnnotationValidations.validate(NonNull.class, null, mGetCredentialOptions);
     }
 
-    public static final @NonNull Creator<GetCredentialsRequest> CREATOR =
-            new Creator<GetCredentialsRequest>() {
+    public static final @NonNull Creator<GetCredentialRequest> CREATOR =
+            new Creator<GetCredentialRequest>() {
                 @Override
-                public GetCredentialsRequest createFromParcel(Parcel in) {
-                    return new GetCredentialsRequest(in);
+                public GetCredentialRequest createFromParcel(Parcel in) {
+                    return new GetCredentialRequest(in);
                 }
 
                 @Override
-                public GetCredentialsRequest[] newArray(int size) {
-                    return new GetCredentialsRequest[size];
+                public GetCredentialRequest[] newArray(int size) {
+                    return new GetCredentialRequest[size];
                 }
             };
 
@@ -92,7 +94,7 @@
     }
 
     /**
-     * Builder for {@link GetCredentialsRequest}.
+     * Builder for {@link GetCredentialRequest}.
      */
     public static final class Builder {
         private String mCallingPackage;
@@ -139,18 +141,18 @@
         }
 
         /**
-         * Builds a new {@link GetCredentialsRequest} instance.
+         * Builds a new {@link GetCredentialRequest} instance.
          *
          * @throws NullPointerException If {@code getCredentialOptions} is null.
          * @throws IllegalArgumentException If {@code getCredentialOptions} is empty, or if
          * {@code callingPackage} is null or empty.
          */
-        public @NonNull GetCredentialsRequest build() {
+        public @NonNull GetCredentialRequest build() {
             Preconditions.checkStringNotEmpty(mCallingPackage,
                     "Must set the calling package");
             Preconditions.checkCollectionNotEmpty(mGetCredentialOptions,
                     "getCredentialOptions");
-            return new GetCredentialsRequest(mCallingPackage, mGetCredentialOptions);
+            return new GetCredentialRequest(mCallingPackage, mGetCredentialOptions);
         }
     }
 }
diff --git a/core/java/android/service/credentials/GetCredentialsRequest.aidl b/core/java/android/service/credentials/GetCredentialsRequest.aidl
deleted file mode 100644
index b309d69..0000000
--- a/core/java/android/service/credentials/GetCredentialsRequest.aidl
+++ /dev/null
@@ -1,3 +0,0 @@
-package android.service.credentials;
-
-parcelable GetCredentialsRequest;
\ No newline at end of file
diff --git a/core/java/android/service/credentials/GetCredentialsResponse.aidl b/core/java/android/service/credentials/GetCredentialsResponse.aidl
deleted file mode 100644
index 0d8c635..0000000
--- a/core/java/android/service/credentials/GetCredentialsResponse.aidl
+++ /dev/null
@@ -1,3 +0,0 @@
-package android.service.credentials;
-
-parcelable GetCredentialsResponse;
\ No newline at end of file
diff --git a/core/java/android/service/credentials/IBeginGetCredentialsCallback.aidl b/core/java/android/service/credentials/IBeginGetCredentialsCallback.aidl
new file mode 100644
index 0000000..9ac28f2
--- /dev/null
+++ b/core/java/android/service/credentials/IBeginGetCredentialsCallback.aidl
@@ -0,0 +1,13 @@
+package android.service.credentials;
+
+import android.service.credentials.BeginGetCredentialsResponse;
+
+/**
+ * Interface from the system to a credential provider service.
+ *
+ * @hide
+ */
+oneway interface IBeginGetCredentialsCallback {
+    void onSuccess(in BeginGetCredentialsResponse response);
+    void onFailure(int errorCode, in CharSequence message);
+}
\ No newline at end of file
diff --git a/core/java/android/service/credentials/ICredentialProviderService.aidl b/core/java/android/service/credentials/ICredentialProviderService.aidl
index b9eb3ed..1306882 100644
--- a/core/java/android/service/credentials/ICredentialProviderService.aidl
+++ b/core/java/android/service/credentials/ICredentialProviderService.aidl
@@ -17,9 +17,9 @@
 package android.service.credentials;
 
 import android.os.ICancellationSignal;
-import android.service.credentials.GetCredentialsRequest;
+import android.service.credentials.BeginGetCredentialsRequest;
 import android.service.credentials.BeginCreateCredentialRequest;
-import android.service.credentials.IGetCredentialsCallback;
+import android.service.credentials.IBeginGetCredentialsCallback;
 import android.service.credentials.IBeginCreateCredentialCallback;
 import android.os.ICancellationSignal;
 
@@ -29,6 +29,6 @@
  * @hide
  */
 interface ICredentialProviderService {
-    ICancellationSignal onGetCredentials(in GetCredentialsRequest request, in IGetCredentialsCallback callback);
+    ICancellationSignal onBeginGetCredentials(in BeginGetCredentialsRequest request, in IBeginGetCredentialsCallback callback);
     ICancellationSignal onBeginCreateCredential(in BeginCreateCredentialRequest request, in IBeginCreateCredentialCallback callback);
 }
diff --git a/core/java/android/service/credentials/IGetCredentialsCallback.aidl b/core/java/android/service/credentials/IGetCredentialsCallback.aidl
deleted file mode 100644
index 6e20c55..0000000
--- a/core/java/android/service/credentials/IGetCredentialsCallback.aidl
+++ /dev/null
@@ -1,13 +0,0 @@
-package android.service.credentials;
-
-import android.service.credentials.GetCredentialsResponse;
-
-/**
- * Interface from the system to a credential provider service.
- *
- * @hide
- */
-oneway interface IGetCredentialsCallback {
-    void onSuccess(in GetCredentialsResponse response);
-    void onFailure(int errorCode, in CharSequence message);
-}
\ No newline at end of file
diff --git a/core/java/android/service/notification/NotificationListenerService.java b/core/java/android/service/notification/NotificationListenerService.java
index e821af1..d113a3c 100644
--- a/core/java/android/service/notification/NotificationListenerService.java
+++ b/core/java/android/service/notification/NotificationListenerService.java
@@ -267,6 +267,8 @@
      * will be restored via NotificationListeners#notifyPostedLocked()
      */
     public static final int REASON_LOCKDOWN = 23;
+    // If adding a new notification cancellation reason, you must also add handling for it in
+    // NotificationCancelledEvent.fromCancelReason.
 
     /**
      * @hide
diff --git a/core/java/android/service/voice/AbstractHotwordDetector.java b/core/java/android/service/voice/AbstractHotwordDetector.java
index 5d3852b..c90ab67 100644
--- a/core/java/android/service/voice/AbstractHotwordDetector.java
+++ b/core/java/android/service/voice/AbstractHotwordDetector.java
@@ -25,7 +25,9 @@
 import android.app.compat.CompatChanges;
 import android.media.AudioFormat;
 import android.media.permission.Identity;
+import android.os.Binder;
 import android.os.Handler;
+import android.os.IBinder;
 import android.os.Looper;
 import android.os.ParcelFileDescriptor;
 import android.os.PersistableBundle;
@@ -49,19 +51,20 @@
     private final IVoiceInteractionManagerService mManagerService;
     private final Handler mHandler;
     private final HotwordDetector.Callback mCallback;
-    private final int mDetectorType;
     private Consumer<AbstractHotwordDetector> mOnDestroyListener;
     private final AtomicBoolean mIsDetectorActive;
+    /**
+     * A token which is used by voice interaction system service to identify different detectors.
+     */
+    private final IBinder mToken = new Binder();
 
     AbstractHotwordDetector(
             IVoiceInteractionManagerService managerService,
-            HotwordDetector.Callback callback,
-            int detectorType) {
+            HotwordDetector.Callback callback) {
         mManagerService = managerService;
         // TODO: this needs to be supplied from above
         mHandler = new Handler(Looper.getMainLooper());
         mCallback = callback;
-        mDetectorType = detectorType;
         mIsDetectorActive = new AtomicBoolean(true);
     }
 
@@ -75,7 +78,7 @@
     /**
      * Detect hotword from an externally supplied stream of data.
      *
-     * @return true if the request to start recognition succeeded
+     * @return {@code true} if the request to start recognition succeeded
      */
     @Override
     public boolean startRecognition(
@@ -94,6 +97,7 @@
                     audioStream,
                     audioFormat,
                     options,
+                    mToken,
                     new BinderCallback(mHandler, mCallback));
         } catch (RemoteException e) {
             e.rethrowFromSystemServer();
@@ -102,23 +106,7 @@
         return true;
     }
 
-    /**
-     * Set configuration and pass read-only data to hotword detection service.
-     *
-     * @param options Application configuration data to provide to the
-     *         {@link HotwordDetectionService}. PersistableBundle does not allow any remotable
-     *         objects or other contents that can be used to communicate with other processes.
-     * @param sharedMemory The unrestricted data blob to provide to the
-     *         {@link HotwordDetectionService}. Use this to provide the hotword models data or other
-     *         such data to the trusted process.
-     * @throws IllegalDetectorStateException Thrown when a caller has a target SDK of
-     *         Android Tiramisu or above and attempts to start a recognition when the detector is
-     *         not able based on the state. Because the caller receives updates via an asynchronous
-     *         callback and the state of the detector can change without caller's knowledge, a
-     *         checked exception is thrown.
-     * @throws IllegalStateException if this HotwordDetector wasn't specified to use a
-     *         {@link HotwordDetectionService} when it was created.
-     */
+    /** {@inheritDoc} */
     @Override
     public void updateState(@Nullable PersistableBundle options,
             @Nullable SharedMemory sharedMemory) throws IllegalDetectorStateException {
@@ -127,7 +115,7 @@
         }
         throwIfDetectorIsNoLongerActive();
         try {
-            mManagerService.updateState(options, sharedMemory);
+            mManagerService.updateState(options, sharedMemory, mToken);
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -144,7 +132,7 @@
         Identity identity = new Identity();
         identity.packageName = ActivityThread.currentOpPackageName();
         try {
-            mManagerService.initAndVerifyDetector(identity, options, sharedMemory, callback,
+            mManagerService.initAndVerifyDetector(identity, options, sharedMemory, mToken, callback,
                     detectorType);
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
@@ -167,6 +155,11 @@
             return;
         }
         mIsDetectorActive.set(false);
+        try {
+            mManagerService.destroyDetector(mToken);
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
         synchronized (mLock) {
             mOnDestroyListener.accept(this);
         }
diff --git a/core/java/android/service/voice/AlwaysOnHotwordDetector.java b/core/java/android/service/voice/AlwaysOnHotwordDetector.java
index d58f6d3..9008bf7 100644
--- a/core/java/android/service/voice/AlwaysOnHotwordDetector.java
+++ b/core/java/android/service/voice/AlwaysOnHotwordDetector.java
@@ -293,7 +293,7 @@
     private final Handler mHandler;
     private final IBinder mBinder = new Binder();
     private final int mTargetSdkVersion;
-    private final boolean mSupportHotwordDetectionService;
+    private final boolean mSupportSandboxedDetectionService;
 
     @GuardedBy("mLock")
     private boolean mIsAvailabilityOverriddenByTestApi = false;
@@ -728,53 +728,24 @@
          */
         public abstract void onDetected(@NonNull EventPayload eventPayload);
 
-        /**
-         * Called when the detection fails due to an error.
-         */
+        /** {@inheritDoc} */
         public abstract void onError();
 
-        /**
-         * Called when the recognition is paused temporarily for some reason.
-         * This is an informational callback, and the clients shouldn't be doing anything here
-         * except showing an indication on their UI if they have to.
-         */
+        /** {@inheritDoc} */
         public abstract void onRecognitionPaused();
 
-        /**
-         * Called when the recognition is resumed after it was temporarily paused.
-         * This is an informational callback, and the clients shouldn't be doing anything here
-         * except showing an indication on their UI if they have to.
-         */
+        /** {@inheritDoc} */
         public abstract void onRecognitionResumed();
 
-        /**
-         * Called when the {@link HotwordDetectionService second stage detection} did not detect the
-         * keyphrase.
-         *
-         * @param result Info about the second stage detection result, provided by the
-         *         {@link HotwordDetectionService}.
-         */
+        /** {@inheritDoc} */
         public void onRejected(@NonNull HotwordRejectedResult result) {
         }
 
-        /**
-         * Called when the {@link HotwordDetectionService} is created by the system and given a
-         * short amount of time to report it's initialization state.
-         *
-         * @param status Info about initialization state of {@link HotwordDetectionService}; the
-         * allowed values are {@link HotwordDetectionService#INITIALIZATION_STATUS_SUCCESS},
-         * 1<->{@link HotwordDetectionService#getMaxCustomInitializationStatus()},
-         * {@link HotwordDetectionService#INITIALIZATION_STATUS_UNKNOWN}.
-         */
+        /** {@inheritDoc} */
         public void onHotwordDetectionServiceInitialized(int status) {
         }
 
-        /**
-         * Called with the {@link HotwordDetectionService} is restarted.
-         *
-         * Clients are expected to call {@link HotwordDetector#updateState} to share the state with
-         * the newly created service.
-         */
+        /** {@inheritDoc} */
         public void onHotwordDetectionServiceRestarted() {
         }
     }
@@ -785,24 +756,16 @@
      * @param callback A non-null Callback for receiving the recognition events.
      * @param modelManagementService A service that allows management of sound models.
      * @param targetSdkVersion The target SDK version.
-     * @param supportHotwordDetectionService {@code true} if hotword detection service should be
+     * @param SupportSandboxedDetectionService {@code true} if HotwordDetectionService should be
      * triggered, otherwise {@code false}.
-     * @param options Application configuration data provided by the
-     * {@link VoiceInteractionService}. PersistableBundle does not allow any remotable objects or
-     * other contents that can be used to communicate with other processes.
-     * @param sharedMemory The unrestricted data blob provided by the
-     * {@link VoiceInteractionService}. Use this to provide the hotword models data or other
-     * such data to the trusted process.
      *
      * @hide
      */
     public AlwaysOnHotwordDetector(String text, Locale locale, Callback callback,
             KeyphraseEnrollmentInfo keyphraseEnrollmentInfo,
             IVoiceInteractionManagerService modelManagementService, int targetSdkVersion,
-            boolean supportHotwordDetectionService) {
-        super(modelManagementService, callback,
-                supportHotwordDetectionService ? DETECTOR_TYPE_TRUSTED_HOTWORD_DSP
-                        : DETECTOR_TYPE_NORMAL);
+            boolean supportSandboxedDetectionService) {
+        super(modelManagementService, callback);
 
         mHandler = new MyHandler();
         mText = text;
@@ -812,12 +775,12 @@
         mInternalCallback = new SoundTriggerListener(mHandler);
         mModelManagementService = modelManagementService;
         mTargetSdkVersion = targetSdkVersion;
-        mSupportHotwordDetectionService = supportHotwordDetectionService;
+        mSupportSandboxedDetectionService = supportSandboxedDetectionService;
     }
 
     @Override
     void initialize(@Nullable PersistableBundle options, @Nullable SharedMemory sharedMemory) {
-        if (mSupportHotwordDetectionService) {
+        if (mSupportSandboxedDetectionService) {
             initAndVerifyDetector(options, sharedMemory, mInternalCallback,
                     DETECTOR_TYPE_TRUSTED_HOTWORD_DSP);
         }
@@ -849,7 +812,7 @@
     public final void updateState(@Nullable PersistableBundle options,
             @Nullable SharedMemory sharedMemory) throws IllegalDetectorStateException {
         synchronized (mLock) {
-            if (!mSupportHotwordDetectionService) {
+            if (!mSupportSandboxedDetectionService) {
                 throw new IllegalStateException(
                         "updateState called, but it doesn't support hotword detection service");
             }
@@ -1422,10 +1385,7 @@
         return mKeyphraseEnrollmentInfo.getManageKeyphraseIntent(action, mText, mLocale);
     }
 
-    /**
-     * Invalidates this hotword detector so that any future calls to this result
-     * in an IllegalStateException.
-     */
+    /** {@inheritDoc} */
     @Override
     public void destroy() {
         synchronized (mLock) {
@@ -1448,8 +1408,8 @@
      * @hide
      */
     @Override
-    public boolean isUsingHotwordDetectionService() {
-        return mSupportHotwordDetectionService;
+    public boolean isUsingSandboxedDetectionService() {
+        return mSupportSandboxedDetectionService;
     }
 
     /**
diff --git a/core/java/android/service/voice/HotwordDetectionService.java b/core/java/android/service/voice/HotwordDetectionService.java
index 552a793..a47c096 100644
--- a/core/java/android/service/voice/HotwordDetectionService.java
+++ b/core/java/android/service/voice/HotwordDetectionService.java
@@ -140,7 +140,7 @@
     @Nullable
     private IRecognitionServiceManager mIRecognitionServiceManager;
 
-    private final IHotwordDetectionService mInterface = new IHotwordDetectionService.Stub() {
+    private final ISandboxedDetectionService mInterface = new ISandboxedDetectionService.Stub() {
         @Override
         public void detectFromDspSource(
                 SoundTrigger.KeyphraseRecognitionEvent event,
diff --git a/core/java/android/service/voice/HotwordDetector.java b/core/java/android/service/voice/HotwordDetector.java
index 1a0dc89..b7f7d54 100644
--- a/core/java/android/service/voice/HotwordDetector.java
+++ b/core/java/android/service/voice/HotwordDetector.java
@@ -96,7 +96,7 @@
      * <p>
      * Calling this again while recognition is active does nothing.
      *
-     * @return true if the request to start recognition succeeded
+     * @return {@code true} if the request to start recognition succeeded
      * @throws IllegalDetectorStateException Thrown when a caller has a target SDK of API level 33
      *         or above and attempts to start a recognition when the detector is not able based on
      *         the state. This can be thrown even if the state has been checked before calling this
@@ -109,7 +109,7 @@
     /**
      * Stops hotword recognition.
      *
-     * @return true if the request to stop recognition succeeded
+     * @return {@code true} if the request to stop recognition succeeded
      * @throws IllegalDetectorStateException Thrown when a caller has a target SDK of API level 33
      *         or above and attempts to stop a recognition when the detector is not able based on
      *         the state. This can be thrown even if the state has been checked before calling this
@@ -129,7 +129,7 @@
      *         source of the audio. This will be provided to the {@link HotwordDetectionService}.
      *         PersistableBundle does not allow any remotable objects or other contents that can be
      *         used to communicate with other processes.
-     * @return true if the request to start recognition succeeded
+     * @return {@code true} if the request to start recognition succeeded
      * @throws IllegalDetectorStateException Thrown when a caller has a target SDK of API level 33
      *         or above and attempts to start a recognition when the detector is not able based on
      *         the state. This can be thrown even if the state has been checked before calling this
@@ -164,7 +164,9 @@
 
     /**
      * Invalidates this hotword detector so that any future calls to this result
-     * in an {@link IllegalStateException}.
+     * in an {@link IllegalStateException} when a caller has a target SDK below API level 33
+     * or an {@link IllegalDetectorStateException} when a caller has a target SDK of API level 33
+     * or above.
      *
      * <p>If there are no other {@link HotwordDetector} instances linked to the
      * {@link HotwordDetectionService}, the service will be shutdown.
@@ -176,7 +178,7 @@
     /**
      * @hide
      */
-    default boolean isUsingHotwordDetectionService() {
+    default boolean isUsingSandboxedDetectionService() {
         throw new UnsupportedOperationException("Not implemented. Must override in a subclass.");
     }
 
@@ -234,7 +236,7 @@
         void onRecognitionResumed();
 
         /**
-         * Called when the {@link HotwordDetectionService second stage detection} did not detect the
+         * Called when the {@link HotwordDetectionService} second stage detection did not detect the
          * keyphrase.
          *
          * @param result Info about the second stage detection result, provided by the
@@ -244,7 +246,7 @@
 
         /**
          * Called when the {@link HotwordDetectionService} is created by the system and given a
-         * short amount of time to report it's initialization state.
+         * short amount of time to report its initialization state.
          *
          * @param status Info about initialization state of {@link HotwordDetectionService}; the
          * allowed values are {@link HotwordDetectionService#INITIALIZATION_STATUS_SUCCESS},
diff --git a/core/java/android/service/voice/IHotwordDetectionService.aidl b/core/java/android/service/voice/ISandboxedDetectionService.aidl
similarity index 94%
rename from core/java/android/service/voice/IHotwordDetectionService.aidl
rename to core/java/android/service/voice/ISandboxedDetectionService.aidl
index 9ef9307..5537fd1 100644
--- a/core/java/android/service/voice/IHotwordDetectionService.aidl
+++ b/core/java/android/service/voice/ISandboxedDetectionService.aidl
@@ -29,11 +29,11 @@
 import android.speech.IRecognitionServiceManager;
 
 /**
- * Provide the interface to communicate with hotword detection service.
+ * Provide the interface to communicate with sandboxed detection service.
  *
  * @hide
  */
-oneway interface IHotwordDetectionService {
+oneway interface ISandboxedDetectionService {
     void detectFromDspSource(
         in SoundTrigger.KeyphraseRecognitionEvent event,
         in AudioFormat audioFormat,
diff --git a/core/java/android/service/voice/SoftwareHotwordDetector.java b/core/java/android/service/voice/SoftwareHotwordDetector.java
index 11688df..f1b7745 100644
--- a/core/java/android/service/voice/SoftwareHotwordDetector.java
+++ b/core/java/android/service/voice/SoftwareHotwordDetector.java
@@ -59,7 +59,7 @@
             IVoiceInteractionManagerService managerService,
             AudioFormat audioFormat,
             HotwordDetector.Callback callback) {
-        super(managerService, callback, DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE);
+        super(managerService, callback);
 
         mManagerService = managerService;
         mAudioFormat = audioFormat;
@@ -129,7 +129,7 @@
      * @hide
      */
     @Override
-    public boolean isUsingHotwordDetectionService() {
+    public boolean isUsingSandboxedDetectionService() {
         return true;
     }
 
diff --git a/core/java/android/service/voice/VoiceInteractionService.java b/core/java/android/service/voice/VoiceInteractionService.java
index 7c125c7..a59578e 100644
--- a/core/java/android/service/voice/VoiceInteractionService.java
+++ b/core/java/android/service/voice/VoiceInteractionService.java
@@ -430,7 +430,7 @@
                 safelyShutdownAllHotwordDetectors();
             } else {
                 for (HotwordDetector detector : mActiveHotwordDetectors) {
-                    if (detector.isUsingHotwordDetectionService()
+                    if (detector.isUsingSandboxedDetectionService()
                             != supportHotwordDetectionService) {
                         throw new IllegalStateException(
                                 "It disallows to create trusted and non-trusted detectors "
@@ -513,7 +513,7 @@
                 safelyShutdownAllHotwordDetectors();
             } else {
                 for (HotwordDetector detector : mActiveHotwordDetectors) {
-                    if (!detector.isUsingHotwordDetectionService()) {
+                    if (!detector.isUsingSandboxedDetectionService()) {
                         throw new IllegalStateException(
                                 "It disallows to create trusted and non-trusted detectors "
                                         + "at the same time.");
@@ -605,7 +605,7 @@
 
     private void shutdownHotwordDetectionServiceIfRequiredLocked() {
         for (HotwordDetector detector : mActiveHotwordDetectors) {
-            if (detector.isUsingHotwordDetectionService()) {
+            if (detector.isUsingSandboxedDetectionService()) {
                 return;
             }
         }
diff --git a/core/java/android/telephony/TelephonyRegistryManager.java b/core/java/android/telephony/TelephonyRegistryManager.java
index 0a1538de..519647d 100644
--- a/core/java/android/telephony/TelephonyRegistryManager.java
+++ b/core/java/android/telephony/TelephonyRegistryManager.java
@@ -45,6 +45,7 @@
 
 import com.android.internal.annotations.GuardedBy;
 import com.android.internal.listeners.ListenerExecutor;
+import com.android.internal.telephony.ICarrierConfigChangeListener;
 import com.android.internal.telephony.ICarrierPrivilegesCallback;
 import com.android.internal.telephony.IOnSubscriptionsChangedListener;
 import com.android.internal.telephony.ITelephonyRegistry;
@@ -54,8 +55,10 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.WeakHashMap;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.Executor;
 import java.util.stream.Collectors;
 
@@ -89,6 +92,14 @@
             IOnSubscriptionsChangedListener> mOpportunisticSubscriptionChangedListenerMap
             = new HashMap<>();
 
+    /**
+     * A mapping between {@link CarrierConfigManager.CarrierConfigChangeListener} and its callback
+     * ICarrierConfigChangeListener.
+     */
+    private final ConcurrentHashMap<CarrierConfigManager.CarrierConfigChangeListener,
+                ICarrierConfigChangeListener>
+            mCarrierConfigChangeListenerMap = new ConcurrentHashMap<>();
+
 
     /** @hide **/
     public TelephonyRegistryManager(@NonNull Context context) {
@@ -1412,4 +1423,94 @@
             throw e.rethrowFromSystemServer();
         }
     }
+
+    /**
+     * Register a {@link android.telephony.CarrierConfigManager.CarrierConfigChangeListener} to get
+     * notification when carrier configurations have changed.
+     *
+     * @param executor The executor on which the callback will be executed.
+     * @param listener The CarrierConfigChangeListener to be registered with.
+     */
+    public void addCarrierConfigChangedListener(
+            @NonNull @CallbackExecutor Executor executor,
+            @NonNull CarrierConfigManager.CarrierConfigChangeListener listener) {
+        Objects.requireNonNull(executor, "Executor should be non-null.");
+        Objects.requireNonNull(listener, "Listener should be non-null.");
+        if (mCarrierConfigChangeListenerMap.get(listener) != null) {
+            Log.e(TAG, "registerCarrierConfigChangeListener: listener already present");
+            return;
+        }
+
+        ICarrierConfigChangeListener callback = new ICarrierConfigChangeListener.Stub() {
+            @Override
+            public void onCarrierConfigChanged(int slotIndex, int subId, int carrierId,
+                    int specificCarrierId) {
+                Log.d(TAG, "onCarrierConfigChanged call in ICarrierConfigChangeListener callback");
+                final long identify = Binder.clearCallingIdentity();
+                try {
+                    executor.execute(() -> listener.onCarrierConfigChanged(slotIndex, subId,
+                            carrierId, specificCarrierId));
+                } finally {
+                    Binder.restoreCallingIdentity(identify);
+                }
+            }
+        };
+
+        try {
+            sRegistry.addCarrierConfigChangeListener(callback,
+                    mContext.getOpPackageName(), mContext.getAttributionTag());
+            mCarrierConfigChangeListenerMap.put(listener, callback);
+        } catch (RemoteException re) {
+            // system server crashes
+            throw re.rethrowFromSystemServer();
+        }
+    }
+
+    /**
+     * Unregister to stop the notification when carrier configurations changed.
+     *
+     * @param listener The CarrierConfigChangeListener to be unregistered with.
+     */
+    public void removeCarrierConfigChangedListener(
+            @NonNull CarrierConfigManager.CarrierConfigChangeListener listener) {
+        Objects.requireNonNull(listener, "Listener should be non-null.");
+        if (mCarrierConfigChangeListenerMap.get(listener) == null) {
+            Log.e(TAG, "removeCarrierConfigChangedListener: listener was not present");
+            return;
+        }
+
+        try {
+            sRegistry.removeCarrierConfigChangeListener(
+                    mCarrierConfigChangeListenerMap.get(listener), mContext.getOpPackageName());
+            mCarrierConfigChangeListenerMap.remove(listener);
+        } catch (RemoteException re) {
+            // System sever crashes
+            throw re.rethrowFromSystemServer();
+        }
+    }
+
+    /**
+     * Notify the registrants the carrier configurations have changed.
+     *
+     * @param slotIndex         The SIM slot index on which to monitor and get notification.
+     * @param subId             The subscription on the SIM slot. May be
+     *                          {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID}.
+     * @param carrierId         The optional carrier Id, may be
+     *                          {@link TelephonyManager#UNKNOWN_CARRIER_ID}.
+     * @param specificCarrierId The optional specific carrier Id, may be {@link
+     *                          TelephonyManager#UNKNOWN_CARRIER_ID}.
+     */
+    public void notifyCarrierConfigChanged(int slotIndex, int subId, int carrierId,
+            int specificCarrierId) {
+        // Only validate slotIndex, all others are optional and allowed to be invalid
+        if (!SubscriptionManager.isValidPhoneId(slotIndex)) {
+            Log.e(TAG, "notifyCarrierConfigChanged, ignored: invalid slotIndex " + slotIndex);
+            return;
+        }
+        try {
+            sRegistry.notifyCarrierConfigChanged(slotIndex, subId, carrierId, specificCarrierId);
+        } catch (RemoteException re) {
+            throw re.rethrowFromSystemServer();
+        }
+    }
 }
diff --git a/core/java/android/util/DisplayMetrics.java b/core/java/android/util/DisplayMetrics.java
index 959295b..101a071 100755
--- a/core/java/android/util/DisplayMetrics.java
+++ b/core/java/android/util/DisplayMetrics.java
@@ -20,12 +20,23 @@
 import android.compat.annotation.UnsupportedAppUsage;
 import android.content.res.FontScaleConverter;
 import android.os.SystemProperties;
+import android.view.WindowManager;
 
 /**
  * A structure describing general information about a display, such as its
  * size, density, and font scaling.
  * <p>To access the DisplayMetrics members, retrieve display metrics like this:</p>
  * <pre>context.getResources().getDisplayMetrics();</pre>
+ *
+ * <p>
+ * For UI layout, obtain {@link android.view.WindowMetrics} from
+ * {@link WindowManager#getCurrentWindowMetrics()}. {@code DisplayMetrics} should only be used for
+ * obtaining display related properties, such as {@link #xdpi} and {@link #ydpi}
+ * </p><p>
+ * See {@link #density} for more information about the differences between {@link #xdpi},
+ * {@link #ydpi} and {@link #density}.
+ * </p>
+ *
  */
 public class DisplayMetrics {
     /**
diff --git a/core/java/android/util/FeatureFlagUtils.java b/core/java/android/util/FeatureFlagUtils.java
index 4277d01..2c4f38d 100644
--- a/core/java/android/util/FeatureFlagUtils.java
+++ b/core/java/android/util/FeatureFlagUtils.java
@@ -52,16 +52,6 @@
     public static final String SETTINGS_SUPPORT_LARGE_SCREEN = "settings_support_large_screen";
 
     /**
-     * Feature flag to allow/restrict intent redirection from/to clone profile.
-     * Default value is false,this is to ensure that framework is not impacted by intent redirection
-     * till we are ready to launch.
-     * From Android U onwards, this would be set to true and eventually removed.
-     * @hide
-     */
-    public static final String SETTINGS_ALLOW_INTENT_REDIRECTION_FOR_CLONE_PROFILE =
-            "settings_allow_intent_redirection_for_clone_profile";
-
-    /**
      * Support locale opt-out and opt-in switch for per app's language.
      * @hide
      */
@@ -174,7 +164,6 @@
         DEFAULT_FLAGS.put(SETTINGS_ENABLE_SECURITY_HUB, "true");
         DEFAULT_FLAGS.put(SETTINGS_SUPPORT_LARGE_SCREEN, "true");
         DEFAULT_FLAGS.put("settings_search_always_expand", "true");
-        DEFAULT_FLAGS.put(SETTINGS_ALLOW_INTENT_REDIRECTION_FOR_CLONE_PROFILE, "false");
         DEFAULT_FLAGS.put(SETTINGS_APP_LOCALE_OPT_IN_ENABLED, "true");
         DEFAULT_FLAGS.put(SETTINGS_VOLUME_PANEL_IN_SYSTEMUI, "false");
         DEFAULT_FLAGS.put(SETTINGS_ENABLE_MONITOR_PHANTOM_PROCS, "true");
@@ -196,7 +185,6 @@
 
     static {
         PERSISTENT_FLAGS = new HashSet<>();
-        PERSISTENT_FLAGS.add(SETTINGS_ALLOW_INTENT_REDIRECTION_FOR_CLONE_PROFILE);
         PERSISTENT_FLAGS.add(SETTINGS_APP_LOCALE_OPT_IN_ENABLED);
         PERSISTENT_FLAGS.add(SETTINGS_SUPPORT_LARGE_SCREEN);
         PERSISTENT_FLAGS.add(SETTINGS_ENABLE_MONITOR_PHANTOM_PROCS);
diff --git a/core/java/android/view/AttachedSurfaceControl.java b/core/java/android/view/AttachedSurfaceControl.java
index c692981..3b082bc 100644
--- a/core/java/android/view/AttachedSurfaceControl.java
+++ b/core/java/android/view/AttachedSurfaceControl.java
@@ -140,13 +140,13 @@
     }
 
     /**
-     * Returns a SyncTarget that can be used to sync {@link AttachedSurfaceControl} in a
+     * Returns a SurfaceSyncGroup that can be used to sync {@link AttachedSurfaceControl} in a
      * {@link SurfaceSyncGroup}
      *
      * @hide
      */
     @Nullable
-    default SurfaceSyncGroup.SyncTarget getSyncTarget() {
+    default SurfaceSyncGroup getOrCreateSurfaceSyncGroup() {
         return null;
     }
 }
diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java
index a42d3eb..71030bcc 100644
--- a/core/java/android/view/Display.java
+++ b/core/java/android/view/Display.java
@@ -1469,7 +1469,8 @@
      * @param outMetrics A {@link DisplayMetrics} object which receives the display metrics.
      *
      * @deprecated Use {@link WindowMetrics#getBounds()} to get the dimensions of the application
-     *     window. Use {@link Configuration#densityDpi} to get the display density.
+     *     window. Use {@link WindowMetrics#getDensity()} to get the density of the application
+     *     window.
      */
     @Deprecated
     public void getMetrics(DisplayMetrics outMetrics) {
diff --git a/core/java/android/view/KeyCharacterMap.java b/core/java/android/view/KeyCharacterMap.java
index a6f88a7..ea5d9a6 100644
--- a/core/java/android/view/KeyCharacterMap.java
+++ b/core/java/android/view/KeyCharacterMap.java
@@ -177,6 +177,8 @@
     private static final int ACCENT_UMLAUT = '\u00A8';
     private static final int ACCENT_VERTICAL_LINE_ABOVE = '\u02C8';
     private static final int ACCENT_VERTICAL_LINE_BELOW = '\u02CC';
+    private static final int ACCENT_APOSTROPHE = '\'';
+    private static final int ACCENT_QUOTATION_MARK = '"';
 
     /* Legacy dead key display characters used in previous versions of the API.
      * We still support these characters by mapping them to their non-legacy version. */
@@ -204,8 +206,6 @@
         addCombining('\u030A', ACCENT_RING_ABOVE);
         addCombining('\u030B', ACCENT_DOUBLE_ACUTE);
         addCombining('\u030C', ACCENT_CARON);
-        addCombining('\u030D', ACCENT_VERTICAL_LINE_ABOVE);
-        //addCombining('\u030E', ACCENT_DOUBLE_VERTICAL_LINE_ABOVE);
         //addCombining('\u030F', ACCENT_DOUBLE_GRAVE);
         //addCombining('\u0310', ACCENT_CANDRABINDU);
         //addCombining('\u0311', ACCENT_INVERTED_BREVE);
@@ -229,11 +229,17 @@
         sCombiningToAccent.append('\u0340', ACCENT_GRAVE);
         sCombiningToAccent.append('\u0341', ACCENT_ACUTE);
         sCombiningToAccent.append('\u0343', ACCENT_COMMA_ABOVE);
+        sCombiningToAccent.append('\u030D', ACCENT_APOSTROPHE);
+        sCombiningToAccent.append('\u030E', ACCENT_QUOTATION_MARK);
 
         // One-way legacy mappings to preserve compatibility with older applications.
         sAccentToCombining.append(ACCENT_GRAVE_LEGACY, '\u0300');
         sAccentToCombining.append(ACCENT_CIRCUMFLEX_LEGACY, '\u0302');
         sAccentToCombining.append(ACCENT_TILDE_LEGACY, '\u0303');
+
+        // One-way mappings to use the preferred accent
+        sAccentToCombining.append(ACCENT_APOSTROPHE, '\u0301');
+        sAccentToCombining.append(ACCENT_QUOTATION_MARK, '\u0308');
     }
 
     private static void addCombining(int combining, int accent) {
diff --git a/core/java/android/view/KeyEvent.java b/core/java/android/view/KeyEvent.java
index 06c1b25..61582cd 100644
--- a/core/java/android/view/KeyEvent.java
+++ b/core/java/android/view/KeyEvent.java
@@ -892,13 +892,18 @@
      * The use of this button does not usually correspond to the function of an eraser.
      */
     public static final int KEYCODE_STYLUS_BUTTON_TAIL = 311;
+    /**
+     * Key code constant: To open recent apps view (a.k.a. Overview).
+     * This key is handled by the framework and is never delivered to applications.
+     */
+    public static final int KEYCODE_RECENT_APPS = 312;
 
    /**
      * Integer value of the last KEYCODE. Increases as new keycodes are added to KeyEvent.
      * @hide
      */
     @TestApi
-    public static final int LAST_KEYCODE = KEYCODE_STYLUS_BUTTON_TAIL;
+    public static final int LAST_KEYCODE = KEYCODE_RECENT_APPS;
 
     // NOTE: If you add a new keycode here you must also add it to:
     //  isSystem()
@@ -2021,6 +2026,7 @@
             case KeyEvent.KEYCODE_MENU:
             case KeyEvent.KEYCODE_SOFT_RIGHT:
             case KeyEvent.KEYCODE_HOME:
+            case KeyEvent.KEYCODE_RECENT_APPS:
             case KeyEvent.KEYCODE_BACK:
             case KeyEvent.KEYCODE_CALL:
             case KeyEvent.KEYCODE_ENDCALL:
diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java
index c8a5d8d..4fbb249 100644
--- a/core/java/android/view/MotionEvent.java
+++ b/core/java/android/view/MotionEvent.java
@@ -2199,6 +2199,7 @@
     }
 
     /** @hide */
+    @TestApi
     @Override
     public int getDisplayId() {
         return nativeGetDisplayId(mNativePtr);
diff --git a/core/java/android/view/ScrollCaptureConnection.java b/core/java/android/view/ScrollCaptureConnection.java
index c50f70a..f0c7909 100644
--- a/core/java/android/view/ScrollCaptureConnection.java
+++ b/core/java/android/view/ScrollCaptureConnection.java
@@ -129,7 +129,7 @@
             close();
         }
         mCancellation = null;
-        Trace.asyncTraceForTrackEnd(TRACE_TAG_GRAPHICS, TRACE_TRACK, START_CAPTURE, mTraceId);
+        Trace.asyncTraceForTrackEnd(TRACE_TAG_GRAPHICS, TRACE_TRACK, mTraceId);
     }
 
     @BinderThread
@@ -164,7 +164,7 @@
         } finally {
             mCancellation = null;
         }
-        Trace.asyncTraceForTrackEnd(TRACE_TAG_GRAPHICS, TRACE_TRACK, REQUEST_IMAGE, mTraceId);
+        Trace.asyncTraceForTrackEnd(TRACE_TAG_GRAPHICS, TRACE_TRACK, mTraceId);
     }
 
     @BinderThread
@@ -200,8 +200,8 @@
             mCancellation = null;
             close();
         }
-        Trace.asyncTraceForTrackEnd(TRACE_TAG_GRAPHICS, TRACE_TRACK, END_CAPTURE, mTraceId);
-        Trace.asyncTraceForTrackEnd(TRACE_TAG_GRAPHICS, TRACE_TRACK, SESSION, mTraceId);
+        Trace.asyncTraceForTrackEnd(TRACE_TAG_GRAPHICS, TRACE_TRACK, mTraceId);
+        Trace.asyncTraceForTrackEnd(TRACE_TAG_GRAPHICS, TRACE_TRACK, mTraceId);
     }
 
     @Override
diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java
index 89a0c05..5e8e191 100644
--- a/core/java/android/view/SurfaceControl.java
+++ b/core/java/android/view/SurfaceControl.java
@@ -187,8 +187,8 @@
             int L, int T, int R, int B);
     private static native void nativeSetDisplaySize(long transactionObj, IBinder displayToken,
             int width, int height);
-    private static native StaticDisplayInfo nativeGetStaticDisplayInfo(IBinder displayToken);
-    private static native DynamicDisplayInfo nativeGetDynamicDisplayInfo(IBinder displayToken);
+    private static native StaticDisplayInfo nativeGetStaticDisplayInfo(long displayId);
+    private static native DynamicDisplayInfo nativeGetDynamicDisplayInfo(long displayId);
     private static native DisplayedContentSamplingAttributes
             nativeGetDisplayedContentSamplingAttributes(IBinder displayToken);
     private static native boolean nativeSetDisplayedContentSamplingEnabled(IBinder displayToken,
@@ -275,6 +275,7 @@
             int l, int t, int r, int b);
     private static native void nativeSetDefaultApplyToken(IBinder token);
     private static native IBinder nativeGetDefaultApplyToken();
+    private static native boolean nativeBootFinished();
 
 
     /**
@@ -1627,21 +1628,15 @@
     /**
      * @hide
      */
-    public static StaticDisplayInfo getStaticDisplayInfo(IBinder displayToken) {
-        if (displayToken == null) {
-            throw new IllegalArgumentException("displayToken must not be null");
-        }
-        return nativeGetStaticDisplayInfo(displayToken);
+    public static StaticDisplayInfo getStaticDisplayInfo(long displayId) {
+        return nativeGetStaticDisplayInfo(displayId);
     }
 
     /**
      * @hide
      */
-    public static DynamicDisplayInfo getDynamicDisplayInfo(IBinder displayToken) {
-        if (displayToken == null) {
-            throw new IllegalArgumentException("displayToken must not be null");
-        }
-        return nativeGetDynamicDisplayInfo(displayToken);
+    public static DynamicDisplayInfo getDynamicDisplayInfo(long displayId) {
+        return nativeGetDynamicDisplayInfo(displayId);
     }
 
     /**
@@ -2382,6 +2377,14 @@
     }
 
     /**
+     * Lets surfaceFlinger know the boot procedure is completed.
+     * @hide
+     */
+    public static boolean bootFinished() {
+        return nativeBootFinished();
+    }
+
+    /**
      * Interface to handle request to
      * {@link SurfaceControl.Transaction#addTransactionCommittedListener(Executor, TransactionCommittedListener)}
      */
@@ -3876,4 +3879,5 @@
         SyncFence fence = new SyncFence(nativeFencePtr);
         callback.accept(fence);
     }
+
 }
diff --git a/core/java/android/view/SurfaceControlViewHost.java b/core/java/android/view/SurfaceControlViewHost.java
index 1889772..0a134be 100644
--- a/core/java/android/view/SurfaceControlViewHost.java
+++ b/core/java/android/view/SurfaceControlViewHost.java
@@ -404,14 +404,6 @@
     }
 
     /**
-     * @hide
-     */
-    @TestApi
-    public void relayout(WindowManager.LayoutParams attrs) {
-        relayout(attrs, SurfaceControl.Transaction::apply);
-    }
-
-    /**
      * Forces relayout and draw and allows to set a custom callback when it is finished
      * @hide
      */
@@ -423,6 +415,14 @@
     }
 
     /**
+     * @hide
+     */
+    @TestApi
+    public void relayout(WindowManager.LayoutParams attrs) {
+        mViewRoot.setLayoutParams(attrs, false);
+    }
+
+    /**
      * Modify the size of the root view.
      *
      * @param width Width in pixels
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java
index 33ea92d..9db084e 100644
--- a/core/java/android/view/SurfaceView.java
+++ b/core/java/android/view/SurfaceView.java
@@ -982,8 +982,8 @@
 
                 final boolean redrawNeeded = sizeChanged || creating || hintChanged
                         || (mVisible && !mDrawFinished) || alphaChanged || relativeZChanged;
-                boolean shouldSyncBuffer =
-                        redrawNeeded && viewRoot.wasRelayoutRequested() && viewRoot.isInLocalSync();
+                boolean shouldSyncBuffer = redrawNeeded && viewRoot.wasRelayoutRequested()
+                        && viewRoot.isInWMSRequestedSync();
                 SyncBufferTransactionCallback syncBufferTransactionCallback = null;
                 if (shouldSyncBuffer) {
                     syncBufferTransactionCallback = new SyncBufferTransactionCallback();
@@ -1073,35 +1073,34 @@
     private void handleSyncBufferCallback(SurfaceHolder.Callback[] callbacks,
             SyncBufferTransactionCallback syncBufferTransactionCallback) {
 
-        getViewRootImpl().addToSync((parentSyncGroup, syncBufferCallback) ->
-                redrawNeededAsync(callbacks, () -> {
-                    Transaction t = null;
-                    if (mBlastBufferQueue != null) {
-                        mBlastBufferQueue.stopContinuousSyncTransaction();
-                        t = syncBufferTransactionCallback.waitForTransaction();
-                    }
+        final SurfaceSyncGroup surfaceSyncGroup = new SurfaceSyncGroup();
+        getViewRootImpl().addToSync(surfaceSyncGroup);
+        redrawNeededAsync(callbacks, () -> {
+            Transaction t = null;
+            if (mBlastBufferQueue != null) {
+                mBlastBufferQueue.stopContinuousSyncTransaction();
+                t = syncBufferTransactionCallback.waitForTransaction();
+            }
 
-                    syncBufferCallback.onTransactionReady(t);
-                    onDrawFinished();
-                }));
+            surfaceSyncGroup.onTransactionReady(t);
+            onDrawFinished();
+        });
     }
 
     private void handleSyncNoBuffer(SurfaceHolder.Callback[] callbacks) {
-        final SurfaceSyncGroup syncGroup = new SurfaceSyncGroup();
+        final SurfaceSyncGroup surfaceSyncGroup = new SurfaceSyncGroup();
         synchronized (mSyncGroups) {
-            mSyncGroups.add(syncGroup);
+            mSyncGroups.add(surfaceSyncGroup);
         }
 
-        syncGroup.addToSync((parentSyncGroup, syncBufferCallback) ->
-                redrawNeededAsync(callbacks, () -> {
-                    syncBufferCallback.onTransactionReady(null);
-                    onDrawFinished();
-                    synchronized (mSyncGroups) {
-                        mSyncGroups.remove(syncGroup);
-                    }
-                }));
+        redrawNeededAsync(callbacks, () -> {
+            synchronized (mSyncGroups) {
+                mSyncGroups.remove(surfaceSyncGroup);
+            }
+            surfaceSyncGroup.onTransactionReady(null);
+            onDrawFinished();
+        });
 
-        syncGroup.markSyncReady();
     }
 
     private void redrawNeededAsync(SurfaceHolder.Callback[] callbacks,
@@ -1119,7 +1118,7 @@
         if (viewRoot != null) {
             synchronized (mSyncGroups) {
                 for (SurfaceSyncGroup syncGroup : mSyncGroups) {
-                    viewRoot.mergeSync(syncGroup);
+                    viewRoot.addToSync(syncGroup);
                 }
             }
         }
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index bfb489e..b2973ef 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -471,16 +471,6 @@
     private boolean mAppVisibilityChanged;
     int mOrigWindowType = -1;
 
-    /** Whether the window had focus during the most recent traversal. */
-    boolean mHadWindowFocus;
-
-    /**
-     * Whether the window lost focus during a previous traversal and has not
-     * yet gained it back. Used to determine whether a WINDOW_STATE_CHANGE
-     * accessibility events should be sent during traversal.
-     */
-    boolean mLostWindowFocus;
-
     // Set to true if the owner of this window is in the stopped state,
     // so the window should no longer be active.
     @UnsupportedAppUsage
@@ -605,19 +595,21 @@
     String mLastPerformDrawSkippedReason;
     /** The reason the last call to performTraversals() returned without drawing */
     String mLastPerformTraversalsSkipDrawReason;
-    /** The state of the local sync, if one is in progress. Can be one of the states below. */
-    int mLocalSyncState;
+    /** The state of the WMS requested sync, if one is in progress. Can be one of the states
+     * below. */
+    int mWmsRequestSyncGroupState;
 
-    // The possible states of the local sync, see createSyncIfNeeded()
-    private final int LOCAL_SYNC_NONE = 0;
-    private final int LOCAL_SYNC_PENDING = 1;
-    private final int LOCAL_SYNC_RETURNED = 2;
-    private final int LOCAL_SYNC_MERGED = 3;
+    // The possible states of the WMS requested sync, see createSyncIfNeeded()
+    private static final int WMS_SYNC_NONE = 0;
+    private static final int WMS_SYNC_PENDING = 1;
+    private static final int WMS_SYNC_RETURNED = 2;
+    private static final int WMS_SYNC_MERGED = 3;
 
     /**
-     * Set whether the draw should send the buffer to system server. When set to true, VRI will
-     * create a sync transaction with BBQ and send the resulting buffer to system server. If false,
-     * VRI will not try to sync a buffer in BBQ, but still report when a draw occurred.
+     * Set whether the requested SurfaceSyncGroup should sync the buffer. When set to true, VRI will
+     * create a sync transaction with BBQ and send the resulting buffer back to the
+     * SurfaceSyncGroup. If false, VRI will not try to sync a buffer in BBQ, but still report when a
+     * draw occurred.
      */
     private boolean mSyncBuffer = false;
 
@@ -859,8 +851,19 @@
         return mHandwritingInitiator;
     }
 
-    private SurfaceSyncGroup mSyncGroup;
-    private SurfaceSyncGroup.TransactionReadyCallback mTransactionReadyCallback;
+    /**
+     * A SurfaceSyncGroup that is created when WMS requested to sync the buffer
+     */
+    private SurfaceSyncGroup mWmsRequestSyncGroup;
+
+    /**
+     * The SurfaceSyncGroup that represents the active VRI SurfaceSyncGroup. This is non null if
+     * anyone requested the SurfaceSyncGroup for this VRI to ensure that anyone trying to sync with
+     * this VRI are collected together. The SurfaceSyncGroup is cleared when the VRI draws since
+     * that is the stop point where all changes are have been applied. A new SurfaceSyncGroup is
+     * created after that point when something wants to sync VRI again.
+     */
+    private SurfaceSyncGroup mActiveSurfaceSyncGroup;
 
     private static final Object sSyncProgressLock = new Object();
     // The count needs to be static since it's used to enable or disable RT animations which is
@@ -3630,20 +3633,8 @@
         }
 
         final boolean changedVisibility = (viewVisibilityChanged || mFirst) && isViewVisible;
-        final boolean hasWindowFocus = mAttachInfo.mHasWindowFocus && isViewVisible;
-        final boolean regainedFocus = hasWindowFocus && mLostWindowFocus;
-        if (regainedFocus) {
-            mLostWindowFocus = false;
-        } else if (!hasWindowFocus && mHadWindowFocus) {
-            mLostWindowFocus = true;
-        }
-
-        if (changedVisibility || regainedFocus) {
-            // Toasts are presented as notifications - don't present them as windows as well
-            boolean isToast = mWindowAttributes.type == TYPE_TOAST;
-            if (!isToast) {
-                host.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
-            }
+        if (changedVisibility) {
+            maybeFireAccessibilityWindowStateChangedEvent();
         }
 
         mFirst = false;
@@ -3651,8 +3642,8 @@
         mNewSurfaceNeeded = false;
         mActivityRelaunched = false;
         mViewVisibility = viewVisibility;
-        mHadWindowFocus = hasWindowFocus;
 
+        final boolean hasWindowFocus = mAttachInfo.mHasWindowFocus && isViewVisible;
         mImeFocusController.onTraversal(hasWindowFocus, mWindowAttributes);
 
         if ((relayoutResult & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0) {
@@ -3665,6 +3656,12 @@
         boolean cancelAndRedraw = cancelDueToPreDrawListener
                  || (cancelDraw && mDrewOnceForSync);
         if (!cancelAndRedraw) {
+            // A sync was already requested before the WMS requested sync. This means we need to
+            // sync the buffer, regardless if WMS wants to sync the buffer.
+            if (mActiveSurfaceSyncGroup != null) {
+                mSyncBuffer = true;
+            }
+
             createSyncIfNeeded();
             mDrewOnceForSync = true;
         }
@@ -3678,8 +3675,8 @@
                 mPendingTransitions.clear();
             }
 
-            if (mTransactionReadyCallback != null) {
-                mTransactionReadyCallback.onTransactionReady(null);
+            if (mActiveSurfaceSyncGroup != null) {
+                mActiveSurfaceSyncGroup.onTransactionReady(null);
             }
         } else if (cancelAndRedraw) {
             mLastPerformTraversalsSkipDrawReason = cancelDueToPreDrawListener
@@ -3694,8 +3691,8 @@
                 }
                 mPendingTransitions.clear();
             }
-            if (!performDraw() && mTransactionReadyCallback != null) {
-                mTransactionReadyCallback.onTransactionReady(null);
+            if (!performDraw() && mActiveSurfaceSyncGroup != null) {
+                mActiveSurfaceSyncGroup.onTransactionReady(null);
             }
         }
 
@@ -3709,39 +3706,40 @@
         if (!cancelAndRedraw) {
             mReportNextDraw = false;
             mLastReportNextDrawReason = null;
-            mTransactionReadyCallback = null;
+            mActiveSurfaceSyncGroup = null;
             mSyncBuffer = false;
-            if (isInLocalSync()) {
-                mSyncGroup.markSyncReady();
-                mSyncGroup = null;
-                mLocalSyncState = LOCAL_SYNC_NONE;
+            if (isInWMSRequestedSync()) {
+                mWmsRequestSyncGroup.onTransactionReady(null);
+                mWmsRequestSyncGroup = null;
+                mWmsRequestSyncGroupState = WMS_SYNC_NONE;
             }
         }
     }
 
     private void createSyncIfNeeded() {
-        // Started a sync already or there's nothing needing to sync
-        if (isInLocalSync() || !mReportNextDraw) {
+        // WMS requested sync already started or there's nothing needing to sync
+        if (isInWMSRequestedSync() || !mReportNextDraw) {
             return;
         }
 
         final int seqId = mSyncSeqId;
-        mLocalSyncState = LOCAL_SYNC_PENDING;
-        mSyncGroup = new SurfaceSyncGroup(transaction -> {
-            mLocalSyncState = LOCAL_SYNC_RETURNED;
+        mWmsRequestSyncGroupState = WMS_SYNC_PENDING;
+        mWmsRequestSyncGroup = new SurfaceSyncGroup(t -> {
+            mWmsRequestSyncGroupState = WMS_SYNC_RETURNED;
             // Callback will be invoked on executor thread so post to main thread.
             mHandler.postAtFrontOfQueue(() -> {
-                if (transaction != null) {
-                    mSurfaceChangedTransaction.merge(transaction);
+                if (t != null) {
+                    mSurfaceChangedTransaction.merge(t);
                 }
-                mLocalSyncState = LOCAL_SYNC_MERGED;
+                mWmsRequestSyncGroupState = WMS_SYNC_MERGED;
                 reportDrawFinished(seqId);
             });
         });
         if (DEBUG_BLAST) {
-            Log.d(mTag, "Setup new sync id=" + mSyncGroup);
+            Log.d(mTag, "Setup new sync id=" + mWmsRequestSyncGroup);
         }
-        mSyncGroup.addToSync(mSyncTarget);
+
+        mWmsRequestSyncGroup.addToSync(this);
         notifySurfaceSyncStarted();
     }
 
@@ -3842,43 +3840,7 @@
         }
 
         if (mAdded) {
-            profileRendering(hasWindowFocus);
-            if (hasWindowFocus) {
-                if (mAttachInfo.mThreadedRenderer != null && mSurface.isValid()) {
-                    mFullRedrawNeeded = true;
-                    try {
-                        final Rect surfaceInsets = mWindowAttributes.surfaceInsets;
-                        mAttachInfo.mThreadedRenderer.initializeIfNeeded(
-                                mWidth, mHeight, mAttachInfo, mSurface, surfaceInsets);
-                    } catch (OutOfResourcesException e) {
-                        Log.e(mTag, "OutOfResourcesException locking surface", e);
-                        try {
-                            if (!mWindowSession.outOfMemory(mWindow)) {
-                                Slog.w(mTag, "No processes killed for memory;"
-                                        + " killing self");
-                                Process.killProcess(Process.myPid());
-                            }
-                        } catch (RemoteException ex) {
-                        }
-                        // Retry in a bit.
-                        mHandler.sendMessageDelayed(mHandler.obtainMessage(
-                                MSG_WINDOW_FOCUS_CHANGED), 500);
-                        return;
-                    }
-                }
-            }
-
-            mAttachInfo.mHasWindowFocus = hasWindowFocus;
-            mImeFocusController.onPreWindowFocus(hasWindowFocus, mWindowAttributes);
-
-            if (mView != null) {
-                mAttachInfo.mKeyDispatchState.reset();
-                mView.dispatchWindowFocusChanged(hasWindowFocus);
-                mAttachInfo.mTreeObserver.dispatchOnWindowFocusChange(hasWindowFocus);
-                if (mAttachInfo.mTooltipHost != null) {
-                    mAttachInfo.mTooltipHost.hideTooltip();
-                }
-            }
+            dispatchFocusEvent(hasWindowFocus);
 
             // Note: must be done after the focus change callbacks,
             // so all of the view state is set up correctly.
@@ -3895,6 +3857,8 @@
                         ~WindowManager.LayoutParams
                                 .SOFT_INPUT_IS_FORWARD_NAVIGATION;
 
+                maybeFireAccessibilityWindowStateChangedEvent();
+
                 // Refocusing a window that has a focused view should fire a
                 // focus event for the view since the global focused view changed.
                 fireAccessibilityFocusEventIfHasFocusedNode();
@@ -3914,6 +3878,44 @@
         }
     }
 
+    private void dispatchFocusEvent(boolean hasWindowFocus) {
+        profileRendering(hasWindowFocus);
+        if (hasWindowFocus && mAttachInfo.mThreadedRenderer != null && mSurface.isValid()) {
+            mFullRedrawNeeded = true;
+            try {
+                final Rect surfaceInsets = mWindowAttributes.surfaceInsets;
+                mAttachInfo.mThreadedRenderer.initializeIfNeeded(
+                        mWidth, mHeight, mAttachInfo, mSurface, surfaceInsets);
+            } catch (OutOfResourcesException e) {
+                Log.e(mTag, "OutOfResourcesException locking surface", e);
+                try {
+                    if (!mWindowSession.outOfMemory(mWindow)) {
+                        Slog.w(mTag, "No processes killed for memory;"
+                                + " killing self");
+                        Process.killProcess(Process.myPid());
+                    }
+                } catch (RemoteException ex) {
+                }
+                // Retry in a bit.
+                mHandler.sendMessageDelayed(mHandler.obtainMessage(
+                        MSG_WINDOW_FOCUS_CHANGED), 500);
+                return;
+            }
+        }
+
+        mAttachInfo.mHasWindowFocus = hasWindowFocus;
+        mImeFocusController.onPreWindowFocus(hasWindowFocus, mWindowAttributes);
+
+        if (mView != null) {
+            mAttachInfo.mKeyDispatchState.reset();
+            mView.dispatchWindowFocusChanged(hasWindowFocus);
+            mAttachInfo.mTreeObserver.dispatchOnWindowFocusChange(hasWindowFocus);
+            if (mAttachInfo.mTooltipHost != null) {
+                mAttachInfo.mTooltipHost.hideTooltip();
+            }
+        }
+    }
+
     private void handleWindowTouchModeChanged() {
         final boolean inTouchMode;
         synchronized (this) {
@@ -3922,6 +3924,14 @@
         ensureTouchModeLocally(inTouchMode);
     }
 
+    private void maybeFireAccessibilityWindowStateChangedEvent() {
+        // Toasts are presented as notifications - don't present them as windows as well.
+        boolean isToast = mWindowAttributes != null && (mWindowAttributes.type == TYPE_TOAST);
+        if (!isToast && mView != null) {
+            mView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
+        }
+    }
+
     private void fireAccessibilityFocusEventIfHasFocusedNode() {
         if (!AccessibilityManager.getInstance(mContext).isEnabled()) {
             return;
@@ -4380,19 +4390,11 @@
         return mAttachInfo.mThreadedRenderer != null && mAttachInfo.mThreadedRenderer.isEnabled();
     }
 
-    void addToSync(SurfaceSyncGroup.SyncTarget syncable) {
-        if (!isInLocalSync()) {
-            return;
-        }
-        mSyncGroup.addToSync(syncable);
-    }
-
     /**
-     * This VRI is currently in the middle of a sync request, but specifically one initiated from
-     * within VRI.
+     * This VRI is currently in the middle of a sync request that was initiated by WMS.
      */
-    public boolean isInLocalSync() {
-        return mSyncGroup != null;
+    public boolean isInWMSRequestedSync() {
+        return mWmsRequestSyncGroup != null;
     }
 
     private void addFrameCommitCallbackIfNeeded() {
@@ -4459,7 +4461,7 @@
             return false;
         }
 
-        final boolean fullRedrawNeeded = mFullRedrawNeeded || mTransactionReadyCallback != null;
+        final boolean fullRedrawNeeded = mFullRedrawNeeded || mActiveSurfaceSyncGroup != null;
         mFullRedrawNeeded = false;
 
         mIsDrawing = true;
@@ -4467,9 +4469,9 @@
 
         addFrameCommitCallbackIfNeeded();
 
-        boolean usingAsyncReport = isHardwareEnabled() && mTransactionReadyCallback != null;
+        boolean usingAsyncReport = isHardwareEnabled() && mActiveSurfaceSyncGroup != null;
         if (usingAsyncReport) {
-            registerCallbacksForSync(mSyncBuffer, mTransactionReadyCallback);
+            registerCallbacksForSync(mSyncBuffer, mActiveSurfaceSyncGroup);
         } else if (mHasPendingTransactions) {
             // These callbacks are only needed if there's no sync involved and there were calls to
             // applyTransactionOnDraw. These callbacks check if the draw failed for any reason and
@@ -4520,11 +4522,10 @@
             }
 
             if (mSurfaceHolder != null && mSurface.isValid()) {
-                final SurfaceSyncGroup.TransactionReadyCallback transactionReadyCallback =
-                        mTransactionReadyCallback;
+                final SurfaceSyncGroup surfaceSyncGroup = mActiveSurfaceSyncGroup;
                 SurfaceCallbackHelper sch = new SurfaceCallbackHelper(() ->
-                        mHandler.post(() -> transactionReadyCallback.onTransactionReady(null)));
-                mTransactionReadyCallback = null;
+                        mHandler.post(() -> surfaceSyncGroup.onTransactionReady(null)));
+                mActiveSurfaceSyncGroup = null;
 
                 SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks();
 
@@ -4535,8 +4536,8 @@
                 }
             }
         }
-        if (mTransactionReadyCallback != null && !usingAsyncReport) {
-            mTransactionReadyCallback.onTransactionReady(null);
+        if (mActiveSurfaceSyncGroup != null && !usingAsyncReport) {
+            mActiveSurfaceSyncGroup.onTransactionReady(null);
         }
         if (mPerformContentCapture) {
             performContentCaptureInitialReport();
@@ -8626,8 +8627,8 @@
             writer.println(innerPrefix + "mLastPerformDrawFailedReason="
                 + mLastPerformDrawSkippedReason);
         }
-        if (mLocalSyncState != LOCAL_SYNC_NONE) {
-            writer.println(innerPrefix + "mLocalSyncState=" + mLocalSyncState);
+        if (mWmsRequestSyncGroupState != WMS_SYNC_NONE) {
+            writer.println(innerPrefix + "mWmsRequestSyncGroupState=" + mWmsRequestSyncGroupState);
         }
         writer.println(innerPrefix + "mLastReportedMergedConfiguration="
                 + mLastReportedMergedConfiguration);
@@ -11215,7 +11216,7 @@
     }
 
     private void registerCallbacksForSync(boolean syncBuffer,
-            final SurfaceSyncGroup.TransactionReadyCallback transactionReadyCallback) {
+            final SurfaceSyncGroup surfaceSyncGroup) {
         if (!isHardwareEnabled()) {
             return;
         }
@@ -11242,7 +11243,7 @@
                 // pendingDrawFinished.
                 if ((syncResult
                         & (SYNC_LOST_SURFACE_REWARD_IF_FOUND | SYNC_CONTEXT_IS_STOPPED)) != 0) {
-                    transactionReadyCallback.onTransactionReady(
+                    surfaceSyncGroup.onTransactionReady(
                             mBlastBufferQueue.gatherPendingTransactions(frame));
                     return null;
                 }
@@ -11253,7 +11254,7 @@
 
                 if (syncBuffer) {
                     mBlastBufferQueue.syncNextTransaction(
-                            transactionReadyCallback::onTransactionReady);
+                            surfaceSyncGroup::onTransactionReady);
                 }
 
                 return didProduceBuffer -> {
@@ -11273,7 +11274,7 @@
                         // since the frame didn't draw on this vsync. It's possible the frame will
                         // draw later, but it's better to not be sync than to block on a frame that
                         // may never come.
-                        transactionReadyCallback.onTransactionReady(
+                        surfaceSyncGroup.onTransactionReady(
                                 mBlastBufferQueue.gatherPendingTransactions(frame));
                         return;
                     }
@@ -11282,35 +11283,23 @@
                     // syncNextTransaction callback. Instead, just report back to the Syncer so it
                     // knows that this sync request is complete.
                     if (!syncBuffer) {
-                        transactionReadyCallback.onTransactionReady(null);
+                        surfaceSyncGroup.onTransactionReady(null);
                     }
                 };
             }
         });
     }
 
-    public final SurfaceSyncGroup.SyncTarget mSyncTarget = new SurfaceSyncGroup.SyncTarget() {
-        @Override
-        public void onAddedToSyncGroup(SurfaceSyncGroup parentSyncGroup,
-                SurfaceSyncGroup.TransactionReadyCallback transactionReadyCallback) {
-            updateSyncInProgressCount(parentSyncGroup);
-            if (!isInLocalSync()) {
-                // Always sync the buffer if the sync request did not come from VRI.
-                mSyncBuffer = true;
-            }
-
-            if (mTransactionReadyCallback != null) {
-                Log.d(mTag, "Already set sync for the next draw.");
-                mTransactionReadyCallback.onTransactionReady(null);
-            }
-            if (DEBUG_BLAST) {
-                Log.d(mTag, "Setting syncFrameCallback");
-            }
-            mTransactionReadyCallback = transactionReadyCallback;
+    @Override
+    public SurfaceSyncGroup getOrCreateSurfaceSyncGroup() {
+        if (mActiveSurfaceSyncGroup == null) {
+            mActiveSurfaceSyncGroup = new SurfaceSyncGroup();
+            updateSyncInProgressCount(mActiveSurfaceSyncGroup);
             if (!mIsInTraversal && !mTraversalScheduled) {
                 scheduleTraversals();
             }
         }
+        return mActiveSurfaceSyncGroup;
     };
 
     private final Executor mSimpleExecutor = Runnable::run;
@@ -11335,15 +11324,10 @@
         });
     }
 
-    @Override
-    public SurfaceSyncGroup.SyncTarget getSyncTarget() {
-        return mSyncTarget;
-    }
-
-    void mergeSync(SurfaceSyncGroup otherSyncGroup) {
-        if (!isInLocalSync()) {
+    void addToSync(SurfaceSyncGroup syncable) {
+        if (mActiveSurfaceSyncGroup == null) {
             return;
         }
-        mSyncGroup.merge(otherSyncGroup);
+        mActiveSurfaceSyncGroup.addToSync(syncable, false /* parentSyncGroupMerge */);
     }
 }
diff --git a/core/java/android/view/WindowMetrics.java b/core/java/android/view/WindowMetrics.java
index 52e4e15..141849f 100644
--- a/core/java/android/view/WindowMetrics.java
+++ b/core/java/android/view/WindowMetrics.java
@@ -25,22 +25,64 @@
  * <p>
  * This is usually obtained from {@link WindowManager#getCurrentWindowMetrics()} and
  * {@link WindowManager#getMaximumWindowMetrics()}.
+ * </p>
+ * After {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, it also provides density.
+ * <h3>Obtains Window Dimensions in Density-independent Pixel(DP)</h3>
+ * <p>
+ * While {@link #getDensity()} is provided, the dimension in density-independent pixel could also be
+ * calculated with {@code WindowMetrics} properties, which is similar to
+ * {@link android.content.res.Configuration#screenWidthDp}
+ * <pre class="prettyprint">
+ * float widthInDp = windowMetrics.getBounds().width() / windowMetrics.getDensity();
+ * float heightInDp = windowMetrics.getBounds().height() / windowMetrics.getDensity();
+ * </pre>
+ * Also, the density in DPI can be obtained by:
+ * <pre class="prettyprint">
+ * float densityDp = DisplayMetrics.DENSITY_DEFAULT * windowMetrics.getDensity();
+ * </pre>
+ * </p>
  *
  * @see WindowInsets#getInsets(int)
  * @see WindowManager#getCurrentWindowMetrics()
  * @see WindowManager#getMaximumWindowMetrics()
+ * @see android.annotation.UiContext
  */
 public final class WindowMetrics {
-    private final @NonNull Rect mBounds;
-    private final @NonNull WindowInsets mWindowInsets;
+    @NonNull
+    private final Rect mBounds;
+    @NonNull
+    private final WindowInsets mWindowInsets;
 
+    /** @see android.util.DisplayMetrics#density */
+    private final float mDensity;
+
+    /** @deprecated use {@link #WindowMetrics(Rect, WindowInsets, float)} instead. */
+    @Deprecated
     public WindowMetrics(@NonNull Rect bounds, @NonNull WindowInsets windowInsets) {
-        mBounds = bounds;
-        mWindowInsets = windowInsets;
+        this(bounds, windowInsets, 1.0f);
     }
 
     /**
-     * Returns the bounds of the area associated with this window or visual context.
+     * The constructor to create a {@link WindowMetrics} instance.
+     * <p>
+     * Note that in most cases {@link WindowMetrics} is obtained from
+     * {@link WindowManager#getCurrentWindowMetrics()} or
+     * {@link WindowManager#getMaximumWindowMetrics()}.
+     * </p>
+     *
+     * @param bounds The window bounds
+     * @param windowInsets The {@link WindowInsets} of the window
+     * @param density The window density
+     */
+    public WindowMetrics(@NonNull Rect bounds, @NonNull WindowInsets windowInsets, float density) {
+        mBounds = bounds;
+        mWindowInsets = windowInsets;
+        mDensity = density;
+    }
+
+    /**
+     * Returns the bounds of the area associated with this window or
+     * {@link android.annotation.UiContext}.
      * <p>
      * <b>Note that the size of the reported bounds can have different size than
      * {@link Display#getSize(Point)}.</b> This method reports the window size including all system
@@ -66,16 +108,40 @@
      *
      * @return window bounds in pixels.
      */
-    public @NonNull Rect getBounds() {
+    @NonNull
+    public Rect getBounds() {
         return mBounds;
     }
 
     /**
-     * Returns the {@link WindowInsets} of the area associated with this window or visual context.
+     * Returns the {@link WindowInsets} of the area associated with this window or
+     * {@link android.annotation.UiContext}.
      *
      * @return the {@link WindowInsets} of the visual area.
      */
-    public @NonNull WindowInsets getWindowInsets() {
+    @NonNull
+    public WindowInsets getWindowInsets() {
         return mWindowInsets;
     }
+
+    /**
+     * Returns the density of the area associated with this window or
+     * {@link android.annotation.UiContext}, which uses the same units as
+     * {@link android.util.DisplayMetrics#density}.
+     *
+     * @see android.util.DisplayMetrics#DENSITY_DEFAULT
+     * @see android.util.DisplayMetrics#density
+     */
+    public float getDensity() {
+        return mDensity;
+    }
+
+    @Override
+    public String toString() {
+        return WindowMetrics.class.getSimpleName() + ":{"
+                + "bounds=" + mBounds
+                + ", windowInsets=" + mWindowInsets
+                + ", density" + mDensity
+                + "}";
+    }
 }
diff --git a/core/java/android/view/accessibility/AccessibilityDisplayProxy.java b/core/java/android/view/accessibility/AccessibilityDisplayProxy.java
index 44b6deb..a757236 100644
--- a/core/java/android/view/accessibility/AccessibilityDisplayProxy.java
+++ b/core/java/android/view/accessibility/AccessibilityDisplayProxy.java
@@ -242,11 +242,7 @@
             super(context, executor, new AccessibilityService.Callbacks() {
                 @Override
                 public void onAccessibilityEvent(AccessibilityEvent event) {
-                    // TODO(254545943): Remove check when event processing is done more upstream in
-                    // AccessibilityManagerService.
-                    if (event.getDisplayId() == mDisplayId) {
-                        AccessibilityDisplayProxy.this.onAccessibilityEvent(event);
-                    }
+                    AccessibilityDisplayProxy.this.onAccessibilityEvent(event);
                 }
 
                 @Override
diff --git a/core/java/android/view/accessibility/AccessibilityManager.java b/core/java/android/view/accessibility/AccessibilityManager.java
index 423c560..9abbba9 100644
--- a/core/java/android/view/accessibility/AccessibilityManager.java
+++ b/core/java/android/view/accessibility/AccessibilityManager.java
@@ -25,6 +25,7 @@
 import android.accessibilityservice.AccessibilityShortcutInfo;
 import android.annotation.CallbackExecutor;
 import android.annotation.ColorInt;
+import android.annotation.FloatRange;
 import android.annotation.IntDef;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
@@ -75,6 +76,7 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.Executor;
 
 /**
@@ -138,6 +140,21 @@
     public static final int AUTOCLICK_DELAY_DEFAULT = 600;
 
     /**
+     * The contrast is defined as a float in [-1, 1], with a default value of 0.
+     * @hide
+     */
+    public static final float CONTRAST_MIN_VALUE = -1f;
+
+    /** @hide */
+    public static final float CONTRAST_MAX_VALUE = 1f;
+
+    /** @hide */
+    public static final float CONTRAST_DEFAULT_VALUE = 0f;
+
+    /** @hide */
+    public static final float CONTRAST_NOT_SET = Float.MIN_VALUE;
+
+    /**
      * Activity action: Launch UI to manage which accessibility service or feature is assigned
      * to the navigation bar Accessibility button.
      * <p>
@@ -246,6 +263,8 @@
     @UnsupportedAppUsage(trackingBug = 123768939L)
     boolean mIsHighTextContrastEnabled;
 
+    private float mUiContrast;
+
     boolean mIsAudioDescriptionByDefaultRequested;
 
     // accessibility tracing state
@@ -270,6 +289,9 @@
     private final ArrayMap<HighTextContrastChangeListener, Handler>
             mHighTextContrastStateChangeListeners = new ArrayMap<>();
 
+    private final ArrayMap<UiContrastChangeListener, Executor>
+            mUiContrastChangeListeners = new ArrayMap<>();
+
     private final ArrayMap<AccessibilityServicesStateChangeListener, Executor>
             mServicesStateChangeListeners = new ArrayMap<>();
 
@@ -336,7 +358,7 @@
          *
          * @param manager The manager that is calling back
          */
-        void onAccessibilityServicesStateChanged(@NonNull  AccessibilityManager manager);
+        void onAccessibilityServicesStateChanged(@NonNull AccessibilityManager manager);
     }
 
     /**
@@ -358,6 +380,21 @@
     }
 
     /**
+     * Listener for the UI contrast. To listen for changes to
+     * the UI contrast on the device, implement this interface and
+     * register it with the system by calling {@link #addUiContrastChangeListener}.
+     */
+    public interface UiContrastChangeListener {
+
+        /**
+         * Called when the color contrast enabled state changes.
+         *
+         * @param uiContrast The color contrast as in {@link #getUiContrast}
+         */
+        void onUiContrastChanged(@FloatRange(from = -1.0f, to = 1.0f) float uiContrast);
+    }
+
+    /**
      * Listener for the audio description by default state. To listen for
      * changes to the audio description by default state on the device,
      * implement this interface and register it with the system by calling
@@ -471,6 +508,16 @@
                 updateFocusAppearanceLocked(strokeWidth, color);
             }
         }
+
+        @Override
+        public void setUiContrast(float contrast) {
+            synchronized (mLock) {
+                // if value changed in the settings, update the cached value and notify listeners
+                if (Math.abs(mUiContrast - contrast) < 1e-10) return;
+                mUiContrast = contrast;
+            }
+            mHandler.obtainMessage(MyCallback.MSG_NOTIFY_CONTRAST_CHANGED).sendToTarget();
+        }
     };
 
     /**
@@ -641,7 +688,7 @@
     /**
      * Returns if the high text contrast in the system is enabled.
      * <p>
-     * <strong>Note:</strong> You need to query this only if you application is
+     * <strong>Note:</strong> You need to query this only if your application is
      * doing its own rendering and does not rely on the platform rendering pipeline.
      * </p>
      *
@@ -661,6 +708,24 @@
     }
 
     /**
+     * Returns the color contrast for the user.
+     * <p>
+     * <strong>Note:</strong> You need to query this only if your application is
+     * doing its own rendering and does not rely on the platform rendering pipeline.
+     * </p>
+     * @return The color contrast, float in [-1, 1] where
+     *          0 corresponds to the default contrast
+     *         -1 corresponds to the minimum contrast that the user can set
+     *          1 corresponds to the maximum contrast that the user can set
+     */
+    @FloatRange(from = -1.0f, to = 1.0f)
+    public float getUiContrast() {
+        synchronized (mLock) {
+            return mUiContrast;
+        }
+    }
+
+    /**
      * Sends an {@link AccessibilityEvent}.
      *
      * @param event The event to send.
@@ -1240,6 +1305,35 @@
     }
 
     /**
+     * Registers a {@link UiContrastChangeListener} for the current user.
+     *
+     * @param executor The executor on which the listener should be called back.
+     * @param listener The listener.
+     */
+    public void addUiContrastChangeListener(
+            @NonNull @CallbackExecutor Executor executor,
+            @NonNull UiContrastChangeListener listener) {
+        Objects.requireNonNull(executor);
+        Objects.requireNonNull(listener);
+        synchronized (mLock) {
+            mUiContrastChangeListeners.put(listener, executor);
+        }
+    }
+
+    /**
+     * Unregisters a {@link UiContrastChangeListener} for the current user.
+     * If the listener was not registered, does nothing and returns.
+     *
+     * @param listener The listener to unregister.
+     */
+    public void removeUiContrastChangeListener(@NonNull UiContrastChangeListener listener) {
+        Objects.requireNonNull(listener);
+        synchronized (mLock) {
+            mUiContrastChangeListeners.remove(listener);
+        }
+    }
+
+    /**
      * Registers a {@link AudioDescriptionRequestedChangeListener}
      * for changes in the audio description by default state of the system.
      * The value could be read via {@link #isAudioDescriptionRequested}.
@@ -2004,6 +2098,7 @@
             mRelevantEventTypes = IntPair.second(userStateAndRelevantEvents);
             updateUiTimeout(service.getRecommendedTimeoutMillis());
             updateFocusAppearanceLocked(service.getFocusStrokeWidth(), service.getFocusColor());
+            mUiContrast = service.getUiContrast();
             mService = service;
         } catch (RemoteException re) {
             Log.e(LOG_TAG, "AccessibilityManagerService is dead", re);
@@ -2082,6 +2177,22 @@
     }
 
     /**
+     * Notifies the registered {@link UiContrastChangeListener}s if the value changed.
+     */
+    private void notifyUiContrastChanged() {
+        final ArrayMap<UiContrastChangeListener, Executor> listeners;
+        synchronized (mLock) {
+            listeners = new ArrayMap<>(mUiContrastChangeListeners);
+        }
+
+        listeners.entrySet().forEach(entry -> {
+            UiContrastChangeListener listener = entry.getKey();
+            Executor executor = entry.getValue();
+            executor.execute(() -> listener.onUiContrastChanged(mUiContrast));
+        });
+    }
+
+    /**
      * Notifies the registered {@link AudioDescriptionStateChangeListener}s.
      */
     private void notifyAudioDescriptionbyDefaultStateChanged() {
@@ -2171,6 +2282,7 @@
 
     private final class MyCallback implements Handler.Callback {
         public static final int MSG_SET_STATE = 1;
+        public static final int MSG_NOTIFY_CONTRAST_CHANGED = 2;
 
         @Override
         public boolean handleMessage(Message message) {
@@ -2182,6 +2294,9 @@
                         setStateLocked(state);
                     }
                 } break;
+                case MSG_NOTIFY_CONTRAST_CHANGED: {
+                    notifyUiContrastChanged();
+                }
             }
             return true;
         }
diff --git a/core/java/android/view/accessibility/IAccessibilityManager.aidl b/core/java/android/view/accessibility/IAccessibilityManager.aidl
index 364c7c8..c2d899a 100644
--- a/core/java/android/view/accessibility/IAccessibilityManager.aidl
+++ b/core/java/android/view/accessibility/IAccessibilityManager.aidl
@@ -118,4 +118,6 @@
 
     // Used by UiAutomation for tests on the InputFilter
     void injectInputEventToInputFilter(in InputEvent event);
+
+    float getUiContrast();
 }
diff --git a/core/java/android/view/accessibility/IAccessibilityManagerClient.aidl b/core/java/android/view/accessibility/IAccessibilityManagerClient.aidl
index 041399c..931f862 100644
--- a/core/java/android/view/accessibility/IAccessibilityManagerClient.aidl
+++ b/core/java/android/view/accessibility/IAccessibilityManagerClient.aidl
@@ -31,4 +31,6 @@
     void setRelevantEventTypes(int eventTypes);
 
     void setFocusAppearance(int strokeWidth, int color);
+
+    void setUiContrast(float contrast);
 }
diff --git a/core/java/android/view/inputmethod/TextBoundsInfo.java b/core/java/android/view/inputmethod/TextBoundsInfo.java
index 4e87405..dd05543 100644
--- a/core/java/android/view/inputmethod/TextBoundsInfo.java
+++ b/core/java/android/view/inputmethod/TextBoundsInfo.java
@@ -25,6 +25,7 @@
 import android.os.Bundle;
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.text.Layout;
 import android.text.SegmentFinder;
 
 import com.android.internal.util.ArrayUtils;
@@ -314,6 +315,554 @@
     }
 
     /**
+     * Return the index of the closest character to the given position.
+     * It's similar to the text layout API {@link Layout#getOffsetForHorizontal(int, float)}.
+     * And it's mainly used to find the cursor index (the index of the character before which the
+     * cursor should be placed) for the given position. It's guaranteed that the returned index is
+     * a grapheme break. Check {@link #getGraphemeSegmentFinder()} for more information.
+     *
+     * <p>It's assumed that the editor lays out text in horizontal lines from top to bottom and each
+     * line is laid out according to the display algorithm specified in
+     * <a href="https://unicode.org/reports/tr9/#Basic_Display_Algorithm"> unicode bidirectional
+     * algorithm</a>.
+     * </p>
+     *
+     * <p> This method won't check the text ranges whose line information is missing. For example,
+     * the {@link TextBoundsInfo}'s range is from index 5 to 15. If the associated
+     * {@link SegmentFinder} only identifies one line range from 7 to 12. Then this method
+     * won't check the text in the ranges of [5, 7) and [12, 15).
+     * </p>
+     *
+     * @param x the x coordinates of the interested location, in the editor's coordinates.
+     * @param y the y coordinates of the interested location, in the editor's coordinates.
+     * @return the index of the character whose position is closest to the given location. It will
+     * return -1 if it can't find a character.
+     *
+     * @see Layout#getOffsetForHorizontal(int, float)
+     */
+    public int getOffsetForPosition(float x, float y) {
+        final int[] lineRange = new int[2];
+        final RectF lineBounds = new RectF();
+        getLineInfo(y, lineRange, lineBounds);
+        // No line is found, return -1;
+        if (lineRange[0] == -1 || lineRange[1] == -1) return -1;
+        final int lineStart = lineRange[0];
+        final int lineEnd = lineRange[1];
+
+        final boolean lineEndsWithLinefeed =
+                (getCharacterFlags(lineEnd - 1) & FLAG_CHARACTER_LINEFEED) != 0;
+
+        // Consider the following 2 cases:
+        // Case 1:
+        //   Text: "AB\nCD"
+        //   Layout: AB
+        //           CD
+        // Case 2:
+        //   Text: "ABCD"
+        //   Layout: AB
+        //           CD
+        // If user wants to insert a 'X' character at the end of the first line:
+        //   In case 1, 'X' is inserted before the last character '\n'.
+        //   In case 2, 'X' is inserted after the last character 'B'.
+        // So if a line ends with linefeed, it shouldn't check the cursor position after the last
+        // character.
+        final int lineLimit;
+        if (lineEndsWithLinefeed) {
+            lineLimit = lineEnd;
+        } else {
+            lineLimit = lineEnd + 1;
+        }
+        // Point graphemeStart to the start of the first grapheme segment intersects with the line.
+        int graphemeStart = mGraphemeSegmentFinder.nextEndBoundary(lineStart);
+        // The grapheme information is missing.
+        if (graphemeStart == SegmentFinder.DONE) return -1;
+        graphemeStart = mGraphemeSegmentFinder.previousStartBoundary(graphemeStart);
+
+        int target = -1;
+        float minDistance = Float.MAX_VALUE;
+        while (graphemeStart != SegmentFinder.DONE && graphemeStart < lineLimit) {
+            if (graphemeStart >= lineStart) {
+                float cursorPosition = getCursorHorizontalPosition(graphemeStart, lineStart,
+                        lineEnd, lineBounds.left, lineBounds.right);
+                final float distance = Math.abs(cursorPosition - x);
+                if (distance < minDistance) {
+                    minDistance = distance;
+                    target = graphemeStart;
+                }
+            }
+            graphemeStart = mGraphemeSegmentFinder.nextStartBoundary(graphemeStart);
+        }
+
+        return target;
+    }
+
+    /**
+     * Whether the primary position at the given index is the previous character's trailing
+     * position. <br/>
+     *
+     * For LTR character, trailing position is its right edge. For RTL character, trailing position
+     * is its left edge.
+     *
+     * The primary position is defined as the position of a newly inserted character with the
+     * context direction at the given offset. In contrast, the secondary position is the position
+     * of a newly inserted character with the context's opposite direction at the given offset.
+     *
+     * In Android, the trailing position is used for primary position when the direction run after
+     * the given index has a higher level than the current direction run.
+     *
+     * <p>
+     * For example:
+     * (L represents LTR character, and R represents RTL character. The number is the index)
+     * <pre>
+     * input text:          L0 L1 L2 R3 R4 R5 L6 L7 L8
+     * render result:       L0 L1 L2 R5 R4 R3 L6 L7 L8
+     * BiDi Run:            [ Run 0 ][ Run 1 ][ Run 2 ]
+     * BiDi Level:          0  0  0  1  1  1  0  0  0
+     * </pre>
+     *
+     * The index 3 is a BiDi transition point, the cursor can be placed either after L2 or before
+     * R3. Because the bidi level of run 1 is higher than the run 0, this method returns true. And
+     * the cursor should be placed after L2.
+     * <pre>
+     * render result:       L0 L1 L2 R5 R4 R3 L6 L7 L8
+     * position after L2:           |
+     * position before R3:                   |
+     * result position:             |
+     * </pre>
+     *
+     * The index 6 is also a Bidi transition point, the 2 possible cursor positions are exactly the
+     * same as index 3. However, since the bidi level of run 2 is higher than the run 1, this
+     * method returns false. And the cursor should be placed before L6.
+     * <pre>
+     * render result:       L0 L1 L2 R5 R4 R3 L6 L7 L8
+     * position after R5:           |
+     * position before L6:                   |
+     * result position:                      |
+     * </pre>
+     *
+     * This method helps guarantee that the cursor index and the cursor position forms a one to
+     * one relation.
+     * </p>
+     *
+     * @param offset the offset of the character in front of which the cursor is placed. It must be
+     *              the start index of a grapheme. And it must be in the range from lineStart to
+     *              lineEnd. An offset equal to lineEnd is allowed. It indicates that the cursor is
+     *              placed at the end of current line instead of the start of the following line.
+     * @param lineStart the start index of the line that index belongs to, inclusive.
+     * @param lineEnd the end index of the line that index belongs to, exclusive.
+     * @return true if primary position is the trailing position of the previous character.
+     *
+     * @see #getCursorHorizontalPosition(int, int, int, float, float)
+     */
+    private boolean primaryIsTrailingPrevious(int offset, int lineStart, int lineEnd) {
+        final int bidiLevel;
+        if (offset < lineEnd) {
+            bidiLevel = getCharacterBidiLevel(offset);
+        } else {
+            // index equals to lineEnd, use line's BiDi level for the BiDi run.
+            boolean lineIsRtl =
+                    (getCharacterFlags(offset - 1) & FLAG_LINE_IS_RTL) == FLAG_LINE_IS_RTL;
+            bidiLevel = lineIsRtl ? 1 : 0;
+        }
+        final int bidiLevelBefore;
+        if (offset > lineStart) {
+            // Here it assumes index is always the start of a grapheme. And (index - 1) belongs to
+            // the previous grapheme.
+            bidiLevelBefore = getCharacterBidiLevel(offset - 1);
+        } else {
+            // index equals to lineStart, use line's BiDi level for previous BiDi run.
+            boolean lineIsRtl =
+                    (getCharacterFlags(offset) & FLAG_LINE_IS_RTL) == FLAG_LINE_IS_RTL;
+            bidiLevelBefore = lineIsRtl ? 1 : 0;
+        }
+        return bidiLevelBefore < bidiLevel;
+    }
+
+    /**
+     * Returns the x coordinates of the cursor at the given index. (The index of the character
+     * before which the cursor should be placed.)
+     *
+     * @param index the character index before which the cursor is placed. It must be the start
+     *              index of a grapheme. It must be in the range from lineStart to lineEnd.
+     *              An index equal to lineEnd is allowed. It indicates that the cursor is
+     *              placed at the end of current line instead of the start of the following line.
+     * @param lineStart start index of the line that index belongs to, inclusive.
+     * @param lineEnd end index of the line that index belongs, exclusive.
+     * @return the x coordinates of the cursor at the given index,
+     *
+     * @see #primaryIsTrailingPrevious(int, int, int)
+     */
+    private float getCursorHorizontalPosition(int index, int lineStart, int lineEnd,
+            float lineLeft, float lineRight) {
+        Preconditions.checkArgumentInRange(index, lineStart, lineEnd, "index");
+        final boolean lineIsRtl = (getCharacterFlags(lineStart) & FLAG_LINE_IS_RTL) != 0;
+        final boolean isPrimaryIsTrailingPrevious =
+                primaryIsTrailingPrevious(index, lineStart, lineEnd);
+
+        // The index of the character used to compute the cursor position.
+        final int targetIndex;
+        // Whether to use the start position of the character.
+        // For LTR character start is the left edge. For RTL character, start is the right edge.
+        final boolean isStart;
+        if (isPrimaryIsTrailingPrevious) {
+            // (index - 1) belongs to the previous line(if any), return the line start position.
+            if (index <= lineStart) {
+                return lineIsRtl ? lineRight : lineLeft;
+            }
+            targetIndex = index - 1;
+            isStart = false;
+        } else {
+            // index belongs to the next line(if any), return the line end position.
+            if (index >= lineEnd) {
+                return lineIsRtl ? lineLeft : lineRight;
+            }
+            targetIndex = index;
+            isStart = true;
+        }
+
+        // The BiDi level is odd when the character is RTL.
+        final boolean isRtl = (getCharacterBidiLevel(targetIndex) & 1) != 0;
+        final int offset = targetIndex - mStart;
+        // If the character is RTL, the start is the right edge. Otherwise, the start is the
+        // left edge:
+        //  +-----------------------+
+        //  |       | start | end   |
+        //  |-------+-------+-------|
+        //  | RTL   | right | left  |
+        //  |-------+-------+-------|
+        //  | LTR   | left  | right |
+        //  +-------+-------+-------+
+        return (isRtl != isStart) ? mCharacterBounds[4 * offset] : mCharacterBounds[4 * offset + 2];
+    }
+
+    /**
+     * Return the minimal rectangle that contains all the characters in the given range.
+     *
+     * @param start the start index of the given range, inclusive.
+     * @param end the end index of the given range, exclusive.
+     * @param rectF the {@link RectF} to receive the bounds.
+     */
+    private void getBoundsForRange(int start, int end, @NonNull RectF rectF) {
+        Preconditions.checkArgumentInRange(start, mStart, mEnd - 1, "start");
+        Preconditions.checkArgumentInRange(end, start, mEnd, "end");
+        if (end <= start) {
+            rectF.setEmpty();
+            return;
+        }
+
+        rectF.left = Float.MAX_VALUE;
+        rectF.top = Float.MAX_VALUE;
+        rectF.right = Float.MIN_VALUE;
+        rectF.bottom = Float.MIN_VALUE;
+        for (int index = start; index < end; ++index) {
+            final int offset = index - mStart;
+            rectF.left = Math.min(rectF.left, mCharacterBounds[4 * offset]);
+            rectF.top = Math.min(rectF.top, mCharacterBounds[4 * offset + 1]);
+            rectF.right = Math.max(rectF.right, mCharacterBounds[4 * offset + 2]);
+            rectF.bottom = Math.max(rectF.bottom, mCharacterBounds[4 * offset + 3]);
+        }
+    }
+
+    /**
+     * Return the character range and bounds of the closest line to the given {@code y} coordinate,
+     * in the editor's local coordinates.
+     *
+     * If the given y is above the first line or below the last line -1 will be returned for line
+     * start and end.
+     *
+     * This method assumes that the lines are laid out from the top to bottom.
+     *
+     * @param y the y coordinates used to search for the line.
+     * @param characterRange a two element array used to receive the character range of the line.
+     *                       If no valid line is found -1 will be returned for both start and end.
+     * @param bounds {@link RectF} to receive the line bounds result, nullable. If given, it can
+     *                            still be modified even if no valid line is found.
+     */
+    private void getLineInfo(float y, @NonNull int[] characterRange, @Nullable RectF bounds) {
+        characterRange[0] = -1;
+        characterRange[1] = -1;
+
+        // Starting from the first line.
+        int currentLineEnd = mLineSegmentFinder.nextEndBoundary(mStart);
+        if (currentLineEnd == SegmentFinder.DONE) return;
+        int currentLineStart = mLineSegmentFinder.previousStartBoundary(currentLineEnd);
+
+        float top = Float.MAX_VALUE;
+        float bottom = Float.MIN_VALUE;
+        float minDistance = Float.MAX_VALUE;
+        final RectF currentLineBounds = new RectF();
+        while (currentLineStart != SegmentFinder.DONE && currentLineStart < mEnd) {
+            final int lineStartInRange = Math.max(mStart, currentLineStart);
+            final int lineEndInRange = Math.min(mEnd, currentLineEnd);
+            getBoundsForRange(lineStartInRange, lineEndInRange, currentLineBounds);
+
+            top = Math.min(currentLineBounds.top, top);
+            bottom = Math.max(currentLineBounds.bottom, bottom);
+
+            final float distance = verticalDistance(currentLineBounds, y);
+
+            if (distance == 0f) {
+                characterRange[0] = currentLineStart;
+                characterRange[1] = currentLineEnd;
+                if (bounds != null) {
+                    bounds.set(currentLineBounds);
+                }
+                return;
+            }
+
+            if (distance < minDistance) {
+                minDistance = distance;
+                characterRange[0] = currentLineStart;
+                characterRange[1] = currentLineEnd;
+                if (bounds != null) {
+                    bounds.set(currentLineBounds);
+                }
+            }
+            if (y < bounds.top) break;
+            currentLineStart = mLineSegmentFinder.nextStartBoundary(currentLineStart);
+            currentLineEnd = mLineSegmentFinder.nextEndBoundary(currentLineEnd);
+        }
+
+        // y is above the first line or below the last line. The founded line is still invalid,
+        // clear the result.
+        if (y < top || y > bottom) {
+            characterRange[0] = -1;
+            characterRange[1] = -1;
+            if (bounds != null) {
+                bounds.setEmpty();
+            }
+        }
+    }
+
+    /**
+     * Finds the range of text which is inside the specified rectangle area. This method is a
+     * counterpart of the
+     * {@link Layout#getRangeForRect(RectF, SegmentFinder, Layout.TextInclusionStrategy)}.
+     *
+     * <p>It's assumed that the editor lays out text in horizontal lines from top to bottom
+     * and each line is laid out according to the display algorithm specified in
+     * <a href="https://unicode.org/reports/tr9/#Basic_Display_Algorithm"> unicode bidirectional
+     * algorithm</a>.
+     * </p>
+     *
+     * <p> This method won't check the text ranges whose line information is missing. For example,
+     * the {@link TextBoundsInfo}'s range is from index 5 to 15. If the associated line
+     * {@link SegmentFinder} only identifies one line range from 7 to 12. Then this method
+     * won't check the text in the ranges of [5, 7) and [12, 15).
+     * </p>
+     *
+     * @param area area for which the text range will be found
+     * @param segmentFinder SegmentFinder for determining the ranges of text to be considered as a
+     *     text segment
+     * @param inclusionStrategy strategy for determining whether a text segment is inside the
+     *          specified area
+     * @return the text range stored in a two element int array. The first element is the
+     * start (inclusive) of the text range, and the second element is the end (exclusive) character
+     * offsets of the text range, or null if there are no text segments inside the area.
+     *
+     * @see Layout#getRangeForRect(RectF, SegmentFinder, Layout.TextInclusionStrategy)
+     */
+    @Nullable
+    public int[] getRangeForRect(@NonNull RectF area, @NonNull SegmentFinder segmentFinder,
+            @NonNull Layout.TextInclusionStrategy inclusionStrategy) {
+        int lineEnd = mLineSegmentFinder.nextEndBoundary(mStart);
+        // Line information is missing.
+        if (lineEnd == SegmentFinder.DONE) return null;
+        int lineStart = mLineSegmentFinder.previousStartBoundary(lineEnd);
+
+        int start = -1;
+        while (lineStart != SegmentFinder.DONE && start == -1) {
+            start = getStartForRectWithinLine(lineStart, lineEnd, area, segmentFinder,
+                    inclusionStrategy);
+            lineStart = mLineSegmentFinder.nextStartBoundary(lineStart);
+            lineEnd = mLineSegmentFinder.nextEndBoundary(lineEnd);
+        }
+
+        // Can't find the start index; the specified contains no valid segment.
+        if (start == -1) return null;
+
+        lineStart = mLineSegmentFinder.previousStartBoundary(mEnd);
+        // Line information is missing.
+        if (lineStart == SegmentFinder.DONE) return null;
+        lineEnd = mLineSegmentFinder.nextEndBoundary(lineStart);
+        int end = -1;
+        while (lineEnd > start && end == -1) {
+            end = getEndForRectWithinLine(lineStart, lineEnd, area, segmentFinder,
+                    inclusionStrategy);
+            lineStart = mLineSegmentFinder.previousStartBoundary(lineStart);
+            lineEnd = mLineSegmentFinder.previousEndBoundary(lineEnd);
+        }
+
+        // We've already found start, end is guaranteed to be found at this point.
+        start = segmentFinder.previousStartBoundary(start + 1);
+        end = segmentFinder.nextEndBoundary(end - 1);
+        return new int[] { start, end };
+    }
+
+    /**
+     * Find the start character index of the first text segments within a line inside the specified
+     * {@code area}.
+     *
+     * @param lineStart the start of this line, inclusive .
+     * @param lineEnd the end of this line, exclusive.
+     * @param area the area inside which the text segments will be found.
+     * @param segmentFinder SegmentFinder for determining the ranges of text to be considered a
+     *                      text segment.
+     * @param inclusionStrategy strategy for determining whether a text segment is inside the
+     *                          specified area.
+     * @return the start index of the first segment in the area.
+     */
+    private int getStartForRectWithinLine(int lineStart, int lineEnd, @NonNull RectF area,
+            @NonNull SegmentFinder segmentFinder,
+            @NonNull Layout.TextInclusionStrategy inclusionStrategy) {
+        if (lineStart >= lineEnd) return -1;
+
+        int runStart = lineStart;
+        int runLevel = -1;
+        // Check the BiDi runs and search for the start index.
+        for (int index = lineStart; index < lineEnd; ++index) {
+            final int level = getCharacterBidiLevel(index);
+            if (level != runLevel) {
+                final int start = getStartForRectWithinRun(runStart, index, area, segmentFinder,
+                        inclusionStrategy);
+                if (start != -1) {
+                    return start;
+                }
+
+                runStart = index;
+                runLevel = level;
+            }
+        }
+        return getStartForRectWithinRun(runStart, lineEnd, area, segmentFinder, inclusionStrategy);
+    }
+
+    /**
+     * Find the start character index of the first text segments within the directional run inside
+     * the specified {@code area}.
+     *
+     * @param runStart the start of this directional run, inclusive.
+     * @param runEnd the end of this directional run, exclusive.
+     * @param area the area inside which the text segments will be found.
+     * @param segmentFinder SegmentFinder for determining the ranges of text to be considered a
+     *                      text segment.
+     * @param inclusionStrategy strategy for determining whether a text segment is inside the
+     *                          specified area.
+     * @return the start index of the first segment in the area.
+     */
+    private int getStartForRectWithinRun(int runStart, int runEnd, @NonNull RectF area,
+            @NonNull SegmentFinder segmentFinder,
+            @NonNull Layout.TextInclusionStrategy inclusionStrategy) {
+        if (runStart >= runEnd) return -1;
+
+        int segmentEndOffset = segmentFinder.nextEndBoundary(runStart);
+        // No segment is found in run.
+        if (segmentEndOffset == SegmentFinder.DONE) return -1;
+        int segmentStartOffset = segmentFinder.previousStartBoundary(segmentEndOffset);
+
+        final RectF segmentBounds = new RectF();
+        while (segmentStartOffset != SegmentFinder.DONE && segmentStartOffset < runEnd) {
+            final int start = Math.max(runStart, segmentStartOffset);
+            final int end = Math.min(runEnd, segmentEndOffset);
+            getBoundsForRange(start, end, segmentBounds);
+            // Find the first segment inside the area, return the start.
+            if (inclusionStrategy.isSegmentInside(segmentBounds, area)) return start;
+
+            segmentStartOffset = segmentFinder.nextStartBoundary(segmentStartOffset);
+            segmentEndOffset = segmentFinder.nextEndBoundary(segmentEndOffset);
+        }
+        return -1;
+    }
+
+    /**
+     * Find the end character index of the last text segments within a line inside the specified
+     * {@code area}.
+     *
+     * @param lineStart the start of this line, inclusive .
+     * @param lineEnd the end of this line, exclusive.
+     * @param area the area inside which the text segments will be found.
+     * @param segmentFinder SegmentFinder for determining the ranges of text to be considered a
+     *                      text segment.
+     * @param inclusionStrategy strategy for determining whether a text segment is inside the
+     *                          specified area.
+     * @return the end index of the last segment in the area.
+     */
+    private int getEndForRectWithinLine(int lineStart, int lineEnd, @NonNull RectF area,
+            @NonNull SegmentFinder segmentFinder,
+            @NonNull Layout.TextInclusionStrategy inclusionStrategy) {
+        if (lineStart >= lineEnd) return -1;
+        lineStart = Math.max(lineStart, mStart);
+        lineEnd = Math.min(lineEnd, mEnd);
+
+        // The exclusive run end index.
+        int runEnd = lineEnd;
+        int runLevel = -1;
+        // Check the BiDi runs backwards and search for the end index.
+        for (int index = lineEnd - 1; index >= lineStart; --index) {
+            final int level = getCharacterBidiLevel(index);
+            if (level != runLevel) {
+                final int end = getEndForRectWithinRun(index + 1, runEnd, area, segmentFinder,
+                        inclusionStrategy);
+                if (end != -1) return end;
+
+                runEnd = index + 1;
+                runLevel = level;
+            }
+        }
+        return getEndForRectWithinRun(lineStart, runEnd, area, segmentFinder, inclusionStrategy);
+    }
+
+    /**
+     * Find the end character index of the last text segments within the directional run inside the
+     * specified {@code area}.
+     *
+     * @param runStart the start of this directional run, inclusive.
+     * @param runEnd the end of this directional run, exclusive.
+     * @param area the area inside which the text segments will be found.
+     * @param segmentFinder SegmentFinder for determining the ranges of text to be considered a
+     *                      text segment.
+     * @param inclusionStrategy strategy for determining whether a text segment is inside the
+     *                          specified area.
+     * @return the end index of the last segment in the area.
+     */
+    private int getEndForRectWithinRun(int runStart, int runEnd, @NonNull RectF area,
+            @NonNull SegmentFinder segmentFinder,
+            @NonNull Layout.TextInclusionStrategy inclusionStrategy) {
+        if (runStart >= runEnd) return -1;
+
+        int segmentStart = segmentFinder.previousStartBoundary(runEnd);
+        // No segment is found before the runEnd.
+        if (segmentStart == SegmentFinder.DONE) return -1;
+        int segmentEnd = segmentFinder.nextEndBoundary(segmentStart);
+
+        final RectF segmentBounds = new RectF();
+        while (segmentEnd != SegmentFinder.DONE && segmentEnd > runStart) {
+            final int start = Math.max(runStart, segmentStart);
+            final int end = Math.min(runEnd, segmentEnd);
+            getBoundsForRange(start, end, segmentBounds);
+            // Find the last segment inside the area, return the end.
+            if (inclusionStrategy.isSegmentInside(segmentBounds, area)) return end;
+
+            segmentStart = segmentFinder.previousStartBoundary(segmentStart);
+            segmentEnd = segmentFinder.previousEndBoundary(segmentEnd);
+        }
+        return -1;
+    }
+
+    /**
+     * Get the vertical distance from the {@code pointF} to the {@code rectF}. It's useful to find
+     * the corresponding line for a given point.
+     */
+    private static float verticalDistance(@NonNull RectF rectF, float y) {
+        if (rectF.top <= y && y < rectF.bottom) {
+            return 0f;
+        }
+        if (y < rectF.top) {
+            return rectF.top - y;
+        }
+        return y - rectF.bottom;
+    }
+
+    /**
      * Describe the kinds of special objects contained in this Parcelable
      * instance's marshaled representation. For example, if the object will
      * include a file descriptor in the output of {@link #writeToParcel(Parcel, int)},
diff --git a/core/java/android/window/SurfaceSyncGroup.java b/core/java/android/window/SurfaceSyncGroup.java
index 3950739..250652a 100644
--- a/core/java/android/window/SurfaceSyncGroup.java
+++ b/core/java/android/window/SurfaceSyncGroup.java
@@ -40,64 +40,65 @@
  * mechanism so each sync implementation doesn't need to handle it themselves. The SurfaceSyncGroup
  * class is used the following way.
  *
- * 1. {@link #SurfaceSyncGroup()} constructor is called
- * 2. {@link #addToSync(SyncTarget)} is called for every SyncTarget object that wants to be
- * included in the sync. If the addSync is called for an {@link AttachedSurfaceControl} or
- * {@link SurfaceView} it needs to be called on the UI thread. When addToSync is called, it's
+ * 1. {@link #addToSync(SurfaceSyncGroup, boolean)} is called for every SurfaceSyncGroup object that
+ * wants to be included in the sync. If the addSync is called for an {@link AttachedSurfaceControl}
+ * or {@link SurfaceView} it needs to be called on the UI thread. When addToSync is called, it's
  * guaranteed that any UI updates that were requested before addToSync but after the last frame
  * drew, will be included in the sync.
- * 3. {@link #markSyncReady()} should be called when all the {@link SyncTarget}s have been added
- * to the SurfaceSyncGroup. At this point, the SurfaceSyncGroup is closed and no more SyncTargets
- * can be added to it.
- * 4. The SurfaceSyncGroup will gather the data for each SyncTarget using the steps described below.
- * When all the SyncTargets have finished, the syncRequestComplete will be invoked and the
- * transaction will either be applied or sent to the caller. In most cases, only the
- * SurfaceSyncGroup  should be handling the Transaction object directly. However, there are some
+ * 2. {@link #markSyncReady()} should be called when all the {@link SurfaceSyncGroup}s have been
+ * added to the SurfaceSyncGroup. At this point, the SurfaceSyncGroup is closed and no more
+ * SurfaceSyncGroups can be added to it.
+ * 3. The SurfaceSyncGroup will gather the data for each SurfaceSyncGroup using the steps described
+ * below. When all the SurfaceSyncGroups have finished, the syncRequestComplete will be invoked and
+ * the transaction will either be applied or sent to the caller. In most cases, only the
+ * SurfaceSyncGroup should be handling the Transaction object directly. However, there are some
  * cases where the framework needs to send the Transaction elsewhere, like in ViewRootImpl, so that
  * option is provided.
  *
- * The following is what happens within the {@link SurfaceSyncGroup}
- * 1. Each SyncTarget will get a {@link SyncTarget#onAddedToSyncGroup} callback that contains a
- * {@link TransactionReadyCallback}.
- * 2. Each {@link SyncTarget} needs to invoke
- * {@link TransactionReadyCallback#onTransactionReady(Transaction)}. This makes sure the
- * SurfaceSyncGroup knows when the SyncTarget is complete, allowing the SurfaceSyncGroup to get the
- * Transaction that contains the buffer.
- * 3. When the final TransactionReadyCallback finishes for the SurfaceSyncGroup, in most cases the
- * transaction is applied and then the sync complete callbacks are invoked, letting the callers know
- * the sync is now complete.
+ * The following is what happens within the {@link android.window.SurfaceSyncGroup}
+ * 1. Each SurfaceSyncGroup will get a
+ * {@link SurfaceSyncGroup#onAddedToSyncGroup(SurfaceSyncGroup, TransactionReadyCallback)} callback
+ * that contains a  {@link TransactionReadyCallback}.
+ * 2. Each {@link SurfaceSyncGroup} needs to invoke
+ * {@link SurfaceSyncGroup#onTransactionReady(Transaction)}.
+ * This makes sure the parent SurfaceSyncGroup knows when the SurfaceSyncGroup is complete, allowing
+ * the parent SurfaceSyncGroup to get the Transaction that contains the changes for the child
+ * SurfaceSyncGroup
+ * 3. When the final TransactionReadyCallback finishes for the child SurfaceSyncGroups, the
+ * transaction is either applied if it's the top most parent or the final merged transaction is sent
+ * up to its parent SurfaceSyncGroup.
  *
  * @hide
  */
-public final class SurfaceSyncGroup {
+public class SurfaceSyncGroup {
     private static final String TAG = "SurfaceSyncGroup";
     private static final boolean DEBUG = false;
 
     private static Supplier<Transaction> sTransactionFactory = Transaction::new;
 
     /**
-     * Class that collects the {@link SyncTarget}s and notifies when all the surfaces have
+     * Class that collects the {@link SurfaceSyncGroup}s and notifies when all the surfaces have
      * a frame ready.
      */
     private final Object mLock = new Object();
 
     @GuardedBy("mLock")
-    private final Set<Integer> mPendingSyncs = new ArraySet<>();
+    private final Set<TransactionReadyCallback> mPendingSyncs = new ArraySet<>();
     @GuardedBy("mLock")
     private final Transaction mTransaction = sTransactionFactory.get();
     @GuardedBy("mLock")
     private boolean mSyncReady;
 
     @GuardedBy("mLock")
-    private Consumer<Transaction> mSyncRequestCompleteCallback;
-
-    @GuardedBy("mLock")
-    private final Set<SurfaceSyncGroup> mMergedSyncGroups = new ArraySet<>();
-
-    @GuardedBy("mLock")
     private boolean mFinished;
 
     @GuardedBy("mLock")
+    private TransactionReadyCallback mTransactionReadyCallback;
+
+    @GuardedBy("mLock")
+    private SurfaceSyncGroup mParentSyncGroup;
+
+    @GuardedBy("mLock")
     private final ArraySet<Pair<Executor, Runnable>> mSyncCompleteCallbacks = new ArraySet<>();
 
     /**
@@ -122,16 +123,16 @@
     /**
      * Creates a sync.
      *
-     * @param syncRequestComplete The complete callback that contains the syncId and transaction
-     *                            with all the sync data merged. The Transaction passed back can be
-     *                            null.
+     * @param transactionReadyCallback The complete callback that contains the syncId and
+     *                                 transaction with all the sync data merged. The Transaction
+     *                                 passed back can be null.
      *
      * NOTE: Only should be used by ViewRootImpl
      * @hide
      */
-    public SurfaceSyncGroup(Consumer<Transaction> syncRequestComplete) {
-        mSyncRequestCompleteCallback = transaction -> {
-            syncRequestComplete.accept(transaction);
+    public SurfaceSyncGroup(Consumer<Transaction> transactionReadyCallback) {
+        mTransactionReadyCallback = transaction -> {
+            transactionReadyCallback.accept(transaction);
             synchronized (mLock) {
                 for (Pair<Executor, Runnable> callback : mSyncCompleteCallbacks) {
                     callback.first.execute(callback.second);
@@ -157,6 +158,31 @@
     }
 
     /**
+     * Mark the sync set as ready to complete. No more data can be added to the specified
+     * syncId.
+     * Once the sync set is marked as ready, it will be able to complete once all Syncables in the
+     * set have completed their sync
+     */
+    public void markSyncReady() {
+        onTransactionReady(null);
+    }
+
+    /**
+     * Similar to {@link #markSyncReady()}, but a transaction is passed in to merge with the
+     * SurfaceSyncGroup.
+     * @param t The transaction that merges into the main Transaction for the SurfaceSyncGroup.
+     */
+    public void onTransactionReady(@Nullable Transaction t) {
+        synchronized (mLock) {
+            mSyncReady = true;
+            if (t != null) {
+                mTransaction.merge(t);
+            }
+            checkIfSyncIsComplete();
+        }
+    }
+
+    /**
      * Add a SurfaceView to a sync set. This is different than
      * {@link #addToSync(AttachedSurfaceControl)} because it requires the caller to notify the start
      * and finish drawing in order to sync.
@@ -171,7 +197,13 @@
     @UiThread
     public boolean addToSync(SurfaceView surfaceView,
             Consumer<SurfaceViewFrameCallback> frameCallbackConsumer) {
-        return addToSync(new SurfaceViewSyncTarget(surfaceView, frameCallbackConsumer));
+        SurfaceSyncGroup surfaceSyncGroup = new SurfaceSyncGroup();
+        if (addToSync(surfaceSyncGroup, false /* parentSyncGroupMerge */)) {
+            frameCallbackConsumer.accept(
+                    () -> surfaceView.syncNextFrame(surfaceSyncGroup::onTransactionReady));
+            return true;
+        }
+        return false;
     }
 
     /**
@@ -185,29 +217,38 @@
         if (viewRoot == null) {
             return false;
         }
-        SyncTarget syncTarget = viewRoot.getSyncTarget();
-        if (syncTarget == null) {
+        SurfaceSyncGroup surfaceSyncGroup = viewRoot.getOrCreateSurfaceSyncGroup();
+        if (surfaceSyncGroup == null) {
             return false;
         }
-        return addToSync(syncTarget);
+        return addToSync(surfaceSyncGroup, false /* parentSyncGroupMerge */);
     }
 
     /**
-     * Add a {@link SyncTarget} to a sync set. The sync set will wait for all
+     * Add a {@link SurfaceSyncGroup} to a sync set. The sync set will wait for all
      * SyncableSurfaces to complete before notifying.
      *
-     * @param syncTarget A SyncTarget that implements how to handle syncing transactions.
-     * @return true if the SyncTarget was successfully added to the SyncGroup, false otherwise.
+     * @param surfaceSyncGroup A SyncableSurface that implements how to handle syncing
+     *                         buffers.
+     * @return true if the SyncGroup was successfully added to the current SyncGroup, false
+     * otherwise.
      */
-    public boolean addToSync(SyncTarget syncTarget) {
+    public boolean addToSync(SurfaceSyncGroup surfaceSyncGroup, boolean parentSyncGroupMerge) {
         TransactionReadyCallback transactionReadyCallback = new TransactionReadyCallback() {
             @Override
             public void onTransactionReady(Transaction t) {
                 synchronized (mLock) {
                     if (t != null) {
+                        // When an older parent sync group is added due to a child syncGroup getting
+                        // added to multiple groups, we need to maintain merge order so the older
+                        // parentSyncGroup transactions are overwritten by anything in the newer
+                        // parentSyncGroup.
+                        if (parentSyncGroupMerge) {
+                            t.merge(mTransaction);
+                        }
                         mTransaction.merge(t);
                     }
-                    mPendingSyncs.remove(hashCode());
+                    mPendingSyncs.remove(this);
                     checkIfSyncIsComplete();
                 }
             }
@@ -216,48 +257,16 @@
         synchronized (mLock) {
             if (mSyncReady) {
                 Log.e(TAG, "Sync " + this + " was already marked as ready. No more "
-                        + "SyncTargets can be added.");
+                        + "SurfaceSyncGroups can be added.");
                 return false;
             }
-            mPendingSyncs.add(transactionReadyCallback.hashCode());
+            mPendingSyncs.add(transactionReadyCallback);
         }
-        syncTarget.onAddedToSyncGroup(this, transactionReadyCallback);
+        surfaceSyncGroup.onAddedToSyncGroup(this, transactionReadyCallback);
         return true;
     }
 
     /**
-     * Mark the sync set as ready to complete. No more data can be added to the specified
-     * syncId.
-     * Once the sync set is marked as ready, it will be able to complete once all Syncables in the
-     * set have completed their sync
-     */
-    public void markSyncReady() {
-        synchronized (mLock) {
-            mSyncReady = true;
-            checkIfSyncIsComplete();
-        }
-    }
-
-    @GuardedBy("mLock")
-    private void checkIfSyncIsComplete() {
-        if (!mSyncReady || !mPendingSyncs.isEmpty() || !mMergedSyncGroups.isEmpty()) {
-            if (DEBUG) {
-                Log.d(TAG, "Syncable is not complete. mSyncReady=" + mSyncReady
-                        + " mPendingSyncs=" + mPendingSyncs.size() + " mergedSyncs="
-                        + mMergedSyncGroups.size());
-            }
-            return;
-        }
-
-        if (DEBUG) {
-            Log.d(TAG, "Successfully finished sync id=" + this);
-        }
-
-        mSyncRequestCompleteCallback.accept(mTransaction);
-        mFinished = true;
-    }
-
-    /**
      * Add a Transaction to this sync set. This allows the caller to provide other info that
      * should be synced with the transactions.
      */
@@ -267,99 +276,68 @@
         }
     }
 
-    private void updateCallback(Consumer<Transaction> transactionConsumer) {
+    @GuardedBy("mLock")
+    private void checkIfSyncIsComplete() {
+        if (mFinished) {
+            if (DEBUG) {
+                Log.d(TAG, "SurfaceSyncGroup=" + this + " is already complete");
+            }
+            return;
+        }
+
+        if (!mSyncReady || !mPendingSyncs.isEmpty()) {
+            if (DEBUG) {
+                Log.d(TAG, "SurfaceSyncGroup=" + this + " is not complete. mSyncReady="
+                        + mSyncReady + " mPendingSyncs=" + mPendingSyncs.size());
+            }
+            return;
+        }
+
+        if (DEBUG) {
+            Log.d(TAG, "Successfully finished sync id=" + this);
+        }
+        mTransactionReadyCallback.onTransactionReady(mTransaction);
+        mFinished = true;
+    }
+
+    private void onAddedToSyncGroup(SurfaceSyncGroup parentSyncGroup,
+            TransactionReadyCallback transactionReadyCallback) {
+        boolean finished = false;
         synchronized (mLock) {
             if (mFinished) {
-                Log.e(TAG, "Attempting to merge SyncGroup " + this + " when sync is"
-                        + " already complete");
-                transactionConsumer.accept(null);
-            }
-
-            final Consumer<Transaction> oldCallback = mSyncRequestCompleteCallback;
-            mSyncRequestCompleteCallback = transaction -> {
-                oldCallback.accept(null);
-                transactionConsumer.accept(transaction);
-            };
-        }
-    }
-
-    /**
-     * Merge a SyncGroup into this SyncGroup. Since SyncGroups could still have pending SyncTargets,
-     * we need to make sure those can still complete before the mergeTo SyncGroup is considered
-     * complete.
-     *
-     * We keep track of all the merged SyncGroups until they are marked as done, and then they
-     * are removed from the set. This SyncGroup is not considered done until all the merged
-     * SyncGroups are done.
-     *
-     * When the merged SyncGroup is complete, it will invoke the original syncRequestComplete
-     * callback but send an empty transaction to ensure the changes are applied early. This
-     * is needed in case the original sync is relying on the callback to continue processing.
-     *
-     * @param otherSyncGroup The other SyncGroup to merge into this one.
-     */
-    public void merge(SurfaceSyncGroup otherSyncGroup) {
-        synchronized (mLock) {
-            mMergedSyncGroups.add(otherSyncGroup);
-        }
-        otherSyncGroup.updateCallback(transaction -> {
-            synchronized (mLock) {
-                mMergedSyncGroups.remove(otherSyncGroup);
-                if (transaction != null) {
-                    mTransaction.merge(transaction);
+                finished = true;
+            } else {
+                // If this SurfaceSyncGroup was already added to a different SurfaceSyncGroup, we
+                // need to combine everything. We can add the old SurfaceSyncGroup parent to the new
+                // parent so the new parent doesn't complete until the old parent does.
+                // Additionally, the old parent will not get the final transaction object and
+                // instead will send it to the new parent, ensuring that any other SurfaceSyncGroups
+                // from the original parent are also combined with the new parent SurfaceSyncGroup.
+                if (mParentSyncGroup != null) {
+                    Log.d(TAG, "Already part of sync group " + mParentSyncGroup + " " + this);
+                    parentSyncGroup.addToSync(mParentSyncGroup, true /* parentSyncGroupMerge */);
                 }
-                checkIfSyncIsComplete();
+                mParentSyncGroup = parentSyncGroup;
+                final TransactionReadyCallback lastCallback = mTransactionReadyCallback;
+                mTransactionReadyCallback = t -> {
+                    lastCallback.onTransactionReady(null);
+                    transactionReadyCallback.onTransactionReady(t);
+                };
             }
-        });
-    }
-
-    /**
-     * Wrapper class to help synchronize SurfaceViews
-     */
-    private static class SurfaceViewSyncTarget implements SyncTarget {
-        private final SurfaceView mSurfaceView;
-        private final Consumer<SurfaceViewFrameCallback> mFrameCallbackConsumer;
-
-        SurfaceViewSyncTarget(SurfaceView surfaceView,
-                Consumer<SurfaceViewFrameCallback> frameCallbackConsumer) {
-            mSurfaceView = surfaceView;
-            mFrameCallbackConsumer = frameCallbackConsumer;
         }
 
-        @Override
-        public void onAddedToSyncGroup(SurfaceSyncGroup parentSyncGroup,
-                TransactionReadyCallback transactionReadyCallback) {
-            mFrameCallbackConsumer.accept(
-                    () -> mSurfaceView.syncNextFrame(transactionReadyCallback::onTransactionReady));
+        // Invoke the callback outside of the lock when the SurfaceSyncGroup being added was already
+        // complete.
+        if (finished) {
+            transactionReadyCallback.onTransactionReady(null);
         }
     }
-
-    /**
-     * A SyncTarget that can be added to a sync set.
-     */
-    public interface SyncTarget {
-        /**
-         * Called when the SyncTarget has been added to a SyncGroup as is ready to begin handing a
-         * sync request. When invoked, the implementor is required to call
-         * {@link TransactionReadyCallback#onTransactionReady(Transaction)} in order for this
-         * SurfaceSyncGroup to fully complete.
-         *
-         * Always invoked on the thread that initiated the call to {@link #addToSync(SyncTarget)}
-         *
-         * @param parentSyncGroup The sync group this target has been added to.
-         * @param transactionReadyCallback A TransactionReadyCallback that the caller must invoke
-         *                                 onTransactionReady
-         */
-        void onAddedToSyncGroup(SurfaceSyncGroup parentSyncGroup,
-                TransactionReadyCallback transactionReadyCallback);
-    }
-
     /**
      * Interface so the SurfaceSyncer can know when it's safe to start and when everything has been
      * completed. The caller should invoke the calls when the rendering has started and finished a
      * frame.
      */
-    public interface TransactionReadyCallback {
+    private interface TransactionReadyCallback {
         /**
          * Invoked when the transaction is ready to sync.
          *
diff --git a/core/java/android/window/TaskConstants.java b/core/java/android/window/TaskConstants.java
new file mode 100644
index 0000000..c403840
--- /dev/null
+++ b/core/java/android/window/TaskConstants.java
@@ -0,0 +1,106 @@
+/*
+ * 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 android.window;
+
+import android.annotation.IntDef;
+
+/**
+ * Holds constants related to task managements but not suitable in {@code TaskOrganizer}.
+ * @hide
+ */
+public class TaskConstants {
+
+    /**
+     * Sizes of a z-order region assigned to child layers of task layers. Components are allowed to
+     * use all values in [assigned value, assigned value + region size).
+     * @hide
+     */
+    public static final int TASK_CHILD_LAYER_REGION_SIZE = 10000;
+
+    /**
+     * Indicates system responding to task drag resizing while app content isn't updated.
+     * @hide
+     */
+    public static final int TASK_CHILD_LAYER_TASK_BACKGROUND = -3 * TASK_CHILD_LAYER_REGION_SIZE;
+
+    /**
+     * Provides solid color letterbox background or blur effect and dimming for the wallpaper
+     * letterbox background. It also listens to touches for double tap gesture for repositioning
+     * letterbox.
+     * @hide
+     */
+    public static final int TASK_CHILD_LAYER_LETTERBOX_BACKGROUND =
+            -2 * TASK_CHILD_LAYER_REGION_SIZE;
+
+    /**
+     * When a unresizable app is moved in the different configuration, a restart button appears
+     * allowing to adapt (~resize) app to the new configuration mocks.
+     * @hide
+     */
+    public static final int TASK_CHILD_LAYER_SIZE_COMPAT_RESTART_BUTTON =
+            TASK_CHILD_LAYER_REGION_SIZE;
+
+    /**
+     * Shown the first time an app is opened in size compat mode in landscape.
+     * @hide
+     */
+    public static final int TASK_CHILD_LAYER_LETTERBOX_EDUCATION = 2 * TASK_CHILD_LAYER_REGION_SIZE;
+
+    /**
+     * Captions, window frames and resize handlers around task windows.
+     * @hide
+     */
+    public static final int TASK_CHILD_LAYER_WINDOW_DECORATIONS = 3 * TASK_CHILD_LAYER_REGION_SIZE;
+
+    /**
+     * Overlays the task when going into PIP w/ gesture navigation.
+     * @hide
+     */
+    public static final int TASK_CHILD_LAYER_RECENTS_ANIMATION_PIP_OVERLAY =
+            4 * TASK_CHILD_LAYER_REGION_SIZE;
+
+    /**
+     * Allows other apps to add overlays on the task (i.e. game dashboard)
+     * @hide
+     */
+    public static final int TASK_CHILD_LAYER_TASK_OVERLAY = 5 * TASK_CHILD_LAYER_REGION_SIZE;
+
+    /**
+     * Legacy machanism to force an activity to the top of the task (i.e. for work profile
+     * comfirmation).
+     * @hide
+     */
+    public static final int TASK_CHILD_LAYER_TASK_OVERLAY_ACTIVITIES =
+            6 * TASK_CHILD_LAYER_REGION_SIZE;
+
+    /**
+     * Z-orders of task child layers other than activities, task fragments and layers interleaved
+     * with them, e.g. IME windows. [-10000, 10000) is reserved for these layers.
+     * @hide
+     */
+    @IntDef({
+            TASK_CHILD_LAYER_TASK_BACKGROUND,
+            TASK_CHILD_LAYER_LETTERBOX_BACKGROUND,
+            TASK_CHILD_LAYER_SIZE_COMPAT_RESTART_BUTTON,
+            TASK_CHILD_LAYER_LETTERBOX_EDUCATION,
+            TASK_CHILD_LAYER_WINDOW_DECORATIONS,
+            TASK_CHILD_LAYER_RECENTS_ANIMATION_PIP_OVERLAY,
+            TASK_CHILD_LAYER_TASK_OVERLAY,
+            TASK_CHILD_LAYER_TASK_OVERLAY_ACTIVITIES
+    })
+    public @interface TaskChildLayer {}
+}
diff --git a/core/java/android/window/TaskFragmentCreationParams.java b/core/java/android/window/TaskFragmentCreationParams.java
index 81ab783..c9ddf92 100644
--- a/core/java/android/window/TaskFragmentCreationParams.java
+++ b/core/java/android/window/TaskFragmentCreationParams.java
@@ -20,6 +20,7 @@
 import static android.app.WindowConfiguration.WindowingMode;
 
 import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.annotation.TestApi;
 import android.graphics.Rect;
 import android.os.IBinder;
@@ -57,14 +58,33 @@
 
     /** The initial windowing mode of the TaskFragment. Inherits from parent if not set. */
     @WindowingMode
-    private int mWindowingMode = WINDOWING_MODE_UNDEFINED;
+    private final int mWindowingMode;
+
+    /**
+     * The fragment token of the paired primary TaskFragment.
+     * When it is set, the new TaskFragment will be positioned right above the paired TaskFragment.
+     * Otherwise, the new TaskFragment will be positioned on the top of the Task by default.
+     *
+     * This is different from {@link WindowContainerTransaction#setAdjacentTaskFragments} as we may
+     * set this when the pair of TaskFragments are stacked, while adjacent is only set on the pair
+     * of TaskFragments that are in split.
+     *
+     * This is needed in case we need to launch a placeholder Activity to split below a transparent
+     * always-expand Activity.
+     */
+    @Nullable
+    private final IBinder mPairedPrimaryFragmentToken;
 
     private TaskFragmentCreationParams(
-            @NonNull TaskFragmentOrganizerToken organizer,
-            @NonNull IBinder fragmentToken, @NonNull IBinder ownerToken) {
+            @NonNull TaskFragmentOrganizerToken organizer, @NonNull IBinder fragmentToken,
+            @NonNull IBinder ownerToken, @NonNull Rect initialBounds,
+            @WindowingMode int windowingMode, @Nullable IBinder pairedPrimaryFragmentToken) {
         mOrganizer = organizer;
         mFragmentToken = fragmentToken;
         mOwnerToken = ownerToken;
+        mInitialBounds.set(initialBounds);
+        mWindowingMode = windowingMode;
+        mPairedPrimaryFragmentToken = pairedPrimaryFragmentToken;
     }
 
     @NonNull
@@ -92,12 +112,22 @@
         return mWindowingMode;
     }
 
+    /**
+     * TODO(b/232476698): remove the hide with adding CTS for this in next release.
+     * @hide
+     */
+    @Nullable
+    public IBinder getPairedPrimaryFragmentToken() {
+        return mPairedPrimaryFragmentToken;
+    }
+
     private TaskFragmentCreationParams(Parcel in) {
         mOrganizer = TaskFragmentOrganizerToken.CREATOR.createFromParcel(in);
         mFragmentToken = in.readStrongBinder();
         mOwnerToken = in.readStrongBinder();
         mInitialBounds.readFromParcel(in);
         mWindowingMode = in.readInt();
+        mPairedPrimaryFragmentToken = in.readStrongBinder();
     }
 
     /** @hide */
@@ -108,6 +138,7 @@
         dest.writeStrongBinder(mOwnerToken);
         mInitialBounds.writeToParcel(dest, flags);
         dest.writeInt(mWindowingMode);
+        dest.writeStrongBinder(mPairedPrimaryFragmentToken);
     }
 
     @NonNull
@@ -132,6 +163,7 @@
                 + " ownerToken=" + mOwnerToken
                 + " initialBounds=" + mInitialBounds
                 + " windowingMode=" + mWindowingMode
+                + " pairedFragmentToken=" + mPairedPrimaryFragmentToken
                 + "}";
     }
 
@@ -159,6 +191,9 @@
         @WindowingMode
         private int mWindowingMode = WINDOWING_MODE_UNDEFINED;
 
+        @Nullable
+        private IBinder mPairedPrimaryFragmentToken;
+
         public Builder(@NonNull TaskFragmentOrganizerToken organizer,
                 @NonNull IBinder fragmentToken, @NonNull IBinder ownerToken) {
             mOrganizer = organizer;
@@ -180,14 +215,29 @@
             return this;
         }
 
+        /**
+         * Sets the fragment token of the paired primary TaskFragment.
+         * When it is set, the new TaskFragment will be positioned right above the paired
+         * TaskFragment. Otherwise, the new TaskFragment will be positioned on the top of the Task
+         * by default.
+         *
+         * This is needed in case we need to launch a placeholder Activity to split below a
+         * transparent always-expand Activity.
+         *
+         * TODO(b/232476698): remove the hide with adding CTS for this in next release.
+         * @hide
+         */
+        @NonNull
+        public Builder setPairedPrimaryFragmentToken(@Nullable IBinder fragmentToken) {
+            mPairedPrimaryFragmentToken = fragmentToken;
+            return this;
+        }
+
         /** Constructs the options to create TaskFragment with. */
         @NonNull
         public TaskFragmentCreationParams build() {
-            final TaskFragmentCreationParams result = new TaskFragmentCreationParams(
-                    mOrganizer, mFragmentToken, mOwnerToken);
-            result.mInitialBounds.set(mInitialBounds);
-            result.mWindowingMode = mWindowingMode;
-            return result;
+            return new TaskFragmentCreationParams(mOrganizer, mFragmentToken, mOwnerToken,
+                    mInitialBounds, mWindowingMode, mPairedPrimaryFragmentToken);
         }
     }
 }
diff --git a/core/java/android/window/TaskFragmentOrganizer.java b/core/java/android/window/TaskFragmentOrganizer.java
index ef19c55..283df76 100644
--- a/core/java/android/window/TaskFragmentOrganizer.java
+++ b/core/java/android/window/TaskFragmentOrganizer.java
@@ -20,22 +20,20 @@
 import static android.view.WindowManager.TRANSIT_CLOSE;
 import static android.view.WindowManager.TRANSIT_NONE;
 import static android.view.WindowManager.TRANSIT_OPEN;
-import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_CREATE_TASK_FRAGMENT;
-import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_DELETE_TASK_FRAGMENT;
-import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_REPARENT_ACTIVITY_TO_TASK_FRAGMENT;
 
 import android.annotation.CallSuper;
+import android.annotation.IntDef;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.annotation.TestApi;
-import android.app.WindowConfiguration;
 import android.os.Bundle;
 import android.os.IBinder;
 import android.os.RemoteException;
 import android.view.RemoteAnimationDefinition;
 import android.view.WindowManager;
 
-import java.util.List;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
 import java.util.concurrent.Executor;
 
 /**
@@ -63,6 +61,52 @@
     public static final String KEY_ERROR_CALLBACK_OP_TYPE = "operation_type";
 
     /**
+     * No change set.
+     */
+    @WindowManager.TransitionType
+    @TaskFragmentTransitionType
+    public static final int TASK_FRAGMENT_TRANSIT_NONE = TRANSIT_NONE;
+
+    /**
+     * A window that didn't exist before has been created and made visible.
+     */
+    @WindowManager.TransitionType
+    @TaskFragmentTransitionType
+    public static final int TASK_FRAGMENT_TRANSIT_OPEN = TRANSIT_OPEN;
+
+    /**
+     * A window that was visible no-longer exists (was finished or destroyed).
+     */
+    @WindowManager.TransitionType
+    @TaskFragmentTransitionType
+    public static final int TASK_FRAGMENT_TRANSIT_CLOSE = TRANSIT_CLOSE;
+
+    /**
+     * A window is visible before and after but changes in some way (eg. it resizes or changes
+     * windowing-mode).
+     */
+    @WindowManager.TransitionType
+    @TaskFragmentTransitionType
+    public static final int TASK_FRAGMENT_TRANSIT_CHANGE = TRANSIT_CHANGE;
+
+    /**
+     * Introduced a sub set of {@link WindowManager.TransitionType} for the types that are used for
+     * TaskFragment transition.
+     *
+     * Doing this instead of exposing {@link WindowManager.TransitionType} because we want to keep
+     * the Shell transition API hidden until it comes fully stable.
+     * @hide
+     */
+    @IntDef(prefix = { "TASK_FRAGMENT_TRANSIT_" }, value = {
+            TASK_FRAGMENT_TRANSIT_NONE,
+            TASK_FRAGMENT_TRANSIT_OPEN,
+            TASK_FRAGMENT_TRANSIT_CLOSE,
+            TASK_FRAGMENT_TRANSIT_CHANGE,
+    })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface TaskFragmentTransitionType {}
+
+    /**
      * Creates a {@link Bundle} with an exception, operation type and TaskFragmentInfo (if any)
      * that can be passed to {@link ITaskFragmentOrganizer#onTaskFragmentError}.
      * @hide
@@ -155,7 +199,7 @@
      *                          {@link #onTransactionReady(TaskFragmentTransaction)}
      * @param wct               {@link WindowContainerTransaction} that the server should apply for
      *                          update of the transaction.
-     * @param transitionType    {@link WindowManager.TransitionType} if it needs to start a
+     * @param transitionType    {@link TaskFragmentTransitionType} if it needs to start a
      *                          transition.
      * @param shouldApplyIndependently  If {@code true}, the {@code wct} will request a new
      *                                  transition, which will be queued until the sync engine is
@@ -163,11 +207,10 @@
      *                                  the {@code wct} will be directly applied to the active sync.
      * @see com.android.server.wm.WindowOrganizerController#enforceTaskFragmentOrganizerPermission
      * for permission enforcement.
-     * @hide
      */
     public void onTransactionHandled(@NonNull IBinder transactionToken,
             @NonNull WindowContainerTransaction wct,
-            @WindowManager.TransitionType int transitionType, boolean shouldApplyIndependently) {
+            @TaskFragmentTransitionType int transitionType, boolean shouldApplyIndependently) {
         wct.setTaskFragmentOrganizer(mInterface);
         try {
             getController().onTransactionHandled(transactionToken, wct, transitionType,
@@ -178,22 +221,19 @@
     }
 
     /**
-     * Routes to {@link ITaskFragmentOrganizerController#applyTransaction} instead of
-     * {@link IWindowOrganizerController#applyTransaction} for the different transition options.
-     *
+     * Must use {@link #applyTransaction(WindowContainerTransaction, int, boolean)} instead.
      * @see #applyTransaction(WindowContainerTransaction, int, boolean)
      */
     @Override
     public void applyTransaction(@NonNull WindowContainerTransaction wct) {
-        // TODO(b/207070762) doing so to keep CTS compatibility. Remove in the next release.
-        applyTransaction(wct, getTransitionType(wct), false /* shouldApplyIndependently */);
+        throw new RuntimeException("Not allowed!");
     }
 
     /**
      * Requests the server to apply the given {@link WindowContainerTransaction}.
      *
      * @param wct   {@link WindowContainerTransaction} to apply.
-     * @param transitionType    {@link WindowManager.TransitionType} if it needs to start a
+     * @param transitionType    {@link TaskFragmentTransitionType} if it needs to start a
      *                          transition.
      * @param shouldApplyIndependently  If {@code true}, the {@code wct} will request a new
      *                                  transition, which will be queued until the sync engine is
@@ -201,10 +241,9 @@
      *                                  the {@code wct} will be directly applied to the active sync.
      * @see com.android.server.wm.WindowOrganizerController#enforceTaskFragmentOrganizerPermission
      * for permission enforcement.
-     * @hide
      */
     public void applyTransaction(@NonNull WindowContainerTransaction wct,
-            @WindowManager.TransitionType int transitionType, boolean shouldApplyIndependently) {
+            @TaskFragmentTransitionType int transitionType, boolean shouldApplyIndependently) {
         if (wct.isEmpty()) {
             return;
         }
@@ -217,56 +256,13 @@
     }
 
     /**
-     * Gets the default {@link WindowManager.TransitionType} based on the requested
-     * {@link WindowContainerTransaction}.
-     * @hide
-     */
-    // TODO(b/207070762): let Extensions to set the transition type instead.
-    @WindowManager.TransitionType
-    public static int getTransitionType(@NonNull WindowContainerTransaction wct) {
-        if (wct.isEmpty()) {
-            return TRANSIT_NONE;
-        }
-        for (WindowContainerTransaction.Change change : wct.getChanges().values()) {
-            if ((change.getWindowSetMask() & WindowConfiguration.WINDOW_CONFIG_BOUNDS) != 0) {
-                // Treat as TRANSIT_CHANGE when there is TaskFragment resizing.
-                return TRANSIT_CHANGE;
-            }
-        }
-        boolean containsCreatingTaskFragment = false;
-        boolean containsDeleteTaskFragment = false;
-        final List<WindowContainerTransaction.HierarchyOp> ops = wct.getHierarchyOps();
-        for (int i = ops.size() - 1; i >= 0; i--) {
-            final int type = ops.get(i).getType();
-            if (type == HIERARCHY_OP_TYPE_REPARENT_ACTIVITY_TO_TASK_FRAGMENT) {
-                // Treat as TRANSIT_CHANGE when there is activity reparent.
-                return TRANSIT_CHANGE;
-            }
-            if (type == HIERARCHY_OP_TYPE_CREATE_TASK_FRAGMENT) {
-                containsCreatingTaskFragment = true;
-            } else if (type == HIERARCHY_OP_TYPE_DELETE_TASK_FRAGMENT) {
-                containsDeleteTaskFragment = true;
-            }
-        }
-        if (containsCreatingTaskFragment) {
-            return TRANSIT_OPEN;
-        }
-        if (containsDeleteTaskFragment) {
-            return TRANSIT_CLOSE;
-        }
-
-        // Use TRANSIT_CHANGE as default.
-        return TRANSIT_CHANGE;
-    }
-
-    /**
      * Called when the transaction is ready so that the organizer can update the TaskFragments based
      * on the changes in transaction.
      */
     public void onTransactionReady(@NonNull TaskFragmentTransaction transaction) {
         // Notify the server to finish the transaction.
         onTransactionHandled(transaction.getTransactionToken(), new WindowContainerTransaction(),
-                TRANSIT_NONE, false /* shouldApplyIndependently */);
+                TASK_FRAGMENT_TRANSIT_NONE, false /* shouldApplyIndependently */);
     }
 
     private final ITaskFragmentOrganizer mInterface = new ITaskFragmentOrganizer.Stub() {
diff --git a/core/java/android/window/WindowOrganizer.java b/core/java/android/window/WindowOrganizer.java
index 930aaa2..695d01e 100644
--- a/core/java/android/window/WindowOrganizer.java
+++ b/core/java/android/window/WindowOrganizer.java
@@ -40,14 +40,11 @@
      * Apply multiple WindowContainer operations at once.
      *
      * Note that using this API requires the caller to hold
-     * {@link android.Manifest.permission#MANAGE_ACTIVITY_TASKS}, unless the caller is using
-     * {@link TaskFragmentOrganizer}, in which case it is allowed to change TaskFragment that is
-     * created by itself.
+     * {@link android.Manifest.permission#MANAGE_ACTIVITY_TASKS}.
      *
      * @param t The transaction to apply.
      */
-    @RequiresPermission(value = android.Manifest.permission.MANAGE_ACTIVITY_TASKS,
-            conditional = true)
+    @RequiresPermission(value = android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
     public void applyTransaction(@NonNull WindowContainerTransaction t) {
         try {
             if (!t.isEmpty()) {
@@ -62,9 +59,7 @@
      * Apply multiple WindowContainer operations at once.
      *
      * Note that using this API requires the caller to hold
-     * {@link android.Manifest.permission#MANAGE_ACTIVITY_TASKS}, unless the caller is using
-     * {@link TaskFragmentOrganizer}, in which case it is allowed to change TaskFragment that is
-     * created by itself.
+     * {@link android.Manifest.permission#MANAGE_ACTIVITY_TASKS}.
      *
      * @param t The transaction to apply.
      * @param callback This transaction will use the synchronization scheme described in
@@ -73,8 +68,7 @@
      * @return An ID for the sync operation which will later be passed to transactionReady callback.
      *         This lets the caller differentiate overlapping sync operations.
      */
-    @RequiresPermission(value = android.Manifest.permission.MANAGE_ACTIVITY_TASKS,
-            conditional = true)
+    @RequiresPermission(value = android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
     public int applySyncTransaction(@NonNull WindowContainerTransaction t,
             @NonNull WindowContainerTransactionCallback callback) {
         try {
diff --git a/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java b/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java
index 43be031..e0b0110 100644
--- a/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java
+++ b/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java
@@ -226,9 +226,7 @@
         Slog.d(TAG, "Accessibility shortcut activated");
         final ContentResolver cr = mContext.getContentResolver();
         final int userId = ActivityManager.getCurrentUser();
-        final int dialogAlreadyShown = Settings.Secure.getIntForUser(
-                cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, DialogStatus.NOT_SHOWN,
-                userId);
+
         // Play a notification vibration
         Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
         if ((vibrator != null) && vibrator.hasVibrator()) {
@@ -239,7 +237,7 @@
             vibrator.vibrate(vibePattern, -1, VIBRATION_ATTRIBUTES);
         }
 
-        if (dialogAlreadyShown == DialogStatus.NOT_SHOWN) {
+        if (shouldShowDialog()) {
             // The first time, we show a warning rather than toggle the service to give the user a
             // chance to turn off this feature before stuff gets enabled.
             mAlertDialog = createShortcutWarningDialog(userId);
@@ -269,6 +267,20 @@
         }
     }
 
+    /** Whether the warning dialog should be shown instead of performing the shortcut. */
+    private boolean shouldShowDialog() {
+        if (hasFeatureLeanback()) {
+            // Never show the dialog on TV, instead always perform the shortcut directly.
+            return false;
+        }
+        final ContentResolver cr = mContext.getContentResolver();
+        final int userId = ActivityManager.getCurrentUser();
+        final int dialogAlreadyShown = Settings.Secure.getIntForUser(cr,
+                Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, DialogStatus.NOT_SHOWN,
+                userId);
+        return dialogAlreadyShown == DialogStatus.NOT_SHOWN;
+    }
+
     /**
      * Show toast to alert the user that the accessibility shortcut turned on or off an
      * accessibility service.
diff --git a/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl b/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl
index 9f23f24..b9ca557 100644
--- a/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl
+++ b/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl
@@ -252,11 +252,13 @@
      * @param sharedMemory The unrestricted data blob to provide to the
      * {@link HotwordDetectionService}. Use this to provide the hotword models data or other
      * such data to the trusted process.
+     * @param token Use this to identify which detector calls this method.
      */
     @EnforcePermission("MANAGE_HOTWORD_DETECTION")
     void updateState(
             in PersistableBundle options,
-            in SharedMemory sharedMemory);
+            in SharedMemory sharedMemory,
+            in IBinder token);
 
     /**
      * Set configuration and pass read-only data to hotword detection service when creating
@@ -272,6 +274,7 @@
      * @param sharedMemory The unrestricted data blob to provide to the
      * {@link HotwordDetectionService}. Use this to provide the hotword models data or other
      * such data to the trusted process.
+     * @param token Use this to identify which detector calls this method.
      * @param callback Use this to report {@link HotwordDetectionService} status.
      * @param detectorType Indicate which detector is used.
      */
@@ -280,10 +283,18 @@
             in Identity originatorIdentity,
             in PersistableBundle options,
             in SharedMemory sharedMemory,
+            in IBinder token,
             in IHotwordRecognitionStatusCallback callback,
             int detectorType);
 
     /**
+     * Destroy the detector callback.
+     *
+     * @param token Indicate which callback will be destroyed.
+     */
+    void destroyDetector(in IBinder token);
+
+    /**
      * Requests to shutdown hotword detection service.
      */
     void shutdownHotwordDetectionService();
@@ -298,6 +309,7 @@
         in ParcelFileDescriptor audioStream,
         in AudioFormat audioFormat,
         in PersistableBundle options,
+        in IBinder token,
         in IMicrophoneHotwordDetectionVoiceInteractionCallback callback);
 
     /**
diff --git a/core/java/com/android/internal/content/om/TEST_MAPPING b/core/java/com/android/internal/content/om/TEST_MAPPING
index 4cb595b..98dadce7 100644
--- a/core/java/com/android/internal/content/om/TEST_MAPPING
+++ b/core/java/com/android/internal/content/om/TEST_MAPPING
@@ -7,6 +7,28 @@
           "include-filter": "com.android.internal.content."
         }
       ]
+    },
+    {
+      "name": "SelfTargetingOverlayDeviceTests"
+    }
+  ],
+  "presubmit-large": [
+    {
+      "name": "CtsContentTestCases",
+      "options": [
+        {
+          "exclude-annotation": "androidx.test.filters.FlakyTest"
+        },
+        {
+          "exclude-annotation": "org.junit.Ignore"
+        },
+        {
+          "include-filter": "android.content.om.cts"
+        },
+        {
+          "include-filter": "android.content.res.loader.cts"
+        }
+      ]
     }
   ]
-}
\ No newline at end of file
+}
diff --git a/core/java/com/android/internal/inputmethod/InputBindResult.java b/core/java/com/android/internal/inputmethod/InputBindResult.java
index f1014971..7dbbffd 100644
--- a/core/java/com/android/internal/inputmethod/InputBindResult.java
+++ b/core/java/com/android/internal/inputmethod/InputBindResult.java
@@ -170,6 +170,9 @@
          * display.
          */
         int ERROR_INVALID_DISPLAY_ID = 15;
+        /**
+         * Indicates that a valid session is created and result is ready for accessibility.
+         */
         int SUCCESS_WITH_ACCESSIBILITY_SESSION = 16;
     }
 
@@ -389,6 +392,8 @@
                 return "ERROR_DISPLAY_ID_MISMATCH";
             case ResultCode.ERROR_INVALID_DISPLAY_ID:
                 return "ERROR_INVALID_DISPLAY_ID";
+            case ResultCode.SUCCESS_WITH_ACCESSIBILITY_SESSION:
+                return "SUCCESS_WITH_ACCESSIBILITY_SESSION";
             default:
                 return "Unknown(" + result + ")";
         }
diff --git a/core/java/com/android/internal/jank/InteractionJankMonitor.java b/core/java/com/android/internal/jank/InteractionJankMonitor.java
index 75f0bf5..7bd6ec8 100644
--- a/core/java/com/android/internal/jank/InteractionJankMonitor.java
+++ b/core/java/com/android/internal/jank/InteractionJankMonitor.java
@@ -780,17 +780,17 @@
         // 2. The returned string should be the same with the name defined in atoms.proto.
         switch (cujType) {
             case CUJ_NOTIFICATION_SHADE_EXPAND_COLLAPSE:
-                return "SHADE_EXPAND_COLLAPSE";
+                return "NOTIFICATION_SHADE_EXPAND_COLLAPSE";
             case CUJ_NOTIFICATION_SHADE_SCROLL_FLING:
-                return "SHADE_SCROLL_FLING";
+                return "NOTIFICATION_SHADE_SCROLL_FLING";
             case CUJ_NOTIFICATION_SHADE_ROW_EXPAND:
-                return "SHADE_ROW_EXPAND";
+                return "NOTIFICATION_SHADE_ROW_EXPAND";
             case CUJ_NOTIFICATION_SHADE_ROW_SWIPE:
-                return "SHADE_ROW_SWIPE";
+                return "NOTIFICATION_SHADE_ROW_SWIPE";
             case CUJ_NOTIFICATION_SHADE_QS_EXPAND_COLLAPSE:
-                return "SHADE_QS_EXPAND_COLLAPSE";
+                return "NOTIFICATION_SHADE_QS_EXPAND_COLLAPSE";
             case CUJ_NOTIFICATION_SHADE_QS_SCROLL_SWIPE:
-                return "SHADE_QS_SCROLL_SWIPE";
+                return "NOTIFICATION_SHADE_QS_SCROLL_SWIPE";
             case CUJ_LAUNCHER_APP_LAUNCH_FROM_RECENTS:
                 return "LAUNCHER_APP_LAUNCH_FROM_RECENTS";
             case CUJ_LAUNCHER_APP_LAUNCH_FROM_ICON:
@@ -880,9 +880,9 @@
             case CUJ_SPLIT_SCREEN_EXIT:
                 return "SPLIT_SCREEN_EXIT";
             case CUJ_LOCKSCREEN_LAUNCH_CAMERA:
-                return "CUJ_LOCKSCREEN_LAUNCH_CAMERA";
+                return "LOCKSCREEN_LAUNCH_CAMERA";
             case CUJ_SPLIT_SCREEN_RESIZE:
-                return "CUJ_SPLIT_SCREEN_RESIZE";
+                return "SPLIT_SCREEN_RESIZE";
             case CUJ_SETTINGS_SLIDER:
                 return "SETTINGS_SLIDER";
             case CUJ_TAKE_SCREENSHOT:
diff --git a/core/java/com/android/internal/os/BatteryStatsHistory.java b/core/java/com/android/internal/os/BatteryStatsHistory.java
index 556e146..66d64c4 100644
--- a/core/java/com/android/internal/os/BatteryStatsHistory.java
+++ b/core/java/com/android/internal/os/BatteryStatsHistory.java
@@ -49,6 +49,7 @@
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.ConcurrentModificationException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -163,10 +164,6 @@
      */
     private int mCurrentParcelEnd;
     /**
-     * When iterating history files, the current record count.
-     */
-    private int mRecordCount = 0;
-    /**
      * Used when BatteryStatsImpl object is created from deserialization of a parcel,
      * such as Settings app or checkin file, to iterate over history parcels.
      */
@@ -199,10 +196,8 @@
     private boolean mMeasuredEnergyHeaderWritten = false;
     private boolean mCpuUsageHeaderWritten = false;
     private final VarintParceler mVarintParceler = new VarintParceler();
-
     private byte mLastHistoryStepLevel = 0;
-
-    private BatteryStatsHistoryIterator mBatteryStatsHistoryIterator;
+    private boolean mMutable = true;
 
     /**
      * A delegate responsible for computing additional details for a step in battery history.
@@ -493,25 +488,21 @@
      * @return always return true.
      */
     public BatteryStatsHistoryIterator iterate() {
-        mRecordCount = 0;
         mCurrentFileIndex = 0;
         mCurrentParcel = null;
         mCurrentParcelEnd = 0;
         mParcelIndex = 0;
-        mBatteryStatsHistoryIterator = new BatteryStatsHistoryIterator(this);
-        return mBatteryStatsHistoryIterator;
+        mMutable = false;
+        return new BatteryStatsHistoryIterator(this);
     }
 
     /**
      * Finish iterating history files and history buffer.
      */
-    void finishIteratingHistory() {
+    void iteratorFinished() {
         // setDataPosition so mHistoryBuffer Parcel can be written.
         mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize());
-        mBatteryStatsHistoryIterator = null;
-        if (DEBUG) {
-            Slog.d(TAG, "Battery history records iterated: " + mRecordCount);
-        }
+        mMutable = true;
     }
 
     /**
@@ -519,17 +510,11 @@
      * history file, when reached the mActiveFile (highest numbered history file), do not read from
      * mActiveFile, read from history buffer instead because the buffer has more updated data.
      *
-     * @param out a history item.
      * @return The parcel that has next record. null if finished all history files and history
      * buffer
      */
-    public Parcel getNextParcel(HistoryItem out) {
-        if (mRecordCount == 0) {
-            // reset out if it is the first record.
-            out.clear();
-        }
-        ++mRecordCount;
-
+    @Nullable
+    public Parcel getNextParcel() {
         // First iterate through all records in current parcel.
         if (mCurrentParcel != null) {
             if (mCurrentParcel.dataPosition() < mCurrentParcelEnd) {
@@ -1047,6 +1032,17 @@
     }
 
     /**
+     * Records a wakelock release event.
+     */
+    public void recordWakelockStopEvent(long elapsedRealtimeMs, long uptimeMs, String historyName,
+            int uid) {
+        mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag;
+        mHistoryCur.wakelockTag.string = historyName != null ? historyName : "";
+        mHistoryCur.wakelockTag.uid = uid;
+        recordStateStopEvent(elapsedRealtimeMs, uptimeMs, HistoryItem.STATE_WAKE_LOCK_FLAG);
+    }
+
+    /**
      * Records an event when some state flag changes to true.
      */
     public void recordStateStartEvent(long elapsedRealtimeMs, long uptimeMs, int stateFlags) {
@@ -1259,6 +1255,10 @@
             return;
         }
 
+        if (!mMutable) {
+            throw new ConcurrentModificationException("Battery history is not writable");
+        }
+
         final long timeDiffMs = (mHistoryBaseTimeMs + elapsedRealtimeMs) - mHistoryLastWritten.time;
         final int diffStates = mHistoryLastWritten.states ^ (cur.states & mActiveHistoryStates);
         final int diffStates2 = mHistoryLastWritten.states2 ^ (cur.states2 & mActiveHistoryStates2);
@@ -1379,8 +1379,8 @@
 
     private void writeHistoryItem(long elapsedRealtimeMs,
             @SuppressWarnings("UnusedVariable") long uptimeMs, HistoryItem cur, byte cmd) {
-        if (mBatteryStatsHistoryIterator != null) {
-            throw new IllegalStateException("Can't do this while iterating history!");
+        if (!mMutable) {
+            throw new ConcurrentModificationException("Battery history is not writable");
         }
         mHistoryBufferLastPos = mHistoryBuffer.dataPosition();
         mHistoryLastLastWritten.setTo(mHistoryLastWritten);
@@ -1676,7 +1676,10 @@
                     Slog.i(TAG, "WRITE DELTA: cpuUsageDetails=" + cur.cpuUsageDetails);
                 }
                 if (!mCpuUsageHeaderWritten) {
-                    dest.writeStringArray(cur.cpuUsageDetails.cpuBracketDescriptions);
+                    dest.writeInt(cur.cpuUsageDetails.cpuBracketDescriptions.length);
+                    for (String desc: cur.cpuUsageDetails.cpuBracketDescriptions) {
+                        dest.writeString(desc);
+                    }
                     mCpuUsageHeaderWritten = true;
                 }
                 dest.writeInt(cur.cpuUsageDetails.uid);
diff --git a/core/java/com/android/internal/os/BatteryStatsHistoryIterator.java b/core/java/com/android/internal/os/BatteryStatsHistoryIterator.java
index 09fe100..b88116d 100644
--- a/core/java/com/android/internal/os/BatteryStatsHistoryIterator.java
+++ b/core/java/com/android/internal/os/BatteryStatsHistoryIterator.java
@@ -23,10 +23,13 @@
 import android.util.Slog;
 import android.util.SparseArray;
 
+import java.util.Iterator;
+
 /**
  * An iterator for {@link BatteryStats.HistoryItem}'s.
  */
-public class BatteryStatsHistoryIterator {
+public class BatteryStatsHistoryIterator implements Iterator<BatteryStats.HistoryItem>,
+        AutoCloseable {
     private static final boolean DEBUG = false;
     private static final String TAG = "BatteryStatsHistoryItr";
     private final BatteryStatsHistory mBatteryStatsHistory;
@@ -38,29 +41,51 @@
     private final BatteryStatsHistory.VarintParceler mVarintParceler =
             new BatteryStatsHistory.VarintParceler();
 
+    private final BatteryStats.HistoryItem mHistoryItem = new BatteryStats.HistoryItem();
+
+    private static final int MAX_ENERGY_CONSUMER_COUNT = 100;
+    private static final int MAX_CPU_BRACKET_COUNT = 100;
+
     public BatteryStatsHistoryIterator(@NonNull BatteryStatsHistory history) {
         mBatteryStatsHistory = history;
+        mHistoryItem.clear();
+    }
+
+    @Override
+    public boolean hasNext() {
+        Parcel p = mBatteryStatsHistory.getNextParcel();
+        if (p == null) {
+            close();
+            return false;
+        }
+        return true;
     }
 
     /**
-     * Retrieves the next HistoryItem from battery history, if available. Returns false if there
+     * Retrieves the next HistoryItem from battery history, if available. Returns null if there
      * are no more items.
      */
-    public boolean next(BatteryStats.HistoryItem out) {
-        Parcel p = mBatteryStatsHistory.getNextParcel(out);
+    @Override
+    public BatteryStats.HistoryItem next() {
+        Parcel p = mBatteryStatsHistory.getNextParcel();
         if (p == null) {
-            mBatteryStatsHistory.finishIteratingHistory();
-            return false;
+            close();
+            return null;
         }
 
-        final long lastRealtimeMs = out.time;
-        final long lastWalltimeMs = out.currentTime;
-        readHistoryDelta(p, out);
-        if (out.cmd != BatteryStats.HistoryItem.CMD_CURRENT_TIME
-                && out.cmd != BatteryStats.HistoryItem.CMD_RESET && lastWalltimeMs != 0) {
-            out.currentTime = lastWalltimeMs + (out.time - lastRealtimeMs);
+        final long lastRealtimeMs = mHistoryItem.time;
+        final long lastWalltimeMs = mHistoryItem.currentTime;
+        try {
+            readHistoryDelta(p, mHistoryItem);
+        } catch (Throwable t) {
+            Slog.wtf(TAG, "Corrupted battery history", t);
+            return null;
         }
-        return true;
+        if (mHistoryItem.cmd != BatteryStats.HistoryItem.CMD_CURRENT_TIME
+                && mHistoryItem.cmd != BatteryStats.HistoryItem.CMD_RESET && lastWalltimeMs != 0) {
+            mHistoryItem.currentTime = lastWalltimeMs + (mHistoryItem.time - lastRealtimeMs);
+        }
+        return mHistoryItem;
     }
 
     private void readHistoryDelta(Parcel src, BatteryStats.HistoryItem cur) {
@@ -210,6 +235,12 @@
                 }
 
                 final int consumerCount = src.readInt();
+                if (consumerCount > MAX_ENERGY_CONSUMER_COUNT) {
+                    // Check to avoid a heap explosion in case the parcel is corrupted
+                    throw new IllegalStateException(
+                            "EnergyConsumer count too high: " + consumerCount
+                                    + ". Max = " + MAX_ENERGY_CONSUMER_COUNT);
+                }
                 mMeasuredEnergyDetails.consumers =
                         new BatteryStats.MeasuredEnergyDetails.EnergyConsumer[consumerCount];
                 mMeasuredEnergyDetails.chargeUC = new long[consumerCount];
@@ -236,7 +267,16 @@
 
             if ((extensionFlags & BatteryStatsHistory.EXTENSION_CPU_USAGE_HEADER_FLAG) != 0) {
                 mCpuUsageDetails = new BatteryStats.CpuUsageDetails();
-                mCpuUsageDetails.cpuBracketDescriptions = src.readStringArray();
+                final int cpuBracketCount = src.readInt();
+                if (cpuBracketCount > MAX_CPU_BRACKET_COUNT) {
+                    // Check to avoid a heap explosion in case the parcel is corrupted
+                    throw new IllegalStateException("Too many CPU brackets: " + cpuBracketCount
+                            + ". Max = " + MAX_CPU_BRACKET_COUNT);
+                }
+                mCpuUsageDetails.cpuBracketDescriptions = new String[cpuBracketCount];
+                for (int i = 0; i < cpuBracketCount; i++) {
+                    mCpuUsageDetails.cpuBracketDescriptions[i] = src.readString();
+                }
                 mCpuUsageDetails.cpuUsageMs =
                         new long[mCpuUsageDetails.cpuBracketDescriptions.length];
             } else if (mCpuUsageDetails != null) {
@@ -294,7 +334,8 @@
     /**
      * Should be called when iteration is complete.
      */
+    @Override
     public void close() {
-        mBatteryStatsHistory.finishIteratingHistory();
+        mBatteryStatsHistory.iteratorFinished();
     }
 }
diff --git a/core/java/com/android/internal/security/TEST_MAPPING b/core/java/com/android/internal/security/TEST_MAPPING
index 803760c..b47ecec 100644
--- a/core/java/com/android/internal/security/TEST_MAPPING
+++ b/core/java/com/android/internal/security/TEST_MAPPING
@@ -14,6 +14,19 @@
     {
       "name": "ApkVerityTest",
       "file_patterns": ["VerityUtils\\.java"]
+    },
+    {
+      "name": "UpdatableSystemFontTest",
+      "file_patterns": ["VerityUtils\\.java"]
+    },
+    {
+      "name": "CtsAppSecurityHostTestCases",
+      "options": [
+        {
+          "include-filter": "android.appsecurity.cts.ApkVerityInstallTest"
+        }
+      ],
+      "file_patterns": ["VerityUtils\\.java"]
     }
   ]
 }
diff --git a/services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt b/core/java/com/android/internal/telephony/ICarrierConfigChangeListener.aidl
similarity index 71%
copy from services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt
copy to core/java/com/android/internal/telephony/ICarrierConfigChangeListener.aidl
index 528680e7..0f7ab0a 100644
--- a/services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt
+++ b/core/java/com/android/internal/telephony/ICarrierConfigChangeListener.aidl
@@ -14,11 +14,8 @@
  * limitations under the License.
  */
 
-package com.android.server.permission.access.external
+package com.android.internal.telephony;
 
-class RoSystemProperties {
-    companion object {
-        const val CONTROL_PRIVAPP_PERMISSIONS_DISABLE = false
-        const val CONTROL_PRIVAPP_PERMISSIONS_ENFORCE = false
-    }
-}
+oneway interface ICarrierConfigChangeListener {
+    void onCarrierConfigChanged(int slotIndex, int subId, int carrierId, int specificCarrierId);
+}
\ No newline at end of file
diff --git a/core/java/com/android/internal/telephony/ITelephonyRegistry.aidl b/core/java/com/android/internal/telephony/ITelephonyRegistry.aidl
index 7ba2686..54936c6 100644
--- a/core/java/com/android/internal/telephony/ITelephonyRegistry.aidl
+++ b/core/java/com/android/internal/telephony/ITelephonyRegistry.aidl
@@ -32,6 +32,7 @@
 import android.telephony.ServiceState;
 import android.telephony.SignalStrength;
 import android.telephony.emergency.EmergencyNumber;
+import com.android.internal.telephony.ICarrierConfigChangeListener;
 import com.android.internal.telephony.ICarrierPrivilegesCallback;
 import com.android.internal.telephony.IPhoneStateListener;
 import com.android.internal.telephony.IOnSubscriptionsChangedListener;
@@ -109,4 +110,8 @@
             int phoneId, in List<String> privilegedPackageNames, in int[] privilegedUids);
     void notifyCarrierServiceChanged(int phoneId, in String packageName, int uid);
 
+    void addCarrierConfigChangeListener(ICarrierConfigChangeListener listener,
+            String pkg, String featureId);
+    void removeCarrierConfigChangeListener(ICarrierConfigChangeListener listener, String pkg);
+    void notifyCarrierConfigChanged(int phoneId, int subId, int carrierId, int specificCarrierId);
 }
diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java
index 953b36b..cc5de3e 100644
--- a/core/java/com/android/internal/widget/LockPatternUtils.java
+++ b/core/java/com/android/internal/widget/LockPatternUtils.java
@@ -1742,7 +1742,7 @@
     }
 
     public static boolean userOwnsFrpCredential(Context context, UserInfo info) {
-        return info != null && info.isPrimary() && info.isAdmin() && frpCredentialEnabled(context);
+        return info != null && info.isMain() && info.isAdmin() && frpCredentialEnabled(context);
     }
 
     public static boolean frpCredentialEnabled(Context context) {
diff --git a/core/jni/TEST_MAPPING b/core/jni/TEST_MAPPING
index 004c30e..2844856 100644
--- a/core/jni/TEST_MAPPING
+++ b/core/jni/TEST_MAPPING
@@ -11,6 +11,29 @@
         }
       ],
       "file_patterns": ["CharsetUtils|FastData"]
+    },
+    {
+      "name": "SelfTargetingOverlayDeviceTests",
+      "file_patterns": ["Overlay"]
+    }
+  ],
+  "presubmit-large": [
+    {
+      "name": "CtsContentTestCases",
+      "options": [
+        {
+          "exclude-annotation": "androidx.test.filters.FlakyTest"
+        },
+        {
+          "exclude-annotation": "org.junit.Ignore"
+        },
+        {
+          "include-filter": "android.content.om.cts"
+        },
+        {
+          "include-filter": "android.content.res.loader.cts"
+        }
+      ]
     }
   ]
 }
diff --git a/core/jni/android_hardware_Camera.cpp b/core/jni/android_hardware_Camera.cpp
index 365a18d..a8abe50 100644
--- a/core/jni/android_hardware_Camera.cpp
+++ b/core/jni/android_hardware_Camera.cpp
@@ -529,9 +529,8 @@
     return Camera::getNumberOfCameras();
 }
 
-static void android_hardware_Camera_getCameraInfo(JNIEnv *env, jobject thiz,
-    jint cameraId, jobject info_obj)
-{
+static void android_hardware_Camera_getCameraInfo(JNIEnv *env, jobject thiz, jint cameraId,
+                                                  jboolean overrideToPortrait, jobject info_obj) {
     CameraInfo cameraInfo;
     if (cameraId >= Camera::getNumberOfCameras() || cameraId < 0) {
         ALOGE("%s: Unknown camera ID %d", __FUNCTION__, cameraId);
@@ -539,7 +538,7 @@
         return;
     }
 
-    status_t rc = Camera::getCameraInfo(cameraId, &cameraInfo);
+    status_t rc = Camera::getCameraInfo(cameraId, overrideToPortrait, &cameraInfo);
     if (rc != NO_ERROR) {
         jniThrowRuntimeException(env, "Fail to get camera info");
         return;
@@ -555,9 +554,9 @@
 }
 
 // connect to camera service
-static jint android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz,
-    jobject weak_this, jint cameraId, jstring clientPackageName)
-{
+static jint android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz, jobject weak_this,
+                                                 jint cameraId, jstring clientPackageName,
+                                                 jboolean overrideToPortrait) {
     // Convert jstring to String16
     const char16_t *rawClientName = reinterpret_cast<const char16_t*>(
         env->GetStringChars(clientPackageName, NULL));
@@ -567,8 +566,9 @@
                             reinterpret_cast<const jchar*>(rawClientName));
 
     int targetSdkVersion = android_get_application_target_sdk_version();
-    sp<Camera> camera = Camera::connect(cameraId, clientName, Camera::USE_CALLING_UID,
-                                        Camera::USE_CALLING_PID, targetSdkVersion);
+    sp<Camera> camera =
+            Camera::connect(cameraId, clientName, Camera::USE_CALLING_UID, Camera::USE_CALLING_PID,
+                            targetSdkVersion, overrideToPortrait);
     if (camera == NULL) {
         return -EACCES;
     }
@@ -596,7 +596,7 @@
 
     // Update default display orientation in case the sensor is reverse-landscape
     CameraInfo cameraInfo;
-    status_t rc = Camera::getCameraInfo(cameraId, &cameraInfo);
+    status_t rc = Camera::getCameraInfo(cameraId, overrideToPortrait, &cameraInfo);
     if (rc != NO_ERROR) {
         ALOGE("%s: getCameraInfo error: %d", __FUNCTION__, rc);
         return rc;
@@ -1051,93 +1051,43 @@
 //-------------------------------------------------
 
 static const JNINativeMethod camMethods[] = {
-  { "getNumberOfCameras",
-    "()I",
-    (void *)android_hardware_Camera_getNumberOfCameras },
-  { "_getCameraInfo",
-    "(ILandroid/hardware/Camera$CameraInfo;)V",
-    (void*)android_hardware_Camera_getCameraInfo },
-  { "native_setup",
-    "(Ljava/lang/Object;ILjava/lang/String;)I",
-    (void*)android_hardware_Camera_native_setup },
-  { "native_release",
-    "()V",
-    (void*)android_hardware_Camera_release },
-  { "setPreviewSurface",
-    "(Landroid/view/Surface;)V",
-    (void *)android_hardware_Camera_setPreviewSurface },
-  { "setPreviewTexture",
-    "(Landroid/graphics/SurfaceTexture;)V",
-    (void *)android_hardware_Camera_setPreviewTexture },
-  { "setPreviewCallbackSurface",
-    "(Landroid/view/Surface;)V",
-    (void *)android_hardware_Camera_setPreviewCallbackSurface },
-  { "startPreview",
-    "()V",
-    (void *)android_hardware_Camera_startPreview },
-  { "_stopPreview",
-    "()V",
-    (void *)android_hardware_Camera_stopPreview },
-  { "previewEnabled",
-    "()Z",
-    (void *)android_hardware_Camera_previewEnabled },
-  { "setHasPreviewCallback",
-    "(ZZ)V",
-    (void *)android_hardware_Camera_setHasPreviewCallback },
-  { "_addCallbackBuffer",
-    "([BI)V",
-    (void *)android_hardware_Camera_addCallbackBuffer },
-  { "native_autoFocus",
-    "()V",
-    (void *)android_hardware_Camera_autoFocus },
-  { "native_cancelAutoFocus",
-    "()V",
-    (void *)android_hardware_Camera_cancelAutoFocus },
-  { "native_takePicture",
-    "(I)V",
-    (void *)android_hardware_Camera_takePicture },
-  { "native_setParameters",
-    "(Ljava/lang/String;)V",
-    (void *)android_hardware_Camera_setParameters },
-  { "native_getParameters",
-    "()Ljava/lang/String;",
-    (void *)android_hardware_Camera_getParameters },
-  { "reconnect",
-    "()V",
-    (void*)android_hardware_Camera_reconnect },
-  { "lock",
-    "()V",
-    (void*)android_hardware_Camera_lock },
-  { "unlock",
-    "()V",
-    (void*)android_hardware_Camera_unlock },
-  { "startSmoothZoom",
-    "(I)V",
-    (void *)android_hardware_Camera_startSmoothZoom },
-  { "stopSmoothZoom",
-    "()V",
-    (void *)android_hardware_Camera_stopSmoothZoom },
-  { "setDisplayOrientation",
-    "(I)V",
-    (void *)android_hardware_Camera_setDisplayOrientation },
-  { "_enableShutterSound",
-    "(Z)Z",
-    (void *)android_hardware_Camera_enableShutterSound },
-  { "_startFaceDetection",
-    "(I)V",
-    (void *)android_hardware_Camera_startFaceDetection },
-  { "_stopFaceDetection",
-    "()V",
-    (void *)android_hardware_Camera_stopFaceDetection},
-  { "enableFocusMoveCallback",
-    "(I)V",
-    (void *)android_hardware_Camera_enableFocusMoveCallback},
-  { "setAudioRestriction",
-    "(I)V",
-    (void *)android_hardware_Camera_setAudioRestriction},
-  { "getAudioRestriction",
-    "()I",
-    (void *)android_hardware_Camera_getAudioRestriction},
+        {"getNumberOfCameras", "()I", (void *)android_hardware_Camera_getNumberOfCameras},
+        {"_getCameraInfo", "(IZLandroid/hardware/Camera$CameraInfo;)V",
+         (void *)android_hardware_Camera_getCameraInfo},
+        {"native_setup", "(Ljava/lang/Object;ILjava/lang/String;Z)I",
+         (void *)android_hardware_Camera_native_setup},
+        {"native_release", "()V", (void *)android_hardware_Camera_release},
+        {"setPreviewSurface", "(Landroid/view/Surface;)V",
+         (void *)android_hardware_Camera_setPreviewSurface},
+        {"setPreviewTexture", "(Landroid/graphics/SurfaceTexture;)V",
+         (void *)android_hardware_Camera_setPreviewTexture},
+        {"setPreviewCallbackSurface", "(Landroid/view/Surface;)V",
+         (void *)android_hardware_Camera_setPreviewCallbackSurface},
+        {"startPreview", "()V", (void *)android_hardware_Camera_startPreview},
+        {"_stopPreview", "()V", (void *)android_hardware_Camera_stopPreview},
+        {"previewEnabled", "()Z", (void *)android_hardware_Camera_previewEnabled},
+        {"setHasPreviewCallback", "(ZZ)V", (void *)android_hardware_Camera_setHasPreviewCallback},
+        {"_addCallbackBuffer", "([BI)V", (void *)android_hardware_Camera_addCallbackBuffer},
+        {"native_autoFocus", "()V", (void *)android_hardware_Camera_autoFocus},
+        {"native_cancelAutoFocus", "()V", (void *)android_hardware_Camera_cancelAutoFocus},
+        {"native_takePicture", "(I)V", (void *)android_hardware_Camera_takePicture},
+        {"native_setParameters", "(Ljava/lang/String;)V",
+         (void *)android_hardware_Camera_setParameters},
+        {"native_getParameters", "()Ljava/lang/String;",
+         (void *)android_hardware_Camera_getParameters},
+        {"reconnect", "()V", (void *)android_hardware_Camera_reconnect},
+        {"lock", "()V", (void *)android_hardware_Camera_lock},
+        {"unlock", "()V", (void *)android_hardware_Camera_unlock},
+        {"startSmoothZoom", "(I)V", (void *)android_hardware_Camera_startSmoothZoom},
+        {"stopSmoothZoom", "()V", (void *)android_hardware_Camera_stopSmoothZoom},
+        {"setDisplayOrientation", "(I)V", (void *)android_hardware_Camera_setDisplayOrientation},
+        {"_enableShutterSound", "(Z)Z", (void *)android_hardware_Camera_enableShutterSound},
+        {"_startFaceDetection", "(I)V", (void *)android_hardware_Camera_startFaceDetection},
+        {"_stopFaceDetection", "()V", (void *)android_hardware_Camera_stopFaceDetection},
+        {"enableFocusMoveCallback", "(I)V",
+         (void *)android_hardware_Camera_enableFocusMoveCallback},
+        {"setAudioRestriction", "(I)V", (void *)android_hardware_Camera_setAudioRestriction},
+        {"getAudioRestriction", "()I", (void *)android_hardware_Camera_getAudioRestriction},
 };
 
 struct field {
diff --git a/core/jni/android_media_AudioFormat.h b/core/jni/android_media_AudioFormat.h
index 962b501..a9b1906 100644
--- a/core/jni/android_media_AudioFormat.h
+++ b/core/jni/android_media_AudioFormat.h
@@ -49,6 +49,7 @@
 #define ENCODING_DRA 28
 #define ENCODING_DTS_HD_MA 29
 #define ENCODING_DTS_UHD_P2 30
+#define ENCODING_DSD 31
 
 #define ENCODING_INVALID    0
 #define ENCODING_DEFAULT    1
@@ -122,6 +123,8 @@
         return AUDIO_FORMAT_DTS_HD_MA;
     case ENCODING_DTS_UHD_P2:
         return AUDIO_FORMAT_DTS_UHD_P2;
+    case ENCODING_DSD:
+        return AUDIO_FORMAT_DSD;
     default:
         return AUDIO_FORMAT_INVALID;
     }
@@ -201,6 +204,8 @@
         return ENCODING_DTS_UHD_P2;
     case AUDIO_FORMAT_DEFAULT:
         return ENCODING_DEFAULT;
+    case AUDIO_FORMAT_DSD:
+        return ENCODING_DSD;
     default:
         return ENCODING_INVALID;
     }
diff --git a/core/jni/android_media_AudioMixerAttributes.h b/core/jni/android_media_AudioMixerAttributes.h
new file mode 100644
index 0000000..9e4637f
--- /dev/null
+++ b/core/jni/android_media_AudioMixerAttributes.h
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+#ifndef ANDROID_MEDIA_AUDIOMIXERATTRIBUTES_H
+#define ANDROID_MEDIA_AUDIOMIXERATTRIBUTES_H
+
+#include <system/audio.h>
+
+// Keep sync with AudioMixerAttributes.java
+#define MIXER_BEHAVIOR_DEFAULT 0
+#define MIXER_BEHAVIOR_BIT_PERFECT 1
+// Invalid value is not added in JAVA API, but keep sync with native value
+#define MIXER_BEHAVIOR_INVALID -1
+
+static inline audio_mixer_behavior_t audioMixerBehaviorToNative(int mixerBehavior) {
+    switch (mixerBehavior) {
+        case MIXER_BEHAVIOR_DEFAULT:
+            return AUDIO_MIXER_BEHAVIOR_DEFAULT;
+        case MIXER_BEHAVIOR_BIT_PERFECT:
+            return AUDIO_MIXER_BEHAVIOR_BIT_PERFECT;
+        default:
+            return AUDIO_MIXER_BEHAVIOR_INVALID;
+    }
+}
+
+static inline jint audioMixerBehaviorFromNative(audio_mixer_behavior_t mixerBehavior) {
+    switch (mixerBehavior) {
+        case AUDIO_MIXER_BEHAVIOR_DEFAULT:
+            return MIXER_BEHAVIOR_DEFAULT;
+        case AUDIO_MIXER_BEHAVIOR_BIT_PERFECT:
+            return MIXER_BEHAVIOR_BIT_PERFECT;
+        case AUDIO_MIXER_BEHAVIOR_INVALID:
+        default:
+            return MIXER_BEHAVIOR_INVALID;
+    }
+}
+
+#endif
diff --git a/core/jni/android_media_AudioSystem.cpp b/core/jni/android_media_AudioSystem.cpp
index 2433a05..28ac464 100644
--- a/core/jni/android_media_AudioSystem.cpp
+++ b/core/jni/android_media_AudioSystem.cpp
@@ -21,6 +21,7 @@
 #include <android/media/AudioVibratorInfo.h>
 #include <android/media/INativeSpatializerCallback.h>
 #include <android/media/ISpatializer.h>
+#include <android/media/audio/common/AudioConfigBase.h>
 #include <android_os_Parcel.h>
 #include <audiomanager/AudioManager.h>
 #include <jni.h>
@@ -34,6 +35,7 @@
 #include <system/audio_policy.h>
 #include <utils/Log.h>
 
+#include <optional>
 #include <sstream>
 #include <vector>
 
@@ -43,6 +45,7 @@
 #include "android_media_AudioEffectDescriptor.h"
 #include "android_media_AudioErrors.h"
 #include "android_media_AudioFormat.h"
+#include "android_media_AudioMixerAttributes.h"
 #include "android_media_AudioProfile.h"
 #include "android_media_MicrophoneInfo.h"
 #include "android_util_Binder.h"
@@ -51,6 +54,7 @@
 // ----------------------------------------------------------------------------
 
 using namespace android;
+using media::audio::common::AudioConfigBase;
 
 static const char* const kClassPathName = "android/media/AudioSystem";
 
@@ -145,10 +149,12 @@
 } gAudioMixFields;
 
 static jclass gAudioFormatClass;
+static jmethodID gAudioFormatCstor;
 static struct {
     jfieldID    mEncoding;
     jfieldID    mSampleRate;
     jfieldID    mChannelMask;
+    jfieldID mChannelIndexMask;
     // other fields unused by JNI
 } gAudioFormatFields;
 
@@ -211,6 +217,7 @@
     jfieldID mChannelMasks;
     jfieldID mChannelIndexMasks;
     jfieldID mEncapsulationType;
+    jfieldID mMixerBehaviors;
 } gAudioProfileFields;
 
 jclass gVibratorClass;
@@ -221,6 +228,13 @@
     jmethodID getMaxAmplitude;
 } gVibratorMethods;
 
+jclass gAudioMixerAttributesClass;
+jmethodID gAudioMixerAttributesCstor;
+static struct {
+    jfieldID mFormat;
+    jfieldID mMixerBehavior;
+} gAudioMixerAttributesField;
+
 static Mutex gLock;
 
 enum AudioError {
@@ -237,6 +251,12 @@
 
 #define MAX_PORT_GENERATION_SYNC_ATTEMPTS 5
 
+// Keep sync with AudioFormat.java
+#define AUDIO_FORMAT_HAS_PROPERTY_ENCODING 0x1
+#define AUDIO_FORMAT_HAS_PROPERTY_SAMPLE_RATE 0x2
+#define AUDIO_FORMAT_HAS_PROPERTY_CHANNEL_MASK 0x4
+#define AUDIO_FORMAT_HAS_PROPERTY_CHANNEL_INDEX_MASK 0x8
+
 // ----------------------------------------------------------------------------
 // ref-counted object for audio port callbacks
 class JNIAudioPortCallback: public AudioSystem::AudioPortCallback
@@ -2105,6 +2125,80 @@
     }
 }
 
+void javaAudioFormatToNativeAudioConfigBase(JNIEnv *env, const jobject jFormat,
+                                            audio_config_base_t *nConfigBase, bool isInput) {
+    *nConfigBase = AUDIO_CONFIG_BASE_INITIALIZER;
+    nConfigBase->format =
+            audioFormatToNative(env->GetIntField(jFormat, gAudioFormatFields.mEncoding));
+    nConfigBase->sample_rate = env->GetIntField(jFormat, gAudioFormatFields.mSampleRate);
+    jint jChannelMask = env->GetIntField(jFormat, gAudioFormatFields.mChannelMask);
+    jint jChannelIndexMask = env->GetIntField(jFormat, gAudioFormatFields.mChannelIndexMask);
+    nConfigBase->channel_mask = jChannelIndexMask != 0
+            ? audio_channel_mask_from_representation_and_bits(AUDIO_CHANNEL_REPRESENTATION_INDEX,
+                                                              jChannelIndexMask)
+            : isInput ? inChannelMaskToNative(jChannelMask)
+                      : outChannelMaskToNative(jChannelMask);
+}
+
+jobject nativeAudioConfigBaseToJavaAudioFormat(JNIEnv *env, const audio_config_base_t *nConfigBase,
+                                               bool isInput) {
+    if (nConfigBase == nullptr) {
+        return nullptr;
+    }
+    int propertyMask = AUDIO_FORMAT_HAS_PROPERTY_ENCODING | AUDIO_FORMAT_HAS_PROPERTY_SAMPLE_RATE;
+    int channelMask = 0;
+    int channelIndexMask = 0;
+    switch (audio_channel_mask_get_representation(nConfigBase->channel_mask)) {
+        case AUDIO_CHANNEL_REPRESENTATION_POSITION:
+            channelMask = isInput ? inChannelMaskFromNative(nConfigBase->channel_mask)
+                                  : outChannelMaskFromNative(nConfigBase->channel_mask);
+            propertyMask |= AUDIO_FORMAT_HAS_PROPERTY_CHANNEL_MASK;
+            break;
+        case AUDIO_CHANNEL_REPRESENTATION_INDEX:
+            channelIndexMask = audio_channel_mask_get_bits(nConfigBase->channel_mask);
+            propertyMask |= AUDIO_FORMAT_HAS_PROPERTY_CHANNEL_INDEX_MASK;
+            break;
+        default:
+            // This must not happen
+            break;
+    }
+    return env->NewObject(gAudioFormatClass, gAudioFormatCstor, propertyMask,
+                          audioFormatFromNative(nConfigBase->format), nConfigBase->sample_rate,
+                          channelMask, channelIndexMask);
+}
+
+jint convertAudioMixerAttributesToNative(JNIEnv *env, const jobject jAudioMixerAttributes,
+                                         audio_mixer_attributes_t *nMixerAttributes) {
+    ScopedLocalRef<jobject> jFormat(env,
+                                    env->GetObjectField(jAudioMixerAttributes,
+                                                        gAudioMixerAttributesField.mFormat));
+    javaAudioFormatToNativeAudioConfigBase(env, jFormat.get(), &nMixerAttributes->config,
+                                           false /*isInput*/);
+    nMixerAttributes->mixer_behavior = audioMixerBehaviorToNative(
+            env->GetIntField(jAudioMixerAttributes, gAudioMixerAttributesField.mMixerBehavior));
+    if (nMixerAttributes->mixer_behavior == AUDIO_MIXER_BEHAVIOR_INVALID) {
+        return (jint)AUDIO_JAVA_BAD_VALUE;
+    }
+    return (jint)AUDIO_JAVA_SUCCESS;
+}
+
+jobject convertAudioMixerAttributesFromNative(JNIEnv *env,
+                                              const audio_mixer_attributes_t *nMixerAttributes) {
+    if (nMixerAttributes == nullptr) {
+        return nullptr;
+    }
+    jint mixerBehavior = audioMixerBehaviorFromNative(nMixerAttributes->mixer_behavior);
+    if (mixerBehavior == MIXER_BEHAVIOR_INVALID) {
+        return nullptr;
+    }
+    ScopedLocalRef<jobject>
+            jFormat(env,
+                    nativeAudioConfigBaseToJavaAudioFormat(env, &nMixerAttributes->config,
+                                                           false /*isInput*/));
+    return env->NewObject(gAudioMixerAttributesClass, gAudioMixerAttributesCstor, jFormat.get(),
+                          mixerBehavior);
+}
+
 static jint convertAudioMixToNative(JNIEnv *env,
                                     AudioMix *nAudioMix,
                                     const jobject jAudioMix)
@@ -2868,6 +2962,20 @@
     return canBeSpatialized;
 }
 
+static jobject android_media_AudioSystem_nativeGetSoundDose(JNIEnv *env, jobject thiz,
+                                                            jobject jISoundDoseCallback) {
+    sp<media::ISoundDoseCallback> nISoundDoseCallback = interface_cast<media::ISoundDoseCallback>(
+            ibinderForJavaObject(env, jISoundDoseCallback));
+
+    sp<media::ISoundDose> nSoundDose;
+    status_t status = AudioSystem::getSoundDoseInterface(nISoundDoseCallback, &nSoundDose);
+
+    if (status != NO_ERROR) {
+        return nullptr;
+    }
+    return javaObjectForIBinder(env, IInterface::asBinder(nSoundDose));
+}
+
 // keep these values in sync with AudioSystem.java
 #define DIRECT_NOT_SUPPORTED 0
 #define DIRECT_OFFLOAD_SUPPORTED 1
@@ -2957,6 +3065,142 @@
     return jStatus;
 }
 
+static jint android_media_AudioSystem_getSupportedMixerAttributes(JNIEnv *env, jobject thiz,
+                                                                  jint jDeviceId,
+                                                                  jobject jAudioMixerAttributes) {
+    ALOGV("%s", __func__);
+    if (jAudioMixerAttributes == NULL) {
+        ALOGE("getSupportedMixerAttributes NULL AudioMixerAttributes list");
+        return (jint)AUDIO_JAVA_BAD_VALUE;
+    }
+    if (!env->IsInstanceOf(jAudioMixerAttributes, gListClass)) {
+        ALOGE("getSupportedMixerAttributes not a list");
+        return (jint)AUDIO_JAVA_BAD_VALUE;
+    }
+
+    std::vector<audio_mixer_attributes_t> nMixerAttributes;
+    status_t status = AudioSystem::getSupportedMixerAttributes((audio_port_handle_t)jDeviceId,
+                                                               &nMixerAttributes);
+    if (status != NO_ERROR) {
+        return nativeToJavaStatus(status);
+    }
+    for (const auto &mixerAttr : nMixerAttributes) {
+        ScopedLocalRef<jobject> jMixerAttributes(env,
+                                                 convertAudioMixerAttributesFromNative(env,
+                                                                                       &mixerAttr));
+        if (jMixerAttributes.get() == nullptr) {
+            return (jint)AUDIO_JAVA_ERROR;
+        }
+
+        env->CallBooleanMethod(jAudioMixerAttributes, gListMethods.add, jMixerAttributes.get());
+    }
+
+    return (jint)AUDIO_JAVA_SUCCESS;
+}
+
+static jint android_media_AudioSystem_setPreferredMixerAttributes(JNIEnv *env, jobject thiz,
+                                                                  jobject jAudioAttributes,
+                                                                  jint portId, jint uid,
+                                                                  jobject jAudioMixerAttributes) {
+    ALOGV("%s", __func__);
+
+    if (jAudioAttributes == nullptr) {
+        ALOGE("jAudioAttributes is NULL");
+        return (jint)AUDIO_JAVA_BAD_VALUE;
+    }
+    if (jAudioMixerAttributes == nullptr) {
+        ALOGE("jAudioMixerAttributes is NULL");
+        return (jint)AUDIO_JAVA_BAD_VALUE;
+    }
+
+    JNIAudioAttributeHelper::UniqueAaPtr paa = JNIAudioAttributeHelper::makeUnique();
+    jint jStatus = JNIAudioAttributeHelper::nativeFromJava(env, jAudioAttributes, paa.get());
+    if (jStatus != (jint)AUDIO_JAVA_SUCCESS) {
+        return jStatus;
+    }
+
+    audio_mixer_attributes_t mixerAttributes = AUDIO_MIXER_ATTRIBUTES_INITIALIZER;
+    jStatus = convertAudioMixerAttributesToNative(env, jAudioMixerAttributes, &mixerAttributes);
+    if (jStatus != (jint)AUDIO_JAVA_SUCCESS) {
+        return jStatus;
+    }
+
+    status_t status =
+            AudioSystem::setPreferredMixerAttributes(paa.get(), (audio_port_handle_t)portId,
+                                                     (uid_t)uid, &mixerAttributes);
+    return nativeToJavaStatus(status);
+}
+
+static jint android_media_AudioSystem_getPreferredMixerAttributes(JNIEnv *env, jobject thiz,
+                                                                  jobject jAudioAttributes,
+                                                                  jint portId,
+                                                                  jobject jAudioMixerAttributes) {
+    ALOGV("%s", __func__);
+
+    if (jAudioAttributes == nullptr) {
+        ALOGE("getPreferredMixerAttributes jAudioAttributes is NULL");
+        return (jint)AUDIO_JAVA_BAD_VALUE;
+    }
+    if (jAudioMixerAttributes == NULL) {
+        ALOGE("getPreferredMixerAttributes NULL AudioMixerAttributes list");
+        return (jint)AUDIO_JAVA_BAD_VALUE;
+    }
+    if (!env->IsInstanceOf(jAudioMixerAttributes, gListClass)) {
+        ALOGE("getPreferredMixerAttributes not a list");
+        return (jint)AUDIO_JAVA_BAD_VALUE;
+    }
+
+    JNIAudioAttributeHelper::UniqueAaPtr paa = JNIAudioAttributeHelper::makeUnique();
+    jint jStatus = JNIAudioAttributeHelper::nativeFromJava(env, jAudioAttributes, paa.get());
+    if (jStatus != (jint)AUDIO_JAVA_SUCCESS) {
+        return jStatus;
+    }
+
+    std::optional<audio_mixer_attributes_t> nMixerAttributes;
+    status_t status =
+            AudioSystem::getPreferredMixerAttributes(paa.get(), (audio_port_handle_t)portId,
+                                                     &nMixerAttributes);
+    if (status != NO_ERROR) {
+        return nativeToJavaStatus(status);
+    }
+
+    ScopedLocalRef<jobject>
+            jMixerAttributes(env,
+                             convertAudioMixerAttributesFromNative(env,
+                                                                   nMixerAttributes.has_value()
+                                                                           ? &nMixerAttributes
+                                                                                      .value()
+                                                                           : nullptr));
+    if (jMixerAttributes.get() == nullptr) {
+        return (jint)AUDIO_JAVA_ERROR;
+    }
+
+    env->CallBooleanMethod(jAudioMixerAttributes, gListMethods.add, jMixerAttributes.get());
+    return AUDIO_JAVA_SUCCESS;
+}
+
+static jint android_media_AudioSystem_clearPreferredMixerAttributes(JNIEnv *env, jobject thiz,
+                                                                    jobject jAudioAttributes,
+                                                                    jint portId, jint uid) {
+    ALOGV("%s", __func__);
+
+    if (jAudioAttributes == nullptr) {
+        ALOGE("jAudioAttributes is NULL");
+        return (jint)AUDIO_JAVA_BAD_VALUE;
+    }
+
+    JNIAudioAttributeHelper::UniqueAaPtr paa = JNIAudioAttributeHelper::makeUnique();
+    jint jStatus = JNIAudioAttributeHelper::nativeFromJava(env, jAudioAttributes, paa.get());
+    if (jStatus != (jint)AUDIO_JAVA_SUCCESS) {
+        return jStatus;
+    }
+
+    status_t status =
+            AudioSystem::clearPreferredMixerAttributes(paa.get(), (audio_port_handle_t)portId,
+                                                       (uid_t)uid);
+    return nativeToJavaStatus(status);
+}
+
 // ----------------------------------------------------------------------------
 
 static const JNINativeMethod gMethods[] =
@@ -3104,12 +3348,23 @@
           "(Landroid/media/AudioAttributes;Landroid/media/AudioFormat;"
           "[Landroid/media/AudioDeviceAttributes;)Z",
           (void *)android_media_AudioSystem_canBeSpatialized},
+         {"nativeGetSoundDose", "(Landroid/media/ISoundDoseCallback;)Landroid/os/IBinder;",
+          (void *)android_media_AudioSystem_nativeGetSoundDose},
          {"getDirectPlaybackSupport",
           "(Landroid/media/AudioFormat;Landroid/media/AudioAttributes;)I",
           (void *)android_media_AudioSystem_getDirectPlaybackSupport},
          {"getDirectProfilesForAttributes",
           "(Landroid/media/AudioAttributes;Ljava/util/ArrayList;)I",
-          (void *)android_media_AudioSystem_getDirectProfilesForAttributes}};
+          (void *)android_media_AudioSystem_getDirectProfilesForAttributes},
+         {"getSupportedMixerAttributes", "(ILjava/util/List;)I",
+          (void *)android_media_AudioSystem_getSupportedMixerAttributes},
+         {"setPreferredMixerAttributes",
+          "(Landroid/media/AudioAttributes;IILandroid/media/AudioMixerAttributes;)I",
+          (void *)android_media_AudioSystem_setPreferredMixerAttributes},
+         {"getPreferredMixerAttributes", "(Landroid/media/AudioAttributes;ILjava/util/List;)I",
+          (void *)android_media_AudioSystem_getPreferredMixerAttributes},
+         {"clearPreferredMixerAttributes", "(Landroid/media/AudioAttributes;II)I",
+          (void *)android_media_AudioSystem_clearPreferredMixerAttributes}};
 
 static const JNINativeMethod gEventHandlerMethods[] = {
     {"native_setup",
@@ -3272,9 +3527,12 @@
 
     jclass audioFormatClass = FindClassOrDie(env, "android/media/AudioFormat");
     gAudioFormatClass = MakeGlobalRefOrDie(env, audioFormatClass);
+    gAudioFormatCstor = GetMethodIDOrDie(env, audioFormatClass, "<init>", "(IIIII)V");
     gAudioFormatFields.mEncoding = GetFieldIDOrDie(env, audioFormatClass, "mEncoding", "I");
     gAudioFormatFields.mSampleRate = GetFieldIDOrDie(env, audioFormatClass, "mSampleRate", "I");
     gAudioFormatFields.mChannelMask = GetFieldIDOrDie(env, audioFormatClass, "mChannelMask", "I");
+    gAudioFormatFields.mChannelIndexMask =
+            GetFieldIDOrDie(env, audioFormatClass, "mChannelIndexMask", "I");
 
     jclass audioMixingRuleClass = FindClassOrDie(env, "android/media/audiopolicy/AudioMixingRule");
     gAudioMixingRuleClass = MakeGlobalRefOrDie(env, audioMixingRuleClass);
@@ -3348,6 +3606,15 @@
     gVibratorMethods.getMaxAmplitude =
             GetMethodIDOrDie(env, vibratorClass, "getHapticChannelMaximumAmplitude", "()F");
 
+    jclass audioMixerAttributesClass = FindClassOrDie(env, "android/media/AudioMixerAttributes");
+    gAudioMixerAttributesClass = MakeGlobalRefOrDie(env, audioMixerAttributesClass);
+    gAudioMixerAttributesCstor = GetMethodIDOrDie(env, audioMixerAttributesClass, "<init>",
+                                                  "(Landroid/media/AudioFormat;I)V");
+    gAudioMixerAttributesField.mFormat = GetFieldIDOrDie(env, audioMixerAttributesClass, "mFormat",
+                                                         "Landroid/media/AudioFormat;");
+    gAudioMixerAttributesField.mMixerBehavior =
+            GetFieldIDOrDie(env, audioMixerAttributesClass, "mMixerBehavior", "I");
+
     AudioSystem::addErrorCallback(android_media_AudioSystem_error_callback);
 
     RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
diff --git a/core/jni/android_os_Debug.cpp b/core/jni/android_os_Debug.cpp
index 5e0d9b3..fe95762 100644
--- a/core/jni/android_os_Debug.cpp
+++ b/core/jni/android_os_Debug.cpp
@@ -587,6 +587,13 @@
     MEMINFO_ACTIVE,
     MEMINFO_INACTIVE,
     MEMINFO_UNEVICTABLE,
+    MEMINFO_AVAILABLE,
+    MEMINFO_ACTIVE_ANON,
+    MEMINFO_INACTIVE_ANON,
+    MEMINFO_ACTIVE_FILE,
+    MEMINFO_INACTIVE_FILE,
+    MEMINFO_CMA_TOTAL,
+    MEMINFO_CMA_FREE,
     MEMINFO_COUNT
 };
 
diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp
index 1ed3555..34589b7 100644
--- a/core/jni/android_view_SurfaceControl.cpp
+++ b/core/jni/android_view_SurfaceControl.cpp
@@ -1099,10 +1099,9 @@
                           connectionToSinkType);
 }
 
-static jobject nativeGetStaticDisplayInfo(JNIEnv* env, jclass clazz, jobject tokenObj) {
+static jobject nativeGetStaticDisplayInfo(JNIEnv* env, jclass clazz, jlong id) {
     ui::StaticDisplayInfo info;
-    if (const auto token = ibinderForJavaObject(env, tokenObj);
-        !token || SurfaceComposerClient::getStaticDisplayInfo(token, &info) != NO_ERROR) {
+    if (SurfaceComposerClient::getStaticDisplayInfo(id, &info) != NO_ERROR) {
         return nullptr;
     }
 
@@ -1160,10 +1159,9 @@
                           capabilities.getDesiredMinLuminance());
 }
 
-static jobject nativeGetDynamicDisplayInfo(JNIEnv* env, jclass clazz, jobject tokenObj) {
+static jobject nativeGetDynamicDisplayInfo(JNIEnv* env, jclass clazz, jlong displayId) {
     ui::DynamicDisplayInfo info;
-    if (const auto token = ibinderForJavaObject(env, tokenObj);
-        !token || SurfaceComposerClient::getDynamicDisplayInfo(token, &info) != NO_ERROR) {
+    if (SurfaceComposerClient::getDynamicDisplayInfoFromId(displayId, &info) != NO_ERROR) {
         return nullptr;
     }
 
@@ -1908,6 +1906,11 @@
     return javaObjectForIBinder(env, token);
 }
 
+static jboolean nativeBootFinished(JNIEnv* env, jclass clazz) {
+    status_t error = SurfaceComposerClient::bootFinished();
+    return error == OK ? JNI_TRUE : JNI_FALSE;
+}
+
 // ----------------------------------------------------------------------------
 
 SurfaceControl* android_view_SurfaceControl_getNativeSurfaceControl(JNIEnv* env,
@@ -2020,10 +2023,10 @@
     {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V",
             (void*)nativeSetDisplaySize },
     {"nativeGetStaticDisplayInfo",
-            "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$StaticDisplayInfo;",
+            "(J)Landroid/view/SurfaceControl$StaticDisplayInfo;",
             (void*)nativeGetStaticDisplayInfo },
     {"nativeGetDynamicDisplayInfo",
-            "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DynamicDisplayInfo;",
+            "(J)Landroid/view/SurfaceControl$DynamicDisplayInfo;",
             (void*)nativeGetDynamicDisplayInfo },
     {"nativeSetDesiredDisplayModeSpecs",
             "(Landroid/os/IBinder;Landroid/view/SurfaceControl$DesiredDisplayModeSpecs;)Z",
@@ -2140,6 +2143,8 @@
                 (void*)nativeSetDefaultApplyToken },
     {"nativeGetDefaultApplyToken", "()Landroid/os/IBinder;",
                 (void*)nativeGetDefaultApplyToken },
+    {"nativeBootFinished", "()Z",
+            (void*)nativeBootFinished },
         // clang-format on
 };
 
diff --git a/core/proto/OWNERS b/core/proto/OWNERS
index 9070933..db391f7 100644
--- a/core/proto/OWNERS
+++ b/core/proto/OWNERS
@@ -16,7 +16,8 @@
 per-file package_item_info.proto = toddke@google.com,patb@google.com
 per-file usagestatsservice.proto, usagestatsservice_v2.proto = file:/core/java/android/app/usage/OWNERS
 per-file apphibernationservice.proto = file:/core/java/android/apphibernation/OWNERS
-per-file android/hardware/sensorprivacy.proto = ntmyren@google.com,evanseverson@google.com,ewol@google.com
+per-file android/hardware/sensorprivacy.proto = ntmyren@google.com,evanseverson@google.com
+per-file background_install_control.proto = wenhaowang@google.com,georgechan@google.com,billylau@google.com
 
 # Biometrics
 jaggies@google.com
diff --git a/core/proto/android/server/background_install_control.proto b/core/proto/android/server/background_install_control.proto
new file mode 100644
index 0000000..38e6b4d
--- /dev/null
+++ b/core/proto/android/server/background_install_control.proto
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+
+syntax = "proto2";
+package com.android.server.pm;
+
+option java_multiple_files = true;
+
+// Proto for the background installed packages.
+// It's used for serializing the background installed package info to disk.
+message BackgroundInstalledPackagesProto {
+  repeated BackgroundInstalledPackageProto bg_installed_pkg = 1;
+}
+
+// Proto for the background installed package entry
+message BackgroundInstalledPackageProto {
+  optional string package_name = 1;
+  optional int32 user_id = 2;
+}
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index fb451dd..fd4d4f8 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -3349,6 +3349,14 @@
                 android:description="@string/permdesc_companionProfileWatch"
                 android:protectionLevel="normal" />
 
+    <!-- Allows app to request to be associated with a device via
+         {@link android.companion.CompanionDeviceManager}
+         as "glasses"
+         <p>Protection level: normal
+     -->
+    <permission android:name="android.permission.REQUEST_COMPANION_PROFILE_GLASSES"
+        android:protectionLevel="normal" />
+
     <!-- Allows application to request to be associated with a virtual display capable of streaming
          Android applications
          ({@link android.companion.AssociationRequest#DEVICE_PROFILE_APP_STREAMING})
@@ -3358,6 +3366,14 @@
     <permission android:name="android.permission.REQUEST_COMPANION_PROFILE_APP_STREAMING"
                 android:protectionLevel="signature|privileged" />
 
+    <!-- Allows application to request to stream content from an Android host to a nearby device
+         ({@link android.companion.AssociationRequest#DEVICE_PROFILE_NEARBY_DEVICE_STREAMING})
+         by {@link android.companion.CompanionDeviceManager}.
+        <p>Not for use by third-party applications.
+    -->
+    <permission android:name="android.permission.REQUEST_COMPANION_PROFILE_NEARBY_DEVICE_STREAMING"
+        android:protectionLevel="signature|privileged" />
+
     <!-- Allows application to request to be associated with a vehicle head unit capable of
          automotive projection
          ({@link android.companion.AssociationRequest#DEVICE_PROFILE_AUTOMOTIVE_PROJECTION})
@@ -3847,6 +3863,11 @@
     <permission android:name="android.permission.REQUEST_UNIQUE_ID_ATTESTATION"
          android:protectionLevel="signature" />
 
+    <!-- Allows an application to get enabled credential manager providers.
+         @hide -->
+    <permission android:name="android.permission.LIST_ENABLED_CREDENTIAL_PROVIDERS"
+        android:protectionLevel="signature|privileged" />
+
     <!-- ========================================= -->
     <!-- Permissions for special development tools -->
     <!-- ========================================= -->
@@ -4025,7 +4046,7 @@
          @hide
     -->
     <permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW"
-        android:protectionLevel="signature" />
+        android:protectionLevel="signature|module" />
 
     <!-- Allows an application to avoid all toast rate limiting restrictions.
          <p>Not for use by third-party applications.
@@ -4629,6 +4650,8 @@
          <p>Protection level: appop
      -->
     <permission android:name="android.permission.SCHEDULE_EXACT_ALARM"
+        android:label="@string/permlab_schedule_exact_alarm"
+        android:description="@string/permdesc_schedule_exact_alarm"
         android:protectionLevel="normal|appop"/>
 
     <!-- Allows apps to use exact alarms just like with {@link
@@ -4654,6 +4677,8 @@
          lower standby bucket.
     -->
     <permission android:name="android.permission.USE_EXACT_ALARM"
+                android:label="@string/permlab_use_exact_alarm"
+                android:description="@string/permdesc_use_exact_alarm"
                 android:protectionLevel="normal"/>
 
     <!-- Allows an application to query tablet mode state and monitor changes
@@ -4912,7 +4937,7 @@
     <!-- Allows an application to manage the companion devices.
          @hide -->
     <permission android:name="android.permission.MANAGE_COMPANION_DEVICES"
-                android:protectionLevel="signature|role" />
+                android:protectionLevel="module|signature|role" />
 
     <!-- Allows an application to subscribe to notifications about the presence status change
          of their associated companion device
@@ -4950,6 +4975,15 @@
     <permission android:name="android.permission.ROTATE_SURFACE_FLINGER"
         android:protectionLevel="signature|recents" />
 
+    <!-- @SystemApi Allows an application to provide hints to SurfaceFlinger that can influence
+         its wakes up time to compose the next frame. This is a subset of the capabilities granted
+         by {@link #ACCESS_SURFACE_FLINGER}.
+         <p>Not for use by third-party applications.
+         @hide
+    -->
+    <permission android:name="android.permission.WAKEUP_SURFACE_FLINGER"
+        android:protectionLevel="signature|recents" />
+
     <!-- Allows an application to take screen shots and more generally
          get access to the frame buffer data.
          <p>Not for use by third-party applications.
@@ -6772,6 +6806,14 @@
          @hide -->
     <permission android:name="android.permission.HANDLE_QUERY_PACKAGE_RESTART"
                 android:protectionLevel="signature" />
+
+    <!-- Allows low-level access to re-mapping modifier keys.
+         <p>Not for use by third-party applications.
+         @hide
+         @TestApi -->
+    <permission android:name="android.permission.REMAP_MODIFIER_KEYS"
+                android:protectionLevel="signature" />
+
     <uses-permission android:name="android.permission.HANDLE_QUERY_PACKAGE_RESTART" />
 
     <!-- Allows financed device kiosk apps to perform actions on the Device Lock service
@@ -7346,6 +7388,10 @@
                  android:permission="android.permission.BIND_JOB_SERVICE" >
         </service>
 
+        <service android:name="com.android.server.healthconnect.storage.AutoDeleteService"
+                 android:permission="android.permission.BIND_JOB_SERVICE" >
+        </service>
+
         <service android:name="com.android.server.pm.PackageManagerShellCommandDataLoader"
             android:exported="false">
             <intent-filter>
diff --git a/core/res/OWNERS b/core/res/OWNERS
index a2ef400..b878189 100644
--- a/core/res/OWNERS
+++ b/core/res/OWNERS
@@ -21,6 +21,11 @@
 tsuji@google.com
 yamasani@google.com
 
+# WindowManager team
+# TODO(262451702): Move WindowManager configs out of config.xml in a separate file
+per-file core/res/res/values/config.xml = file:/services/core/java/com/android/server/wm/OWNERS
+per-file core/res/res/values/symbols.xml = file:/services/core/java/com/android/server/wm/OWNERS
+
 # Resources finalization
 per-file res/xml/public-staging.xml = file:/tools/aapt2/OWNERS
 per-file res/xml/public-final.xml = file:/tools/aapt2/OWNERS
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 7946493..2d832bc 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -8955,9 +8955,6 @@
         <!-- Flag indicating whether a recognition service can be selected as default. The default
              value of this flag is true. -->
         <attr name="selectableAsDefault" format="boolean" />
-        <!-- The maximal number of recognition sessions ongoing at the same time.
-             The default value is 1, meaning no concurrency. -->
-        <attr name="maxConcurrentSessionsCount" format="integer" />
     </declare-styleable>
 
     <!-- Use <code>voice-interaction-service</code> as the root tag of the XML resource that
diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml
index c8a65a7..d4644c5 100644
--- a/core/res/res/values/attrs_manifest.xml
+++ b/core/res/res/values/attrs_manifest.xml
@@ -294,6 +294,9 @@
         <!-- Additional flag from base permission type: this permission can be automatically
             granted to the system app predictor -->
         <flag name="appPredictor" value="0x200000" />
+        <!-- Additional flag from base permission type: this permission can also be granted if the
+             requesting application is included in the mainline module}. -->
+        <flag name="module" value="0x400000" />
         <!-- Additional flag from base permission type: this permission can be automatically
             granted to the system companion device manager service -->
         <flag name="companion" value="0x800000" />
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 9a585a1..f995a6e 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -1371,30 +1371,6 @@
          Must be in the range specified by minimum and maximum. -->
     <item name="config_screenBrightnessSettingDefaultFloat" format="float" type="dimen">-2</item>
 
-    <!-- Note: This setting is deprecated, please use
-    config_screenBrightnessSettingForVrDefaultFloat instead -->
-    <integer name="config_screenBrightnessForVrSettingDefault">86</integer>
-
-    <!-- Note: This setting is deprecated, please use
-    config_screenBrightnessSettingForVrMinimumFloat instead -->
-    <integer name="config_screenBrightnessForVrSettingMinimum">79</integer>
-
-    <!-- Note: This setting is deprecated, please use
-    config_screenBrightnessSettingForVrMaximumFloat instead -->
-    <integer name="config_screenBrightnessForVrSettingMaximum">255</integer>
-
-    <!-- Default screen brightness for VR setting as a float.
-    Equivalent to 86/255-->
-    <item name="config_screenBrightnessSettingForVrDefaultFloat" format="float" type="dimen">0.33464</item>
-
-    <!-- Minimum screen brightness setting allowed for VR. Device panels start increasing pulse
-     width as brightness decreases below this threshold as float.
-     Equivalent to 79/255 -->
-    <item name="config_screenBrightnessSettingForVrMinimumFloat" format="float" type="dimen">0.307087</item>
-
-    <!-- Maximum screen brightness setting allowed for VR as float. -->
-    <item name="config_screenBrightnessSettingForVrMaximumFloat" format="float" type="dimen">1.0</item>
-
     <!-- Screen brightness used to dim the screen while dozing in a very low power state.
          May be less than the minimum allowed brightness setting
          that can be set by the user. -->
@@ -2507,6 +2483,10 @@
          states. -->
     <bool name="config_dozeAlwaysOnDisplayAvailable">false</bool>
 
+    <!-- Control whether the pickup gesture is enabled by default. This value will be used
+     during initialization when the setting is still null. -->
+    <bool name="config_dozePickupGestureEnabled">true</bool>
+
     <!-- Control whether the always on display mode is enabled by default. This value will be used
          during initialization when the setting is still null. -->
     <bool name="config_dozeAlwaysOnEnabled">true</bool>
@@ -3442,6 +3422,11 @@
          phone object irrespective of this config -->
     <bool name="config_switch_phone_on_voice_reg_state_change">true</bool>
 
+    <!-- Config determines whether Memory Availability Notification is supported over Ims so that
+         the RP-SMMA Notification is sent over Ims to SMS Service center indicating that UE can now
+          start receiving SMS after failures due to Memory Full event -->
+    <bool name="config_smma_notification_supported_over_ims">false</bool>
+
     <bool name="config_sms_force_7bit_encoding">false</bool>
 
     <!-- Number of physical SIM slots on the device. This includes both eSIM and pSIM slots, and
@@ -4785,11 +4770,11 @@
     <integer name="config_defaultPeakRefreshRate">0</integer>
 
     <!-- The display uses different gamma curves for different refresh rates. It's hard for panel
-         vendor to tune the curves to have exact same brightness for different refresh rate. So
+         vendors to tune the curves to have exact same brightness for different refresh rate. So
          flicker could be observed at switch time. The issue is worse at the gamma lower end.
          In addition, human eyes are more sensitive to the flicker at darker environment.
          To prevent flicker, we only support higher refresh rates if the display brightness is above
-         a threshold. And the darker environment could have higher threshold.
+         a threshold.
          For example, no higher refresh rate if
              display brightness <= disp0 && ambient brightness <= amb0
              || display brightness <= disp1 && ambient brightness <= amb1 -->
@@ -4811,13 +4796,12 @@
     <integer name="config_defaultRefreshRateInZone">0</integer>
 
     <!-- The display uses different gamma curves for different refresh rates. It's hard for panel
-         vendor to tune the curves to have exact same brightness for different refresh rate. So
+         vendors to tune the curves to have exact same brightness for different refresh rate. So
          flicker could be observed at switch time. The issue can be observed on the screen with
          even full white content at the high brightness. To prevent flickering, we support fixed
          refresh rates if the display and ambient brightness are equal to or above the provided
          thresholds. You can define multiple threshold levels as higher brightness environments
-         may have lower display brightness requirements for the flickering is visible. And the
-         high brightness environment could have higher threshold.
+         may have lower display brightness requirements for the flickering is visible.
          For example, fixed refresh rate if
              display brightness >= disp0 && ambient brightness >= amb0
              || display brightness >= disp1 && ambient brightness >= amb1 -->
@@ -5297,6 +5281,10 @@
     <!-- Whether using split screen aspect ratio as a default aspect ratio for unresizable apps. -->
     <bool name="config_letterboxIsSplitScreenAspectRatioForUnresizableAppsEnabled">false</bool>
 
+    <!-- Whether the specific behaviour for translucent activities letterboxing is enabled.
+         TODO(b/255532890) Enable when ignoreOrientationRequest is set -->
+    <bool name="config_letterboxIsEnabledForTranslucentActivities">false</bool>
+
     <!-- Whether a camera compat controller is enabled to allow the user to apply or revert
          treatment for stretched issues in camera viewfinder. -->
     <bool name="config_isCameraCompatControlForStretchedIssuesEnabled">false</bool>
diff --git a/core/res/res/values/locale_config.xml b/core/res/res/values/locale_config.xml
index 78ec145..bd93aa9 100644
--- a/core/res/res/values/locale_config.xml
+++ b/core/res/res/values/locale_config.xml
@@ -23,7 +23,7 @@
         <item>ak-GH</item> <!-- Akan (Ghana) -->
         <item>am-ET</item> <!-- Amharic (Ethiopia) -->
         <item>ar-AE</item> <!-- Arabic (United Arab Emirates) -->
-        <item>ar-AE-u-nu-arab</item> <!-- Arabic (United Arab Emirates, Arabic Digits) -->
+        <item>ar-AE-u-nu-arab</item> <!-- Arabic (United Arab Emirates, Arabic-Indic Digits) -->
         <item>ar-BH</item> <!-- Arabic (Bahrain) -->
         <item>ar-BH-u-nu-latn</item> <!-- Arabic (Bahrain, Western Digits) -->
         <item>ar-DJ</item> <!-- Arabic (Djibouti) -->
@@ -108,6 +108,7 @@
         <item>cgg-UG</item> <!-- Chiga (Uganda) -->
         <item>chr-US</item> <!-- Cherokee (United States) -->
         <item>cs-CZ</item> <!-- Czech (Czechia) -->
+        <item>cv-RU</item> <!-- Chuvash (Russia) -->
         <item>cy-GB</item> <!-- Welsh (United Kingdom) -->
         <item>da-DK</item> <!-- Danish (Denmark) -->
         <item>da-GL</item> <!-- Danish (Greenland) -->
@@ -270,42 +271,42 @@
         <item>fa-AF-u-nu-latn</item> <!-- Persian (Afghanistan, Western Digits) -->
         <item>fa-IR</item> <!-- Persian (Iran) -->
         <item>fa-IR-u-nu-latn</item> <!-- Persian (Iran, Western Digits) -->
-        <item>ff-Adlm-BF</item> <!-- Fulah (Adlam, Burkina Faso) -->
-        <item>ff-Adlm-BF-u-nu-latn</item> <!-- Fulah (Adlam, Burkina Faso, Western Digits) -->
-        <item>ff-Adlm-CM</item> <!-- Fulah (Adlam, Cameroon) -->
-        <item>ff-Adlm-CM-u-nu-latn</item> <!-- Fulah (Adlam, Cameroon, Western Digits) -->
-        <item>ff-Adlm-GH</item> <!-- Fulah (Adlam, Ghana) -->
-        <item>ff-Adlm-GH-u-nu-latn</item> <!-- Fulah (Adlam, Ghana, Western Digits) -->
-        <item>ff-Adlm-GM</item> <!-- Fulah (Adlam, Gambia) -->
-        <item>ff-Adlm-GM-u-nu-latn</item> <!-- Fulah (Adlam, Gambia, Western Digits) -->
-        <item>ff-Adlm-GN</item> <!-- Fulah (Adlam, Guinea) -->
-        <item>ff-Adlm-GN-u-nu-latn</item> <!-- Fulah (Adlam, Guinea, Western Digits) -->
-        <item>ff-Adlm-GW</item> <!-- Fulah (Adlam, Guinea-Bissau) -->
-        <item>ff-Adlm-GW-u-nu-latn</item> <!-- Fulah (Adlam, Guinea-Bissau, Western Digits) -->
-        <item>ff-Adlm-LR</item> <!-- Fulah (Adlam, Liberia) -->
-        <item>ff-Adlm-LR-u-nu-latn</item> <!-- Fulah (Adlam, Liberia, Western Digits) -->
-        <item>ff-Adlm-MR</item> <!-- Fulah (Adlam, Mauritania) -->
-        <item>ff-Adlm-MR-u-nu-latn</item> <!-- Fulah (Adlam, Mauritania, Western Digits) -->
-        <item>ff-Adlm-NE</item> <!-- Fulah (Adlam, Niger) -->
-        <item>ff-Adlm-NE-u-nu-latn</item> <!-- Fulah (Adlam, Niger, Western Digits) -->
-        <item>ff-Adlm-NG</item> <!-- Fulah (Adlam, Nigeria) -->
-        <item>ff-Adlm-NG-u-nu-latn</item> <!-- Fulah (Adlam, Nigeria, Western Digits) -->
-        <item>ff-Adlm-SL</item> <!-- Fulah (Adlam, Sierra Leone) -->
-        <item>ff-Adlm-SL-u-nu-latn</item> <!-- Fulah (Adlam, Sierra Leone, Western Digits) -->
-        <item>ff-Adlm-SN</item> <!-- Fulah (Adlam, Senegal) -->
-        <item>ff-Adlm-SN-u-nu-latn</item> <!-- Fulah (Adlam, Senegal, Western Digits) -->
-        <item>ff-Latn-BF</item> <!-- Fulah (Latin, Burkina Faso) -->
-        <item>ff-Latn-CM</item> <!-- Fulah (Latin, Cameroon) -->
-        <item>ff-Latn-GH</item> <!-- Fulah (Latin, Ghana) -->
-        <item>ff-Latn-GM</item> <!-- Fulah (Latin, Gambia) -->
-        <item>ff-Latn-GN</item> <!-- Fulah (Latin, Guinea) -->
-        <item>ff-Latn-GW</item> <!-- Fulah (Latin, Guinea-Bissau) -->
-        <item>ff-Latn-LR</item> <!-- Fulah (Latin, Liberia) -->
-        <item>ff-Latn-MR</item> <!-- Fulah (Latin, Mauritania) -->
-        <item>ff-Latn-NE</item> <!-- Fulah (Latin, Niger) -->
-        <item>ff-Latn-NG</item> <!-- Fulah (Latin, Nigeria) -->
-        <item>ff-Latn-SL</item> <!-- Fulah (Latin, Sierra Leone) -->
-        <item>ff-Latn-SN</item> <!-- Fulah (Latin, Senegal) -->
+        <item>ff-Adlm-BF</item> <!-- Fula (Adlam, Burkina Faso) -->
+        <item>ff-Adlm-BF-u-nu-latn</item> <!-- Fula (Adlam, Burkina Faso, Western Digits) -->
+        <item>ff-Adlm-CM</item> <!-- Fula (Adlam, Cameroon) -->
+        <item>ff-Adlm-CM-u-nu-latn</item> <!-- Fula (Adlam, Cameroon, Western Digits) -->
+        <item>ff-Adlm-GH</item> <!-- Fula (Adlam, Ghana) -->
+        <item>ff-Adlm-GH-u-nu-latn</item> <!-- Fula (Adlam, Ghana, Western Digits) -->
+        <item>ff-Adlm-GM</item> <!-- Fula (Adlam, Gambia) -->
+        <item>ff-Adlm-GM-u-nu-latn</item> <!-- Fula (Adlam, Gambia, Western Digits) -->
+        <item>ff-Adlm-GN</item> <!-- Fula (Adlam, Guinea) -->
+        <item>ff-Adlm-GN-u-nu-latn</item> <!-- Fula (Adlam, Guinea, Western Digits) -->
+        <item>ff-Adlm-GW</item> <!-- Fula (Adlam, Guinea-Bissau) -->
+        <item>ff-Adlm-GW-u-nu-latn</item> <!-- Fula (Adlam, Guinea-Bissau, Western Digits) -->
+        <item>ff-Adlm-LR</item> <!-- Fula (Adlam, Liberia) -->
+        <item>ff-Adlm-LR-u-nu-latn</item> <!-- Fula (Adlam, Liberia, Western Digits) -->
+        <item>ff-Adlm-MR</item> <!-- Fula (Adlam, Mauritania) -->
+        <item>ff-Adlm-MR-u-nu-latn</item> <!-- Fula (Adlam, Mauritania, Western Digits) -->
+        <item>ff-Adlm-NE</item> <!-- Fula (Adlam, Niger) -->
+        <item>ff-Adlm-NE-u-nu-latn</item> <!-- Fula (Adlam, Niger, Western Digits) -->
+        <item>ff-Adlm-NG</item> <!-- Fula (Adlam, Nigeria) -->
+        <item>ff-Adlm-NG-u-nu-latn</item> <!-- Fula (Adlam, Nigeria, Western Digits) -->
+        <item>ff-Adlm-SL</item> <!-- Fula (Adlam, Sierra Leone) -->
+        <item>ff-Adlm-SL-u-nu-latn</item> <!-- Fula (Adlam, Sierra Leone, Western Digits) -->
+        <item>ff-Adlm-SN</item> <!-- Fula (Adlam, Senegal) -->
+        <item>ff-Adlm-SN-u-nu-latn</item> <!-- Fula (Adlam, Senegal, Western Digits) -->
+        <item>ff-Latn-BF</item> <!-- Fula (Latin, Burkina Faso) -->
+        <item>ff-Latn-CM</item> <!-- Fula (Latin, Cameroon) -->
+        <item>ff-Latn-GH</item> <!-- Fula (Latin, Ghana) -->
+        <item>ff-Latn-GM</item> <!-- Fula (Latin, Gambia) -->
+        <item>ff-Latn-GN</item> <!-- Fula (Latin, Guinea) -->
+        <item>ff-Latn-GW</item> <!-- Fula (Latin, Guinea-Bissau) -->
+        <item>ff-Latn-LR</item> <!-- Fula (Latin, Liberia) -->
+        <item>ff-Latn-MR</item> <!-- Fula (Latin, Mauritania) -->
+        <item>ff-Latn-NE</item> <!-- Fula (Latin, Niger) -->
+        <item>ff-Latn-NG</item> <!-- Fula (Latin, Nigeria) -->
+        <item>ff-Latn-SL</item> <!-- Fula (Latin, Sierra Leone) -->
+        <item>ff-Latn-SN</item> <!-- Fula (Latin, Senegal) -->
         <item>fi-FI</item> <!-- Finnish (Finland) -->
         <item>fil-PH</item> <!-- Filipino (Philippines) -->
         <item>fo-DK</item> <!-- Faroese (Denmark) -->
@@ -373,12 +374,13 @@
         <item>ha-NG</item> <!-- Hausa (Nigeria) -->
         <item>haw-US</item> <!-- Hawaiian (United States) -->
         <item>hi-IN</item> <!-- Hindi (India) -->
+        <item>hi-Latn-IN</item> <!-- Hindi (Latin, India) -->
         <item>hr-BA</item> <!-- Croatian (Bosnia & Herzegovina) -->
         <item>hr-HR</item> <!-- Croatian (Croatia) -->
         <item>hsb-DE</item> <!-- Upper Sorbian (Germany) -->
         <item>hu-HU</item> <!-- Hungarian (Hungary) -->
         <item>hy-AM</item> <!-- Armenian (Armenia) -->
-        <item>ia-001</item> <!-- Interlingua (World) -->
+        <item>ia-001</item> <!-- Interlingua (world) -->
         <item>ig-NG</item> <!-- Igbo (Nigeria) -->
         <item>ii-CN</item> <!-- Sichuan Yi (China) -->
         <item>in-ID</item> <!-- Indonesian (Indonesia) -->
@@ -397,6 +399,7 @@
         <item>kam-KE</item> <!-- Kamba (Kenya) -->
         <item>kde-TZ</item> <!-- Makonde (Tanzania) -->
         <item>kea-CV</item> <!-- Kabuverdianu (Cape Verde) -->
+        <item>kgp-BR</item> <!-- Kaingang (Brazil) -->
         <item>khq-ML</item> <!-- Koyra Chiini (Mali) -->
         <item>ki-KE</item> <!-- Kikuyu (Kenya) -->
         <item>kk-KZ</item> <!-- Kazakh (Kazakhstan) -->
@@ -408,6 +411,9 @@
         <item>ko-KP</item> <!-- Korean (North Korea) -->
         <item>ko-KR</item> <!-- Korean (South Korea) -->
         <item>kok-IN</item> <!-- Konkani (India) -->
+        <item>ks-Arab-IN</item> <!-- Kashmiri (Arabic, India) -->
+        <item>ks-Arab-IN-u-nu-latn</item> <!-- Kashmiri (Arabic, India, Western Digits) -->
+        <item>ks-Deva-IN</item> <!-- Kashmiri (Devanagari, India) -->
         <item>ksb-TZ</item> <!-- Shambala (Tanzania) -->
         <item>ksf-CM</item> <!-- Bafia (Cameroon) -->
         <item>ksh-DE</item> <!-- Colognian (Germany) -->
@@ -435,7 +441,7 @@
         <item>mg-MG</item> <!-- Malagasy (Madagascar) -->
         <item>mgh-MZ</item> <!-- Makhuwa-Meetto (Mozambique) -->
         <item>mgo-CM</item> <!-- Metaʼ (Cameroon) -->
-        <item>mi-NZ</item> <!-- Maori (New Zealand) -->
+        <item>mi-NZ</item> <!-- Māori (New Zealand) -->
         <item>mk-MK</item> <!-- Macedonian (North Macedonia) -->
         <item>ml-IN</item> <!-- Malayalam (India) -->
         <item>mn-MN</item> <!-- Mongolian (Mongolia) -->
@@ -500,6 +506,8 @@
         <item>qu-BO</item> <!-- Quechua (Bolivia) -->
         <item>qu-EC</item> <!-- Quechua (Ecuador) -->
         <item>qu-PE</item> <!-- Quechua (Peru) -->
+        <item>raj-IN</item> <!-- Rajasthani (India) -->
+        <item>raj-IN-u-nu-latn</item> <!-- Rajasthani (India, Western Digits) -->
         <item>rm-CH</item> <!-- Romansh (Switzerland) -->
         <item>rn-BI</item> <!-- Rundi (Burundi) -->
         <item>ro-MD</item> <!-- Romanian (Moldova) -->
@@ -514,11 +522,13 @@
         <item>rw-RW</item> <!-- Kinyarwanda (Rwanda) -->
         <item>rwk-TZ</item> <!-- Rwa (Tanzania) -->
         <item>sa-IN</item> <!-- Sanskrit (India) -->
-        <item>sah-RU</item> <!-- Sakha (Russia) -->
+        <item>sa-IN-u-nu-latn</item> <!-- Sanskrit (India, Western Digits) -->
+        <item>sah-RU</item> <!-- Yakut (Russia) -->
         <item>saq-KE</item> <!-- Samburu (Kenya) -->
         <item>sat-IN</item> <!-- Santali (India) -->
         <item>sat-IN-u-nu-latn</item> <!-- Santali (India, Western Digits) -->
         <item>sbp-TZ</item> <!-- Sangu (Tanzania) -->
+        <item>sc-IT</item> <!-- Sardinian (Italy) -->
         <item>sd-Arab-PK</item> <!-- Sindhi (Arabic, Pakistan) -->
         <item>sd-Arab-PK-u-nu-latn</item> <!-- Sindhi (Arabic, Pakistan, Western Digits) -->
         <item>sd-Deva-IN</item> <!-- Sindhi (Devanagari, India) -->
@@ -565,6 +575,8 @@
         <item>teo-UG</item> <!-- Teso (Uganda) -->
         <item>tg-TJ</item> <!-- Tajik (Tajikistan) -->
         <item>th-TH</item> <!-- Thai (Thailand) -->
+        <item>ti-ER</item> <!-- Tigrinya (Eritrea) -->
+        <item>ti-ET</item> <!-- Tigrinya (Ethiopia) -->
         <item>tk-TM</item> <!-- Turkmen (Turkmenistan) -->
         <item>to-TO</item> <!-- Tongan (Tonga) -->
         <item>tr-CY</item> <!-- Turkish (Cyprus) -->
@@ -586,10 +598,14 @@
         <item>vun-TZ</item> <!-- Vunjo (Tanzania) -->
         <item>wae-CH</item> <!-- Walser (Switzerland) -->
         <item>wo-SN</item> <!-- Wolof (Senegal) -->
+        <item>xh-ZA</item> <!-- Xhosa (South Africa) -->
         <item>xog-UG</item> <!-- Soga (Uganda) -->
         <item>yav-CM</item> <!-- Yangben (Cameroon) -->
         <item>yo-BJ</item> <!-- Yoruba (Benin) -->
         <item>yo-NG</item> <!-- Yoruba (Nigeria) -->
+        <item>yrl-BR</item> <!-- Nheengatu (Brazil) -->
+        <item>yrl-CO</item> <!-- Nheengatu (Colombia) -->
+        <item>yrl-VE</item> <!-- Nheengatu (Venezuela) -->
         <item>yue-Hans-CN</item> <!-- Cantonese (Simplified, China) -->
         <item>yue-Hant-HK</item> <!-- Cantonese (Traditional, Hong Kong) -->
         <item>zgh-MA</item> <!-- Standard Moroccan Tamazight (Morocco) -->
diff --git a/core/res/res/values/public-staging.xml b/core/res/res/values/public-staging.xml
index a9bec7a9..90141e5 100644
--- a/core/res/res/values/public-staging.xml
+++ b/core/res/res/values/public-staging.xml
@@ -117,7 +117,7 @@
     <public name="accessibilityDataPrivate" />
     <public name="enableTextStylingShortcuts" />
     <public name="requiredDisplayCategory"/>
-    <public name="maxConcurrentSessionsCount" />
+    <public name="removed_maxConcurrentSessionsCount" />
   </staging-public-group>
 
   <staging-public-group type="id" first-id="0x01cd0000">
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 39012ae..8106e24 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -139,9 +139,9 @@
     <!-- Displayed when a SIM PUK password is too short. -->
     <string name="invalidPuk">Type a PUK that is 8 numbers or longer.</string>
     <!-- Displayed to prompt the user to type the PUK password to unlock
-         the SIM card. -->
-    <string name="needPuk">Your SIM card is PUK-locked. Type the PUK code to unlock it.</string>
-    <string name="needPuk2">Type PUK2 to unblock SIM card.</string>
+         the SIM. -->
+    <string name="needPuk">Your SIM is PUK-locked. Type the PUK code to unlock it.</string>
+    <string name="needPuk2">Type PUK2 to unblock SIM.</string>
     <!-- Displayed when user attempts to change SIM PIN1 without enabling PIN1. -->
     <string name="enablePin">Unsuccessful, enable SIM/RUIM Lock.</string>
     <!-- Displayed when a SIM PIN/PUK is entered incorrectly. -->
@@ -1133,6 +1133,16 @@
     <string name="permdesc_useDataInBackground">This app can use data in the background. This may increase data usage.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permlab_schedule_exact_alarm">Schedule precisely timed actions</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_schedule_exact_alarm">This app can schedule work to happen at a desired time in the future. This also means that the app can run when you\u2019re not actively using the device.</string>
+
+    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permlab_use_exact_alarm">Schedule alarms or event reminders</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_use_exact_alarm">This app can schedule actions like alarms and reminders to notify you at a desired time in the future.</string>
+
+    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_persistentActivity">make app always run</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permdesc_persistentActivity" product="tablet">Allows the app to make parts of itself persistent in memory.  This can limit memory available to other apps slowing down the tablet.</string>
@@ -2519,23 +2529,23 @@
     <!-- Shown when face unlock failed multiple times so we're just using the backup -->
     <string name="faceunlock_multiple_failures">Maximum Face Unlock attempts exceeded</string>
 
-    <!-- Shown in the lock screen when there is no SIM card. -->
-    <string name="lockscreen_missing_sim_message_short">No SIM card</string>
-    <!-- Shown in the lock screen when there is no SIM card. -->
-    <string name="lockscreen_missing_sim_message" product="tablet">No SIM card in tablet.</string>
-    <!-- Shown in the lock screen when there is no SIM card. -->
-    <string name="lockscreen_missing_sim_message" product="tv">No SIM card in your Android TV device.</string>
-    <!-- Shown in the lock screen when there is no SIM card. -->
-    <string name="lockscreen_missing_sim_message" product="default">No SIM card in phone.</string>
-    <!-- Shown in the lock screen to ask the user to insert a SIM card. -->
-    <string name="lockscreen_missing_sim_instructions">Insert a SIM card.</string>
-    <!-- Shown in the lock screen to ask the user to insert a SIM card when sim is missing or not readable. -->
-    <string name="lockscreen_missing_sim_instructions_long">The SIM card is missing or not readable. Insert a SIM card.</string>
-    <!-- Shown in the lock screen when SIM card is permanently disabled. -->
-    <string name="lockscreen_permanent_disabled_sim_message_short">Unusable SIM card.</string>
-    <!-- Shown in the lock screen to inform the user to SIM card is permanently disabled. -->
-    <string name="lockscreen_permanent_disabled_sim_instructions">Your SIM card has been permanently disabled.\n
-    Contact your wireless service provider for another SIM card.</string>
+    <!-- Shown in the lock screen when there is no SIM. -->
+    <string name="lockscreen_missing_sim_message_short">No SIM</string>
+    <!-- Shown in the lock screen when there is no SIM. -->
+    <string name="lockscreen_missing_sim_message" product="tablet">No SIM in tablet.</string>
+    <!-- Shown in the lock screen when there is no SIM. -->
+    <string name="lockscreen_missing_sim_message" product="tv">No SIM in your Android TV device.</string>
+    <!-- Shown in the lock screen when there is no SIM. -->
+    <string name="lockscreen_missing_sim_message" product="default">No SIM in phone.</string>
+    <!-- Shown in the lock screen to ask the user to add a SIM. -->
+    <string name="lockscreen_missing_sim_instructions">Add a SIM.</string>
+    <!-- Shown in the lock screen to ask the user to add a SIM when sim is missing or not readable. -->
+    <string name="lockscreen_missing_sim_instructions_long">The SIM is missing or not readable. Add a SIM.</string>
+    <!-- Shown in the lock screen when SIM is permanently disabled. -->
+    <string name="lockscreen_permanent_disabled_sim_message_short">Unusable SIM.</string>
+    <!-- Shown in the lock screen to inform the user to SIM is permanently deactivated. -->
+    <string name="lockscreen_permanent_disabled_sim_instructions">Your SIM has been permanently deactivated.\n
+    Contact your wireless service provider for another SIM.</string>
 
     <!-- Shown on transport control of lockscreen. Pressing button goes to previous track. -->
     <string name="lockscreen_transport_prev_description">Previous track</string>
@@ -2562,17 +2572,17 @@
 
     <!-- When the user enters a wrong sim pin too many times, it becomes
          PUK locked (Pin Unlock Kode) -->
-    <string name="lockscreen_sim_puk_locked_message">SIM card is PUK-locked.</string>
+    <string name="lockscreen_sim_puk_locked_message">SIM is PUK-locked.</string>
     <!-- Shown in the lock screen when the SIM has become PUK locked and the user must call customer care to unlock it. -->
     <string name="lockscreen_sim_puk_locked_instructions">See the User Guide or contact Customer Care.</string>
 
     <!-- Shown in the lock screen to tell the user that their SIM is locked and they must unlock it. -->
-    <string name="lockscreen_sim_locked_message">SIM card is locked.</string>
+    <string name="lockscreen_sim_locked_message">SIM is locked.</string>
 
     <!-- For the unlock screen, When the user enters a sim unlock code, it takes a little while to check
          whether it is valid, and to unlock the sim if it is valid.  we display a
          progress dialog in the meantime.  this is the emssage. -->
-    <string name="lockscreen_sim_unlock_progress_dialog_message">Unlocking SIM card\u2026</string>
+    <string name="lockscreen_sim_unlock_progress_dialog_message">Unlocking SIM\u2026</string>
 
     <!-- For the unlock screen, Information message shown in dialog when user has too many failed attempts at
          drawing the unlock pattern -->
@@ -3873,13 +3883,13 @@
 
     <!-- SIM swap and device reboot Dialog --> <skip />
     <!-- See SIM_REMOVED_DIALOG.  This is the title of that dialog. -->
-    <string name="sim_removed_title">SIM card removed</string>
+    <string name="sim_removed_title">SIM removed</string>
     <!-- See SIM_REMOVED_DIALOG.  This is the message of that dialog. -->
-    <string name="sim_removed_message">The mobile network will be unavailable until you restart with a valid SIM card inserted.</string>
+    <string name="sim_removed_message">The mobile network will be unavailable until you restart with a valid SIM.</string>
     <!-- See SIM_REMOVED_DIALOG.  This is the button of that dialog. -->
     <string name="sim_done_button">Done</string>
     <!-- See SIM_ADDED_DIALOG.  This is the title of that dialog. -->
-    <string name="sim_added_title">SIM card added</string>
+    <string name="sim_added_title">SIM added</string>
     <!-- See SIM_ADDED_DIALOG.  This is the message of that dialog. -->
     <string name="sim_added_message">Restart your device to access the mobile network.</string>
     <!-- See SIM_ADDED_DIALOG.  This is the button of that dialog. -->
@@ -4703,8 +4713,8 @@
     <string name="kg_puk_enter_pin_hint">Enter desired PIN code</string>
     <!-- Message shown when the user needs to confirm the PIN they just entered in the PUK screen -->
     <string name="kg_enter_confirm_pin_hint">Confirm desired PIN code</string>
-    <!-- Message shown in dialog while the device is unlocking the SIM card -->
-    <string name="kg_sim_unlock_progress_dialog_message">Unlocking SIM card\u2026</string>
+    <!-- Message shown in dialog while the device is unlocking the SIM -->
+    <string name="kg_sim_unlock_progress_dialog_message">Unlocking SIM\u2026</string>
     <!-- Message shown when the user enters the wrong PIN code -->
     <string name="kg_password_wrong_pin_code">Incorrect PIN code.</string>
     <!-- Message shown when the user enters an invalid SIM pin password in PUK screen -->
@@ -4927,7 +4937,7 @@
 
     <!-- Title of Color Correction feature, which is mostly used to help users who are colorblind,
      shown in the warning dialog about the accessibility shortcut. -->
-    <string name="color_correction_feature_name">Color Correction</string>
+    <string name="color_correction_feature_name">Color correction</string>
 
     <!-- Title of One Handed Mode feature, shown in the system gestures of the accessibility shortcut. [CHAR LIMIT=none] -->
     <string name="one_handed_mode_feature_name">One-Handed mode</string>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index ace7e4c..151530b 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -2062,12 +2062,6 @@
   <java-symbol type="integer" name="config_screenBrightnessSettingMinimum" />
   <java-symbol type="integer" name="config_screenBrightnessSettingMaximum" />
   <java-symbol type="integer" name="config_screenBrightnessSettingDefault" />
-  <java-symbol type="integer" name="config_screenBrightnessForVrSettingDefault" />
-  <java-symbol type="integer" name="config_screenBrightnessForVrSettingMaximum" />
-  <java-symbol type="integer" name="config_screenBrightnessForVrSettingMinimum" />
-  <java-symbol type="dimen" name="config_screenBrightnessSettingForVrMinimumFloat" />
-  <java-symbol type="dimen" name="config_screenBrightnessSettingForVrMaximumFloat" />
-  <java-symbol type="dimen" name="config_screenBrightnessSettingForVrDefaultFloat" />
   <java-symbol type="dimen" name="config_screenBrightnessSettingMinimumFloat" />
   <java-symbol type="dimen" name="config_screenBrightnessSettingMaximumFloat" />
   <java-symbol type="dimen" name="config_screenBrightnessSettingDefaultFloat" />
@@ -2816,6 +2810,7 @@
   <java-symbol type="bool" name="config_switch_phone_on_voice_reg_state_change" />
   <java-symbol type="string" name="whichHomeApplicationNamed" />
   <java-symbol type="string" name="whichHomeApplicationLabel" />
+  <java-symbol type="bool" name="config_smma_notification_supported_over_ims" />
   <java-symbol type="bool" name="config_sms_force_7bit_encoding" />
   <java-symbol type="bool" name="config_defaultWindowFeatureOptionsPanel" />
   <java-symbol type="bool" name="config_defaultWindowFeatureContextMenu" />
@@ -3826,6 +3821,7 @@
   <java-symbol type="string" name="config_cameraShutterSound" />
   <java-symbol type="integer" name="config_autoGroupAtCount" />
   <java-symbol type="bool" name="config_dozeAlwaysOnDisplayAvailable" />
+  <java-symbol type="bool" name="config_dozePickupGestureEnabled" />
   <java-symbol type="bool" name="config_dozeAlwaysOnEnabled" />
   <java-symbol type="bool" name="config_dozeSupportsAodWallpaper" />
   <java-symbol type="bool" name="config_displayBlanksAfterDoze" />
@@ -4401,6 +4397,9 @@
   <!-- Set to true to make assistant show in front of the dream/screensaver. -->
   <java-symbol type="bool" name="config_assistantOnTopOfDream"/>
 
+  <!-- Set to true to enable letterboxing on translucent activities. -->
+  <java-symbol type="bool" name="config_letterboxIsEnabledForTranslucentActivities" />
+
   <java-symbol type="string" name="config_overrideComponentUiPackage" />
 
   <java-symbol type="string" name="notification_channel_network_status" />
diff --git a/core/res/res/xml/bookmarks.xml b/core/res/res/xml/bookmarks.xml
index 454f456..3087aaa 100644
--- a/core/res/res/xml/bookmarks.xml
+++ b/core/res/res/xml/bookmarks.xml
@@ -19,23 +19,20 @@
      Bookmarks for vendor apps should be added to a bookmarks resource overlay; not here.
 
      Typical shortcuts (not necessarily defined here):
-       'a': Calculator
        'b': Browser
        'c': Contacts
        'e': Email
        'g': GMail
-       'l': Calendar
+       'k': Calendar
        'm': Maps
        'p': Music
        's': SMS
        't': Talk
+       'u': Calculator
        'y': YouTube
 -->
 <bookmarks>
     <bookmark
-        category="android.intent.category.APP_CALCULATOR"
-        shortcut="a" />
-    <bookmark
         category="android.intent.category.APP_BROWSER"
         shortcut="b" />
     <bookmark
@@ -46,7 +43,7 @@
         shortcut="e" />
     <bookmark
         category="android.intent.category.APP_CALENDAR"
-        shortcut="l" />
+        shortcut="k" />
     <bookmark
         category="android.intent.category.APP_MAPS"
         shortcut="m" />
@@ -56,4 +53,7 @@
     <bookmark
         category="android.intent.category.APP_MESSAGING"
         shortcut="s" />
+    <bookmark
+        category="android.intent.category.APP_CALCULATOR"
+        shortcut="u" />
 </bookmarks>
diff --git a/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/functional/RadioTunerTest.java b/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/functional/RadioTunerTest.java
index 3f35e99..cabeb13 100644
--- a/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/functional/RadioTunerTest.java
+++ b/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/functional/RadioTunerTest.java
@@ -17,6 +17,7 @@
 
 import static org.junit.Assert.*;
 import static org.junit.Assume.*;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyBoolean;
 import static org.mockito.Matchers.anyInt;
@@ -335,8 +336,10 @@
         assertEquals(RadioManager.STATUS_OK, scanRet);
         assertEquals(RadioManager.STATUS_OK, cancelRet);
 
-        verify(mCallback, after(kCancelTimeoutMs).atMost(1)).onError(RadioTuner.ERROR_CANCELLED);
+        verify(mCallback, after(kCancelTimeoutMs).atMost(1))
+                .onTuneFailed(eq(RadioTuner.TUNER_RESULT_CANCELED), any());
         verify(mCallback, atMost(1)).onProgramInfoChanged(any());
+        Mockito.reset(mCallback);
     }
 
     @Test
diff --git a/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/DefaultRadioTunerTest.java b/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/DefaultRadioTunerTest.java
index 2fa3f876..65e55a2 100644
--- a/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/DefaultRadioTunerTest.java
+++ b/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/DefaultRadioTunerTest.java
@@ -130,6 +130,18 @@
     };
 
     @Test
+    public void seek_forRadioTuner_throwsException() {
+        UnsupportedOperationException thrown = assertThrows(
+                UnsupportedOperationException.class, () -> {
+                    DEFAULT_RADIO_TUNER.seek(RadioTuner.DIRECTION_DOWN,
+                            /* skipSubChannel= */ false);
+                });
+
+        assertWithMessage("Exception for seeking on default radio tuner")
+                .that(thrown).hasMessageThat().contains("Seeking is not supported");
+    }
+
+    @Test
     public void getDynamicProgramList_forRadioTuner_returnsNull() {
         assertWithMessage("Dynamic program list obtained from default radio tuner")
                 .that(DEFAULT_RADIO_TUNER.getDynamicProgramList(new ProgramList.Filter())).isNull();
@@ -143,29 +155,45 @@
 
     @Test
     public void isConfigFlagSet_forRadioTuner_throwsException() {
-        assertThrows(UnsupportedOperationException.class, () -> {
-            DEFAULT_RADIO_TUNER.isConfigFlagSet(/* flag= */ 1);
-        });
+        UnsupportedOperationException thrown = assertThrows(
+                UnsupportedOperationException.class, () -> {
+                    DEFAULT_RADIO_TUNER.isConfigFlagSet(/* flag= */ 1);
+                });
+
+        assertWithMessage("Exception for isConfigFlagSet on default radio tuner")
+                .that(thrown).hasMessageThat().contains("isConfigFlagSet is not supported");
     }
 
     @Test
     public void setConfigFlag_forRadioTuner_throwsException() {
-        assertThrows(UnsupportedOperationException.class, () -> {
+        UnsupportedOperationException thrown = assertThrows(UnsupportedOperationException.class,
+                () -> {
             DEFAULT_RADIO_TUNER.setConfigFlag(/* flag= */ 1, /* value= */ false);
         });
+
+        assertWithMessage("Exception for setting config flag on default radio tuner")
+                .that(thrown).hasMessageThat().contains("Setting config flag is not supported");
     }
 
     @Test
     public void setParameters_forRadioTuner_throwsException() {
-        assertThrows(UnsupportedOperationException.class, () -> {
+        UnsupportedOperationException thrown = assertThrows(UnsupportedOperationException.class,
+                () -> {
             DEFAULT_RADIO_TUNER.setParameters(Map.of("testKey", "testValue"));
         });
+
+        assertWithMessage("Exception for setting parameters from default radio tuner")
+                .that(thrown).hasMessageThat().contains("Setting parameters is not supported");
     }
 
     @Test
     public void getParameters_forRadioTuner_throwsException() {
-        assertThrows(UnsupportedOperationException.class, () -> {
+        UnsupportedOperationException thrown = assertThrows(UnsupportedOperationException.class,
+                () -> {
             DEFAULT_RADIO_TUNER.getParameters(List.of("testKey"));
         });
+
+        assertWithMessage("Exception for getting parameters from default radio tuner")
+                .that(thrown).hasMessageThat().contains("Getting parameters is not supported");
     }
 }
diff --git a/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/ProgramListTest.java b/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/ProgramListTest.java
index 2b9de18..87f91fa 100644
--- a/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/ProgramListTest.java
+++ b/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/ProgramListTest.java
@@ -41,6 +41,8 @@
 import android.os.RemoteException;
 import android.util.ArraySet;
 
+import androidx.test.InstrumentationRegistry;
+
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
@@ -54,6 +56,8 @@
 @RunWith(MockitoJUnitRunner.class)
 public final class ProgramListTest {
 
+    public final Context mContext = InstrumentationRegistry.getContext();
+
     private static final int CREATOR_ARRAY_SIZE = 3;
     private static final VerificationWithTimeout CALLBACK_TIMEOUT = timeout(/* millis= */ 500);
 
@@ -109,8 +113,6 @@
     @Mock
     private IRadioService mRadioServiceMock;
     @Mock
-    private Context mContextMock;
-    @Mock
     private ITuner mTunerMock;
     @Mock
     private RadioTuner.Callback mTunerCallbackMock;
@@ -477,7 +479,7 @@
     }
 
     private void createRadioTuner() throws Exception {
-        RadioManager radioManager = new RadioManager(mContextMock, mRadioServiceMock);
+        RadioManager radioManager = new RadioManager(mContext, mRadioServiceMock);
         RadioManager.BandConfig band = new RadioManager.FmBandConfig(
                 new RadioManager.FmBandDescriptor(RadioManager.REGION_ITU_1, RadioManager.BAND_FM,
                         /* lowerLimit= */ 87500, /* upperLimit= */ 108000, /* spacing= */ 200,
@@ -487,7 +489,7 @@
         doAnswer(invocation -> {
             mTunerCallback = (ITunerCallback) invocation.getArguments()[3];
             return mTunerMock;
-        }).when(mRadioServiceMock).openTuner(anyInt(), any(), anyBoolean(), any());
+        }).when(mRadioServiceMock).openTuner(anyInt(), any(), anyBoolean(), any(), anyInt());
 
         mRadioTuner = radioManager.openTuner(/* moduleId= */ 0, band,
                 /* withAudio= */ true, mTunerCallbackMock, /* handler= */ null);
diff --git a/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/RadioManagerTest.java b/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/RadioManagerTest.java
index 44aa6d1..03742eb 100644
--- a/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/RadioManagerTest.java
+++ b/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/RadioManagerTest.java
@@ -18,14 +18,16 @@
 
 import static com.google.common.truth.Truth.assertWithMessage;
 
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import android.annotation.Nullable;
 import android.content.Context;
+import android.content.pm.ApplicationInfo;
 import android.hardware.radio.Announcement;
 import android.hardware.radio.IAnnouncementListener;
 import android.hardware.radio.ICloseHandle;
@@ -34,6 +36,7 @@
 import android.hardware.radio.RadioManager;
 import android.hardware.radio.RadioMetadata;
 import android.hardware.radio.RadioTuner;
+import android.os.Build;
 import android.os.Parcel;
 import android.os.RemoteException;
 import android.util.ArrayMap;
@@ -53,6 +56,8 @@
 @RunWith(MockitoJUnitRunner.class)
 public final class RadioManagerTest {
 
+    private static final int TEST_TARGET_SDK_VERSION = Build.VERSION_CODES.CUR_DEVELOPMENT;
+
     private static final int REGION = RadioManager.REGION_ITU_2;
     private static final int FM_LOWER_LIMIT = 87500;
     private static final int FM_UPPER_LIMIT = 108000;
@@ -126,6 +131,7 @@
                     /* vendorInfo= */ new ArrayMap<>()));
 
     private RadioManager mRadioManager;
+    private final ApplicationInfo mApplicationInfo = new ApplicationInfo();
 
     @Mock
     private IRadioService mRadioServiceMock;
@@ -1008,7 +1014,8 @@
         mRadioManager.openTuner(moduleId, FM_BAND_CONFIG, withAudio, mCallbackMock,
                 /* handler= */ null);
 
-        verify(mRadioServiceMock).openTuner(eq(moduleId), eq(FM_BAND_CONFIG), eq(withAudio), any());
+        verify(mRadioServiceMock).openTuner(eq(moduleId), eq(FM_BAND_CONFIG), eq(withAudio), any(),
+                anyInt());
     }
 
     @Test
@@ -1103,6 +1110,8 @@
     }
 
     private void createRadioManager() throws RemoteException {
+        mApplicationInfo.targetSdkVersion = TEST_TARGET_SDK_VERSION;
+        when(mContextMock.getApplicationInfo()).thenReturn(mApplicationInfo);
         when(mRadioServiceMock.listModules()).thenReturn(Arrays.asList(AMFM_PROPERTIES));
         when(mRadioServiceMock.addAnnouncementListener(any(), any())).thenReturn(mCloseHandleMock);
 
diff --git a/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/TunerAdapterTest.java b/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/TunerAdapterTest.java
index bdba6a1..d851a7724 100644
--- a/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/TunerAdapterTest.java
+++ b/core/tests/BroadcastRadioTests/src/android/hardware/radio/tests/unittests/TunerAdapterTest.java
@@ -27,6 +27,7 @@
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
+import android.content.pm.ApplicationInfo;
 import android.graphics.Bitmap;
 import android.hardware.radio.IRadioService;
 import android.hardware.radio.ITuner;
@@ -35,6 +36,7 @@
 import android.hardware.radio.RadioManager;
 import android.hardware.radio.RadioMetadata;
 import android.hardware.radio.RadioTuner;
+import android.os.Build;
 
 import org.junit.After;
 import org.junit.Before;
@@ -51,11 +53,12 @@
 @RunWith(MockitoJUnitRunner.class)
 public final class TunerAdapterTest {
 
+    private static final int TEST_TARGET_SDK_VERSION = Build.VERSION_CODES.CUR_DEVELOPMENT;
+
     private static final int CALLBACK_TIMEOUT_MS = 30_000;
     private static final int AM_LOWER_LIMIT_KHZ = 150;
 
     private static final RadioManager.BandConfig TEST_BAND_CONFIG = createBandConfig();
-
     private static final ProgramSelector.Identifier FM_IDENTIFIER =
             new ProgramSelector.Identifier(ProgramSelector.IDENTIFIER_TYPE_AMFM_FREQUENCY,
                     /* value= */ 94300);
@@ -66,6 +69,7 @@
 
     private RadioTuner mRadioTuner;
     private ITunerCallback mTunerCallback;
+    private final ApplicationInfo mApplicationInfo = new ApplicationInfo();
 
     @Mock
     private IRadioService mRadioServiceMock;
@@ -78,12 +82,14 @@
 
     @Before
     public void setUp() throws Exception {
+        mApplicationInfo.targetSdkVersion = TEST_TARGET_SDK_VERSION;
+        when(mContextMock.getApplicationInfo()).thenReturn(mApplicationInfo);
         RadioManager radioManager = new RadioManager(mContextMock, mRadioServiceMock);
 
         doAnswer(invocation -> {
             mTunerCallback = (ITunerCallback) invocation.getArguments()[3];
             return mTunerMock;
-        }).when(mRadioServiceMock).openTuner(anyInt(), any(), anyBoolean(), any());
+        }).when(mRadioServiceMock).openTuner(anyInt(), any(), anyBoolean(), any(), anyInt());
 
         doAnswer(invocation -> {
             ProgramSelector program = (ProgramSelector) invocation.getArguments()[0];
@@ -92,7 +98,7 @@
                 throw new IllegalArgumentException();
             }
             if (program.getPrimaryId().getValue() < AM_LOWER_LIMIT_KHZ) {
-                mTunerCallback.onTuneFailed(RadioManager.STATUS_BAD_VALUE, program);
+                mTunerCallback.onTuneFailed(RadioTuner.TUNER_RESULT_INVALID_ARGUMENTS, program);
             } else {
                 mTunerCallback.onCurrentProgramInfoChanged(FM_PROGRAM_INFO);
             }
@@ -170,15 +176,30 @@
     }
 
     @Test
+    public void scan_forTunerAdapter_succeeds() throws Exception {
+        doAnswer(invocation -> {
+            mTunerCallback.onCurrentProgramInfoChanged(FM_PROGRAM_INFO);
+            return RadioManager.STATUS_OK;
+        }).when(mTunerMock).seek(anyBoolean(), anyBoolean());
+
+        int scanStatus = mRadioTuner.scan(RadioTuner.DIRECTION_DOWN, /* skipSubChannel= */ false);
+
+        verify(mTunerMock).seek(/* directionDown= */ true, /* skipSubChannel= */ false);
+        assertWithMessage("Status for scaning")
+                .that(scanStatus).isEqualTo(RadioManager.STATUS_OK);
+        verify(mCallbackMock, timeout(CALLBACK_TIMEOUT_MS)).onProgramInfoChanged(FM_PROGRAM_INFO);
+    }
+
+    @Test
     public void seek_forTunerAdapter_succeeds() throws Exception {
         doAnswer(invocation -> {
             mTunerCallback.onCurrentProgramInfoChanged(FM_PROGRAM_INFO);
             return RadioManager.STATUS_OK;
-        }).when(mTunerMock).scan(anyBoolean(), anyBoolean());
+        }).when(mTunerMock).seek(anyBoolean(), anyBoolean());
 
         int scanStatus = mRadioTuner.scan(RadioTuner.DIRECTION_DOWN, /* skipSubChannel= */ false);
 
-        verify(mTunerMock).scan(/* directionDown= */ true, /* skipSubChannel= */ false);
+        verify(mTunerMock).seek(/* directionDown= */ true, /* skipSubChannel= */ false);
         assertWithMessage("Status for seeking")
                 .that(scanStatus).isEqualTo(RadioManager.STATUS_OK);
         verify(mCallbackMock, timeout(CALLBACK_TIMEOUT_MS)).onProgramInfoChanged(FM_PROGRAM_INFO);
@@ -187,13 +208,14 @@
     @Test
     public void seek_forTunerAdapter_invokesOnErrorWhenTimeout() throws Exception {
         doAnswer(invocation -> {
-            mTunerCallback.onError(RadioTuner.ERROR_SCAN_TIMEOUT);
+            mTunerCallback.onTuneFailed(RadioTuner.TUNER_RESULT_TIMEOUT, FM_SELECTOR);
             return RadioManager.STATUS_OK;
-        }).when(mTunerMock).scan(anyBoolean(), anyBoolean());
+        }).when(mTunerMock).seek(anyBoolean(), anyBoolean());
 
         mRadioTuner.scan(RadioTuner.DIRECTION_UP, /* skipSubChannel*/ true);
 
-        verify(mCallbackMock, timeout(CALLBACK_TIMEOUT_MS)).onError(RadioTuner.ERROR_SCAN_TIMEOUT);
+        verify(mCallbackMock, timeout(CALLBACK_TIMEOUT_MS)).onTuneFailed(
+                RadioTuner.TUNER_RESULT_TIMEOUT, FM_SELECTOR);
     }
 
     @Test
@@ -224,7 +246,7 @@
         mRadioTuner.tune(invalidSelector);
 
         verify(mCallbackMock, timeout(CALLBACK_TIMEOUT_MS))
-                .onTuneFailed(RadioManager.STATUS_BAD_VALUE, invalidSelector);
+                .onTuneFailed(RadioTuner.TUNER_RESULT_INVALID_ARGUMENTS, invalidSelector);
     }
 
     @Test
@@ -415,6 +437,17 @@
     }
 
     @Test
+    public void onConfigFlagUpdated_forTunerCallbackAdapter() throws Exception {
+        int configFlag = RadioManager.CONFIG_RDS_AF;
+        boolean configFlagValue = true;
+
+        mTunerCallback.onConfigFlagUpdated(configFlag, configFlagValue);
+
+        verify(mCallbackMock, timeout(CALLBACK_TIMEOUT_MS))
+                .onConfigFlagUpdated(configFlag, configFlagValue);
+    }
+
+    @Test
     public void onParametersUpdated_forTunerCallbackAdapter() throws Exception {
         Map<String, String> parametersExpected = Map.of("ParameterKeyMock", "ParameterValueMock");
 
diff --git a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/IRadioServiceAidlImplTest.java b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/IRadioServiceAidlImplTest.java
index a2df426..9803474 100644
--- a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/IRadioServiceAidlImplTest.java
+++ b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/IRadioServiceAidlImplTest.java
@@ -23,6 +23,7 @@
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyBoolean;
 import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -33,6 +34,7 @@
 import android.hardware.radio.ITuner;
 import android.hardware.radio.ITunerCallback;
 import android.hardware.radio.RadioManager;
+import android.os.Build;
 import android.os.IBinder;
 import android.os.ServiceManager;
 
@@ -55,6 +57,7 @@
             "android.hardware.broadcastradio.IBroadcastRadio/amfm";
     private static final String DAB_SERVICE_NAME =
             "android.hardware.broadcastradio.IBroadcastRadio/dab";
+    private static final int TARGET_SDK_VERSION = Build.VERSION_CODES.CUR_DEVELOPMENT;
 
     private IRadioServiceAidlImpl mAidlImpl;
 
@@ -82,7 +85,7 @@
         doNothing().when(mServiceMock).enforcePolicyAccess();
 
         when(mHalMock.listModules()).thenReturn(List.of(mModuleMock));
-        when(mHalMock.openSession(anyInt(), any(), anyBoolean(), any()))
+        when(mHalMock.openSession(anyInt(), any(), anyBoolean(), any(), eq(TARGET_SDK_VERSION)))
                 .thenReturn(mTunerMock);
         when(mHalMock.addAnnouncementListener(any(), any())).thenReturn(mICloseHandle);
 
@@ -114,7 +117,7 @@
     @Test
     public void openTuner_forAidlImpl() throws Exception {
         ITuner tuner = mAidlImpl.openTuner(/* moduleId= */ 0, mBandConfigMock,
-                /* withAudio= */ true, mTunerCallbackMock);
+                /* withAudio= */ true, mTunerCallbackMock, TARGET_SDK_VERSION);
 
         assertWithMessage("Tuner opened in AIDL HAL")
                 .that(tuner).isEqualTo(mTunerMock);
diff --git a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/IRadioServiceHidlImplTest.java b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/IRadioServiceHidlImplTest.java
index 5ab9435..cfff477 100644
--- a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/IRadioServiceHidlImplTest.java
+++ b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/IRadioServiceHidlImplTest.java
@@ -32,6 +32,7 @@
 import android.hardware.radio.ITuner;
 import android.hardware.radio.ITunerCallback;
 import android.hardware.radio.RadioManager;
+import android.os.Build;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -49,6 +50,7 @@
 
     private static final int HAL1_MODULE_ID = 0;
     private static final int[] ENABLE_TYPES = new int[]{Announcement.TYPE_TRAFFIC};
+    private static final int TARGET_SDK_VERSION = Build.VERSION_CODES.CUR_DEVELOPMENT;
 
     private IRadioServiceHidlImpl mHidlImpl;
 
@@ -103,7 +105,7 @@
     @Test
     public void openTuner_withHal1ModuleId_forHidlImpl() throws Exception {
         ITuner tuner = mHidlImpl.openTuner(HAL1_MODULE_ID, mBandConfigMock,
-                /* withAudio= */ true, mTunerCallbackMock);
+                /* withAudio= */ true, mTunerCallbackMock, TARGET_SDK_VERSION);
 
         assertWithMessage("Tuner opened in HAL 1")
                 .that(tuner).isEqualTo(mHal1TunerMock);
@@ -112,7 +114,7 @@
     @Test
     public void openTuner_withHal2ModuleId_forHidlImpl() throws Exception {
         ITuner tuner = mHidlImpl.openTuner(HAL1_MODULE_ID + 1, mBandConfigMock,
-                /* withAudio= */ true, mTunerCallbackMock);
+                /* withAudio= */ true, mTunerCallbackMock, TARGET_SDK_VERSION);
 
         assertWithMessage("Tuner opened in HAL 2")
                 .that(tuner).isEqualTo(mHal2TunerMock);
diff --git a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/BroadcastRadioServiceImplTest.java b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/BroadcastRadioServiceImplTest.java
index 1cc0a985..f404082 100644
--- a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/BroadcastRadioServiceImplTest.java
+++ b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/BroadcastRadioServiceImplTest.java
@@ -36,6 +36,7 @@
 import android.hardware.radio.ITunerCallback;
 import android.hardware.radio.RadioManager;
 import android.hardware.radio.RadioTuner;
+import android.os.Build;
 import android.os.IBinder;
 import android.os.IServiceCallback;
 import android.os.RemoteException;
@@ -54,6 +55,8 @@
 
 public final class BroadcastRadioServiceImplTest extends ExtendedRadioMockitoTestCase {
 
+    private static final int TARGET_SDK_VERSION = Build.VERSION_CODES.CUR_DEVELOPMENT;
+
     private static final int FM_RADIO_MODULE_ID = 0;
     private static final int DAB_RADIO_MODULE_ID = 1;
     private static final ArrayList<String> SERVICE_LIST =
@@ -137,7 +140,8 @@
         createBroadcastRadioService();
 
         ITuner session = mBroadcastRadioService.openSession(FM_RADIO_MODULE_ID,
-                /* legacyConfig= */ null, /* withAudio= */ true, mTunerCallbackMock);
+                /* legacyConfig= */ null, /* withAudio= */ true, mTunerCallbackMock,
+                TARGET_SDK_VERSION);
 
         assertWithMessage("Session opened in FM radio module")
                 .that(session).isEqualTo(mFmTunerSessionMock);
@@ -148,7 +152,8 @@
         createBroadcastRadioService();
 
         ITuner session = mBroadcastRadioService.openSession(DAB_RADIO_MODULE_ID + 1,
-                /* legacyConfig= */ null, /* withAudio= */ true, mTunerCallbackMock);
+                /* legacyConfig= */ null, /* withAudio= */ true, mTunerCallbackMock,
+                TARGET_SDK_VERSION);
 
         assertWithMessage("Session opened with id not found").that(session).isNull();
     }
@@ -160,7 +165,8 @@
 
         IllegalStateException thrown = assertThrows(IllegalStateException.class,
                 () -> mBroadcastRadioService.openSession(FM_RADIO_MODULE_ID,
-                        /* legacyConfig= */ null, /* withAudio= */ true, mTunerCallbackMock));
+                        /* legacyConfig= */ null, /* withAudio= */ true, mTunerCallbackMock,
+                        TARGET_SDK_VERSION));
 
         assertWithMessage("Exception for opening session by non-current user")
                 .that(thrown).hasMessageThat().contains("Cannot open session for non-current user");
@@ -228,7 +234,7 @@
             return null;
         }).when(mFmBinderMock).linkToDeath(any(), anyInt());
 
-        when(mFmRadioModuleMock.openSession(eq(mTunerCallbackMock)))
+        when(mFmRadioModuleMock.openSession(eq(mTunerCallbackMock), eq(TARGET_SDK_VERSION)))
                 .thenReturn(mFmTunerSessionMock);
     }
 }
diff --git a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/ConversionUtilsResultTest.java b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/ConversionUtilsResultTest.java
new file mode 100644
index 0000000..df3ddfd
--- /dev/null
+++ b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/ConversionUtilsResultTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.server.broadcastradio.aidl;
+
+import android.hardware.broadcastradio.Result;
+import android.hardware.radio.RadioTuner;
+
+import com.google.common.truth.Expect;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+import java.util.List;
+
+@RunWith(Parameterized.class)
+public final class ConversionUtilsResultTest {
+
+    private final int mHalResult;
+    private final int mTunerResult;
+
+    @Rule
+    public final Expect expect = Expect.create();
+
+    public ConversionUtilsResultTest(int halResult, int tunerResult) {
+        this.mHalResult = halResult;
+        this.mTunerResult = tunerResult;
+    }
+
+    @Parameterized.Parameters
+    public static List<Object[]> inputParameters() {
+        return Arrays.asList(new Object[][]{
+                {Result.OK, RadioTuner.TUNER_RESULT_OK},
+                {Result.INTERNAL_ERROR, RadioTuner.TUNER_RESULT_INTERNAL_ERROR},
+                {Result.INVALID_ARGUMENTS, RadioTuner.TUNER_RESULT_INVALID_ARGUMENTS},
+                {Result.INVALID_STATE, RadioTuner.TUNER_RESULT_INVALID_STATE},
+                {Result.NOT_SUPPORTED, RadioTuner.TUNER_RESULT_NOT_SUPPORTED},
+                {Result.TIMEOUT, RadioTuner.TUNER_RESULT_TIMEOUT},
+                {Result.UNKNOWN_ERROR, RadioTuner.TUNER_RESULT_UNKNOWN_ERROR}
+        });
+    }
+
+    @Test
+    public void halResultToTunerResult() {
+        expect.withMessage("Tuner result converted from AIDL HAL result %s", mHalResult)
+                .that(ConversionUtils.halResultToTunerResult(mHalResult))
+                .isEqualTo(mTunerResult);
+    }
+}
diff --git a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/ConversionUtilsTest.java b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/ConversionUtilsTest.java
index 3119554..a1cebb6 100644
--- a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/ConversionUtilsTest.java
+++ b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/ConversionUtilsTest.java
@@ -25,6 +25,7 @@
 import android.hardware.radio.Announcement;
 import android.hardware.radio.ProgramSelector;
 import android.hardware.radio.RadioManager;
+import android.os.Build;
 
 import com.google.common.truth.Expect;
 
@@ -69,6 +70,18 @@
     public final Expect expect = Expect.create();
 
     @Test
+    public void isAtLeastU_withTSdkVersion_returnsFalse() {
+        expect.withMessage("Target SDK version of T")
+                .that(ConversionUtils.isAtLeastU(Build.VERSION_CODES.TIRAMISU)).isFalse();
+    }
+
+    @Test
+    public void isAtLeastU_withCurrentSdkVersion_returnsTrue() {
+        expect.withMessage("Target SDK version of U")
+                .that(ConversionUtils.isAtLeastU(Build.VERSION_CODES.CUR_DEVELOPMENT)).isTrue();
+    }
+
+    @Test
     public void propertiesFromHalProperties_idsMatch() {
         expect.withMessage("Properties id")
                 .that(MODULE_PROPERTIES.getId()).isEqualTo(TEST_ID);
diff --git a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/TunerSessionTest.java b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/TunerSessionTest.java
index 993ca77..c5c6349 100644
--- a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/TunerSessionTest.java
+++ b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/aidl/TunerSessionTest.java
@@ -42,6 +42,7 @@
 import android.hardware.radio.ProgramSelector;
 import android.hardware.radio.RadioManager;
 import android.hardware.radio.RadioTuner;
+import android.os.Build;
 import android.os.ServiceSpecificException;
 import android.util.ArrayMap;
 import android.util.ArraySet;
@@ -65,6 +66,7 @@
  */
 public final class TunerSessionTest extends ExtendedRadioMockitoTestCase {
 
+    private static final int TARGET_SDK_VERSION = Build.VERSION_CODES.CUR_DEVELOPMENT;
     private static final VerificationWithTimeout CALLBACK_TIMEOUT =
             timeout(/* millis= */ 200);
     private static final int SIGNAL_QUALITY = 1;
@@ -299,6 +301,18 @@
     }
 
     @Test
+    public void tune_withLowerSdkVersion() throws Exception {
+        openAidlClients(/* numClients= */ 1, Build.VERSION_CODES.TIRAMISU);
+        ProgramSelector initialSel = AidlTestUtils.makeFmSelector(AM_FM_FREQUENCY_LIST[1]);
+        RadioManager.ProgramInfo tuneInfo =
+                AidlTestUtils.makeProgramInfo(initialSel, SIGNAL_QUALITY);
+
+        mTunerSessions[0].tune(initialSel);
+
+        verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT).onCurrentProgramInfoChanged(tuneInfo);
+    }
+
+    @Test
     public void tune_withMultipleSessions() throws Exception {
         int numSessions = 3;
         openAidlClients(numSessions);
@@ -377,49 +391,49 @@
     }
 
     @Test
-    public void scan_withDirectionUp() throws Exception {
+    public void seek_withDirectionUp() throws Exception {
         long initFreq = AM_FM_FREQUENCY_LIST[2];
         ProgramSelector initialSel = AidlTestUtils.makeFmSelector(initFreq);
-        RadioManager.ProgramInfo scanUpInfo = AidlTestUtils.makeProgramInfo(
+        RadioManager.ProgramInfo seekUpInfo = AidlTestUtils.makeProgramInfo(
                 AidlTestUtils.makeFmSelector(getSeekFrequency(initFreq, /* seekDown= */ false)),
                 SIGNAL_QUALITY);
         openAidlClients(/* numClients= */ 1);
         mHalCurrentInfo = AidlTestUtils.makeHalProgramInfo(
                 ConversionUtils.programSelectorToHalProgramSelector(initialSel), SIGNAL_QUALITY);
 
-        mTunerSessions[0].scan(/* directionDown= */ false, /* skipSubChannel= */ false);
+        mTunerSessions[0].seek(/* directionDown= */ false, /* skipSubChannel= */ false);
 
         verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT)
-                .onCurrentProgramInfoChanged(scanUpInfo);
+                .onCurrentProgramInfoChanged(seekUpInfo);
     }
 
     @Test
-    public void scan_callsOnTuneFailedWhenTimeout() throws Exception {
+    public void seek_callsOnTuneFailedWhenTimeout() throws Exception {
         int numSessions = 2;
         openAidlClients(numSessions);
 
-        mTunerSessions[0].scan(/* directionDown= */ false, /* skipSubChannel= */ false);
+        mTunerSessions[0].seek(/* directionDown= */ false, /* skipSubChannel= */ false);
 
         for (int index = 0; index < numSessions; index++) {
             verify(mAidlTunerCallbackMocks[index], CALLBACK_TIMEOUT)
-                    .onTuneFailed(eq(Result.TIMEOUT), any());
+                    .onTuneFailed(eq(RadioTuner.TUNER_RESULT_TIMEOUT), any());
         }
     }
 
     @Test
-    public void scan_withDirectionDown() throws Exception {
+    public void seek_withDirectionDown() throws Exception {
         long initFreq = AM_FM_FREQUENCY_LIST[2];
         ProgramSelector initialSel = AidlTestUtils.makeFmSelector(initFreq);
-        RadioManager.ProgramInfo scanUpInfo = AidlTestUtils.makeProgramInfo(
+        RadioManager.ProgramInfo seekUpInfo = AidlTestUtils.makeProgramInfo(
                 AidlTestUtils.makeFmSelector(getSeekFrequency(initFreq, /* seekDown= */ true)),
                 SIGNAL_QUALITY);
         openAidlClients(/* numClients= */ 1);
         mHalCurrentInfo = AidlTestUtils.makeHalProgramInfo(
                 ConversionUtils.programSelectorToHalProgramSelector(initialSel), SIGNAL_QUALITY);
 
-        mTunerSessions[0].scan(/* directionDown= */ true, /* skipSubChannel= */ false);
+        mTunerSessions[0].seek(/* directionDown= */ true, /* skipSubChannel= */ false);
         verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT)
-                .onCurrentProgramInfoChanged(scanUpInfo);
+                .onCurrentProgramInfoChanged(seekUpInfo);
     }
 
     @Test
@@ -585,7 +599,7 @@
     }
 
     @Test
-    public void onConfigFlagUpdated_forTunerCallback() throws Exception {
+    public void onAntennaStateChange_forTunerCallback() throws Exception {
         int numSessions = 3;
         openAidlClients(numSessions);
 
@@ -598,6 +612,21 @@
     }
 
     @Test
+    public void onConfigFlagUpdated_forTunerCallback() throws Exception {
+        int numSessions = 3;
+        openAidlClients(numSessions);
+        int flag = UNSUPPORTED_CONFIG_FLAG + 1;
+        boolean configFlagValue = true;
+
+        mHalTunerCallback.onConfigFlagUpdated(flag, configFlagValue);
+
+        for (int index = 0; index < numSessions; index++) {
+            verify(mAidlTunerCallbackMocks[index], CALLBACK_TIMEOUT)
+                    .onConfigFlagUpdated(flag, configFlagValue);
+        }
+    }
+
+    @Test
     public void onParametersUpdated_forTunerCallback() throws Exception {
         int numSessions = 3;
         openAidlClients(numSessions);
@@ -612,13 +641,17 @@
                     .onParametersUpdated(parametersExpected);
         }
     }
-
     private void openAidlClients(int numClients) throws Exception {
+        openAidlClients(numClients, TARGET_SDK_VERSION);
+    }
+
+    private void openAidlClients(int numClients, int targetSdkVersion) throws Exception {
         mAidlTunerCallbackMocks = new android.hardware.radio.ITunerCallback[numClients];
         mTunerSessions = new TunerSession[numClients];
         for (int index = 0; index < numClients; index++) {
             mAidlTunerCallbackMocks[index] = mock(android.hardware.radio.ITunerCallback.class);
-            mTunerSessions[index] = mRadioModule.openSession(mAidlTunerCallbackMocks[index]);
+            mTunerSessions[index] = mRadioModule.openSession(mAidlTunerCallbackMocks[index],
+                    targetSdkVersion);
         }
     }
 
diff --git a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/hal2/ConvertResultTest.java b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/hal2/ConvertResultTest.java
new file mode 100644
index 0000000..d106de9
--- /dev/null
+++ b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/hal2/ConvertResultTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.server.broadcastradio.hal2;
+
+import android.hardware.broadcastradio.V2_0.Result;
+import android.hardware.radio.RadioTuner;
+
+import com.google.common.truth.Expect;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+import java.util.List;
+
+@RunWith(Parameterized.class)
+public final class ConvertResultTest {
+
+    private final int mHalResult;
+    private final int mTunerResult;
+
+    @Rule
+    public final Expect expect = Expect.create();
+
+    public ConvertResultTest(int halResult, int tunerResult) {
+        this.mHalResult = halResult;
+        this.mTunerResult = tunerResult;
+    }
+
+    @Parameterized.Parameters
+    public static List<Object[]> inputParameters() {
+        return Arrays.asList(new Object[][]{
+                {Result.OK, RadioTuner.TUNER_RESULT_OK},
+                {Result.INTERNAL_ERROR, RadioTuner.TUNER_RESULT_INTERNAL_ERROR},
+                {Result.INVALID_ARGUMENTS, RadioTuner.TUNER_RESULT_INVALID_ARGUMENTS},
+                {Result.INVALID_STATE, RadioTuner.TUNER_RESULT_INVALID_STATE},
+                {Result.NOT_SUPPORTED, RadioTuner.TUNER_RESULT_NOT_SUPPORTED},
+                {Result.TIMEOUT, RadioTuner.TUNER_RESULT_TIMEOUT},
+                {Result.UNKNOWN_ERROR, RadioTuner.TUNER_RESULT_UNKNOWN_ERROR}
+        });
+    }
+
+    @Test
+    public void halResultToTunerResult() {
+        expect.withMessage("Tuner result converted from HAL 2.0 result %s",
+                Result.toString(mHalResult))
+                .that(Convert.halResultToTunerResult(mHalResult))
+                .isEqualTo(mTunerResult);
+    }
+}
diff --git a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/hal2/TunerSessionHidlTest.java b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/hal2/TunerSessionHidlTest.java
index ff988a2..db16c03 100644
--- a/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/hal2/TunerSessionHidlTest.java
+++ b/core/tests/BroadcastRadioTests/src/com/android/server/broadcastradio/hal2/TunerSessionHidlTest.java
@@ -384,49 +384,49 @@
     }
 
     @Test
-    public void scan_withDirectionUp() throws Exception {
+    public void seek_withDirectionUp() throws Exception {
         long initFreq = AM_FM_FREQUENCY_LIST[2];
         ProgramSelector initialSel = TestUtils.makeFmSelector(initFreq);
-        RadioManager.ProgramInfo scanUpInfo = TestUtils.makeProgramInfo(
+        RadioManager.ProgramInfo seekUpInfo = TestUtils.makeProgramInfo(
                 TestUtils.makeFmSelector(getSeekFrequency(initFreq, /* seekDown= */ false)),
                 SIGNAL_QUALITY);
         openAidlClients(/* numClients= */ 1);
         mHalCurrentInfo = TestUtils.makeHalProgramInfo(
                 Convert.programSelectorToHal(initialSel), SIGNAL_QUALITY);
 
-        mTunerSessions[0].scan(/* directionDown= */ false, /* skipSubChannel= */ false);
+        mTunerSessions[0].seek(/* directionDown= */ false, /* skipSubChannel= */ false);
 
         verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT)
-                .onCurrentProgramInfoChanged(scanUpInfo);
+                .onCurrentProgramInfoChanged(seekUpInfo);
     }
 
     @Test
-    public void scan_callsOnTuneFailedWhenTimeout() throws Exception {
+    public void seek_callsOnTuneFailedWhenTimeout() throws Exception {
         int numSessions = 2;
         openAidlClients(numSessions);
 
-        mTunerSessions[0].scan(/* directionDown= */ false, /* skipSubChannel= */ false);
+        mTunerSessions[0].seek(/* directionDown= */ false, /* skipSubChannel= */ false);
 
         for (int index = 0; index < numSessions; index++) {
             verify(mAidlTunerCallbackMocks[index], CALLBACK_TIMEOUT)
-                    .onTuneFailed(eq(Result.TIMEOUT), any());
+                    .onTuneFailed(eq(RadioTuner.TUNER_RESULT_TIMEOUT), any());
         }
     }
 
     @Test
-    public void scan_withDirectionDown() throws Exception {
+    public void seek_withDirectionDown() throws Exception {
         long initFreq = AM_FM_FREQUENCY_LIST[2];
         ProgramSelector initialSel = TestUtils.makeFmSelector(initFreq);
-        RadioManager.ProgramInfo scanUpInfo = TestUtils.makeProgramInfo(
+        RadioManager.ProgramInfo seekUpInfo = TestUtils.makeProgramInfo(
                 TestUtils.makeFmSelector(getSeekFrequency(initFreq, /* seekDown= */ true)),
                 SIGNAL_QUALITY);
         openAidlClients(/* numClients= */ 1);
         mHalCurrentInfo = TestUtils.makeHalProgramInfo(
                 Convert.programSelectorToHal(initialSel), SIGNAL_QUALITY);
 
-        mTunerSessions[0].scan(/* directionDown= */ true, /* skipSubChannel= */ false);
+        mTunerSessions[0].seek(/* directionDown= */ true, /* skipSubChannel= */ false);
         verify(mAidlTunerCallbackMocks[0], CALLBACK_TIMEOUT)
-                .onCurrentProgramInfoChanged(scanUpInfo);
+                .onCurrentProgramInfoChanged(seekUpInfo);
     }
 
     @Test
diff --git a/core/tests/GameManagerTests/src/android/app/GameModeConfigurationTest.java b/core/tests/GameManagerTests/src/android/app/GameModeConfigurationTest.java
index 7462bcf..b3e74d3 100644
--- a/core/tests/GameManagerTests/src/android/app/GameModeConfigurationTest.java
+++ b/core/tests/GameManagerTests/src/android/app/GameModeConfigurationTest.java
@@ -77,10 +77,10 @@
     }
 
     @Test
-    public void testToBuilder() {
+    public void testBuilderConstructor() {
         GameModeConfiguration config = new GameModeConfiguration
                 .Builder().setFpsOverride(40).setScalingFactor(0.5f).build();
-        GameModeConfiguration newConfig = config.toBuilder().build();
+        GameModeConfiguration newConfig = new GameModeConfiguration.Builder(config).build();
         assertEquals(config, newConfig);
     }
 
diff --git a/core/tests/GameManagerTests/src/android/app/GameModeInfoTest.java b/core/tests/GameManagerTests/src/android/app/GameModeInfoTest.java
index ecd9b6b8..5fa6084 100644
--- a/core/tests/GameManagerTests/src/android/app/GameModeInfoTest.java
+++ b/core/tests/GameManagerTests/src/android/app/GameModeInfoTest.java
@@ -43,7 +43,7 @@
         int[] availableGameModes =
                 new int[]{GameManager.GAME_MODE_STANDARD, GameManager.GAME_MODE_PERFORMANCE,
                         GameManager.GAME_MODE_BATTERY, GameManager.GAME_MODE_CUSTOM};
-        int[] optedInGameModes = new int[]{GameManager.GAME_MODE_PERFORMANCE};
+        int[] overriddenGameModes = new int[]{GameManager.GAME_MODE_PERFORMANCE};
         GameModeConfiguration batteryConfig = new GameModeConfiguration
                 .Builder().setFpsOverride(40).setScalingFactor(0.5f).build();
         GameModeConfiguration performanceConfig = new GameModeConfiguration
@@ -51,7 +51,7 @@
         GameModeInfo gameModeInfo = new GameModeInfo.Builder()
                 .setActiveGameMode(activeGameMode)
                 .setAvailableGameModes(availableGameModes)
-                .setOptedInGameModes(optedInGameModes)
+                .setOverriddenGameModes(overriddenGameModes)
                 .setDownscalingAllowed(true)
                 .setFpsOverrideAllowed(false)
                 .setGameModeConfiguration(GameManager.GAME_MODE_BATTERY, batteryConfig)
@@ -59,7 +59,7 @@
                 .build();
 
         assertArrayEquals(availableGameModes, gameModeInfo.getAvailableGameModes());
-        assertArrayEquals(optedInGameModes, gameModeInfo.getOptedInGameModes());
+        assertArrayEquals(overriddenGameModes, gameModeInfo.getOverriddenGameModes());
         assertEquals(activeGameMode, gameModeInfo.getActiveGameMode());
         assertTrue(gameModeInfo.isDownscalingAllowed());
         assertFalse(gameModeInfo.isFpsOverrideAllowed());
@@ -75,8 +75,8 @@
         assertEquals(gameModeInfo.getActiveGameMode(), newGameModeInfo.getActiveGameMode());
         assertArrayEquals(gameModeInfo.getAvailableGameModes(),
                 newGameModeInfo.getAvailableGameModes());
-        assertArrayEquals(gameModeInfo.getOptedInGameModes(),
-                newGameModeInfo.getOptedInGameModes());
+        assertArrayEquals(gameModeInfo.getOverriddenGameModes(),
+                newGameModeInfo.getOverriddenGameModes());
         assertTrue(newGameModeInfo.isDownscalingAllowed());
         assertFalse(newGameModeInfo.isFpsOverrideAllowed());
         assertEquals(performanceConfig,
diff --git a/core/tests/coretests/src/android/companion/virtual/OWNERS b/core/tests/coretests/src/android/companion/virtual/OWNERS
new file mode 100644
index 0000000..1a3e927
--- /dev/null
+++ b/core/tests/coretests/src/android/companion/virtual/OWNERS
@@ -0,0 +1,3 @@
+set noparent
+
+include /services/companion/java/com/android/server/companion/virtual/OWNERS
\ No newline at end of file
diff --git a/core/tests/coretests/src/android/companion/virtual/camera/VirtualCameraOutputTest.java b/core/tests/coretests/src/android/companion/virtual/camera/VirtualCameraOutputTest.java
new file mode 100644
index 0000000..694b312
--- /dev/null
+++ b/core/tests/coretests/src/android/companion/virtual/camera/VirtualCameraOutputTest.java
@@ -0,0 +1,128 @@
+/*
+ * 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 android.companion.virtual.camera;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.junit.Assert.fail;
+
+import android.graphics.PixelFormat;
+import android.hardware.camera2.params.InputConfiguration;
+import android.os.ParcelFileDescriptor;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class VirtualCameraOutputTest {
+
+    private static final String TAG = "VirtualCameraOutputTest";
+
+    private ExecutorService mExecutor;
+
+    private InputConfiguration mConfiguration;
+
+    @Before
+    public void setUp() {
+        mExecutor = Executors.newSingleThreadExecutor();
+        mConfiguration = new InputConfiguration(64, 64, PixelFormat.RGB_888);
+    }
+
+    @After
+    public void cleanUp() {
+        mExecutor.shutdownNow();
+    }
+
+    @Test
+    public void createStreamDescriptor_successfulDataStream() {
+        byte[] cameraData = new byte[]{1, 2, 3, 4, 5};
+        VirtualCameraInput input = createCameraInput(cameraData);
+        VirtualCameraOutput output = new VirtualCameraOutput(input, mExecutor);
+        ParcelFileDescriptor descriptor = output.getStreamDescriptor(mConfiguration);
+
+        try (FileInputStream fis = new FileInputStream(descriptor.getFileDescriptor())) {
+            byte[] receivedData = fis.readNBytes(cameraData.length);
+
+            output.closeStream();
+            assertThat(receivedData).isEqualTo(cameraData);
+        } catch (IOException exception) {
+            fail("Unable to read bytes from FileInputStream. Message: " + exception.getMessage());
+        }
+    }
+
+    @Test
+    public void createStreamDescriptor_multipleCallsSameStream() {
+        VirtualCameraInput input = createCameraInput(new byte[]{0});
+        VirtualCameraOutput output = new VirtualCameraOutput(input, mExecutor);
+
+        ParcelFileDescriptor firstDescriptor = output.getStreamDescriptor(mConfiguration);
+        ParcelFileDescriptor secondDescriptor = output.getStreamDescriptor(mConfiguration);
+
+        assertThat(firstDescriptor).isSameInstanceAs(secondDescriptor);
+    }
+
+    @Test
+    public void createStreamDescriptor_differentStreams() {
+        VirtualCameraInput input = createCameraInput(new byte[]{0});
+        VirtualCameraOutput callback = new VirtualCameraOutput(input, mExecutor);
+
+        InputConfiguration differentConfig = new InputConfiguration(mConfiguration.getWidth() + 1,
+                mConfiguration.getHeight() + 1, mConfiguration.getFormat());
+
+        ParcelFileDescriptor firstDescriptor = callback.getStreamDescriptor(mConfiguration);
+        ParcelFileDescriptor secondDescriptor = callback.getStreamDescriptor(differentConfig);
+
+        assertThat(firstDescriptor).isNotSameInstanceAs(secondDescriptor);
+    }
+
+    private VirtualCameraInput createCameraInput(byte[] data) {
+        return new VirtualCameraInput() {
+            private ByteArrayInputStream mInputStream = null;
+
+            @Override
+            @NonNull
+            public InputStream openStream(@NonNull InputConfiguration inputConfiguration) {
+                closeStream();
+                mInputStream = new ByteArrayInputStream(data);
+                return mInputStream;
+            }
+
+            @Override
+            public void closeStream() {
+                if (mInputStream == null) {
+                    return;
+                }
+                try {
+                    mInputStream.close();
+                } catch (IOException e) {
+                    Log.e(TAG, "Unable to close image stream.", e);
+                }
+                mInputStream = null;
+            }
+        };
+    }
+}
diff --git a/core/tests/coretests/src/android/content/ContextTest.java b/core/tests/coretests/src/android/content/ContextTest.java
index bc356f8..324f810 100644
--- a/core/tests/coretests/src/android/content/ContextTest.java
+++ b/core/tests/coretests/src/android/content/ContextTest.java
@@ -16,7 +16,7 @@
 
 package android.content;
 
-import static android.companion.virtual.VirtualDeviceManager.DEFAULT_DEVICE_ID;
+import static android.companion.virtual.VirtualDeviceManager.DEVICE_ID_DEFAULT;
 import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY;
 import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC;
 import static android.view.Display.DEFAULT_DISPLAY;
@@ -216,7 +216,7 @@
         final Context systemContext =
                 ActivityThread.currentActivityThread().getSystemContext();
 
-        assertEquals(systemContext.getDeviceId(), DEFAULT_DEVICE_ID);
+        assertEquals(systemContext.getDeviceId(), DEVICE_ID_DEFAULT);
     }
 
     @Test
@@ -224,7 +224,7 @@
         final Context systemUiContext =
                 ActivityThread.currentActivityThread().getSystemUiContext();
 
-        assertEquals(systemUiContext.getDeviceId(), DEFAULT_DEVICE_ID);
+        assertEquals(systemUiContext.getDeviceId(), DEVICE_ID_DEFAULT);
     }
 
     @Test
@@ -232,7 +232,7 @@
         final Context testContext =
                 InstrumentationRegistry.getInstrumentation().getTargetContext();
 
-        assertEquals(testContext.getDeviceId(), DEFAULT_DEVICE_ID);
+        assertEquals(testContext.getDeviceId(), DEVICE_ID_DEFAULT);
     }
 
     private Context createUiContext() {
diff --git a/core/tests/coretests/src/android/os/EnvironmentTest.java b/core/tests/coretests/src/android/os/EnvironmentTest.java
index 8e63a0f..ef38cde 100644
--- a/core/tests/coretests/src/android/os/EnvironmentTest.java
+++ b/core/tests/coretests/src/android/os/EnvironmentTest.java
@@ -22,12 +22,12 @@
 import static android.os.Environment.HAS_OTHER;
 import static android.os.Environment.classifyExternalStorageDirectory;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static com.google.common.truth.Truth.assertThat;
 
-import android.app.AppOpsManager;
+import static org.junit.Assert.assertEquals;
+
 import android.content.Context;
+import android.os.storage.StorageManager;
 
 import androidx.test.InstrumentationRegistry;
 import androidx.test.runner.AndroidJUnit4;
@@ -38,6 +38,9 @@
 import org.junit.runner.RunWith;
 
 import java.io.File;
+import java.util.ArrayList;
+import java.util.UUID;
+import java.util.function.BiFunction;
 
 @RunWith(AndroidJUnit4.class)
 public class EnvironmentTest {
@@ -104,4 +107,42 @@
         Environment.buildPath(dir, "Taxes.pdf").createNewFile();
         assertEquals(HAS_OTHER, classifyExternalStorageDirectory(dir));
     }
+
+    @Test
+    public void testDataCePackageDirectoryForUser() {
+        testDataPackageDirectoryForUser(
+                (uuid, userHandle) -> Environment.getDataCePackageDirectoryForUser(
+                        uuid, userHandle, getContext().getPackageName()),
+                (uuid, user) -> Environment.getDataUserCePackageDirectory(
+                        uuid, user, getContext().getPackageName())
+        );
+    }
+
+    @Test
+    public void testDataDePackageDirectoryForUser() {
+        testDataPackageDirectoryForUser(
+                (uuid, userHandle) -> Environment.getDataDePackageDirectoryForUser(
+                        uuid, userHandle, getContext().getPackageName()),
+                (uuid, user) -> Environment.getDataUserDePackageDirectory(
+                        uuid, user, getContext().getPackageName())
+        );
+    }
+
+    private void testDataPackageDirectoryForUser(
+            BiFunction<UUID, UserHandle, File> publicApi,
+            BiFunction<String, Integer, File> hideApi) {
+        var uuids = new ArrayList<String>();
+        uuids.add(null); // Private internal
+        uuids.add("primary_physical");
+        uuids.add("system");
+        uuids.add("3939-3939"); // FAT Volume
+        uuids.add("57554103-df3e-4475-ae7a-8feba49353ac"); // Random valid UUID
+        var userHandle = UserHandle.of(0);
+
+        // Check that the @hide method is consistent with the public API
+        for (String uuid : uuids) {
+            assertThat(publicApi.apply(StorageManager.convert(uuid), userHandle))
+                    .isEqualTo(hideApi.apply(uuid, 0));
+        }
+    }
 }
diff --git a/core/tests/coretests/src/com/android/internal/jank/InteractionJankMonitorTest.java b/core/tests/coretests/src/com/android/internal/jank/InteractionJankMonitorTest.java
index 7674135..8f83461 100644
--- a/core/tests/coretests/src/com/android/internal/jank/InteractionJankMonitorTest.java
+++ b/core/tests/coretests/src/com/android/internal/jank/InteractionJankMonitorTest.java
@@ -20,7 +20,6 @@
 
 import static com.android.internal.jank.FrameTracker.REASON_CANCEL_TIMEOUT;
 import static com.android.internal.jank.FrameTracker.REASON_END_NORMAL;
-import static com.android.internal.jank.InteractionJankMonitor.CUJ_LOCKSCREEN_LAUNCH_CAMERA;
 import static com.android.internal.jank.InteractionJankMonitor.CUJ_NOTIFICATION_ADD;
 import static com.android.internal.jank.InteractionJankMonitor.CUJ_NOTIFICATION_APP_START;
 import static com.android.internal.jank.InteractionJankMonitor.CUJ_NOTIFICATION_HEADS_UP_APPEAR;
@@ -32,7 +31,6 @@
 import static com.android.internal.jank.InteractionJankMonitor.CUJ_NOTIFICATION_SHADE_ROW_EXPAND;
 import static com.android.internal.jank.InteractionJankMonitor.CUJ_NOTIFICATION_SHADE_ROW_SWIPE;
 import static com.android.internal.jank.InteractionJankMonitor.CUJ_NOTIFICATION_SHADE_SCROLL_FLING;
-import static com.android.internal.jank.InteractionJankMonitor.CUJ_SPLIT_SCREEN_RESIZE;
 import static com.android.internal.jank.InteractionJankMonitor.CUJ_TO_STATSD_INTERACTION_TYPE;
 import static com.android.internal.jank.InteractionJankMonitor.MAX_LENGTH_OF_CUJ_NAME;
 import static com.android.internal.jank.InteractionJankMonitor.getNameOfCuj;
@@ -92,7 +90,6 @@
 public class InteractionJankMonitorTest {
     private static final String CUJ_POSTFIX = "";
     private static final SparseArray<String> ENUM_NAME_EXCEPTION_MAP = new SparseArray<>();
-    private static final SparseArray<String> CUJ_NAME_EXCEPTION_MAP = new SparseArray<>();
     private static final String ENUM_NAME_PREFIX =
             "UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__";
 
@@ -129,22 +126,6 @@
                 CUJ_NOTIFICATION_SHADE_ROW_SWIPE, getEnumName("SHADE_ROW_SWIPE"));
         ENUM_NAME_EXCEPTION_MAP.put(
                 CUJ_NOTIFICATION_SHADE_SCROLL_FLING, getEnumName("SHADE_SCROLL_FLING"));
-
-        CUJ_NAME_EXCEPTION_MAP.put(
-                CUJ_NOTIFICATION_SHADE_EXPAND_COLLAPSE, "CUJ_NOTIFICATION_SHADE_EXPAND_COLLAPSE");
-        CUJ_NAME_EXCEPTION_MAP.put(
-                CUJ_NOTIFICATION_SHADE_QS_EXPAND_COLLAPSE,
-                "CUJ_NOTIFICATION_SHADE_QS_EXPAND_COLLAPSE");
-        CUJ_NAME_EXCEPTION_MAP.put(
-                CUJ_NOTIFICATION_SHADE_QS_SCROLL_SWIPE, "CUJ_NOTIFICATION_SHADE_QS_SCROLL_SWIPE");
-        CUJ_NAME_EXCEPTION_MAP.put(
-                CUJ_NOTIFICATION_SHADE_ROW_EXPAND, "CUJ_NOTIFICATION_SHADE_ROW_EXPAND");
-        CUJ_NAME_EXCEPTION_MAP.put(
-                CUJ_NOTIFICATION_SHADE_ROW_SWIPE, "CUJ_NOTIFICATION_SHADE_ROW_SWIPE");
-        CUJ_NAME_EXCEPTION_MAP.put(
-                CUJ_NOTIFICATION_SHADE_SCROLL_FLING, "CUJ_NOTIFICATION_SHADE_SCROLL_FLING");
-        CUJ_NAME_EXCEPTION_MAP.put(CUJ_LOCKSCREEN_LAUNCH_CAMERA, "CUJ_LOCKSCREEN_LAUNCH_CAMERA");
-        CUJ_NAME_EXCEPTION_MAP.put(CUJ_SPLIT_SCREEN_RESIZE, "CUJ_SPLIT_SCREEN_RESIZE");
     }
 
     private static String getEnumName(String name) {
@@ -272,9 +253,8 @@
                     : formatSimple("%s%s", ENUM_NAME_PREFIX, cujName.substring(4));
             final int enumKey = CUJ_TO_STATSD_INTERACTION_TYPE[cuj];
             final String enumName = enumsMap.get(enumKey);
-            final String expectedNameOfCuj = CUJ_NAME_EXCEPTION_MAP.contains(cuj)
-                    ? CUJ_NAME_EXCEPTION_MAP.get(cuj)
-                    : formatSimple("CUJ_%s", getNameOfCuj(cuj));
+            final String expectedNameOfCuj = formatSimple("CUJ_%s", getNameOfCuj(cuj));
+
             mExpect
                     .withMessage(formatSimple(
                             "%s (%d) not matches %s (%d)", cujName, cuj, enumName, enumKey))
@@ -323,7 +303,7 @@
         // Since the length of the cuj name is tested in another test, no need to test it here.
         // Too long postfix case, should trim the postfix and keep the cuj name completed.
         final String expectedTrimmedName = formatSimple("J<%s::%s>", cujName,
-                "ThisIsTheCujTagThisIsTheCujTagThisIsTheCujTagThisIsTheCujTagThisIsTheCujTagT...");
+                "ThisIsTheCujTagThisIsTheCujTagThisIsTheCujTagThisIsTheCujTagThi...");
         Session longPostfix = new Session(cujType, tooLongTag);
         assertThat(longPostfix.getName()).isEqualTo(expectedTrimmedName);
     }
diff --git a/data/etc/com.android.settings.xml b/data/etc/com.android.settings.xml
index 3958bb7..e278c52 100644
--- a/data/etc/com.android.settings.xml
+++ b/data/etc/com.android.settings.xml
@@ -63,5 +63,6 @@
         <permission name="android.permission.RESTART_WIFI_SUBSYSTEM"/>
         <permission name="android.permission.READ_SAFETY_CENTER_STATUS" />
         <permission name="android.permission.SEND_SAFETY_CENTER_UPDATE" />
+        <permission name="android.permission.LIST_ENABLED_CREDENTIAL_PROVIDERS" />
     </privapp-permissions>
 </permissions>
diff --git a/data/etc/privapp-permissions-platform.xml b/data/etc/privapp-permissions-platform.xml
index 3e2b71f..4109425 100644
--- a/data/etc/privapp-permissions-platform.xml
+++ b/data/etc/privapp-permissions-platform.xml
@@ -232,6 +232,7 @@
 
     <privapp-permissions package="com.android.shell">
         <!-- Needed for test only -->
+        <permission name="android.permission.MANAGE_HEALTH_DATA"/>
         <permission name="android.permission.LAUNCH_DEVICE_MANAGER_SETUP"/>
         <permission name="android.permission.MODIFY_DAY_NIGHT_MODE"/>
         <permission name="android.permission.ACCESS_LOWPAN_STATE"/>
@@ -386,6 +387,7 @@
         <permission name="android.permission.MANAGE_COMPANION_DEVICES" />
         <permission name="android.permission.REQUEST_COMPANION_PROFILE_APP_STREAMING" />
         <permission name="android.permission.REQUEST_COMPANION_PROFILE_WATCH" />
+        <permission name="android.permission.REQUEST_COMPANION_PROFILE_NEARBY_DEVICE_STREAMING" />
         <permission name="android.permission.REQUEST_COMPANION_PROFILE_COMPUTER" />
         <permission name="android.permission.REQUEST_COMPANION_SELF_MANAGED" />
         <!-- Permission required for testing registering pull atom callbacks. -->
diff --git a/data/etc/services.core.protolog.json b/data/etc/services.core.protolog.json
index 3346740..1ab5e4b 100644
--- a/data/etc/services.core.protolog.json
+++ b/data/etc/services.core.protolog.json
@@ -169,6 +169,12 @@
       "group": "WM_ERROR",
       "at": "com\/android\/server\/wm\/WindowManagerService.java"
     },
+    "-1944652783": {
+      "message": "Unable to tell MediaProjectionManagerService to stop the active projection: %s",
+      "level": "ERROR",
+      "group": "WM_DEBUG_CONTENT_RECORDING",
+      "at": "com\/android\/server\/wm\/ContentRecorder.java"
+    },
     "-1941440781": {
       "message": "Creating Pending Move-to-back: %s",
       "level": "VERBOSE",
@@ -619,6 +625,12 @@
       "group": "WM_DEBUG_CONFIGURATION",
       "at": "com\/android\/server\/wm\/ActivityStarter.java"
     },
+    "-1484988952": {
+      "message": "Creating Pending Multiwindow Fullscreen Request: %s",
+      "level": "VERBOSE",
+      "group": "WM_DEBUG_WINDOW_TRANSITIONS",
+      "at": "com\/android\/server\/wm\/ActivityClientController.java"
+    },
     "-1483435730": {
       "message": "InsetsSource setWin %s for type %s",
       "level": "DEBUG",
@@ -709,6 +721,12 @@
       "group": "WM_DEBUG_ADD_REMOVE",
       "at": "com\/android\/server\/wm\/WindowManagerService.java"
     },
+    "-1423223548": {
+      "message": "Unable to tell MediaProjectionManagerService about resizing the active projection: %s",
+      "level": "ERROR",
+      "group": "WM_DEBUG_CONTENT_RECORDING",
+      "at": "com\/android\/server\/wm\/ContentRecorder.java"
+    },
     "-1421296808": {
       "message": "Moving to RESUMED: %s (in existing)",
       "level": "VERBOSE",
@@ -805,6 +823,12 @@
       "group": "WM_DEBUG_CONTENT_RECORDING",
       "at": "com\/android\/server\/wm\/ContentRecorder.java"
     },
+    "-1323783276": {
+      "message": "performEnableScreen: bootFinished() failed.",
+      "level": "WARN",
+      "group": "WM_ERROR",
+      "at": "com\/android\/server\/wm\/WindowManagerService.java"
+    },
     "-1318478129": {
       "message": "applyAnimation: win=%s anim=%d attr=0x%x a=%s transit=%d type=%d isEntrance=%b Callers %s",
       "level": "VERBOSE",
@@ -1603,6 +1627,12 @@
       "group": "WM_ERROR",
       "at": "com\/android\/server\/wm\/WindowManagerService.java"
     },
+    "-576580969": {
+      "message": "viewServerWindowCommand: bootFinished() failed.",
+      "level": "WARN",
+      "group": "WM_ERROR",
+      "at": "com\/android\/server\/wm\/WindowManagerService.java"
+    },
     "-576070986": {
       "message": "Performing post-rotate rotation after seamless rotation",
       "level": "INFO",
@@ -2113,12 +2143,6 @@
       "group": "WM_DEBUG_FOCUS_LIGHT",
       "at": "com\/android\/server\/wm\/DisplayContent.java"
     },
-    "-87703044": {
-      "message": "Boot completed: SurfaceFlinger is dead!",
-      "level": "ERROR",
-      "group": "WM_ERROR",
-      "at": "com\/android\/server\/wm\/WindowManagerService.java"
-    },
     "-86763148": {
       "message": "  KILL SURFACE SESSION %s",
       "level": "INFO",
@@ -2911,12 +2935,6 @@
       "group": "WM_DEBUG_CONTENT_RECORDING",
       "at": "com\/android\/server\/wm\/ContentRecorder.java"
     },
-    "620368427": {
-      "message": "******* TELLING SURFACE FLINGER WE ARE BOOTED!",
-      "level": "INFO",
-      "group": "WM_ERROR",
-      "at": "com\/android\/server\/wm\/WindowManagerService.java"
-    },
     "620519522": {
       "message": "findFocusedWindow: No focusable windows, display=%d",
       "level": "VERBOSE",
diff --git a/data/keyboards/Generic.kl b/data/keyboards/Generic.kl
index a43e225..0f8616d 100644
--- a/data/keyboards/Generic.kl
+++ b/data/keyboards/Generic.kl
@@ -139,7 +139,7 @@
 key 117   NUMPAD_EQUALS
 # key 118 "KEY_KPPLUSMINUS"
 key 119   BREAK
-# key 120 (undefined)
+key 120   RECENT_APPS
 key 121   NUMPAD_COMMA
 key 122   KANA
 key 123   EISU
diff --git a/identity/java/android/security/identity/AuthenticationKeyMetadata.java b/identity/java/android/security/identity/AuthenticationKeyMetadata.java
new file mode 100644
index 0000000..c6abc22
--- /dev/null
+++ b/identity/java/android/security/identity/AuthenticationKeyMetadata.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 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 android.security.identity;
+
+import android.annotation.IntRange;
+import android.annotation.NonNull;
+
+import java.time.Instant;
+
+/**
+ * Data about authentication keys.
+ */
+public final class AuthenticationKeyMetadata {
+    private int mUsageCount;
+    private Instant mExpirationDate;
+
+    AuthenticationKeyMetadata(int usageCount, @NonNull Instant expirationDate) {
+        mUsageCount = usageCount;
+        mExpirationDate = expirationDate;
+    }
+
+    /**
+     * Gets usage count for the authentication key.
+     *
+     * @return the usage count
+     */
+    public @IntRange(from = 0) int getUsageCount() {
+        return mUsageCount;
+    }
+
+    /**
+     * Gets expiration date for the authentication key.
+     *
+     * @return the expiration date of the authentication key.
+     */
+    public @NonNull Instant getExpirationDate() {
+        return mExpirationDate;
+    }
+}
diff --git a/identity/java/android/security/identity/CredentialDataResult.java b/identity/java/android/security/identity/CredentialDataResult.java
index beb03af..dca039a 100644
--- a/identity/java/android/security/identity/CredentialDataResult.java
+++ b/identity/java/android/security/identity/CredentialDataResult.java
@@ -106,6 +106,30 @@
     public abstract @Nullable byte[] getDeviceMac();
 
     /**
+     * Returns a signature over the {@code DeviceAuthenticationBytes} CBOR
+     * specified in {@link #getDeviceNameSpaces()}, to prove to the reader that the data
+     * is from a trusted credential.
+     *
+     * <p>The signature is made using the authentication private key. See section 9.1.3.4 of
+     * ISO/IEC 18013-5:2021 for details of this operation.
+     *
+     * <p>If the session transcript or reader ephemeral key wasn't set on the {@link
+     * PresentationSession} used to obtain this data no signature will be produced and this method
+     * will return {@code null}.
+     *
+     * <p>This is only implemented in feature version 202301 or later. If not implemented, the call
+     * fails with {@link UnsupportedOperationException}. See
+     * {@link android.content.pm.PackageManager#FEATURE_IDENTITY_CREDENTIAL_HARDWARE} for known
+     * feature versions.
+     *
+     * @return A COSE_Sign1 structure as described above or {@code null} if the conditions
+     *     specified above are not met.
+     */
+    public @Nullable byte[] getDeviceSignature() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
      * Returns the static authentication data associated with the dynamic authentication
      * key used to MAC the data returned by {@link #getDeviceNameSpaces()}.
      *
diff --git a/identity/java/android/security/identity/CredstoreCredentialDataResult.java b/identity/java/android/security/identity/CredstoreCredentialDataResult.java
index 7afe3d4..b4fd5d3 100644
--- a/identity/java/android/security/identity/CredstoreCredentialDataResult.java
+++ b/identity/java/android/security/identity/CredstoreCredentialDataResult.java
@@ -47,6 +47,11 @@
     }
 
     @Override
+    public @Nullable byte[] getDeviceSignature() {
+        return mDeviceSignedResult.getSignature();
+    }
+
+    @Override
     public @NonNull byte[] getStaticAuthenticationData() {
         return mDeviceSignedResult.getStaticAuthenticationData();
     }
diff --git a/identity/java/android/security/identity/CredstoreIdentityCredential.java b/identity/java/android/security/identity/CredstoreIdentityCredential.java
index c591c87..449c7a7 100644
--- a/identity/java/android/security/identity/CredstoreIdentityCredential.java
+++ b/identity/java/android/security/identity/CredstoreIdentityCredential.java
@@ -60,16 +60,19 @@
     private Context mContext;
     private ICredential mBinder;
     private CredstorePresentationSession mSession;
+    private int mFeatureVersion;
 
     CredstoreIdentityCredential(Context context, String credentialName,
             @IdentityCredentialStore.Ciphersuite int cipherSuite,
             ICredential binder,
-            @Nullable CredstorePresentationSession session) {
+            @Nullable CredstorePresentationSession session,
+            int featureVersion) {
         mContext = context;
         mCredentialName = credentialName;
         mCipherSuite = cipherSuite;
         mBinder = binder;
         mSession = session;
+        mFeatureVersion = featureVersion;
     }
 
     private KeyPair mEphemeralKeyPair = null;
@@ -347,12 +350,18 @@
             }
         }
 
+        byte[] signature = resultParcel.signature;
+        if (signature != null && signature.length == 0) {
+            signature = null;
+        }
+
         byte[] mac = resultParcel.mac;
         if (mac != null && mac.length == 0) {
             mac = null;
         }
         CredstoreResultData.Builder resultDataBuilder = new CredstoreResultData.Builder(
-                resultParcel.staticAuthenticationData, resultParcel.deviceNameSpaces, mac);
+                mFeatureVersion, resultParcel.staticAuthenticationData,
+                resultParcel.deviceNameSpaces, mac, signature);
 
         for (ResultNamespaceParcel resultNamespaceParcel : resultParcel.resultNamespaces) {
             for (ResultEntryParcel resultEntryParcel : resultNamespaceParcel.entries) {
@@ -371,8 +380,14 @@
 
     @Override
     public void setAvailableAuthenticationKeys(int keyCount, int maxUsesPerKey) {
+        setAvailableAuthenticationKeys(keyCount, maxUsesPerKey, 0);
+    }
+
+    @Override
+    public void setAvailableAuthenticationKeys(int keyCount, int maxUsesPerKey,
+                                               long minValidTimeMillis) {
         try {
-            mBinder.setAvailableAuthenticationKeys(keyCount, maxUsesPerKey);
+            mBinder.setAvailableAuthenticationKeys(keyCount, maxUsesPerKey, minValidTimeMillis);
         } catch (android.os.RemoteException e) {
             throw new RuntimeException("Unexpected RemoteException ", e);
         } catch (android.os.ServiceSpecificException e) {
@@ -472,6 +487,34 @@
     }
 
     @Override
+    public @NonNull List<AuthenticationKeyMetadata> getAuthenticationKeyMetadata() {
+        try {
+            int[] usageCount = mBinder.getAuthenticationDataUsageCount();
+            long[] expirationsMillis = mBinder.getAuthenticationDataExpirations();
+            if (usageCount.length != expirationsMillis.length) {
+                throw new IllegalStateException("Size og usageCount and expirationMillis differ");
+            }
+            List<AuthenticationKeyMetadata> mds = new ArrayList<>();
+            for (int n = 0; n < expirationsMillis.length; n++) {
+                AuthenticationKeyMetadata md = null;
+                long expirationMillis = expirationsMillis[n];
+                if (expirationMillis != Long.MAX_VALUE) {
+                    md = new AuthenticationKeyMetadata(
+                        usageCount[n],
+                        Instant.ofEpochMilli(expirationMillis));
+                }
+                mds.add(md);
+            }
+            return mds;
+        } catch (android.os.RemoteException e) {
+            throw new IllegalStateException("Unexpected RemoteException ", e);
+        } catch (android.os.ServiceSpecificException e) {
+            throw new IllegalStateException("Unexpected ServiceSpecificException with code "
+                    + e.errorCode, e);
+        }
+    }
+
+    @Override
     public @NonNull byte[] proveOwnership(@NonNull byte[] challenge) {
         try {
             byte[] proofOfOwnership = mBinder.proveOwnership(challenge);
diff --git a/identity/java/android/security/identity/CredstoreIdentityCredentialStore.java b/identity/java/android/security/identity/CredstoreIdentityCredentialStore.java
index bbaf086..d785c3c 100644
--- a/identity/java/android/security/identity/CredstoreIdentityCredentialStore.java
+++ b/identity/java/android/security/identity/CredstoreIdentityCredentialStore.java
@@ -19,6 +19,8 @@
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.content.Context;
+import android.content.pm.FeatureInfo;
+import android.content.pm.PackageManager;
 import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.security.GenerateRkpKey;
@@ -30,10 +32,28 @@
 
     private Context mContext = null;
     private ICredentialStore mStore = null;
+    private int mFeatureVersion;
+
+    static int getFeatureVersion(@NonNull Context context) {
+        PackageManager pm = context.getPackageManager();
+        if (pm.hasSystemFeature(PackageManager.FEATURE_IDENTITY_CREDENTIAL_HARDWARE)) {
+            FeatureInfo[] infos = pm.getSystemAvailableFeatures();
+            for (int n = 0; n < infos.length; n++) {
+                FeatureInfo info = infos[n];
+                if (info.name.equals(PackageManager.FEATURE_IDENTITY_CREDENTIAL_HARDWARE)) {
+                    return info.version;
+                }
+            }
+        }
+        // Use of the system feature is not required since Android 12. So for Android 11
+        // return 202009 which is the feature version shipped with Android 11.
+        return 202009;
+    }
 
     private CredstoreIdentityCredentialStore(@NonNull Context context, ICredentialStore store) {
         mContext = context;
         mStore = store;
+        mFeatureVersion = getFeatureVersion(mContext);
     }
 
     static CredstoreIdentityCredentialStore getInstanceForType(@NonNull Context context,
@@ -139,8 +159,7 @@
             ICredential credstoreCredential;
             credstoreCredential = mStore.getCredentialByName(credentialName, cipherSuite);
             return new CredstoreIdentityCredential(mContext, credentialName, cipherSuite,
-                    credstoreCredential,
-                    null);
+                    credstoreCredential, null, mFeatureVersion);
         } catch (android.os.RemoteException e) {
             throw new RuntimeException("Unexpected RemoteException ", e);
         } catch (android.os.ServiceSpecificException e) {
@@ -182,7 +201,8 @@
             throws CipherSuiteNotSupportedException {
         try {
             ISession credstoreSession = mStore.createPresentationSession(cipherSuite);
-            return new CredstorePresentationSession(mContext, cipherSuite, this, credstoreSession);
+            return new CredstorePresentationSession(mContext, cipherSuite, this, credstoreSession,
+                                                    mFeatureVersion);
         } catch (android.os.RemoteException e) {
             throw new RuntimeException("Unexpected RemoteException ", e);
         } catch (android.os.ServiceSpecificException e) {
diff --git a/identity/java/android/security/identity/CredstorePresentationSession.java b/identity/java/android/security/identity/CredstorePresentationSession.java
index e3c6689..96bda52 100644
--- a/identity/java/android/security/identity/CredstorePresentationSession.java
+++ b/identity/java/android/security/identity/CredstorePresentationSession.java
@@ -48,15 +48,18 @@
     private byte[] mSessionTranscript = null;
     private boolean mOperationHandleSet = false;
     private long mOperationHandle = 0;
+    private int mFeatureVersion = 0;
 
     CredstorePresentationSession(Context context,
             @IdentityCredentialStore.Ciphersuite int cipherSuite,
             CredstoreIdentityCredentialStore store,
-            ISession binder) {
+            ISession binder,
+            int featureVersion) {
         mContext = context;
         mCipherSuite = cipherSuite;
         mStore = store;
         mBinder = binder;
+        mFeatureVersion = featureVersion;
     }
 
     private void ensureEphemeralKeyPair() {
@@ -147,7 +150,7 @@
                     mBinder.getCredentialForPresentation(credentialName);
                 credential = new CredstoreIdentityCredential(mContext, credentialName,
                                                              mCipherSuite, credstoreCredential,
-                                                             this);
+                                                             this, mFeatureVersion);
                 mCredentialCache.put(credentialName, credential);
 
                 credential.setAllowUsingExhaustedKeys(request.isAllowUsingExhaustedKeys());
diff --git a/identity/java/android/security/identity/CredstoreResultData.java b/identity/java/android/security/identity/CredstoreResultData.java
index 2ef735e..57c0436 100644
--- a/identity/java/android/security/identity/CredstoreResultData.java
+++ b/identity/java/android/security/identity/CredstoreResultData.java
@@ -30,10 +30,11 @@
  * data requested from a {@link IdentityCredential}.
  */
 class CredstoreResultData extends ResultData {
-
+    int mFeatureVersion = 0;
     byte[] mStaticAuthenticationData = null;
     byte[] mAuthenticatedData = null;
     byte[] mMessageAuthenticationCode = null;
+    byte[] mSignature = null;
 
     private Map<String, Map<String, EntryData>> mData = new LinkedHashMap<>();
 
@@ -61,6 +62,14 @@
     }
 
     @Override
+    @Nullable byte[] getSignature() {
+        if (mFeatureVersion < 202301) {
+            throw new UnsupportedOperationException();
+        }
+        return mSignature;
+    }
+
+    @Override
     public @NonNull byte[] getStaticAuthenticationData() {
         return mStaticAuthenticationData;
     }
@@ -124,13 +133,17 @@
     static class Builder {
         private CredstoreResultData mResultData;
 
-        Builder(byte[] staticAuthenticationData,
+        Builder(int featureVersion,
+                byte[] staticAuthenticationData,
                 byte[] authenticatedData,
-                byte[] messageAuthenticationCode) {
+                byte[] messageAuthenticationCode,
+                byte[] signature) {
             this.mResultData = new CredstoreResultData();
+            this.mResultData.mFeatureVersion = featureVersion;
             this.mResultData.mStaticAuthenticationData = staticAuthenticationData;
             this.mResultData.mAuthenticatedData = authenticatedData;
             this.mResultData.mMessageAuthenticationCode = messageAuthenticationCode;
+            this.mResultData.mSignature = signature;
         }
 
         private Map<String, EntryData> getOrCreateInnerMap(String namespaceName) {
diff --git a/identity/java/android/security/identity/IdentityCredential.java b/identity/java/android/security/identity/IdentityCredential.java
index f440b69..2dd9778 100644
--- a/identity/java/android/security/identity/IdentityCredential.java
+++ b/identity/java/android/security/identity/IdentityCredential.java
@@ -16,6 +16,7 @@
 
 package android.security.identity;
 
+import android.annotation.IntRange;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 
@@ -25,6 +26,7 @@
 import java.security.cert.X509Certificate;
 import java.time.Instant;
 import java.util.Collection;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -236,14 +238,15 @@
      *   IntentToRetain = bool
      * </pre>
      *
-     * <p>If the {@code sessionTranscript} parameter is not {@code null}, the X and Y coordinates
-     * of the public part of the key-pair previously generated by {@link #createEphemeralKeyPair()}
-     * must appear somewhere in the bytes of the CBOR. Each of these coordinates must appear
-     * encoded with the most significant bits first and use the exact amount of bits indicated by
-     * the key size of the ephemeral keys. For example, if the ephemeral key is using the P-256
-     * curve then the 32 bytes for the X coordinate encoded with the most significant bits first
-     * must appear somewhere in {@code sessionTranscript} and ditto for the 32 bytes for the Y
-     * coordinate.
+     * <p>If mdoc session encryption is used (e.g. if {@link #createEphemeralKeyPair()} has been
+     * called) and if the {@code sessionTranscript} parameter is not {@code null}, the X and Y
+     * coordinates of the public part of the key-pair previously generated by
+     * {@link #createEphemeralKeyPair()} must appear somewhere in the bytes of the CBOR. Each of
+     * these coordinates must appear encoded with the most significant bits first and use the
+     * exact amount of bits indicated by the key size of the ephemeral keys. For example, if the
+     * ephemeral key is using the P-256 curve then the 32 bytes for the X coordinate encoded with
+     * the most significant bits first must appear somewhere in {@code sessionTranscript} and
+     * ditto for the 32 bytes for the Y coordinate.
      *
      * <p>If {@code readerSignature} is not {@code null} it must be the bytes of a
      * {@code COSE_Sign1} structure as defined in RFC 8152. For the payload nil shall be used and
@@ -296,7 +299,7 @@
      *                                                session transcripts.
      * @throws NoAuthenticationKeyAvailableException  if authentication keys were never
      *                                                provisioned, the method
-     *                                             {@link #setAvailableAuthenticationKeys(int, int)}
+     *                                      {@link #setAvailableAuthenticationKeys(int, int, long)}
      *                                                was called with {@code keyCount} set to 0,
      *                                                the method
      *                                                {@link #setAllowUsingExhaustedKeys(boolean)}
@@ -330,19 +333,25 @@
      * for which this method has not been called behave as though it had been called wit
      * {@code keyCount} 0 and {@code maxUsesPerKey} 1.
      *
+     * <p>The effect of this method is like calling
+     * {@link #setAvailableAuthenticationKeys(int, int, long)} with the last parameter is set to 0.
+     *
      * @param keyCount      The number of active, certified dynamic authentication keys the
      *                      {@code IdentityCredential} will try to keep available. This value
      *                      must be non-negative.
      * @param maxUsesPerKey The maximum number of times each of the keys will be used before it's
      *                      eligible for replacement. This value must be greater than zero.
+     * @deprecated Use {@link #setAvailableAuthenticationKeys(int, int, long)} instead.
      */
+    @Deprecated
     public abstract void setAvailableAuthenticationKeys(int keyCount, int maxUsesPerKey);
 
     /**
      * Gets a collection of dynamic authentication keys that need certification.
      *
      * <p>When there aren't enough certified dynamic authentication keys, either because the key
-     * count has been increased or because one or more keys have reached their usage count, this
+     * count has been increased or because one or more keys have reached their usage count or
+     * it if a key is too close to its expiration date, this
      * method will generate replacement keys and certificates and return them for issuer
      * certification.  The issuer certificates and associated static authentication data must then
      * be provided back to the Identity Credential using
@@ -400,11 +409,6 @@
      * This should only be called for an authenticated key returned by
      * {@link #getAuthKeysNeedingCertification()}.
      *
-     * <p>This is only implemented in feature version 202101 or later. If not implemented, the call
-     * fails with {@link UnsupportedOperationException}. See
-     * {@link android.content.pm.PackageManager#FEATURE_IDENTITY_CREDENTIAL_HARDWARE} for known
-     * feature versions.
-     *
      * @param authenticationKey The dynamic authentication key for which certification and
      *                          associated static
      *                          authentication data is being provided.
@@ -426,7 +430,9 @@
      * Get the number of times the dynamic authentication keys have been used.
      *
      * @return int array of dynamic authentication key usage counts.
+     * @deprecated Use {@link #getAuthenticationKeyMetadata()} instead.
      */
+    @Deprecated
     public @NonNull abstract int[] getAuthenticationDataUsageCount();
 
     /**
@@ -519,4 +525,47 @@
     public @NonNull byte[] update(@NonNull PersonalizationData personalizationData) {
         throw new UnsupportedOperationException();
     }
+
+    /**
+     * Sets the number of dynamic authentication keys the {@code IdentityCredential} will maintain,
+     * the number of times each should be used, and the minimum amount of time it's valid for.
+     *
+     * <p>The Identity Credential system will select the least-used dynamic authentication key each
+     * time {@link #getEntries(byte[], Map, byte[], byte[])} is called. Identity Credentials
+     * for which this method has not been called behave as though it had been called wit
+     * {@code keyCount} 0, {@code maxUsesPerKey} 1, and {@code minValidTimeMillis} 0.
+     *
+     * <p>Applications can use {@link #getAuthenticationKeyMetadata()} to get a picture of the
+     * usage andtime left of each configured authentication key. This can be used to determine
+     * how urgent it is recertify new authentication keys via the
+     * {@link #getAuthKeysNeedingCertification()} method.
+     *
+     * @param keyCount      The number of active, certified dynamic authentication keys the
+     *                      {@code IdentityCredential} will try to keep available. This value
+     *                      must be non-negative.
+     * @param maxUsesPerKey The maximum number of times each of the keys will be used before it's
+     *                      eligible for replacement. This value must be greater than zero.
+     * @param minValidTimeMillis If a key has less time left than this value it will be eliglible
+     *                           for replacement. This value must be non-negative.
+     */
+    public void setAvailableAuthenticationKeys(
+            @IntRange(from = 0) int keyCount,
+            @IntRange(from = 1) int maxUsesPerKey,
+            @IntRange(from = 0) long minValidTimeMillis) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Get information about dynamic authentication keys.
+     *
+     * <p>The returned list may have <code>null</code> values if certification for the dynamic
+     * authentication key is pending.
+     *
+     * <p>The list is always <code>keyCount</code> elements long.
+     *
+     * @return list of authentication key metadata objects.
+     */
+    public @NonNull List<AuthenticationKeyMetadata> getAuthenticationKeyMetadata() {
+        throw new UnsupportedOperationException();
+    }
 }
diff --git a/identity/java/android/security/identity/PresentationSession.java b/identity/java/android/security/identity/PresentationSession.java
index 6cde611..f392e12 100644
--- a/identity/java/android/security/identity/PresentationSession.java
+++ b/identity/java/android/security/identity/PresentationSession.java
@@ -73,7 +73,8 @@
      * <p>If called, this must be called before any calls to
      * {@link #getCredentialData(String, CredentialDataRequest)}.
      *
-     * <p>The X and Y coordinates of the public part of the key-pair returned by {@link
+     * <p>If mdoc session encryption is used (e.g. if {@link #getEphemeralKeyPair()} has been
+     * called) then the X and Y coordinates of the public part of the key-pair returned by {@link
      * #getEphemeralKeyPair()} must appear somewhere in the bytes of the passed in CBOR.  Each of
      * these coordinates must appear encoded with the most significant bits first and use the exact
      * amount of bits indicated by the key size of the ephemeral keys. For example, if the
diff --git a/identity/java/android/security/identity/ResultData.java b/identity/java/android/security/identity/ResultData.java
index d46f985..8a0e56e 100644
--- a/identity/java/android/security/identity/ResultData.java
+++ b/identity/java/android/security/identity/ResultData.java
@@ -134,6 +134,10 @@
      */
     public abstract @Nullable byte[] getMessageAuthenticationCode();
 
+    @Nullable byte[] getSignature() {
+        throw new UnsupportedOperationException();
+    }
+
     /**
      * Returns the static authentication data associated with the dynamic authentication
      * key used to sign or MAC the data returned by {@link #getAuthenticatedData()}.
diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/JetpackTaskFragmentOrganizer.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/JetpackTaskFragmentOrganizer.java
index d7d43aa..b910287 100644
--- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/JetpackTaskFragmentOrganizer.java
+++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/JetpackTaskFragmentOrganizer.java
@@ -133,8 +133,18 @@
         }
 
         // Create a TaskFragment for the secondary activity.
-        createTaskFragmentAndStartActivity(wct, secondaryFragmentToken, ownerToken,
-                secondaryFragmentBounds, windowingMode, activityIntent,
+        final TaskFragmentCreationParams fragmentOptions = new TaskFragmentCreationParams.Builder(
+                getOrganizerToken(), secondaryFragmentToken, ownerToken)
+                .setInitialBounds(secondaryFragmentBounds)
+                .setWindowingMode(windowingMode)
+                // Make sure to set the paired fragment token so that the new TaskFragment will be
+                // positioned right above the paired TaskFragment.
+                // This is needed in case we need to launch a placeholder Activity to split below a
+                // transparent always-expand Activity.
+                .setPairedPrimaryFragmentToken(launchingFragmentToken)
+                .build();
+        createTaskFragment(wct, fragmentOptions);
+        wct.startActivityInTaskFragment(secondaryFragmentToken, ownerToken, activityIntent,
                 activityOptions);
 
         // Set adjacent to each other so that the containers below will be invisible.
@@ -173,8 +183,21 @@
      */
     void createTaskFragment(@NonNull WindowContainerTransaction wct, @NonNull IBinder fragmentToken,
             @NonNull IBinder ownerToken, @NonNull Rect bounds, @WindowingMode int windowingMode) {
-        final TaskFragmentCreationParams fragmentOptions =
-                createFragmentOptions(fragmentToken, ownerToken, bounds, windowingMode);
+        final TaskFragmentCreationParams fragmentOptions = new TaskFragmentCreationParams.Builder(
+                getOrganizerToken(), fragmentToken, ownerToken)
+                .setInitialBounds(bounds)
+                .setWindowingMode(windowingMode)
+                .build();
+        createTaskFragment(wct, fragmentOptions);
+    }
+
+    void createTaskFragment(@NonNull WindowContainerTransaction wct,
+            @NonNull TaskFragmentCreationParams fragmentOptions) {
+        if (mFragmentInfos.containsKey(fragmentOptions.getFragmentToken())) {
+            throw new IllegalArgumentException(
+                    "There is an existing TaskFragment with fragmentToken="
+                            + fragmentOptions.getFragmentToken());
+        }
         wct.createTaskFragment(fragmentOptions);
     }
 
@@ -189,18 +212,6 @@
         wct.reparentActivityToTaskFragment(fragmentToken, activity.getActivityToken());
     }
 
-    /**
-     * @param ownerToken The token of the activity that creates this task fragment. It does not
-     *                   have to be a child of this task fragment, but must belong to the same task.
-     */
-    private void createTaskFragmentAndStartActivity(@NonNull WindowContainerTransaction wct,
-            @NonNull IBinder fragmentToken, @NonNull IBinder ownerToken, @NonNull Rect bounds,
-            @WindowingMode int windowingMode, @NonNull Intent activityIntent,
-            @Nullable Bundle activityOptions) {
-        createTaskFragment(wct, fragmentToken, ownerToken, bounds, windowingMode);
-        wct.startActivityInTaskFragment(fragmentToken, ownerToken, activityIntent, activityOptions);
-    }
-
     void setAdjacentTaskFragments(@NonNull WindowContainerTransaction wct,
             @NonNull IBinder primary, @Nullable IBinder secondary, @Nullable SplitRule splitRule) {
         WindowContainerTransaction.TaskFragmentAdjacentParams adjacentParams = null;
@@ -238,22 +249,6 @@
         wct.setCompanionTaskFragment(secondary, finishSecondaryWithPrimary ? primary : null);
     }
 
-    TaskFragmentCreationParams createFragmentOptions(@NonNull IBinder fragmentToken,
-            @NonNull IBinder ownerToken, @NonNull Rect bounds, @WindowingMode int windowingMode) {
-        if (mFragmentInfos.containsKey(fragmentToken)) {
-            throw new IllegalArgumentException(
-                    "There is an existing TaskFragment with fragmentToken=" + fragmentToken);
-        }
-
-        return new TaskFragmentCreationParams.Builder(
-                getOrganizerToken(),
-                fragmentToken,
-                ownerToken)
-                .setInitialBounds(bounds)
-                .setWindowingMode(windowingMode)
-                .build();
-    }
-
     void resizeTaskFragment(@NonNull WindowContainerTransaction wct, @NonNull IBinder fragmentToken,
             @Nullable Rect bounds) {
         if (!mFragmentInfos.containsKey(fragmentToken)) {
diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/SplitController.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/SplitController.java
index 6f9a4ff8..5afb1d1 100644
--- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/SplitController.java
+++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/SplitController.java
@@ -20,11 +20,11 @@
 import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
 import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
 import static android.view.Display.DEFAULT_DISPLAY;
-import static android.view.WindowManager.TRANSIT_CLOSE;
-import static android.view.WindowManager.TRANSIT_OPEN;
 import static android.window.TaskFragmentOrganizer.KEY_ERROR_CALLBACK_OP_TYPE;
 import static android.window.TaskFragmentOrganizer.KEY_ERROR_CALLBACK_TASK_FRAGMENT_INFO;
 import static android.window.TaskFragmentOrganizer.KEY_ERROR_CALLBACK_THROWABLE;
+import static android.window.TaskFragmentOrganizer.TASK_FRAGMENT_TRANSIT_CLOSE;
+import static android.window.TaskFragmentOrganizer.TASK_FRAGMENT_TRANSIT_OPEN;
 import static android.window.TaskFragmentTransaction.TYPE_ACTIVITY_REPARENTED_TO_TASK;
 import static android.window.TaskFragmentTransaction.TYPE_TASK_FRAGMENT_APPEARED;
 import static android.window.TaskFragmentTransaction.TYPE_TASK_FRAGMENT_ERROR;
@@ -340,7 +340,8 @@
 
         container.setInfo(wct, taskFragmentInfo);
         if (container.isFinished()) {
-            mTransactionManager.getCurrentTransactionRecord().setOriginType(TRANSIT_CLOSE);
+            mTransactionManager.getCurrentTransactionRecord()
+                    .setOriginType(TASK_FRAGMENT_TRANSIT_CLOSE);
             mPresenter.cleanupContainer(wct, container, false /* shouldFinishDependent */);
         } else {
             // Update with the latest Task configuration.
@@ -376,22 +377,27 @@
                 // Do not finish the dependents if the last activity is reparented to PiP.
                 // Instead, the original split should be cleanup, and the dependent may be
                 // expanded to fullscreen.
-                mTransactionManager.getCurrentTransactionRecord().setOriginType(TRANSIT_CLOSE);
+                mTransactionManager.getCurrentTransactionRecord()
+                        .setOriginType(TASK_FRAGMENT_TRANSIT_CLOSE);
                 cleanupForEnterPip(wct, container);
                 mPresenter.cleanupContainer(wct, container, false /* shouldFinishDependent */);
             } else if (taskFragmentInfo.isTaskClearedForReuse()) {
                 // Do not finish the dependents if this TaskFragment was cleared due to
                 // launching activity in the Task.
-                mTransactionManager.getCurrentTransactionRecord().setOriginType(TRANSIT_CLOSE);
+                mTransactionManager.getCurrentTransactionRecord()
+                        .setOriginType(TASK_FRAGMENT_TRANSIT_CLOSE);
                 mPresenter.cleanupContainer(wct, container, false /* shouldFinishDependent */);
             } else if (taskFragmentInfo.isClearedForReorderActivityToFront()) {
                 // Do not finish the dependents if this TaskFragment was cleared to reorder
                 // the launching Activity to front of the Task.
+                mTransactionManager.getCurrentTransactionRecord()
+                        .setOriginType(TASK_FRAGMENT_TRANSIT_CLOSE);
                 mPresenter.cleanupContainer(wct, container, false /* shouldFinishDependent */);
             } else if (!container.isWaitingActivityAppear()) {
                 // Do not finish the container before the expected activity appear until
                 // timeout.
-                mTransactionManager.getCurrentTransactionRecord().setOriginType(TRANSIT_CLOSE);
+                mTransactionManager.getCurrentTransactionRecord()
+                        .setOriginType(TASK_FRAGMENT_TRANSIT_CLOSE);
                 mPresenter.cleanupContainer(wct, container, true /* shouldFinishDependent */);
             }
         } else if (wasInPip && isInPip) {
@@ -585,7 +591,8 @@
                 container.setInfo(wct, taskFragmentInfo);
                 container.clearPendingAppearedActivities();
                 if (container.isEmpty()) {
-                    mTransactionManager.getCurrentTransactionRecord().setOriginType(TRANSIT_CLOSE);
+                    mTransactionManager.getCurrentTransactionRecord()
+                            .setOriginType(TASK_FRAGMENT_TRANSIT_CLOSE);
                     mPresenter.cleanupContainer(wct, container, false /* shouldFinishDependent */);
                 }
                 break;
@@ -1000,7 +1007,8 @@
     @GuardedBy("mLock")
     void onTaskFragmentAppearEmptyTimeout(@NonNull WindowContainerTransaction wct,
             @NonNull TaskFragmentContainer container) {
-        mTransactionManager.getCurrentTransactionRecord().setOriginType(TRANSIT_CLOSE);
+        mTransactionManager.getCurrentTransactionRecord()
+                .setOriginType(TASK_FRAGMENT_TRANSIT_CLOSE);
         mPresenter.cleanupContainer(wct, container, false /* shouldFinishDependent */);
     }
 
@@ -1218,14 +1226,14 @@
     TaskFragmentContainer newContainer(@NonNull Activity pendingAppearedActivity,
             @NonNull Activity activityInTask, int taskId) {
         return newContainer(pendingAppearedActivity, null /* pendingAppearedIntent */,
-                activityInTask, taskId);
+                activityInTask, taskId, null /* pairedPrimaryContainer */);
     }
 
     @GuardedBy("mLock")
     TaskFragmentContainer newContainer(@NonNull Intent pendingAppearedIntent,
             @NonNull Activity activityInTask, int taskId) {
         return newContainer(null /* pendingAppearedActivity */, pendingAppearedIntent,
-                activityInTask, taskId);
+                activityInTask, taskId, null /* pairedPrimaryContainer */);
     }
 
     /**
@@ -1237,10 +1245,13 @@
      * @param activityInTask            activity in the same Task so that we can get the Task bounds
      *                                  if needed.
      * @param taskId                    parent Task of the new TaskFragment.
+     * @param pairedPrimaryContainer    the paired primary {@link TaskFragmentContainer}. When it is
+     *                                  set, the new container will be added right above it.
      */
     @GuardedBy("mLock")
     TaskFragmentContainer newContainer(@Nullable Activity pendingAppearedActivity,
-            @Nullable Intent pendingAppearedIntent, @NonNull Activity activityInTask, int taskId) {
+            @Nullable Intent pendingAppearedIntent, @NonNull Activity activityInTask, int taskId,
+            @Nullable TaskFragmentContainer pairedPrimaryContainer) {
         if (activityInTask == null) {
             throw new IllegalArgumentException("activityInTask must not be null,");
         }
@@ -1249,7 +1260,7 @@
         }
         final TaskContainer taskContainer = mTaskContainers.get(taskId);
         final TaskFragmentContainer container = new TaskFragmentContainer(pendingAppearedActivity,
-                pendingAppearedIntent, taskContainer, this);
+                pendingAppearedIntent, taskContainer, this, pairedPrimaryContainer);
         return container;
     }
 
@@ -1563,7 +1574,8 @@
         // (not resumed yet).
         if (isOnCreated || primaryActivity.isResumed()) {
             // Only set trigger type if the launch happens in foreground.
-            mTransactionManager.getCurrentTransactionRecord().setOriginType(TRANSIT_OPEN);
+            mTransactionManager.getCurrentTransactionRecord()
+                    .setOriginType(TASK_FRAGMENT_TRANSIT_OPEN);
             return null;
         }
         final ActivityOptions options = ActivityOptions.makeBasic();
@@ -1591,7 +1603,8 @@
             return false;
         }
 
-        mTransactionManager.getCurrentTransactionRecord().setOriginType(TRANSIT_CLOSE);
+        mTransactionManager.getCurrentTransactionRecord()
+                .setOriginType(TASK_FRAGMENT_TRANSIT_CLOSE);
         mPresenter.cleanupContainer(wct, splitContainer.getSecondaryContainer(),
                 false /* shouldFinishDependent */);
         return true;
@@ -1891,7 +1904,7 @@
             synchronized (mLock) {
                 final TransactionRecord transactionRecord = mTransactionManager
                         .startNewTransaction();
-                transactionRecord.setOriginType(TRANSIT_OPEN);
+                transactionRecord.setOriginType(TASK_FRAGMENT_TRANSIT_OPEN);
                 SplitController.this.onActivityCreated(transactionRecord.getTransaction(),
                         activity);
                 // The WCT should be applied and merged to the activity launch transition.
@@ -1980,7 +1993,7 @@
             synchronized (mLock) {
                 final TransactionRecord transactionRecord = mTransactionManager
                         .startNewTransaction();
-                transactionRecord.setOriginType(TRANSIT_OPEN);
+                transactionRecord.setOriginType(TASK_FRAGMENT_TRANSIT_OPEN);
                 final WindowContainerTransaction wct = transactionRecord.getTransaction();
                 final TaskFragmentContainer launchedInTaskFragment;
                 if (launchingActivity != null) {
diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/SplitPresenter.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/SplitPresenter.java
index 5395fb2..47253d3 100644
--- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/SplitPresenter.java
+++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/SplitPresenter.java
@@ -36,6 +36,7 @@
 import android.view.View;
 import android.view.WindowInsets;
 import android.view.WindowMetrics;
+import android.window.TaskFragmentCreationParams;
 import android.window.WindowContainerTransaction;
 
 import androidx.annotation.GuardedBy;
@@ -307,10 +308,13 @@
         }
 
         final int taskId = primaryContainer.getTaskId();
-        final TaskFragmentContainer secondaryContainer = mController.newContainer(activityIntent,
-                launchingActivity, taskId);
-        final int windowingMode = mController.getTaskContainer(taskId)
-                .getWindowingModeForSplitTaskFragment(primaryRectBounds);
+        final TaskFragmentContainer secondaryContainer = mController.newContainer(
+                null /* pendingAppearedActivity */, activityIntent, launchingActivity, taskId,
+                // Pass in the primary container to make sure it is added right above the primary.
+                primaryContainer);
+        final TaskContainer taskContainer = mController.getTaskContainer(taskId);
+        final int windowingMode = taskContainer.getWindowingModeForSplitTaskFragment(
+                primaryRectBounds);
         mController.registerSplit(wct, primaryContainer, launchingActivity, secondaryContainer,
                 rule, splitAttributes);
         startActivityToSide(wct, primaryContainer.getTaskFragmentToken(), primaryRectBounds,
@@ -412,17 +416,18 @@
     }
 
     @Override
-    void createTaskFragment(@NonNull WindowContainerTransaction wct, @NonNull IBinder fragmentToken,
-            @NonNull IBinder ownerToken, @NonNull Rect bounds, @WindowingMode int windowingMode) {
-        final TaskFragmentContainer container = mController.getContainer(fragmentToken);
+    void createTaskFragment(@NonNull WindowContainerTransaction wct,
+            @NonNull TaskFragmentCreationParams fragmentOptions) {
+        final TaskFragmentContainer container = mController.getContainer(
+                fragmentOptions.getFragmentToken());
         if (container == null) {
             throw new IllegalStateException(
                     "Creating a task fragment that is not registered with controller.");
         }
 
-        container.setLastRequestedBounds(bounds);
-        container.setLastRequestedWindowingMode(windowingMode);
-        super.createTaskFragment(wct, fragmentToken, ownerToken, bounds, windowingMode);
+        container.setLastRequestedBounds(fragmentOptions.getInitialBounds());
+        container.setLastRequestedWindowingMode(fragmentOptions.getWindowingMode());
+        super.createTaskFragment(wct, fragmentOptions);
     }
 
     @Override
diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskFragmentAnimationRunner.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskFragmentAnimationRunner.java
index 322f854..dcc12ac 100644
--- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskFragmentAnimationRunner.java
+++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskFragmentAnimationRunner.java
@@ -19,6 +19,7 @@
 import static android.os.Process.THREAD_PRIORITY_DISPLAY;
 import static android.view.RemoteAnimationTarget.MODE_CHANGING;
 import static android.view.RemoteAnimationTarget.MODE_CLOSING;
+import static android.view.RemoteAnimationTarget.MODE_OPENING;
 import static android.view.WindowManager.TRANSIT_OLD_ACTIVITY_CLOSE;
 import static android.view.WindowManager.TRANSIT_OLD_ACTIVITY_OPEN;
 import static android.view.WindowManager.TRANSIT_OLD_TASK_FRAGMENT_CHANGE;
@@ -253,6 +254,10 @@
     @NonNull
     private List<TaskFragmentAnimationAdapter> createChangeAnimationAdapters(
             @NonNull RemoteAnimationTarget[] targets) {
+        if (shouldUseJumpCutForChangeAnimation(targets)) {
+            return new ArrayList<>();
+        }
+
         final List<TaskFragmentAnimationAdapter> adapters = new ArrayList<>();
         for (RemoteAnimationTarget target : targets) {
             if (target.mode == MODE_CHANGING) {
@@ -282,4 +287,24 @@
         }
         return adapters;
     }
+
+    /**
+     * Whether we should use jump cut for the change transition.
+     * This normally happens when opening a new secondary with the existing primary using a
+     * different split layout. This can be complicated, like from horizontal to vertical split with
+     * new split pairs.
+     * Uses a jump cut animation to simplify.
+     */
+    private boolean shouldUseJumpCutForChangeAnimation(@NonNull RemoteAnimationTarget[] targets) {
+        boolean hasOpeningWindow = false;
+        boolean hasClosingWindow = false;
+        for (RemoteAnimationTarget target : targets) {
+            if (target.hasAnimatingParent) {
+                continue;
+            }
+            hasOpeningWindow |= target.mode == MODE_OPENING;
+            hasClosingWindow |= target.mode == MODE_CLOSING;
+        }
+        return hasOpeningWindow && hasClosingWindow;
+    }
 }
diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskFragmentContainer.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskFragmentContainer.java
index e31792a..fcf0ac7 100644
--- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskFragmentContainer.java
+++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskFragmentContainer.java
@@ -118,10 +118,12 @@
     /**
      * Creates a container with an existing activity that will be re-parented to it in a window
      * container transaction.
+     * @param pairedPrimaryContainer    when it is set, the new container will be add right above it
      */
     TaskFragmentContainer(@Nullable Activity pendingAppearedActivity,
             @Nullable Intent pendingAppearedIntent, @NonNull TaskContainer taskContainer,
-            @NonNull SplitController controller) {
+            @NonNull SplitController controller,
+            @Nullable TaskFragmentContainer pairedPrimaryContainer) {
         if ((pendingAppearedActivity == null && pendingAppearedIntent == null)
                 || (pendingAppearedActivity != null && pendingAppearedIntent != null)) {
             throw new IllegalArgumentException(
@@ -130,7 +132,16 @@
         mController = controller;
         mToken = new Binder("TaskFragmentContainer");
         mTaskContainer = taskContainer;
-        taskContainer.mContainers.add(this);
+        if (pairedPrimaryContainer != null) {
+            if (pairedPrimaryContainer.getTaskContainer() != taskContainer) {
+                throw new IllegalArgumentException(
+                        "pairedPrimaryContainer must be in the same Task");
+            }
+            final int primaryIndex = taskContainer.mContainers.indexOf(pairedPrimaryContainer);
+            taskContainer.mContainers.add(primaryIndex + 1, this);
+        } else {
+            taskContainer.mContainers.add(this);
+        }
         if (pendingAppearedActivity != null) {
             addPendingAppearedActivity(pendingAppearedActivity);
         }
diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TransactionManager.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TransactionManager.java
index 0071fea..396956e 100644
--- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TransactionManager.java
+++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TransactionManager.java
@@ -16,12 +16,12 @@
 
 package androidx.window.extensions.embedding;
 
-import static android.view.WindowManager.TRANSIT_CHANGE;
-import static android.view.WindowManager.TRANSIT_NONE;
+import static android.window.TaskFragmentOrganizer.TASK_FRAGMENT_TRANSIT_CHANGE;
+import static android.window.TaskFragmentOrganizer.TASK_FRAGMENT_TRANSIT_NONE;
 
 import android.os.IBinder;
-import android.view.WindowManager.TransitionType;
 import android.window.TaskFragmentOrganizer;
+import android.window.TaskFragmentOrganizer.TaskFragmentTransitionType;
 import android.window.WindowContainerTransaction;
 
 import androidx.annotation.NonNull;
@@ -122,8 +122,8 @@
          * @see #setOriginType(int)
          * @see #getTransactionTransitionType()
          */
-        @TransitionType
-        private int mOriginType = TRANSIT_NONE;
+        @TaskFragmentTransitionType
+        private int mOriginType = TASK_FRAGMENT_TRANSIT_NONE;
 
         TransactionRecord(@Nullable IBinder taskFragmentTransactionToken) {
             mTaskFragmentTransactionToken = taskFragmentTransactionToken;
@@ -136,12 +136,12 @@
         }
 
         /**
-         * Sets the {@link TransitionType} that triggers this transaction. If there are multiple
-         * calls, only the first call will be respected as the "origin" type.
+         * Sets the {@link TaskFragmentTransitionType} that triggers this transaction. If there are
+         * multiple calls, only the first call will be respected as the "origin" type.
          */
-        void setOriginType(@TransitionType int type) {
+        void setOriginType(@TaskFragmentTransitionType int type) {
             ensureCurrentTransaction();
-            if (mOriginType != TRANSIT_NONE) {
+            if (mOriginType != TASK_FRAGMENT_TRANSIT_NONE) {
                 // Skip if the origin type has already been set.
                 return;
             }
@@ -188,14 +188,16 @@
         }
 
         /**
-         * Gets the {@link TransitionType} that we will request transition with for the
+         * Gets the {@link TaskFragmentTransitionType} that we will request transition with for the
          * current {@link WindowContainerTransaction}.
          */
         @VisibleForTesting
-        @TransitionType
+        @TaskFragmentTransitionType
         int getTransactionTransitionType() {
-            // Use TRANSIT_CHANGE as default if there is not opening/closing window.
-            return mOriginType != TRANSIT_NONE ? mOriginType : TRANSIT_CHANGE;
+            // Use TASK_FRAGMENT_TRANSIT_CHANGE as default if there is not opening/closing window.
+            return mOriginType != TASK_FRAGMENT_TRANSIT_NONE
+                    ? mOriginType
+                    : TASK_FRAGMENT_TRANSIT_CHANGE;
         }
     }
 }
diff --git a/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/JetpackTaskFragmentOrganizerTest.java b/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/JetpackTaskFragmentOrganizerTest.java
index 31aa09c..bbb454d 100644
--- a/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/JetpackTaskFragmentOrganizerTest.java
+++ b/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/JetpackTaskFragmentOrganizerTest.java
@@ -102,7 +102,7 @@
     public void testExpandTaskFragment() {
         final TaskContainer taskContainer = createTestTaskContainer();
         final TaskFragmentContainer container = new TaskFragmentContainer(null /* activity */,
-                new Intent(), taskContainer, mSplitController);
+                new Intent(), taskContainer, mSplitController, null /* pairedPrimaryContainer */);
         final TaskFragmentInfo info = createMockInfo(container);
         mOrganizer.mFragmentInfos.put(container.getTaskFragmentToken(), info);
         container.setInfo(mTransaction, info);
diff --git a/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/SplitControllerTest.java b/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/SplitControllerTest.java
index 221c764..6725dfd 100644
--- a/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/SplitControllerTest.java
+++ b/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/SplitControllerTest.java
@@ -169,7 +169,7 @@
         final TaskContainer taskContainer = createTestTaskContainer();
         // tf1 has no running activity so is not active.
         final TaskFragmentContainer tf1 = new TaskFragmentContainer(null /* activity */,
-                new Intent(), taskContainer, mSplitController);
+                new Intent(), taskContainer, mSplitController, null /* pairedPrimaryContainer */);
         // tf2 has running activity so is active.
         final TaskFragmentContainer tf2 = mock(TaskFragmentContainer.class);
         doReturn(1).when(tf2).getRunningActivityCount();
@@ -375,7 +375,7 @@
         final Intent intent = new Intent();
         final TaskContainer taskContainer = createTestTaskContainer();
         final TaskFragmentContainer container = new TaskFragmentContainer(null /* activity */,
-                intent, taskContainer, mSplitController);
+                intent, taskContainer, mSplitController, null /* pairedPrimaryContainer */);
         final SplitController.ActivityStartMonitor monitor =
                 mSplitController.getActivityStartMonitor();
 
@@ -609,7 +609,7 @@
                 false /* isOnReparent */);
 
         assertFalse(result);
-        verify(mSplitController, never()).newContainer(any(), any(), any(), anyInt());
+        verify(mSplitController, never()).newContainer(any(), any(), any(), anyInt(), any());
     }
 
     @Test
@@ -771,7 +771,7 @@
                 false /* isOnReparent */);
 
         assertTrue(result);
-        verify(mSplitController, never()).newContainer(any(), any(), any(), anyInt());
+        verify(mSplitController, never()).newContainer(any(), any(), any(), anyInt(), any());
         verify(mSplitController, never()).registerSplit(any(), any(), any(), any(), any(), any());
     }
 
@@ -813,7 +813,7 @@
                 false /* isOnReparent */);
 
         assertTrue(result);
-        verify(mSplitController, never()).newContainer(any(), any(), any(), anyInt());
+        verify(mSplitController, never()).newContainer(any(), any(), any(), anyInt(), any());
         verify(mSplitController, never()).registerSplit(any(), any(), any(), any(), any(), any());
     }
 
diff --git a/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TaskContainerTest.java b/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TaskContainerTest.java
index 95328ce..13e7092 100644
--- a/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TaskContainerTest.java
+++ b/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TaskContainerTest.java
@@ -122,7 +122,7 @@
         assertTrue(taskContainer.isEmpty());
 
         final TaskFragmentContainer tf = new TaskFragmentContainer(null /* activity */,
-                new Intent(), taskContainer, mController);
+                new Intent(), taskContainer, mController, null /* pairedPrimaryContainer */);
 
         assertFalse(taskContainer.isEmpty());
 
@@ -138,11 +138,11 @@
         assertNull(taskContainer.getTopTaskFragmentContainer());
 
         final TaskFragmentContainer tf0 = new TaskFragmentContainer(null /* activity */,
-                new Intent(), taskContainer, mController);
+                new Intent(), taskContainer, mController, null /* pairedPrimaryContainer */);
         assertEquals(tf0, taskContainer.getTopTaskFragmentContainer());
 
         final TaskFragmentContainer tf1 = new TaskFragmentContainer(null /* activity */,
-                new Intent(), taskContainer, mController);
+                new Intent(), taskContainer, mController, null /* pairedPrimaryContainer */);
         assertEquals(tf1, taskContainer.getTopTaskFragmentContainer());
     }
 
diff --git a/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TaskFragmentContainerTest.java b/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TaskFragmentContainerTest.java
index 99f56b4..5c3ba72 100644
--- a/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TaskFragmentContainerTest.java
+++ b/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TaskFragmentContainerTest.java
@@ -94,18 +94,21 @@
 
         // One of the activity and the intent must be non-null
         assertThrows(IllegalArgumentException.class,
-                () -> new TaskFragmentContainer(null, null, taskContainer, mController));
+                () -> new TaskFragmentContainer(null, null, taskContainer, mController,
+                        null /* pairedPrimaryContainer */));
 
         // One of the activity and the intent must be null.
         assertThrows(IllegalArgumentException.class,
-                () -> new TaskFragmentContainer(mActivity, mIntent, taskContainer, mController));
+                () -> new TaskFragmentContainer(mActivity, mIntent, taskContainer, mController,
+                        null /* pairedPrimaryContainer */));
     }
 
     @Test
     public void testFinish() {
         final TaskContainer taskContainer = createTestTaskContainer();
         final TaskFragmentContainer container = new TaskFragmentContainer(mActivity,
-                null /* pendingAppearedIntent */, taskContainer, mController);
+                null /* pendingAppearedIntent */, taskContainer, mController,
+                null /* pairedPrimaryContainer */);
         doReturn(container).when(mController).getContainerWithActivity(mActivity);
 
         // Only remove the activity, but not clear the reference until appeared.
@@ -137,12 +140,14 @@
     public void testFinish_notFinishActivityThatIsReparenting() {
         final TaskContainer taskContainer = createTestTaskContainer();
         final TaskFragmentContainer container0 = new TaskFragmentContainer(mActivity,
-                null /* pendingAppearedIntent */, taskContainer, mController);
+                null /* pendingAppearedIntent */, taskContainer, mController,
+                null /* pairedPrimaryContainer */);
         final TaskFragmentInfo info = createMockTaskFragmentInfo(container0, mActivity);
         container0.setInfo(mTransaction, info);
         // Request to reparent the activity to a new TaskFragment.
         final TaskFragmentContainer container1 = new TaskFragmentContainer(mActivity,
-                null /* pendingAppearedIntent */, taskContainer, mController);
+                null /* pendingAppearedIntent */, taskContainer, mController,
+                null /* pairedPrimaryContainer */);
         doReturn(container1).when(mController).getContainerWithActivity(mActivity);
         final WindowContainerTransaction wct = new WindowContainerTransaction();
 
@@ -159,7 +164,8 @@
         final TaskContainer taskContainer = createTestTaskContainer();
         // Pending activity should be cleared when it has appeared on server side.
         final TaskFragmentContainer pendingActivityContainer = new TaskFragmentContainer(mActivity,
-                null /* pendingAppearedIntent */, taskContainer, mController);
+                null /* pendingAppearedIntent */, taskContainer, mController,
+                null /* pairedPrimaryContainer */);
 
         assertTrue(pendingActivityContainer.mPendingAppearedActivities.contains(
                 mActivity.getActivityToken()));
@@ -172,7 +178,8 @@
 
         // Pending intent should be cleared when the container becomes non-empty.
         final TaskFragmentContainer pendingIntentContainer = new TaskFragmentContainer(
-                null /* pendingAppearedActivity */, mIntent, taskContainer, mController);
+                null /* pendingAppearedActivity */, mIntent, taskContainer, mController,
+                null /* pairedPrimaryContainer */);
 
         assertEquals(mIntent, pendingIntentContainer.getPendingAppearedIntent());
 
@@ -187,7 +194,7 @@
     public void testIsWaitingActivityAppear() {
         final TaskContainer taskContainer = createTestTaskContainer();
         final TaskFragmentContainer container = new TaskFragmentContainer(null /* activity */,
-                mIntent, taskContainer, mController);
+                mIntent, taskContainer, mController, null /* pairedPrimaryContainer */);
 
         assertTrue(container.isWaitingActivityAppear());
 
@@ -209,7 +216,7 @@
         doNothing().when(mController).onTaskFragmentAppearEmptyTimeout(any(), any());
         final TaskContainer taskContainer = createTestTaskContainer();
         final TaskFragmentContainer container = new TaskFragmentContainer(null /* activity */,
-                mIntent, taskContainer, mController);
+                mIntent, taskContainer, mController, null /* pairedPrimaryContainer */);
 
         assertNull(container.mAppearEmptyTimeout);
 
@@ -249,7 +256,7 @@
     public void testCollectNonFinishingActivities() {
         final TaskContainer taskContainer = createTestTaskContainer();
         final TaskFragmentContainer container = new TaskFragmentContainer(null /* activity */,
-                mIntent, taskContainer, mController);
+                mIntent, taskContainer, mController, null /* pairedPrimaryContainer */);
         List<Activity> activities = container.collectNonFinishingActivities();
 
         assertTrue(activities.isEmpty());
@@ -277,7 +284,7 @@
     public void testAddPendingActivity() {
         final TaskContainer taskContainer = createTestTaskContainer();
         final TaskFragmentContainer container = new TaskFragmentContainer(null /* activity */,
-                mIntent, taskContainer, mController);
+                mIntent, taskContainer, mController, null /* pairedPrimaryContainer */);
         container.addPendingAppearedActivity(mActivity);
 
         assertEquals(1, container.collectNonFinishingActivities().size());
@@ -291,9 +298,9 @@
     public void testIsAbove() {
         final TaskContainer taskContainer = createTestTaskContainer();
         final TaskFragmentContainer container0 = new TaskFragmentContainer(null /* activity */,
-                mIntent, taskContainer, mController);
+                mIntent, taskContainer, mController, null /* pairedPrimaryContainer */);
         final TaskFragmentContainer container1 = new TaskFragmentContainer(null /* activity */,
-                mIntent, taskContainer, mController);
+                mIntent, taskContainer, mController, null /* pairedPrimaryContainer */);
 
         assertTrue(container1.isAbove(container0));
         assertFalse(container0.isAbove(container1));
@@ -303,7 +310,7 @@
     public void testGetBottomMostActivity() {
         final TaskContainer taskContainer = createTestTaskContainer();
         final TaskFragmentContainer container = new TaskFragmentContainer(null /* activity */,
-                mIntent, taskContainer, mController);
+                mIntent, taskContainer, mController, null /* pairedPrimaryContainer */);
         container.addPendingAppearedActivity(mActivity);
 
         assertEquals(mActivity, container.getBottomMostActivity());
@@ -320,7 +327,7 @@
     public void testOnActivityDestroyed() {
         final TaskContainer taskContainer = createTestTaskContainer(mController);
         final TaskFragmentContainer container = new TaskFragmentContainer(null /* activity */,
-                mIntent, taskContainer, mController);
+                mIntent, taskContainer, mController, null /* pairedPrimaryContainer */);
         container.addPendingAppearedActivity(mActivity);
         final List<IBinder> activities = new ArrayList<>();
         activities.add(mActivity.getActivityToken());
@@ -340,7 +347,7 @@
         // True if no info set.
         final TaskContainer taskContainer = createTestTaskContainer();
         final TaskFragmentContainer container = new TaskFragmentContainer(null /* activity */,
-                mIntent, taskContainer, mController);
+                mIntent, taskContainer, mController, null /* pairedPrimaryContainer */);
         spyOn(taskContainer);
         doReturn(true).when(taskContainer).isVisible();
 
@@ -403,7 +410,7 @@
     public void testHasAppearedActivity() {
         final TaskContainer taskContainer = createTestTaskContainer();
         final TaskFragmentContainer container = new TaskFragmentContainer(null /* activity */,
-                mIntent, taskContainer, mController);
+                mIntent, taskContainer, mController, null /* pairedPrimaryContainer */);
         container.addPendingAppearedActivity(mActivity);
 
         assertFalse(container.hasAppearedActivity(mActivity.getActivityToken()));
@@ -420,7 +427,7 @@
     public void testHasPendingAppearedActivity() {
         final TaskContainer taskContainer = createTestTaskContainer();
         final TaskFragmentContainer container = new TaskFragmentContainer(null /* activity */,
-                mIntent, taskContainer, mController);
+                mIntent, taskContainer, mController, null /* pairedPrimaryContainer */);
         container.addPendingAppearedActivity(mActivity);
 
         assertTrue(container.hasPendingAppearedActivity(mActivity.getActivityToken()));
@@ -437,9 +444,9 @@
     public void testHasActivity() {
         final TaskContainer taskContainer = createTestTaskContainer(mController);
         final TaskFragmentContainer container1 = new TaskFragmentContainer(null /* activity */,
-                mIntent, taskContainer, mController);
+                mIntent, taskContainer, mController, null /* pairedPrimaryContainer */);
         final TaskFragmentContainer container2 = new TaskFragmentContainer(null /* activity */,
-                mIntent, taskContainer, mController);
+                mIntent, taskContainer, mController, null /* pairedPrimaryContainer */);
 
         // Activity is pending appeared on container2.
         container2.addPendingAppearedActivity(mActivity);
@@ -472,6 +479,27 @@
         assertTrue(container2.hasActivity(mActivity.getActivityToken()));
     }
 
+    @Test
+    public void testNewContainerWithPairedPrimaryContainer() {
+        final TaskContainer taskContainer = createTestTaskContainer();
+        final TaskFragmentContainer tf0 = new TaskFragmentContainer(
+                null /* pendingAppearedActivity */, new Intent(), taskContainer, mController,
+                null /* pairedPrimaryTaskFragment */);
+        final TaskFragmentContainer tf1 = new TaskFragmentContainer(
+                null /* pendingAppearedActivity */, new Intent(), taskContainer, mController,
+                null /* pairedPrimaryTaskFragment */);
+        taskContainer.mContainers.add(tf0);
+        taskContainer.mContainers.add(tf1);
+
+        // When tf2 is created with using tf0 as pairedPrimaryContainer, tf2 should be inserted
+        // right above tf0.
+        final TaskFragmentContainer tf2 = new TaskFragmentContainer(
+                null /* pendingAppearedActivity */, new Intent(), taskContainer, mController, tf0);
+        assertEquals(0, taskContainer.indexOf(tf0));
+        assertEquals(1, taskContainer.indexOf(tf2));
+        assertEquals(2, taskContainer.indexOf(tf1));
+    }
+
     /** Creates a mock activity in the organizer process. */
     private Activity createMockActivity() {
         final Activity activity = mock(Activity.class);
diff --git a/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TransactionManagerTest.java b/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TransactionManagerTest.java
index 62006bd..459b6d2 100644
--- a/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TransactionManagerTest.java
+++ b/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TransactionManagerTest.java
@@ -16,9 +16,9 @@
 
 package androidx.window.extensions.embedding;
 
-import static android.view.WindowManager.TRANSIT_CHANGE;
-import static android.view.WindowManager.TRANSIT_CLOSE;
-import static android.view.WindowManager.TRANSIT_OPEN;
+import static android.window.TaskFragmentOrganizer.TASK_FRAGMENT_TRANSIT_CHANGE;
+import static android.window.TaskFragmentOrganizer.TASK_FRAGMENT_TRANSIT_CLOSE;
+import static android.window.TaskFragmentOrganizer.TASK_FRAGMENT_TRANSIT_OPEN;
 
 import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
 import static com.android.dx.mockito.inline.extended.ExtendedMockito.verifyNoMoreInteractions;
@@ -86,27 +86,29 @@
 
     @Test
     public void testSetTransactionOriginType() {
-        // Return TRANSIT_CHANGE if there is no trigger type set.
+        // Return TASK_FRAGMENT_TRANSIT_CHANGE if there is no trigger type set.
         TransactionRecord transactionRecord = mTransactionManager.startNewTransaction();
 
-        assertEquals(TRANSIT_CHANGE, transactionRecord.getTransactionTransitionType());
+        assertEquals(TASK_FRAGMENT_TRANSIT_CHANGE,
+                transactionRecord.getTransactionTransitionType());
 
         // Return the first set type.
         mTransactionManager.getCurrentTransactionRecord().abort();
         transactionRecord = mTransactionManager.startNewTransaction();
-        transactionRecord.setOriginType(TRANSIT_OPEN);
+        transactionRecord.setOriginType(TASK_FRAGMENT_TRANSIT_OPEN);
 
-        assertEquals(TRANSIT_OPEN, transactionRecord.getTransactionTransitionType());
+        assertEquals(TASK_FRAGMENT_TRANSIT_OPEN, transactionRecord.getTransactionTransitionType());
 
-        transactionRecord.setOriginType(TRANSIT_CLOSE);
+        transactionRecord.setOriginType(TASK_FRAGMENT_TRANSIT_CLOSE);
 
-        assertEquals(TRANSIT_OPEN, transactionRecord.getTransactionTransitionType());
+        assertEquals(TASK_FRAGMENT_TRANSIT_OPEN, transactionRecord.getTransactionTransitionType());
 
         // Reset when #startNewTransaction().
         transactionRecord.abort();
         transactionRecord = mTransactionManager.startNewTransaction();
 
-        assertEquals(TRANSIT_CHANGE, transactionRecord.getTransactionTransitionType());
+        assertEquals(TASK_FRAGMENT_TRANSIT_CHANGE,
+                transactionRecord.getTransactionTransitionType());
     }
 
     @Test
diff --git a/libs/WindowManager/Shell/AndroidManifest.xml b/libs/WindowManager/Shell/AndroidManifest.xml
index 8881be7..36d3313 100644
--- a/libs/WindowManager/Shell/AndroidManifest.xml
+++ b/libs/WindowManager/Shell/AndroidManifest.xml
@@ -21,5 +21,6 @@
     <uses-permission android:name="android.permission.CAPTURE_BLACKOUT_CONTENT" />
     <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
     <uses-permission android:name="android.permission.ROTATE_SURFACE_FLINGER" />
+    <uses-permission android:name="android.permission.WAKEUP_SURFACE_FLINGER" />
     <uses-permission android:name="android.permission.READ_FRAME_BUFFER" />
 </manifest>
diff --git a/libs/WindowManager/Shell/res/layout/tv_pip_menu.xml b/libs/WindowManager/Shell/res/layout/tv_pip_menu.xml
index 70755e6..dcce4698 100644
--- a/libs/WindowManager/Shell/res/layout/tv_pip_menu.xml
+++ b/libs/WindowManager/Shell/res/layout/tv_pip_menu.xml
@@ -44,67 +44,15 @@
             android:background="@color/tv_pip_menu_dim_layer"
             android:alpha="0"/>
 
-        <ScrollView
-            android:id="@+id/tv_pip_menu_scroll"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:scrollbars="none"
-            android:visibility="gone"/>
-
-        <HorizontalScrollView
-            android:id="@+id/tv_pip_menu_horizontal_scroll"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:scrollbars="none">
-
-            <LinearLayout
-                android:id="@+id/tv_pip_menu_action_buttons"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:orientation="horizontal"
-                android:alpha="0">
-
-                <Space
-                    android:layout_width="@dimen/pip_menu_button_wrapper_margin"
-                    android:layout_height="@dimen/pip_menu_button_wrapper_margin"/>
-
-                <com.android.wm.shell.common.TvWindowMenuActionButton
-                    android:id="@+id/tv_pip_menu_fullscreen_button"
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:src="@drawable/pip_ic_fullscreen_white"
-                    android:text="@string/pip_fullscreen" />
-
-                <com.android.wm.shell.common.TvWindowMenuActionButton
-                    android:id="@+id/tv_pip_menu_close_button"
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:src="@drawable/pip_ic_close_white"
-                    android:text="@string/pip_close" />
-
-                <!-- More TvWindowMenuActionButtons may be added here at runtime. -->
-
-                <com.android.wm.shell.common.TvWindowMenuActionButton
-                    android:id="@+id/tv_pip_menu_move_button"
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:src="@drawable/pip_ic_move_white"
-                    android:text="@string/pip_move" />
-
-                <com.android.wm.shell.common.TvWindowMenuActionButton
-                    android:id="@+id/tv_pip_menu_expand_button"
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:src="@drawable/pip_ic_collapse"
-                    android:visibility="gone"
-                    android:text="@string/pip_collapse" />
-
-                <Space
-                    android:layout_width="@dimen/pip_menu_button_wrapper_margin"
-                    android:layout_height="@dimen/pip_menu_button_wrapper_margin"/>
-
-            </LinearLayout>
-        </HorizontalScrollView>
+        <com.android.internal.widget.RecyclerView
+            android:id="@+id/tv_pip_menu_action_buttons"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center"
+            android:padding="@dimen/pip_menu_button_start_end_offset"
+            android:clipToPadding="false"
+            android:alpha="0"
+            android:contentDescription="@string/a11y_pip_menu_entered"/>
     </FrameLayout>
 
     <!-- Frame around the content, just overlapping the corners to make them round -->
diff --git a/libs/WindowManager/Shell/res/layout/tv_window_menu_action_button.xml b/libs/WindowManager/Shell/res/layout/tv_window_menu_action_button.xml
index c4dbd39..b2ac85b 100644
--- a/libs/WindowManager/Shell/res/layout/tv_window_menu_action_button.xml
+++ b/libs/WindowManager/Shell/res/layout/tv_window_menu_action_button.xml
@@ -21,6 +21,7 @@
     android:layout_width="@dimen/tv_window_menu_button_size"
     android:layout_height="@dimen/tv_window_menu_button_size"
     android:padding="@dimen/tv_window_menu_button_margin"
+    android:duplicateParentState="true"
     android:stateListAnimator="@animator/tv_window_menu_action_button_animator"
     android:focusable="true">
 
diff --git a/libs/WindowManager/Shell/res/values-am/strings.xml b/libs/WindowManager/Shell/res/values-am/strings.xml
index 51de2e5..8b46704 100644
--- a/libs/WindowManager/Shell/res/values-am/strings.xml
+++ b/libs/WindowManager/Shell/res/values-am/strings.xml
@@ -22,8 +22,8 @@
     <string name="pip_phone_settings" msgid="5468987116750491918">"ቅንብሮች"</string>
     <string name="pip_phone_enter_split" msgid="7042877263880641911">"የተከፈለ ማያ ገጽን አስገባ"</string>
     <string name="pip_menu_title" msgid="5393619322111827096">"ምናሌ"</string>
-    <string name="pip_menu_accessibility_title" msgid="8129016817688656249">"የስዕል-ላይ-ስዕል ምናሌ"</string>
-    <string name="pip_notification_title" msgid="1347104727641353453">"<xliff:g id="NAME">%s</xliff:g> በስዕል-ላይ-ስዕል ውስጥ ነው"</string>
+    <string name="pip_menu_accessibility_title" msgid="8129016817688656249">"የሥዕል-ላይ-ሥዕል ምናሌ"</string>
+    <string name="pip_notification_title" msgid="1347104727641353453">"<xliff:g id="NAME">%s</xliff:g> በሥዕል-ላይ-ሥዕል ውስጥ ነው"</string>
     <string name="pip_notification_message" msgid="8854051911700302620">"<xliff:g id="NAME">%s</xliff:g> ይህን ባህሪ እንዲጠቀም ካልፈለጉ ቅንብሮችን ለመክፈት መታ ያድርጉና ያጥፉት።"</string>
     <string name="pip_play" msgid="3496151081459417097">"አጫውት"</string>
     <string name="pip_pause" msgid="690688849510295232">"ባለበት አቁም"</string>
diff --git a/libs/WindowManager/Shell/res/values-am/strings_tv.xml b/libs/WindowManager/Shell/res/values-am/strings_tv.xml
index d64c051..a6be578 100644
--- a/libs/WindowManager/Shell/res/values-am/strings_tv.xml
+++ b/libs/WindowManager/Shell/res/values-am/strings_tv.xml
@@ -17,7 +17,7 @@
 
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="notification_channel_tv_pip" msgid="2576686079160402435">"ስዕል-ላይ-ስዕል"</string>
+    <string name="notification_channel_tv_pip" msgid="2576686079160402435">"ሥዕል-ላይ-ሥዕል"</string>
     <string name="pip_notification_unknown_title" msgid="2729870284350772311">"(ርዕስ የሌለው ፕሮግራም)"</string>
     <string name="pip_close" msgid="2955969519031223530">"ዝጋ"</string>
     <string name="pip_fullscreen" msgid="7278047353591302554">"ሙሉ ማያ ገጽ"</string>
@@ -25,7 +25,7 @@
     <string name="pip_expand" msgid="1051966011679297308">"ዘርጋ"</string>
     <string name="pip_collapse" msgid="3903295106641385962">"ሰብስብ"</string>
     <string name="pip_edu_text" msgid="7930546669915337998">"ለመቆጣጠሪያዎች "<annotation icon="home_icon">"መነሻ"</annotation>"ን ሁለቴ ይጫኑ"</string>
-    <string name="a11y_pip_menu_entered" msgid="5106343214776801614">"የስዕል-ላይ-ስዕል ምናሌ።"</string>
+    <string name="a11y_pip_menu_entered" msgid="5106343214776801614">"የሥዕል-ላይ-ሥዕል ምናሌ።"</string>
     <string name="a11y_action_pip_move_left" msgid="6612980937817141583">"ወደ ግራ ውሰድ"</string>
     <string name="a11y_action_pip_move_right" msgid="1119409122645529936">"ወደ ቀኝ ውሰድ"</string>
     <string name="a11y_action_pip_move_up" msgid="98502616918621959">"ወደ ላይ ውሰድ"</string>
diff --git a/libs/WindowManager/Shell/res/values-hi/strings.xml b/libs/WindowManager/Shell/res/values-hi/strings.xml
index 1a7cf3e..9a926d8 100644
--- a/libs/WindowManager/Shell/res/values-hi/strings.xml
+++ b/libs/WindowManager/Shell/res/values-hi/strings.xml
@@ -34,8 +34,7 @@
     <string name="accessibility_action_pip_unstash" msgid="7467499339610437646">"दिखाएं"</string>
     <string name="dock_forced_resizable" msgid="1749750436092293116">"ऐप्लिकेशन शायद स्प्लिट स्क्रीन मोड में काम न करे."</string>
     <string name="dock_non_resizeble_failed_to_dock_text" msgid="7408396418008948957">"ऐप विभाजित स्‍क्रीन का समर्थन नहीं करता है."</string>
-    <!-- no translation found for dock_multi_instances_not_supported_text (5242868470666346929) -->
-    <skip />
+    <string name="dock_multi_instances_not_supported_text" msgid="5242868470666346929">"इस ऐप्लिकेशन को सिर्फ़ एक विंडो में खोला जा सकता है."</string>
     <string name="forced_resizable_secondary_display" msgid="1768046938673582671">"हो सकता है कि ऐप प्राइमरी (मुख्य) डिस्प्ले के अलावा बाकी दूसरे डिस्प्ले पर काम न करे."</string>
     <string name="activity_launch_on_secondary_display_failed_text" msgid="4226485344988071769">"प्राइमरी (मुख्य) डिस्प्ले के अलावा बाकी दूसरे डिस्प्ले पर ऐप लॉन्च नहीं किया जा सकता."</string>
     <string name="accessibility_divider" msgid="703810061635792791">"विभाजित स्क्रीन विभाजक"</string>
diff --git a/libs/WindowManager/Shell/res/values-ml/strings.xml b/libs/WindowManager/Shell/res/values-ml/strings.xml
index 1f2ee77..0923312 100644
--- a/libs/WindowManager/Shell/res/values-ml/strings.xml
+++ b/libs/WindowManager/Shell/res/values-ml/strings.xml
@@ -34,8 +34,7 @@
     <string name="accessibility_action_pip_unstash" msgid="7467499339610437646">"അൺസ്റ്റാഷ് ചെയ്യൽ"</string>
     <string name="dock_forced_resizable" msgid="1749750436092293116">"സ്‌ക്രീൻ വിഭജന മോഡിൽ ആപ്പ് പ്രവർത്തിച്ചേക്കില്ല."</string>
     <string name="dock_non_resizeble_failed_to_dock_text" msgid="7408396418008948957">"സ്പ്ലിറ്റ്-സ്ക്രീനിനെ ആപ്പ് പിന്തുണയ്ക്കുന്നില്ല."</string>
-    <!-- no translation found for dock_multi_instances_not_supported_text (5242868470666346929) -->
-    <skip />
+    <string name="dock_multi_instances_not_supported_text" msgid="5242868470666346929">"ഈ ആപ്പ് ഒരു വിൻഡോയിൽ മാത്രമേ തുറക്കാനാകൂ."</string>
     <string name="forced_resizable_secondary_display" msgid="1768046938673582671">"രണ്ടാം ഡിസ്‌പ്ലേയിൽ ആപ്പ് പ്രവർത്തിച്ചേക്കില്ല."</string>
     <string name="activity_launch_on_secondary_display_failed_text" msgid="4226485344988071769">"രണ്ടാം ഡിസ്‌പ്ലേകളിൽ സമാരംഭിക്കുന്നതിനെ ആപ്പ് അനുവദിക്കുന്നില്ല."</string>
     <string name="accessibility_divider" msgid="703810061635792791">"സ്പ്ലിറ്റ്-സ്ക്രീൻ ഡിവൈഡർ"</string>
diff --git a/libs/WindowManager/Shell/res/values-ta/strings.xml b/libs/WindowManager/Shell/res/values-ta/strings.xml
index 2039685..525f2ea 100644
--- a/libs/WindowManager/Shell/res/values-ta/strings.xml
+++ b/libs/WindowManager/Shell/res/values-ta/strings.xml
@@ -34,8 +34,7 @@
     <string name="accessibility_action_pip_unstash" msgid="7467499339610437646">"Unstash"</string>
     <string name="dock_forced_resizable" msgid="1749750436092293116">"திரைப் பிரிப்பு அம்சத்தில் ஆப்ஸ் செயல்படாமல் போகக்கூடும்."</string>
     <string name="dock_non_resizeble_failed_to_dock_text" msgid="7408396418008948957">"திரையைப் பிரிப்பதைப் ஆப்ஸ் ஆதரிக்கவில்லை."</string>
-    <!-- no translation found for dock_multi_instances_not_supported_text (5242868470666346929) -->
-    <skip />
+    <string name="dock_multi_instances_not_supported_text" msgid="5242868470666346929">"இந்த ஆப்ஸை 1 சாளரத்தில் மட்டுமே திறக்க முடியும்."</string>
     <string name="forced_resizable_secondary_display" msgid="1768046938673582671">"இரண்டாம்நிலைத் திரையில் ஆப்ஸ் வேலை செய்யாமல் போகக்கூடும்."</string>
     <string name="activity_launch_on_secondary_display_failed_text" msgid="4226485344988071769">"இரண்டாம்நிலைத் திரைகளில் பயன்பாட்டைத் தொடங்க முடியாது."</string>
     <string name="accessibility_divider" msgid="703810061635792791">"திரையைப் பிரிக்கும் பிரிப்பான்"</string>
diff --git a/libs/WindowManager/Shell/res/values-tvdpi/dimen.xml b/libs/WindowManager/Shell/res/values-tvdpi/dimen.xml
index 9833a88..0b61d7a 100644
--- a/libs/WindowManager/Shell/res/values-tvdpi/dimen.xml
+++ b/libs/WindowManager/Shell/res/values-tvdpi/dimen.xml
@@ -28,7 +28,7 @@
     <dimen name="pip_menu_background_corner_radius">6dp</dimen>
     <dimen name="pip_menu_border_width">4dp</dimen>
     <dimen name="pip_menu_outer_space">24dp</dimen>
-    <dimen name="pip_menu_button_wrapper_margin">26dp</dimen>
+    <dimen name="pip_menu_button_start_end_offset">30dp</dimen>
 
     <!-- outer space minus border width -->
     <dimen name="pip_menu_outer_space_frame">20dp</dimen>
diff --git a/libs/WindowManager/Shell/res/values/config.xml b/libs/WindowManager/Shell/res/values/config.xml
index c6197c8..23db233 100644
--- a/libs/WindowManager/Shell/res/values/config.xml
+++ b/libs/WindowManager/Shell/res/values/config.xml
@@ -113,6 +113,6 @@
     <bool name="config_dimNonImeAttachedSide">true</bool>
 
     <!-- Components support to launch multiple instances into split-screen -->
-    <string-array name="config_componentsSupportMultiInstancesSplit">
+    <string-array name="config_appsSupportMultiInstancesSplit">
     </string-array>
 </resources>
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingAnimationRunner.java b/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingAnimationRunner.java
index c0a6456..164d2f1 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingAnimationRunner.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/activityembedding/ActivityEmbeddingAnimationRunner.java
@@ -17,6 +17,7 @@
 package com.android.wm.shell.activityembedding;
 
 import static android.view.WindowManager.TRANSIT_CHANGE;
+import static android.view.WindowManager.TRANSIT_CLOSE;
 import static android.view.WindowManagerPolicyConstants.TYPE_LAYER_OFFSET;
 import static android.window.TransitionInfo.FLAG_IS_BEHIND_STARTING_WINDOW;
 
@@ -112,23 +113,30 @@
             @NonNull List<Consumer<SurfaceControl.Transaction>> postStartTransactionCallbacks) {
         final List<ActivityEmbeddingAnimationAdapter> adapters = createAnimationAdapters(info,
                 startTransaction);
-        addEdgeExtensionIfNeeded(startTransaction, finishTransaction, postStartTransactionCallbacks,
-                adapters);
-        addBackgroundColorIfNeeded(info, startTransaction, finishTransaction, adapters);
-        long duration = 0;
-        for (ActivityEmbeddingAnimationAdapter adapter : adapters) {
-            duration = Math.max(duration, adapter.getDurationHint());
-        }
         final ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
-        animator.setDuration(duration);
-        animator.addUpdateListener((anim) -> {
-            // Update all adapters in the same transaction.
-            final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
+        long duration = 0;
+        if (adapters.isEmpty()) {
+            // Jump cut
+            // No need to modify the animator, but to update the startTransaction with the changes'
+            // ending states.
+            prepareForJumpCut(info, startTransaction);
+        } else {
+            addEdgeExtensionIfNeeded(startTransaction, finishTransaction,
+                    postStartTransactionCallbacks, adapters);
+            addBackgroundColorIfNeeded(info, startTransaction, finishTransaction, adapters);
             for (ActivityEmbeddingAnimationAdapter adapter : adapters) {
-                adapter.onAnimationUpdate(t, animator.getCurrentPlayTime());
+                duration = Math.max(duration, adapter.getDurationHint());
             }
-            t.apply();
-        });
+            animator.addUpdateListener((anim) -> {
+                // Update all adapters in the same transaction.
+                final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
+                for (ActivityEmbeddingAnimationAdapter adapter : adapters) {
+                    adapter.onAnimationUpdate(t, animator.getCurrentPlayTime());
+                }
+                t.apply();
+            });
+        }
+        animator.setDuration(duration);
         animator.addListener(new Animator.AnimatorListener() {
             @Override
             public void onAnimationStart(Animator animation) {}
@@ -292,6 +300,10 @@
     @NonNull
     private List<ActivityEmbeddingAnimationAdapter> createChangeAnimationAdapters(
             @NonNull TransitionInfo info, @NonNull SurfaceControl.Transaction startTransaction) {
+        if (shouldUseJumpCutForChangeTransition(info)) {
+            return new ArrayList<>();
+        }
+
         final List<ActivityEmbeddingAnimationAdapter> adapters = new ArrayList<>();
         final Set<TransitionInfo.Change> handledChanges = new ArraySet<>();
 
@@ -374,9 +386,11 @@
             }
 
             final Animation animation;
-            if (change.getParent() != null
-                    && handledChanges.contains(info.getChange(change.getParent()))) {
-                // No-op if it will be covered by the changing parent window.
+            if ((change.getParent() != null
+                    && handledChanges.contains(info.getChange(change.getParent())))
+                    || change.getMode() == TRANSIT_CHANGE) {
+                // No-op if it will be covered by the changing parent window, or it is a changing
+                // window without bounds change.
                 animation = ActivityEmbeddingAnimationSpec.createNoopAnimation(change);
             } else if (Transitions.isClosingType(change.getMode())) {
                 animation = mAnimationSpec.createChangeBoundsCloseAnimation(change, parentBounds);
@@ -421,6 +435,74 @@
                 animationChange.getLeash(), cropBounds, Integer.MAX_VALUE);
     }
 
+    /**
+     * Whether we should use jump cut for the change transition.
+     * This normally happens when opening a new secondary with the existing primary using a
+     * different split layout. This can be complicated, like from horizontal to vertical split with
+     * new split pairs.
+     * Uses a jump cut animation to simplify.
+     */
+    private boolean shouldUseJumpCutForChangeTransition(@NonNull TransitionInfo info) {
+        // There can be reparenting of changing Activity to new open TaskFragment, so we need to
+        // exclude both in the first iteration.
+        final List<TransitionInfo.Change> changingChanges = new ArrayList<>();
+        for (TransitionInfo.Change change : info.getChanges()) {
+            if (change.getMode() != TRANSIT_CHANGE
+                    || change.getStartAbsBounds().equals(change.getEndAbsBounds())) {
+                continue;
+            }
+            changingChanges.add(change);
+            final WindowContainerToken parentToken = change.getParent();
+            if (parentToken != null) {
+                // When the parent window is also included in the transition as an opening window,
+                // we would like to animate the parent window instead.
+                final TransitionInfo.Change parentChange = info.getChange(parentToken);
+                if (parentChange != null && Transitions.isOpeningType(parentChange.getMode())) {
+                    changingChanges.add(parentChange);
+                }
+            }
+        }
+        if (changingChanges.isEmpty()) {
+            // No changing target found.
+            return true;
+        }
+
+        // Check if the transition contains both opening and closing windows.
+        boolean hasOpeningWindow = false;
+        boolean hasClosingWindow = false;
+        for (TransitionInfo.Change change : info.getChanges()) {
+            if (changingChanges.contains(change)) {
+                continue;
+            }
+            if (change.getParent() != null
+                    && changingChanges.contains(info.getChange(change.getParent()))) {
+                // No-op if it will be covered by the changing parent window.
+                continue;
+            }
+            hasOpeningWindow |= Transitions.isOpeningType(change.getMode());
+            hasClosingWindow |= Transitions.isClosingType(change.getMode());
+        }
+        return hasOpeningWindow && hasClosingWindow;
+    }
+
+    /** Updates the changes to end states in {@code startTransaction} for jump cut animation. */
+    private void prepareForJumpCut(@NonNull TransitionInfo info,
+            @NonNull SurfaceControl.Transaction startTransaction) {
+        for (TransitionInfo.Change change : info.getChanges()) {
+            final SurfaceControl leash = change.getLeash();
+            startTransaction.setPosition(leash,
+                    change.getEndRelOffset().x, change.getEndRelOffset().y);
+            startTransaction.setWindowCrop(leash,
+                    change.getEndAbsBounds().width(), change.getEndAbsBounds().height());
+            if (change.getMode() == TRANSIT_CLOSE) {
+                startTransaction.hide(leash);
+            } else {
+                startTransaction.show(leash);
+                startTransaction.setAlpha(leash, 1f);
+            }
+        }
+    }
+
     /** To provide an {@link Animation} based on the transition infos. */
     private interface AnimationProvider {
         Animation get(@NonNull TransitionInfo info, @NonNull TransitionInfo.Change change,
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleBadgeIconFactory.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleBadgeIconFactory.java
index d3a9a67..56b13b8 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleBadgeIconFactory.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleBadgeIconFactory.java
@@ -19,7 +19,6 @@
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
-import android.graphics.Color;
 import android.graphics.Path;
 import android.graphics.Rect;
 import android.graphics.drawable.AdaptiveIconDrawable;
@@ -59,7 +58,8 @@
     private class CircularRingDrawable extends CircularAdaptiveIcon {
 
         final int mImportantConversationColor;
-        final Rect mTempBounds = new Rect();
+        final int mRingWidth;
+        final Rect mInnerBounds = new Rect();
 
         final Drawable mDr;
 
@@ -68,6 +68,8 @@
             mDr = dr;
             mImportantConversationColor = mContext.getResources().getColor(
                     R.color.important_conversation, null);
+            mRingWidth = mContext.getResources().getDimensionPixelSize(
+                    com.android.internal.R.dimen.importance_ring_stroke_width);
         }
 
         @Override
@@ -75,11 +77,10 @@
             int save = canvas.save();
             canvas.clipPath(getIconMask());
             canvas.drawColor(mImportantConversationColor);
-            int ringStrokeWidth = mContext.getResources().getDimensionPixelSize(
-                    com.android.internal.R.dimen.importance_ring_stroke_width);
-            mTempBounds.set(getBounds());
-            mTempBounds.inset(ringStrokeWidth, ringStrokeWidth);
-            mDr.setBounds(mTempBounds);
+            mInnerBounds.set(getBounds());
+            mInnerBounds.inset(mRingWidth, mRingWidth);
+            canvas.translate(mInnerBounds.left, mInnerBounds.top);
+            mDr.setBounds(0, 0, mInnerBounds.width(), mInnerBounds.height());
             mDr.draw(canvas);
             canvas.restoreToCount(save);
         }
@@ -106,7 +107,6 @@
             int save = canvas.save();
             canvas.clipPath(getIconMask());
 
-            canvas.drawColor(Color.BLACK);
             Drawable d;
             if ((d = getBackground()) != null) {
                 d.draw(canvas);
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/TvWindowMenuActionButton.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/TvWindowMenuActionButton.java
index 39b0b55..8ba785a 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/TvWindowMenuActionButton.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/TvWindowMenuActionButton.java
@@ -19,6 +19,8 @@
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.graphics.drawable.Drawable;
+import android.graphics.drawable.Icon;
+import android.os.Handler;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -30,11 +32,11 @@
 /**
  * A common action button for TV window menu layouts.
  */
-public class TvWindowMenuActionButton extends RelativeLayout implements View.OnClickListener {
+public class TvWindowMenuActionButton extends RelativeLayout {
     private final ImageView mIconImageView;
     private final View mButtonBackgroundView;
-    private final View mButtonView;
-    private OnClickListener mOnClickListener;
+
+    private Icon mCurrentIcon;
 
     public TvWindowMenuActionButton(Context context) {
         this(context, null, 0, 0);
@@ -56,7 +58,6 @@
         inflater.inflate(R.layout.tv_window_menu_action_button, this);
 
         mIconImageView = findViewById(R.id.icon);
-        mButtonView = findViewById(R.id.button);
         mButtonBackgroundView = findViewById(R.id.background);
 
         final int[] values = new int[]{android.R.attr.src, android.R.attr.text};
@@ -71,23 +72,6 @@
         typedArray.recycle();
     }
 
-    @Override
-    public void setOnClickListener(OnClickListener listener) {
-        // We do not want to set an OnClickListener to the TvWindowMenuActionButton itself, but only
-        // to the ImageView. So let's "cash" the listener we've been passed here and set a "proxy"
-        // listener to the ImageView.
-        mOnClickListener = listener;
-        mButtonView.setOnClickListener(listener != null ? this : null);
-    }
-
-    @Override
-    public void onClick(View v) {
-        if (mOnClickListener != null) {
-            // Pass the correct view - this.
-            mOnClickListener.onClick(this);
-        }
-    }
-
     /**
      * Sets the drawable for the button with the given drawable.
      */
@@ -104,11 +88,24 @@
         }
     }
 
+    public void setImageIconAsync(Icon icon, Handler handler) {
+        mCurrentIcon = icon;
+        // Remove old image while waiting for the new one to load.
+        mIconImageView.setImageDrawable(null);
+        icon.loadDrawableAsync(mContext, d -> {
+            // The image hasn't been set any other way and the drawable belongs to the most
+            // recently set Icon.
+            if (mIconImageView.getDrawable() == null && mCurrentIcon == icon) {
+                mIconImageView.setImageDrawable(d);
+            }
+        }, handler);
+    }
+
     /**
      * Sets the text for description the with the given string.
      */
     public void setTextAndDescription(CharSequence text) {
-        mButtonView.setContentDescription(text);
+        setContentDescription(text);
     }
 
     /**
@@ -118,16 +115,6 @@
         setTextAndDescription(getContext().getString(resId));
     }
 
-    @Override
-    public void setEnabled(boolean enabled) {
-        mButtonView.setEnabled(enabled);
-    }
-
-    @Override
-    public boolean isEnabled() {
-        return mButtonView.isEnabled();
-    }
-
     /**
      * Marks this button as a custom close action button.
      * This changes the style of the action button to highlight that this action finishes the
@@ -147,10 +134,10 @@
 
     @Override
     public String toString() {
-        if (mButtonView.getContentDescription() == null) {
+        if (getContentDescription() == null) {
             return TvWindowMenuActionButton.class.getSimpleName();
         }
-        return mButtonView.getContentDescription().toString();
+        return getContentDescription().toString();
     }
 
 }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerView.java
index 214b304..c634198 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerView.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerView.java
@@ -403,5 +403,10 @@
             }
             return true;
         }
+
+        @Override
+        public boolean onDoubleTapEvent(@NonNull MotionEvent e) {
+            return true;
+        }
     }
 }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitDecorManager.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitDecorManager.java
index c836b95..a9d3c9f 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitDecorManager.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitDecorManager.java
@@ -74,7 +74,8 @@
 
     private boolean mShown;
     private boolean mIsResizing;
-    private final Rect mBounds = new Rect();
+    private final Rect mOldBounds = new Rect();
+    private final Rect mResizingBounds = new Rect();
     private final Rect mTempRect = new Rect();
     private ValueAnimator mFadeAnimator;
 
@@ -158,6 +159,8 @@
         mResizingIconView = null;
         mIsResizing = false;
         mShown = false;
+        mOldBounds.setEmpty();
+        mResizingBounds.setEmpty();
     }
 
     /** Showing resizing hint. */
@@ -170,13 +173,14 @@
 
         if (!mIsResizing) {
             mIsResizing = true;
-            mBounds.set(newBounds);
+            mOldBounds.set(newBounds);
         }
+        mResizingBounds.set(newBounds);
         mOffsetX = offsetX;
         mOffsetY = offsetY;
 
         final boolean show =
-                newBounds.width() > mBounds.width() || newBounds.height() > mBounds.height();
+                newBounds.width() > mOldBounds.width() || newBounds.height() > mOldBounds.height();
         final boolean update = show != mShown;
         if (update && mFadeAnimator != null && mFadeAnimator.isRunning()) {
             // If we need to animate and animator still running, cancel it before we ensure both
@@ -193,8 +197,8 @@
 
         if (mGapBackgroundLeash == null && !immediately) {
             final boolean isLandscape = newBounds.height() == sideBounds.height();
-            final int left = isLandscape ? mBounds.width() : 0;
-            final int top = isLandscape ? 0 : mBounds.height();
+            final int left = isLandscape ? mOldBounds.width() : 0;
+            final int top = isLandscape ? 0 : mOldBounds.height();
             mGapBackgroundLeash = SurfaceUtils.makeColorLayer(mHostLeash,
                     GAP_BACKGROUND_SURFACE_NAME, mSurfaceSession);
             // Fill up another side bounds area.
@@ -272,6 +276,8 @@
         mIsResizing = false;
         mOffsetX = 0;
         mOffsetY = 0;
+        mOldBounds.setEmpty();
+        mResizingBounds.setEmpty();
         if (mFadeAnimator != null && mFadeAnimator.isRunning()) {
             if (!mShown) {
                 // If fade-out animation is running, just add release callback to it.
@@ -303,8 +309,8 @@
 
     /** Screenshot host leash and attach on it if meet some conditions */
     public void screenshotIfNeeded(SurfaceControl.Transaction t) {
-        if (!mShown && mIsResizing) {
-            mTempRect.set(mBounds);
+        if (!mShown && mIsResizing && !mOldBounds.equals(mResizingBounds)) {
+            mTempRect.set(mOldBounds);
             mTempRect.offsetTo(0, 0);
             mScreenshot = ScreenshotUtils.takeScreenshot(t, mHostLeash, mTempRect,
                     Integer.MAX_VALUE - 1);
@@ -315,7 +321,7 @@
     public void setScreenshotIfNeeded(SurfaceControl screenshot, SurfaceControl.Transaction t) {
         if (screenshot == null || !screenshot.isValid()) return;
 
-        if (!mShown && mIsResizing) {
+        if (!mShown && mIsResizing && !mOldBounds.equals(mResizingBounds)) {
             mScreenshot = screenshot;
             t.reparent(screenshot, mHostLeash);
             t.setLayer(screenshot, Integer.MAX_VALUE - 1);
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/TvPipModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/TvPipModule.java
index 8022e9b..b144d22 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/TvPipModule.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/TvPipModule.java
@@ -81,6 +81,7 @@
             PipParamsChangedForwarder pipParamsChangedForwarder,
             DisplayController displayController,
             WindowManagerShellWrapper windowManagerShellWrapper,
+            @ShellMainThread Handler mainHandler, // needed for registerReceiverForAllUsers()
             @ShellMainThread ShellExecutor mainExecutor) {
         return Optional.of(
                 TvPipController.create(
@@ -100,6 +101,7 @@
                         pipParamsChangedForwarder,
                         displayController,
                         windowManagerShellWrapper,
+                        mainHandler,
                         mainExecutor));
     }
 
@@ -157,22 +159,17 @@
             Context context,
             TvPipBoundsState tvPipBoundsState,
             SystemWindows systemWindows,
-            PipMediaController pipMediaController,
             @ShellMainThread Handler mainHandler) {
-        return new TvPipMenuController(context, tvPipBoundsState, systemWindows, pipMediaController,
-                mainHandler);
+        return new TvPipMenuController(context, tvPipBoundsState, systemWindows, mainHandler);
     }
 
-    // Handler needed for registerReceiverForAllUsers()
     @WMSingleton
     @Provides
     static TvPipNotificationController provideTvPipNotificationController(Context context,
             PipMediaController pipMediaController,
-            PipParamsChangedForwarder pipParamsChangedForwarder,
-            TvPipBoundsState tvPipBoundsState,
-            @ShellMainThread Handler mainHandler) {
+            PipParamsChangedForwarder pipParamsChangedForwarder) {
         return new TvPipNotificationController(context, pipMediaController,
-                pipParamsChangedForwarder, tvPipBoundsState, mainHandler);
+                pipParamsChangedForwarder);
     }
 
     @WMSingleton
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java
index dc1634a..661c08b1 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java
@@ -702,7 +702,7 @@
         // Use optional-of-lazy for the dependency that this provider relies on.
         // Lazy ensures that this provider will not be the cause the dependency is created
         // when it will not be returned due to the condition below.
-        if (DesktopModeStatus.IS_SUPPORTED) {
+        if (DesktopModeStatus.isProto1Enabled()) {
             return desktopModeController.map(Lazy::get);
         }
         return Optional.empty();
@@ -719,7 +719,7 @@
         // Use optional-of-lazy for the dependency that this provider relies on.
         // Lazy ensures that this provider will not be the cause the dependency is created
         // when it will not be returned due to the condition below.
-        if (DesktopModeStatus.IS_SUPPORTED) {
+        if (DesktopModeStatus.isAnyEnabled()) {
             return desktopModeTaskRepository.map(Lazy::get);
         }
         return Optional.empty();
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeController.java
index 5824f51..f5f3573 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeController.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeController.java
@@ -40,6 +40,7 @@
 import android.provider.Settings;
 import android.util.ArraySet;
 import android.view.SurfaceControl;
+import android.view.WindowManager;
 import android.window.DisplayAreaInfo;
 import android.window.TransitionInfo;
 import android.window.TransitionRequestInfo;
@@ -100,7 +101,7 @@
         mDesktopModeTaskRepository = desktopModeTaskRepository;
         mMainExecutor = mainExecutor;
         mSettingsObserver = new SettingsObserver(mContext, mainHandler);
-        if (DesktopModeStatus.isSupported()) {
+        if (DesktopModeStatus.isProto1Enabled()) {
             shellInit.addInitCallback(this::onInit, this);
         }
     }
@@ -329,15 +330,17 @@
     @Override
     public WindowContainerTransaction handleRequest(@NonNull IBinder transition,
             @NonNull TransitionRequestInfo request) {
-        // Only do anything if we are in desktop mode and opening a task/app in freeform
+        // Only do anything if we are in desktop mode and opening/moving-to-front a task/app in
+        // freeform
         if (!DesktopModeStatus.isActive(mContext)) {
             ProtoLog.d(WM_SHELL_DESKTOP_MODE,
                     "skip shell transition request: desktop mode not active");
             return null;
         }
-        if (request.getType() != TRANSIT_OPEN) {
+        if (request.getType() != TRANSIT_OPEN && request.getType() != TRANSIT_TO_FRONT) {
             ProtoLog.d(WM_SHELL_DESKTOP_MODE,
-                    "skip shell transition request: only supports TRANSIT_OPEN");
+                    "skip shell transition request: unsupported type %s",
+                    WindowManager.transitTypeToString(request.getType()));
             return null;
         }
         if (request.getTriggerTask() == null
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeStatus.java b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeStatus.java
index e3eb2b7..67f4a19 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeStatus.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeStatus.java
@@ -33,17 +33,38 @@
     /**
      * Flag to indicate whether desktop mode is available on the device
      */
-    public static final boolean IS_SUPPORTED = SystemProperties.getBoolean(
+    private static final boolean IS_SUPPORTED = SystemProperties.getBoolean(
             "persist.wm.debug.desktop_mode", false);
 
     /**
+     * Flag to indicate whether desktop mode proto 2 is available on the device
+     */
+    private static final boolean IS_PROTO2_ENABLED = SystemProperties.getBoolean(
+            "persist.wm.debug.desktop_mode_2", false);
+
+    /**
      * Return {@code true} if desktop mode support is enabled
      */
-    public static boolean isSupported() {
+    public static boolean isProto1Enabled() {
         return IS_SUPPORTED;
     }
 
     /**
+     * Return {@code true} is desktop windowing proto 2 is enabled
+     */
+    public static boolean isProto2Enabled() {
+        return IS_PROTO2_ENABLED;
+    }
+
+    /**
+     * Return {@code true} if proto 1 or 2 is enabled.
+     * Can be used to guard logic that is common for both prototypes.
+     */
+    public static boolean isAnyEnabled() {
+        return isProto1Enabled() || isProto2Enabled();
+    }
+
+    /**
      * Check if desktop mode is active
      *
      * @return {@code true} if active
@@ -61,5 +82,4 @@
             return false;
         }
     }
-
 }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropPolicy.java b/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropPolicy.java
index 62bf517..d93a901 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropPolicy.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropPolicy.java
@@ -240,7 +240,7 @@
             // Update launch options for the split side we are targeting.
             position = leftOrTop ? SPLIT_POSITION_TOP_OR_LEFT : SPLIT_POSITION_BOTTOM_OR_RIGHT;
             // Add some data for logging splitscreen once it is invoked
-            mSplitScreen.logOnDroppedToSplit(position, mLoggerSessionId);
+            mSplitScreen.onDroppedToSplit(position, mLoggerSessionId);
         }
 
         final ClipDescription description = data.getDescription();
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskListener.java b/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskListener.java
index 8a9b74f..793bad8 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskListener.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskListener.java
@@ -68,7 +68,7 @@
 
     private void onInit() {
         mShellTaskOrganizer.addListenerForType(this, TASK_LISTENER_TYPE_FREEFORM);
-        if (DesktopModeStatus.IS_SUPPORTED) {
+        if (DesktopModeStatus.isAnyEnabled()) {
             mShellTaskOrganizer.addFocusListener(this);
         }
     }
@@ -90,7 +90,7 @@
             t.apply();
         }
 
-        if (DesktopModeStatus.IS_SUPPORTED) {
+        if (DesktopModeStatus.isAnyEnabled()) {
             mDesktopModeTaskRepository.ifPresent(repository -> {
                 repository.addOrMoveFreeformTaskToTop(taskInfo.taskId);
                 if (taskInfo.isVisible) {
@@ -110,7 +110,7 @@
                 taskInfo.taskId);
         mTasks.remove(taskInfo.taskId);
 
-        if (DesktopModeStatus.IS_SUPPORTED) {
+        if (DesktopModeStatus.isAnyEnabled()) {
             mDesktopModeTaskRepository.ifPresent(repository -> {
                 repository.removeFreeformTask(taskInfo.taskId);
                 if (repository.removeActiveTask(taskInfo.taskId)) {
@@ -134,7 +134,7 @@
                 taskInfo.taskId);
         mWindowDecorationViewModel.onTaskInfoChanged(state.mTaskInfo);
 
-        if (DesktopModeStatus.IS_SUPPORTED) {
+        if (DesktopModeStatus.isAnyEnabled()) {
             mDesktopModeTaskRepository.ifPresent(repository -> {
                 if (taskInfo.isVisible) {
                     if (repository.addActiveTask(taskInfo.taskId)) {
@@ -152,7 +152,7 @@
         ProtoLog.v(ShellProtoLogGroup.WM_SHELL_TASK_ORG,
                 "Freeform Task Focus Changed: #%d focused=%b",
                 taskInfo.taskId, taskInfo.isFocused);
-        if (DesktopModeStatus.IS_SUPPORTED && taskInfo.isFocused) {
+        if (DesktopModeStatus.isAnyEnabled() && taskInfo.isFocused) {
             mDesktopModeTaskRepository.ifPresent(repository -> {
                 repository.addOrMoveFreeformTaskToTop(taskInfo.taskId);
             });
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java
index 85bad17..e6c7e10 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java
@@ -358,8 +358,10 @@
             WindowContainerTransaction wct = null;
             if (isOutPipDirection(direction)) {
                 // Only need to reset surface properties. The server-side operations were already
-                // done at the start.
-                if (tx != null) {
+                // done at the start. But if it is running fixed rotation, there will be a seamless
+                // display transition later. So the last rotation transform needs to be kept to
+                // avoid flickering, and then the display transition will reset the transform.
+                if (tx != null && !mInFixedRotation) {
                     mFinishTransaction.merge(tx);
                 }
             } else {
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipAction.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipAction.java
new file mode 100644
index 0000000..222307f
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipAction.java
@@ -0,0 +1,87 @@
+/*
+ * 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.wm.shell.pip.tv;
+
+import android.annotation.IntDef;
+import android.annotation.NonNull;
+import android.app.Notification;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.os.Handler;
+
+import com.android.wm.shell.common.TvWindowMenuActionButton;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.util.Objects;
+
+abstract class TvPipAction {
+
+    @Retention(RetentionPolicy.SOURCE)
+    @IntDef(prefix = {"ACTION_"}, value = {
+            ACTION_FULLSCREEN,
+            ACTION_CLOSE,
+            ACTION_MOVE,
+            ACTION_EXPAND_COLLAPSE,
+            ACTION_CUSTOM,
+            ACTION_CUSTOM_CLOSE
+    })
+    public @interface ActionType {
+    }
+
+    public static final int ACTION_FULLSCREEN = 0;
+    public static final int ACTION_CLOSE = 1;
+    public static final int ACTION_MOVE = 2;
+    public static final int ACTION_EXPAND_COLLAPSE = 3;
+    public static final int ACTION_CUSTOM = 4;
+    public static final int ACTION_CUSTOM_CLOSE = 5;
+
+    @ActionType
+    private final int mActionType;
+
+    @NonNull
+    private final SystemActionsHandler mSystemActionsHandler;
+
+    TvPipAction(@ActionType int actionType, @NonNull SystemActionsHandler systemActionsHandler) {
+        Objects.requireNonNull(systemActionsHandler);
+        mActionType = actionType;
+        mSystemActionsHandler = systemActionsHandler;
+    }
+
+    boolean isCloseAction() {
+        return mActionType == ACTION_CLOSE || mActionType == ACTION_CUSTOM_CLOSE;
+    }
+
+    @ActionType
+    int getActionType() {
+        return mActionType;
+    }
+
+    abstract void populateButton(@NonNull TvWindowMenuActionButton button, Handler mainHandler);
+
+    abstract PendingIntent getPendingIntent();
+
+    void executeAction() {
+        mSystemActionsHandler.executeAction(mActionType);
+    }
+
+    abstract Notification.Action toNotificationAction(Context context);
+
+    interface SystemActionsHandler {
+        void executeAction(@TvPipAction.ActionType int actionType);
+    }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipActionsProvider.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipActionsProvider.java
new file mode 100644
index 0000000..fa62a73
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipActionsProvider.java
@@ -0,0 +1,245 @@
+/*
+ * 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.wm.shell.pip.tv;
+
+import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE;
+import static com.android.wm.shell.pip.tv.TvPipAction.ACTION_CLOSE;
+import static com.android.wm.shell.pip.tv.TvPipAction.ACTION_CUSTOM;
+import static com.android.wm.shell.pip.tv.TvPipAction.ACTION_CUSTOM_CLOSE;
+import static com.android.wm.shell.pip.tv.TvPipAction.ACTION_EXPAND_COLLAPSE;
+import static com.android.wm.shell.pip.tv.TvPipAction.ACTION_FULLSCREEN;
+import static com.android.wm.shell.pip.tv.TvPipAction.ACTION_MOVE;
+import static com.android.wm.shell.pip.tv.TvPipController.ACTION_CLOSE_PIP;
+import static com.android.wm.shell.pip.tv.TvPipController.ACTION_MOVE_PIP;
+import static com.android.wm.shell.pip.tv.TvPipController.ACTION_TOGGLE_EXPANDED_PIP;
+import static com.android.wm.shell.pip.tv.TvPipController.ACTION_TO_FULLSCREEN;
+
+import android.annotation.NonNull;
+import android.app.RemoteAction;
+import android.content.Context;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.protolog.common.ProtoLog;
+import com.android.wm.shell.R;
+import com.android.wm.shell.pip.PipMediaController;
+import com.android.wm.shell.pip.PipUtils;
+import com.android.wm.shell.protolog.ShellProtoLogGroup;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Creates the system TvPipActions (fullscreen, close, move, expand/collapse),  and handles all the
+ * changes to the actions, including the custom app actions and media actions. Other components can
+ * listen to those changes.
+ */
+public class TvPipActionsProvider implements TvPipAction.SystemActionsHandler {
+    private static final String TAG = TvPipActionsProvider.class.getSimpleName();
+
+    private static final int CLOSE_ACTION_INDEX = 1;
+    private static final int FIRST_CUSTOM_ACTION_INDEX = 2;
+
+    private final List<Listener> mListeners = new ArrayList<>();
+    private final TvPipAction.SystemActionsHandler mSystemActionsHandler;
+
+    private final List<TvPipAction> mActionsList;
+    private final TvPipSystemAction mDefaultCloseAction;
+    private final TvPipSystemAction mExpandCollapseAction;
+
+    private final List<RemoteAction> mMediaActions = new ArrayList<>();
+    private final List<RemoteAction> mAppActions = new ArrayList<>();
+
+    public TvPipActionsProvider(Context context, PipMediaController pipMediaController,
+            TvPipAction.SystemActionsHandler systemActionsHandler) {
+        mSystemActionsHandler = systemActionsHandler;
+
+        mActionsList = new ArrayList<>();
+        mActionsList.add(new TvPipSystemAction(ACTION_FULLSCREEN, R.string.pip_fullscreen,
+                R.drawable.pip_ic_fullscreen_white, ACTION_TO_FULLSCREEN, context,
+                mSystemActionsHandler));
+
+        mDefaultCloseAction = new TvPipSystemAction(ACTION_CLOSE, R.string.pip_close,
+                R.drawable.pip_ic_close_white, ACTION_CLOSE_PIP, context, mSystemActionsHandler);
+        mActionsList.add(mDefaultCloseAction);
+
+        mActionsList.add(new TvPipSystemAction(ACTION_MOVE, R.string.pip_move,
+                R.drawable.pip_ic_move_white, ACTION_MOVE_PIP, context, mSystemActionsHandler));
+
+        mExpandCollapseAction = new TvPipSystemAction(ACTION_EXPAND_COLLAPSE, R.string.pip_collapse,
+                R.drawable.pip_ic_collapse, ACTION_TOGGLE_EXPANDED_PIP, context,
+                mSystemActionsHandler);
+        mActionsList.add(mExpandCollapseAction);
+
+        pipMediaController.addActionListener(this::onMediaActionsChanged);
+    }
+
+    @Override
+    public void executeAction(@TvPipAction.ActionType int actionType) {
+        if (mSystemActionsHandler != null) {
+            mSystemActionsHandler.executeAction(actionType);
+        }
+    }
+
+    private void notifyActionsChanged(int added, int changed, int startIndex) {
+        for (Listener listener : mListeners) {
+            listener.onActionsChanged(added, changed, startIndex);
+        }
+    }
+
+    @VisibleForTesting(visibility = PACKAGE)
+    public void setAppActions(@NonNull List<RemoteAction> appActions, RemoteAction closeAction) {
+        // Update close action.
+        mActionsList.set(CLOSE_ACTION_INDEX,
+                closeAction == null ? mDefaultCloseAction
+                        : new TvPipCustomAction(ACTION_CUSTOM_CLOSE, closeAction,
+                                mSystemActionsHandler));
+        notifyActionsChanged(/* added= */ 0, /* updated= */ 1, CLOSE_ACTION_INDEX);
+
+        // Replace custom actions with new ones.
+        mAppActions.clear();
+        for (RemoteAction action : appActions) {
+            if (action != null && !PipUtils.remoteActionsMatch(action, closeAction)) {
+                // Only show actions that aren't duplicates of the custom close action.
+                mAppActions.add(action);
+            }
+        }
+
+        updateCustomActions(mAppActions);
+    }
+
+    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
+    public void onMediaActionsChanged(List<RemoteAction> actions) {
+        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
+                "%s: onMediaActionsChanged()", TAG);
+
+        mMediaActions.clear();
+        // Don't show disabled actions.
+        for (RemoteAction remoteAction : actions) {
+            if (remoteAction.isEnabled()) {
+                mMediaActions.add(remoteAction);
+            }
+        }
+
+        updateCustomActions(mMediaActions);
+    }
+
+    private void updateCustomActions(@NonNull List<RemoteAction> customActions) {
+        List<RemoteAction> newCustomActions = customActions;
+        if (newCustomActions == mMediaActions && !mAppActions.isEmpty()) {
+            // Don't show the media actions while there are app actions.
+            return;
+        } else if (newCustomActions == mAppActions && mAppActions.isEmpty()) {
+            // If all the app actions were removed, show the media actions.
+            newCustomActions = mMediaActions;
+        }
+
+        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
+                "%s: replaceCustomActions, count: %d", TAG, newCustomActions.size());
+        int oldCustomActionsCount = 0;
+        for (TvPipAction action : mActionsList) {
+            if (action.getActionType() == ACTION_CUSTOM) {
+                oldCustomActionsCount++;
+            }
+        }
+        mActionsList.removeIf(tvPipAction -> tvPipAction.getActionType() == ACTION_CUSTOM);
+
+        List<TvPipAction> actions = new ArrayList<>();
+        for (RemoteAction action : newCustomActions) {
+            actions.add(new TvPipCustomAction(ACTION_CUSTOM, action, mSystemActionsHandler));
+        }
+        mActionsList.addAll(FIRST_CUSTOM_ACTION_INDEX, actions);
+
+        int added = newCustomActions.size() - oldCustomActionsCount;
+        int changed = Math.min(newCustomActions.size(), oldCustomActionsCount);
+        notifyActionsChanged(added, changed, FIRST_CUSTOM_ACTION_INDEX);
+    }
+
+    @VisibleForTesting(visibility = PACKAGE)
+    public void updateExpansionEnabled(boolean enabled) {
+        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
+                "%s: updateExpansionState, enabled: %b", TAG, enabled);
+        int actionIndex = mActionsList.indexOf(mExpandCollapseAction);
+        boolean actionInList = actionIndex != -1;
+        if (enabled && !actionInList) {
+            mActionsList.add(mExpandCollapseAction);
+            actionIndex = mActionsList.size() - 1;
+        } else if (!enabled && actionInList) {
+            mActionsList.remove(actionIndex);
+        } else {
+            return;
+        }
+        notifyActionsChanged(/* added= */ enabled ? 1 : -1, /* updated= */ 0, actionIndex);
+    }
+
+    @VisibleForTesting(visibility = PACKAGE)
+    public void onPipExpansionToggled(boolean expanded) {
+        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
+                "%s: onPipExpansionToggled, expanded: %b", TAG, expanded);
+
+        mExpandCollapseAction.update(
+                expanded ? R.string.pip_collapse : R.string.pip_expand,
+                expanded ? R.drawable.pip_ic_collapse : R.drawable.pip_ic_expand);
+
+        notifyActionsChanged(/* added= */ 0, /* updated= */ 1,
+                mActionsList.indexOf(mExpandCollapseAction));
+    }
+
+    List<TvPipAction> getActionsList() {
+        return mActionsList;
+    }
+
+    @NonNull
+    TvPipAction getCloseAction() {
+        return mActionsList.get(CLOSE_ACTION_INDEX);
+    }
+
+    void addListener(Listener listener) {
+        if (!mListeners.contains(listener)) {
+            mListeners.add(listener);
+        }
+    }
+
+    /**
+     * Returns the index of the first action of the given action type or -1 if none can be found.
+     */
+    int getFirstIndexOfAction(@TvPipAction.ActionType int actionType) {
+        for (int i = 0; i < mActionsList.size(); i++) {
+            if (mActionsList.get(i).getActionType() == actionType) {
+                return i;
+            }
+        }
+        return -1;
+    }
+
+    /**
+     * Allow components to listen to updates to the actions list, including where they happen so
+     * that changes can be animated.
+     */
+    interface Listener {
+        /**
+         * Notifies the listener how many actions were added/removed or updated.
+         *
+         * @param added      can be positive (number of actions added), negative (number of actions
+         *                   removed) or zero (the number of actions stayed the same).
+         * @param updated    the number of actions that might have been updated and need to be
+         *                   refreshed.
+         * @param startIndex The index of the first updated action. The added/removed actions start
+         *                   at (startIndex + updated).
+         */
+        void onActionsChanged(int added, int updated, int startIndex);
+    }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipController.java
index 3e8de45..7671081 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipController.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipController.java
@@ -22,13 +22,16 @@
 import android.annotation.IntDef;
 import android.app.ActivityManager;
 import android.app.ActivityTaskManager;
-import android.app.PendingIntent;
 import android.app.RemoteAction;
 import android.app.TaskInfo;
+import android.content.BroadcastReceiver;
 import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.graphics.Rect;
+import android.os.Handler;
 import android.os.RemoteException;
 import android.view.Gravity;
 
@@ -67,8 +70,8 @@
  */
 public class TvPipController implements PipTransitionController.PipTransitionCallback,
         TvPipBoundsController.PipBoundsListener, TvPipMenuController.Delegate,
-        TvPipNotificationController.Delegate, DisplayController.OnDisplaysChangedListener,
-        ConfigurationChangeListener, UserChangeListener {
+        DisplayController.OnDisplaysChangedListener, ConfigurationChangeListener,
+        UserChangeListener {
     private static final String TAG = "TvPipController";
 
     private static final int NONEXISTENT_TASK_ID = -1;
@@ -98,6 +101,17 @@
      */
     private static final int STATE_PIP_MENU = 2;
 
+    static final String ACTION_SHOW_PIP_MENU =
+            "com.android.wm.shell.pip.tv.notification.action.SHOW_PIP_MENU";
+    static final String ACTION_CLOSE_PIP =
+            "com.android.wm.shell.pip.tv.notification.action.CLOSE_PIP";
+    static final String ACTION_MOVE_PIP =
+            "com.android.wm.shell.pip.tv.notification.action.MOVE_PIP";
+    static final String ACTION_TOGGLE_EXPANDED_PIP =
+            "com.android.wm.shell.pip.tv.notification.action.TOGGLE_EXPANDED_PIP";
+    static final String ACTION_TO_FULLSCREEN =
+            "com.android.wm.shell.pip.tv.notification.action.FULLSCREEN";
+
     private final Context mContext;
 
     private final ShellController mShellController;
@@ -107,6 +121,7 @@
     private final PipAppOpsListener mAppOpsListener;
     private final PipTaskOrganizer mPipTaskOrganizer;
     private final PipMediaController mPipMediaController;
+    private final TvPipActionsProvider mTvPipActionsProvider;
     private final TvPipNotificationController mPipNotificationController;
     private final TvPipMenuController mTvPipMenuController;
     private final PipTransitionController mPipTransitionController;
@@ -115,14 +130,16 @@
     private final DisplayController mDisplayController;
     private final WindowManagerShellWrapper mWmShellWrapper;
     private final ShellExecutor mMainExecutor;
+    private final Handler mMainHandler; // For registering the broadcast receiver
     private final TvPipImpl mImpl = new TvPipImpl();
 
+    private final ActionBroadcastReceiver mActionBroadcastReceiver;
+
     @State
     private int mState = STATE_NO_PIP;
     private int mPreviousGravity = TvPipBoundsState.DEFAULT_TV_GRAVITY;
     private int mPinnedTaskId = NONEXISTENT_TASK_ID;
 
-    private RemoteAction mCloseAction;
     // How long the shell will wait for the app to close the PiP if a custom action is set.
     private int mPipForceCloseDelay;
 
@@ -146,6 +163,7 @@
             PipParamsChangedForwarder pipParamsChangedForwarder,
             DisplayController displayController,
             WindowManagerShellWrapper wmShell,
+            Handler mainHandler,
             ShellExecutor mainExecutor) {
         return new TvPipController(
                 context,
@@ -164,6 +182,7 @@
                 pipParamsChangedForwarder,
                 displayController,
                 wmShell,
+                mainHandler,
                 mainExecutor).mImpl;
     }
 
@@ -184,8 +203,10 @@
             PipParamsChangedForwarder pipParamsChangedForwarder,
             DisplayController displayController,
             WindowManagerShellWrapper wmShellWrapper,
+            Handler mainHandler,
             ShellExecutor mainExecutor) {
         mContext = context;
+        mMainHandler = mainHandler;
         mMainExecutor = mainExecutor;
         mShellController = shellController;
         mDisplayController = displayController;
@@ -198,12 +219,17 @@
         mTvPipBoundsController.setListener(this);
 
         mPipMediaController = pipMediaController;
+        mTvPipActionsProvider = new TvPipActionsProvider(context, pipMediaController,
+                this::executeAction);
 
         mPipNotificationController = pipNotificationController;
-        mPipNotificationController.setDelegate(this);
+        mPipNotificationController.setTvPipActionsProvider(mTvPipActionsProvider);
 
         mTvPipMenuController = tvPipMenuController;
         mTvPipMenuController.setDelegate(this);
+        mTvPipMenuController.setTvPipActionsProvider(mTvPipActionsProvider);
+
+        mActionBroadcastReceiver = new ActionBroadcastReceiver();
 
         mAppOpsListener = pipAppOpsListener;
         mPipTaskOrganizer = pipTaskOrganizer;
@@ -241,7 +267,7 @@
                 "%s: onConfigurationChanged(), state=%s", TAG, stateToName(mState));
 
         loadConfigurations();
-        mPipNotificationController.onConfigurationChanged(mContext);
+        mPipNotificationController.onConfigurationChanged();
         mTvPipBoundsAlgorithm.onConfigurationChanged(mContext);
     }
 
@@ -256,9 +282,10 @@
      * Starts the process if bringing up the Pip menu if by issuing a command to move Pip
      * task/window to the "Menu" position. We'll show the actual Menu UI (eg. actions) once the Pip
      * task/window is properly positioned in {@link #onPipTransitionFinished(int)}.
+     *
+     * @param moveMenu If true, show the moveMenu, otherwise show the regular menu.
      */
-    @Override
-    public void showPictureInPictureMenu() {
+    private void showPictureInPictureMenu(boolean moveMenu) {
         ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                 "%s: showPictureInPictureMenu(), state=%s", TAG, stateToName(mState));
 
@@ -269,7 +296,11 @@
         }
 
         setState(STATE_PIP_MENU);
-        mTvPipMenuController.showMenu();
+        if (moveMenu) {
+            mTvPipMenuController.showMovementMenu();
+        } else {
+            mTvPipMenuController.showMenu();
+        }
         updatePinnedStackBounds();
     }
 
@@ -289,8 +320,7 @@
     /**
      * Opens the "Pip-ed" Activity fullscreen.
      */
-    @Override
-    public void movePipToFullscreen() {
+    private void movePipToFullscreen() {
         ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                 "%s: movePipToFullscreen(), state=%s", TAG, stateToName(mState));
 
@@ -298,8 +328,7 @@
         onPipDisappeared();
     }
 
-    @Override
-    public void togglePipExpansion() {
+    private void togglePipExpansion() {
         ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                 "%s: togglePipExpansion()", TAG);
         boolean expanding = !mTvPipBoundsState.isTvPipExpanded();
@@ -310,18 +339,11 @@
         }
         mTvPipBoundsState.setTvPipManuallyCollapsed(!expanding);
         mTvPipBoundsState.setTvPipExpanded(expanding);
-        mPipNotificationController.updateExpansionState();
 
         updatePinnedStackBounds();
     }
 
     @Override
-    public void enterPipMovementMenu() {
-        setState(STATE_PIP_MENU);
-        mTvPipMenuController.showMovementMenuOnly();
-    }
-
-    @Override
     public void movePip(int keycode) {
         if (mTvPipBoundsAlgorithm.updateGravity(keycode)) {
             mTvPipMenuController.updateGravity(mTvPipBoundsState.getTvPipGravity());
@@ -373,30 +395,23 @@
     @Override
     public void onPipTargetBoundsChange(Rect targetBounds, int animationDuration) {
         mPipTaskOrganizer.scheduleAnimateResizePip(targetBounds,
-                animationDuration, rect -> mTvPipMenuController.updateExpansionState());
+                animationDuration, null);
         mTvPipMenuController.onPipTransitionToTargetBoundsStarted(targetBounds);
     }
 
     /**
      * Closes Pip window.
      */
-    @Override
     public void closePip() {
-        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                "%s: closePip(), state=%s, loseAction=%s", TAG, stateToName(mState),
-                mCloseAction);
+        closeCurrentPiP(mPinnedTaskId);
+    }
 
-        if (mCloseAction != null) {
-            try {
-                mCloseAction.getActionIntent().send();
-            } catch (PendingIntent.CanceledException e) {
-                ProtoLog.w(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                        "%s: Failed to send close action, %s", TAG, e);
-            }
-            mMainExecutor.executeDelayed(() -> closeCurrentPiP(mPinnedTaskId), mPipForceCloseDelay);
-        } else {
-            closeCurrentPiP(mPinnedTaskId);
-        }
+    /**
+     * Force close the current PiP after some time in case the custom action hasn't done it by
+     * itself.
+     */
+    public void customClosePip() {
+        mMainExecutor.executeDelayed(() -> closeCurrentPiP(mPinnedTaskId), mPipForceCloseDelay);
     }
 
     private void closeCurrentPiP(int pinnedTaskId) {
@@ -426,6 +441,7 @@
         mPinnedTaskId = pinnedTask.taskId;
 
         mPipMediaController.onActivityPinned();
+        mActionBroadcastReceiver.register();
         mPipNotificationController.show(pinnedTask.topActivity.getPackageName());
     }
 
@@ -445,6 +461,8 @@
                 "%s: onPipDisappeared() state=%s", TAG, stateToName(mState));
 
         mPipNotificationController.dismiss();
+        mActionBroadcastReceiver.unregister();
+
         mTvPipMenuController.closeMenu();
         mTvPipBoundsState.resetTvPipState();
         mTvPipBoundsController.onPipDismissed();
@@ -454,6 +472,11 @@
 
     @Override
     public void onPipTransitionStarted(int direction, Rect currentPipBounds) {
+        final boolean enterPipTransition = PipAnimationController.isInPipDirection(direction);
+        if (enterPipTransition && mState == STATE_NO_PIP) {
+            // Set the initial ability to expand the PiP when entering PiP.
+            updateExpansionState();
+        }
         ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                 "%s: onPipTransition_Started(), state=%s, direction=%d",
                 TAG, stateToName(mState), direction);
@@ -465,6 +488,7 @@
                 "%s: onPipTransition_Canceled(), state=%s", TAG, stateToName(mState));
         mTvPipMenuController.onPipTransitionFinished(
                 PipAnimationController.isInPipDirection(direction));
+        mTvPipActionsProvider.onPipExpansionToggled(mTvPipBoundsState.isTvPipExpanded());
     }
 
     @Override
@@ -477,6 +501,12 @@
                 "%s: onPipTransition_Finished(), state=%s, direction=%d",
                 TAG, stateToName(mState), direction);
         mTvPipMenuController.onPipTransitionFinished(enterPipTransition);
+        mTvPipActionsProvider.onPipExpansionToggled(mTvPipBoundsState.isTvPipExpanded());
+    }
+
+    private void updateExpansionState() {
+        mTvPipActionsProvider.updateExpansionEnabled(mTvPipBoundsState.isTvExpandedPipSupported()
+                && mTvPipBoundsState.getDesiredTvExpandedAspectRatio() != 0);
     }
 
     private void setState(@State int state) {
@@ -534,8 +564,7 @@
                 ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                         "%s: onActionsChanged()", TAG);
 
-                mTvPipMenuController.setAppActions(actions, closeAction);
-                mCloseAction = closeAction;
+                mTvPipActionsProvider.setAppActions(actions, closeAction);
             }
 
             @Override
@@ -555,7 +584,7 @@
                         "%s: onExpandedAspectRatioChanged: %f", TAG, ratio);
 
                 mTvPipBoundsState.setDesiredTvExpandedAspectRatio(ratio, false);
-                mTvPipMenuController.updateExpansionState();
+                updateExpansionState();
 
                 // 1) PiP is expanded and only aspect ratio changed, but wasn't disabled
                 // --> update bounds, but don't toggle
@@ -662,6 +691,90 @@
         }
     }
 
+    private void executeAction(@TvPipAction.ActionType int actionType) {
+        switch (actionType) {
+            case TvPipAction.ACTION_FULLSCREEN:
+                movePipToFullscreen();
+                break;
+            case TvPipAction.ACTION_CLOSE:
+                closePip();
+                break;
+            case TvPipAction.ACTION_MOVE:
+                showPictureInPictureMenu(/* moveMenu= */ true);
+                break;
+            case TvPipAction.ACTION_CUSTOM_CLOSE:
+                customClosePip();
+                break;
+            case TvPipAction.ACTION_EXPAND_COLLAPSE:
+                togglePipExpansion();
+                break;
+            default:
+                // NOOP
+                break;
+        }
+    }
+
+    private class ActionBroadcastReceiver extends BroadcastReceiver {
+        private static final String SYSTEMUI_PERMISSION = "com.android.systemui.permission.SELF";
+
+        final IntentFilter mIntentFilter;
+
+        {
+            mIntentFilter = new IntentFilter();
+            mIntentFilter.addAction(ACTION_CLOSE_PIP);
+            mIntentFilter.addAction(ACTION_SHOW_PIP_MENU);
+            mIntentFilter.addAction(ACTION_MOVE_PIP);
+            mIntentFilter.addAction(ACTION_TOGGLE_EXPANDED_PIP);
+            mIntentFilter.addAction(ACTION_TO_FULLSCREEN);
+        }
+
+        boolean mRegistered = false;
+
+        void register() {
+            if (mRegistered) return;
+
+            mContext.registerReceiverForAllUsers(this, mIntentFilter, SYSTEMUI_PERMISSION,
+                    mMainHandler);
+            mRegistered = true;
+        }
+
+        void unregister() {
+            if (!mRegistered) return;
+
+            mContext.unregisterReceiver(this);
+            mRegistered = false;
+        }
+
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            final String action = intent.getAction();
+            ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
+                    "%s: on(Broadcast)Receive(), action=%s", TAG, action);
+
+            if (ACTION_SHOW_PIP_MENU.equals(action)) {
+                showPictureInPictureMenu(/* moveMenu= */ false);
+            } else {
+                executeAction(getCorrespondingActionType(action));
+            }
+        }
+
+        @TvPipAction.ActionType
+        private int getCorrespondingActionType(String broadcast) {
+            if (ACTION_CLOSE_PIP.equals(broadcast)) {
+                return TvPipAction.ACTION_CLOSE;
+            } else if (ACTION_MOVE_PIP.equals(broadcast)) {
+                return TvPipAction.ACTION_MOVE;
+            } else if (ACTION_TOGGLE_EXPANDED_PIP.equals(broadcast)) {
+                return TvPipAction.ACTION_EXPAND_COLLAPSE;
+            } else if (ACTION_TO_FULLSCREEN.equals(broadcast)) {
+                return TvPipAction.ACTION_FULLSCREEN;
+            }
+
+            // Default: handle it like an action we don't know the content of.
+            return TvPipAction.ACTION_CUSTOM;
+        }
+    }
+
     private class TvPipImpl implements Pip {
         // Not used
     }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipCustomAction.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipCustomAction.java
new file mode 100644
index 0000000..449a2bf
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipCustomAction.java
@@ -0,0 +1,96 @@
+/*
+ * 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.wm.shell.pip.tv;
+
+import static android.app.Notification.Action.SEMANTIC_ACTION_DELETE;
+import static android.app.Notification.Action.SEMANTIC_ACTION_NONE;
+
+import android.annotation.NonNull;
+import android.app.Notification;
+import android.app.PendingIntent;
+import android.app.RemoteAction;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Handler;
+
+import com.android.internal.protolog.common.ProtoLog;
+import com.android.wm.shell.common.TvWindowMenuActionButton;
+import com.android.wm.shell.protolog.ShellProtoLogGroup;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * A TvPipAction for actions that the app provides via {@link
+ * android.app.PictureInPictureParams.Builder#setCloseAction(RemoteAction)} or {@link
+ * android.app.PictureInPictureParams.Builder#setActions(List)}.
+ */
+public class TvPipCustomAction extends TvPipAction {
+    private static final String TAG = TvPipCustomAction.class.getSimpleName();
+
+    private final RemoteAction mRemoteAction;
+
+    TvPipCustomAction(@ActionType int actionType, @NonNull RemoteAction remoteAction,
+            SystemActionsHandler systemActionsHandler) {
+        super(actionType, systemActionsHandler);
+        Objects.requireNonNull(remoteAction);
+        mRemoteAction = remoteAction;
+    }
+
+    void populateButton(@NonNull TvWindowMenuActionButton button, Handler mainHandler) {
+        if (button == null || mainHandler == null) return;
+        if (mRemoteAction.getContentDescription().length() > 0) {
+            button.setTextAndDescription(mRemoteAction.getContentDescription());
+        } else {
+            button.setTextAndDescription(mRemoteAction.getTitle());
+        }
+        button.setImageIconAsync(mRemoteAction.getIcon(), mainHandler);
+        button.setEnabled(isCloseAction() || mRemoteAction.isEnabled());
+    }
+
+    PendingIntent getPendingIntent() {
+        return mRemoteAction.getActionIntent();
+    }
+
+    void executeAction() {
+        super.executeAction();
+        try {
+            mRemoteAction.getActionIntent().send();
+        } catch (PendingIntent.CanceledException e) {
+            ProtoLog.w(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
+                    "%s: Failed to send action, %s", TAG, e);
+        }
+    }
+
+    @Override
+    Notification.Action toNotificationAction(Context context) {
+        Notification.Action.Builder builder = new Notification.Action.Builder(
+                mRemoteAction.getIcon(),
+                mRemoteAction.getTitle(),
+                mRemoteAction.getActionIntent());
+        Bundle extras = new Bundle();
+        extras.putCharSequence(Notification.EXTRA_PICTURE_CONTENT_DESCRIPTION,
+                mRemoteAction.getContentDescription());
+        builder.addExtras(extras);
+
+        builder.setSemanticAction(isCloseAction()
+                ? SEMANTIC_ACTION_DELETE : SEMANTIC_ACTION_NONE);
+        builder.setContextual(true);
+        return builder.build();
+    }
+
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java
index ab7edbf..00e4f47 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java
@@ -41,13 +41,10 @@
 import com.android.internal.protolog.common.ProtoLog;
 import com.android.wm.shell.R;
 import com.android.wm.shell.common.SystemWindows;
-import com.android.wm.shell.pip.PipMediaController;
 import com.android.wm.shell.pip.PipMenuController;
 import com.android.wm.shell.protolog.ShellProtoLogGroup;
 
-import java.util.ArrayList;
 import java.util.List;
-import java.util.Objects;
 
 /**
  * Manages the visibility of the PiP Menu as user interacts with PiP.
@@ -60,22 +57,20 @@
     private final SystemWindows mSystemWindows;
     private final TvPipBoundsState mTvPipBoundsState;
     private final Handler mMainHandler;
+    private TvPipActionsProvider mTvPipActionsProvider;
 
     private Delegate mDelegate;
     private SurfaceControl mLeash;
     private TvPipMenuView mPipMenuView;
     private View mPipBackgroundView;
 
+    private boolean mMenuIsOpen;
     // User can actively move the PiP via the DPAD.
     private boolean mInMoveMode;
     // Used when only showing the move menu since we want to close the menu completely when
     // exiting the move menu instead of showing the regular button menu.
     private boolean mCloseAfterExitMoveMenu;
 
-    private final List<RemoteAction> mMediaActions = new ArrayList<>();
-    private final List<RemoteAction> mAppActions = new ArrayList<>();
-    private RemoteAction mCloseAction;
-
     private SyncRtSurfaceTransactionApplier mApplier;
     private SyncRtSurfaceTransactionApplier mBackgroundApplier;
     RectF mTmpSourceRectF = new RectF();
@@ -83,8 +78,7 @@
     Matrix mMoveTransform = new Matrix();
 
     public TvPipMenuController(Context context, TvPipBoundsState tvPipBoundsState,
-            SystemWindows systemWindows, PipMediaController pipMediaController,
-            Handler mainHandler) {
+            SystemWindows systemWindows, Handler mainHandler) {
         mContext = context;
         mTvPipBoundsState = tvPipBoundsState;
         mSystemWindows = systemWindows;
@@ -101,9 +95,6 @@
         context.registerReceiverForAllUsers(closeSystemDialogsBroadcastReceiver,
                 new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS), null /* permission */,
                 mainHandler, Context.RECEIVER_EXPORTED);
-
-        pipMediaController.addActionListener(this::onMediaActionsChanged);
-
     }
 
     void setDelegate(Delegate delegate) {
@@ -120,6 +111,10 @@
         mDelegate = delegate;
     }
 
+    void setTvPipActionsProvider(TvPipActionsProvider tvPipActionsProvider) {
+        mTvPipActionsProvider = tvPipActionsProvider;
+    }
+
     @Override
     public void attach(SurfaceControl leash) {
         if (mDelegate == null) {
@@ -146,15 +141,19 @@
         int pipMenuBorderWidth = mContext.getResources()
                 .getDimensionPixelSize(R.dimen.pip_menu_border_width);
         mTvPipBoundsState.setPipMenuPermanentDecorInsets(Insets.of(-pipMenuBorderWidth,
-                    -pipMenuBorderWidth, -pipMenuBorderWidth, -pipMenuBorderWidth));
+                -pipMenuBorderWidth, -pipMenuBorderWidth, -pipMenuBorderWidth));
         mTvPipBoundsState.setPipMenuTemporaryDecorInsets(Insets.of(0, 0, 0, -pipEduTextHeight));
     }
 
     private void attachPipMenuView() {
-        mPipMenuView = new TvPipMenuView(mContext, mMainHandler, this);
+        if (mTvPipActionsProvider == null) {
+            ProtoLog.e(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
+                    "%s: Actions provider is not set", TAG);
+            return;
+        }
+        mPipMenuView = new TvPipMenuView(mContext, mMainHandler, this, mTvPipActionsProvider);
         setUpViewSurfaceZOrder(mPipMenuView, 1);
         addPipMenuViewToSystemWindows(mPipMenuView, MENU_WINDOW_TITLE);
-        maybeUpdateMenuViewActions();
     }
 
     private void attachPipBackgroundView() {
@@ -189,17 +188,22 @@
         // and the menu view has been fully remeasured and relaid out, we add a small delay here by
         // posting on the handler.
         mMainHandler.post(() -> {
-            mPipMenuView.onPipTransitionFinished(
-                    enterTransition, mTvPipBoundsState.isTvPipExpanded());
+            if (mPipMenuView != null) {
+                mPipMenuView.onPipTransitionFinished(enterTransition);
+            }
         });
     }
 
-    void showMovementMenuOnly() {
+    void showMovementMenu() {
         ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                 "%s: showMovementMenuOnly()", TAG);
         setInMoveMode(true);
-        mCloseAfterExitMoveMenu = true;
-        showMenuInternal();
+        if (mMenuIsOpen) {
+            mPipMenuView.showMoveMenu(mDelegate.getPipGravity());
+        } else {
+            mCloseAfterExitMoveMenu = true;
+            showMenuInternal();
+        }
     }
 
     @Override
@@ -214,14 +218,13 @@
         if (mPipMenuView == null) {
             return;
         }
-        maybeUpdateMenuViewActions();
-        updateExpansionState();
 
+        mMenuIsOpen = true;
         grantPipMenuFocus(true);
         if (mInMoveMode) {
             mPipMenuView.showMoveMenu(mDelegate.getPipGravity());
         } else {
-            mPipMenuView.showButtonsMenu();
+            mPipMenuView.showButtonsMenu(/* exitingMoveMode= */ false);
         }
         mPipMenuView.updateBounds(mTvPipBoundsState.getBounds());
     }
@@ -236,11 +239,6 @@
         mPipMenuView.showMovementHints(gravity);
     }
 
-    void updateExpansionState() {
-        mPipMenuView.setExpandedModeEnabled(mTvPipBoundsState.isTvExpandedPipSupported()
-                && mTvPipBoundsState.getDesiredTvExpandedAspectRatio() != 0);
-    }
-
     private Rect calculateMenuSurfaceBounds(Rect pipBounds) {
         return mPipMenuView.getPipMenuContainerBounds(pipBounds);
     }
@@ -252,6 +250,8 @@
         if (mPipMenuView == null) {
             return;
         }
+
+        mMenuIsOpen = false;
         mPipMenuView.hideAllUserControls();
         grantPipMenuFocus(false);
         mDelegate.onMenuClosed();
@@ -272,29 +272,19 @@
     }
 
     @Override
-    public void onEnterMoveMode() {
-        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                "%s: onEnterMoveMode - %b, close when exiting move menu: %b", TAG, mInMoveMode,
-                mCloseAfterExitMoveMenu);
-        setInMoveMode(true);
-        mPipMenuView.showMoveMenu(mDelegate.getPipGravity());
-    }
-
-    @Override
     public boolean onExitMoveMode() {
         ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                "%s: onExitMoveMode - %b, close when exiting move menu: %b", TAG, mInMoveMode,
-                mCloseAfterExitMoveMenu);
+                "%s: onExitMoveMode - %b, close when exiting move menu: %b",
+                TAG, mInMoveMode, mCloseAfterExitMoveMenu);
 
-        if (mCloseAfterExitMoveMenu) {
-            setInMoveMode(false);
-            mCloseAfterExitMoveMenu = false;
-            closeMenu();
-            return true;
-        }
         if (mInMoveMode) {
             setInMoveMode(false);
-            mPipMenuView.showButtonsMenu();
+            if (mCloseAfterExitMoveMenu) {
+                mCloseAfterExitMoveMenu = false;
+                closeMenu();
+            } else {
+                mPipMenuView.showButtonsMenu(/* exitingMoveMode= */ true);
+            }
             return true;
         }
         return false;
@@ -319,51 +309,7 @@
 
     @Override
     public void setAppActions(List<RemoteAction> actions, RemoteAction closeAction) {
-        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                "%s: setAppActions()", TAG);
-        updateAdditionalActionsList(mAppActions, actions, closeAction);
-    }
-
-    private void onMediaActionsChanged(List<RemoteAction> actions) {
-        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                "%s: onMediaActionsChanged()", TAG);
-
-        // Hide disabled actions.
-        List<RemoteAction> enabledActions = new ArrayList<>();
-        for (RemoteAction remoteAction : actions) {
-            if (remoteAction.isEnabled()) {
-                enabledActions.add(remoteAction);
-            }
-        }
-        updateAdditionalActionsList(mMediaActions, enabledActions, mCloseAction);
-    }
-
-    private void updateAdditionalActionsList(List<RemoteAction> destination,
-            @Nullable List<RemoteAction> source, RemoteAction closeAction) {
-        final int number = source != null ? source.size() : 0;
-        if (number == 0 && destination.isEmpty() && Objects.equals(closeAction, mCloseAction)) {
-            // Nothing changed.
-            return;
-        }
-
-        mCloseAction = closeAction;
-
-        destination.clear();
-        if (number > 0) {
-            destination.addAll(source);
-        }
-        maybeUpdateMenuViewActions();
-    }
-
-    private void maybeUpdateMenuViewActions() {
-        if (mPipMenuView == null) {
-            return;
-        }
-        if (!mAppActions.isEmpty()) {
-            mPipMenuView.setAdditionalActions(mAppActions, mCloseAction, mMainHandler);
-        } else {
-            mPipMenuView.setAdditionalActions(mMediaActions, mCloseAction, mMainHandler);
-        }
+        // NOOP - handled via the TvPipActionsProvider
     }
 
     @Override
@@ -544,42 +490,21 @@
     }
 
     @Override
-    public void onCloseButtonClick() {
-        mDelegate.closePip();
-    }
-
-    @Override
-    public void onFullscreenButtonClick() {
-        mDelegate.movePipToFullscreen();
-    }
-
-    @Override
-    public void onToggleExpandedMode() {
-        mDelegate.togglePipExpansion();
-    }
-
-    @Override
     public void onCloseEduText() {
         mTvPipBoundsState.setPipMenuTemporaryDecorInsets(Insets.NONE);
         mDelegate.closeEduText();
     }
 
     interface Delegate {
-        void movePipToFullscreen();
-
         void movePip(int keycode);
 
         void onInMoveModeChanged();
 
         int getPipGravity();
 
-        void togglePipExpansion();
-
         void onMenuClosed();
 
         void closeEduText();
-
-        void closePip();
     }
 
     private void grantPipMenuFocus(boolean grantFocus) {
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuView.java
index 57e95c4..56c602a 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuView.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuView.java
@@ -25,119 +25,102 @@
 import static android.view.KeyEvent.KEYCODE_DPAD_UP;
 import static android.view.KeyEvent.KEYCODE_ENTER;
 
-import android.app.PendingIntent;
-import android.app.RemoteAction;
+import static com.android.wm.shell.pip.tv.TvPipAction.ACTION_MOVE;
+
 import android.content.Context;
 import android.graphics.Rect;
 import android.os.Handler;
 import android.view.Gravity;
 import android.view.KeyEvent;
-import android.view.SurfaceControl;
 import android.view.View;
 import android.view.ViewGroup;
-import android.view.ViewRootImpl;
 import android.view.accessibility.AccessibilityManager;
 import android.widget.FrameLayout;
-import android.widget.HorizontalScrollView;
 import android.widget.ImageView;
-import android.widget.LinearLayout;
-import android.widget.ScrollView;
 
 import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
 
 import com.android.internal.protolog.common.ProtoLog;
+import com.android.internal.widget.LinearLayoutManager;
+import com.android.internal.widget.RecyclerView;
 import com.android.wm.shell.R;
 import com.android.wm.shell.common.TvWindowMenuActionButton;
 import com.android.wm.shell.pip.PipUtils;
 import com.android.wm.shell.protolog.ShellProtoLogGroup;
 
-import java.util.ArrayList;
 import java.util.List;
 
 /**
- * A View that represents Pip Menu on TV. It's responsible for displaying 3 ever-present Pip Menu
- * actions: Fullscreen, Move and Close, but could also display "additional" actions, that may be set
- * via a {@link #setAdditionalActions(List, RemoteAction, Handler)} call.
+ * A View that represents Pip Menu on TV. It's responsible for displaying the Pip menu actions from
+ * the TvPipActionsProvider as well as the buttons for manually moving the PiP.
  */
-public class TvPipMenuView extends FrameLayout implements View.OnClickListener {
+public class TvPipMenuView extends FrameLayout implements TvPipActionsProvider.Listener {
     private static final String TAG = "TvPipMenuView";
 
-    private static final int FIRST_CUSTOM_ACTION_POSITION = 3;
+    private final TvPipMenuView.Listener mListener;
 
-    private final Listener mListener;
+    private final TvPipActionsProvider mTvPipActionsProvider;
 
-    private final LinearLayout mActionButtonsContainer;
-    private final View mMenuFrameView;
-    private final List<TvWindowMenuActionButton> mAdditionalButtons = new ArrayList<>();
+    private final RecyclerView mActionButtonsRecyclerView;
+    private final LinearLayoutManager mButtonLayoutManager;
+    private final RecyclerViewAdapter mRecyclerViewAdapter;
+
     private final View mPipFrameView;
+    private final View mMenuFrameView;
     private final View mPipView;
+
+    private final View mPipBackground;
+    private final View mDimLayer;
+
     private final TvPipMenuEduTextDrawer mEduTextDrawer;
+
     private final int mPipMenuOuterSpace;
     private final int mPipMenuBorderWidth;
 
+    private final int mPipMenuFadeAnimationDuration;
+    private final int mResizeAnimationDuration;
+
     private final ImageView mArrowUp;
     private final ImageView mArrowRight;
     private final ImageView mArrowDown;
     private final ImageView mArrowLeft;
     private final TvWindowMenuActionButton mA11yDoneButton;
 
-    private final View mPipBackground;
-    private final View mDimLayer;
-
-    private final ScrollView mScrollView;
-    private final HorizontalScrollView mHorizontalScrollView;
-    private View mFocusedButton;
-
     private Rect mCurrentPipBounds;
     private boolean mMoveMenuIsVisible;
     private boolean mButtonMenuIsVisible;
-
-    private final TvWindowMenuActionButton mExpandButton;
-    private final TvWindowMenuActionButton mCloseButton;
-
     private boolean mSwitchingOrientation;
 
-    private final int mPipMenuFadeAnimationDuration;
-    private final int mResizeAnimationDuration;
-
     private final AccessibilityManager mA11yManager;
     private final Handler mMainHandler;
 
     public TvPipMenuView(@NonNull Context context, @NonNull Handler mainHandler,
-            @NonNull Listener listener) {
+            @NonNull Listener listener, TvPipActionsProvider tvPipActionsProvider) {
         super(context, null, 0, 0);
-
         inflate(context, R.layout.tv_pip_menu, this);
 
         mMainHandler = mainHandler;
         mListener = listener;
-
         mA11yManager = context.getSystemService(AccessibilityManager.class);
 
-        mActionButtonsContainer = findViewById(R.id.tv_pip_menu_action_buttons);
-        mActionButtonsContainer.findViewById(R.id.tv_pip_menu_fullscreen_button)
-                .setOnClickListener(this);
+        mActionButtonsRecyclerView = findViewById(R.id.tv_pip_menu_action_buttons);
+        mButtonLayoutManager = new LinearLayoutManager(mContext);
+        mActionButtonsRecyclerView.setLayoutManager(mButtonLayoutManager);
+        mActionButtonsRecyclerView.setPreserveFocusAfterLayout(true);
 
-        mCloseButton = mActionButtonsContainer.findViewById(R.id.tv_pip_menu_close_button);
-        mCloseButton.setOnClickListener(this);
-        mCloseButton.setIsCustomCloseAction(true);
+        mTvPipActionsProvider = tvPipActionsProvider;
+        mRecyclerViewAdapter = new RecyclerViewAdapter(tvPipActionsProvider.getActionsList());
+        mActionButtonsRecyclerView.setAdapter(mRecyclerViewAdapter);
 
-        mActionButtonsContainer.findViewById(R.id.tv_pip_menu_move_button)
-                .setOnClickListener(this);
-        mExpandButton = findViewById(R.id.tv_pip_menu_expand_button);
-        mExpandButton.setOnClickListener(this);
-
-        mPipBackground = findViewById(R.id.tv_pip_menu_background);
-        mDimLayer = findViewById(R.id.tv_pip_menu_dim_layer);
-
-        mScrollView = findViewById(R.id.tv_pip_menu_scroll);
-        mHorizontalScrollView = findViewById(R.id.tv_pip_menu_horizontal_scroll);
+        tvPipActionsProvider.addListener(this);
 
         mMenuFrameView = findViewById(R.id.tv_pip_menu_frame);
         mPipFrameView = findViewById(R.id.tv_pip_border);
         mPipView = findViewById(R.id.tv_pip);
 
+        mPipBackground = findViewById(R.id.tv_pip_menu_background);
+        mDimLayer = findViewById(R.id.tv_pip_menu_dim_layer);
+
         mArrowUp = findViewById(R.id.tv_pip_menu_arrow_up);
         mArrowRight = findViewById(R.id.tv_pip_menu_arrow_right);
         mArrowDown = findViewById(R.id.tv_pip_menu_arrow_down);
@@ -160,8 +143,12 @@
     }
 
     void onPipTransitionToTargetBoundsStarted(Rect targetBounds) {
+        if (targetBounds == null) {
+            return;
+        }
+
         // Fade out content by fading in view on top.
-        if (mCurrentPipBounds != null && targetBounds != null) {
+        if (mCurrentPipBounds != null) {
             boolean ratioChanged = PipUtils.aspectRatioChanged(
                     mCurrentPipBounds.width() / (float) mCurrentPipBounds.height(),
                     targetBounds.width() / (float) targetBounds.height());
@@ -177,7 +164,7 @@
         // Update buttons.
         final boolean vertical = targetBounds.height() > targetBounds.width();
         final boolean orientationChanged =
-                vertical != (mActionButtonsContainer.getOrientation() == LinearLayout.VERTICAL);
+                vertical != (mButtonLayoutManager.getOrientation() == LinearLayoutManager.VERTICAL);
         ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                 "%s: onPipTransitionToTargetBoundsStarted(), orientation changed %b",
                 TAG, orientationChanged);
@@ -187,27 +174,27 @@
 
         if (mButtonMenuIsVisible) {
             mSwitchingOrientation = true;
-            mActionButtonsContainer.animate()
+            mActionButtonsRecyclerView.animate()
                     .alpha(0)
                     .setInterpolator(TvPipInterpolators.EXIT)
                     .setDuration(mResizeAnimationDuration / 2)
                     .withEndAction(() -> {
-                        changeButtonScrollOrientation(targetBounds);
-                        updateButtonGravity(targetBounds);
+                        mButtonLayoutManager.setOrientation(vertical
+                                ? LinearLayoutManager.VERTICAL : LinearLayoutManager.HORIZONTAL);
                         // Only make buttons visible again in onPipTransitionFinished to keep in
                         // sync with PiP content alpha animation.
                     });
         } else {
-            changeButtonScrollOrientation(targetBounds);
-            updateButtonGravity(targetBounds);
+            mButtonLayoutManager.setOrientation(vertical
+                    ? LinearLayoutManager.VERTICAL : LinearLayoutManager.HORIZONTAL);
         }
     }
 
-    void onPipTransitionFinished(boolean enterTransition, boolean isTvPipExpanded) {
+    void onPipTransitionFinished(boolean enterTransition) {
         ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                 "%s: onPipTransitionFinished()", TAG);
 
-        // Fade in content by fading out view on top.
+        // Fade in content by fading out view on top (faded out at every aspect ratio change).
         mPipBackground.animate()
                 .alpha(0f)
                 .setDuration(mResizeAnimationDuration / 2)
@@ -218,16 +205,11 @@
             mEduTextDrawer.init();
         }
 
-        setIsExpanded(isTvPipExpanded);
-
-        // Update buttons.
         if (mSwitchingOrientation) {
-            mActionButtonsContainer.animate()
+            mActionButtonsRecyclerView.animate()
                     .alpha(1)
                     .setInterpolator(TvPipInterpolators.ENTER)
                     .setDuration(mResizeAnimationDuration / 2);
-        } else {
-            refocusPreviousButton();
         }
         mSwitchingOrientation = false;
     }
@@ -240,107 +222,9 @@
                 "%s: updateLayout, width: %s, height: %s", TAG, updatedBounds.width(),
                 updatedBounds.height());
         mCurrentPipBounds = updatedBounds;
-        if (!mSwitchingOrientation) {
-            updateButtonGravity(mCurrentPipBounds);
-        }
-
         updatePipFrameBounds();
     }
 
-    private void changeButtonScrollOrientation(Rect bounds) {
-        final boolean vertical = bounds.height() > bounds.width();
-
-        final ViewGroup oldScrollView = vertical ? mHorizontalScrollView : mScrollView;
-        final ViewGroup newScrollView = vertical ? mScrollView : mHorizontalScrollView;
-
-        if (oldScrollView.getChildCount() == 1) {
-            ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                    "%s: orientation changed", TAG);
-            oldScrollView.removeView(mActionButtonsContainer);
-            oldScrollView.setVisibility(GONE);
-            mActionButtonsContainer.setOrientation(vertical ? LinearLayout.VERTICAL
-                    : LinearLayout.HORIZONTAL);
-            newScrollView.addView(mActionButtonsContainer);
-            newScrollView.setVisibility(VISIBLE);
-            if (mFocusedButton != null) {
-                mFocusedButton.requestFocus();
-            }
-        }
-    }
-
-    /**
-     * Change button gravity based on new dimensions
-     */
-    private void updateButtonGravity(Rect bounds) {
-        final boolean vertical = bounds.height() > bounds.width();
-        // Use Math.max since the possible orientation change might not have been applied yet.
-        final int buttonsSize = Math.max(mActionButtonsContainer.getHeight(),
-                mActionButtonsContainer.getWidth());
-
-        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                "%s: buttons container width: %s, height: %s", TAG,
-                mActionButtonsContainer.getWidth(), mActionButtonsContainer.getHeight());
-
-        final boolean buttonsFit =
-                vertical ? buttonsSize < bounds.height()
-                        : buttonsSize < bounds.width();
-        final int buttonGravity = buttonsFit ? Gravity.CENTER
-                : (vertical ? Gravity.CENTER_HORIZONTAL : Gravity.CENTER_VERTICAL);
-
-        final LayoutParams params = (LayoutParams) mActionButtonsContainer.getLayoutParams();
-        params.gravity = buttonGravity;
-        mActionButtonsContainer.setLayoutParams(params);
-
-        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                "%s: vertical: %b, buttonsFit: %b, gravity: %s", TAG, vertical, buttonsFit,
-                Gravity.toString(buttonGravity));
-    }
-
-    private void refocusPreviousButton() {
-        if (mMoveMenuIsVisible || mCurrentPipBounds == null || mFocusedButton == null) {
-            return;
-        }
-        final boolean vertical = mCurrentPipBounds.height() > mCurrentPipBounds.width();
-
-        if (!mFocusedButton.hasFocus()) {
-            ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                    "%s: request focus from: %s", TAG, mFocusedButton);
-            mFocusedButton.requestFocus();
-        } else {
-            ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                    "%s: already focused: %s", TAG, mFocusedButton);
-        }
-
-        // Do we need to scroll?
-        final Rect buttonBounds = new Rect();
-        final Rect scrollBounds = new Rect();
-        if (vertical) {
-            mScrollView.getDrawingRect(scrollBounds);
-        } else {
-            mHorizontalScrollView.getDrawingRect(scrollBounds);
-        }
-        mFocusedButton.getHitRect(buttonBounds);
-
-        if (scrollBounds.contains(buttonBounds)) {
-            // Button is already completely visible, don't scroll
-            ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                    "%s: not scrolling", TAG);
-            return;
-        }
-
-        // Scrolling so the button is visible to the user.
-        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                "%s: scrolling to focused button", TAG);
-
-        if (vertical) {
-            mScrollView.smoothScrollTo((int) mFocusedButton.getX(),
-                    (int) mFocusedButton.getY());
-        } else {
-            mHorizontalScrollView.smoothScrollTo((int) mFocusedButton.getX(),
-                    (int) mFocusedButton.getY());
-        }
-    }
-
     Rect getPipMenuContainerBounds(Rect pipBounds) {
         final Rect menuUiBounds = new Rect(pipBounds);
         menuUiBounds.inset(-mPipMenuOuterSpace, -mPipMenuOuterSpace);
@@ -370,20 +254,14 @@
             mPipView.setLayoutParams(pipViewParams);
         }
 
-
-    }
-
-    void setExpandedModeEnabled(boolean enabled) {
-        mExpandButton.setVisibility(enabled ? VISIBLE : GONE);
-    }
-
-    void setIsExpanded(boolean expanded) {
-        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                "%s: setIsExpanded, expanded: %b", TAG, expanded);
-        mExpandButton.setImageResource(
-                expanded ? R.drawable.pip_ic_collapse : R.drawable.pip_ic_expand);
-        mExpandButton.setTextAndDescription(
-                expanded ? R.string.pip_collapse : R.string.pip_expand);
+        // Keep focused button within the visible area while the PiP is changing size. Otherwise,
+        // the button would lose focus which would cause a need for scrolling and re-focusing after
+        // the animation finishes, which does not look good.
+        View focusedChild = mActionButtonsRecyclerView.getFocusedChild();
+        if (focusedChild != null) {
+            mActionButtonsRecyclerView.scrollToPosition(
+                    mActionButtonsRecyclerView.getChildLayoutPosition(focusedChild));
+        }
     }
 
     /**
@@ -391,48 +269,63 @@
      */
     void showMoveMenu(int gravity) {
         ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, "%s: showMoveMenu()", TAG);
-        showButtonsMenu(false);
         showMovementHints(gravity);
+        setMenuButtonsVisible(false);
         setFrameHighlighted(true);
 
-        mHorizontalScrollView.setFocusable(false);
-        mScrollView.setFocusable(false);
+        animateAlphaTo(mA11yManager.isEnabled() ? 1f : 0f, mDimLayer);
 
         mEduTextDrawer.closeIfNeeded();
     }
 
-    void showButtonsMenu() {
+
+    void showButtonsMenu(boolean exitingMoveMode) {
         ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                "%s: showButtonsMenu()", TAG);
-        showButtonsMenu(true);
+                "%s: showButtonsMenu(), exitingMoveMode %b", TAG, exitingMoveMode);
+        setMenuButtonsVisible(true);
         hideMovementHints();
         setFrameHighlighted(true);
+        animateAlphaTo(1f, mDimLayer);
+        mEduTextDrawer.closeIfNeeded();
 
-        mHorizontalScrollView.setFocusable(true);
-        mScrollView.setFocusable(true);
-
-        // Always focus on the first button when opening the menu, except directly after moving.
-        if (mFocusedButton == null) {
-            // Focus on first button (there is a Space at position 0)
-            mFocusedButton = mActionButtonsContainer.getChildAt(1);
-            // Reset scroll position.
-            mScrollView.scrollTo(0, 0);
-            mHorizontalScrollView.scrollTo(
-                    isLayoutRtl() ? mActionButtonsContainer.getWidth() : 0, 0);
+        if (exitingMoveMode) {
+            scrollAndRefocusButton(mTvPipActionsProvider.getFirstIndexOfAction(ACTION_MOVE),
+                    /* alwaysScroll= */ false);
+        } else {
+            scrollAndRefocusButton(0, /* alwaysScroll= */ true);
         }
-        refocusPreviousButton();
+    }
+
+    private void scrollAndRefocusButton(int position, boolean alwaysScroll) {
+        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
+                "%s: scrollAndRefocusButton, target: %d", TAG, position);
+
+        if (alwaysScroll || !refocusButton(position)) {
+            mButtonLayoutManager.scrollToPositionWithOffset(position, 0);
+            mActionButtonsRecyclerView.post(() -> refocusButton(position));
+        }
     }
 
     /**
-     * Hides all menu views, including the menu frame.
+     * @return true if focus was requested, false if focus request could not be carried out due to
+     * the view for the position not being available (scrolling beforehand will be necessary).
      */
+    private boolean refocusButton(int position) {
+        View itemToFocus = mButtonLayoutManager.findViewByPosition(position);
+        if (itemToFocus != null) {
+            itemToFocus.requestFocus();
+            itemToFocus.requestAccessibilityFocus();
+        }
+        return itemToFocus != null;
+    }
+
     void hideAllUserControls() {
         ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                 "%s: hideAllUserControls()", TAG);
-        mFocusedButton = null;
-        showButtonsMenu(false);
+        setMenuButtonsVisible(false);
         hideMovementHints();
         setFrameHighlighted(false);
+        animateAlphaTo(0f, mDimLayer);
     }
 
     @Override
@@ -463,134 +356,19 @@
                 });
     }
 
-    /**
-     * Button order:
-     * - Fullscreen
-     * - Close
-     * - Custom actions (app or media actions)
-     * - System actions
-     */
-    void setAdditionalActions(List<RemoteAction> actions, RemoteAction closeAction,
-            Handler mainHandler) {
-        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                "%s: setAdditionalActions()", TAG);
-
-        // Replace system close action with custom close action if available
-        if (closeAction != null) {
-            setActionForButton(closeAction, mCloseButton, mainHandler);
-        } else {
-            mCloseButton.setTextAndDescription(R.string.pip_close);
-            mCloseButton.setImageResource(R.drawable.pip_ic_close_white);
-        }
-        mCloseButton.setIsCustomCloseAction(closeAction != null);
-        // Make sure the close action is always enabled
-        mCloseButton.setEnabled(true);
-
-        // Make sure we exactly as many additional buttons as we have actions to display.
-        final int actionsNumber = actions.size();
-        int buttonsNumber = mAdditionalButtons.size();
-        if (actionsNumber > buttonsNumber) {
-            // Add buttons until we have enough to display all the actions.
-            while (actionsNumber > buttonsNumber) {
-                TvWindowMenuActionButton button = new TvWindowMenuActionButton(mContext);
-                button.setOnClickListener(this);
-
-                mActionButtonsContainer.addView(button,
-                        FIRST_CUSTOM_ACTION_POSITION + buttonsNumber);
-                mAdditionalButtons.add(button);
-
-                buttonsNumber++;
-            }
-        } else if (actionsNumber < buttonsNumber) {
-            // Hide buttons until we as many as the actions.
-            while (actionsNumber < buttonsNumber) {
-                final View button = mAdditionalButtons.get(buttonsNumber - 1);
-                button.setVisibility(View.GONE);
-                button.setTag(null);
-
-                buttonsNumber--;
-            }
-        }
-
-        // "Assign" actions to the buttons.
-        for (int index = 0; index < actionsNumber; index++) {
-            final RemoteAction action = actions.get(index);
-            final TvWindowMenuActionButton button = mAdditionalButtons.get(index);
-
-            // Remove action if it matches the custom close action.
-            if (PipUtils.remoteActionsMatch(action, closeAction)) {
-                button.setVisibility(GONE);
-                continue;
-            }
-            setActionForButton(action, button, mainHandler);
-        }
-
-        if (mCurrentPipBounds != null) {
-            updateButtonGravity(mCurrentPipBounds);
-            refocusPreviousButton();
-        }
-    }
-
-    private void setActionForButton(RemoteAction action, TvWindowMenuActionButton button,
-            Handler mainHandler) {
-        button.setVisibility(View.VISIBLE); // Ensure the button is visible.
-        if (action.getContentDescription().length() > 0) {
-            button.setTextAndDescription(action.getContentDescription());
-        } else {
-            button.setTextAndDescription(action.getTitle());
-        }
-        button.setEnabled(action.isEnabled());
-        button.setTag(action);
-        action.getIcon().loadDrawableAsync(mContext, button::setImageDrawable, mainHandler);
-    }
-
-    @Nullable
-    SurfaceControl getWindowSurfaceControl() {
-        final ViewRootImpl root = getViewRootImpl();
-        if (root == null) {
-            return null;
-        }
-        final SurfaceControl out = root.getSurfaceControl();
-        if (out != null && out.isValid()) {
-            return out;
-        }
-        return null;
-    }
-
     @Override
-    public void onClick(View v) {
-        final int id = v.getId();
-        if (id == R.id.tv_pip_menu_fullscreen_button) {
-            mListener.onFullscreenButtonClick();
-        } else if (id == R.id.tv_pip_menu_move_button) {
-            mListener.onEnterMoveMode();
-        } else if (id == R.id.tv_pip_menu_close_button) {
-            mListener.onCloseButtonClick();
-        } else if (id == R.id.tv_pip_menu_expand_button) {
-            mListener.onToggleExpandedMode();
-        } else {
-            // This should be an "additional action"
-            final RemoteAction action = (RemoteAction) v.getTag();
-            if (action != null) {
-                try {
-                    action.getActionIntent().send();
-                } catch (PendingIntent.CanceledException e) {
-                    ProtoLog.w(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                            "%s: Failed to send action, %s", TAG, e);
-                }
-            } else {
-                ProtoLog.w(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                        "%s: RemoteAction is null", TAG);
-            }
+    public void onActionsChanged(int added, int updated, int startIndex) {
+        mRecyclerViewAdapter.notifyItemRangeChanged(startIndex, updated);
+        if (added > 0) {
+            mRecyclerViewAdapter.notifyItemRangeInserted(startIndex + updated, added);
+        } else if (added < 0) {
+            mRecyclerViewAdapter.notifyItemRangeRemoved(startIndex + updated, -added);
         }
     }
 
     @Override
     public boolean dispatchKeyEvent(KeyEvent event) {
         if (event.getAction() == ACTION_UP) {
-            if (!mMoveMenuIsVisible) {
-                mFocusedButton = mActionButtonsContainer.getFocusedChild();
-            }
 
             if (event.getKeyCode() == KEYCODE_BACK) {
                 mListener.onBackPress();
@@ -624,10 +402,6 @@
     public void showMovementHints(int gravity) {
         ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                 "%s: showMovementHints(), position: %s", TAG, Gravity.toString(gravity));
-
-        if (mMoveMenuIsVisible) {
-            return;
-        }
         mMoveMenuIsVisible = true;
 
         animateAlphaTo(checkGravity(gravity, Gravity.BOTTOM) ? 1f : 0f, mArrowUp);
@@ -643,9 +417,12 @@
 
         animateAlphaTo(a11yEnabled ? 1f : 0f, mA11yDoneButton);
         if (a11yEnabled) {
+            mA11yDoneButton.setVisibility(VISIBLE);
             mA11yDoneButton.setOnClickListener(v -> {
                 mListener.onExitMoveMode();
             });
+            mA11yDoneButton.requestFocus();
+            mA11yDoneButton.requestAccessibilityFocus();
         }
     }
 
@@ -684,33 +461,67 @@
     /**
      * Show or hide the pip buttons menu.
      */
-    public void showButtonsMenu(boolean show) {
+    private void setMenuButtonsVisible(boolean visible) {
         ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                "%s: showUserActions: %b", TAG, show);
-        if (mButtonMenuIsVisible == show) {
-            return;
-        }
-        mButtonMenuIsVisible = show;
-
-        if (show) {
-            mActionButtonsContainer.setVisibility(VISIBLE);
-            refocusPreviousButton();
-        }
-        animateAlphaTo(show ? 1 : 0, mActionButtonsContainer);
-        animateAlphaTo(show ? 1 : 0, mDimLayer);
-        mEduTextDrawer.closeIfNeeded();
+                "%s: showUserActions: %b", TAG, visible);
+        mButtonMenuIsVisible = visible;
+        animateAlphaTo(visible ? 1 : 0, mActionButtonsRecyclerView);
     }
 
     private void setFrameHighlighted(boolean highlighted) {
         mMenuFrameView.setActivated(highlighted);
     }
 
+    private class RecyclerViewAdapter extends
+            RecyclerView.Adapter<RecyclerViewAdapter.ButtonViewHolder> {
+
+        private final List<TvPipAction> mActionList;
+
+        RecyclerViewAdapter(List<TvPipAction> actionList) {
+            this.mActionList = actionList;
+        }
+
+        @NonNull
+        @Override
+        public ButtonViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+            return new ButtonViewHolder(new TvWindowMenuActionButton(mContext));
+        }
+
+        @Override
+        public void onBindViewHolder(@NonNull ButtonViewHolder holder, int position) {
+            TvPipAction action = mActionList.get(position);
+            action.populateButton(holder.mButton, mMainHandler);
+        }
+
+        @Override
+        public int getItemCount() {
+            return mActionList.size();
+        }
+
+        private class ButtonViewHolder extends RecyclerView.ViewHolder implements OnClickListener {
+            TvWindowMenuActionButton mButton;
+
+            ButtonViewHolder(@NonNull View itemView) {
+                super(itemView);
+                mButton = (TvWindowMenuActionButton) itemView;
+                mButton.setOnClickListener(this);
+            }
+
+            @Override
+            public void onClick(View v) {
+                TvPipAction action = mActionList.get(
+                        mActionButtonsRecyclerView.getChildLayoutPosition(v));
+                if (action != null) {
+                    action.executeAction();
+                }
+            }
+        }
+    }
+
     interface Listener extends TvPipMenuEduTextDrawer.Listener {
 
         void onBackPress();
 
-        void onEnterMoveMode();
-
         /**
          * Called when a button for exiting move mode was pressed.
          *
@@ -723,11 +534,5 @@
          * @return whether pip movement was handled.
          */
         boolean onPipMovement(int keycode);
-
-        void onCloseButtonClick();
-
-        void onFullscreenButtonClick();
-
-        void onToggleExpandedMode();
     }
-}
+}
\ No newline at end of file
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipNotificationController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipNotificationController.java
index e3308f0..f22ee59 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipNotificationController.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipNotificationController.java
@@ -16,18 +16,13 @@
 
 package com.android.wm.shell.pip.tv;
 
-import static android.app.Notification.Action.SEMANTIC_ACTION_DELETE;
-import static android.app.Notification.Action.SEMANTIC_ACTION_NONE;
-
+import android.annotation.NonNull;
 import android.app.Notification;
 import android.app.NotificationManager;
 import android.app.PendingIntent;
-import android.app.RemoteAction;
-import android.content.BroadcastReceiver;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
-import android.content.IntentFilter;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
 import android.graphics.Bitmap;
@@ -35,7 +30,6 @@
 import android.graphics.drawable.Icon;
 import android.media.session.MediaSession;
 import android.os.Bundle;
-import android.os.Handler;
 import android.text.TextUtils;
 
 import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
@@ -47,7 +41,6 @@
 import com.android.wm.shell.pip.PipUtils;
 import com.android.wm.shell.protolog.ShellProtoLogGroup;
 
-import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -55,39 +48,18 @@
  * <p>Once it's created, it will manage the PiP notification UI by itself except for handling
  * configuration changes and user initiated expanded PiP toggling.
  */
-public class TvPipNotificationController {
-    private static final String TAG = "TvPipNotification";
+public class TvPipNotificationController implements TvPipActionsProvider.Listener {
+    private static final String TAG = TvPipNotificationController.class.getSimpleName();
 
     // Referenced in com.android.systemui.util.NotificationChannels.
     public static final String NOTIFICATION_CHANNEL = "TVPIP";
     private static final String NOTIFICATION_TAG = "TvPip";
-    private static final String SYSTEMUI_PERMISSION = "com.android.systemui.permission.SELF";
-
-    private static final String ACTION_SHOW_PIP_MENU =
-            "com.android.wm.shell.pip.tv.notification.action.SHOW_PIP_MENU";
-    private static final String ACTION_CLOSE_PIP =
-            "com.android.wm.shell.pip.tv.notification.action.CLOSE_PIP";
-    private static final String ACTION_MOVE_PIP =
-            "com.android.wm.shell.pip.tv.notification.action.MOVE_PIP";
-    private static final String ACTION_TOGGLE_EXPANDED_PIP =
-            "com.android.wm.shell.pip.tv.notification.action.TOGGLE_EXPANDED_PIP";
-    private static final String ACTION_FULLSCREEN =
-            "com.android.wm.shell.pip.tv.notification.action.FULLSCREEN";
 
     private final Context mContext;
     private final PackageManager mPackageManager;
     private final NotificationManager mNotificationManager;
     private final Notification.Builder mNotificationBuilder;
-    private final ActionBroadcastReceiver mActionBroadcastReceiver;
-    private final Handler mMainHandler;
-    private Delegate mDelegate;
-    private final TvPipBoundsState mTvPipBoundsState;
-
-    private String mDefaultTitle;
-
-    private final List<RemoteAction> mCustomActions = new ArrayList<>();
-    private final List<RemoteAction> mMediaActions = new ArrayList<>();
-    private RemoteAction mCustomCloseAction;
+    private TvPipActionsProvider mTvPipActionsProvider;
 
     private MediaSession.Token mMediaSessionToken;
 
@@ -95,19 +67,23 @@
     private String mPackageName;
 
     private boolean mIsNotificationShown;
+    private String mDefaultTitle;
     private String mPipTitle;
     private String mPipSubtitle;
 
+    // Saving the actions, so they don't have to be regenerated when e.g. the PiP title changes.
+    @NonNull
+    private Notification.Action[] mPipActions;
+
     private Bitmap mActivityIcon;
 
     public TvPipNotificationController(Context context, PipMediaController pipMediaController,
-            PipParamsChangedForwarder pipParamsChangedForwarder, TvPipBoundsState tvPipBoundsState,
-            Handler mainHandler) {
+            PipParamsChangedForwarder pipParamsChangedForwarder) {
         mContext = context;
         mPackageManager = context.getPackageManager();
         mNotificationManager = context.getSystemService(NotificationManager.class);
-        mMainHandler = mainHandler;
-        mTvPipBoundsState = tvPipBoundsState;
+
+        mPipActions = new Notification.Action[0];
 
         mNotificationBuilder = new Notification.Builder(context, NOTIFICATION_CHANNEL)
                 .setLocalOnly(true)
@@ -117,34 +93,15 @@
                 .setOnlyAlertOnce(true)
                 .setSmallIcon(R.drawable.pip_icon)
                 .setAllowSystemGeneratedContextualActions(false)
-                .setContentIntent(createPendingIntent(context, ACTION_FULLSCREEN))
-                .setDeleteIntent(getCloseAction().actionIntent)
-                .extend(new Notification.TvExtender()
-                        .setContentIntent(createPendingIntent(context, ACTION_SHOW_PIP_MENU))
-                        .setDeleteIntent(createPendingIntent(context, ACTION_CLOSE_PIP)));
+                .setContentIntent(
+                        createPendingIntent(context, TvPipController.ACTION_TO_FULLSCREEN));
+        // TvExtender and DeleteIntent set later since they might change.
 
-        mActionBroadcastReceiver = new ActionBroadcastReceiver();
-
-        pipMediaController.addActionListener(this::onMediaActionsChanged);
         pipMediaController.addTokenListener(this::onMediaSessionTokenChanged);
 
         pipParamsChangedForwarder.addListener(
                 new PipParamsChangedForwarder.PipParamsChangedCallback() {
                     @Override
-                    public void onExpandedAspectRatioChanged(float ratio) {
-                        updateExpansionState();
-                    }
-
-                    @Override
-                    public void onActionsChanged(List<RemoteAction> actions,
-                            RemoteAction closeAction) {
-                        mCustomActions.clear();
-                        mCustomActions.addAll(actions);
-                        mCustomCloseAction = closeAction;
-                        updateNotificationContent();
-                    }
-
-                    @Override
                     public void onTitleChanged(String title) {
                         mPipTitle = title;
                         updateNotificationContent();
@@ -157,34 +114,33 @@
                     }
                 });
 
-        onConfigurationChanged(context);
+        onConfigurationChanged();
     }
 
-    void setDelegate(Delegate delegate) {
-        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, "%s: setDelegate(), delegate=%s",
-                TAG, delegate);
+    /**
+     * Call before showing any notification.
+     */
+    void setTvPipActionsProvider(@NonNull TvPipActionsProvider tvPipActionsProvider) {
+        mTvPipActionsProvider = tvPipActionsProvider;
+        mTvPipActionsProvider.addListener(this);
+    }
 
-        if (mDelegate != null) {
-            throw new IllegalStateException(
-                    "The delegate has already been set and should not change.");
-        }
-        if (delegate == null) {
-            throw new IllegalArgumentException("The delegate must not be null.");
-        }
-
-        mDelegate = delegate;
+    void onConfigurationChanged() {
+        mDefaultTitle = mContext.getResources().getString(R.string.pip_notification_unknown_title);
+        updateNotificationContent();
     }
 
     void show(String packageName) {
         ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, "%s: show %s", TAG, packageName);
-        if (mDelegate == null) {
-            throw new IllegalStateException("Delegate is not set.");
+        if (mTvPipActionsProvider == null) {
+            ProtoLog.e(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
+                    "%s: Missing TvPipActionsProvider", TAG);
+            return;
         }
 
         mIsNotificationShown = true;
         mPackageName = packageName;
         mActivityIcon = getActivityIcon();
-        mActionBroadcastReceiver.register();
 
         updateNotificationContent();
     }
@@ -194,151 +150,42 @@
 
         mIsNotificationShown = false;
         mPackageName = null;
-        mActionBroadcastReceiver.unregister();
-
         mNotificationManager.cancel(NOTIFICATION_TAG, SystemMessage.NOTE_TV_PIP);
     }
 
-    private Notification.Action getToggleAction(boolean expanded) {
-        if (expanded) {
-            return createSystemAction(R.drawable.pip_ic_collapse,
-                    R.string.pip_collapse, ACTION_TOGGLE_EXPANDED_PIP);
-        } else {
-            return createSystemAction(R.drawable.pip_ic_expand, R.string.pip_expand,
-                    ACTION_TOGGLE_EXPANDED_PIP);
-        }
-    }
-
-    private Notification.Action createSystemAction(int iconRes, int titleRes, String action) {
-        Notification.Action.Builder builder = new Notification.Action.Builder(
-                Icon.createWithResource(mContext, iconRes),
-                mContext.getString(titleRes),
-                createPendingIntent(mContext, action));
-        builder.setContextual(true);
-        return builder.build();
-    }
-
-    private void onMediaActionsChanged(List<RemoteAction> actions) {
-        mMediaActions.clear();
-        mMediaActions.addAll(actions);
-        if (mCustomActions.isEmpty()) {
-            updateNotificationContent();
-        }
-    }
-
     private void onMediaSessionTokenChanged(MediaSession.Token token) {
         mMediaSessionToken = token;
         updateNotificationContent();
     }
 
-    private Notification.Action remoteToNotificationAction(RemoteAction action) {
-        return remoteToNotificationAction(action, SEMANTIC_ACTION_NONE);
-    }
-
-    private Notification.Action remoteToNotificationAction(RemoteAction action,
-            int semanticAction) {
-        Notification.Action.Builder builder = new Notification.Action.Builder(action.getIcon(),
-                action.getTitle(),
-                action.getActionIntent());
-        if (action.getContentDescription() != null) {
-            Bundle extras = new Bundle();
-            extras.putCharSequence(Notification.EXTRA_PICTURE_CONTENT_DESCRIPTION,
-                    action.getContentDescription());
-            builder.addExtras(extras);
-        }
-        builder.setSemanticAction(semanticAction);
-        builder.setContextual(true);
-        return builder.build();
-    }
-
-    private Notification.Action[] getNotificationActions() {
-        final List<Notification.Action> actions = new ArrayList<>();
-
-        // 1. Fullscreen
-        actions.add(getFullscreenAction());
-        // 2. Close
-        actions.add(getCloseAction());
-        // 3. App actions
-        final List<RemoteAction> appActions =
-                mCustomActions.isEmpty() ? mMediaActions : mCustomActions;
-        for (RemoteAction appAction : appActions) {
-            if (PipUtils.remoteActionsMatch(mCustomCloseAction, appAction)
-                    || !appAction.isEnabled()) {
-                continue;
-            }
-            actions.add(remoteToNotificationAction(appAction));
-        }
-        // 4. Move
-        actions.add(getMoveAction());
-        // 5. Toggle expansion (if expanded PiP enabled)
-        if (mTvPipBoundsState.getDesiredTvExpandedAspectRatio() > 0
-                && mTvPipBoundsState.isTvExpandedPipSupported()) {
-            actions.add(getToggleAction(mTvPipBoundsState.isTvPipExpanded()));
-        }
-        return actions.toArray(new Notification.Action[0]);
-    }
-
-    private Notification.Action getCloseAction() {
-        if (mCustomCloseAction == null) {
-            return createSystemAction(R.drawable.pip_ic_close_white, R.string.pip_close,
-                    ACTION_CLOSE_PIP);
-        } else {
-            return remoteToNotificationAction(mCustomCloseAction, SEMANTIC_ACTION_DELETE);
-        }
-    }
-
-    private Notification.Action getFullscreenAction() {
-        return createSystemAction(R.drawable.pip_ic_fullscreen_white,
-                R.string.pip_fullscreen, ACTION_FULLSCREEN);
-    }
-
-    private Notification.Action getMoveAction() {
-        return createSystemAction(R.drawable.pip_ic_move_white, R.string.pip_move,
-                ACTION_MOVE_PIP);
-    }
-
-    /**
-     * Called by {@link TvPipController} when the configuration is changed.
-     */
-    void onConfigurationChanged(Context context) {
-        mDefaultTitle = context.getResources().getString(R.string.pip_notification_unknown_title);
-        updateNotificationContent();
-    }
-
-    void updateExpansionState() {
-        updateNotificationContent();
-    }
-
     private void updateNotificationContent() {
         if (mPackageManager == null || !mIsNotificationShown) {
             return;
         }
 
-        Notification.Action[] actions = getNotificationActions();
         ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                 "%s: update(), title: %s, subtitle: %s, mediaSessionToken: %s, #actions: %s", TAG,
-                getNotificationTitle(), mPipSubtitle, mMediaSessionToken, actions.length);
-        for (Notification.Action action : actions) {
-            ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, "%s: action: %s", TAG,
-                    action.toString());
-        }
-
+                getNotificationTitle(), mPipSubtitle, mMediaSessionToken, mPipActions.length);
         mNotificationBuilder
                 .setWhen(System.currentTimeMillis())
                 .setContentTitle(getNotificationTitle())
                 .setContentText(mPipSubtitle)
                 .setSubText(getApplicationLabel(mPackageName))
-                .setActions(actions);
+                .setActions(mPipActions);
         setPipIcon();
 
         Bundle extras = new Bundle();
         extras.putParcelable(Notification.EXTRA_MEDIA_SESSION, mMediaSessionToken);
         mNotificationBuilder.setExtras(extras);
 
+        PendingIntent closeIntent = mTvPipActionsProvider.getCloseAction().getPendingIntent();
+        mNotificationBuilder.setDeleteIntent(closeIntent);
         // TvExtender not recognized if not set last.
         mNotificationBuilder.extend(new Notification.TvExtender()
-                .setContentIntent(createPendingIntent(mContext, ACTION_SHOW_PIP_MENU))
-                .setDeleteIntent(createPendingIntent(mContext, ACTION_CLOSE_PIP)));
+                .setContentIntent(
+                        createPendingIntent(mContext, TvPipController.ACTION_SHOW_PIP_MENU))
+                .setDeleteIntent(closeIntent));
+
         mNotificationManager.notify(NOTIFICATION_TAG, SystemMessage.NOTE_TV_PIP,
                 mNotificationBuilder.build());
     }
@@ -390,68 +237,20 @@
         return ImageUtils.buildScaledBitmap(drawable, width, height, /* allowUpscaling */ true);
     }
 
-    private static PendingIntent createPendingIntent(Context context, String action) {
+    static PendingIntent createPendingIntent(Context context, String action) {
         return PendingIntent.getBroadcast(context, 0,
                 new Intent(action).setPackage(context.getPackageName()),
                 PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
     }
 
-    private class ActionBroadcastReceiver extends BroadcastReceiver {
-        final IntentFilter mIntentFilter;
-        {
-            mIntentFilter = new IntentFilter();
-            mIntentFilter.addAction(ACTION_CLOSE_PIP);
-            mIntentFilter.addAction(ACTION_SHOW_PIP_MENU);
-            mIntentFilter.addAction(ACTION_MOVE_PIP);
-            mIntentFilter.addAction(ACTION_TOGGLE_EXPANDED_PIP);
-            mIntentFilter.addAction(ACTION_FULLSCREEN);
+    @Override
+    public void onActionsChanged(int added, int updated, int startIndex) {
+        List<TvPipAction> actions = mTvPipActionsProvider.getActionsList();
+        mPipActions = new Notification.Action[actions.size()];
+        for (int i = 0; i < mPipActions.length; i++) {
+            mPipActions[i] = actions.get(i).toNotificationAction(mContext);
         }
-        boolean mRegistered = false;
-
-        void register() {
-            if (mRegistered) return;
-
-            mContext.registerReceiverForAllUsers(this, mIntentFilter, SYSTEMUI_PERMISSION,
-                    mMainHandler);
-            mRegistered = true;
-        }
-
-        void unregister() {
-            if (!mRegistered) return;
-
-            mContext.unregisterReceiver(this);
-            mRegistered = false;
-        }
-
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            final String action = intent.getAction();
-            ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                    "%s: on(Broadcast)Receive(), action=%s", TAG, action);
-
-            if (ACTION_SHOW_PIP_MENU.equals(action)) {
-                mDelegate.showPictureInPictureMenu();
-            } else if (ACTION_CLOSE_PIP.equals(action)) {
-                mDelegate.closePip();
-            } else if (ACTION_MOVE_PIP.equals(action)) {
-                mDelegate.enterPipMovementMenu();
-            } else if (ACTION_TOGGLE_EXPANDED_PIP.equals(action)) {
-                mDelegate.togglePipExpansion();
-            } else if (ACTION_FULLSCREEN.equals(action)) {
-                mDelegate.movePipToFullscreen();
-            }
-        }
+        updateNotificationContent();
     }
 
-    interface Delegate {
-        void showPictureInPictureMenu();
-
-        void closePip();
-
-        void enterPipMovementMenu();
-
-        void togglePipExpansion();
-
-        void movePipToFullscreen();
-    }
 }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipSystemAction.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipSystemAction.java
new file mode 100644
index 0000000..93b6a90
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipSystemAction.java
@@ -0,0 +1,83 @@
+/*
+ * 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.wm.shell.pip.tv;
+
+import static android.app.Notification.Action.SEMANTIC_ACTION_DELETE;
+import static android.app.Notification.Action.SEMANTIC_ACTION_NONE;
+
+import android.annotation.DrawableRes;
+import android.annotation.NonNull;
+import android.annotation.StringRes;
+import android.app.Notification;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.graphics.drawable.Icon;
+import android.os.Handler;
+
+import com.android.wm.shell.common.TvWindowMenuActionButton;
+
+/**
+ * A TvPipAction for actions that the system provides, i.e. fullscreen, default close, move,
+ * expand/collapse.
+ */
+public class TvPipSystemAction extends TvPipAction {
+
+    @StringRes
+    private int mTitleResource;
+    @DrawableRes
+    private int mIconResource;
+
+    private final PendingIntent mBroadcastIntent;
+
+    TvPipSystemAction(@ActionType int actionType, @StringRes int title, @DrawableRes int icon,
+            String broadcastAction, @NonNull Context context,
+            SystemActionsHandler systemActionsHandler) {
+        super(actionType, systemActionsHandler);
+        update(title, icon);
+        mBroadcastIntent = TvPipNotificationController.createPendingIntent(context,
+                broadcastAction);
+    }
+
+    void update(@StringRes int title, @DrawableRes int icon) {
+        mTitleResource = title;
+        mIconResource = icon;
+    }
+
+    void populateButton(@NonNull TvWindowMenuActionButton button, Handler mainHandler) {
+        button.setTextAndDescription(mTitleResource);
+        button.setImageResource(mIconResource);
+        button.setEnabled(true);
+    }
+
+    PendingIntent getPendingIntent() {
+        return mBroadcastIntent;
+    }
+
+    @Override
+    Notification.Action toNotificationAction(Context context) {
+        Notification.Action.Builder builder = new Notification.Action.Builder(
+                Icon.createWithResource(context, mIconResource),
+                context.getString(mTitleResource),
+                mBroadcastIntent);
+
+        builder.setSemanticAction(isCloseAction()
+                ? SEMANTIC_ACTION_DELETE : SEMANTIC_ACTION_NONE);
+        builder.setContextual(true);
+        return builder.build();
+    }
+
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/MainStage.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/MainStage.java
index e7ec15e..89538cb 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/MainStage.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/MainStage.java
@@ -16,9 +16,6 @@
 
 package com.android.wm.shell.splitscreen;
 
-import static com.android.wm.shell.common.split.SplitScreenConstants.CONTROLLED_ACTIVITY_TYPES;
-import static com.android.wm.shell.common.split.SplitScreenConstants.CONTROLLED_WINDOWING_MODES;
-
 import android.content.Context;
 import android.view.SurfaceSession;
 import android.window.WindowContainerToken;
@@ -34,8 +31,6 @@
  * @see StageCoordinator
  */
 class MainStage extends StageTaskListener {
-    private static final String TAG = MainStage.class.getSimpleName();
-
     private boolean mIsActive = false;
 
     MainStage(Context context, ShellTaskOrganizer taskOrganizer, int displayId,
@@ -52,15 +47,8 @@
     void activate(WindowContainerTransaction wct, boolean includingTopTask) {
         if (mIsActive) return;
 
-        final WindowContainerToken rootToken = mRootTaskInfo.token;
         if (includingTopTask) {
-            wct.reparentTasks(
-                    null /* currentParent */,
-                    rootToken,
-                    CONTROLLED_WINDOWING_MODES,
-                    CONTROLLED_ACTIVITY_TYPES,
-                    true /* onTop */,
-                    true /* reparentTopOnly */);
+            reparentTopTask(wct);
         }
 
         mIsActive = true;
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java
index 9329d02..ef70d9b 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java
@@ -18,7 +18,6 @@
 
 import static android.app.ActivityManager.START_SUCCESS;
 import static android.app.ActivityManager.START_TASK_TO_FRONT;
-import static android.app.ActivityTaskManager.INVALID_TASK_ID;
 import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
 import static android.content.Intent.FLAG_ACTIVITY_NO_USER_ACTION;
 import static android.view.Display.DEFAULT_DISPLAY;
@@ -98,7 +97,6 @@
 import java.io.PrintWriter;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
-import java.util.Objects;
 import java.util.Optional;
 import java.util.concurrent.Executor;
 
@@ -123,7 +121,8 @@
     public static final int EXIT_REASON_SCREEN_LOCKED = 7;
     public static final int EXIT_REASON_SCREEN_LOCKED_SHOW_ON_TOP = 8;
     public static final int EXIT_REASON_CHILD_TASK_ENTER_PIP = 9;
-    public static final int EXIT_REASON_FULLSCREEN_SHORTCUT = 10;
+    public static final int EXIT_REASON_RECREATE_SPLIT = 10;
+    public static final int EXIT_REASON_FULLSCREEN_SHORTCUT = 11;
     @IntDef(value = {
             EXIT_REASON_UNKNOWN,
             EXIT_REASON_APP_DOES_NOT_SUPPORT_MULTIWINDOW,
@@ -135,6 +134,7 @@
             EXIT_REASON_SCREEN_LOCKED,
             EXIT_REASON_SCREEN_LOCKED_SHOW_ON_TOP,
             EXIT_REASON_CHILD_TASK_ENTER_PIP,
+            EXIT_REASON_RECREATE_SPLIT,
             EXIT_REASON_FULLSCREEN_SHORTCUT,
     })
     @Retention(RetentionPolicy.SOURCE)
@@ -171,7 +171,7 @@
     private final IconProvider mIconProvider;
     private final Optional<RecentTasksController> mRecentTasksOptional;
     private final SplitScreenShellCommandHandler mSplitScreenShellCommandHandler;
-    private final String[] mMultiInstancesComponents;
+    private final String[] mAppsSupportMultiInstances;
 
     @VisibleForTesting
     StageCoordinator mStageCoordinator;
@@ -221,8 +221,8 @@
 
         // TODO(255224696): Remove the config once having a way for client apps to opt-in
         //                  multi-instances split.
-        mMultiInstancesComponents = mContext.getResources()
-                .getStringArray(R.array.config_componentsSupportMultiInstancesSplit);
+        mAppsSupportMultiInstances = mContext.getResources()
+                .getStringArray(R.array.config_appsSupportMultiInstancesSplit);
     }
 
     @VisibleForTesting
@@ -261,8 +261,8 @@
         mStageCoordinator = stageCoordinator;
         mSplitScreenShellCommandHandler = new SplitScreenShellCommandHandler(this);
         shellInit.addInitCallback(this::onInit, this);
-        mMultiInstancesComponents = mContext.getResources()
-                .getStringArray(R.array.config_componentsSupportMultiInstancesSplit);
+        mAppsSupportMultiInstances = mContext.getResources()
+                .getStringArray(R.array.config_appsSupportMultiInstancesSplit);
     }
 
     public SplitScreen asSplitScreen() {
@@ -472,7 +472,7 @@
      */
     public void startShortcut(String packageName, String shortcutId, @SplitPosition int position,
             @Nullable Bundle options, UserHandle user, @NonNull InstanceId instanceId) {
-        mStageCoordinator.getLogger().enterRequested(instanceId, ENTER_REASON_LAUNCHER);
+        mStageCoordinator.onRequestToSplit(instanceId, ENTER_REASON_LAUNCHER);
         startShortcut(packageName, shortcutId, position, options, user);
     }
 
@@ -520,7 +520,7 @@
      */
     public void startIntent(PendingIntent intent, @Nullable Intent fillInIntent,
             @SplitPosition int position, @Nullable Bundle options, @NonNull InstanceId instanceId) {
-        mStageCoordinator.getLogger().enterRequested(instanceId, ENTER_REASON_LAUNCHER);
+        mStageCoordinator.onRequestToSplit(instanceId, ENTER_REASON_LAUNCHER);
         startIntent(intent, fillInIntent, position, options);
     }
 
@@ -529,7 +529,7 @@
             @SplitPosition int splitPosition, float splitRatio, RemoteAnimationAdapter adapter,
             InstanceId instanceId) {
         Intent fillInIntent = null;
-        if (launchSameComponentAdjacently(pendingIntent, splitPosition, taskId)) {
+        if (launchSameAppAdjacently(pendingIntent, taskId)) {
             if (supportMultiInstancesSplit(pendingIntent.getIntent().getComponent())) {
                 fillInIntent = new Intent();
                 fillInIntent.addFlags(FLAG_ACTIVITY_MULTIPLE_TASK);
@@ -556,7 +556,7 @@
             int taskId, @Nullable Bundle options2, @SplitPosition int splitPosition,
             float splitRatio, @Nullable RemoteTransition remoteTransition, InstanceId instanceId) {
         Intent fillInIntent = null;
-        if (launchSameComponentAdjacently(pendingIntent, splitPosition, taskId)) {
+        if (launchSameAppAdjacently(pendingIntent, taskId)) {
             if (supportMultiInstancesSplit(pendingIntent.getIntent().getComponent())) {
                 fillInIntent = new Intent();
                 fillInIntent.addFlags(FLAG_ACTIVITY_MULTIPLE_TASK);
@@ -578,7 +578,7 @@
             float splitRatio, RemoteAnimationAdapter adapter, InstanceId instanceId) {
         Intent fillInIntent1 = null;
         Intent fillInIntent2 = null;
-        if (launchSameComponentAdjacently(pendingIntent1, pendingIntent2)) {
+        if (launchSameAppAdjacently(pendingIntent1, pendingIntent2)) {
             if (supportMultiInstancesSplit(pendingIntent1.getIntent().getComponent())) {
                 fillInIntent1 = new Intent();
                 fillInIntent1.addFlags(FLAG_ACTIVITY_MULTIPLE_TASK);
@@ -613,7 +613,7 @@
         if (fillInIntent == null) fillInIntent = new Intent();
         fillInIntent.addFlags(FLAG_ACTIVITY_NO_USER_ACTION);
 
-        if (launchSameComponentAdjacently(intent, position, INVALID_TASK_ID)) {
+        if (launchSameAppAdjacently(position, intent)) {
             final ComponentName launching = intent.getIntent().getComponent();
             if (supportMultiInstancesSplit(launching)) {
                 // To prevent accumulating large number of instances in the background, reuse task
@@ -647,47 +647,52 @@
         mStageCoordinator.startIntent(intent, fillInIntent, position, options);
     }
 
-    /** Returns {@code true} if it's launching the same component on both sides of the split. */
-    private boolean launchSameComponentAdjacently(@Nullable PendingIntent pendingIntent,
-            @SplitPosition int position, int taskId) {
-        if (pendingIntent == null || pendingIntent.getIntent() == null) return false;
-
-        final ComponentName launchingActivity = pendingIntent.getIntent().getComponent();
-        if (launchingActivity == null) return false;
-
-        if (taskId != INVALID_TASK_ID) {
-            final ActivityManager.RunningTaskInfo taskInfo =
-                    mTaskOrganizer.getRunningTaskInfo(taskId);
-            if (taskInfo != null) {
-                return Objects.equals(taskInfo.baseIntent.getComponent(), launchingActivity);
-            }
-            return false;
+    @Nullable
+    private String getPackageName(Intent intent) {
+        if (intent == null || intent.getComponent() == null) {
+            return null;
         }
-
-        if (!isSplitScreenVisible()) {
-            // Split screen is not yet activated, check if the current top running task is valid to
-            // split together.
-            final ActivityManager.RunningTaskInfo topRunningTask = mRecentTasksOptional
-                    .map(recentTasks -> recentTasks.getTopRunningTask()).orElse(null);
-            if (topRunningTask != null && isValidToEnterSplitScreen(topRunningTask)) {
-                return Objects.equals(topRunningTask.baseIntent.getComponent(), launchingActivity);
-            }
-            return false;
-        }
-
-        // Compare to the adjacent side of the split to determine if this is launching the same
-        // component adjacently.
-        final ActivityManager.RunningTaskInfo pairedTaskInfo =
-                getTaskInfo(SplitLayout.reversePosition(position));
-        final ComponentName pairedActivity = pairedTaskInfo != null
-                ? pairedTaskInfo.baseIntent.getComponent() : null;
-        return Objects.equals(launchingActivity, pairedActivity);
+        return intent.getComponent().getPackageName();
     }
 
-    private boolean launchSameComponentAdjacently(PendingIntent pendingIntent1,
+    private boolean launchSameAppAdjacently(@SplitPosition int position,
+            PendingIntent pendingIntent) {
+        ActivityManager.RunningTaskInfo adjacentTaskInfo = null;
+        if (isSplitScreenVisible()) {
+            adjacentTaskInfo = getTaskInfo(SplitLayout.reversePosition(position));
+        } else {
+            adjacentTaskInfo = mRecentTasksOptional
+                    .map(recentTasks -> recentTasks.getTopRunningTask()).orElse(null);
+            if (!isValidToEnterSplitScreen(adjacentTaskInfo)) {
+                return false;
+            }
+        }
+
+        if (adjacentTaskInfo == null) {
+            return false;
+        }
+
+        final String targetPackageName = getPackageName(pendingIntent.getIntent());
+        final String adjacentPackageName = getPackageName(adjacentTaskInfo.baseIntent);
+        return targetPackageName != null && targetPackageName.equals(adjacentPackageName);
+    }
+
+    private boolean launchSameAppAdjacently(PendingIntent pendingIntent, int taskId) {
+        final ActivityManager.RunningTaskInfo adjacentTaskInfo =
+                mTaskOrganizer.getRunningTaskInfo(taskId);
+        if (adjacentTaskInfo == null) {
+            return false;
+        }
+        final String targetPackageName = getPackageName(pendingIntent.getIntent());
+        final String adjacentPackageName = getPackageName(adjacentTaskInfo.baseIntent);
+        return targetPackageName != null && targetPackageName.equals(adjacentPackageName);
+    }
+
+    private boolean launchSameAppAdjacently(PendingIntent pendingIntent1,
             PendingIntent pendingIntent2) {
-        return Objects.equals(pendingIntent1.getIntent().getComponent(),
-                pendingIntent2.getIntent().getComponent());
+        final String targetPackageName = getPackageName(pendingIntent1.getIntent());
+        final String adjacentPackageName = getPackageName(pendingIntent2.getIntent());
+        return targetPackageName != null && targetPackageName.equals(adjacentPackageName);
     }
 
     @VisibleForTesting
@@ -695,9 +700,9 @@
     boolean supportMultiInstancesSplit(@Nullable ComponentName launching) {
         if (launching == null) return false;
 
-        final String componentName = launching.flattenToString();
-        for (int i = 0; i < mMultiInstancesComponents.length; i++) {
-            if (mMultiInstancesComponents[i].equals(componentName)) {
+        final String packageName = launching.getPackageName();
+        for (int i = 0; i < mAppsSupportMultiInstances.length; i++) {
+            if (mAppsSupportMultiInstances[i].equals(packageName)) {
                 return true;
             }
         }
@@ -781,10 +786,10 @@
         return splitTasksLayer;
     }
     /**
-     * Sets drag info to be logged when splitscreen is entered.
+     * Drop callback when splitscreen is entered.
      */
-    public void logOnDroppedToSplit(@SplitPosition int position, InstanceId dragSessionId) {
-        mStageCoordinator.logOnDroppedToSplit(position, dragSessionId);
+    public void onDroppedToSplit(@SplitPosition int position, InstanceId dragSessionId) {
+        mStageCoordinator.onDroppedToSplit(position, dragSessionId);
     }
 
     /**
@@ -812,6 +817,8 @@
                 return "APP_DOES_NOT_SUPPORT_MULTIWINDOW";
             case EXIT_REASON_CHILD_TASK_ENTER_PIP:
                 return "CHILD_TASK_ENTER_PIP";
+            case EXIT_REASON_RECREATE_SPLIT:
+                return "RECREATE_SPLIT";
             default:
                 return "unknown reason, reason int = " + exitReason;
         }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitscreenEventLogger.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitscreenEventLogger.java
index 1016e1b..5483fa5 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitscreenEventLogger.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitscreenEventLogger.java
@@ -21,9 +21,11 @@
 import static com.android.internal.util.FrameworkStatsLog.SPLITSCREEN_UICHANGED__ENTER_REASON__UNKNOWN_ENTER;
 import static com.android.internal.util.FrameworkStatsLog.SPLITSCREEN_UICHANGED__EXIT_REASON__APP_DOES_NOT_SUPPORT_MULTIWINDOW;
 import static com.android.internal.util.FrameworkStatsLog.SPLITSCREEN_UICHANGED__EXIT_REASON__APP_FINISHED;
+import static com.android.internal.util.FrameworkStatsLog.SPLITSCREEN_UICHANGED__EXIT_REASON__CHILD_TASK_ENTER_PIP;
 import static com.android.internal.util.FrameworkStatsLog.SPLITSCREEN_UICHANGED__EXIT_REASON__DEVICE_FOLDED;
 import static com.android.internal.util.FrameworkStatsLog.SPLITSCREEN_UICHANGED__EXIT_REASON__DRAG_DIVIDER;
 import static com.android.internal.util.FrameworkStatsLog.SPLITSCREEN_UICHANGED__EXIT_REASON__FULLSCREEN_SHORTCUT;
+import static com.android.internal.util.FrameworkStatsLog.SPLITSCREEN_UICHANGED__EXIT_REASON__RECREATE_SPLIT;
 import static com.android.internal.util.FrameworkStatsLog.SPLITSCREEN_UICHANGED__EXIT_REASON__RETURN_HOME;
 import static com.android.internal.util.FrameworkStatsLog.SPLITSCREEN_UICHANGED__EXIT_REASON__ROOT_TASK_VANISHED;
 import static com.android.internal.util.FrameworkStatsLog.SPLITSCREEN_UICHANGED__EXIT_REASON__SCREEN_LOCKED;
@@ -37,9 +39,11 @@
 import static com.android.wm.shell.splitscreen.SplitScreenController.ENTER_REASON_UNKNOWN;
 import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_APP_DOES_NOT_SUPPORT_MULTIWINDOW;
 import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_APP_FINISHED;
+import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_CHILD_TASK_ENTER_PIP;
 import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_DEVICE_FOLDED;
 import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_DRAG_DIVIDER;
 import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_FULLSCREEN_SHORTCUT;
+import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_RECREATE_SPLIT;
 import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_RETURN_HOME;
 import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_ROOT_TASK_VANISHED;
 import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_SCREEN_LOCKED;
@@ -182,6 +186,10 @@
                 return SPLITSCREEN_UICHANGED__EXIT_REASON__SCREEN_LOCKED;
             case EXIT_REASON_SCREEN_LOCKED_SHOW_ON_TOP:
                 return SPLITSCREEN_UICHANGED__EXIT_REASON__SCREEN_LOCKED_SHOW_ON_TOP;
+            case EXIT_REASON_CHILD_TASK_ENTER_PIP:
+                return SPLITSCREEN_UICHANGED__EXIT_REASON__CHILD_TASK_ENTER_PIP;
+            case EXIT_REASON_RECREATE_SPLIT:
+                return SPLITSCREEN_UICHANGED__EXIT_REASON__RECREATE_SPLIT;
             case EXIT_REASON_FULLSCREEN_SHORTCUT:
                 return SPLITSCREEN_UICHANGED__EXIT_REASON__FULLSCREEN_SHORTCUT;
             case EXIT_REASON_UNKNOWN:
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java
index da8dc87..5be29db 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java
@@ -49,10 +49,11 @@
 import static com.android.wm.shell.splitscreen.SplitScreenController.ENTER_REASON_MULTI_INSTANCE;
 import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_APP_DOES_NOT_SUPPORT_MULTIWINDOW;
 import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_APP_FINISHED;
-import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_FULLSCREEN_SHORTCUT;
 import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_CHILD_TASK_ENTER_PIP;
 import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_DEVICE_FOLDED;
 import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_DRAG_DIVIDER;
+import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_FULLSCREEN_SHORTCUT;
+import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_RECREATE_SPLIT;
 import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_RETURN_HOME;
 import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_ROOT_TASK_VANISHED;
 import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_SCREEN_LOCKED_SHOW_ON_TOP;
@@ -199,7 +200,8 @@
     // and exit, since exit itself can trigger a number of changes that update the stages.
     private boolean mShouldUpdateRecents;
     private boolean mExitSplitScreenOnHide;
-    private boolean mIsDividerRemoteAnimating;
+    private boolean mIsSplitEntering;
+    private boolean mIsDropEntering;
     private boolean mIsExiting;
 
     /** The target stage to dismiss to when unlock after folded. */
@@ -347,10 +349,14 @@
         return mSplitTransitions;
     }
 
-    boolean isSplitScreenVisible() {
+    public boolean isSplitScreenVisible() {
         return mSideStageListener.mVisible && mMainStageListener.mVisible;
     }
 
+    public boolean isSplitActive() {
+        return mMainStage.isActive();
+    }
+
     @StageType
     int getStageOfTask(int taskId) {
         if (mMainStage.containsTask(taskId)) {
@@ -373,11 +379,14 @@
             targetStage = mSideStage;
             sideStagePosition = stagePosition;
         } else {
-            if (mMainStage.isActive()) {
+            if (isSplitScreenVisible()) {
                 // If the split screen is activated, retrieves target stage based on position.
                 targetStage = stagePosition == mSideStagePosition ? mSideStage : mMainStage;
                 sideStagePosition = mSideStagePosition;
             } else {
+                // Exit split if it running background.
+                exitSplitScreen(null /* childrenToTop */, EXIT_REASON_RECREATE_SPLIT);
+
                 targetStage = mSideStage;
                 sideStagePosition = stagePosition;
             }
@@ -673,6 +682,10 @@
             @Nullable PendingIntent mainPendingIntent, @Nullable Intent mainFillInIntent,
             @Nullable Bundle mainOptions, @SplitPosition int sidePosition, float splitRatio,
             RemoteAnimationAdapter adapter, InstanceId instanceId) {
+        if (!isSplitScreenVisible()) {
+            exitSplitScreen(null /* childrenToTop */, EXIT_REASON_RECREATE_SPLIT);
+        }
+
         // Init divider first to make divider leash for remote animation target.
         mSplitLayout.init();
         mSplitLayout.setDivideRatio(splitRatio);
@@ -685,11 +698,13 @@
 
         // Set false to avoid record new bounds with old task still on top;
         mShouldUpdateRecents = false;
-        mIsDividerRemoteAnimating = true;
+        mIsSplitEntering = true;
 
         final WindowContainerTransaction evictWct = new WindowContainerTransaction();
-        prepareEvictChildTasks(SPLIT_POSITION_TOP_OR_LEFT, evictWct);
-        prepareEvictChildTasks(SPLIT_POSITION_BOTTOM_OR_RIGHT, evictWct);
+        if (isSplitScreenVisible()) {
+            mMainStage.evictAllChildren(evictWct);
+            mSideStage.evictAllChildren(evictWct);
+        }
 
         IRemoteAnimationRunner wrapper = new IRemoteAnimationRunner.Stub() {
             @Override
@@ -769,7 +784,7 @@
 
     private void onRemoteAnimationFinishedOrCancelled(boolean cancel,
             WindowContainerTransaction evictWct) {
-        mIsDividerRemoteAnimating = false;
+        mIsSplitEntering = false;
         mShouldUpdateRecents = true;
         // If any stage has no child after animation finished, it means that split will display
         // nothing, such status will happen if task and intent is same app but not support
@@ -781,6 +796,9 @@
             mSplitUnsupportedToast.show();
         } else {
             mSyncQueue.queue(evictWct);
+            mSyncQueue.runInSync(t -> {
+                updateSurfaceBounds(mSplitLayout, t, false /* applyResizingOffset */);
+            });
         }
     }
 
@@ -815,7 +833,7 @@
         switch (stage) {
             case STAGE_TYPE_UNDEFINED: {
                 if (position != SPLIT_POSITION_UNDEFINED) {
-                    if (mMainStage.isActive()) {
+                    if (isSplitScreenVisible()) {
                         // Use the stage of the specified position
                         options = resolveStartStage(
                                 position == mSideStagePosition ? STAGE_TYPE_SIDE : STAGE_TYPE_MAIN,
@@ -1045,14 +1063,13 @@
             }
         });
         mShouldUpdateRecents = false;
-        mIsDividerRemoteAnimating = false;
+        mIsSplitEntering = false;
 
         mSplitLayout.getInvisibleBounds(mTempRect1);
         if (childrenToTop == null || childrenToTop.getTopVisibleChildTaskId() == INVALID_TASK_ID) {
             mSideStage.removeAllTasks(wct, false /* toTop */);
             mMainStage.deactivate(wct, false /* toTop */);
             wct.reorder(mRootTaskInfo.token, false /* onTop */);
-            wct.setForceTranslucent(mRootTaskInfo.token, true);
             wct.setBounds(mSideStage.mRootTaskInfo.token, mTempRect1);
             onTransitionAnimationComplete();
         } else {
@@ -1064,6 +1081,8 @@
             wct.setSmallestScreenWidthDp(childrenToTop.mRootTaskInfo.token,
                     SMALLEST_SCREEN_WIDTH_DP_UNDEFINED);
         }
+        wct.setReparentLeafTaskIfRelaunch(mRootTaskInfo.token,
+                false /* reparentLeafTaskIfRelaunch */);
         mSyncQueue.queue(wct);
         mSyncQueue.runInSync(t -> {
             t.setWindowCrop(mMainStage.mRootLeash, null)
@@ -1082,7 +1101,6 @@
                     mMainStage.deactivate(finishedWCT, childrenToTop == mMainStage /* toTop */);
                     mSideStage.removeAllTasks(finishedWCT, childrenToTop == mSideStage /* toTop */);
                     finishedWCT.reorder(mRootTaskInfo.token, false /* toTop */);
-                    finishedWCT.setForceTranslucent(mRootTaskInfo.token, true);
                     finishedWCT.setBounds(mSideStage.mRootTaskInfo.token, mTempRect1);
                     mSyncQueue.queue(finishedWCT);
                     mSyncQueue.runInSync(at -> {
@@ -1374,7 +1392,7 @@
                 && !ENABLE_SHELL_TRANSITIONS) {
             // Clear the divider remote animating flag as the divider will be re-rendered to apply
             // the new rotation config.
-            mIsDividerRemoteAnimating = false;
+            mIsSplitEntering = false;
             mSplitLayout.update(null /* t */);
             onLayoutSizeChanged(mSplitLayout);
         }
@@ -1423,6 +1441,36 @@
         });
     }
 
+    void onChildTaskAppeared(StageListenerImpl stageListener, int taskId) {
+        if (stageListener == mSideStageListener && !isSplitScreenVisible() && isSplitActive()
+                && !mIsSplitEntering) {
+            // Handle entring split case here if split already running background.
+            if (mIsDropEntering) {
+                mSplitLayout.resetDividerPosition();
+            } else {
+                mSplitLayout.setDividerAtBorder(mSideStagePosition == SPLIT_POSITION_TOP_OR_LEFT);
+            }
+            final WindowContainerTransaction wct = new WindowContainerTransaction();
+            mMainStage.reparentTopTask(wct);
+            mMainStage.evictAllChildren(wct);
+            mSideStage.evictOtherChildren(wct, taskId);
+            updateWindowBounds(mSplitLayout, wct);
+            wct.reorder(mRootTaskInfo.token, true);
+            wct.setForceTranslucent(mRootTaskInfo.token, false);
+
+            mSyncQueue.queue(wct);
+            mSyncQueue.runInSync(t -> {
+                if (mIsDropEntering) {
+                    updateSurfaceBounds(mSplitLayout, t, false /* applyResizingOffset */);
+                    mIsDropEntering = false;
+                } else {
+                    mShowDecorImmediately = true;
+                    mSplitLayout.flingDividerToCenter();
+                }
+            });
+        }
+    }
+
     private void onRootTaskVanished() {
         final WindowContainerTransaction wct = new WindowContainerTransaction();
         if (mRootTaskInfo != null) {
@@ -1441,20 +1489,22 @@
             return;
         }
 
+        final WindowContainerTransaction wct = new WindowContainerTransaction();
         if (!mainStageVisible) {
+            wct.setReparentLeafTaskIfRelaunch(mRootTaskInfo.token,
+                    true /* setReparentLeafTaskIfRelaunch */);
+            wct.setForceTranslucent(mRootTaskInfo.token, true);
             // Both stages are not visible, check if it needs to dismiss split screen.
-            if (mExitSplitScreenOnHide
-                    // Don't dismiss split screen when both stages are not visible due to sleeping
-                    // display.
-                    || (!mMainStage.mRootTaskInfo.isSleeping
-                    && !mSideStage.mRootTaskInfo.isSleeping)) {
+            if (mExitSplitScreenOnHide) {
                 exitSplitScreen(null /* childrenToTop */, EXIT_REASON_RETURN_HOME);
             }
+        } else {
+            wct.setReparentLeafTaskIfRelaunch(mRootTaskInfo.token,
+                    false /* setReparentLeafTaskIfRelaunch */);
+            wct.setForceTranslucent(mRootTaskInfo.token, false);
         }
-
+        mSyncQueue.queue(wct);
         mSyncQueue.runInSync(t -> {
-            t.setVisibility(mSideStage.mRootLeash, sideStageVisible)
-                    .setVisibility(mMainStage.mRootLeash, mainStageVisible);
             setDividerVisibility(mainStageVisible, t);
         });
     }
@@ -1479,7 +1529,7 @@
         mDividerVisible = visible;
         sendSplitVisibilityChanged();
 
-        if (mIsDividerRemoteAnimating) {
+        if (mIsSplitEntering) {
             ProtoLog.d(ShellProtoLogGroup.WM_SHELL_SPLIT_SCREEN,
                     "   Skip animating divider bar due to it's remote animating.");
             return;
@@ -1499,7 +1549,7 @@
                     "   Skip animating divider bar due to divider leash not ready.");
             return;
         }
-        if (mIsDividerRemoteAnimating) {
+        if (mIsSplitEntering) {
             ProtoLog.d(ShellProtoLogGroup.WM_SHELL_SPLIT_SCREEN,
                     "   Skip animating divider bar due to it's remote animating.");
             return;
@@ -1555,26 +1605,21 @@
         if (!hasChildren && !mIsExiting && mMainStage.isActive()) {
             if (isSideStage && mMainStageListener.mVisible) {
                 // Exit to main stage if side stage no longer has children.
-                if (ENABLE_SHELL_TRANSITIONS) {
-                    exitSplitScreen(mMainStage, EXIT_REASON_APP_FINISHED);
-                } else {
-                    mSplitLayout.flingDividerToDismiss(
-                            mSideStagePosition == SPLIT_POSITION_BOTTOM_OR_RIGHT,
-                            EXIT_REASON_APP_FINISHED);
-                }
+                mSplitLayout.flingDividerToDismiss(
+                        mSideStagePosition == SPLIT_POSITION_BOTTOM_OR_RIGHT,
+                        EXIT_REASON_APP_FINISHED);
             } else if (!isSideStage && mSideStageListener.mVisible) {
                 // Exit to side stage if main stage no longer has children.
-                if (ENABLE_SHELL_TRANSITIONS) {
-                    exitSplitScreen(mSideStage, EXIT_REASON_APP_FINISHED);
-                } else {
-                    mSplitLayout.flingDividerToDismiss(
-                            mSideStagePosition != SPLIT_POSITION_BOTTOM_OR_RIGHT,
-                            EXIT_REASON_APP_FINISHED);
-                }
+                mSplitLayout.flingDividerToDismiss(
+                        mSideStagePosition != SPLIT_POSITION_BOTTOM_OR_RIGHT,
+                        EXIT_REASON_APP_FINISHED);
+            } else if (!isSplitScreenVisible()) {
+                exitSplitScreen(null /* childrenToTop */, EXIT_REASON_APP_FINISHED);
             }
         } else if (isSideStage && hasChildren && !mMainStage.isActive()) {
-            final WindowContainerTransaction wct = new WindowContainerTransaction();
             mSplitLayout.init();
+
+            final WindowContainerTransaction wct = new WindowContainerTransaction();
             if (mLogger.isEnterRequestedByDrag()) {
                 prepareEnterSplitScreen(wct);
             } else {
@@ -1589,8 +1634,9 @@
 
             mSyncQueue.queue(wct);
             mSyncQueue.runInSync(t -> {
-                if (mLogger.isEnterRequestedByDrag()) {
+                if (mIsDropEntering) {
                     updateSurfaceBounds(mSplitLayout, t, false /* applyResizingOffset */);
+                    mIsDropEntering = false;
                 } else {
                     mShowDecorImmediately = true;
                     mSplitLayout.flingDividerToCenter();
@@ -1945,10 +1991,6 @@
         }
     }
 
-    public boolean isSplitActive() {
-        return mMainStage.isActive();
-    }
-
     @Override
     public void mergeAnimation(IBinder transition, TransitionInfo info,
             SurfaceControl.Transaction t, IBinder mergeTarget,
@@ -2304,11 +2346,29 @@
     /**
      * Sets drag info to be logged when splitscreen is next entered.
      */
-    public void logOnDroppedToSplit(@SplitPosition int position, InstanceId dragSessionId) {
+    public void onDroppedToSplit(@SplitPosition int position, InstanceId dragSessionId) {
+        if (!isSplitScreenVisible()) {
+            mIsDropEntering = true;
+        }
+        if (!isSplitScreenVisible()) {
+            // If split running background, exit split first.
+            exitSplitScreen(null /* childrenToTop */, EXIT_REASON_RECREATE_SPLIT);
+        }
         mLogger.enterRequestedByDrag(position, dragSessionId);
     }
 
     /**
+     * Sets info to be logged when splitscreen is next entered.
+     */
+    public void onRequestToSplit(InstanceId sessionId, int enterReason) {
+        if (!isSplitScreenVisible()) {
+            // If split running background, exit split first.
+            exitSplitScreen(null /* childrenToTop */, EXIT_REASON_RECREATE_SPLIT);
+        }
+        mLogger.enterRequested(sessionId, enterReason);
+    }
+
+    /**
      * Logs the exit of splitscreen.
      */
     private void logExit(@ExitReason int exitReason) {
@@ -2343,6 +2403,11 @@
         }
 
         @Override
+        public void onChildTaskAppeared(int taskId) {
+            StageCoordinator.this.onChildTaskAppeared(this, taskId);
+        }
+
+        @Override
         public void onStatusChanged(boolean visible, boolean hasChildren) {
             if (!mHasRootTask) return;
 
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageTaskListener.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageTaskListener.java
index 8a52c87..a841b7f 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageTaskListener.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageTaskListener.java
@@ -22,6 +22,7 @@
 import static android.view.RemoteAnimationTarget.MODE_OPENING;
 
 import static com.android.wm.shell.common.split.SplitScreenConstants.CONTROLLED_ACTIVITY_TYPES;
+import static com.android.wm.shell.common.split.SplitScreenConstants.CONTROLLED_WINDOWING_MODES;
 import static com.android.wm.shell.common.split.SplitScreenConstants.CONTROLLED_WINDOWING_MODES_WHEN_ACTIVE;
 import static com.android.wm.shell.transition.Transitions.ENABLE_SHELL_TRANSITIONS;
 
@@ -69,6 +70,8 @@
     public interface StageListenerCallbacks {
         void onRootTaskAppeared();
 
+        void onChildTaskAppeared(int taskId);
+
         void onStatusChanged(boolean visible, boolean hasChildren);
 
         void onChildTaskStatusChanged(int taskId, boolean present, boolean visible);
@@ -185,6 +188,7 @@
                 // Status is managed/synchronized by the transition lifecycle.
                 return;
             }
+            mCallbacks.onChildTaskAppeared(taskId);
             sendStatusChanged();
         } else {
             throw new IllegalArgumentException(this + "\n Unknown task: " + taskInfo
@@ -338,6 +342,14 @@
         }
     }
 
+    void evictOtherChildren(WindowContainerTransaction wct, int taskId) {
+        for (int i = mChildrenTaskInfo.size() - 1; i >= 0; i--) {
+            final ActivityManager.RunningTaskInfo taskInfo = mChildrenTaskInfo.valueAt(i);
+            if (taskId == taskInfo.taskId) continue;
+            wct.reparent(taskInfo.token, null /* parent */, false /* onTop */);
+        }
+    }
+
     void evictNonOpeningChildren(RemoteAnimationTarget[] apps, WindowContainerTransaction wct) {
         final SparseArray<ActivityManager.RunningTaskInfo> toBeEvict = mChildrenTaskInfo.clone();
         for (int i = 0; i < apps.length; i++) {
@@ -360,6 +372,12 @@
         }
     }
 
+    void reparentTopTask(WindowContainerTransaction wct) {
+        wct.reparentTasks(null /* currentParent */, mRootTaskInfo.token,
+                CONTROLLED_WINDOWING_MODES, CONTROLLED_ACTIVITY_TYPES,
+                true /* onTop */, true /* reparentTopOnly */);
+    }
+
     void resetBounds(WindowContainerTransaction wct) {
         wct.setBounds(mRootTaskInfo.token, null);
         wct.setAppBounds(mRootTaskInfo.token, null);
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultMixedHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultMixedHandler.java
index 3cba929..a2d7bc4 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultMixedHandler.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultMixedHandler.java
@@ -111,7 +111,7 @@
     @Override
     public WindowContainerTransaction handleRequest(@NonNull IBinder transition,
             @NonNull TransitionRequestInfo request) {
-        if (mPipHandler.requestHasPipEnter(request) && mSplitHandler.isSplitActive()) {
+        if (mPipHandler.requestHasPipEnter(request) && mSplitHandler.isSplitScreenVisible()) {
             ProtoLog.v(ShellProtoLogGroup.WM_SHELL_TRANSITIONS, " Got a PiP-enter request while "
                     + "Split-Screen is active, so treat it as Mixed.");
             if (request.getRemoteTransition() != null) {
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java
index 5655402..42e2b3f 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java
@@ -46,6 +46,7 @@
 
 import androidx.annotation.Nullable;
 
+import com.android.internal.annotations.VisibleForTesting;
 import com.android.wm.shell.R;
 import com.android.wm.shell.ShellTaskOrganizer;
 import com.android.wm.shell.common.DisplayController;
@@ -56,7 +57,6 @@
 import com.android.wm.shell.transition.Transitions;
 
 import java.util.Optional;
-import java.util.function.Supplier;
 
 /**
  * View model for the window decoration with a caption and shadows. Works with
@@ -66,7 +66,6 @@
 public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
     private static final String TAG = "CaptionViewModel";
     private final CaptionWindowDecoration.Factory mCaptionWindowDecorFactory;
-    private final Supplier<InputManager> mInputManagerSupplier;
     private final ActivityTaskManager mActivityTaskManager;
     private final ShellTaskOrganizer mTaskOrganizer;
     private final Context mContext;
@@ -82,7 +81,7 @@
 
     private final SparseArray<CaptionWindowDecoration> mWindowDecorByTaskId = new SparseArray<>();
     private final DragStartListenerImpl mDragStartListener = new DragStartListenerImpl();
-    private EventReceiverFactory mEventReceiverFactory = new EventReceiverFactory();
+    private InputMonitorFactory mInputMonitorFactory;
 
     public CaptionWindowDecorViewModel(
             Context context,
@@ -101,10 +100,11 @@
                 syncQueue,
                 desktopModeController,
                 new CaptionWindowDecoration.Factory(),
-                InputManager::getInstance);
+                new InputMonitorFactory());
     }
 
-    public CaptionWindowDecorViewModel(
+    @VisibleForTesting
+    CaptionWindowDecorViewModel(
             Context context,
             Handler mainHandler,
             Choreographer mainChoreographer,
@@ -113,8 +113,7 @@
             SyncTransactionQueue syncQueue,
             Optional<DesktopModeController> desktopModeController,
             CaptionWindowDecoration.Factory captionWindowDecorFactory,
-            Supplier<InputManager> inputManagerSupplier) {
-
+            InputMonitorFactory inputMonitorFactory) {
         mContext = context;
         mMainHandler = mainHandler;
         mMainChoreographer = mainChoreographer;
@@ -125,11 +124,7 @@
         mDesktopModeController = desktopModeController;
 
         mCaptionWindowDecorFactory = captionWindowDecorFactory;
-        mInputManagerSupplier = inputManagerSupplier;
-    }
-
-    void setEventReceiverFactory(EventReceiverFactory eventReceiverFactory) {
-        mEventReceiverFactory = eventReceiverFactory;
+        mInputMonitorFactory = inputMonitorFactory;
     }
 
     @Override
@@ -205,7 +200,6 @@
         decoration.close();
         int displayId = taskInfo.displayId;
         if (mEventReceiversByDisplay.contains(displayId)) {
-            EventReceiver eventReceiver = mEventReceiversByDisplay.get(displayId);
             removeTaskFromEventReceiver(displayId);
         }
     }
@@ -408,12 +402,6 @@
         }
     }
 
-    class EventReceiverFactory {
-        EventReceiver create(InputMonitor inputMonitor, InputChannel channel, Looper looper) {
-            return new EventReceiver(inputMonitor, channel, looper);
-        }
-    }
-
     /**
      * Handle MotionEvents relevant to focused task's caption that don't directly touch it
      *
@@ -500,11 +488,11 @@
     }
 
     private void createInputChannel(int displayId) {
-        InputManager inputManager = mInputManagerSupplier.get();
+        InputManager inputManager = InputManager.getInstance();
         InputMonitor inputMonitor =
-                inputManager.monitorGestureInput("caption-touch", mContext.getDisplayId());
-        EventReceiver eventReceiver = mEventReceiverFactory.create(
-                inputMonitor, inputMonitor.getInputChannel(), Looper.myLooper());
+                mInputMonitorFactory.create(inputManager, mContext);
+        EventReceiver eventReceiver = new EventReceiver(inputMonitor,
+                inputMonitor.getInputChannel(), Looper.myLooper());
         mEventReceiversByDisplay.put(displayId, eventReceiver);
     }
 
@@ -517,7 +505,7 @@
 
     private boolean shouldShowWindowDecor(RunningTaskInfo taskInfo) {
         if (taskInfo.getWindowingMode() == WINDOWING_MODE_FREEFORM) return true;
-        return DesktopModeStatus.IS_SUPPORTED
+        return DesktopModeStatus.isAnyEnabled()
                 && taskInfo.getActivityType() == ACTIVITY_TYPE_STANDARD
                 && mDisplayController.getDisplayContext(taskInfo.displayId)
                 .getResources().getConfiguration().smallestScreenWidthDp >= 600;
@@ -562,4 +550,12 @@
             mWindowDecorByTaskId.get(taskId).closeHandleMenu();
         }
     }
+
+    static class InputMonitorFactory {
+        InputMonitor create(InputManager inputManager, Context context) {
+            return inputManager.monitorGestureInput("caption-touch", context.getDisplayId());
+        }
+    }
 }
+
+
diff --git a/libs/WindowManager/Shell/tests/unittest/AndroidManifest.xml b/libs/WindowManager/Shell/tests/unittest/AndroidManifest.xml
index 59d9104..fac0461 100644
--- a/libs/WindowManager/Shell/tests/unittest/AndroidManifest.xml
+++ b/libs/WindowManager/Shell/tests/unittest/AndroidManifest.xml
@@ -19,6 +19,8 @@
     xmlns:tools="http://schemas.android.com/tools"
     package="com.android.wm.shell.tests">
 
+    <uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
+
     <application android:debuggable="true" android:largeHeap="true">
         <uses-library android:name="android.test.mock" />
         <uses-library android:name="android.test.runner" />
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopModeControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopModeControllerTest.java
index dad9133..707c049 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopModeControllerTest.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopModeControllerTest.java
@@ -23,6 +23,7 @@
 import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
 import static android.app.WindowConfiguration.WINDOW_CONFIG_BOUNDS;
 import static android.view.WindowManager.TRANSIT_CHANGE;
+import static android.view.WindowManager.TRANSIT_CLOSE;
 import static android.view.WindowManager.TRANSIT_OPEN;
 import static android.view.WindowManager.TRANSIT_TO_FRONT;
 import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_REORDER;
@@ -100,7 +101,7 @@
     @Before
     public void setUp() {
         mMockitoSession = mockitoSession().mockStatic(DesktopModeStatus.class).startMocking();
-        when(DesktopModeStatus.isSupported()).thenReturn(true);
+        when(DesktopModeStatus.isProto1Enabled()).thenReturn(true);
         when(DesktopModeStatus.isActive(any())).thenReturn(true);
 
         mShellInit = Mockito.spy(new ShellInit(mTestExecutor));
@@ -129,7 +130,7 @@
 
     @Test
     public void instantiate_flagOff_doNotAddInitCallback() {
-        when(DesktopModeStatus.isSupported()).thenReturn(false);
+        when(DesktopModeStatus.isProto1Enabled()).thenReturn(false);
         clearInvocations(mShellInit);
 
         createController();
@@ -334,10 +335,10 @@
     }
 
     @Test
-    public void testHandleTransitionRequest_notTransitOpen_returnsNull() {
+    public void testHandleTransitionRequest_unsupportedTransit_returnsNull() {
         WindowContainerTransaction wct = mController.handleRequest(
                 new Binder(),
-                new TransitionRequestInfo(TRANSIT_TO_FRONT, null /* trigger */, null /* remote */));
+                new TransitionRequestInfo(TRANSIT_CLOSE, null /* trigger */, null /* remote */));
         assertThat(wct).isNull();
     }
 
@@ -352,7 +353,7 @@
     }
 
     @Test
-    public void testHandleTransitionRequest_returnsWct() {
+    public void testHandleTransitionRequest_taskOpen_returnsWct() {
         RunningTaskInfo trigger = new RunningTaskInfo();
         trigger.token = new MockToken().mToken;
         trigger.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FREEFORM);
@@ -362,6 +363,17 @@
         assertThat(wct).isNotNull();
     }
 
+    @Test
+    public void testHandleTransitionRequest_taskToFront_returnsWct() {
+        RunningTaskInfo trigger = new RunningTaskInfo();
+        trigger.token = new MockToken().mToken;
+        trigger.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FREEFORM);
+        WindowContainerTransaction wct = mController.handleRequest(
+                mock(IBinder.class),
+                new TransitionRequestInfo(TRANSIT_TO_FRONT, trigger, null /* remote */));
+        assertThat(wct).isNotNull();
+    }
+
     private DesktopModeController createController() {
         return new DesktopModeController(mContext, mShellInit, mShellController,
                 mShellTaskOrganizer, mRootTaskDisplayAreaOrganizer, mTransitions,
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipActionProviderTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipActionProviderTest.java
new file mode 100644
index 0000000..91040e9
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/tv/TvPipActionProviderTest.java
@@ -0,0 +1,309 @@
+/*
+ * 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.wm.shell.pip.tv;
+
+import static com.android.wm.shell.pip.tv.TvPipAction.ACTION_CLOSE;
+import static com.android.wm.shell.pip.tv.TvPipAction.ACTION_CUSTOM;
+import static com.android.wm.shell.pip.tv.TvPipAction.ACTION_CUSTOM_CLOSE;
+import static com.android.wm.shell.pip.tv.TvPipAction.ACTION_EXPAND_COLLAPSE;
+import static com.android.wm.shell.pip.tv.TvPipAction.ACTION_FULLSCREEN;
+import static com.android.wm.shell.pip.tv.TvPipAction.ACTION_MOVE;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import android.app.PendingIntent;
+import android.app.RemoteAction;
+import android.graphics.drawable.Icon;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
+import android.util.Log;
+
+import com.android.wm.shell.ShellTestCase;
+import com.android.wm.shell.pip.PipMediaController;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Unit tests for {@link TvPipActionsProvider}
+ */
+@SmallTest
+@RunWith(AndroidTestingRunner.class)
+@TestableLooper.RunWithLooper
+public class TvPipActionProviderTest extends ShellTestCase {
+    private static final String TAG = TvPipActionProviderTest.class.getSimpleName();
+    private TvPipActionsProvider mActionsProvider;
+
+    @Mock
+    private PipMediaController mMockPipMediaController;
+    @Mock
+    private TvPipActionsProvider.Listener mMockListener;
+    @Mock
+    private TvPipAction.SystemActionsHandler mMockSystemActionsHandler;
+    @Mock
+    private Icon mMockIcon;
+    @Mock
+    private PendingIntent mMockPendingIntent;
+
+    private RemoteAction createRemoteAction(int identifier) {
+        return new RemoteAction(mMockIcon, "" + identifier, "" + identifier, mMockPendingIntent);
+    }
+
+    private List<RemoteAction> createRemoteActions(int numberOfActions) {
+        List<RemoteAction> actions = new ArrayList<>();
+        for (int i = 0; i < numberOfActions; i++) {
+            actions.add(createRemoteAction(i));
+        }
+        return actions;
+    }
+
+    private boolean checkActionsMatch(List<TvPipAction> actions, int[] actionTypes) {
+        for (int i = 0; i < actions.size(); i++) {
+            int type = actions.get(i).getActionType();
+            if (type != actionTypes[i]) {
+                Log.e(TAG, "Action at index " + i + ": found " + type
+                        + ", expected " + actionTypes[i]);
+                return false;
+            }
+        }
+        return true;
+    }
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mActionsProvider = new TvPipActionsProvider(mContext, mMockPipMediaController,
+                mMockSystemActionsHandler);
+    }
+
+    @Test
+    public void defaultSystemActions_regularPip() {
+        mActionsProvider.updateExpansionEnabled(false);
+        assertTrue(checkActionsMatch(mActionsProvider.getActionsList(),
+                new int[]{ACTION_FULLSCREEN, ACTION_CLOSE, ACTION_MOVE}));
+    }
+
+    @Test
+    public void defaultSystemActions_expandedPip() {
+        mActionsProvider.updateExpansionEnabled(true);
+        assertTrue(checkActionsMatch(mActionsProvider.getActionsList(),
+                new int[]{ACTION_FULLSCREEN, ACTION_CLOSE, ACTION_MOVE, ACTION_EXPAND_COLLAPSE}));
+    }
+
+    @Test
+    public void expandedPip_enableExpansion_enable() {
+        // PiP has expanded PiP disabled.
+        mActionsProvider.updateExpansionEnabled(false);
+
+        mActionsProvider.addListener(mMockListener);
+        mActionsProvider.updateExpansionEnabled(true);
+
+        assertTrue(checkActionsMatch(mActionsProvider.getActionsList(),
+                new int[]{ACTION_FULLSCREEN, ACTION_CLOSE, ACTION_MOVE, ACTION_EXPAND_COLLAPSE}));
+        verify(mMockListener).onActionsChanged(/* added= */ 1, /* updated= */ 0, /* index= */ 3);
+    }
+
+    @Test
+    public void expandedPip_enableExpansion_disable() {
+        mActionsProvider.updateExpansionEnabled(true);
+
+        mActionsProvider.addListener(mMockListener);
+        mActionsProvider.updateExpansionEnabled(false);
+
+        assertTrue(checkActionsMatch(mActionsProvider.getActionsList(),
+                new int[]{ACTION_FULLSCREEN, ACTION_CLOSE, ACTION_MOVE}));
+        verify(mMockListener).onActionsChanged(/* added= */ -1, /* updated= */ 0, /* index= */ 3);
+    }
+
+    @Test
+    public void expandedPip_enableExpansion_AlreadyEnabled() {
+        mActionsProvider.updateExpansionEnabled(true);
+
+        mActionsProvider.addListener(mMockListener);
+        mActionsProvider.updateExpansionEnabled(true);
+
+        assertTrue(checkActionsMatch(mActionsProvider.getActionsList(),
+                new int[]{ACTION_FULLSCREEN, ACTION_CLOSE, ACTION_MOVE, ACTION_EXPAND_COLLAPSE}));
+    }
+
+    @Test
+    public void expandedPip_toggleExpansion() {
+        // PiP has expanded PiP enabled, but is in a collapsed state
+        mActionsProvider.updateExpansionEnabled(true);
+        mActionsProvider.onPipExpansionToggled(/* expanded= */ false);
+
+        mActionsProvider.addListener(mMockListener);
+        mActionsProvider.onPipExpansionToggled(/* expanded= */ true);
+
+        assertTrue(checkActionsMatch(mActionsProvider.getActionsList(),
+                new int[]{ACTION_FULLSCREEN, ACTION_CLOSE, ACTION_MOVE, ACTION_EXPAND_COLLAPSE}));
+        verify(mMockListener).onActionsChanged(0, 1, 3);
+    }
+
+    @Test
+    public void customActions_added() {
+        mActionsProvider.updateExpansionEnabled(false);
+        mActionsProvider.addListener(mMockListener);
+
+        mActionsProvider.setAppActions(createRemoteActions(2), null);
+
+        assertTrue(checkActionsMatch(mActionsProvider.getActionsList(),
+                new int[]{ACTION_FULLSCREEN, ACTION_CLOSE, ACTION_CUSTOM, ACTION_CUSTOM,
+                        ACTION_MOVE}));
+        verify(mMockListener).onActionsChanged(/* added= */ 2, /* updated= */ 0, /* index= */ 2);
+    }
+
+    @Test
+    public void customActions_replacedMore() {
+        mActionsProvider.updateExpansionEnabled(false);
+        mActionsProvider.setAppActions(createRemoteActions(2), null);
+
+        mActionsProvider.addListener(mMockListener);
+        mActionsProvider.setAppActions(createRemoteActions(3), null);
+
+        assertTrue(checkActionsMatch(mActionsProvider.getActionsList(),
+                new int[]{ACTION_FULLSCREEN, ACTION_CLOSE, ACTION_CUSTOM, ACTION_CUSTOM,
+                        ACTION_CUSTOM, ACTION_MOVE}));
+        verify(mMockListener).onActionsChanged(/* added= */ 1, /* updated= */ 2, /* index= */ 2);
+    }
+
+    @Test
+    public void customActions_replacedLess() {
+        mActionsProvider.updateExpansionEnabled(false);
+        mActionsProvider.setAppActions(createRemoteActions(2), null);
+
+        mActionsProvider.addListener(mMockListener);
+        mActionsProvider.setAppActions(createRemoteActions(0), null);
+
+        assertTrue(checkActionsMatch(mActionsProvider.getActionsList(),
+                new int[]{ACTION_FULLSCREEN, ACTION_CLOSE, ACTION_MOVE}));
+        verify(mMockListener).onActionsChanged(/* added= */ -2, /* updated= */ 0, /* index= */ 2);
+    }
+
+    @Test
+    public void customCloseAdded() {
+        mActionsProvider.updateExpansionEnabled(false);
+
+        List<RemoteAction> customActions = new ArrayList<>();
+        mActionsProvider.setAppActions(customActions, null);
+
+        mActionsProvider.addListener(mMockListener);
+        mActionsProvider.setAppActions(customActions, createRemoteAction(0));
+
+        assertTrue(checkActionsMatch(mActionsProvider.getActionsList(),
+                new int[]{ACTION_FULLSCREEN, ACTION_CUSTOM_CLOSE, ACTION_MOVE}));
+        verify(mMockListener).onActionsChanged(/* added= */ 0, /* updated= */ 1, /* index= */ 1);
+    }
+
+    @Test
+    public void customClose_matchesOtherCustomAction() {
+        mActionsProvider.updateExpansionEnabled(false);
+
+        List<RemoteAction> customActions = createRemoteActions(2);
+        RemoteAction customClose = createRemoteAction(/* id= */ 10);
+        customActions.add(customClose);
+
+        mActionsProvider.addListener(mMockListener);
+        mActionsProvider.setAppActions(customActions, customClose);
+
+        assertTrue(checkActionsMatch(mActionsProvider.getActionsList(),
+                new int[]{ACTION_FULLSCREEN, ACTION_CUSTOM_CLOSE, ACTION_CUSTOM, ACTION_CUSTOM,
+                        ACTION_MOVE}));
+        verify(mMockListener).onActionsChanged(/* added= */ 0, /* updated= */ 1, /* index= */ 1);
+        verify(mMockListener).onActionsChanged(/* added= */ 2, /* updated= */ 0, /* index= */ 2);
+    }
+
+    @Test
+    public void mediaActions_added_whileCustomActionsExist() {
+        mActionsProvider.updateExpansionEnabled(false);
+        mActionsProvider.setAppActions(createRemoteActions(2), null);
+
+        mActionsProvider.addListener(mMockListener);
+        mActionsProvider.onMediaActionsChanged(createRemoteActions(3));
+
+        assertTrue(checkActionsMatch(mActionsProvider.getActionsList(),
+                new int[]{ACTION_FULLSCREEN, ACTION_CLOSE, ACTION_CUSTOM, ACTION_CUSTOM,
+                        ACTION_MOVE}));
+        verify(mMockListener, times(0)).onActionsChanged(anyInt(), anyInt(), anyInt());
+    }
+
+    @Test
+    public void customActions_removed_whileMediaActionsExist() {
+        mActionsProvider.updateExpansionEnabled(false);
+        mActionsProvider.onMediaActionsChanged(createRemoteActions(2));
+        mActionsProvider.setAppActions(createRemoteActions(3), null);
+
+        mActionsProvider.addListener(mMockListener);
+        mActionsProvider.setAppActions(createRemoteActions(0), null);
+
+        assertTrue(checkActionsMatch(mActionsProvider.getActionsList(),
+                new int[]{ACTION_FULLSCREEN, ACTION_CLOSE, ACTION_CUSTOM, ACTION_CUSTOM,
+                        ACTION_MOVE}));
+        verify(mMockListener).onActionsChanged(/* added= */ -1, /* updated= */ 2, /* index= */ 2);
+    }
+
+    @Test
+    public void customCloseOnly_mediaActionsShowing() {
+        mActionsProvider.updateExpansionEnabled(false);
+        mActionsProvider.onMediaActionsChanged(createRemoteActions(2));
+
+        mActionsProvider.addListener(mMockListener);
+        mActionsProvider.setAppActions(createRemoteActions(0), createRemoteAction(5));
+
+        assertTrue(checkActionsMatch(mActionsProvider.getActionsList(),
+                new int[]{ACTION_FULLSCREEN, ACTION_CUSTOM_CLOSE, ACTION_CUSTOM, ACTION_CUSTOM,
+                        ACTION_MOVE}));
+        verify(mMockListener).onActionsChanged(/* added= */ 0, /* updated= */ 1, /* index= */ 1);
+    }
+
+    @Test
+    public void customActions_showDisabledActions() {
+        mActionsProvider.updateExpansionEnabled(false);
+
+        List<RemoteAction> customActions = createRemoteActions(2);
+        customActions.get(0).setEnabled(false);
+        mActionsProvider.setAppActions(customActions, null);
+
+        assertTrue(checkActionsMatch(mActionsProvider.getActionsList(),
+                new int[]{ACTION_FULLSCREEN, ACTION_CLOSE, ACTION_CUSTOM, ACTION_CUSTOM,
+                        ACTION_MOVE}));
+    }
+
+    @Test
+    public void mediaActions_hideDisabledActions() {
+        mActionsProvider.updateExpansionEnabled(false);
+
+        List<RemoteAction> customActions = createRemoteActions(2);
+        customActions.get(0).setEnabled(false);
+        mActionsProvider.onMediaActionsChanged(customActions);
+
+        assertTrue(checkActionsMatch(mActionsProvider.getActionsList(),
+                new int[]{ACTION_FULLSCREEN, ACTION_CLOSE, ACTION_CUSTOM, ACTION_MOVE}));
+    }
+
+}
+
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModelTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModelTests.java
index ad6fced..0dbf30d 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModelTests.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModelTests.java
@@ -21,14 +21,15 @@
 import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
 
 import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.anyInt;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import android.app.ActivityManager;
+import android.hardware.display.DisplayManager;
+import android.hardware.display.VirtualDisplay;
 import android.hardware.input.InputManager;
 import android.os.Handler;
 import android.os.Looper;
@@ -37,9 +38,9 @@
 import android.view.InputChannel;
 import android.view.InputMonitor;
 import android.view.SurfaceControl;
+import android.view.SurfaceView;
 
 import androidx.test.filters.SmallTest;
-import androidx.test.rule.GrantPermissionRule;
 
 import com.android.wm.shell.ShellTaskOrganizer;
 import com.android.wm.shell.ShellTestCase;
@@ -55,37 +56,28 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
-import java.util.function.Supplier;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 /** Tests of {@link CaptionWindowDecorViewModel} */
 @SmallTest
 public class CaptionWindowDecorViewModelTests extends ShellTestCase {
-    @Mock private CaptionWindowDecoration mCaptionWindowDecoration;
 
+    private static final String TAG = "CaptionWindowDecorViewModelTests";
+
+    @Mock private CaptionWindowDecoration mCaptionWindowDecoration;
     @Mock private CaptionWindowDecoration.Factory mCaptionWindowDecorFactory;
 
     @Mock private Handler mMainHandler;
-
     @Mock private Choreographer mMainChoreographer;
-
     @Mock private ShellTaskOrganizer mTaskOrganizer;
-
     @Mock private DisplayController mDisplayController;
-
     @Mock private SyncTransactionQueue mSyncQueue;
-
     @Mock private DesktopModeController mDesktopModeController;
-
     @Mock private InputMonitor mInputMonitor;
-
-    @Mock private InputChannel mInputChannel;
-
-    @Mock private CaptionWindowDecorViewModel.EventReceiverFactory mEventReceiverFactory;
-
-    @Mock private CaptionWindowDecorViewModel.EventReceiver mEventReceiver;
-
     @Mock private InputManager mInputManager;
 
+    @Mock private CaptionWindowDecorViewModel.InputMonitorFactory mMockInputMonitorFactory;
     private final List<InputManager> mMockInputManagers = new ArrayList<>();
 
     private CaptionWindowDecorViewModel mCaptionWindowDecorViewModel;
@@ -104,44 +96,46 @@
                 mSyncQueue,
                 Optional.of(mDesktopModeController),
                 mCaptionWindowDecorFactory,
-                new MockObjectSupplier<>(mMockInputManagers, () -> mock(InputManager.class)));
-        mCaptionWindowDecorViewModel.setEventReceiverFactory(mEventReceiverFactory);
+                mMockInputMonitorFactory
+            );
 
         doReturn(mCaptionWindowDecoration)
             .when(mCaptionWindowDecorFactory)
             .create(any(), any(), any(), any(), any(), any(), any(), any());
 
-        when(mInputManager.monitorGestureInput(any(), anyInt())).thenReturn(mInputMonitor);
-        when(mEventReceiverFactory.create(any(), any(), any())).thenReturn(mEventReceiver);
-        when(mInputMonitor.getInputChannel()).thenReturn(mInputChannel);
+        when(mMockInputMonitorFactory.create(any(), any())).thenReturn(mInputMonitor);
+        // InputChannel cannot be mocked because it passes to InputEventReceiver.
+        final InputChannel[] inputChannels = InputChannel.openInputChannelPair(TAG);
+        inputChannels[0].dispose();
+        when(mInputMonitor.getInputChannel()).thenReturn(inputChannels[1]);
     }
 
     @Test
     public void testDeleteCaptionOnChangeTransitionWhenNecessary() throws Exception {
-        Looper.prepare();
         final int taskId = 1;
         final ActivityManager.RunningTaskInfo taskInfo =
-                createTaskInfo(taskId, WINDOWING_MODE_FREEFORM);
+                createTaskInfo(taskId, Display.DEFAULT_DISPLAY, WINDOWING_MODE_FREEFORM);
         SurfaceControl surfaceControl = mock(SurfaceControl.class);
-        final SurfaceControl.Transaction startT = mock(SurfaceControl.Transaction.class);
-        final SurfaceControl.Transaction finishT = mock(SurfaceControl.Transaction.class);
-        GrantPermissionRule.grant(android.Manifest.permission.MONITOR_INPUT);
+        runOnMainThread(() -> {
+            final SurfaceControl.Transaction startT = mock(SurfaceControl.Transaction.class);
+            final SurfaceControl.Transaction finishT = mock(SurfaceControl.Transaction.class);
 
-        mCaptionWindowDecorViewModel.onTaskOpening(taskInfo, surfaceControl, startT, finishT);
+            mCaptionWindowDecorViewModel.onTaskOpening(taskInfo, surfaceControl, startT, finishT);
+
+            taskInfo.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_UNDEFINED);
+            taskInfo.configuration.windowConfiguration.setActivityType(ACTIVITY_TYPE_UNDEFINED);
+            mCaptionWindowDecorViewModel.onTaskChanging(taskInfo, surfaceControl, startT, finishT);
+        });
         verify(mCaptionWindowDecorFactory)
                 .create(
-                    mContext,
-                    mDisplayController,
-                    mTaskOrganizer,
-                    taskInfo,
-                    surfaceControl,
-                    mMainHandler,
-                    mMainChoreographer,
-                    mSyncQueue);
-
-        taskInfo.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_UNDEFINED);
-        taskInfo.configuration.windowConfiguration.setActivityType(ACTIVITY_TYPE_UNDEFINED);
-        mCaptionWindowDecorViewModel.onTaskChanging(taskInfo, surfaceControl, startT, finishT);
+                        mContext,
+                        mDisplayController,
+                        mTaskOrganizer,
+                        taskInfo,
+                        surfaceControl,
+                        mMainHandler,
+                        mMainChoreographer,
+                        mSyncQueue);
         verify(mCaptionWindowDecoration).close();
     }
 
@@ -149,70 +143,105 @@
     public void testCreateCaptionOnChangeTransitionWhenNecessary() throws Exception {
         final int taskId = 1;
         final ActivityManager.RunningTaskInfo taskInfo =
-                createTaskInfo(taskId, WINDOWING_MODE_UNDEFINED);
+                createTaskInfo(taskId, Display.DEFAULT_DISPLAY, WINDOWING_MODE_UNDEFINED);
         SurfaceControl surfaceControl = mock(SurfaceControl.class);
-        final SurfaceControl.Transaction startT = mock(SurfaceControl.Transaction.class);
-        final SurfaceControl.Transaction finishT = mock(SurfaceControl.Transaction.class);
-        taskInfo.configuration.windowConfiguration.setActivityType(ACTIVITY_TYPE_UNDEFINED);
+        runOnMainThread(() -> {
+            final SurfaceControl.Transaction startT = mock(SurfaceControl.Transaction.class);
+            final SurfaceControl.Transaction finishT = mock(SurfaceControl.Transaction.class);
+            taskInfo.configuration.windowConfiguration.setActivityType(ACTIVITY_TYPE_UNDEFINED);
 
-        mCaptionWindowDecorViewModel.onTaskChanging(taskInfo, surfaceControl, startT, finishT);
+            mCaptionWindowDecorViewModel.onTaskChanging(taskInfo, surfaceControl, startT, finishT);
 
-        verify(mCaptionWindowDecorFactory, never())
+            taskInfo.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FREEFORM);
+            taskInfo.configuration.windowConfiguration.setActivityType(ACTIVITY_TYPE_STANDARD);
+
+            mCaptionWindowDecorViewModel.onTaskChanging(taskInfo, surfaceControl, startT, finishT);
+        });
+        verify(mCaptionWindowDecorFactory, times(1))
                 .create(
-                    mContext,
-                    mDisplayController,
-                    mTaskOrganizer,
-                    taskInfo,
-                    surfaceControl,
-                    mMainHandler,
-                    mMainChoreographer,
-                    mSyncQueue);
-
-        taskInfo.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FREEFORM);
-        taskInfo.configuration.windowConfiguration.setActivityType(ACTIVITY_TYPE_STANDARD);
-
-        mCaptionWindowDecorViewModel.onTaskChanging(taskInfo, surfaceControl, startT, finishT);
-
-        verify(mCaptionWindowDecorFactory)
-                .create(
-                    mContext,
-                    mDisplayController,
-                    mTaskOrganizer,
-                    taskInfo,
-                    surfaceControl,
-                    mMainHandler,
-                    mMainChoreographer,
-                    mSyncQueue);
+                        mContext,
+                        mDisplayController,
+                        mTaskOrganizer,
+                        taskInfo,
+                        surfaceControl,
+                        mMainHandler,
+                        mMainChoreographer,
+                        mSyncQueue);
     }
 
-    private static ActivityManager.RunningTaskInfo createTaskInfo(int taskId, int windowingMode) {
+    @Test
+    public void testCreateAndDisposeEventReceiver() throws Exception {
+        final int taskId = 1;
+        final ActivityManager.RunningTaskInfo taskInfo =
+                createTaskInfo(taskId, Display.DEFAULT_DISPLAY, WINDOWING_MODE_FREEFORM);
+        taskInfo.configuration.windowConfiguration.setActivityType(ACTIVITY_TYPE_STANDARD);
+        runOnMainThread(() -> {
+            SurfaceControl surfaceControl = mock(SurfaceControl.class);
+            final SurfaceControl.Transaction startT = mock(SurfaceControl.Transaction.class);
+            final SurfaceControl.Transaction finishT = mock(SurfaceControl.Transaction.class);
+
+            mCaptionWindowDecorViewModel.onTaskOpening(taskInfo, surfaceControl, startT, finishT);
+
+            mCaptionWindowDecorViewModel.destroyWindowDecoration(taskInfo);
+        });
+        verify(mMockInputMonitorFactory).create(any(), any());
+        verify(mInputMonitor).dispose();
+    }
+
+    @Test
+    public void testEventReceiversOnMultipleDisplays() throws Exception {
+        runOnMainThread(() -> {
+            SurfaceView surfaceView = new SurfaceView(mContext);
+            final DisplayManager mDm = mContext.getSystemService(DisplayManager.class);
+            final VirtualDisplay secondaryDisplay = mDm.createVirtualDisplay(
+                    "testEventReceiversOnMultipleDisplays", /*width=*/ 400, /*height=*/ 400,
+                    /*densityDpi=*/ 320, surfaceView.getHolder().getSurface(),
+                    DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY);
+            int secondaryDisplayId = secondaryDisplay.getDisplay().getDisplayId();
+
+            final int taskId = 1;
+            final ActivityManager.RunningTaskInfo taskInfo =
+                    createTaskInfo(taskId, Display.DEFAULT_DISPLAY, WINDOWING_MODE_FREEFORM);
+            final ActivityManager.RunningTaskInfo secondTaskInfo =
+                    createTaskInfo(taskId + 1, secondaryDisplayId, WINDOWING_MODE_FREEFORM);
+            final ActivityManager.RunningTaskInfo thirdTaskInfo =
+                    createTaskInfo(taskId + 2, secondaryDisplayId, WINDOWING_MODE_FREEFORM);
+
+            SurfaceControl surfaceControl = mock(SurfaceControl.class);
+            final SurfaceControl.Transaction startT = mock(SurfaceControl.Transaction.class);
+            final SurfaceControl.Transaction finishT = mock(SurfaceControl.Transaction.class);
+
+            mCaptionWindowDecorViewModel.onTaskOpening(taskInfo, surfaceControl, startT, finishT);
+            mCaptionWindowDecorViewModel.onTaskOpening(secondTaskInfo, surfaceControl,
+                    startT, finishT);
+            mCaptionWindowDecorViewModel.onTaskOpening(thirdTaskInfo, surfaceControl,
+                    startT, finishT);
+            mCaptionWindowDecorViewModel.destroyWindowDecoration(thirdTaskInfo);
+            mCaptionWindowDecorViewModel.destroyWindowDecoration(taskInfo);
+        });
+        verify(mMockInputMonitorFactory, times(2)).create(any(), any());
+        verify(mInputMonitor, times(1)).dispose();
+    }
+
+    private void runOnMainThread(Runnable r) throws Exception {
+        final Handler mainHandler = new Handler(Looper.getMainLooper());
+        final CountDownLatch latch = new CountDownLatch(1);
+        mainHandler.post(() -> {
+            r.run();
+            latch.countDown();
+        });
+        latch.await(20, TimeUnit.MILLISECONDS);
+    }
+
+    private static ActivityManager.RunningTaskInfo createTaskInfo(int taskId,
+            int displayId, int windowingMode) {
         ActivityManager.RunningTaskInfo taskInfo =
                  new TestRunningTaskInfoBuilder()
-                .setDisplayId(Display.DEFAULT_DISPLAY)
+                .setDisplayId(displayId)
                 .setVisible(true)
                 .build();
         taskInfo.taskId = taskId;
         taskInfo.configuration.windowConfiguration.setWindowingMode(windowingMode);
         return taskInfo;
     }
-
-    private static class MockObjectSupplier<T> implements Supplier<T> {
-        private final List<T> mObjects;
-        private final Supplier<T> mDefaultSupplier;
-        private int mNumOfCalls = 0;
-
-        private MockObjectSupplier(List<T> objects, Supplier<T> defaultSupplier) {
-            mObjects = objects;
-            mDefaultSupplier = defaultSupplier;
-        }
-
-        @Override
-        public T get() {
-            final T mock =
-                    mNumOfCalls < mObjects.size() ? mObjects.get(mNumOfCalls)
-                        : mDefaultSupplier.get();
-            ++mNumOfCalls;
-            return mock;
-        }
-    }
 }
diff --git a/libs/hwui/Properties.cpp b/libs/hwui/Properties.cpp
index 277955e..6affc6a 100644
--- a/libs/hwui/Properties.cpp
+++ b/libs/hwui/Properties.cpp
@@ -82,7 +82,7 @@
 int Properties::contextPriority = 0;
 float Properties::defaultSdrWhitePoint = 200.f;
 
-bool Properties::useHintManager = true;
+bool Properties::useHintManager = false;
 int Properties::targetCpuTimePercentage = 70;
 
 bool Properties::enableWebViewOverlays = true;
@@ -142,7 +142,7 @@
 
     runningInEmulator = base::GetBoolProperty(PROPERTY_IS_EMULATOR, false);
 
-    useHintManager = base::GetBoolProperty(PROPERTY_USE_HINT_MANAGER, true);
+    useHintManager = base::GetBoolProperty(PROPERTY_USE_HINT_MANAGER, false);
     targetCpuTimePercentage = base::GetIntProperty(PROPERTY_TARGET_CPU_TIME_PERCENTAGE, 70);
     if (targetCpuTimePercentage <= 0 || targetCpuTimePercentage > 100) targetCpuTimePercentage = 70;
 
diff --git a/libs/hwui/jni/Mesh.cpp b/libs/hwui/jni/Mesh.cpp
index 109aac3..7b9a93f 100644
--- a/libs/hwui/jni/Mesh.cpp
+++ b/libs/hwui/jni/Mesh.cpp
@@ -45,7 +45,8 @@
             genVertexBuffer(env, vertexBuffer, vertexCount * skMeshSpec->stride(), isDirect);
     auto skRect = SkRect::MakeLTRB(left, top, right, bottom);
     auto mesh = SkMesh::Make(skMeshSpec, SkMesh::Mode(mode), skVertexBuffer, vertexCount,
-                             vertexOffset, nullptr, skRect);
+                             vertexOffset, nullptr, skRect)
+                        .mesh;
     auto meshPtr = std::make_unique<MeshWrapper>(MeshWrapper{mesh, MeshUniformBuilder(skMeshSpec)});
     return reinterpret_cast<jlong>(meshPtr.release());
 }
@@ -62,7 +63,8 @@
     auto skRect = SkRect::MakeLTRB(left, top, right, bottom);
     auto mesh = SkMesh::MakeIndexed(skMeshSpec, SkMesh::Mode(mode), skVertexBuffer, vertexCount,
                                     vertexOffset, skIndexBuffer, indexCount, indexOffset, nullptr,
-                                    skRect);
+                                    skRect)
+                        .mesh;
     auto meshPtr = std::make_unique<MeshWrapper>(MeshWrapper{mesh, MeshUniformBuilder(skMeshSpec)});
     return reinterpret_cast<jlong>(meshPtr.release());
 }
@@ -71,14 +73,17 @@
     auto wrapper = reinterpret_cast<MeshWrapper*>(meshWrapper);
     auto mesh = wrapper->mesh;
     if (indexed) {
-        wrapper->mesh = SkMesh::MakeIndexed(
-                sk_ref_sp(mesh.spec()), mesh.mode(), sk_ref_sp(mesh.vertexBuffer()),
-                mesh.vertexCount(), mesh.vertexOffset(), sk_ref_sp(mesh.indexBuffer()),
-                mesh.indexCount(), mesh.indexOffset(), wrapper->builder.fUniforms, mesh.bounds());
+        wrapper->mesh = SkMesh::MakeIndexed(sk_ref_sp(mesh.spec()), mesh.mode(),
+                                            sk_ref_sp(mesh.vertexBuffer()), mesh.vertexCount(),
+                                            mesh.vertexOffset(), sk_ref_sp(mesh.indexBuffer()),
+                                            mesh.indexCount(), mesh.indexOffset(),
+                                            wrapper->builder.fUniforms, mesh.bounds())
+                                .mesh;
     } else {
-        wrapper->mesh = SkMesh::Make(
-                sk_ref_sp(mesh.spec()), mesh.mode(), sk_ref_sp(mesh.vertexBuffer()),
-                mesh.vertexCount(), mesh.vertexOffset(), wrapper->builder.fUniforms, mesh.bounds());
+        wrapper->mesh = SkMesh::Make(sk_ref_sp(mesh.spec()), mesh.mode(),
+                                     sk_ref_sp(mesh.vertexBuffer()), mesh.vertexCount(),
+                                     mesh.vertexOffset(), wrapper->builder.fUniforms, mesh.bounds())
+                                .mesh;
     }
 }
 
diff --git a/libs/hwui/tests/common/TestContext.cpp b/libs/hwui/tests/common/TestContext.cpp
index 0faa8f4..fd596d9 100644
--- a/libs/hwui/tests/common/TestContext.cpp
+++ b/libs/hwui/tests/common/TestContext.cpp
@@ -31,10 +31,8 @@
         const std::vector<PhysicalDisplayId> ids = SurfaceComposerClient::getPhysicalDisplayIds();
         LOG_ALWAYS_FATAL_IF(ids.empty(), "%s: No displays", __FUNCTION__);
 
-        const sp<IBinder> token = SurfaceComposerClient::getPhysicalDisplayToken(ids.front());
-        LOG_ALWAYS_FATAL_IF(!token, "%s: No internal display", __FUNCTION__);
-
-        const status_t status = SurfaceComposerClient::getStaticDisplayInfo(token, &info);
+        const status_t status =
+                SurfaceComposerClient::getStaticDisplayInfo(ids.front().value, &info);
         LOG_ALWAYS_FATAL_IF(status, "%s: Failed to get display info", __FUNCTION__);
 #endif
         return info;
diff --git a/location/java/android/location/Country.java b/location/java/android/location/Country.java
index 8e1bb1f0..53cc943 100644
--- a/location/java/android/location/Country.java
+++ b/location/java/android/location/Country.java
@@ -16,6 +16,7 @@
 
 package android.location;
 
+import android.annotation.IntDef;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.annotation.SystemApi;
@@ -24,6 +25,8 @@
 import android.os.Parcelable;
 import android.os.SystemClock;
 
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
 import java.util.Locale;
 
 /**
@@ -54,8 +57,22 @@
     public static final int COUNTRY_SOURCE_LOCALE = 3;
 
     /**
-     * The ISO 3166-1 two letters country code.
+     * Country source type
+     *
+     * @hide
      */
+    @IntDef(
+            prefix = {"COUNTRY_SOURCE_"},
+            value = {
+                    COUNTRY_SOURCE_NETWORK,
+                    COUNTRY_SOURCE_LOCATION,
+                    COUNTRY_SOURCE_SIM,
+                    COUNTRY_SOURCE_LOCALE
+            })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface CountrySource {}
+
+    /** The ISO 3166-1 two letters country code. */
     private final String mCountryIso;
 
     /**
@@ -73,21 +90,18 @@
 
     /**
      * @param countryIso the ISO 3166-1 two letters country code.
-     * @param source where the countryIso came from, could be one of below
-     *        values
-     *        <p>
-     *        <ul>
-     *        <li>{@link #COUNTRY_SOURCE_NETWORK}</li>
-     *        <li>{@link #COUNTRY_SOURCE_LOCATION}</li>
-     *        <li>{@link #COUNTRY_SOURCE_SIM}</li>
-     *        <li>{@link #COUNTRY_SOURCE_LOCALE}</li>
-     *        </ul>
-     *
-     * @hide
+     * @param source where the countryIso came from, could be one of below values
+     *     <p>
+     *     <ul>
+     *       <li>{@link #COUNTRY_SOURCE_NETWORK}
+     *       <li>{@link #COUNTRY_SOURCE_LOCATION}
+     *       <li>{@link #COUNTRY_SOURCE_SIM}
+     *       <li>{@link #COUNTRY_SOURCE_LOCALE}
+     *     </ul>
      */
-    @UnsupportedAppUsage
-    public Country(final String countryIso, final int source) {
-        if (countryIso == null || source < COUNTRY_SOURCE_NETWORK
+    public Country(@NonNull final String countryIso, @CountrySource final int source) {
+        if (countryIso == null
+                || source < COUNTRY_SOURCE_NETWORK
                 || source > COUNTRY_SOURCE_LOCALE) {
             throw new IllegalArgumentException();
         }
@@ -115,9 +129,24 @@
 
     /**
      * @return the ISO 3166-1 two letters country code
+     *
+     * @hide
+     *
+     * @deprecated clients using getCountryIso should use the {@link #getCountryCode()} API instead.
+     */
+    @UnsupportedAppUsage
+    @Deprecated
+    public String getCountryIso() {
+        return mCountryIso;
+    }
+
+    /**
+     * Retrieves country code.
+     *
+     * @return country code in ISO 3166-1:alpha2
      */
     @NonNull
-    public String getCountryIso() {
+    public String getCountryCode() {
         return mCountryIso;
     }
 
@@ -131,6 +160,7 @@
      *         <li>{@link #COUNTRY_SOURCE_LOCALE}</li>
      *         </ul>
      */
+    @CountrySource
     public int getSource() {
         return mSource;
     }
diff --git a/location/java/android/location/CountryDetector.java b/location/java/android/location/CountryDetector.java
index 3a0edfc..6abb350 100644
--- a/location/java/android/location/CountryDetector.java
+++ b/location/java/android/location/CountryDetector.java
@@ -24,28 +24,32 @@
 import android.content.Context;
 import android.os.Build;
 import android.os.Handler;
+import android.os.HandlerExecutor;
 import android.os.Looper;
 import android.os.RemoteException;
 import android.util.Log;
 
 import java.util.HashMap;
+import java.util.concurrent.Executor;
+import java.util.function.Consumer;
 
 /**
- * This class provides access to the system country detector service. This
- * service allows applications to obtain the country that the user is in.
- * <p>
- * The country will be detected in order of reliability, like
+ * This class provides access to the system country detector service. This service allows
+ * applications to obtain the country that the user is in.
+ *
+ * <p>The country will be detected in order of reliability, like
+ *
  * <ul>
- * <li>Mobile network</li>
- * <li>Location</li>
- * <li>SIM's country</li>
- * <li>Phone's locale</li>
+ *   <li>Mobile network
+ *   <li>Location
+ *   <li>SIM's country
+ *   <li>Phone's locale
  * </ul>
- * <p>
- * Call the {@link #detectCountry()} to get the available country immediately.
- * <p>
- * To be notified of the future country change, use the
- * {@link #addCountryListener}
+ *
+ * <p>Call the {@link #detectCountry()} to get the available country immediately.
+ *
+ * <p>To be notified of the future country change, use the {@link #addCountryListener}
+ *
  * <p>
  *
  * @hide
@@ -55,57 +59,52 @@
 public class CountryDetector {
 
     /**
-     * The class to wrap the ICountryListener.Stub and CountryListener objects
-     * together. The CountryListener will be notified through the specific
-     * looper once the country changed and detected.
+     * The class to wrap the ICountryListener.Stub , CountryListener & {@code Consumer<Country>}
+     * objects together.
+     *
+     * <p>The CountryListener will be notified through the Handler Executor once the country changed
+     * and detected.
+     *
+     * <p>{@code Consumer<Country>} callback interface is notified through the specific executor
+     * once the country changed and detected.
      */
-    private final static class ListenerTransport extends ICountryListener.Stub {
+    private static final class ListenerTransport extends ICountryListener.Stub {
 
-        private final CountryListener mListener;
+        private final Consumer<Country> mListener;
+        private final Executor mExecutor;
 
-        private final Handler mHandler;
-
-        public ListenerTransport(CountryListener listener, Looper looper) {
-            mListener = listener;
-            if (looper != null) {
-                mHandler = new Handler(looper);
-            } else {
-                mHandler = new Handler();
-            }
+        ListenerTransport(Consumer<Country> consumer, Executor executor) {
+            mListener = consumer;
+            mExecutor = executor;
         }
 
         public void onCountryDetected(final Country country) {
-            mHandler.post(new Runnable() {
-                public void run() {
-                    mListener.onCountryDetected(country);
-                }
-            });
+            mExecutor.execute(() -> mListener.accept(country));
         }
     }
 
-    private final static String TAG = "CountryDetector";
+    private static final String TAG = "CountryDetector";
     private final ICountryDetector mService;
-    private final HashMap<CountryListener, ListenerTransport> mListeners;
+    private final HashMap<Consumer<Country>, ListenerTransport> mListeners;
 
     /**
-     * @hide - hide this constructor because it has a parameter of type
-     *       ICountryDetector, which is a system private class. The right way to
-     *       create an instance of this class is using the factory
-     *       Context.getSystemService.
+     * @hide - hide this constructor because it has a parameter of type ICountryDetector, which is a
+     *     system private class. The right way to create an instance of this class is using the
+     *     factory Context.getSystemService.
      */
     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
     public CountryDetector(ICountryDetector service) {
         mService = service;
-        mListeners = new HashMap<CountryListener, ListenerTransport>();
+        mListeners = new HashMap<>();
     }
 
     /**
      * Start detecting the country that the user is in.
      *
-     * @return the country if it is available immediately, otherwise null will
-     *         be returned.
+     * @return the country if it is available immediately, otherwise null will be returned.
+     * @hide
      */
-    @Nullable
+    @UnsupportedAppUsage
     public Country detectCountry() {
         try {
             return mService.detectCountry();
@@ -116,40 +115,64 @@
     }
 
     /**
-     * Add a listener to receive the notification when the country is detected
-     * or changed.
+     * Add a listener to receive the notification when the country is detected or changed.
      *
      * @param listener will be called when the country is detected or changed.
-     * @param looper a Looper object whose message queue will be used to
-     *        implement the callback mechanism. If looper is null then the
-     *        callbacks will be called on the main thread.
+     * @param looper a Looper object whose message queue will be used to implement the callback
+     *     mechanism. If looper is null then the callbacks will be called on the main thread.
+     * @hide
+     * @deprecated client using this api should use {@link
+     *     #registerCountryDetectorCallback(Executor, Consumer)} }
      */
+    @UnsupportedAppUsage
+    @Deprecated
     public void addCountryListener(@NonNull CountryListener listener, @Nullable Looper looper) {
-        synchronized (mListeners) {
-            if (!mListeners.containsKey(listener)) {
-                ListenerTransport transport = new ListenerTransport(listener, looper);
-                try {
-                    mService.addCountryListener(transport);
-                    mListeners.put(listener, transport);
-                } catch (RemoteException e) {
-                    Log.e(TAG, "addCountryListener: RemoteException", e);
-                }
-            }
-        }
+        Handler handler = looper != null ? new Handler(looper) : new Handler();
+        registerCountryDetectorCallback(new HandlerExecutor(handler), listener);
     }
 
     /**
      * Remove the listener
+     *
+     * @hide
+     * @deprecated client using this api should use {@link
+     *     #unregisterCountryDetectorCallback(Consumer)}
      */
-    public void removeCountryListener(@NonNull CountryListener listener) {
+    @UnsupportedAppUsage
+    @Deprecated
+    public void removeCountryListener(CountryListener listener) {
+        unregisterCountryDetectorCallback(listener);
+    }
+
+    /**
+     * Add a callback interface, to be notified when country code is added or changes.
+     *
+     * @param executor The callback executor for the response.
+     * @param consumer {@link Consumer} callback to receive the country code when changed/detected
+     */
+    public void registerCountryDetectorCallback(
+            @NonNull Executor executor, @NonNull Consumer<Country> consumer) {
         synchronized (mListeners) {
-            ListenerTransport transport = mListeners.get(listener);
+            unregisterCountryDetectorCallback(consumer);
+            ListenerTransport transport = new ListenerTransport(consumer, executor);
+            try {
+                mService.addCountryListener(transport);
+                mListeners.put(consumer, transport);
+            } catch (RemoteException e) {
+                throw e.rethrowFromSystemServer();
+            }
+        }
+    }
+
+    /** Remove the callback subscribed to Update country code */
+    public void unregisterCountryDetectorCallback(@NonNull Consumer<Country> consumer) {
+        synchronized (mListeners) {
+            ListenerTransport transport = mListeners.remove(consumer);
             if (transport != null) {
                 try {
-                    mListeners.remove(listener);
                     mService.removeCountryListener(transport);
                 } catch (RemoteException e) {
-                    Log.e(TAG, "removeCountryListener: RemoteException", e);
+                    throw e.rethrowFromSystemServer();
                 }
             }
         }
diff --git a/location/java/android/location/CountryListener.java b/location/java/android/location/CountryListener.java
index 5c06d82..0ca6962 100644
--- a/location/java/android/location/CountryListener.java
+++ b/location/java/android/location/CountryListener.java
@@ -16,8 +16,9 @@
 
 package android.location;
 
-import android.annotation.NonNull;
-import android.annotation.SystemApi;
+import android.compat.annotation.UnsupportedAppUsage;
+
+import java.util.function.Consumer;
 
 /**
  * The listener for receiving the notification when the country is detected or
@@ -25,11 +26,17 @@
  *
  * @hide
  */
-@SystemApi(client = SystemApi.Client.PRIVILEGED_APPS)
-public interface CountryListener {
+public interface CountryListener extends Consumer<Country> {
     /**
      * @param country the changed or detected country.
-     *
      */
-    void onCountryDetected(@NonNull Country country);
+    @UnsupportedAppUsage
+    void onCountryDetected(Country country);
+
+    /**
+     * @param country the changed or detected country.
+     */
+    default void accept(Country country) {
+        onCountryDetected(country);
+    }
 }
diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java
index 9b81c09..3619d3a 100644
--- a/location/java/android/location/LocationManager.java
+++ b/location/java/android/location/LocationManager.java
@@ -195,6 +195,21 @@
     public static final String GPS_PROVIDER = "gps";
 
     /**
+     * Standard name of the GNSS hardware location provider.
+     *
+     * <p>This provider is similar to {@link LocationManager#GPS_PROVIDER}, but it directly uses the
+     * HAL GNSS implementation and doesn't go through any provider overrides that may exist. This
+     * provider will only be available when the GPS_PROVIDER is overridden with a proxy using {@link
+     * android.location.provider.LocationProviderBase#ACTION_GNSS_PROVIDER}, and is intended only
+     * for use internally by the location provider system.
+     *
+     * @hide
+     */
+    @SystemApi
+    @RequiresPermission(Manifest.permission.LOCATION_HARDWARE)
+    public static final String GPS_HARDWARE_PROVIDER = "gps_hardware";
+
+    /**
      * A special location provider for receiving locations without actively initiating a location
      * fix. This location provider is always present.
      *
diff --git a/location/java/android/location/altitude/AltitudeConverter.java b/location/java/android/location/altitude/AltitudeConverter.java
index 506128e..d46b4d2 100644
--- a/location/java/android/location/altitude/AltitudeConverter.java
+++ b/location/java/android/location/altitude/AltitudeConverter.java
@@ -151,20 +151,17 @@
      * altitude accuracy if the {@code location} has a finite and non-negative vertical accuracy;
      * otherwise, does not add a corresponding accuracy.
      *
-     * <p>Must be called off the main thread as data may be loaded from raw assets. Throws an
-     * {@link IOException} if an I/O error occurs when loading data.
+     * <p>Must be called off the main thread as data may be loaded from raw assets.
      *
-     * <p>Throws an {@link IllegalArgumentException} if the {@code location} has an invalid
-     * latitude, longitude, or altitude above WGS84. Specifically:
-     *
-     * <ul>
-     *     <li>The latitude must be between -90 and 90, both inclusive.
-     *     <li>The longitude must be between -180 and 180, both inclusive.
-     *     <li>The altitude above WGS84 must be finite.
-     * </ul>
+     * @throws IOException              if an I/O error occurs when loading data from raw assets.
+     * @throws IllegalArgumentException if the {@code location} has an invalid latitude, longitude,
+     *                                  or altitude above WGS84. Specifically, the latitude must be
+     *                                  between -90 and 90 (both inclusive), the longitude must be
+     *                                  between -180 and 180 (both inclusive), and the altitude
+     *                                  above WGS84 must be finite.
      */
     @WorkerThread
-    public void addMslAltitude(@NonNull Context context, @NonNull Location location)
+    public void addMslAltitudeToLocation(@NonNull Context context, @NonNull Location location)
             throws IOException {
         validate(location);
         MapParamsProto params = GeoidHeightMap.getParams(context);
diff --git a/location/java/android/location/provider/LocationProviderBase.java b/location/java/android/location/provider/LocationProviderBase.java
index 5acec79..18672b7 100644
--- a/location/java/android/location/provider/LocationProviderBase.java
+++ b/location/java/android/location/provider/LocationProviderBase.java
@@ -104,8 +104,6 @@
     /**
      * The action the wrapping service should have in its intent filter to implement the
      * {@link android.location.LocationManager#GPS_PROVIDER}.
-     *
-     * @hide
      */
     public static final String ACTION_GNSS_PROVIDER =
             "android.location.provider.action.GNSS_PROVIDER";
diff --git a/media/java/android/media/AudioDeviceInfo.java b/media/java/android/media/AudioDeviceInfo.java
index 3b30b1d..5a72b0b 100644
--- a/media/java/android/media/AudioDeviceInfo.java
+++ b/media/java/android/media/AudioDeviceInfo.java
@@ -89,6 +89,8 @@
     public static final int TYPE_USB_ACCESSORY    = 12;
     /**
      * A device type describing the audio device associated with a dock.
+     * Starting at API 34, this device type only represents digital docks, while docks with an
+     * analog connection are represented with {@link #TYPE_DOCK_ANALOG}.
      * @see #TYPE_DOCK_ANALOG
      */
     public static final int TYPE_DOCK             = 13;
diff --git a/media/java/android/media/AudioFormat.java b/media/java/android/media/AudioFormat.java
index ccd4ed0..4d3f05b 100644
--- a/media/java/android/media/AudioFormat.java
+++ b/media/java/android/media/AudioFormat.java
@@ -373,6 +373,8 @@
      * Use {@link #ENCODING_DTS_UHD_P2} to transmit DTS UHD Profile 2 (aka DTS:X Profile 2)
      * bitstream. */
     public static final int ENCODING_DTS_UHD_P2 = 30;
+    /** Audio data format: Direct Stream Digital */
+    public static final int ENCODING_DSD = 31;
 
     /** @hide */
     public static String toLogFriendlyEncoding(int enc) {
@@ -437,6 +439,8 @@
                 return "ENCODING_DTS_HD_MA";
             case ENCODING_DTS_UHD_P2:
                 return "ENCODING_DTS_UHD_P2";
+            case ENCODING_DSD:
+                return "ENCODING_DSD";
             default :
                 return "invalid encoding " + enc;
         }
@@ -798,6 +802,7 @@
             case ENCODING_DRA:
             case ENCODING_DTS_HD_MA:
             case ENCODING_DTS_UHD_P2:
+            case ENCODING_DSD:
                 return true;
             default:
                 return false;
@@ -837,6 +842,7 @@
             case ENCODING_DRA:
             case ENCODING_DTS_HD_MA:
             case ENCODING_DTS_UHD_P2:
+            case ENCODING_DSD:
                 return true;
             default:
                 return false;
@@ -1211,6 +1217,7 @@
                 case ENCODING_DRA:
                 case ENCODING_DTS_HD_MA:
                 case ENCODING_DTS_UHD_P2:
+                case ENCODING_DSD:
                     mEncoding = encoding;
                     break;
                 case ENCODING_INVALID:
@@ -1441,7 +1448,8 @@
         ENCODING_DTS_UHD_P1,
         ENCODING_DRA,
         ENCODING_DTS_HD_MA,
-        ENCODING_DTS_UHD_P2 }
+        ENCODING_DTS_UHD_P2,
+        ENCODING_DSD }
     )
     @Retention(RetentionPolicy.SOURCE)
     public @interface Encoding {}
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index ae0d45f..3ed2c4b 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -8518,6 +8518,221 @@
         }
     }
 
+    //====================================================================
+    // Preferred mixer attributes
+
+    /**
+     * Returns the {@link AudioMixerAttributes} that can be used to set as preferred mixe
+     * attributes via {@link #setPreferredMixerAttributes(
+     * AudioAttributes, AudioDeviceInfo, AudioMixerAttributes)}.
+     * <p>Note that only USB devices are guaranteed to expose configurable mixer attributes, the
+     * returned list may be empty when devices do not allow dynamic configuration.
+     *
+     * @param device the device to query
+     * @return a list of {@link AudioMixerAttributes} that can be used as preferred mixer attributes
+     *         for the given device.
+     * @see #setPreferredMixerAttributes(AudioAttributes, AudioDeviceInfo, AudioMixerAttributes)
+     */
+    @NonNull
+    public List<AudioMixerAttributes> getSupportedMixerAttributes(@NonNull AudioDeviceInfo device) {
+        Objects.requireNonNull(device);
+        List<AudioMixerAttributes> mixerAttrs = new ArrayList<>();
+        return (AudioSystem.getSupportedMixerAttributes(device.getId(), mixerAttrs)
+                == AudioSystem.SUCCESS) ? mixerAttrs : new ArrayList<>();
+    }
+
+    /**
+     * Configures the mixer attributes for a particular {@link AudioAttributes} over a given
+     * {@link AudioDeviceInfo}.
+     * <p>When constructing an {@link AudioMixerAttributes} for setting preferred mixer attributes,
+     * the mixer format must be constructed from an {@link AudioProfile} that can be used to set
+     * preferred mixer attributes.
+     * <p>The ownership of preferred mixer attributes is recognized by uid. When a playback from the
+     * same uid is routed to the given audio device when calling this API, the output mixer/stream
+     * will be configured with the values previously set via this API.
+     * <p>Use {@link #clearPreferredMixerAttributes(AudioAttributes, AudioDeviceInfo)}
+     * to cancel setting mixer attributes for this {@link AudioAttributes}.
+     *
+     * @param attributes the {@link AudioAttributes} whose mixer attributes should be set.
+     *                   Currently, only {@link AudioAttributes#USAGE_MEDIA} is supported. When
+     *                   playing audio targeted at the given device, use the same attributes for
+     *                   playback.
+     * @param device the device to be routed. Currently, only USB device will be allowed.
+     * @param mixerAttributes the preferred mixer attributes. When playing audio targeted at the
+     *                        given device, use the same {@link AudioFormat} for both playback
+     *                        and the mixer attributes.
+     * @return true only if the preferred mixer attributes are set successfully.
+     * @see #getPreferredMixerAttributes(AudioAttributes, AudioDeviceInfo)
+     * @see #clearPreferredMixerAttributes(AudioAttributes, AudioDeviceInfo)
+     */
+    @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_SETTINGS)
+    public boolean setPreferredMixerAttributes(@NonNull AudioAttributes attributes,
+            @NonNull AudioDeviceInfo device,
+            @NonNull AudioMixerAttributes mixerAttributes) {
+        Objects.requireNonNull(attributes);
+        Objects.requireNonNull(device);
+        Objects.requireNonNull(mixerAttributes);
+        try {
+            final int status = getService().setPreferredMixerAttributes(
+                    attributes, device.getId(), mixerAttributes);
+            return status == AudioSystem.SUCCESS;
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
+    /**
+     * Returns current preferred mixer attributes that is set via
+     * {@link #setPreferredMixerAttributes(AudioAttributes, AudioDeviceInfo, AudioMixerAttributes)}
+     *
+     * @param attributes the {@link AudioAttributes} whose mixer attributes should be set.
+     * @param device the expected routing device
+     * @return the preferred mixer attributes, which will be null when no preferred mixer attributes
+     *         have been set, or when they have been cleared.
+     * @see #setPreferredMixerAttributes(AudioAttributes, AudioDeviceInfo, AudioMixerAttributes)
+     * @see #clearPreferredMixerAttributes(AudioAttributes, AudioDeviceInfo)
+     */
+    @Nullable
+    public AudioMixerAttributes getPreferredMixerAttributes(
+            @NonNull AudioAttributes attributes,
+            @NonNull AudioDeviceInfo device) {
+        Objects.requireNonNull(attributes);
+        Objects.requireNonNull(device);
+        List<AudioMixerAttributes> mixerAttrList = new ArrayList<>();
+        int ret = AudioSystem.getPreferredMixerAttributes(
+                attributes, device.getId(), mixerAttrList);
+        if (ret == AudioSystem.SUCCESS) {
+            return mixerAttrList.isEmpty() ? null : mixerAttrList.get(0);
+        } else {
+            Log.e(TAG, "Failed calling getPreferredMixerAttributes, ret=" + ret);
+            return null;
+        }
+    }
+
+    /**
+     * Clears the current preferred mixer attributes that were previously set via
+     * {@link #setPreferredMixerAttributes(AudioAttributes, AudioDeviceInfo, AudioMixerAttributes)}
+     *
+     * @param attributes the {@link AudioAttributes} whose mixer attributes should be cleared.
+     * @param device the expected routing device
+     * @return true only if the preferred mixer attributes are removed successfully.
+     * @see #setPreferredMixerAttributes(AudioAttributes, AudioDeviceInfo, AudioMixerAttributes)
+     * @see #getPreferredMixerAttributes(AudioAttributes, AudioDeviceInfo)
+     */
+    @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_SETTINGS)
+    public boolean clearPreferredMixerAttributes(
+            @NonNull AudioAttributes attributes,
+            @NonNull AudioDeviceInfo device) {
+        Objects.requireNonNull(attributes);
+        Objects.requireNonNull(device);
+        try {
+            final int status = getService().clearPreferredMixerAttributes(
+                    attributes, device.getId());
+            return status == AudioSystem.SUCCESS;
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
+    /**
+     * Interface to be notified of changes in the preferred mixer attributes.
+     * <p>Note that this listener will only be invoked whenever
+     * {@link #setPreferredMixerAttributes(AudioAttributes, AudioDeviceInfo, AudioMixerAttributes)}
+     * or {@link #clearPreferredMixerAttributes(AudioAttributes, AudioDeviceInfo)} or device
+     * disconnection causes a change in preferred mixer attributes.
+     * @see #setPreferredMixerAttributes(AudioAttributes, AudioDeviceInfo, AudioMixerAttributes)
+     * @see #clearPreferredMixerAttributes(AudioAttributes, AudioDeviceInfo)
+     */
+    public interface OnPreferredMixerAttributesChangedListener {
+        /**
+         * Called on the listener to indicate that the preferred mixer attributes for the audio
+         * attributes over the given device has changed.
+         *
+         * @param attributes the audio attributes for playback
+         * @param device the targeted device
+         * @param mixerAttributes the {@link AudioMixerAttributes} that contains information for
+         *                        preferred mixer attributes or null if preferred mixer attributes
+         *                        is cleared
+         */
+        void onPreferredMixerAttributesChanged(
+                @NonNull AudioAttributes attributes,
+                @NonNull AudioDeviceInfo device,
+                @Nullable AudioMixerAttributes mixerAttributes);
+    }
+
+    /**
+     * Manage the {@link OnPreferredMixerAttributesChangedListener} listeners and the
+     * {@link PreferredMixerAttributesDispatcherStub}.
+     */
+    private final CallbackUtil.LazyListenerManager<OnPreferredMixerAttributesChangedListener>
+            mPrefMixerAttributesListenerMgr = new CallbackUtil.LazyListenerManager();
+
+    /**
+     * Adds a listener for being notified of changes to the preferred mixer attributes.
+     * @param executor the executor to execute the callback
+     * @param listener the listener to be notified of changes in the preferred mixer attributes.
+     */
+    public void addOnPreferredMixerAttributesChangedListener(
+            @NonNull @CallbackExecutor Executor executor,
+            @NonNull OnPreferredMixerAttributesChangedListener listener) {
+        Objects.requireNonNull(executor);
+        Objects.requireNonNull(listener);
+        mPrefMixerAttributesListenerMgr.addListener(executor, listener,
+                "addOnPreferredMixerAttributesChangedListener",
+                () -> new PreferredMixerAttributesDispatcherStub());
+    }
+
+    /**
+     * Removes a previously added listener of changes to the preferred mixer attributes.
+     * @param listener the listener to be notified of changes in the preferred mixer attributes,
+     *                 which were added via {@link #addOnPreferredMixerAttributesChangedListener(
+     *                 Executor, OnPreferredMixerAttributesChangedListener)}.
+     */
+    public void removeOnPreferredMixerAttributesChangedListener(
+            @NonNull OnPreferredMixerAttributesChangedListener listener) {
+        Objects.requireNonNull(listener);
+        mPrefMixerAttributesListenerMgr.removeListener(listener,
+                "removeOnPreferredMixerAttributesChangedListener");
+    }
+
+    private final class PreferredMixerAttributesDispatcherStub
+            extends IPreferredMixerAttributesDispatcher.Stub
+            implements CallbackUtil.DispatcherStub {
+
+        @Override
+        public void register(boolean register) {
+            try {
+                if (register) {
+                    getService().registerPreferredMixerAttributesDispatcher(this);
+                } else {
+                    getService().unregisterPreferredMixerAttributesDispatcher(this);
+                }
+            } catch (RemoteException e) {
+                e.rethrowFromSystemServer();
+            }
+        }
+
+        @Override
+        public void dispatchPrefMixerAttributesChanged(@NonNull AudioAttributes attr,
+                                                       int deviceId,
+                                                       @Nullable AudioMixerAttributes mixerAttr) {
+            // TODO: If the device is disconnected, we may not be able to find the device with
+            // given device id. We need a better to carry the device information via binder.
+            AudioDeviceInfo device = getDeviceForPortId(deviceId, GET_DEVICES_OUTPUTS);
+            if (device == null) {
+                Log.d(TAG, "Drop preferred mixer attributes changed as the device("
+                        + deviceId + ") is disconnected");
+                return;
+            }
+            mPrefMixerAttributesListenerMgr.callListeners(
+                    (listener) -> listener.onPreferredMixerAttributesChanged(
+                            attr, device, mixerAttr));
+        }
+    }
+
+    //====================================================================
+    // Mute await connection
+
     private final Object mMuteAwaitConnectionListenerLock = new Object();
 
     @GuardedBy("mMuteAwaitConnectionListenerLock")
diff --git a/media/java/android/media/AudioMixerAttributes.aidl b/media/java/android/media/AudioMixerAttributes.aidl
new file mode 100644
index 0000000..0d9badd
--- /dev/null
+++ b/media/java/android/media/AudioMixerAttributes.aidl
@@ -0,0 +1,18 @@
+/* Copyright 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 android.media;
+
+parcelable AudioMixerAttributes;
diff --git a/media/java/android/media/AudioMixerAttributes.java b/media/java/android/media/AudioMixerAttributes.java
new file mode 100644
index 0000000..3856da6
--- /dev/null
+++ b/media/java/android/media/AudioMixerAttributes.java
@@ -0,0 +1,194 @@
+/*
+ * 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 android.media;
+
+import android.annotation.IntDef;
+import android.annotation.NonNull;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.util.Objects;
+
+/**
+ * Class to represent the attributes of the audio mixer: its format, which represents by an
+ * {@link AudioFormat} object and mixer behavior.
+ */
+public final class AudioMixerAttributes implements Parcelable {
+
+    /**
+     * Constant indicating the audio mixer behavior will follow the default platform behavior, which
+     * is mixing all audio sources in the mixer.
+     */
+    public static final int MIXER_BEHAVIOR_DEFAULT = 0;
+
+    /**
+     * Constant indicating the audio mixer behavior is bit-perfect, which indicates there will
+     * not be mixing happen, the audio data will be sent as is down to the HAL.
+     */
+    public static final int MIXER_BEHAVIOR_BIT_PERFECT = 1;
+
+    /** @hide */
+    @IntDef(flag = false, prefix = "MIXER_BEHAVIOR_", value = {
+            MIXER_BEHAVIOR_DEFAULT,
+            MIXER_BEHAVIOR_BIT_PERFECT
+    })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface MixerBehavior {}
+
+    private final AudioFormat mFormat;
+    private final @MixerBehavior int mMixerBehavior;
+
+    /**
+     * Constructor from {@link AudioFormat} and mixer behavior
+     */
+    AudioMixerAttributes(AudioFormat format, @MixerBehavior int mixerBehavior) {
+        mFormat = format;
+        mMixerBehavior = mixerBehavior;
+    }
+
+    /**
+     * Return the format of the audio mixer. The format is an {@link AudioFormat} object, which
+     * includes encoding format, sample rate and channel mask or channel index mask.
+     * @return the format of the audio mixer.
+     */
+    @NonNull
+    public AudioFormat getFormat() {
+        return mFormat;
+    }
+
+    /**
+     * Returns the mixer behavior for this set of mixer attributes.
+     *
+     * @return the mixer behavior
+     */
+    public @MixerBehavior int getMixerBehavior() {
+        return mMixerBehavior;
+    }
+
+    /**
+     * Builder class for {@link AudioMixerAttributes} objects.
+     */
+    public static final class Builder {
+        private final AudioFormat mFormat;
+        private int mMixerBehavior = MIXER_BEHAVIOR_DEFAULT;
+
+        /**
+         * Constructs a new Builder with the defaults.
+         *
+         * @param format the {@link AudioFormat} for the audio mixer.
+         */
+        public Builder(@NonNull AudioFormat format) {
+            Objects.requireNonNull(format);
+            mFormat = format;
+        }
+
+        /**
+         * Combines all attributes that have been set and returns a new {@link AudioMixerAttributes}
+         * object.
+         * @return a new {@link AudioMixerAttributes} object
+         */
+        public @NonNull AudioMixerAttributes build() {
+            AudioMixerAttributes ama = new AudioMixerAttributes(mFormat, mMixerBehavior);
+            return ama;
+        }
+
+        /**
+         * Sets the mixer behavior for the audio mixer
+         * @param mixerBehavior must be {@link #MIXER_BEHAVIOR_DEFAULT} or
+         *                      {@link #MIXER_BEHAVIOR_BIT_PERFECT}.
+         * @return the same Builder instance.
+         */
+        public @NonNull Builder setMixerBehavior(@MixerBehavior int mixerBehavior) {
+            switch (mixerBehavior) {
+                case MIXER_BEHAVIOR_DEFAULT:
+                case MIXER_BEHAVIOR_BIT_PERFECT:
+                    mMixerBehavior = mixerBehavior;
+                    break;
+                default:
+                    throw new IllegalArgumentException("Invalid mixer behavior " + mixerBehavior);
+            }
+            return this;
+        }
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(mFormat, mMixerBehavior);
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        AudioMixerAttributes that = (AudioMixerAttributes) o;
+        return (mFormat.equals(that.mFormat)
+                && (mMixerBehavior == that.mMixerBehavior));
+    }
+
+    private String mixerBehaviorToString(@MixerBehavior int mixerBehavior) {
+        switch (mixerBehavior) {
+            case MIXER_BEHAVIOR_DEFAULT:
+                return "default";
+            case MIXER_BEHAVIOR_BIT_PERFECT:
+                return "bit-perfect";
+            default:
+                return "unknown";
+        }
+    }
+
+    @Override
+    public String toString() {
+        return new String("AudioMixerAttributes:"
+                + " format:" + mFormat.toString()
+                + " mixer behavior:" + mixerBehaviorToString(mMixerBehavior));
+    }
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public void writeToParcel(@NonNull Parcel dest, int flags) {
+        dest.writeParcelable(mFormat, flags);
+        dest.writeInt(mMixerBehavior);
+    }
+
+    private AudioMixerAttributes(@NonNull Parcel in) {
+        mFormat = in.readParcelable(AudioFormat.class.getClassLoader(), AudioFormat.class);
+        mMixerBehavior = in.readInt();
+    }
+
+    public static final @NonNull Parcelable.Creator<AudioMixerAttributes> CREATOR =
+            new Parcelable.Creator<AudioMixerAttributes>() {
+                /**
+                 * Rebuilds an AudioMixerAttributes previously stored with writeToParcel().
+                 * @param p Parcel object to read the AudioMixerAttributes from
+                 * @return a new AudioMixerAttributes created from the data in the parcel
+                 */
+                public AudioMixerAttributes createFromParcel(Parcel p) {
+                    return new AudioMixerAttributes(p);
+                }
+
+                public AudioMixerAttributes[] newArray(int size) {
+                    return new AudioMixerAttributes[size];
+                }
+            };
+}
diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java
index a48edac..3e0d657 100644
--- a/media/java/android/media/AudioSystem.java
+++ b/media/java/android/media/AudioSystem.java
@@ -2260,6 +2260,20 @@
 
     /**
      * @hide
+     * Register the sound dose callback with the audio server and returns the binder to the
+     * ISoundDose interface.
+     *
+     * @return ISoundDose interface with registered callback.
+     */
+    @Nullable
+    public static ISoundDose getSoundDoseInterface(ISoundDoseCallback callback) {
+        return ISoundDose.Stub.asInterface(nativeGetSoundDose(callback));
+    }
+
+    private static native IBinder nativeGetSoundDose(ISoundDoseCallback callback);
+
+    /**
+     * @hide
      * @param attributes audio attributes describing the playback use case
      * @param audioProfilesList the list of AudioProfiles that can be played as direct output
      * @return {@link #SUCCESS} if the list of AudioProfiles was successfully created (can be empty)
@@ -2426,4 +2440,40 @@
      * Keep in sync with core/jni/android_media_DeviceCallback.h.
      */
     final static int NATIVE_EVENT_ROUTING_CHANGE = 1000;
+
+    /**
+     * @hide
+     * Query the mixer attributes that can be set as preferred mixer attributes for the given
+     * device.
+     */
+    public static native int getSupportedMixerAttributes(
+            int deviceId, @NonNull List<AudioMixerAttributes> mixerAttrs);
+
+    /**
+     * @hide
+     * Set preferred mixer attributes for a given device when playing particular
+     * audio attributes.
+     */
+    public static native int setPreferredMixerAttributes(
+            @NonNull AudioAttributes attributes,
+            int portId,
+            int uid,
+            @NonNull AudioMixerAttributes mixerAttributes);
+
+    /**
+     * @hide
+     * Get preferred mixer attributes that is previously set via
+     * {link #setPreferredMixerAttributes}.
+     */
+    public static native int getPreferredMixerAttributes(
+            @NonNull AudioAttributes attributes, int portId,
+            List<AudioMixerAttributes> mixerAttributesList);
+
+    /**
+     * @hide
+     * Clear preferred mixer attributes that is previously set via
+     * {@link #setPreferredMixerAttributes}
+     */
+    public static native int clearPreferredMixerAttributes(
+            @NonNull AudioAttributes attributes, int portId, int uid);
 }
diff --git a/media/java/android/media/IAudioService.aidl b/media/java/android/media/IAudioService.aidl
index ee453a4..5502db2 100644
--- a/media/java/android/media/IAudioService.aidl
+++ b/media/java/android/media/IAudioService.aidl
@@ -23,6 +23,7 @@
 import android.media.AudioFormat;
 import android.media.AudioFocusInfo;
 import android.media.AudioHalVersionInfo;
+import android.media.AudioMixerAttributes;
 import android.media.AudioPlaybackConfiguration;
 import android.media.AudioRecordingConfiguration;
 import android.media.AudioRoutesInfo;
@@ -37,6 +38,7 @@
 import android.media.IDeviceVolumeBehaviorDispatcher;
 import android.media.IMuteAwaitConnectionCallback;
 import android.media.IPlaybackConfigDispatcher;
+import android.media.IPreferredMixerAttributesDispatcher;
 import android.media.IRecordingConfigDispatcher;
 import android.media.IRingtonePlayer;
 import android.media.IStrategyPreferredDevicesDispatcher;
@@ -573,4 +575,14 @@
             boolean handlesvolumeAdjustment);
 
     AudioHalVersionInfo getHalVersion();
+
+    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_SETTINGS)")
+    int setPreferredMixerAttributes(
+            in AudioAttributes aa, int portId, in AudioMixerAttributes mixerAttributes);
+    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_SETTINGS)")
+    int clearPreferredMixerAttributes(in AudioAttributes aa, int portId);
+    void registerPreferredMixerAttributesDispatcher(
+            IPreferredMixerAttributesDispatcher dispatcher);
+    oneway void unregisterPreferredMixerAttributesDispatcher(
+            IPreferredMixerAttributesDispatcher dispatcher);
 }
diff --git a/media/java/android/media/IPreferredMixerAttributesDispatcher.aidl b/media/java/android/media/IPreferredMixerAttributesDispatcher.aidl
new file mode 100644
index 0000000..9138fa7
--- /dev/null
+++ b/media/java/android/media/IPreferredMixerAttributesDispatcher.aidl
@@ -0,0 +1,34 @@
+/*
+ * 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 android.media;
+
+import android.media.AudioAttributes;
+import android.media.AudioMixerAttributes;
+
+/**
+ * AIDL for AudioService to signal preferred mixer attributes update.
+ *
+ * {@hide}
+ */
+oneway interface IPreferredMixerAttributesDispatcher {
+
+    void dispatchPrefMixerAttributesChanged(
+            in AudioAttributes attributes,
+            int deviceId,
+            in @nullable AudioMixerAttributes mixerAttributes);
+
+}
diff --git a/media/java/android/media/MediaMetrics.java b/media/java/android/media/MediaMetrics.java
index a4a8cc4..5509782 100644
--- a/media/java/android/media/MediaMetrics.java
+++ b/media/java/android/media/MediaMetrics.java
@@ -49,10 +49,11 @@
         public static final String AUDIO_FOCUS = AUDIO + SEPARATOR + "focus";
         public static final String AUDIO_FORCE_USE = AUDIO + SEPARATOR + "forceUse";
         public static final String AUDIO_MIC = AUDIO + SEPARATOR + "mic";
+        public static final String AUDIO_MIDI = AUDIO + SEPARATOR + "midi";
+        public static final String AUDIO_MODE = AUDIO + SEPARATOR + "mode";
         public static final String AUDIO_SERVICE = AUDIO + SEPARATOR + "service";
         public static final String AUDIO_VOLUME = AUDIO + SEPARATOR + "volume";
         public static final String AUDIO_VOLUME_EVENT = AUDIO_VOLUME + SEPARATOR + "event";
-        public static final String AUDIO_MODE = AUDIO + SEPARATOR + "mode";
         public static final String METRICS_MANAGER = "metrics" + SEPARATOR + "manager";
     }
 
@@ -90,15 +91,27 @@
         // The client name
         public static final Key<String> CLIENT_NAME = createKey("clientName", String.class);
 
+        public static final Key<Integer> CLOSED_COUNT =
+                createKey("closedCount", Integer.class); // MIDI
+
         // The device type
         public static final Key<Integer> DELAY_MS = createKey("delayMs", Integer.class);
 
         // The device type
         public static final Key<String> DEVICE = createKey("device", String.class);
 
+        // Whether the device is disconnected. This is either "true" or "false"
+        public static final Key<String> DEVICE_DISCONNECTED =
+                createKey("deviceDisconnected", String.class); // MIDI
+
+        // The ID of the device
+        public static final Key<Integer> DEVICE_ID =
+                createKey("deviceId", Integer.class); // MIDI
+
         // For volume changes, up or down
         public static final Key<String> DIRECTION = createKey("direction", String.class);
-
+        public static final Key<Long> DURATION_NS =
+                createKey("durationNs", Long.class); // MIDI
         // A reason for early return or error
         public static final Key<String> EARLY_RETURN =
                 createKey("earlyReturn", String.class);
@@ -128,11 +141,17 @@
         // Generally string "true" or "false"
         public static final Key<String> HAS_HEAD_TRACKER =
                 createKey("hasHeadTracker", String.class);     // spatializer
+        public static final Key<Integer> HARDWARE_TYPE =
+                createKey("hardwareType", Integer.class); // MIDI
         // Generally string "true" or "false"
         public static final Key<String> HEAD_TRACKER_ENABLED =
                 createKey("headTrackerEnabled", String.class); // spatializer
 
         public static final Key<Integer> INDEX = createKey("index", Integer.class); // volume
+        public static final Key<Integer> INPUT_PORT_COUNT =
+                createKey("inputPortCount", Integer.class); // MIDI
+        // Either "true" or "false"
+        public static final Key<String> IS_SHARED = createKey("isShared", String.class); // MIDI
         public static final Key<String> LOG_SESSION_ID = createKey("logSessionId", String.class);
         public static final Key<Integer> MAX_INDEX = createKey("maxIndex", Integer.class); // vol
         public static final Key<Integer> MIN_INDEX = createKey("minIndex", Integer.class); // vol
@@ -149,6 +168,11 @@
         public static final Key<Integer> OBSERVERS =
                 createKey("observers", Integer.class);
 
+        public static final Key<Integer> OPENED_COUNT =
+                createKey("openedCount", Integer.class); // MIDI
+        public static final Key<Integer> OUTPUT_PORT_COUNT =
+                createKey("outputPortCount", Integer.class); // MIDI
+
         public static final Key<String> REQUEST =
                 createKey("request", String.class);
 
@@ -163,6 +187,18 @@
         public static final Key<String> STATE = createKey("state", String.class);
         public static final Key<Integer> STATUS = createKey("status", Integer.class);
         public static final Key<String> STREAM_TYPE = createKey("streamType", String.class);
+
+        // The following MIDI string is generally either "true" or "false"
+        public static final Key<String> SUPPORTS_MIDI_UMP =
+                createKey("supportsMidiUmp", String.class); // Universal MIDI Packets
+
+        public static final Key<Integer> TOTAL_INPUT_BYTES =
+                createKey("totalInputBytes", Integer.class); // MIDI
+        public static final Key<Integer> TOTAL_OUTPUT_BYTES =
+                createKey("totalOutputBytes", Integer.class); // MIDI
+
+        // The following MIDI string is generally either "true" or "false"
+        public static final Key<String> USING_ALSA = createKey("usingAlsa", String.class);
     }
 
     /**
diff --git a/media/java/android/media/MediaRouter2Manager.java b/media/java/android/media/MediaRouter2Manager.java
index 7786f61..aea6bcb 100644
--- a/media/java/android/media/MediaRouter2Manager.java
+++ b/media/java/android/media/MediaRouter2Manager.java
@@ -76,13 +76,7 @@
     private static MediaRouter2Manager sInstance;
 
     private final MediaSessionManager mMediaSessionManager;
-
-    final String mPackageName;
-
-    private final Context mContext;
-
     private final Client mClient;
-
     private final IMediaRouterService mMediaRouterService;
     private final AtomicInteger mScanRequestCount = new AtomicInteger(/* initialValue= */ 0);
     final Handler mHandler;
@@ -120,16 +114,14 @@
     }
 
     private MediaRouter2Manager(Context context) {
-        mContext = context.getApplicationContext();
         mMediaRouterService = IMediaRouterService.Stub.asInterface(
                 ServiceManager.getService(Context.MEDIA_ROUTER_SERVICE));
         mMediaSessionManager = (MediaSessionManager) context
                 .getSystemService(Context.MEDIA_SESSION_SERVICE);
-        mPackageName = mContext.getPackageName();
         mHandler = new Handler(context.getMainLooper());
         mClient = new Client();
         try {
-            mMediaRouterService.registerManager(mClient, mPackageName);
+            mMediaRouterService.registerManager(mClient, context.getPackageName());
         } catch (RemoteException ex) {
             throw ex.rethrowFromSystemServer();
         }
diff --git a/media/java/android/media/RouteListingPreference.java b/media/java/android/media/RouteListingPreference.java
index 62f233e..84e6d3c 100644
--- a/media/java/android/media/RouteListingPreference.java
+++ b/media/java/android/media/RouteListingPreference.java
@@ -142,7 +142,12 @@
         @Retention(RetentionPolicy.SOURCE)
         @IntDef(
                 prefix = {"DISABLE_REASON_"},
-                value = {DISABLE_REASON_NONE, DISABLE_REASON_SUBSCRIPTION_REQUIRED})
+                value = {
+                    DISABLE_REASON_NONE,
+                    DISABLE_REASON_SUBSCRIPTION_REQUIRED,
+                    DISABLE_REASON_DOWNLOADED_CONTENT,
+                    DISABLE_REASON_AD
+                })
         public @interface DisableReason {}
 
         /** The corresponding route is available for routing. */
@@ -152,6 +157,13 @@
          * routing.
          */
         public static final int DISABLE_REASON_SUBSCRIPTION_REQUIRED = 1;
+        /**
+         * The corresponding route is not available because downloaded content cannot be routed to
+         * it.
+         */
+        public static final int DISABLE_REASON_DOWNLOADED_CONTENT = 2;
+        /** The corresponding route is not available because an ad is in progress. */
+        public static final int DISABLE_REASON_AD = 3;
 
         @NonNull
         public static final Creator<Item> CREATOR =
@@ -216,6 +228,8 @@
          *
          * @see #DISABLE_REASON_NONE
          * @see #DISABLE_REASON_SUBSCRIPTION_REQUIRED
+         * @see #DISABLE_REASON_DOWNLOADED_CONTENT
+         * @see #DISABLE_REASON_AD
          */
         @DisableReason
         public int getDisableReason() {
diff --git a/media/java/android/media/audiopolicy/AudioVolumeGroup.java b/media/java/android/media/audiopolicy/AudioVolumeGroup.java
index d58111d..1a9ebbc 100644
--- a/media/java/android/media/audiopolicy/AudioVolumeGroup.java
+++ b/media/java/android/media/audiopolicy/AudioVolumeGroup.java
@@ -51,7 +51,7 @@
     /**
      * human-readable name of this volume group.
      */
-    private final String mName;
+    private final @NonNull String mName;
 
     private final AudioAttributes[] mAudioAttributes;
     private int[] mLegacyStreamTypes;
@@ -113,7 +113,7 @@
 
         AudioVolumeGroup thatAvg = (AudioVolumeGroup) o;
 
-        return mName == thatAvg.mName && mId == thatAvg.mId
+        return mName.equals(thatAvg.mName) && mId == thatAvg.mId
                 && Arrays.equals(mAudioAttributes, thatAvg.mAudioAttributes);
     }
 
diff --git a/media/java/android/media/midi/IMidiManager.aidl b/media/java/android/media/midi/IMidiManager.aidl
index b03f785..bd678a5 100644
--- a/media/java/android/media/midi/IMidiManager.aidl
+++ b/media/java/android/media/midi/IMidiManager.aidl
@@ -60,4 +60,7 @@
     // used by MIDI devices to report their status
     // the token is used by MidiService for death notification
     void setDeviceStatus(in IMidiDeviceServer server, in MidiDeviceStatus status);
+
+    // Updates the number of bytes sent and received
+    void updateTotalBytes(in IMidiDeviceServer server, int inputBytes, int outputBytes);
 }
diff --git a/media/java/android/media/midi/MidiDeviceServer.java b/media/java/android/media/midi/MidiDeviceServer.java
index d5916b9..fc33cef 100644
--- a/media/java/android/media/midi/MidiDeviceServer.java
+++ b/media/java/android/media/midi/MidiDeviceServer.java
@@ -36,6 +36,7 @@
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * Internal class used for providing an implementation for a MIDI device.
@@ -79,6 +80,9 @@
     private final HashMap<MidiInputPort, PortClient> mInputPortClients =
             new HashMap<MidiInputPort, PortClient>();
 
+    private AtomicInteger mTotalInputBytes = new AtomicInteger();
+    private AtomicInteger mTotalOutputBytes = new AtomicInteger();
+
     public interface Callback {
         /**
          * Called to notify when an our device status has changed
@@ -133,6 +137,8 @@
                 int portNumber = mOutputPort.getPortNumber();
                 mInputPortOutputPorts[portNumber] = null;
                 mInputPortOpen[portNumber] = false;
+                mTotalOutputBytes.addAndGet(mOutputPort.pullTotalBytesCount());
+                updateTotalBytes();
                 updateDeviceStatus();
             }
             IoUtils.closeQuietly(mOutputPort);
@@ -156,6 +162,8 @@
                 dispatcher.getSender().disconnect(mInputPort);
                 int openCount = dispatcher.getReceiverCount();
                 mOutputPortOpenCount[portNumber] = openCount;
+                mTotalInputBytes.addAndGet(mInputPort.pullTotalBytesCount());
+                updateTotalBytes();
                 updateDeviceStatus();
            }
 
@@ -405,18 +413,20 @@
         synchronized (mGuard) {
             if (mIsClosed) return;
             mGuard.close();
-
             for (int i = 0; i < mInputPortCount; i++) {
                 MidiOutputPort outputPort = mInputPortOutputPorts[i];
                 if (outputPort != null) {
+                    mTotalOutputBytes.addAndGet(outputPort.pullTotalBytesCount());
                     IoUtils.closeQuietly(outputPort);
                     mInputPortOutputPorts[i] = null;
                 }
             }
             for (MidiInputPort inputPort : mInputPorts) {
+                mTotalInputBytes.addAndGet(inputPort.pullTotalBytesCount());
                 IoUtils.closeQuietly(inputPort);
             }
             mInputPorts.clear();
+            updateTotalBytes();
             try {
                 mMidiManager.unregisterDeviceServer(mServer);
             } catch (RemoteException e) {
@@ -449,4 +459,12 @@
         System.arraycopy(mOutputPortDispatchers, 0, receivers, 0, mOutputPortCount);
         return receivers;
     }
+
+    private void updateTotalBytes() {
+        try {
+            mMidiManager.updateTotalBytes(mServer, mTotalInputBytes.get(), mTotalOutputBytes.get());
+        } catch (RemoteException e) {
+            Log.e(TAG, "RemoteException in updateTotalBytes");
+        }
+    }
 }
diff --git a/media/java/android/media/midi/MidiInputPort.java b/media/java/android/media/midi/MidiInputPort.java
index a300886..fe42b58 100644
--- a/media/java/android/media/midi/MidiInputPort.java
+++ b/media/java/android/media/midi/MidiInputPort.java
@@ -28,6 +28,7 @@
 import java.io.FileDescriptor;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * This class is used for sending data to a port on a MIDI device
@@ -43,6 +44,7 @@
 
     private final CloseGuard mGuard = CloseGuard.get();
     private boolean mIsClosed;
+    private AtomicInteger mTotalBytes = new AtomicInteger();
 
     // buffer to use for sending data out our output stream
     private final byte[] mBuffer = new byte[MidiPortImpl.MAX_PACKET_SIZE];
@@ -87,6 +89,7 @@
             }
             int length = MidiPortImpl.packData(msg, offset, count, timestamp, mBuffer);
             mOutputStream.write(mBuffer, 0, length);
+            mTotalBytes.addAndGet(length);
         }
     }
 
@@ -170,4 +173,12 @@
             super.finalize();
         }
     }
+
+    /**
+     * Pulls total number of bytes and sets to zero. This allows multiple callers.
+     * @hide
+     */
+    public int pullTotalBytesCount() {
+        return mTotalBytes.getAndSet(0);
+    }
 }
diff --git a/media/java/android/media/midi/MidiOutputPort.java b/media/java/android/media/midi/MidiOutputPort.java
index 5411e66..d948477 100644
--- a/media/java/android/media/midi/MidiOutputPort.java
+++ b/media/java/android/media/midi/MidiOutputPort.java
@@ -31,6 +31,7 @@
 import java.io.FileDescriptor;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * This class is used for receiving data from a port on a MIDI device
@@ -46,6 +47,7 @@
 
     private final CloseGuard mGuard = CloseGuard.get();
     private boolean mIsClosed;
+    private AtomicInteger mTotalBytes = new AtomicInteger();
 
     // This thread reads MIDI events from a socket and distributes them to the list of
     // MidiReceivers attached to this device.
@@ -83,6 +85,7 @@
                             Log.e(TAG, "Unknown packet type " + packetType);
                             break;
                     }
+                    mTotalBytes.addAndGet(count);
                 } // while (true)
             } catch (IOException e) {
                 // FIXME report I/O failure?
@@ -163,4 +166,12 @@
             super.finalize();
         }
     }
+
+    /**
+     * Pulls total number of bytes and sets to zero. This allows multiple callers.
+     * @hide
+     */
+    public int pullTotalBytesCount() {
+        return mTotalBytes.getAndSet(0);
+    }
 }
diff --git a/media/java/android/media/projection/IMediaProjectionCallback.aidl b/media/java/android/media/projection/IMediaProjectionCallback.aidl
index f3743d1..2c8de2e 100644
--- a/media/java/android/media/projection/IMediaProjectionCallback.aidl
+++ b/media/java/android/media/projection/IMediaProjectionCallback.aidl
@@ -19,4 +19,5 @@
 /** {@hide} */
 oneway interface IMediaProjectionCallback {
     void onStop();
+    void onCapturedContentResize(int width, int height);
 }
diff --git a/media/java/android/media/projection/IMediaProjectionManager.aidl b/media/java/android/media/projection/IMediaProjectionManager.aidl
index 1d58a40..a63d02b 100644
--- a/media/java/android/media/projection/IMediaProjectionManager.aidl
+++ b/media/java/android/media/projection/IMediaProjectionManager.aidl
@@ -27,12 +27,32 @@
 interface IMediaProjectionManager {
     @UnsupportedAppUsage
     boolean hasProjectionPermission(int uid, String packageName);
+
+    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
+            + ".permission.MANAGE_MEDIA_PROJECTION)")
     IMediaProjection createProjection(int uid, String packageName, int type,
             boolean permanentGrant);
+
     boolean isValidMediaProjection(IMediaProjection projection);
+
+    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
+            + ".permission.MANAGE_MEDIA_PROJECTION)")
     MediaProjectionInfo getActiveProjectionInfo();
+
+    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
+            + ".permission.MANAGE_MEDIA_PROJECTION)")
     void stopActiveProjection();
+
+    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
+            + ".permission.MANAGE_MEDIA_PROJECTION)")
+    void notifyActiveProjectionCapturedContentResized(int width, int height);
+
+    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
+            + ".permission.MANAGE_MEDIA_PROJECTION)")
     void addCallback(IMediaProjectionWatcherCallback callback);
+
+    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
+            + ".permission.MANAGE_MEDIA_PROJECTION)")
     void removeCallback(IMediaProjectionWatcherCallback callback);
 
     /**
diff --git a/media/java/android/media/projection/MediaProjection.java b/media/java/android/media/projection/MediaProjection.java
index ae44fc5..3dfff1f 100644
--- a/media/java/android/media/projection/MediaProjection.java
+++ b/media/java/android/media/projection/MediaProjection.java
@@ -234,7 +234,7 @@
     /**
      * Callbacks for the projection session.
      */
-    public static abstract class Callback {
+    public abstract static class Callback {
         /**
          * Called when the MediaProjection session is no longer valid.
          * <p>
@@ -243,6 +243,46 @@
          * </p>
          */
         public void onStop() { }
+
+        /**
+         * Indicates the width and height of the captured region in pixels. Called immediately after
+         * capture begins to provide the app with accurate sizing for the stream. Also called
+         * when the region captured in this MediaProjection session is resized.
+         * <p>
+         * The given width and height, in pixels, corresponds to the same width and height that
+         * would be returned from {@link android.view.WindowMetrics#getBounds()}
+         * </p>
+         * <p>
+         * Without the application resizing the {@link VirtualDisplay} (returned from
+         * {@code MediaProjection#createVirtualDisplay}) and output {@link Surface} (provided
+         * to {@code MediaProjection#createVirtualDisplay}), the captured stream will have
+         * letterboxing (black bars) around the recorded content to make up for the
+         * difference in aspect ratio.
+         * </p>
+         * <p>
+         * The application can prevent the letterboxing by overriding this method, and
+         * updating the size of both the {@link VirtualDisplay} and output {@link Surface}:
+         * </p>
+         *
+         * <pre>
+         * &#x40;Override
+         * public String onCapturedContentResize(int width, int height) {
+         *     // VirtualDisplay instance from MediaProjection#createVirtualDisplay
+         *     virtualDisplay.resize(width, height, dpi);
+         *
+         *     // Create a new Surface with the updated size (depending on the application's use
+         *     // case, this may be through different APIs - see Surface documentation for
+         *     // options).
+         *     int texName; // the OpenGL texture object name
+         *     SurfaceTexture surfaceTexture = new SurfaceTexture(texName);
+         *     surfaceTexture.setDefaultBufferSize(width, height);
+         *     Surface surface = new Surface(surfaceTexture);
+         *
+         *     // Ensure the VirtualDisplay has the updated Surface to send the capture to.
+         *     virtualDisplay.setSurface(surface);
+         * }</pre>
+         */
+        public void onCapturedContentResize(int width, int height) { }
     }
 
     private final class MediaProjectionCallback extends IMediaProjectionCallback.Stub {
@@ -252,6 +292,13 @@
                 cbr.onStop();
             }
         }
+
+        @Override
+        public void onCapturedContentResize(int width, int height) {
+            for (CallbackRecord cbr : mCallbacks.values()) {
+                cbr.onCapturedContentResize(width, height);
+            }
+        }
     }
 
     private final static class CallbackRecord {
@@ -271,5 +318,9 @@
                 }
             });
         }
+
+        public void onCapturedContentResize(int width, int height) {
+            mHandler.post(() -> mCallback.onCapturedContentResize(width, height));
+        }
     }
 }
diff --git a/services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt b/media/java/android/media/projection/MediaProjectionConfig.aidl
similarity index 71%
copy from services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt
copy to media/java/android/media/projection/MediaProjectionConfig.aidl
index 528680e7..f78385f 100644
--- a/services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt
+++ b/media/java/android/media/projection/MediaProjectionConfig.aidl
@@ -14,11 +14,6 @@
  * limitations under the License.
  */
 
-package com.android.server.permission.access.external
+package android.media.projection;
 
-class RoSystemProperties {
-    companion object {
-        const val CONTROL_PRIVAPP_PERMISSIONS_DISABLE = false
-        const val CONTROL_PRIVAPP_PERMISSIONS_ENFORCE = false
-    }
-}
+parcelable MediaProjectionConfig;
diff --git a/media/java/android/media/projection/MediaProjectionConfig.java b/media/java/android/media/projection/MediaProjectionConfig.java
new file mode 100644
index 0000000..29afaa6
--- /dev/null
+++ b/media/java/android/media/projection/MediaProjectionConfig.java
@@ -0,0 +1,293 @@
+/*
+ * 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 android.media.projection;
+
+import static android.view.Display.DEFAULT_DISPLAY;
+
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+
+import android.annotation.IntDef;
+import android.annotation.IntRange;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.os.Parcelable;
+
+import com.android.internal.util.AnnotationValidations;
+import com.android.internal.util.DataClass;
+
+import java.lang.annotation.Retention;
+
+/**
+ * Configure the {@link MediaProjection} session requested from
+ * {@link MediaProjectionManager#createScreenCaptureIntent(MediaProjectionConfig)}.
+ */
+@DataClass(
+        genEqualsHashCode = true,
+        genAidl = true,
+        genSetters = false,
+        genConstructor = false,
+        genBuilder = false,
+        genToString = false,
+        genHiddenConstDefs = true,
+        genHiddenGetters = true,
+        genConstDefs = false
+)
+public final class MediaProjectionConfig implements Parcelable {
+
+    /**
+     * The user, rather than the host app, determines which region of the display to capture.
+     * @hide
+     */
+    public static final int CAPTURE_REGION_USER_CHOICE = 0;
+
+    /**
+     * The host app specifies a particular display to capture.
+     * @hide
+     */
+    public static final int CAPTURE_REGION_FIXED_DISPLAY = 1;
+
+    /** @hide */
+    @IntDef(prefix = "CAPTURE_REGION_", value = {
+            CAPTURE_REGION_USER_CHOICE,
+            CAPTURE_REGION_FIXED_DISPLAY
+    })
+    @Retention(SOURCE)
+    public @interface CaptureRegion {
+    }
+
+    /**
+     * The particular display to capture. Only used when {@link #getRegionToCapture()} is
+     * {@link #CAPTURE_REGION_FIXED_DISPLAY}; ignored otherwise.
+     *
+     * Only supports values of {@link android.view.Display#DEFAULT_DISPLAY}.
+     */
+    @IntRange(from = DEFAULT_DISPLAY, to = DEFAULT_DISPLAY)
+    private int mDisplayToCapture;
+
+    /**
+     * The region to capture. Defaults to the user's choice.
+     */
+    @CaptureRegion
+    private int mRegionToCapture = CAPTURE_REGION_USER_CHOICE;
+
+    /**
+     * Default instance, with region set to the user's choice.
+     */
+    private MediaProjectionConfig() {
+    }
+
+    /**
+     * Customized instance, with region set to the provided value.
+     */
+    private MediaProjectionConfig(@CaptureRegion int captureRegion) {
+        mRegionToCapture = captureRegion;
+    }
+
+    /**
+     * Returns an instance which restricts the user to capturing a particular display.
+     *
+     * @param displayId The id of the display to capture. Only supports values of
+     *                  {@link android.view.Display#DEFAULT_DISPLAY}.
+     * @throws IllegalArgumentException If the given {@code displayId} is outside the range of
+     * supported values.
+     */
+    @NonNull
+    public static MediaProjectionConfig createConfigForDisplay(
+            @IntRange(from = DEFAULT_DISPLAY, to = DEFAULT_DISPLAY) int displayId) {
+        if (displayId != DEFAULT_DISPLAY) {
+            throw new IllegalArgumentException(
+                    "A config for capturing the non-default display is not supported; requested "
+                            + "display id "
+                            + displayId);
+        }
+        MediaProjectionConfig config = new MediaProjectionConfig(CAPTURE_REGION_FIXED_DISPLAY);
+        config.mDisplayToCapture = displayId;
+        return config;
+    }
+
+    /**
+     * Returns an instance which allows the user to decide which region is captured. The consent
+     * dialog presents the user with all possible options. If the user selects display capture,
+     * then only the {@link android.view.Display#DEFAULT_DISPLAY} is supported.
+     *
+     * <p>
+     * When passed in to
+     * {@link MediaProjectionManager#createScreenCaptureIntent(MediaProjectionConfig)}, the consent
+     * dialog shown to the user will be the same as if just
+     * {@link MediaProjectionManager#createScreenCaptureIntent()} was invoked.
+     * </p>
+     */
+    @NonNull
+    public static MediaProjectionConfig createConfigForUserChoice() {
+        return new MediaProjectionConfig(CAPTURE_REGION_USER_CHOICE);
+    }
+
+    /**
+     * Returns string representation of the captured region.
+     */
+    @NonNull
+    private static String captureRegionToString(int value) {
+        switch (value) {
+            case CAPTURE_REGION_USER_CHOICE:
+                return "CAPTURE_REGION_USERS_CHOICE";
+            case CAPTURE_REGION_FIXED_DISPLAY:
+                return "CAPTURE_REGION_GIVEN_DISPLAY";
+            default:
+                return Integer.toHexString(value);
+        }
+    }
+
+    @Override
+    public String toString() {
+        return "MediaProjectionConfig { "
+                + "displayToCapture = " + mDisplayToCapture + ", "
+                + "regionToCapture = " + captureRegionToString(mRegionToCapture)
+                + " }";
+    }
+
+
+
+
+
+    // Code below generated by codegen v1.0.23.
+    //
+    // DO NOT MODIFY!
+    // CHECKSTYLE:OFF Generated code
+    //
+    // To regenerate run:
+    // $ codegen $ANDROID_BUILD_TOP/frameworks/base/media/java/android/media/projection/MediaProjectionConfig.java
+    //
+    // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
+    //   Settings > Editor > Code Style > Formatter Control
+    //@formatter:off
+
+
+    /**
+     * The particular display to capture. Only used when {@link #getRegionToCapture()} is
+     * {@link #CAPTURE_REGION_FIXED_DISPLAY}; ignored otherwise.
+     *
+     * Only supports values of {@link android.view.Display#DEFAULT_DISPLAY}.
+     *
+     * @hide
+     */
+    @DataClass.Generated.Member
+    public @IntRange(from = DEFAULT_DISPLAY, to = DEFAULT_DISPLAY) int getDisplayToCapture() {
+        return mDisplayToCapture;
+    }
+
+    /**
+     * The region to capture. Defaults to the user's choice.
+     *
+     * @hide
+     */
+    @DataClass.Generated.Member
+    public @CaptureRegion int getRegionToCapture() {
+        return mRegionToCapture;
+    }
+
+    @Override
+    @DataClass.Generated.Member
+    public boolean equals(@Nullable Object o) {
+        // You can override field equality logic by defining either of the methods like:
+        // boolean fieldNameEquals(MediaProjectionConfig other) { ... }
+        // boolean fieldNameEquals(FieldType otherValue) { ... }
+
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        @SuppressWarnings("unchecked")
+        MediaProjectionConfig that = (MediaProjectionConfig) o;
+        //noinspection PointlessBooleanExpression
+        return true
+                && mDisplayToCapture == that.mDisplayToCapture
+                && mRegionToCapture == that.mRegionToCapture;
+    }
+
+    @Override
+    @DataClass.Generated.Member
+    public int hashCode() {
+        // You can override field hashCode logic by defining methods like:
+        // int fieldNameHashCode() { ... }
+
+        int _hash = 1;
+        _hash = 31 * _hash + mDisplayToCapture;
+        _hash = 31 * _hash + mRegionToCapture;
+        return _hash;
+    }
+
+    @Override
+    @DataClass.Generated.Member
+    public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
+        // You can override field parcelling by defining methods like:
+        // void parcelFieldName(Parcel dest, int flags) { ... }
+
+        dest.writeInt(mDisplayToCapture);
+        dest.writeInt(mRegionToCapture);
+    }
+
+    @Override
+    @DataClass.Generated.Member
+    public int describeContents() { return 0; }
+
+    /** @hide */
+    @SuppressWarnings({"unchecked", "RedundantCast"})
+    @DataClass.Generated.Member
+    /* package-private */ MediaProjectionConfig(@NonNull android.os.Parcel in) {
+        // You can override field unparcelling by defining methods like:
+        // static FieldType unparcelFieldName(Parcel in) { ... }
+
+        int displayToCapture = in.readInt();
+        int regionToCapture = in.readInt();
+
+        this.mDisplayToCapture = displayToCapture;
+        AnnotationValidations.validate(
+                IntRange.class, null, mDisplayToCapture,
+                "from", DEFAULT_DISPLAY,
+                "to", DEFAULT_DISPLAY);
+        this.mRegionToCapture = regionToCapture;
+        AnnotationValidations.validate(
+                CaptureRegion.class, null, mRegionToCapture);
+
+        // onConstructed(); // You can define this method to get a callback
+    }
+
+    @DataClass.Generated.Member
+    public static final @NonNull Parcelable.Creator<MediaProjectionConfig> CREATOR
+            = new Parcelable.Creator<MediaProjectionConfig>() {
+        @Override
+        public MediaProjectionConfig[] newArray(int size) {
+            return new MediaProjectionConfig[size];
+        }
+
+        @Override
+        public MediaProjectionConfig createFromParcel(@NonNull android.os.Parcel in) {
+            return new MediaProjectionConfig(in);
+        }
+    };
+
+    @DataClass.Generated(
+            time = 1671030124845L,
+            codegenVersion = "1.0.23",
+            sourceFile = "frameworks/base/media/java/android/media/projection/MediaProjectionConfig.java",
+            inputSignatures = "public static final  int CAPTURE_REGION_USER_CHOICE\npublic static final  int CAPTURE_REGION_FIXED_DISPLAY\nprivate @android.annotation.IntRange int mDisplayToCapture\nprivate @android.media.projection.MediaProjectionConfig.CaptureRegion int mRegionToCapture\npublic static @android.annotation.NonNull android.media.projection.MediaProjectionConfig createConfigForDisplay(int)\npublic static @android.annotation.NonNull android.media.projection.MediaProjectionConfig createConfigForUserChoice()\nprivate static @android.annotation.NonNull java.lang.String captureRegionToString(int)\npublic @java.lang.Override java.lang.String toString()\nclass MediaProjectionConfig extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genAidl=true, genSetters=false, genConstructor=false, genBuilder=false, genToString=false, genHiddenConstDefs=true, genHiddenGetters=true, genConstDefs=false)")
+    @Deprecated
+    private void __metadata() {}
+
+
+    //@formatter:on
+    // End of generated code
+
+}
diff --git a/media/java/android/media/projection/MediaProjectionManager.java b/media/java/android/media/projection/MediaProjectionManager.java
index b3bd980..a4215e68 100644
--- a/media/java/android/media/projection/MediaProjectionManager.java
+++ b/media/java/android/media/projection/MediaProjectionManager.java
@@ -38,6 +38,13 @@
 @SystemService(Context.MEDIA_PROJECTION_SERVICE)
 public final class MediaProjectionManager {
     private static final String TAG = "MediaProjectionManager";
+
+    /**
+     * Intent extra to customize the permission dialog based on the host app's preferences.
+     * @hide
+     */
+    public static final String EXTRA_MEDIA_PROJECTION_CONFIG =
+            "android.media.projection.extra.EXTRA_MEDIA_PROJECTION_CONFIG";
     /** @hide */
     public static final String EXTRA_APP_TOKEN = "android.media.projection.extra.EXTRA_APP_TOKEN";
     /** @hide */
@@ -64,11 +71,13 @@
     }
 
     /**
-     * Returns an Intent that <b>must</b> be passed to startActivityForResult()
-     * in order to start screen capture. The activity will prompt
-     * the user whether to allow screen capture.  The result of this
-     * activity should be passed to getMediaProjection.
+     * Returns an {@link Intent} that <b>must</b> be passed to
+     * {@link Activity#startActivityForResult(Intent, int)} (or similar) in order to start screen
+     * capture. The activity will prompt the user whether to allow screen capture.  The result of
+     * this activity (received by overriding {@link Activity#onActivityResult(int, int, Intent)})
+     * should be passed to {@link #getMediaProjection(int, Intent)}.
      */
+    @NonNull
     public Intent createScreenCaptureIntent() {
         Intent i = new Intent();
         final ComponentName mediaProjectionPermissionDialogComponent =
@@ -80,6 +89,49 @@
     }
 
     /**
+     * Returns an {@link Intent} that <b>must</b> be passed to
+     * {@link Activity#startActivityForResult(Intent, int)} (or similar) in order to start screen
+     * capture. Customizes the activity and resulting {@link MediaProjection} session based up
+     * the provided {@code config}. The activity will prompt the user whether to allow screen
+     * capture. The result of this activity (received by overriding
+     * {@link Activity#onActivityResult(int, int, Intent)}) should be passed to
+     * {@link #getMediaProjection(int, Intent)}.
+     *
+     * <p>
+     * If {@link MediaProjectionConfig} was created from:
+     * <li>
+     *     <ul>
+     *         {@link MediaProjectionConfig#createConfigForDisplay(int)}, then creates an
+     *         {@link Intent} for capturing this particular display. The activity limits the user's
+     *         choice to just the display specified.
+     *     </ul>
+     *     <ul>
+     *         {@link MediaProjectionConfig#createConfigForUserChoice()}, then creates an
+     *         {@link Intent} for deferring which region to capture to the user. This gives the
+     *         user the same behaviour as calling {@link #createScreenCaptureIntent()}. The
+     *         activity gives the user the choice between
+     *         {@link android.view.Display#DEFAULT_DISPLAY}, or a different region.
+     *     </ul>
+     * </li>
+     *
+     * @param config Customization for the {@link MediaProjection} that this {@link Intent} requests
+     *               the user's consent for.
+     * @return An {@link Intent} requesting the user's consent, specialized based upon the given
+     * configuration.
+     */
+    @NonNull
+    public Intent createScreenCaptureIntent(@NonNull MediaProjectionConfig config) {
+        Intent i = new Intent();
+        final ComponentName mediaProjectionPermissionDialogComponent =
+                ComponentName.unflattenFromString(mContext.getResources()
+                        .getString(com.android.internal.R.string
+                                .config_mediaProjectionPermissionDialogComponent));
+        i.setComponent(mediaProjectionPermissionDialogComponent);
+        i.putExtra(EXTRA_MEDIA_PROJECTION_CONFIG, config);
+        return i;
+    }
+
+    /**
      * Retrieves the {@link MediaProjection} obtained from a successful screen
      * capture request. The result code and data from the request are provided
      * by overriding {@link Activity#onActivityResult(int, int, Intent)
diff --git a/media/java/android/media/projection/OWNERS b/media/java/android/media/projection/OWNERS
index 9ca3910..96532d0 100644
--- a/media/java/android/media/projection/OWNERS
+++ b/media/java/android/media/projection/OWNERS
@@ -1,2 +1,3 @@
 michaelwr@google.com
 santoscordon@google.com
+chaviw@google.com
diff --git a/media/java/android/media/tv/interactive/TvInteractiveAppService.java b/media/java/android/media/tv/interactive/TvInteractiveAppService.java
index 90eed9e..00150d5 100755
--- a/media/java/android/media/tv/interactive/TvInteractiveAppService.java
+++ b/media/java/android/media/tv/interactive/TvInteractiveAppService.java
@@ -457,7 +457,9 @@
         /**
          * Receives started recording's ID.
          *
-         * @param recordingId The ID of the recording started
+         * @param recordingId The ID of the recording started. The TV app should provide and
+         *                    maintain this ID to identify the recording in the future.
+         * @see #onRecordingStopped(String)
          */
         public void onRecordingStarted(@NonNull String recordingId) {
         }
@@ -465,13 +467,13 @@
         /**
          * Receives stopped recording's ID.
          *
-         * @param recordingId The ID of the recording stopped
-         * @hide
+         * @param recordingId The ID of the recording stopped. This ID is created and maintained by
+         *                    the TV app when the recording was started.
+         * @see #onRecordingStarted(String)
          */
         public void onRecordingStopped(@NonNull String recordingId) {
         }
 
-
         /**
          * Receives signing result.
          * @param signingId the ID to identify the request. It's the same as the corresponding ID in
@@ -952,13 +954,14 @@
         }
 
         /**
-         * Requests starting of recording
+         * Requests the recording associated with the recordingId to stop.
          *
-         * <p> This is used to request the active {@link android.media.tv.TvRecordingClient} to
+         * <p> This is used to request the associated {@link android.media.tv.TvRecordingClient} to
          * call {@link android.media.tv.TvRecordingClient#stopRecording()}.
-         * @see android.media.tv.TvRecordingClient#stopRecording()
          *
-         * @hide
+         * @param recordingId The ID of the recording to stop. This is provided by the TV app in
+         *                    {@link TvInteractiveAppView#notifyRecordingStarted(String)}
+         * @see android.media.tv.TvRecordingClient#stopRecording()
          */
         @CallSuper
         public void requestStopRecording(@NonNull String recordingId) {
@@ -976,8 +979,6 @@
             });
         }
 
-
-
         /**
          * Requests signing of the given data.
          *
diff --git a/media/java/android/media/tv/interactive/TvInteractiveAppView.java b/media/java/android/media/tv/interactive/TvInteractiveAppView.java
index fcd781b..1177688 100755
--- a/media/java/android/media/tv/interactive/TvInteractiveAppView.java
+++ b/media/java/android/media/tv/interactive/TvInteractiveAppView.java
@@ -585,6 +585,7 @@
      *
      * @param recordingId The ID of the recording started. This ID is created and maintained by the
      *                    TV app and is used to identify the recording in the future.
+     * @see TvInteractiveAppView#notifyRecordingStopped(String)
      */
     public void notifyRecordingStarted(@NonNull String recordingId) {
         if (DEBUG) {
@@ -601,7 +602,6 @@
      * @param recordingId The ID of the recording stopped. This ID is created and maintained
      *                    by the TV app when a recording is started.
      * @see TvInteractiveAppView#notifyRecordingStarted(String)
-     * @hide
      */
     public void notifyRecordingStopped(@NonNull String recordingId) {
         if (DEBUG) {
@@ -877,7 +877,8 @@
          * is called.
          *
          * @param iAppServiceId The ID of the TV interactive app service bound to this view.
-         * @param programUri The program URI to record
+         * @param programUri The URI of the program to record
+         *
          */
         public void onRequestStartRecording(
                 @NonNull String iAppServiceId,
@@ -885,12 +886,14 @@
         }
 
         /**
-         * This is called when {@link TvInteractiveAppService.Session#requestStopRecording()}
+         * This is called when {@link TvInteractiveAppService.Session#requestStopRecording(String)}
          * is called.
          *
          * @param iAppServiceId The ID of the TV interactive app service bound to this view.
-         * @param recordingId The ID of the recording to stop.
-         * @hide
+         * @param recordingId The ID of the recording to stop. This is provided by the TV app in
+         *                    {@link #notifyRecordingStarted(String)}
+         * @see #notifyRecordingStarted(String)
+         * @see #notifyRecordingStopped(String)
          */
         public void onRequestStopRecording(
                 @NonNull String iAppServiceId,
diff --git a/media/tests/AudioPolicyTest/AndroidManifest.xml b/media/tests/AudioPolicyTest/AndroidManifest.xml
index f696735..5c911b1 100644
--- a/media/tests/AudioPolicyTest/AndroidManifest.xml
+++ b/media/tests/AudioPolicyTest/AndroidManifest.xml
@@ -24,13 +24,22 @@
 
     <application>
         <uses-library android:name="android.test.runner" />
-        <activity android:label="@string/app_name" android:name="AudioPolicyTestActivity"
+        <activity android:label="@string/app_name" android:name="AudioVolumeTestActivity"
                   android:screenOrientation="landscape" android:exported="true">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER"/>
             </intent-filter>
         </activity>
+        <activity android:label="@string/app_name" android:name="AudioPolicyDeathTestActivity"
+                  android:screenOrientation="landscape"
+                  android:process=":AudioPolicyDeathTestActivityProcess"
+                  android:exported="true">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER"/>
+            </intent-filter>
+        </activity>
     </application>
 
     <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
diff --git a/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioPolicyDeathTest.java b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioPolicyDeathTest.java
new file mode 100644
index 0000000..841804b
--- /dev/null
+++ b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioPolicyDeathTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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.audiopolicytest;
+
+import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.media.AudioAttributes;
+import android.media.AudioFormat;
+import android.media.AudioManager;
+import android.media.AudioTrack;
+import android.platform.test.annotations.Presubmit;
+import android.util.Log;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@Presubmit
+@RunWith(AndroidJUnit4.class)
+public class AudioPolicyDeathTest {
+    private static final String TAG = "AudioPolicyDeathTest";
+
+    private static final int SAMPLE_RATE = 48000;
+    private static final int PLAYBACK_TIME_MS = 2000;
+
+    private static final IntentFilter AUDIO_NOISY_INTENT_FILTER =
+            new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
+
+    private class MyBroadcastReceiver extends BroadcastReceiver {
+        private boolean mReceived = false;
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intent.getAction())) {
+                synchronized (this) {
+                    mReceived = true;
+                    notify();
+                }
+            }
+        }
+
+        public synchronized boolean received() {
+            return mReceived;
+        }
+    }
+    private final MyBroadcastReceiver mReceiver = new MyBroadcastReceiver();
+
+    private Context mContext;
+
+    @Before
+    public void setUp() {
+        mContext = getApplicationContext();
+        assertEquals(PackageManager.PERMISSION_GRANTED,
+                mContext.checkSelfPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING));
+    }
+
+    //-----------------------------------------------------------------
+    // Tests that an AUDIO_BECOMING_NOISY intent is broadcast when an app having registered
+    // a dynamic audio policy that intercepts an active media playback dies
+    //-----------------------------------------------------------------
+    @Test
+    public void testPolicyClientDeathSendBecomingNoisyIntent() {
+        mContext.registerReceiver(mReceiver, AUDIO_NOISY_INTENT_FILTER);
+
+        // Launch process registering a dynamic auido policy and dying after PLAYBACK_TIME_MS/2 ms
+        Intent intent = new Intent(mContext, AudioPolicyDeathTestActivity.class);
+        intent.putExtra("captureDurationMs", PLAYBACK_TIME_MS / 2);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+        mContext.startActivity(intent);
+
+        AudioTrack track = createAudioTrack();
+        track.play();
+        synchronized (mReceiver) {
+            long startTimeMs = System.currentTimeMillis();
+            long elapsedTimeMs = 0;
+            while (elapsedTimeMs < PLAYBACK_TIME_MS && !mReceiver.received()) {
+                try {
+                    mReceiver.wait(PLAYBACK_TIME_MS - elapsedTimeMs);
+                } catch (InterruptedException e) {
+                    Log.w(TAG, "wait interrupted");
+                }
+                elapsedTimeMs = System.currentTimeMillis() - startTimeMs;
+            }
+        }
+
+        track.stop();
+        track.release();
+
+        assertTrue(mReceiver.received());
+    }
+
+    private AudioTrack createAudioTrack() {
+        AudioFormat format = new AudioFormat.Builder()
+                .setChannelMask(AudioFormat.CHANNEL_OUT_STEREO)
+                .setEncoding(AudioFormat.ENCODING_PCM_16BIT)
+                .setSampleRate(SAMPLE_RATE)
+                .build();
+
+        short[] data = new short[PLAYBACK_TIME_MS * SAMPLE_RATE * format.getChannelCount() / 1000];
+        AudioAttributes attributes =
+                new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build();
+
+        AudioTrack track = new AudioTrack(attributes, format, data.length,
+                AudioTrack.MODE_STATIC, AudioManager.AUDIO_SESSION_ID_GENERATE);
+        track.write(data, 0, data.length);
+
+        return track;
+    }
+}
diff --git a/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioPolicyDeathTestActivity.java b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioPolicyDeathTestActivity.java
new file mode 100644
index 0000000..957e719
--- /dev/null
+++ b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioPolicyDeathTestActivity.java
@@ -0,0 +1,132 @@
+/*
+ * 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.audiopolicytest;
+
+import android.app.Activity;
+import android.media.AudioAttributes;
+import android.media.AudioFormat;
+import android.media.AudioManager;
+import android.media.AudioRecord;
+import android.media.audiopolicy.AudioMix;
+import android.media.audiopolicy.AudioMixingRule;
+import android.media.audiopolicy.AudioPolicy;
+import android.os.Bundle;
+import android.os.Looper;
+import android.util.Log;
+
+// This activity will register a dynamic audio policy to intercept media playback and launch
+// a thread that will capture audio from the policy mix and crash after the time indicated by
+// intent extra "captureDurationMs" has elapsed
+public class AudioPolicyDeathTestActivity extends Activity  {
+    private static final String TAG = "AudioPolicyDeathTestActivity";
+
+    private static final int SAMPLE_RATE = 48000;
+    private static final int RECORD_TIME_MS = 1000;
+
+    private AudioManager mAudioManager = null;
+    private AudioPolicy mAudioPolicy = null;
+
+    public AudioPolicyDeathTestActivity() {
+    }
+
+    @Override
+    public void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+
+        mAudioManager = getApplicationContext().getSystemService(AudioManager.class);
+
+        AudioAttributes attributes = new AudioAttributes.Builder()
+                .setUsage(AudioAttributes.USAGE_MEDIA).build();
+        AudioMixingRule.Builder audioMixingRuleBuilder = new AudioMixingRule.Builder()
+                .addRule(attributes, AudioMixingRule.RULE_MATCH_ATTRIBUTE_USAGE);
+
+        AudioFormat audioFormat = new AudioFormat.Builder()
+                .setEncoding(AudioFormat.ENCODING_PCM_16BIT)
+                .setChannelMask(AudioFormat.CHANNEL_OUT_STEREO)
+                .setSampleRate(SAMPLE_RATE)
+                .build();
+
+        AudioMix audioMix = new AudioMix.Builder(audioMixingRuleBuilder.build())
+                .setFormat(audioFormat)
+                .setRouteFlags(AudioMix.ROUTE_FLAG_LOOP_BACK)
+                .build();
+
+        AudioPolicy.Builder audioPolicyBuilder = new AudioPolicy.Builder(getApplicationContext());
+        audioPolicyBuilder.addMix(audioMix)
+                .setLooper(Looper.getMainLooper());
+        mAudioPolicy = audioPolicyBuilder.build();
+
+        int result = mAudioManager.registerAudioPolicy(mAudioPolicy);
+        if (result != AudioManager.SUCCESS) {
+            Log.w(TAG, "registerAudioPolicy failed, status: " + result);
+            return;
+        }
+        AudioRecord audioRecord = mAudioPolicy.createAudioRecordSink(audioMix);
+        if (audioRecord == null) {
+            Log.w(TAG, "AudioRecord creation failed");
+            return;
+        }
+
+        int captureDurationMs = getIntent().getIntExtra("captureDurationMs", RECORD_TIME_MS);
+        AudioCapturingThread thread = new AudioCapturingThread(audioRecord, captureDurationMs);
+        thread.start();
+    }
+
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        if (mAudioManager != null && mAudioPolicy != null) {
+            mAudioManager.unregisterAudioPolicy(mAudioPolicy);
+        }
+    }
+
+    // A thread that captures audio from the supplied AudioRecord and crashes after the supplied
+    // duration has elapsed
+    private static class AudioCapturingThread extends Thread {
+        private final AudioRecord mAudioRecord;
+        private final int mDurationMs;
+
+        AudioCapturingThread(AudioRecord record, int durationMs) {
+            super();
+            mAudioRecord = record;
+            mDurationMs = durationMs;
+        }
+
+        @Override
+        @SuppressWarnings("ConstantOverflow")
+        public void run() {
+            int samplesLeft = mDurationMs * SAMPLE_RATE * mAudioRecord.getChannelCount() / 1000;
+            short[] readBuffer = new short[samplesLeft / 10];
+            mAudioRecord.startRecording();
+            long startTimeMs = System.currentTimeMillis();
+            long elapsedTimeMs = 0;
+            do {
+                int read = readBuffer.length < samplesLeft ? readBuffer.length : samplesLeft;
+                read = mAudioRecord.read(readBuffer, 0, read);
+                elapsedTimeMs = System.currentTimeMillis() - startTimeMs;
+                if (read < 0) {
+                    Log.w(TAG, "read error: " + read);
+                    break;
+                }
+                samplesLeft -= read;
+            } while (elapsedTimeMs < mDurationMs && samplesLeft > 0);
+
+            // force process to crash
+            int i = 1 / 0;
+        }
+    }
+}
diff --git a/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioPolicyTestActivity.java b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumeTestActivity.java
similarity index 91%
rename from media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioPolicyTestActivity.java
rename to media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumeTestActivity.java
index e31c01a..8f61815 100644
--- a/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioPolicyTestActivity.java
+++ b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumeTestActivity.java
@@ -19,9 +19,9 @@
 import android.app.Activity;
 import android.os.Bundle;
 
-public class AudioPolicyTestActivity extends Activity  {
+public class AudioVolumeTestActivity extends Activity  {
 
-    public AudioPolicyTestActivity() {
+    public AudioVolumeTestActivity() {
     }
 
     /** Called when the activity is first created. */
diff --git a/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumesTestRule.java b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumesTestRule.java
index fc3b198..c6ec7a6 100644
--- a/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumesTestRule.java
+++ b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumesTestRule.java
@@ -100,7 +100,7 @@
 
     @Before
     public void setUp() throws Exception {
-        ActivityScenario.launch(AudioPolicyTestActivity.class);
+        ActivityScenario.launch(AudioVolumeTestActivity.class);
 
         mContext = getApplicationContext();
         mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java
index a2eae2c..2b7bcbe 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java
@@ -85,7 +85,8 @@
     public void testCameraInfo() throws Exception {
         for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) {
 
-            CameraInfo info = mUtils.getCameraService().getCameraInfo(cameraId);
+            CameraInfo info = mUtils.getCameraService().getCameraInfo(cameraId,
+                    /*overrideToPortrait*/false);
             assertTrue("Facing was not set for camera " + cameraId, info.info.facing != -1);
             assertTrue("Orientation was not set for camera " + cameraId,
                     info.info.orientation != -1);
@@ -159,7 +160,8 @@
                     .connect(dummyCallbacks, cameraId, clientPackageName,
                             ICameraService.USE_CALLING_UID,
                             ICameraService.USE_CALLING_PID,
-                            getContext().getApplicationInfo().targetSdkVersion);
+                            getContext().getApplicationInfo().targetSdkVersion,
+                            /*overrideToPortrait*/false);
             assertNotNull(String.format("Camera %s was null", cameraId), cameraUser);
 
             Log.v(TAG, String.format("Camera %s connected", cameraId));
@@ -264,7 +266,8 @@
                         dummyCallbacks, String.valueOf(cameraId),
                         clientPackageName, clientAttributionTag,
                         ICameraService.USE_CALLING_UID, 0 /*oomScoreOffset*/,
-                        getContext().getApplicationInfo().targetSdkVersion);
+                        getContext().getApplicationInfo().targetSdkVersion,
+                        /*overrideToPortrait*/false);
             assertNotNull(String.format("Camera %s was null", cameraId), cameraUser);
 
             Log.v(TAG, String.format("Camera %s connected", cameraId));
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraDeviceBinderTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraDeviceBinderTest.java
index 0890346..9d09dcc 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraDeviceBinderTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraDeviceBinderTest.java
@@ -244,7 +244,8 @@
 
         mCameraUser = mUtils.getCameraService().connectDevice(mMockCb, mCameraId,
                 clientPackageName, clientAttributionTag, ICameraService.USE_CALLING_UID,
-                /*oomScoreOffset*/0, getContext().getApplicationInfo().targetSdkVersion);
+                /*oomScoreOffset*/0, getContext().getApplicationInfo().targetSdkVersion,
+                /*overrideToPortrait*/false);
         assertNotNull(String.format("Camera %s was null", mCameraId), mCameraUser);
         mHandlerThread = new HandlerThread(TAG);
         mHandlerThread.start();
@@ -417,7 +418,7 @@
     @SmallTest
     public void testCameraCharacteristics() throws RemoteException {
         CameraMetadataNative info = mUtils.getCameraService().getCameraCharacteristics(mCameraId,
-                getContext().getApplicationInfo().targetSdkVersion);
+                getContext().getApplicationInfo().targetSdkVersion, /*overrideToPortrait*/false);
 
         assertFalse(info.isEmpty());
         assertNotNull(info.get(CameraCharacteristics.SCALER_AVAILABLE_FORMATS));
diff --git a/media/tests/projection/Android.bp b/media/tests/projection/Android.bp
new file mode 100644
index 0000000..08d9501
--- /dev/null
+++ b/media/tests/projection/Android.bp
@@ -0,0 +1,46 @@
+//########################################################################
+// Build MediaProjectionTests package
+//########################################################################
+
+package {
+    // See: http://go/android-license-faq
+    // A large-scale-change added 'default_applicable_licenses' to import
+    // all of the 'license_kinds' from "frameworks_base_license"
+    // to get the below license kinds:
+    //   SPDX-license-identifier-Apache-2.0
+    default_applicable_licenses: ["frameworks_base_license"],
+}
+
+android_test {
+    name: "MediaProjectionTests",
+
+    srcs: ["**/*.java"],
+
+    libs: [
+        "android.test.base",
+        "android.test.mock",
+        "android.test.runner",
+    ],
+
+    static_libs: [
+        "androidx.test.runner",
+        "androidx.test.rules",
+        "androidx.test.ext.junit",
+        "mockito-target-extended-minus-junit4",
+        "platform-test-annotations",
+        "testng",
+        "truth-prebuilt",
+    ],
+
+    // Needed for mockito-target-extended-minus-junit4
+    jni_libs: [
+        "libdexmakerjvmtiagent",
+        "libstaticjvmtiagent",
+    ],
+
+    test_suites: ["device-tests"],
+
+    platform_apis: true,
+
+    certificate: "platform",
+}
diff --git a/media/tests/projection/AndroidManifest.xml b/media/tests/projection/AndroidManifest.xml
new file mode 100644
index 0000000..62f148c
--- /dev/null
+++ b/media/tests/projection/AndroidManifest.xml
@@ -0,0 +1,32 @@
+<!--
+  ~ 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.
+  -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+          android:installLocation="internalOnly"
+          package="android.media.projection.mediaprojectiontests"
+          android:sharedUserId="com.android.uid.test">
+    <uses-permission android:name="android.permission.READ_COMPAT_CHANGE_CONFIG" />
+
+    <application android:debuggable="true"
+                 android:testOnly="true">
+        <uses-library android:name="android.test.mock" android:required="true"/>
+        <uses-library android:name="android.test.runner"/>
+    </application>
+
+    <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
+                     android:targetPackage="android.media.projection.mediaprojectiontests"
+                     android:label="MediaProjection package tests"/>
+</manifest>
diff --git a/media/tests/projection/AndroidTest.xml b/media/tests/projection/AndroidTest.xml
new file mode 100644
index 0000000..f64930a
--- /dev/null
+++ b/media/tests/projection/AndroidTest.xml
@@ -0,0 +1,32 @@
+<!--
+  ~ 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.
+  -->
+
+<configuration description="Runs MediaProjection package Tests.">
+    <option name="test-suite-tag" value="apct" />
+    <option name="test-suite-tag" value="apct-instrumentation" />
+    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+        <option name="cleanup-apks" value="true" />
+        <option name="install-arg" value="-t" />
+        <option name="test-file-name" value="MediaProjectionTests.apk" />
+    </target_preparer>
+
+    <option name="test-tag" value="MediaProjectionTests" />
+    <test class="com.android.tradefed.testtype.AndroidJUnitTest">
+        <option name="package" value="android.media.projection.mediaprojectiontests" />
+        <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
+        <option name="hidden-api-checks" value="false" />
+    </test>
+</configuration>
diff --git a/media/tests/projection/OWNERS b/media/tests/projection/OWNERS
new file mode 100644
index 0000000..832bcd9
--- /dev/null
+++ b/media/tests/projection/OWNERS
@@ -0,0 +1 @@
+include /media/java/android/media/projection/OWNERS
diff --git a/media/tests/projection/TEST_MAPPING b/media/tests/projection/TEST_MAPPING
new file mode 100644
index 0000000..ddb68af
--- /dev/null
+++ b/media/tests/projection/TEST_MAPPING
@@ -0,0 +1,13 @@
+{
+    "presubmit": [
+        {
+            "name": "FrameworksServicesTests",
+            "options": [
+                {"include-filter": "android.media.projection.mediaprojectiontests"},
+                {"exclude-annotation": "android.platform.test.annotations.FlakyTest"},
+                {"exclude-annotation": "androidx.test.filters.FlakyTest"},
+                {"exclude-annotation": "org.junit.Ignore"}
+            ]
+        }
+    ]
+}
diff --git a/media/tests/projection/src/android/media/projection/MediaProjectionConfigTest.java b/media/tests/projection/src/android/media/projection/MediaProjectionConfigTest.java
new file mode 100644
index 0000000..a30f2e3
--- /dev/null
+++ b/media/tests/projection/src/android/media/projection/MediaProjectionConfigTest.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 android.media.projection;
+
+import static android.media.projection.MediaProjectionConfig.CAPTURE_REGION_FIXED_DISPLAY;
+import static android.media.projection.MediaProjectionConfig.CAPTURE_REGION_USER_CHOICE;
+import static android.view.Display.DEFAULT_DISPLAY;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.junit.Assert.assertThrows;
+
+import android.os.Parcel;
+import android.platform.test.annotations.Presubmit;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.SmallTest;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Tests for the {@link MediaProjectionConfig} class.
+ *
+ * Build/Install/Run:
+ * atest MediaProjectionTests:MediaProjectionConfigTest
+ */
+@SmallTest
+@Presubmit
+@RunWith(AndroidJUnit4.class)
+public class MediaProjectionConfigTest {
+    private static final MediaProjectionConfig DISPLAY_CONFIG =
+            MediaProjectionConfig.createConfigForDisplay(DEFAULT_DISPLAY);
+    private static final MediaProjectionConfig USERS_CHOICE_CONFIG =
+            MediaProjectionConfig.createConfigForUserChoice();
+
+    @Test
+    public void testParcelable() {
+        Parcel parcel = Parcel.obtain();
+        DISPLAY_CONFIG.writeToParcel(parcel, 0 /* flags */);
+        parcel.setDataPosition(0);
+        MediaProjectionConfig config = MediaProjectionConfig.CREATOR.createFromParcel(parcel);
+        assertThat(DISPLAY_CONFIG).isEqualTo(config);
+        parcel.recycle();
+    }
+
+    @Test
+    public void testCreateDisplayConfig() {
+        assertThrows(IllegalArgumentException.class,
+                () -> MediaProjectionConfig.createConfigForDisplay(-1));
+        assertThrows(IllegalArgumentException.class,
+                () -> MediaProjectionConfig.createConfigForDisplay(DEFAULT_DISPLAY + 1));
+        assertThat(DISPLAY_CONFIG.getRegionToCapture()).isEqualTo(CAPTURE_REGION_FIXED_DISPLAY);
+        assertThat(DISPLAY_CONFIG.getDisplayToCapture()).isEqualTo(DEFAULT_DISPLAY);
+    }
+
+    @Test
+    public void testCreateUsersChoiceConfig() {
+        assertThat(USERS_CHOICE_CONFIG.getRegionToCapture()).isEqualTo(CAPTURE_REGION_USER_CHOICE);
+    }
+
+    @Test
+    public void testEquals() {
+        assertThat(MediaProjectionConfig.createConfigForUserChoice()).isEqualTo(
+                USERS_CHOICE_CONFIG);
+        assertThat(DISPLAY_CONFIG).isNotEqualTo(USERS_CHOICE_CONFIG);
+        assertThat(MediaProjectionConfig.createConfigForDisplay(DEFAULT_DISPLAY)).isEqualTo(
+                DISPLAY_CONFIG);
+    }
+}
diff --git a/media/tests/projection/src/android/media/projection/MediaProjectionManagerTest.java b/media/tests/projection/src/android/media/projection/MediaProjectionManagerTest.java
new file mode 100644
index 0000000..a3e4908
--- /dev/null
+++ b/media/tests/projection/src/android/media/projection/MediaProjectionManagerTest.java
@@ -0,0 +1,125 @@
+/*
+ * 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 android.media.projection;
+
+import static android.media.projection.MediaProjectionManager.EXTRA_MEDIA_PROJECTION_CONFIG;
+import static android.view.Display.DEFAULT_DISPLAY;
+
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.quality.Strictness.LENIENT;
+
+import android.annotation.NonNull;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.platform.test.annotations.Presubmit;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.SmallTest;
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoSession;
+
+/**
+ * Tests for the {@link MediaProjectionManager} class.
+ *
+ * Build/Install/Run:
+ * atest MediaProjectionTests:MediaProjectionManagerTest
+ */
+@SmallTest
+@Presubmit
+@RunWith(AndroidJUnit4.class)
+public class MediaProjectionManagerTest {
+    private MediaProjectionManager mMediaProjectionManager;
+    private Context mContext;
+    private MockitoSession mMockingSession;
+    private static final MediaProjectionConfig DISPLAY_CONFIG =
+            MediaProjectionConfig.createConfigForDisplay(DEFAULT_DISPLAY);
+    private static final MediaProjectionConfig USERS_CHOICE_CONFIG =
+            MediaProjectionConfig.createConfigForUserChoice();
+
+    @Before
+    public void setup() throws Exception {
+        mMockingSession =
+                mockitoSession()
+                        .initMocks(this)
+                        .strictness(LENIENT)
+                        .startMocking();
+        mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
+        spyOn(mContext);
+        mMediaProjectionManager = new MediaProjectionManager(mContext);
+    }
+
+    @After
+    public void teardown() {
+        mMockingSession.finishMocking();
+    }
+
+    @Test
+    public void testCreateScreenCaptureIntent() {
+        final String dialogPackage = "test.package";
+        preparePermissionDialogComponent(dialogPackage);
+
+        final Intent intent = mMediaProjectionManager.createScreenCaptureIntent();
+        assertThat(intent).isNotNull();
+        assertThat(intent.getComponent().getPackageName()).contains(dialogPackage);
+    }
+
+    @Test
+    public void testCreateScreenCaptureIntent_display() {
+        final String dialogPackage = "test.package";
+        preparePermissionDialogComponent(dialogPackage);
+
+        final Intent intent = mMediaProjectionManager.createScreenCaptureIntent(DISPLAY_CONFIG);
+        assertThat(intent).isNotNull();
+        assertThat(intent.getComponent().getPackageName()).contains(dialogPackage);
+        assertThat(intent.getParcelableExtra(EXTRA_MEDIA_PROJECTION_CONFIG,
+                MediaProjectionConfig.class)).isEqualTo(DISPLAY_CONFIG);
+    }
+
+    @Test
+    public void testCreateScreenCaptureIntent_usersChoice() {
+        final String dialogPackage = "test.package";
+        preparePermissionDialogComponent(dialogPackage);
+
+        final Intent intent = mMediaProjectionManager.createScreenCaptureIntent(
+                USERS_CHOICE_CONFIG);
+        assertThat(intent).isNotNull();
+        assertThat(intent.getComponent().getPackageName()).contains(dialogPackage);
+        assertThat(intent.getParcelableExtra(EXTRA_MEDIA_PROJECTION_CONFIG,
+                MediaProjectionConfig.class)).isEqualTo(USERS_CHOICE_CONFIG);
+    }
+
+    private void preparePermissionDialogComponent(@NonNull String dialogPackage) {
+        final Resources mockResources = mock(Resources.class);
+        when(mContext.getResources()).thenReturn(mockResources);
+        doReturn(dialogPackage + "/.TestActivity").when(mockResources).getString(
+                com.android.internal.R.string
+                        .config_mediaProjectionPermissionDialogComponent);
+    }
+}
diff --git a/packages/CarrierDefaultApp/res/values-af/strings.xml b/packages/CarrierDefaultApp/res/values-af/strings.xml
index 3bc18ce..f3ea488 100644
--- a/packages/CarrierDefaultApp/res/values-af/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-af/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Die netwerk waarby jy probeer aansluit, het sekuriteitkwessies."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Byvoorbeeld, die aanmeldbladsy behoort dalk nie aan die organisasie wat gewys word nie."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Gaan in elk geval deur blaaier voort"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Netwerkhupstoot"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s beveel ’n datahupstoot aan"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Koop ’n netwerkhupstoot vir beter werkverrigting"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Nie nou nie"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Bestuur"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Koop ’n netwerkhupstoot."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-ar/strings.xml b/packages/CarrierDefaultApp/res/values-ar/strings.xml
index cd979b2..f5ae9f2 100644
--- a/packages/CarrierDefaultApp/res/values-ar/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-ar/strings.xml
@@ -16,16 +16,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"الشبكة التي تحاول الانضمام إليها بها مشاكل أمنية."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"على سبيل المثال، قد لا تنتمي صفحة تسجيل الدخول إلى المؤسسة المعروضة."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"المتابعة على أي حال عبر المتصفح"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"خطة معزَّزة للشبكة"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"‏هناك اقتراح من %s بخطة معزَّزة للبيانات"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"من خلال شراء خطة معزَّزة للشبكة، يمكنك الاستفادة من أداء أفضل."</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"لاحقًا"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"إدارة"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"شراء خطة معزَّزة للشبكة"</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-as/strings.xml b/packages/CarrierDefaultApp/res/values-as/strings.xml
index fdafe2b..b983fd1 100644
--- a/packages/CarrierDefaultApp/res/values-as/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-as/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"আপুনি সংযোগ কৰিবলৈ বিচৰা নেটৱৰ্কটোত সুৰক্ষাজনিত সমস্যা আছে।"</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"উদাহৰণস্বৰূপে, আপোনাক দেখুওৱা লগ ইনৰ পৃষ্ঠাটো প্ৰতিষ্ঠানটোৰ নিজা নহ\'বও পাৰে।"</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"তথাপিও ব্ৰাউজাৰৰ জৰিয়তে অব্যাহত ৰাখক"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"নেটৱৰ্ক পৰিৱৰ্ধন"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%sএ এটা ডেটা পৰিৱৰ্ধনৰ চুপাৰিছ কৰিছে"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"উন্নত পাৰদৰ্শিতা পাবলৈ এটা নেটৱৰ্ক পৰিৱৰ্ধন ক্ৰয় কৰক"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"এতিয়া নহয়"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"পৰিচালনা কৰক"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"এটা নেটৱৰ্ক পৰিৱৰ্ধন ক্ৰয় কৰক।"</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-az/strings.xml b/packages/CarrierDefaultApp/res/values-az/strings.xml
index 32c3c1c..3e6e1a8 100644
--- a/packages/CarrierDefaultApp/res/values-az/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-az/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Qoşulmaq istədiyiniz şəbəkənin təhlükəsizlik problemləri var."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Məsələn, giriş səhifəsi göstərilən təşkilata aid olmaya bilər."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Hər bir halda brazuer ilə davam edin"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Əlavə trafik"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s əlavə data trafiki almağı tövsiyə edir"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Daha yaxşı performans üçün əlavə şəbəkə trafiki alın"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"İndi yox"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"İdarə edin"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Əlavə trafik alın."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-b+sr+Latn/strings.xml b/packages/CarrierDefaultApp/res/values-b+sr+Latn/strings.xml
index 932fc03..a1974f0 100644
--- a/packages/CarrierDefaultApp/res/values-b+sr+Latn/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-b+sr+Latn/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Mreža kojoj pokušavate da se pridružite ima bezbednosnih problema."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Na primer, stranica za prijavljivanje možda ne pripada prikazanoj organizaciji."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Ipak nastavi preko pregledača"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Pojačanje mreže"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s preporučuje povećanje podataka"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Kupite pojačanje mreže za bolji učinak"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Ne sada"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Upravljajte"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Kupite pojačanje mreže."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-be/strings.xml b/packages/CarrierDefaultApp/res/values-be/strings.xml
index 20606f6..1cb013b 100644
--- a/packages/CarrierDefaultApp/res/values-be/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-be/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"У сеткі, да якой вы спрабуеце далучыцца, ёсць праблемы з бяспекай."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Напрыклад, старонка ўваходу можа не належаць указанай арганізацыі."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Усё роўна працягнуць праз браўзер"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Паскарэнне сеткі"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s рэкамендуе паскарэнне перадачы даных"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Купіце паскарэнне сеткі, каб павысіць прадукцыйнасць"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Не цяпер"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Кіраваць"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Купіць паскарэнне сеткі."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-bg/strings.xml b/packages/CarrierDefaultApp/res/values-bg/strings.xml
index 46a9db5..aee67d7 100644
--- a/packages/CarrierDefaultApp/res/values-bg/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-bg/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Мрежата, към която опитвате да се присъедините, има проблеми със сигурността."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Например страницата за вход може да не принадлежи на показаната организация."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Продължаване през браузър въпреки това"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Подсилване на мрежата"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s препоръчва увеличаване на данните"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Купете подсилване на мрежата за по-висока ефективност"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Не сега"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Управление"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Купете подсилване на мрежата."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-bn/strings.xml b/packages/CarrierDefaultApp/res/values-bn/strings.xml
index 0826ae1..7f93175 100644
--- a/packages/CarrierDefaultApp/res/values-bn/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-bn/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"আপনি যে নেটওয়ার্কে যোগ দেওয়ার চেষ্টা করছেন সেটিতে নিরাপত্তাজনিত সমস্যা আছে।"</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"যেমন, লগ-ইন পৃষ্ঠাটি যে প্রতিষ্ঠানের পৃষ্ঠা বলে দেখানো আছে, আসলে তা নাও হতে পারে৷"</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"যাই হোক, ব্রাউজারের মাধ্যমে চালিয়ে যান"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"নেটওয়ার্ক বুস্ট"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s ডেটা বুস্ট করার জন্য সাজেস্ট করে"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"আরও ভাল পারফর্ম্যান্সের জন্য নেটওয়ার্ক বুস্ট কিনুন"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"এখন নয়"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"ম্যানেজ করুন"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"নেটওয়ার্ক বুস্ট কিনুন।"</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-bs/strings.xml b/packages/CarrierDefaultApp/res/values-bs/strings.xml
index e2bc342..093f03f 100644
--- a/packages/CarrierDefaultApp/res/values-bs/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-bs/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Mreža kojoj pokušavate pristupiti ima sigurnosnih problema."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Naprimjer, stranica za prijavljivanje možda ne pripada prikazanoj organizaciji."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Ipak nastavi preko preglednika"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Pojačanje mreže"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s preporučuje povećanje podataka"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Kupite pojačanje mreže za bolju izvedbu"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Ne sad"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Upravljajte"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Kupite pojačanje mreže."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-ca/strings.xml b/packages/CarrierDefaultApp/res/values-ca/strings.xml
index bdde567..63b243a 100644
--- a/packages/CarrierDefaultApp/res/values-ca/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-ca/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"La xarxa a què et vols connectar té problemes de seguretat."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Per exemple, la pàgina d\'inici de sessió podria no pertànyer a l\'organització que es mostra."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Continua igualment mitjançant el navegador"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Optimització de xarxa"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s recomana optimitzar les dades"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Compra una optimització de xarxa per millorar-ne el rendiment"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Ara no"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Gestiona"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Compra una optimització de xarxa."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-cs/strings.xml b/packages/CarrierDefaultApp/res/values-cs/strings.xml
index d5fdac9..3cff883 100644
--- a/packages/CarrierDefaultApp/res/values-cs/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-cs/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Síť, ke které se pokoušíte připojit, má bezpečnostní problémy."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Přihlašovací stránka například nemusí patřit zobrazované organizaci."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Přesto pokračovat prostřednictvím prohlížeče"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Zesilovač sítě"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s doporučuje zesílení datového připojení"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Pořiďte si zesilovač, který zvýší výkon sítě"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Teď ne"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Spravovat"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Kupte si zesilovač sítě."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-da/strings.xml b/packages/CarrierDefaultApp/res/values-da/strings.xml
index 8b2bb7c..487f62c 100644
--- a/packages/CarrierDefaultApp/res/values-da/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-da/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Der er sikkerhedsproblemer på det netværk, du forsøger at logge ind på."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Det er f.eks. ikke sikkert, at loginsiden tilhører den anførte organisation."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Fortsæt alligevel via browseren"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Netværksboost"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s anbefaler et databoost"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Køb et netværksboost for at få en bedre ydeevne"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Ikke nu"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Administrer"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Køb et netværksboost."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-de/strings.xml b/packages/CarrierDefaultApp/res/values-de/strings.xml
index 21af41c..1394d10 100644
--- a/packages/CarrierDefaultApp/res/values-de/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-de/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Im Netzwerk, zu dem du eine Verbindung herstellen möchtest, liegen Sicherheitsprobleme vor."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Beispiel: Die Log-in-Seite gehört eventuell nicht zur angezeigten Organisation."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Trotzdem in einem Browser fortfahren"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Netzwerk-Boost"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s empfiehlt einen Daten-Boost"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Netzwerk-Boost für bessere Leistung kaufen"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Nicht jetzt"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Verwalten"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Jetzt Netzwerk-Boost kaufen."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-el/strings.xml b/packages/CarrierDefaultApp/res/values-el/strings.xml
index 7514314..3551401 100644
--- a/packages/CarrierDefaultApp/res/values-el/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-el/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Παρουσιάζονται προβλήματα ασφάλειας στο δίκτυο στο οποίο προσπαθείτε να συνδεθείτε."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Για παράδειγμα, η σελίδα σύνδεσης ενδέχεται να μην ανήκει στον οργανισμό που εμφανίζεται."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Συνέχεια ούτως ή άλλως μέσω του προγράμματος περιήγησης"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Ενίσχυση δικτύου"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"Η %s συνιστά ενίσχυση δεδομένων"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Αγοράστε ενίσχυση δικτύου για καλύτερη απόδοση"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Όχι τώρα"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Διαχείριση"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Αγορά ενίσχυσης δικτύου."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-es-rUS/strings.xml b/packages/CarrierDefaultApp/res/values-es-rUS/strings.xml
index bddae48..5fa8347 100644
--- a/packages/CarrierDefaultApp/res/values-es-rUS/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-es-rUS/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"La red a la que intentas conectarte tiene problemas de seguridad."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Por ejemplo, es posible que la página de acceso no pertenezca a la organización que aparece."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Continuar de todos modos desde el navegador"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Potenciación de red"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s recomienda un potenciador de datos"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Compra un potenciador de red para obtener un mejor rendimiento"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Ahora no"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Administrar"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Compra un potenciador de red."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-es/strings.xml b/packages/CarrierDefaultApp/res/values-es/strings.xml
index dd56770..e65bc9b 100644
--- a/packages/CarrierDefaultApp/res/values-es/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-es/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"La red a la que intentas unirte tiene problemas de seguridad."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Por ejemplo, es posible que la página de inicio de sesión no pertenezca a la organización mostrada."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Continuar de todos modos a través del navegador"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Mejora de red"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s recomienda una mejora de datos"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Compra una mejora de red para impulsar el rendimiento"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Ahora no"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Gestionar"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Compra una mejora de red."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-et/strings.xml b/packages/CarrierDefaultApp/res/values-et/strings.xml
index 8cdc291..a951e7f 100644
--- a/packages/CarrierDefaultApp/res/values-et/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-et/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Võrgul, millega üritate ühenduse luua, on turvaprobleeme."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Näiteks ei pruugi sisselogimisleht kuuluda kuvatavale organisatsioonile."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Jätka siiski brauseris"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Võrgu võimendus"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s soovitab andmeside võimendust"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Ostke võrgu võimendus, et toimivust parandada"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Mitte praegu"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Haldamine"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Ostke võrgu võimendus."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-eu/strings.xml b/packages/CarrierDefaultApp/res/values-eu/strings.xml
index 22565dc..ad80cc9 100644
--- a/packages/CarrierDefaultApp/res/values-eu/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-eu/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Erabili nahi duzun sareak segurtasun-arazoak ditu."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Adibidez, baliteke saioa hasteko orria adierazitako erakundearena ez izatea."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Jarraitu arakatzailearen bidez, halere"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Sarearen hobekuntza"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s zerbitzuak datuak hobetzeko gomendatzen du"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Errendimendua areagotzeko, erosi sarearen hobekuntza bat"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Orain ez"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Kudeatu"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Erosi sarearen hobekuntza bat."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-fa/strings.xml b/packages/CarrierDefaultApp/res/values-fa/strings.xml
index ecb9930..4f55d76 100644
--- a/packages/CarrierDefaultApp/res/values-fa/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-fa/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"شبکه‌ای که می‌خواهید به آن بپیوندید مشکلات امنیتی دارد."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"به عنوان مثال، صفحه ورود به سیستم ممکن است متعلق به سازمان نشان داده شده نباشد."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"درهر صورت ازطریق مرورگر ادامه یابد"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"تقویت‌کننده شبکه"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"‏%s توصیه می‌کند از تقویت‌کننده داده استفاده کنید"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"برای بهبود عملکرد، تقویت‌کننده شبکه خریداری کنید"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"اکنون نه"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"مدیریت"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"تقویت‌کننده شبکه بخرید."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-fi/strings.xml b/packages/CarrierDefaultApp/res/values-fi/strings.xml
index 850f9db..5ceddfb 100644
--- a/packages/CarrierDefaultApp/res/values-fi/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-fi/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Verkossa, johon yrität muodostaa yhteyttä, havaittiin turvallisuusongelmia."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Kirjautumissivu ei välttämättä kuulu näytetylle organisaatiolle."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Jatka selaimen kautta"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Tehokkaampi verkko"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s suosittelee tehokkaampaa verkkoa"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Osta tehokkaampi verkko, jotta saat parempia tuloksia"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Ei nyt"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Muokkaa"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Osta tehokkaampi verkko."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-fr-rCA/strings.xml b/packages/CarrierDefaultApp/res/values-fr-rCA/strings.xml
index 61fc2e4..d7dc3ac 100644
--- a/packages/CarrierDefaultApp/res/values-fr-rCA/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-fr-rCA/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Le réseau que vous essayez de joindre présente des problèmes de sécurité."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Par exemple, la page de connexion pourrait ne pas appartenir à l\'organisation représentée."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Continuer quand même dans un navigateur"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Amplification de réseau"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s recommande une augmentation des données"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Acheter une amplification de réseau pour de meilleures performances"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Plus tard"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Gérer"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Acheter une amplification de réseau."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-fr/strings.xml b/packages/CarrierDefaultApp/res/values-fr/strings.xml
index ef1857d..2067e7b 100644
--- a/packages/CarrierDefaultApp/res/values-fr/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-fr/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Le réseau auquel vous essayez de vous connecter présente des problèmes de sécurité."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Par exemple, la page de connexion peut ne pas appartenir à l\'organisation représentée."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Continuer quand même dans le navigateur"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Boost réseau"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s recommande de booster les données"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Achetez un boost réseau pour améliorer les performances"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Pas maintenant"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Gérer"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Acheter un boost réseau."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-gl/strings.xml b/packages/CarrierDefaultApp/res/values-gl/strings.xml
index 6dde8a8..a01941f 100644
--- a/packages/CarrierDefaultApp/res/values-gl/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-gl/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"A rede á que tentas unirte ten problemas de seguranza."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Por exemplo, é posible que a páxina de inicio de sesión non pertenza á organización que se mostra."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Continuar igualmente co navegador"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Optimizador de rede"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s recomenda un optimizador de datos"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Compra un optimizador de rede para obter un mellor rendemento"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Agora non"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Xestionar"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Compra un optimizador de rede."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-gu/strings.xml b/packages/CarrierDefaultApp/res/values-gu/strings.xml
index 473a035..28f9ecb 100644
--- a/packages/CarrierDefaultApp/res/values-gu/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-gu/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"તમે જોડાવાનો પ્રયાસ કરી રહ્યા છો તે નેટવર્કમાં સુરક્ષા સંબંધી સમસ્યાઓ છે."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"ઉદાહરણ તરીકે, લોગિન પૃષ્ઠ બતાવવામાં આવેલી સંસ્થાનું ન પણ હોય."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"તો પણ બ્રાઉઝર મારફતે ચાલુ રાખો"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"નેટવર્ક બૂસ્ટ"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"ડેટા બૂસ્ટનો સુઝાવ %s દ્વારા આપવામાં આવે છે"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"બહેતર પર્ફોર્મન્સ માટે, કોઈ નેટવર્ક બૂસ્ટ ખરીદો"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"હમણાં નહીં"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"મેનેજ કરો"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"કોઈ નેટવર્ક બૂસ્ટ ખરીદો."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-hi/strings.xml b/packages/CarrierDefaultApp/res/values-hi/strings.xml
index d878c1c..75206b7 100644
--- a/packages/CarrierDefaultApp/res/values-hi/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-hi/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"आप जिस नेटवर्क में शामिल होने की कोशिश कर रहे हैं उसमें सुरक्षा से जुड़ी समस्‍याएं हैं."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"उदाहरण के लिए, हो सकता है कि लॉगिन पेज दिखाए गए संगठन का ना हो."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"ब्राउज़र के ज़रिए किसी भी तरह जारी रखें"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"नेटवर्क बूस्ट"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s, डेटा बूस्ट इस्तेमाल करने का सुझाव देता है"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"बेहतर परफ़ॉर्मेंस के लिए, नेटवर्क बूस्ट खरीदें"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"अभी नहीं"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"मैनेज करें"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"नेटवर्क बूस्ट खरीदें."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-hr/strings.xml b/packages/CarrierDefaultApp/res/values-hr/strings.xml
index 0da2280..d31f4f8 100644
--- a/packages/CarrierDefaultApp/res/values-hr/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-hr/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Mreža kojoj se pokušavate pridružiti ima sigurnosne poteškoće."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Na primjer, stranica za prijavu možda ne pripada prikazanoj organizaciji."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Ipak nastavi putem preglednika"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Pojačanje mreže"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s preporučuje povećanje podataka"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Kupite pojačanje mreže za bolju izvedbu"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Ne sad"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Upravljajte"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Kupite pojačanje mreže."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-hu/strings.xml b/packages/CarrierDefaultApp/res/values-hu/strings.xml
index 95c1db8..afd6742 100644
--- a/packages/CarrierDefaultApp/res/values-hu/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-hu/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Biztonsági problémák vannak azzal a hálózattal, amelyhez csatlakozni szeretne."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Például lehetséges, hogy a bejelentkezési oldal nem a megjelenített szervezethez tartozik."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Folytatás ennek ellenére böngészőn keresztül"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Teljesítménynövelés"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s a teljesítménynövelést javasol"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Vásároljon teljesítménynövelési lehetőséget a jobb teljesítmény érdekében"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Most nem"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Kezelés"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Vásároljon teljesítménynövelést."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-hy/strings.xml b/packages/CarrierDefaultApp/res/values-hy/strings.xml
index a846e04..1effc3d 100644
--- a/packages/CarrierDefaultApp/res/values-hy/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-hy/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Ցանցը, որին փորձում եք միանալ, անվտանգության խնդիրներ ունի:"</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Օրինակ՝ մուտքի էջը կարող է ցուցադրված կազմակերպության էջը չլինել:"</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Շարունակել դիտարկիչի միջոցով"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Բջջային ինտերնետի փաթեթ"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s-ը խորհուրդ է տալիս գնել բջջային ինտերնետի փաթեթ"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Գնեք բջջային ինտերնետի փաթեթ՝ աշխատանքի արդյունավետությունը լավացնելու համար"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Ոչ հիմա"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Կառավարել"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Գնել ցանցի բջջային ինտերնետի փաթեթ։"</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-in/strings.xml b/packages/CarrierDefaultApp/res/values-in/strings.xml
index 488ad09..ed7385a 100644
--- a/packages/CarrierDefaultApp/res/values-in/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-in/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Jaringan yang ingin Anda masuki memiliki masalah keamanan."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Misalnya, halaman login mungkin bukan milik organisasi yang ditampilkan."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Tetap lanjutkan melalui browser"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Penguat sinyal"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s merekomendasikan penguat sinyal data seluler"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Beli penguat sinyal untuk performa yang lebih baik"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Lain kali"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Kelola"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Beli penguat sinyal."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-is/strings.xml b/packages/CarrierDefaultApp/res/values-is/strings.xml
index ab4981d..df8c01b 100644
--- a/packages/CarrierDefaultApp/res/values-is/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-is/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Öryggisvandamál eru á netinu sem þú ert að reyna að tengjast."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Til dæmis getur verið að innskráningarsíðan tilheyri ekki fyrirtækinu sem birtist."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Halda samt áfram í vafra"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Nethröðun"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s mælir með auknu gagnamagni"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Kauptu nethröðun til að bæta afköstin"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Ekki núna"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Stjórna"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Kaupa nethröðun."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-it/strings.xml b/packages/CarrierDefaultApp/res/values-it/strings.xml
index 95ea060..3c76f21 100644
--- a/packages/CarrierDefaultApp/res/values-it/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-it/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"La rete a cui stai tentando di accedere presenta problemi di sicurezza."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Ad esempio, la pagina di accesso potrebbe non appartenere all\'organizzazione indicata."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Continua comunque dal browser"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Potenziamento di rete"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s consiglia un aumento dei dati"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Acquista un potenziamento di rete per migliorare le prestazioni"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Non ora"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Gestisci"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Acquista un potenziamento di rete."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-iw/strings.xml b/packages/CarrierDefaultApp/res/values-iw/strings.xml
index 263ed1a..9f7cc8e 100644
--- a/packages/CarrierDefaultApp/res/values-iw/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-iw/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"יש בעיות אבטחה ברשת שאליה אתה מנסה להתחבר."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"לדוגמה, ייתכן שדף ההתחברות אינו שייך לארגון המוצג."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"המשך בכל זאת באמצעות דפדפן"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"מגבר לרשת"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"‏יש המלצה של %s להגברת הרשת"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"קניית מגבר לרשת לשיפור הביצועים"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"לא עכשיו"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"ניהול"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"קניית מגבר לרשת."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-ja/strings.xml b/packages/CarrierDefaultApp/res/values-ja/strings.xml
index 3b22ae1..4b709afc 100644
--- a/packages/CarrierDefaultApp/res/values-ja/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-ja/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"接続しようとしているネットワークにセキュリティの問題があります。"</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"たとえば、ログインページが表示されている組織に属していない可能性があります。"</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"ブラウザから続行"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"ネットワーク ブースト"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s ではデータブーストが推奨されます"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"ネットワーク ブーストを購入してパフォーマンスを改善しましょう"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"後で"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"管理"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"ネットワーク ブーストを購入できます。"</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-ka/strings.xml b/packages/CarrierDefaultApp/res/values-ka/strings.xml
index 4b9cd38..713c488 100644
--- a/packages/CarrierDefaultApp/res/values-ka/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-ka/strings.xml
@@ -14,16 +14,12 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"ქსელს, რომელთან დაკავშრებასაც ცდილობთ, უსაფრთხოების პრობლემები აქვს."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"მაგალითად, სისტემაში შესვლის გვერდი შეიძლება არ ეკუთვნოდეს ნაჩვენებ ორგანიზაციას."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"მაინც ბრაუზერში გაგრძელება"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"ქსელის გაძლიერება"</string>
+    <!-- String.format failed for translation -->
     <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
     <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"შეიძინეთ ქსელის გაძლიერება უკეთესი მუშაობისთვის"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"ახლა არა"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"მართვა"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"შეიძინეთ ქსელის გაძლიერება."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-kk/strings.xml b/packages/CarrierDefaultApp/res/values-kk/strings.xml
index fce8dd2..13fdc0a 100644
--- a/packages/CarrierDefaultApp/res/values-kk/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-kk/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Қосылайын деп жатқан желіңізде қауіпсіздік мәселелері бар."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Мысалы, кіру беті көрсетілген ұйымға тиесілі болмауы мүмкін."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Бәрібір браузер арқылы жалғастыру"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Күшейтілген желі"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s күшейтілген желі пакетін ұсынады"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Өнімділікті арттыру үшін күшейтілген желі пакетін сатып алыңыз."</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Қазір емес"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Басқару"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Күшейтілген желіні сатып алыңыз."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-km/strings.xml b/packages/CarrierDefaultApp/res/values-km/strings.xml
index 983f09e..7993f6f 100644
--- a/packages/CarrierDefaultApp/res/values-km/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-km/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"បណ្តាញដែលអ្នកកំពុងព្យាយាមចូលមានបញ្ហាសុវត្ថិភាព។"</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"ឧទាហរណ៍៖ ទំព័រចូលនេះអាចនឹងមិនមែនជាកម្មសិទ្ធិរបស់ស្ថាប័នដែលបានបង្ហាញនេះទេ។"</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"យ៉ាងណាក៏ដោយនៅតែបន្តតាមរយៈកម្មវិធីរុករកតាមអ៊ីនធឺណិត"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"ការបង្កើនល្បឿនបណ្ដាញ"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s ណែនាំ​ឱ្យបង្កើន​ទិន្នន័យ"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"ទិញ​ការបង្កើនល្បឿនបណ្ដាញ ដើម្បីឱ្យប្រតិបត្តិការ​ប្រសើរជាងមុន"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"កុំទាន់"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"គ្រប់គ្រង"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"ទិញការបង្កើន​ល្បឿនបណ្ដាញ។"</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-kn/strings.xml b/packages/CarrierDefaultApp/res/values-kn/strings.xml
index 86b29ce..323885e 100644
--- a/packages/CarrierDefaultApp/res/values-kn/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-kn/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"ನೀವು ಸೇರಬೇಕೆಂದಿರುವ ನೆಟ್‌ವರ್ಕ್, ಭದ್ರತೆ ಸಮಸ್ಯೆಗಳನ್ನು ಹೊಂದಿದೆ."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"ಉದಾಹರಣೆಗೆ, ಲಾಗಿನ್ ಪುಟವು ತೋರಿಸಲಾಗಿರುವ ಸಂಸ್ಥೆಗೆ ಸಂಬಂಧಿಸಿಲ್ಲದಿರಬಹುದು."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"ಪರವಾಗಿಲ್ಲ, ಬ್ರೌಸರ್ ಮೂಲಕ ಮುಂದುವರಿಸಿ"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"ನೆಟ್‌ವರ್ಕ್ ಬೂಸ್ಟ್"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s ಡೇಟಾ ಬೂಸ್ಟ್ ಅನ್ನು ಶಿಫಾರಸು ಮಾಡುತ್ತದೆ"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"ಉತ್ತಮ ಕಾರ್ಯಕ್ಷಮತೆಗಾಗಿ ನೆಟ್‌ವರ್ಕ್ ಬೂಸ್ಟ್ ಅನ್ನು ಖರೀದಿಸಿ"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"ಸದ್ಯಕ್ಕೆ ಬೇಡ"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"ನಿರ್ವಹಿಸಿ"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"ನೆಟ್‌ವರ್ಕ್ ಬೂಸ್ಟ್ ಖರೀದಿಸಿ."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-ko/strings.xml b/packages/CarrierDefaultApp/res/values-ko/strings.xml
index 3c6f4a6..8ce69a3 100644
--- a/packages/CarrierDefaultApp/res/values-ko/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-ko/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"가입하려는 네트워크에 보안 문제가 있습니다."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"예를 들어 로그인 페이지가 표시된 조직에 속하지 않을 수 있습니다."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"브라우저를 통해 계속하기"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"성능 향상"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s에서 성능 향상을 권장합니다"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"성능 향상을 구매하여 성능을 개선하세요."</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"나중에"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"관리"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"성능 향상을 구매하세요."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-ky/strings.xml b/packages/CarrierDefaultApp/res/values-ky/strings.xml
index 3cece7d..637620c 100644
--- a/packages/CarrierDefaultApp/res/values-ky/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-ky/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Кошулайын деген тармагыңызда коопсуздук көйгөйлөрү бар."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Мисалы, аккаунтка кирүү баракчасы көрсөтүлгөн уюмга таандык эмес болушу мүмкүн."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Баары бир серепчи аркылуу улантуу"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Тармакты оптималдаштыруу"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s тармак оптималдаштыруусун сунуштайт"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Иштин майнаптуулугун жогорулатуу үчүн тармакты оптималдаштыруу мүмкүнчүлүгүн сатып алыңыз"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Азыр эмес"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Тескөө"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Тармакты оптималдаштырууну сатып алыңыз."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-lo/strings.xml b/packages/CarrierDefaultApp/res/values-lo/strings.xml
index c6c0533..124e5cc 100644
--- a/packages/CarrierDefaultApp/res/values-lo/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-lo/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"ເຄືອຂ່າຍທີ່ທ່ານກຳລັງເຂົ້າຮ່ວມມີບັນຫາຄວາມປອດໄພ."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"ຕົວຢ່າງ, ໜ້າເຂົ້າສູ່ລະບົບອາດຈະບໍ່ແມ່ນຂອງອົງກອນທີ່ປາກົດ."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"ດຳເນີນການຕໍ່ຜ່ານໂປຣແກຣມທ່ອງເວັບ"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"ການເພີ່ມປະສິດທິພາບເຄືອຂ່າຍ"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s ແນະນຳໃຫ້ເພີ່ມປະສິດທິພາບຂໍ້ມູນ"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"ຊື້ການເພີ່ມປະສິດທິພາບເຄືອຂ່າຍເພື່ອປະສິດທິພາບການເຮັດວຽກທີ່ດີຂຶ້ນ"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"ບໍ່ຟ້າວເທື່ອ"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"ຈັດການ"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"ຊື້ການເພີ່ມປະສິດທິພາບເຄືອຂ່າຍ."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-lt/strings.xml b/packages/CarrierDefaultApp/res/values-lt/strings.xml
index fe33b1d..61e1593 100644
--- a/packages/CarrierDefaultApp/res/values-lt/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-lt/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Kilo tinklo, prie kurio bandote prisijungti, saugos problemų."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Pavyzdžiui, prisijungimo puslapis gali nepriklausyti rodomai organizacijai."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Vis tiek tęsti naudojant naršyklę"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Papildomi duomenys"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s rekomenduoja įsigyti papildomų duomenų"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Įsigykite papildomų duomenų, kad pagerintumėte našumą"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Ne dabar"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Tvarkyti"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Įsigykite papildomų duomenų."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-lv/strings.xml b/packages/CarrierDefaultApp/res/values-lv/strings.xml
index f8864e2..3472b4c 100644
--- a/packages/CarrierDefaultApp/res/values-lv/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-lv/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Tīklā, kuram mēģināt pievienoties, ir drošības problēmas."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Piemēram, pieteikšanās lapa, iespējams, nepieder norādītajai organizācijai."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Tomēr turpināt, izmantojot pārlūkprogrammu"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Tīkla veiktspējas uzlabojums"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s iesaka veiktspējas uzlabojumu"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Iegādājieties tīkla veiktspējas uzlabojumu."</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Vēlāk"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Pārvaldīt"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Iegādājieties tīkla veiktspējas uzlabojumu."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-mk/strings.xml b/packages/CarrierDefaultApp/res/values-mk/strings.xml
index 0b8daaf..759c58a 100644
--- a/packages/CarrierDefaultApp/res/values-mk/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-mk/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Мрежата на која се обидувате да се придружите има проблеми со безбедноста."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"На пример, страницата за најавување може да не припаѓа на прикажаната организација."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Сепак продолжи преку прелистувач"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Засилување за мрежата"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s препорачува засилување за мрежата"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Купете засилување за мрежата за подобра изведба"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Не сега"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Управувајте"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Купете засилување за мрежата."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-ml/strings.xml b/packages/CarrierDefaultApp/res/values-ml/strings.xml
index f27d4d8..08a04e3 100644
--- a/packages/CarrierDefaultApp/res/values-ml/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-ml/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"നിങ്ങൾ ചേരാൻ ശ്രമിക്കുന്ന നെറ്റ്‌വർക്കിൽ സുരക്ഷാ പ്രശ്‌നങ്ങളുണ്ടായിരിക്കാം."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"ഉദാഹരണത്തിന്, കാണിച്ചിരിക്കുന്ന ഓർഗനൈസേഷന്റേതായിരിക്കില്ല ലോഗിൻ പേജ്."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"എന്തായാലും ബ്രൗസർ വഴി തുടരുക"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"നെറ്റ്‌വർക്ക് ബൂസ്റ്റ്"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s ഡാറ്റാ ബൂസ്റ്റ് നിർദ്ദേശിക്കുന്നു"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"മികച്ച പ്രകടനത്തിന് നെറ്റ്‌വർക്ക് ബൂസ്റ്റ് വാങ്ങുക"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"ഇപ്പോൾ വേണ്ട"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"മാനേജ് ചെയ്യുക"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"ഒരു നെറ്റ്‌വർക്ക് ബൂസ്‌റ്റ് വാങ്ങുക."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-mn/strings.xml b/packages/CarrierDefaultApp/res/values-mn/strings.xml
index 354bd34..5ef4243 100644
--- a/packages/CarrierDefaultApp/res/values-mn/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-mn/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Таны холбогдох гэж буй сүлжээ аюулгүй байдлын асуудалтай байна."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Жишээлбэл нэвтрэх хуудас нь харагдаж буй байгууллагынх биш байж болно."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Ямар ч тохиолдолд хөтчөөр үргэлжлүүлэх"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Сүлжээний идэвхжүүлэлт"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s дата идэвхжүүлэлтийг санал болгодог"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Илүү сайн гүйцэтгэл авах бол сүлжээний идэвхжүүлэлтийг худалдаж авна уу"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Одоо биш"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Удирдах"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Сүлжээний идэвхжүүлэлтийг худалдан авна уу."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-mr/strings.xml b/packages/CarrierDefaultApp/res/values-mr/strings.xml
index c61d3c8..930ed8c 100644
--- a/packages/CarrierDefaultApp/res/values-mr/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-mr/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"तुम्ही ज्या नेटवर्कमध्‍ये सामील होण्याचा प्रयत्न करत आहात त्यात सुरक्षितता समस्या आहेत."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"उदाहरणार्थ, लॉग इन पृष्‍ठ दर्शवलेल्या संस्थेच्या मालकीचे नसू शकते."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"तरीही ब्राउझरद्वारे सुरू ठेवा"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"नेटवर्क बूस्ट"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s डेटा बूस्टची शिफारस करते"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"आणखी चांगल्या परफॉर्मन्ससाठी नेटवर्क बूस्ट खरेदी करा"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"आता नको"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"व्यवस्थापित करा"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"नेटवर्क बूस्ट खरेदी करा."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-ms/strings.xml b/packages/CarrierDefaultApp/res/values-ms/strings.xml
index 366463f..2f95915 100644
--- a/packages/CarrierDefaultApp/res/values-ms/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-ms/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Rangkaian yang cuba anda sertai mempunyai isu keselamatan."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Contohnya, halaman log masuk mungkin bukan milik organisasi yang ditunjukkan."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Teruskan juga melalui penyemak imbas"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Perangsang rangkaian"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s mengesyorkan peningkatan data"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Beli perangsang rangkaian untuk mendapatkan prestasi yang lebih baik"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Bukan sekarang"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Urus"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Beli perangsang rangkaian."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-my/strings.xml b/packages/CarrierDefaultApp/res/values-my/strings.xml
index 2fa6188..1ca4317 100644
--- a/packages/CarrierDefaultApp/res/values-my/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-my/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"သင်ချိတ်ဆက်ရန် ကြိုးစားနေသည့် ကွန်ရက်တွင် လုံခြုံရေးပြဿနာများ ရှိနေသည်။"</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"ဥပမာ− ဝင်ရောက်ရန် စာမျက်နှာသည် ပြသထားသည့် အဖွဲ့အစည်းနှင့် သက်ဆိုင်မှုမရှိခြင်း ဖြစ်နိုင်ပါသည်။"</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"မည်သို့ပင်ဖြစ်စေ ဘရောက်ဇာမှတစ်ဆင့် ရှေ့ဆက်ရန်"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"ကွန်ရက်မြှင့်တင်အက်ပ်"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s က ဒေတာမြှင့်တင်ရန် အကြံပြုသည်"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"စွမ်းဆောင်ရည် ပိုကောင်းစေရန် ကွန်ရက်မြှင့်တင်အက်ပ် ဝယ်ပါ"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"ယခုမလုပ်ပါ"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"စီမံရန်"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"ကွန်ရက်မြှင့်တင်အက်ပ် ဝယ်ယူရန်။"</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-nb/strings.xml b/packages/CarrierDefaultApp/res/values-nb/strings.xml
index 16f8eaa..8660207 100644
--- a/packages/CarrierDefaultApp/res/values-nb/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-nb/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Nettverket du prøver å logge på, har sikkerhetsproblemer."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Det er for eksempel mulig at påloggingssiden ikke tilhører organisasjonen som vises."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Fortsett likevel via nettleseren"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Nettverksboost"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s anbefaler en databoost"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Kjøp en nettverksboost for å få bedre ytelse"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Ikke nå"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Administrer"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Kjøp en nettverksboost."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-ne/strings.xml b/packages/CarrierDefaultApp/res/values-ne/strings.xml
index cb175df..c92237c 100644
--- a/packages/CarrierDefaultApp/res/values-ne/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-ne/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"तपाईंले सामेल हुने प्रयास गरिरहनु भएको नेटवर्कमा सुरक्षा सम्बन्धी समस्याहरू छन्।"</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"उदाहरणका लागि, लग इन पृष्ठ देखाइएको संस्थाको नहुन सक्छ।"</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"जे भए पनि ब्राउजर मार्फत जारी राख्नुहोस्"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"नेटवर्क बुस्ट"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s ले डेटा बुस्ट किन्न सिफारिस गर्छ"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"अझ राम्रो पर्फर्मेन्सका लागि नेटवर्क बुस्ट किन्नुहोस्"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"अहिले होइन"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"व्यवस्थापन गर्नुहोस्"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"नेटवर्क बुस्ट किन्नुहोस्।"</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-nl/strings.xml b/packages/CarrierDefaultApp/res/values-nl/strings.xml
index 8511ff5..1cd929e 100644
--- a/packages/CarrierDefaultApp/res/values-nl/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-nl/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Het netwerk waarmee je verbinding probeert te maken, heeft beveiligingsproblemen."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Zo hoort de weergegeven inlogpagina misschien niet bij de weergegeven organisatie."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Toch doorgaan via browser"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Netwerkboost"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s raadt een databoost aan"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Koop een netwerkboost voor betere prestaties"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Niet nu"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Beheren"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Koop een netwerkboost."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-or/strings.xml b/packages/CarrierDefaultApp/res/values-or/strings.xml
index 65fd7bb..4a01c12 100644
--- a/packages/CarrierDefaultApp/res/values-or/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-or/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"ଆପଣ ଯୋଗ ଦେବାକୁ ଚେଷ୍ଟା କରୁଥିବା ନେଟୱର୍କର ସୁରକ୍ଷା ସମସ୍ୟା ଅଛି।"</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"ଉଦାହରଣସ୍ୱରୂପ, ଲଗଇନ୍‍ ପୃଷ୍ଠା ଦେଖାଯାଇଥିବା ସଂସ୍ଥାର ହୋଇନଥାଇପାରେ।"</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"ବ୍ରାଉଜର୍‍ ଜରିଆରେ ଯେମିତିବି ହେଉ ଜାରି ରଖନ୍ତୁ"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"ନେଟୱାର୍କ ବୁଷ୍ଟ"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s ଏକ ଡାଟା ବୁଷ୍ଟ ପାଇଁ ସୁପାରିଶ କରେ"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"ଆହୁରି ଭଲ ପରଫରମାନ୍ସ ପାଇଁ ଏକ ନେଟୱାର୍କ ବୁଷ୍ଟ କିଣନ୍ତୁ"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"ବର୍ତ୍ତମାନ ନୁହେଁ"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"ପରିଚାଳନା କରନ୍ତୁ"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"ଏକ ନେଟୱାର୍କ ବୁଷ୍ଟ କିଣନ୍ତୁ।"</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-pa/strings.xml b/packages/CarrierDefaultApp/res/values-pa/strings.xml
index 0f096ab..6b15c1e 100644
--- a/packages/CarrierDefaultApp/res/values-pa/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-pa/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"ਤੁਸੀਂ ਜਿਸ ਨੈੱਟਵਰਕ ਵਿੱਚ ਸ਼ਾਮਲ ਹੋਣ ਦੀ ਕੋਸ਼ਿਸ਼ ਕਰ ਰਹੇ ਹੋ ਉਸ ਵਿੱਚ ਸੁਰੱਖਿਆ ਸਬੰਧੀ ਸਮੱਸਿਆਵਾਂ ਹਨ।"</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"ਉਦਾਹਰਣ ਵੱਜੋਂ, ਲੌਗ-ਇਨ ਪੰਨਾ ਦਿਖਾਈ ਗਈ ਸੰਸਥਾ ਨਾਲ ਸੰਬੰਧਿਤ ਨਹੀਂ ਹੋ ਸਕਦਾ ਹੈ।"</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"ਬ੍ਰਾਊਜ਼ਰ ਰਾਹੀਂ ਫਿਰ ਵੀ ਜਾਰੀ ਰੱਖੋ"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"ਨੈੱਟਵਰਕ ਬੂਸਟ"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s ਵੱਲੋਂ ਡਾਟਾ ਬੂਸਟ ਦੀ ਸਿਫ਼ਾਰਸ਼ ਕੀਤੀ ਜਾਂਦੀ ਹੈ"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"ਬਿਹਤਰ ਕਾਰਗੁਜ਼ਾਰੀ ਲਈ ਨੈੱਟਵਰਕ ਬੂਸਟ ਖਰੀਦੋ"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"ਹੁਣੇ ਨਹੀਂ"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"ਪ੍ਰਬੰਧਨ ਕਰੋ"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"ਨੈੱਟਵਰਕ ਬੂਸਟ ਖਰੀਦੋ।"</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-pl/strings.xml b/packages/CarrierDefaultApp/res/values-pl/strings.xml
index 08bc767..86306a2 100644
--- a/packages/CarrierDefaultApp/res/values-pl/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-pl/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"W sieci, z którą próbujesz się połączyć, występują problemy z zabezpieczeniami."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Na przykład strona logowania może nie należeć do wyświetlanej organizacji."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Kontynuuj mimo to w przeglądarce"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Wzmocnienie sygnału"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s zaleca wzmocnienie transmisji danych"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Kup wzmocnienie sygnału, aby zwiększyć skuteczność sieci"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Nie teraz"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Zarządzaj"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Kup wzmocnienie sygnału"</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-pt-rBR/strings.xml b/packages/CarrierDefaultApp/res/values-pt-rBR/strings.xml
index 23b4152..1138a8b 100644
--- a/packages/CarrierDefaultApp/res/values-pt-rBR/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-pt-rBR/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"A rede à qual você está tentando se conectar tem problemas de segurança."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Por exemplo, a página de login pode não pertencer à organização mostrada."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Continuar mesmo assim pelo navegador"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Aumento de rede"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s recomenda um aumento de dados"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Aumente a rede para ter um desempenho melhor"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Agora não"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Gerenciar"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Comprar um aumento de rede."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-pt/strings.xml b/packages/CarrierDefaultApp/res/values-pt/strings.xml
index 23b4152..1138a8b 100644
--- a/packages/CarrierDefaultApp/res/values-pt/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-pt/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"A rede à qual você está tentando se conectar tem problemas de segurança."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Por exemplo, a página de login pode não pertencer à organização mostrada."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Continuar mesmo assim pelo navegador"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Aumento de rede"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s recomenda um aumento de dados"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Aumente a rede para ter um desempenho melhor"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Agora não"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Gerenciar"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Comprar um aumento de rede."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-ro/strings.xml b/packages/CarrierDefaultApp/res/values-ro/strings.xml
index 165952c..4a9d57c2 100644
--- a/packages/CarrierDefaultApp/res/values-ro/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-ro/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Rețeaua la care încercați să vă conectați are probleme de securitate."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"De exemplu, este posibil ca pagina de conectare să nu aparțină organizației afișate."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Continuă oricum prin browser"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Pachet de date"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s recomandă un pachet de date"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Cumpără un pachet de date pentru o performanță mai bună"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Nu acum"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Gestionează"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Cumpără un pachet de date."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-ru/strings.xml b/packages/CarrierDefaultApp/res/values-ru/strings.xml
index 77ce91f..4fd6ffb 100644
--- a/packages/CarrierDefaultApp/res/values-ru/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-ru/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Сеть, к которой вы хотите подключиться, небезопасна."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Например, страница входа в аккаунт может быть фиктивной."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Продолжить в браузере"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Ускорение сети"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s рекомендует использовать дополнительные данные"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Приобретите ускорение сети, чтобы повысить ее производительность"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Не сейчас"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Настроить"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Покупка ускорения сети."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-si/strings.xml b/packages/CarrierDefaultApp/res/values-si/strings.xml
index fe981ca..7dad968 100644
--- a/packages/CarrierDefaultApp/res/values-si/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-si/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"ඔබ සම්බන්ධ වීමට උත්සහ කරන ජාලයේ ආරක්ෂක ගැටළු ඇත."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"උදාහරණයක් ලෙස, පුරනය වන පිටුව පෙන්වා ඇති සංවිධානයට අයිති නැති විය හැක."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"කෙසේ වුවත් බ්‍රවුසරය හරහා ඉදිරියට යන්න"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"ජාල වැඩි කිරීම"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s දත්ත වැඩි කිරීමක් නිර්දේශ කරයි"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"වඩා හොඳ කාර්ය සාධනයක් සඳහා ජාල වැඩි වීමක් මිල දී ගන්න"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"දැන් නොවේ"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"කළමනාකරණය කරන්න"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"ජාල වැඩි වීමක් මිල දී ගන්න."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-sl/strings.xml b/packages/CarrierDefaultApp/res/values-sl/strings.xml
index 1a0f74b9..66dec186 100644
--- a/packages/CarrierDefaultApp/res/values-sl/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-sl/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Omrežje, ki se mu poskušate pridružiti, ima varnostne težave."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Stran za prijavo na primer morda ne pripada prikazani organizaciji."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Vseeno nadaljuj v brskalniku"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Izboljšanje omrežja"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s priporoča izboljšanje prenosa podatkov"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Za boljše delovanje si zagotovite izboljšanje omrežja."</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Ne zdaj"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Upravljanje"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Nakup izboljšanja omrežja"</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-sq/strings.xml b/packages/CarrierDefaultApp/res/values-sq/strings.xml
index f6e1935..c0d430e 100644
--- a/packages/CarrierDefaultApp/res/values-sq/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-sq/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Rrjeti në të cilin po përpiqesh të bashkohesh ka probleme sigurie."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"për shembull, faqja e identifikimit mund të mos i përkasë organizatës së shfaqur."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Vazhdo gjithsesi nëpërmjet shfletuesit"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Paketa e përforcimit të rrjetit"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s rekomandon një paketë përforcimi të të dhënave"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Bli një paketë përforcimi të rrjetit për një performancë më të mirë"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Jo tani"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Menaxho"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Bli një paketë përforcimi të rrjetit."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-sr/strings.xml b/packages/CarrierDefaultApp/res/values-sr/strings.xml
index e615ead..84db181b 100644
--- a/packages/CarrierDefaultApp/res/values-sr/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-sr/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Мрежа којој покушавате да се придружите има безбедносних проблема."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"На пример, страница за пријављивање можда не припада приказаној организацији."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Ипак настави преко прегледача"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Појачање мреже"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s препоручује повећање података"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Купите појачање мреже за бољи учинак"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Не сада"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Управљајте"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Купите појачање мреже."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-sv/strings.xml b/packages/CarrierDefaultApp/res/values-sv/strings.xml
index 778663b..5e8853a 100644
--- a/packages/CarrierDefaultApp/res/values-sv/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-sv/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Nätverket du försöker ansluta till har säkerhetsproblem."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Det kan t.ex. hända att inloggningssidan inte tillhör den organisation som visas."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Fortsätt ändå via webbläsaren"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Nätverksboost"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s rekommenderar en databoost"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Köp en nätverksboost för bättre resultat"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Inte nu"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Hantera"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Köp en nätverksboost."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-sw/strings.xml b/packages/CarrierDefaultApp/res/values-sw/strings.xml
index 4f0745c..c99eb13 100644
--- a/packages/CarrierDefaultApp/res/values-sw/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-sw/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Mtandao unaojaribu kujiunga nao una matatizo ya usalama."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Kwa mfano, ukurasa wa kuingia katika akaunti unaweza usiwe unamilikiwa na shirika lililoonyeshwa."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Endelea hata hivyo kupitia kivinjari"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Kuimarisha mtandao"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s inapendekeza kuimarisha data"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Nunua kifaa cha kuimarisha mtandao kwa utendaji bora zaidi"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Si sasa"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Dhibiti"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Nunua kifaa cha kuimarisha mtandao."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-ta/strings.xml b/packages/CarrierDefaultApp/res/values-ta/strings.xml
index a1d2928..6f7f480 100644
--- a/packages/CarrierDefaultApp/res/values-ta/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-ta/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"நீங்கள் சேர முயலும் நெட்வொர்க்கில் பாதுகாப்புச் சிக்கல்கள் உள்ளன."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"எடுத்துக்காட்டாக, உள்நுழைவுப் பக்கமானது காட்டப்படும் அமைப்பிற்குச் சொந்தமானதாக இல்லாமல் இருக்கலாம்."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"பரவாயில்லை, உலாவி வழியாகத் தொடர்க"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"நெட்வொர்க் பூஸ்ட்"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"டேட்டா பூஸ்ட்டை %s பரிந்துரைக்கிறது"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"சிறப்பான செயல்திறனுக்கு நெட்வொர்க் பூஸ்ட்டை வாங்கவும்"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"இப்போது வேண்டாம்"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"நிர்வகியுங்கள்"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"நெட்வொர்க் பூஸ்ட்டை வாங்குங்கள்."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-te/strings.xml b/packages/CarrierDefaultApp/res/values-te/strings.xml
index 7139903..d1e49ca 100644
--- a/packages/CarrierDefaultApp/res/values-te/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-te/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"మీరు చేరడానికి ప్రయత్నిస్తున్న నెట్‌వర్క్ భద్రతా సమస్యలను కలిగి ఉంది."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"ఉదాహరణకు, లాగిన్ పేజీ చూపిన సంస్థకు చెందినది కాకపోవచ్చు."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"ఏదేమైనా బ్రౌజర్ ద్వారా కొనసాగించు"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"నెట్‌వర్క్ బూస్ట్"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"డేటా బూస్ట్‌ను %s సిఫార్సు చేస్తోంది"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"మెరుగైన పనితీరు కోసం నెట్‌వర్క్ బూస్ట్‌ను కొనుగోలు చేయండి"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"ఇప్పుడు కాదు"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"మేనేజ్ చేయండి"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"నెట్‌వర్క్ బూస్ట్‌ను కొనుగోలు చేయండి."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-th/strings.xml b/packages/CarrierDefaultApp/res/values-th/strings.xml
index 5c63bb1..3988995 100644
--- a/packages/CarrierDefaultApp/res/values-th/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-th/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"เครือข่ายที่คุณพยายามเข้าร่วมมีปัญหาด้านความปลอดภัย"</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"ตัวอย่างเช่น หน้าเข้าสู่ระบบอาจไม่ใช่ขององค์กรที่แสดงไว้"</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"ดำเนินการต่อผ่านเบราว์เซอร์"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"เพิ่มประสิทธิภาพเครือข่าย"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s แนะนำให้เพิ่มอินเทอร์เน็ตมือถือ"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"ซื้อการเพิ่มประสิทธิภาพเครือข่ายเพื่อการทำงานที่ดียิ่งขึ้น"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"ไว้ทีหลัง"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"จัดการ"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"ซื้อการเพิ่มประสิทธิภาพเครือข่าย"</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-tl/strings.xml b/packages/CarrierDefaultApp/res/values-tl/strings.xml
index 9e320c8..6375a93 100644
--- a/packages/CarrierDefaultApp/res/values-tl/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-tl/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"May mga isyu sa seguridad ang network na sinusubukan mong salihan."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Halimbawa, maaaring hindi pag-aari ng ipinapakitang organisasyon ang page ng login."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Magpatuloy pa rin sa pamamagitan ng browser"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Network boost"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"Nagrerekomenda ng data boost ang %s"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Bumili ng network boost para sa mas mahusay na performance"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Huwag muna"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Pamahalaan"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Bumili ng network boost."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-tr/strings.xml b/packages/CarrierDefaultApp/res/values-tr/strings.xml
index 63616cc..72808e68 100644
--- a/packages/CarrierDefaultApp/res/values-tr/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-tr/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Katılmaya çalıştığınız ağda güvenlik sorunları var."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Örneğin, giriş sayfası, gösterilen kuruluşa ait olmayabilir."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Yine de tarayıcıyla devam et"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Ağ güçlendirme"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s veri güçlendirme öneriyor"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Daha iyi performans için ağ güçlendirme satın alın"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Şimdi değil"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Yönet"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Ağ güçlendirme satın alın."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-uk/strings.xml b/packages/CarrierDefaultApp/res/values-uk/strings.xml
index bd44327..2b30164 100644
--- a/packages/CarrierDefaultApp/res/values-uk/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-uk/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"У мережі, до якої ви намагаєтеся під’єднатись, є проблеми з безпекою."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Наприклад, сторінка входу може не належати вказаній організації."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Усе одно продовжити у веб-переглядачі"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Покращення характеристик мережі"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s рекомендує придбати покращення характеристик мережі"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Придбайте покращення характеристик мережі, щоб підвищити продуктивність"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Не зараз"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Керувати"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Придбайте покращення характеристик мережі."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-ur/strings.xml b/packages/CarrierDefaultApp/res/values-ur/strings.xml
index 3294cf5..104f806 100644
--- a/packages/CarrierDefaultApp/res/values-ur/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-ur/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"آپ جس نیٹ ورک میں شامل ہونے کی کوشش کر رہے ہیں، اس میں سیکیورٹی کے مسائل ہیں۔"</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"مثال کے طور پر ہو سکتا ہے کہ لاگ ان صفحہ دکھائی گئی تنظیم سے تعلق نہ رکھتا ہو۔"</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"براؤزر کے ذریعے بہرحال جاری رکھیں"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"نیٹ ورک بوسٹ"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"‏%s ڈیٹا بوسٹ کی تجویز کرتا ہے"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"بہتر کارکردگی کے لیے نیٹ ورک بوسٹ خریدیں"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"ابھی نہیں"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"نظم کریں"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"نیٹ ورک بوسٹ خریدیں۔"</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-uz/strings.xml b/packages/CarrierDefaultApp/res/values-uz/strings.xml
index 4eca545..a4eb377 100644
--- a/packages/CarrierDefaultApp/res/values-uz/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-uz/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Siz ulanmoqchi bo‘lgan tarmoqda xavfsizlik bilan bog‘liq muammolar mavjud."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Masalan, tizimga kirish sahifasi ko‘rsatilgan tashkilotga tegishli bo‘lmasligi mumkin."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Brauzerda davom ettirish"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Tarmoq kuchaytirgichi"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s maʼlumotlarni kuchaytirishni tavsiya qiladi"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Yaxshiroq ishlash uchun tarmoq kuchaytirgichini sotib oling"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Hozir emas"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Boshqarish"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Tarmoq kuchaytirgichini sotib oling."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-vi/strings.xml b/packages/CarrierDefaultApp/res/values-vi/strings.xml
index d8f15e8..6f6a314 100644
--- a/packages/CarrierDefaultApp/res/values-vi/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-vi/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"Mạng mà bạn đang cố gắng tham gia có vấn đề về bảo mật."</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"Ví dụ: trang đăng nhập có thể không thuộc về tổ chức được hiển thị."</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"Vẫn tiếp tục qua trình duyệt"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"Tăng tốc độ mạng"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s đề xuất tăng tốc độ dữ liệu"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"Mua gói tăng tốc độ mạng để cải thiện hiệu suất"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"Để sau"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"Quản lý"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"Mua gói tăng tốc độ mạng."</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-zh-rCN/strings.xml b/packages/CarrierDefaultApp/res/values-zh-rCN/strings.xml
index 4ce19f5..a92278d 100644
--- a/packages/CarrierDefaultApp/res/values-zh-rCN/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-zh-rCN/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"您尝试加入的网络存在安全问题。"</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"例如,登录页面可能并不属于页面上显示的单位。"</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"仍然通过浏览器继续操作"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"网络加速"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"%s建议提升移动网络速度"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"购买网络加速服务,以获得更好的效果"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"以后再说"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"管理"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"购买网络加速服务。"</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-zh-rHK/strings.xml b/packages/CarrierDefaultApp/res/values-zh-rHK/strings.xml
index f019beb..959b497 100644
--- a/packages/CarrierDefaultApp/res/values-zh-rHK/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-zh-rHK/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"您正在嘗試加入的網絡有安全性問題。"</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"例如,登入頁面可能並不屬於所顯示的機構。"</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"仍要透過瀏覽器繼續操作"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"網絡強化"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"「%s」建議購買流動數據強化"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"購買網絡強化以提升效能"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"暫時不要"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"管理"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"購買網絡強化。"</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/res/values-zh-rTW/strings.xml b/packages/CarrierDefaultApp/res/values-zh-rTW/strings.xml
index 32724b5..29acabf 100644
--- a/packages/CarrierDefaultApp/res/values-zh-rTW/strings.xml
+++ b/packages/CarrierDefaultApp/res/values-zh-rTW/strings.xml
@@ -14,16 +14,10 @@
     <string name="ssl_error_warning" msgid="3127935140338254180">"你嘗試加入的網路有安全性問題。"</string>
     <string name="ssl_error_example" msgid="6188711843183058764">"例如,登入網頁中顯示的機構可能並非該網頁實際隸屬的機構。"</string>
     <string name="ssl_error_continue" msgid="1138548463994095584">"仍要透過瀏覽器繼續操作"</string>
-    <!-- no translation found for network_boost_notification_channel (5430986172506159199) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_title (8226368121348880044) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_detail (3812434025544196192) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_not_now (4129218252146702688) -->
-    <skip />
-    <!-- no translation found for network_boost_notification_button_manage (1511552684142641182) -->
-    <skip />
-    <!-- no translation found for slice_purchase_app_label (915654761797446390) -->
-    <skip />
+    <string name="network_boost_notification_channel" msgid="5430986172506159199">"網路增強"</string>
+    <string name="network_boost_notification_title" msgid="8226368121348880044">"「%s」建議購買行動數據增強"</string>
+    <string name="network_boost_notification_detail" msgid="3812434025544196192">"購買網路增強以提升效能"</string>
+    <string name="network_boost_notification_button_not_now" msgid="4129218252146702688">"暫時不要"</string>
+    <string name="network_boost_notification_button_manage" msgid="1511552684142641182">"管理"</string>
+    <string name="slice_purchase_app_label" msgid="915654761797446390">"購買網路增強。"</string>
 </resources>
diff --git a/packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/SlicePurchaseBroadcastReceiver.java b/packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/SlicePurchaseBroadcastReceiver.java
index b322b8b..367ae06 100644
--- a/packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/SlicePurchaseBroadcastReceiver.java
+++ b/packages/CarrierDefaultApp/src/com/android/carrierdefaultapp/SlicePurchaseBroadcastReceiver.java
@@ -175,7 +175,9 @@
                 && isPendingIntentValid(intent, SlicePurchaseController.EXTRA_INTENT_REQUEST_FAILED)
                 && isPendingIntentValid(intent,
                         SlicePurchaseController.EXTRA_INTENT_NOT_DEFAULT_DATA_SUBSCRIPTION)
-                && isPendingIntentValid(intent, SlicePurchaseController.EXTRA_INTENT_SUCCESS);
+                && isPendingIntentValid(intent, SlicePurchaseController.EXTRA_INTENT_SUCCESS)
+                && isPendingIntentValid(intent,
+                        SlicePurchaseController.EXTRA_INTENT_NOTIFICATION_SHOWN);
     }
 
     private static boolean isPendingIntentValid(@NonNull Intent intent, @NonNull String extra) {
@@ -208,6 +210,8 @@
             case SlicePurchaseController.EXTRA_INTENT_NOT_DEFAULT_DATA_SUBSCRIPTION:
                 return "not default data subscription";
             case SlicePurchaseController.EXTRA_INTENT_SUCCESS: return "success";
+            case SlicePurchaseController.EXTRA_INTENT_NOTIFICATION_SHOWN:
+                return "notification shown";
             default: {
                 loge("Unknown pending intent extra: " + extra);
                 return "unknown(" + extra + ")";
@@ -220,7 +224,7 @@
         logd("onReceive intent: " + intent.getAction());
         switch (intent.getAction()) {
             case SlicePurchaseController.ACTION_START_SLICE_PURCHASE_APP:
-                onDisplayBoosterNotification(context, intent);
+                onDisplayNetworkBoostNotification(context, intent);
                 break;
             case SlicePurchaseController.ACTION_SLICE_PURCHASE_APP_RESPONSE_TIMEOUT:
                 onTimeout(context, intent);
@@ -233,7 +237,8 @@
         }
     }
 
-    private void onDisplayBoosterNotification(@NonNull Context context, @NonNull Intent intent) {
+    private void onDisplayNetworkBoostNotification(@NonNull Context context,
+            @NonNull Intent intent) {
         if (!isIntentValid(intent)) {
             sendSlicePurchaseAppResponse(intent,
                     SlicePurchaseController.EXTRA_INTENT_REQUEST_FAILED);
@@ -280,10 +285,12 @@
 
         int capability = intent.getIntExtra(SlicePurchaseController.EXTRA_PREMIUM_CAPABILITY,
                 SlicePurchaseController.PREMIUM_CAPABILITY_INVALID);
-        logd("Display the booster notification for capability "
+        logd("Display the network boost notification for capability "
                 + TelephonyManager.convertPremiumCapabilityToString(capability));
         context.getSystemService(NotificationManager.class).notifyAsUser(
                 NETWORK_BOOST_NOTIFICATION_TAG, capability, notification, UserHandle.ALL);
+        sendSlicePurchaseAppResponse(intent,
+                SlicePurchaseController.EXTRA_INTENT_NOTIFICATION_SHOWN);
     }
 
     /**
@@ -338,7 +345,7 @@
                 + " timed out.");
         if (sSlicePurchaseActivities.get(capability) == null) {
             // Notification is still active
-            logd("Closing booster notification since the user did not respond in time.");
+            logd("Closing network boost notification since the user did not respond in time.");
             context.getSystemService(NotificationManager.class).cancelAsUser(
                     NETWORK_BOOST_NOTIFICATION_TAG, capability, UserHandle.ALL);
         } else {
diff --git a/packages/CarrierDefaultApp/tests/unit/src/com/android/carrierdefaultapp/SlicePurchaseBroadcastReceiverTest.java b/packages/CarrierDefaultApp/tests/unit/src/com/android/carrierdefaultapp/SlicePurchaseBroadcastReceiverTest.java
index 5765e5b..ab99a76 100644
--- a/packages/CarrierDefaultApp/tests/unit/src/com/android/carrierdefaultapp/SlicePurchaseBroadcastReceiverTest.java
+++ b/packages/CarrierDefaultApp/tests/unit/src/com/android/carrierdefaultapp/SlicePurchaseBroadcastReceiverTest.java
@@ -64,6 +64,7 @@
     @Mock PendingIntent mCanceledIntent;
     @Mock PendingIntent mContentIntent1;
     @Mock PendingIntent mContentIntent2;
+    @Mock PendingIntent mNotificationShownIntent;
     @Mock Context mContext;
     @Mock Resources mResources;
     @Mock NotificationManager mNotificationManager;
@@ -136,7 +137,7 @@
     }
 
     @Test
-    public void testDisplayBoosterNotification() {
+    public void testDisplayNetworkBoostNotification() throws Exception {
         // set up intent
         doReturn(SlicePurchaseController.ACTION_START_SLICE_PURCHASE_APP).when(mIntent).getAction();
         doReturn(PHONE_ID).when(mIntent).getIntExtra(
@@ -148,11 +149,17 @@
         doReturn(TAG).when(mIntent).getStringExtra(
                 eq(SlicePurchaseController.EXTRA_REQUESTING_APP_NAME));
 
-        // set up pending intent
+        // set up pending intents
         doReturn(TelephonyManager.PHONE_PROCESS_NAME).when(mPendingIntent).getCreatorPackage();
         doReturn(true).when(mPendingIntent).isBroadcast();
         doReturn(mPendingIntent).when(mIntent).getParcelableExtra(
                 anyString(), eq(PendingIntent.class));
+        doReturn(TelephonyManager.PHONE_PROCESS_NAME).when(mNotificationShownIntent)
+                .getCreatorPackage();
+        doReturn(true).when(mNotificationShownIntent).isBroadcast();
+        doReturn(mNotificationShownIntent).when(mIntent).getParcelableExtra(
+                eq(SlicePurchaseController.EXTRA_INTENT_NOTIFICATION_SHOWN),
+                eq(PendingIntent.class));
 
         // set up notification
         doReturn(mResources).when(mContext).getResources();
@@ -185,8 +192,10 @@
         assertEquals(2, notification.actions.length);
         assertEquals(mCanceledIntent, notification.actions[0].actionIntent);
         assertEquals(mContentIntent2, notification.actions[1].actionIntent);
-    }
 
+        // verify SlicePurchaseController was notified
+        verify(mNotificationShownIntent).send();
+    }
 
     @Test
     public void testNotificationCanceled() {
diff --git a/packages/CompanionDeviceManager/res/drawable-night/ic_permission_microphone.xml b/packages/CompanionDeviceManager/res/drawable-night/ic_permission_microphone.xml
new file mode 100644
index 0000000..161e4e6e
--- /dev/null
+++ b/packages/CompanionDeviceManager/res/drawable-night/ic_permission_microphone.xml
@@ -0,0 +1,26 @@
+<!--
+  ~ 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.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24"
+    android:tint="@android:color/system_accent1_200">
+  <path
+      android:fillColor="@android:color/white"
+      android:pathData="M12,14Q10.75,14 9.875,13.125Q9,12.25 9,11V5Q9,3.75 9.875,2.875Q10.75,2 12,2Q13.25,2 14.125,2.875Q15,3.75 15,5V11Q15,12.25 14.125,13.125Q13.25,14 12,14ZM12,8Q12,8 12,8Q12,8 12,8Q12,8 12,8Q12,8 12,8Q12,8 12,8Q12,8 12,8Q12,8 12,8Q12,8 12,8ZM11,21V17.925Q8.4,17.575 6.7,15.6Q5,13.625 5,11H7Q7,13.075 8.463,14.537Q9.925,16 12,16Q14.075,16 15.538,14.537Q17,13.075 17,11H19Q19,13.625 17.3,15.6Q15.6,17.575 13,17.925V21ZM12,12Q12.425,12 12.713,11.712Q13,11.425 13,11V5Q13,4.575 12.713,4.287Q12.425,4 12,4Q11.575,4 11.288,4.287Q11,4.575 11,5V11Q11,11.425 11.288,11.712Q11.575,12 12,12Z"/>
+</vector>
diff --git a/packages/CompanionDeviceManager/res/drawable/ic_glasses.xml b/packages/CompanionDeviceManager/res/drawable/ic_glasses.xml
new file mode 100644
index 0000000..5f8d566
--- /dev/null
+++ b/packages/CompanionDeviceManager/res/drawable/ic_glasses.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ 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.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+  android:height="24dp"
+  android:width="24dp"
+  android:viewportHeight="160"
+  android:viewportWidth="160" >
+  <path android:fillAlpha="0" android:fillColor="#000000"
+        android:pathData="M69.48,83.33A26.97,24.46 0,0 1,42.92 107.8,26.97 24.46,0 0,1 15.56,84.07 26.97,24.46 0,0 1,41.29 58.9,26.97 24.46,0 0,1 69.43,81.86"
+        android:strokeColor="#000000" android:strokeWidth="2.265"/>
+    <path android:fillAlpha="0" android:fillColor="#000000"
+        android:pathData="m143.73,83.58a26.97,24.46 0,0 1,-26.56 24.46,26.97 24.46,0 0,1 -27.36,-23.72 26.97,24.46 0,0 1,25.73 -25.18,26.97 24.46,0 0,1 28.14,22.96"
+        android:strokeColor="#000000" android:strokeWidth="2.265"/>
+    <path android:fillAlpha="0" android:fillColor="#000000"
+        android:pathData="m69.42,82.98c20.37,-0.25 20.37,-0.25 20.37,-0.25"
+        android:strokeColor="#000000" android:strokeWidth="2.265"/>
+    <path android:fillAlpha="0" android:fillColor="#000000"
+        android:pathData="M15.37,83.78 L1.9,56.83"
+        android:strokeColor="#000000" android:strokeWidth="2.265"/>
+    <path android:fillAlpha="0" android:fillColor="#000000"
+        android:pathData="M143.67,82.75C154.48,57.9 154.48,58.04 154.48,58.04"
+        android:strokeColor="#000000" android:strokeWidth="2.265"/>
+</vector>
diff --git a/packages/CompanionDeviceManager/res/drawable/ic_permission_microphone.xml b/packages/CompanionDeviceManager/res/drawable/ic_permission_microphone.xml
new file mode 100644
index 0000000..eca625d
--- /dev/null
+++ b/packages/CompanionDeviceManager/res/drawable/ic_permission_microphone.xml
@@ -0,0 +1,24 @@
+<!--
+  ~ 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.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24"
+    android:tint="@android:color/system_accent1_600">
+  <path android:fillColor="@android:color/white" android:pathData="M12,14Q10.75,14 9.875,13.125Q9,12.25 9,11V5Q9,3.75 9.875,2.875Q10.75,2 12,2Q13.25,2 14.125,2.875Q15,3.75 15,5V11Q15,12.25 14.125,13.125Q13.25,14 12,14ZM12,8Q12,8 12,8Q12,8 12,8Q12,8 12,8Q12,8 12,8Q12,8 12,8Q12,8 12,8Q12,8 12,8Q12,8 12,8ZM11,21V17.925Q8.4,17.575 6.7,15.6Q5,13.625 5,11H7Q7,13.075 8.463,14.537Q9.925,16 12,16Q14.075,16 15.538,14.537Q17,13.075 17,11H19Q19,13.625 17.3,15.6Q15.6,17.575 13,17.925V21ZM12,12Q12.425,12 12.713,11.712Q13,11.425 13,11V5Q13,4.575 12.713,4.287Q12.425,4 12,4Q11.575,4 11.288,4.287Q11,4.575 11,5V11Q11,11.425 11.288,11.712Q11.575,12 12,12Z"/>
+</vector>
diff --git a/packages/CompanionDeviceManager/res/drawable/ic_permission_nearby_device_streaming.xml b/packages/CompanionDeviceManager/res/drawable/ic_permission_nearby_device_streaming.xml
new file mode 100644
index 0000000..7295e78
--- /dev/null
+++ b/packages/CompanionDeviceManager/res/drawable/ic_permission_nearby_device_streaming.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ 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.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24"
+        android:viewportHeight="24"
+        android:tint="@android:color/system_accent1_600">
+    <path
+        android:pathData="M6.2529,18.5H16.2529V17.5H18.2529V21.5C18.2529,22.6 17.3529,23.5 16.2529,23.5H6.2529C5.1529,23.5 4.2529,22.6 4.2529,21.5V3.5C4.2529,2.4 5.1529,1.51 6.2529,1.51L16.2529,1.5C17.3529,1.5 18.2529,2.4 18.2529,3.5V7.5H16.2529V6.5H6.2529V18.5ZM16.2529,3.5H6.2529V4.5H16.2529V3.5ZM6.2529,21.5V20.5H16.2529V21.5H6.2529ZM12.6553,9.4049C12.6553,8.8526 13.103,8.4049 13.6553,8.4049H20.5254C21.0776,8.4049 21.5254,8.8526 21.5254,9.4049V14.6055C21.5254,15.1578 21.0776,15.6055 20.5254,15.6055H14.355L12.6553,17.0871V9.4049Z"
+        android:fillColor="#3C4043"
+        android:fillType="evenOdd"/>
+</vector>
\ No newline at end of file
diff --git a/packages/CompanionDeviceManager/res/values/strings.xml b/packages/CompanionDeviceManager/res/values/strings.xml
index 97201e2..3b21541 100644
--- a/packages/CompanionDeviceManager/res/values/strings.xml
+++ b/packages/CompanionDeviceManager/res/values/strings.xml
@@ -36,6 +36,18 @@
     <!-- Description of the privileges the application will get if associated with the companion device of WATCH profile for singleDevice(type) [CHAR LIMIT=NONE] -->
     <string name="summary_watch_single_device">The app is needed to manage your <xliff:g id="device_name" example="My Watch">%1$s</xliff:g>. <xliff:g id="app_name" example="Android Wear">%2$s</xliff:g> will be allowed to interact with these permissions:</string>
 
+    <!-- TODO(b/256140614) To replace all glasses related strings with final versions -->
+    <!-- ================= DEVICE_PROFILE_GLASSES ================= -->
+
+    <!-- The name of the "glasses" device type [CHAR LIMIT=30] -->
+    <string name="profile_name_glasses">glasses</string>
+
+    <!-- Description of the privileges the application will get if associated with the companion device of GLASSES profile (type) [CHAR LIMIT=NONE] -->
+    <string name="summary_glasses">This app is needed to manage your <xliff:g id="device_name" example="My Glasses">%1$s</xliff:g>. <xliff:g id="app_name" example="Glasses">%2$s</xliff:g> will be allowed to access your Phone, SMS, Contacts, Microphone and Nearby devices permissions.</string>
+
+    <!-- Description of the privileges the application will get if associated with the companion device of GLASSES profile for singleDevice(type) [CHAR LIMIT=NONE] -->
+    <string name="summary_glasses_single_device">The app is needed to manage your <xliff:g id="device_name" example="My Glasses">%1$s</xliff:g>. <xliff:g id="app_name" example="Glasses">%2$s</xliff:g> will be allowed to interact with these permissions:</string>
+
     <!-- ================= DEVICE_PROFILE_APP_STREAMING ================= -->
 
     <!-- Confirmation for associating an application with a companion device of APP_STREAMING profile (type) [CHAR LIMIT=NONE] -->
@@ -69,6 +81,18 @@
     <!-- Description of the helper dialog for COMPUTER profile. [CHAR LIMIT=NONE] -->
     <string name="helper_summary_computer"><xliff:g id="app_name" example="GMS">%1$s</xliff:g> is requesting permission on behalf of your <xliff:g id="device_type" example="Chromebook">%2$s</xliff:g> to access your phone\u2019s photos, media, and notifications</string>
 
+    <!-- TODO(b/256140614) To replace all nearby_device_streaming related strings with final versions -->
+    <!-- ================= DEVICE_PROFILE_NEARBY_DEVICE_STREAMING ================= -->
+
+    <!-- Confirmation for associating an application with a companion device of NEARBY_DEVICE_STREAMING profile (type) [CHAR LIMIT=NONE] -->
+    <string name="title_nearby_device_streaming">Allow &lt;strong&gt;<xliff:g id="app_name" example="NearbyStreamer">%1$s</xliff:g>&lt;/strong&gt; to perform this action from your phone</string>
+
+    <!-- Title of the helper dialog for NEARBY_DEVICE_STREAMING profile [CHAR LIMIT=30]. -->
+    <string name="helper_title_nearby_device_streaming">Cross-device services</string>
+
+    <!-- Description of the helper dialog for NEARBY_DEVICE_STREAMING profile. [CHAR LIMIT=NONE] -->
+    <string name="helper_summary_nearby_device_streaming"><xliff:g id="app_name" example="NearbyStreamerApp">%1$s</xliff:g> is requesting permission on behalf of your <xliff:g id="device_type" example="NearbyDevice">%2$s</xliff:g> to stream content to nearby devices</string>
+
     <!-- ================= null profile ================= -->
 
     <!-- A noun for a companion device with unspecified profile (type) [CHAR LIMIT=30] -->
@@ -116,7 +140,10 @@
     <!-- Calendar permission will be granted of corresponding profile [CHAR LIMIT=30] -->
     <string name="permission_calendar">Calendar</string>
 
-    <!-- Calendar permission will be granted of corresponding profile [CHAR LIMIT=30] -->
+    <!-- Microphone permission will be granted to corresponding profile [CHAR LIMIT=30] -->
+    <string name="permission_microphone">Microphone</string>
+
+    <!-- Nearby devices permission will be granted of corresponding profile [CHAR LIMIT=30] -->
     <string name="permission_nearby_devices">Nearby devices</string>
 
     <!-- Storage permission will be granted of corresponding profile [CHAR LIMIT=30] -->
@@ -128,6 +155,9 @@
     <!-- Apps permission will be granted of corresponding profile [CHAR LIMIT=30] -->
     <string name="permission_app_streaming">Apps</string>
 
+    <!-- Nearby_device_streaming permission will be granted to the corresponding profile [CHAR LIMIT=30] -->
+    <string name="permission_nearby_device_streaming">Nearby Device Streaming</string>
+
     <!-- Description of phone permission of corresponding profile [CHAR LIMIT=NONE] -->
     <string name="permission_phone_summary">Can access your phone number and network info. Required for making calls and VoIP, voicemail, call redirect, and editing call logs</string>
 
@@ -142,6 +172,10 @@
     <!-- TODO(b/253644212) Need the description for calendar permission  -->
     <string name="permission_calendar_summary"></string>
 
+    <!-- Description of microphone permission of corresponding profile [CHAR LIMIT=NONE] -->
+    <!-- TODO(b/256140614) Need the description for microphone permission  -->
+    <string name="permission_microphone_summary">Can record audio using the microphone</string>
+
     <!-- Description of nearby devices' permission of corresponding profile [CHAR LIMIT=NONE] -->
     <!-- TODO(b/253644212) Need the description for nearby devices' permission  -->
     <string name="permission_nearby_devices_summary"></string>
@@ -155,4 +189,8 @@
     <!-- Description of storage permission of corresponding profile [CHAR LIMIT=NONE] -->
     <string name="permission_storage_summary"></string>
 
+    <!-- Description of nearby_device_streaming permission of corresponding profile [CHAR LIMIT=NONE] -->
+    <!-- TODO(b/256140614) Need the description for nearby devices' permission  -->
+    <string name="permission_nearby_device_streaming_summary">Stream content to a nearby device</string>
+
 </resources>
diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java
index 3a3a5d2..49a63345 100644
--- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java
+++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java
@@ -19,6 +19,8 @@
 import static android.companion.AssociationRequest.DEVICE_PROFILE_APP_STREAMING;
 import static android.companion.AssociationRequest.DEVICE_PROFILE_AUTOMOTIVE_PROJECTION;
 import static android.companion.AssociationRequest.DEVICE_PROFILE_COMPUTER;
+import static android.companion.AssociationRequest.DEVICE_PROFILE_GLASSES;
+import static android.companion.AssociationRequest.DEVICE_PROFILE_NEARBY_DEVICE_STREAMING;
 import static android.companion.AssociationRequest.DEVICE_PROFILE_WATCH;
 import static android.companion.CompanionDeviceManager.REASON_CANCELED;
 import static android.companion.CompanionDeviceManager.REASON_DISCOVERY_TIMEOUT;
@@ -34,7 +36,9 @@
 import static com.android.companiondevicemanager.PermissionListAdapter.PERMISSION_APP_STREAMING;
 import static com.android.companiondevicemanager.PermissionListAdapter.PERMISSION_CALENDAR;
 import static com.android.companiondevicemanager.PermissionListAdapter.PERMISSION_CONTACTS;
+import static com.android.companiondevicemanager.PermissionListAdapter.PERMISSION_MICROPHONE;
 import static com.android.companiondevicemanager.PermissionListAdapter.PERMISSION_NEARBY_DEVICES;
+import static com.android.companiondevicemanager.PermissionListAdapter.PERMISSION_NEARBY_DEVICE_STREAMING;
 import static com.android.companiondevicemanager.PermissionListAdapter.PERMISSION_NOTIFICATION;
 import static com.android.companiondevicemanager.PermissionListAdapter.PERMISSION_PHONE;
 import static com.android.companiondevicemanager.PermissionListAdapter.PERMISSION_SMS;
@@ -501,6 +505,12 @@
                 mPermissionTypes.addAll(Arrays.asList(PERMISSION_NOTIFICATION, PERMISSION_STORAGE));
                 break;
 
+            case DEVICE_PROFILE_NEARBY_DEVICE_STREAMING:
+                title = getHtmlFromResources(this, R.string.title_nearby_device_streaming,
+                        deviceName);
+                mPermissionTypes.add(PERMISSION_NEARBY_DEVICE_STREAMING);
+                break;
+
             default:
                 throw new RuntimeException("Unsupported profile " + deviceProfile);
         }
@@ -556,7 +566,7 @@
         }
 
         final String deviceName = mSelectedDevice.getDisplayName();
-        final String profileName = getString(R.string.profile_name_watch);
+        final String profileName;
         final Spanned title;
         final Spanned summary;
         final Drawable profileIcon;
@@ -569,6 +579,7 @@
             mSummary.setVisibility(View.GONE);
             mConstraintList.setVisibility(View.GONE);
         } else if (deviceProfile.equals(DEVICE_PROFILE_WATCH)) {
+            profileName = getString(R.string.profile_name_watch);
             title = getHtmlFromResources(this, R.string.confirmation_title, appLabel, deviceName);
             summary = getHtmlFromResources(
                     this, R.string.summary_watch_single_device, profileName, appLabel);
@@ -579,6 +590,18 @@
                     PERMISSION_CALENDAR, PERMISSION_NEARBY_DEVICES));
 
             setupPermissionList();
+        } else if (deviceProfile.equals(DEVICE_PROFILE_GLASSES)) {
+            profileName = getString(R.string.profile_name_glasses);
+            title = getHtmlFromResources(this, R.string.confirmation_title, appLabel, profileName);
+            summary = getHtmlFromResources(
+                    this, R.string.summary_glasses_single_device, profileName, appLabel);
+            profileIcon = getIcon(this, R.drawable.ic_glasses);
+
+            mPermissionTypes.addAll(Arrays.asList(
+                    PERMISSION_PHONE, PERMISSION_SMS, PERMISSION_CONTACTS,
+                    PERMISSION_MICROPHONE, PERMISSION_NEARBY_DEVICES));
+
+            setupPermissionList();
         } else {
             throw new RuntimeException("Unsupported profile " + deviceProfile);
         }
@@ -607,6 +630,10 @@
             profileName = getString(R.string.profile_name_watch);
             summary = getHtmlFromResources(this, R.string.summary_watch, profileName, appLabel);
             profileIcon = getIcon(this, R.drawable.ic_watch);
+        } else if (deviceProfile.equals(DEVICE_PROFILE_GLASSES)) {
+            profileName = getString(R.string.profile_name_glasses);
+            summary = getHtmlFromResources(this, R.string.summary_glasses, profileName, appLabel);
+            profileIcon = getIcon(this, R.drawable.ic_glasses);
         } else {
             throw new RuntimeException("Unsupported profile " + deviceProfile);
         }
diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionVendorHelperDialogFragment.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionVendorHelperDialogFragment.java
index 804e7577..eae14a6 100644
--- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionVendorHelperDialogFragment.java
+++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionVendorHelperDialogFragment.java
@@ -18,6 +18,7 @@
 
 import static android.companion.AssociationRequest.DEVICE_PROFILE_APP_STREAMING;
 import static android.companion.AssociationRequest.DEVICE_PROFILE_COMPUTER;
+import static android.companion.AssociationRequest.DEVICE_PROFILE_NEARBY_DEVICE_STREAMING;
 
 import static com.android.companiondevicemanager.Utils.getApplicationIcon;
 import static com.android.companiondevicemanager.Utils.getHtmlFromResources;
@@ -134,6 +135,14 @@
                         getContext(), R.string.helper_summary_computer, title, displayName);
                 break;
 
+            case DEVICE_PROFILE_NEARBY_DEVICE_STREAMING:
+                title = getHtmlFromResources(getContext(),
+                        R.string.helper_title_nearby_device_streaming);
+                summary = getHtmlFromResources(
+                        getContext(), R.string.helper_summary_nearby_device_streaming, title,
+                        displayName);
+                break;
+
             default:
                 throw new RuntimeException("Unsupported profile " + deviceProfile);
         }
diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/PermissionListAdapter.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/PermissionListAdapter.java
index 0ee94a2..00c44d6 100644
--- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/PermissionListAdapter.java
+++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/PermissionListAdapter.java
@@ -50,6 +50,8 @@
     static final int PERMISSION_CONTACTS = 5;
     static final int PERMISSION_CALENDAR = 6;
     static final int PERMISSION_NEARBY_DEVICES = 7;
+    static final int PERMISSION_NEARBY_DEVICE_STREAMING = 8;
+    static final int PERMISSION_MICROPHONE = 9;
 
     private static final Map<Integer, Integer> sTitleMap;
     static {
@@ -62,6 +64,8 @@
         map.put(PERMISSION_CONTACTS, R.string.permission_contacts);
         map.put(PERMISSION_CALENDAR, R.string.permission_calendar);
         map.put(PERMISSION_NEARBY_DEVICES, R.string.permission_nearby_devices);
+        map.put(PERMISSION_NEARBY_DEVICE_STREAMING, R.string.permission_nearby_device_streaming);
+        map.put(PERMISSION_MICROPHONE, R.string.permission_microphone);
         sTitleMap = unmodifiableMap(map);
     }
 
@@ -76,6 +80,9 @@
         map.put(PERMISSION_CONTACTS, R.string.permission_contacts_summary);
         map.put(PERMISSION_CALENDAR, R.string.permission_calendar_summary);
         map.put(PERMISSION_NEARBY_DEVICES, R.string.permission_nearby_devices_summary);
+        map.put(PERMISSION_NEARBY_DEVICE_STREAMING,
+                R.string.permission_nearby_device_streaming_summary);
+        map.put(PERMISSION_MICROPHONE, R.string.permission_microphone_summary);
         sSummaryMap = unmodifiableMap(map);
     }
 
@@ -90,6 +97,9 @@
         map.put(PERMISSION_CONTACTS, R.drawable.ic_permission_contacts);
         map.put(PERMISSION_CALENDAR, R.drawable.ic_permission_calendar);
         map.put(PERMISSION_NEARBY_DEVICES, R.drawable.ic_permission_nearby_devices);
+        map.put(PERMISSION_NEARBY_DEVICE_STREAMING,
+                R.drawable.ic_permission_nearby_device_streaming);
+        map.put(PERMISSION_MICROPHONE, R.drawable.ic_permission_microphone);
         sIconMap = unmodifiableMap(map);
     }
 
diff --git a/packages/CredentialManager/res/drawable/ic_face.xml b/packages/CredentialManager/res/drawable/ic_face.xml
deleted file mode 100644
index 16fe144..0000000
--- a/packages/CredentialManager/res/drawable/ic_face.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<!--
-  ~ 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.
-  -->
-
-<!--TODO: Testing only icon. Remove later. -->
-
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:tools="http://schemas.android.com/tools"
-        tools:ignore="VectorPath"
-        android:width="24dp"
-        android:height="24dp"
-        android:viewportWidth="24"
-        android:viewportHeight="24"
-        android:tint="?attr/colorControlNormal">
-    <path
-        android:fillColor="#808080"
-        android:pathData="M9.025,14.275Q8.5,14.275 8.125,13.9Q7.75,13.525 7.75,13Q7.75,12.475 8.125,12.1Q8.5,11.725 9.025,11.725Q9.575,11.725 9.938,12.1Q10.3,12.475 10.3,13Q10.3,13.525 9.938,13.9Q9.575,14.275 9.025,14.275ZM14.975,14.275Q14.425,14.275 14.062,13.9Q13.7,13.525 13.7,13Q13.7,12.475 14.062,12.1Q14.425,11.725 14.975,11.725Q15.5,11.725 15.875,12.1Q16.25,12.475 16.25,13Q16.25,13.525 15.875,13.9Q15.5,14.275 14.975,14.275ZM12,19.925Q15.325,19.925 17.625,17.625Q19.925,15.325 19.925,12Q19.925,11.4 19.85,10.85Q19.775,10.3 19.575,9.775Q19.05,9.9 18.538,9.962Q18.025,10.025 17.45,10.025Q15.2,10.025 13.188,9.062Q11.175,8.1 9.775,6.375Q8.975,8.3 7.5,9.712Q6.025,11.125 4.075,11.85Q4.075,11.9 4.075,11.925Q4.075,11.95 4.075,12Q4.075,15.325 6.375,17.625Q8.675,19.925 12,19.925ZM12,22.2Q9.9,22.2 8.038,21.4Q6.175,20.6 4.788,19.225Q3.4,17.85 2.6,15.988Q1.8,14.125 1.8,12Q1.8,9.875 2.6,8.012Q3.4,6.15 4.788,4.775Q6.175,3.4 8.038,2.6Q9.9,1.8 12,1.8Q14.125,1.8 15.988,2.6Q17.85,3.4 19.225,4.775Q20.6,6.15 21.4,8.012Q22.2,9.875 22.2,12Q22.2,14.125 21.4,15.988Q20.6,17.85 19.225,19.225Q17.85,20.6 15.988,21.4Q14.125,22.2 12,22.2Z"/>
-</vector>
\ No newline at end of file
diff --git a/packages/CredentialManager/res/drawable/ic_manage_accounts.xml b/packages/CredentialManager/res/drawable/ic_manage_accounts.xml
deleted file mode 100644
index adad2f1..0000000
--- a/packages/CredentialManager/res/drawable/ic_manage_accounts.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<!--
-  ~ 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.
-  -->
-
-<!--TODO: Testing only icon. Remove later. -->
-
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:tools="http://schemas.android.com/tools"
-        tools:ignore="VectorPath"
-        android:width="24dp"
-        android:height="24dp"
-        android:viewportWidth="24"
-        android:viewportHeight="24"
-        android:tint="?attr/colorControlNormal">
-    <path
-        android:fillColor="#808080"
-        android:pathData="M16.1,21.2 L15.775,19.675Q15.5,19.55 15.25,19.425Q15,19.3 14.75,19.1L13.275,19.575L12.2,17.75L13.375,16.725Q13.325,16.4 13.325,16.112Q13.325,15.825 13.375,15.5L12.2,14.475L13.275,12.65L14.75,13.1Q15,12.925 15.25,12.787Q15.5,12.65 15.775,12.55L16.1,11.025H18.25L18.55,12.55Q18.825,12.65 19.075,12.8Q19.325,12.95 19.575,13.15L21.05,12.65L22.125,14.525L20.95,15.55Q21.025,15.825 21.013,16.137Q21,16.45 20.95,16.725L22.125,17.75L21.05,19.575L19.575,19.1Q19.325,19.3 19.075,19.425Q18.825,19.55 18.55,19.675L18.25,21.2ZM1.8,20.3V17.3Q1.8,16.375 2.275,15.613Q2.75,14.85 3.5,14.475Q4.775,13.825 6.425,13.362Q8.075,12.9 10,12.9Q10.2,12.9 10.4,12.9Q10.6,12.9 10.775,12.95Q9.925,14.85 10.062,16.738Q10.2,18.625 11.4,20.3ZM17.175,18.075Q17.975,18.075 18.55,17.487Q19.125,16.9 19.125,16.1Q19.125,15.3 18.55,14.725Q17.975,14.15 17.175,14.15Q16.375,14.15 15.788,14.725Q15.2,15.3 15.2,16.1Q15.2,16.9 15.788,17.487Q16.375,18.075 17.175,18.075ZM10,11.9Q8.25,11.9 7.025,10.662Q5.8,9.425 5.8,7.7Q5.8,5.95 7.025,4.725Q8.25,3.5 10,3.5Q11.75,3.5 12.975,4.725Q14.2,5.95 14.2,7.7Q14.2,9.425 12.975,10.662Q11.75,11.9 10,11.9Z"/>
-</vector>
\ No newline at end of file
diff --git a/packages/CredentialManager/res/values-af/strings.xml b/packages/CredentialManager/res/values-af/strings.xml
index 377c13f..a548219 100644
--- a/packages/CredentialManager/res/values-af/strings.xml
+++ b/packages/CredentialManager/res/values-af/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Stoor in ’n ander plek"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Gebruik ’n ander toestel"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Stoor op ’n ander toestel"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"’n Maklike manier om veilig aan te meld"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Gebruik jou vingerafdruk, gesig of skermslot om aan te meld met ’n unieke wagwoordsleutel wat nie vergeet of gesteel kan word nie. Kom meer te wete"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Kies waar om <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Kies waar om <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"skep jou wagwoordsleutels"</string>
     <string name="save_your_password" msgid="6597736507991704307">"stoor jou wagwoord"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"stoor jou aanmeldinligting"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Stel ’n verstekwagwoordbestuurder om jou wagwoorde en wagwoordsleutels te stoor, en meld volgende keer vinniger aan."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Skep ’n wagwoordsleutel in <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Stoor jou wagwoord in <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Stoor jou aanmeldinligting in <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"wagwoordsleutel"</string>
     <string name="password" msgid="6738570945182936667">"wagwoord"</string>
     <string name="sign_ins" msgid="4710739369149469208">"aanmeldings"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Skep wagwoordsleutel in"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Stoor wagwoord in"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Stoor aanmelding in"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Skep ’n wagwoordsleutel op ’n ander toestel?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Gebruik <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> vir al jou aanmeldings?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Hierdie wagwoordbestuurder sal jou wagwoorde en wagwoordsleutels berg om jou te help om maklik aan te meld."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Stel as verstek"</string>
     <string name="use_once" msgid="9027366575315399714">"Gebruik een keer"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> wagwoorde, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> wagwoordsleutels"</string>
diff --git a/packages/CredentialManager/res/values-am/strings.xml b/packages/CredentialManager/res/values-am/strings.xml
index b80fe2c..6fdc696 100644
--- a/packages/CredentialManager/res/values-am/strings.xml
+++ b/packages/CredentialManager/res/values-am/strings.xml
@@ -3,45 +3,34 @@
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
     <!-- no translation found for app_name (4539824758261855508) -->
     <skip />
-    <!-- no translation found for string_cancel (6369133483981306063) -->
-    <skip />
-    <!-- no translation found for string_continue (1346732695941131882) -->
-    <skip />
-    <!-- no translation found for string_create_in_another_place (1033635365843437603) -->
-    <skip />
-    <!-- no translation found for string_save_to_another_place (7590325934591079193) -->
-    <skip />
-    <!-- no translation found for string_use_another_device (8754514926121520445) -->
-    <skip />
+    <string name="string_cancel" msgid="6369133483981306063">"ይቅር"</string>
+    <string name="string_continue" msgid="1346732695941131882">"ቀጥል"</string>
+    <string name="string_create_in_another_place" msgid="1033635365843437603">"በሌላ ቦታ ውስጥ ይፍጠሩ"</string>
+    <string name="string_save_to_another_place" msgid="7590325934591079193">"ወደ ሌላ ቦታ ያስቀምጡ"</string>
+    <string name="string_use_another_device" msgid="8754514926121520445">"ሌላ መሣሪያ ይጠቀሙ"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"ወደ ሌላ መሣሪያ ያስቀምጡ"</string>
-    <!-- no translation found for passkey_creation_intro_title (402553911484409884) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
-    <!-- no translation found for passkey_creation_intro_body (7493320456005579290) -->
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
     <skip />
-    <!-- no translation found for choose_provider_title (7245243990139698508) -->
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"የት <xliff:g id="CREATETYPES">%1$s</xliff:g> እንደሚሆን ይምረጡ"</string>
     <!-- no translation found for create_your_passkeys (8901224153607590596) -->
     <skip />
-    <!-- no translation found for save_your_password (6597736507991704307) -->
-    <skip />
-    <!-- no translation found for save_your_sign_in_info (7213978049817076882) -->
-    <skip />
+    <string name="save_your_password" msgid="6597736507991704307">"የይለፍ ቃልዎን ያስቀምጡ"</string>
+    <string name="save_your_sign_in_info" msgid="7213978049817076882">"የመግቢያ መረጃዎን ያስቀምጡ"</string>
     <!-- no translation found for choose_provider_body (8045759834416308059) -->
     <skip />
-    <!-- no translation found for choose_create_option_passkey_title (4146408187146573131) -->
-    <skip />
-    <!-- no translation found for choose_create_option_password_title (8812546498357380545) -->
-    <skip />
-    <!-- no translation found for choose_create_option_sign_in_title (6318246378475961834) -->
-    <skip />
-    <!-- no translation found for choose_create_option_description (4419171903963100257) -->
-    <skip />
-    <!-- no translation found for passkey (632353688396759522) -->
-    <skip />
-    <!-- no translation found for password (6738570945182936667) -->
-    <skip />
-    <!-- no translation found for sign_ins (4710739369149469208) -->
-    <skip />
+    <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"በ<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ውስጥ የይለፍ ቁልፍ ይፈጠር?"</string>
+    <string name="choose_create_option_password_title" msgid="8812546498357380545">"የይለፍ ቃልዎ ወደ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ይቀመጥ?"</string>
+    <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"የመግቢያ መረጃዎ ወደ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ይቀመጥ?"</string>
+    <string name="choose_create_option_description" msgid="4419171903963100257">"የእርስዎን <xliff:g id="APPDOMAINNAME">%1$s</xliff:g> <xliff:g id="TYPE">%2$s</xliff:g> በማንኛውም መሣሪያ ላይ መጠቀም ይችላሉ። ለ<xliff:g id="CREATEINFODISPLAYNAME">%4$s</xliff:g> ወደ <xliff:g id="PROVIDERINFODISPLAYNAME">%3$s</xliff:g> ተቀምጧል"</string>
+    <string name="passkey" msgid="632353688396759522">"የይለፍ ቁልፍ"</string>
+    <string name="password" msgid="6738570945182936667">"የይለፍ ቃል"</string>
+    <string name="sign_ins" msgid="4710739369149469208">"መግቢያዎች"</string>
     <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
     <skip />
     <!-- no translation found for save_password_to_title (3450480045270186421) -->
@@ -50,54 +39,31 @@
     <skip />
     <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
     <skip />
-    <!-- no translation found for use_provider_for_all_title (4201020195058980757) -->
-    <skip />
+    <string name="use_provider_for_all_title" msgid="4201020195058980757">"ለሁሉም መግቢያዎችዎ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>ን ይጠቀሙ?"</string>
     <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
     <skip />
-    <!-- no translation found for set_as_default (4415328591568654603) -->
-    <skip />
-    <!-- no translation found for use_once (9027366575315399714) -->
-    <skip />
-    <!-- no translation found for more_options_usage_passwords_passkeys (4794903978126339473) -->
-    <skip />
-    <!-- no translation found for more_options_usage_passwords (1632047277723187813) -->
-    <skip />
-    <!-- no translation found for more_options_usage_passkeys (5390320437243042237) -->
-    <skip />
+    <string name="set_as_default" msgid="4415328591568654603">"እንደ ነባሪ ያዋቅሩ"</string>
+    <string name="use_once" msgid="9027366575315399714">"አንዴ ይጠቀሙ"</string>
+    <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> የይለፍ ቃሎች፣ <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> የይለፍ ቁልፎች"</string>
+    <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> የይለፍ ቃሎች"</string>
+    <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> የይለፍ ቁልፎች"</string>
     <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
     <skip />
-    <!-- no translation found for another_device (5147276802037801217) -->
-    <skip />
-    <!-- no translation found for other_password_manager (565790221427004141) -->
-    <skip />
-    <!-- no translation found for close_sheet (1393792015338908262) -->
-    <skip />
-    <!-- no translation found for accessibility_back_arrow_button (3233198183497842492) -->
-    <skip />
-    <!-- no translation found for get_dialog_title_use_passkey_for (6236608872708021767) -->
-    <skip />
-    <!-- no translation found for get_dialog_title_use_sign_in_for (5283099528915572980) -->
-    <skip />
-    <!-- no translation found for get_dialog_title_choose_sign_in_for (1361715440877613701) -->
-    <skip />
-    <!-- no translation found for get_dialog_use_saved_passkey_for (4618100798664888512) -->
-    <skip />
-    <!-- no translation found for get_dialog_button_label_no_thanks (8114363019023838533) -->
-    <skip />
-    <!-- no translation found for get_dialog_button_label_continue (6446201694794283870) -->
-    <skip />
-    <!-- no translation found for get_dialog_title_sign_in_options (2092876443114893618) -->
-    <skip />
-    <!-- no translation found for get_dialog_heading_for_username (3456868514554204776) -->
-    <skip />
-    <!-- no translation found for get_dialog_heading_locked_password_managers (8911514851762862180) -->
-    <skip />
-    <!-- no translation found for locked_credential_entry_label_subtext (9213450912991988691) -->
-    <skip />
-    <!-- no translation found for get_dialog_heading_manage_sign_ins (3522556476480676782) -->
-    <skip />
-    <!-- no translation found for get_dialog_heading_from_another_device (1166697017046724072) -->
-    <skip />
-    <!-- no translation found for get_dialog_option_headline_use_a_different_device (8201578814988047549) -->
-    <skip />
+    <string name="another_device" msgid="5147276802037801217">"ሌላ መሣሪያ"</string>
+    <string name="other_password_manager" msgid="565790221427004141">"ሌሎች የይለፍ ቃል አስተዳዳሪዎች"</string>
+    <string name="close_sheet" msgid="1393792015338908262">"ሉህን ዝጋ"</string>
+    <string name="accessibility_back_arrow_button" msgid="3233198183497842492">"ወደ ቀዳሚው ገፅ ይመለሱ"</string>
+    <string name="get_dialog_title_use_passkey_for" msgid="6236608872708021767">"የተቀመጠ የይለፍ ቁልፍዎን ለ<xliff:g id="APP_NAME">%1$s</xliff:g> ይጠቀሙ?"</string>
+    <string name="get_dialog_title_use_sign_in_for" msgid="5283099528915572980">"የተቀመጠ መግቢያዎን ለ<xliff:g id="APP_NAME">%1$s</xliff:g> ይጠቀሙ?"</string>
+    <string name="get_dialog_title_choose_sign_in_for" msgid="1361715440877613701">"ለ<xliff:g id="APP_NAME">%1$s</xliff:g> የተቀመጠ መግቢያ ይጠቀሙ"</string>
+    <string name="get_dialog_use_saved_passkey_for" msgid="4618100798664888512">"በሌላ መንገድ ይግቡ"</string>
+    <string name="get_dialog_button_label_no_thanks" msgid="8114363019023838533">"አይ አመሰግናለሁ"</string>
+    <string name="get_dialog_button_label_continue" msgid="6446201694794283870">"ቀጥል"</string>
+    <string name="get_dialog_title_sign_in_options" msgid="2092876443114893618">"የመግቢያ አማራጮች"</string>
+    <string name="get_dialog_heading_for_username" msgid="3456868514554204776">"ለ<xliff:g id="USERNAME">%1$s</xliff:g>"</string>
+    <string name="get_dialog_heading_locked_password_managers" msgid="8911514851762862180">"የተቆለፉ የሚስጥር ቁልፍ አስተዳዳሪዎች"</string>
+    <string name="locked_credential_entry_label_subtext" msgid="9213450912991988691">"ለመክፈት መታ ያድርጉ"</string>
+    <string name="get_dialog_heading_manage_sign_ins" msgid="3522556476480676782">"መግቢያዎችን ያስተዳድሩ"</string>
+    <string name="get_dialog_heading_from_another_device" msgid="1166697017046724072">"ከሌላ መሣሪያ"</string>
+    <string name="get_dialog_option_headline_use_a_different_device" msgid="8201578814988047549">"የተለየ መሣሪያ ይጠቀሙ"</string>
 </resources>
diff --git a/packages/CredentialManager/res/values-ar/strings.xml b/packages/CredentialManager/res/values-ar/strings.xml
index a5c85c5..6a2c9a1 100644
--- a/packages/CredentialManager/res/values-ar/strings.xml
+++ b/packages/CredentialManager/res/values-ar/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"مدير بيانات الاعتماد"</string>
     <string name="string_cancel" msgid="6369133483981306063">"إلغاء"</string>
     <string name="string_continue" msgid="1346732695941131882">"متابعة"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"الإنشاء في مكان آخر"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"الحفظ في مكان آخر"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"استخدام جهاز آخر"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"الحفظ على جهاز آخر"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"طريقة بسيطة لتسجيل الدخول بأمان"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"استخدِم بصمة إصبعك أو وجهك أو قفل الشاشة لتسجيل الدخول باستخدام مفتاح مرور فريد لا يمكن نسيانه أو سرقته. مزيد من المعلومات"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"اختيار مكان <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"اختيار مكان <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"إنشاء مفاتيح مرورك"</string>
     <string name="save_your_password" msgid="6597736507991704307">"حفظ كلمة المرور"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"حفظ معلومات تسجيل الدخول"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"يمكنك ضبط خدمة تلقائية لـ \"مدير كلمات المرور\" من أجل حفظ كلمات المرور ومفاتيح المرور وتسجيل الدخول بشكل أسرع في المرة القادمة."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"هل تريد إنشاء مفتاح مرور في \"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>\"؟"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"هل تريد حفظ كلمة مرورك في \"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>\"؟"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"هل تريد حفظ معلومات تسجيل الدخول في \"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>\"؟"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"مفتاح مرور"</string>
     <string name="password" msgid="6738570945182936667">"كلمة المرور"</string>
     <string name="sign_ins" msgid="4710739369149469208">"عمليات تسجيل الدخول"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"إنشاء مفتاح مرور في"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"حفظ كلمة المرور في"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"حفظ معلومات تسجيل الدخول في"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"هل تريد إنشاء مفتاح مرور في جهاز آخر؟"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"هل تريد استخدام \"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>\" لكل عمليات تسجيل الدخول؟"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"سيخزِّن \"مدير كلمات المرور\" هذا كلمات المرور ومفاتيح المرور لمساعدتك في تسجيل الدخول بسهولة."</string>
     <string name="set_as_default" msgid="4415328591568654603">"ضبط الخيار كتلقائي"</string>
     <string name="use_once" msgid="9027366575315399714">"الاستخدام مرة واحدة"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"عدد كلمات المرور هو <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>، و عدد مفاتيح المرور هو <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g>"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"عدد كلمات المرور: <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"عدد مفاتيح المرور: <xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g>"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"مفتاح مرور"</string>
     <string name="another_device" msgid="5147276802037801217">"جهاز آخر"</string>
     <string name="other_password_manager" msgid="565790221427004141">"خدمات مدراء كلمات المرور الأخرى"</string>
     <string name="close_sheet" msgid="1393792015338908262">"إغلاق ورقة البيانات"</string>
diff --git a/packages/CredentialManager/res/values-as/strings.xml b/packages/CredentialManager/res/values-as/strings.xml
index 4d0ba68..7d3b5f8 100644
--- a/packages/CredentialManager/res/values-as/strings.xml
+++ b/packages/CredentialManager/res/values-as/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"অন্য ঠাইত ছেভ কৰক"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"অন্য ডিভাইচ ব্যৱহাৰ কৰক"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"অন্য এটা ডিভাইচত ছেভ কৰক"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"সুৰক্ষিতভাৱে ছাইন ইন কৰাৰ এক সৰল উপায়"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"পাহৰি নোযোৱা অথবা চুৰি কৰিব নোৱৰা এটা অদ্বিতীয় পাছকী ব্যৱহাৰ কৰি ছাইন ইন কৰিবলৈ আপোনাৰ ফিংগাৰপ্ৰিণ্ট, মুখাৱয়ব অথবা স্ক্ৰীন লক ব্যৱহাৰ কৰক। অধিক জানক"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"ক’ত <xliff:g id="CREATETYPES">%1$s</xliff:g> সেয়া বাছনি কৰক"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"ক’ত <xliff:g id="CREATETYPES">%1$s</xliff:g> সেয়া বাছনি কৰক"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"আপোনাৰ পাছকী সৃষ্টি কৰক"</string>
     <string name="save_your_password" msgid="6597736507991704307">"আপোনাৰ পাছৱৰ্ড ছেভ কৰক"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"আপোনাৰ ছাইন ইন কৰাৰ তথ্য ছেভ কৰক"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"আপোনাৰ পাছৱৰ্ড আৰু পাছকী ছেভ কৰিবলৈ এটা ডিফ’ল্ট পাছৱৰ্ড পৰিচালক ছেট কৰক আৰু পৰৱৰ্তী বাৰ দ্ৰুতভাৱে ছাইন ইন কৰক।"</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>ত পাছকী সৃষ্টি কৰিবনে?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>ত আপোনাৰ পাছৱৰ্ড ছেভ কৰিবনে?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>ত আপোনাৰ ছাইন ইন কৰাৰ তথ্য ছেভ কৰিবনে?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"পাছকী"</string>
     <string name="password" msgid="6738570945182936667">"পাছৱৰ্ড"</string>
     <string name="sign_ins" msgid="4710739369149469208">"ছাইন-ইন"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"ইয়াত পাছকী সৃষ্টি কৰক"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"ইয়াত পাছৱৰ্ড ছেভ কৰক"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"ইয়াত ছাইন ইন কৰাৰ তথ্য ছেভ কৰক"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"অন্য এটা ডিভাইচত এটা পাছকী সৃষ্টি কৰিবনে?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"আপোনাৰ আটাইবোৰ ছাইন ইনৰ বাবে <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ব্যৱহাৰ কৰিবনে?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"আপোনাক সহজে ছাইন ইন কৰাত সহায় কৰিবলৈ এই পাছৱৰ্ড পৰিচালকটোৱে আপোনাৰ পাছৱৰ্ড আৰু পাছকী ষ্ট’ৰ কৰিব।"</string>
     <string name="set_as_default" msgid="4415328591568654603">"ডিফ’ল্ট হিচাপে ছেট কৰক"</string>
     <string name="use_once" msgid="9027366575315399714">"এবাৰ ব্যৱহাৰ কৰক"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> টা পাছৱৰ্ড, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> টা পাছকী"</string>
diff --git a/packages/CredentialManager/res/values-az/strings.xml b/packages/CredentialManager/res/values-az/strings.xml
index 14313f7..45af67b 100644
--- a/packages/CredentialManager/res/values-az/strings.xml
+++ b/packages/CredentialManager/res/values-az/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Başqa yerdə yadda saxlayın"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Digər cihaz istifadə edin"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Başqa cihazda yadda saxlayın"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Təhlükəsiz daxil olmağın sadə yolu"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Unutmaq və ya oğurlamaq mümkün olmayan unikal giriş açarı ilə daxil olmaq üçün barmaq izi, üz və ya ekran kilidindən istifadə edin. Ətraflı məlumat"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> üçün yer seçin"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> üçün yer seçin"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"giriş açarları yaradın"</string>
     <string name="save_your_password" msgid="6597736507991704307">"parolunuzu yadda saxlayın"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"giriş məlumatınızı yadda saxlayın"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Parollarınızı və giriş açarlarınızı saxlamaq və növbəti dəfə daha sürətli daxil olmaq üçün defolt parol meneceri ayarlayın."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> xidmətində giriş açarı yaradılsın?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Parol <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> xidmətində saxlanılsın?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Giriş məlumatınız <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> xidmətində saxlanılsın?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"giriş açarı"</string>
     <string name="password" msgid="6738570945182936667">"parol"</string>
     <string name="sign_ins" msgid="4710739369149469208">"girişlər"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Burada giriş açarı yaradın:"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Parolu burada yadda saxlayın:"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Girişi burada yadda saxlayın:"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Başqa cihazda giriş açarı yaradılsın?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Bütün girişlər üçün <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> istifadə edilsin?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Bu parol meneceri asanlıqla daxil olmanıza kömək etmək üçün parollarınızı və giriş açarlarınızı saxlayacaq."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Defolt olaraq seçin"</string>
     <string name="use_once" msgid="9027366575315399714">"Bir dəfə istifadə edin"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> parol, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> giriş açarı"</string>
diff --git a/packages/CredentialManager/res/values-b+sr+Latn/strings.xml b/packages/CredentialManager/res/values-b+sr+Latn/strings.xml
index c58ec14..7a8e40d 100644
--- a/packages/CredentialManager/res/values-b+sr+Latn/strings.xml
+++ b/packages/CredentialManager/res/values-b+sr+Latn/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Menadžer akreditiva"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Otkaži"</string>
     <string name="string_continue" msgid="1346732695941131882">"Nastavi"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Napravi na drugom mestu"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Sačuvaj na drugom mestu"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Koristi drugi uređaj"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Sačuvaj na drugi uređaj"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Jednostavan način da se bezbedno prijavljujete"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Koristite otisak prsta, zaključavanje licem ili zaključavanje ekrana da biste se prijavili pomoću jedinstvenog pristupnog koda koji ne može da se zaboravi ili ukrade. Saznajte više"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Odaberite lokaciju za: <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Odaberite lokaciju za: <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"napravite pristupne kodove"</string>
     <string name="save_your_password" msgid="6597736507991704307">"sačuvajte lozinku"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"sačuvajte podatke o prijavljivanju"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Podesite podrazumevani menadžer lozinki da biste sačuvali lozinke i pristupne kodove i sledeći put se prijavili brže."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Želite da napravite pristupni kôd kod korisnika <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Želite da sačuvate lozinku kod korisnika <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Želite da sačuvate podatke o prijavljivanju kod korisnika <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"pristupni kôd"</string>
     <string name="password" msgid="6738570945182936667">"lozinka"</string>
     <string name="sign_ins" msgid="4710739369149469208">"prijavljivanja"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Napravite pristupni kôd u:"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Sačuvajte lozinku na:"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Sačuvajte podatke o prijavljivanju na:"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Želite da napravite pristupni kôd na drugom uređaju?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Želite da za sva prijavljivanja koristite: <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Ovaj menadžer lozinki će čuvati lozinke i pristupne kodove da biste se lako prijavljivali."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Podesi kao podrazumevano"</string>
     <string name="use_once" msgid="9027366575315399714">"Koristi jednom"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"Lozinki: <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>, pristupnih kodova:<xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g>"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"Lozinki: <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"Pristupnih kodova: <xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g>"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Pristupni kôd"</string>
     <string name="another_device" msgid="5147276802037801217">"Drugi uređaj"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Drugi menadžeri lozinki"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Zatvorite tabelu"</string>
diff --git a/packages/CredentialManager/res/values-be/strings.xml b/packages/CredentialManager/res/values-be/strings.xml
index 3c23afd..4b60244 100644
--- a/packages/CredentialManager/res/values-be/strings.xml
+++ b/packages/CredentialManager/res/values-be/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Менеджар уліковых даных"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Скасаваць"</string>
     <string name="string_continue" msgid="1346732695941131882">"Далей"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Стварыць у іншым месцы"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Захаваць у іншым месцы"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Скарыстаць іншую прыладу"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Захаваць на іншую прыладу"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Просты спосаб бяспечнага ўваходу"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Для ўваходу з унікальным ключом доступу, які нельга згубіць ці ўкрасці, можна скарыстаць адбітак пальца, распазнаванне твару ці разблакіроўку экрана. Даведацца больш"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Выберыце, дзе <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Выберыце, дзе <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"стварыць ключы доступу"</string>
     <string name="save_your_password" msgid="6597736507991704307">"захаваць пароль"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"захаваць інфармацыю пра спосаб уваходу"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Каб у далейшым хутка выконваць уваход, наладзьце стандартны менеджар пароляў для захавання вашых пароляў і ключоў доступу."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Стварыць ключ доступу ў папцы \"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>\"?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Захаваць пароль у папку \"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>\"?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Захаваць інфармацыю пра спосаб уваходу ў папку \"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>\"?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"ключ доступу"</string>
     <string name="password" msgid="6738570945182936667">"пароль"</string>
     <string name="sign_ins" msgid="4710739369149469208">"спосабы ўваходу"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Дзе стварыць ключ доступу:"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Куды захаваць пароль:"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Куды захаваць спосаб уваходу:"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Стварыць ключ доступу на іншай прыладзе?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Выкарыстоўваць папку \"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>\" для ўсіх спосабаў уваходу?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Каб вам было прасцей уваходзіць у сістэму, вашы паролі і ключы доступу будуць захоўвацца ў менеджары пароляў."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Выкарыстоўваць стандартна"</string>
     <string name="use_once" msgid="9027366575315399714">"Скарыстаць адзін раз"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"Пароляў: <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>, ключоў доступу: <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g>"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"Пароляў: <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"Ключоў доступу: <xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g>"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Ключ доступу"</string>
     <string name="another_device" msgid="5147276802037801217">"Іншая прылада"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Іншыя спосабы ўваходу"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Закрыць аркуш"</string>
diff --git a/packages/CredentialManager/res/values-bg/strings.xml b/packages/CredentialManager/res/values-bg/strings.xml
index af7eb17..302cc3a 100644
--- a/packages/CredentialManager/res/values-bg/strings.xml
+++ b/packages/CredentialManager/res/values-bg/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Мениджър на идентификационни данни"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Отказ"</string>
     <string name="string_continue" msgid="1346732695941131882">"Напред"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Създаване другаде"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Запазване на друго място"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Използване на друго устройство"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Запазване на друго устройство"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Лесен начин за безопасно влизане в профил"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Използвайте отпечатъка, лицето или опцията си за заключване на екрана, за да влизате в профила си с помощта на уникален код за достъп, който не може да бъде забравен или откраднат. Научете повече"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Изберете място за <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Изберете място за <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"създаване на кодовете ви за достъп"</string>
     <string name="save_your_password" msgid="6597736507991704307">"запазване на паролата ви"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"запазване на данните ви за вход"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Задайте основен мениджър на пароли, за да запазвате своите пароли и кодове за достъп, така че следващия път да влезете по-бързо в профила си."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Да се създаде ли код за достъп в(ъв) <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Искате ли да запазите паролата си в(ъв) <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Искате ли да запазите данните си за вход в(ъв) <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"код за достъп"</string>
     <string name="password" msgid="6738570945182936667">"парола"</string>
     <string name="sign_ins" msgid="4710739369149469208">"данни за вход"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Създаване на код за достъп в(ъв)"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Запазване на паролата в(ъв)"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Запазване на данните за вход в(ъв)"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Да се създаде ли код за достъп на друго устройство?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Да се използва ли <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> за всичките ви данни за вход?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Този мениджър на пароли ще съхранява вашите пароли и кодове за достъп, за да влизате лесно в профила си."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Задаване като основно"</string>
     <string name="use_once" msgid="9027366575315399714">"Еднократно използване"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> пароли, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> кода за достъп"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> пароли"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> кода за достъп"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Код за достъп"</string>
     <string name="another_device" msgid="5147276802037801217">"Друго устройство"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Други мениджъри на пароли"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Затваряне на таблицата"</string>
diff --git a/packages/CredentialManager/res/values-bn/strings.xml b/packages/CredentialManager/res/values-bn/strings.xml
index 152e5bd..ad0bdea 100644
--- a/packages/CredentialManager/res/values-bn/strings.xml
+++ b/packages/CredentialManager/res/values-bn/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"CredentialManager"</string>
     <string name="string_cancel" msgid="6369133483981306063">"বাতিল করুন"</string>
     <string name="string_continue" msgid="1346732695941131882">"চালিয়ে যান"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"অন্য জায়গায় তৈরি করুন"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"অন্য জায়গায় সেভ করুন"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"অন্য ডিভাইস ব্যবহার করুন"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"অন্য ডিভাইসে সেভ করুন"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"নিরাপদে সাইন-ইন করার একটি সহজ উপায়"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"একটি অনন্য পাসকী ব্যবহার করে সাইন-ইন করতে আপনার ফিঙ্গারপ্রিন্ট, মুখ বা স্ক্রিন লক ব্যবহার করুন যেটি ভুলে যাবেন না বা হারিয়ে যাবেন না। আরও জানুন"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> কোথায় সেভ করবেন তা বেছে নিন"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> কোথায় সেভ করবেন তা বেছে নিন"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"আপনার পাসকী তৈরি করা"</string>
     <string name="save_your_password" msgid="6597736507991704307">"আপনার পাসওয়ার্ড সেভ করুন"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"আপনার সাইন-ইন করা সম্পর্কিত তথ্য সেভ করুন"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"আপনার পাসওয়ার্ড ও পাসকী সেভ করার জন্য একটি ডিফল্ট Password Manager সেট করুন এবং পরবর্তী সময়ে আরও ঝটপট সাইন-ইন করুন।"</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>-এ পাসকী তৈরি করবেন?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"আপনার পাসওয়ার্ড <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>-এ সেভ করবেন?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"আপনার সাইন-ইন করা সম্পর্কিত তথ্য <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>-এ সেভ করবেন?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"পাসকী"</string>
     <string name="password" msgid="6738570945182936667">"পাসওয়ার্ড"</string>
     <string name="sign_ins" msgid="4710739369149469208">"সাইন-ইন"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"এখানে পাসকী তৈরি করুন"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"এখানে পাসওয়ার্ড সেভ করা"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"এখানে সাইন-ইন করা সম্পর্কিত ক্রেডেনশিয়াল সেভ করা"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"অন্য একটি ডিভাইসে পাসকী তৈরি করবেন?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"আপনার সব সাইন-ইনের জন্য <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ব্যবহার করবেন?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"এই Password Manager আপনার পাসওয়ার্ড ও পাসকী সেভ করবে, যাতে সহজেই সাইন-ইন করতে পারেন।"</string>
     <string name="set_as_default" msgid="4415328591568654603">"ডিফল্ট হিসেবে সেট করুন"</string>
     <string name="use_once" msgid="9027366575315399714">"একবার ব্যবহার করুন"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>টি পাসওয়ার্ড, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g>টি পাসকী"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>টি পাসওয়ার্ড"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g>টি পাসকী"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"পাসকী"</string>
     <string name="another_device" msgid="5147276802037801217">"অন্য ডিভাইস"</string>
     <string name="other_password_manager" msgid="565790221427004141">"অন্যান্য Password Manager"</string>
     <string name="close_sheet" msgid="1393792015338908262">"শিট বন্ধ করুন"</string>
diff --git a/packages/CredentialManager/res/values-bs/strings.xml b/packages/CredentialManager/res/values-bs/strings.xml
index d774b88..2a96102 100644
--- a/packages/CredentialManager/res/values-bs/strings.xml
+++ b/packages/CredentialManager/res/values-bs/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Sačuvajte na drugom mjestu"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Koristite drugi uređaj"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Sačuvajte na drugom uređaju"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Jednostavan način za sigurnu prijavu"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Koristite otisak prsta, lice ili zaključavanje ekrana da se prijavite jedinstvenim pristupnim ključem koji se ne može zaboraviti niti ukrasti. Saznajte više"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Odaberite gdje <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Odaberite gdje <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"izradite pristupne ključeve"</string>
     <string name="save_your_password" msgid="6597736507991704307">"sačuvajte lozinku"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"sačuvajte informacije za prijavu"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Postavite zadani upravitelj zaporki da biste spremili zaporke i pristupne ključeve i sljedeći put se brže prijavili."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Kreirati pristupni ključ na usluzi <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Sačuvati lozinku na usluzi <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Sačuvati informacije za prijavu na usluzi <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"pristupni ključ"</string>
     <string name="password" msgid="6738570945182936667">"lozinka"</string>
     <string name="sign_ins" msgid="4710739369149469208">"prijave"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Izradite pristupni ključ u"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Spremite zaporku na"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Spremite podatke za prijavu na"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Želite li izraditi pristupni ključ na nekom drugom uređaju?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Koristiti uslugu <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> za sve vaše prijave?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Upravitelj zaporki pohranit će vaše zaporke i pristupne ključeve radi jednostavnije prijave."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Postavi kao zadano"</string>
     <string name="use_once" msgid="9027366575315399714">"Koristi jednom"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"Broj lozinki: <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>; broj pristupnih ključeva: <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g>"</string>
diff --git a/packages/CredentialManager/res/values-ca/strings.xml b/packages/CredentialManager/res/values-ca/strings.xml
index bfd9164..8b1e395280 100644
--- a/packages/CredentialManager/res/values-ca/strings.xml
+++ b/packages/CredentialManager/res/values-ca/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Gestor de credencials"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Cancel·la"</string>
     <string name="string_continue" msgid="1346732695941131882">"Continua"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Crea en un altre lloc"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Desa en un altre lloc"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Utilitza un altre dispositiu"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Desa en un altre dispositiu"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Una manera senzilla i segura d\'iniciar la sessió"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Utilitza l\'empremta digital, la cara o el bloqueig de pantalla per iniciar la sessió amb una clau d\'accés única que no es pot oblidar ni robar. Més informació"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Tria on vols <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Tria on vols <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"crea les teves claus d\'accés"</string>
     <string name="save_your_password" msgid="6597736507991704307">"desar la contrasenya"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"desar la teva informació d\'inici de sessió"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Defineix un gestor de contrasenyes predeterminat per desar les teves contrasenyes i claus d\'accés d\'una manera més ràpida la pròxima vegada."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Vols crear una clau d\'accés a <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Vols desar la contrasenya a <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Vols desar la teva informació d\'inici de sessió a <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"clau d\'accés"</string>
     <string name="password" msgid="6738570945182936667">"contrasenya"</string>
     <string name="sign_ins" msgid="4710739369149469208">"inicis de sessió"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Crea una clau d\'accés a"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Desa la contrasenya a"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Desa l\'inici de sessió a"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Vols crear una clau d\'accés en un altre dispositiu?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Vols utilitzar <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> per a tots els teus inicis de sessió?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Aquest gestor de contrasenyes emmagatzemarà les teves contrasenyes i claus d\'accés per ajudar-te a iniciar la sessió fàcilment."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Estableix com a predeterminada"</string>
     <string name="use_once" msgid="9027366575315399714">"Utilitza un cop"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> contrasenyes, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> claus d\'accés"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> contrasenyes"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> claus d\'accés"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Clau d\'accés"</string>
     <string name="another_device" msgid="5147276802037801217">"Un altre dispositiu"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Altres gestors de contrasenyes"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Tanca el full"</string>
diff --git a/packages/CredentialManager/res/values-cs/strings.xml b/packages/CredentialManager/res/values-cs/strings.xml
index 72a5f98..b032033 100644
--- a/packages/CredentialManager/res/values-cs/strings.xml
+++ b/packages/CredentialManager/res/values-cs/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Správce oprávnění"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Zrušit"</string>
     <string name="string_continue" msgid="1346732695941131882">"Pokračovat"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Vytvořit na jiném místě"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Uložit na jiné místo"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Použít jiné zařízení"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Uložit do jiného zařízení"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Jednoduchý způsob, jak se bezpečně přihlásit"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Použijte svůj otisk prstu, obličej nebo zámek obrazovky k přihlášení pomocí jedinečného přístupového klíče, který nemůžete zapomenout a který vám nikdo nemůže odcizit. Další informace"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Zvolte, kde <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Zvolte, kde <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"vytvářet přístupové klíče"</string>
     <string name="save_your_password" msgid="6597736507991704307">"uložte si heslo"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"uložte své přihlašovací údaje"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Nastavte si výchozího správce hesel, do kterého si budete ukládat hesla a přístupové klíče za účelem rychlejšího přihlašování."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Vytvořit přístupový klíč v <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Uložit heslo do <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Uložit přihlašovací údaje do <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"přístupový klíč"</string>
     <string name="password" msgid="6738570945182936667">"heslo"</string>
     <string name="sign_ins" msgid="4710739369149469208">"přihlášení"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Vytvořit přístupový klíč v"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Uložit heslo do účtu"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Uložit přihlášení do"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Vytvořit přístupový klíč v jiném zařízení?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Používat <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> pro všechna přihlášení?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Tento správce hesel bude ukládat vaše hesla a přístupové klíče, abyste se mohli snadno přihlásit."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Nastavit jako výchozí"</string>
     <string name="use_once" msgid="9027366575315399714">"Použít jednou"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"Počet hesel: <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>, počet přístupových klíčů: <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g>"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"Počet hesel: <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"Počet přístupových klíčů: <xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g>"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Přístupový klíč"</string>
     <string name="another_device" msgid="5147276802037801217">"Jiné zařízení"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Další správci hesel"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Zavřít list"</string>
diff --git a/packages/CredentialManager/res/values-da/strings.xml b/packages/CredentialManager/res/values-da/strings.xml
index a05137e..0c63af5 100644
--- a/packages/CredentialManager/res/values-da/strings.xml
+++ b/packages/CredentialManager/res/values-da/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Loginstyring"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Annuller"</string>
     <string name="string_continue" msgid="1346732695941131882">"Fortsæt"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Opret et andet sted"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Gem et andet sted"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Brug en anden enhed"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Gem på en anden enhed"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"En nemmere og mere sikker måde at logge ind på"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Brug dit fingeraftryk, dit ansigt eller din skærmlås for at logge ind med en unik adgangsnøgle, der hverken kan glemmes eller stjæles. Få flere oplysninger"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Vælg, hvor du vil <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Vælg, hvor du vil <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"oprette dine adgangsnøgler"</string>
     <string name="save_your_password" msgid="6597736507991704307">"gem din adgangskode"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"gem dine loginoplysninger"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Angiv en standardadgangskodeadministrator for at gemme dine adgangskoder og adgangsnøgler og logge hurtigere ind næste gang."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Vil du oprette en adgangsnøgle i <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Vil du gemme din adgangskode i <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Vil du gemme dine loginoplysninger i <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"adgangsnøgle"</string>
     <string name="password" msgid="6738570945182936667">"adgangskode"</string>
     <string name="sign_ins" msgid="4710739369149469208">"loginmetoder"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Opret adgangsnøgle i"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Gem adgangskode i"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Gem loginmetode i"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Vil du oprette en adgangsnøgle i en anden enhed?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Vil du bruge <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> til alle dine loginmetoder?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Denne adgangskodeadministrator gemmer dine adgangskoder og adgangsnøgler for at hjælpe dig med nemt at logge ind."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Angiv som standard"</string>
     <string name="use_once" msgid="9027366575315399714">"Brug én gang"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> adgangskoder, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> adgangsnøgler"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> adgangskoder"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> adgangsnøgler"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Adgangsnøgle"</string>
     <string name="another_device" msgid="5147276802037801217">"En anden enhed"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Andre adgangskodeadministratorer"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Luk arket"</string>
diff --git a/packages/CredentialManager/res/values-de/strings.xml b/packages/CredentialManager/res/values-de/strings.xml
index fa1e8f1..7d50aed 100644
--- a/packages/CredentialManager/res/values-de/strings.xml
+++ b/packages/CredentialManager/res/values-de/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"An anderem Ort speichern"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Anderes Gerät verwenden"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Auf einem anderen Gerät speichern"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Einfach und sicher anmelden"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Verwende deinen Fingerabdruck oder deine Gesichts- bzw. Displaysperre, um dich mit einem eindeutigen Passkey anzumelden, der nicht vergessen oder gestohlen werden kann. Weitere Informationen"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Ort auswählen für: <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Ort auswählen für: <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"Passkeys erstellen"</string>
     <string name="save_your_password" msgid="6597736507991704307">"Passwort speichern"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"Anmeldedaten speichern"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Du kannst einen Passwortmanager festlegen, der standardmäßig zum Speichern deiner Passwörter und Passkeys verwendet wird, damit du dich das nächste Mal schneller anmelden kannst."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Passkey hier erstellen: <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Passwort hier speichern: <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Anmeldedaten hier speichern: <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"Passkey"</string>
     <string name="password" msgid="6738570945182936667">"Passwort"</string>
     <string name="sign_ins" msgid="4710739369149469208">"Anmeldungen"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Passkey hier erstellen:"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Passwort hier speichern:"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Anmeldedaten hier speichern:"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Passkey auf anderem Gerät erstellen?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> für alle Anmeldungen verwenden?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Mit diesem Passwortmanager werden deine Passwörter und Passkeys gespeichert, damit du dich problemlos anmelden kannst."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Als Standard festlegen"</string>
     <string name="use_once" msgid="9027366575315399714">"Einmal verwenden"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> Passwörter, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> Passkeys"</string>
diff --git a/packages/CredentialManager/res/values-el/strings.xml b/packages/CredentialManager/res/values-el/strings.xml
index 706d9f3..a088d1d 100644
--- a/packages/CredentialManager/res/values-el/strings.xml
+++ b/packages/CredentialManager/res/values-el/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Αποθήκευση σε άλλη θέση"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Χρήση άλλης συσκευής"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Αποθήκευση σε άλλη συσκευή"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Ένας απλός τρόπος για ασφαλή σύνδεση"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Χρησιμοποιήστε το δακτυλικό αποτύπωμα, το πρόσωπο ή το κλείδωμα οθόνης σας για να συνδεθείτε με ένα μοναδικό κλειδί πρόσβασης που δεν είναι δυνατό να ξεχάσετε ή να κλαπεί. Μάθετε περισσότερα"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Επιλέξτε θέση για <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Επιλέξτε θέση για <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"δημιουργήστε τα κλειδιά πρόσβασής σας"</string>
     <string name="save_your_password" msgid="6597736507991704307">"αποθήκευση του κωδικού πρόσβασής σας"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"αποθήκευση των στοιχείων σύνδεσής σας"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Για να συνδέεστε πιο γρήγορα, ορίστε ένα προεπιλεγμένο πρόγραμμα διαχείρισης κωδικών πρόσβασης για να αποθηκεύετε τους κωδικούς και τα κλειδιά πρόσβασής σας."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Να δημιουργηθει κλειδί πρόσβασης στο <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>;"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Να αποθηκευτεί ο κωδικός πρόσβασής σας στο <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>;"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Να αποθηκευτούν τα στοιχεία σύνδεσής σας στο <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>;"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"κλειδί πρόσβασης"</string>
     <string name="password" msgid="6738570945182936667">"κωδικός πρόσβασης"</string>
     <string name="sign_ins" msgid="4710739369149469208">"στοιχεία σύνδεσης"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Δημιουργία κλειδιού πρόσβασης σε"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Αποθήκευση κωδικού πρόσβασης σε"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Αποθήκευση στοιχείων σύνδεσης σε"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Δημιουργία κλειδιού πρόσβασης σε άλλη συσκευή;"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Να χρησιμοποιηθεί το <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> για όλες τις συνδέσεις σας;"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Αυτός ο διαχειριστής κωδικών πρόσβασης θα αποθηκεύει τους κωδικούς πρόσβασης και τα κλειδιά πρόσβασης, για να συνδέεστε εύκολα."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Ορισμός ως προεπιλογής"</string>
     <string name="use_once" msgid="9027366575315399714">"Χρήση μία φορά"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> κωδικοί πρόσβασης, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> κλειδιά πρόσβασης"</string>
diff --git a/packages/CredentialManager/res/values-en-rAU/strings.xml b/packages/CredentialManager/res/values-en-rAU/strings.xml
index 7adeded..a9a6f02 100644
--- a/packages/CredentialManager/res/values-en-rAU/strings.xml
+++ b/packages/CredentialManager/res/values-en-rAU/strings.xml
@@ -8,8 +8,14 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Save to another place"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Use another device"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Save to another device"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"A simple way to sign in safely"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Use your fingerprint, face or screen lock to sign in with a unique passkey that can’t be forgotten or stolen. Learn more"</string>
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
     <string name="choose_provider_title" msgid="7245243990139698508">"Choose where to <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
     <string name="create_your_passkeys" msgid="8901224153607590596">"create your passkeys"</string>
     <string name="save_your_password" msgid="6597736507991704307">"save your password"</string>
diff --git a/packages/CredentialManager/res/values-en-rCA/strings.xml b/packages/CredentialManager/res/values-en-rCA/strings.xml
index 8a8b884..c895a41 100644
--- a/packages/CredentialManager/res/values-en-rCA/strings.xml
+++ b/packages/CredentialManager/res/values-en-rCA/strings.xml
@@ -8,8 +8,10 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Save to another place"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Use another device"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Save to another device"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"A simple way to sign in safely"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Use your fingerprint, face or screen lock to sign in with a unique passkey that can’t be forgotten or stolen. Learn more"</string>
+    <string name="passkey_creation_intro_title" msgid="4251037543787718844">"Safer with passkeys"</string>
+    <string name="passkey_creation_intro_body_password" msgid="312712407571126228">"No need to create or remember complex passwords"</string>
+    <string name="passkey_creation_intro_body_fingerprint" msgid="691816235541508203">"Use your fingerprint, face, or screen lock to create a unique passkey"</string>
+    <string name="passkey_creation_intro_body_device" msgid="477121861162321129">"Passkeys are saved to a password manager, so you can sign in on other devices"</string>
     <string name="choose_provider_title" msgid="7245243990139698508">"Choose where to <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
     <string name="create_your_passkeys" msgid="8901224153607590596">"create your passkeys"</string>
     <string name="save_your_password" msgid="6597736507991704307">"save your password"</string>
diff --git a/packages/CredentialManager/res/values-en-rGB/strings.xml b/packages/CredentialManager/res/values-en-rGB/strings.xml
index 7adeded..a9a6f02 100644
--- a/packages/CredentialManager/res/values-en-rGB/strings.xml
+++ b/packages/CredentialManager/res/values-en-rGB/strings.xml
@@ -8,8 +8,14 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Save to another place"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Use another device"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Save to another device"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"A simple way to sign in safely"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Use your fingerprint, face or screen lock to sign in with a unique passkey that can’t be forgotten or stolen. Learn more"</string>
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
     <string name="choose_provider_title" msgid="7245243990139698508">"Choose where to <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
     <string name="create_your_passkeys" msgid="8901224153607590596">"create your passkeys"</string>
     <string name="save_your_password" msgid="6597736507991704307">"save your password"</string>
diff --git a/packages/CredentialManager/res/values-en-rIN/strings.xml b/packages/CredentialManager/res/values-en-rIN/strings.xml
index 7adeded..a9a6f02 100644
--- a/packages/CredentialManager/res/values-en-rIN/strings.xml
+++ b/packages/CredentialManager/res/values-en-rIN/strings.xml
@@ -8,8 +8,14 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Save to another place"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Use another device"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Save to another device"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"A simple way to sign in safely"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Use your fingerprint, face or screen lock to sign in with a unique passkey that can’t be forgotten or stolen. Learn more"</string>
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
     <string name="choose_provider_title" msgid="7245243990139698508">"Choose where to <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
     <string name="create_your_passkeys" msgid="8901224153607590596">"create your passkeys"</string>
     <string name="save_your_password" msgid="6597736507991704307">"save your password"</string>
diff --git a/packages/CredentialManager/res/values-en-rXC/strings.xml b/packages/CredentialManager/res/values-en-rXC/strings.xml
index 85e94df..efa0633 100644
--- a/packages/CredentialManager/res/values-en-rXC/strings.xml
+++ b/packages/CredentialManager/res/values-en-rXC/strings.xml
@@ -8,8 +8,10 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‎‏‏‏‏‏‏‏‏‏‎‏‎‎‏‎‏‎‏‎‏‏‎‎‏‎‎‎‎‎‏‎‎‏‏‏‎‎‎‏‏‏‎‎‏‎‎‏‎‏‏‏‏‎‎‎‏‏‏‎‎‏‏‎‎‎‏‏‎‎‏‎Save to another place‎‏‎‎‏‎"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‎‏‏‏‏‏‏‏‏‏‏‏‎‎‏‎‏‏‏‏‏‏‎‎‏‎‎‏‎‎‎‏‏‏‏‎‎‎‏‎‎‏‎‎‎‎‎‎‏‎‏‎‏‎‎‎‎‎‎‏‏‎‏‎‎‏‏‏‏‎‏‎Use another device‎‏‎‎‏‎"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‎‏‏‏‏‏‎‏‏‏‎‏‏‎‎‏‏‎‎‎‏‏‏‎‎‎‎‏‏‏‎‏‏‏‏‏‏‏‏‏‏‎‎‏‏‏‎‎‎‏‏‎‏‏‎‏‎‏‏‎‎‎‏‎‏‏‎‏‎‎Save to another device‎‏‎‎‏‎"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‎‏‏‏‏‎‏‏‏‎‏‏‎‎‏‎‏‏‎‎‎‏‎‏‎‎‎‏‎‏‎‎‏‏‎‎‏‎‏‎‎‎‎‏‏‏‏‏‎‎‎‏‏‏‎‏‎‎‎‎‎‎‏‏‏‎‎‎A simple way to sign in safely‎‏‎‎‏‎"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‎‏‏‏‏‏‏‏‏‏‎‎‏‏‏‏‏‏‏‏‏‎‏‏‎‎‏‏‏‏‏‎‏‎‎‎‎‎‎‏‏‏‎‎‎‎‎‎‏‏‎‎‎‎‏‎‏‏‏‎‎‏‎‎‎‎‏‏‎‏‎‎Use your fingerprint, face or screen lock to sign in with a unique passkey that can’t be forgotten or stolen. Learn more‎‏‎‎‏‎"</string>
+    <string name="passkey_creation_intro_title" msgid="4251037543787718844">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‎‏‏‏‏‏‏‎‏‏‏‎‏‎‏‏‏‏‏‏‏‎‏‎‏‏‏‎‎‎‎‎‎‏‏‏‏‏‏‎‎‎‎‏‎‎‎‏‎‏‎‎‎‎‏‏‏‎‏‎‎‎‏‎‏‏‏‏‎‎‎Safer with passkeys‎‏‎‎‏‎"</string>
+    <string name="passkey_creation_intro_body_password" msgid="312712407571126228">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‎‏‏‏‏‎‏‏‏‎‎‎‏‎‏‎‏‏‎‏‏‏‏‏‎‏‎‎‏‎‎‎‏‏‏‎‎‏‎‎‎‏‎‎‎‏‎‎‎‏‎‎‏‎‏‎‏‏‏‏‏‎‏‎‏‎‎‎No need to create or remember complex passwords‎‏‎‎‏‎"</string>
+    <string name="passkey_creation_intro_body_fingerprint" msgid="691816235541508203">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‎‏‏‏‏‏‎‎‏‎‎‏‏‎‎‏‏‎‎‏‏‏‎‏‎‎‏‏‎‎‏‏‎‎‏‏‎‏‏‎‏‎‎‏‎‏‎‎‏‏‎‎‏‎‏‏‎‎‎‎‎‏‏‎‏‎‏‏‎Use your fingerprint, face, or screen lock to create a unique passkey‎‏‎‎‏‎"</string>
+    <string name="passkey_creation_intro_body_device" msgid="477121861162321129">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‎‏‏‏‏‎‏‏‏‏‎‏‎‎‏‏‏‏‏‎‎‎‏‎‎‏‏‏‏‎‎‏‏‏‎‎‎‎‎‏‎‎‏‎‎‏‎‎‏‏‏‎‏‎‎‎‏‎‎‏‏‏‎‏‎‎‏‎Passkeys are saved to a password manager, so you can sign in on other devices‎‏‎‎‏‎"</string>
     <string name="choose_provider_title" msgid="7245243990139698508">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‎‏‏‏‏‏‏‏‏‏‎‎‏‎‎‏‎‎‎‏‏‎‎‎‏‎‎‎‏‏‏‎‎‎‎‎‏‎‏‏‎‏‎‎‏‏‏‎‏‎‎‏‏‏‏‎‏‏‏‏‏‎‏‎‏‎‎‏‏‎‎‎Choose where to ‎‏‎‎‏‏‎<xliff:g id="CREATETYPES">%1$s</xliff:g>‎‏‎‎‏‏‏‎‎‏‎‎‏‎"</string>
     <string name="create_your_passkeys" msgid="8901224153607590596">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‎‏‏‏‏‏‏‏‏‏‏‏‎‏‏‏‎‎‎‎‏‏‏‏‎‎‎‎‎‎‎‎‎‏‏‎‏‎‎‏‏‏‏‏‏‎‏‏‏‏‎‏‎‎‎‎‏‎‏‎‎‏‎‏‏‎‎‎‏‎‎‎create your passkeys‎‏‎‎‏‎"</string>
     <string name="save_your_password" msgid="6597736507991704307">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‎‏‏‏‏‏‏‏‏‎‏‏‎‏‏‏‎‎‎‏‏‏‏‏‏‎‏‏‏‏‎‎‏‏‎‎‏‎‏‏‏‎‏‎‎‎‎‎‏‏‏‏‎‎‎‏‏‎‎‎‎‏‎‏‏‏‏‎‎‏‏‎save your password‎‏‎‎‏‎"</string>
diff --git a/packages/CredentialManager/res/values-es-rUS/strings.xml b/packages/CredentialManager/res/values-es-rUS/strings.xml
index 5b8e442..21f0720 100644
--- a/packages/CredentialManager/res/values-es-rUS/strings.xml
+++ b/packages/CredentialManager/res/values-es-rUS/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Guardar en otra ubicación"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Usar otro dispositivo"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Guardar en otro dispositivo"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Un modo simple y seguro de ingresar"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Usa tu huella dactilar, tu rostro o el bloqueo de pantalla para acceder con una llave de acceso única que no olvidarás ni podrán robarte. Más información"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Elige dónde <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Elige dónde <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"crea tus llaves de acceso"</string>
     <string name="save_your_password" msgid="6597736507991704307">"guardar tu contraseña"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"guardar tu información de acceso"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Configura un administrador de contraseñas predeterminado para guardar tus contraseñas y llaves de acceso, y acceder más rápido la próxima vez."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"¿Quieres crear una llave de acceso en <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"¿Quieres guardar tu contraseña de <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"¿Quieres guardar tu información de acceso a <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"llave de acceso"</string>
     <string name="password" msgid="6738570945182936667">"contraseña"</string>
     <string name="sign_ins" msgid="4710739369149469208">"accesos"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Crear llave de acceso en"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Guardar contraseña en"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Guardar acceso en"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"¿Quieres crear una llave de acceso en otro dispositivo?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"¿Quieres usar <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> para todos tus accesos?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Este administrador de contraseñas almacenará tus contraseñas y llaves de acceso para ayudarte a acceder fácilmente."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Establecer como predeterminado"</string>
     <string name="use_once" msgid="9027366575315399714">"Usar una vez"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> llaves de acceso, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> contraseñas"</string>
diff --git a/packages/CredentialManager/res/values-es/strings.xml b/packages/CredentialManager/res/values-es/strings.xml
index 19fde72..409bdac 100644
--- a/packages/CredentialManager/res/values-es/strings.xml
+++ b/packages/CredentialManager/res/values-es/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Gestor de credenciales"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Cancelar"</string>
     <string name="string_continue" msgid="1346732695941131882">"Continuar"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Crear en otro lugar"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Guardar en otro lugar"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Usar otro dispositivo"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Guardar en otro dispositivo"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Una forma sencilla y segura de iniciar sesión"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Usa la huella digital, la cara o el bloqueo de pantalla para iniciar sesión con una llave de acceso única que no se puede olvidar ni robar. Más información"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Elige dónde <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Elige dónde <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"crea tus llaves de acceso"</string>
     <string name="save_your_password" msgid="6597736507991704307">"guardar tu contraseña"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"guardar tu información de inicio de sesión"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Define un gestor de contraseñas predeterminado para guardar tus contraseñas y llaves de acceso e iniciar sesión más rápido la próxima vez."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"¿Crear una llave de acceso en <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"¿Guardar tu contraseña en <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"¿Guardar tu información de inicio de sesión en <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"llave de acceso"</string>
     <string name="password" msgid="6738570945182936667">"contraseña"</string>
     <string name="sign_ins" msgid="4710739369149469208">"inicios de sesión"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Crear llave de acceso en"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Guardar contraseña en"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Guardar inicio de sesión en"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"¿Crear una llave de acceso en otro dispositivo?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"¿Usar <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> para todos tus inicios de sesión?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Este gestor de contraseñas almacenará tus contraseñas y llaves de acceso para que puedas iniciar sesión fácilmente."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Fijar como predeterminado"</string>
     <string name="use_once" msgid="9027366575315399714">"Usar una vez"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> contraseñas, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> llaves de acceso"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> contraseñas"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> llaves de acceso"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Llave de acceso"</string>
     <string name="another_device" msgid="5147276802037801217">"Otro dispositivo"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Otros gestores de contraseñas"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Cerrar hoja"</string>
diff --git a/packages/CredentialManager/res/values-et/strings.xml b/packages/CredentialManager/res/values-et/strings.xml
index 5b1b070..bfaec78 100644
--- a/packages/CredentialManager/res/values-et/strings.xml
+++ b/packages/CredentialManager/res/values-et/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Mandaatide haldur"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Tühista"</string>
     <string name="string_continue" msgid="1346732695941131882">"Jätka"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Loo teises kohas"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Salvesta teise kohta"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Kasuta teist seadet"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Salvesta teise seadmesse"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Lihtne viis turvaliselt sisselogimiseks"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Kasutage sõrmejälge, nägu või ekraanilukku, et logida sisse unikaalse pääsuvõtmega, mida ei saa unustada ega varastada. Lisateave"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Valige, kus <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Valige, kus <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"looge oma pääsuvõtmed"</string>
     <string name="save_your_password" msgid="6597736507991704307">"parool salvestada"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"sisselogimisandmed salvestada"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Määrake vaikeparoolihaldur, et oma paroolid ja pääsuvõtmed salvestada ning järgmisel korral kiiremini sisse logida."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Kas luua teenuses <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> pääsuvõti?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Kas salvestada parool teenusesse <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Kas salvestada sisselogimisteave teenusesse <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"pääsukood"</string>
     <string name="password" msgid="6738570945182936667">"parool"</string>
     <string name="sign_ins" msgid="4710739369149469208">"sisselogimisandmed"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Loo pääsuvõti:"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Salvesta parool:"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Salvesta sisselogimisandmed:"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Kas luua pääsuvõti teises seadmes?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Kas kasutada teenust <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> kõigi teie sisselogimisandmete puhul?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"See paroolihaldur salvestab teie paroolid ja pääsuvõtmed, et aidata teil hõlpsalt sisse logida."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Määra vaikeseadeks"</string>
     <string name="use_once" msgid="9027366575315399714">"Kasuta ühe korra"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> parooli, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> pääsuvõtit"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> parooli"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> pääsuvõtit"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Pääsukood"</string>
     <string name="another_device" msgid="5147276802037801217">"Teine seade"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Muud paroolihaldurid"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Sule leht"</string>
diff --git a/packages/CredentialManager/res/values-eu/strings.xml b/packages/CredentialManager/res/values-eu/strings.xml
index b2c1fe5..5a1494b 100644
--- a/packages/CredentialManager/res/values-eu/strings.xml
+++ b/packages/CredentialManager/res/values-eu/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Kredentzialen kudeatzailea"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Utzi"</string>
     <string name="string_continue" msgid="1346732695941131882">"Egin aurrera"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Sortu beste toki batean"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Gorde beste toki batean"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Erabili beste gailu bat"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Gorde beste gailu batean"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Segurtasun osoz saioa hasteko modu erraza"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Erabili hatz-marka, aurpegia edo pantailaren blokeoa ahaztu edo lapurtu ezin den sarbide-gako baten bidez saioa hasteko. Lortu informazio gehiago"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Aukeratu non <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Aukeratu non <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"sortu sarbide-gakoak"</string>
     <string name="save_your_password" msgid="6597736507991704307">"gorde pasahitza"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"gorde kredentzialei buruzko informazioa"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Ezarri pasahitz-kudeatzaile lehenetsia pasahitzak eta sarbide-gakoak gordetzeko, eta hurrengoan saioa bizkorrago hasteko."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Sarbide-gako bat sortu nahi duzu <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> aplikazioan?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Pasahitza <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> aplikazioan gorde nahi duzu?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Kredentzialei buruzko informazioa <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> aplikazioan gorde nahi duzu?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"sarbide-gakoa"</string>
     <string name="password" msgid="6738570945182936667">"pasahitza"</string>
     <string name="sign_ins" msgid="4710739369149469208">"kredentzialak"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Sortu sarbide-gako bat hemen:"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Gorde pasahitza hemen:"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Gorde kredentzialak hemen:"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Sarbide-gako bat sortu nahi duzu beste gailu batean?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> erabili nahi duzu kredentzial guztietarako?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Pasahitz-kudeatzaile honek pasahitzak eta sarbide-gakoak gordeko ditu saioa erraz has dezazun."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Ezarri lehenetsi gisa"</string>
     <string name="use_once" msgid="9027366575315399714">"Erabili behin"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> pasahitz eta <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> sarbide-gako"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> pasahitz"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> sarbide-gako"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Sarbide-gakoa"</string>
     <string name="another_device" msgid="5147276802037801217">"Beste gailu bat"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Beste pasahitz-kudeatzaile batzuk"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Itxi orria"</string>
diff --git a/packages/CredentialManager/res/values-fa/strings.xml b/packages/CredentialManager/res/values-fa/strings.xml
index 98b487c..065bde4 100644
--- a/packages/CredentialManager/res/values-fa/strings.xml
+++ b/packages/CredentialManager/res/values-fa/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"مدیر اعتبارنامه"</string>
     <string name="string_cancel" msgid="6369133483981306063">"لغو"</string>
     <string name="string_continue" msgid="1346732695941131882">"ادامه"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"ایجاد در مکانی دیگر"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"ذخیره در مکانی دیگر"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"استفاده از دستگاهی دیگر"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"ذخیره در دستگاهی دیگر"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"روشی ساده برای ورود به سیستم ایمن"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"برای ورود به سیستم با گذرکلیدی یکتا که غیرقابل فراموش شدن یا دزدیده شدن باشد، از اثر انگشت، چهره، یا قفل صفحه استفاده کنید. بیشتر بدانید"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"انتخاب محل <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"انتخاب محل <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"ایجاد گذرکلید"</string>
     <string name="save_your_password" msgid="6597736507991704307">"ذخیره گذرواژه"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"ذخیره اطلاعات ورود به سیستم"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"برای ذخیره کردن گذرواژه‌ها و گذرکلیدهایتان، مدیر گذرواژه پیش‌فرض تنظیم کنید تا دفعه بعدی سریع‌تر به سیستم وارد شوید."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"گذرکلید در <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ایجاد شود؟"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"گذرواژه در <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ذخیره شود؟"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"اطلاعات ورود به سیستم در <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ذخیره شود؟"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"گذرکلید"</string>
     <string name="password" msgid="6738570945182936667">"گذرواژه"</string>
     <string name="sign_ins" msgid="4710739369149469208">"ورود به سیستم‌ها"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"ایجاد گذرکلید در"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"ذخیره گذرواژه در"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"ذخیره ورود به سیستم در"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"گذرکلید در دستگاهی دیگر ایجاد شود؟"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"از <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> برای همه ورود به سیستم‌ها استفاده شود؟"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"این مدیر گذرواژه گذرکلیدها و گذرواژه‌های شما را ذخیره خواهد کرد تا به‌راحتی بتوانید به سیستم وارد شوید."</string>
     <string name="set_as_default" msgid="4415328591568654603">"تنظیم به‌عنوان پیش‌فرض"</string>
     <string name="use_once" msgid="9027366575315399714">"یک‌بار استفاده"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> گذرواژه، <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> گذرکلید"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> گذرواژه"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> گذرکلید"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"گذرکلید"</string>
     <string name="another_device" msgid="5147276802037801217">"دستگاهی دیگر"</string>
     <string name="other_password_manager" msgid="565790221427004141">"دیگر مدیران گذرواژه"</string>
     <string name="close_sheet" msgid="1393792015338908262">"بستن برگ"</string>
diff --git a/packages/CredentialManager/res/values-fi/strings.xml b/packages/CredentialManager/res/values-fi/strings.xml
index 9ad178a..cbea24be 100644
--- a/packages/CredentialManager/res/values-fi/strings.xml
+++ b/packages/CredentialManager/res/values-fi/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Kirjautumistietojen hallinta"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Peru"</string>
     <string name="string_continue" msgid="1346732695941131882">"Jatka"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Luo muualla"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Tallenna muualle"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Käytä toista laitetta"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Tallenna toiselle laitteelle"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Helppo tapa kirjautua turvallisesti sisään"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Käytä sormenjälkeä, kasvoja tai näytön lukitusta, niin voit kirjautua sisään yksilöllisellä avainkoodilla, jota ei voi unohtaa tai varastaa. Lue lisää"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Valitse paikka: <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Valitse paikka: <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"luo avainkoodeja"</string>
     <string name="save_your_password" msgid="6597736507991704307">"tallenna salasanasi"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"tallenna kirjautumistiedot"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Aseta salasanojen ylläpidolle oletustyökalu, niin voit tallentaa salasanat ja avainkoodit sekä kirjautua sisään nopeammin ensi kerralla."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Luodaanko avainkoodi (<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>)?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Tallennetaanko salasanasi tänne: <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Tallennetaanko kirjautumistietosi tänne: <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"avainkoodi"</string>
     <string name="password" msgid="6738570945182936667">"salasana"</string>
     <string name="sign_ins" msgid="4710739369149469208">"sisäänkirjautumiset"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Luo avainkoodi tänne:"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Tallenna salasana tänne:"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Tallenna kirjautumistiedot tänne:"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Luodaanko avainkoodi toisella laitteella?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Otetaanko <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> käyttöön kaikissa sisäänkirjautumisissa?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Tämä salasanojen ylläpitotyökalu tallentaa salasanat ja avainkoodit, jotta voit kirjautua helposti sisään."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Aseta oletukseksi"</string>
     <string name="use_once" msgid="9027366575315399714">"Käytä kerran"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> salasanaa, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> avainkoodia"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> salasanaa"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> avainkoodia"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Avainkoodi"</string>
     <string name="another_device" msgid="5147276802037801217">"Toinen laite"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Muut salasanojen ylläpitotyökalut"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Sulje taulukko"</string>
diff --git a/packages/CredentialManager/res/values-fr-rCA/strings.xml b/packages/CredentialManager/res/values-fr-rCA/strings.xml
index a2e7581..b122fd2 100644
--- a/packages/CredentialManager/res/values-fr-rCA/strings.xml
+++ b/packages/CredentialManager/res/values-fr-rCA/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Enregistrer à un autre emplacement"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Utiliser un autre appareil"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Enregistrer sur un autre appareil"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Une manière simple de se connecter en toute sécurité"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Utilisez vos empreintes digitales, votre visage ou un écran de verrouillage pour vous connecter avec une clé d\'accès unique qui ne peut pas être oubliée ou volée. En savoir plus"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Choisir où <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Choisir où <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"créer vos clés d\'accès"</string>
     <string name="save_your_password" msgid="6597736507991704307">"enregistrer votre mot de passe"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"enregistrer vos données de connexion"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Sélectionnez un gestionnaire de mots de passe par défaut où seront enregistrés vos mots de passe et vos clés d\'accès, et connectez-vous plus rapidement la prochaine fois."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Créer une clé d\'accès dans <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Enregistrer votre mot de passe dans <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Enregistrer vos données de connexion dans <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"clé d\'accès"</string>
     <string name="password" msgid="6738570945182936667">"mot de passe"</string>
     <string name="sign_ins" msgid="4710739369149469208">"connexions"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Créer une clé d\'accès dans"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Enregistrer le mot de passe dans"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Enregistrer la connexion dans"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Créer une clé d\'accès dans un autre appareil?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Utiliser <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> pour toutes vos connexions?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Ce gestionnaire de mots de passe va enregistrer vos mots de passe et vos clés d\'accès pour vous aider à vous connecter facilement."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Définir par défaut"</string>
     <string name="use_once" msgid="9027366575315399714">"Utiliser une fois"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> mots de passe, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> clés d\'accès"</string>
diff --git a/packages/CredentialManager/res/values-fr/strings.xml b/packages/CredentialManager/res/values-fr/strings.xml
index 2b280fb..cf69329 100644
--- a/packages/CredentialManager/res/values-fr/strings.xml
+++ b/packages/CredentialManager/res/values-fr/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Enregistrer ailleurs"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Utiliser un autre appareil"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Enregistrer sur un autre appareil"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Une façon simple et sécurisée de vous connecter"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Utilisez votre empreinte digitale, votre visage ou le verrouillage de l\'écran pour vous connecter avec une clé d\'accès unique que vous ne pourrez pas oublier ni vous faire voler. En savoir plus"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Choisir où <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Choisir où <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"créer vos clés d\'accès"</string>
     <string name="save_your_password" msgid="6597736507991704307">"enregistrer votre mot de passe"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"enregistrer vos informations de connexion"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Définissez un gestionnaire de mots de passe par défaut pour enregistrer vos mots de passe et clés d\'accès et vous connecter plus rapidement la prochaine fois."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Créer une clé d\'accès dans <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Enregistrer votre mot de passe dans <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Enregistrer vos informations de connexion dans <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"clé d\'accès"</string>
     <string name="password" msgid="6738570945182936667">"mot de passe"</string>
     <string name="sign_ins" msgid="4710739369149469208">"connexions"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Créer une clé d\'accès dans"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Enregistrer le mot de passe dans"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Enregistrer les informations de connexion dans"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Créer une clé d\'accès dans un autre appareil ?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Utiliser <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> pour toutes vos connexions ?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Ce gestionnaire de mots de passe stockera vos mots de passe et clés d\'accès pour vous permettre de vous connecter facilement."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Définir par défaut"</string>
     <string name="use_once" msgid="9027366575315399714">"Utiliser une fois"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> mots de passe, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> clés d\'accès"</string>
diff --git a/packages/CredentialManager/res/values-gl/strings.xml b/packages/CredentialManager/res/values-gl/strings.xml
index cc03ca4..c41dca0 100644
--- a/packages/CredentialManager/res/values-gl/strings.xml
+++ b/packages/CredentialManager/res/values-gl/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Gardar noutro lugar"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Usar outro dispositivo"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Gardar noutro dispositivo"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Un xeito fácil de iniciar sesión de forma segura"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Usa a impresión dixital, a cara ou o bloqueo de pantalla para iniciar sesión cunha clave de acceso única que non podes esquecer nin cha poden roubar. Máis información"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Escolle onde <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Escolle onde <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"crear as túas claves de acceso"</string>
     <string name="save_your_password" msgid="6597736507991704307">"gardar o contrasinal"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"gardar a información de inicio de sesión"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Configura un xestor de contrasinais como predefinido para gardar os teus contrasinais e as túas claves de acceso, e iniciar sesión máis rápido a próxima vez."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Queres crear unha clave de acceso en <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Queres gardar o contrasinal en <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Queres gardar a información de inicio de sesión en <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"clave de acceso"</string>
     <string name="password" msgid="6738570945182936667">"contrasinal"</string>
     <string name="sign_ins" msgid="4710739369149469208">"métodos de inicio de sesión"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Crear clave de acceso en"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Gardar contrasinal en"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Gardar método de inicio de sesión en"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Queres crear unha clave de acceso noutro dispositivo?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Queres usar <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> cada vez que inicies sesión?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Este xestor de contrasinais almacenará os contrasinais e as claves de acceso para axudarche a iniciar sesión facilmente."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Establecer como predeterminado"</string>
     <string name="use_once" msgid="9027366575315399714">"Usar unha vez"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> contrasinais, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> claves de acceso"</string>
diff --git a/packages/CredentialManager/res/values-gu/strings.xml b/packages/CredentialManager/res/values-gu/strings.xml
index f796d20..17df19e 100644
--- a/packages/CredentialManager/res/values-gu/strings.xml
+++ b/packages/CredentialManager/res/values-gu/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"કોઈ અન્ય સ્થાન પર સાચવો"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"કોઈ અન્ય ડિવાઇસનો ઉપયોગ કરો"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"અન્ય ડિવાઇસ પર સાચવો"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"સલામત રીતે સાઇન ઇન કરવાની સરળ રીત"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"ભૂલી ન શકાય કે ચોરાઈ ન જાય, તેવી કોઈ વિશિષ્ટ પાસકી વડે સાઇન ઇન કરવા માટે, તમારી ફિંગરપ્રિન્ટ, ચહેરો અથવા સ્ક્રીન લૉકનો ઉપયોગ કરો. વધુ જાણો"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> ક્યાં સાચવવી છે, તે પસંદ કરો"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> ક્યાં સાચવવી છે, તે પસંદ કરો"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"તમારી પાસકી બનાવો"</string>
     <string name="save_your_password" msgid="6597736507991704307">"તમારો પાસવર્ડ સાચવો"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"તમારી સાઇન-ઇનની માહિતી સાચવો"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"તમારા પાસવર્ડ અને પાસકી સાચવવા માટે કોઈ ડિફૉલ્ટ પાસવર્ડ મેનેજર સેટ કરો અને આગલી વખતે વધુ ઝડપથી સાઇન ઇન કરો."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"શું <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>માં કોઈ પાસકી બનાવીએ?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"શું તમારો પાસવર્ડ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>માં સાચવીએ?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"શું તમારી સાઇન-ઇનની માહિતી <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>માં સાચવીએ?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"પાસકી"</string>
     <string name="password" msgid="6738570945182936667">"પાસવર્ડ"</string>
     <string name="sign_ins" msgid="4710739369149469208">"સાઇન-ઇન"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"આમાં પાસકી બનાવો"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"પાસવર્ડ અહીં સાચવો"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"સાઇન-ઇનની માહિતી અહીં સાચવો"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"શું અન્ય ડિવાઇસમાં પાસકી બનાવવા માગો છો?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"શું તમારા બધા સાઇન-ઇન માટે <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>નો ઉપયોગ કરીએ?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"આ પાસવર્ડ મેનેજર તમને સરળતાથી સાઇન ઇન કરવામાં સહાય કરવા માટે, તમારા પાસવર્ડ અને પાસકીને સ્ટોર કરશે."</string>
     <string name="set_as_default" msgid="4415328591568654603">"ડિફૉલ્ટ તરીકે સેટ કરો"</string>
     <string name="use_once" msgid="9027366575315399714">"એકવાર ઉપયોગ કરો"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> પાસવર્ડ, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> પાસકી"</string>
diff --git a/packages/CredentialManager/res/values-hi/strings.xml b/packages/CredentialManager/res/values-hi/strings.xml
index fbf1c02..0147139 100644
--- a/packages/CredentialManager/res/values-hi/strings.xml
+++ b/packages/CredentialManager/res/values-hi/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"CredentialManager"</string>
     <string name="string_cancel" msgid="6369133483981306063">"रद्द करें"</string>
     <string name="string_continue" msgid="1346732695941131882">"जारी रखें"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"दूसरी जगह पर बनाएं"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"दूसरी जगह पर सेव करें"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"दूसरे डिवाइस का इस्तेमाल करें"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"दूसरे डिवाइस पर सेव करें"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"सुरक्षित तरीके से साइन इन करने का आसान तरीका"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"साइन इन करने के लिए फ़िंगरप्रिंट, फ़ेस या स्क्रीन लॉक जैसी यूनीक पासकी का इस्तेमाल करें. इन्हें, न तो भुलाया जा सकता है न ही चुराया जा सकता है. ज़्यादा जानें"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"चुनें कि <xliff:g id="CREATETYPES">%1$s</xliff:g> कहां पर सेव करना है"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"चुनें कि <xliff:g id="CREATETYPES">%1$s</xliff:g> कहां पर सेव करना है"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"अपनी पासकी बनाएं"</string>
     <string name="save_your_password" msgid="6597736507991704307">"अपना पासवर्ड सेव करें"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"साइन इन से जुड़ी अपनी जानकारी सेव करें"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"डिफ़ॉल्ट पासवर्ड मैनेजर सेट करें, ताकि आपके पासवर्ड और पासकी सेव की जा सकें और अगली बार आप तेज़ी से साइन इन कर सकें."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"क्या आपको <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> में पासकी बनानी है?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"क्या आपको अपना पासवर्ड <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> में सेव करना है?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"क्या आपको साइन इन करने से जुड़ी जानकारी <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> में सेव करनी है?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"पासकी"</string>
     <string name="password" msgid="6738570945182936667">"पासवर्ड"</string>
     <string name="sign_ins" msgid="4710739369149469208">"साइन इन"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"पासकी इसमें बनाएं"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"पासवर्ड इसमें सेव करें"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"साइन इन से जुड़ी जानकारी इसमें सेव करें"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"क्या आपको किसी दूसरे डिवाइस में पासकी बनानी है?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"क्या आपको साइन इन से जुड़ी सारी जानकारी सेव करने के लिए, <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> का इस्तेमाल करना है?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"पासवर्ड और पासकी को इस पासवर्ड मैनेजर में सेव करके, आसानी से साइन इन किया जा सकता है."</string>
     <string name="set_as_default" msgid="4415328591568654603">"डिफ़ॉल्ट के तौर पर सेट करें"</string>
     <string name="use_once" msgid="9027366575315399714">"इसका इस्तेमाल एक बार किया जा सकता है"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> पासवर्ड और <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> पासकी"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> पासवर्ड"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> पासकी"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"पासकी"</string>
     <string name="another_device" msgid="5147276802037801217">"दूसरा डिवाइस"</string>
     <string name="other_password_manager" msgid="565790221427004141">"दूसरे पासवर्ड मैनेजर"</string>
     <string name="close_sheet" msgid="1393792015338908262">"शीट बंद करें"</string>
diff --git a/packages/CredentialManager/res/values-hr/strings.xml b/packages/CredentialManager/res/values-hr/strings.xml
index 6c1952f..a5bd3ba 100644
--- a/packages/CredentialManager/res/values-hr/strings.xml
+++ b/packages/CredentialManager/res/values-hr/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Upravitelj vjerodajnicama"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Odustani"</string>
     <string name="string_continue" msgid="1346732695941131882">"Nastavi"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Izradi na drugom mjestu"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Spremi na drugom mjestu"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Upotrijebite neki drugi uređaj"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Spremi na drugi uređaj"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Jednostavan način za sigurnu prijavu"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Prijavite se otiskom prsta, licem ili zaključavanjem zaslona kao jedinstvenim pristupnim ključem koji je nemoguće zaboraviti ili ukrasti. Saznajte više"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Odaberite mjesto za sljedeće: <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Odaberite mjesto za sljedeće: <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"izradite pristupne ključeve"</string>
     <string name="save_your_password" msgid="6597736507991704307">"spremi zaporku"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"spremi podatke za prijavu"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Postavite zadani upravitelj zaporki da biste spremili zaporke i pristupne ključeve i sljedeći put se brže prijavili."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Želite li izraditi pristupni ključ na usluzi <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Želite li spremiti zaporku na usluzi <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Želite li spremiti podatke o prijavi na usluzi <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"pristupni ključ"</string>
     <string name="password" msgid="6738570945182936667">"zaporka"</string>
     <string name="sign_ins" msgid="4710739369149469208">"prijave"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Izradite pristupni ključ u"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Spremite zaporku na"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Spremite podatke za prijavu na"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Želite li izraditi pristupni ključ na nekom drugom uređaju?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Želite li upotrebljavati uslugu <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> za sve prijave?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Upravitelj zaporki pohranit će vaše zaporke i pristupne ključeve radi jednostavnije prijave."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Postavi kao zadano"</string>
     <string name="use_once" msgid="9027366575315399714">"Upotrijebi jednom"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"Broj zaporki: <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>, broj pristupnih ključeva: <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g>"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"Broj zaporki: <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"Broj pristupnih ključeva: <xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g>"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Pristupni ključ"</string>
     <string name="another_device" msgid="5147276802037801217">"Drugi uređaj"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Drugi upravitelji zaporki"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Zatvaranje lista"</string>
diff --git a/packages/CredentialManager/res/values-hu/strings.xml b/packages/CredentialManager/res/values-hu/strings.xml
index 0efa3e8..4c77038 100644
--- a/packages/CredentialManager/res/values-hu/strings.xml
+++ b/packages/CredentialManager/res/values-hu/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Mentés másik helyre"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Másik eszköz használata"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Mentés másik eszközre"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"A biztonságos bejelentkezés egyszerű módja"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Ujjlenyomatát, arcát vagy képernyőzárát használva egyedi azonosítókulccsal jelentkezhet be, amelyet nem lehet elfelejteni vagy ellopni. További információ."</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Válassza ki a(z) <xliff:g id="CREATETYPES">%1$s</xliff:g> helyét"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Válassza ki a(z) <xliff:g id="CREATETYPES">%1$s</xliff:g> helyét"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"azonosítókulcsok létrehozása"</string>
     <string name="save_your_password" msgid="6597736507991704307">"jelszó mentése"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"bejelentkezési adatok mentése"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Állítson be alapértelmezett jelszókezelőt jelszavai és azonosítókulcsai mentéséhez és a gyorsabb bejelentkezéshez."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Létrehoz azonosítókulcsot a(z) <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> szolgáltatásban?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Menti jelszavát a(z) <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> szolgáltatásba?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Menti bejelentkezési adatait a(z) <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> szolgáltatásba?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"azonosítókulcs"</string>
     <string name="password" msgid="6738570945182936667">"jelszó"</string>
     <string name="sign_ins" msgid="4710739369149469208">"bejelentkezési adatok"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Azonosítókulcs létrehozása itt:"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Jelszó mentése ide:"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Bejelentkezési adatok mentése ide:"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Létrehoz azonosítókulcsot egy másik eszközön?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Szeretné a következőt használni az összes bejelentkezési adatához: <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Ez a jelszókezelő a bejelentkezés megkönnyítése érdekében tárolja jelszavait és azonosítókulcsait."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Beállítás alapértelmezettként"</string>
     <string name="use_once" msgid="9027366575315399714">"Egyszeri használat"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> jelszó, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> azonosítókulcs"</string>
diff --git a/packages/CredentialManager/res/values-hy/strings.xml b/packages/CredentialManager/res/values-hy/strings.xml
index de47e9f..afa529a 100644
--- a/packages/CredentialManager/res/values-hy/strings.xml
+++ b/packages/CredentialManager/res/values-hy/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Մուտքի տվյալների կառավարիչ"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Չեղարկել"</string>
     <string name="string_continue" msgid="1346732695941131882">"Շարունակել"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Ստեղծել այլ տեղում"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Պահել այլ տեղում"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Օգտագործել այլ սարք"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Պահել մեկ այլ սարքում"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Մուտք գործելու անվտանգ և պարզ եղանակ"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Օգտագործեք ձեր մատնահետքը, դեմքը կամ էկրանի կողպումը՝ մուտք գործելու հաշիվ եզակի անցաբառի միջոցով, որը հնարավոր չէ կոտրել կամ մոռանալ։ Իմանալ ավելին"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Ընտրեք, թե որտեղ <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Ընտրեք, թե որտեղ <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"ստեղծել ձեր անցաբառերը"</string>
     <string name="save_your_password" msgid="6597736507991704307">"պահել գաղտնաբառը"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"պահել մուտքի տվյալները"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Սահմանեք գաղտնաբառերի կանխադրված կառավարիչ՝ ձեր գաղտնաբառերն ու անցաբառերը պահելու և հաջորդ անգամ ավելի արագ մուտք գործելու համար։"</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Ստեղծե՞լ անցաբառ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> հավելվածում"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Պահե՞լ ձեր գաղտնաբառը <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> հավելվածում"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Պահե՞լ ձեր մուտքի տվյալները <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> հավելվածում"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"անցաբառ"</string>
     <string name="password" msgid="6738570945182936667">"գաղտնաբառ"</string>
     <string name="sign_ins" msgid="4710739369149469208">"մուտք"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Ստեղծել անցաբառ…"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Պահել գաղտնաբառը…"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Պահել մուտքի տվյալները…"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Ստեղծե՞լ անցաբառ մեկ այլ սարքում"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Միշտ մուտք գործե՞լ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> հավելվածի միջոցով"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Գաղտնաբառերի այս կառավարիչը կպահի ձեր գաղտնաբառերն ու անցաբառերը՝ օգնելու ձեզ հեշտությամբ մուտք գործել հաշիվ։"</string>
     <string name="set_as_default" msgid="4415328591568654603">"Նշել որպես կանխադրված"</string>
     <string name="use_once" msgid="9027366575315399714">"Օգտագործել մեկ անգամ"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> գաղտնաբառ, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> անցաբառ"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> գաղտնաբառ"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> անցաբառ"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Անցաբառ"</string>
     <string name="another_device" msgid="5147276802037801217">"Այլ սարք"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Գաղտնաբառերի այլ կառավարիչներ"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Փակել թերթը"</string>
diff --git a/packages/CredentialManager/res/values-in/strings.xml b/packages/CredentialManager/res/values-in/strings.xml
index d980d44..5cad3f3 100644
--- a/packages/CredentialManager/res/values-in/strings.xml
+++ b/packages/CredentialManager/res/values-in/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Simpan ke tempat lain"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Gunakan perangkat lain"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Simpan ke perangkat lain"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Cara mudah untuk login dengan aman"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Gunakan sidik jari, wajah, atau kunci layar untuk login dengan kunci sandi unik yang mudah diingat dan tidak dapat dicuri. Pelajari lebih lanjut"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Pilih tempat untuk <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Pilih tempat untuk <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"membuat kunci sandi Anda"</string>
     <string name="save_your_password" msgid="6597736507991704307">"menyimpan sandi Anda"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"menyimpan info login Anda"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Setel pengelola sandi default untuk menyimpan sandi dan kunci sandi sehingga nantinya Anda dapat login lebih cepat."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Buat kunci sandi di <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Simpan sandi ke <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Simpan info login ke <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"kunci sandi"</string>
     <string name="password" msgid="6738570945182936667">"sandi"</string>
     <string name="sign_ins" msgid="4710739369149469208">"login"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Buat kunci sandi di"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Simpan sandi ke"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Simpan info login ke"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Buat kunci sandi di perangkat lain?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Gunakan <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> untuk semua info login Anda?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Pengelola sandi ini akan menyimpan sandi dan kunci sandi untuk membantu Anda login dengan mudah."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Setel sebagai default"</string>
     <string name="use_once" msgid="9027366575315399714">"Gunakan sekali"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> sandi, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> kunci sandi"</string>
diff --git a/packages/CredentialManager/res/values-is/strings.xml b/packages/CredentialManager/res/values-is/strings.xml
index 3fd6af2..f34dd69e 100644
--- a/packages/CredentialManager/res/values-is/strings.xml
+++ b/packages/CredentialManager/res/values-is/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Skilríkjastjórnun"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Hætta við"</string>
     <string name="string_continue" msgid="1346732695941131882">"Áfram"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Búa til annarsstaðar"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Vista annarsstaðar"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Nota annað tæki"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Vista í öðru tæki"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Einföld leið við örugga innskráningu"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Notaðu fingrafar, andlit eða skjálás til að skrá þig inn með einkvæmum aðgangslykli sem ekki er hægt að gleyma eða stela. Nánar"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Veldu hvar á að <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Veldu hvar á að <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"búa til aðgangslykla"</string>
     <string name="save_your_password" msgid="6597736507991704307">"vistaðu aðgangsorðið"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"vistaðu innskráningarupplýsingarnar"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Stilltu sjálfgefna aðgangsorðastjórnun til að vista aðgangsorð og aðgangslykla og skrá þig hraðar inn næst."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Búa til aðgangslykil í <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Vista aðgangsorð í <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Vista innskráningarupplýsingar í <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"aðgangslykill"</string>
     <string name="password" msgid="6738570945182936667">"aðgangsorð"</string>
     <string name="sign_ins" msgid="4710739369149469208">"innskráningar"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Búa til aðgangslykil í"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Vista aðgangsorð á"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Vista innskráningu á"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Viltu búa til aðgangslykil í öðru tæki?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Nota <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> fyrir allar innskráningar?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Þessi aðgangsorðastjórnun vistar aðgangsorð og aðgangslykla til að auðvelda þér að skrá þig inn."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Stilla sem sjálfgefið"</string>
     <string name="use_once" msgid="9027366575315399714">"Nota einu sinni"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> aðgangsorð, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> aðgangslyklar"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> aðgangsorð"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> aðgangslyklar"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Aðgangslykill"</string>
     <string name="another_device" msgid="5147276802037801217">"Annað tæki"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Önnur aðgangsorðastjórnun"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Loka blaði"</string>
diff --git a/packages/CredentialManager/res/values-it/strings.xml b/packages/CredentialManager/res/values-it/strings.xml
index 3a7b0fb..ddb2f3a 100644
--- a/packages/CredentialManager/res/values-it/strings.xml
+++ b/packages/CredentialManager/res/values-it/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Salva in un altro luogo"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Usa un altro dispositivo"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Salva su un altro dispositivo"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Un modo semplice per accedere in sicurezza"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Usa l\'impronta digitale, il volto o il blocco schermo per accedere con una passkey unica che non può essere dimenticata o rubata. Scopri di più"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Scegli dove <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Scegli dove <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"Crea le tue passkey"</string>
     <string name="save_your_password" msgid="6597736507991704307">"salva la password"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"salva le tue informazioni di accesso"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Imposta un gestore delle password predefinito per salvare le tue password e passkey in modo da poter accedere più velocemente la prossima volta."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Vuoi creare una passkey su <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Vuoi salvare la password su <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Vuoi salvare le informazioni di accesso su <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"passkey"</string>
     <string name="password" msgid="6738570945182936667">"password"</string>
     <string name="sign_ins" msgid="4710739369149469208">"accessi"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Crea passkey su"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Salva password su"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Salva accesso su"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Vuoi creare una passkey su un altro dispositivo?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Vuoi usare <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> per tutti gli accessi?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Questo gestore delle password archivierà le password e le passkey per aiutarti ad accedere facilmente."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Imposta come valore predefinito"</string>
     <string name="use_once" msgid="9027366575315399714">"Usa una volta"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> password, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> passkey"</string>
diff --git a/packages/CredentialManager/res/values-iw/strings.xml b/packages/CredentialManager/res/values-iw/strings.xml
index 397ad60..50752eb 100644
--- a/packages/CredentialManager/res/values-iw/strings.xml
+++ b/packages/CredentialManager/res/values-iw/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"שמירה במקום אחר"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"שימוש במכשיר אחר"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"שמירה במכשיר אחר"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"דרך פשוטה להיכנס לחשבון בבטחה"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"אפשר להשתמש בטביעת אצבע, בזיהוי פנים או בנעילת מסך כדי להיכנס לחשבון עם מפתח גישה ייחודי שאי אפשר לשכוח או לגנוב אותו. מידע נוסף"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"צריך לבחור לאן <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"צריך לבחור לאן <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"יצירת מפתחות גישה"</string>
     <string name="save_your_password" msgid="6597736507991704307">"שמירת הסיסמה שלך"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"שמירת פרטי הכניסה שלך"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"יש לקבוע את מנהל הסיסמאות שיוגדר כברירת מחדל כדי לשמור את הסיסמאות ומפתחות הגישה, ולהיכנס לחשבון מהר יותר בפעם הבאה."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"ליצור מפתח גישה ב-<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"לשמור את הסיסמה ב-<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"לשמור את פרטי הכניסה ב-<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"מפתח גישה"</string>
     <string name="password" msgid="6738570945182936667">"סיסמה"</string>
     <string name="sign_ins" msgid="4710739369149469208">"פרטי כניסה"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"יצירת מפתח גישה ב"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"שמירת הסיסמה של"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"שמירת פרטי הכניסה של"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"ליצור מפתח גישה במכשיר אחר?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"להשתמש ב-<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> בכל הכניסות?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"במנהל הסיסמאות הזה יאוחסנו הסיסמאות ומפתחות הגישה שלך, כדי לעזור לך להיכנס לחשבון בקלות."</string>
     <string name="set_as_default" msgid="4415328591568654603">"הגדרה כברירת מחדל"</string>
     <string name="use_once" msgid="9027366575315399714">"שימוש פעם אחת"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> סיסמאות, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> מפתחות גישה"</string>
diff --git a/packages/CredentialManager/res/values-ja/strings.xml b/packages/CredentialManager/res/values-ja/strings.xml
index 0340b66..783a444 100644
--- a/packages/CredentialManager/res/values-ja/strings.xml
+++ b/packages/CredentialManager/res/values-ja/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"別の場所に保存"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"別のデバイスを使用"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"他のデバイスに保存"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"安全にログインする簡単な方法"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"忘れたり盗まれたりする可能性がある一意のパスキーと合わせて、ログインに指紋認証、顔認証、画面ロックを使用できます。詳細"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> の保存場所の選択"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> の保存場所の選択"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"パスキーの作成"</string>
     <string name="save_your_password" msgid="6597736507991704307">"パスワードを保存"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"ログイン情報を保存"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"デフォルトのパスワード マネージャーを設定すると、パスワードやパスキーを保存して、次回から素早くログインできるようになります。"</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> でパスキーを作成しますか?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> にパスワードを保存しますか?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> にログイン情報を保存しますか?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"パスキー"</string>
     <string name="password" msgid="6738570945182936667">"パスワード"</string>
     <string name="sign_ins" msgid="4710739369149469208">"ログイン"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"パスキーの作成先"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"パスワードの保存先"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"ログイン情報の保存先"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"他のデバイスでパスキーを作成しますか?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"ログインのたびに <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> を使用しますか?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"このパスワード マネージャーに、パスワードやパスキーが保存され、簡単にログインできるようになります。"</string>
     <string name="set_as_default" msgid="4415328591568654603">"デフォルトに設定"</string>
     <string name="use_once" msgid="9027366575315399714">"1 回使用"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> 件のパスワード、<xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> 件のパスキー"</string>
diff --git a/packages/CredentialManager/res/values-ka/strings.xml b/packages/CredentialManager/res/values-ka/strings.xml
index 3da7ea3..eba01d4 100644
--- a/packages/CredentialManager/res/values-ka/strings.xml
+++ b/packages/CredentialManager/res/values-ka/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"სხვა სივრცეში შენახვა"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"სხვა მოწყობილობის გამოყენება"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"სხვა მოწყობილობაზე შენახვა"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"უსაფრთხოდ შესვლის მარტივი გზა"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"გამოიყენეთ თქვენი თითის ანაბეჭდი, სახის ამოცნობა და ეკრანის დაბლოკვა სისტემაში უნიკალური წვდომის გასაღებით შესასვლელად, რომლის დავიწყება ან მოპარვა შეუძლებელია. შეიტყვეთ მეტი"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"აირჩიეთ, სად უნდა <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"აირჩიეთ, სად უნდა <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"შექმენით თქვენი პაროლი"</string>
     <string name="save_your_password" msgid="6597736507991704307">"შეინახეთ თქვენი პაროლი"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"შეინახეთ თქვენი სისტემაში შესვლის ინფორმაცია"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"დააყენეთ პაროლის ნაგულისხმევი მენეჯერი, რათა შეინახოთ თქვენი პაროლები და გასაღებები და შეხვიდეთ უფრო სწრაფად შემდეგ ჯერზე."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"გსურთ წვდომის გასაღების შექმნა <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>-ში?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"გსურთ თქვენი პაროლის შენახვა <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>-ში?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"გსურთ თქვენი სისტემაში შესვლის მონაცემების შენახვა <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>-ში?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"წვდომის გასაღები"</string>
     <string name="password" msgid="6738570945182936667">"პაროლი"</string>
     <string name="sign_ins" msgid="4710739369149469208">"სისტემაში შესვლა"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"წვდომის გასაღების შექმნა"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"პაროლის შენახვა"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"შესვლის შენახვა"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"გსურთ პაროლის შექმნა სხვა მოწყობილობაში?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"გსურთ, გამოიყენოთ<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> სისტემაში ყველა შესვლისთვის?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"მოცემული პაროლების მმართველი შეინახავს თქვენს პაროლებს და წვდომის გასაღებს, რომლებიც დაგეხმარებათ სისტემაში მარტივად შესვლაში."</string>
     <string name="set_as_default" msgid="4415328591568654603">"ნაგულისხმევად დაყენება"</string>
     <string name="use_once" msgid="9027366575315399714">"ერთხელ გამოყენება"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> პაროლი, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> წვდომის გასაღები"</string>
diff --git a/packages/CredentialManager/res/values-kk/strings.xml b/packages/CredentialManager/res/values-kk/strings.xml
index 9491f8e..d7d255b 100644
--- a/packages/CredentialManager/res/values-kk/strings.xml
+++ b/packages/CredentialManager/res/values-kk/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Тіркелу деректері менеджері"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Бас тарту"</string>
     <string name="string_continue" msgid="1346732695941131882">"Жалғастыру"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Басқа орында жасау"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Басқа орынға сақтау"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Басқа құрылғыны пайдалану"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Басқа құрылғыға сақтау"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Қауіпсіз кірудің оңай жолы"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Ұмытылмайтын немесе ұрланбайтын бірегей кіру кілтінің көмегімен кіру үшін саусақ ізін, бетті анықтау функциясын немесе экран құлпын пайдаланыңыз. Толық ақпарат"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> таңдау"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> таңдау"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"кіру кілттерін жасаңыз"</string>
     <string name="save_your_password" msgid="6597736507991704307">"құпия сөзді сақтау"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"тіркелу деректерін сақтау"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Құпия сөздер мен кіру кілттерін сақтап, келесі рет жылдам кіру үшін әдепкі құпия сөз менеджерін орнатыңыз."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> қолданбасында кіру кілті жасалсын ба?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> қолданбасына құпия сөз сақталсын ба?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> қолданбасына тіркелу деректері сақталсын ба?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"кіру кілті"</string>
     <string name="password" msgid="6738570945182936667">"құпия сөз"</string>
     <string name="sign_ins" msgid="4710739369149469208">"кіру әрекеттері"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Кіру кілтін жасау"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Құпия сөзді келесіге сақтау:"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Кіру деректерін келесіге сақтау:"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Кіру кілті басқа құрылғыда жасалсын ба?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Барлық кіру әрекеті үшін <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> пайдаланылсын ба?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Аккаунтқа оңай кіру үшін құпия сөз менеджері құпия сөздер мен кіру кілттерін сақтайды."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Әдепкі етіп орнату"</string>
     <string name="use_once" msgid="9027366575315399714">"Бір рет пайдалану"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> құпия сөз, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> кіру кілті"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> құпия сөз"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> кіру кілті"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Кіру кілті"</string>
     <string name="another_device" msgid="5147276802037801217">"Басқа құрылғы"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Басқа құпия сөз менеджерлері"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Парақты жабу"</string>
diff --git a/packages/CredentialManager/res/values-km/strings.xml b/packages/CredentialManager/res/values-km/strings.xml
index 80167fc..b104661 100644
--- a/packages/CredentialManager/res/values-km/strings.xml
+++ b/packages/CredentialManager/res/values-km/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"កម្មវិធី​គ្រប់គ្រង​ព័ត៌មាន​ផ្ទៀងផ្ទាត់"</string>
     <string name="string_cancel" msgid="6369133483981306063">"បោះបង់"</string>
     <string name="string_continue" msgid="1346732695941131882">"បន្ត"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"បង្កើតនៅកន្លែងផ្សេងទៀត"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"រក្សាទុកក្នុងកន្លែងផ្សេងទៀត"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"ប្រើ​ឧបករណ៍​ផ្សេងទៀត"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"រក្សាទុកទៅក្នុងឧបករណ៍ផ្សេង"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"វិធីដ៏សាមញ្ញ ដើម្បីចូលគណនីដោយសុវត្ថិភាព"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"ប្រើស្នាមម្រាមដៃ មុខ ឬការចាក់សោអេក្រង់របស់អ្នក ដើម្បីចូលគណនីដោយប្រើកូដសម្ងាត់ខុសប្លែកពីគេដែលមិនអាចភ្លេច ឬត្រូវគេលួច។ ស្វែងយល់បន្ថែម"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"ជ្រើសរើសកន្លែងដែលត្រូវ <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"ជ្រើសរើសកន្លែងដែលត្រូវ <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"បង្កើត​កូដសម្ងាត់របស់អ្នក"</string>
     <string name="save_your_password" msgid="6597736507991704307">"រក្សាទុកពាក្យសម្ងាត់របស់អ្នក"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"រក្សាទុកព័ត៌មានចូលគណនីរបស់អ្នក"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"កំណត់​កម្មវិធីគ្រប់គ្រងពាក្យសម្ងាត់​លំនាំដើម ដើម្បីរក្សាទុក​ពាក្យសម្ងាត់និង​កូដសម្ងាត់របស់អ្នក និងចូលគណនី​កាន់តែរហ័ស​នៅពេលលើកក្រោយ។"</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"បង្កើតកូដសម្ងាត់នៅក្នុង <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ឬ?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"រក្សាទុកពាក្យសម្ងាត់របស់អ្នកក្នុង <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ឬ?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"រក្សាទុកព័ត៌មានចូលគណនីរបស់អ្នកក្នុង <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ឬ?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"កូដសម្ងាត់"</string>
     <string name="password" msgid="6738570945182936667">"ពាក្យសម្ងាត់"</string>
     <string name="sign_ins" msgid="4710739369149469208">"ការចូល​គណនី"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"បង្កើតកូដសម្ងាត់នៅក្នុង"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"រក្សាទុក​ពាក្យសម្ងាត់ទៅ"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"រក្សាទុក​ការចូល​គណនីទៅ"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"បង្កើតកូដសម្ងាត់​នៅក្នុងឧបករណ៍​ផ្សេងទៀតឬ?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"ប្រើ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> សម្រាប់ការចូលគណនីទាំងអស់របស់អ្នកឬ?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"កម្មវិធីគ្រប់គ្រងពាក្យសម្ងាត់នេះ​នឹងរក្សាទុកពាក្យសម្ងាត់ និងកូដសម្ងាត់​របស់អ្នក ដើម្បីជួយឱ្យអ្នក​ចូលគណនី​បានយ៉ាងងាយស្រួល។"</string>
     <string name="set_as_default" msgid="4415328591568654603">"កំណត់ជាលំនាំដើម"</string>
     <string name="use_once" msgid="9027366575315399714">"ប្រើម្ដង"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"ពាក្យសម្ងាត់ <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> កូដសម្ងាត់ <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g>"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"ពាក្យសម្ងាត់ <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"កូដសម្ងាត់ <xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g>"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"កូដសម្ងាត់"</string>
     <string name="another_device" msgid="5147276802037801217">"ឧបករណ៍​ផ្សេងទៀត"</string>
     <string name="other_password_manager" msgid="565790221427004141">"កម្មវិធីគ្រប់គ្រងពាក្យសម្ងាត់ផ្សេងទៀត"</string>
     <string name="close_sheet" msgid="1393792015338908262">"បិទសន្លឹក"</string>
diff --git a/packages/CredentialManager/res/values-kn/strings.xml b/packages/CredentialManager/res/values-kn/strings.xml
index 96304ac..033eec1 100644
--- a/packages/CredentialManager/res/values-kn/strings.xml
+++ b/packages/CredentialManager/res/values-kn/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"ಮತ್ತೊಂದು ಸ್ಥಳದಲ್ಲಿ ಉಳಿಸಿ"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"ಬೇರೊಂದು ಸಾಧನವನ್ನು ಬಳಸಿ"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"ಬೇರೊಂದು ಸಾಧನದಲ್ಲಿ ಉಳಿಸಿ"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"ಸುರಕ್ಷಿತವಾಗಿ ಸೈನ್ ಇನ್ ಮಾಡುವ ಸುಲಭ ವಿಧಾನ"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"ಮರೆಯಲಾಗದ ಅಥವಾ ಕದಿಯಲಾಗದ ಅನನ್ಯ ಪಾಸ್‌ಕೀ ಮೂಲಕ ಸೈನ್ ಇನ್ ಮಾಡಲು ನಿಮ್ಮ ಫಿಂಗರ್‌ಪ್ರಿಂಟ್, ಫೇಸ್ ಲಾಕ್ ಅಥವಾ ಸ್ಕ್ರೀನ್ ಲಾಕ್ ಬಳಸಿ. ಇನ್ನಷ್ಟು ತಿಳಿಯಿರಿ"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> ಅನ್ನು ಎಲ್ಲಿ ಉಳಿಸಬೇಕು ಎಂದು ಆಯ್ಕೆಮಾಡಿ"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> ಅನ್ನು ಎಲ್ಲಿ ಉಳಿಸಬೇಕು ಎಂದು ಆಯ್ಕೆಮಾಡಿ"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"ನಿಮ್ಮ ಪಾಸ್‌ಕೀಗಳನ್ನು ರಚಿಸಿ"</string>
     <string name="save_your_password" msgid="6597736507991704307">"ನಿಮ್ಮ ಪಾಸ್‌ವರ್ಡ್‌ ಉಳಿಸಿ"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"ನಿಮ್ಮ ಸೈನ್-ಇನ್ ಮಾಹಿತಿ ಉಳಿಸಿ"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"ನಿಮ್ಮ ಪಾಸ್‌ವರ್ಡ್‌ಗಳು ಮತ್ತು ಪಾಸ್‌ಕೀಗಳನ್ನು ಉಳಿಸಲು ಡೀಫಾಲ್ಟ್ ಪಾಸ್‌ವರ್ಡ್ ನಿರ್ವಾಹಕವನ್ನು ಸೆಟ್ ಮಾಡಿ ಹಾಗೂ ಮುಂದಿನ ಬಾರಿ ವೇಗವಾಗಿ ಸೈನ್ ಇನ್ ಮಾಡಿ."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ನಲ್ಲಿ ಪಾಸ್‌ಕೀ ರಚಿಸಬೇಕೆ?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"ನಿಮ್ಮ ಪಾಸ್‌ವರ್ಡ್ ಅನ್ನು <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ಗೆ ಉಳಿಸಬೇಕೆ?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"ನಿಮ್ಮ ಸೈನ್ ಇನ್ ಮಾಹಿತಿಯನ್ನು <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ಗೆ ಉಳಿಸಬೇಕೆ?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"ಪಾಸ್‌ಕೀ"</string>
     <string name="password" msgid="6738570945182936667">"ಪಾಸ್‌ವರ್ಡ್"</string>
     <string name="sign_ins" msgid="4710739369149469208">"ಸೈನ್-ಇನ್‌ಗಳು"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"ಇಲ್ಲಿ ಪಾಸ್‌ಕೀ ರಚಿಸಿ"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"ಇಲ್ಲಿಗೆ ಪಾಸ್‌ವರ್ಡ್ ಉಳಿಸಿ"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"ಇಲ್ಲಿಗೆ ಸೈನ್-ಇನ್ ಮಾಹಿತಿ ಉಳಿಸಿ"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"ಮತ್ತೊಂದು ಸಾಧನದಲ್ಲಿ ಪಾಸ್‌ಕೀ ರಚಿಸಬೇಕೆ?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"ನಿಮ್ಮ ಎಲ್ಲಾ ಸೈನ್-ಇನ್‌ಗಳಿಗಾಗಿ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ಅನ್ನು ಬಳಸುವುದೇ?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"ಈ ಪಾಸ್‌ವರ್ಡ್ ನಿರ್ವಾಹಕವು ನಿಮಗೆ ಸುಲಭವಾಗಿ ಸೈನ್ ಇನ್ ಮಾಡುವುದಕ್ಕೆ ಸಹಾಯ ಮಾಡಲು ನಿಮ್ಮ ಪಾಸ್‌ವರ್ಡ್‌ಗಳು ಮತ್ತು ಪಾಸ್‌ಕೀಗಳನ್ನು ಸಂಗ್ರಹಿಸುತ್ತದೆ."</string>
     <string name="set_as_default" msgid="4415328591568654603">"ಡೀಫಾಲ್ಟ್ ಆಗಿ ಸೆಟ್ ಮಾಡಿ"</string>
     <string name="use_once" msgid="9027366575315399714">"ಒಂದು ಬಾರಿ ಬಳಸಿ"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> ಪಾಸ್‌ವರ್ಡ್‌ಗಳು, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> ಪಾಸ್‌ಕೀಗಳು"</string>
diff --git a/packages/CredentialManager/res/values-ko/strings.xml b/packages/CredentialManager/res/values-ko/strings.xml
index 58518c1..44f22d7 100644
--- a/packages/CredentialManager/res/values-ko/strings.xml
+++ b/packages/CredentialManager/res/values-ko/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"인증서 관리자"</string>
     <string name="string_cancel" msgid="6369133483981306063">"취소"</string>
     <string name="string_continue" msgid="1346732695941131882">"계속"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"다른 위치에 만들기"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"다른 위치에 저장"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"다른 기기 사용"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"다른 기기에 저장"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"안전하게 로그인하는 간단한 방법"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"지문, 얼굴 인식 또는 화면 잠금을 통해 잊어버리거나 분실할 염려가 없는 고유한 패스키로 로그인하세요. 자세히 알아보기"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> 작업을 위한 위치 선택"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> 작업을 위한 위치 선택"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"패스키 만들기"</string>
     <string name="save_your_password" msgid="6597736507991704307">"비밀번호 저장"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"로그인 정보 저장"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"기본 비밀번호 관리자를 설정하여 비밀번호와 패스키를 저장하고 다음에 더 빠르게 로그인하세요."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>에 패스키를 만드시겠습니까?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>에 비밀번호를 저장하시겠습니까?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>에 로그인 정보를 저장하시겠습니까?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"패스키"</string>
     <string name="password" msgid="6738570945182936667">"비밀번호"</string>
     <string name="sign_ins" msgid="4710739369149469208">"로그인 정보"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"다음 위치에 패스키 만들기"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"비밀번호를 다음에 저장"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"로그인 정보를 다음에 저장"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"다른 기기에서 패스키를 만들까요?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"모든 로그인에 <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>을(를) 사용하시겠습니까?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"이 비밀번호 관리자는 비밀번호와 패스키를 저장하여 사용자가 간편하게 로그인하도록 돕습니다."</string>
     <string name="set_as_default" msgid="4415328591568654603">"기본값으로 설정"</string>
     <string name="use_once" msgid="9027366575315399714">"한 번 사용"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"비밀번호 <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>개, 패스키 <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g>개"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"비밀번호 <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>개"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"패스키 <xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g>개"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"패스키"</string>
     <string name="another_device" msgid="5147276802037801217">"다른 기기"</string>
     <string name="other_password_manager" msgid="565790221427004141">"기타 비밀번호 관리자"</string>
     <string name="close_sheet" msgid="1393792015338908262">"시트 닫기"</string>
diff --git a/packages/CredentialManager/res/values-ky/strings.xml b/packages/CredentialManager/res/values-ky/strings.xml
index 298657e..c4621cf 100644
--- a/packages/CredentialManager/res/values-ky/strings.xml
+++ b/packages/CredentialManager/res/values-ky/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Credential Manager"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Жок"</string>
     <string name="string_continue" msgid="1346732695941131882">"Улантуу"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Башка жерде түзүү"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Башка жерге сактоо"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Башка түзмөк колдонуу"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Башка түзмөккө сактоо"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Коопсуз кирүүнүн жөнөкөй жолу"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Унутуп калууга же уурдатууга мүмкүн эмес болгон уникалдуу ачкыч менен манжа изин, жүзүнөн таанып ачуу же экранды кулпулоо функцияларын колдонуп өзүңүздү ырастай аласыз. Кененирээк"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> үчүн жер тандаңыз"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> үчүн жер тандаңыз"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"мүмкүндүк алуу ачкычтарын түзүү"</string>
     <string name="save_your_password" msgid="6597736507991704307">"сырсөзүңүздү сактаңыз"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"кирүү маалыматын сактаңыз"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Сырсөздөр менен мүмкүндүк алуу ачкычтары сактала турган демейки сырсөздөрдү башкаргычты тандап, кийинки жолу аккаунтуңузга тезирээк кириңиз."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> колдонмосунда мүмкүндүк алуу ачкычын түзөсүзбү?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Сырсөзүңүздү <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> колдонмосунда сактайсызбы?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Кирүү маалыматын <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> колдонмосунда сактайсызбы?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"мүмкүндүк алуу ачкычы"</string>
     <string name="password" msgid="6738570945182936667">"сырсөз"</string>
     <string name="sign_ins" msgid="4710739369149469208">"кирүүлөр"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Мүмкүндүк алуу ачкычын бул жерден түзүү:"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Сырсөздү каякка сактайсыз:"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Аккаунтка кирүү маалыматын каякка сактайсыз:"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Мүмкүндүк алуу ачкычы башка түзмөктө түзүлсүнбү?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> бардык аккаунттарга кирүү үчүн колдонулсунбу?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Сырсөздөрүңүздү жана ачкычтарыңызды Сырсөздөрдү башкаргычка сактап коюп, каалаган убакта колдоно берсеңиз болот."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Демейки катары коюу"</string>
     <string name="use_once" msgid="9027366575315399714">"Бир жолу колдонуу"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> сырсөз, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> мүмкүндүк алуу ачкычы"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> сырсөз"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> мүмкүндүк алуу ачкычы"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Мүмкүндүк алуу ачкычы"</string>
     <string name="another_device" msgid="5147276802037801217">"Башка түзмөк"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Башка сырсөздөрдү башкаргычтар"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Баракты жабуу"</string>
diff --git a/packages/CredentialManager/res/values-lo/strings.xml b/packages/CredentialManager/res/values-lo/strings.xml
index 215262b..7429389 100644
--- a/packages/CredentialManager/res/values-lo/strings.xml
+++ b/packages/CredentialManager/res/values-lo/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"ຕົວຈັດການຂໍ້ມູນການເຂົ້າສູ່ລະບົບ"</string>
     <string name="string_cancel" msgid="6369133483981306063">"ຍົກເລີກ"</string>
     <string name="string_continue" msgid="1346732695941131882">"ສືບຕໍ່"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"ສ້າງໃນບ່ອນອື່ນ"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"ບັນທຶກໃສ່ບ່ອນອື່ນ"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"ໃຊ້ອຸປະກອນອື່ນ"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"ບັນທຶກໃສ່ອຸປະກອນອື່ນ"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"ວິທີງ່າຍໆໃນການເຂົ້າສູ່ລະບົບຢ່າງປອດໄພ"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"ໃຊ້ລາຍນິ້ວມື, ໃບໜ້າ ຫຼື ລັອກໜ້າຈໍຂອງທ່ານເພື່ອເຂົ້າສູ່ລະບົບດ້ວຍກະແຈຜ່ານທີ່ບໍ່ຊ້ຳກັນເພື່ອບໍ່ໃຫ້ລືມ ຫຼື ຖືກລັກໄດ້. ສຶກສາເພີ່ມເຕີມ"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"ເລືອກບ່ອນທີ່ຈະ <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"ເລືອກບ່ອນທີ່ຈະ <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"ສ້າງກະແຈຜ່ານຂອງທ່ານ"</string>
     <string name="save_your_password" msgid="6597736507991704307">"ບັນທຶກລະຫັດຜ່ານຂອງທ່ານ"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"ບັນທຶກຂໍ້ມູນການເຂົ້າສູ່ລະບົບຂອງທ່ານ"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"ຕັ້ງຄ່າເລີ່ມຕົ້ນຂອງຕົວຈັດການລະຫັດຜ່ານເພື່ອບັນທຶກລະຫັດຜ່ານ ແລະ ກະແຈຜ່ານຂອງທ່ານ ແລະ ເຂົ້າສູ່ລະບົບໄດ້ໄວຂຶ້ນໃນເທື່ອຕໍ່ໄປ."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"ສ້າງກະແຈຜ່ານໃນ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ບໍ?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"ບັນທຶກລະຫັດຜ່ານຂອງທ່ານໃສ່ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ບໍ?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"ບັນທຶກຂໍ້ມູນການເຂົ້າສູ່ລະບົບຂອງທ່ານໃສ່ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ບໍ?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"ກະແຈຜ່ານ"</string>
     <string name="password" msgid="6738570945182936667">"ລະຫັດຜ່ານ"</string>
     <string name="sign_ins" msgid="4710739369149469208">"ການເຂົ້າສູ່ລະບົບ"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"ສ້າງກະແຈຜ່ານໃນ"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"ບັນທຶກລະຫັດຜ່ານໃສ່"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"ບັນທຶກການເຂົ້າສູ່ລະບົບໃສ່"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"ສ້າງກະແຈຜ່ານໃນອຸປະກອນອື່ນບໍ?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"ໃຊ້ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ສຳລັບການເຂົ້າສູ່ລະບົບທັງໝົດຂອງທ່ານບໍ?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"ຕົວຈັດການລະຫັດຜ່ານນີ້ຈະຈັດເກັບລະຫັດຜ່ານ ແລະ ກະແຈຜ່ານຂອງທ່ານໄວ້ເພື່ອຊ່ວຍໃຫ້ທ່ານເຂົ້າສູ່ລະບົບໄດ້ໂດຍງ່າຍ."</string>
     <string name="set_as_default" msgid="4415328591568654603">"ຕັ້ງເປັນຄ່າເລີ່ມຕົ້ນ"</string>
     <string name="use_once" msgid="9027366575315399714">"ໃຊ້ເທື່ອດຽວ"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> ລະຫັດຜ່ານ, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> ກະແຈຜ່ານ"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> ລະຫັດຜ່ານ"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> ກະແຈຜ່ານ"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"ກະແຈຜ່ານ"</string>
     <string name="another_device" msgid="5147276802037801217">"ອຸປະກອນອື່ນ"</string>
     <string name="other_password_manager" msgid="565790221427004141">"ຕົວຈັດການລະຫັດຜ່ານອື່ນໆ"</string>
     <string name="close_sheet" msgid="1393792015338908262">"ປິດຊີດ"</string>
diff --git a/packages/CredentialManager/res/values-lt/strings.xml b/packages/CredentialManager/res/values-lt/strings.xml
index 6125fe3..aa5d97a 100644
--- a/packages/CredentialManager/res/values-lt/strings.xml
+++ b/packages/CredentialManager/res/values-lt/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Išsaugoti kitoje vietoje"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Naudoti kitą įrenginį"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Išsaugoti kitame įrenginyje"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Paprastas saugaus prisijungimo metodas"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Naudodami piršto atspaudą, veidą ar ekrano užraktą prisijunkite su unikaliu „passkey“, kurio neįmanoma pamiršti ar pavogti. Sužinokite daugiau"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Pasirinkite, kur <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Pasirinkite, kur <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"kurkite slaptažodžius"</string>
     <string name="save_your_password" msgid="6597736507991704307">"išsaugoti slaptažodį"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"išsaugoti prisijungimo informaciją"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Nustatykite numatytąją slaptažodžių tvarkyklę, kad išsaugotumėte slaptažodžius ir kitą kartą galėtumėte sparčiau prisijungti."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Sukurti „passkey“ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Išsaugoti slaptažodį <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Išsaugoti prisijungimo informaciją <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"„passkey“"</string>
     <string name="password" msgid="6738570945182936667">"slaptažodis"</string>
     <string name="sign_ins" msgid="4710739369149469208">"prisijungimo informacija"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Slaptažodžio kūrimas"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Išsaugoti slaptažodį"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Išsaugoti prisijungimo informaciją"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Sukurti slaptažodį kitame įrenginyje?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Naudoti <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> visada prisijungiant?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Šioje slaptažodžių tvarkyklėje bus saugomi jūsų slaptažodžiai, kad galėtumėte lengvai prisijungti."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Nustatyti kaip numatytąjį"</string>
     <string name="use_once" msgid="9027366575315399714">"Naudoti vieną kartą"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"slaptažodžių: <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>, „passkey“: <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g>"</string>
diff --git a/packages/CredentialManager/res/values-lv/strings.xml b/packages/CredentialManager/res/values-lv/strings.xml
index 43c036f..06446ab 100644
--- a/packages/CredentialManager/res/values-lv/strings.xml
+++ b/packages/CredentialManager/res/values-lv/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Saglabāt citur"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Izmantot citu ierīci"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Saglabāt citā ierīcē"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Vienkāršs veids, kā droši pierakstīties"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Izmantojiet pirksta nospiedumu, autorizāciju pēc sejas vai ekrāna bloķēšanu, lai pierakstītos ar unikālu piekļuves atslēgu, ko nevar aizmirst vai nozagt. Uzziniet vairāk."</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Izvēlieties, kur: <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Izvēlieties, kur: <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"veidot piekļuves atslēgas"</string>
     <string name="save_your_password" msgid="6597736507991704307">"saglabāt paroli"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"saglabāt pierakstīšanās informāciju"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Iestatiet noklusējuma paroļu pārvaldnieku, lai saglabātu paroles un piekļuves atslēgas un nākamajā reizē pierakstītos ātrāk."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Vai izveidot piekļuves atslēgu šeit: <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Vai saglabāt paroli šeit: <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Vai saglabāt pierakstīšanās informāciju šeit: <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"piekļuves atslēga"</string>
     <string name="password" msgid="6738570945182936667">"parole"</string>
     <string name="sign_ins" msgid="4710739369149469208">"pierakstīšanās informācija"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Izveidot piekļuves atslēgu šeit:"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Saglabāt paroli šeit:"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Saglabāt pierakstīšanās informāciju šeit:"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Vai izveidot piekļuves atslēgu citā ierīcē?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Vai vienmēr izmantot <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>, lai pierakstītos?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Šis paroļu pārvaldnieks glabās jūsu paroles un piekļuves atslēgas, lai atvieglotu pierakstīšanos."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Iestatīt kā noklusējumu"</string>
     <string name="use_once" msgid="9027366575315399714">"Izmantot vienreiz"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> paroles, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> piekļuves atslēgas"</string>
diff --git a/packages/CredentialManager/res/values-mk/strings.xml b/packages/CredentialManager/res/values-mk/strings.xml
index 059f042..8093d74 100644
--- a/packages/CredentialManager/res/values-mk/strings.xml
+++ b/packages/CredentialManager/res/values-mk/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Зачувајте на друго место"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Употребете друг уред"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Зачувајте на друг уред"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Едноставен начин за безбедно најавување"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Користете го отпечатокот, заклучувањето со лик или заклучувањето екран за да се најавите со единствен криптографски клуч што не може да се заборави или украде. Дознајте повеќе"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Изберете каде да <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Изберете каде да <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"создајте криптографски клучеви"</string>
     <string name="save_your_password" msgid="6597736507991704307">"се зачува лозинката"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"се зачуваат податоците за најавување"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Поставете стандарден управник со лозинки за да ги складира вашите лозинки и криптографски клучеви и најавете се побрзо следниот пат."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Да се создаде криптографски клуч во <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Да се зачува вашата лозинка во <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Да се зачуваат вашите податоци за најавување во <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"криптографски клуч"</string>
     <string name="password" msgid="6738570945182936667">"лозинка"</string>
     <string name="sign_ins" msgid="4710739369149469208">"најавувања"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Создајте криптографски клуч во"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Зачувајте ја лозинката во"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Зачувајте го најавувањето во"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Да се создаде криптографски клуч во друг уред?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Да се користи <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> за сите ваши најавувања?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Овој управник со лозинки ќе ги складира вашите лозинки и криптографски клучеви за да ви помогне лесно да се најавите."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Постави како стандардна опција"</string>
     <string name="use_once" msgid="9027366575315399714">"Употребете еднаш"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> лозинки, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> криптографски клучеви"</string>
diff --git a/packages/CredentialManager/res/values-ml/strings.xml b/packages/CredentialManager/res/values-ml/strings.xml
index e4f6d69..68a6419 100644
--- a/packages/CredentialManager/res/values-ml/strings.xml
+++ b/packages/CredentialManager/res/values-ml/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"മറ്റൊരു സ്ഥലത്തേക്ക് സംരക്ഷിക്കുക"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"മറ്റൊരു ഉപകരണം ഉപയോഗിക്കുക"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"മറ്റൊരു ഉപകരണത്തിലേക്ക് സംരക്ഷിക്കുക"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"സുരക്ഷിതമായി സൈൻ ഇൻ ചെയ്യാനുള്ള ലളിതമായ മാർഗ്ഗം"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"മറന്നുപോകാനും മോഷ്‌ടിക്കാനും സാധ്യതയില്ലാത്ത തനത് പാസ്‌കീ ഉപയോഗിച്ച് സൈൻ ഇൻ ചെയ്യാൻ നിങ്ങളുടെ ഫിംഗർപ്രിന്റോ മുഖമോ സ്‌ക്രീൻ ലോക്കോ ഉപയോഗിക്കുക. കൂടുതലറിയുക"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"എവിടെ <xliff:g id="CREATETYPES">%1$s</xliff:g> എന്ന് തിരഞ്ഞെടുക്കുക"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"എവിടെ <xliff:g id="CREATETYPES">%1$s</xliff:g> എന്ന് തിരഞ്ഞെടുക്കുക"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"നിങ്ങളുടെ പാസ്‌കീകൾ സൃഷ്‌ടിക്കുക"</string>
     <string name="save_your_password" msgid="6597736507991704307">"നിങ്ങളുടെ പാസ്‌വേഡ് സംരക്ഷിക്കുക"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"നിങ്ങളുടെ സൈൻ ഇൻ വിവരങ്ങൾ സംരക്ഷിക്കുക"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"നിങ്ങളുടെ പാസ്‌വേഡുകളും പാസ്‌കീകളും സംരക്ഷിക്കാനും അടുത്ത തവണ വേഗത്തിൽ സൈൻ ഇൻ ചെയ്യാനും ഒരു ഡിഫോൾട്ട് പാസ്‌വേഡ് മാനേജർ സജ്ജീകരിക്കുക."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> എന്നതിൽ ഒരു പാസ്‌കീ സൃഷ്‌ടിക്കണോ?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"പാസ്‌വേഡ് <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> എന്നതിലേക്ക് സംരക്ഷിക്കണോ?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"സൈൻ ഇൻ വിവരങ്ങൾ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> എന്നതിലേക്ക് സംരക്ഷിക്കണോ?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"പാസ്‌കീ"</string>
     <string name="password" msgid="6738570945182936667">"പാസ്‌വേഡ്"</string>
     <string name="sign_ins" msgid="4710739369149469208">"സൈൻ ഇന്നുകൾ"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"ഇനിപ്പറയുന്നതിൽ പാസ്‌കീ സൃഷ്‌ടിക്കുക"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"പാസ്‌വേഡ് ഇനിപ്പറയുന്നതിൽ സംരക്ഷിക്കുക"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"ഇനിപ്പറയുന്നതിലേക്ക് സൈൻ ഇൻ സംരക്ഷിക്കുക"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"മറ്റൊരു ഉപകരണത്തിൽ പാസ്‌കീ സൃഷ്ടിക്കണോ?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"നിങ്ങളുടെ എല്ലാ സൈൻ ഇന്നുകൾക്കും <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ഉപയോഗിക്കണോ?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"എളുപ്പത്തിൽ സൈൻ ഇൻ ചെയ്യാൻ സഹായിക്കുന്നതിന് ഈ പാസ്‌വേഡ് മാനേജർ നിങ്ങളുടെ പാസ്‌വേഡുകളും പാസ്‌കീകളും സംഭരിക്കും."</string>
     <string name="set_as_default" msgid="4415328591568654603">"ഡിഫോൾട്ടായി സജ്ജീകരിക്കുക"</string>
     <string name="use_once" msgid="9027366575315399714">"ഒരു തവണ ഉപയോഗിക്കുക"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> പാസ്‌വേഡുകൾ, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> പാസ്‌കീകൾ"</string>
diff --git a/packages/CredentialManager/res/values-mn/strings.xml b/packages/CredentialManager/res/values-mn/strings.xml
index 3f8d4ca..40ef5e5 100644
--- a/packages/CredentialManager/res/values-mn/strings.xml
+++ b/packages/CredentialManager/res/values-mn/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Өөр газар хадгалах"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Өөр төхөөрөмж ашиглах"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Өөр төхөөрөмжид хадгалах"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Аюулгүй нэвтрэх энгийн арга"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Мартах эсвэл хулгайд алдах боломжгүй өвөрмөц passkey-н хамт нэвтрэх хурууны хээ, царай эсвэл дэлгэцийн түгжээгээ ашиглана уу. Нэмэлт мэдээлэл авах"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Хаана <xliff:g id="CREATETYPES">%1$s</xliff:g>-г сонгоно уу"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Хаана <xliff:g id="CREATETYPES">%1$s</xliff:g>-г сонгоно уу"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"passkey-үүдээ үүсгэнэ үү"</string>
     <string name="save_your_password" msgid="6597736507991704307">"нууц үгээ хадгалах"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"нэвтрэх мэдээллээ хадгалах"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Нууц үгнүүд болон passkey-г хадгалах болон дараагийн удаа илүү хурдан нэвтрэхийн тулд өгөгдмөл нууц үгний менежерийг тохируулна уу"</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>-д passkey үүсгэх үү?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Нууц үгээ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>-д хадгалах уу?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Нэвтрэх мэдээллээ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>-д хадгалах уу?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"passkey"</string>
     <string name="password" msgid="6738570945182936667">"нууц үг"</string>
     <string name="sign_ins" msgid="4710739369149469208">"нэвтрэлт"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Дараахад passkey үүсгэх"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Нууц үгийг дараахад хадгалах"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Нэвтрэх мэдээллийг дараахад хадгалах"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Өөр төхөөрөмжид passkey үүсгэх үү?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>-г бүх нэвтрэлтдээ ашиглах уу?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Танд хялбархан нэвтрэхэд туслахын тулд энэ нууц үгний менежер таны нууц үг болон passkey-г хадгална."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Өгөгдмөлөөр тохируулах"</string>
     <string name="use_once" msgid="9027366575315399714">"Нэг удаа ашиглах"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> нууц үг, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> passkey"</string>
diff --git a/packages/CredentialManager/res/values-mr/strings.xml b/packages/CredentialManager/res/values-mr/strings.xml
index aa6f253..60c969d 100644
--- a/packages/CredentialManager/res/values-mr/strings.xml
+++ b/packages/CredentialManager/res/values-mr/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"क्रेडेंशियल व्यवस्थापक"</string>
     <string name="string_cancel" msgid="6369133483981306063">"रद्द करा"</string>
     <string name="string_continue" msgid="1346732695941131882">"पुढे सुरू ठेवा"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"दुसऱ्या ठिकाणी तयार करा"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"दुसऱ्या ठिकाणी सेव्ह करा"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"दुसरे डिव्‍हाइस वापरा"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"दुसऱ्या डिव्हाइसवर सेव्ह करा"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"सुरक्षितपणे साइन इन करण्याचा सोपा मार्ग"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"युनिक पासकीसह साइन इन करण्यासाठी तुमचे फिंगरप्रिंट, फेस किंवा स्क्रीन लॉक वापरा, जे विसरता येणार नाही किंवा चोरीला जाणार नाही. अधिक जाणून घ्या"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> कुठे करायचे ते निवडा"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> कुठे करायचे ते निवडा"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"तुमच्या पासकी तयार करा"</string>
     <string name="save_your_password" msgid="6597736507991704307">"तुमचा पासवर्ड सेव्ह करा"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"तुमची साइन-इन माहिती सेव्ह करा"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"तुमचे पासवर्ड आणि पासकी सेव्ह करण्यासाठी डीफॉल्ट पासवर्ड मॅनेजर सेट करा व पुढच्या वेळी आणखी जलद साइन इन करा."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> मध्ये पासकी तयार करायची का?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"तुमचा पासवर्ड <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> वर सेव्ह करायचा का?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"तुमची साइन-इन माहिती <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> वर सेव्ह करायची का?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"पासकी"</string>
     <string name="password" msgid="6738570945182936667">"पासवर्ड"</string>
     <string name="sign_ins" msgid="4710739369149469208">"साइन-इन"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"यामध्ये पासकी तयार करा"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"यावर पासवर्ड सेव्ह करा"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"यावर साइन-इन सेव्ह करा"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"दुसऱ्या डिव्हाइसमध्ये पासकी तयार करायची आहे का?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"तुमच्या सर्व साइन-इन साठी <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>वापरायचे का?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"तुम्हाला सहजरीत्या साइन इन करण्यात मदत करण्यासाठी हा पासवर्ड व्यवस्थापक तुमचे पासवर्ड आणि पासकी स्टोअर करेल."</string>
     <string name="set_as_default" msgid="4415328591568654603">"डिफॉल्ट म्हणून सेट करा"</string>
     <string name="use_once" msgid="9027366575315399714">"एकदा वापरा"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> पासवर्ड, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> पासकी"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> पासवर्ड"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> पासकी"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"पासकी"</string>
     <string name="another_device" msgid="5147276802037801217">"इतर डिव्हाइस"</string>
     <string name="other_password_manager" msgid="565790221427004141">"इतर पासवर्ड व्यवस्थापक"</string>
     <string name="close_sheet" msgid="1393792015338908262">"शीट बंद करा"</string>
diff --git a/packages/CredentialManager/res/values-ms/strings.xml b/packages/CredentialManager/res/values-ms/strings.xml
index d5f8c0e..a590e95 100644
--- a/packages/CredentialManager/res/values-ms/strings.xml
+++ b/packages/CredentialManager/res/values-ms/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Simpan di tempat lain"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Gunakan peranti lain"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Simpan kepada peranti lain"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Cara mudah untuk log masuk dengan selamat"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Gunakan cap jari, wajah atau kunci skrin anda untuk log masuk menggunakan kunci laluan unik yang tidak boleh dilupakan atau dicuri. Ketahui lebih lanjut"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Pilih tempat untuk <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Pilih tempat untuk <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"buat kunci laluan anda"</string>
     <string name="save_your_password" msgid="6597736507991704307">"simpan kata laluan anda"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"simpan maklumat log masuk anda"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Tetapkan pengurus kata laluan lalai untuk menyimpan kata laluan dan kunci laluan dan log masuk dengan lebih pantas pada masa akan datang."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Buat kunci laluan dalam <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Simpan kata laluan anda pada <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Simpan maklumat log masuk anda pada <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"kunci laluan"</string>
     <string name="password" msgid="6738570945182936667">"kata laluan"</string>
     <string name="sign_ins" msgid="4710739369149469208">"log masuk"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Buat kunci laluan dalam"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Simpan kata laluan pada"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Simpan maklumat log masuk pada"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Buat kunci laluan dalam peranti lain?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Gunakan <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> untuk semua log masuk anda?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Pengurus kata laluan ini akan menyimpan kata laluan dan kunci laluan anda untuk membantu anda log masuk dengan mudah."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Tetapkan sebagai lalai"</string>
     <string name="use_once" msgid="9027366575315399714">"Gunakan sekali"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"Kata laluan <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>, kunci laluan <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g>"</string>
diff --git a/packages/CredentialManager/res/values-my/strings.xml b/packages/CredentialManager/res/values-my/strings.xml
index eda2f741..c7c88a7 100644
--- a/packages/CredentialManager/res/values-my/strings.xml
+++ b/packages/CredentialManager/res/values-my/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"အထောက်အထားမန်နေဂျာ"</string>
     <string name="string_cancel" msgid="6369133483981306063">"မလုပ်တော့"</string>
     <string name="string_continue" msgid="1346732695941131882">"ရှေ့ဆက်ရန်"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"နောက်တစ်နေရာတွင် ပြုလုပ်ရန်"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"နောက်တစ်နေရာတွင် သိမ်းရန်"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"စက်နောက်တစ်ခု သုံးရန်"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"စက်နောက်တစ်ခုတွင် သိမ်းရန်"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"လုံခြုံစွာလက်မှတ်ထိုးဝင်ရန် ရိုးရှင်းသောနည်း"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"မေ့မသွား (သို့) ခိုးမသွားနိုင်သော သီးခြားလျှို့ဝှက်ကီးဖြင့် လက်မှတ်ထိုးဝင်ရန် သင့်လက်ဗွေ၊ မျက်နှာ (သို့) ဖန်သားပြင်လော့ခ် သုံးနိုင်သည်။ ပိုမိုလေ့လာရန်"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> ရန် နေရာရွေးပါ"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> ရန် နေရာရွေးပါ"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"သင့်လျှို့ဝှက်ကီး ပြုလုပ်ခြင်း"</string>
     <string name="save_your_password" msgid="6597736507991704307">"သင့်စကားဝှက် သိမ်းရန်"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"သင်၏ လက်မှတ်ထိုးဝင်သည့်အချက်အလက်ကို သိမ်းရန်"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"သင့်စကားဝှက်၊ လျှို့ဝှက်ကီးများ သိမ်းဆည်းရန်နှင့် နောက်တစ်ကြိမ်တွင် မြန်ဆန်စွာ လက်မှတ်ထိုးဝင်ရောက်ရန် မူရင်းစကားဝှက်မန်နေဂျာကို သတ်မှတ်ပါ။"</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> တွင် လျှို့ဝှက်ကီး ပြုလုပ်မလား။"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"သင့်စကားဝှက်ကို <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> တွင် သိမ်းမလား။"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"သင်၏ လက်မှတ်ထိုးဝင်သည့်အချက်အလက်ကို <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> တွင် သိမ်းမလား။"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"လျှို့ဝှက်ကီး"</string>
     <string name="password" msgid="6738570945182936667">"စကားဝှက်"</string>
     <string name="sign_ins" msgid="4710739369149469208">"လက်မှတ်ထိုးဝင်မှုများ"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"ဤနေရာတွင် လျှို့ဝှက်ကီးပြုလုပ်ရန်"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"စကားဝှက်ကို ဤနေရာတွင် သိမ်းရန်"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"လက်မှတ်ထိုးဝင်မှုကို ဤနေရာတွင် သိမ်းရန်"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"အခြားစက်တွင် လျှို့ဝှက်ကီးပြုလုပ်မလား။"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"သင်၏လက်မှတ်ထိုးဝင်မှု အားလုံးအတွက် <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> သုံးမလား။"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"သင်အလွယ်တကူ လက်မှတ်ထိုးဝင်နိုင်ရန် ဤစကားဝှက်မန်နေဂျာက စကားဝှက်နှင့် လျှို့ဝှက်ကီးများကို သိမ်းပါမည်။"</string>
     <string name="set_as_default" msgid="4415328591568654603">"မူရင်းအဖြစ် သတ်မှတ်ရန်"</string>
     <string name="use_once" msgid="9027366575315399714">"တစ်ကြိမ်သုံးရန်"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"စကားဝှက် <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> ခု၊ လျှို့ဝှက်ကီး <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> ခု"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"စကားဝှက် <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> ခု"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"လျှို့ဝှက်ကီး <xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> ခု"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"လျှို့ဝှက်ကီး"</string>
     <string name="another_device" msgid="5147276802037801217">"စက်နောက်တစ်ခု"</string>
     <string name="other_password_manager" msgid="565790221427004141">"အခြားစကားဝှက်မန်နေဂျာများ"</string>
     <string name="close_sheet" msgid="1393792015338908262">"စာမျက်နှာ ပိတ်ရန်"</string>
diff --git a/packages/CredentialManager/res/values-nb/strings.xml b/packages/CredentialManager/res/values-nb/strings.xml
index 82854b8..f113f72 100644
--- a/packages/CredentialManager/res/values-nb/strings.xml
+++ b/packages/CredentialManager/res/values-nb/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Legitimasjonslagring"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Avbryt"</string>
     <string name="string_continue" msgid="1346732695941131882">"Fortsett"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Opprett på et annet sted"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Lagre på et annet sted"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Bruk en annen enhet"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Lagre på en annen enhet"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"En enkel og trygg påloggingsmåte"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Bruk fingeravtrykk, ansiktet eller en skjermlås til å logge på med en unik tilgangsnøkkel du verken kan glemme eller miste. Finn ut mer"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Velg hvor <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Velg hvor <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"opprette tilgangsnøklene dine"</string>
     <string name="save_your_password" msgid="6597736507991704307">"lagre passordet ditt"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"lagre påloggingsinformasjonen din"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Angi et standardverktøy for passordlagring for å lagre passordene og tilgangsnøklene dine og logge på raskere neste gang."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Vil du opprette en tilgangsnøkkel i <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Vil du lagre passordet i <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Vil du lagre påloggingsinformasjonen i <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"tilgangsnøkkel"</string>
     <string name="password" msgid="6738570945182936667">"passord"</string>
     <string name="sign_ins" msgid="4710739369149469208">"pålogginger"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Opprett en tilgangsnøkkel på"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Lagre passordet i"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Lagre påloggingen i"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Vil du opprette en tilgangsnøkkel på en annen enhet?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Vil du bruke <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> for alle pålogginger?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Dette verktøyet for passordlagring lagrer passord og tilgangsnøkler, så det blir lett å logge på."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Angi som standard"</string>
     <string name="use_once" msgid="9027366575315399714">"Bruk én gang"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> passord, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> tilgangsnøkler"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> passord"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> tilgangsnøkler"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Tilgangsnøkkel"</string>
     <string name="another_device" msgid="5147276802037801217">"En annen enhet"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Andre løsninger for passordlagring"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Lukk arket"</string>
diff --git a/packages/CredentialManager/res/values-ne/strings.xml b/packages/CredentialManager/res/values-ne/strings.xml
index 23f4f43..cc8a38a 100644
--- a/packages/CredentialManager/res/values-ne/strings.xml
+++ b/packages/CredentialManager/res/values-ne/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"क्रिडेन्सियल म्यानेजर"</string>
     <string name="string_cancel" msgid="6369133483981306063">"रद्द गर्नुहोस्"</string>
     <string name="string_continue" msgid="1346732695941131882">"जारी राख्नुहोस्"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"अर्को ठाउँमा बनाउनुहोस्"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"अर्को ठाउँमा सेभ गर्नुहोस्"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"अर्को डिभाइस प्रयोग गर्नुहोस्"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"अर्को डिभाइसमा सेभ गर्नुहोस्"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"सुरक्षित तरिकाले साइन इन गर्ने सरल तरिका"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"नभुलिने वा चोरी नहुने खालको अद्वितीय पासकीका साथै आफ्ना फिंगरप्रिन्ट, अनुहार वा स्क्रिन लक प्रयोग गरी साइन इन गर्नुहोस्। थप जान्नुहोस्"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> सेभ गर्ने ठाउँ छनौट गर्नुहोस्"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> सेभ गर्ने ठाउँ छनौट गर्नुहोस्"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"आफ्ना पासकीहरू बाउनुहोस्"</string>
     <string name="save_your_password" msgid="6597736507991704307">"आफ्नो पासवर्ड सेभ गर्नुहोस्"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"आफ्नो साइन इनसम्बन्धी जानकारी सेभ गर्नुहोस्"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"आफ्ना पासवर्ड तथा पासकीहरू सेभ गर्न र अर्को पटक अझ छिटो साइन इन गर्न डिफल्ट पासवर्ड म्यानेजर सेट गर्नुहोस्।"</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> मा पासकी बनाउने हो?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"तपाईंको पासवर्ड <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> मा सेभ गर्ने हो?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"तपाईंको साइन इनसम्बन्धी जानकारी <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> मा सेभ गर्ने हो?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"पासकी"</string>
     <string name="password" msgid="6738570945182936667">"पासवर्ड"</string>
     <string name="sign_ins" msgid="4710739369149469208">"साइन इनसम्बन्धी जानकारी"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"यसमा पासकी बनाउनुहोस्:"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"यसमा पासवर्ड सेभ गर्नुहोस्:"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"यसमा साइन इनसम्बन्धी जानकारी सेभ गर्नुहोस्:"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"अर्को डिभाइसमा पासकी बनाउने हो?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"तपाईंले साइन इन गर्ने सबै डिभाइसहरूमा <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> प्रयोग गर्ने हो?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"तपाईं सजिलै साइन इन गर्न सक्नुहोस् भन्नाका लागि यो पासवर्ड म्यानेजरले तपाईंका पासवर्ड तथा पासकीहरू सेभ गर्ने छ।"</string>
     <string name="set_as_default" msgid="4415328591568654603">"डिफल्ट जानकारीका रूपमा सेट गर्नुहोस्"</string>
     <string name="use_once" msgid="9027366575315399714">"एक पटक प्रयोग गर्नुहोस्"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> वटा पासवर्ड, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> वटा पासकी"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> वटा पासवर्ड"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> वटा पासकी"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"पासकी"</string>
     <string name="another_device" msgid="5147276802037801217">"अर्को डिभाइस"</string>
     <string name="other_password_manager" msgid="565790221427004141">"अन्य पासवर्ड म्यानेजरहरू"</string>
     <string name="close_sheet" msgid="1393792015338908262">"पाना बन्द गर्नुहोस्"</string>
diff --git a/packages/CredentialManager/res/values-nl/strings.xml b/packages/CredentialManager/res/values-nl/strings.xml
index c91a318..72dff73 100644
--- a/packages/CredentialManager/res/values-nl/strings.xml
+++ b/packages/CredentialManager/res/values-nl/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Op een andere locatie opslaan"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Een ander apparaat gebruiken"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Opslaan op een ander apparaat"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Een makkelijke manier om beveiligd in te loggen"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Gebruik je vingerafdruk, gezichtsvergrendeling of schermvergrendeling om in te loggen met een unieke toegangssleutel die je niet kunt vergeten en die anderen niet kunnen stelen. Meer informatie"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Een locatie kiezen voor <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Een locatie kiezen voor <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"je toegangssleutels maken"</string>
     <string name="save_your_password" msgid="6597736507991704307">"je wachtwoord opslaan"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"je inloggegevens opslaan"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Stel een standaard wachtwoordmanager in om je wachtwoorden en toegangssleutels op te slaan zodat je de volgende keer sneller kunt inloggen."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Een toegangssleutel maken in <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Je wachtwoord opslaan in <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Je inloggegevens opslaan in <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"toegangssleutel"</string>
     <string name="password" msgid="6738570945182936667">"wachtwoord"</string>
     <string name="sign_ins" msgid="4710739369149469208">"inloggegevens"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Toegangssleutel maken in"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Wachtwoord opslaan in"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Inloggegevens opslaan in"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Toegangssleutel maken op een ander apparaat?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> elke keer gebruiken als je inlogt?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Deze wachtwoordmanager slaat je wachtwoorden en toegangssleutels op zodat je makkelijk kunt inloggen."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Instellen als standaard"</string>
     <string name="use_once" msgid="9027366575315399714">"Eén keer gebruiken"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> wachtwoorden, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> toegangssleutels"</string>
diff --git a/packages/CredentialManager/res/values-or/strings.xml b/packages/CredentialManager/res/values-or/strings.xml
index 838ddfe..a1bbf1c 100644
--- a/packages/CredentialManager/res/values-or/strings.xml
+++ b/packages/CredentialManager/res/values-or/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"କ୍ରେଡେନସିଆଲ ମେନେଜର"</string>
     <string name="string_cancel" msgid="6369133483981306063">"ବାତିଲ କରନ୍ତୁ"</string>
     <string name="string_continue" msgid="1346732695941131882">"ଜାରି ରଖନ୍ତୁ"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"ଅନ୍ୟ ଏକ ସ୍ଥାନରେ ତିଆରି କରନ୍ତୁ"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"ଅନ୍ୟ ଏକ ସ୍ଥାନରେ ସେଭ କରନ୍ତୁ"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"ଅନ୍ୟ ଏହି ଡିଭାଇସ ବ୍ୟବହାର କରନ୍ତୁ"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"ଅନ୍ୟ ଏକ ଡିଭାଇସରେ ସେଭ କରନ୍ତୁ"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"ସୁରକ୍ଷିତ ଭାବେ ସାଇନ ଇନ କରିବାର ଏକ ସରଳ ଉପାୟ"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"ଏକ ସ୍ୱତନ୍ତ୍ର ପାସକୀ ମାଧ୍ୟମରେ ସାଇନ ଇନ କରିବା ପାଇଁ ଆପଣଙ୍କ ଟିପଚିହ୍ନ, ଫେସ କିମ୍ବା ସ୍କ୍ରିନ ଲକ ବ୍ୟବହାର କରନ୍ତୁ ଯାହାକୁ ଭୁଲି ପାରିବେ ନାହିଁ କିମ୍ବା ଚୋରି ହୋଇପାରିବ ନାହିଁ। ଅଧିକ ଜାଣନ୍ତୁ"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"କେଉଁଠି <xliff:g id="CREATETYPES">%1$s</xliff:g> କରିବେ, ତାହା ବାଛନ୍ତୁ"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"କେଉଁଠି <xliff:g id="CREATETYPES">%1$s</xliff:g> କରିବେ, ତାହା ବାଛନ୍ତୁ"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"ଆପଣଙ୍କ ପାସକୀଗୁଡ଼ିକ ତିଆରି କରନ୍ତୁ"</string>
     <string name="save_your_password" msgid="6597736507991704307">"ଆପଣଙ୍କ ପାସୱାର୍ଡ ସେଭ କରନ୍ତୁ"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"ଆପଣଙ୍କ ସାଇନ-ଇନ ସୂଚନା ସେଭ କରନ୍ତୁ"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"ଆପଣଙ୍କ ପାସୱାର୍ଡ ଓ ପାସକୀଗୁଡ଼ିକୁ ସେଭ କରିବା ପାଇଁ ଏକ ଡିଫଲ୍ଟ Password Manager ସେଟ କରନ୍ତୁ ଏବଂ ପରବର୍ତ୍ତୀ ଥର ଶୀଘ୍ର ସାଇନ ଇନ କରନ୍ତୁ।"</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>ରେ ଏକ ପାସକୀ ତିଆରି କରିବେ?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"ଆପଣଙ୍କ ପାସୱାର୍ଡକୁ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>ରେ ସେଭ କରିବେ?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"ଆପଣଙ୍କ ସାଇନ-ଇନ ସୂଚନାକୁ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>ରେ ସେଭ କରିବେ?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"ପାସକୀ"</string>
     <string name="password" msgid="6738570945182936667">"ପାସୱାର୍ଡ"</string>
     <string name="sign_ins" msgid="4710739369149469208">"ସାଇନ-ଇନ"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"ଏଥିରେ ପାସକୀ ତିଆରି କରନ୍ତୁ"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"ଏଥିରେ ପାସୱାର୍ଡ ସେଭ କରନ୍ତୁ"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"ଏଥିରେ ସାଇନ-ଇନ ସେଭ କରନ୍ତୁ"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"ଅନ୍ୟ ଏକ ଡିଭାଇସରେ ପାସକୀ ତିଆରି କରିବେ?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"ଆପଣଙ୍କ ସମସ୍ତ ସାଇନ-ଇନ ପାଇଁ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ବ୍ୟବହାର କରିବେ?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"ଏହି Password Manager ସହଜରେ ସାଇନ ଇନ କରିବାରେ ଆପଣଙ୍କୁ ସାହାଯ୍ୟ କରିବା ପାଇଁ ଆପଣଙ୍କ ପାସୱାର୍ଡ ଏବଂ ପାସକୀଗୁଡ଼ିକୁ ଷ୍ଟୋର କରିବ।"</string>
     <string name="set_as_default" msgid="4415328591568654603">"ଡିଫଲ୍ଟ ଭାବେ ସେଟ କରନ୍ତୁ"</string>
     <string name="use_once" msgid="9027366575315399714">"ଥରେ ବ୍ୟବହାର କରନ୍ତୁ"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>ଟି ପାସୱାର୍ଡ, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g>ଟି ପାସକୀ"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>ଟି ପାସୱାର୍ଡ"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g>ଟି ପାସକୀ"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"ପାସକୀ"</string>
     <string name="another_device" msgid="5147276802037801217">"ଅନ୍ୟ ଏକ ଡିଭାଇସ"</string>
     <string name="other_password_manager" msgid="565790221427004141">"ଅନ୍ୟ Password Manager"</string>
     <string name="close_sheet" msgid="1393792015338908262">"ସିଟ ବନ୍ଦ କରନ୍ତୁ"</string>
diff --git a/packages/CredentialManager/res/values-pa/strings.xml b/packages/CredentialManager/res/values-pa/strings.xml
index 74b2ab1..36989c6 100644
--- a/packages/CredentialManager/res/values-pa/strings.xml
+++ b/packages/CredentialManager/res/values-pa/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"ਕ੍ਰੀਡੈਂਸ਼ੀਅਲ ਪ੍ਰਬੰਧਕ"</string>
     <string name="string_cancel" msgid="6369133483981306063">"ਰੱਦ ਕਰੋ"</string>
     <string name="string_continue" msgid="1346732695941131882">"ਜਾਰੀ ਰੱਖੋ"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"ਕਿਸੇ ਹੋਰ ਥਾਂ \'ਤੇ ਬਣਾਓ"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"ਕਿਸੇ ਹੋਰ ਥਾਂ \'ਤੇ ਰੱਖਿਅਤ ਕਰੋ"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"ਕੋਈ ਹੋਰ ਡੀਵਾਈਸ ਦੀ ਵਰਤੋਂ ਕਰੋ"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"ਕਿਸੇ ਹੋਰ ਡੀਵਾਈਸ \'ਤੇ ਰੱਖਿਅਤ ਕਰੋ"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"ਸੁਰੱਖਿਅਤ ਢੰਗ ਨਾਲ ਸਾਈਨ-ਇਨ ਕਰਨ ਦਾ ਆਸਾਨ ਤਰੀਕਾ"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"ਵਿਲੱਖਣ ਪਾਸਕੀ ਨਾਲ ਸਾਈਨ-ਇਨ ਕਰਨ ਵਾਸਤੇ ਆਪਣੇ ਫਿੰਗਰਪ੍ਰਿੰਟ, ਚਿਹਰੇ ਜਾਂ ਸਕ੍ਰੀਨ ਲਾਕ ਦੀ ਵਰਤੋਂ ਕਰੋ ਜਿਸਨੂੰ ਭੁੱਲਿਆ ਜਾਂ ਚੋਰੀ ਨਹੀਂ ਕੀਤਾ ਜਾ ਸਕਦਾ। ਹੋਰ ਜਾਣੋ"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> ਲਈ ਕੋਈ ਥਾਂ ਚੁਣੋ"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> ਲਈ ਕੋਈ ਥਾਂ ਚੁਣੋ"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"ਆਪਣੀਆਂ ਪਾਸਕੀਆਂ ਬਣਾਓ"</string>
     <string name="save_your_password" msgid="6597736507991704307">"ਆਪਣਾ ਪਾਸਵਰਡ ਰੱਖਿਅਤ ਕਰੋ"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"ਆਪਣੀ ਸਾਈਨ-ਇਨ ਜਾਣਕਾਰੀ ਰੱਖਿਅਤ ਕਰੋ"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"ਆਪਣੇ ਪਾਸਵਰਡਾਂ ਅਤੇ ਪਾਸਕੀਆਂ ਨੂੰ ਰੱਖਿਅਤ ਕਰਨ ਲਈ ਕੋਈ ਪੂਰਵ-ਨਿਰਧਾਰਿਤ ਪਾਸਵਰਡ ਪ੍ਰਬੰਧਕ ਸੈੱਟ ਕਰੋ ਅਤੇ ਅਗਲੀ ਵਾਰ ਤੇਜ਼ੀ ਨਾਲ ਸਾਈਨ-ਇਨ ਕਰੋ।"</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"ਕੀ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ਵਿੱਚ ਪਾਸਕੀ ਨੂੰ ਬਣਾਉਣਾ ਹੈ?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"ਕੀ ਆਪਣੇ ਪਾਸਵਰਡ ਨੂੰ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ਵਿੱਚ ਰੱਖਿਅਤ ਕਰਨਾ ਹੈ?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"ਕੀ ਆਪਣੀ ਸਾਈਨ-ਇਨ ਜਾਣਕਾਰੀ ਨੂੰ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ਵਿੱਚ ਰੱਖਿਅਤ ਕਰਨਾ ਹੈ?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"ਪਾਸਕੀ"</string>
     <string name="password" msgid="6738570945182936667">"ਪਾਸਵਰਡ"</string>
     <string name="sign_ins" msgid="4710739369149469208">"ਸਾਈਨ-ਇਨਾਂ ਦੀ ਜਾਣਕਾਰੀ"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"ਇਸ ਵਿੱਚ ਪਾਸਕੀ ਬਣਾਓ"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"ਇਸ \'ਤੇ ਪਾਸਵਰਡ ਰੱਖਿਅਤ ਕਰੋ"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"ਇਸ \'ਤੇ ਸਾਈਨ-ਇਨ ਜਾਣਕਾਰੀ ਰੱਖਿਅਤ ਕਰੋ"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"ਕੀ ਕਿਸੇ ਹੋਰ ਡੀਵਾਈਸ ਵਿੱਚ ਕੋਈ ਪਾਸਕੀ ਬਣਾਉਣੀ ਹੈ?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"ਕੀ ਆਪਣੇ ਸਾਰੇ ਸਾਈਨ-ਇਨਾਂ ਲਈ<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ਦੀ ਵਰਤੋਂ ਕਰਨੀ ਹੈ?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"ਇਹ ਪਾਸਵਰਡ ਪ੍ਰਬੰਧਕ ਤੁਹਾਡੀ ਆਸਾਨੀ ਨਾਲ ਸਾਈਨ-ਇਨ ਕਰਨ ਵਿੱਚ ਮਦਦ ਕਰਨ ਲਈ ਤੁਹਾਡੇ ਪਾਸਵਰਡਾਂ ਅਤੇ ਪਾਸਕੀਆਂ ਨੂੰ ਸਟੋਰ ਕਰੇਗਾ।"</string>
     <string name="set_as_default" msgid="4415328591568654603">"ਪੂਰਵ-ਨਿਰਧਾਰਿਤ ਵਜੋਂ ਸੈੱਟ ਕਰੋ"</string>
     <string name="use_once" msgid="9027366575315399714">"ਇੱਕ ਵਾਰ ਵਰਤੋ"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> ਪਾਸਵਰਡ, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> ਪਾਸਕੀਆਂ"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> ਪਾਸਵਰਡ"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> ਪਾਸਕੀਆਂ"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"ਪਾਸਕੀ"</string>
     <string name="another_device" msgid="5147276802037801217">"ਹੋਰ ਡੀਵਾਈਸ"</string>
     <string name="other_password_manager" msgid="565790221427004141">"ਹੋਰ ਪਾਸਵਰਡ ਪ੍ਰਬੰਧਕ"</string>
     <string name="close_sheet" msgid="1393792015338908262">"ਸ਼ੀਟ ਬੰਦ ਕਰੋ"</string>
diff --git a/packages/CredentialManager/res/values-pl/strings.xml b/packages/CredentialManager/res/values-pl/strings.xml
index af6bc9d..462ded0 100644
--- a/packages/CredentialManager/res/values-pl/strings.xml
+++ b/packages/CredentialManager/res/values-pl/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Menedżer danych logowania"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Anuluj"</string>
     <string name="string_continue" msgid="1346732695941131882">"Dalej"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Utwórz w innym miejscu"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Zapisz w innym miejscu"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Użyj innego urządzenia"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Zapisz na innym urządzeniu"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Prosty sposób na bezpieczne logowanie"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Używaj odcisku palca, rozpoznawania twarzy lub blokady ekranu, aby logować się z wykorzystaniem unikalnego klucza, którego nie można zapomnieć ani utracić w wyniku kradzieży. Więcej informacji"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Wybierz, gdzie chcesz <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Wybierz, gdzie chcesz <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"tworzyć klucze"</string>
     <string name="save_your_password" msgid="6597736507991704307">"zapisać hasło"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"zapisać dane logowania"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Ustaw domyślny menedżer haseł, aby zapisywać swoje hasła oraz klucze dostępu i aby logować się szybciej w przyszłości."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Utworzyć klucz w usłudze <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Zapisać hasło w usłudze <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Zapisać dane logowania w usłudze <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"klucz"</string>
     <string name="password" msgid="6738570945182936667">"hasło"</string>
     <string name="sign_ins" msgid="4710739369149469208">"dane logowania"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Utwórz klucz w usłudze"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Zapisz hasło w usłudze"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Zapisz dane logowania w usłudze"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Utworzyć klucz na innym urządzeniu?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Używać usługi <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> w przypadku wszystkich danych logowania?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Menedżer haseł będzie zapisywał Twoje hasła i klucze, aby ułatwić Ci logowanie."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Ustaw jako domyślną"</string>
     <string name="use_once" msgid="9027366575315399714">"Użyj raz"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"Hasła: <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>, klucze: <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g>"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"Hasła: <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"Klucze: <xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g>"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Klucz"</string>
     <string name="another_device" msgid="5147276802037801217">"Inne urządzenie"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Inne menedżery haseł"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Zamknij arkusz"</string>
diff --git a/packages/CredentialManager/res/values-pt-rBR/strings.xml b/packages/CredentialManager/res/values-pt-rBR/strings.xml
index d950bb4..945adc2 100644
--- a/packages/CredentialManager/res/values-pt-rBR/strings.xml
+++ b/packages/CredentialManager/res/values-pt-rBR/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Salvar em outro lugar"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Usar outro dispositivo"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Salvar em outro dispositivo"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Uma maneira simples de fazer login com segurança"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Use a impressão digital, o reconhecimento facial ou um bloqueio de tela para fazer login com uma única chave de acesso que não pode ser esquecida ou perdida. Saiba mais"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Escolha onde <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Escolha onde <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"crie suas chaves de acesso"</string>
     <string name="save_your_password" msgid="6597736507991704307">"salvar sua senha"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"salvar suas informações de login"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Defina um gerenciador de senhas padrão para salvar suas senhas e chaves de acesso e fazer login mais rápido na próxima vez."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Criar uma chave de acesso em <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Salvar sua senha em <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Salvar suas informações de login em <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"chave de acesso"</string>
     <string name="password" msgid="6738570945182936667">"senha"</string>
     <string name="sign_ins" msgid="4710739369149469208">"logins"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Criar chave de acesso em"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Salvar senha em"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Salvar informações de login em"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Criar uma chave de acesso em outro dispositivo?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Usar <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> para todos os seus logins?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Este gerenciador de senhas vai armazenar suas senhas e chaves de acesso para facilitar o processo de login."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Definir como padrão"</string>
     <string name="use_once" msgid="9027366575315399714">"Usar uma vez"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> senhas, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> chaves de acesso"</string>
diff --git a/packages/CredentialManager/res/values-pt-rPT/strings.xml b/packages/CredentialManager/res/values-pt-rPT/strings.xml
index c46143c..93a7a5f 100644
--- a/packages/CredentialManager/res/values-pt-rPT/strings.xml
+++ b/packages/CredentialManager/res/values-pt-rPT/strings.xml
@@ -8,8 +8,14 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Guardar noutro lugar"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Usar outro dispositivo"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Guardar noutro dispositivo"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Uma forma simples de iniciar sessão em segurança"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Use a sua impressão digital, rosto ou bloqueio de ecrã para iniciar sessão com uma chave de acesso única que não pode ser esquecida nem perdida. Saiba mais"</string>
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
     <string name="choose_provider_title" msgid="7245243990139698508">"Escolha onde quer guardar <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
     <string name="create_your_passkeys" msgid="8901224153607590596">"criar as suas chaves de acesso"</string>
     <string name="save_your_password" msgid="6597736507991704307">"guardar a sua palavra-passe"</string>
diff --git a/packages/CredentialManager/res/values-pt/strings.xml b/packages/CredentialManager/res/values-pt/strings.xml
index d950bb4..945adc2 100644
--- a/packages/CredentialManager/res/values-pt/strings.xml
+++ b/packages/CredentialManager/res/values-pt/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Salvar em outro lugar"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Usar outro dispositivo"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Salvar em outro dispositivo"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Uma maneira simples de fazer login com segurança"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Use a impressão digital, o reconhecimento facial ou um bloqueio de tela para fazer login com uma única chave de acesso que não pode ser esquecida ou perdida. Saiba mais"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Escolha onde <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Escolha onde <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"crie suas chaves de acesso"</string>
     <string name="save_your_password" msgid="6597736507991704307">"salvar sua senha"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"salvar suas informações de login"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Defina um gerenciador de senhas padrão para salvar suas senhas e chaves de acesso e fazer login mais rápido na próxima vez."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Criar uma chave de acesso em <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Salvar sua senha em <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Salvar suas informações de login em <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"chave de acesso"</string>
     <string name="password" msgid="6738570945182936667">"senha"</string>
     <string name="sign_ins" msgid="4710739369149469208">"logins"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Criar chave de acesso em"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Salvar senha em"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Salvar informações de login em"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Criar uma chave de acesso em outro dispositivo?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Usar <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> para todos os seus logins?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Este gerenciador de senhas vai armazenar suas senhas e chaves de acesso para facilitar o processo de login."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Definir como padrão"</string>
     <string name="use_once" msgid="9027366575315399714">"Usar uma vez"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> senhas, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> chaves de acesso"</string>
diff --git a/packages/CredentialManager/res/values-ro/strings.xml b/packages/CredentialManager/res/values-ro/strings.xml
index 6947281..da7ec1a 100644
--- a/packages/CredentialManager/res/values-ro/strings.xml
+++ b/packages/CredentialManager/res/values-ro/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Manager de date de conectare"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Anulează"</string>
     <string name="string_continue" msgid="1346732695941131882">"Continuă"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Creează în alt loc"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Salvează în alt loc"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Folosește alt dispozitiv"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Salvează pe alt dispozitiv"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Un mod simplu de a te conecta în siguranță"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Folosește-ți amprenta, fața sau blocarea ecranului ca să te conectezi cu o cheie de acces unică, pe care nu o poți uita și care nu poate fi furată. Află mai multe"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Alege unde <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Alege unde <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"creează cheile de acces"</string>
     <string name="save_your_password" msgid="6597736507991704307">"salvează parola"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"salvează informațiile de conectare"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Setează un manager de parole implicit pentru a salva parolele și cheile de acces și a te conecta mai rapid data viitoare."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Creezi o cheie de acces în <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Salvezi parola în <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Salvezi informațiile de conectare în <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"cheie de acces"</string>
     <string name="password" msgid="6738570945182936667">"parolă"</string>
     <string name="sign_ins" msgid="4710739369149469208">"date de conectare"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Creează o cheie de acces în"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Salvează parola în"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Salvează datele de conectare în"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Creezi o cheie de acces în alt dispozitiv?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Folosești <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> pentru toate conectările?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Managerul de parole îți va stoca parolele și cheile de acces, pentru a te ajuta să te conectezi cu ușurință."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Setează ca prestabilite"</string>
     <string name="use_once" msgid="9027366575315399714">"Folosește o dată"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> parole, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> chei de acces"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> parole"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> chei de acces"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Cheie de acces"</string>
     <string name="another_device" msgid="5147276802037801217">"Alt dispozitiv"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Alți manageri de parole"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Închide foaia"</string>
diff --git a/packages/CredentialManager/res/values-ru/strings.xml b/packages/CredentialManager/res/values-ru/strings.xml
index dcc643e..7dc51a2 100644
--- a/packages/CredentialManager/res/values-ru/strings.xml
+++ b/packages/CredentialManager/res/values-ru/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Сохранить в другом месте"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Использовать другое устройство"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Сохранить на другом устройстве"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Простой и безопасный способ входа"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"С уникальным ключом доступа, который невозможно украсть или забыть, вы можете подтверждать свою личность по отпечатку пальца, с помощью фейсконтроля или блокировки экрана. Подробнее…"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Выберите, где <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Выберите, где <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"создать ключи доступа"</string>
     <string name="save_your_password" msgid="6597736507991704307">"сохранить пароль"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"сохранить данные для входа"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Задайте менеджер паролей по умолчанию, чтобы сохранять пароли и ключи доступа и быстро выполнять вход."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Создать ключ доступа в приложении \"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>\"?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Сохранить пароль в приложении \"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>\"?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Сохранить учетные данные в приложении \"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>\"?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"ключ доступа"</string>
     <string name="password" msgid="6738570945182936667">"пароль"</string>
     <string name="sign_ins" msgid="4710739369149469208">"входы"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Выберите, где создать ключ доступа"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Выберите, где сохранить пароль"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Выберите, где сохранить учетные данные"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Создать ключ доступа на другом устройстве?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Всегда входить с помощью приложения \"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>\"?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"В этом менеджере паролей можно сохранять учетные данные, например ключи доступа, чтобы потом использовать их."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Использовать по умолчанию"</string>
     <string name="use_once" msgid="9027366575315399714">"Использовать один раз"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"Пароли (<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>) и ключи доступа (<xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g>)"</string>
diff --git a/packages/CredentialManager/res/values-si/strings.xml b/packages/CredentialManager/res/values-si/strings.xml
index bf885a9..fd94e5a 100644
--- a/packages/CredentialManager/res/values-si/strings.xml
+++ b/packages/CredentialManager/res/values-si/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"අක්තපත්‍ර කළමනාකරු"</string>
     <string name="string_cancel" msgid="6369133483981306063">"අවලංගු කරන්න"</string>
     <string name="string_continue" msgid="1346732695941131882">"ඉදිරියට යන්න"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"වෙනත් ස්ථානයක තනන්න"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"වෙනත් ස්ථානයකට සුරකින්න"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"වෙනත් උපාංගයක් භාවිතා කරන්න"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"වෙනත් උපාංගයකට සුරකින්න"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"සුරක්ෂිතව පුරනය වීමට සරල ක්‍රමයක්"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"අමතක කළ නොහැකි හෝ සොරකම් කළ නොහැකි අනන්‍ය මුරයතුරක් සමග පුරනය වීමට ඔබේ ඇඟිලි සලකුණ, මුහුණ හෝ තිර අගුල භාවිතා කරන්න. තව දැන ගන්න⁠"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> කොතැනක ද යන්න තෝරා ගන්න"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> කොතැනක ද යන්න තෝරා ගන්න"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"ඔබේ මුරයතුරු තනන්න"</string>
     <string name="save_your_password" msgid="6597736507991704307">"ඔබේ මුරපදය සුරකින්න"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"ඔබේ පුරනය වීමේ තතු සුරකින්න"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"ඔබේ මුරපද සහ මුරයතුරු සුරැකීමට පෙරනිමි මුරපද කළමනාකරු සකසන්න සහ මීළඟ වතාවේ වේගයෙන් පුරනය වන්න."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> තුළ මුරයතුරක් තනන්න ද?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"ඔබේ මුරපදය <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> වෙත සුරකින්න ද?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"ඔබේ පුරනය වීමේ තතු <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> වෙත සුරකින්න ද?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"මුරයතුර"</string>
     <string name="password" msgid="6738570945182936667">"මුරපදය"</string>
     <string name="sign_ins" msgid="4710739369149469208">"පුරනය වීම්"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"මුරයතුර තනන්නේ"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"මෙයට මුරපදය සුරකින්න"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"පුරනය වීම සුරකින්නේ"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"වෙනත් උපාංගයක මුරයතුරක් තනන්න ද?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"ඔබේ සියලු පුරනය වීම් සඳහා <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> භාවිතා කරන්න ද?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"මෙම මුරපද කළමනාකරු ඔබට පහසුවෙන් පුරනය වීමට උදවු කිරීම සඳහා ඔබේ මුරපද සහ මුරයතුරු ගබඩා කරනු ඇත."</string>
     <string name="set_as_default" msgid="4415328591568654603">"පෙරනිමි ලෙස සකසන්න"</string>
     <string name="use_once" msgid="9027366575315399714">"වරක් භාවිතා කරන්න"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"මුරපද <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>ක්, මුරයතුරු <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g>ක්"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"මුරපද <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>ක්"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"මුරයතුරු <xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g>ක්"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"මුරයතුර"</string>
     <string name="another_device" msgid="5147276802037801217">"වෙනත් උපාංගයක්"</string>
     <string name="other_password_manager" msgid="565790221427004141">"වෙනත් මුරපද කළමනාකරුවන්"</string>
     <string name="close_sheet" msgid="1393792015338908262">"පත්‍රය වසන්න"</string>
diff --git a/packages/CredentialManager/res/values-sk/strings.xml b/packages/CredentialManager/res/values-sk/strings.xml
index 1c73c57..cd81361 100644
--- a/packages/CredentialManager/res/values-sk/strings.xml
+++ b/packages/CredentialManager/res/values-sk/strings.xml
@@ -8,8 +8,14 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Uložiť inde"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Použiť iné zariadenie"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Uložiť do iného zariadenia"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Jednoduchý spôsob bezpečného prihlasovania"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Použite odtlačok prsta, tvár alebo zámku obrazovky a prihláste sa jedinečným prístupovým kľúčom, ktorý sa nedá zabudnúť ani ukradnúť. Ďalšie informácie"</string>
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
     <string name="choose_provider_title" msgid="7245243990139698508">"Vyberte, kam <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
     <string name="create_your_passkeys" msgid="8901224153607590596">"vytvoriť prístupové kľúče"</string>
     <string name="save_your_password" msgid="6597736507991704307">"uložiť heslo"</string>
diff --git a/packages/CredentialManager/res/values-sl/strings.xml b/packages/CredentialManager/res/values-sl/strings.xml
index 969f290..c769e19 100644
--- a/packages/CredentialManager/res/values-sl/strings.xml
+++ b/packages/CredentialManager/res/values-sl/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Shranjevanje na drugo mesto"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Uporabi drugo napravo"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Shrani v drugo napravo"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Preprost način za varno prijavo"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Če se želite prijaviti z enoličnim ključem za dostop, ki ga ni mogoče pozabiti ali ukrasti, uporabite prstni odtis, obraz ali nastavljeni način za odklepanje zaslona. Več o tem"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Izberite mesto za <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Izberite mesto za <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"ustvarjanje ključev za dostop"</string>
     <string name="save_your_password" msgid="6597736507991704307">"shranjevanje gesla"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"shranjevanje podatkov za prijavo"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Nastavite privzetega upravitelja gesel za shranjevanje gesel in ključev za dostop, da se boste naslednjič lahko hitreje prijavili."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Želite ustvariti ključ za dostop pod »<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>«?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Želite shraniti geslo pod »<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>«?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Želite shraniti podatke za prijavo pod »<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>«?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"ključ za dostop"</string>
     <string name="password" msgid="6738570945182936667">"geslo"</string>
     <string name="sign_ins" msgid="4710739369149469208">"prijave"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Ustvarjanje ključa za dostop v"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Shranjevanje gesla v"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Shranjevanje podatkov za prijavo v"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Želite ustvariti ključ za dostop v drugi napravi?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Želite za vse prijave uporabiti »<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>«?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"V tem upravitelju gesel bodo shranjeni gesla in ključi za dostop, kar vam bo olajšalo prijavo."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Nastavi kot privzeto"</string>
     <string name="use_once" msgid="9027366575315399714">"Uporabi enkrat"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"Št. gesel: <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>, št. ključev za dostop: <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g>"</string>
diff --git a/packages/CredentialManager/res/values-sq/strings.xml b/packages/CredentialManager/res/values-sq/strings.xml
index bce0683..7e656d6 100644
--- a/packages/CredentialManager/res/values-sq/strings.xml
+++ b/packages/CredentialManager/res/values-sq/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Menaxheri i kredencialeve"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Anulo"</string>
     <string name="string_continue" msgid="1346732695941131882">"Vazhdo"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Krijo në një vend tjetër"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Ruaj në një vend tjetër"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Përdor një pajisje tjetër"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Ruaj në një pajisje tjetër"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Një mënyrë e thjeshtë për t\'u identifikuar në mënyrë të sigurt"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Përdor gjurmën e gishtit, fytyrën ose kyçjen e ekranit për t\'u identifikuar me një çelës unik kalimi i cili nuk mund të harrohet ose të vidhet. Mëso më shumë"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Zgjidh se ku të <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Zgjidh se ku të <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"do t\'i krijosh çelësat e tu të kalimit"</string>
     <string name="save_your_password" msgid="6597736507991704307">"ruaj fjalëkalimin"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"ruaj informacionet e tua të identifikimit"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Cakto një menaxher të parazgjedhur të fjalëkalimeve për të ruajtur fjalëkalimet dhe çelësat e kalimit dhe për t\'u identifikuar më shpejt herën tjetër."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Të krijohet një çelës kalimi në <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Të ruhet fjalëkalimi në <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Të ruhen informacionet e tua të identifikimit në <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"çelësi i kalimit"</string>
     <string name="password" msgid="6738570945182936667">"fjalëkalimi"</string>
     <string name="sign_ins" msgid="4710739369149469208">"identifikimet"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Krijo çelësin e kalimit te"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Ruaj fjalëkalimin në"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Ruaj identifikimin në"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Të krijohet një çelës kalimi në një pajisje tjetër?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Të përdoret <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> për të gjitha identifikimet?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Ky menaxher i fjalëkalimeve do të ruajë fjalëkalimet dhe çelësat e kalimit për të të ndihmuar të identifikohesh me lehtësi."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Cakto si parazgjedhje"</string>
     <string name="use_once" msgid="9027366575315399714">"Përdor një herë"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> fjalëkalime, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> çelësa kalimi"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> fjalëkalime"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> çelësa kalimi"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Çelësi i kalimit"</string>
     <string name="another_device" msgid="5147276802037801217">"Një pajisje tjetër"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Menaxherët e tjerë të fjalëkalimeve"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Mbyll fletën"</string>
diff --git a/packages/CredentialManager/res/values-sr/strings.xml b/packages/CredentialManager/res/values-sr/strings.xml
index 6a5235c..cfb6c05 100644
--- a/packages/CredentialManager/res/values-sr/strings.xml
+++ b/packages/CredentialManager/res/values-sr/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Менаџер акредитива"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Откажи"</string>
     <string name="string_continue" msgid="1346732695941131882">"Настави"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Направи на другом месту"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Сачувај на другом месту"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Користи други уређај"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Сачувај на други уређај"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Једноставан начин да се безбедно пријављујете"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Користите отисак прста, закључавање лицем или закључавање екрана да бисте се пријавили помоћу јединственог приступног кода који не може да се заборави или украде. Сазнајте више"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Одаберите локацију за: <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Одаберите локацију за: <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"направите приступне кодове"</string>
     <string name="save_your_password" msgid="6597736507991704307">"сачувајте лозинку"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"сачувајте податке о пријављивању"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Подесите подразумевани менаџер лозинки да бисте сачували лозинке и приступне кодове и следећи пут се пријавили брже."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Желите да направите приступни кôд код корисника <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Желите да сачувате лозинку код корисника <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Желите да сачувате податке о пријављивању код корисника <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"приступни кôд"</string>
     <string name="password" msgid="6738570945182936667">"лозинка"</string>
     <string name="sign_ins" msgid="4710739369149469208">"пријављивања"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Направите приступни кôд у:"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Сачувајте лозинку на:"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Сачувајте податке о пријављивању на:"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Желите да направите приступни кôд на другом уређају?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Желите да за сва пријављивања користите: <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Овај менаџер лозинки ће чувати лозинке и приступне кодове да бисте се лако пријављивали."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Подеси као подразумевано"</string>
     <string name="use_once" msgid="9027366575315399714">"Користи једном"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"Лозинки: <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>, приступних кодова:<xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g>"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"Лозинки: <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"Приступних кодова: <xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g>"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Приступни кôд"</string>
     <string name="another_device" msgid="5147276802037801217">"Други уређај"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Други менаџери лозинки"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Затворите табелу"</string>
diff --git a/packages/CredentialManager/res/values-sv/strings.xml b/packages/CredentialManager/res/values-sv/strings.xml
index a4fffb9..842d787 100644
--- a/packages/CredentialManager/res/values-sv/strings.xml
+++ b/packages/CredentialManager/res/values-sv/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Spara på en annan plats"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Använd en annan enhet"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Spara på en annan enhet"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Ett enkelt sätt att logga in säkert på"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Använd ditt fingeravtryck, ansikte eller skärmlås om du vill logga in med en unik nyckel som inte kan glömmas bort eller bli stulen. Läs mer"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Välj var du <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Välj var du <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"skapa nycklar"</string>
     <string name="save_your_password" msgid="6597736507991704307">"spara lösenordet"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"spara inloggningsuppgifterna"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Ställ in vilken lösenordshanterare som ska användas som standard om du vill spara lösenord, nycklar och inloggningsuppgifter snabbare nästa gång."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Vill du skapa en nyckel i <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Vill du spara ditt lösenord i <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Vill du spara dina inloggningsuppgifter i <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"nyckel"</string>
     <string name="password" msgid="6738570945182936667">"lösenord"</string>
     <string name="sign_ins" msgid="4710739369149469208">"inloggningar"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Skapa nyckel i"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Spara lösenordet i"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Spara inloggningen i"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Vill du skapa en nyckel på en annan enhet?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Vill du använda <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> för alla dina inloggningar?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Den här lösenordshanteraren sparar dina lösenord och nycklar för att underlätta inloggning."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Ange som standard"</string>
     <string name="use_once" msgid="9027366575315399714">"Använd en gång"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> lösenord, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> nycklar"</string>
diff --git a/packages/CredentialManager/res/values-sw/strings.xml b/packages/CredentialManager/res/values-sw/strings.xml
index bfd1074..3eb7432 100644
--- a/packages/CredentialManager/res/values-sw/strings.xml
+++ b/packages/CredentialManager/res/values-sw/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Kidhibiti cha Vitambulisho"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Ghairi"</string>
     <string name="string_continue" msgid="1346732695941131882">"Endelea"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Unda katika sehemu nyingine"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Hifadhi sehemu nyingine"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Tumia kifaa kingine"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Hifadhi kwenye kifaa kingine"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Njia rahisi ya kuingia katika akaunti kwa usalama"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Tumia alama ya vidole, uso au kipengele cha kufunga skrini ili uingie katika kaunti kwa kutumia nenosiri la kipekee ambalo haliwezi kusahaulika au kuibiwa. Pata maelezo zaidi"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Chagua mahali pa <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Chagua mahali pa <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"unda funguo zako za siri"</string>
     <string name="save_your_password" msgid="6597736507991704307">"hifadhi nenosiri lako"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"hifadhi maelezo yako ya kuingia katika akaunti"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Weka kidhibiti chaguomsingi cha manenosiri ili uhifadhi manenosiri na funguo zako za siri na uingie katika akaunti kwa haraka wakati mwingine."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Ungependa kuunda ufunguo wa siri katika <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Ungependa kuhifadhi nenosiri lako kwenye <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Ungependa kuhifadhi maelezo yako ya kuingia katika akaunti kwenye <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"ufunguo wa siri"</string>
     <string name="password" msgid="6738570945182936667">"nenosiri"</string>
     <string name="sign_ins" msgid="4710739369149469208">"michakato ya kuingia katika akaunti"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Unda ufunguo wa siri kwenye"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Hifadhi nenosiri kwenye"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Hifadhi kitambulisho cha kuingia katika akaunti kwenye"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Ungependa kuunda ufunguo wa siri kwenye kifaa kingine?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Ungependa kutumia <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> kwa ajili ya michakato yako yote ya kuingia katika akaunti?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Kidhibiti hiki cha manenosiri kitahifadhi manenosiri na funguo zako za siri ili kukusaidia uingie katika akaunti kwa urahisi."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Weka iwe chaguomsingi"</string>
     <string name="use_once" msgid="9027366575315399714">"Tumia mara moja"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"Manenosiri <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>, funguo <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> za siri"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"Manenosiri <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"Funguo <xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> za siri"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Ufunguo wa siri"</string>
     <string name="another_device" msgid="5147276802037801217">"Kifaa kingine"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Vidhibiti vinginevyo vya manenosiri"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Funga laha"</string>
diff --git a/packages/CredentialManager/res/values-ta/strings.xml b/packages/CredentialManager/res/values-ta/strings.xml
index 10c5259..2d7d84e 100644
--- a/packages/CredentialManager/res/values-ta/strings.xml
+++ b/packages/CredentialManager/res/values-ta/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"அனுமதிச் சான்று நிர்வாகி"</string>
     <string name="string_cancel" msgid="6369133483981306063">"ரத்துசெய்"</string>
     <string name="string_continue" msgid="1346732695941131882">"தொடர்க"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"மற்றொரு இடத்தில் உருவாக்கவும்"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"மற்றொரு இடத்தில் சேமிக்கவும்"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"மற்றொரு சாதனத்தைப் பயன்படுத்தவும்"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"வேறொரு சாதனத்தில் சேமியுங்கள்"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"பாதுகாப்பாக உள்நுழைவதற்கான எளிய வழி"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"தனித்துவமான கடவுக்குறியீடு (மறக்காதவை அல்லது திருடமுடியாதவை) மூலம் உள்நுழைய, உங்கள் கைரேகை, முகம் அல்லது திரைப்பூட்டைப் பயன்படுத்தி உள்நுழையவும். மேலும் அறிக"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> எங்கே காட்டப்பட வேண்டும் என்பதைத் தேர்வுசெய்தல்"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> எங்கே காட்டப்பட வேண்டும் என்பதைத் தேர்வுசெய்தல்"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"உங்கள் கடவுச்சாவிகளை உருவாக்குங்கள்"</string>
     <string name="save_your_password" msgid="6597736507991704307">"உங்கள் கடவுச்சொல்லைச் சேமிக்கவும்"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"உங்கள் உள்நுழைவு தகவலைச் சேமிக்கவும்"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"கடவுச்சொற்கள் &amp; கடவுச்சாவிகளைச் சேமிக்கவும் அடுத்தமுறை விரைவாக உள்நுழையவும் ஓர் இயல்பான Password Managerரை அமையுங்கள்."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>ல் கடவுக்குறியீட்டை உருவாக்க வேண்டுமா?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"உங்கள் கடவுச்சொல்லை <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>ல் சேமிக்க வேண்டுமா?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"உங்கள் உள்நுழைவுத் தகவலை <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>ல் சேமிக்க வேண்டுமா?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"கடவுக்குறியீடு"</string>
     <string name="password" msgid="6738570945182936667">"கடவுச்சொல்"</string>
     <string name="sign_ins" msgid="4710739369149469208">"உள்நுழைவுகள்"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"இதில் கடவுச்சாவியை உருவாக்குங்கள்:"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"கடவுச்சொல்லை இதில் சேமியுங்கள்:"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"உள்நுழைவுத் தகவலை இதில் சேமியுங்கள்:"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"வேறொரு சாதனத்தில் கடவுச்சாவியை உருவாக்கவா?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"உங்கள் அனைத்து உள்நுழைவுகளுக்கும் <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>ஐப் பயன்படுத்தவா?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"எளிதில் உள்நுழைவதற்கு உதவும் வகையில் இந்த Password Manager உங்கள் கடவுச்சொற்களையும் கடவுச்சாவிகளையும் சேமிக்கும்."</string>
     <string name="set_as_default" msgid="4415328591568654603">"இயல்பானதாக அமை"</string>
     <string name="use_once" msgid="9027366575315399714">"ஒருமுறை பயன்படுத்தவும்"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> கடவுச்சொற்கள், <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> கடவுக்குறியீடுகள்"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> கடவுச்சொற்கள்"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> கடவுக்குறியீடுகள்"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"கடவுக்குறியீடு"</string>
     <string name="another_device" msgid="5147276802037801217">"மற்றொரு சாதனம்"</string>
     <string name="other_password_manager" msgid="565790221427004141">"பிற கடவுச்சொல் நிர்வாகிகள்"</string>
     <string name="close_sheet" msgid="1393792015338908262">"ஷீட்டை மூடும்"</string>
diff --git a/packages/CredentialManager/res/values-te/strings.xml b/packages/CredentialManager/res/values-te/strings.xml
index f7617b3..664252d 100644
--- a/packages/CredentialManager/res/values-te/strings.xml
+++ b/packages/CredentialManager/res/values-te/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"డాక్యుమెంట్ ప్రూఫ్ మేనేజర్"</string>
     <string name="string_cancel" msgid="6369133483981306063">"రద్దు చేయండి"</string>
     <string name="string_continue" msgid="1346732695941131882">"కొనసాగించండి"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"మరొక స్థలంలో క్రియేట్ చేయండి"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"మరొక స్థలంలో సేవ్ చేయండి"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"మరొక పరికరాన్ని ఉపయోగించండి"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"మరొక పరికరంలో సేవ్ చేయండి"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"సురక్షితంగా సైన్ ఇన్ చేయడానికి సులభమైన మార్గం"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"మర్చిపోలేని లేదా దొంగిలించలేని ప్రత్యేకమైన పాస్-కీతో సైన్ ఇన్ చేయడానికి మీ వేలిముద్ర, ముఖం లేదా స్క్రీన్ లాక్‌ను ఉపయోగించండి. మరింత తెలుసుకోండి"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"ఎక్కడ <xliff:g id="CREATETYPES">%1$s</xliff:g> చేయాలో ఎంచుకోండి"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"ఎక్కడ <xliff:g id="CREATETYPES">%1$s</xliff:g> చేయాలో ఎంచుకోండి"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"మీ పాస్-కీలను క్రియేట్ చేయండి"</string>
     <string name="save_your_password" msgid="6597736507991704307">"మీ పాస్‌వర్డ్‌ను సేవ్ చేయండి"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"మీ సైన్ ఇన్ సమాచారాన్ని సేవ్ చేయండి"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"మీ పాస్‌వర్డ్‌లు, పాస్‌కీలను సేవ్ చేయడానికి ఆటోమేటిక్ సెట్టింగ్ పాస్‌వర్డ్ మేనేజర్‌ను సెట్ చేయండి, తదుపరిసారి వేగంగా సైన్ ఇన్ చేయండి."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>లో పాస్-కీని క్రియేట్ చేయాలా?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"మీ పాస్‌వర్డ్‌ను <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>కు సేవ్ చేయాలా?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"మీ సైన్ ఇన్ సమాచారాన్ని <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>కు సేవ్ చేయాలా?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"పాస్-కీ"</string>
     <string name="password" msgid="6738570945182936667">"పాస్‌వర్డ్"</string>
     <string name="sign_ins" msgid="4710739369149469208">"సైన్‌ ఇన్‌లు"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"వీటిలో పాస్-కీని క్రియేట్ చేయండి"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"పాస్‌వర్డ్‌ను దీనికి సేవ్ చేయండి"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"సైన్ ఇన్‌ను దీనికి సేవ్ చేయండి"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"మరొక పరికరంలో పాస్-కీని క్రియేట్ చేయాలా?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"మీ అన్ని సైన్-ఇన్ వివరాల కోసం <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>ను ఉపయోగించాలా?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"మీరు సులభంగా సైన్ ఇన్ చేయడంలో సహాయపడటానికి ఈ పాస్‌వర్డ్ మేనేజర్ మీ పాస్‌వర్డ్‌లు, పాస్-కీలను స్టోర్ చేస్తుంది."</string>
     <string name="set_as_default" msgid="4415328591568654603">"ఆటోమేటిక్ సెట్టింగ్‌గా సెట్ చేయండి"</string>
     <string name="use_once" msgid="9027366575315399714">"ఒకసారి ఉపయోగించండి"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> పాస్‌వర్డ్‌లు, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> పాస్-కీలు"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> పాస్‌వర్డ్‌లు"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> పాస్-కీలు"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"పాస్-కీ"</string>
     <string name="another_device" msgid="5147276802037801217">"మరొక పరికరం"</string>
     <string name="other_password_manager" msgid="565790221427004141">"ఇతర పాస్‌వర్డ్ మేనేజర్‌లు"</string>
     <string name="close_sheet" msgid="1393792015338908262">"షీట్‌ను మూసివేయండి"</string>
diff --git a/packages/CredentialManager/res/values-th/strings.xml b/packages/CredentialManager/res/values-th/strings.xml
index d70e94a..106c456 100644
--- a/packages/CredentialManager/res/values-th/strings.xml
+++ b/packages/CredentialManager/res/values-th/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"บันทึกลงในตำแหน่งอื่น"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"ใช้อุปกรณ์อื่น"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"ย้ายไปยังอุปกรณ์อื่น"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"วิธีง่ายๆ ในการลงชื่อเข้าใช้อย่างปลอดภัย"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"ใช้ลายนิ้วมือ ใบหน้า หรือล็อกหน้าจอในการลงชื่อเข้าใช้ด้วยพาสคีย์ที่ไม่ซ้ำกันเพื่อไม่ให้ลืมหรือถูกขโมยได้ ดูข้อมูลเพิ่มเติม"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"เลือกตำแหน่งที่จะ <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"เลือกตำแหน่งที่จะ <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"สร้างพาสคีย์"</string>
     <string name="save_your_password" msgid="6597736507991704307">"บันทึกรหัสผ่าน"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"บันทึกข้อมูลการลงชื่อเข้าใช้"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"ตั้งค่าเครื่องมือจัดการรหัสผ่านเริ่มต้นเพื่อบันทึกรหัสผ่านและพาสคีย์ของคุณ และลงชื่อเข้าใช้ได้เร็วขึ้นในครั้งถัดไป"</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"สร้างพาสคีย์ใน <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ใช่ไหม"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"บันทึกรหัสผ่านลงใน <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ใช่ไหม"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"บันทึกข้อมูลการลงชื่อเข้าใช้ลงใน <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ใช่ไหม"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"พาสคีย์"</string>
     <string name="password" msgid="6738570945182936667">"รหัสผ่าน"</string>
     <string name="sign_ins" msgid="4710739369149469208">"การลงชื่อเข้าใช้"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"สร้างพาสคีย์ใน"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"บันทึกรหัสผ่านลงใน"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"บันทึกการลงชื่อเข้าใช้ไปยัง"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"สร้างพาสคีย์ในอุปกรณ์อื่นไหม"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"ใช้ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> สำหรับการลงชื่อเข้าใช้ทั้งหมดใช่ไหม"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"เครื่องมือจัดการรหัสผ่านนี้จะจัดเก็บรหัสผ่านและพาสคีย์ไว้เพื่อช่วยให้คุณลงชื่อเข้าใช้ได้โดยง่าย"</string>
     <string name="set_as_default" msgid="4415328591568654603">"ตั้งเป็นค่าเริ่มต้น"</string>
     <string name="use_once" msgid="9027366575315399714">"ใช้ครั้งเดียว"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"รหัสผ่าน <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> รายการ พาสคีย์ <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> รายการ"</string>
diff --git a/packages/CredentialManager/res/values-tl/strings.xml b/packages/CredentialManager/res/values-tl/strings.xml
index 01fd2f0..d550190 100644
--- a/packages/CredentialManager/res/values-tl/strings.xml
+++ b/packages/CredentialManager/res/values-tl/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"I-save sa ibang lugar"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Gumamit ng ibang device"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"I-save sa ibang device"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Simpleng paraan para mag-sign in lang ligtas"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Gamitin ang iyong fingerprint, mukha, o lock ng screen para mag-sign in gamit ang natatanging passkey na hindi makakalimutan o mananakaw. Matuto pa"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Piliin kung saan <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Piliin kung saan <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"gawin ang iyong mga passkey"</string>
     <string name="save_your_password" msgid="6597736507991704307">"i-save ang iyong password"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"i-save ang iyong impormasyon sa pag-sign in"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Magtakda ng default na password manager para i-save ang iyong mga password at passkey at mag-sign in nang mas mabilis sa susunod."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Gumawa ng passkey sa <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"I-save ang iyong password sa <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"I-save ang iyong impormasyon sa pag-sign in sa <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"passkey"</string>
     <string name="password" msgid="6738570945182936667">"password"</string>
     <string name="sign_ins" msgid="4710739369149469208">"mga sign-in"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Gumawa ng passkey sa"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"I-save ang password sa"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"I-save ang sign-in sa"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Gumawa ng passkey sa ibang device?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Gamitin ang <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> para sa lahat ng iyong pag-sign in?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Iso-store ng password manager na ito ang iyong mga password at passkey para madali kang makapag-sign in."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Itakda bilang default"</string>
     <string name="use_once" msgid="9027366575315399714">"Gamitin nang isang beses"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> (na) password, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> (na) passkey"</string>
diff --git a/packages/CredentialManager/res/values-tr/strings.xml b/packages/CredentialManager/res/values-tr/strings.xml
index 30ed43e..09c6590 100644
--- a/packages/CredentialManager/res/values-tr/strings.xml
+++ b/packages/CredentialManager/res/values-tr/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Kimlik Bilgisi Yöneticisi"</string>
     <string name="string_cancel" msgid="6369133483981306063">"İptal"</string>
     <string name="string_continue" msgid="1346732695941131882">"Devam"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Başka bir yerde oluşturun"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Başka bir yere kaydedin"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Başka bir cihaz kullan"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Başka bir cihaza kaydet"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Güvenli bir şekilde oturum açmanın basit yolu"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Parmak iziniz, yüzünüz ya da ekran kilidinizi kullanarak unutması veya çalınması mümkün olmayan benzersiz bir şifre anahtarıyla oturum açın. Daha fazla bilgi"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> yerini seçin"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> yerini seçin"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"şifre anahtarlarınızı oluşturun"</string>
     <string name="save_your_password" msgid="6597736507991704307">"şifrenizi kaydedin"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"oturum açma bilgilerinizi kaydedin"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Şifrelerinizi ve şifre anahtarlarınızı kaydedip bir dahaki sefere daha hızlı oturum açmak için varsayılan bir şifre yöneticisi belirleyin."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> içinde şifre anahtarı oluşturulsun mu?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Şifreniz <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> içine kaydedilsin mi?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Oturum açma bilgileriniz <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> içine kaydedilsin mi?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"şifre anahtarı"</string>
     <string name="password" msgid="6738570945182936667">"şifre"</string>
     <string name="sign_ins" msgid="4710739369149469208">"oturum aç"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Şifre anahtarının oluşturulacağı yer:"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Şifreyi şuraya kaydet:"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Oturum açma bilgilerinin kaydedileceği yer:"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Başka bir cihazda şifre anahtarı oluşturulsun mu?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Tüm oturum açma işlemlerinizde <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> kullanılsın mı?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Bu şifre yöneticisi, şifrelerinizi ve şifre anahtarlarınızı saklayarak kolayca oturum açmanıza yardımcı olur."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Varsayılan olarak ayarla"</string>
     <string name="use_once" msgid="9027366575315399714">"Bir kez kullanın"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> şifre, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> şifre anahtarı"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> şifre"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> şifre anahtarı"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Şifre anahtarı"</string>
     <string name="another_device" msgid="5147276802037801217">"Başka bir cihaz"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Diğer şifre yöneticileri"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Sayfayı kapat"</string>
diff --git a/packages/CredentialManager/res/values-uk/strings.xml b/packages/CredentialManager/res/values-uk/strings.xml
index 69d4612..9a12e33 100644
--- a/packages/CredentialManager/res/values-uk/strings.xml
+++ b/packages/CredentialManager/res/values-uk/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Диспетчер облікових даних"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Скасувати"</string>
     <string name="string_continue" msgid="1346732695941131882">"Продовжити"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Створити в іншому місці"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Зберегти в іншому місці"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Скористатись іншим пристроєм"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Зберегти на іншому пристрої"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Зручний спосіб для безпечного входу"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Користуйтеся відбитком пальця, фейсконтролем або іншим способом розблокування екрана, щоб входити в обліковий запис за допомогою унікального ключа доступу, який неможливо забути чи викрасти. Докладніше"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Виберіть, де <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Виберіть, де <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"створювати ключі доступу"</string>
     <string name="save_your_password" msgid="6597736507991704307">"зберегти пароль"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"зберегти дані для входу"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Налаштуйте менеджер паролів за умовчанням, щоб зберігати свої паролі та ключі доступу й надалі входити в облікові записи швидше."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Створити ключ доступу в сервісі <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Зберегти ваш пароль у сервісі <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Зберегти ваші дані для входу в сервіс <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"ключ доступу"</string>
     <string name="password" msgid="6738570945182936667">"пароль"</string>
     <string name="sign_ins" msgid="4710739369149469208">"дані для входу"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Створити ключ доступу в"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Зберегти пароль в обліковому записі"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Зберегти дані для входу в обліковий запис"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Створити ключ доступу на іншому пристрої?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Використовувати сервіс <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> в усіх випадках входу?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Цей менеджер паролів зберігатиме ваші паролі та ключі доступу, щоб ви могли легко входити в облікові записи."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Вибрати за умовчанням"</string>
     <string name="use_once" msgid="9027366575315399714">"Скористатися раз"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"Кількість паролів: <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>; кількість ключів доступу: <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g>"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"Кількість паролів: <xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"Кількість ключів доступу: <xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g>"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Ключ доступу"</string>
     <string name="another_device" msgid="5147276802037801217">"Інший пристрій"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Інші менеджери паролів"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Закрити аркуш"</string>
diff --git a/packages/CredentialManager/res/values-ur/strings.xml b/packages/CredentialManager/res/values-ur/strings.xml
index 2d66079..50fbb8d 100644
--- a/packages/CredentialManager/res/values-ur/strings.xml
+++ b/packages/CredentialManager/res/values-ur/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"دوسرے مقام میں محفوظ کریں"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"کوئی دوسرا آلہ استعمال کریں"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"دوسرے آلے میں محفوظ کریں"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"محفوظ طریقے سے سائن ان کرنے کا آسان طریقہ"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"اپنے فنگر پرنٹ، چہرے یا اسکرین لاک کا استعمال کریں تاکہ ایک ایسی منفرد پاس کی سے سائن ان کیا جا سکے جسے بھولا یا چوری نہیں کیا جا سکتا۔ مزید جانیں"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> کی جگہ منتخب کریں"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> کی جگہ منتخب کریں"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"اپنی پاس کیز تخلیق کریں"</string>
     <string name="save_your_password" msgid="6597736507991704307">"اپنا پاس ورڈ محفوظ کریں"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"اپنے سائن ان کی معلومات محفوظ کریں"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"اپنے پاس ورڈز اور پاس کیز کو محفوظ کرنے اور اگلی بار تیزی سے سائن ان کرنے کے لیے ایک ڈیفالٹ پاس ورڈ مینیجر سیٹ کریں۔"</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> میں پاس کی تخلیق کریں؟"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"اپنا پاس ورڈ <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> میں محفوظ کریں؟"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"اپنے سائن ان کی معلومات کو <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> میں محفوظ کریں؟"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"پاس کی"</string>
     <string name="password" msgid="6738570945182936667">"پاس ورڈ"</string>
     <string name="sign_ins" msgid="4710739369149469208">"سائن انز"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"اس میں پاس کی تخلیق کریں"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"میں پاس ورڈ محفوظ کریں"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"میں سائن ان محفوظ کریں"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"کسی اور آلے میں پاس کی تخلیق کریں؟"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"اپنے سبھی سائن انز کے لیے <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> کا استعمال کریں؟"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"یہ پاس ورڈ مینیجر آپ کے پاس ورڈز اور پاس کیز کو آسانی سے سائن ان کرنے میں آپ کی مدد کرنے کے لیے اسٹور کرے گا۔"</string>
     <string name="set_as_default" msgid="4415328591568654603">"بطور ڈیفالٹ سیٹ کریں"</string>
     <string name="use_once" msgid="9027366575315399714">"ایک بار استعمال کریں"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> پاس ورڈز، <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> پاس کیز"</string>
diff --git a/packages/CredentialManager/res/values-uz/strings.xml b/packages/CredentialManager/res/values-uz/strings.xml
index 4ac35b2..b46979a 100644
--- a/packages/CredentialManager/res/values-uz/strings.xml
+++ b/packages/CredentialManager/res/values-uz/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Hisob maʼlumotlari menejeri"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Bekor qilish"</string>
     <string name="string_continue" msgid="1346732695941131882">"Davom etish"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Boshqa joyda yaratish"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Boshqa joyga saqlash"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Boshqa qurilmadan foydalaning"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Boshqa qurilmaga saqlash"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Xavfsiz kirishning oddiy usuli"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Esda qoladigan maxsus kalit bilan kirishda barmoq izi, yuz axboroti yoki ekran qulfidan foydalaning. Batafsil"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> joyini tanlang"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"<xliff:g id="CREATETYPES">%1$s</xliff:g> joyini tanlang"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"kodlar yaratish"</string>
     <string name="save_your_password" msgid="6597736507991704307">"Parolni saqlash"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"kirish axborotini saqlang"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Parol va kodlarni saqlash va keyingi safar tezroq kirish uchun standart parollar menejerini sozlang."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Kalit <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> xizmatida yaratilsinmi?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Parol <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> xizmatida saqlansinmi?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Hisob maʼlumotlari <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> xizmatida saqlansinmi?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"kalit"</string>
     <string name="password" msgid="6738570945182936667">"parol"</string>
     <string name="sign_ins" msgid="4710739369149469208">"kirishlar"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Kod yaratish vositasi"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Parolni bu hisobga saqlash"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Kirish axborotini saqlash"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Boshqa qurilmada kod yaratilsinmi?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Hamma kirishlarda <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> ishlatilsinmi?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Bu parollar menejerida hisobga oson kirishga yordam beruvchi parol va kalitlar saqlanadi."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Birlamchi deb belgilash"</string>
     <string name="use_once" msgid="9027366575315399714">"Bir marta ishlatish"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> ta parol, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> ta kalit"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> ta parol"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> ta kalit"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Kod"</string>
     <string name="another_device" msgid="5147276802037801217">"Boshqa qurilma"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Boshqa parol menejerlari"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Varaqni yopish"</string>
diff --git a/packages/CredentialManager/res/values-vi/strings.xml b/packages/CredentialManager/res/values-vi/strings.xml
index fd5b986..6c3022e 100644
--- a/packages/CredentialManager/res/values-vi/strings.xml
+++ b/packages/CredentialManager/res/values-vi/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Trình quản lý thông tin xác thực"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Huỷ"</string>
     <string name="string_continue" msgid="1346732695941131882">"Tiếp tục"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Tạo ở vị trí khác"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Lưu vào vị trí khác"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Dùng thiết bị khác"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Lưu vào thiết bị khác"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Cách đơn giản để đăng nhập an toàn"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Dùng vân tay, khuôn mặt hoặc phương thức khoá màn hình để đăng nhập bằng một mã xác thực duy nhất mà bạn không lo sẽ quên hay bị đánh cắp. Tìm hiểu thêm"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"Chọn vị trí <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"Chọn vị trí <xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"tạo mã xác thực"</string>
     <string name="save_your_password" msgid="6597736507991704307">"lưu mật khẩu của bạn"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"lưu thông tin đăng nhập của bạn"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"Đặt một trình quản lý mật khẩu mặc định để lưu mật khẩu và mã xác thực của bạn, nhờ đó, bạn sẽ đăng nhập nhanh hơn vào lần sau."</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"Tạo một mã xác thực trong <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"Lưu mật khẩu của bạn vào <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"Lưu thông tin đăng nhập của bạn vào <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"mã xác thực"</string>
     <string name="password" msgid="6738570945182936667">"mật khẩu"</string>
     <string name="sign_ins" msgid="4710739369149469208">"thông tin đăng nhập"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"Tạo mã xác thực trong"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"Lưu mật khẩu vào"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"Lưu thông tin đăng nhập vào"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"Tạo mã xác thực trong một thiết bị khác?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"Dùng <xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g> cho mọi thông tin đăng nhập của bạn?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"Trình quản lý mật khẩu này sẽ lưu trữ mật khẩu và mã xác thực của bạn để bạn dễ dàng đăng nhập."</string>
     <string name="set_as_default" msgid="4415328591568654603">"Đặt làm mặc định"</string>
     <string name="use_once" msgid="9027366575315399714">"Dùng một lần"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> mật khẩu, <xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> mã xác thực"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> mật khẩu"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> mã xác thực"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Mã xác thực"</string>
     <string name="another_device" msgid="5147276802037801217">"Thiết bị khác"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Trình quản lý mật khẩu khác"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Đóng trang tính"</string>
diff --git a/packages/CredentialManager/res/values-zh-rCN/strings.xml b/packages/CredentialManager/res/values-zh-rCN/strings.xml
index a14dd2f..9e6c514 100644
--- a/packages/CredentialManager/res/values-zh-rCN/strings.xml
+++ b/packages/CredentialManager/res/values-zh-rCN/strings.xml
@@ -1,23 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Credential Manager"</string>
     <string name="string_cancel" msgid="6369133483981306063">"取消"</string>
     <string name="string_continue" msgid="1346732695941131882">"继续"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"在另一位置创建"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"保存到另一位置"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"使用另一台设备"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"保存到其他设备"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"简单又安全的登录方式"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"借助指纹、人脸识别或屏幕锁定功能,使用不会被忘记或被盗且具有唯一性的通行密钥登录。了解详情"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"选择<xliff:g id="CREATETYPES">%1$s</xliff:g>的位置"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"选择<xliff:g id="CREATETYPES">%1$s</xliff:g>的位置"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"创建通行密钥"</string>
     <string name="save_your_password" msgid="6597736507991704307">"保存您的密码"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"保存您的登录信息"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"设置默认密码管理工具,以便保存您的密码和通行密钥,从而提高下次的登录速度。"</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"在“<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>”中创建通行密钥?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"将您的密码保存至“<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>”?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"将您的登录信息保存至“<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>”?"</string>
@@ -25,24 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"通行密钥"</string>
     <string name="password" msgid="6738570945182936667">"密码"</string>
     <string name="sign_ins" msgid="4710739369149469208">"登录"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"在以下位置创建通行密钥"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"将密码保存到"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"将登录信息保存到"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"在其他设备上创建通行密钥?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"将“<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>”用于您的所有登录信息?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"此密码管理工具将会存储您的密码和通行密钥,以帮助您轻松登录。"</string>
     <string name="set_as_default" msgid="4415328591568654603">"设为默认项"</string>
     <string name="use_once" msgid="9027366575315399714">"使用一次"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> 个密码,<xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> 个通行密钥"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> 个密码"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> 个通行密钥"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"通行密钥"</string>
     <string name="another_device" msgid="5147276802037801217">"另一台设备"</string>
     <string name="other_password_manager" msgid="565790221427004141">"其他密码管理工具"</string>
     <string name="close_sheet" msgid="1393792015338908262">"关闭工作表"</string>
diff --git a/packages/CredentialManager/res/values-zh-rHK/strings.xml b/packages/CredentialManager/res/values-zh-rHK/strings.xml
index 71dfa1a..cc596d7 100644
--- a/packages/CredentialManager/res/values-zh-rHK/strings.xml
+++ b/packages/CredentialManager/res/values-zh-rHK/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"儲存至其他位置"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"改用其他裝置"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"儲存至其他裝置"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"安全又簡便的登入方式"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"使用指紋、面孔或螢幕鎖定配合密鑰登入。密鑰獨一無二,您不用擔心忘記密鑰或密鑰被盜。瞭解詳情"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"選擇「<xliff:g id="CREATETYPES">%1$s</xliff:g>」的位置"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"選擇「<xliff:g id="CREATETYPES">%1$s</xliff:g>」的位置"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"建立密鑰"</string>
     <string name="save_your_password" msgid="6597736507991704307">"儲存密碼"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"儲存登入資料"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"設定預設的密碼管理工具以儲存密碼和密碼密鑰,下次就能更快速登入。"</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"要在「<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>」建立密鑰嗎?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"要將密碼儲存至「<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>」嗎?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"要將登入資料儲存至「<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>」嗎?"</string>
@@ -24,23 +28,18 @@
     <string name="passkey" msgid="632353688396759522">"密鑰"</string>
     <string name="password" msgid="6738570945182936667">"密碼"</string>
     <string name="sign_ins" msgid="4710739369149469208">"登入資料"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"在此裝置建立密鑰:"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"將密碼儲存至以下位置:"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"將登入資料儲存至以下位置:"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"要在另一部裝置上建立密鑰嗎?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"要將「<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>」用於所有的登入資料嗎?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"此密碼管理工具將儲存您的密碼和密鑰,協助您輕鬆登入。"</string>
     <string name="set_as_default" msgid="4415328591568654603">"設定為預設"</string>
     <string name="use_once" msgid="9027366575315399714">"單次使用"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> 個密碼,<xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> 個密鑰"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> 個密碼"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g> 個密鑰"</string>
-    <string name="passkey_before_subtitle" msgid="2448119456208647444">"密碼金鑰"</string>
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"密鑰"</string>
     <string name="another_device" msgid="5147276802037801217">"其他裝置"</string>
     <string name="other_password_manager" msgid="565790221427004141">"其他密碼管理工具"</string>
     <string name="close_sheet" msgid="1393792015338908262">"閂工作表"</string>
diff --git a/packages/CredentialManager/res/values-zh-rTW/strings.xml b/packages/CredentialManager/res/values-zh-rTW/strings.xml
index 0d636c2..1fa1bd6 100644
--- a/packages/CredentialManager/res/values-zh-rTW/strings.xml
+++ b/packages/CredentialManager/res/values-zh-rTW/strings.xml
@@ -8,15 +8,19 @@
     <string name="string_save_to_another_place" msgid="7590325934591079193">"儲存至其他位置"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"改用其他裝置"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"儲存至其他裝置"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"安全又簡單的登入方式"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"登入帳戶時,你可以使用指紋、人臉或螢幕鎖定功能搭配不重複的密碼金鑰,不必擔心忘記密碼金鑰或遭人竊取。瞭解詳情"</string>
-    <string name="choose_provider_title" msgid="7245243990139698508">"選擇「<xliff:g id="CREATETYPES">%1$s</xliff:g>」的位置"</string>
-    <!-- no translation found for create_your_passkeys (8901224153607590596) -->
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
     <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
+    <string name="choose_provider_title" msgid="7245243990139698508">"選擇「<xliff:g id="CREATETYPES">%1$s</xliff:g>」的位置"</string>
+    <string name="create_your_passkeys" msgid="8901224153607590596">"建立金鑰密碼"</string>
     <string name="save_your_password" msgid="6597736507991704307">"儲存密碼"</string>
     <string name="save_your_sign_in_info" msgid="7213978049817076882">"儲存登入資訊"</string>
-    <!-- no translation found for choose_provider_body (8045759834416308059) -->
-    <skip />
+    <string name="choose_provider_body" msgid="8045759834416308059">"你可以設定預設的密碼管理工具以儲存密碼和密碼金鑰,下次就能更快速登入。"</string>
     <string name="choose_create_option_passkey_title" msgid="4146408187146573131">"要在「<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>」建立密碼金鑰嗎?"</string>
     <string name="choose_create_option_password_title" msgid="8812546498357380545">"要將密碼儲存至「<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>」嗎?"</string>
     <string name="choose_create_option_sign_in_title" msgid="6318246378475961834">"要將登入資訊儲存至「<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>」嗎?"</string>
@@ -24,17 +28,12 @@
     <string name="passkey" msgid="632353688396759522">"密碼金鑰"</string>
     <string name="password" msgid="6738570945182936667">"密碼"</string>
     <string name="sign_ins" msgid="4710739369149469208">"登入資訊"</string>
-    <!-- no translation found for create_passkey_in_title (2714306562710897785) -->
-    <skip />
-    <!-- no translation found for save_password_to_title (3450480045270186421) -->
-    <skip />
-    <!-- no translation found for save_sign_in_to_title (8328143607671760232) -->
-    <skip />
-    <!-- no translation found for create_passkey_in_other_device_title (6372952459932674632) -->
-    <skip />
+    <string name="create_passkey_in_title" msgid="2714306562710897785">"在以下位置建立密碼金鑰:"</string>
+    <string name="save_password_to_title" msgid="3450480045270186421">"將密碼儲存到以下位置:"</string>
+    <string name="save_sign_in_to_title" msgid="8328143607671760232">"將登入資訊儲存到以下位置:"</string>
+    <string name="create_passkey_in_other_device_title" msgid="6372952459932674632">"要在另一部裝置上建立密碼金鑰嗎?"</string>
     <string name="use_provider_for_all_title" msgid="4201020195058980757">"要將「<xliff:g id="PROVIDERINFODISPLAYNAME">%1$s</xliff:g>」用於所有的登入資訊嗎?"</string>
-    <!-- no translation found for use_provider_for_all_description (6560593199974037820) -->
-    <skip />
+    <string name="use_provider_for_all_description" msgid="6560593199974037820">"這個密碼管理工具會儲存你的密碼和密碼金鑰,協助你輕鬆登入。"</string>
     <string name="set_as_default" msgid="4415328591568654603">"設為預設"</string>
     <string name="use_once" msgid="9027366575315399714">"單次使用"</string>
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g> 個密碼,<xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g> 個密碼金鑰"</string>
diff --git a/packages/CredentialManager/res/values-zu/strings.xml b/packages/CredentialManager/res/values-zu/strings.xml
index a35c6d2..772104d 100644
--- a/packages/CredentialManager/res/values-zu/strings.xml
+++ b/packages/CredentialManager/res/values-zu/strings.xml
@@ -1,16 +1,21 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- no translation found for app_name (4539824758261855508) -->
-    <skip />
+    <string name="app_name" msgid="4539824758261855508">"Umphathi Wezimfanelo"</string>
     <string name="string_cancel" msgid="6369133483981306063">"Khansela"</string>
     <string name="string_continue" msgid="1346732695941131882">"Qhubeka"</string>
     <string name="string_create_in_another_place" msgid="1033635365843437603">"Sungula kwenye indawo"</string>
     <string name="string_save_to_another_place" msgid="7590325934591079193">"Londoloza kwenye indawo"</string>
     <string name="string_use_another_device" msgid="8754514926121520445">"Sebenzisa enye idivayisi"</string>
     <string name="string_save_to_another_device" msgid="1959562542075194458">"Londoloza kwenye idivayisi"</string>
-    <string name="passkey_creation_intro_title" msgid="402553911484409884">"Indlela elula yokungena ngemvume ngokuphephile"</string>
-    <string name="passkey_creation_intro_body" msgid="7493320456005579290">"Sebenzisa isigxivizo somunwe, ubuso noma ukukhiya isikrini ukuze ungene ngemvume ngokhiye wokudlula oyingqayizivele ongenakulibaleka noma owebiwe. Funda kabanzi"</string>
+    <!-- no translation found for passkey_creation_intro_title (4251037543787718844) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_password (312712407571126228) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_fingerprint (691816235541508203) -->
+    <skip />
+    <!-- no translation found for passkey_creation_intro_body_device (477121861162321129) -->
+    <skip />
     <string name="choose_provider_title" msgid="7245243990139698508">"Khetha lapho onga-<xliff:g id="CREATETYPES">%1$s</xliff:g>"</string>
     <!-- no translation found for create_your_passkeys (8901224153607590596) -->
     <skip />
@@ -41,8 +46,7 @@
     <string name="more_options_usage_passwords_passkeys" msgid="4794903978126339473">"Amaphasiwedi angu-<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>, okhiye bokudlula abangu-<xliff:g id="PASSKEYSNUMBER">%2$s</xliff:g>"</string>
     <string name="more_options_usage_passwords" msgid="1632047277723187813">"Amaphasiwedi angu-<xliff:g id="PASSWORDSNUMBER">%1$s</xliff:g>"</string>
     <string name="more_options_usage_passkeys" msgid="5390320437243042237">"Okhiye bokudlula abangu-<xliff:g id="PASSKEYSNUMBER">%1$s</xliff:g>"</string>
-    <!-- no translation found for passkey_before_subtitle (2448119456208647444) -->
-    <skip />
+    <string name="passkey_before_subtitle" msgid="2448119456208647444">"Ukhiye wokudlula"</string>
     <string name="another_device" msgid="5147276802037801217">"Enye idivayisi"</string>
     <string name="other_password_manager" msgid="565790221427004141">"Abanye abaphathi bephasiwedi"</string>
     <string name="close_sheet" msgid="1393792015338908262">"Vala ishidi"</string>
diff --git a/packages/CredentialManager/res/values/strings.xml b/packages/CredentialManager/res/values/strings.xml
index 870d983..a3ebf1e 100644
--- a/packages/CredentialManager/res/values/strings.xml
+++ b/packages/CredentialManager/res/values/strings.xml
@@ -80,6 +80,8 @@
   <string name="close_sheet">"Close sheet"</string>
   <!-- Spoken content description of the back arrow button. -->
   <string name="accessibility_back_arrow_button">"Go back to the previous page"</string>
+  <!-- Spoken content description of the close button. -->
+  <string name="accessibility_close_button">"Close the Credential Manager action suggestion appearing at the bottom of the screen"</string>
 
   <!-- Strings for the get flow. -->
   <!-- This appears as the title of the modal bottom sheet asking for user confirmation to use the single previously saved passkey to sign in to the app. [CHAR LIMIT=200] -->
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt b/packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt
index 2780c3c..d2b2924 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt
@@ -41,10 +41,7 @@
 import android.os.ResultReceiver
 import android.service.credentials.CredentialProviderService
 import com.android.credentialmanager.createflow.CreateCredentialUiState
-import com.android.credentialmanager.createflow.EnabledProviderInfo
-import com.android.credentialmanager.createflow.RemoteInfo
 import com.android.credentialmanager.getflow.GetCredentialUiState
-import com.android.credentialmanager.getflow.GetScreenState
 import com.android.credentialmanager.jetpack.developer.CreatePasswordRequest.Companion.toBundle
 import com.android.credentialmanager.jetpack.developer.CreatePublicKeyCredentialRequest
 import com.android.credentialmanager.jetpack.developer.PublicKeyCredential.Companion.TYPE_PUBLIC_KEY_CREDENTIAL
@@ -102,7 +99,7 @@
   }
 
   fun onOptionSelected(
-    providerPackageName: String,
+    providerId: String,
     entryKey: String,
     entrySubkey: String,
     resultCode: Int? = null,
@@ -110,7 +107,7 @@
   ) {
     val userSelectionDialogResult = UserSelectionDialogResult(
       requestInfo.token,
-      providerPackageName,
+      providerId,
       entryKey,
       entrySubkey,
       if (resultCode != null) ProviderPendingIntentResponse(resultCode, resultData) else null
@@ -124,11 +121,9 @@
     val providerEnabledList = GetFlowUtils.toProviderList(
     // TODO: handle runtime cast error
       providerEnabledList as List<GetCredentialProviderData>, context)
-    // TODO: covert from real requestInfo
-    val requestDisplayInfo = com.android.credentialmanager.getflow.RequestDisplayInfo("the app")
+    val requestDisplayInfo = GetFlowUtils.toRequestDisplayInfo(requestInfo)
     return GetCredentialUiState(
       providerEnabledList,
-      GetScreenState.PRIMARY_SELECTION,
       requestDisplayInfo,
     )
   }
@@ -141,36 +136,15 @@
     val providerDisabledList = CreateFlowUtils.toDisabledProviderList(
       // Handle runtime cast error
       providerDisabledList, context)
-    var defaultProvider: EnabledProviderInfo? = null
-    var remoteEntry: RemoteInfo? = null
-    var createOptionSize = 0
-    var lastSeenProviderWithNonEmptyCreateOptions: EnabledProviderInfo? = null
     providerEnabledList.forEach{providerInfo -> providerInfo.createOptions =
       providerInfo.createOptions.sortedWith(compareBy { it.lastUsedTimeMillis }).reversed()
-      if (providerInfo.isDefault) {defaultProvider = providerInfo}
-      if (providerInfo.remoteEntry != null) {
-        remoteEntry = providerInfo.remoteEntry!!
-      }
-      if (providerInfo.createOptions.isNotEmpty()) {
-        createOptionSize += providerInfo.createOptions.size
-        lastSeenProviderWithNonEmptyCreateOptions = providerInfo
-      }
     }
-    return CreateCredentialUiState(
-      enabledProviders = providerEnabledList,
-      disabledProviders = providerDisabledList,
-      CreateFlowUtils.toCreateScreenState(
-        createOptionSize, false,
-        requestDisplayInfo, defaultProvider, remoteEntry),
-      requestDisplayInfo,
-      false,
-      CreateFlowUtils.toActiveEntry(
-        /*defaultProvider=*/defaultProvider, createOptionSize,
-        lastSeenProviderWithNonEmptyCreateOptions, remoteEntry),
-    )
+    return CreateFlowUtils.toCreateCredentialUiState(
+      providerEnabledList, providerDisabledList, requestDisplayInfo, false)
   }
 
   companion object {
+    // TODO: find a way to resolve this static field leak problem
     lateinit var repo: CredentialManagerRepo
 
     fun setup(
@@ -201,7 +175,6 @@
         .setRemoteEntry(
           newRemoteEntry("key2", "subkey-1")
         )
-        .setIsDefaultProvider(true)
         .build(),
       CreateCredentialProviderData
         .Builder("com.dashlane")
@@ -248,12 +221,10 @@
           listOf(
             newActionEntry(
               "key3", "subkey-1", TYPE_PASSWORD_CREDENTIAL,
-              Icon.createWithResource(context, R.drawable.ic_manage_accounts),
               "Open Google Password Manager", "elisa.beckett@gmail.com"
             ),
             newActionEntry(
               "key3", "subkey-2", TYPE_PASSWORD_CREDENTIAL,
-              Icon.createWithResource(context, R.drawable.ic_manage_accounts),
               "Open Google Password Manager", "beckett-family@gmail.com"
             ),
           )
@@ -278,7 +249,6 @@
           listOf(
             newActionEntry(
               "key3", "subkey-1", TYPE_PASSWORD_CREDENTIAL,
-              Icon.createWithResource(context, R.drawable.ic_face),
               "Open Enpass"
             ),
           )
@@ -290,7 +260,6 @@
     key: String,
     subkey: String,
     credentialType: String,
-    icon: Icon,
     text: String,
     subtext: String? = null,
   ): Entry {
@@ -298,7 +267,7 @@
       Entry.CREDENTIAL_MANAGER_ENTRY_URI, SliceSpec(credentialType, 1)
     ).addText(
       text, null, listOf(Entry.HINT_ACTION_TITLE)
-    ).addIcon(icon, null, listOf(Entry.HINT_ACTION_ICON))
+    )
     if (subtext != null) {
       slice.addText(subtext, null, listOf(Entry.HINT_ACTION_SUBTEXT))
     }
@@ -518,7 +487,7 @@
       GetCredentialRequest.Builder()
         .addGetCredentialOption(
           GetCredentialOption(
-            TYPE_PUBLIC_KEY_CREDENTIAL, Bundle(), /*requireSystemProvider=*/ false)
+            TYPE_PUBLIC_KEY_CREDENTIAL, Bundle(), Bundle(), /*requireSystemProvider=*/ false)
         )
         .build(),
       /*isFirstUsage=*/false,
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorActivity.kt b/packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorActivity.kt
index 6a4c599..cdff2d4 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorActivity.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorActivity.kt
@@ -43,6 +43,7 @@
   override fun onCreate(savedInstanceState: Bundle?) {
     super.onCreate(savedInstanceState)
     CredentialManagerRepo.setup(this, intent)
+    UserConfigRepo.setup(this)
     val requestInfo = CredentialManagerRepo.getInstance().requestInfo
     setContent {
       CredentialSelectorTheme {
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/DataConverter.kt b/packages/CredentialManager/src/com/android/credentialmanager/DataConverter.kt
index 0d7e819..db676b2 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/DataConverter.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/DataConverter.kt
@@ -31,6 +31,8 @@
 import com.android.credentialmanager.createflow.EnabledProviderInfo
 import com.android.credentialmanager.createflow.CreateScreenState
 import com.android.credentialmanager.createflow.ActiveEntry
+import com.android.credentialmanager.createflow.DisabledProviderInfo
+import com.android.credentialmanager.createflow.CreateCredentialUiState
 import com.android.credentialmanager.getflow.ActionEntryInfo
 import com.android.credentialmanager.getflow.AuthenticationEntryInfo
 import com.android.credentialmanager.getflow.CredentialEntryInfo
@@ -67,7 +69,8 @@
           .getPackageInfo(packageName!!,
             PackageManager.PackageInfoFlags.of(0))
         val providerDisplayName = pkgInfo.applicationInfo.loadLabel(packageManager).toString()
-        // TODO: decide what to do when failed to load a provider icon
+        // TODO: get the provider icon from the service
+        //  and decide what to do when failed to load a provider icon
         val providerIcon = pkgInfo.applicationInfo.loadIcon(packageManager)!!
         ProviderInfo(
           id = it.providerFlattenedComponentName,
@@ -83,11 +86,19 @@
             it.authenticationEntry),
           remoteEntry = getRemoteEntry(it.providerFlattenedComponentName, it.remoteEntry),
           actionEntryList = getActionEntryList(
-            it.providerFlattenedComponentName, it.actionChips, context),
+            it.providerFlattenedComponentName, it.actionChips, providerIcon),
         )
       }
     }
 
+    fun toRequestDisplayInfo(
+      requestInfo: RequestInfo,
+    ): com.android.credentialmanager.getflow.RequestDisplayInfo {
+      return com.android.credentialmanager.getflow.RequestDisplayInfo(
+        appDomainName = requestInfo.appPackageName
+      )
+    }
+
 
     /* From service data structure to UI credential entry list representation. */
     private fun getCredentialOptionInfoList(
@@ -111,7 +122,7 @@
           displayName = credentialEntryUi.userDisplayName?.toString(),
           // TODO: proper fallback
           icon = credentialEntryUi.entryIcon?.loadDrawable(context)
-            ?: context.getDrawable(R.drawable.ic_passkey)!!,
+            ?: context.getDrawable(R.drawable.ic_other_sign_in)!!,
           lastUsedTimeMillis = credentialEntryUi.lastUsedTimeMillis,
         )
       }
@@ -156,7 +167,7 @@
     private fun getActionEntryList(
       providerId: String,
       actionEntries: List<Entry>,
-      context: Context,
+      providerIcon: Drawable,
     ): List<ActionEntryInfo> {
       return actionEntries.map {
         val actionEntryUi = ActionUi.fromSlice(it.slice)
@@ -169,7 +180,7 @@
           fillInIntent = it.frameworkExtrasIntent,
           title = actionEntryUi.text.toString(),
           // TODO: gracefully fail
-          icon = actionEntryUi.icon.loadDrawable(context)!!,
+          icon = providerIcon,
           subTitle = actionEntryUi.subtext?.toString(),
         )
       }
@@ -199,14 +210,13 @@
         val pkgInfo = packageManager
           .getPackageInfo(packageName!!,
             PackageManager.PackageInfoFlags.of(0))
-        com.android.credentialmanager.createflow.EnabledProviderInfo(
+        EnabledProviderInfo(
           // TODO: decide what to do when failed to load a provider icon
           icon = pkgInfo.applicationInfo.loadIcon(packageManager)!!,
           name = it.providerFlattenedComponentName,
           displayName = pkgInfo.applicationInfo.loadLabel(packageManager).toString(),
           createOptions = toCreationOptionInfoList(
             it.providerFlattenedComponentName, it.saveEntries, requestDisplayInfo, context),
-          isDefault = it.isDefaultProvider,
           remoteEntry = toRemoteInfo(it.providerFlattenedComponentName, it.remoteEntry),
         )
       }
@@ -247,8 +257,7 @@
             createCredentialRequestJetpack.password,
             createCredentialRequestJetpack.type,
             requestInfo.appPackageName,
-            context.getDrawable(R.drawable.ic_password)!!,
-            requestInfo.isFirstUsage
+            context.getDrawable(R.drawable.ic_password)!!
           )
         }
         is CreatePublicKeyCredentialRequest -> {
@@ -266,8 +275,7 @@
             displayName,
             createCredentialRequestJetpack.type,
             requestInfo.appPackageName,
-            context.getDrawable(R.drawable.ic_passkey)!!,
-            requestInfo.isFirstUsage)
+            context.getDrawable(R.drawable.ic_passkey)!!)
         }
         // TODO: correctly parsing for other sign-ins
         else -> {
@@ -276,20 +284,60 @@
             "Elisa Beckett",
             "other-sign-ins",
             requestInfo.appPackageName,
-            context.getDrawable(R.drawable.ic_other_sign_in)!!,
-            requestInfo.isFirstUsage)
+            context.getDrawable(R.drawable.ic_other_sign_in)!!)
         }
       }
     }
 
-    fun toCreateScreenState(
+    fun toCreateCredentialUiState(
+      enabledProviders: List<EnabledProviderInfo>,
+      disabledProviders: List<DisabledProviderInfo>?,
+      requestDisplayInfo: RequestDisplayInfo,
+      isOnPasskeyIntroStateAlready: Boolean,
+    ): CreateCredentialUiState {
+      var createOptionSize = 0
+      var lastSeenProviderWithNonEmptyCreateOptions: EnabledProviderInfo? = null
+      var remoteEntry: RemoteInfo? = null
+      var defaultProvider: EnabledProviderInfo? = null
+      val defaultProviderId = UserConfigRepo.getInstance().getDefaultProviderId()
+      enabledProviders.forEach {
+          enabledProvider ->
+        if (defaultProviderId != null) {
+          if (enabledProvider.name == defaultProviderId) {
+            defaultProvider = enabledProvider
+          }
+        }
+        if (enabledProvider.createOptions.isNotEmpty()) {
+          createOptionSize += enabledProvider.createOptions.size
+          lastSeenProviderWithNonEmptyCreateOptions = enabledProvider
+        }
+        if (enabledProvider.remoteEntry != null) {
+          remoteEntry = enabledProvider.remoteEntry!!
+        }
+      }
+      return CreateCredentialUiState(
+        enabledProviders = enabledProviders,
+        disabledProviders = disabledProviders,
+        toCreateScreenState(
+          createOptionSize, isOnPasskeyIntroStateAlready,
+          requestDisplayInfo, defaultProvider, remoteEntry),
+        requestDisplayInfo,
+        isOnPasskeyIntroStateAlready,
+        toActiveEntry(
+          /*defaultProvider=*/defaultProvider, createOptionSize,
+          lastSeenProviderWithNonEmptyCreateOptions, remoteEntry),
+      )
+    }
+
+    private fun toCreateScreenState(
       createOptionSize: Int,
       isOnPasskeyIntroStateAlready: Boolean,
       requestDisplayInfo: RequestDisplayInfo,
       defaultProvider: EnabledProviderInfo?,
       remoteEntry: RemoteInfo?,
     ): CreateScreenState {
-      return if (requestDisplayInfo.isFirstUsage && requestDisplayInfo
+      return if (
+        UserConfigRepo.getInstance().getIsFirstUse() && requestDisplayInfo
           .type == TYPE_PUBLIC_KEY_CREDENTIAL && !isOnPasskeyIntroStateAlready) {
         CreateScreenState.PASSKEY_INTRO
       } else if (
@@ -304,12 +352,12 @@
       } else if (createOptionSize == 0 && remoteEntry != null) {
         CreateScreenState.EXTERNAL_ONLY_SELECTION
       } else {
-          // TODO: properly handle error and gracefully finish itself
-          throw java.lang.IllegalStateException("Empty provider list.")
+        // TODO: properly handle error and gracefully finish itself
+        throw java.lang.IllegalStateException("Empty provider list.")
       }
     }
 
-   fun toActiveEntry(
+    private fun toActiveEntry(
       defaultProvider: EnabledProviderInfo?,
       createOptionSize: Int,
       lastSeenProviderWithNonEmptyCreateOptions: EnabledProviderInfo?,
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/UserConfigRepo.kt b/packages/CredentialManager/src/com/android/credentialmanager/UserConfigRepo.kt
new file mode 100644
index 0000000..5e77663
--- /dev/null
+++ b/packages/CredentialManager/src/com/android/credentialmanager/UserConfigRepo.kt
@@ -0,0 +1,70 @@
+/*
+ * 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.credentialmanager
+
+import android.content.Context
+import android.content.SharedPreferences
+
+class UserConfigRepo(context: Context) {
+    val sharedPreferences: SharedPreferences = context.getSharedPreferences(
+        context.packageName, Context.MODE_PRIVATE)
+
+    fun setDefaultProvider(
+        providerId: String
+    ) {
+        sharedPreferences.edit().apply {
+            putString(DEFAULT_PROVIDER, providerId)
+            apply()
+        }
+    }
+
+    fun setIsFirstUse(
+        isFirstUse: Boolean
+    ) {
+        sharedPreferences.edit().apply {
+            putBoolean(IS_PASSKEY_FIRST_USE, isFirstUse)
+            apply()
+        }
+    }
+
+    fun getDefaultProviderId(): String? {
+        return sharedPreferences.getString(DEFAULT_PROVIDER, null)
+    }
+
+    fun getIsFirstUse(): Boolean {
+        return sharedPreferences.getBoolean(IS_PASSKEY_FIRST_USE, true)
+    }
+
+    companion object {
+        lateinit var repo: UserConfigRepo
+
+        const val DEFAULT_PROVIDER = "default_provider"
+        // This first use value only applies to passkeys, not related with if generally
+        // credential manager is first use or not
+        const val IS_PASSKEY_FIRST_USE = "is_passkey_first_use"
+
+        fun setup(
+            context: Context,
+        ) {
+            repo = UserConfigRepo(context)
+        }
+
+        fun getInstance(): UserConfigRepo {
+            return repo
+        }
+    }
+}
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt
index 5d22bfd..38e2caa 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt
@@ -108,7 +108,8 @@
                     )
                     CreateScreenState.MORE_OPTIONS_ROW_INTRO -> MoreOptionsRowIntroCard(
                         providerInfo = uiState.activeEntry?.activeProvider!!,
-                        onDefaultOrNotSelected = viewModel::onDefaultOrNotSelected
+                        onChangeDefaultSelected = viewModel::onChangeDefaultSelected,
+                        onUseOnceSelected = viewModel::onUseOnceSelected,
                     )
                     CreateScreenState.EXTERNAL_ONLY_SELECTION -> ExternalOnlySelectionCard(
                         requestDisplayInfo = uiState.requestDisplayInfo,
@@ -118,7 +119,7 @@
                         onCancel = viewModel::onCancel,
                     )
                 }
-            } else if (uiState.hidden && uiState.selectedEntry != null) {
+            } else if (uiState.selectedEntry != null && !uiState.providerActivityPending) {
                 viewModel.launchProviderUi(providerActivityLauncher)
             }
         },
@@ -313,7 +314,7 @@
                             }
                         }
                     }
-                    if (disabledProviderList != null) {
+                    if (disabledProviderList != null && disabledProviderList.isNotEmpty()) {
                         item {
                             MoreOptionsDisabledProvidersRow(
                                 disabledProviders = disabledProviderList,
@@ -431,14 +432,12 @@
                             }
                         }
                     }
-                    if (disabledProviderList != null) {
-                        item {
-                            MoreOptionsDisabledProvidersRow(
-                                disabledProviders = disabledProviderList,
-                                onDisabledPasswordManagerSelected =
-                                onDisabledPasswordManagerSelected,
-                            )
-                        }
+                    item {
+                        MoreOptionsDisabledProvidersRow(
+                            disabledProviders = disabledProviderList,
+                            onDisabledPasswordManagerSelected =
+                            onDisabledPasswordManagerSelected,
+                        )
                     }
                     // TODO: handle the error situation that if multiple remoteInfos exists
                     enabledProviderList.forEach {
@@ -466,7 +465,8 @@
 @Composable
 fun MoreOptionsRowIntroCard(
     providerInfo: EnabledProviderInfo,
-    onDefaultOrNotSelected: () -> Unit,
+    onChangeDefaultSelected: () -> Unit,
+    onUseOnceSelected: () -> Unit,
 ) {
     ContainerCard() {
         Column() {
@@ -498,11 +498,11 @@
             ) {
                 CancelButton(
                     stringResource(R.string.use_once),
-                    onClick = onDefaultOrNotSelected
+                    onClick = onUseOnceSelected
                 )
                 ConfirmButton(
                     stringResource(R.string.set_as_default),
-                    onClick = onDefaultOrNotSelected
+                    onClick = onChangeDefaultSelected
                 )
             }
             Divider(
@@ -748,7 +748,7 @@
                 },
                 contentDescription = null,
                 tint = LocalAndroidColorScheme.current.colorAccentPrimaryVariant,
-                modifier = Modifier.padding(horizontal = 18.dp).size(32.dp)
+                modifier = Modifier.padding(start = 10.dp).size(32.dp)
             )
         },
         label = {
@@ -759,7 +759,7 @@
                         TextOnSurfaceVariant(
                             text = requestDisplayInfo.title,
                             style = MaterialTheme.typography.titleLarge,
-                            modifier = Modifier.padding(top = 16.dp),
+                            modifier = Modifier.padding(top = 16.dp, start = 5.dp),
                         )
                         TextSecondary(
                             text = if (requestDisplayInfo.subtitle != null) {
@@ -770,27 +770,27 @@
                                 stringResource(R.string.passkey_before_subtitle)
                             },
                             style = MaterialTheme.typography.bodyMedium,
-                            modifier = Modifier.padding(bottom = 16.dp),
+                            modifier = Modifier.padding(bottom = 16.dp, start = 5.dp),
                         )
                     }
                     TYPE_PASSWORD_CREDENTIAL -> {
                         TextOnSurfaceVariant(
                             text = requestDisplayInfo.title,
                             style = MaterialTheme.typography.titleLarge,
-                            modifier = Modifier.padding(top = 16.dp),
+                            modifier = Modifier.padding(top = 16.dp, start = 5.dp),
                         )
                         TextSecondary(
                             // This subtitle would never be null for create password
                             text = requestDisplayInfo.subtitle ?: "",
                             style = MaterialTheme.typography.bodyMedium,
-                            modifier = Modifier.padding(bottom = 16.dp),
+                            modifier = Modifier.padding(bottom = 16.dp, start = 5.dp),
                         )
                     }
                     else -> {
                         TextOnSurfaceVariant(
                             text = requestDisplayInfo.title,
                             style = MaterialTheme.typography.titleLarge,
-                            modifier = Modifier.padding(top = 16.dp, bottom = 16.dp),
+                            modifier = Modifier.padding(top = 16.dp, bottom = 16.dp, start = 5.dp),
                         )
                     }
                 }
@@ -810,7 +810,7 @@
         onClick = onOptionSelected,
         icon = {
             Image(
-                modifier = Modifier.padding(horizontal = 16.dp).size(32.dp),
+                modifier = Modifier.padding(start = 10.dp).size(32.dp),
                 bitmap = providerInfo.icon.toBitmap().asImageBitmap(),
                 contentDescription = null
             )
@@ -820,12 +820,18 @@
                 TextOnSurfaceVariant(
                     text = providerInfo.displayName,
                     style = MaterialTheme.typography.titleLarge,
-                    modifier = Modifier.padding(top = 16.dp),
+                    modifier = Modifier.padding(top = 16.dp, start = 5.dp),
                 )
                 if (createOptionInfo.userProviderDisplayName != null) {
                     TextSecondary(
                         text = createOptionInfo.userProviderDisplayName,
                         style = MaterialTheme.typography.bodyMedium,
+                        // TODO: update the logic here for the case there is only total count
+                        modifier = if (
+                            createOptionInfo.passwordCount != null ||
+                            createOptionInfo.passkeyCount != null
+                        ) Modifier.padding(start = 5.dp) else Modifier
+                            .padding(bottom = 16.dp, start = 5.dp),
                     )
                 }
                 if (createOptionInfo.passwordCount != null &&
@@ -839,7 +845,7 @@
                             createOptionInfo.passkeyCount
                         ),
                         style = MaterialTheme.typography.bodyMedium,
-                        modifier = Modifier.padding(bottom = 16.dp),
+                        modifier = Modifier.padding(bottom = 16.dp, start = 5.dp),
                     )
                 } else if (createOptionInfo.passwordCount != null) {
                     TextSecondary(
@@ -849,7 +855,7 @@
                             createOptionInfo.passwordCount
                         ),
                         style = MaterialTheme.typography.bodyMedium,
-                        modifier = Modifier.padding(bottom = 16.dp),
+                        modifier = Modifier.padding(bottom = 16.dp, start = 5.dp),
                     )
                 } else if (createOptionInfo.passkeyCount != null) {
                     TextSecondary(
@@ -859,7 +865,7 @@
                             createOptionInfo.passkeyCount
                         ),
                         style = MaterialTheme.typography.bodyMedium,
-                        modifier = Modifier.padding(bottom = 16.dp),
+                        modifier = Modifier.padding(bottom = 16.dp, start = 5.dp),
                     )
                 } else if (createOptionInfo.totalCredentialCount != null) {
                     // TODO: Handle the case when there is total count
@@ -873,34 +879,36 @@
 @OptIn(ExperimentalMaterial3Api::class)
 @Composable
 fun MoreOptionsDisabledProvidersRow(
-    disabledProviders: List<ProviderInfo>,
+    disabledProviders: List<ProviderInfo>?,
     onDisabledPasswordManagerSelected: () -> Unit,
 ) {
-    Entry(
-        onClick = onDisabledPasswordManagerSelected,
-        icon = {
-            Icon(
-                Icons.Filled.Add,
-                contentDescription = null,
-                modifier = Modifier.padding(start = 16.dp)
-            )
-        },
-        label = {
-            Column() {
-                TextOnSurfaceVariant(
-                    text = stringResource(R.string.other_password_manager),
-                    style = MaterialTheme.typography.titleLarge,
-                    modifier = Modifier.padding(top = 16.dp, start = 16.dp),
+    if (disabledProviders != null && disabledProviders.isNotEmpty()) {
+        Entry(
+            onClick = onDisabledPasswordManagerSelected,
+            icon = {
+                Icon(
+                    Icons.Filled.Add,
+                    contentDescription = null,
+                    modifier = Modifier.padding(start = 16.dp)
                 )
-                // TODO: Update the subtitle once design is confirmed
-                TextSecondary(
-                    text = disabledProviders.joinToString(separator = ", ") { it.displayName },
-                    style = MaterialTheme.typography.bodyMedium,
-                    modifier = Modifier.padding(bottom = 16.dp, start = 16.dp),
-                )
+            },
+            label = {
+                Column() {
+                    TextOnSurfaceVariant(
+                        text = stringResource(R.string.other_password_manager),
+                        style = MaterialTheme.typography.titleLarge,
+                        modifier = Modifier.padding(top = 16.dp, start = 5.dp),
+                    )
+                    // TODO: Update the subtitle once design is confirmed
+                    TextSecondary(
+                        text = disabledProviders.joinToString(separator = ", ") { it.displayName },
+                        style = MaterialTheme.typography.bodyMedium,
+                        modifier = Modifier.padding(bottom = 16.dp, start = 5.dp),
+                    )
+                }
             }
-        }
-    )
+        )
+    }
 }
 
 @OptIn(ExperimentalMaterial3Api::class)
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialViewModel.kt b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialViewModel.kt
index 3d23f5d..9d029dff 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialViewModel.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialViewModel.kt
@@ -29,6 +29,7 @@
 import androidx.lifecycle.ViewModel
 import com.android.credentialmanager.CreateFlowUtils
 import com.android.credentialmanager.CredentialManagerRepo
+import com.android.credentialmanager.UserConfigRepo
 import com.android.credentialmanager.common.DialogResult
 import com.android.credentialmanager.common.ProviderActivityResult
 import com.android.credentialmanager.common.ResultState
@@ -42,6 +43,7 @@
   val activeEntry: ActiveEntry? = null,
   val selectedEntry: EntryInfo? = null,
   val hidden: Boolean = false,
+  val providerActivityPending: Boolean = false,
 )
 
 class CreateCredentialViewModel(
@@ -60,32 +62,15 @@
   }
 
   fun onConfirmIntro() {
-    var createOptionSize = 0
-    var lastSeenProviderWithNonEmptyCreateOptions: EnabledProviderInfo? = null
-    var remoteEntry: RemoteInfo? = null
-    uiState.enabledProviders.forEach {
-      enabledProvider ->
-      if (enabledProvider.createOptions.isNotEmpty()) {
-        createOptionSize += enabledProvider.createOptions.size
-        lastSeenProviderWithNonEmptyCreateOptions = enabledProvider
-      }
-      if (enabledProvider.remoteEntry != null) {
-        remoteEntry = enabledProvider.remoteEntry!!
-      }
-    }
-    uiState = uiState.copy(
-      currentScreenState = CreateFlowUtils.toCreateScreenState(
-        createOptionSize, true,
-        uiState.requestDisplayInfo, null, remoteEntry),
-      showActiveEntryOnly = createOptionSize > 1,
-      activeEntry = CreateFlowUtils.toActiveEntry(
-        null, createOptionSize, lastSeenProviderWithNonEmptyCreateOptions, remoteEntry),
-    )
+    uiState = CreateFlowUtils.toCreateCredentialUiState(
+      uiState.enabledProviders, uiState.disabledProviders,
+      uiState.requestDisplayInfo, true)
+    UserConfigRepo.getInstance().setIsFirstUse(false)
   }
 
   fun getProviderInfoByName(providerName: String): EnabledProviderInfo {
     return uiState.enabledProviders.single {
-      it.name.equals(providerName)
+      it.name == providerName
     }
   }
 
@@ -115,6 +100,8 @@
       showActiveEntryOnly = true,
       activeEntry = activeEntry
     )
+    val providerId = uiState.activeEntry?.activeProvider?.name
+    onDefaultChanged(providerId)
   }
 
   fun onDisabledPasswordManagerSelected() {
@@ -126,11 +113,29 @@
     dialogResult.value = DialogResult(ResultState.CANCELED)
   }
 
-  fun onDefaultOrNotSelected() {
+  fun onChangeDefaultSelected() {
     uiState = uiState.copy(
       currentScreenState = CreateScreenState.CREATION_OPTION_SELECTION,
     )
-    // TODO: implement the if choose as default or not logic later
+    val providerId = uiState.activeEntry?.activeProvider?.name
+    onDefaultChanged(providerId)
+  }
+
+  fun onUseOnceSelected() {
+    uiState = uiState.copy(
+      currentScreenState = CreateScreenState.CREATION_OPTION_SELECTION,
+    )
+  }
+
+  fun onDefaultChanged(providerId: String?) {
+    if (providerId != null) {
+      Log.d(
+        "Account Selector", "Default provider changed to: " +
+                " {provider=$providerId")
+      UserConfigRepo.getInstance().setDefaultProvider(providerId)
+    } else {
+      Log.w("Account Selector", "Null provider is being changed")
+    }
   }
 
   fun onEntrySelected(selectedEntry: EntryInfo) {
@@ -162,6 +167,9 @@
   ) {
     val entry = uiState.selectedEntry
     if (entry != null && entry.pendingIntent != null) {
+      uiState = uiState.copy(
+        providerActivityPending = true,
+      )
       val intentSenderRequest = IntentSenderRequest.Builder(entry.pendingIntent)
         .setFillInIntent(entry.fillInIntent).build()
       launcher.launch(intentSenderRequest)
@@ -192,6 +200,7 @@
       uiState = uiState.copy(
         selectedEntry = null,
         hidden = false,
+        providerActivityPending = false,
       )
     } else {
       if (entry != null) {
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateModel.kt b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateModel.kt
index 21abe08..fda0b97 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateModel.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateModel.kt
@@ -31,7 +31,6 @@
   name: String,
   displayName: String,
   var createOptions: List<CreateOptionInfo>,
-  val isDefault: Boolean,
   var remoteEntry: RemoteInfo?,
 ) : ProviderInfo(icon, name, displayName)
 
@@ -77,7 +76,6 @@
   val type: String,
   val appDomainName: String,
   val typeIcon: Drawable,
-  val isFirstUsage: Boolean,
 )
 
 /**
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt
index 21342a1..619f5a3 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt
@@ -16,6 +16,7 @@
 
 package com.android.credentialmanager.getflow
 
+import android.credentials.Credential
 import android.text.TextUtils
 import androidx.activity.compose.ManagedActivityResultLauncher
 import androidx.activity.result.ActivityResult
@@ -32,15 +33,20 @@
 import androidx.compose.foundation.layout.wrapContentHeight
 import androidx.compose.foundation.lazy.LazyColumn
 import androidx.compose.foundation.lazy.items
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.ArrowBack
+import androidx.compose.material.icons.filled.Close
+import androidx.compose.material.icons.outlined.Lock
 import androidx.compose.material3.Divider
 import androidx.compose.material3.ExperimentalMaterial3Api
 import androidx.compose.material3.Icon
 import androidx.compose.material3.IconButton
 import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Snackbar
+import androidx.compose.material3.Text
+import androidx.compose.material3.TextButton
 import androidx.compose.material3.TopAppBar
 import androidx.compose.material3.TopAppBarDefaults
-import androidx.compose.material.icons.Icons
-import androidx.compose.material.icons.filled.ArrowBack
 import androidx.compose.runtime.Composable
 import androidx.compose.runtime.LaunchedEffect
 import androidx.compose.ui.Alignment
@@ -65,6 +71,7 @@
 import com.android.credentialmanager.common.ui.TransparentBackgroundEntry
 import com.android.credentialmanager.jetpack.developer.PublicKeyCredential
 import com.android.credentialmanager.ui.theme.EntryShape
+import com.android.credentialmanager.ui.theme.LocalAndroidColorScheme
 
 @Composable
 fun GetCredentialScreen(
@@ -75,39 +82,50 @@
         initialValue = ModalBottomSheetValue.Expanded,
         skipHalfExpanded = true
     )
-    ModalBottomSheetLayout(
-        sheetBackgroundColor = MaterialTheme.colorScheme.surface,
-        modifier = Modifier.background(Color.Transparent),
-        sheetState = state,
-        sheetContent = {
-            val uiState = viewModel.uiState
-            if (!uiState.hidden) {
-                when (uiState.currentScreenState) {
-                    GetScreenState.PRIMARY_SELECTION -> PrimarySelectionCard(
-                        requestDisplayInfo = uiState.requestDisplayInfo,
-                        providerDisplayInfo = uiState.providerDisplayInfo,
-                        onEntrySelected = viewModel::onEntrySelected,
-                        onCancel = viewModel::onCancel,
-                        onMoreOptionSelected = viewModel::onMoreOptionSelected,
-                    )
-                    GetScreenState.ALL_SIGN_IN_OPTIONS -> AllSignInOptionCard(
-                        providerInfoList = uiState.providerInfoList,
-                        providerDisplayInfo = uiState.providerDisplayInfo,
-                        onEntrySelected = viewModel::onEntrySelected,
-                        onBackButtonClicked = viewModel::onBackToPrimarySelectionScreen,
-                    )
+    val uiState = viewModel.uiState
+    if (uiState.currentScreenState != GetScreenState.REMOTE_ONLY) {
+        ModalBottomSheetLayout(
+            sheetBackgroundColor = MaterialTheme.colorScheme.surface,
+            modifier = Modifier.background(Color.Transparent),
+            sheetState = state,
+            sheetContent = {
+                // TODO: hide UI at top level
+                if (!uiState.hidden) {
+                    if (uiState.currentScreenState == GetScreenState.PRIMARY_SELECTION) {
+                        PrimarySelectionCard(
+                            requestDisplayInfo = uiState.requestDisplayInfo,
+                            providerDisplayInfo = uiState.providerDisplayInfo,
+                            onEntrySelected = viewModel::onEntrySelected,
+                            onCancel = viewModel::onCancel,
+                            onMoreOptionSelected = viewModel::onMoreOptionSelected,
+                        )
+                    } else {
+                        AllSignInOptionCard(
+                            providerInfoList = uiState.providerInfoList,
+                            providerDisplayInfo = uiState.providerDisplayInfo,
+                            onEntrySelected = viewModel::onEntrySelected,
+                            onBackButtonClicked = viewModel::onBackToPrimarySelectionScreen,
+                            onCancel = viewModel::onCancel,
+                            isNoAccount = uiState.isNoAccount,
+                        )
+                    }
+                } else if (uiState.selectedEntry != null && !uiState.providerActivityPending) {
+                    viewModel.launchProviderUi(providerActivityLauncher)
                 }
-            } else if (uiState.hidden && uiState.selectedEntry != null) {
-                viewModel.launchProviderUi(providerActivityLauncher)
+            },
+            scrimColor = MaterialTheme.colorScheme.scrim.copy(alpha = 0.8f),
+            sheetShape = EntryShape.TopRoundedCorner,
+        ) {}
+        LaunchedEffect(state.currentValue) {
+            if (state.currentValue == ModalBottomSheetValue.Hidden) {
+                viewModel.onCancel()
             }
-        },
-        scrimColor = MaterialTheme.colorScheme.scrim.copy(alpha = 0.8f),
-        sheetShape = EntryShape.TopRoundedCorner,
-    ) {}
-    LaunchedEffect(state.currentValue) {
-        if (state.currentValue == ModalBottomSheetValue.Hidden) {
-            viewModel.onCancel()
         }
+    } else {
+        SnackBarScreen(
+            onClick = viewModel::onMoreOptionOnSnackBarSelected,
+            onCancel = viewModel::onCancel,
+        )
     }
 }
 
@@ -173,7 +191,7 @@
                 color = Color.Transparent
             )
             Row(
-                horizontalArrangement = Arrangement.Start,
+                horizontalArrangement = Arrangement.SpaceBetween,
                 modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp)
             ) {
                 CancelButton(stringResource(R.string.get_dialog_button_label_no_thanks), onCancel)
@@ -195,6 +213,8 @@
     providerDisplayInfo: ProviderDisplayInfo,
     onEntrySelected: (EntryInfo) -> Unit,
     onBackButtonClicked: () -> Unit,
+    onCancel: () -> Unit,
+    isNoAccount: Boolean,
 ) {
     val sortedUserNameToCredentialEntryList =
         providerDisplayInfo.sortedUserNameToCredentialEntryList
@@ -212,7 +232,7 @@
                     )
                 },
                 navigationIcon = {
-                    IconButton(onClick = onBackButtonClicked) {
+                    IconButton(onClick = if (isNoAccount) onCancel else onBackButtonClicked) {
                         Icon(
                             Icons.Filled.ArrowBack,
                             contentDescription = stringResource(
@@ -405,11 +425,12 @@
     Entry(
         onClick = { onEntrySelected(credentialEntryInfo) },
         icon = {
-            Image(
+            Icon(
                 modifier = Modifier.padding(start = 10.dp).size(32.dp),
                 bitmap = credentialEntryInfo.icon.toBitmap().asImageBitmap(),
                 // TODO: add description.
-                contentDescription = ""
+                contentDescription = "",
+                tint = LocalAndroidColorScheme.current.colorAccentPrimaryVariant,
             )
         },
         label = {
@@ -418,19 +439,24 @@
                 TextOnSurfaceVariant(
                     text = credentialEntryInfo.userName,
                     style = MaterialTheme.typography.titleLarge,
-                    modifier = Modifier.padding(top = 16.dp)
+                    modifier = Modifier.padding(top = 16.dp, start = 5.dp)
                 )
                 TextSecondary(
-                    text =
-                    if (TextUtils.isEmpty(credentialEntryInfo.displayName))
-                        credentialEntryInfo.credentialTypeDisplayName
-                    else
-                        credentialEntryInfo.credentialTypeDisplayName +
-                                stringResource(
-                                    R.string.get_dialog_sign_in_type_username_separator) +
-                                credentialEntryInfo.displayName,
+                    text = if (
+                        credentialEntryInfo.credentialType == Credential.TYPE_PASSWORD_CREDENTIAL) {
+                        "••••••••••••"
+                    } else {
+                        if (TextUtils.isEmpty(credentialEntryInfo.displayName))
+                            credentialEntryInfo.credentialTypeDisplayName
+                        else
+                            credentialEntryInfo.credentialTypeDisplayName +
+                                    stringResource(
+                                        R.string.get_dialog_sign_in_type_username_separator
+                                    ) +
+                                    credentialEntryInfo.displayName
+                    },
                     style = MaterialTheme.typography.bodyMedium,
-                    modifier = Modifier.padding(bottom = 16.dp)
+                    modifier = Modifier.padding(bottom = 16.dp, start = 5.dp)
                 )
             }
         }
@@ -454,17 +480,27 @@
             )
         },
         label = {
-            Column() {
-                // TODO: fix the text values.
-                TextOnSurfaceVariant(
-                    text = authenticationEntryInfo.title,
-                    style = MaterialTheme.typography.titleLarge,
-                    modifier = Modifier.padding(top = 16.dp)
-                )
-                TextSecondary(
-                    text = stringResource(R.string.locked_credential_entry_label_subtext),
-                    style = MaterialTheme.typography.bodyMedium,
-                    modifier = Modifier.padding(bottom = 16.dp)
+            Row(
+                horizontalArrangement = Arrangement.SpaceBetween,
+                modifier = Modifier.fillMaxWidth().padding(horizontal = 5.dp),
+                ) {
+                Column() {
+                    // TODO: fix the text values.
+                    TextOnSurfaceVariant(
+                        text = authenticationEntryInfo.title,
+                        style = MaterialTheme.typography.titleLarge,
+                        modifier = Modifier.padding(top = 16.dp)
+                    )
+                    TextSecondary(
+                        text = stringResource(R.string.locked_credential_entry_label_subtext),
+                        style = MaterialTheme.typography.bodyMedium,
+                        modifier = Modifier.padding(bottom = 16.dp)
+                    )
+                }
+                Icon(
+                    Icons.Outlined.Lock,
+                    null,
+                    Modifier.align(alignment = Alignment.CenterVertically).padding(end = 10.dp),
                 )
             }
         }
@@ -491,11 +527,13 @@
                 TextOnSurfaceVariant(
                     text = actionEntryInfo.title,
                     style = MaterialTheme.typography.titleLarge,
+                    modifier = Modifier.padding(start = 5.dp),
                 )
                 if (actionEntryInfo.subTitle != null) {
                     TextSecondary(
                         text = actionEntryInfo.subTitle,
                         style = MaterialTheme.typography.bodyMedium,
+                        modifier = Modifier.padding(start = 5.dp),
                     )
                 }
             }
@@ -518,3 +556,37 @@
         }
     )
 }
+
+@OptIn(ExperimentalMaterial3Api::class)
+@Composable
+fun SnackBarScreen(
+    onClick: (Boolean) -> Unit,
+    onCancel: () -> Unit,
+) {
+    // TODO: Change the height, width and position according to the design
+    Snackbar (
+        modifier = Modifier.padding(horizontal = 80.dp).padding(top = 700.dp),
+        shape = EntryShape.FullMediumRoundedCorner,
+        containerColor = LocalAndroidColorScheme.current.colorBackground,
+        contentColor = LocalAndroidColorScheme.current.colorAccentPrimaryVariant,
+    ) {
+        Row(
+            horizontalArrangement = Arrangement.SpaceBetween,
+            verticalAlignment = Alignment.CenterVertically,
+        ) {
+            TextButton(
+                onClick = {onClick(true)},
+            ) {
+                Text(text = stringResource(R.string.get_dialog_use_saved_passkey_for))
+            }
+            IconButton(onClick = onCancel) {
+                Icon(
+                    Icons.Filled.Close,
+                    contentDescription = stringResource(
+                        R.string.accessibility_close_button
+                    )
+                )
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialViewModel.kt b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialViewModel.kt
index 33e7021..c182397 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialViewModel.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialViewModel.kt
@@ -36,11 +36,13 @@
 
 data class GetCredentialUiState(
   val providerInfoList: List<ProviderInfo>,
-  val currentScreenState: GetScreenState,
   val requestDisplayInfo: RequestDisplayInfo,
+  val currentScreenState: GetScreenState = toGetScreenState(providerInfoList),
   val providerDisplayInfo: ProviderDisplayInfo = toProviderDisplayInfo(providerInfoList),
   val selectedEntry: EntryInfo? = null,
   val hidden: Boolean = false,
+  val providerActivityPending: Boolean = false,
+  val isNoAccount: Boolean = false,
 )
 
 class GetCredentialViewModel(
@@ -79,6 +81,9 @@
   ) {
     val entry = uiState.selectedEntry
     if (entry != null && entry.pendingIntent != null) {
+      uiState = uiState.copy(
+        providerActivityPending = true,
+      )
       val intentSenderRequest = IntentSenderRequest.Builder(entry.pendingIntent)
         .setFillInIntent(entry.fillInIntent).build()
       launcher.launch(intentSenderRequest)
@@ -96,6 +101,7 @@
       uiState = uiState.copy(
         selectedEntry = null,
         hidden = false,
+        providerActivityPending = false,
       )
     } else {
       if (entry != null) {
@@ -122,6 +128,14 @@
     )
   }
 
+  fun onMoreOptionOnSnackBarSelected(isNoAccount: Boolean) {
+    Log.d("Account Selector", "More Option on snackBar selected")
+    uiState = uiState.copy(
+      currentScreenState = GetScreenState.ALL_SIGN_IN_OPTIONS,
+      isNoAccount = isNoAccount,
+    )
+  }
+
   fun onBackToPrimarySelectionScreen() {
     uiState = uiState.copy(
       currentScreenState = GetScreenState.PRIMARY_SELECTION
@@ -187,9 +201,36 @@
   )
 }
 
+private fun toGetScreenState(
+  providerInfoList: List<ProviderInfo>
+): GetScreenState {
+  var noLocalAccount = true
+  var remoteInfo: RemoteEntryInfo? = null
+  providerInfoList.forEach{providerInfo -> if (
+    providerInfo.credentialEntryList.isNotEmpty() || providerInfo.authenticationEntry != null
+  ) { noLocalAccount = false }
+    // TODO: handle the error situation that if multiple remoteInfos exists
+    if (providerInfo.remoteEntry != null) {
+      remoteInfo = providerInfo.remoteEntry
+    }
+  }
+
+  return if (noLocalAccount && remoteInfo != null)
+    GetScreenState.REMOTE_ONLY else GetScreenState.PRIMARY_SELECTION
+}
+
 internal class CredentialEntryInfoComparator : Comparator<CredentialEntryInfo> {
   override fun compare(p0: CredentialEntryInfo, p1: CredentialEntryInfo): Int {
-    // First order by last used timestamp
+    // First prefer passkey type for its security benefits
+    if (p0.credentialType != p1.credentialType) {
+      if (PublicKeyCredential.TYPE_PUBLIC_KEY_CREDENTIAL == p0.credentialType) {
+        return -1
+      } else if (PublicKeyCredential.TYPE_PUBLIC_KEY_CREDENTIAL == p1.credentialType) {
+        return 1
+      }
+    }
+
+    // Then order by last used timestamp
     if (p0.lastUsedTimeMillis != null && p1.lastUsedTimeMillis != null) {
       if (p0.lastUsedTimeMillis < p1.lastUsedTimeMillis) {
         return 1
@@ -201,15 +242,6 @@
     } else if (p1.lastUsedTimeMillis != null && p1.lastUsedTimeMillis > 0) {
       return 1
     }
-
-    // Then prefer passkey type for its security benefits
-    if (p0.credentialType != p1.credentialType) {
-      if (PublicKeyCredential.TYPE_PUBLIC_KEY_CREDENTIAL == p0.credentialType) {
-        return -1
-      } else if (PublicKeyCredential.TYPE_PUBLIC_KEY_CREDENTIAL == p1.credentialType) {
-        return 1
-      }
-    }
     return 0
   }
 }
\ No newline at end of file
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetModel.kt b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetModel.kt
index 0c3baff..3a2a738 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetModel.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetModel.kt
@@ -120,4 +120,6 @@
   PRIMARY_SELECTION,
   /** The secondary credential selection page, where all sign-in options are listed. */
   ALL_SIGN_IN_OPTIONS,
+  /** The snackbar only page when there's no account but only a remoteEntry. */
+  REMOTE_ONLY,
 }
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetCredentialOption.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetCredentialOption.kt
index eb65241..ef48a77 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetCredentialOption.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetCredentialOption.kt
@@ -28,9 +28,9 @@
  *                              otherwise
  */
 open class GetCredentialOption(
-        val type: String,
-        val data: Bundle,
-        val requireSystemProvider: Boolean,
+    val type: String,
+    val data: Bundle,
+    val requireSystemProvider: Boolean,
 ) {
     companion object {
         @JvmStatic
@@ -38,14 +38,20 @@
             return try {
                 when (from.type) {
                     Credential.TYPE_PASSWORD_CREDENTIAL ->
-                        GetPasswordOption.createFrom(from.data)
+                        GetPasswordOption.createFrom(from.credentialRetrievalData)
                     PublicKeyCredential.TYPE_PUBLIC_KEY_CREDENTIAL ->
-                        GetPublicKeyCredentialBaseOption.createFrom(from.data)
+                        GetPublicKeyCredentialBaseOption.createFrom(from.credentialRetrievalData)
                     else ->
-                        GetCredentialOption(from.type, from.data, from.requireSystemProvider())
+                        GetCredentialOption(
+                            from.type, from.credentialRetrievalData, from.requireSystemProvider()
+                        )
                 }
             } catch (e: FrameworkClassParsingException) {
-                GetCredentialOption(from.type, from.data, from.requireSystemProvider())
+                GetCredentialOption(
+                    from.type,
+                    from.credentialRetrievalData,
+                    from.requireSystemProvider()
+                )
             }
         }
     }
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/ActionUi.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/ActionUi.kt
index 1e639fe..19c5c2d 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/ActionUi.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/ActionUi.kt
@@ -18,7 +18,6 @@
 
 import android.app.slice.Slice
 import android.credentials.ui.Entry
-import android.graphics.drawable.Icon
 
 /**
  * UI representation for a credential entry used during the get credential flow.
@@ -26,28 +25,24 @@
  * TODO: move to jetpack.
  */
 class ActionUi(
-  val icon: Icon,
   val text: CharSequence,
   val subtext: CharSequence?,
 ) {
   companion object {
     fun fromSlice(slice: Slice): ActionUi {
-      var icon: Icon? = null
       var text: CharSequence? = null
       var subtext: CharSequence? = null
 
       val items = slice.items
       items.forEach {
-        if (it.hasHint(Entry.HINT_ACTION_ICON)) {
-          icon = it.icon
-        } else if (it.hasHint(Entry.HINT_ACTION_TITLE)) {
+        if (it.hasHint(Entry.HINT_ACTION_TITLE)) {
           text = it.text
         } else if (it.hasHint(Entry.HINT_ACTION_SUBTEXT)) {
           subtext = it.text
         }
       }
       // TODO: fail NPE more elegantly.
-      return ActionUi(icon!!, text!!, subtext)
+      return ActionUi(text!!, subtext)
     }
   }
 }
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/CredentialEntryUi.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/CredentialEntryUi.kt
index 1693eb6..47b5af0 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/CredentialEntryUi.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/CredentialEntryUi.kt
@@ -16,8 +16,8 @@
 
 package com.android.credentialmanager.jetpack.provider
 
+import android.app.PendingIntent
 import android.app.slice.Slice
-import android.credentials.ui.Entry
 import android.graphics.drawable.Icon
 
 /**
@@ -32,38 +32,57 @@
   val userDisplayName: CharSequence?,
   val entryIcon: Icon?,
   val lastUsedTimeMillis: Long?,
+  // TODO: Remove note
   val note: CharSequence?,
 ) {
   companion object {
-    fun fromSlice(slice: Slice): CredentialEntryUi {
-      var credentialType = slice.spec!!.type
-      var credentialTypeDisplayName: CharSequence? = null
-      var userName: CharSequence? = null
-      var userDisplayName: CharSequence? = null
-      var entryIcon: Icon? = null
-      var lastUsedTimeMillis: Long? = null
-      var note: CharSequence? = null
+    // Copied over from jetpack
+    const val SLICE_HINT_TYPE_DISPLAY_NAME =
+            "androidx.credentials.provider.credentialEntry.SLICE_HINT_TYPE_DISPLAY_NAME"
+    const val SLICE_HINT_USERNAME =
+            "androidx.credentials.provider.credentialEntry.SLICE_HINT_USER_NAME"
+    const val SLICE_HINT_DISPLAYNAME =
+            "androidx.credentials.provider.credentialEntry.SLICE_HINT_CREDENTIAL_TYPE_DISPLAY_NAME"
+    const val SLICE_HINT_LAST_USED_TIME_MILLIS =
+            "androidx.credentials.provider.credentialEntry.SLICE_HINT_LAST_USED_TIME_MILLIS"
+    const val SLICE_HINT_ICON =
+            "androidx.credentials.provider.credentialEntry.SLICE_HINT_PROFILE_ICON"
+    const val SLICE_HINT_PENDING_INTENT =
+            "androidx.credentials.provider.credentialEntry.SLICE_HINT_PENDING_INTENT"
 
-      val items = slice.items
-      items.forEach {
-        if (it.hasHint(Entry.HINT_CREDENTIAL_TYPE_DISPLAY_NAME)) {
-          credentialTypeDisplayName = it.text
-        } else if (it.hasHint(Entry.HINT_USER_NAME)) {
-          userName = it.text
-        } else if (it.hasHint(Entry.HINT_PASSKEY_USER_DISPLAY_NAME)) {
-          userDisplayName = it.text
-        } else if (it.hasHint(Entry.HINT_PROFILE_ICON)) {
-          entryIcon = it.icon
-        } else if (it.hasHint(Entry.HINT_LAST_USED_TIME_MILLIS)) {
+    /**
+     * Returns an instance of [CredentialEntryUi] derived from a [Slice] object.
+     *
+     * @param slice the [Slice] object constructed through jetpack library
+     */
+    @JvmStatic
+    fun fromSlice(slice: Slice): CredentialEntryUi {
+      var username: CharSequence? = null
+      var displayName: CharSequence = ""
+      var icon: Icon? = null
+      var pendingIntent: PendingIntent? = null
+      var lastUsedTimeMillis: Long = 0
+      var note: CharSequence? = null
+      var typeDisplayName: CharSequence = ""
+
+      slice.items.forEach {
+        if (it.hasHint(SLICE_HINT_TYPE_DISPLAY_NAME)) {
+          typeDisplayName = it.text
+        } else if (it.hasHint(SLICE_HINT_USERNAME)) {
+          username = it.text
+        } else if (it.hasHint(SLICE_HINT_DISPLAYNAME)) {
+          displayName = it.text
+        } else if (it.hasHint(SLICE_HINT_ICON)) {
+          icon = it.icon
+        } else if (it.hasHint(SLICE_HINT_PENDING_INTENT)) {
+          pendingIntent = it.action
+        } else if (it.hasHint(SLICE_HINT_LAST_USED_TIME_MILLIS)) {
           lastUsedTimeMillis = it.long
-        } else if (it.hasHint(Entry.HINT_NOTE)) {
-          note = it.text
         }
       }
-
       return CredentialEntryUi(
-        credentialType, credentialTypeDisplayName!!, userName!!, userDisplayName, entryIcon,
-        lastUsedTimeMillis, note,
+              slice.spec!!.type, typeDisplayName, username!!, displayName, icon,
+              lastUsedTimeMillis, note,
       )
     }
   }
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/SaveEntryUi.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/SaveEntryUi.kt
index bcc0531..313f0f9 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/SaveEntryUi.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/SaveEntryUi.kt
@@ -16,8 +16,8 @@
 
 package com.android.credentialmanager.jetpack.provider
 
+import android.app.PendingIntent
 import android.app.slice.Slice
-import android.credentials.ui.Entry
 import android.graphics.drawable.Icon
 
 /**
@@ -35,38 +35,45 @@
   val lastUsedTimeMillis: Long?,
 ) {
   companion object {
+    const val SLICE_HINT_ACCOUNT_NAME =
+            "androidx.credentials.provider.createEntry.SLICE_HINT_USER_PROVIDER_ACCOUNT_NAME"
+    const val SLICE_HINT_ICON =
+            "androidx.credentials.provider.createEntry.SLICE_HINT_PROFILE_ICON"
+    const val SLICE_HINT_CREDENTIAL_COUNT_INFORMATION =
+            "androidx.credentials.provider.createEntry.SLICE_HINT_CREDENTIAL_COUNT_INFORMATION"
+    const val SLICE_HINT_LAST_USED_TIME_MILLIS =
+            "androidx.credentials.provider.createEntry.SLICE_HINT_LAST_USED_TIME_MILLIS"
+    const val SLICE_HINT_PENDING_INTENT =
+            "androidx.credentials.provider.createEntry.SLICE_HINT_PENDING_INTENT"
+
+    /**
+     * Returns an instance of [SaveEntryUi] derived from a [Slice] object.
+     *
+     * @param slice the [Slice] object constructed through the jetpack library
+     */
+    @JvmStatic
     fun fromSlice(slice: Slice): SaveEntryUi {
-      var userProviderAccountName: CharSequence? = null
-      var credentialTypeIcon: Icon? = null
-      var profileIcon: Icon? = null
-      var passwordCount: Int? = null
-      var passkeyCount: Int? = null
-      var totalCredentialCount: Int? = null
-      var lastUsedTimeMillis: Long? = null
+      var accountName: CharSequence? = null
+      var icon: Icon? = null
+      var pendingIntent: PendingIntent? = null
+      var lastUsedTimeMillis: Long = 0
 
-
-      val items = slice.items
-      items.forEach {
-        if (it.hasHint(Entry.HINT_USER_PROVIDER_ACCOUNT_NAME)) {
-          userProviderAccountName = it.text
-        } else if (it.hasHint(Entry.HINT_CREDENTIAL_TYPE_ICON)) {
-          credentialTypeIcon = it.icon
-        } else if (it.hasHint(Entry.HINT_PROFILE_ICON)) {
-          profileIcon = it.icon
-        } else if (it.hasHint(Entry.HINT_PASSWORD_COUNT)) {
-          passwordCount = it.int
-        } else if (it.hasHint(Entry.HINT_PASSKEY_COUNT)) {
-          passkeyCount = it.int
-        } else if (it.hasHint(Entry.HINT_TOTAL_CREDENTIAL_COUNT)) {
-          totalCredentialCount = it.int
-        } else if (it.hasHint(Entry.HINT_LAST_USED_TIME_MILLIS)) {
+      slice.items.forEach {
+        if (it.hasHint(SLICE_HINT_ACCOUNT_NAME)) {
+          accountName = it.text
+        } else if (it.hasHint(SLICE_HINT_ICON)) {
+          icon = it.icon
+        } else if (it.hasHint(SLICE_HINT_PENDING_INTENT)) {
+          pendingIntent = it.action
+        } else if (it.hasHint(SLICE_HINT_LAST_USED_TIME_MILLIS)) {
           lastUsedTimeMillis = it.long
         }
       }
-      // TODO: fail NPE more elegantly.
+
       return SaveEntryUi(
-        userProviderAccountName!!, credentialTypeIcon, profileIcon,
-        passwordCount, passkeyCount, totalCredentialCount, lastUsedTimeMillis,
+              // TODO: Add count parsing
+              accountName!!, icon, icon,
+              0, 0, 0, lastUsedTimeMillis,
       )
     }
   }
diff --git a/packages/InputDevices/res/raw/keyboard_layout_english_us_intl.kcm b/packages/InputDevices/res/raw/keyboard_layout_english_us_intl.kcm
index 66c1c98..aa31493 100644
--- a/packages/InputDevices/res/raw/keyboard_layout_english_us_intl.kcm
+++ b/packages/InputDevices/res/raw/keyboard_layout_english_us_intl.kcm
@@ -292,10 +292,10 @@
 
 key APOSTROPHE {
     label:                              '\''
-    base:                               '\''
-    shift:                              '"'
-    ralt:                               '\u0301'
-    shift+ralt:                         '\u0308'
+    base:                               '\u030D'
+    shift:                              '\u030E'
+    ralt:                               '\u00B4'
+    shift+ralt:                         '\u00A8'
 }
 
 ### ROW 4
diff --git a/packages/PackageInstaller/res/values/strings.xml b/packages/PackageInstaller/res/values/strings.xml
index 6a3b239..b713c14 100644
--- a/packages/PackageInstaller/res/values/strings.xml
+++ b/packages/PackageInstaller/res/values/strings.xml
@@ -119,6 +119,10 @@
     <string name="uninstall_update_text_multiuser">Replace this app with the factory version? All data will be removed. This affects all users of this device, including those with work profiles.</string>
     <!-- Label of a checkbox that allows to keep the data (e.g. files, settings) of the app on uninstall [CHAR LIMIT=none] -->
     <string name="uninstall_keep_data">Keep <xliff:g id="size" example="1.5MB">%1$s</xliff:g> of app data.</string>
+    <!--  [CHAR LIMIT=none] -->
+    <string name="uninstall_application_text_current_user_clone_profile">Do you want to delete this app?</string>
+    <!--  [CHAR LIMIT=none] -->
+    <string name="uninstall_application_text_with_clone_instance">Do you want to uninstall this app? <xliff:g id="package_label">%1$s</xliff:g> clone will also be deleted.</string>
 
     <!-- Label for the notification channel containing notifications for current uninstall operations [CHAR LIMIT=40] -->
     <string name="uninstalling_notification_channel">Running uninstalls</string>
@@ -137,6 +141,8 @@
     <string name="uninstall_failed">Uninstall unsuccessful.</string>
     <!-- [CHAR LIMIT=100] -->
     <string name="uninstall_failed_app">Uninstalling <xliff:g id="package_label">%1$s</xliff:g> unsuccessful.</string>
+    <!-- [CHAR LIMIT=100] -->
+    <string name="uninstalling_cloned_app">Deleting <xliff:g id="package_label">%1$s</xliff:g> clone\u2026</string>
     <!-- String presented to the user when uninstalling a package failed because the target package
         is a current device administrator [CHAR LIMIT=80] -->
     <string name="uninstall_failed_device_policy_manager">Can\'t uninstall active device admin
@@ -219,6 +225,9 @@
         TV or loss of data that may result from its use.
     </string>
 
+    <!-- Label for cloned app in uninstall dialogue [CHAR LIMIT=40] -->
+    <string name="cloned_app_label"><xliff:g id="package_label">%1$s</xliff:g> Clone</string>
+
     <!-- Label for button to continue install of an app whose source cannot be identified [CHAR LIMIT=40] -->
     <string name="anonymous_source_continue">Continue</string>
 
diff --git a/packages/PackageInstaller/src/com/android/packageinstaller/UninstallUninstalling.java b/packages/PackageInstaller/src/com/android/packageinstaller/UninstallUninstalling.java
index 7bf27df..1485352 100644
--- a/packages/PackageInstaller/src/com/android/packageinstaller/UninstallUninstalling.java
+++ b/packages/PackageInstaller/src/com/android/packageinstaller/UninstallUninstalling.java
@@ -33,8 +33,10 @@
 import android.content.pm.VersionedPackage;
 import android.os.Bundle;
 import android.os.IBinder;
+import android.os.Process;
 import android.os.RemoteException;
 import android.os.UserHandle;
+import android.os.UserManager;
 import android.util.Log;
 import android.widget.Toast;
 
@@ -51,6 +53,7 @@
 
     static final String EXTRA_APP_LABEL = "com.android.packageinstaller.extra.APP_LABEL";
     static final String EXTRA_KEEP_DATA = "com.android.packageinstaller.extra.KEEP_DATA";
+    public static final String EXTRA_IS_CLONE_USER = "isCloneUser";
 
     private int mUninstallId;
     private ApplicationInfo mAppInfo;
@@ -76,6 +79,18 @@
                 boolean keepData = getIntent().getBooleanExtra(EXTRA_KEEP_DATA, false);
                 UserHandle user = getIntent().getParcelableExtra(Intent.EXTRA_USER);
 
+                boolean isCloneUser = false;
+                if (user == null) {
+                    user = Process.myUserHandle();
+                }
+
+                UserManager customUserManager = UninstallUninstalling.this
+                        .createContextAsUser(UserHandle.of(user.getIdentifier()), 0)
+                        .getSystemService(UserManager.class);
+                if (customUserManager.isUserOfType(UserManager.USER_TYPE_PROFILE_CLONE)) {
+                    isCloneUser = true;
+                }
+
                 // Show dialog, which is the whole UI
                 FragmentTransaction transaction = getFragmentManager().beginTransaction();
                 Fragment prev = getFragmentManager().findFragmentByTag("dialog");
@@ -83,6 +98,9 @@
                     transaction.remove(prev);
                 }
                 DialogFragment dialog = new UninstallUninstallingFragment();
+                Bundle args = new Bundle();
+                args.putBoolean(EXTRA_IS_CLONE_USER, isCloneUser);
+                dialog.setArguments(args);
                 dialog.setCancelable(false);
                 dialog.show(transaction, "dialog");
 
@@ -176,9 +194,20 @@
         public Dialog onCreateDialog(Bundle savedInstanceState) {
             AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
 
+            Bundle bundle = getArguments();
+            boolean isCloneUser = false;
+            if (bundle != null) {
+                isCloneUser = bundle.getBoolean(EXTRA_IS_CLONE_USER);
+            }
+
             dialogBuilder.setCancelable(false);
-            dialogBuilder.setMessage(getActivity().getString(R.string.uninstalling_app,
-                    ((UninstallUninstalling) getActivity()).mLabel));
+            if (isCloneUser) {
+                dialogBuilder.setMessage(getActivity().getString(R.string.uninstalling_cloned_app,
+                        ((UninstallUninstalling) getActivity()).mLabel));
+            } else {
+                dialogBuilder.setMessage(getActivity().getString(R.string.uninstalling_app,
+                        ((UninstallUninstalling) getActivity()).mLabel));
+            }
 
             Dialog dialog = dialogBuilder.create();
             dialog.setCanceledOnTouchOutside(false);
diff --git a/packages/PackageInstaller/src/com/android/packageinstaller/handheld/UninstallAlertDialogFragment.java b/packages/PackageInstaller/src/com/android/packageinstaller/handheld/UninstallAlertDialogFragment.java
index c9230b4..a1bc992 100644
--- a/packages/PackageInstaller/src/com/android/packageinstaller/handheld/UninstallAlertDialogFragment.java
+++ b/packages/PackageInstaller/src/com/android/packageinstaller/handheld/UninstallAlertDialogFragment.java
@@ -123,6 +123,7 @@
                 messageBuilder.append(" ").append(appLabel).append(".\n\n");
             }
         }
+        boolean isClonedApp = false;
 
         final boolean isUpdate =
                 ((dialogInfo.appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0);
@@ -144,16 +145,36 @@
                     messageBuilder.append(
                             getString(R.string.uninstall_application_text_current_user_work_profile,
                                     userInfo.name));
+                } else if (userInfo.isCloneProfile()
+                        && userInfo.profileGroupId == myUserHandle.getIdentifier()) {
+                    isClonedApp = true;
+                    messageBuilder.append(getString(
+                            R.string.uninstall_application_text_current_user_clone_profile));
                 } else {
                     messageBuilder.append(
                             getString(R.string.uninstall_application_text_user, userInfo.name));
                 }
+            } else if (isCloneProfile(myUserHandle)) {
+                isClonedApp = true;
+                messageBuilder.append(getString(
+                        R.string.uninstall_application_text_current_user_clone_profile));
             } else {
-                messageBuilder.append(getString(R.string.uninstall_application_text));
+                if (Process.myUserHandle().equals(UserHandle.SYSTEM)
+                        && hasClonedInstance(dialogInfo.appInfo.packageName)) {
+                    messageBuilder.append(getString(
+                            R.string.uninstall_application_text_with_clone_instance,
+                            appLabel));
+                } else {
+                    messageBuilder.append(getString(R.string.uninstall_application_text));
+                }
             }
         }
 
-        dialogBuilder.setTitle(appLabel);
+        if (isClonedApp) {
+            dialogBuilder.setTitle(getString(R.string.cloned_app_label, appLabel));
+        } else {
+            dialogBuilder.setTitle(appLabel);
+        }
         dialogBuilder.setPositiveButton(android.R.string.ok, this);
         dialogBuilder.setNegativeButton(android.R.string.cancel, this);
 
@@ -192,6 +213,42 @@
         return dialogBuilder.create();
     }
 
+    private boolean isCloneProfile(UserHandle userHandle) {
+        UserManager customUserManager = getContext()
+                .createContextAsUser(UserHandle.of(userHandle.getIdentifier()), 0)
+                .getSystemService(UserManager.class);
+        if (customUserManager.isUserOfType(UserManager.USER_TYPE_PROFILE_CLONE)) {
+            return true;
+        }
+        return false;
+    }
+
+    private boolean hasClonedInstance(String packageName) {
+        // Check if clone user is present on the device.
+        UserHandle cloneUser = null;
+        UserManager userManager = getContext().getSystemService(UserManager.class);
+        List<UserHandle> profiles = userManager.getUserProfiles();
+        for (UserHandle userHandle : profiles) {
+            if (!Process.myUserHandle().equals(UserHandle.SYSTEM) && isCloneProfile(userHandle)) {
+                cloneUser = userHandle;
+                break;
+            }
+        }
+
+        // Check if another instance of given package exists in clone user profile.
+        if (cloneUser != null) {
+            try {
+                if (getContext().getPackageManager()
+                        .getPackageUidAsUser(packageName, cloneUser.getIdentifier()) > 0) {
+                    return true;
+                }
+            } catch (PackageManager.NameNotFoundException e) {
+                return false;
+            }
+        }
+        return false;
+    }
+
     @Override
     public void onClick(DialogInterface dialog, int which) {
         if (which == Dialog.BUTTON_POSITIVE) {
diff --git a/packages/PrintSpooler/res/values-ca/strings.xml b/packages/PrintSpooler/res/values-ca/strings.xml
index a346cb2..4ee4323 100644
--- a/packages/PrintSpooler/res/values-ca/strings.xml
+++ b/packages/PrintSpooler/res/values-ca/strings.xml
@@ -56,6 +56,7 @@
     <string name="print_select_printer" msgid="7388760939873368698">"Selecciona una impressora"</string>
     <string name="print_forget_printer" msgid="5035287497291910766">"Oblida la impressora"</string>
     <plurals name="print_search_result_count_utterance" formatted="false" msgid="6997663738361080868">
+      <item quantity="many"><xliff:g id="COUNT_1">%1$s</xliff:g> printers found</item>
       <item quantity="other">S\'han trobat <xliff:g id="COUNT_1">%1$s</xliff:g> impressores</item>
       <item quantity="one">S\'ha trobat <xliff:g id="COUNT_0">%1$s</xliff:g> impressora</item>
     </plurals>
@@ -76,6 +77,7 @@
     <string name="disabled_services_title" msgid="7313253167968363211">"Serveis desactivats"</string>
     <string name="all_services_title" msgid="5578662754874906455">"Tots els serveis"</string>
     <plurals name="print_services_recommendation_subtitle" formatted="false" msgid="5678487708807185138">
+      <item quantity="many">Install to discover <xliff:g id="COUNT_1">%1$s</xliff:g> printers</item>
       <item quantity="other">Instal·la\'l per detectar <xliff:g id="COUNT_1">%1$s</xliff:g> impressores</item>
       <item quantity="one">Instal·la\'l per detectar <xliff:g id="COUNT_0">%1$s</xliff:g> impressora</item>
     </plurals>
diff --git a/packages/PrintSpooler/res/values-iw/strings.xml b/packages/PrintSpooler/res/values-iw/strings.xml
index 2ed8b7f..4c93df7 100644
--- a/packages/PrintSpooler/res/values-iw/strings.xml
+++ b/packages/PrintSpooler/res/values-iw/strings.xml
@@ -56,10 +56,9 @@
     <string name="print_select_printer" msgid="7388760939873368698">"בחירת מדפסת"</string>
     <string name="print_forget_printer" msgid="5035287497291910766">"לשכוח את המדפסת"</string>
     <plurals name="print_search_result_count_utterance" formatted="false" msgid="6997663738361080868">
+      <item quantity="one">נמצאו <xliff:g id="COUNT_1">%1$s</xliff:g> מדפסות</item>
       <item quantity="two">נמצאו <xliff:g id="COUNT_1">%1$s</xliff:g> מדפסות</item>
-      <item quantity="many">נמצאו <xliff:g id="COUNT_1">%1$s</xliff:g> מדפסות</item>
       <item quantity="other">נמצאו <xliff:g id="COUNT_1">%1$s</xliff:g> מדפסות</item>
-      <item quantity="one">נמצאה מדפסת <xliff:g id="COUNT_0">%1$s</xliff:g></item>
     </plurals>
     <string name="printer_extended_description_template" msgid="1366699227703381874">"<xliff:g id="PRINT_SERVICE_LABEL">%1$s</xliff:g> - <xliff:g id="PRINTER_DESCRIPTION">%2$s</xliff:g>"</string>
     <string name="printer_info_desc" msgid="7181988788991581654">"מידע נוסף על המדפסת הזו"</string>
@@ -78,10 +77,9 @@
     <string name="disabled_services_title" msgid="7313253167968363211">"שירותים מושבתים"</string>
     <string name="all_services_title" msgid="5578662754874906455">"כל השירותים"</string>
     <plurals name="print_services_recommendation_subtitle" formatted="false" msgid="5678487708807185138">
+      <item quantity="one">יש להתקין כדי לגלות <xliff:g id="COUNT_1">%1$s</xliff:g> מדפסות</item>
       <item quantity="two">יש להתקין כדי לגלות <xliff:g id="COUNT_1">%1$s</xliff:g> מדפסות</item>
-      <item quantity="many">יש להתקין כדי לגלות <xliff:g id="COUNT_1">%1$s</xliff:g> מדפסות</item>
       <item quantity="other">יש להתקין כדי לגלות <xliff:g id="COUNT_1">%1$s</xliff:g> מדפסות</item>
-      <item quantity="one">יש להתקין כדי לגלות מדפסת אחת (<xliff:g id="COUNT_0">%1$s</xliff:g>)‏</item>
     </plurals>
     <string name="printing_notification_title_template" msgid="295903957762447362">"בתהליך הדפסה של <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
     <string name="cancelling_notification_title_template" msgid="1821759594704703197">"המערכת מבטלת את <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
diff --git a/packages/SettingsLib/AppPreference/Android.bp b/packages/SettingsLib/AppPreference/Android.bp
index 122f606..af7b8b4 100644
--- a/packages/SettingsLib/AppPreference/Android.bp
+++ b/packages/SettingsLib/AppPreference/Android.bp
@@ -23,5 +23,6 @@
     apex_available: [
         "//apex_available:platform",
         "com.android.permission",
+        "com.android.healthconnect",
     ],
 }
diff --git a/packages/SettingsLib/Spa/gallery/AndroidManifest.xml b/packages/SettingsLib/Spa/gallery/AndroidManifest.xml
index 37d6b42..965fdcf 100644
--- a/packages/SettingsLib/Spa/gallery/AndroidManifest.xml
+++ b/packages/SettingsLib/Spa/gallery/AndroidManifest.xml
@@ -38,8 +38,12 @@
         <provider
             android:name="com.android.settingslib.spa.search.SpaSearchProvider"
             android:authorities="com.android.spa.gallery.search.provider"
-            android:enabled="true"
-            android:exported="false">
+            android:exported="true"
+            android:grantUriPermissions="true"
+            android:permission="android.permission.READ_SEARCH_INDEXABLES">
+            <intent-filter>
+                <action android:name="android.content.action.SPA_SEARCH_PROVIDER" />
+            </intent-filter>
         </provider>
 
         <provider android:name="com.android.settingslib.spa.slice.SpaSliceProvider"
@@ -67,7 +71,6 @@
         <provider
             android:name="com.android.settingslib.spa.debug.DebugProvider"
             android:authorities="com.android.spa.gallery.debug.provider"
-            android:enabled="true"
             android:exported="false">
         </provider>
 
diff --git a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/GallerySpaEnvironment.kt b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/GallerySpaEnvironment.kt
index db49909..e54e276 100644
--- a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/GallerySpaEnvironment.kt
+++ b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/GallerySpaEnvironment.kt
@@ -17,7 +17,7 @@
 package com.android.settingslib.spa.gallery
 
 import android.content.Context
-import com.android.settingslib.spa.framework.common.LocalLogger
+import com.android.settingslib.spa.debug.DebugLogger
 import com.android.settingslib.spa.framework.common.SettingsPageProviderRepository
 import com.android.settingslib.spa.framework.common.SpaEnvironment
 import com.android.settingslib.spa.framework.common.createSettingsPage
@@ -83,7 +83,7 @@
         )
     }
 
-    override val logger = LocalLogger()
+    override val logger = DebugLogger()
 
     override val browseActivityClass = GalleryMainActivity::class.java
     override val sliceBroadcastReceiverClass = SpaSliceBroadcastReceiver::class.java
diff --git a/packages/SettingsLib/Spa/screenshot/Android.bp b/packages/SettingsLib/Spa/screenshot/Android.bp
new file mode 100644
index 0000000..4e6b646
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/Android.bp
@@ -0,0 +1,41 @@
+//
+// 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 {
+    default_applicable_licenses: ["frameworks_base_license"],
+}
+
+android_test {
+    name: "SpaScreenshotTests",
+    test_suites: ["device-tests"],
+
+    asset_dirs: ["assets"],
+
+    srcs: ["src/**/*.kt"],
+
+    certificate: "platform",
+
+    static_libs: [
+        "SpaLib",
+        "SpaLibTestUtils",
+        "androidx.compose.runtime_runtime",
+        "androidx.test.ext.junit",
+        "androidx.test.runner",
+        "mockito-target-minus-junit4",
+        "platform-screenshot-diff-core",
+    ],
+    kotlincflags: ["-Xjvm-default=all"],
+}
diff --git a/packages/SettingsLib/Spa/screenshot/AndroidManifest.xml b/packages/SettingsLib/Spa/screenshot/AndroidManifest.xml
new file mode 100644
index 0000000..d59a154
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/AndroidManifest.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+  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.
+  -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.android.settingslib.spa.screenshot">
+
+    <uses-sdk android:minSdkVersion="21"/>
+
+    <application>
+        <uses-library android:name="android.test.runner" />
+        <activity android:name=".DebugActivity" android:exported="true" />
+    </application>
+
+    <instrumentation
+        android:name="androidx.test.runner.AndroidJUnitRunner"
+        android:label="Screenshot tests for SpaLib"
+        android:targetPackage="com.android.settingslib.spa.screenshot">
+    </instrumentation>
+</manifest>
diff --git a/packages/SettingsLib/Spa/screenshot/AndroidTest.xml b/packages/SettingsLib/Spa/screenshot/AndroidTest.xml
new file mode 100644
index 0000000..e0c08e8
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/AndroidTest.xml
@@ -0,0 +1,36 @@
+<!--
+  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.
+  -->
+
+<configuration description="Runs screendiff tests.">
+    <option name="test-suite-tag" value="apct-instrumentation" />
+    <option name="test-suite-tag" value="apct" />
+    <target_preparer class="com.android.tradefed.targetprep.DeviceSetup">
+        <option name="optimized-property-setting" value="true" />
+    </target_preparer>
+    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+        <option name="cleanup-apks" value="true" />
+        <option name="test-file-name" value="SpaScreenshotTests.apk" />
+    </target_preparer>
+    <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector">
+        <option name="directory-keys"
+            value="/data/user/0/com.android.settingslib.spa.screenshot/files/settings_screenshots" />
+        <option name="collect-on-run-ended-only" value="true" />
+    </metrics_collector>
+    <test class="com.android.tradefed.testtype.AndroidJUnitTest">
+        <option name="package" value="com.android.settingslib.spa.screenshot" />
+        <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
+    </test>
+</configuration>
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_actionButtons.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_actionButtons.png
new file mode 100644
index 0000000..74113d8
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_actionButtons.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_barChart.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_barChart.png
new file mode 100644
index 0000000..0d22c6a
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_barChart.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_footer.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_footer.png
new file mode 100644
index 0000000..f77b8a7
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_footer.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_imageIllustration.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_imageIllustration.png
new file mode 100644
index 0000000..9372791
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_imageIllustration.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_lineChart.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_lineChart.png
new file mode 100644
index 0000000..dda9e9e
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_lineChart.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_mainSwitchPreference.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_mainSwitchPreference.png
new file mode 100644
index 0000000..bf19a2c
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_mainSwitchPreference.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_pieChart.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_pieChart.png
new file mode 100644
index 0000000..b14e196e
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_pieChart.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_preference.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_preference.png
new file mode 100644
index 0000000..c77f9b1
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_preference.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_progressBar.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_progressBar.png
new file mode 100644
index 0000000..6bf20be
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_progressBar.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_slider.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_slider.png
new file mode 100644
index 0000000..dda6f0a
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_slider.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_spinner.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_spinner.png
new file mode 100644
index 0000000..7468169
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_spinner.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_switchPreference.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_switchPreference.png
new file mode 100644
index 0000000..669f443
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_switchPreference.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_twoTargetSwitchPreference.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_twoTargetSwitchPreference.png
new file mode 100644
index 0000000..8e37cc0
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_landscape_twoTargetSwitchPreference.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_actionButtons.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_actionButtons.png
new file mode 100644
index 0000000..b0543e0
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_actionButtons.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_barChart.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_barChart.png
new file mode 100644
index 0000000..3755928
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_barChart.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_footer.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_footer.png
new file mode 100644
index 0000000..f77b8a7
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_footer.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_imageIllustration.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_imageIllustration.png
new file mode 100644
index 0000000..7800149
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_imageIllustration.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_lineChart.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_lineChart.png
new file mode 100644
index 0000000..be40959
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_lineChart.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_mainSwitchPreference.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_mainSwitchPreference.png
new file mode 100644
index 0000000..2d5894e
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_mainSwitchPreference.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_pieChart.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_pieChart.png
new file mode 100644
index 0000000..2a54b9e
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_pieChart.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_preference.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_preference.png
new file mode 100644
index 0000000..b0fc305
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_preference.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_progressBar.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_progressBar.png
new file mode 100644
index 0000000..fa01348
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_progressBar.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_slider.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_slider.png
new file mode 100644
index 0000000..213c0b2
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_slider.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_spinner.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_spinner.png
new file mode 100644
index 0000000..7468169
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_spinner.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_switchPreference.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_switchPreference.png
new file mode 100644
index 0000000..ce7ab78
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_switchPreference.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_twoTargetSwitchPreference.png b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_twoTargetSwitchPreference.png
new file mode 100644
index 0000000..9d92f7a
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/phone/light_portrait_twoTargetSwitchPreference.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_actionButtons.png b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_actionButtons.png
new file mode 100644
index 0000000..5255d14
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_actionButtons.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_barChart.png b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_barChart.png
new file mode 100644
index 0000000..8f3f664
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_barChart.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_footer.png b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_footer.png
new file mode 100644
index 0000000..cc1de55
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_footer.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_imageIllustration.png b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_imageIllustration.png
new file mode 100644
index 0000000..e29f26a
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_imageIllustration.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_lineChart.png b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_lineChart.png
new file mode 100644
index 0000000..8b9bc5c
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_lineChart.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_mainSwitchPreference.png b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_mainSwitchPreference.png
new file mode 100644
index 0000000..b1676b3
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_mainSwitchPreference.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_pieChart.png b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_pieChart.png
new file mode 100644
index 0000000..2a7b341
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_pieChart.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_preference.png b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_preference.png
new file mode 100644
index 0000000..4845ea8
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_preference.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_progressBar.png b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_progressBar.png
new file mode 100644
index 0000000..7e57958
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_progressBar.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_slider.png b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_slider.png
new file mode 100644
index 0000000..d1abaa6
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_slider.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_spinner.png b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_spinner.png
new file mode 100644
index 0000000..c211e0e
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_spinner.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_switchPreference.png b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_switchPreference.png
new file mode 100644
index 0000000..9c57e33
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_switchPreference.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_twoTargetSwitchPreference.png b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_twoTargetSwitchPreference.png
new file mode 100644
index 0000000..d416a0b
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/assets/tablet/dark_portrait_twoTargetSwitchPreference.png
Binary files differ
diff --git a/packages/SettingsLib/Spa/screenshot/res/drawable/accessibility_captioning_banner.xml b/packages/SettingsLib/Spa/screenshot/res/drawable/accessibility_captioning_banner.xml
new file mode 100644
index 0000000..6597ffb
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/res/drawable/accessibility_captioning_banner.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="412dp"
+    android:height="300dp"
+    android:viewportWidth="412"
+    android:viewportHeight="300">
+  <path
+      android:pathData="M383.9,300H28.1C12.6,300 0,287.4 0,271.9V28.1C0,12.6 12.6,0 28.1,0h355.8C399.4,0 412,12.6 412,28.1v243.8C412,287.4 399.4,300 383.9,300z"
+      android:fillColor="#FFFFFF"/>
+  <path
+      android:pathData="M79.2,179.6h53.6v8.5h-53.6z"
+      android:fillColor="#1A73E8"/>
+  <path
+      android:pathData="M142.5,179.6h30.4v8.5h-30.4z"
+      android:fillColor="#1A73E8"/>
+  <path
+      android:pathData="M79.2,195.5h79.2v8.5h-79.2z"
+      android:fillColor="#1A73E8"/>
+  <path
+      android:pathData="M168.1,195.5h34.1v8.5h-34.1z"
+      android:fillColor="#1A73E8"/>
+  <path
+      android:pathData="M211.9,195.5h34.1v8.5h-34.1z"
+      android:fillColor="#1A73E8"/>
+  <path
+      android:pathData="M182.7,179.6h73.1v8.5h-73.1z"
+      android:fillColor="#1A73E8"/>
+  <path
+      android:pathData="M265.5,179.6h26.8v8.5h-26.8z"
+      android:fillColor="#1A73E8"/>
+  <path
+      android:pathData="M302.1,179.6h26.8v8.5h-26.8z"
+      android:fillColor="#1A73E8"/>
+  <path
+      android:pathData="M142.7,67.9h-11.5c-1.6,0 -2.9,1.3 -2.9,2.9H67.8c-7.9,0 -14.4,6.5 -14.4,14.4v132.4c0,7.9 6.5,14.4 14.4,14.4h276.4c7.9,0 14.4,-6.5 14.4,-14.4V85.2c0,-7.9 -6.5,-14.4 -14.4,-14.4H203.1c0,-1.6 -1.3,-2.9 -2.9,-2.9h-28.8c-1.6,0 -2.9,1.3 -2.9,2.9h-23C145.5,69.2 144.3,67.9 142.7,67.9zM344.2,73.7c6.4,0 11.5,5.2 11.5,11.5v132.4c0,6.3 -5.2,11.5 -11.5,11.5H67.8c-6.4,0 -11.5,-5.2 -11.5,-11.5V85.2c0,-6.3 5.2,-11.5 11.5,-11.5H344.2z"
+      android:fillColor="#DADCE0"/>
+</vector>
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/Bitmap.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/Bitmap.kt
new file mode 100644
index 0000000..814d4a1
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/Bitmap.kt
@@ -0,0 +1,66 @@
+/*
+ * 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.settingslib.spa.screenshot
+
+import android.graphics.Bitmap
+import android.graphics.Canvas
+import android.os.Build
+import android.view.View
+import platform.test.screenshot.matchers.MSSIMMatcher
+import platform.test.screenshot.matchers.PixelPerfectMatcher
+
+/** Draw this [View] into a [Bitmap]. */
+// TODO(b/195673633): Remove this once Compose screenshot tests use hardware rendering for their
+// tests.
+fun View.drawIntoBitmap(): Bitmap {
+    val bitmap =
+        Bitmap.createBitmap(
+            measuredWidth,
+            measuredHeight,
+            Bitmap.Config.ARGB_8888,
+        )
+    val canvas = Canvas(bitmap)
+    draw(canvas)
+    return bitmap
+}
+
+/**
+ * The [BitmapMatcher][platform.test.screenshot.matchers.BitmapMatcher] that should be used for
+ * screenshot *unit* tests.
+ */
+val UnitTestBitmapMatcher =
+    if (Build.CPU_ABI == "x86_64") {
+        // Different CPU architectures can sometimes end up rendering differently, so we can't do
+        // pixel-perfect matching on different architectures using the same golden. Given that our
+        // presubmits are run on cf_x86_64_phone, our goldens should be perfectly matched on the
+        // x86_64 architecture and use the Structural Similarity Index on others.
+        // TODO(b/237511747): Run our screenshot presubmit tests on arm64 instead so that we can
+        // do pixel perfect matching both at presubmit time and at development time with actual
+        // devices.
+        PixelPerfectMatcher()
+    } else {
+        MSSIMMatcher()
+    }
+
+/**
+ * The [BitmapMatcher][platform.test.screenshot.matchers.BitmapMatcher] that should be used for
+ * screenshot *unit* tests.
+ *
+ * We use the Structural Similarity Index for integration tests because they usually contain
+ * additional information and noise that shouldn't break the test.
+ */
+val IntegrationTestBitmapMatcher = MSSIMMatcher()
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/DefaultDeviceEmulationSpec.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/DefaultDeviceEmulationSpec.kt
new file mode 100644
index 0000000..d7f42b3
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/DefaultDeviceEmulationSpec.kt
@@ -0,0 +1,66 @@
+/*
+ * 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.settingslib.spa.screenshot
+
+import platform.test.screenshot.DeviceEmulationSpec
+import platform.test.screenshot.DisplaySpec
+
+/**
+ * The emulations specs for all 8 permutations of:
+ * - phone or tablet.
+ * - dark of light mode.
+ * - portrait or landscape.
+ */
+val DeviceEmulationSpec.Companion.PhoneAndTabletFull
+    get() = PhoneAndTabletFullSpec
+
+private val PhoneAndTabletFullSpec =
+    DeviceEmulationSpec.forDisplays(Displays.Phone, Displays.Tablet)
+
+/**
+ * The emulations specs of:
+ * - phone + light mode + portrait.
+ * - phone + light mode + landscape.
+ * - tablet + dark mode + portrait.
+ *
+ * This allows to test the most important permutations of a screen/layout with only 3
+ * configurations.
+ */
+val DeviceEmulationSpec.Companion.PhoneAndTabletMinimal
+    get() = PhoneAndTabletMinimalSpec
+
+private val PhoneAndTabletMinimalSpec =
+    DeviceEmulationSpec.forDisplays(Displays.Phone, isDarkTheme = false) +
+        DeviceEmulationSpec.forDisplays(Displays.Tablet, isDarkTheme = true, isLandscape = false)
+
+object Displays {
+    val Phone =
+        DisplaySpec(
+            "phone",
+            width = 1440,
+            height = 3120,
+            densityDpi = 560,
+        )
+
+    val Tablet =
+        DisplaySpec(
+            "tablet",
+            width = 2560,
+            height = 1600,
+            densityDpi = 320,
+        )
+}
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/SettingsGoldenImagePathManager.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/SettingsGoldenImagePathManager.kt
new file mode 100644
index 0000000..25bc098
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/SettingsGoldenImagePathManager.kt
@@ -0,0 +1,44 @@
+/*
+ * 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.settingslib.spa.screenshot
+
+import androidx.test.platform.app.InstrumentationRegistry
+import platform.test.screenshot.GoldenImagePathManager
+import platform.test.screenshot.PathConfig
+
+/** A [GoldenImagePathManager] that should be used for all Settings screenshot tests. */
+class SettingsGoldenImagePathManager(
+    pathConfig: PathConfig,
+    assetsPathRelativeToBuildRoot: String
+) :
+    GoldenImagePathManager(
+        appContext = InstrumentationRegistry.getInstrumentation().context,
+        assetsPathRelativeToBuildRoot = assetsPathRelativeToBuildRoot,
+        deviceLocalPath =
+        InstrumentationRegistry.getInstrumentation()
+            .targetContext
+            .filesDir
+            .absolutePath
+            .toString() + "/settings_screenshots",
+        pathConfig = pathConfig,
+    ) {
+    override fun toString(): String {
+        // This string is appended to all actual/expected screenshots on the device, so make sure
+        // it is a static value.
+        return "SettingsGoldenImagePathManager"
+    }
+}
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/SettingsScreenshotTestRule.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/SettingsScreenshotTestRule.kt
new file mode 100644
index 0000000..7a7cf31
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/SettingsScreenshotTestRule.kt
@@ -0,0 +1,91 @@
+/*
+ * 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.settingslib.spa.screenshot
+
+import androidx.activity.ComponentActivity
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Surface
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.platform.ViewRootForTest
+import androidx.compose.ui.test.junit4.createAndroidComposeRule
+import androidx.compose.ui.test.onRoot
+import com.android.settingslib.spa.framework.theme.SettingsTheme
+import org.junit.rules.RuleChain
+import org.junit.rules.TestRule
+import org.junit.runner.Description
+import org.junit.runners.model.Statement
+import platform.test.screenshot.DeviceEmulationRule
+import platform.test.screenshot.DeviceEmulationSpec
+import platform.test.screenshot.MaterialYouColorsRule
+import platform.test.screenshot.ScreenshotTestRule
+import platform.test.screenshot.getEmulatedDevicePathConfig
+
+/** A rule for Settings screenshot diff tests. */
+class SettingsScreenshotTestRule(
+    emulationSpec: DeviceEmulationSpec,
+    assetsPathRelativeToBuildRoot: String
+) : TestRule {
+    private val colorsRule = MaterialYouColorsRule()
+    private val deviceEmulationRule = DeviceEmulationRule(emulationSpec)
+    private val screenshotRule =
+        ScreenshotTestRule(
+            SettingsGoldenImagePathManager(
+                getEmulatedDevicePathConfig(emulationSpec),
+                assetsPathRelativeToBuildRoot
+            )
+        )
+    private val composeRule = createAndroidComposeRule<ComponentActivity>()
+    private val delegateRule =
+        RuleChain.outerRule(colorsRule)
+            .around(deviceEmulationRule)
+            .around(screenshotRule)
+            .around(composeRule)
+    private val matcher = UnitTestBitmapMatcher
+
+    override fun apply(base: Statement, description: Description): Statement {
+        return delegateRule.apply(base, description)
+    }
+
+    /**
+     * Compare [content] with the golden image identified by [goldenIdentifier] in the context of
+     * [testSpec].
+     */
+    fun screenshotTest(
+        goldenIdentifier: String,
+        content: @Composable () -> Unit,
+    ) {
+        // Make sure that the activity draws full screen and fits the whole display.
+        val activity = composeRule.activity
+        activity.mainExecutor.execute { activity.window.setDecorFitsSystemWindows(false) }
+
+        // Set the content using the AndroidComposeRule to make sure that the Activity is set up
+        // correctly.
+        composeRule.setContent {
+            SettingsTheme {
+                Surface(
+                    color = MaterialTheme.colorScheme.background,
+                ) {
+                    content()
+                }
+            }
+        }
+        composeRule.waitForIdle()
+
+        val view = (composeRule.onRoot().fetchSemanticsNode().root as ViewRootForTest).view
+        screenshotRule.assertBitmapAgainstGolden(view.drawIntoBitmap(), goldenIdentifier, matcher)
+    }
+}
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/button/ActionButtonsScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/button/ActionButtonsScreenshotTest.kt
new file mode 100644
index 0000000..b2e0b18
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/button/ActionButtonsScreenshotTest.kt
@@ -0,0 +1,58 @@
+/*
+ * 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.settingslib.spa.screenshot
+
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.outlined.Delete
+import androidx.compose.material.icons.outlined.Launch
+import androidx.compose.material.icons.outlined.WarningAmber
+import com.android.settingslib.spa.widget.button.ActionButton
+import com.android.settingslib.spa.widget.button.ActionButtons
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.Parameterized
+import platform.test.screenshot.DeviceEmulationSpec
+
+/** A screenshot test for ExampleFeature. */
+@RunWith(Parameterized::class)
+class ActionButtonsScreenshotTest(emulationSpec: DeviceEmulationSpec) {
+    companion object {
+        @Parameterized.Parameters(name = "{0}")
+        @JvmStatic
+        fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
+    }
+
+    @get:Rule
+    val screenshotRule =
+        SettingsScreenshotTestRule(
+            emulationSpec,
+            "frameworks/base/packages/SettingsLib/Spa/screenshot/assets"
+        )
+
+    @Test
+    fun test() {
+        screenshotRule.screenshotTest("actionButtons") {
+            val actionButtons = listOf(
+                ActionButton(text = "Open", imageVector = Icons.Outlined.Launch) {},
+                ActionButton(text = "Uninstall", imageVector = Icons.Outlined.Delete) {},
+                ActionButton(text = "Force stop", imageVector = Icons.Outlined.WarningAmber) {},
+            )
+            ActionButtons(actionButtons)
+        }
+    }
+}
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/BarChartScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/BarChartScreenshotTest.kt
new file mode 100644
index 0000000..27d270c
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/BarChartScreenshotTest.kt
@@ -0,0 +1,76 @@
+/*
+ * 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.settingslib.spa.screenshot
+
+import com.android.settingslib.spa.widget.chart.BarChart
+import com.android.settingslib.spa.widget.chart.BarChartData
+import com.android.settingslib.spa.widget.chart.BarChartModel
+import com.github.mikephil.charting.formatter.IAxisValueFormatter
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.Parameterized
+import platform.test.screenshot.DeviceEmulationSpec
+
+/** A screenshot test for ExampleFeature. */
+@RunWith(Parameterized::class)
+class BarChartScreenshotTest(emulationSpec: DeviceEmulationSpec) {
+    companion object {
+        @Parameterized.Parameters(name = "{0}")
+        @JvmStatic
+        fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
+    }
+
+    @get:Rule
+    val screenshotRule =
+        SettingsScreenshotTestRule(
+            emulationSpec,
+            "frameworks/base/packages/SettingsLib/Spa/screenshot/assets"
+        )
+
+    @Test
+    fun test() {
+        screenshotRule.screenshotTest("barChart") {
+            BarChart(
+                barChartModel = object : BarChartModel {
+                    override val chartDataList = listOf(
+                        BarChartData(x = 0f, y = 12f),
+                        BarChartData(x = 1f, y = 5f),
+                        BarChartData(x = 2f, y = 21f),
+                        BarChartData(x = 3f, y = 5f),
+                        BarChartData(x = 4f, y = 10f),
+                        BarChartData(x = 5f, y = 9f),
+                        BarChartData(x = 6f, y = 1f),
+                    )
+                    override val xValueFormatter =
+                        IAxisValueFormatter { value, _ ->
+                            "${WeekDay.values()[value.toInt()]}"
+                        }
+                    override val yValueFormatter =
+                        IAxisValueFormatter { value, _ ->
+                            "${value.toInt()}m"
+                        }
+                    override val yAxisMaxValue = 30f
+                }
+            )
+        }
+    }
+
+    private enum class WeekDay(val num: Int) {
+        Sun(0), Mon(1), Tue(2), Wed(3), Thu(4), Fri(5), Sat(6),
+    }
+}
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/LineChartScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/LineChartScreenshotTest.kt
new file mode 100644
index 0000000..f9d93f8
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/LineChartScreenshotTest.kt
@@ -0,0 +1,76 @@
+/*
+ * 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.settingslib.spa.screenshot
+
+import com.android.settingslib.spa.widget.chart.LineChart
+import com.android.settingslib.spa.widget.chart.LineChartData
+import com.android.settingslib.spa.widget.chart.LineChartModel
+import com.github.mikephil.charting.formatter.IAxisValueFormatter
+import java.text.NumberFormat
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.Parameterized
+import platform.test.screenshot.DeviceEmulationSpec
+
+/** A screenshot test for ExampleFeature. */
+@RunWith(Parameterized::class)
+class LineChartScreenshotTest(emulationSpec: DeviceEmulationSpec) {
+    companion object {
+        @Parameterized.Parameters(name = "{0}")
+        @JvmStatic
+        fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
+    }
+
+    @get:Rule
+    val screenshotRule =
+        SettingsScreenshotTestRule(
+            emulationSpec,
+            "frameworks/base/packages/SettingsLib/Spa/screenshot/assets"
+        )
+
+    @Test
+    fun test() {
+        screenshotRule.screenshotTest("lineChart") {
+            LineChart(
+                lineChartModel = object : LineChartModel {
+                    override val chartDataList = listOf(
+                        LineChartData(x = 0f, y = 0f),
+                        LineChartData(x = 1f, y = 0.1f),
+                        LineChartData(x = 2f, y = 0.2f),
+                        LineChartData(x = 3f, y = 0.6f),
+                        LineChartData(x = 4f, y = 0.9f),
+                        LineChartData(x = 5f, y = 1.0f),
+                        LineChartData(x = 6f, y = 0.8f),
+                    )
+                    override val xValueFormatter =
+                        IAxisValueFormatter { value, _ ->
+                            "${WeekDay.values()[value.toInt()]}"
+                        }
+                    override val yValueFormatter =
+                        IAxisValueFormatter { value, _ ->
+                            NumberFormat.getPercentInstance().format(value)
+                        }
+                }
+            )
+        }
+    }
+
+    private enum class WeekDay(val num: Int) {
+        Sun(0), Mon(1), Tue(2), Wed(3), Thu(4), Fri(5), Sat(6),
+    }
+}
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/PieChartScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/PieChartScreenshotTest.kt
new file mode 100644
index 0000000..34ded3c
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/PieChartScreenshotTest.kt
@@ -0,0 +1,59 @@
+/*
+ * 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.settingslib.spa.screenshot
+
+import com.android.settingslib.spa.widget.chart.PieChart
+import com.android.settingslib.spa.widget.chart.PieChartData
+import com.android.settingslib.spa.widget.chart.PieChartModel
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.Parameterized
+import platform.test.screenshot.DeviceEmulationSpec
+
+/** A screenshot test for ExampleFeature. */
+@RunWith(Parameterized::class)
+class PieChartScreenshotTest(emulationSpec: DeviceEmulationSpec) {
+    companion object {
+        @Parameterized.Parameters(name = "{0}")
+        @JvmStatic
+        fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
+    }
+
+    @get:Rule
+    val screenshotRule =
+        SettingsScreenshotTestRule(
+            emulationSpec,
+            "frameworks/base/packages/SettingsLib/Spa/screenshot/assets"
+        )
+
+    @Test
+    fun test() {
+        screenshotRule.screenshotTest("pieChart") {
+            PieChart(
+                pieChartModel = object : PieChartModel {
+                    override val chartDataList = listOf(
+                        PieChartData(label = "Settings", value = 20f),
+                        PieChartData(label = "Chrome", value = 5f),
+                        PieChartData(label = "Gmail", value = 3f),
+                    )
+                    override val centerText = "Today"
+                }
+            )
+        }
+    }
+}
\ No newline at end of file
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/illustration/ImageIllustrationScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/illustration/ImageIllustrationScreenshotTest.kt
new file mode 100644
index 0000000..91aca05
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/illustration/ImageIllustrationScreenshotTest.kt
@@ -0,0 +1,53 @@
+/*
+ * 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.settingslib.spa.screenshot
+
+import com.android.settingslib.spa.widget.illustration.Illustration
+import com.android.settingslib.spa.widget.illustration.IllustrationModel
+import com.android.settingslib.spa.widget.illustration.ResourceType
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.Parameterized
+import platform.test.screenshot.DeviceEmulationSpec
+
+/** A screenshot test for ExampleFeature. */
+@RunWith(Parameterized::class)
+class ImageIllustrationScreenshotTest(emulationSpec: DeviceEmulationSpec) {
+    companion object {
+        @Parameterized.Parameters(name = "{0}")
+        @JvmStatic
+        fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
+    }
+
+    @get:Rule
+    val screenshotRule =
+        SettingsScreenshotTestRule(
+            emulationSpec,
+            "frameworks/base/packages/SettingsLib/Spa/screenshot/assets"
+        )
+
+    @Test
+    fun test() {
+        screenshotRule.screenshotTest("imageIllustration") {
+            Illustration(object : IllustrationModel {
+                override val resId = R.drawable.accessibility_captioning_banner
+                override val resourceType = ResourceType.IMAGE
+            })
+        }
+    }
+}
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/MainSwitchPreferenceScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/MainSwitchPreferenceScreenshotTest.kt
new file mode 100644
index 0000000..a366b9e
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/MainSwitchPreferenceScreenshotTest.kt
@@ -0,0 +1,65 @@
+/*
+ * 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.settingslib.spa.screenshot
+
+import androidx.compose.foundation.layout.Column
+import com.android.settingslib.spa.framework.compose.stateOf
+import com.android.settingslib.spa.widget.preference.MainSwitchPreference
+import com.android.settingslib.spa.widget.preference.SwitchPreferenceModel
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.Parameterized
+import platform.test.screenshot.DeviceEmulationSpec
+
+/** A screenshot test for ExampleFeature. */
+@RunWith(Parameterized::class)
+class MainSwitchPreferenceScreenshotTest(emulationSpec: DeviceEmulationSpec) {
+    companion object {
+        @Parameterized.Parameters(name = "{0}")
+        @JvmStatic
+        fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
+    }
+
+    @get:Rule
+    val screenshotRule =
+        SettingsScreenshotTestRule(
+            emulationSpec,
+            "frameworks/base/packages/SettingsLib/Spa/screenshot/assets"
+        )
+
+    @Test
+    fun test() {
+        screenshotRule.screenshotTest("mainSwitchPreference") {
+            Column {
+                MainSwitchPreference(
+                    object : SwitchPreferenceModel {
+                        override val title = "MainSwitchPreference"
+                        override val checked = stateOf(false)
+                        override val onCheckedChange = null
+                    })
+
+                MainSwitchPreference(object : SwitchPreferenceModel {
+                    override val title = "Not changeable"
+                    override val changeable = stateOf(false)
+                    override val checked = stateOf(true)
+                    override val onCheckedChange = null
+                })
+            }
+        }
+    }
+}
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/PreferenceScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/PreferenceScreenshotTest.kt
new file mode 100644
index 0000000..d72152c
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/PreferenceScreenshotTest.kt
@@ -0,0 +1,91 @@
+/*
+ * 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.settingslib.spa.screenshot
+
+import androidx.compose.foundation.layout.Column
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.outlined.Autorenew
+import androidx.compose.material.icons.outlined.DisabledByDefault
+import androidx.compose.runtime.Composable
+import com.android.settingslib.spa.framework.compose.toState
+import com.android.settingslib.spa.widget.preference.Preference
+import com.android.settingslib.spa.widget.preference.PreferenceModel
+import com.android.settingslib.spa.widget.ui.SettingsIcon
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.Parameterized
+import platform.test.screenshot.DeviceEmulationSpec
+
+/** A screenshot test for ExampleFeature. */
+@RunWith(Parameterized::class)
+class PreferenceScreenshotTest(emulationSpec: DeviceEmulationSpec) {
+    companion object {
+        @Parameterized.Parameters(name = "{0}")
+        @JvmStatic
+        fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
+        private const val TITLE = "Title"
+        private const val SUMMARY = "Summary"
+        private const val LONG_SUMMARY =
+            "Long long long long long long long long long long long long long long long summary"
+    }
+
+    @get:Rule
+    val screenshotRule =
+        SettingsScreenshotTestRule(
+            emulationSpec,
+            "frameworks/base/packages/SettingsLib/Spa/screenshot/assets"
+        )
+
+    @Test
+    fun test() {
+        screenshotRule.screenshotTest("preference") {
+            Column {
+                Preference(object : PreferenceModel {
+                    override val title = TITLE
+                })
+
+                Preference(object : PreferenceModel {
+                    override val title = TITLE
+                    override val summary = SUMMARY.toState()
+                })
+
+                Preference(object : PreferenceModel {
+                    override val title = TITLE
+                    override val summary = LONG_SUMMARY.toState()
+                })
+
+                Preference(object : PreferenceModel {
+                    override val title = TITLE
+                    override val summary = SUMMARY.toState()
+                    override val enabled = false.toState()
+                    override val icon = @Composable {
+                        SettingsIcon(imageVector = Icons.Outlined.DisabledByDefault)
+                    }
+                })
+
+                Preference(object : PreferenceModel {
+                    override val title = TITLE
+                    override val summary = SUMMARY.toState()
+                    override val icon = @Composable {
+                        SettingsIcon(imageVector = Icons.Outlined.Autorenew)
+                    }
+                })
+            }
+        }
+    }
+}
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/ProgressBarPreferenceScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/ProgressBarPreferenceScreenshotTest.kt
new file mode 100644
index 0000000..5fcaf85
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/ProgressBarPreferenceScreenshotTest.kt
@@ -0,0 +1,88 @@
+/*
+ * 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.settingslib.spa.screenshot
+
+import androidx.compose.foundation.layout.Column
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.outlined.Delete
+import androidx.compose.material.icons.outlined.SystemUpdate
+import androidx.compose.runtime.Composable
+import com.android.settingslib.spa.widget.preference.ProgressBarPreference
+import com.android.settingslib.spa.widget.preference.ProgressBarPreferenceModel
+import com.android.settingslib.spa.widget.preference.ProgressBarWithDataPreference
+import com.android.settingslib.spa.widget.ui.CircularProgressBar
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.Parameterized
+import platform.test.screenshot.DeviceEmulationSpec
+
+/** A screenshot test for ExampleFeature. */
+@RunWith(Parameterized::class)
+class ProgressBarPreferenceScreenshotTest(emulationSpec: DeviceEmulationSpec) {
+    companion object {
+        @Parameterized.Parameters(name = "{0}")
+        @JvmStatic
+        fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
+    }
+
+    @get:Rule
+    val screenshotRule =
+        SettingsScreenshotTestRule(
+            emulationSpec,
+            "frameworks/base/packages/SettingsLib/Spa/screenshot/assets"
+        )
+
+    @Test
+    fun test() {
+        screenshotRule.screenshotTest("progressBar") {
+            Column {
+                LargeProgressBar()
+                SimpleProgressBar()
+                ProgressBarWithData()
+                CircularProgressBar(progress = 0.8f, radius = 160f)
+            }
+        }
+    }
+}
+
+@Composable
+private fun LargeProgressBar() {
+    ProgressBarPreference(object : ProgressBarPreferenceModel {
+        override val title = "Large Progress Bar"
+        override val progress = 0.2f
+        override val height = 20f
+    })
+}
+
+@Composable
+private fun SimpleProgressBar() {
+    ProgressBarPreference(object : ProgressBarPreferenceModel {
+        override val title = "Simple Progress Bar"
+        override val progress = 0.2f
+        override val icon = Icons.Outlined.SystemUpdate
+    })
+}
+
+@Composable
+private fun ProgressBarWithData() {
+    ProgressBarWithDataPreference(model = object : ProgressBarPreferenceModel {
+        override val title = "Progress Bar with Data"
+        override val progress = 0.2f
+        override val icon = Icons.Outlined.Delete
+    }, data = "25G")
+}
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/SliderPreferenceScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/SliderPreferenceScreenshotTest.kt
new file mode 100644
index 0000000..48c922d
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/SliderPreferenceScreenshotTest.kt
@@ -0,0 +1,73 @@
+/*
+ * 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.settingslib.spa.screenshot
+
+import androidx.compose.foundation.layout.Column
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.outlined.AccessAlarm
+import com.android.settingslib.spa.widget.preference.SliderPreference
+import com.android.settingslib.spa.widget.preference.SliderPreferenceModel
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.Parameterized
+import platform.test.screenshot.DeviceEmulationSpec
+
+/** A screenshot test for ExampleFeature. */
+@RunWith(Parameterized::class)
+class SliderPreferenceScreenshotTest(emulationSpec: DeviceEmulationSpec) {
+    companion object {
+        @Parameterized.Parameters(name = "{0}")
+        @JvmStatic
+        fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
+    }
+
+    @get:Rule
+    val screenshotRule =
+        SettingsScreenshotTestRule(
+            emulationSpec,
+            "frameworks/base/packages/SettingsLib/Spa/screenshot/assets"
+        )
+
+    @Test
+    fun test() {
+        screenshotRule.screenshotTest("slider") {
+            Column {
+                SliderPreference(object : SliderPreferenceModel {
+                    override val title = "Simple Slider"
+                    override val initValue = 40
+                })
+
+                SliderPreference(object : SliderPreferenceModel {
+                    override val title = "Slider with icon"
+                    override val initValue = 30
+                    override val onValueChangeFinished = {
+                        println("onValueChangeFinished")
+                    }
+                    override val icon = Icons.Outlined.AccessAlarm
+                })
+
+                SliderPreference(object : SliderPreferenceModel {
+                    override val title = "Slider with steps"
+                    override val initValue = 2
+                    override val valueRange = 1..5
+                    override val showSteps = true
+                })
+            }
+        }
+    }
+}
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/SwitchPreferenceScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/SwitchPreferenceScreenshotTest.kt
new file mode 100644
index 0000000..2c84a8e
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/SwitchPreferenceScreenshotTest.kt
@@ -0,0 +1,102 @@
+/*
+ * 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.settingslib.spa.screenshot
+
+import androidx.compose.foundation.layout.Column
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.outlined.AirplanemodeActive
+import androidx.compose.runtime.Composable
+import com.android.settingslib.spa.framework.compose.stateOf
+import com.android.settingslib.spa.widget.preference.SwitchPreference
+import com.android.settingslib.spa.widget.preference.SwitchPreferenceModel
+import com.android.settingslib.spa.widget.ui.SettingsIcon
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.Parameterized
+import platform.test.screenshot.DeviceEmulationSpec
+
+/** A screenshot test for ExampleFeature. */
+@RunWith(Parameterized::class)
+class SwitchPreferenceScreenshotTest(emulationSpec: DeviceEmulationSpec) {
+    companion object {
+        @Parameterized.Parameters(name = "{0}")
+        @JvmStatic
+        fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
+    }
+
+    @get:Rule
+    val screenshotRule =
+        SettingsScreenshotTestRule(
+            emulationSpec,
+            "frameworks/base/packages/SettingsLib/Spa/screenshot/assets"
+        )
+
+    @Test
+    fun test() {
+        screenshotRule.screenshotTest("switchPreference") {
+            Column {
+                SampleSwitchPreference()
+                SampleSwitchPreferenceWithSummary()
+                SampleNotChangeableSwitchPreference()
+                SampleSwitchPreferenceWithIcon()
+            }
+        }
+    }
+}
+
+@Composable
+private fun SampleSwitchPreference() {
+    SwitchPreference(object : SwitchPreferenceModel {
+        override val title = "SwitchPreference"
+        override val checked = stateOf(false)
+        override val onCheckedChange = null
+    })
+}
+
+@Composable
+private fun SampleSwitchPreferenceWithSummary() {
+    SwitchPreference(object : SwitchPreferenceModel {
+        override val title = "SwitchPreference"
+        override val summary = stateOf("With summary")
+        override val checked = stateOf(true)
+        override val onCheckedChange = null
+    })
+}
+
+@Composable
+private fun SampleNotChangeableSwitchPreference() {
+    SwitchPreference(object : SwitchPreferenceModel {
+        override val title = "SwitchPreference"
+        override val summary = stateOf("Not changeable")
+        override val changeable = stateOf(false)
+        override val checked = stateOf(true)
+        override val onCheckedChange = null
+    })
+}
+
+@Composable
+private fun SampleSwitchPreferenceWithIcon() {
+    SwitchPreference(object : SwitchPreferenceModel {
+        override val title = "SwitchPreference"
+        override val checked = stateOf(true)
+        override val onCheckedChange = null
+        override val icon = @Composable {
+            SettingsIcon(imageVector = Icons.Outlined.AirplanemodeActive)
+        }
+    })
+}
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/TwoTargetSwitchPreferenceScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/TwoTargetSwitchPreferenceScreenshotTest.kt
new file mode 100644
index 0000000..2c37212
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/TwoTargetSwitchPreferenceScreenshotTest.kt
@@ -0,0 +1,71 @@
+/*
+ * 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.settingslib.spa.screenshot
+
+import androidx.compose.foundation.layout.Column
+import com.android.settingslib.spa.framework.compose.stateOf
+import com.android.settingslib.spa.widget.preference.TwoTargetSwitchPreference
+import com.android.settingslib.spa.widget.preference.SwitchPreferenceModel
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.Parameterized
+import platform.test.screenshot.DeviceEmulationSpec
+
+/** A screenshot test for ExampleFeature. */
+@RunWith(Parameterized::class)
+class TwoTargetSwitchPreferenceScreenshotTest(emulationSpec: DeviceEmulationSpec) {
+    companion object {
+        @Parameterized.Parameters(name = "{0}")
+        @JvmStatic
+        fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
+    }
+
+    @get:Rule
+    val screenshotRule =
+        SettingsScreenshotTestRule(
+            emulationSpec,
+            "frameworks/base/packages/SettingsLib/Spa/screenshot/assets"
+        )
+
+    @Test
+    fun test() {
+        screenshotRule.screenshotTest("twoTargetSwitchPreference") {
+            Column {
+                TwoTargetSwitchPreference(object : SwitchPreferenceModel {
+                    override val title = "TwoTargetSwitchPreference"
+                    override val checked = stateOf(false)
+                    override val onCheckedChange = null
+                }) {}
+
+                TwoTargetSwitchPreference(object : SwitchPreferenceModel {
+                    override val title = "TwoTargetSwitchPreference"
+                    override val summary = stateOf("With summary")
+                    override val checked = stateOf(true)
+                    override val onCheckedChange = null
+                }) {}
+
+                TwoTargetSwitchPreference(object : SwitchPreferenceModel {
+                    override val title = "Not changeable"
+                    override val changeable = stateOf(false)
+                    override val checked = stateOf(true)
+                    override val onCheckedChange = null
+                }) {}
+            }
+        }
+    }
+}
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/ui/FooterScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/ui/FooterScreenshotTest.kt
new file mode 100644
index 0000000..0a0faf6
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/ui/FooterScreenshotTest.kt
@@ -0,0 +1,48 @@
+/*
+ * 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.settingslib.spa.screenshot
+
+import com.android.settingslib.spa.widget.ui.Footer
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.Parameterized
+import platform.test.screenshot.DeviceEmulationSpec
+
+/** A screenshot test for ExampleFeature. */
+@RunWith(Parameterized::class)
+class FooterScreenshotTest(emulationSpec: DeviceEmulationSpec) {
+    companion object {
+        @Parameterized.Parameters(name = "{0}")
+        @JvmStatic
+        fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
+    }
+
+    @get:Rule
+    val screenshotRule =
+        SettingsScreenshotTestRule(
+            emulationSpec,
+            "frameworks/base/packages/SettingsLib/Spa/screenshot/assets"
+        )
+
+    @Test
+    fun test() {
+        screenshotRule.screenshotTest("footer") {
+            Footer(footerText = "Footer text always at the end of page.")
+        }
+    }
+}
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/ui/SpinnerScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/ui/SpinnerScreenshotTest.kt
new file mode 100644
index 0000000..e9b5b30
--- /dev/null
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/ui/SpinnerScreenshotTest.kt
@@ -0,0 +1,52 @@
+/*
+ * 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.settingslib.spa.screenshot
+
+import com.android.settingslib.spa.widget.ui.Spinner
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.Parameterized
+import platform.test.screenshot.DeviceEmulationSpec
+
+/** A screenshot test for ExampleFeature. */
+@RunWith(Parameterized::class)
+class SpinnerScreenshotTest(emulationSpec: DeviceEmulationSpec) {
+    companion object {
+        @Parameterized.Parameters(name = "{0}")
+        @JvmStatic
+        fun getTestSpecs() = DeviceEmulationSpec.PhoneAndTabletMinimal
+    }
+
+    @get:Rule
+    val screenshotRule =
+        SettingsScreenshotTestRule(
+            emulationSpec,
+            "frameworks/base/packages/SettingsLib/Spa/screenshot/assets"
+        )
+
+    @Test
+    fun test() {
+        screenshotRule.screenshotTest("spinner") {
+            Spinner(
+                options = (1..3).map { "Option $it" },
+                selectedIndex = 0,
+                setIndex = {},
+            )
+        }
+    }
+}
diff --git a/packages/SettingsLib/Spa/spa/Android.bp b/packages/SettingsLib/Spa/spa/Android.bp
index 3ea3b5c..40613ce 100644
--- a/packages/SettingsLib/Spa/spa/Android.bp
+++ b/packages/SettingsLib/Spa/spa/Android.bp
@@ -44,3 +44,9 @@
     ],
     min_sdk_version: "31",
 }
+
+// Expose the srcs to tests, so the tests can access the internal classes.
+filegroup {
+    name: "SpaLib_srcs",
+    srcs: ["src/**/*.kt"],
+}
diff --git a/packages/SettingsLib/Spa/spa/build.gradle b/packages/SettingsLib/Spa/spa/build.gradle
index 19963fb..85ac8ec 100644
--- a/packages/SettingsLib/Spa/spa/build.gradle
+++ b/packages/SettingsLib/Spa/spa/build.gradle
@@ -108,6 +108,17 @@
                     // Excludes files forked from Accompanist.
                     "com/android/settingslib/spa/framework/compose/DrawablePainter*",
                     "com/android/settingslib/spa/framework/compose/Pager*",
+
+                    // Excludes inline functions, which is not covered in Jacoco reports.
+                    "com/android/settingslib/spa/framework/util/Collections*",
+                    "com/android/settingslib/spa/framework/util/Flows*",
+
+                    // Excludes debug functions
+                    "com/android/settingslib/spa/framework/compose/TimeMeasurer*",
+
+                    // Excludes slice demo presenter & provider
+                    "com/android/settingslib/spa/slice/presenter/Demo*",
+                    "com/android/settingslib/spa/slice/provider/Demo*",
             ],
     )
     executionData.from = fileTree(dir: "$buildDir/outputs/code_coverage/debugAndroidTest/connected")
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/debug/DebugFormat.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/debug/DebugFormat.kt
index 5873635..6ecf9c3 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/debug/DebugFormat.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/debug/DebugFormat.kt
@@ -40,7 +40,7 @@
 }
 
 fun SettingsPage.debugArguments(): String {
-    val normArguments = parameter.normalize(arguments)
+    val normArguments = parameter.normalize(arguments, eraseRuntimeValues = true)
     if (normArguments == null || normArguments.isEmpty) return "[No arguments]"
     return normArguments.toString().removeRange(0, 6)
 }
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/debug/DebugLogger.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/debug/DebugLogger.kt
new file mode 100644
index 0000000..7d48336
--- /dev/null
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/debug/DebugLogger.kt
@@ -0,0 +1,34 @@
+/*
+ * 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.settingslib.spa.debug
+
+import android.os.Bundle
+import android.util.Log
+import com.android.settingslib.spa.framework.common.LogCategory
+import com.android.settingslib.spa.framework.common.LogEvent
+import com.android.settingslib.spa.framework.common.SpaLogger
+
+class DebugLogger : SpaLogger {
+    override fun message(tag: String, msg: String, category: LogCategory) {
+        Log.d("SpaMsg-$category", "[$tag] $msg")
+    }
+
+    override fun event(id: String, event: LogEvent, category: LogCategory, extraData: Bundle) {
+        val extraMsg = extraData.toString().removeRange(0, 6)
+        Log.d("SpaEvent-$category", "[$id] $event $extraMsg")
+    }
+}
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/debug/DebugProvider.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/debug/DebugProvider.kt
index 59ec985..838c0cf 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/debug/DebugProvider.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/debug/DebugProvider.kt
@@ -27,11 +27,7 @@
 import android.database.MatrixCursor
 import android.net.Uri
 import android.util.Log
-import com.android.settingslib.spa.framework.common.ColumnEnum
-import com.android.settingslib.spa.framework.common.QueryEnum
 import com.android.settingslib.spa.framework.common.SpaEnvironmentFactory
-import com.android.settingslib.spa.framework.common.addUri
-import com.android.settingslib.spa.framework.common.getColumns
 import com.android.settingslib.spa.framework.util.KEY_DESTINATION
 import com.android.settingslib.spa.framework.util.KEY_HIGHLIGHT_ENTRY
 import com.android.settingslib.spa.framework.util.KEY_SESSION_SOURCE_NAME
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/ProviderColumn.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/debug/ProviderColumn.kt
similarity index 60%
rename from packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/ProviderColumn.kt
rename to packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/debug/ProviderColumn.kt
index 61b46be..bb9a134 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/ProviderColumn.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/debug/ProviderColumn.kt
@@ -14,10 +14,9 @@
  * limitations under the License.
  */
 
-package com.android.settingslib.spa.framework.common
+package com.android.settingslib.spa.debug
 
 import android.content.UriMatcher
-import androidx.annotation.VisibleForTesting
 
 /**
  * Enum to define all column names in provider.
@@ -39,12 +38,6 @@
     ENTRY_INTENT_URI("entryIntent"),
     ENTRY_HIERARCHY_PATH("entryPath"),
     ENTRY_START_ADB("entryStartAdb"),
-
-    // Columns related to search
-    SEARCH_TITLE("searchTitle"),
-    SEARCH_KEYWORD("searchKw"),
-    SEARCH_PATH("searchPath"),
-    SEARCH_STATUS_DISABLED("searchDisabled"),
 }
 
 /**
@@ -89,54 +82,16 @@
             ColumnEnum.ENTRY_HIERARCHY_PATH,
         )
     ),
-
-    SEARCH_STATIC_DATA_QUERY(
-        "search_static", 301,
-        listOf(
-            ColumnEnum.ENTRY_ID,
-            ColumnEnum.ENTRY_INTENT_URI,
-            ColumnEnum.SEARCH_TITLE,
-            ColumnEnum.SEARCH_KEYWORD,
-            ColumnEnum.SEARCH_PATH,
-        )
-    ),
-    SEARCH_DYNAMIC_DATA_QUERY(
-        "search_dynamic", 302,
-        listOf(
-            ColumnEnum.ENTRY_ID,
-            ColumnEnum.ENTRY_INTENT_URI,
-            ColumnEnum.SEARCH_TITLE,
-            ColumnEnum.SEARCH_KEYWORD,
-            ColumnEnum.SEARCH_PATH,
-        )
-    ),
-    SEARCH_IMMUTABLE_STATUS_DATA_QUERY(
-        "search_immutable_status", 303,
-        listOf(
-            ColumnEnum.ENTRY_ID,
-            ColumnEnum.SEARCH_STATUS_DISABLED,
-        )
-    ),
-    SEARCH_MUTABLE_STATUS_DATA_QUERY(
-        "search_mutable_status", 304,
-        listOf(
-            ColumnEnum.ENTRY_ID,
-            ColumnEnum.SEARCH_STATUS_DISABLED,
-        )
-    ),
 }
 
-@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
-fun QueryEnum.getColumns(): Array<String> {
+internal fun QueryEnum.getColumns(): Array<String> {
     return columnNames.map { it.id }.toTypedArray()
 }
 
-@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
-fun QueryEnum.getIndex(name: ColumnEnum): Int {
+internal fun QueryEnum.getIndex(name: ColumnEnum): Int {
     return columnNames.indexOf(name)
 }
 
-@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
-fun QueryEnum.addUri(uriMatcher: UriMatcher, authority: String) {
+internal fun QueryEnum.addUri(uriMatcher: UriMatcher, authority: String) {
     uriMatcher.addURI(authority, queryPath, queryMatchCode)
 }
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SettingsEntry.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SettingsEntry.kt
index 702c075..0871304 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SettingsEntry.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SettingsEntry.kt
@@ -25,8 +25,8 @@
 import androidx.compose.runtime.remember
 import com.android.settingslib.spa.framework.compose.LocalNavController
 
-const val INJECT_ENTRY_NAME = "INJECT"
-const val ROOT_ENTRY_NAME = "ROOT"
+private const val INJECT_ENTRY_NAME = "INJECT"
+private const val ROOT_ENTRY_NAME = "ROOT"
 
 interface EntryData {
     val pageId: String?
@@ -35,6 +35,8 @@
         get() = null
     val isHighlighted: Boolean
         get() = false
+    val arguments: Bundle?
+        get() = null
 }
 
 val LocalEntryDataProvider =
@@ -121,11 +123,11 @@
     }
 
     private fun fullArgument(runtimeArguments: Bundle? = null): Bundle {
-        val arguments = Bundle()
-        if (owner.arguments != null) arguments.putAll(owner.arguments)
-        // Put runtime args later, which can override page args.
-        if (runtimeArguments != null) arguments.putAll(runtimeArguments)
-        return arguments
+        return Bundle().apply {
+            if (owner.arguments != null) putAll(owner.arguments)
+            // Put runtime args later, which can override page args.
+            if (runtimeArguments != null) putAll(runtimeArguments)
+        }
     }
 
     fun getStatusData(runtimeArguments: Bundle? = null): EntryStatusData? {
@@ -142,19 +144,21 @@
 
     @Composable
     fun UiLayout(runtimeArguments: Bundle? = null) {
-        CompositionLocalProvider(provideLocalEntryData()) {
-            uiLayoutImpl(fullArgument(runtimeArguments))
+        val arguments = remember { fullArgument(runtimeArguments) }
+        CompositionLocalProvider(provideLocalEntryData(arguments)) {
+            uiLayoutImpl(arguments)
         }
     }
 
     @Composable
-    fun provideLocalEntryData(): ProvidedValue<EntryData> {
+    private fun provideLocalEntryData(arguments: Bundle): ProvidedValue<EntryData> {
         val controller = LocalNavController.current
         return LocalEntryDataProvider provides remember {
             object : EntryData {
                 override val pageId = containerPage().id
                 override val entryId = id
                 override val isHighlighted = controller.highlightEntryId == id
+                override val arguments = arguments
             }
         }
     }
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SettingsPage.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SettingsPage.kt
index 7a39b73..2bfa2a4 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SettingsPage.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SettingsPage.kt
@@ -69,7 +69,7 @@
             parameter: List<NamedNavArgument> = emptyList(),
             arguments: Bundle? = null
         ): String {
-            val normArguments = parameter.normalize(arguments)
+            val normArguments = parameter.normalize(arguments, eraseRuntimeValues = true)
             return "$name:${normArguments?.toString()}".toHashId()
         }
     }
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SpaEnvironment.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SpaEnvironment.kt
index 6d0b810..f672ee0 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SpaEnvironment.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SpaEnvironment.kt
@@ -29,6 +29,10 @@
 object SpaEnvironmentFactory {
     private var spaEnvironment: SpaEnvironment? = null
 
+    fun reset() {
+        spaEnvironment = null
+    }
+
     fun reset(env: SpaEnvironment) {
         spaEnvironment = env
         Log.d(TAG, "reset")
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SpaLogger.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SpaLogger.kt
index 6ecb7fa..78df0f2 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SpaLogger.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SpaLogger.kt
@@ -17,7 +17,6 @@
 package com.android.settingslib.spa.framework.common
 
 import android.os.Bundle
-import android.util.Log
 
 // Defines the category of the log, for quick filter
 enum class LogCategory {
@@ -62,14 +61,3 @@
     ) {
     }
 }
-
-class LocalLogger : SpaLogger {
-    override fun message(tag: String, msg: String, category: LogCategory) {
-        Log.d("SpaMsg-$category", "[$tag] $msg")
-    }
-
-    override fun event(id: String, event: LogEvent, category: LogCategory, extraData: Bundle) {
-        val extraMsg = extraData.toString().removeRange(0, 6)
-        Log.d("SpaEvent-$category", "[$id] $event $extraMsg")
-    }
-}
\ No newline at end of file
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/theme/SettingsColors.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/theme/SettingsColors.kt
index fa17e08..d72ec26 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/theme/SettingsColors.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/theme/SettingsColors.kt
@@ -18,6 +18,7 @@
 
 import android.content.Context
 import android.os.Build
+import androidx.annotation.VisibleForTesting
 import androidx.compose.runtime.Composable
 import androidx.compose.runtime.remember
 import androidx.compose.runtime.staticCompositionLocalOf
@@ -64,7 +65,8 @@
  *
  * @param context The context required to get system resource data.
  */
-private fun dynamicLightColorScheme(context: Context): SettingsColorScheme {
+@VisibleForTesting
+internal fun dynamicLightColorScheme(context: Context): SettingsColorScheme {
     val tonalPalette = dynamicTonalPalette(context)
     return SettingsColorScheme(
         background = tonalPalette.neutral95,
@@ -90,7 +92,8 @@
  *
  * @param context The context required to get system resource data.
  */
-private fun dynamicDarkColorScheme(context: Context): SettingsColorScheme {
+@VisibleForTesting
+internal fun dynamicDarkColorScheme(context: Context): SettingsColorScheme {
     val tonalPalette = dynamicTonalPalette(context)
     return SettingsColorScheme(
         background = tonalPalette.neutral10,
@@ -107,7 +110,8 @@
     )
 }
 
-private fun darkColorScheme(): SettingsColorScheme {
+@VisibleForTesting
+internal fun darkColorScheme(): SettingsColorScheme {
     val tonalPalette = tonalPalette()
     return SettingsColorScheme(
         background = tonalPalette.neutral10,
@@ -124,7 +128,8 @@
     )
 }
 
-private fun lightColorScheme(): SettingsColorScheme {
+@VisibleForTesting
+internal fun lightColorScheme(): SettingsColorScheme {
     val tonalPalette = tonalPalette()
     return SettingsColorScheme(
         background = tonalPalette.neutral95,
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/util/EntryLogger.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/util/EntryLogger.kt
index 1c88187..8ff4368 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/util/EntryLogger.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/util/EntryLogger.kt
@@ -28,9 +28,12 @@
 @Composable
 fun logEntryEvent(): (event: LogEvent, extraData: Bundle) -> Unit {
     val entryId = LocalEntryDataProvider.current.entryId ?: return { _, _ -> }
+    val arguments = LocalEntryDataProvider.current.arguments
     return { event, extraData ->
         SpaEnvironmentFactory.instance.logger.event(
-            entryId, event, category = LogCategory.VIEW, extraData = extraData
+            entryId, event, category = LogCategory.VIEW, extraData = extraData.apply {
+                if (arguments != null) putAll(arguments)
+            }
         )
     }
 }
@@ -40,7 +43,7 @@
     if (onClick == null) return null
     val logEvent = logEntryEvent()
     return {
-        logEvent(LogEvent.ENTRY_CLICK, Bundle.EMPTY)
+        logEvent(LogEvent.ENTRY_CLICK, bundleOf())
         onClick()
     }
 }
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/util/PageLogger.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/util/PageLogger.kt
index a881254..271443e 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/util/PageLogger.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/util/PageLogger.kt
@@ -48,7 +48,10 @@
                     extraData = bundleOf(
                         LOG_DATA_DISPLAY_NAME to page.displayName,
                         LOG_DATA_SESSION_NAME to navController.sessionSourceName,
-                    )
+                    ).apply {
+                        val normArguments = parameter.normalize(arguments)
+                        if (normArguments != null) putAll(normArguments)
+                    }
                 )
             }
             if (event == Lifecycle.Event.ON_START) {
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/util/Parameter.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/util/Parameter.kt
index f10d3b0..be303f0 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/util/Parameter.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/util/Parameter.kt
@@ -47,12 +47,15 @@
     return argsArray.joinToString("") { arg -> "/$arg" }
 }
 
-fun List<NamedNavArgument>.normalize(arguments: Bundle? = null): Bundle? {
+fun List<NamedNavArgument>.normalize(
+    arguments: Bundle? = null,
+    eraseRuntimeValues: Boolean = false
+): Bundle? {
     if (this.isEmpty()) return null
     val normArgs = Bundle()
     for (navArg in this) {
         // Erase value of runtime parameters.
-        if (navArg.isRuntimeParam()) {
+        if (navArg.isRuntimeParam() && eraseRuntimeValues) {
             normArgs.putString(navArg.name, null)
             continue
         }
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/search/SpaSearchContract.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/search/SpaSearchContract.kt
index 2301f04..83dcd13 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/search/SpaSearchContract.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/search/SpaSearchContract.kt
@@ -33,6 +33,13 @@
 /** ContentProvider path for search mutable status */
 const val SEARCH_MUTABLE_STATUS = "search_mutable_status"
 
+/** ContentProvider path for search static row */
+const val SEARCH_STATIC_ROW = "search_static_row"
+
+/** ContentProvider path for search dynamic row */
+const val SEARCH_DYNAMIC_ROW = "search_dynamic_row"
+
+
 /** Enum to define all column names in provider. */
 enum class ColumnEnum(val id: String) {
     ENTRY_ID("entryId"),
@@ -76,6 +83,7 @@
             ColumnEnum.SEARCH_PATH,
             ColumnEnum.INTENT_TARGET_PACKAGE,
             ColumnEnum.INTENT_TARGET_CLASS,
+            ColumnEnum.INTENT_EXTRAS,
             ColumnEnum.SLICE_URI,
             ColumnEnum.LEGACY_KEY
         )
@@ -94,4 +102,34 @@
             ColumnEnum.ENTRY_DISABLED,
         )
     ),
+    SEARCH_STATIC_ROW_QUERY(
+        SEARCH_STATIC_ROW,
+        listOf(
+            ColumnEnum.ENTRY_ID,
+            ColumnEnum.SEARCH_TITLE,
+            ColumnEnum.SEARCH_KEYWORD,
+            ColumnEnum.SEARCH_PATH,
+            ColumnEnum.INTENT_TARGET_PACKAGE,
+            ColumnEnum.INTENT_TARGET_CLASS,
+            ColumnEnum.INTENT_EXTRAS,
+            ColumnEnum.SLICE_URI,
+            ColumnEnum.LEGACY_KEY,
+            ColumnEnum.ENTRY_DISABLED,
+        )
+    ),
+    SEARCH_DYNAMIC_ROW_QUERY(
+        SEARCH_DYNAMIC_ROW,
+        listOf(
+            ColumnEnum.ENTRY_ID,
+            ColumnEnum.SEARCH_TITLE,
+            ColumnEnum.SEARCH_KEYWORD,
+            ColumnEnum.SEARCH_PATH,
+            ColumnEnum.INTENT_TARGET_PACKAGE,
+            ColumnEnum.INTENT_TARGET_CLASS,
+            ColumnEnum.INTENT_EXTRAS,
+            ColumnEnum.SLICE_URI,
+            ColumnEnum.LEGACY_KEY,
+            ColumnEnum.ENTRY_DISABLED,
+        )
+    ),
 }
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/search/SpaSearchProvider.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/search/SpaSearchProvider.kt
index 21bc75a..057f13f 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/search/SpaSearchProvider.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/search/SpaSearchProvider.kt
@@ -28,7 +28,6 @@
 import android.os.Parcelable
 import android.util.Log
 import androidx.annotation.VisibleForTesting
-import com.android.settingslib.spa.framework.common.EntryStatusData
 import com.android.settingslib.spa.framework.common.SettingsEntry
 import com.android.settingslib.spa.framework.common.SpaEnvironmentFactory
 import com.android.settingslib.spa.framework.util.SESSION_SEARCH
@@ -49,6 +48,8 @@
  *   $ adb shell content query --uri content://<AuthorityPath>/search_dynamic_data
  *   $ adb shell content query --uri content://<AuthorityPath>/search_immutable_status
  *   $ adb shell content query --uri content://<AuthorityPath>/search_mutable_status
+ *   $ adb shell content query --uri content://<AuthorityPath>/search_static_row
+ *   $ adb shell content query --uri content://<AuthorityPath>/search_dynamic_row
  */
 class SpaSearchProvider : ContentProvider() {
     private val spaEnvironment get() = SpaEnvironmentFactory.instance
@@ -58,7 +59,9 @@
         SEARCH_STATIC_DATA to 301,
         SEARCH_DYNAMIC_DATA to 302,
         SEARCH_MUTABLE_STATUS to 303,
-        SEARCH_IMMUTABLE_STATUS to 304
+        SEARCH_IMMUTABLE_STATUS to 304,
+        SEARCH_STATIC_ROW to 305,
+        SEARCH_DYNAMIC_ROW to 306
     )
 
     override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?): Int {
@@ -114,6 +117,8 @@
                     querySearchMutableStatusData()
                 queryMatchCode[SEARCH_IMMUTABLE_STATUS] ->
                     querySearchImmutableStatusData()
+                queryMatchCode[SEARCH_STATIC_ROW] -> querySearchStaticRow()
+                queryMatchCode[SEARCH_DYNAMIC_ROW] -> querySearchDynamicRow()
                 else -> throw UnsupportedOperationException("Unknown Uri $uri")
             }
         } catch (e: UnsupportedOperationException) {
@@ -125,7 +130,7 @@
     }
 
     @VisibleForTesting
-    fun querySearchImmutableStatusData(): Cursor {
+    internal fun querySearchImmutableStatusData(): Cursor {
         val entryRepository by spaEnvironment.entryRepository
         val cursor = MatrixCursor(QueryEnum.SEARCH_IMMUTABLE_STATUS_DATA_QUERY.getColumns())
         for (entry in entryRepository.getAllEntries()) {
@@ -136,7 +141,7 @@
     }
 
     @VisibleForTesting
-    fun querySearchMutableStatusData(): Cursor {
+    internal fun querySearchMutableStatusData(): Cursor {
         val entryRepository by spaEnvironment.entryRepository
         val cursor = MatrixCursor(QueryEnum.SEARCH_MUTABLE_STATUS_DATA_QUERY.getColumns())
         for (entry in entryRepository.getAllEntries()) {
@@ -147,7 +152,7 @@
     }
 
     @VisibleForTesting
-    fun querySearchStaticData(): Cursor {
+    internal fun querySearchStaticData(): Cursor {
         val entryRepository by spaEnvironment.entryRepository
         val cursor = MatrixCursor(QueryEnum.SEARCH_STATIC_DATA_QUERY.getColumns())
         for (entry in entryRepository.getAllEntries()) {
@@ -158,7 +163,7 @@
     }
 
     @VisibleForTesting
-    fun querySearchDynamicData(): Cursor {
+    internal fun querySearchDynamicData(): Cursor {
         val entryRepository by spaEnvironment.entryRepository
         val cursor = MatrixCursor(QueryEnum.SEARCH_DYNAMIC_DATA_QUERY.getColumns())
         for (entry in entryRepository.getAllEntries()) {
@@ -168,6 +173,31 @@
         return cursor
     }
 
+    @VisibleForTesting
+    fun querySearchStaticRow(): Cursor {
+        val entryRepository by spaEnvironment.entryRepository
+        val cursor = MatrixCursor(QueryEnum.SEARCH_STATIC_ROW_QUERY.getColumns())
+        for (entry in entryRepository.getAllEntries()) {
+            if (!entry.isAllowSearch || entry.isSearchDataDynamic || entry.hasMutableStatus)
+                continue
+            fetchSearchRow(entry, cursor)
+        }
+        return cursor
+    }
+
+    @VisibleForTesting
+    fun querySearchDynamicRow(): Cursor {
+        val entryRepository by spaEnvironment.entryRepository
+        val cursor = MatrixCursor(QueryEnum.SEARCH_DYNAMIC_ROW_QUERY.getColumns())
+        for (entry in entryRepository.getAllEntries()) {
+            if (!entry.isAllowSearch || (!entry.isSearchDataDynamic && !entry.hasMutableStatus))
+                continue
+            fetchSearchRow(entry, cursor)
+        }
+        return cursor
+    }
+
+
     private fun fetchSearchData(entry: SettingsEntry, cursor: MatrixCursor) {
         val entryRepository by spaEnvironment.entryRepository
 
@@ -196,12 +226,42 @@
 
     private fun fetchStatusData(entry: SettingsEntry, cursor: MatrixCursor) {
         // Fetch status data. We can add runtime arguments later if necessary
-        val statusData = entry.getStatusData() ?: EntryStatusData()
+        val statusData = entry.getStatusData() ?: return
         cursor.newRow()
             .add(ColumnEnum.ENTRY_ID.id, entry.id)
             .add(ColumnEnum.ENTRY_DISABLED.id, statusData.isDisabled)
     }
 
+    private fun fetchSearchRow(entry: SettingsEntry, cursor: MatrixCursor) {
+        val entryRepository by spaEnvironment.entryRepository
+
+        // Fetch search data. We can add runtime arguments later if necessary
+        val searchData = entry.getSearchData() ?: return
+        val intent = entry.createIntent(SESSION_SEARCH)
+        val row = cursor.newRow().add(ColumnEnum.ENTRY_ID.id, entry.id)
+            .add(ColumnEnum.SEARCH_TITLE.id, searchData.title)
+            .add(ColumnEnum.SEARCH_KEYWORD.id, searchData.keyword)
+            .add(
+                ColumnEnum.SEARCH_PATH.id,
+                entryRepository.getEntryPathWithTitle(entry.id, searchData.title)
+            )
+        intent?.let {
+            row.add(ColumnEnum.INTENT_TARGET_PACKAGE.id, spaEnvironment.appContext.packageName)
+                .add(ColumnEnum.INTENT_TARGET_CLASS.id, spaEnvironment.browseActivityClass?.name)
+                .add(ColumnEnum.INTENT_EXTRAS.id, marshall(intent.extras))
+        }
+        if (entry.hasSliceSupport)
+            row.add(
+                ColumnEnum.SLICE_URI.id, Uri.Builder()
+                    .fromEntry(entry, spaEnvironment.sliceProviderAuthorities)
+            )
+        // TODO: support legacy key
+
+        // Fetch status data. We can add runtime arguments later if necessary
+        val statusData = entry.getStatusData() ?: return
+        row.add(ColumnEnum.ENTRY_DISABLED.id, statusData.isDisabled)
+    }
+
     private fun QueryEnum.getColumns(): Array<String> {
         return columnNames.map { it.id }.toTypedArray()
     }
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/slice/provider/Demo.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/slice/provider/Demo.kt
index b65b91f..e4a7386 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/slice/provider/Demo.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/slice/provider/Demo.kt
@@ -19,6 +19,7 @@
 import android.app.PendingIntent
 import android.content.Context
 import android.net.Uri
+import androidx.core.R
 import androidx.core.graphics.drawable.IconCompat
 import androidx.slice.Slice
 import androidx.slice.SliceManager
@@ -52,10 +53,7 @@
 private fun createSliceAction(context: Context, intent: PendingIntent): SliceAction {
     return SliceAction.create(
         intent,
-        IconCompat.createWithResource(
-            context,
-            com.google.android.material.R.drawable.navigation_empty_icon
-        ),
+        IconCompat.createWithResource(context, R.drawable.notification_action_background),
         ListBuilder.ICON_IMAGE,
         "Enter app"
     )
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/scaffold/CustomizedAppBar.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/scaffold/CustomizedAppBar.kt
index 7db1ca1..ae88ed7 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/scaffold/CustomizedAppBar.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/scaffold/CustomizedAppBar.kt
@@ -132,7 +132,10 @@
                     .asPaddingValues()
                     .horizontalValues()
             )
-            .padding(horizontal = SettingsDimension.itemPaddingAround),
+            .padding(
+                start = SettingsDimension.itemPaddingAround,
+                end = SettingsDimension.itemPaddingEnd,
+            ),
         overflow = TextOverflow.Ellipsis,
         maxLines = maxLines,
     )
diff --git a/packages/SettingsLib/Spa/tests/Android.bp b/packages/SettingsLib/Spa/tests/Android.bp
index 69740058..f9e64ae 100644
--- a/packages/SettingsLib/Spa/tests/Android.bp
+++ b/packages/SettingsLib/Spa/tests/Android.bp
@@ -22,7 +22,10 @@
     name: "SpaLibTests",
     test_suites: ["device-tests"],
 
-    srcs: ["src/**/*.kt"],
+    srcs: [
+        ":SpaLib_srcs",
+        "src/**/*.kt",
+    ],
 
     static_libs: [
         "SpaLib",
diff --git a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/framework/common/SettingsEntryTest.kt b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/framework/common/SettingsEntryTest.kt
index f98963c..b600ac6 100644
--- a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/framework/common/SettingsEntryTest.kt
+++ b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/framework/common/SettingsEntryTest.kt
@@ -16,10 +16,13 @@
 
 package com.android.settingslib.spa.framework.common
 
+import android.net.Uri
 import androidx.compose.runtime.Composable
 import androidx.compose.ui.test.junit4.createComposeRule
 import androidx.core.os.bundleOf
 import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settingslib.spa.slice.appendSpaParams
+import com.android.settingslib.spa.slice.getEntryId
 import com.android.settingslib.spa.tests.testutils.getUniqueEntryId
 import com.android.settingslib.spa.tests.testutils.getUniquePageId
 import com.google.common.truth.Truth.assertThat
@@ -27,8 +30,8 @@
 import org.junit.Test
 import org.junit.runner.RunWith
 
-const val INJECT_ENTRY_NAME = "INJECT"
-const val ROOT_ENTRY_NAME = "ROOT"
+const val INJECT_ENTRY_NAME_TEST = "INJECT"
+const val ROOT_ENTRY_NAME_TEST = "ROOT"
 
 class MacroForTest(private val pageId: String, private val entryId: String) : EntryMacro {
     @Composable
@@ -95,12 +98,12 @@
         val entryInject = SettingsEntryBuilder.createInject(owner).build()
         assertThat(entryInject.id).isEqualTo(
             getUniqueEntryId(
-                INJECT_ENTRY_NAME,
+                INJECT_ENTRY_NAME_TEST,
                 owner,
                 toPage = owner
             )
         )
-        assertThat(entryInject.displayName).isEqualTo("${INJECT_ENTRY_NAME}_mySpp")
+        assertThat(entryInject.displayName).isEqualTo("${INJECT_ENTRY_NAME_TEST}_mySpp")
         assertThat(entryInject.fromPage).isNull()
         assertThat(entryInject.toPage).isNotNull()
     }
@@ -111,7 +114,7 @@
         val entryInject = SettingsEntryBuilder.createRoot(owner, "myRootEntry").build()
         assertThat(entryInject.id).isEqualTo(
             getUniqueEntryId(
-                ROOT_ENTRY_NAME,
+                ROOT_ENTRY_NAME_TEST,
                 owner,
                 toPage = owner
             )
@@ -169,4 +172,25 @@
         assertThat(statusData?.isDisabled).isTrue()
         assertThat(statusData?.isSwitchOff).isTrue()
     }
+
+    @Test
+    fun testSetSliceDataFn() {
+        val owner = SettingsPage.create("mySpp")
+        val entryId = getUniqueEntryId("myEntry", owner)
+        val emptySliceData = EntrySliceData()
+
+        val entryBuilder = SettingsEntryBuilder.create(owner, "myEntry")
+            .setSliceDataFn { uri, _ ->
+                return@setSliceDataFn if (uri.getEntryId() == entryId) emptySliceData else null
+            }
+        val entry = entryBuilder.build()
+        assertThat(entry.id).isEqualTo(entryId)
+        assertThat(entry.hasSliceSupport).isTrue()
+        assertThat(entry.getSliceData(Uri.EMPTY)).isNull()
+        assertThat(
+            entry.getSliceData(
+                Uri.Builder().scheme("content").appendSpaParams(entryId = entryId).build()
+            )
+        ).isEqualTo(emptySliceData)
+    }
 }
diff --git a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/framework/common/SpaEnvironmentTest.kt b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/framework/common/SpaEnvironmentTest.kt
new file mode 100644
index 0000000..3b0e36b
--- /dev/null
+++ b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/framework/common/SpaEnvironmentTest.kt
@@ -0,0 +1,60 @@
+/*
+ * 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.settingslib.spa.framework.common
+
+import android.content.Context
+import androidx.compose.ui.test.junit4.createComposeRule
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settingslib.spa.tests.testutils.SpaEnvironmentForTest
+import com.google.common.truth.Truth
+import org.junit.Assert
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class SpaEnvironmentTest {
+    private val context: Context = ApplicationProvider.getApplicationContext()
+    private val spaEnvironment = SpaEnvironmentForTest(context)
+
+    @get:Rule
+    val composeTestRule = createComposeRule()
+
+    @Test
+    fun testSpaEnvironmentFactory() {
+        SpaEnvironmentFactory.reset()
+        Truth.assertThat(SpaEnvironmentFactory.isReady()).isFalse()
+        Assert.assertThrows(UnsupportedOperationException::class.java) {
+            SpaEnvironmentFactory.instance
+        }
+
+        SpaEnvironmentFactory.reset(spaEnvironment)
+        Truth.assertThat(SpaEnvironmentFactory.isReady()).isTrue()
+        Truth.assertThat(SpaEnvironmentFactory.instance).isEqualTo(spaEnvironment)
+    }
+
+    @Test
+    fun testSpaEnvironmentFactoryForPreview() {
+        SpaEnvironmentFactory.reset()
+        composeTestRule.setContent {
+            Truth.assertThat(SpaEnvironmentFactory.isReady()).isFalse()
+            SpaEnvironmentFactory.resetForPreview()
+            Truth.assertThat(SpaEnvironmentFactory.isReady()).isTrue()
+        }
+    }
+}
\ No newline at end of file
diff --git a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/framework/theme/SettingsColorsTest.kt b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/framework/theme/SettingsColorsTest.kt
new file mode 100644
index 0000000..5ea92ab
--- /dev/null
+++ b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/framework/theme/SettingsColorsTest.kt
@@ -0,0 +1,79 @@
+/*
+ * 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.settingslib.spa.framework.theme
+
+import android.content.Context
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+import org.junit.runner.RunWith
+import androidx.compose.ui.graphics.Color
+
+@RunWith(AndroidJUnit4::class)
+class SettingsColorsTest {
+    private val context: Context = ApplicationProvider.getApplicationContext()
+
+    @Test
+    fun testDynamicTheme() {
+        // The dynamic color could be different in different device, just check basic restrictions:
+        // 1. text color is different with background color
+        // 2. primary / spinner color is different with its on-item color
+        val ls = dynamicLightColorScheme(context)
+        assertThat(ls.categoryTitle).isNotEqualTo(ls.background)
+        assertThat(ls.secondaryText).isNotEqualTo(ls.background)
+        assertThat(ls.primaryContainer).isNotEqualTo(ls.onPrimaryContainer)
+        assertThat(ls.spinnerHeaderContainer).isNotEqualTo(ls.onSpinnerHeaderContainer)
+        assertThat(ls.spinnerItemContainer).isNotEqualTo(ls.onSpinnerItemContainer)
+
+        val ds = dynamicDarkColorScheme(context)
+        assertThat(ds.categoryTitle).isNotEqualTo(ds.background)
+        assertThat(ds.secondaryText).isNotEqualTo(ds.background)
+        assertThat(ds.primaryContainer).isNotEqualTo(ds.onPrimaryContainer)
+        assertThat(ds.spinnerHeaderContainer).isNotEqualTo(ds.onSpinnerHeaderContainer)
+        assertThat(ds.spinnerItemContainer).isNotEqualTo(ds.onSpinnerItemContainer)
+    }
+
+    @Test
+    fun testStaticTheme() {
+        val ls = lightColorScheme()
+        assertThat(ls.background).isEqualTo(Color(red = 244, green = 239, blue = 244))
+        assertThat(ls.categoryTitle).isEqualTo(Color(red = 103, green = 80, blue = 164))
+        assertThat(ls.surface).isEqualTo(Color(red = 255, green = 251, blue = 254))
+        assertThat(ls.surfaceHeader).isEqualTo(Color(red = 230, green = 225, blue = 229))
+        assertThat(ls.secondaryText).isEqualTo(Color(red = 73, green = 69, blue = 79))
+        assertThat(ls.primaryContainer).isEqualTo(Color(red = 234, green = 221, blue = 255))
+        assertThat(ls.onPrimaryContainer).isEqualTo(Color(red = 28, green = 27, blue = 31))
+        assertThat(ls.spinnerHeaderContainer).isEqualTo(Color(red = 234, green = 221, blue = 255))
+        assertThat(ls.onSpinnerHeaderContainer).isEqualTo(Color(red = 28, green = 27, blue = 31))
+        assertThat(ls.spinnerItemContainer).isEqualTo(Color(red = 232, green = 222, blue = 248))
+        assertThat(ls.onSpinnerItemContainer).isEqualTo(Color(red = 73, green = 69, blue = 79))
+
+        val ds = darkColorScheme()
+        assertThat(ds.background).isEqualTo(Color(red = 28, green = 27, blue = 31))
+        assertThat(ds.categoryTitle).isEqualTo(Color(red = 234, green = 221, blue = 255))
+        assertThat(ds.surface).isEqualTo(Color(red = 49, green = 48, blue = 51))
+        assertThat(ds.surfaceHeader).isEqualTo(Color(red = 72, green = 70, blue = 73))
+        assertThat(ds.secondaryText).isEqualTo(Color(red = 202, green = 196, blue = 208))
+        assertThat(ds.primaryContainer).isEqualTo(Color(red = 232, green = 222, blue = 248))
+        assertThat(ds.onPrimaryContainer).isEqualTo(Color(red = 28, green = 27, blue = 31))
+        assertThat(ds.spinnerHeaderContainer).isEqualTo(Color(red = 234, green = 221, blue = 255))
+        assertThat(ds.onSpinnerHeaderContainer).isEqualTo(Color(red = 28, green = 27, blue = 31))
+        assertThat(ds.spinnerItemContainer).isEqualTo(Color(red = 232, green = 222, blue = 248))
+        assertThat(ds.onSpinnerItemContainer).isEqualTo(Color(red = 73, green = 69, blue = 79))
+    }
+}
diff --git a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/framework/util/CollectionsTest.kt b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/framework/util/CollectionsTest.kt
new file mode 100644
index 0000000..62f4707
--- /dev/null
+++ b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/framework/util/CollectionsTest.kt
@@ -0,0 +1,47 @@
+/*
+ * 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.settingslib.spa.framework.util
+
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.google.common.truth.Truth
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.runTest
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@OptIn(ExperimentalCoroutinesApi::class)
+@RunWith(AndroidJUnit4::class)
+class CollectionsTest {
+    @Test
+    fun testAsyncForEach() = runTest {
+        var sum = 0
+        listOf(1, 2, 3).asyncForEach { sum += it }
+        Truth.assertThat(sum).isEqualTo(6)
+    }
+
+    @Test
+    fun testAsyncFilter() = runTest {
+        val res = listOf(1, 2, 3).asyncFilter { it >= 2 }
+        Truth.assertThat(res).containsExactly(2, 3).inOrder()
+    }
+
+    @Test
+    fun testAsyncMap() = runTest {
+        val res = listOf(1, 2, 3).asyncMap { it + 1 }
+        Truth.assertThat(res).containsExactly(2, 3, 4).inOrder()
+    }
+}
diff --git a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/framework/util/ParameterTest.kt b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/framework/util/ParameterTest.kt
index 48ebd8d..0aa846c 100644
--- a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/framework/util/ParameterTest.kt
+++ b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/framework/util/ParameterTest.kt
@@ -88,7 +88,7 @@
         val emptyParam = navArguments.normalize()
         assertThat(emptyParam).isNotNull()
         assertThat(emptyParam.toString()).isEqualTo(
-            "Bundle[{rt_param=null, unset_string_param=null, unset_int_param=null}]"
+            "Bundle[{unset_rt_param=null, unset_string_param=null, unset_int_param=null}]"
         )
 
         val setPartialParam = navArguments.normalize(
@@ -99,7 +99,7 @@
         )
         assertThat(setPartialParam).isNotNull()
         assertThat(setPartialParam.toString()).isEqualTo(
-            "Bundle[{rt_param=null, string_param=myStr, unset_int_param=null}]"
+            "Bundle[{rt_param=rtStr, string_param=myStr, unset_int_param=null}]"
         )
 
         val setAllParam = navArguments.normalize(
@@ -107,7 +107,8 @@
                 "string_param" to "myStr",
                 "int_param" to 10,
                 "rt_param" to "rtStr",
-            )
+            ),
+            eraseRuntimeValues = true
         )
         assertThat(setAllParam).isNotNull()
         assertThat(setAllParam.toString()).isEqualTo(
diff --git a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/search/SpaSearchProviderTest.kt b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/search/SpaSearchProviderTest.kt
index 831aded..007d08b 100644
--- a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/search/SpaSearchProviderTest.kt
+++ b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/search/SpaSearchProviderTest.kt
@@ -41,27 +41,25 @@
     private val pageOwner = spaEnvironment.createPage("SppForSearch")
 
     @Test
+    fun testQueryColumnSetup() {
+        Truth.assertThat(QueryEnum.SEARCH_STATIC_DATA_QUERY.columnNames)
+            .containsExactlyElementsIn(QueryEnum.SEARCH_DYNAMIC_DATA_QUERY.columnNames)
+        Truth.assertThat(QueryEnum.SEARCH_MUTABLE_STATUS_DATA_QUERY.columnNames)
+            .containsExactlyElementsIn(QueryEnum.SEARCH_IMMUTABLE_STATUS_DATA_QUERY.columnNames)
+        Truth.assertThat(QueryEnum.SEARCH_STATIC_ROW_QUERY.columnNames)
+            .containsExactlyElementsIn(QueryEnum.SEARCH_DYNAMIC_ROW_QUERY.columnNames)
+    }
+
+    @Test
     fun testQuerySearchStatusData() {
         SpaEnvironmentFactory.reset(spaEnvironment)
 
         val immutableStatus = searchProvider.querySearchImmutableStatusData()
-        Truth.assertThat(immutableStatus.count).isEqualTo(2)
+        Truth.assertThat(immutableStatus.count).isEqualTo(1)
         immutableStatus.moveToFirst()
         immutableStatus.checkValue(
             QueryEnum.SEARCH_IMMUTABLE_STATUS_DATA_QUERY,
             ColumnEnum.ENTRY_ID,
-            pageOwner.getEntryId("SearchStaticWithNoStatus")
-        )
-        immutableStatus.checkValue(
-            QueryEnum.SEARCH_IMMUTABLE_STATUS_DATA_QUERY,
-            ColumnEnum.ENTRY_DISABLED,
-            false.toString()
-        )
-
-        immutableStatus.moveToNext()
-        immutableStatus.checkValue(
-            QueryEnum.SEARCH_IMMUTABLE_STATUS_DATA_QUERY,
-            ColumnEnum.ENTRY_ID,
             pageOwner.getEntryId("SearchDynamicWithImmutableStatus")
         )
         immutableStatus.checkValue(
@@ -163,6 +161,97 @@
             listOf("kw1", "kw2").toString()
         )
     }
+
+    @Test
+    fun testQuerySearchIndexRow() {
+        SpaEnvironmentFactory.reset(spaEnvironment)
+
+        val staticRow = searchProvider.querySearchStaticRow()
+        Truth.assertThat(staticRow.count).isEqualTo(1)
+        staticRow.moveToFirst()
+        staticRow.checkValue(
+            QueryEnum.SEARCH_STATIC_ROW_QUERY,
+            ColumnEnum.ENTRY_ID,
+            pageOwner.getEntryId("SearchStaticWithNoStatus")
+        )
+        staticRow.checkValue(
+            QueryEnum.SEARCH_STATIC_ROW_QUERY, ColumnEnum.SEARCH_TITLE, "SearchStaticWithNoStatus"
+        )
+        staticRow.checkValue(
+            QueryEnum.SEARCH_STATIC_ROW_QUERY, ColumnEnum.SEARCH_KEYWORD, listOf("").toString()
+        )
+        staticRow.checkValue(
+            QueryEnum.SEARCH_STATIC_ROW_QUERY,
+            ColumnEnum.SEARCH_PATH,
+            listOf("SearchStaticWithNoStatus", "SppForSearch").toString()
+        )
+        staticRow.checkValue(
+            QueryEnum.SEARCH_STATIC_ROW_QUERY,
+            ColumnEnum.INTENT_TARGET_PACKAGE,
+            spaEnvironment.appContext.packageName
+        )
+        staticRow.checkValue(
+            QueryEnum.SEARCH_STATIC_ROW_QUERY,
+            ColumnEnum.INTENT_TARGET_CLASS,
+            "com.android.settingslib.spa.tests.testutils.BlankActivity"
+        )
+
+        // Check extras in intent
+        val bundle =
+            staticRow.getExtras(QueryEnum.SEARCH_STATIC_ROW_QUERY, ColumnEnum.INTENT_EXTRAS)
+        Truth.assertThat(bundle).isNotNull()
+        Truth.assertThat(bundle!!.size()).isEqualTo(3)
+        Truth.assertThat(bundle.getString("spaActivityDestination")).isEqualTo("SppForSearch")
+        Truth.assertThat(bundle.getString("highlightEntry"))
+            .isEqualTo(pageOwner.getEntryId("SearchStaticWithNoStatus"))
+        Truth.assertThat(bundle.getString("sessionSource")).isEqualTo("search")
+
+        Truth.assertThat(
+            staticRow.getString(
+                QueryEnum.SEARCH_STATIC_ROW_QUERY.columnNames.indexOf(
+                    ColumnEnum.ENTRY_DISABLED
+                )
+            )
+        ).isNull()
+
+        val dynamicRow = searchProvider.querySearchDynamicRow()
+        Truth.assertThat(dynamicRow.count).isEqualTo(3)
+        dynamicRow.moveToFirst()
+        dynamicRow.checkValue(
+            QueryEnum.SEARCH_DYNAMIC_ROW_QUERY,
+            ColumnEnum.ENTRY_ID,
+            pageOwner.getEntryId("SearchStaticWithMutableStatus")
+        )
+        dynamicRow.checkValue(
+            QueryEnum.SEARCH_DYNAMIC_ROW_QUERY, ColumnEnum.ENTRY_DISABLED, false.toString()
+        )
+
+        dynamicRow.moveToNext()
+        dynamicRow.checkValue(
+            QueryEnum.SEARCH_DYNAMIC_ROW_QUERY,
+            ColumnEnum.ENTRY_ID,
+            pageOwner.getEntryId("SearchDynamicWithMutableStatus")
+        )
+        dynamicRow.checkValue(
+            QueryEnum.SEARCH_DYNAMIC_ROW_QUERY, ColumnEnum.ENTRY_DISABLED, true.toString()
+        )
+
+
+        dynamicRow.moveToNext()
+        dynamicRow.checkValue(
+            QueryEnum.SEARCH_DYNAMIC_ROW_QUERY,
+            ColumnEnum.ENTRY_ID,
+            pageOwner.getEntryId("SearchDynamicWithImmutableStatus")
+        )
+        dynamicRow.checkValue(
+            QueryEnum.SEARCH_DYNAMIC_ROW_QUERY,
+            ColumnEnum.SEARCH_KEYWORD,
+            listOf("kw1", "kw2").toString()
+        )
+        dynamicRow.checkValue(
+            QueryEnum.SEARCH_DYNAMIC_ROW_QUERY, ColumnEnum.ENTRY_DISABLED, true.toString()
+        )
+    }
 }
 
 private fun Cursor.checkValue(query: QueryEnum, column: ColumnEnum, value: String) {
diff --git a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/tests/testutils/UniqueIdHelper.kt b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/tests/testutils/UniqueIdHelper.kt
index 7e51fea..ce9b791 100644
--- a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/tests/testutils/UniqueIdHelper.kt
+++ b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/tests/testutils/UniqueIdHelper.kt
@@ -27,7 +27,7 @@
     parameter: List<NamedNavArgument> = emptyList(),
     arguments: Bundle? = null
 ): String {
-    val normArguments = parameter.normalize(arguments)
+    val normArguments = parameter.normalize(arguments, eraseRuntimeValues = true)
     return "$name:${normArguments?.toString()}".toHashId()
 }
 
diff --git a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/ProgressBarPreferenceTest.kt b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/ProgressBarPreferenceTest.kt
index 5611f8c..2140c07 100644
--- a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/ProgressBarPreferenceTest.kt
+++ b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/ProgressBarPreferenceTest.kt
@@ -16,6 +16,9 @@
 
 package com.android.settingslib.spa.widget.preference
 
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.outlined.Launch
+import androidx.compose.ui.graphics.vector.ImageVector
 import androidx.compose.ui.semantics.ProgressBarRangeInfo
 import androidx.compose.ui.semantics.SemanticsProperties.ProgressBarRangeInfo
 import androidx.compose.ui.test.SemanticsMatcher
@@ -49,6 +52,7 @@
             ProgressBarWithDataPreference(model = object : ProgressBarPreferenceModel {
                 override val title = "Title"
                 override val progress = 0.2f
+                override val icon: ImageVector = Icons.Outlined.Launch
             }, data = "Data")
         }
         composeTestRule.onNodeWithText("Title").assertIsDisplayed()
diff --git a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/ui/ProgressBarTest.kt b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/ui/ProgressBarTest.kt
new file mode 100644
index 0000000..072c2cc
--- /dev/null
+++ b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/ui/ProgressBarTest.kt
@@ -0,0 +1,49 @@
+/*
+ * 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.settingslib.spa.widget.ui
+
+import androidx.compose.ui.semantics.ProgressBarRangeInfo
+import androidx.compose.ui.semantics.SemanticsProperties
+import androidx.compose.ui.test.SemanticsMatcher
+import androidx.compose.ui.test.assertIsDisplayed
+import androidx.compose.ui.test.junit4.createComposeRule
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class ProgressBarTest {
+    @get:Rule
+    val composeTestRule = createComposeRule()
+
+    @Test
+    fun testProgressBar() {
+        composeTestRule.setContent {
+            LinearProgressBar(progress = .5f)
+            CircularProgressBar(progress = .2f)
+        }
+
+        fun progressEqualsTo(progress: Float): SemanticsMatcher =
+            SemanticsMatcher.expectValue(
+                SemanticsProperties.ProgressBarRangeInfo,
+                ProgressBarRangeInfo(progress, 0f..1f, 0)
+            )
+        composeTestRule.onNode(progressEqualsTo(0.5f)).assertIsDisplayed()
+        composeTestRule.onNode(progressEqualsTo(0.2f)).assertIsDisplayed()
+    }
+}
diff --git a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/ui/TextTest.kt b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/ui/TextTest.kt
new file mode 100644
index 0000000..7e5b4f8
--- /dev/null
+++ b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/ui/TextTest.kt
@@ -0,0 +1,44 @@
+/*
+ * 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.settingslib.spa.widget.ui
+
+import androidx.compose.ui.test.assertIsDisplayed
+import androidx.compose.ui.test.junit4.createComposeRule
+import androidx.compose.ui.test.onNodeWithText
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settingslib.spa.framework.compose.toState
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class TextTest {
+    @get:Rule
+    val composeTestRule = createComposeRule()
+
+    @Test
+    fun testTitle() {
+        composeTestRule.setContent {
+            SettingsTitle(title = "myTitleValue")
+            SettingsTitle(title = "myTitleState".toState())
+            PlaceholderTitle(title = "myTitlePlaceholder")
+        }
+        composeTestRule.onNodeWithText("myTitleState").assertIsDisplayed()
+        composeTestRule.onNodeWithText("myTitleValue").assertIsDisplayed()
+        composeTestRule.onNodeWithText("myTitlePlaceholder").assertIsDisplayed()
+    }
+}
diff --git a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppInfoPage.kt b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppInfoPage.kt
index 5ae5ada..62db7bd 100644
--- a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppInfoPage.kt
+++ b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppInfoPage.kt
@@ -93,7 +93,7 @@
         ) {
             val context = LocalContext.current
             val internalListModel = remember {
-                TogglePermissionInternalAppListModel(context, listModel)
+                TogglePermissionInternalAppListModel(context, listModel, ::RestrictionsProviderImpl)
             }
             val record = remember { listModel.transformItem(app) }
             if (!remember { listModel.isChangeable(record) }) return
diff --git a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPage.kt b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPage.kt
index 00eb607..f65e310 100644
--- a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPage.kt
+++ b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPage.kt
@@ -42,6 +42,7 @@
 import com.android.settingslib.spaprivileged.model.app.AppRecord
 import com.android.settingslib.spaprivileged.model.app.userId
 import com.android.settingslib.spaprivileged.model.enterprise.Restrictions
+import com.android.settingslib.spaprivileged.model.enterprise.RestrictionsProviderFactory
 import com.android.settingslib.spaprivileged.model.enterprise.RestrictionsProviderImpl
 import com.android.settingslib.spaprivileged.template.preference.RestrictedSwitchPreference
 import kotlinx.coroutines.flow.Flow
@@ -64,41 +65,18 @@
         val permissionType = parameter.getStringArg(PERMISSION, arguments)!!
         val appListPage = SettingsPage.create(name, parameter = parameter, arguments = arguments)
         val appInfoPage = TogglePermissionAppInfoPageProvider.buildPageData(permissionType)
-        val entryList = mutableListOf<SettingsEntry>()
         // TODO: add more categories, such as personal, work, cloned, etc.
-        for (category in listOf("personal")) {
-            entryList.add(
-                SettingsEntryBuilder.createLinkFrom("${ENTRY_NAME}_$category", appListPage)
-                    .setLink(toPage = appInfoPage)
-                    .build()
-            )
+        return listOf("personal").map { category ->
+            SettingsEntryBuilder.createLinkFrom("${ENTRY_NAME}_$category", appListPage)
+                .setLink(toPage = appInfoPage)
+                .build()
         }
-        return entryList
     }
 
     @Composable
     override fun Page(arguments: Bundle?) {
-        TogglePermissionAppList(arguments?.getString(PERMISSION)!!)
-    }
-
-    @Composable
-    private fun TogglePermissionAppList(permissionType: String) {
-        val listModel = appListTemplate.rememberModel(permissionType)
-        val context = LocalContext.current
-        val internalListModel = remember {
-            TogglePermissionInternalAppListModel(context, listModel)
-        }
-        AppListPage(
-            title = stringResource(listModel.pageTitleResId),
-            listModel = internalListModel,
-        ) {
-            AppListItem(
-                onClick = TogglePermissionAppInfoPageProvider.navigator(
-                    permissionType = permissionType,
-                    app = record.app,
-                ),
-            )
-        }
+        val permissionType = arguments?.getString(PERMISSION)!!
+        appListTemplate.rememberModel(permissionType).TogglePermissionAppList(permissionType)
     }
 
     companion object {
@@ -132,9 +110,34 @@
     }
 }
 
+@Composable
+internal fun <T : AppRecord> TogglePermissionAppListModel<T>.TogglePermissionAppList(
+    permissionType: String,
+    restrictionsProviderFactory: RestrictionsProviderFactory = ::RestrictionsProviderImpl,
+    appList: @Composable AppListInput<T>.() -> Unit = { AppList() },
+) {
+    val context = LocalContext.current
+    val internalListModel = remember {
+        TogglePermissionInternalAppListModel(context, this, restrictionsProviderFactory)
+    }
+    AppListPage(
+        title = stringResource(pageTitleResId),
+        listModel = internalListModel,
+        appList = appList,
+    ) {
+        AppListItem(
+            onClick = TogglePermissionAppInfoPageProvider.navigator(
+                permissionType = permissionType,
+                app = record.app,
+            ),
+        )
+    }
+}
+
 internal class TogglePermissionInternalAppListModel<T : AppRecord>(
     private val context: Context,
     private val listModel: TogglePermissionAppListModel<T>,
+    private val restrictionsProviderFactory: RestrictionsProviderFactory,
 ) : AppListModel<T> {
     override fun transform(userIdFlow: Flow<Int>, appListFlow: Flow<List<ApplicationInfo>>) =
         listModel.transform(userIdFlow, appListFlow)
@@ -147,12 +150,12 @@
 
     @Composable
     fun getSummary(record: T): State<String> {
-        val restrictionsProvider = remember {
+        val restrictionsProvider = remember(record.app.userId) {
             val restrictions = Restrictions(
                 userId = record.app.userId,
                 keys = listModel.switchRestrictionKeys,
             )
-            RestrictionsProviderImpl(context, restrictions)
+            restrictionsProviderFactory(context, restrictions)
         }
         val restrictedMode = restrictionsProvider.restrictedModeState()
         val allowed = listModel.isAllowed(record)
diff --git a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/scaffold/RestrictedMenuItem.kt b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/scaffold/RestrictedMenuItem.kt
index 8c1421a..86b6f02 100644
--- a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/scaffold/RestrictedMenuItem.kt
+++ b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/scaffold/RestrictedMenuItem.kt
@@ -16,7 +16,6 @@
 
 package com.android.settingslib.spaprivileged.template.scaffold
 
-import android.content.Context
 import androidx.compose.runtime.Composable
 import androidx.compose.runtime.remember
 import androidx.compose.ui.platform.LocalContext
@@ -24,7 +23,7 @@
 import com.android.settingslib.spaprivileged.model.enterprise.BaseUserRestricted
 import com.android.settingslib.spaprivileged.model.enterprise.BlockedByAdmin
 import com.android.settingslib.spaprivileged.model.enterprise.Restrictions
-import com.android.settingslib.spaprivileged.model.enterprise.RestrictionsProvider
+import com.android.settingslib.spaprivileged.model.enterprise.RestrictionsProviderFactory
 import com.android.settingslib.spaprivileged.model.enterprise.RestrictionsProviderImpl
 
 @Composable
@@ -41,7 +40,7 @@
     text: String,
     restrictions: Restrictions,
     onClick: () -> Unit,
-    restrictionsProviderFactory: (Context, Restrictions) -> RestrictionsProvider,
+    restrictionsProviderFactory: RestrictionsProviderFactory,
 ) {
     val context = LocalContext.current
     val restrictionsProvider = remember(restrictions) {
diff --git a/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPageTest.kt b/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPageTest.kt
index 355dfb6..75b884c 100644
--- a/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPageTest.kt
+++ b/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPageTest.kt
@@ -17,14 +17,22 @@
 package com.android.settingslib.spaprivileged.template.app
 
 import android.content.Context
+import android.content.pm.ApplicationInfo
 import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.runtime.State
 import androidx.compose.ui.platform.LocalContext
 import androidx.compose.ui.test.assertIsDisplayed
 import androidx.compose.ui.test.junit4.createComposeRule
 import androidx.compose.ui.test.onNodeWithText
+import androidx.compose.ui.test.performClick
 import androidx.test.core.app.ApplicationProvider
 import androidx.test.ext.junit.runners.AndroidJUnit4
-import com.android.settingslib.spaprivileged.test.R
+import com.android.settingslib.spa.framework.compose.stateOf
+import com.android.settingslib.spa.testutils.FakeNavControllerWrapper
+import com.android.settingslib.spaprivileged.R
+import com.android.settingslib.spaprivileged.model.enterprise.NoRestricted
+import com.android.settingslib.spaprivileged.tests.testutils.FakeRestrictionsProvider
+import com.android.settingslib.spaprivileged.tests.testutils.TestAppRecord
 import com.android.settingslib.spaprivileged.tests.testutils.TestTogglePermissionAppListModel
 import com.google.common.truth.Truth.assertThat
 import org.junit.Rule
@@ -38,10 +46,97 @@
 
     private val context: Context = ApplicationProvider.getApplicationContext()
 
+    private val fakeNavControllerWrapper = FakeNavControllerWrapper()
+
+    private val fakeRestrictionsProvider = FakeRestrictionsProvider()
+
     @Test
-    fun appListInjectEntry_titleDisplayed() {
+    fun internalAppListModel_whenAllowed() {
+        fakeRestrictionsProvider.restrictedMode = NoRestricted
+        val listModel = TestTogglePermissionAppListModel(isAllowed = true)
+        val internalAppListModel = TogglePermissionInternalAppListModel(
+            context = context,
+            listModel = listModel,
+            restrictionsProviderFactory = { _, _ -> fakeRestrictionsProvider },
+        )
+
+        val summaryState = getSummary(internalAppListModel)
+
+        assertThat(summaryState.value).isEqualTo(
+            context.getString(R.string.app_permission_summary_allowed)
+        )
+    }
+
+    @Test
+    fun internalAppListModel_whenNotAllowed() {
+        fakeRestrictionsProvider.restrictedMode = NoRestricted
+        val listModel = TestTogglePermissionAppListModel(isAllowed = false)
+        val internalAppListModel = TogglePermissionInternalAppListModel(
+            context = context,
+            listModel = listModel,
+            restrictionsProviderFactory = { _, _ -> fakeRestrictionsProvider },
+        )
+
+        val summaryState = getSummary(internalAppListModel)
+
+        assertThat(summaryState.value).isEqualTo(
+            context.getString(R.string.app_permission_summary_not_allowed)
+        )
+    }
+
+    @Test
+    fun internalAppListModel_whenComputingAllowed() {
+        fakeRestrictionsProvider.restrictedMode = NoRestricted
+        val listModel = TestTogglePermissionAppListModel(isAllowed = null)
+        val internalAppListModel = TogglePermissionInternalAppListModel(
+            context = context,
+            listModel = listModel,
+            restrictionsProviderFactory = { _, _ -> fakeRestrictionsProvider },
+        )
+
+        val summaryState = getSummary(internalAppListModel)
+
+        assertThat(summaryState.value).isEqualTo(
+            context.getString(R.string.summary_placeholder)
+        )
+    }
+
+    @Test
+    fun appListItem_onClick_navigate() {
+        val listModel = TestTogglePermissionAppListModel()
+        composeTestRule.setContent {
+            listModel.TogglePermissionAppList(
+                permissionType = PERMISSION_TYPE,
+                restrictionsProviderFactory = { _, _ -> fakeRestrictionsProvider },
+            ) {
+                fakeNavControllerWrapper.Wrapper {
+                    AppListItemModel(
+                        record = listModel.transformItem(APP),
+                        label = LABEL,
+                        summary = stateOf(SUMMARY),
+                    ).appItem()
+                }
+            }
+        }
+
+        composeTestRule.onNodeWithText(LABEL).performClick()
+
+        assertThat(fakeNavControllerWrapper.navigateCalledWith)
+            .isEqualTo("TogglePermissionAppInfoPage/test.PERMISSION/package.name/0")
+    }
+
+    @Test
+    fun getRoute() {
+        val route = TogglePermissionAppListPageProvider.getRoute(PERMISSION_TYPE)
+
+        assertThat(route).isEqualTo("TogglePermissionAppList/test.PERMISSION")
+    }
+
+    @Test
+    fun buildInjectEntry_titleDisplayed() {
+        val listModel = TestTogglePermissionAppListModel()
         val entry = TogglePermissionAppListPageProvider.buildInjectEntry(PERMISSION_TYPE) {
-            TestTogglePermissionAppListModel()
+            listModel
         }.build()
 
         composeTestRule.setContent {
@@ -50,18 +145,27 @@
             }
         }
 
-        composeTestRule.onNodeWithText(context.getString(R.string.test_permission_title))
+        composeTestRule.onNodeWithText(context.getString(listModel.pageTitleResId))
             .assertIsDisplayed()
     }
 
-    @Test
-    fun appListRoute() {
-        val route = TogglePermissionAppListPageProvider.getRoute(PERMISSION_TYPE)
-
-        assertThat(route).isEqualTo("TogglePermissionAppList/test.PERMISSION")
+    private fun getSummary(
+        internalAppListModel: TogglePermissionInternalAppListModel<TestAppRecord>,
+    ): State<String> {
+        lateinit var summary: State<String>
+        composeTestRule.setContent {
+            summary = internalAppListModel.getSummary(record = TestAppRecord(APP))
+        }
+        return summary
     }
 
     private companion object {
         const val PERMISSION_TYPE = "test.PERMISSION"
+        const val PACKAGE_NAME = "package.name"
+        const val LABEL = "Label"
+        const val SUMMARY = "Summary"
+        val APP = ApplicationInfo().apply {
+            packageName = PACKAGE_NAME
+        }
     }
 }
diff --git a/packages/SettingsLib/res/values-af/strings.xml b/packages/SettingsLib/res/values-af/strings.xml
index 0234330..fb46dfb 100644
--- a/packages/SettingsLib/res/values-af/strings.xml
+++ b/packages/SettingsLib/res/values-af/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> oor tot vol"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> oor tot vol"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> – Laaiproses is onderbreek"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Laaiproses is onderbreek"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – Laai tot <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Onbekend"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Laai"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Laai tans vinnig"</string>
diff --git a/packages/SettingsLib/res/values-am/strings.xml b/packages/SettingsLib/res/values-am/strings.xml
index 29b188c..fa53f0d 100644
--- a/packages/SettingsLib/res/values-am/strings.xml
+++ b/packages/SettingsLib/res/values-am/strings.xml
@@ -233,7 +233,7 @@
     <string name="adb_pair_method_qrcode_title" msgid="6982904096137468634">"የQR ኮድን በመጠቀም መሣሪያን ያጣምሩ"</string>
     <string name="adb_pair_method_qrcode_summary" msgid="7130694277228970888">"የQR ኮድ መቃኛን በመጠቀም አዲስ መሣሪያዎችን ያጣምሩ"</string>
     <string name="adb_pair_method_code_title" msgid="1122590300445142904">"የማጣመሪያ ኮድን በመጠቀም መሣሪያን ያጣምሩ"</string>
-    <string name="adb_pair_method_code_summary" msgid="6370414511333685185">"የስድስት አኃዝ ኮድ በመጠቀም አዲስ መሣሪያዎችን ያጣምሩ"</string>
+    <string name="adb_pair_method_code_summary" msgid="6370414511333685185">"የስድስት አሃዝ ኮድ በመጠቀም አዲስ መሣሪያዎችን ያጣምሩ"</string>
     <string name="adb_paired_devices_title" msgid="5268997341526217362">"የተጣመሩ መሣሪያዎች"</string>
     <string name="adb_wireless_device_connected_summary" msgid="3039660790249148713">"አሁን ላይ ተገናኝቷል"</string>
     <string name="adb_wireless_device_details_title" msgid="7129369670526565786">"የመሣሪያ ዝርዝሮች"</string>
@@ -344,7 +344,7 @@
     <string name="wait_for_debugger" msgid="7461199843335409809">"ስህተት ማስወገጃውን ጠብቅ"</string>
     <string name="wait_for_debugger_summary" msgid="6846330006113363286">"ስህተቱ የተወገደለት መተግበሪያ ከመፈጸሙ በፊት የስህተት ማስወገጃው እስኪያያዝ ድረስ እየጠበቀው ነው"</string>
     <string name="debug_input_category" msgid="7349460906970849771">"ግብዓት"</string>
-    <string name="debug_drawing_category" msgid="5066171112313666619">"ስዕል"</string>
+    <string name="debug_drawing_category" msgid="5066171112313666619">"ሥዕል"</string>
     <string name="debug_hw_drawing_category" msgid="5830815169336975162">"የተፋጠነ የሃርድዌር አሰጣጥ"</string>
     <string name="media_category" msgid="8122076702526144053">"ማህደረመረጃ"</string>
     <string name="debug_monitoring_category" msgid="1597387133765424994">"ቁጥጥር"</string>
@@ -467,7 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"እስኪሞላ ድረስ <xliff:g id="TIME">%1$s</xliff:g> ይቀራል"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - እስኪሞላ ድረስ <xliff:g id="TIME">%2$s</xliff:g> ይቀራል"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - ኃይል መሙላት ባለበት ቆሟል"</string>
+    <!-- no translation found for power_charging_limited (6732738149313642521) -->
+    <skip />
     <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
     <skip />
     <string name="battery_info_status_unknown" msgid="268625384868401114">"ያልታወቀ"</string>
@@ -548,10 +549,10 @@
     <string name="shared_data_title" msgid="1017034836800864953">"የተጋራ ውሂብ"</string>
     <string name="shared_data_summary" msgid="5516326713822885652">"የተጋራ ውሂብን ይመልከቱ እና ያሻሽሉ"</string>
     <string name="shared_data_no_blobs_text" msgid="3108114670341737434">"ለዚህ ተጠቃሚ ምንም የተጋራ ውሂብ የለም።"</string>
-    <string name="shared_data_query_failure_text" msgid="3489828881998773687">"የተጋራውን ውሂብ በማግኘት ላይ ስሕተት ነበረ። እንደገና ይሞክሩ።"</string>
+    <string name="shared_data_query_failure_text" msgid="3489828881998773687">"የተጋራውን ውሂብ በማግኘት ላይ ስህተት ነበረ። እንደገና ይሞክሩ።"</string>
     <string name="blob_id_text" msgid="8680078988996308061">"የተጋራ ውሂብ መታወቂያ፦ <xliff:g id="BLOB_ID">%d</xliff:g>"</string>
     <string name="blob_expires_text" msgid="7882727111491739331">"በ<xliff:g id="DATE">%s</xliff:g> ላይ የአገልግሎት ጊዜው ያበቃል"</string>
-    <string name="shared_data_delete_failure_text" msgid="3842701391009628947">"የተጋራውን ውሂብ በመሰረዝ ላይ ስሕተት ነበረ።"</string>
+    <string name="shared_data_delete_failure_text" msgid="3842701391009628947">"የተጋራውን ውሂብ በመሰረዝ ላይ ስህተት ነበረ።"</string>
     <string name="shared_data_no_accessors_dialog_text" msgid="8903738462570715315">"ለዚህ የተጋራ ውሂብ ምንም የሚያስፈልጉ ኪራዮች የሉም። ሊሰርዙት ይፈልጋሉ?"</string>
     <string name="accessor_info_title" msgid="8289823651512477787">"ውሂብ የሚጋሩ መተግበሪያዎች"</string>
     <string name="accessor_no_description_text" msgid="7510967452505591456">"በመተግበሪያው ምንም ዝርዝር መረጃ አልተሰጠም።"</string>
diff --git a/packages/SettingsLib/res/values-ar/strings.xml b/packages/SettingsLib/res/values-ar/strings.xml
index 28a3f18..88db7be 100644
--- a/packages/SettingsLib/res/values-ar/strings.xml
+++ b/packages/SettingsLib/res/values-ar/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"يتبقّى <xliff:g id="TIME">%1$s</xliff:g> حتى اكتمال شحن البطارية."</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - يتبقّى <xliff:g id="TIME">%2$s</xliff:g> حتى اكتمال شحن البطارية."</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - تم إيقاف الشحن مؤقتًا"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - الشحن متوقّف مؤقتًا"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - الشحن حتى <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"غير معروف"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"جارٍ الشحن"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"جارٍ الشحن سريعًا"</string>
diff --git a/packages/SettingsLib/res/values-as/strings.xml b/packages/SettingsLib/res/values-as/strings.xml
index fc54e04..3f068b4 100644
--- a/packages/SettingsLib/res/values-as/strings.xml
+++ b/packages/SettingsLib/res/values-as/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"সম্পূৰ্ণ হ’বলৈ <xliff:g id="TIME">%1$s</xliff:g> বাকী আছে"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"সম্পূৰ্ণ হ’বলৈ <xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g> বাকী আছে"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - চাৰ্জিং পজ কৰা হৈছে"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - চাৰ্জিং পজ কৰা হৈছে"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>লৈ চাৰ্জিং"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"অজ্ঞাত"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"চাৰ্জ কৰি থকা হৈছে"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"দ্ৰুততাৰে চাৰ্জ হৈছে"</string>
diff --git a/packages/SettingsLib/res/values-az/strings.xml b/packages/SettingsLib/res/values-az/strings.xml
index e2e294f..8eb8d5b 100644
--- a/packages/SettingsLib/res/values-az/strings.xml
+++ b/packages/SettingsLib/res/values-az/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"Tam şarj edilənədək <xliff:g id="TIME">%1$s</xliff:g> qalıb"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - tam şarj edilənədək <xliff:g id="TIME">%2$s</xliff:g> qalıb"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Şarj durdurulub"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Şarj durdurulub"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> olana qədər şarj edilir"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Naməlum"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Enerji doldurma"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Sürətlə doldurulur"</string>
diff --git a/packages/SettingsLib/res/values-b+sr+Latn/strings.xml b/packages/SettingsLib/res/values-b+sr+Latn/strings.xml
index 479c9ca..bbdd8bf 100644
--- a/packages/SettingsLib/res/values-b+sr+Latn/strings.xml
+++ b/packages/SettingsLib/res/values-b+sr+Latn/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> do kraja punjenja"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> do kraja punjenja"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> – Punjenje je zaustavljeno"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – Punjenje je pauzirano"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – punjenje do <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Nepoznato"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Puni se"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Brzo se puni"</string>
diff --git a/packages/SettingsLib/res/values-be/strings.xml b/packages/SettingsLib/res/values-be/strings.xml
index b45996c..28c1e86 100644
--- a/packages/SettingsLib/res/values-be/strings.xml
+++ b/packages/SettingsLib/res/values-be/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"Да поўнай зарадкі засталося <xliff:g id="TIME">%1$s</xliff:g>"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – да поўнай зарадкі засталося: <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Зарадка прыпынена"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Зарадка прыпынена"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – зарадка да <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Невядома"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Зарадка"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Хуткая зарадка"</string>
diff --git a/packages/SettingsLib/res/values-bg/strings.xml b/packages/SettingsLib/res/values-bg/strings.xml
index ecb5208..61e441d 100644
--- a/packages/SettingsLib/res/values-bg/strings.xml
+++ b/packages/SettingsLib/res/values-bg/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"Оставащо време до пълно зареждане: <xliff:g id="TIME">%1$s</xliff:g>"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – Оставащо време до пълно зареждане: <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g>: Зареждането е на пауза"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – зареждането е на пауза"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – зарежда се до <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Неизвестно"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Зарежда се"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Зарежда се бързо"</string>
diff --git a/packages/SettingsLib/res/values-bn/strings.xml b/packages/SettingsLib/res/values-bn/strings.xml
index fda27ed..a9d32a9 100644
--- a/packages/SettingsLib/res/values-bn/strings.xml
+++ b/packages/SettingsLib/res/values-bn/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g>-এ ব্যাটারি পুরো চার্জ হয়ে যাবে"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g>-এ ব্যাটারি পুরো চার্জ হয়ে যাবে"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - চার্জিং পজ করা হয়েছে"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - চার্জিং পজ করা হয়েছে"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> পর্যন্ত চার্জ হচ্ছে"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"অজানা"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"চার্জ হচ্ছে"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"দ্রুত চার্জ হচ্ছে"</string>
diff --git a/packages/SettingsLib/res/values-bs/strings.xml b/packages/SettingsLib/res/values-bs/strings.xml
index cae96e9..b5c9177 100644
--- a/packages/SettingsLib/res/values-bs/strings.xml
+++ b/packages/SettingsLib/res/values-bs/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> do potpune napunjenosti"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> do potpune napunjenosti"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Punjenje je pauzirano"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Punjenje je pauzirano"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – Punjenje do <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Nepoznato"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Punjenje"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Brzo punjenje"</string>
diff --git a/packages/SettingsLib/res/values-ca/strings.xml b/packages/SettingsLib/res/values-ca/strings.xml
index 51a4a02..8add8c8 100644
--- a/packages/SettingsLib/res/values-ca/strings.xml
+++ b/packages/SettingsLib/res/values-ca/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g>: <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> per completar la càrrega"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g>: <xliff:g id="TIME">%2$s</xliff:g> per completar la càrrega"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g>: la càrrega s\'ha posat en pausa"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g>: la càrrega s\'ha posat en pausa"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g>: s\'està carregant fins al <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Desconegut"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"S\'està carregant"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Carregant ràpidament"</string>
diff --git a/packages/SettingsLib/res/values-cs/strings.xml b/packages/SettingsLib/res/values-cs/strings.xml
index a50e527..4dc3c66 100644
--- a/packages/SettingsLib/res/values-cs/strings.xml
+++ b/packages/SettingsLib/res/values-cs/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> do úplného nabití"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> do úplného nabití"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> – Nabíjení je pozastaveno"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – Nabíjení pozastaveno"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – nabíjení do <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Neznámé"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Nabíjí se"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Rychlé nabíjení"</string>
diff --git a/packages/SettingsLib/res/values-da/strings.xml b/packages/SettingsLib/res/values-da/strings.xml
index 95e0130..9ab499a 100644
--- a/packages/SettingsLib/res/values-da/strings.xml
+++ b/packages/SettingsLib/res/values-da/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"Fuldt opladet om <xliff:g id="TIME">%1$s</xliff:g>"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – fuldt opladet om <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Opladningen er sat på pause"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – Opladning er sat på pause"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – Oplader til <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Ukendt"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Oplader"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Oplader hurtigt"</string>
diff --git a/packages/SettingsLib/res/values-de/strings.xml b/packages/SettingsLib/res/values-de/strings.xml
index 12fce37..68d61c0 100644
--- a/packages/SettingsLib/res/values-de/strings.xml
+++ b/packages/SettingsLib/res/values-de/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"Voll in <xliff:g id="TIME">%1$s</xliff:g>"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – voll in <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> – Ladevorgang angehalten"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – Laden pausiert"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – Aufladung auf <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Unbekannt"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Wird aufgeladen"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Schnelles Aufladen"</string>
diff --git a/packages/SettingsLib/res/values-el/strings.xml b/packages/SettingsLib/res/values-el/strings.xml
index f54d5d2..59ae638 100644
--- a/packages/SettingsLib/res/values-el/strings.xml
+++ b/packages/SettingsLib/res/values-el/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"Απομένουν <xliff:g id="TIME">%1$s</xliff:g> για πλήρη φόρτιση"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - Απομένουν <xliff:g id="TIME">%2$s</xliff:g> για πλήρη φόρτιση"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Η φόρτιση τέθηκε σε παύση"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Φόρτιση σε παύση"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - Φόρτιση έως το <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Άγνωστο"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Φόρτιση"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Ταχεία φόρτιση"</string>
diff --git a/packages/SettingsLib/res/values-en-rAU/strings.xml b/packages/SettingsLib/res/values-en-rAU/strings.xml
index 208dbfa..3c98c25 100644
--- a/packages/SettingsLib/res/values-en-rAU/strings.xml
+++ b/packages/SettingsLib/res/values-en-rAU/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> left until full"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> left until full"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Charging is paused"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – charging paused"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – charging to <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Unknown"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Charging"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Charging rapidly"</string>
diff --git a/packages/SettingsLib/res/values-en-rCA/strings.xml b/packages/SettingsLib/res/values-en-rCA/strings.xml
index aac80ab..833a9e4 100644
--- a/packages/SettingsLib/res/values-en-rCA/strings.xml
+++ b/packages/SettingsLib/res/values-en-rCA/strings.xml
@@ -467,7 +467,7 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> left until full"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g> left until full"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Charging is paused"</string>
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Charging paused"</string>
     <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - Charging to <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Unknown"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Charging"</string>
diff --git a/packages/SettingsLib/res/values-en-rGB/strings.xml b/packages/SettingsLib/res/values-en-rGB/strings.xml
index 208dbfa..3c98c25 100644
--- a/packages/SettingsLib/res/values-en-rGB/strings.xml
+++ b/packages/SettingsLib/res/values-en-rGB/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> left until full"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> left until full"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Charging is paused"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – charging paused"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – charging to <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Unknown"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Charging"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Charging rapidly"</string>
diff --git a/packages/SettingsLib/res/values-en-rIN/strings.xml b/packages/SettingsLib/res/values-en-rIN/strings.xml
index 208dbfa..3c98c25 100644
--- a/packages/SettingsLib/res/values-en-rIN/strings.xml
+++ b/packages/SettingsLib/res/values-en-rIN/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> left until full"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> left until full"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Charging is paused"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – charging paused"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – charging to <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Unknown"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Charging"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Charging rapidly"</string>
diff --git a/packages/SettingsLib/res/values-en-rXC/strings.xml b/packages/SettingsLib/res/values-en-rXC/strings.xml
index bfd7e83..b856eb1 100644
--- a/packages/SettingsLib/res/values-en-rXC/strings.xml
+++ b/packages/SettingsLib/res/values-en-rXC/strings.xml
@@ -467,7 +467,7 @@
     <string name="power_charging" msgid="6727132649743436802">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‏‏‏‏‎‏‏‏‎‏‎‏‎‏‏‎‏‏‏‎‎‏‎‎‏‏‏‎‎‎‎‎‎‎‏‏‎‎‏‎‎‎‏‏‏‎‎‎‏‏‏‏‎‎‏‏‎‎‎‎‎‎‎‎‏‎‎‎‏‎‎‏‏‎<xliff:g id="LEVEL">%1$s</xliff:g>‎‏‎‎‏‏‏‎ - ‎‏‎‎‏‏‎<xliff:g id="STATE">%2$s</xliff:g>‎‏‎‎‏‏‏‎‎‏‎‎‏‎"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‏‏‏‏‏‏‎‎‎‎‎‎‏‏‎‏‎‎‎‎‎‎‏‎‏‎‏‎‏‏‎‏‏‏‎‎‏‎‏‎‎‎‎‏‏‏‏‎‏‏‏‏‏‎‏‎‎‎‎‏‎‎‎‎‏‏‎‎‏‎‎‏‏‎<xliff:g id="TIME">%1$s</xliff:g>‎‏‎‎‏‏‏‎ left until full‎‏‎‎‏‎"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‏‏‏‏‎‏‎‏‎‏‎‎‎‎‏‎‎‎‎‎‎‎‎‏‏‎‏‏‏‏‎‏‏‏‎‏‎‏‏‏‎‏‎‎‎‎‎‏‎‏‏‏‏‏‎‎‏‏‏‎‏‎‎‏‏‏‎‎‏‎‎‏‏‎<xliff:g id="LEVEL">%1$s</xliff:g>‎‏‎‎‏‏‏‎ - ‎‏‎‎‏‏‎<xliff:g id="TIME">%2$s</xliff:g>‎‏‎‎‏‏‏‎ left until full‎‏‎‎‏‎"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‏‏‏‏‏‎‎‎‎‎‏‏‎‎‎‎‎‎‎‏‎‏‎‎‏‏‏‎‎‏‏‎‎‎‎‏‏‎‎‏‎‏‎‏‎‏‏‏‎‎‏‎‏‏‏‏‏‎‏‎‏‎‎‏‎‏‎‎‏‎‎‏‏‎<xliff:g id="LEVEL">%1$s</xliff:g>‎‏‎‎‏‏‏‎ - Charging is paused‎‏‎‎‏‎"</string>
+    <string name="power_charging_limited" msgid="6732738149313642521">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‏‏‏‏‎‏‏‏‎‏‎‏‏‎‏‏‏‏‎‏‏‏‏‏‎‏‏‎‏‎‏‏‎‎‏‏‎‏‏‎‏‏‏‎‎‎‏‏‏‏‏‎‎‎‎‎‎‎‎‎‎‏‏‎‎‏‎‎‏‎‎‏‏‎<xliff:g id="LEVEL">%1$s</xliff:g>‎‏‎‎‏‏‏‎ - Charging paused‎‏‎‎‏‎"</string>
     <string name="power_charging_future_paused" msgid="6829683663982987290">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‏‏‏‏‎‏‏‏‏‎‏‏‎‎‎‏‏‏‏‏‏‎‏‎‎‏‎‎‎‏‏‎‏‏‎‏‏‎‏‏‏‏‏‏‏‏‏‏‏‎‏‎‎‎‏‎‎‎‎‎‎‏‏‎‏‎‎‎‏‎‎‏‏‎<xliff:g id="LEVEL">%1$s</xliff:g>‎‏‎‎‏‏‏‎ - Charging to ‎‏‎‎‏‏‎<xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>‎‏‎‎‏‏‏‎‎‏‎‎‏‎"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‎‏‎‏‏‏‎‏‏‏‎‏‎‎‏‎‏‏‎‎‏‎‏‎‏‏‏‎‏‎‏‎‎‎‎‏‎‏‎‏‏‏‎‏‏‏‏‎‎‏‏‏‏‏‏‎‏‏‎‏‎‎Unknown‎‏‎‎‏‎"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‏‏‎‏‏‏‎‏‏‎‏‏‎‎‏‎‏‎‏‏‏‎‏‏‏‎‎‏‎‎‎‏‏‏‎‎‎‏‎‏‏‎‏‎‏‎‎‎‎‎‏‏‎‎‏‏‎‏‏‎‎‏‏‎‏‎Charging‎‏‎‎‏‎"</string>
diff --git a/packages/SettingsLib/res/values-es-rUS/strings.xml b/packages/SettingsLib/res/values-es-rUS/strings.xml
index c11d6eb0..78af70a 100644
--- a/packages/SettingsLib/res/values-es-rUS/strings.xml
+++ b/packages/SettingsLib/res/values-es-rUS/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g>: <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> para completar"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g> para completar"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Se pausó la carga"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Se pausó la carga"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - Cargando hasta <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Desconocido"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Cargando"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Cargando rápidamente"</string>
diff --git a/packages/SettingsLib/res/values-es/strings.xml b/packages/SettingsLib/res/values-es/strings.xml
index 1ef351a..ea3047b 100644
--- a/packages/SettingsLib/res/values-es/strings.xml
+++ b/packages/SettingsLib/res/values-es/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> hasta la carga completa"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g>: <xliff:g id="TIME">%2$s</xliff:g> hasta la carga completa"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Carga en pausa"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Carga pausada"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - Cargando hasta <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Desconocido"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Cargando"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Carga rápida"</string>
diff --git a/packages/SettingsLib/res/values-et/strings.xml b/packages/SettingsLib/res/values-et/strings.xml
index e156011..78ade67 100644
--- a/packages/SettingsLib/res/values-et/strings.xml
+++ b/packages/SettingsLib/res/values-et/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"Täislaadimiseks kulub <xliff:g id="TIME">%1$s</xliff:g>"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – täislaadimiseks kulub <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> – laadimine on peatatud"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – laadimine peatati"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – laadimine tasemeni <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Tundmatu"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Laadimine"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Kiirlaadimine"</string>
diff --git a/packages/SettingsLib/res/values-eu/strings.xml b/packages/SettingsLib/res/values-eu/strings.xml
index e5f399c..748f991 100644
--- a/packages/SettingsLib/res/values-eu/strings.xml
+++ b/packages/SettingsLib/res/values-eu/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> guztiz kargatu arte"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g> guztiz kargatu arte"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Kargatze-prozesua etenda dago"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Kargatze-prozesua pausatuta dago"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> arte kargatzen"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Ezezaguna"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Kargatzen"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Bizkor kargatzen"</string>
diff --git a/packages/SettingsLib/res/values-fa/strings.xml b/packages/SettingsLib/res/values-fa/strings.xml
index ccacfde..44e61ef 100644
--- a/packages/SettingsLib/res/values-fa/strings.xml
+++ b/packages/SettingsLib/res/values-fa/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - ‏<xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> تا شارژ کامل باقی مانده است"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g> تا شارژ کامل باقی مانده است"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - شارژ موقتاً متوقف شده است"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - شارژ موقتاً متوقف شد"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - درحال شارژ تا <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"ناشناس"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"در حال شارژ شدن"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"درحال شارژ شدن سریع"</string>
diff --git a/packages/SettingsLib/res/values-fi/strings.xml b/packages/SettingsLib/res/values-fi/strings.xml
index 101dc67..2599eb3 100644
--- a/packages/SettingsLib/res/values-fi/strings.xml
+++ b/packages/SettingsLib/res/values-fi/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> kunnes täynnä"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> kunnes täynnä"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> – Lataus on keskeytetty"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – Lataaminen keskeytetty"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – Tavoite: <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Tuntematon"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Ladataan"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Nopea lataus"</string>
diff --git a/packages/SettingsLib/res/values-fr-rCA/strings.xml b/packages/SettingsLib/res/values-fr-rCA/strings.xml
index ff58a51..314e8d1 100644
--- a/packages/SettingsLib/res/values-fr-rCA/strings.xml
+++ b/packages/SettingsLib/res/values-fr-rCA/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> jusqu\'à la recharge complète"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> (<xliff:g id="TIME">%2$s</xliff:g> jusqu\'à la recharge complète)"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - La recharge est interrompue"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – Recharge interrompue"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - En charge jusqu\'à <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Inconnu"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Charge en cours…"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Recharge rapide"</string>
diff --git a/packages/SettingsLib/res/values-fr/strings.xml b/packages/SettingsLib/res/values-fr/strings.xml
index f9725f6..5cab1de 100644
--- a/packages/SettingsLib/res/values-fr/strings.xml
+++ b/packages/SettingsLib/res/values-fr/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"Chargée à 100 %% dans <xliff:g id="TIME">%1$s</xliff:g>"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - chargée à 100 %% dans <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> – La recharge est en pause"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – Recharge interrompue"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - Recharge jusqu\'à <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Inconnu"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Batterie en charge"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Charge rapide"</string>
diff --git a/packages/SettingsLib/res/values-gl/strings.xml b/packages/SettingsLib/res/values-gl/strings.xml
index 3ceb99c..52bdaf6 100644
--- a/packages/SettingsLib/res/values-gl/strings.xml
+++ b/packages/SettingsLib/res/values-gl/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> para completar a carga"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> (<xliff:g id="TIME">%2$s</xliff:g> para completar a carga)"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g>: a carga está en pausa"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g>: Carga en pausa"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g>: Cargando ata o <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Descoñecido"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Cargando"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Cargando rapidamente"</string>
diff --git a/packages/SettingsLib/res/values-gu/strings.xml b/packages/SettingsLib/res/values-gu/strings.xml
index 1821546..5a875a7 100644
--- a/packages/SettingsLib/res/values-gu/strings.xml
+++ b/packages/SettingsLib/res/values-gu/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"પૂર્ણ ચાર્જ થવામાં <xliff:g id="TIME">%1$s</xliff:g> બાકી છે"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - પૂર્ણ ચાર્જ થવામાં <xliff:g id="TIME">%2$s</xliff:g> બાકી છે"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - ચાર્જિંગ થોભાવવામાં આવ્યું છે"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - ચાર્જિંગ થોભાવેલું છે"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> સુધી ચાર્જિંગ"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"અજાણ્યું"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"ચાર્જ થઈ રહ્યું છે"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"ઝડપથી ચાર્જ થાય છે"</string>
diff --git a/packages/SettingsLib/res/values-hi/strings.xml b/packages/SettingsLib/res/values-hi/strings.xml
index 4b899bb..0a38d16 100644
--- a/packages/SettingsLib/res/values-hi/strings.xml
+++ b/packages/SettingsLib/res/values-hi/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> में बैटरी पूरी चार्ज हो जाएगी"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g> में बैटरी पूरी चार्ज हो जाएगी"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - चार्जिंग को रोका गया है"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - चार्जिंग रोकी गई है"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> तक चार्ज किया जा रहा है"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"अज्ञात"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"चार्ज हो रही है"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"तेज़ चार्ज हो रही है"</string>
@@ -602,7 +601,7 @@
     <string name="guest_exit_clear_data_button" msgid="3425812652180679014">"मिटाएं"</string>
     <string name="guest_exit_save_data_button" msgid="3690974510644963547">"सेव करें"</string>
     <string name="guest_exit_button" msgid="5774985819191803960">"मेहमान मोड से बाहर निकलें"</string>
-    <string name="guest_reset_button" msgid="2515069346223503479">"मेहमान मोड के सेशन को रीसेट करें?"</string>
+    <string name="guest_reset_button" msgid="2515069346223503479">"मेहमान मोड के सेशन को रीसेट करें"</string>
     <string name="guest_exit_quick_settings_button" msgid="1912362095913765471">"मेहमान मोड से बाहर निकलें"</string>
     <string name="guest_notification_ephemeral" msgid="7263252466950923871">"बाहर निकलने पर, सारी गतिविधि मिट जाएगी"</string>
     <string name="guest_notification_non_ephemeral" msgid="6843799963012259330">"बाहर निकलने पर, गतिविधि को मिटाया या सेव किया जा सकता है"</string>
diff --git a/packages/SettingsLib/res/values-hr/strings.xml b/packages/SettingsLib/res/values-hr/strings.xml
index 46c8b90..03eba0f 100644
--- a/packages/SettingsLib/res/values-hr/strings.xml
+++ b/packages/SettingsLib/res/values-hr/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> do napunjenosti"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> do napunjenosti"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> – punjenje je pauzirano"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – punjenje pauzirano"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – punjenje do <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Nepoznato"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Punjenje"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Brzo punjenje"</string>
diff --git a/packages/SettingsLib/res/values-hu/strings.xml b/packages/SettingsLib/res/values-hu/strings.xml
index d74490f..04a3ac6 100644
--- a/packages/SettingsLib/res/values-hu/strings.xml
+++ b/packages/SettingsLib/res/values-hu/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> a teljes töltöttségig"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> a teljes töltöttségig"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> – A töltés szünetel"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – Töltés szüneteltetve"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – Töltés eddig: <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Ismeretlen"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Töltés"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Gyorstöltés"</string>
diff --git a/packages/SettingsLib/res/values-hy/strings.xml b/packages/SettingsLib/res/values-hy/strings.xml
index c26f94f..13f969c 100644
--- a/packages/SettingsLib/res/values-hy/strings.xml
+++ b/packages/SettingsLib/res/values-hy/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> մինչև լրիվ լիցքավորումը"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> մինչև լրիվ լիցքավորումը"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> – Լիցքավորումը դադարեցված է"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – Լիցքավորումը դադարեցվել է"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – Լիցքավորում մինչև <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Անհայտ"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Լիցքավորում"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Արագ լիցքավորում"</string>
diff --git a/packages/SettingsLib/res/values-in/strings.xml b/packages/SettingsLib/res/values-in/strings.xml
index 203485f..650d50b 100644
--- a/packages/SettingsLib/res/values-in/strings.xml
+++ b/packages/SettingsLib/res/values-in/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> lagi sampai penuh"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g> lagi sampai penuh"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Pengisian daya dijeda"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Pengisian daya dijeda"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - Mengisi daya sampai <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Tidak diketahui"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Mengisi daya"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Mengisi daya cepat"</string>
diff --git a/packages/SettingsLib/res/values-is/strings.xml b/packages/SettingsLib/res/values-is/strings.xml
index 9185877..da576f5 100644
--- a/packages/SettingsLib/res/values-is/strings.xml
+++ b/packages/SettingsLib/res/values-is/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> fram að fullri hleðslu"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g> fram að fullri hleðslu"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Hlé var gert á hleðslu"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Hlé gert á hleðslu"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - hleður upp að <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Óþekkt"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Í hleðslu"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Hröð hleðsla"</string>
diff --git a/packages/SettingsLib/res/values-it/strings.xml b/packages/SettingsLib/res/values-it/strings.xml
index 0cd9e1e..7042506 100644
--- a/packages/SettingsLib/res/values-it/strings.xml
+++ b/packages/SettingsLib/res/values-it/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> alla ricarica completa"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g> alla ricarica completa"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Ricarica in pausa"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Ricarica in pausa"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - Ricarica fino a <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Sconosciuta"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"In carica"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Ricarica veloce"</string>
diff --git a/packages/SettingsLib/res/values-iw/strings.xml b/packages/SettingsLib/res/values-iw/strings.xml
index 6293105..143c99d 100644
--- a/packages/SettingsLib/res/values-iw/strings.xml
+++ b/packages/SettingsLib/res/values-iw/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g>‏ – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"הזמן הנותר לטעינה מלאה: <xliff:g id="TIME">%1$s</xliff:g>"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – הזמן הנותר לטעינה מלאה: <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> – הטעינה הושהתה"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – הטעינה מושהית"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – טעינה עד מצב של <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"לא ידוע"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"בטעינה"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"הסוללה נטענת מהר"</string>
@@ -514,7 +513,7 @@
     <string name="ims_reg_status_not_registered" msgid="2989287366045704694">"לא רשום"</string>
     <string name="status_unavailable" msgid="5279036186589861608">"לא זמין"</string>
     <string name="wifi_status_mac_randomized" msgid="466382542497832189">"‏כתובת ה-MAC אקראית"</string>
-    <string name="wifi_tether_connected_summary" msgid="5282919920463340158">"{count,plural, =0{אין מכשירים מחוברים}=1{מכשיר אחד מחובר}two{# מכשירים מחוברים}many{# מכשירים מחוברים}other{# מכשירים מחוברים}}"</string>
+    <string name="wifi_tether_connected_summary" msgid="5282919920463340158">"{count,plural, =0{אין מכשירים מחוברים}=1{מכשיר אחד מחובר}one{# מכשירים מחוברים}two{# מכשירים מחוברים}other{# מכשירים מחוברים}}"</string>
     <string name="accessibility_manual_zen_more_time" msgid="5141801092071134235">"יותר זמן."</string>
     <string name="accessibility_manual_zen_less_time" msgid="6828877595848229965">"פחות זמן."</string>
     <string name="cancel" msgid="5665114069455378395">"ביטול"</string>
diff --git a/packages/SettingsLib/res/values-ja/strings.xml b/packages/SettingsLib/res/values-ja/strings.xml
index 9a9d6ea..11a5258 100644
--- a/packages/SettingsLib/res/values-ja/strings.xml
+++ b/packages/SettingsLib/res/values-ja/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"完了まであと <xliff:g id="TIME">%1$s</xliff:g>"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - 完了まであと <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - 充電は一時停止中"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - 充電を一時停止しています"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> まで充電"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"不明"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"充電中"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"急速充電中"</string>
diff --git a/packages/SettingsLib/res/values-ka/strings.xml b/packages/SettingsLib/res/values-ka/strings.xml
index 2fa2d80..d6c0f38 100644
--- a/packages/SettingsLib/res/values-ka/strings.xml
+++ b/packages/SettingsLib/res/values-ka/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"სრულ დატენვამდე დარჩენილია <xliff:g id="TIME">%1$s</xliff:g>"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> — სრულ დატენვამდე დარჩენილია <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - დატენვა ᲨეᲩერებულია"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - დატენვა დაპაუზებულია"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – დატენვა შემდეგ ნიშნულამდე: <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"უცნობი"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"იტენება"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"სწრაფად იტენება"</string>
diff --git a/packages/SettingsLib/res/values-kk/strings.xml b/packages/SettingsLib/res/values-kk/strings.xml
index a332004..96f2595 100644
--- a/packages/SettingsLib/res/values-kk/strings.xml
+++ b/packages/SettingsLib/res/values-kk/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"Толық зарядталғанға дейін <xliff:g id="TIME">%1$s</xliff:g> қалды."</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – толық зарядталғанға дейін <xliff:g id="TIME">%2$s</xliff:g> қалды."</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> – зарядтау кідіртілді."</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – Зарядтау кідіртілді"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> деңгейіне дейін зарядталады"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Белгісіз"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Зарядталуда"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Жылдам зарядталуда"</string>
diff --git a/packages/SettingsLib/res/values-km/strings.xml b/packages/SettingsLib/res/values-km/strings.xml
index 2d78295..db4afdf 100644
--- a/packages/SettingsLib/res/values-km/strings.xml
+++ b/packages/SettingsLib/res/values-km/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> ទៀតទើបពេញ"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - នៅសល់ <xliff:g id="TIME">%2$s</xliff:g> ទៀតទើបពេញ"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - ការសាកថ្មត្រូវបានផ្អាក"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - បានផ្អាក​ការសាកថ្ម"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - កំពុង​សាកថ្ម​ឱ្យដល់កម្រិត <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"មិន​ស្គាល់"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"កំពុងសាក​ថ្ម"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"កំពុងសាកថ្មយ៉ាងឆាប់រហ័ស"</string>
diff --git a/packages/SettingsLib/res/values-kn/strings.xml b/packages/SettingsLib/res/values-kn/strings.xml
index 5db4b16..74c2c74 100644
--- a/packages/SettingsLib/res/values-kn/strings.xml
+++ b/packages/SettingsLib/res/values-kn/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> - ಸಮಯದಲ್ಲಿ ಪೂರ್ತಿ ಚಾರ್ಜ್ ಆಗುತ್ತದೆ"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g> ಸಮಯದಲ್ಲಿ ಪೂರ್ತಿ ಚಾರ್ಜ್ ಆಗುತ್ತದೆ"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - ಚಾರ್ಜಿಂಗ್ ಅನ್ನು ವಿರಾಮಗೊಳಿಸಲಾಗಿದೆ"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - ಚಾರ್ಜಿಂಗ್ ವಿರಾಮಗೊಂಡಿದೆ"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> ವರೆಗೆ ಚಾರ್ಜ್ ಮಾಡಲಾಗುತ್ತಿದೆ"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"ಅಪರಿಚಿತ"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"ಚಾರ್ಜ್ ಆಗುತ್ತಿದೆ"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"ವೇಗದ ಚಾರ್ಜಿಂಗ್"</string>
diff --git a/packages/SettingsLib/res/values-ko/strings.xml b/packages/SettingsLib/res/values-ko/strings.xml
index 30ab26c..7a8ce1a 100644
--- a/packages/SettingsLib/res/values-ko/strings.xml
+++ b/packages/SettingsLib/res/values-ko/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> 후 충전 완료"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g>: <xliff:g id="TIME">%2$s</xliff:g> 후 충전 완료"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - 충전 일시중지됨"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - 충전 일시중지됨"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>까지 충전"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"알 수 없음"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"충전 중"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"고속 충전 중"</string>
diff --git a/packages/SettingsLib/res/values-ky/strings.xml b/packages/SettingsLib/res/values-ky/strings.xml
index baacfd7..534c94f 100644
--- a/packages/SettingsLib/res/values-ky/strings.xml
+++ b/packages/SettingsLib/res/values-ky/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> кийин толук кубатталат"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> кийин толук кубатталат"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Кубаттоо тындырылды"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Кубаттоо тындырылды"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> чейин кубаттоо"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Белгисиз"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Кубатталууда"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Ыкчам кубатталууда"</string>
diff --git a/packages/SettingsLib/res/values-lo/strings.xml b/packages/SettingsLib/res/values-lo/strings.xml
index 36755f7..f37a4ea 100644
--- a/packages/SettingsLib/res/values-lo/strings.xml
+++ b/packages/SettingsLib/res/values-lo/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"ຍັງເຫຼືອອີກ <xliff:g id="TIME">%1$s</xliff:g> ຈຶ່ງຈະສາກເຕັມ"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"ຍັງເຫຼືອອີກ <xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g> ຈຶ່ງຈະສາກເຕັມ"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - ການສາກໄຟຖືກຢຸດໄວ້ຊົ່ວຄາວ"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - ຢຸດການສາກໄວ້ຊົ່ວຄາວແລ້ວ"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - ກຳລັງສາກຈົນເຖິງ <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"ບໍ່ຮູ້ຈັກ"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"ກຳລັງສາກໄຟ"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"ກຳລັງສາກໄຟດ່ວນ"</string>
diff --git a/packages/SettingsLib/res/values-lt/strings.xml b/packages/SettingsLib/res/values-lt/strings.xml
index 50652ea..cdfa115 100644
--- a/packages/SettingsLib/res/values-lt/strings.xml
+++ b/packages/SettingsLib/res/values-lt/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"Liko <xliff:g id="TIME">%1$s</xliff:g>, kol bus visiškai įkrauta"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – liko <xliff:g id="TIME">%2$s</xliff:g>, kol bus visiškai įkrauta"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> – įkrovimas pristabdytas"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – įkrovimas pristabdytas"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – įkraunama iki <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Nežinomas"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Kraunasi..."</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Greitai įkraunama"</string>
diff --git a/packages/SettingsLib/res/values-lv/strings.xml b/packages/SettingsLib/res/values-lv/strings.xml
index c199fea..a5ecfff 100644
--- a/packages/SettingsLib/res/values-lv/strings.xml
+++ b/packages/SettingsLib/res/values-lv/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> — <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> līdz pilnai uzlādei"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> — <xliff:g id="TIME">%2$s</xliff:g> līdz pilnai uzlādei"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> — uzlāde ir pārtraukta"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Uzlāde ir apturēta"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g>. Tiks uzlādēts līdz <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Nezināms"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Uzlāde"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Notiek ātrā uzlāde"</string>
diff --git a/packages/SettingsLib/res/values-mk/strings.xml b/packages/SettingsLib/res/values-mk/strings.xml
index 957f68b..a41d953 100644
--- a/packages/SettingsLib/res/values-mk/strings.xml
+++ b/packages/SettingsLib/res/values-mk/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> до полна батерија"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g> до полна батерија"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Полнењето е паузирано"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Полнењето е паузирано"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - Се полни на <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Непознато"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Се полни"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Брзо полнење"</string>
diff --git a/packages/SettingsLib/res/values-ml/strings.xml b/packages/SettingsLib/res/values-ml/strings.xml
index 1cc92ca..83b87f8 100644
--- a/packages/SettingsLib/res/values-ml/strings.xml
+++ b/packages/SettingsLib/res/values-ml/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"പൂർണ്ണമാകാൻ <xliff:g id="TIME">%1$s</xliff:g> ശേഷിക്കുന്നു"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - പൂർണ്ണമാകാൻ <xliff:g id="TIME">%2$s</xliff:g> ശേഷിക്കുന്നു"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - ചാർജിംഗ് താൽക്കാലികമായി നിർത്തി"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - ചാർജ് ചെയ്യൽ താൽക്കാലികമായി നിർത്തി"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> വരെ ചാർജ് ചെയ്യുന്നു"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"അജ്ഞാതം"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"ചാർജ് ചെയ്യുന്നു"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"അതിവേഗ ചാർജിംഗ്"</string>
diff --git a/packages/SettingsLib/res/values-mn/strings.xml b/packages/SettingsLib/res/values-mn/strings.xml
index a107c70..b77d8fb 100644
--- a/packages/SettingsLib/res/values-mn/strings.xml
+++ b/packages/SettingsLib/res/values-mn/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"Дүүрэх хүртэл <xliff:g id="TIME">%1$s</xliff:g> үлдсэн"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - дүүрэх хүртэл <xliff:g id="TIME">%2$s</xliff:g> үлдсэн"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Цэнэглэхийг түр зогсоосон"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Цэнэглэлтийг түр зогсоосон"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> руу цэнэглэж байна"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Тодорхойгүй"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Цэнэглэж байна"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Хурдан цэнэглэж байна"</string>
diff --git a/packages/SettingsLib/res/values-mr/strings.xml b/packages/SettingsLib/res/values-mr/strings.xml
index d5c83a8..9d91684 100644
--- a/packages/SettingsLib/res/values-mr/strings.xml
+++ b/packages/SettingsLib/res/values-mr/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"पूर्ण चार्ज होण्यासाठी <xliff:g id="TIME">%1$s</xliff:g> शिल्लक आहेत"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - पूर्ण चार्ज होण्यासाठी <xliff:g id="TIME">%2$s</xliff:g> शिल्लक आहे"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - चार्ज करणे थांबवले आहे"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - चार्ज करणे थांबवले"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> वर चार्ज करत आहे"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"अज्ञात"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"चार्ज होत आहे"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"वेगाने चार्ज होत आहे"</string>
diff --git a/packages/SettingsLib/res/values-ms/strings.xml b/packages/SettingsLib/res/values-ms/strings.xml
index ae8be8e..d302214 100644
--- a/packages/SettingsLib/res/values-ms/strings.xml
+++ b/packages/SettingsLib/res/values-ms/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> lagi sebelum penuh"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g> lagi sebelum penuh"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Pengecasan dijeda"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Pengecasan dijeda"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - Mengecas kepada <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Tidak diketahui"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Mengecas"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Mengecas dgn cepat"</string>
diff --git a/packages/SettingsLib/res/values-my/strings.xml b/packages/SettingsLib/res/values-my/strings.xml
index f16cdca..1e26b08 100644
--- a/packages/SettingsLib/res/values-my/strings.xml
+++ b/packages/SettingsLib/res/values-my/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"အားပြည့်ရန် <xliff:g id="TIME">%1$s</xliff:g> လိုသည်"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"အားပြည့်ရန် <xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g> လိုသည်"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - အားသွင်းခြင်းကို ခဏရပ်ထားသည်"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - အားသွင်းမှု ခဏရပ်ထားသည်"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> အထိ အားသွင်းရန်"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"မသိ"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"အားသွင်းနေပါသည်"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"အမြန် အားသွင်းနေသည်"</string>
diff --git a/packages/SettingsLib/res/values-nb/strings.xml b/packages/SettingsLib/res/values-nb/strings.xml
index f7a10a6..be52597 100644
--- a/packages/SettingsLib/res/values-nb/strings.xml
+++ b/packages/SettingsLib/res/values-nb/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"Fulladet om <xliff:g id="TIME">%1$s</xliff:g>"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – Fulladet om <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Ladingen er satt på pause"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Ladingen er satt på pause"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – lader til <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Ukjent"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Lader"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Lader raskt"</string>
diff --git a/packages/SettingsLib/res/values-ne/strings.xml b/packages/SettingsLib/res/values-ne/strings.xml
index a966f15..4d2eb2e 100644
--- a/packages/SettingsLib/res/values-ne/strings.xml
+++ b/packages/SettingsLib/res/values-ne/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"पूरा चार्ज हुन <xliff:g id="TIME">%1$s</xliff:g> लाग्ने छ"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - पूरा चार्ज हुन <xliff:g id="TIME">%2$s</xliff:g> लाग्ने छ"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - चार्ज गर्ने प्रक्रिया रोकिएको छ"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - चार्ज गर्ने प्रक्रिया पज गरिएको छ"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> सम्म चार्ज हुने छ"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"अज्ञात"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"चार्ज हुँदै छ"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"द्रुत गतिमा चार्ज गरिँदै छ"</string>
diff --git a/packages/SettingsLib/res/values-nl/strings.xml b/packages/SettingsLib/res/values-nl/strings.xml
index c5406ee..898da11 100644
--- a/packages/SettingsLib/res/values-nl/strings.xml
+++ b/packages/SettingsLib/res/values-nl/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"Vol over <xliff:g id="TIME">%1$s</xliff:g>"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - vol over <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Opladen is onderbroken"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Opladen onderbroken"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - Opladen tot <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Onbekend"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Opladen"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Snel opladen"</string>
diff --git a/packages/SettingsLib/res/values-or/strings.xml b/packages/SettingsLib/res/values-or/strings.xml
index 37cc25e..6b6752f 100644
--- a/packages/SettingsLib/res/values-or/strings.xml
+++ b/packages/SettingsLib/res/values-or/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"ପୂର୍ଣ୍ଣ ହେବାକୁ ଆଉ <xliff:g id="TIME">%1$s</xliff:g> ବାକି ଅଛି"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - ପୂର୍ଣ୍ଣ ହେବାକୁ ଆଉ <xliff:g id="TIME">%2$s</xliff:g> ବାକି ଅଛି"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - ଚାର୍ଜିଂକୁ ବିରତ କରାଯାଇଛି"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - ଚାର୍ଜିଂ ବିରତ କରାଯାଇଛି"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> ପର୍ଯ୍ୟନ୍ତ ଚାର୍ଜ ହେଉଛି"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"ଅଜ୍ଞାତ"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"ଚାର୍ଜ ହେଉଛି"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"ଶୀଘ୍ର ଚାର୍ଜ ହେଉଛି"</string>
diff --git a/packages/SettingsLib/res/values-pa/strings.xml b/packages/SettingsLib/res/values-pa/strings.xml
index 767cbc5..896b5ec 100644
--- a/packages/SettingsLib/res/values-pa/strings.xml
+++ b/packages/SettingsLib/res/values-pa/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"ਬੈਟਰੀ ਪੂਰੀ ਚਾਰਜ ਹੋਣ ਵਿੱਚ <xliff:g id="TIME">%1$s</xliff:g> ਬਾਕੀ"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - ਬੈਟਰੀ ਪੂਰੀ ਚਾਰਜ ਹੋਣ ਵਿੱਚ <xliff:g id="TIME">%2$s</xliff:g> ਬਾਕੀ"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - ਚਾਰਜਿੰਗ ਨੂੰ ਰੋਕਿਆ ਗਿਆ ਹੈ"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - ਬੈਟਰੀ ਦੀ ਚਾਰਜਿੰਗ ਨੂੰ ਰੋਕਿਆ ਗਿਆ"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> ਤੱਕ ਚਾਰਜ ਕੀਤਾ ਜਾ ਰਿਹਾ ਹੈ"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"ਅਗਿਆਤ"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"ਚਾਰਜ ਹੋ ਰਹੀ ਹੈ"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"ਤੇਜ਼ ਚਾਰਜ ਹੋ ਰਹੀ ਹੈ"</string>
diff --git a/packages/SettingsLib/res/values-pl/strings.xml b/packages/SettingsLib/res/values-pl/strings.xml
index 48bc82e..263e0d7 100644
--- a/packages/SettingsLib/res/values-pl/strings.xml
+++ b/packages/SettingsLib/res/values-pl/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> do pełnego naładowania"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> do pełnego naładowania"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> – ładowanie zostało wstrzymane"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – wstrzymano ładowanie"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – Ładuję do <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Nieznane"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Ładowanie"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Szybkie ładowanie"</string>
diff --git a/packages/SettingsLib/res/values-pt-rBR/strings.xml b/packages/SettingsLib/res/values-pt-rBR/strings.xml
index 68a1c49..e107064 100644
--- a/packages/SettingsLib/res/values-pt-rBR/strings.xml
+++ b/packages/SettingsLib/res/values-pt-rBR/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> até a conclusão"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g>: <xliff:g id="TIME">%2$s</xliff:g> até a conclusão"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g>: o carregamento está pausado"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g>: carregamento pausado"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g>: carregando até <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Desconhecido"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Carregando"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Carregando rápido"</string>
diff --git a/packages/SettingsLib/res/values-pt-rPT/strings.xml b/packages/SettingsLib/res/values-pt-rPT/strings.xml
index 87bab50..165ecc4 100644
--- a/packages/SettingsLib/res/values-pt-rPT/strings.xml
+++ b/packages/SettingsLib/res/values-pt-rPT/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> até à carga máxima"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> até à carga máxima"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> – O carregamento está pausado"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – Carregamento em pausa"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – A carregar até <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Desconhecido"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"A carregar"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Carregamento rápido"</string>
diff --git a/packages/SettingsLib/res/values-pt/strings.xml b/packages/SettingsLib/res/values-pt/strings.xml
index 68a1c49..e107064 100644
--- a/packages/SettingsLib/res/values-pt/strings.xml
+++ b/packages/SettingsLib/res/values-pt/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> até a conclusão"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g>: <xliff:g id="TIME">%2$s</xliff:g> até a conclusão"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g>: o carregamento está pausado"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g>: carregamento pausado"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g>: carregando até <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Desconhecido"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Carregando"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Carregando rápido"</string>
diff --git a/packages/SettingsLib/res/values-ro/strings.xml b/packages/SettingsLib/res/values-ro/strings.xml
index f81ef4c..44ec043 100644
--- a/packages/SettingsLib/res/values-ro/strings.xml
+++ b/packages/SettingsLib/res/values-ro/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> până la finalizare"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> până la finalizare"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> – Încărcarea este întreruptă"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – Încărcarea s-a întrerupt"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – Se încarcă până la <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Necunoscut"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Se încarcă"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Se încarcă rapid"</string>
diff --git a/packages/SettingsLib/res/values-ru/strings.xml b/packages/SettingsLib/res/values-ru/strings.xml
index 4dcee13..102cf1b 100644
--- a/packages/SettingsLib/res/values-ru/strings.xml
+++ b/packages/SettingsLib/res/values-ru/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> до полной зарядки"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> до полной зарядки"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g>: зарядка приостановлена"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – зарядка приостановлена"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – заряжается до <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Неизвестно"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Идет зарядка"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Быстрая зарядка"</string>
diff --git a/packages/SettingsLib/res/values-si/strings.xml b/packages/SettingsLib/res/values-si/strings.xml
index 17c59ea..a8963af 100644
--- a/packages/SettingsLib/res/values-si/strings.xml
+++ b/packages/SettingsLib/res/values-si/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"සම්පූර්ණ වීමට <xliff:g id="TIME">%1$s</xliff:g>ක් ඉතිරියි"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - සම්පූර්ණ වීමට <xliff:g id="TIME">%2$s</xliff:g>ක් ඉතිරියි"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - ආරෝපණය විරාම කර ඇත"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - ආරෝපණය විරාම කළා"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> වෙත ආරෝපණය"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"නොදනී"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"ආරෝපණය වෙමින්"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"ශීඝ්‍ර ආරෝපණය"</string>
diff --git a/packages/SettingsLib/res/values-sk/strings.xml b/packages/SettingsLib/res/values-sk/strings.xml
index d9ce6cf..d7bdd89 100644
--- a/packages/SettingsLib/res/values-sk/strings.xml
+++ b/packages/SettingsLib/res/values-sk/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> do úplného nabitia"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> do úplného nabitia"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Nabíjanie je pozastavené"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – nabíjanie bolo pozastavené"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – nabíja sa na úroveň <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Neznáme"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Nabíja sa"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Rýchle nabíjanie"</string>
diff --git a/packages/SettingsLib/res/values-sl/strings.xml b/packages/SettingsLib/res/values-sl/strings.xml
index 8f9b059..6cb5b3c 100644
--- a/packages/SettingsLib/res/values-sl/strings.xml
+++ b/packages/SettingsLib/res/values-sl/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"Še <xliff:g id="TIME">%1$s</xliff:g> do napolnjenosti"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – še <xliff:g id="TIME">%2$s</xliff:g> do napolnjenosti"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> – Polnjenje je začasno zaustavljeno"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – polnjenje je začasno zaustavljeno"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – polnjenje do <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Neznano"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Polnjenje"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Hitro polnjenje"</string>
diff --git a/packages/SettingsLib/res/values-sq/strings.xml b/packages/SettingsLib/res/values-sq/strings.xml
index d467eea..54a8361 100644
--- a/packages/SettingsLib/res/values-sq/strings.xml
+++ b/packages/SettingsLib/res/values-sq/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> derisa të mbushet"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g> derisa të mbushet"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Karikimi është vendosur në pauzë"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Karikimi në pauzë"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - Po karikohet deri në <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"I panjohur"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Po karikohet"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Karikim i shpejtë"</string>
diff --git a/packages/SettingsLib/res/values-sr/strings.xml b/packages/SettingsLib/res/values-sr/strings.xml
index 9cc43d9..d61938b 100644
--- a/packages/SettingsLib/res/values-sr/strings.xml
+++ b/packages/SettingsLib/res/values-sr/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> до краја пуњења"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> до краја пуњења"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> – Пуњење је заустављено"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – Пуњење је паузирано"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – пуњење до <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Непознато"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Пуни се"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Брзо се пуни"</string>
diff --git a/packages/SettingsLib/res/values-sv/strings.xml b/packages/SettingsLib/res/values-sv/strings.xml
index 89deafa..3ba4e9b 100644
--- a/packages/SettingsLib/res/values-sv/strings.xml
+++ b/packages/SettingsLib/res/values-sv/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> kvar tills fulladdat"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> kvar tills fulladdat"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Laddningen har pausats"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – Laddningen har pausats"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – Laddar till <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Okänd"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Laddar"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Laddas snabbt"</string>
diff --git a/packages/SettingsLib/res/values-sw/strings.xml b/packages/SettingsLib/res/values-sw/strings.xml
index 1fa5edd..c167697 100644
--- a/packages/SettingsLib/res/values-sw/strings.xml
+++ b/packages/SettingsLib/res/values-sw/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"Zimesalia <xliff:g id="TIME">%1$s</xliff:g> ijae chaji"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g> zimesalia ijae chaji"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Imesitisha kuchaji"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Imesitisha kuchaji"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - Itachaji hadi <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Haijulikani"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Inachaji"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Inachaji kwa kasi"</string>
diff --git a/packages/SettingsLib/res/values-ta/strings.xml b/packages/SettingsLib/res/values-ta/strings.xml
index 1b7b643..57661ba 100644
--- a/packages/SettingsLib/res/values-ta/strings.xml
+++ b/packages/SettingsLib/res/values-ta/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"முழுவதும் சார்ஜாக <xliff:g id="TIME">%1$s</xliff:g> ஆகும்"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - முழுவதும் சார்ஜாக <xliff:g id="TIME">%2$s</xliff:g> ஆகும்"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - சார்ஜ் ஏறுவது இடைநிறுத்தப்பட்டுள்ளது"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - சார்ஜிங் இடைநிறுத்தப்பட்டது"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> வரை சார்ஜ் செய்யப்படும்"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"அறியப்படாத"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"சார்ஜ் ஆகிறது"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"வேகமாக சார்ஜாகிறது"</string>
diff --git a/packages/SettingsLib/res/values-te/strings.xml b/packages/SettingsLib/res/values-te/strings.xml
index 27e9dbd..365a8f2 100644
--- a/packages/SettingsLib/res/values-te/strings.xml
+++ b/packages/SettingsLib/res/values-te/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g>లో పూర్తిగా ఛార్జ్ అవుతుంది"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g>లో పూర్తిగా ఛార్జ్ అవుతుంది"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - ఛార్జింగ్ పాజ్ చేయబడింది"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - ఛార్జింగ్ పాజ్ చేయబడింది"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> ఛార్జింగ్"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"తెలియదు"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"ఛార్జ్ అవుతోంది"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"వేగవంతమైన ఛార్జింగ్"</string>
diff --git a/packages/SettingsLib/res/values-th/strings.xml b/packages/SettingsLib/res/values-th/strings.xml
index 6b9c077..cea4dd2 100644
--- a/packages/SettingsLib/res/values-th/strings.xml
+++ b/packages/SettingsLib/res/values-th/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"อีก <xliff:g id="TIME">%1$s</xliff:g>จึงจะเต็ม"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - อีก <xliff:g id="TIME">%2$s</xliff:g> จึงจะเต็ม"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - การชาร์จหยุดชั่วคราว"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - หยุดชาร์จชั่วคราว"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - กำลังชาร์จจนถึง <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"ไม่ทราบ"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"กำลังชาร์จ"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"กำลังชาร์จอย่างเร็ว"</string>
diff --git a/packages/SettingsLib/res/values-tl/strings.xml b/packages/SettingsLib/res/values-tl/strings.xml
index fddc1d0..e4503a0 100644
--- a/packages/SettingsLib/res/values-tl/strings.xml
+++ b/packages/SettingsLib/res/values-tl/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> na lang bago mapuno"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g> na lang bago mapuno"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Naka-pause ang pag-charge"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Na-pause ang pag-charge"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - China-charge hanggang <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Hindi Kilala"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Nagcha-charge"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Mabilis na charge"</string>
diff --git a/packages/SettingsLib/res/values-tr/strings.xml b/packages/SettingsLib/res/values-tr/strings.xml
index 31dcedb8..eada480 100644
--- a/packages/SettingsLib/res/values-tr/strings.xml
+++ b/packages/SettingsLib/res/values-tr/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"Tamamen şarj olmasına <xliff:g id="TIME">%1$s</xliff:g> kaldı"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - Tamamen şarj olmasına <xliff:g id="TIME">%2$s</xliff:g> kaldı"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g>: Şarj işlemi duraklatıldı"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Şarj işlemi duraklatıldı"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> seviyesine kadar şarj ediliyor"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Bilinmiyor"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Şarj oluyor"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Hızlı şarj oluyor"</string>
diff --git a/packages/SettingsLib/res/values-uk/strings.xml b/packages/SettingsLib/res/values-uk/strings.xml
index 2fdc227..8ab8db7 100644
--- a/packages/SettingsLib/res/values-uk/strings.xml
+++ b/packages/SettingsLib/res/values-uk/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> до повного заряду"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> до повного заряду"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Заряджання призупинено"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – заряджання призупинено"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - Заряджання до <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Невідомо"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Заряджається"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Швидке заряджання"</string>
diff --git a/packages/SettingsLib/res/values-ur/strings.xml b/packages/SettingsLib/res/values-ur/strings.xml
index 82dbdb3..ebc6edc 100644
--- a/packages/SettingsLib/res/values-ur/strings.xml
+++ b/packages/SettingsLib/res/values-ur/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"‎<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>‎"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"مکمل چارج ہونے میں <xliff:g id="TIME">%1$s</xliff:g> باقی ہے"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"مکمل چارج ہونے میں <xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g> باقی ہے"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - چارجنگ موقوف ہے"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - چارجنگ موقوف کی گئی"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> چارج کیا جائے گا"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"نامعلوم"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"چارج ہو رہا ہے"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"تیزی سے چارج ہو رہا ہے"</string>
diff --git a/packages/SettingsLib/res/values-uz/strings.xml b/packages/SettingsLib/res/values-uz/strings.xml
index ab997b6..19601dd 100644
--- a/packages/SettingsLib/res/values-uz/strings.xml
+++ b/packages/SettingsLib/res/values-uz/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"Toʻlishiga <xliff:g id="TIME">%1$s</xliff:g> qoldi"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – Toʻlishiga <xliff:g id="TIME">%2$s</xliff:g> qoldi"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Quvvatlash pauza qilindi"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – Quvvatlash pauzada"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g>, <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g> gacha quvvat oladi"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Noma’lum"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Quvvat olmoqda"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Tezkor quvvat olmoqda"</string>
diff --git a/packages/SettingsLib/res/values-vi/strings.xml b/packages/SettingsLib/res/values-vi/strings.xml
index 44c820a5..f900480 100644
--- a/packages/SettingsLib/res/values-vi/strings.xml
+++ b/packages/SettingsLib/res/values-vi/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> nữa là pin đầy"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> – <xliff:g id="TIME">%2$s</xliff:g> nữa là pin đầy"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> – Đã tạm dừng sạc"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> – Đã tạm dừng sạc"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> – Sạc đến <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Không xác định"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Đang sạc"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Đang sạc nhanh"</string>
diff --git a/packages/SettingsLib/res/values-zh-rCN/strings.xml b/packages/SettingsLib/res/values-zh-rCN/strings.xml
index eae1c39..6909f22 100644
--- a/packages/SettingsLib/res/values-zh-rCN/strings.xml
+++ b/packages/SettingsLib/res/values-zh-rCN/strings.xml
@@ -141,7 +141,7 @@
     <string name="bluetooth_pairing_decline" msgid="6483118841204885890">"取消"</string>
     <string name="bluetooth_pairing_will_share_phonebook" msgid="3064334458659165176">"配对之后,所配对的设备将可以在建立连接后访问您的通讯录和通话记录。"</string>
     <string name="bluetooth_pairing_error_message" msgid="6626399020672335565">"无法与“<xliff:g id="DEVICE_NAME">%1$s</xliff:g>”进行配对。"</string>
-    <string name="bluetooth_pairing_pin_error_message" msgid="264422127613704940">"PIN 码或密钥不正确,因此无法与“<xliff:g id="DEVICE_NAME">%1$s</xliff:g>”配对。"</string>
+    <string name="bluetooth_pairing_pin_error_message" msgid="264422127613704940">"PIN 码或通行密钥不正确,因此无法与“<xliff:g id="DEVICE_NAME">%1$s</xliff:g>”配对。"</string>
     <string name="bluetooth_pairing_device_down_error_message" msgid="2554424863101358857">"无法与“<xliff:g id="DEVICE_NAME">%1$s</xliff:g>”进行通信。"</string>
     <string name="bluetooth_pairing_rejected_error_message" msgid="5943444352777314442">"<xliff:g id="DEVICE_NAME">%1$s</xliff:g> 已拒绝配对。"</string>
     <string name="bluetooth_talkback_computer" msgid="3736623135703893773">"计算机"</string>
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"还需<xliff:g id="TIME">%1$s</xliff:g>充满"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - 还需<xliff:g id="TIME">%2$s</xliff:g>充满"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - 充电已暂停"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - 已暂停充电"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - 正在充到 <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"未知"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"正在充电"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"正在快速充电"</string>
diff --git a/packages/SettingsLib/res/values-zh-rHK/strings.xml b/packages/SettingsLib/res/values-zh-rHK/strings.xml
index 4371bb3..2d59d2d 100644
--- a/packages/SettingsLib/res/values-zh-rHK/strings.xml
+++ b/packages/SettingsLib/res/values-zh-rHK/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g>後充滿電"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g>後充滿電"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - 已暫停充電"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - 已暫停充電"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - 正在充電至 <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"未知"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"充電中"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"快速充電中"</string>
diff --git a/packages/SettingsLib/res/values-zh-rTW/strings.xml b/packages/SettingsLib/res/values-zh-rTW/strings.xml
index d76a4a4..40b42fc 100644
--- a/packages/SettingsLib/res/values-zh-rTW/strings.xml
+++ b/packages/SettingsLib/res/values-zh-rTW/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g>後充飽"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g>後充飽"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - 已暫停充電"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - 已暫停充電"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - 正在充電至 <xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"不明"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"充電中"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"快速充電中"</string>
diff --git a/packages/SettingsLib/res/values-zu/strings.xml b/packages/SettingsLib/res/values-zu/strings.xml
index 4dc7651..a73f067 100644
--- a/packages/SettingsLib/res/values-zu/strings.xml
+++ b/packages/SettingsLib/res/values-zu/strings.xml
@@ -467,9 +467,8 @@
     <string name="power_charging" msgid="6727132649743436802">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="STATE">%2$s</xliff:g>"</string>
     <string name="power_remaining_charging_duration_only" msgid="8085099012811384899">"<xliff:g id="TIME">%1$s</xliff:g> okusele kuze kugcwale"</string>
     <string name="power_charging_duration" msgid="6127154952524919719">"<xliff:g id="LEVEL">%1$s</xliff:g> - <xliff:g id="TIME">%2$s</xliff:g> okusele kuze kugcwale"</string>
-    <string name="power_charging_limited" msgid="6971664137170239141">"<xliff:g id="LEVEL">%1$s</xliff:g> - Ukushaja kumisiwe okwesikhashana"</string>
-    <!-- no translation found for power_charging_future_paused (6829683663982987290) -->
-    <skip />
+    <string name="power_charging_limited" msgid="6732738149313642521">"<xliff:g id="LEVEL">%1$s</xliff:g> - Ukushaja kumiswe isikhashana"</string>
+    <string name="power_charging_future_paused" msgid="6829683663982987290">"<xliff:g id="LEVEL">%1$s</xliff:g> - Ishaja ku-<xliff:g id="DOCK_DEFENDER_THRESHOLD">%2$s</xliff:g>"</string>
     <string name="battery_info_status_unknown" msgid="268625384868401114">"Akwaziwa"</string>
     <string name="battery_info_status_charging" msgid="4279958015430387405">"Iyashaja"</string>
     <string name="battery_info_status_charging_fast" msgid="8027559755902954885">"Ishaja ngokushesha"</string>
diff --git a/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java b/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java
index 1573edb..5610ac4 100644
--- a/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java
+++ b/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java
@@ -17,6 +17,7 @@
 package com.android.settingslib;
 
 import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_FEATURES_NONE;
+import static android.app.admin.DevicePolicyManager.MTE_NOT_CONTROLLED_BY_POLICY;
 import static android.app.admin.DevicePolicyManager.PROFILE_KEYGUARD_FEATURES_AFFECT_OWNER;
 
 import android.annotation.NonNull;
@@ -733,6 +734,26 @@
     }
 
     /**
+     * Checks whether MTE (Advanced memory protection) controls are disabled by the enterprise
+     * policy.
+     */
+    @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
+    public static EnforcedAdmin checkIfMteIsDisabled(Context context) {
+        final DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
+        if (dpm.getMtePolicy() == MTE_NOT_CONTROLLED_BY_POLICY) {
+            return null;
+        }
+        EnforcedAdmin admin =
+                RestrictedLockUtils.getProfileOrDeviceOwner(
+                        context, UserHandle.of(UserHandle.USER_SYSTEM));
+        if (admin != null) {
+            return admin;
+        }
+        int profileId = getManagedProfileId(context, UserHandle.USER_SYSTEM);
+        return RestrictedLockUtils.getProfileOrDeviceOwner(context, UserHandle.of(profileId));
+    }
+
+    /**
      * Show restricted setting dialog.
      */
     @RequiresApi(Build.VERSION_CODES.TIRAMISU)
diff --git a/packages/SettingsLib/src/com/android/settingslib/enterprise/ActionDisabledByAdminControllerFactory.java b/packages/SettingsLib/src/com/android/settingslib/enterprise/ActionDisabledByAdminControllerFactory.java
index 1745379..7516d2e 100644
--- a/packages/SettingsLib/src/com/android/settingslib/enterprise/ActionDisabledByAdminControllerFactory.java
+++ b/packages/SettingsLib/src/com/android/settingslib/enterprise/ActionDisabledByAdminControllerFactory.java
@@ -28,6 +28,7 @@
 import android.hardware.biometrics.ParentalControlsUtilsInternal;
 import android.os.UserHandle;
 import android.os.UserManager;
+import android.provider.DeviceConfig;
 import android.text.TextUtils;
 
 /**
@@ -82,6 +83,12 @@
 
     private static boolean isFinancedDevice(Context context) {
         DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
+        // TODO(b/259908270): remove
+        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER,
+                DevicePolicyManager.ADD_ISFINANCED_DEVICE_FLAG,
+                DevicePolicyManager.ADD_ISFINANCED_FEVICE_DEFAULT)) {
+            return dpm.isFinancedDevice();
+        }
         return dpm.isDeviceManaged() && dpm.getDeviceOwnerType(
                 dpm.getDeviceOwnerComponentOnAnyUser()) == DEVICE_OWNER_TYPE_FINANCED;
     }
diff --git a/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java b/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java
index f4355c3..3e63052 100644
--- a/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java
+++ b/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java
@@ -161,10 +161,7 @@
      * @return {@code true} if successfully call, otherwise return {@code false}
      */
     public boolean connectDevice(MediaDevice connectDevice) {
-        MediaDevice device = null;
-        synchronized (mMediaDevicesLock) {
-            device = getMediaDeviceById(mMediaDevices, connectDevice.getId());
-        }
+        MediaDevice device = getMediaDeviceById(connectDevice.getId());
         if (device == null) {
             Log.w(TAG, "connectDevice() connectDevice not in the list!");
             return false;
@@ -277,23 +274,6 @@
     /**
      * Find the MediaDevice through id.
      *
-     * @param devices the list of MediaDevice
-     * @param id the unique id of MediaDevice
-     * @return MediaDevice
-     */
-    public MediaDevice getMediaDeviceById(List<MediaDevice> devices, String id) {
-        for (MediaDevice mediaDevice : devices) {
-            if (TextUtils.equals(mediaDevice.getId(), id)) {
-                return mediaDevice;
-            }
-        }
-        Log.i(TAG, "getMediaDeviceById() can't found device");
-        return null;
-    }
-
-    /**
-     * Find the MediaDevice from all media devices by id.
-     *
      * @param id the unique id of MediaDevice
      * @return MediaDevice
      */
@@ -305,7 +285,7 @@
                 }
             }
         }
-        Log.i(TAG, "Unable to find device " + id);
+        Log.i(TAG, "getMediaDeviceById() failed to find device with id: " + id);
         return null;
     }
 
@@ -672,10 +652,7 @@
 
         @Override
         public void onConnectedDeviceChanged(String id) {
-            MediaDevice connectDevice = null;
-            synchronized (mMediaDevicesLock) {
-                connectDevice = getMediaDeviceById(mMediaDevices, id);
-            }
+            MediaDevice connectDevice = getMediaDeviceById(id);
             connectDevice = connectDevice != null
                     ? connectDevice : updateCurrentConnectedDevice();
 
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/LocalMediaManagerTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/LocalMediaManagerTest.java
index 24bb1bc..3ec0ba6 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/LocalMediaManagerTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/LocalMediaManagerTest.java
@@ -206,8 +206,7 @@
         when(device1.getId()).thenReturn(TEST_DEVICE_ID_1);
         when(device2.getId()).thenReturn(TEST_DEVICE_ID_2);
 
-        final MediaDevice device = mLocalMediaManager
-                .getMediaDeviceById(mLocalMediaManager.mMediaDevices, TEST_DEVICE_ID_2);
+        MediaDevice device = mLocalMediaManager.getMediaDeviceById(TEST_DEVICE_ID_2);
 
         assertThat(device.getId()).isEqualTo(TEST_DEVICE_ID_2);
     }
@@ -222,8 +221,7 @@
         when(device1.getId()).thenReturn(TEST_DEVICE_ID_1);
         when(device2.getId()).thenReturn(TEST_DEVICE_ID_2);
 
-        final MediaDevice device = mLocalMediaManager
-                .getMediaDeviceById(mLocalMediaManager.mMediaDevices, TEST_CURRENT_DEVICE_ID);
+        MediaDevice device = mLocalMediaManager.getMediaDeviceById(TEST_CURRENT_DEVICE_ID);
 
         assertThat(device).isNull();
     }
@@ -238,12 +236,7 @@
         when(device1.getId()).thenReturn(null);
         when(device2.getId()).thenReturn(null);
 
-        MediaDevice device = mLocalMediaManager
-                .getMediaDeviceById(mLocalMediaManager.mMediaDevices, TEST_CURRENT_DEVICE_ID);
-
-        assertThat(device).isNull();
-
-        device = mLocalMediaManager.getMediaDeviceById(TEST_CURRENT_DEVICE_ID);
+        MediaDevice device = mLocalMediaManager.getMediaDeviceById(TEST_CURRENT_DEVICE_ID);
 
         assertThat(device).isNull();
     }
diff --git a/packages/SettingsProvider/res/xml/bookmarks.xml b/packages/SettingsProvider/res/xml/bookmarks.xml
index 454f456..4b97b47 100644
--- a/packages/SettingsProvider/res/xml/bookmarks.xml
+++ b/packages/SettingsProvider/res/xml/bookmarks.xml
@@ -19,7 +19,6 @@
      Bookmarks for vendor apps should be added to a bookmarks resource overlay; not here.
 
      Typical shortcuts (not necessarily defined here):
-       'a': Calculator
        'b': Browser
        'c': Contacts
        'e': Email
@@ -29,13 +28,11 @@
        'p': Music
        's': SMS
        't': Talk
+       'u': Calculator
        'y': YouTube
 -->
 <bookmarks>
     <bookmark
-        category="android.intent.category.APP_CALCULATOR"
-        shortcut="a" />
-    <bookmark
         category="android.intent.category.APP_BROWSER"
         shortcut="b" />
     <bookmark
@@ -46,7 +43,7 @@
         shortcut="e" />
     <bookmark
         category="android.intent.category.APP_CALENDAR"
-        shortcut="l" />
+        shortcut="k" />
     <bookmark
         category="android.intent.category.APP_MAPS"
         shortcut="m" />
@@ -56,4 +53,7 @@
     <bookmark
         category="android.intent.category.APP_MESSAGING"
         shortcut="s" />
+    <bookmark
+        category="android.intent.category.APP_CALCULATOR"
+        shortcut="u" />
 </bookmarks>
diff --git a/packages/SettingsProvider/src/android/provider/settings/validators/SystemSettingsValidators.java b/packages/SettingsProvider/src/android/provider/settings/validators/SystemSettingsValidators.java
index 3e5802e..2ee890f 100644
--- a/packages/SettingsProvider/src/android/provider/settings/validators/SystemSettingsValidators.java
+++ b/packages/SettingsProvider/src/android/provider/settings/validators/SystemSettingsValidators.java
@@ -111,7 +111,6 @@
                 });
         VALIDATORS.put(System.DISPLAY_COLOR_MODE_VENDOR_HINT, ANY_STRING_VALIDATOR);
         VALIDATORS.put(System.SCREEN_OFF_TIMEOUT, NON_NEGATIVE_INTEGER_VALIDATOR);
-        VALIDATORS.put(System.SCREEN_BRIGHTNESS_FOR_VR, new InclusiveIntegerRangeValidator(0, 255));
         VALIDATORS.put(System.SCREEN_BRIGHTNESS_MODE, BOOLEAN_VALIDATOR);
         VALIDATORS.put(System.ADAPTIVE_SLEEP, BOOLEAN_VALIDATOR);
         VALIDATORS.put(System.MODE_RINGER_STREAMS_AFFECTED, NON_NEGATIVE_INTEGER_VALIDATOR);
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
index 85d0b18..7477416 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
@@ -33,7 +33,6 @@
 import android.net.ConnectivityManager;
 import android.os.Build;
 import android.os.Environment;
-import android.os.RemoteException;
 import android.os.SystemProperties;
 import android.os.UserHandle;
 import android.provider.Settings;
@@ -2243,9 +2242,6 @@
             loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS,
                     R.integer.def_screen_brightness);
 
-            loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_FOR_VR,
-                    com.android.internal.R.integer.config_screenBrightnessForVrSettingDefault);
-
             loadBooleanSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_MODE,
                     R.bool.def_screen_brightness_automatic_mode);
 
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java
index 17078c4..8d4a35d 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java
@@ -2841,9 +2841,6 @@
                 Settings.System.SCREEN_BRIGHTNESS,
                 SystemSettingsProto.Screen.BRIGHTNESS);
         dumpSetting(s, p,
-                Settings.System.SCREEN_BRIGHTNESS_FOR_VR,
-                SystemSettingsProto.Screen.BRIGHTNESS_FOR_VR);
-        dumpSetting(s, p,
                 Settings.System.SCREEN_BRIGHTNESS_MODE,
                 SystemSettingsProto.Screen.BRIGHTNESS_MODE);
         dumpSetting(s, p,
@@ -2852,9 +2849,6 @@
         dumpSetting(s, p,
                 Settings.System.SCREEN_BRIGHTNESS_FLOAT,
                 SystemSettingsProto.Screen.BRIGHTNESS_FLOAT);
-        dumpSetting(s, p,
-                Settings.System.SCREEN_BRIGHTNESS_FOR_VR_FLOAT,
-                SystemSettingsProto.Screen.BRIGHTNESS_FOR_VR_FLOAT);
         p.end(screenToken);
 
         dumpSetting(s, p,
diff --git a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java
index 153f0b4..4365a9b 100644
--- a/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java
+++ b/packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java
@@ -100,8 +100,6 @@
                     Settings.System.MIN_REFRESH_RATE, // depends on hardware capabilities
                     Settings.System.PEAK_REFRESH_RATE, // depends on hardware capabilities
                     Settings.System.SCREEN_BRIGHTNESS_FLOAT,
-                    Settings.System.SCREEN_BRIGHTNESS_FOR_VR,
-                    Settings.System.SCREEN_BRIGHTNESS_FOR_VR_FLOAT,
                     Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ,
                     Settings.System.MULTI_AUDIO_FOCUS_ENABLED // form-factor/OEM specific
                     );
@@ -427,6 +425,7 @@
                     Settings.Global.RESTRICTED_NETWORKING_MODE,
                     Settings.Global.REQUIRE_PASSWORD_TO_DECRYPT,
                     Settings.Global.SAFE_BOOT_DISALLOWED,
+                    Settings.Global.SECURE_FRP_MODE,
                     Settings.Global.SELINUX_STATUS,
                     Settings.Global.SELINUX_UPDATE_CONTENT_URL,
                     Settings.Global.SELINUX_UPDATE_METADATA_URL,
diff --git a/packages/Shell/AndroidManifest.xml b/packages/Shell/AndroidManifest.xml
index d3ba5e6..47794b8 100644
--- a/packages/Shell/AndroidManifest.xml
+++ b/packages/Shell/AndroidManifest.xml
@@ -23,6 +23,7 @@
         >
 
         <!-- Standard permissions granted to the shell. -->
+    <uses-permission android:name="android.permission.MANAGE_HEALTH_DATA" />
     <uses-permission android:name="android.permission.LAUNCH_DEVICE_MANAGER_SETUP" />
     <uses-permission android:name="android.permission.GET_RUNTIME_PERMISSIONS" />
     <uses-permission android:name="android.permission.SEND_SMS" />
@@ -321,7 +322,9 @@
     <uses-permission android:name="android.permission.REQUEST_COMPANION_PROFILE_APP_STREAMING" />
     <uses-permission android:name="android.permission.REQUEST_COMPANION_PROFILE_COMPUTER" />
     <uses-permission android:name="android.permission.REQUEST_COMPANION_PROFILE_AUTOMOTIVE_PROJECTION" />
+    <uses-permission android:name="android.permission.REQUEST_COMPANION_PROFILE_NEARBY_DEVICE_STREAMING" />
     <uses-permission android:name="android.permission.REQUEST_COMPANION_PROFILE_WATCH" />
+    <uses-permission android:name="android.permission.REQUEST_COMPANION_PROFILE_GLASSES" />
     <uses-permission android:name="android.permission.REQUEST_COMPANION_SELF_MANAGED" />
 
     <uses-permission android:name="android.permission.MANAGE_APPOPS" />
@@ -360,6 +363,9 @@
     <!-- Permission needed to test wallpaper dimming -->
     <uses-permission android:name="android.permission.SET_WALLPAPER_DIM_AMOUNT" />
 
+    <!-- Permission needed to test wallpapers supporting ambient mode -->
+    <uses-permission android:name="android.permission.AMBIENT_WALLPAPER" />
+
     <!-- Permission required to test ContentResolver caching. -->
     <uses-permission android:name="android.permission.CACHE_CONTENT" />
 
@@ -774,79 +780,8 @@
     <!-- Permissions required for CTS test - CtsAppFgsTestCases -->
     <uses-permission android:name="android.permission.USE_EXACT_ALARM" />
 
-    <!-- Permissions required for CTS test - CtsAppFgsTestCases -->
-    <uses-permission android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED" />
-    <uses-permission android:name="android.permission.health.READ_BASAL_BODY_TEMPERATURE" />
-    <uses-permission android:name="android.permission.health.READ_BASAL_METABOLIC_RATE" />
-    <uses-permission android:name="android.permission.health.READ_BLOOD_GLUCOSE" />
-    <uses-permission android:name="android.permission.health.READ_BLOOD_PRESSURE" />
-    <uses-permission android:name="android.permission.health.READ_BODY_FAT" />
-    <uses-permission android:name="android.permission.health.READ_BODY_TEMPERATURE" />
-    <uses-permission android:name="android.permission.health.READ_BODY_WATER_MASS" />
-    <uses-permission android:name="android.permission.health.READ_BONE_MASS" />
-    <uses-permission android:name="android.permission.health.READ_CERVICAL_MUCUS" />
-    <uses-permission android:name="android.permission.health.READ_DISTANCE" />
-    <uses-permission android:name="android.permission.health.READ_ELEVATION_GAINED" />
-    <uses-permission android:name="android.permission.health.READ_EXERCISE" />
-    <uses-permission android:name="android.permission.health.READ_FLOORS_CLIMBED" />
-    <uses-permission android:name="android.permission.health.READ_HEART_RATE" />
-    <uses-permission android:name="android.permission.health.READ_HEART_RATE_VARIABILITY" />
-    <uses-permission android:name="android.permission.health.READ_HEIGHT" />
-    <uses-permission android:name="android.permission.health.READ_HIP_CIRCUMFERENCE" />
-    <uses-permission android:name="android.permission.health.READ_HYDRATION" />
-    <uses-permission android:name="android.permission.health.READ_LEAN_BODY_MASS" />
-    <uses-permission android:name="android.permission.health.READ_MENSTRUATION" />
-    <uses-permission android:name="android.permission.health.READ_NUTRITION" />
-    <uses-permission android:name="android.permission.health.READ_OVULATION_TEST" />
-    <uses-permission android:name="android.permission.health.READ_OXYGEN_SATURATION" />
-    <uses-permission android:name="android.permission.health.READ_POWER" />
-    <uses-permission android:name="android.permission.health.READ_RESPIRATORY_RATE" />
-    <uses-permission android:name="android.permission.health.READ_RESTING_HEART_RATE" />
-    <uses-permission android:name="android.permission.health.READ_SEXUAL_ACTIVITY" />
-    <uses-permission android:name="android.permission.health.READ_SLEEP" />
-    <uses-permission android:name="android.permission.health.READ_SPEED" />
-    <uses-permission android:name="android.permission.health.READ_STEPS" />
-    <uses-permission android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED" />
-    <uses-permission android:name="android.permission.health.READ_VO2_MAX" />
-    <uses-permission android:name="android.permission.health.READ_WAIST_CIRCUMFERENCE" />
-    <uses-permission android:name="android.permission.health.READ_WEIGHT" />
-    <uses-permission android:name="android.permission.health.READ_WHEELCHAIR_PUSHES" />
-    <uses-permission android:name="android.permission.health.WRITE_ACTIVE_CALORIES_BURNED" />
-    <uses-permission android:name="android.permission.health.WRITE_BASAL_BODY_TEMPERATURE" />
-    <uses-permission android:name="android.permission.health.WRITE_BASAL_METABOLIC_RATE" />
-    <uses-permission android:name="android.permission.health.WRITE_BLOOD_GLUCOSE" />
-    <uses-permission android:name="android.permission.health.WRITE_BLOOD_PRESSURE" />
-    <uses-permission android:name="android.permission.health.WRITE_BODY_FAT" />
-    <uses-permission android:name="android.permission.health.WRITE_BODY_TEMPERATURE" />
-    <uses-permission android:name="android.permission.health.WRITE_BODY_WATER_MASS" />
-    <uses-permission android:name="android.permission.health.WRITE_BONE_MASS" />
-    <uses-permission android:name="android.permission.health.WRITE_CERVICAL_MUCUS" />
-    <uses-permission android:name="android.permission.health.WRITE_DISTANCE" />
-    <uses-permission android:name="android.permission.health.WRITE_ELEVATION_GAINED" />
-    <uses-permission android:name="android.permission.health.WRITE_EXERCISE" />
-    <uses-permission android:name="android.permission.health.WRITE_FLOORS_CLIMBED" />
-    <uses-permission android:name="android.permission.health.WRITE_HEART_RATE" />
-    <uses-permission android:name="android.permission.health.WRITE_HEART_RATE_VARIABILITY" />
-    <uses-permission android:name="android.permission.health.WRITE_HEIGHT" />
-    <uses-permission android:name="android.permission.health.WRITE_HIP_CIRCUMFERENCE" />
-    <uses-permission android:name="android.permission.health.WRITE_HYDRATION" />
-    <uses-permission android:name="android.permission.health.WRITE_LEAN_BODY_MASS" />
-    <uses-permission android:name="android.permission.health.WRITE_MENSTRUATION" />
-    <uses-permission android:name="android.permission.health.WRITE_NUTRITION" />
-    <uses-permission android:name="android.permission.health.WRITE_OVULATION_TEST" />
-    <uses-permission android:name="android.permission.health.WRITE_OXYGEN_SATURATION" />
-    <uses-permission android:name="android.permission.health.WRITE_POWER" />
-    <uses-permission android:name="android.permission.health.WRITE_RESPIRATORY_RATE" />
-    <uses-permission android:name="android.permission.health.WRITE_RESTING_HEART_RATE" />
-    <uses-permission android:name="android.permission.health.WRITE_SEXUAL_ACTIVITY" />
-    <uses-permission android:name="android.permission.health.WRITE_SLEEP" />
-    <uses-permission android:name="android.permission.health.WRITE_SPEED" />
-    <uses-permission android:name="android.permission.health.WRITE_STEPS" />
-    <uses-permission android:name="android.permission.health.WRITE_TOTAL_CALORIES_BURNED" />
-    <uses-permission android:name="android.permission.health.WRITE_VO2_MAX" />
-    <uses-permission android:name="android.permission.health.WRITE_WAIST_CIRCUMFERENCE" />
-    <uses-permission android:name="android.permission.health.WRITE_WEIGHT" />
-    <uses-permission android:name="android.permission.health.WRITE_WHEELCHAIR_PUSHES" />
+    <!-- Permission required for CTS test - CtsHardwareTestCases -->
+    <uses-permission android:name="android.permission.REMAP_MODIFIER_KEYS" />
 
     <!-- Permission required for CTS test - ApplicationExemptionsTests -->
     <uses-permission android:name="android.permission.MANAGE_DEVICE_POLICY_APP_EXEMPTIONS" />
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml
index a8216e8..6984b5a 100644
--- a/packages/SystemUI/AndroidManifest.xml
+++ b/packages/SystemUI/AndroidManifest.xml
@@ -23,11 +23,6 @@
         xmlns:tools="http://schemas.android.com/tools"
         coreApp="true">
 
-    <!-- Using OpenGL ES 2.0 -->
-    <uses-feature
-        android:glEsVersion="0x00020000"
-        android:required="true" />
-
     <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
 
     <!-- Used to read wallpaper -->
@@ -416,6 +411,7 @@
 
         <service android:name=".screenshot.ScreenshotCrossProfileService"
                  android:permission="com.android.systemui.permission.SELF"
+                 android:process=":screenshot_cross_profile"
                  android:exported="false" />
 
         <service android:name=".screenrecord.RecordingService" />
diff --git a/packages/SystemUI/TEST_MAPPING b/packages/SystemUI/TEST_MAPPING
index aaee42f..f92625b 100644
--- a/packages/SystemUI/TEST_MAPPING
+++ b/packages/SystemUI/TEST_MAPPING
@@ -33,6 +33,18 @@
       ]
     },
     {
+      // TODO(b/251476085): Consider merging with SystemUIGoogleScreenshotTests (in U+)
+      "name": "SystemUIGoogleBiometricsScreenshotTests",
+      "options": [
+        {
+          "exclude-annotation": "org.junit.Ignore"
+        },
+        {
+          "exclude-annotation": "androidx.test.filters.FlakyTest"
+        }
+      ]
+    },
+    {
       // Permission indicators
       "name": "CtsPermission4TestCases",
       "options": [
diff --git a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/MultiRippleController.kt b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/MultiRippleController.kt
index 93e78ac..8cd8bf6 100644
--- a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/MultiRippleController.kt
+++ b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/MultiRippleController.kt
@@ -21,9 +21,20 @@
 /** Controller that handles playing [RippleAnimation]. */
 class MultiRippleController(private val multipleRippleView: MultiRippleView) {
 
+    private val ripplesFinishedListeners = ArrayList<RipplesFinishedListener>()
+
     companion object {
         /** Max number of ripple animations at a time. */
         @VisibleForTesting const val MAX_RIPPLE_NUMBER = 10
+
+        interface RipplesFinishedListener {
+            /** Triggered when all the ripples finish running. */
+            fun onRipplesFinish()
+        }
+    }
+
+    fun addRipplesFinishedListener(listener: RipplesFinishedListener) {
+        ripplesFinishedListeners.add(listener)
     }
 
     /** Updates all the ripple colors during the animation. */
@@ -38,8 +49,13 @@
 
         multipleRippleView.ripples.add(rippleAnimation)
 
-        // Remove ripple once the animation is done
-        rippleAnimation.play { multipleRippleView.ripples.remove(rippleAnimation) }
+        rippleAnimation.play {
+            // Remove ripple once the animation is done
+            multipleRippleView.ripples.remove(rippleAnimation)
+            if (multipleRippleView.ripples.isEmpty()) {
+                ripplesFinishedListeners.forEach { listener -> listener.onRipplesFinish() }
+            }
+        }
 
         // Trigger drawing
         multipleRippleView.invalidate()
diff --git a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/MultiRippleView.kt b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/MultiRippleView.kt
index b8dc223..550d2c6 100644
--- a/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/MultiRippleView.kt
+++ b/packages/SystemUI/animation/src/com/android/systemui/surfaceeffects/ripple/MultiRippleView.kt
@@ -33,21 +33,11 @@
 
     @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
     val ripples = ArrayList<RippleAnimation>()
-    private val listeners = ArrayList<RipplesFinishedListener>()
     private val ripplePaint = Paint()
     private var isWarningLogged = false
 
     companion object {
         private const val TAG = "MultiRippleView"
-
-        interface RipplesFinishedListener {
-            /** Triggered when all the ripples finish running. */
-            fun onRipplesFinish()
-        }
-    }
-
-    fun addRipplesFinishedListener(listener: RipplesFinishedListener) {
-        listeners.add(listener)
     }
 
     override fun onDraw(canvas: Canvas?) {
@@ -76,8 +66,6 @@
 
         if (shouldInvalidate) {
             invalidate()
-        } else { // Nothing is playing.
-            listeners.forEach { listener -> listener.onRipplesFinish() }
         }
     }
 }
diff --git a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/SystemUITheme.kt b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/SystemUITheme.kt
index 79e3d3d..00532f4 100644
--- a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/SystemUITheme.kt
+++ b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/SystemUITheme.kt
@@ -18,12 +18,17 @@
 
 import androidx.compose.foundation.isSystemInDarkTheme
 import androidx.compose.material3.MaterialTheme
-import androidx.compose.material3.Typography
 import androidx.compose.material3.dynamicDarkColorScheme
 import androidx.compose.material3.dynamicLightColorScheme
 import androidx.compose.runtime.Composable
 import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.runtime.remember
 import androidx.compose.ui.platform.LocalContext
+import com.android.systemui.compose.theme.typography.TypeScaleTokens
+import com.android.systemui.compose.theme.typography.TypefaceNames
+import com.android.systemui.compose.theme.typography.TypefaceTokens
+import com.android.systemui.compose.theme.typography.TypographyTokens
+import com.android.systemui.compose.theme.typography.systemUITypography
 
 /** The Material 3 theme that should wrap all SystemUI Composables. */
 @Composable
@@ -33,7 +38,7 @@
 ) {
     val context = LocalContext.current
 
-    // TODO(b/230605885): Define our typography and color scheme.
+    // TODO(b/230605885): Define our color scheme.
     val colorScheme =
         if (isDarkTheme) {
             dynamicDarkColorScheme(context)
@@ -41,7 +46,11 @@
             dynamicLightColorScheme(context)
         }
     val androidColorScheme = AndroidColorScheme(context)
-    val typography = Typography()
+    val typefaceNames = remember(context) { TypefaceNames.get(context) }
+    val typography =
+        remember(typefaceNames) {
+            systemUITypography(TypographyTokens(TypeScaleTokens(TypefaceTokens(typefaceNames))))
+        }
 
     MaterialTheme(colorScheme, typography = typography) {
         CompositionLocalProvider(
diff --git a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/SystemUITypography.kt b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/SystemUITypography.kt
new file mode 100644
index 0000000..365f4bb
--- /dev/null
+++ b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/SystemUITypography.kt
@@ -0,0 +1,46 @@
+/*
+ * 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.systemui.compose.theme.typography
+
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Typography
+
+/**
+ * The SystemUI typography.
+ *
+ * Do not use directly and call [MaterialTheme.typography] instead to access the different text
+ * styles.
+ */
+internal fun systemUITypography(typographyTokens: TypographyTokens): Typography {
+    return Typography(
+        displayLarge = typographyTokens.displayLarge,
+        displayMedium = typographyTokens.displayMedium,
+        displaySmall = typographyTokens.displaySmall,
+        headlineLarge = typographyTokens.headlineLarge,
+        headlineMedium = typographyTokens.headlineMedium,
+        headlineSmall = typographyTokens.headlineSmall,
+        titleLarge = typographyTokens.titleLarge,
+        titleMedium = typographyTokens.titleMedium,
+        titleSmall = typographyTokens.titleSmall,
+        bodyLarge = typographyTokens.bodyLarge,
+        bodyMedium = typographyTokens.bodyMedium,
+        bodySmall = typographyTokens.bodySmall,
+        labelLarge = typographyTokens.labelLarge,
+        labelMedium = typographyTokens.labelMedium,
+        labelSmall = typographyTokens.labelSmall,
+    )
+}
diff --git a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypeScaleTokens.kt b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypeScaleTokens.kt
new file mode 100644
index 0000000..537ba0b
--- /dev/null
+++ b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypeScaleTokens.kt
@@ -0,0 +1,97 @@
+/*
+ * 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.systemui.compose.theme.typography
+
+import androidx.compose.ui.unit.sp
+
+internal class TypeScaleTokens(typefaceTokens: TypefaceTokens) {
+    val bodyLargeFont = typefaceTokens.plain
+    val bodyLargeLineHeight = 24.0.sp
+    val bodyLargeSize = 16.sp
+    val bodyLargeTracking = 0.0.sp
+    val bodyLargeWeight = TypefaceTokens.WeightRegular
+    val bodyMediumFont = typefaceTokens.plain
+    val bodyMediumLineHeight = 20.0.sp
+    val bodyMediumSize = 14.sp
+    val bodyMediumTracking = 0.0.sp
+    val bodyMediumWeight = TypefaceTokens.WeightRegular
+    val bodySmallFont = typefaceTokens.plain
+    val bodySmallLineHeight = 16.0.sp
+    val bodySmallSize = 12.sp
+    val bodySmallTracking = 0.1.sp
+    val bodySmallWeight = TypefaceTokens.WeightRegular
+    val displayLargeFont = typefaceTokens.brand
+    val displayLargeLineHeight = 64.0.sp
+    val displayLargeSize = 57.sp
+    val displayLargeTracking = 0.0.sp
+    val displayLargeWeight = TypefaceTokens.WeightRegular
+    val displayMediumFont = typefaceTokens.brand
+    val displayMediumLineHeight = 52.0.sp
+    val displayMediumSize = 45.sp
+    val displayMediumTracking = 0.0.sp
+    val displayMediumWeight = TypefaceTokens.WeightRegular
+    val displaySmallFont = typefaceTokens.brand
+    val displaySmallLineHeight = 44.0.sp
+    val displaySmallSize = 36.sp
+    val displaySmallTracking = 0.0.sp
+    val displaySmallWeight = TypefaceTokens.WeightRegular
+    val headlineLargeFont = typefaceTokens.brand
+    val headlineLargeLineHeight = 40.0.sp
+    val headlineLargeSize = 32.sp
+    val headlineLargeTracking = 0.0.sp
+    val headlineLargeWeight = TypefaceTokens.WeightRegular
+    val headlineMediumFont = typefaceTokens.brand
+    val headlineMediumLineHeight = 36.0.sp
+    val headlineMediumSize = 28.sp
+    val headlineMediumTracking = 0.0.sp
+    val headlineMediumWeight = TypefaceTokens.WeightRegular
+    val headlineSmallFont = typefaceTokens.brand
+    val headlineSmallLineHeight = 32.0.sp
+    val headlineSmallSize = 24.sp
+    val headlineSmallTracking = 0.0.sp
+    val headlineSmallWeight = TypefaceTokens.WeightRegular
+    val labelLargeFont = typefaceTokens.plain
+    val labelLargeLineHeight = 20.0.sp
+    val labelLargeSize = 14.sp
+    val labelLargeTracking = 0.0.sp
+    val labelLargeWeight = TypefaceTokens.WeightMedium
+    val labelMediumFont = typefaceTokens.plain
+    val labelMediumLineHeight = 16.0.sp
+    val labelMediumSize = 12.sp
+    val labelMediumTracking = 0.1.sp
+    val labelMediumWeight = TypefaceTokens.WeightMedium
+    val labelSmallFont = typefaceTokens.plain
+    val labelSmallLineHeight = 16.0.sp
+    val labelSmallSize = 11.sp
+    val labelSmallTracking = 0.1.sp
+    val labelSmallWeight = TypefaceTokens.WeightMedium
+    val titleLargeFont = typefaceTokens.brand
+    val titleLargeLineHeight = 28.0.sp
+    val titleLargeSize = 22.sp
+    val titleLargeTracking = 0.0.sp
+    val titleLargeWeight = TypefaceTokens.WeightRegular
+    val titleMediumFont = typefaceTokens.plain
+    val titleMediumLineHeight = 24.0.sp
+    val titleMediumSize = 16.sp
+    val titleMediumTracking = 0.0.sp
+    val titleMediumWeight = TypefaceTokens.WeightMedium
+    val titleSmallFont = typefaceTokens.plain
+    val titleSmallLineHeight = 20.0.sp
+    val titleSmallSize = 14.sp
+    val titleSmallTracking = 0.0.sp
+    val titleSmallWeight = TypefaceTokens.WeightMedium
+}
diff --git a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypefaceTokens.kt b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypefaceTokens.kt
new file mode 100644
index 0000000..f3d554f
--- /dev/null
+++ b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypefaceTokens.kt
@@ -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.
+ */
+
+@file:OptIn(ExperimentalTextApi::class)
+
+package com.android.systemui.compose.theme.typography
+
+import android.content.Context
+import androidx.compose.ui.text.ExperimentalTextApi
+import androidx.compose.ui.text.font.DeviceFontFamilyName
+import androidx.compose.ui.text.font.Font
+import androidx.compose.ui.text.font.FontFamily
+import androidx.compose.ui.text.font.FontWeight
+
+internal class TypefaceTokens(typefaceNames: TypefaceNames) {
+    companion object {
+        val WeightMedium = FontWeight.Medium
+        val WeightRegular = FontWeight.Normal
+    }
+
+    private val brandFont = DeviceFontFamilyName(typefaceNames.brand)
+    private val plainFont = DeviceFontFamilyName(typefaceNames.plain)
+
+    val brand =
+        FontFamily(
+            Font(brandFont, weight = WeightMedium),
+            Font(brandFont, weight = WeightRegular),
+        )
+    val plain =
+        FontFamily(
+            Font(plainFont, weight = WeightMedium),
+            Font(plainFont, weight = WeightRegular),
+        )
+}
+
+internal data class TypefaceNames
+private constructor(
+    val brand: String,
+    val plain: String,
+) {
+    private enum class Config(val configName: String, val default: String) {
+        Brand("config_headlineFontFamily", "sans-serif"),
+        Plain("config_bodyFontFamily", "sans-serif"),
+    }
+
+    companion object {
+        fun get(context: Context): TypefaceNames {
+            return TypefaceNames(
+                brand = getTypefaceName(context, Config.Brand),
+                plain = getTypefaceName(context, Config.Plain),
+            )
+        }
+
+        private fun getTypefaceName(context: Context, config: Config): String {
+            return context
+                .getString(context.resources.getIdentifier(config.configName, "string", "android"))
+                .takeIf { it.isNotEmpty() }
+                ?: config.default
+        }
+    }
+}
diff --git a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypographyTokens.kt b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypographyTokens.kt
new file mode 100644
index 0000000..55f3d1f
--- /dev/null
+++ b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypographyTokens.kt
@@ -0,0 +1,142 @@
+/*
+ * 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.systemui.compose.theme.typography
+
+import androidx.compose.ui.text.TextStyle
+
+internal class TypographyTokens(typeScaleTokens: TypeScaleTokens) {
+    val bodyLarge =
+        TextStyle(
+            fontFamily = typeScaleTokens.bodyLargeFont,
+            fontWeight = typeScaleTokens.bodyLargeWeight,
+            fontSize = typeScaleTokens.bodyLargeSize,
+            lineHeight = typeScaleTokens.bodyLargeLineHeight,
+            letterSpacing = typeScaleTokens.bodyLargeTracking,
+        )
+    val bodyMedium =
+        TextStyle(
+            fontFamily = typeScaleTokens.bodyMediumFont,
+            fontWeight = typeScaleTokens.bodyMediumWeight,
+            fontSize = typeScaleTokens.bodyMediumSize,
+            lineHeight = typeScaleTokens.bodyMediumLineHeight,
+            letterSpacing = typeScaleTokens.bodyMediumTracking,
+        )
+    val bodySmall =
+        TextStyle(
+            fontFamily = typeScaleTokens.bodySmallFont,
+            fontWeight = typeScaleTokens.bodySmallWeight,
+            fontSize = typeScaleTokens.bodySmallSize,
+            lineHeight = typeScaleTokens.bodySmallLineHeight,
+            letterSpacing = typeScaleTokens.bodySmallTracking,
+        )
+    val displayLarge =
+        TextStyle(
+            fontFamily = typeScaleTokens.displayLargeFont,
+            fontWeight = typeScaleTokens.displayLargeWeight,
+            fontSize = typeScaleTokens.displayLargeSize,
+            lineHeight = typeScaleTokens.displayLargeLineHeight,
+            letterSpacing = typeScaleTokens.displayLargeTracking,
+        )
+    val displayMedium =
+        TextStyle(
+            fontFamily = typeScaleTokens.displayMediumFont,
+            fontWeight = typeScaleTokens.displayMediumWeight,
+            fontSize = typeScaleTokens.displayMediumSize,
+            lineHeight = typeScaleTokens.displayMediumLineHeight,
+            letterSpacing = typeScaleTokens.displayMediumTracking,
+        )
+    val displaySmall =
+        TextStyle(
+            fontFamily = typeScaleTokens.displaySmallFont,
+            fontWeight = typeScaleTokens.displaySmallWeight,
+            fontSize = typeScaleTokens.displaySmallSize,
+            lineHeight = typeScaleTokens.displaySmallLineHeight,
+            letterSpacing = typeScaleTokens.displaySmallTracking,
+        )
+    val headlineLarge =
+        TextStyle(
+            fontFamily = typeScaleTokens.headlineLargeFont,
+            fontWeight = typeScaleTokens.headlineLargeWeight,
+            fontSize = typeScaleTokens.headlineLargeSize,
+            lineHeight = typeScaleTokens.headlineLargeLineHeight,
+            letterSpacing = typeScaleTokens.headlineLargeTracking,
+        )
+    val headlineMedium =
+        TextStyle(
+            fontFamily = typeScaleTokens.headlineMediumFont,
+            fontWeight = typeScaleTokens.headlineMediumWeight,
+            fontSize = typeScaleTokens.headlineMediumSize,
+            lineHeight = typeScaleTokens.headlineMediumLineHeight,
+            letterSpacing = typeScaleTokens.headlineMediumTracking,
+        )
+    val headlineSmall =
+        TextStyle(
+            fontFamily = typeScaleTokens.headlineSmallFont,
+            fontWeight = typeScaleTokens.headlineSmallWeight,
+            fontSize = typeScaleTokens.headlineSmallSize,
+            lineHeight = typeScaleTokens.headlineSmallLineHeight,
+            letterSpacing = typeScaleTokens.headlineSmallTracking,
+        )
+    val labelLarge =
+        TextStyle(
+            fontFamily = typeScaleTokens.labelLargeFont,
+            fontWeight = typeScaleTokens.labelLargeWeight,
+            fontSize = typeScaleTokens.labelLargeSize,
+            lineHeight = typeScaleTokens.labelLargeLineHeight,
+            letterSpacing = typeScaleTokens.labelLargeTracking,
+        )
+    val labelMedium =
+        TextStyle(
+            fontFamily = typeScaleTokens.labelMediumFont,
+            fontWeight = typeScaleTokens.labelMediumWeight,
+            fontSize = typeScaleTokens.labelMediumSize,
+            lineHeight = typeScaleTokens.labelMediumLineHeight,
+            letterSpacing = typeScaleTokens.labelMediumTracking,
+        )
+    val labelSmall =
+        TextStyle(
+            fontFamily = typeScaleTokens.labelSmallFont,
+            fontWeight = typeScaleTokens.labelSmallWeight,
+            fontSize = typeScaleTokens.labelSmallSize,
+            lineHeight = typeScaleTokens.labelSmallLineHeight,
+            letterSpacing = typeScaleTokens.labelSmallTracking,
+        )
+    val titleLarge =
+        TextStyle(
+            fontFamily = typeScaleTokens.titleLargeFont,
+            fontWeight = typeScaleTokens.titleLargeWeight,
+            fontSize = typeScaleTokens.titleLargeSize,
+            lineHeight = typeScaleTokens.titleLargeLineHeight,
+            letterSpacing = typeScaleTokens.titleLargeTracking,
+        )
+    val titleMedium =
+        TextStyle(
+            fontFamily = typeScaleTokens.titleMediumFont,
+            fontWeight = typeScaleTokens.titleMediumWeight,
+            fontSize = typeScaleTokens.titleMediumSize,
+            lineHeight = typeScaleTokens.titleMediumLineHeight,
+            letterSpacing = typeScaleTokens.titleMediumTracking,
+        )
+    val titleSmall =
+        TextStyle(
+            fontFamily = typeScaleTokens.titleSmallFont,
+            fontWeight = typeScaleTokens.titleSmallWeight,
+            fontSize = typeScaleTokens.titleSmallSize,
+            lineHeight = typeScaleTokens.titleSmallLineHeight,
+            letterSpacing = typeScaleTokens.titleSmallTracking,
+        )
+}
diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt
index c540f0f..e138ef8 100644
--- a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt
+++ b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt
@@ -20,6 +20,7 @@
 import android.icu.text.NumberFormat
 import android.util.TypedValue
 import android.view.LayoutInflater
+import android.view.View
 import android.widget.FrameLayout
 import androidx.annotation.VisibleForTesting
 import com.android.systemui.customization.R
@@ -151,9 +152,15 @@
         view: AnimatableClockView,
     ) : DefaultClockFaceController(view) {
         override fun recomputePadding(targetRegion: Rect?) {
-            // Ignore Target Region until top padding fixed in aod
+            // We center the view within the targetRegion instead of within the parent
+            // view by computing the difference and adding that to the padding.
+            val parent = view.parent
+            val yDiff =
+                if (targetRegion != null && parent is View && parent.isLaidOut())
+                    targetRegion.centerY() - parent.height / 2f
+                else 0f
             val lp = view.getLayoutParams() as FrameLayout.LayoutParams
-            lp.topMargin = (-0.5f * view.bottom).toInt()
+            lp.topMargin = (-0.5f * view.bottom + yDiff).toInt()
             view.setLayoutParams(lp)
         }
 
diff --git a/packages/SystemUI/res-keyguard/layout/fgs_footer.xml b/packages/SystemUI/res-keyguard/layout/fgs_footer.xml
deleted file mode 100644
index ee588f99..0000000
--- a/packages/SystemUI/res-keyguard/layout/fgs_footer.xml
+++ /dev/null
@@ -1,105 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-     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.
--->
-<!-- TODO(b/242040009): Remove this file. -->
-<FrameLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="0dp"
-    android:layout_height="@dimen/qs_security_footer_single_line_height"
-    android:layout_weight="1"
-    android:gravity="center"
-    android:clickable="true"
-    android:visibility="gone">
-
-    <LinearLayout
-        android:id="@+id/fgs_text_container"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:layout_marginEnd="@dimen/qs_footer_action_inset"
-        android:background="@drawable/qs_security_footer_background"
-        android:layout_gravity="end"
-        android:gravity="center"
-        android:paddingHorizontal="@dimen/qs_footer_padding"
-        >
-
-        <ImageView
-            android:id="@+id/primary_footer_icon"
-            android:layout_width="@dimen/qs_footer_icon_size"
-            android:layout_height="@dimen/qs_footer_icon_size"
-            android:gravity="start"
-            android:layout_marginEnd="12dp"
-            android:contentDescription="@null"
-            android:src="@drawable/ic_info_outline"
-            android:tint="?android:attr/textColorSecondary" />
-
-        <TextView
-            android:id="@+id/footer_text"
-            android:layout_width="0dp"
-            android:layout_height="wrap_content"
-            android:layout_weight="1"
-            android:maxLines="1"
-            android:ellipsize="end"
-            android:textAppearance="@style/TextAppearance.QS.SecurityFooter"
-            android:textColor="?android:attr/textColorSecondary"/>
-
-        <ImageView
-            android:id="@+id/fgs_new"
-            android:layout_width="12dp"
-            android:layout_height="12dp"
-            android:scaleType="fitCenter"
-            android:src="@drawable/fgs_dot"
-            android:contentDescription="@string/fgs_dot_content_description"
-            />
-
-        <ImageView
-            android:id="@+id/footer_icon"
-            android:layout_width="@dimen/qs_footer_icon_size"
-            android:layout_height="@dimen/qs_footer_icon_size"
-            android:layout_marginStart="8dp"
-            android:contentDescription="@null"
-            android:src="@*android:drawable/ic_chevron_end"
-            android:autoMirrored="true"
-            android:tint="?android:attr/textColorSecondary" />
-    </LinearLayout>
-
-    <FrameLayout
-        android:id="@+id/fgs_number_container"
-        android:layout_width="@dimen/qs_footer_action_button_size"
-        android:layout_height="@dimen/qs_footer_action_button_size"
-        android:background="@drawable/qs_footer_action_circle"
-        android:focusable="true"
-        android:visibility="gone">
-
-        <TextView
-            android:id="@+id/fgs_number"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:textAppearance="@style/TextAppearance.QS.SecurityFooter"
-            android:layout_gravity="center"
-            android:textColor="?android:attr/textColorPrimary"
-            android:textSize="18sp"/>
-        <ImageView
-            android:id="@+id/fgs_collapsed_new"
-            android:layout_width="12dp"
-            android:layout_height="12dp"
-            android:scaleType="fitCenter"
-            android:layout_gravity="bottom|end"
-            android:src="@drawable/fgs_dot"
-            android:contentDescription="@string/fgs_dot_content_description"
-            />
-    </FrameLayout>
-
-</FrameLayout>
\ No newline at end of file
diff --git a/packages/SystemUI/res-keyguard/layout/footer_actions.xml b/packages/SystemUI/res-keyguard/layout/footer_actions.xml
index 2261ae8..4a2a1cb 100644
--- a/packages/SystemUI/res-keyguard/layout/footer_actions.xml
+++ b/packages/SystemUI/res-keyguard/layout/footer_actions.xml
@@ -16,10 +16,8 @@
 -->
 
 <!-- Action buttons for footer in QS/QQS, containing settings button, power off button etc -->
-<!-- TODO(b/242040009): Clean up this file. -->
-<com.android.systemui.qs.FooterActionsView
+<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
     android:layout_width="match_parent"
     android:layout_height="@dimen/footer_actions_height"
     android:elevation="@dimen/qs_panel_elevation"
@@ -28,74 +26,4 @@
     android:background="@drawable/qs_footer_actions_background"
     android:gravity="center_vertical|end"
     android:layout_gravity="bottom"
->
-
-    <LinearLayout
-        android:id="@+id/security_footers_container"
-        android:orientation="horizontal"
-        android:layout_height="@dimen/qs_footer_action_button_size"
-        android:layout_width="0dp"
-        android:layout_weight="1"
-    />
-
-    <!-- Negative margin equal to -->
-    <LinearLayout
-        android:layout_height="match_parent"
-        android:layout_width="wrap_content"
-        android:layout_marginEnd="@dimen/qs_footer_action_inset_negative"
-        >
-
-        <com.android.systemui.statusbar.phone.MultiUserSwitch
-            android:id="@id/multi_user_switch"
-            android:layout_width="@dimen/qs_footer_action_button_size"
-            android:layout_height="@dimen/qs_footer_action_button_size"
-            android:background="@drawable/qs_footer_action_circle"
-            android:focusable="true">
-
-            <ImageView
-                android:id="@+id/multi_user_avatar"
-                android:layout_width="@dimen/qs_footer_icon_size"
-                android:layout_height="@dimen/qs_footer_icon_size"
-                android:layout_gravity="center"
-                android:scaleType="centerInside" />
-        </com.android.systemui.statusbar.phone.MultiUserSwitch>
-
-        <com.android.systemui.statusbar.AlphaOptimizedFrameLayout
-            android:id="@id/settings_button_container"
-            android:layout_width="@dimen/qs_footer_action_button_size"
-            android:layout_height="@dimen/qs_footer_action_button_size"
-            android:background="@drawable/qs_footer_action_circle"
-            android:clipChildren="false"
-            android:clipToPadding="false">
-
-            <com.android.systemui.statusbar.phone.SettingsButton
-                android:id="@+id/settings_button"
-                android:layout_width="@dimen/qs_footer_icon_size"
-                android:layout_height="@dimen/qs_footer_icon_size"
-                android:layout_gravity="center"
-                android:background="@android:color/transparent"
-                android:focusable="false"
-                android:clickable="false"
-                android:importantForAccessibility="yes"
-                android:contentDescription="@string/accessibility_quick_settings_settings"
-                android:scaleType="centerInside"
-                android:src="@drawable/ic_settings"
-                android:tint="?android:attr/textColorPrimary" />
-
-        </com.android.systemui.statusbar.AlphaOptimizedFrameLayout>
-
-        <com.android.systemui.statusbar.AlphaOptimizedImageView
-            android:id="@id/pm_lite"
-            android:layout_width="@dimen/qs_footer_action_button_size"
-            android:layout_height="@dimen/qs_footer_action_button_size"
-            android:background="@drawable/qs_footer_action_circle_color"
-            android:clickable="true"
-            android:clipToPadding="false"
-            android:focusable="true"
-            android:padding="@dimen/qs_footer_icon_padding"
-            android:src="@*android:drawable/ic_lock_power_off"
-            android:contentDescription="@string/accessibility_quick_settings_power_menu"
-            android:tint="?androidprv:attr/textColorOnAccent" />
-
-    </LinearLayout>
-</com.android.systemui.qs.FooterActionsView>
\ No newline at end of file
+/>
\ No newline at end of file
diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml b/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml
index 218c5cc..b49afee 100644
--- a/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml
+++ b/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml
@@ -35,7 +35,6 @@
         android:visibility="invisible" />
     <FrameLayout
         android:id="@+id/lockscreen_clock_view_large"
-        android:layout_marginTop="@dimen/keyguard_large_clock_top_margin"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:clipChildren="false"
diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_host_view.xml b/packages/SystemUI/res-keyguard/layout/keyguard_host_view.xml
index e64b586..8497ff0 100644
--- a/packages/SystemUI/res-keyguard/layout/keyguard_host_view.xml
+++ b/packages/SystemUI/res-keyguard/layout/keyguard_host_view.xml
@@ -27,6 +27,7 @@
     android:layout_height="match_parent"
     android:clipChildren="false"
     android:clipToPadding="false"
+    android:paddingTop="@dimen/keyguard_lock_padding"
     android:importantForAccessibility="yes"> <!-- Needed because TYPE_WINDOW_STATE_CHANGED is sent
                                                   from this view when bouncer is shown -->
 
diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_num_pad_key.xml b/packages/SystemUI/res-keyguard/layout/keyguard_num_pad_key.xml
index 316ad39..411fea5 100644
--- a/packages/SystemUI/res-keyguard/layout/keyguard_num_pad_key.xml
+++ b/packages/SystemUI/res-keyguard/layout/keyguard_num_pad_key.xml
@@ -18,8 +18,6 @@
     <TextView
         android:id="@+id/digit_text"
         style="@style/Widget.TextView.NumPadKey.Digit"
-        android:autoSizeMaxTextSize="32sp"
-        android:autoSizeTextType="uniform"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         />
diff --git a/packages/SystemUI/res-keyguard/values/strings.xml b/packages/SystemUI/res-keyguard/values/strings.xml
index da485a9..cb704fd 100644
--- a/packages/SystemUI/res-keyguard/values/strings.xml
+++ b/packages/SystemUI/res-keyguard/values/strings.xml
@@ -61,25 +61,25 @@
     <!-- SIM messages --><skip />
     <!-- When the user inserts a sim card from an unsupported network, it becomes network locked -->
     <string name="keyguard_network_locked_message">Network locked</string>
-    <!-- Shown when there is no SIM card. -->
-    <string name="keyguard_missing_sim_message_short">No SIM card</string>
-    <!-- Shown to ask the user to insert a SIM card. -->
-    <string name="keyguard_missing_sim_instructions">Insert a SIM card.</string>
-    <!-- Shown to ask the user to insert a SIM card when sim is missing or not readable. -->
-    <string name="keyguard_missing_sim_instructions_long">The SIM card is missing or not readable. Insert a SIM card.</string>
-    <!-- Shown when SIM card is permanently disabled. -->
-    <string name="keyguard_permanent_disabled_sim_message_short">Unusable SIM card.</string>
-    <!-- Shown to inform the user to SIM card is permanently disabled. -->
-    <string name="keyguard_permanent_disabled_sim_instructions">Your SIM card has been permanently disabled.\n
-    Contact your wireless service provider for another SIM card.</string>
+    <!-- Shown when there is no SIM. -->
+    <string name="keyguard_missing_sim_message_short">No SIM</string>
+    <!-- Shown to ask the user to add a SIM. -->
+    <string name="keyguard_missing_sim_instructions">Add a SIM.</string>
+    <!-- Shown to ask the user to add a SIM when sim is missing or not readable. -->
+    <string name="keyguard_missing_sim_instructions_long">The SIM is missing or not readable. Add a SIM.</string>
+    <!-- Shown when SIM is permanently disabled. -->
+    <string name="keyguard_permanent_disabled_sim_message_short">Unusable SIM.</string>
+    <!-- Shown to inform the user to SIM is permanently deactivated. -->
+    <string name="keyguard_permanent_disabled_sim_instructions">Your SIM has been permanently deactivated.\n
+    Contact your wireless service provider for another SIM.</string>
     <!-- Shown to tell the user that their SIM is locked and they must unlock it. -->
-    <string name="keyguard_sim_locked_message">SIM card is locked.</string>
+    <string name="keyguard_sim_locked_message">SIM is locked.</string>
     <!-- When the user enters a wrong sim pin too many times, it becomes PUK locked (Pin Unlock Kode) -->
-    <string name="keyguard_sim_puk_locked_message">SIM card is PUK-locked.</string>
+    <string name="keyguard_sim_puk_locked_message">SIM is PUK-locked.</string>
     <!-- For the unlock screen, When the user enters a sim unlock code, it takes a little while to check
          whether it is valid, and to unlock the sim if it is valid.  we display a
          progress dialog in the meantime.  this is the emssage. -->
-    <string name="keyguard_sim_unlock_progress_dialog_message">Unlocking SIM card\u2026</string>
+    <string name="keyguard_sim_unlock_progress_dialog_message">Unlocking SIM\u2026</string>
     <!-- Composes together the carrier name and the SIM card locked message. Example: CarrierName (SIM LOCKED) -->
     <string name="keyguard_carrier_name_with_sim_locked_template" translatable="false"><xliff:g id="carrier">%s</xliff:g> (<xliff:g id="message">%s</xliff:g>)</string>
 
@@ -139,8 +139,8 @@
     <string name="kg_puk_enter_pin_hint">Enter desired PIN code</string>
     <!-- Message shown when the user needs to confirm the PIN they just entered in the PUK screen -->
     <string name="kg_enter_confirm_pin_hint">Confirm desired PIN code</string>
-    <!-- Message shown in dialog while the device is unlocking the SIM card -->
-    <string name="kg_sim_unlock_progress_dialog_message">Unlocking SIM card\u2026</string>
+    <!-- Message shown in dialog while the device is unlocking the SIM -->
+    <string name="kg_sim_unlock_progress_dialog_message">Unlocking SIM\u2026</string>
     <!-- Message shown when the user enters an invalid SIM pin password in PUK screen -->
     <string name="kg_invalid_sim_pin_hint">Type a PIN that is 4 to 8 numbers.</string>
     <!-- Message shown when the user enters an invalid PUK code in the PUK screen -->
diff --git a/packages/SystemUI/res-product/values/strings.xml b/packages/SystemUI/res-product/values/strings.xml
index b71caef..75c8286 100644
--- a/packages/SystemUI/res-product/values/strings.xml
+++ b/packages/SystemUI/res-product/values/strings.xml
@@ -28,10 +28,10 @@
     <!-- Message of the overlay warning the user to interact with the device or it will go to sleep. [CHAR LIMIT=NONE] -->
     <string name="inattentive_sleep_warning_message" product="default">The device will soon turn off; press to keep it on.</string>
 
-    <!-- Shown when there is no SIM card. -->
-    <string name="keyguard_missing_sim_message" product="tablet">No SIM card in tablet.</string>
-    <!-- Shown when there is no SIM card. -->
-    <string name="keyguard_missing_sim_message" product="default">No SIM card in phone.</string>
+    <!-- Shown when there is no SIM. -->
+    <string name="keyguard_missing_sim_message" product="tablet">No SIM in tablet.</string>
+    <!-- Shown when there is no SIM. -->
+    <string name="keyguard_missing_sim_message" product="default">No SIM in phone.</string>
 
     <!-- String shown in PUK screen when PIN codes don't match -->
     <string name="kg_invalid_confirm_pin_hint" product="default">PIN codes does not match</string>
diff --git a/packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml b/packages/SystemUI/res/drawable/controls_panel_background.xml
similarity index 82%
rename from packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml
rename to packages/SystemUI/res/drawable/controls_panel_background.xml
index 1992c77..9092877 100644
--- a/packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml
+++ b/packages/SystemUI/res/drawable/controls_panel_background.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!--
   ~ Copyright (C) 2022 The Android Open Source Project
   ~
@@ -12,9 +13,10 @@
   ~ 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.
+  ~
   -->
 
 <shape xmlns:android="http://schemas.android.com/apk/res/android">
-    <solid android:color="@color/dream_overlay_aqi_unknown" />
-    <corners android:radius="@dimen/dream_aqi_badge_corner_radius" />
+    <solid android:color="#1F1F1F" />
+    <corners android:radius="@dimen/notification_corner_radius" />
 </shape>
\ No newline at end of file
diff --git a/packages/SystemUI/res/drawable/ic_circle_check_box.xml b/packages/SystemUI/res/drawable/ic_circle_check_box.xml
index b44a32d..00c10ce 100644
--- a/packages/SystemUI/res/drawable/ic_circle_check_box.xml
+++ b/packages/SystemUI/res/drawable/ic_circle_check_box.xml
@@ -18,7 +18,7 @@
     <item
         android:id="@+id/checked"
         android:state_checked="true"
-        android:drawable="@drawable/media_output_status_check" />
+        android:drawable="@drawable/media_output_status_filled_checked" />
     <item
         android:id="@+id/unchecked"
         android:state_checked="false"
diff --git a/packages/SystemUI/res/drawable/media_output_dialog_seekbar_background.xml b/packages/SystemUI/res/drawable/media_output_dialog_seekbar_background.xml
index 55dce8f..43cf003 100644
--- a/packages/SystemUI/res/drawable/media_output_dialog_seekbar_background.xml
+++ b/packages/SystemUI/res/drawable/media_output_dialog_seekbar_background.xml
@@ -17,7 +17,10 @@
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:id="@android:id/background">
         <shape>
-            <corners android:radius="28dp" />
+            <corners
+                     android:bottomRightRadius="28dp"
+                     android:topRightRadius="28dp"
+            />
             <solid android:color="@android:color/transparent" />
             <size
                 android:height="64dp"/>
diff --git a/packages/SystemUI/res/drawable/media_output_icon_volume_off.xml b/packages/SystemUI/res/drawable/media_output_icon_volume_off.xml
new file mode 100644
index 0000000..f29f44c
--- /dev/null
+++ b/packages/SystemUI/res/drawable/media_output_icon_volume_off.xml
@@ -0,0 +1,27 @@
+<!--
+  ~ 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.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="48dp"
+        android:height="48dp"
+        android:viewportWidth="48"
+        android:viewportHeight="48"
+        android:tint="?attr/colorControlNormal"
+        android:autoMirrored="true">
+    <path
+        android:fillColor="@color/media_dialog_item_main_content"
+        android:pathData="M40.65,45.2 L34.05,38.6Q32.65,39.6 31.025,40.325Q29.4,41.05 27.65,41.45V38.35Q28.8,38 29.875,37.575Q30.95,37.15 31.9,36.45L23.65,28.15V40L13.65,30H5.65V18H13.45L2.45,7L4.6,4.85L42.8,43ZM38.85,33.6 L36.7,31.45Q37.7,29.75 38.175,27.85Q38.65,25.95 38.65,23.95Q38.65,18.8 35.65,14.725Q32.65,10.65 27.65,9.55V6.45Q33.85,7.85 37.75,12.725Q41.65,17.6 41.65,23.95Q41.65,26.5 40.95,28.95Q40.25,31.4 38.85,33.6ZM32.15,26.9 L27.65,22.4V15.9Q30,17 31.325,19.2Q32.65,21.4 32.65,24Q32.65,24.75 32.525,25.475Q32.4,26.2 32.15,26.9ZM23.65,18.4 L18.45,13.2 23.65,8ZM20.65,32.7V25.2L16.45,21H8.65V27H14.95ZM18.55,23.1Z"/>
+</vector>
diff --git a/packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml b/packages/SystemUI/res/drawable/media_output_item_check_box.xml
similarity index 62%
copy from packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml
copy to packages/SystemUI/res/drawable/media_output_item_check_box.xml
index 1992c77..a0742900 100644
--- a/packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml
+++ b/packages/SystemUI/res/drawable/media_output_item_check_box.xml
@@ -14,7 +14,13 @@
   ~ limitations under the License.
   -->
 
-<shape xmlns:android="http://schemas.android.com/apk/res/android">
-    <solid android:color="@color/dream_overlay_aqi_unknown" />
-    <corners android:radius="@dimen/dream_aqi_badge_corner_radius" />
-</shape>
\ No newline at end of file
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item
+        android:id="@+id/checked"
+        android:state_checked="true"
+        android:drawable="@drawable/media_output_status_checked" />
+    <item
+        android:id="@+id/unchecked"
+        android:state_checked="false"
+        android:drawable="@drawable/media_output_status_selectable" />
+</selector>
diff --git a/packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml b/packages/SystemUI/res/drawable/media_output_status_checked.xml
similarity index 61%
copy from packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml
copy to packages/SystemUI/res/drawable/media_output_status_checked.xml
index 1992c77..8f83ee2 100644
--- a/packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml
+++ b/packages/SystemUI/res/drawable/media_output_status_checked.xml
@@ -14,7 +14,13 @@
   ~ limitations under the License.
   -->
 
-<shape xmlns:android="http://schemas.android.com/apk/res/android">
-    <solid android:color="@color/dream_overlay_aqi_unknown" />
-    <corners android:radius="@dimen/dream_aqi_badge_corner_radius" />
-</shape>
\ No newline at end of file
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24"
+    android:tint="?attr/colorControlNormal">
+    <path
+        android:fillColor="@android:color/white"
+        android:pathData="M9.55,18 L3.85,12.3 5.275,10.875 9.55,15.15 18.725,5.975 20.15,7.4Z"/>
+</vector>
diff --git a/packages/SystemUI/res/drawable/media_output_status_check.xml b/packages/SystemUI/res/drawable/media_output_status_filled_checked.xml
similarity index 100%
rename from packages/SystemUI/res/drawable/media_output_status_check.xml
rename to packages/SystemUI/res/drawable/media_output_status_filled_checked.xml
diff --git a/packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml b/packages/SystemUI/res/drawable/media_output_status_selectable.xml
similarity index 63%
copy from packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml
copy to packages/SystemUI/res/drawable/media_output_status_selectable.xml
index 1992c77..5465aa7 100644
--- a/packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml
+++ b/packages/SystemUI/res/drawable/media_output_status_selectable.xml
@@ -14,7 +14,13 @@
   ~ limitations under the License.
   -->
 
-<shape xmlns:android="http://schemas.android.com/apk/res/android">
-    <solid android:color="@color/dream_overlay_aqi_unknown" />
-    <corners android:radius="@dimen/dream_aqi_badge_corner_radius" />
-</shape>
\ No newline at end of file
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24"
+    android:tint="?attr/colorControlNormal">
+    <path
+        android:fillColor="@android:color/white"
+        android:pathData="M11,19V13H5V11H11V5H13V11H19V13H13V19Z"/>
+</vector>
diff --git a/packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml b/packages/SystemUI/res/drawable/media_output_title_icon_area.xml
similarity index 72%
copy from packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml
copy to packages/SystemUI/res/drawable/media_output_title_icon_area.xml
index 1992c77..b937937 100644
--- a/packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml
+++ b/packages/SystemUI/res/drawable/media_output_title_icon_area.xml
@@ -14,7 +14,12 @@
   ~ limitations under the License.
   -->
 
-<shape xmlns:android="http://schemas.android.com/apk/res/android">
-    <solid android:color="@color/dream_overlay_aqi_unknown" />
-    <corners android:radius="@dimen/dream_aqi_badge_corner_radius" />
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+       android:shape="rectangle">
+    <corners
+        android:bottomLeftRadius="28dp"
+        android:topLeftRadius="28dp"
+        android:bottomRightRadius="0dp"
+        android:topRightRadius="0dp"/>
+    <solid android:color="@color/media_dialog_item_background" />
 </shape>
\ No newline at end of file
diff --git a/packages/SystemUI/res/layout/activity_rear_display_education.xml b/packages/SystemUI/res/layout/activity_rear_display_education.xml
index 73d3f02..f5fc48c 100644
--- a/packages/SystemUI/res/layout/activity_rear_display_education.xml
+++ b/packages/SystemUI/res/layout/activity_rear_display_education.xml
@@ -33,7 +33,7 @@
                 android:layout_width="@dimen/rear_display_animation_width"
                 android:layout_height="@dimen/rear_display_animation_height"
                 android:layout_gravity="center"
-                android:contentDescription="@null"
+                android:contentDescription="@string/rear_display_accessibility_folded_animation"
                 android:scaleType="fitXY"
                 app:lottie_rawRes="@raw/rear_display_folded"
                 app:lottie_autoPlay="true"
diff --git a/packages/SystemUI/res/layout/activity_rear_display_education_opened.xml b/packages/SystemUI/res/layout/activity_rear_display_education_opened.xml
index 20b93d9..6de06f7 100644
--- a/packages/SystemUI/res/layout/activity_rear_display_education_opened.xml
+++ b/packages/SystemUI/res/layout/activity_rear_display_education_opened.xml
@@ -34,7 +34,7 @@
             android:layout_width="@dimen/rear_display_animation_width"
             android:layout_height="@dimen/rear_display_animation_height"
             android:layout_gravity="center"
-            android:contentDescription="@null"
+            android:contentDescription="@string/rear_display_accessibility_unfolded_animation"
             android:scaleType="fitXY"
             app:lottie_rawRes="@raw/rear_display_turnaround"
             app:lottie_autoPlay="true"
diff --git a/packages/SystemUI/res/layout/clipboard_overlay.xml b/packages/SystemUI/res/layout/clipboard_overlay.xml
index 0e9abee..9134f96 100644
--- a/packages/SystemUI/res/layout/clipboard_overlay.xml
+++ b/packages/SystemUI/res/layout/clipboard_overlay.xml
@@ -102,6 +102,7 @@
         android:layout_margin="@dimen/overlay_border_width"
         android:layout_height="wrap_content"
         android:layout_gravity="center"
+        app:layout_constraintHorizontal_bias="0"
         app:layout_constraintBottom_toBottomOf="@id/preview_border"
         app:layout_constraintStart_toStartOf="@id/preview_border"
         app:layout_constraintEnd_toEndOf="@id/preview_border"
diff --git a/packages/SystemUI/res/layout/controls_with_favorites.xml b/packages/SystemUI/res/layout/controls_with_favorites.xml
index 9efad22..ee3adba 100644
--- a/packages/SystemUI/res/layout/controls_with_favorites.xml
+++ b/packages/SystemUI/res/layout/controls_with_favorites.xml
@@ -90,7 +90,7 @@
       android:layout_weight="1"
       android:layout_marginLeft="@dimen/global_actions_side_margin"
       android:layout_marginRight="@dimen/global_actions_side_margin"
-      android:background="#ff0000"
+      android:background="@drawable/controls_panel_background"
       android:padding="@dimen/global_actions_side_margin"
       android:visibility="gone"
       />
diff --git a/packages/SystemUI/res/layout/dream_overlay_complication_aqi.xml b/packages/SystemUI/res/layout/dream_overlay_complication_aqi.xml
deleted file mode 100644
index fcebb8d..0000000
--- a/packages/SystemUI/res/layout/dream_overlay_complication_aqi.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<!--
-  ~ 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.
-  -->
-
-<TextView
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/aqi_view"
-    style="@style/clock_subtitle"
-    android:visibility="gone"
-    android:background="@drawable/dream_aqi_badge_bg"
-    android:paddingHorizontal="@dimen/dream_aqi_badge_padding_horizontal"
-    android:paddingVertical="@dimen/dream_aqi_badge_padding_vertical"
-    android:layout_width="wrap_content"
-    android:layout_height="wrap_content"/>
\ No newline at end of file
diff --git a/packages/SystemUI/res/layout/dream_overlay_complication_clock_date.xml b/packages/SystemUI/res/layout/dream_overlay_complication_clock_date.xml
deleted file mode 100644
index efbdd1a..0000000
--- a/packages/SystemUI/res/layout/dream_overlay_complication_clock_date.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  ~ 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.
--->
-<TextClock
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/date_view"
-    style="@style/clock_subtitle"
-    android:layout_width="wrap_content"
-    android:layout_height="wrap_content"
-    android:format12Hour="@string/dream_date_complication_date_format"
-    android:format24Hour="@string/dream_date_complication_date_format"/>
diff --git a/packages/SystemUI/res/layout/media_output_list_group_divider.xml b/packages/SystemUI/res/layout/media_output_list_group_divider.xml
new file mode 100644
index 0000000..5e96866
--- /dev/null
+++ b/packages/SystemUI/res/layout/media_output_list_group_divider.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ 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.
+  -->
+
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/device_container"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:orientation="vertical">
+    <TextView
+        android:id="@+id/title"
+        android:layout_width="wrap_content"
+        android:layout_height="36dp"
+        android:layout_gravity="center_vertical|start"
+        android:layout_marginStart="16dp"
+        android:layout_marginEnd="56dp"
+        android:ellipsize="end"
+        android:maxLines="1"
+        android:fontFamily="@*android:string/config_headlineFontFamilyMedium"
+        android:textSize="16sp"/>
+</LinearLayout>
\ No newline at end of file
diff --git a/packages/SystemUI/res/layout/media_output_list_item_advanced.xml b/packages/SystemUI/res/layout/media_output_list_item_advanced.xml
new file mode 100644
index 0000000..d49b9f1
--- /dev/null
+++ b/packages/SystemUI/res/layout/media_output_list_item_advanced.xml
@@ -0,0 +1,156 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2020 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.
+  -->
+
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/device_container"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content">
+    <FrameLayout
+        android:layout_width="match_parent"
+        android:layout_height="64dp"
+        android:id="@+id/item_layout"
+        android:background="@drawable/media_output_item_background"
+        android:layout_marginStart="16dp"
+        android:layout_marginEnd="80dp"
+        android:layout_marginBottom="12dp">
+        <FrameLayout
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:layout_gravity="center_vertical|start">
+            <com.android.systemui.media.dialog.MediaOutputSeekbar
+                android:id="@+id/volume_seekbar"
+                android:splitTrack="false"
+                android:visibility="gone"
+                android:paddingStart="64dp"
+                android:paddingEnd="0dp"
+                android:background="@null"
+                android:contentDescription="@string/media_output_dialog_accessibility_seekbar"
+                android:progressDrawable="@drawable/media_output_dialog_seekbar_background"
+                android:thumb="@null"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"/>
+        </FrameLayout>
+
+        <FrameLayout
+            android:id="@+id/icon_area"
+            android:layout_width="64dp"
+            android:layout_height="64dp"
+            android:background="@drawable/media_output_title_icon_area"
+            android:layout_gravity="center_vertical|start">
+            <ImageView
+                android:id="@+id/title_icon"
+                android:layout_width="24dp"
+                android:layout_height="24dp"
+                android:animateLayoutChanges="true"
+                android:layout_gravity="center"/>
+            <TextView
+                android:id="@+id/volume_value"
+                android:animateLayoutChanges="true"
+                android:layout_gravity="center"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:fontFamily="@*android:string/config_headlineFontFamilyMedium"
+                android:textSize="16sp"
+                android:visibility="gone"/>
+        </FrameLayout>
+
+        <TextView
+            android:id="@+id/title"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_vertical|start"
+            android:layout_marginStart="72dp"
+            android:layout_marginEnd="56dp"
+            android:ellipsize="end"
+            android:maxLines="1"
+            android:fontFamily="@*android:string/config_headlineFontFamilyMedium"
+            android:textSize="16sp"/>
+
+        <LinearLayout
+            android:id="@+id/two_line_layout"
+            android:orientation="vertical"
+            android:layout_width="wrap_content"
+            android:layout_gravity="center_vertical|start"
+            android:layout_height="48dp"
+            android:layout_marginEnd="56dp"
+            android:layout_marginStart="72dp">
+            <TextView
+                android:id="@+id/two_line_title"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:ellipsize="end"
+                android:maxLines="1"
+                android:fontFamily="@*android:string/config_headlineFontFamilyMedium"
+                android:textColor="@color/media_dialog_item_main_content"
+                android:textSize="16sp"/>
+            <TextView
+                android:id="@+id/subtitle"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:ellipsize="end"
+                android:maxLines="1"
+                android:textColor="@color/media_dialog_item_main_content"
+                android:textSize="14sp"
+                android:fontFamily="@*android:string/config_bodyFontFamily"
+                android:visibility="gone"/>
+        </LinearLayout>
+
+        <ProgressBar
+            android:id="@+id/volume_indeterminate_progress"
+            style="?android:attr/progressBarStyleSmallTitle"
+            android:layout_width="24dp"
+            android:layout_height="24dp"
+            android:layout_marginEnd="16dp"
+            android:indeterminate="true"
+            android:layout_gravity="end|center"
+            android:indeterminateOnly="true"
+            android:visibility="gone"/>
+
+        <ImageView
+            android:id="@+id/media_output_item_status"
+            android:layout_width="24dp"
+            android:layout_height="24dp"
+            android:layout_marginEnd="16dp"
+            android:indeterminate="true"
+            android:layout_gravity="end|center"
+            android:indeterminateOnly="true"
+            android:importantForAccessibility="no"
+            android:visibility="gone"/>
+    </FrameLayout>
+    <FrameLayout
+        android:id="@+id/end_action_area"
+        android:layout_width="64dp"
+        android:layout_height="64dp"
+        android:visibility="gone"
+        android:layout_marginBottom="6dp"
+        android:layout_marginEnd="8dp"
+        android:layout_gravity="end|center"
+        android:gravity="center"
+        android:background="@drawable/media_output_item_background_active">
+        <CheckBox
+            android:id="@+id/check_box"
+            android:focusable="false"
+            android:importantForAccessibility="no"
+            android:layout_gravity="center"
+            android:layout_width="24dp"
+            android:layout_height="24dp"
+            android:button="@drawable/media_output_item_check_box"
+            android:visibility="gone"
+            />
+    </FrameLayout>
+</FrameLayout>
\ No newline at end of file
diff --git a/packages/SystemUI/res/layout/quick_settings_security_footer.xml b/packages/SystemUI/res/layout/quick_settings_security_footer.xml
deleted file mode 100644
index 194f3dd..0000000
--- a/packages/SystemUI/res/layout/quick_settings_security_footer.xml
+++ /dev/null
@@ -1,61 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-     Copyright (C) 2014 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.
--->
-<!-- TODO(b/242040009): Remove this file. -->
-<LinearLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="0dp"
-    android:layout_height="@dimen/qs_security_footer_single_line_height"
-    android:layout_weight="1"
-    android:clickable="true"
-    android:orientation="horizontal"
-    android:paddingHorizontal="@dimen/qs_footer_padding"
-    android:gravity="center_vertical"
-    android:layout_gravity="center_vertical|center_horizontal"
-    android:layout_marginEnd="@dimen/qs_footer_action_inset"
-    android:background="@drawable/qs_security_footer_background"
-    >
-
-    <ImageView
-        android:id="@+id/primary_footer_icon"
-        android:layout_width="@dimen/qs_footer_icon_size"
-        android:layout_height="@dimen/qs_footer_icon_size"
-        android:gravity="start"
-        android:layout_marginEnd="12dp"
-        android:contentDescription="@null"
-        android:tint="?android:attr/textColorSecondary" />
-
-    <TextView
-        android:id="@+id/footer_text"
-        android:layout_width="0dp"
-        android:layout_height="wrap_content"
-        android:layout_weight="1"
-        android:singleLine="true"
-        android:ellipsize="end"
-        android:textAppearance="@style/TextAppearance.QS.SecurityFooter"
-        android:textColor="?android:attr/textColorSecondary"/>
-
-    <ImageView
-        android:id="@+id/footer_icon"
-        android:layout_width="@dimen/qs_footer_icon_size"
-        android:layout_height="@dimen/qs_footer_icon_size"
-        android:layout_marginStart="8dp"
-        android:contentDescription="@null"
-        android:src="@*android:drawable/ic_chevron_end"
-        android:autoMirrored="true"
-        android:tint="?android:attr/textColorSecondary" />
-
-</LinearLayout>
diff --git a/packages/SystemUI/res/layout/screenshot_static.xml b/packages/SystemUI/res/layout/screenshot_static.xml
index 8842992..65983b7 100644
--- a/packages/SystemUI/res/layout/screenshot_static.xml
+++ b/packages/SystemUI/res/layout/screenshot_static.xml
@@ -100,6 +100,7 @@
         android:background="@drawable/overlay_preview_background"
         android:adjustViewBounds="true"
         android:clickable="true"
+        app:layout_constraintHorizontal_bias="0"
         app:layout_constraintBottom_toBottomOf="@id/screenshot_preview_border"
         app:layout_constraintStart_toStartOf="@id/screenshot_preview_border"
         app:layout_constraintEnd_toEndOf="@id/screenshot_preview_border"
diff --git a/packages/SystemUI/res/layout/super_notification_shade.xml b/packages/SystemUI/res/layout/super_notification_shade.xml
index bafdb11..4abc176 100644
--- a/packages/SystemUI/res/layout/super_notification_shade.xml
+++ b/packages/SystemUI/res/layout/super_notification_shade.xml
@@ -98,16 +98,18 @@
             android:singleLine="true"
             android:ellipsize="marquee"
             android:focusable="true" />
-        <FrameLayout android:id="@+id/keyguard_bouncer_container"
-                     android:layout_height="0dp"
-                     android:layout_width="match_parent"
-                     android:layout_weight="1"
-                     android:background="@android:color/transparent"
-                     android:visibility="invisible"
-                     android:clipChildren="false"
-                     android:clipToPadding="false" />
     </LinearLayout>
 
+    <FrameLayout android:id="@+id/keyguard_bouncer_container"
+        android:paddingTop="@dimen/status_bar_height"
+        android:layout_height="match_parent"
+        android:layout_width="match_parent"
+        android:layout_weight="1"
+        android:background="@android:color/transparent"
+        android:visibility="invisible"
+        android:clipChildren="false"
+        android:clipToPadding="false" />
+
     <com.android.systemui.biometrics.AuthRippleView
         android:id="@+id/auth_ripple"
         android:layout_width="match_parent"
diff --git a/packages/SystemUI/res/raw/image_wallpaper_fragment_shader.glsl b/packages/SystemUI/res/raw/image_wallpaper_fragment_shader.glsl
deleted file mode 100644
index e4b6e07..0000000
--- a/packages/SystemUI/res/raw/image_wallpaper_fragment_shader.glsl
+++ /dev/null
@@ -1,11 +0,0 @@
-precision mediump float;
-
-// The actual wallpaper texture.
-uniform sampler2D uTexture;
-
-varying vec2 vTextureCoordinates;
-
-void main() {
-    // gets the pixel value of the wallpaper for this uv coordinates on screen.
-    gl_FragColor = texture2D(uTexture, vTextureCoordinates);
-}
\ No newline at end of file
diff --git a/packages/SystemUI/res/raw/image_wallpaper_vertex_shader.glsl b/packages/SystemUI/res/raw/image_wallpaper_vertex_shader.glsl
deleted file mode 100644
index 4393e2b..0000000
--- a/packages/SystemUI/res/raw/image_wallpaper_vertex_shader.glsl
+++ /dev/null
@@ -1,8 +0,0 @@
-attribute vec4 aPosition;
-attribute vec2 aTextureCoordinates;
-varying vec2 vTextureCoordinates;
-
-void main() {
-    vTextureCoordinates = aTextureCoordinates;
-    gl_Position = aPosition;
-}
\ No newline at end of file
diff --git a/packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml b/packages/SystemUI/res/values-h411dp/dimens.xml
similarity index 74%
copy from packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml
copy to packages/SystemUI/res/values-h411dp/dimens.xml
index 1992c77..6b21353 100644
--- a/packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml
+++ b/packages/SystemUI/res/values-h411dp/dimens.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!--
   ~ Copyright (C) 2022 The Android Open Source Project
   ~
@@ -13,8 +14,6 @@
   ~ See the License for the specific language governing permissions and
   ~ limitations under the License.
   -->
-
-<shape xmlns:android="http://schemas.android.com/apk/res/android">
-    <solid android:color="@color/dream_overlay_aqi_unknown" />
-    <corners android:radius="@dimen/dream_aqi_badge_corner_radius" />
-</shape>
\ No newline at end of file
+<resources>
+    <dimen name="volume_row_slider_height">137dp</dimen>
+</resources>
diff --git a/packages/SystemUI/res/values-h700dp/dimens.xml b/packages/SystemUI/res/values-h700dp/dimens.xml
index 055308f..39777ab 100644
--- a/packages/SystemUI/res/values-h700dp/dimens.xml
+++ b/packages/SystemUI/res/values-h700dp/dimens.xml
@@ -17,4 +17,5 @@
 <resources>
     <!-- Margin above the ambient indication container -->
     <dimen name="ambient_indication_container_margin_top">15dp</dimen>
-</resources>
\ No newline at end of file
+    <dimen name="volume_row_slider_height">177dp</dimen>
+</resources>
diff --git a/packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml b/packages/SystemUI/res/values-h841dp/dimens.xml
similarity index 74%
copy from packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml
copy to packages/SystemUI/res/values-h841dp/dimens.xml
index 1992c77..412da19 100644
--- a/packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml
+++ b/packages/SystemUI/res/values-h841dp/dimens.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!--
   ~ Copyright (C) 2022 The Android Open Source Project
   ~
@@ -13,8 +14,6 @@
   ~ See the License for the specific language governing permissions and
   ~ limitations under the License.
   -->
-
-<shape xmlns:android="http://schemas.android.com/apk/res/android">
-    <solid android:color="@color/dream_overlay_aqi_unknown" />
-    <corners android:radius="@dimen/dream_aqi_badge_corner_radius" />
-</shape>
\ No newline at end of file
+<resources>
+    <dimen name="volume_row_slider_height">237dp</dimen>
+</resources>
diff --git a/packages/SystemUI/res/values/colors.xml b/packages/SystemUI/res/values/colors.xml
index 70d53c7..ba6977a 100644
--- a/packages/SystemUI/res/values/colors.xml
+++ b/packages/SystemUI/res/values/colors.xml
@@ -246,15 +246,6 @@
 
     <color name="dream_overlay_camera_mic_off_dot_color">#FCBE03</color>
 
-    <!-- Air Quality -->
-    <color name="dream_overlay_aqi_good">#689F38</color>
-    <color name="dream_overlay_aqi_moderate">#FBC02D</color>
-    <color name="dream_overlay_aqi_unhealthy_sensitive">#F57C00</color>
-    <color name="dream_overlay_aqi_unhealthy">#C53929</color>
-    <color name="dream_overlay_aqi_very_unhealthy">#AD1457</color>
-    <color name="dream_overlay_aqi_hazardous">#880E4F</color>
-    <color name="dream_overlay_aqi_unknown">#BDC1C6</color>
-
     <!-- Dream overlay text shadows -->
     <color name="dream_overlay_clock_key_text_shadow_color">#4D000000</color>
     <color name="dream_overlay_clock_ambient_text_shadow_color">#4D000000</color>
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index dc7e4e4..ea51a89 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -1222,6 +1222,8 @@
     <dimen name="media_output_dialog_app_tier_icon_size">20dp</dimen>
     <dimen name="media_output_dialog_background_radius">16dp</dimen>
     <dimen name="media_output_dialog_active_background_radius">28dp</dimen>
+    <dimen name="media_output_dialog_default_margin_end">16dp</dimen>
+    <dimen name="media_output_dialog_selectable_margin_end">80dp</dimen>
 
     <!-- Distance that the full shade transition takes in order to complete by tapping on a button
          like "expand". -->
@@ -1581,10 +1583,6 @@
     <dimen name="dream_overlay_y_offset">80dp</dimen>
     <dimen name="dream_overlay_exit_y_offset">40dp</dimen>
 
-    <dimen name="dream_aqi_badge_corner_radius">28dp</dimen>
-    <dimen name="dream_aqi_badge_padding_vertical">6dp</dimen>
-    <dimen name="dream_aqi_badge_padding_horizontal">16dp</dimen>
-
     <dimen name="status_view_margin_horizontal">0dp</dimen>
 
     <!-- Media output broadcast dialog QR code picture size -->
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 9ee918d..ae1ff1a 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -849,7 +849,7 @@
     <string name="sensor_privacy_htt_blocked_dialog_content">To use the microphone button, enable microphone access in Settings.</string>
 
     <!-- Sensor privacy dialog: Button to open system settings [CHAR LIMIT=50] -->
-    <string name="sensor_privacy_dialog_open_settings">Open settings.</string>
+    <string name="sensor_privacy_dialog_open_settings">Open Settings</string>
 
     <!-- Default name for the media device shown in the output switcher when the name is not available [CHAR LIMIT=30] -->
     <string name="media_seamless_other_device">Other device</string>
@@ -2481,7 +2481,7 @@
     <!-- Controls menu, edit [CHAR_LIMIT=30] -->
     <string name="controls_menu_edit">Edit controls</string>
 
-    <!-- Title for the media output group dialog with media related devices [CHAR LIMIT=50] -->
+    <!-- Title for the media output dialog with media related devices [CHAR LIMIT=50] -->
     <string name="media_output_dialog_add_output">Add outputs</string>
     <!-- Title for the media output slice with group devices [CHAR LIMIT=50] -->
     <string name="media_output_dialog_group">Group</string>
@@ -2505,6 +2505,8 @@
     <string name="media_output_dialog_accessibility_title">Available devices for audio output.</string>
     <!-- Accessibility text describing purpose of seekbar in media output dialog. [CHAR LIMIT=NONE] -->
     <string name="media_output_dialog_accessibility_seekbar">Volume</string>
+    <!-- Summary for media output volume of a device in percentage [CHAR LIMIT=NONE] -->
+    <string name="media_output_dialog_volume_percentage"><xliff:g id="percentage" example="10">%1$d</xliff:g>%%</string>
 
     <!-- Media Output Broadcast Dialog -->
     <!-- Title for Broadcast First Notify Dialog [CHAR LIMIT=60] -->
@@ -2790,9 +2792,6 @@
     <!-- [CHAR LIMIT=NONE] Le audio broadcast dialog, media app is unknown -->
     <string name="bt_le_audio_broadcast_dialog_unknown_name">Unknown</string>
 
-    <!-- Date format for the Dream Date Complication [CHAR LIMIT=NONE] -->
-    <string name="dream_date_complication_date_format">EEE, MMM d</string>
-
     <!-- Time format for the Dream Time Complication for 12-hour time format [CHAR LIMIT=NONE] -->
     <string name="dream_time_complication_12_hr_time_format">h:mm</string>
 
@@ -2872,4 +2871,8 @@
     <string name="rear_display_bottom_sheet_description">Use the rear-facing camera for a wider photo with higher resolution.</string>
     <!-- Text for education page description to warn user that the display will turn off if the button is clicked. [CHAR_LIMIT=NONE] -->
     <string name="rear_display_bottom_sheet_warning"><b>&#x2731; This screen will turn off</b></string>
+    <!-- Text for education page content description for folded animation. [CHAR_LIMIT=NONE] -->
+    <string name="rear_display_accessibility_folded_animation">Foldable device being unfolded</string>
+    <!-- Text for education page content description for unfolded animation. [CHAR_LIMIT=NONE] -->
+    <string name="rear_display_accessibility_unfolded_animation">Foldable device being flipped around</string>
 </resources>
diff --git a/packages/SystemUI/res/xml/combined_qs_header_scene.xml b/packages/SystemUI/res/xml/combined_qs_header_scene.xml
index c32de70..38c1640 100644
--- a/packages/SystemUI/res/xml/combined_qs_header_scene.xml
+++ b/packages/SystemUI/res/xml/combined_qs_header_scene.xml
@@ -124,6 +124,11 @@
         </KeyFrameSet>
     </Transition>
 
+    <Transition
+        android:id="@+id/large_screen_header_transition"
+        app:constraintSetStart="@id/large_screen_header_constraint"
+        app:constraintSetEnd="@id/large_screen_header_constraint"/>
+
     <Include app:constraintSet="@xml/large_screen_shade_header"/>
 
     <Include app:constraintSet="@xml/qs_header"/>
diff --git a/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ViewScreenshotTestRule.kt b/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ViewScreenshotTestRule.kt
index 6d0cc5e..738b37c 100644
--- a/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ViewScreenshotTestRule.kt
+++ b/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ViewScreenshotTestRule.kt
@@ -34,7 +34,6 @@
 import platform.test.screenshot.DeviceEmulationRule
 import platform.test.screenshot.DeviceEmulationSpec
 import platform.test.screenshot.MaterialYouColorsRule
-import platform.test.screenshot.PathConfig
 import platform.test.screenshot.ScreenshotTestRule
 import platform.test.screenshot.getEmulatedDevicePathConfig
 import platform.test.screenshot.matchers.BitmapMatcher
@@ -43,7 +42,6 @@
 class ViewScreenshotTestRule(
     emulationSpec: DeviceEmulationSpec,
     private val matcher: BitmapMatcher = UnitTestBitmapMatcher,
-    pathConfig: PathConfig = getEmulatedDevicePathConfig(emulationSpec),
     assetsPathRelativeToBuildRoot: String
 ) : TestRule {
     private val colorsRule = MaterialYouColorsRule()
diff --git a/packages/SystemUI/shared/src/com/android/systemui/flags/FlagManager.kt b/packages/SystemUI/shared/src/com/android/systemui/flags/FlagManager.kt
index d172690..d85292a 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/flags/FlagManager.kt
+++ b/packages/SystemUI/shared/src/com/android/systemui/flags/FlagManager.kt
@@ -38,6 +38,7 @@
         const val ACTION_SET_FLAG = "com.android.systemui.action.SET_FLAG"
         const val ACTION_GET_FLAGS = "com.android.systemui.action.GET_FLAGS"
         const val FLAGS_PERMISSION = "com.android.systemui.permission.FLAGS"
+        const val ACTION_SYSUI_STARTED = "com.android.systemui.STARTED"
         const val EXTRA_ID = "id"
         const val EXTRA_VALUE = "value"
         const val EXTRA_FLAGS = "flags"
diff --git a/packages/SystemUI/src/com/android/systemui/util/condition/CombinedCondition.kt b/packages/SystemUI/shared/src/com/android/systemui/shared/condition/CombinedCondition.kt
similarity index 96%
rename from packages/SystemUI/src/com/android/systemui/util/condition/CombinedCondition.kt
rename to packages/SystemUI/shared/src/com/android/systemui/shared/condition/CombinedCondition.kt
index da81d54..2d83458 100644
--- a/packages/SystemUI/src/com/android/systemui/util/condition/CombinedCondition.kt
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/condition/CombinedCondition.kt
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.systemui.util.condition
+package com.android.systemui.shared.condition
 
 /**
  * A higher order [Condition] which combines multiple conditions with a specified
diff --git a/packages/SystemUI/src/com/android/systemui/util/condition/Condition.java b/packages/SystemUI/shared/src/com/android/systemui/shared/condition/Condition.java
similarity index 80%
rename from packages/SystemUI/src/com/android/systemui/util/condition/Condition.java
rename to packages/SystemUI/shared/src/com/android/systemui/shared/condition/Condition.java
index b39adef..cc48090e 100644
--- a/packages/SystemUI/src/com/android/systemui/util/condition/Condition.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/condition/Condition.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2021 The Android Open Source Project
+ * 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.
@@ -14,13 +14,14 @@
  * limitations under the License.
  */
 
-package com.android.systemui.util.condition;
+package com.android.systemui.shared.condition;
 
 import android.util.Log;
 
-import com.android.systemui.statusbar.policy.CallbackController;
-
-import org.jetbrains.annotations.NotNull;
+import androidx.annotation.NonNull;
+import androidx.lifecycle.Lifecycle;
+import androidx.lifecycle.LifecycleEventObserver;
+import androidx.lifecycle.LifecycleOwner;
 
 import java.lang.ref.WeakReference;
 import java.util.ArrayList;
@@ -33,7 +34,7 @@
  * Base class for a condition that needs to be fulfilled in order for {@link Monitor} to inform
  * its callbacks.
  */
-public abstract class Condition implements CallbackController<Condition.Callback> {
+public abstract class Condition {
     private final String mTag = getClass().getSimpleName();
 
     private final ArrayList<WeakReference<Callback>> mCallbacks = new ArrayList<>();
@@ -79,8 +80,7 @@
      * Registers a callback to receive updates once started. This should be called before
      * {@link #start()}. Also triggers the callback immediately if already started.
      */
-    @Override
-    public void addCallback(@NotNull Callback callback) {
+    public void addCallback(@NonNull Callback callback) {
         if (shouldLog()) Log.d(mTag, "adding callback");
         mCallbacks.add(new WeakReference<>(callback));
 
@@ -96,8 +96,7 @@
     /**
      * Removes the provided callback from further receiving updates.
      */
-    @Override
-    public void removeCallback(@NotNull Callback callback) {
+    public void removeCallback(@NonNull Callback callback) {
         if (shouldLog()) Log.d(mTag, "removing callback");
         final Iterator<WeakReference<Callback>> iterator = mCallbacks.iterator();
         while (iterator.hasNext()) {
@@ -116,6 +115,29 @@
     }
 
     /**
+     * Wrapper to {@link #addCallback(Callback)} when a lifecycle is in the resumed state
+     * and {@link #removeCallback(Callback)} when not resumed automatically.
+     */
+    public Callback observe(LifecycleOwner owner, Callback listener) {
+        return observe(owner.getLifecycle(), listener);
+    }
+
+    /**
+     * Wrapper to {@link #addCallback(Callback)} when a lifecycle is in the resumed state
+     * and {@link #removeCallback(Condition.Callback)} when not resumed automatically.
+     */
+    public Callback observe(Lifecycle lifecycle, Callback listener) {
+        lifecycle.addObserver((LifecycleEventObserver) (lifecycleOwner, event) -> {
+            if (event == Lifecycle.Event.ON_RESUME) {
+                addCallback(listener);
+            } else if (event == Lifecycle.Event.ON_PAUSE) {
+                removeCallback(listener);
+            }
+        });
+        return listener;
+    }
+
+    /**
      * Updates the value for whether the condition has been fulfilled, and sends an update if the
      * value changes and any callback is registered.
      *
@@ -187,7 +209,7 @@
      * Creates a new condition which will only be true when both this condition and all the provided
      * conditions are true.
      */
-    public Condition and(Collection<Condition> others) {
+    public Condition and(@NonNull Collection<Condition> others) {
         final List<Condition> conditions = new ArrayList<>(others);
         conditions.add(this);
         return new CombinedCondition(conditions, Evaluator.OP_AND);
@@ -197,7 +219,7 @@
      * Creates a new condition which will only be true when both this condition and the provided
      * condition is true.
      */
-    public Condition and(Condition other) {
+    public Condition and(@NonNull Condition other) {
         return new CombinedCondition(Arrays.asList(this, other), Evaluator.OP_AND);
     }
 
@@ -205,7 +227,7 @@
      * Creates a new condition which will only be true when either this condition or any of the
      * provided conditions are true.
      */
-    public Condition or(Collection<Condition> others) {
+    public Condition or(@NonNull Collection<Condition> others) {
         final List<Condition> conditions = new ArrayList<>(others);
         conditions.add(this);
         return new CombinedCondition(conditions, Evaluator.OP_OR);
@@ -215,7 +237,7 @@
      * Creates a new condition which will only be true when either this condition or the provided
      * condition is true.
      */
-    public Condition or(Condition other) {
+    public Condition or(@NonNull Condition other) {
         return new CombinedCondition(Arrays.asList(this, other), Evaluator.OP_OR);
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/util/condition/Evaluator.kt b/packages/SystemUI/shared/src/com/android/systemui/shared/condition/Evaluator.kt
similarity index 81%
rename from packages/SystemUI/src/com/android/systemui/util/condition/Evaluator.kt
rename to packages/SystemUI/shared/src/com/android/systemui/shared/condition/Evaluator.kt
index cf44e84..23742c5 100644
--- a/packages/SystemUI/src/com/android/systemui/util/condition/Evaluator.kt
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/condition/Evaluator.kt
@@ -1,4 +1,20 @@
-package com.android.systemui.util.condition
+/*
+ * 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.systemui.shared.condition
 
 import android.annotation.IntDef
 
diff --git a/packages/SystemUI/src/com/android/systemui/util/condition/Monitor.java b/packages/SystemUI/shared/src/com/android/systemui/shared/condition/Monitor.java
similarity index 96%
rename from packages/SystemUI/src/com/android/systemui/util/condition/Monitor.java
rename to packages/SystemUI/shared/src/com/android/systemui/shared/condition/Monitor.java
index 24bc907..95675ce 100644
--- a/packages/SystemUI/src/com/android/systemui/util/condition/Monitor.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/condition/Monitor.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2021 The Android Open Source Project
+ * 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.
@@ -14,14 +14,14 @@
  * limitations under the License.
  */
 
-package com.android.systemui.util.condition;
+package com.android.systemui.shared.condition;
 
 import android.util.ArraySet;
 import android.util.Log;
 
-import com.android.systemui.dagger.qualifiers.Main;
+import androidx.annotation.NonNull;
 
-import org.jetbrains.annotations.NotNull;
+import com.android.systemui.dagger.qualifiers.Main;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -100,7 +100,7 @@
      * @param subscription A {@link Subscription} detailing the desired conditions and callback.
      * @return A {@link Subscription.Token} that can be used to remove the subscription.
      */
-    public Subscription.Token addSubscription(@NotNull Subscription subscription) {
+    public Subscription.Token addSubscription(@NonNull Subscription subscription) {
         final Subscription.Token token = new Subscription.Token();
         final SubscriptionState state = new SubscriptionState(subscription);
 
@@ -131,7 +131,7 @@
      * @param token The {@link Subscription.Token} returned when the {@link Subscription} was
      *              originally added.
      */
-    public void removeSubscription(@NotNull Subscription.Token token) {
+    public void removeSubscription(@NonNull Subscription.Token token) {
         mExecutor.execute(() -> {
             if (shouldLog()) Log.d(mTag, "removing subscription");
             if (!mSubscriptions.containsKey(token)) {
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginActionManager.java b/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginActionManager.java
index e226d58..b057fe4 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginActionManager.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginActionManager.java
@@ -362,8 +362,7 @@
         nb.addAction(new Action.Builder(null, "Disable plugin", pi).build());
         mNotificationManager.notify(SystemMessage.NOTE_PLUGIN, nb.build());
         // TODO: Warn user.
-        Log.w(TAG, "Plugin has invalid interface version " + e.getActualVersion()
-                + ", expected " + e.getExpectedVersion());
+        Log.w(TAG, "Error loading plugin; " + e.getMessage());
     }
 
     /**
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/PreviewPositionHelper.java b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/PreviewPositionHelper.java
index c9ea794..b927155 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/PreviewPositionHelper.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/PreviewPositionHelper.java
@@ -39,7 +39,6 @@
     private boolean mIsOrientationChanged;
     private SplitBounds mSplitBounds;
     private int mDesiredStagePosition;
-    private boolean mTaskbarInApp;
 
     public Matrix getMatrix() {
         return mMatrix;
@@ -58,10 +57,6 @@
         mDesiredStagePosition = desiredStagePosition;
     }
 
-    public void setTaskbarInApp(boolean taskbarInApp) {
-        mTaskbarInApp = taskbarInApp;
-    }
-
     /**
      * Updates the matrix based on the provided parameters
      */
@@ -79,34 +74,21 @@
         float scaledTaskbarSize;
         float canvasScreenRatio;
         if (mSplitBounds != null) {
-            float fullscreenTaskWidth;
-            float fullscreenTaskHeight;
-
-            float taskPercent;
             if (mSplitBounds.appsStackedVertically) {
-                taskPercent = mDesiredStagePosition != STAGE_POSITION_TOP_OR_LEFT
-                        ? mSplitBounds.topTaskPercent
-                        : (1 - (mSplitBounds.topTaskPercent + mSplitBounds.dividerHeightPercent));
-                // Scale portrait height to that of (actual screen - taskbar inset)
-                fullscreenTaskHeight = (screenHeightPx) * taskPercent;
-                if (mTaskbarInApp) {
-                    canvasScreenRatio = canvasHeight / fullscreenTaskHeight;
+                if (mDesiredStagePosition == STAGE_POSITION_TOP_OR_LEFT) {
+                    // Top app isn't cropped at all by taskbar
+                    canvasScreenRatio = 0;
                 } else {
-                    if (mDesiredStagePosition == STAGE_POSITION_TOP_OR_LEFT) {
-                        // Top app isn't cropped at all by taskbar
-                        canvasScreenRatio = 0;
-                    } else {
-                        // Same as fullscreen ratio
-                        canvasScreenRatio = (float) canvasWidth / screenWidthPx;
-                    }
+                    // Same as fullscreen ratio
+                    canvasScreenRatio = (float) canvasWidth / screenWidthPx;
                 }
             } else {
                 // For landscape, scale the width
-                taskPercent = mDesiredStagePosition == STAGE_POSITION_TOP_OR_LEFT
+                float taskPercent = mDesiredStagePosition == STAGE_POSITION_TOP_OR_LEFT
                         ? mSplitBounds.leftTaskPercent
                         : (1 - (mSplitBounds.leftTaskPercent + mSplitBounds.dividerWidthPercent));
                 // Scale landscape width to that of actual screen
-                fullscreenTaskWidth = screenWidthPx * taskPercent;
+                float fullscreenTaskWidth = screenWidthPx * taskPercent;
                 canvasScreenRatio = canvasWidth / fullscreenTaskWidth;
             }
         } else {
diff --git a/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt b/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt
index 87e9d56..8f38e58 100644
--- a/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt
+++ b/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt
@@ -15,6 +15,7 @@
  */
 package com.android.keyguard
 
+import android.app.WallpaperManager
 import android.content.BroadcastReceiver
 import android.content.Context
 import android.content.Intent
@@ -100,9 +101,13 @@
     private val regionSamplingEnabled = featureFlags.isEnabled(REGION_SAMPLING)
 
     private fun updateColors() {
+
         if (regionSamplingEnabled && smallRegionSampler != null && largeRegionSampler != null) {
-            smallClockIsDark = smallRegionSampler!!.currentRegionDarkness().isDark
-            largeClockIsDark = largeRegionSampler!!.currentRegionDarkness().isDark
+            val wallpaperManager = WallpaperManager.getInstance(context)
+            if (!wallpaperManager.lockScreenWallpaperExists()) {
+                smallClockIsDark = smallRegionSampler!!.currentRegionDarkness().isDark
+                largeClockIsDark = largeRegionSampler!!.currentRegionDarkness().isDark
+            }
         } else {
             val isLightTheme = TypedValue()
             context.theme.resolveAttribute(android.R.attr.isLightTheme, isLightTheme, true)
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputViewController.java
index 860c8e3..7da27b1 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputViewController.java
@@ -260,7 +260,8 @@
         if (reason != PROMPT_REASON_NONE) {
             int promtReasonStringRes = mView.getPromptReasonStringRes(reason);
             if (promtReasonStringRes != 0) {
-                mMessageAreaController.setMessage(promtReasonStringRes);
+                mMessageAreaController.setMessage(
+                        mView.getResources().getString(promtReasonStringRes), false);
             }
         }
     }
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java
index e6aae9b..6ce84a9 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java
@@ -78,6 +78,7 @@
     private int mCurrentClockSize = SMALL;
 
     private int mKeyguardSmallClockTopMargin = 0;
+    private int mKeyguardLargeClockTopMargin = 0;
     private final ClockRegistry.ClockChangeListener mClockChangedListener;
 
     private ViewGroup mStatusArea;
@@ -164,6 +165,8 @@
         mClockEventController.registerListeners(mView);
         mKeyguardSmallClockTopMargin =
                 mView.getResources().getDimensionPixelSize(R.dimen.keyguard_clock_top_margin);
+        mKeyguardLargeClockTopMargin =
+                mView.getResources().getDimensionPixelSize(R.dimen.keyguard_large_clock_top_margin);
 
         if (mOnlyClock) {
             View ksv = mView.findViewById(R.id.keyguard_slice_view);
@@ -246,6 +249,8 @@
         mView.onDensityOrFontScaleChanged();
         mKeyguardSmallClockTopMargin =
                 mView.getResources().getDimensionPixelSize(R.dimen.keyguard_clock_top_margin);
+        mKeyguardLargeClockTopMargin =
+                mView.getResources().getDimensionPixelSize(R.dimen.keyguard_large_clock_top_margin);
         mView.updateClockTargetRegions();
     }
 
@@ -324,10 +329,18 @@
         }
 
         if (mLargeClockFrame.getVisibility() == View.VISIBLE) {
+            // This gets the expected clock bottom if mLargeClockFrame had a top margin, but it's
+            // top margin only contributed to height and didn't move the top of the view (as this
+            // was the computation previously). As we no longer have a margin, we add this back
+            // into the computation manually.
             int frameHeight = mLargeClockFrame.getHeight();
             int clockHeight = clock.getLargeClock().getView().getHeight();
-            return frameHeight / 2 + clockHeight / 2;
+            return frameHeight / 2 + clockHeight / 2 + mKeyguardLargeClockTopMargin / -2;
         } else {
+            // This is only called if we've never shown the large clock as the frame is inflated
+            // with 'gone', but then the visibility is never set when it is animated away by
+            // KeyguardClockSwitch, instead it is removed from the view hierarchy.
+            // TODO(b/261755021): Cleanup Large Frame Visibility
             int clockHeight = clock.getSmallClock().getView().getHeight();
             return clockHeight + statusBarHeaderHeight + mKeyguardSmallClockTopMargin;
         }
@@ -345,11 +358,15 @@
         if (mLargeClockFrame.getVisibility() == View.VISIBLE) {
             return clock.getLargeClock().getView().getHeight();
         } else {
+            // Is not called except in certain edge cases, see comment in getClockBottom
+            // TODO(b/261755021): Cleanup Large Frame Visibility
             return clock.getSmallClock().getView().getHeight();
         }
     }
 
     boolean isClockTopAligned() {
+        // Returns false except certain edge cases, see comment in getClockBottom
+        // TODO(b/261755021): Cleanup Large Frame Visibility
         return mLargeClockFrame.getVisibility() != View.VISIBLE;
     }
 
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardInputViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardInputViewController.java
index 2e9ad58..d1c9a30 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardInputViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardInputViewController.java
@@ -142,8 +142,11 @@
     }
 
     public void startAppearAnimation() {
-        if (TextUtils.isEmpty(mMessageAreaController.getMessage())) {
-            mMessageAreaController.setMessage(getInitialMessageResId());
+        if (TextUtils.isEmpty(mMessageAreaController.getMessage())
+                && getInitialMessageResId() != 0) {
+            mMessageAreaController.setMessage(
+                    mView.getResources().getString(getInitialMessageResId()),
+                    /* animate= */ false);
         }
         mView.startAppearAnimation();
     }
@@ -163,9 +166,7 @@
     }
 
     /** Determines the message to show in the bouncer when it first appears. */
-    protected int getInitialMessageResId() {
-        return 0;
-    }
+    protected abstract int getInitialMessageResId();
 
     /** Factory for a {@link KeyguardInputViewController}. */
     public static class Factory {
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPINView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPINView.java
index 5d86ccd..67e3400 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardPINView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPINView.java
@@ -52,6 +52,7 @@
     private int mYTransOffset;
     private View mBouncerMessageView;
     @DevicePostureInt private int mLastDevicePosture = DEVICE_POSTURE_UNKNOWN;
+    public static final long ANIMATION_DURATION = 650;
 
     public KeyguardPINView(Context context) {
         this(context, null);
@@ -181,7 +182,7 @@
         if (mAppearAnimator.isRunning()) {
             mAppearAnimator.cancel();
         }
-        mAppearAnimator.setDuration(650);
+        mAppearAnimator.setDuration(ANIMATION_DURATION);
         mAppearAnimator.addUpdateListener(animation -> animate(animation.getAnimatedFraction()));
         mAppearAnimator.start();
     }
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputViewController.java
index f7423ed..8011efd 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputViewController.java
@@ -139,4 +139,9 @@
         super.startErrorAnimation();
         mView.startErrorAnimation();
     }
+
+    @Override
+    protected int getInitialMessageResId() {
+        return R.string.keyguard_enter_your_pin;
+    }
 }
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPinViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPinViewController.java
index f51ac32..35b2db2 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardPinViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPinViewController.java
@@ -74,9 +74,4 @@
         return mView.startDisappearAnimation(
                 mKeyguardUpdateMonitor.needsSlowUnlockTransition(), finishRunnable);
     }
-
-    @Override
-    protected int getInitialMessageResId() {
-        return R.string.keyguard_enter_your_pin;
-    }
 }
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java
index 8f3484a..5d7a6f1 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java
@@ -36,8 +36,11 @@
 
 import static java.lang.Integer.max;
 
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
 import android.animation.AnimatorSet;
 import android.animation.ObjectAnimator;
+import android.animation.ValueAnimator;
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.admin.DevicePolicyManager;
@@ -967,11 +970,23 @@
             }
 
             mUserSwitcherViewGroup.setAlpha(0f);
-            ObjectAnimator alphaAnim = ObjectAnimator.ofFloat(mUserSwitcherViewGroup, View.ALPHA,
-                    1f);
-            alphaAnim.setInterpolator(Interpolators.ALPHA_IN);
-            alphaAnim.setDuration(500);
-            alphaAnim.start();
+            ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
+            int yTrans = mView.getResources().getDimensionPixelSize(R.dimen.pin_view_trans_y_entry);
+            animator.setInterpolator(Interpolators.STANDARD_DECELERATE);
+            animator.setDuration(650);
+            animator.addListener(new AnimatorListenerAdapter() {
+                @Override
+                public void onAnimationEnd(Animator animation) {
+                    mUserSwitcherViewGroup.setAlpha(1f);
+                    mUserSwitcherViewGroup.setTranslationY(0f);
+                }
+            });
+            animator.addUpdateListener(animation -> {
+                float value = (float) animation.getAnimatedValue();
+                mUserSwitcherViewGroup.setAlpha(value);
+                mUserSwitcherViewGroup.setTranslationY(yTrans - yTrans * value);
+            });
+            animator.start();
         }
 
         @Override
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityViewFlipperController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityViewFlipperController.java
index a5c8c78..39b567f 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityViewFlipperController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityViewFlipperController.java
@@ -156,5 +156,10 @@
         @Override
         public void onStartingToHide() {
         }
+
+        @Override
+        protected int getInitialMessageResId() {
+            return 0;
+        }
     }
 }
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java
index 51ade29..3a592a9 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java
@@ -382,6 +382,9 @@
     private static final int HAL_ERROR_RETRY_MAX = 20;
 
     @VisibleForTesting
+    protected static final int HAL_POWER_PRESS_TIMEOUT = 50; // ms
+
+    @VisibleForTesting
     protected final Runnable mFpCancelNotReceived = this::onFingerprintCancelNotReceived;
 
     private final Runnable mFaceCancelNotReceived = this::onFaceCancelNotReceived;
@@ -902,7 +905,7 @@
         }
     }
 
-    private final Runnable mRetryFingerprintAuthentication = new Runnable() {
+    private final Runnable mRetryFingerprintAuthenticationAfterHwUnavailable = new Runnable() {
         @SuppressLint("MissingPermission")
         @Override
         public void run() {
@@ -911,7 +914,8 @@
                 updateFingerprintListeningState(BIOMETRIC_ACTION_UPDATE);
             } else if (mHardwareFingerprintUnavailableRetryCount < HAL_ERROR_RETRY_MAX) {
                 mHardwareFingerprintUnavailableRetryCount++;
-                mHandler.postDelayed(mRetryFingerprintAuthentication, HAL_ERROR_RETRY_TIMEOUT);
+                mHandler.postDelayed(mRetryFingerprintAuthenticationAfterHwUnavailable,
+                        HAL_ERROR_RETRY_TIMEOUT);
             }
         }
     };
@@ -941,12 +945,16 @@
 
         if (msgId == FingerprintManager.FINGERPRINT_ERROR_HW_UNAVAILABLE) {
             mLogger.logRetryAfterFpErrorWithDelay(msgId, errString, HAL_ERROR_RETRY_TIMEOUT);
-            mHandler.postDelayed(mRetryFingerprintAuthentication, HAL_ERROR_RETRY_TIMEOUT);
+            mHandler.postDelayed(mRetryFingerprintAuthenticationAfterHwUnavailable,
+                    HAL_ERROR_RETRY_TIMEOUT);
         }
 
         if (msgId == FingerprintManager.BIOMETRIC_ERROR_POWER_PRESSED) {
-            mLogger.logRetryAfterFpErrorWithDelay(msgId, errString, 0);
-            updateFingerprintListeningState(BIOMETRIC_ACTION_START);
+            mLogger.logRetryAfterFpErrorWithDelay(msgId, errString, HAL_POWER_PRESS_TIMEOUT);
+            mHandler.postDelayed(() -> {
+                mLogger.d("Retrying fingerprint listening after power pressed error.");
+                updateFingerprintListeningState(BIOMETRIC_ACTION_START);
+            }, HAL_POWER_PRESS_TIMEOUT);
         }
 
         boolean lockedOutStateChanged = false;
@@ -1636,7 +1644,7 @@
 
                 @Override
                 public void onAuthenticationFailed() {
-                    requestActiveUnlock(
+                    requestActiveUnlockDismissKeyguard(
                             ActiveUnlockConfig.ACTIVE_UNLOCK_REQUEST_ORIGIN.BIOMETRIC_FAIL,
                             "fingerprintFailure");
                     handleFingerprintAuthFailed();
@@ -2568,6 +2576,18 @@
     }
 
     /**
+     * Attempts to trigger active unlock from trust agent with a request to dismiss the keyguard.
+     */
+    public void requestActiveUnlockDismissKeyguard(
+            @NonNull ActiveUnlockConfig.ACTIVE_UNLOCK_REQUEST_ORIGIN requestOrigin,
+            String extraReason
+    ) {
+        requestActiveUnlock(
+                requestOrigin,
+                extraReason + "-dismissKeyguard", true);
+    }
+
+    /**
      * Whether the UDFPS bouncer is showing.
      */
     public void setUdfpsBouncerShowing(boolean showing) {
diff --git a/packages/SystemUI/src/com/android/keyguard/logging/KeyguardLogger.kt b/packages/SystemUI/src/com/android/keyguard/logging/KeyguardLogger.kt
index 9e58500..886d110 100644
--- a/packages/SystemUI/src/com/android/keyguard/logging/KeyguardLogger.kt
+++ b/packages/SystemUI/src/com/android/keyguard/logging/KeyguardLogger.kt
@@ -54,35 +54,6 @@
         buffer.log(TAG, INFO, { str1 = arg.toString() }, { "$msg: $str1" })
     }
 
-    // TODO: remove after b/237743330 is fixed
-    fun logStatusBarCalculatedAlpha(alpha: Float) {
-        buffer.log(TAG, DEBUG, { double1 = alpha.toDouble() }, { "Calculated new alpha: $double1" })
-    }
-
-    // TODO: remove after b/237743330 is fixed
-    fun logStatusBarExplicitAlpha(alpha: Float) {
-        buffer.log(
-            TAG,
-            DEBUG,
-            { double1 = alpha.toDouble() },
-            { "new mExplicitAlpha value: $double1" }
-        )
-    }
-
-    // TODO: remove after b/237743330 is fixed
-    fun logStatusBarAlphaVisibility(visibility: Int, alpha: Float, state: String) {
-        buffer.log(
-            TAG,
-            DEBUG,
-            {
-                int1 = visibility
-                double1 = alpha.toDouble()
-                str1 = state
-            },
-            { "changing visibility to $int1 with alpha $double1 in state: $str1" }
-        )
-    }
-
     @JvmOverloads
     fun logBiometricMessage(
         @CompileTimeConstant context: String,
diff --git a/packages/SystemUI/src/com/android/keyguard/logging/KeyguardUpdateMonitorLogger.kt b/packages/SystemUI/src/com/android/keyguard/logging/KeyguardUpdateMonitorLogger.kt
index b66ae28..ceebe4c 100644
--- a/packages/SystemUI/src/com/android/keyguard/logging/KeyguardUpdateMonitorLogger.kt
+++ b/packages/SystemUI/src/com/android/keyguard/logging/KeyguardUpdateMonitorLogger.kt
@@ -231,7 +231,7 @@
             int2 = delay
             str1 = "$errString"
         }, {
-            "Fingerprint retrying auth after $int2 ms due to($int1) -> $str1"
+            "Fingerprint scheduling retry auth after $int2 ms due to($int1) -> $str1"
         })
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIInitializer.java b/packages/SystemUI/src/com/android/systemui/SystemUIInitializer.java
index 632fcdc..0fc9ef9 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIInitializer.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIInitializer.java
@@ -22,6 +22,8 @@
 import android.os.HandlerThread;
 import android.util.Log;
 
+import androidx.annotation.Nullable;
+
 import com.android.systemui.dagger.GlobalRootComponent;
 import com.android.systemui.dagger.SysUIComponent;
 import com.android.systemui.dagger.WMComponent;
@@ -53,6 +55,7 @@
         mContext = context;
     }
 
+    @Nullable
     protected abstract GlobalRootComponent.Builder getGlobalRootComponentBuilder();
 
     /**
@@ -69,6 +72,11 @@
      * Starts the initialization process. This stands up the Dagger graph.
      */
     public void init(boolean fromTest) throws ExecutionException, InterruptedException {
+        GlobalRootComponent.Builder globalBuilder = getGlobalRootComponentBuilder();
+        if (globalBuilder == null) {
+            return;
+        }
+
         mRootComponent = getGlobalRootComponentBuilder()
                 .context(mContext)
                 .instrumentationTest(fromTest)
@@ -119,6 +127,7 @@
                     .setBackAnimation(Optional.ofNullable(null))
                     .setDesktopMode(Optional.ofNullable(null));
         }
+
         mSysUIComponent = builder.build();
         if (initializeComponents) {
             mSysUIComponent.init();
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIInitializerImpl.kt b/packages/SystemUI/src/com/android/systemui/SystemUIInitializerImpl.kt
index 8aa3040..55c095b 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIInitializerImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIInitializerImpl.kt
@@ -16,6 +16,7 @@
 
 package com.android.systemui
 
+import android.app.Application
 import android.content.Context
 import com.android.systemui.dagger.DaggerReferenceGlobalRootComponent
 import com.android.systemui.dagger.GlobalRootComponent
@@ -24,7 +25,17 @@
  * {@link SystemUIInitializer} that stands up AOSP SystemUI.
  */
 class SystemUIInitializerImpl(context: Context) : SystemUIInitializer(context) {
-    override fun getGlobalRootComponentBuilder(): GlobalRootComponent.Builder {
-        return DaggerReferenceGlobalRootComponent.builder()
+
+    override fun getGlobalRootComponentBuilder(): GlobalRootComponent.Builder? {
+        return when (Application.getProcessName()) {
+            SCREENSHOT_CROSS_PROFILE_PROCESS -> null
+            else -> DaggerReferenceGlobalRootComponent.builder()
+        }
+    }
+
+    companion object {
+        private const val SYSTEMUI_PROCESS = "com.android.systemui"
+        private const val SCREENSHOT_CROSS_PROFILE_PROCESS =
+                "$SYSTEMUI_PROCESS:screenshot_cross_profile"
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuAnimationController.java b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuAnimationController.java
index 1e14763..e2a9d54 100644
--- a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuAnimationController.java
+++ b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuAnimationController.java
@@ -25,6 +25,9 @@
 import android.os.Looper;
 import android.util.Log;
 import android.view.View;
+import android.view.animation.Animation;
+import android.view.animation.OvershootInterpolator;
+import android.view.animation.TranslateAnimation;
 
 import androidx.dynamicanimation.animation.DynamicAnimation;
 import androidx.dynamicanimation.animation.FlingAnimation;
@@ -33,6 +36,7 @@
 import androidx.dynamicanimation.animation.SpringForce;
 import androidx.recyclerview.widget.RecyclerView;
 
+import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.util.Preconditions;
 
 import java.util.HashMap;
@@ -55,7 +59,11 @@
     private static final float SPRING_AFTER_FLING_DAMPING_RATIO = 0.85f;
     private static final float SPRING_STIFFNESS = 700f;
     private static final float ESCAPE_VELOCITY = 750f;
+    // Make tucked animation by using translation X relative to the view itself.
+    private static final float ANIMATION_TO_X_VALUE = 0.5f;
 
+    private static final int ANIMATION_START_OFFSET_MS = 600;
+    private static final int ANIMATION_DURATION_MS = 600;
     private static final int FADE_OUT_DURATION_MS = 1000;
     private static final int FADE_EFFECT_DURATION_MS = 3000;
 
@@ -64,10 +72,12 @@
     private final Handler mHandler;
     private boolean mIsFadeEffectEnabled;
     private DismissAnimationController.DismissCallback mDismissCallback;
+    private Runnable mSpringAnimationsEndAction;
 
     // Cache the animations state of {@link DynamicAnimation.TRANSLATION_X} and {@link
     // DynamicAnimation.TRANSLATION_Y} to be well controlled by the touch handler
-    private final HashMap<DynamicAnimation.ViewProperty, DynamicAnimation> mPositionAnimations =
+    @VisibleForTesting
+    final HashMap<DynamicAnimation.ViewProperty, DynamicAnimation> mPositionAnimations =
             new HashMap<>();
 
     MenuAnimationController(MenuView menuView) {
@@ -102,6 +112,13 @@
         }
     }
 
+    /**
+     * Sets the action to be called when the all dynamic animations are completed.
+     */
+    void setSpringAnimationsEndAction(Runnable runnable) {
+        mSpringAnimationsEndAction = runnable;
+    }
+
     void setDismissCallback(
             DismissAnimationController.DismissCallback dismissCallback) {
         mDismissCallback = dismissCallback;
@@ -192,7 +209,7 @@
                         ? bounds.right
                         : bounds.bottom;
 
-        final FlingAnimation flingAnimation = new FlingAnimation(mMenuView, menuPositionProperty);
+        final FlingAnimation flingAnimation = createFlingAnimation(mMenuView, menuPositionProperty);
         flingAnimation.setFriction(friction)
                 .setStartVelocity(velocity)
                 .setMinValue(Math.min(currentValue, min))
@@ -217,7 +234,14 @@
         flingAnimation.start();
     }
 
-    private void springMenuWith(DynamicAnimation.ViewProperty property, SpringForce spring,
+    @VisibleForTesting
+    FlingAnimation createFlingAnimation(MenuView menuView,
+            MenuPositionProperty menuPositionProperty) {
+        return new FlingAnimation(menuView, menuPositionProperty);
+    }
+
+    @VisibleForTesting
+    void springMenuWith(DynamicAnimation.ViewProperty property, SpringForce spring,
             float velocity, float finalPosition) {
         final MenuPositionProperty menuPositionProperty = new MenuPositionProperty(property);
         final SpringAnimation springAnimation =
@@ -228,8 +252,13 @@
                                 return;
                             }
 
-                            onSpringAnimationEnd(new PointF(mMenuView.getTranslationX(),
-                                    mMenuView.getTranslationY()));
+                            final boolean areAnimationsRunning =
+                                    mPositionAnimations.values().stream().anyMatch(
+                                            DynamicAnimation::isRunning);
+                            if (!areAnimationsRunning) {
+                                onSpringAnimationsEnd(new PointF(mMenuView.getTranslationX(),
+                                        mMenuView.getTranslationY()));
+                            }
                         })
                         .setStartVelocity(velocity);
 
@@ -332,11 +361,15 @@
                 .start();
     }
 
-    private void onSpringAnimationEnd(PointF position) {
+    private void onSpringAnimationsEnd(PointF position) {
         mMenuView.onBoundsInParentChanged((int) position.x, (int) position.y);
         constrainPositionAndUpdate(position);
 
         fadeOutIfEnabled();
+
+        if (mSpringAnimationsEndAction != null) {
+            mSpringAnimationsEndAction.run();
+        }
     }
 
     private void constrainPositionAndUpdate(PointF position) {
@@ -387,6 +420,26 @@
         mHandler.removeCallbacksAndMessages(/* token= */ null);
     }
 
+    void startTuckedAnimationPreview() {
+        fadeInNowIfEnabled();
+
+        final float toXValue = isOnLeftSide()
+                ? -ANIMATION_TO_X_VALUE
+                : ANIMATION_TO_X_VALUE;
+        final TranslateAnimation animation =
+                new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0,
+                        Animation.RELATIVE_TO_SELF, toXValue,
+                        Animation.RELATIVE_TO_SELF, 0,
+                        Animation.RELATIVE_TO_SELF, 0);
+        animation.setDuration(ANIMATION_DURATION_MS);
+        animation.setRepeatMode(Animation.REVERSE);
+        animation.setInterpolator(new OvershootInterpolator());
+        animation.setRepeatCount(Animation.INFINITE);
+        animation.setStartOffset(ANIMATION_START_OFFSET_MS);
+
+        mMenuView.startAnimation(animation);
+    }
+
     private Handler createUiHandler() {
         return new Handler(requireNonNull(Looper.myLooper(), "looper must not be null"));
     }
diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuEduTooltipView.java b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuEduTooltipView.java
new file mode 100644
index 0000000..4400534
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuEduTooltipView.java
@@ -0,0 +1,222 @@
+/*
+ * 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.systemui.accessibility.floatingmenu;
+
+import static android.util.TypedValue.COMPLEX_UNIT_PX;
+import static android.view.View.MeasureSpec.AT_MOST;
+import static android.view.View.MeasureSpec.UNSPECIFIED;
+
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.graphics.CornerPathEffect;
+import android.graphics.Paint;
+import android.graphics.PointF;
+import android.graphics.Rect;
+import android.graphics.drawable.GradientDrawable;
+import android.graphics.drawable.ShapeDrawable;
+import android.text.method.LinkMovementMethod;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+
+import com.android.settingslib.Utils;
+import com.android.systemui.R;
+import com.android.systemui.recents.TriangleShape;
+
+/**
+ * The tooltip view shows the information about the operation of the anchor view {@link MenuView}
+ * . It's just shown on the left or right of the anchor view.
+ */
+@SuppressLint("ViewConstructor")
+class MenuEduTooltipView extends FrameLayout {
+    private int mFontSize;
+    private int mTextViewMargin;
+    private int mTextViewPadding;
+    private int mTextViewCornerRadius;
+    private int mArrowMargin;
+    private int mArrowWidth;
+    private int mArrowHeight;
+    private int mArrowCornerRadius;
+    private int mColorAccentPrimary;
+    private View mArrowLeftView;
+    private View mArrowRightView;
+    private TextView mMessageView;
+    private final MenuViewAppearance mMenuViewAppearance;
+
+    MenuEduTooltipView(@NonNull Context context, MenuViewAppearance menuViewAppearance) {
+        super(context);
+
+        mMenuViewAppearance = menuViewAppearance;
+
+        updateResources();
+        initViews();
+    }
+
+    @Override
+    protected void onConfigurationChanged(Configuration newConfig) {
+        super.onConfigurationChanged(newConfig);
+
+        updateResources();
+        updateMessageView();
+        updateArrowView();
+
+        updateLocationAndVisibility();
+    }
+
+    void show(CharSequence message) {
+        mMessageView.setText(message);
+
+        updateLocationAndVisibility();
+    }
+
+    void updateLocationAndVisibility() {
+        final boolean isTooltipOnRightOfAnchor = mMenuViewAppearance.isMenuOnLeftSide();
+        updateArrowVisibilityWith(isTooltipOnRightOfAnchor);
+        updateLocationWith(getMenuBoundsInParent(), isTooltipOnRightOfAnchor);
+    }
+
+    /**
+     * Gets the bounds of the {@link MenuView}. Besides, its parent view {@link MenuViewLayer} is
+     * also the root view of the tooltip view.
+     *
+     * @return The menu bounds based on its parent view.
+     */
+    private Rect getMenuBoundsInParent() {
+        final Rect bounds = new Rect();
+        final PointF position = mMenuViewAppearance.getMenuPosition();
+
+        bounds.set((int) position.x, (int) position.y,
+                (int) position.x + mMenuViewAppearance.getMenuWidth(),
+                (int) position.y + mMenuViewAppearance.getMenuHeight());
+
+        return bounds;
+    }
+
+    private void updateResources() {
+        final Resources res = getResources();
+
+        mArrowWidth =
+                res.getDimensionPixelSize(R.dimen.accessibility_floating_tooltip_arrow_width);
+        mArrowHeight =
+                res.getDimensionPixelSize(R.dimen.accessibility_floating_tooltip_arrow_height);
+        mArrowMargin =
+                res.getDimensionPixelSize(
+                        R.dimen.accessibility_floating_tooltip_arrow_margin);
+        mArrowCornerRadius =
+                res.getDimensionPixelSize(
+                        R.dimen.accessibility_floating_tooltip_arrow_corner_radius);
+        mFontSize =
+                res.getDimensionPixelSize(R.dimen.accessibility_floating_tooltip_font_size);
+        mTextViewMargin =
+                res.getDimensionPixelSize(R.dimen.accessibility_floating_tooltip_margin);
+        mTextViewPadding =
+                res.getDimensionPixelSize(R.dimen.accessibility_floating_tooltip_padding);
+        mTextViewCornerRadius =
+                res.getDimensionPixelSize(
+                        R.dimen.accessibility_floating_tooltip_text_corner_radius);
+        mColorAccentPrimary = Utils.getColorAttrDefaultColor(getContext(),
+                com.android.internal.R.attr.colorAccentPrimary);
+    }
+
+    private void updateLocationWith(Rect anchorBoundsInParent, boolean isTooltipOnRightOfAnchor) {
+        final int widthSpec = MeasureSpec.makeMeasureSpec(
+                getAvailableTextViewWidth(isTooltipOnRightOfAnchor), AT_MOST);
+        final int heightSpec = MeasureSpec.makeMeasureSpec(/* size= */ 0, UNSPECIFIED);
+        mMessageView.measure(widthSpec, heightSpec);
+        final LinearLayout.LayoutParams textViewParams =
+                (LinearLayout.LayoutParams) mMessageView.getLayoutParams();
+        textViewParams.width = mMessageView.getMeasuredWidth();
+        mMessageView.setLayoutParams(textViewParams);
+
+        final int layoutWidth = mMessageView.getMeasuredWidth() + mArrowWidth + mArrowMargin;
+        setTranslationX(isTooltipOnRightOfAnchor
+                ? anchorBoundsInParent.right
+                : anchorBoundsInParent.left - layoutWidth);
+
+        setTranslationY(anchorBoundsInParent.centerY() - (mMessageView.getMeasuredHeight() / 2.0f));
+    }
+
+    private void updateMessageView() {
+        mMessageView.setTextSize(COMPLEX_UNIT_PX, mFontSize);
+        mMessageView.setPadding(mTextViewPadding, mTextViewPadding, mTextViewPadding,
+                mTextViewPadding);
+
+        final GradientDrawable gradientDrawable = (GradientDrawable) mMessageView.getBackground();
+        gradientDrawable.setCornerRadius(mTextViewCornerRadius);
+        gradientDrawable.setColor(mColorAccentPrimary);
+    }
+
+    private void updateArrowView() {
+        drawArrow(mArrowLeftView, /* isPointingLeft= */ true);
+        drawArrow(mArrowRightView, /* isPointingLeft= */ false);
+    }
+
+    private void updateArrowVisibilityWith(boolean isTooltipOnRightOfAnchor) {
+        if (isTooltipOnRightOfAnchor) {
+            mArrowLeftView.setVisibility(VISIBLE);
+            mArrowRightView.setVisibility(GONE);
+        } else {
+            mArrowLeftView.setVisibility(GONE);
+            mArrowRightView.setVisibility(VISIBLE);
+        }
+    }
+
+    private void drawArrow(View arrowView, boolean isPointingLeft) {
+        final TriangleShape triangleShape =
+                TriangleShape.createHorizontal(mArrowWidth, mArrowHeight, isPointingLeft);
+        final ShapeDrawable arrowDrawable = new ShapeDrawable(triangleShape);
+        final Paint arrowPaint = arrowDrawable.getPaint();
+        arrowPaint.setColor(mColorAccentPrimary);
+
+        final CornerPathEffect effect = new CornerPathEffect(mArrowCornerRadius);
+        arrowPaint.setPathEffect(effect);
+
+        arrowView.setBackground(arrowDrawable);
+    }
+
+    private void initViews() {
+        final View contentView = LayoutInflater.from(getContext()).inflate(
+                R.layout.accessibility_floating_menu_tooltip, /* root= */ this, /* attachToRoot= */
+                false);
+
+        mMessageView = contentView.findViewById(R.id.text);
+        mMessageView.setMovementMethod(LinkMovementMethod.getInstance());
+
+        mArrowLeftView = contentView.findViewById(R.id.arrow_left);
+        mArrowRightView = contentView.findViewById(R.id.arrow_right);
+
+        updateMessageView();
+        updateArrowView();
+
+        addView(contentView);
+    }
+
+    private int getAvailableTextViewWidth(boolean isOnRightOfAnchor) {
+        final PointF position = mMenuViewAppearance.getMenuPosition();
+        final int availableWidth = isOnRightOfAnchor
+                ? mMenuViewAppearance.getMenuDraggableBounds().width() - (int) position.x
+                : (int) position.x;
+
+        return availableWidth - mArrowWidth - mArrowMargin - mTextViewMargin;
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuInfoRepository.java b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuInfoRepository.java
index 5bc7406..05e1d3f 100644
--- a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuInfoRepository.java
+++ b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuInfoRepository.java
@@ -17,6 +17,7 @@
 package com.android.systemui.accessibility.floatingmenu;
 
 import static android.provider.Settings.Secure.ACCESSIBILITY_FLOATING_MENU_FADE_ENABLED;
+import static android.provider.Settings.Secure.ACCESSIBILITY_FLOATING_MENU_MIGRATION_TOOLTIP_PROMPT;
 import static android.provider.Settings.Secure.ACCESSIBILITY_FLOATING_MENU_OPACITY;
 import static android.provider.Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE;
 import static android.provider.Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES;
@@ -28,6 +29,7 @@
 import static com.android.systemui.accessibility.floatingmenu.MenuViewAppearance.MenuSizeType.SMALL;
 
 import android.annotation.FloatRange;
+import android.annotation.IntDef;
 import android.content.Context;
 import android.database.ContentObserver;
 import android.os.Handler;
@@ -40,6 +42,8 @@
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.systemui.Prefs;
 
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
 import java.util.List;
 
 /**
@@ -52,12 +56,24 @@
     @FloatRange(from = 0.0, to = 1.0)
     private static final float DEFAULT_MENU_POSITION_Y_PERCENT = 0.77f;
     private static final boolean DEFAULT_MOVE_TO_TUCKED_VALUE = false;
+    private static final boolean DEFAULT_HAS_SEEN_DOCK_TOOLTIP_VALUE = false;
+    private static final int DEFAULT_MIGRATION_TOOLTIP_VALUE_PROMPT = MigrationPrompt.DISABLED;
 
     private final Context mContext;
     private final Handler mHandler = new Handler(Looper.getMainLooper());
     private final OnSettingsContentsChanged mSettingsContentsCallback;
     private Position mPercentagePosition;
 
+    @IntDef({
+            MigrationPrompt.DISABLED,
+            MigrationPrompt.ENABLED,
+    })
+    @Retention(RetentionPolicy.SOURCE)
+    @interface MigrationPrompt {
+        int DISABLED = 0;
+        int ENABLED = 1;
+    }
+
     private final ContentObserver mMenuTargetFeaturesContentObserver =
             new ContentObserver(mHandler) {
                 @Override
@@ -99,6 +115,19 @@
                         DEFAULT_MOVE_TO_TUCKED_VALUE));
     }
 
+    void loadDockTooltipVisibility(OnInfoReady<Boolean> callback) {
+        callback.onReady(Prefs.getBoolean(mContext,
+                Prefs.Key.HAS_SEEN_ACCESSIBILITY_FLOATING_MENU_DOCK_TOOLTIP,
+                DEFAULT_HAS_SEEN_DOCK_TOOLTIP_VALUE));
+    }
+
+    void loadMigrationTooltipVisibility(OnInfoReady<Boolean> callback) {
+        callback.onReady(Settings.Secure.getIntForUser(mContext.getContentResolver(),
+                ACCESSIBILITY_FLOATING_MENU_MIGRATION_TOOLTIP_PROMPT,
+                DEFAULT_MIGRATION_TOOLTIP_VALUE_PROMPT, UserHandle.USER_CURRENT)
+                == MigrationPrompt.ENABLED);
+    }
+
     void loadMenuPosition(OnInfoReady<Position> callback) {
         callback.onReady(mPercentagePosition);
     }
@@ -131,6 +160,18 @@
                 percentagePosition.toString());
     }
 
+    void updateDockTooltipVisibility(boolean hasSeen) {
+        Prefs.putBoolean(mContext, Prefs.Key.HAS_SEEN_ACCESSIBILITY_FLOATING_MENU_DOCK_TOOLTIP,
+                hasSeen);
+    }
+
+    void updateMigrationTooltipVisibility(boolean visible) {
+        Settings.Secure.putIntForUser(mContext.getContentResolver(),
+                ACCESSIBILITY_FLOATING_MENU_MIGRATION_TOOLTIP_PROMPT,
+                visible ? MigrationPrompt.ENABLED : MigrationPrompt.DISABLED,
+                UserHandle.USER_CURRENT);
+    }
+
     private Position getStartPosition() {
         final String absolutePositionString = Prefs.getString(mContext,
                 Prefs.Key.ACCESSIBILITY_FLOATING_MENU_POSITION, /* defaultValue= */ null);
diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuListViewTouchHandler.java b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuListViewTouchHandler.java
index bc3cf0a..8a31142 100644
--- a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuListViewTouchHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuListViewTouchHandler.java
@@ -25,6 +25,8 @@
 import androidx.annotation.NonNull;
 import androidx.recyclerview.widget.RecyclerView;
 
+import java.util.Optional;
+
 /**
  * Controls the all touch events of the accessibility target features view{@link RecyclerView} in
  * the {@link MenuView}. And then compute the gestures' velocity for fling and spring
@@ -39,6 +41,7 @@
     private boolean mIsDragging = false;
     private float mTouchSlop;
     private final DismissAnimationController mDismissAnimationController;
+    private Optional<Runnable> mOnActionDownEnd = Optional.empty();
 
     MenuListViewTouchHandler(MenuAnimationController menuAnimationController,
             DismissAnimationController dismissAnimationController) {
@@ -65,6 +68,8 @@
 
                 mMenuAnimationController.cancelAnimations();
                 mDismissAnimationController.maybeConsumeDownMotionEvent(motionEvent);
+
+                mOnActionDownEnd.ifPresent(Runnable::run);
                 break;
             case MotionEvent.ACTION_MOVE:
                 if (mIsDragging || Math.hypot(dx, dy) > mTouchSlop) {
@@ -125,6 +130,10 @@
         // Do nothing
     }
 
+    void setOnActionDownEndListener(Runnable onActionDownEndListener) {
+        mOnActionDownEnd = Optional.ofNullable(onActionDownEndListener);
+    }
+
     /**
      * Adds a movement to the velocity tracker using raw screen coordinates.
      */
diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuViewAppearance.java b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuViewAppearance.java
index a7cdeab..3cd250f 100644
--- a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuViewAppearance.java
+++ b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuViewAppearance.java
@@ -293,7 +293,7 @@
         return bounds;
     }
 
-    private boolean isMenuOnLeftSide() {
+    boolean isMenuOnLeftSide() {
         return mPercentagePosition.getPercentageX() < 0.5f;
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuViewLayer.java b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuViewLayer.java
index c42943c..6f5b39c 100644
--- a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuViewLayer.java
+++ b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuViewLayer.java
@@ -20,6 +20,7 @@
 
 import static androidx.core.view.WindowInsetsCompat.Type;
 
+import static com.android.internal.accessibility.AccessibilityShortcutController.ACCESSIBILITY_BUTTON_COMPONENT_NAME;
 import static com.android.internal.accessibility.common.ShortcutConstants.AccessibilityFragmentType.INVISIBLE_TOGGLE;
 import static com.android.internal.accessibility.util.AccessibilityUtils.getAccessibilityServiceFragmentType;
 import static com.android.internal.accessibility.util.AccessibilityUtils.setAccessibilityServiceState;
@@ -27,8 +28,10 @@
 
 import android.accessibilityservice.AccessibilityServiceInfo;
 import android.annotation.IntDef;
+import android.annotation.StringDef;
 import android.annotation.SuppressLint;
 import android.content.Context;
+import android.content.Intent;
 import android.content.res.Configuration;
 import android.graphics.Rect;
 import android.os.Handler;
@@ -37,6 +40,8 @@
 import android.provider.Settings;
 import android.util.PluralsMessageFormatter;
 import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewTreeObserver;
 import android.view.WindowInsets;
 import android.view.WindowManager;
 import android.view.WindowMetrics;
@@ -45,6 +50,7 @@
 import android.widget.TextView;
 
 import androidx.annotation.NonNull;
+import androidx.lifecycle.Observer;
 
 import com.android.internal.accessibility.dialog.AccessibilityTarget;
 import com.android.internal.annotations.VisibleForTesting;
@@ -58,6 +64,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 
 /**
  * The basic interactions with the child views {@link MenuView}, {@link DismissView}, and
@@ -66,11 +73,13 @@
  * message view would be shown and allowed users to undo it.
  */
 @SuppressLint("ViewConstructor")
-class MenuViewLayer extends FrameLayout {
+class MenuViewLayer extends FrameLayout implements
+        ViewTreeObserver.OnComputeInternalInsetsListener, View.OnClickListener {
     private static final int SHOW_MESSAGE_DELAY_MS = 3000;
 
     private final WindowManager mWindowManager;
     private final MenuView mMenuView;
+    private final MenuListViewTouchHandler mMenuListViewTouchHandler;
     private final MenuMessageView mMessageView;
     private final DismissView mDismissView;
     private final MenuViewAppearance mMenuViewAppearance;
@@ -79,18 +88,38 @@
     private final Handler mHandler = new Handler(Looper.getMainLooper());
     private final IAccessibilityFloatingMenu mFloatingMenu;
     private final DismissAnimationController mDismissAnimationController;
+    private final MenuViewModel mMenuViewModel;
+    private final Observer<Boolean> mDockTooltipObserver =
+            this::onDockTooltipVisibilityChanged;
+    private final Observer<Boolean> mMigrationTooltipObserver =
+            this::onMigrationTooltipVisibilityChanged;
     private final Rect mImeInsetsRect = new Rect();
+    private boolean mIsMigrationTooltipShowing;
+    private boolean mShouldShowDockTooltip;
+    private Optional<MenuEduTooltipView> mEduTooltipView = Optional.empty();
 
     @IntDef({
             LayerIndex.MENU_VIEW,
             LayerIndex.DISMISS_VIEW,
             LayerIndex.MESSAGE_VIEW,
+            LayerIndex.TOOLTIP_VIEW,
     })
     @Retention(RetentionPolicy.SOURCE)
     @interface LayerIndex {
         int MENU_VIEW = 0;
         int DISMISS_VIEW = 1;
         int MESSAGE_VIEW = 2;
+        int TOOLTIP_VIEW = 3;
+    }
+
+    @StringDef({
+            TooltipType.MIGRATION,
+            TooltipType.DOCK,
+    })
+    @Retention(RetentionPolicy.SOURCE)
+    @interface TooltipType {
+        String MIGRATION = "migration";
+        String DOCK = "dock";
     }
 
     @VisibleForTesting
@@ -125,12 +154,12 @@
         mAccessibilityManager = accessibilityManager;
         mFloatingMenu = floatingMenu;
 
-        final MenuViewModel menuViewModel = new MenuViewModel(context);
+        mMenuViewModel = new MenuViewModel(context);
         mMenuViewAppearance = new MenuViewAppearance(context, windowManager);
-        mMenuView = new MenuView(context, menuViewModel, mMenuViewAppearance);
+        mMenuView = new MenuView(context, mMenuViewModel, mMenuViewAppearance);
         mMenuAnimationController = mMenuView.getMenuAnimationController();
         mMenuAnimationController.setDismissCallback(this::hideMenuAndShowMessage);
-
+        mMenuAnimationController.setSpringAnimationsEndAction(this::onSpringAnimationsEndAction);
         mDismissView = new DismissView(context);
         mDismissAnimationController = new DismissAnimationController(mDismissView, mMenuView);
         mDismissAnimationController.setMagnetListener(new MagnetizedObject.MagnetListener() {
@@ -153,9 +182,9 @@
             }
         });
 
-        final MenuListViewTouchHandler menuListViewTouchHandler = new MenuListViewTouchHandler(
-                mMenuAnimationController, mDismissAnimationController);
-        mMenuView.addOnItemTouchListenerToList(menuListViewTouchHandler);
+        mMenuListViewTouchHandler = new MenuListViewTouchHandler(mMenuAnimationController,
+                mDismissAnimationController);
+        mMenuView.addOnItemTouchListenerToList(mMenuListViewTouchHandler);
 
         mMessageView = new MenuMessageView(context);
 
@@ -210,7 +239,12 @@
         super.onAttachedToWindow();
 
         mMenuView.show();
+        setOnClickListener(this);
         setOnApplyWindowInsetsListener((view, insets) -> onWindowInsetsApplied(insets));
+        getViewTreeObserver().addOnComputeInternalInsetsListener(this);
+        mMenuViewModel.getDockTooltipVisibilityData().observeForever(mDockTooltipObserver);
+        mMenuViewModel.getMigrationTooltipVisibilityData().observeForever(
+                mMigrationTooltipObserver);
         mMessageView.setUndoListener(view -> undo());
         mContext.registerComponentCallbacks(mDismissAnimationController);
     }
@@ -220,11 +254,32 @@
         super.onDetachedFromWindow();
 
         mMenuView.hide();
+        setOnClickListener(null);
         setOnApplyWindowInsetsListener(null);
+        getViewTreeObserver().removeOnComputeInternalInsetsListener(this);
+        mMenuViewModel.getDockTooltipVisibilityData().removeObserver(mDockTooltipObserver);
+        mMenuViewModel.getMigrationTooltipVisibilityData().removeObserver(
+                mMigrationTooltipObserver);
         mHandler.removeCallbacksAndMessages(/* token= */ null);
         mContext.unregisterComponentCallbacks(mDismissAnimationController);
     }
 
+    @Override
+    public void onComputeInternalInsets(ViewTreeObserver.InternalInsetsInfo inoutInfo) {
+        inoutInfo.setTouchableInsets(ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION);
+
+        if (mEduTooltipView.isPresent()) {
+            final int x = (int) getX();
+            final int y = (int) getY();
+            inoutInfo.touchableRegion.union(new Rect(x, y, x + getWidth(), y + getHeight()));
+        }
+    }
+
+    @Override
+    public void onClick(View v) {
+        mEduTooltipView.ifPresent(this::removeTooltip);
+    }
+
     private WindowInsets onWindowInsetsApplied(WindowInsets insets) {
         final WindowMetrics windowMetrics = mWindowManager.getCurrentWindowMetrics();
         final WindowInsets windowInsets = windowMetrics.getWindowInsets();
@@ -249,6 +304,78 @@
         return insets;
     }
 
+    private void onMigrationTooltipVisibilityChanged(boolean visible) {
+        mIsMigrationTooltipShowing = visible;
+
+        if (mIsMigrationTooltipShowing) {
+            mEduTooltipView = Optional.of(new MenuEduTooltipView(mContext, mMenuViewAppearance));
+            mEduTooltipView.ifPresent(
+                    view -> addTooltipView(view, getMigrationMessage(), TooltipType.MIGRATION));
+        }
+    }
+
+    private void onDockTooltipVisibilityChanged(boolean hasSeenTooltip) {
+        mShouldShowDockTooltip = !hasSeenTooltip;
+    }
+
+    private void onSpringAnimationsEndAction() {
+        if (mShouldShowDockTooltip) {
+            mEduTooltipView = Optional.of(new MenuEduTooltipView(mContext, mMenuViewAppearance));
+            mEduTooltipView.ifPresent(view -> addTooltipView(view,
+                    getContext().getText(R.string.accessibility_floating_button_docking_tooltip),
+                    TooltipType.DOCK));
+
+            mMenuAnimationController.startTuckedAnimationPreview();
+        }
+    }
+
+    private CharSequence getMigrationMessage() {
+        final Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_DETAILS_SETTINGS);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        intent.putExtra(Intent.EXTRA_COMPONENT_NAME,
+                ACCESSIBILITY_BUTTON_COMPONENT_NAME.flattenToShortString());
+
+        final AnnotationLinkSpan.LinkInfo linkInfo = new AnnotationLinkSpan.LinkInfo(
+                AnnotationLinkSpan.LinkInfo.DEFAULT_ANNOTATION,
+                v -> {
+                    getContext().startActivity(intent);
+                    mEduTooltipView.ifPresent(this::removeTooltip);
+                });
+
+        final int textResId = R.string.accessibility_floating_button_migration_tooltip;
+
+        return AnnotationLinkSpan.linkify(getContext().getText(textResId), linkInfo);
+    }
+
+    private void addTooltipView(MenuEduTooltipView tooltipView, CharSequence message,
+            CharSequence tag) {
+        addView(tooltipView, LayerIndex.TOOLTIP_VIEW);
+
+        tooltipView.show(message);
+        tooltipView.setTag(tag);
+
+        mMenuListViewTouchHandler.setOnActionDownEndListener(
+                () -> mEduTooltipView.ifPresent(this::removeTooltip));
+    }
+
+    private void removeTooltip(View tooltipView) {
+        if (tooltipView.getTag().equals(TooltipType.MIGRATION)) {
+            mMenuViewModel.updateMigrationTooltipVisibility(/* visible= */ false);
+            mIsMigrationTooltipShowing = false;
+        }
+
+        if (tooltipView.getTag().equals(TooltipType.DOCK)) {
+            mMenuViewModel.updateDockTooltipVisibility(/* hasSeen= */ true);
+            mMenuView.clearAnimation();
+            mShouldShowDockTooltip = false;
+        }
+
+        removeView(tooltipView);
+
+        mMenuListViewTouchHandler.setOnActionDownEndListener(null);
+        mEduTooltipView = Optional.empty();
+    }
+
     private void hideMenuAndShowMessage() {
         final int delayTime = mAccessibilityManager.getRecommendedTimeoutMillis(
                 SHOW_MESSAGE_DELAY_MS,
diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuViewModel.java b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuViewModel.java
index bd41787..5fea3b0 100644
--- a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuViewModel.java
+++ b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuViewModel.java
@@ -36,6 +36,8 @@
     private final MutableLiveData<MenuFadeEffectInfo> mFadeEffectInfoData =
             new MutableLiveData<>();
     private final MutableLiveData<Boolean> mMoveToTuckedData = new MutableLiveData<>();
+    private final MutableLiveData<Boolean> mDockTooltipData = new MutableLiveData<>();
+    private final MutableLiveData<Boolean> mMigrationTooltipData = new MutableLiveData<>();
     private final MutableLiveData<Position> mPercentagePositionData = new MutableLiveData<>();
     private final MenuInfoRepository mInfoRepository;
 
@@ -66,11 +68,29 @@
         mInfoRepository.updateMenuSavingPosition(percentagePosition);
     }
 
+    void updateDockTooltipVisibility(boolean hasSeen) {
+        mInfoRepository.updateDockTooltipVisibility(hasSeen);
+    }
+
+    void updateMigrationTooltipVisibility(boolean visible) {
+        mInfoRepository.updateMigrationTooltipVisibility(visible);
+    }
+
     LiveData<Boolean> getMoveToTuckedData() {
         mInfoRepository.loadMenuMoveToTucked(mMoveToTuckedData::setValue);
         return mMoveToTuckedData;
     }
 
+    LiveData<Boolean> getDockTooltipVisibilityData() {
+        mInfoRepository.loadDockTooltipVisibility(mDockTooltipData::setValue);
+        return mDockTooltipData;
+    }
+
+    LiveData<Boolean> getMigrationTooltipVisibilityData() {
+        mInfoRepository.loadMigrationTooltipVisibility(mMigrationTooltipData::setValue);
+        return mMigrationTooltipData;
+    }
+
     LiveData<Position> getPercentagePositionData() {
         mInfoRepository.loadMenuPosition(mPercentagePositionData::setValue);
         return mPercentagePositionData;
diff --git a/packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java b/packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java
index 6785a43..9708d9a 100644
--- a/packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java
@@ -64,7 +64,7 @@
 @SysUISingleton
 public class AppOpsControllerImpl extends BroadcastReceiver implements AppOpsController,
         AppOpsManager.OnOpActiveChangedListener,
-        AppOpsManager.OnOpNotedListener, IndividualSensorPrivacyController.Callback,
+        AppOpsManager.OnOpNotedInternalListener, IndividualSensorPrivacyController.Callback,
         Dumpable {
 
     // This is the minimum time that we will keep AppOps that are noted on record. If multiple
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/TEST_MAPPING b/packages/SystemUI/src/com/android/systemui/biometrics/TEST_MAPPING
deleted file mode 100644
index 794eba4..0000000
--- a/packages/SystemUI/src/com/android/systemui/biometrics/TEST_MAPPING
+++ /dev/null
@@ -1,16 +0,0 @@
-{
-  "presubmit": [
-    {
-      // TODO(b/251476085): Consider merging with SystemUIGoogleScreenshotTests (in U+)
-      "name": "SystemUIGoogleBiometricsScreenshotTests",
-      "options": [
-        {
-          "exclude-annotation": "org.junit.Ignore"
-        },
-        {
-          "exclude-annotation": "androidx.test.filters.FlakyTest"
-        }
-      ]
-    }
-  ]
-}
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java
index 19b0548..1613ca1 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java
@@ -97,6 +97,7 @@
 import java.util.concurrent.Executor;
 
 import javax.inject.Inject;
+import javax.inject.Provider;
 
 import kotlin.Unit;
 
@@ -115,7 +116,7 @@
 @SysUISingleton
 public class UdfpsController implements DozeReceiver, Dumpable {
     private static final String TAG = "UdfpsController";
-    private static final long AOD_INTERRUPT_TIMEOUT_MILLIS = 1000;
+    private static final long AOD_SEND_FINGER_UP_DELAY_MILLIS = 1000;
 
     // Minimum required delay between consecutive touch logs in milliseconds.
     private static final long MIN_TOUCH_LOG_INTERVAL = 50;
@@ -178,7 +179,7 @@
     // interrupt is being tracked and a timeout is used as a last resort to turn off high brightness
     // mode.
     private boolean mIsAodInterruptActive;
-    @Nullable private Runnable mCancelAodTimeoutAction;
+    @Nullable private Runnable mCancelAodFingerUpAction;
     private boolean mScreenOn;
     private Runnable mAodInterruptRunnable;
     private boolean mOnFingerDown;
@@ -280,6 +281,7 @@
                     if (view != null && isOptical()) {
                         unconfigureDisplay(view);
                     }
+                    tryAodSendFingerUp();
                     if (acquiredGood) {
                         mOverlay.onAcquiredGood();
                     }
@@ -747,7 +749,7 @@
             @NonNull SystemUIDialogManager dialogManager,
             @NonNull LatencyTracker latencyTracker,
             @NonNull ActivityLaunchAnimator activityLaunchAnimator,
-            @NonNull Optional<AlternateUdfpsTouchProvider> alternateTouchProvider,
+            @NonNull Optional<Provider<AlternateUdfpsTouchProvider>> alternateTouchProvider,
             @NonNull @BiometricsBackground Executor biometricsExecutor,
             @NonNull PrimaryBouncerInteractor primaryBouncerInteractor,
             @NonNull SinglePointerTouchProcessor singlePointerTouchProcessor) {
@@ -779,7 +781,7 @@
         mUnlockedScreenOffAnimationController = unlockedScreenOffAnimationController;
         mLatencyTracker = latencyTracker;
         mActivityLaunchAnimator = activityLaunchAnimator;
-        mAlternateTouchProvider = alternateTouchProvider.orElse(null);
+        mAlternateTouchProvider = alternateTouchProvider.map(Provider::get).orElse(null);
         mSensorProps = new FingerprintSensorPropertiesInternal(
                 -1 /* sensorId */,
                 SensorProperties.STRENGTH_CONVENIENCE,
@@ -900,12 +902,6 @@
     private void unconfigureDisplay(@NonNull UdfpsView view) {
         if (view.isDisplayConfigured()) {
             view.unconfigureDisplay();
-
-            if (mCancelAodTimeoutAction != null) {
-                mCancelAodTimeoutAction.run();
-                mCancelAodTimeoutAction = null;
-            }
-            mIsAodInterruptActive = false;
         }
     }
 
@@ -945,8 +941,8 @@
             // ACTION_UP/ACTION_CANCEL,  we need to be careful about not letting the screen
             // accidentally remain in high brightness mode. As a mitigation, queue a call to
             // cancel the fingerprint scan.
-            mCancelAodTimeoutAction = mFgExecutor.executeDelayed(this::cancelAodInterrupt,
-                    AOD_INTERRUPT_TIMEOUT_MILLIS);
+            mCancelAodFingerUpAction = mFgExecutor.executeDelayed(this::tryAodSendFingerUp,
+                    AOD_SEND_FINGER_UP_DELAY_MILLIS);
             // using a hard-coded value for major and minor until it is available from the sensor
             onFingerDown(requestId, screenX, screenY, minor, major);
         };
@@ -980,15 +976,27 @@
      * sensors, this can result in illumination persisting for longer than necessary.
      */
     @VisibleForTesting
-    void cancelAodInterrupt() {
+    void tryAodSendFingerUp() {
         if (!mIsAodInterruptActive) {
             return;
         }
+        cancelAodSendFingerUpAction();
         if (mOverlay != null && mOverlay.getOverlayView() != null) {
             onFingerUp(mOverlay.getRequestId(), mOverlay.getOverlayView());
         }
-        mCancelAodTimeoutAction = null;
+    }
+
+    /**
+     * Cancels any scheduled AoD finger-up actions without triggered the finger-up action. Only
+     * call this method if the finger-up event has been guaranteed to have already occurred.
+     */
+    @VisibleForTesting
+    void cancelAodSendFingerUpAction() {
         mIsAodInterruptActive = false;
+        if (mCancelAodFingerUpAction != null) {
+            mCancelAodFingerUpAction.run();
+            mCancelAodFingerUpAction = null;
+        }
     }
 
     private boolean isOptical() {
@@ -1150,6 +1158,7 @@
         if (isOptical()) {
             unconfigureDisplay(view);
         }
+        cancelAodSendFingerUpAction();
     }
 
     /**
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsOverlay.kt b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsOverlay.kt
index 142642a..802b9b6 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsOverlay.kt
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsOverlay.kt
@@ -42,6 +42,7 @@
 import java.util.Optional
 import java.util.concurrent.Executor
 import javax.inject.Inject
+import javax.inject.Provider
 import kotlin.math.cos
 import kotlin.math.pow
 import kotlin.math.sin
@@ -64,7 +65,7 @@
     private val fingerprintManager: FingerprintManager?,
     private val handler: Handler,
     private val biometricExecutor: Executor,
-    private val alternateTouchProvider: Optional<AlternateUdfpsTouchProvider>,
+    private val alternateTouchProvider: Optional<Provider<AlternateUdfpsTouchProvider>>,
     @Main private val fgExecutor: DelayableExecutor,
     private val keyguardUpdateMonitor: KeyguardUpdateMonitor,
     private val authController: AuthController,
@@ -126,6 +127,7 @@
                     if (!processedMotionEvent && goodOverlap) {
                         biometricExecutor.execute {
                             alternateTouchProvider
+                                .map(Provider<AlternateUdfpsTouchProvider>::get)
                                 .get()
                                 .onPointerDown(
                                     requestId,
@@ -142,7 +144,10 @@
 
                             view.configureDisplay {
                                 biometricExecutor.execute {
-                                    alternateTouchProvider.get().onUiReady()
+                                    alternateTouchProvider
+                                        .map(Provider<AlternateUdfpsTouchProvider>::get)
+                                        .get()
+                                        .onUiReady()
                                 }
                             }
 
@@ -158,7 +163,10 @@
             MotionEvent.ACTION_CANCEL -> {
                 if (processedMotionEvent && alternateTouchProvider.isPresent) {
                     biometricExecutor.execute {
-                        alternateTouchProvider.get().onPointerUp(requestId)
+                        alternateTouchProvider
+                            .map(Provider<AlternateUdfpsTouchProvider>::get)
+                            .get()
+                            .onPointerUp(requestId)
                     }
                     fgExecutor.execute {
                         if (keyguardUpdateMonitor.isFingerprintDetectionRunning) {
@@ -241,7 +249,10 @@
             if (overlayView != null && isShowing && alternateTouchProvider.isPresent) {
                 if (processedMotionEvent) {
                     biometricExecutor.execute {
-                        alternateTouchProvider.get().onPointerUp(requestId)
+                        alternateTouchProvider
+                            .map(Provider<AlternateUdfpsTouchProvider>::get)
+                            .get()
+                            .onPointerUp(requestId)
                     }
                     fgExecutor.execute {
                         if (keyguardUpdateMonitor.isFingerprintDetectionRunning) {
diff --git a/packages/SystemUI/src/com/android/systemui/camera/CameraGestureHelper.kt b/packages/SystemUI/src/com/android/systemui/camera/CameraGestureHelper.kt
index e2ef247..58d40d3 100644
--- a/packages/SystemUI/src/com/android/systemui/camera/CameraGestureHelper.kt
+++ b/packages/SystemUI/src/com/android/systemui/camera/CameraGestureHelper.kt
@@ -28,7 +28,6 @@
 import android.os.UserHandle
 import android.util.Log
 import android.view.WindowManager
-import androidx.annotation.VisibleForTesting
 import com.android.keyguard.KeyguardUpdateMonitor
 import com.android.systemui.ActivityIntentHelper
 import com.android.systemui.dagger.qualifiers.Main
@@ -83,7 +82,7 @@
      */
     fun launchCamera(source: Int) {
         val intent: Intent = getStartCameraIntent()
-        intent.putExtra(EXTRA_CAMERA_LAUNCH_SOURCE, source)
+        intent.putExtra(CameraIntents.EXTRA_LAUNCH_SOURCE, source)
         val wouldLaunchResolverActivity = activityIntentHelper.wouldLaunchResolverActivity(
             intent, KeyguardUpdateMonitor.getCurrentUser()
         )
@@ -149,9 +148,4 @@
             cameraIntents.getInsecureCameraIntent()
         }
     }
-
-    companion object {
-        @VisibleForTesting
-        const val EXTRA_CAMERA_LAUNCH_SOURCE = "com.android.systemui.camera_launch_source"
-    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/camera/CameraIntents.kt b/packages/SystemUI/src/com/android/systemui/camera/CameraIntents.kt
index f8a2002..867faf9 100644
--- a/packages/SystemUI/src/com/android/systemui/camera/CameraIntents.kt
+++ b/packages/SystemUI/src/com/android/systemui/camera/CameraIntents.kt
@@ -29,6 +29,7 @@
                 MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE
         val DEFAULT_INSECURE_CAMERA_INTENT_ACTION =
                 MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA
+        const val EXTRA_LAUNCH_SOURCE = "com.android.systemui.camera_launch_source"
 
         @JvmStatic
         fun getOverrideCameraPackage(context: Context): String? {
diff --git a/packages/SystemUI/src/com/android/systemui/clipboardoverlay/ClipboardOverlayController.java b/packages/SystemUI/src/com/android/systemui/clipboardoverlay/ClipboardOverlayController.java
index fb37def..63c2065 100644
--- a/packages/SystemUI/src/com/android/systemui/clipboardoverlay/ClipboardOverlayController.java
+++ b/packages/SystemUI/src/com/android/systemui/clipboardoverlay/ClipboardOverlayController.java
@@ -301,7 +301,9 @@
         } else {
             mView.showDefaultTextPreview();
         }
-        maybeShowRemoteCopy(clipData);
+        if (!isRemote) {
+            maybeShowRemoteCopy(clipData);
+        }
         animateIn();
         mView.announceForAccessibility(accessibilityAnnouncement);
         if (isRemote) {
diff --git a/services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt b/packages/SystemUI/src/com/android/systemui/common/shared/model/TintedIcon.kt
similarity index 71%
copy from services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt
copy to packages/SystemUI/src/com/android/systemui/common/shared/model/TintedIcon.kt
index 528680e7..5dabbbb 100644
--- a/services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt
+++ b/packages/SystemUI/src/com/android/systemui/common/shared/model/TintedIcon.kt
@@ -14,11 +14,12 @@
  * limitations under the License.
  */
 
-package com.android.server.permission.access.external
+package com.android.systemui.common.shared.model
 
-class RoSystemProperties {
-    companion object {
-        const val CONTROL_PRIVAPP_PERMISSIONS_DISABLE = false
-        const val CONTROL_PRIVAPP_PERMISSIONS_ENFORCE = false
-    }
-}
+import androidx.annotation.AttrRes
+
+/** Models an icon with a specific tint. */
+data class TintedIcon(
+    val icon: Icon,
+    @AttrRes val tintAttr: Int?,
+)
diff --git a/packages/SystemUI/src/com/android/systemui/common/ui/binder/TintedIconViewBinder.kt b/packages/SystemUI/src/com/android/systemui/common/ui/binder/TintedIconViewBinder.kt
new file mode 100644
index 0000000..dea8cfd
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/common/ui/binder/TintedIconViewBinder.kt
@@ -0,0 +1,42 @@
+/*
+ * 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.systemui.common.ui.binder
+
+import android.widget.ImageView
+import com.android.settingslib.Utils
+import com.android.systemui.common.shared.model.TintedIcon
+
+object TintedIconViewBinder {
+    /**
+     * Binds the given tinted icon to the view.
+     *
+     * [TintedIcon.tintAttr] will always be applied, meaning that if it is null, then the tint
+     * *will* be reset to null.
+     */
+    fun bind(
+        tintedIcon: TintedIcon,
+        view: ImageView,
+    ) {
+        IconViewBinder.bind(tintedIcon.icon, view)
+        view.imageTintList =
+            if (tintedIcon.tintAttr != null) {
+                Utils.getColorAttr(view.context, tintedIcon.tintAttr)
+            } else {
+                null
+            }
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/controls/ControlsServiceInfo.kt b/packages/SystemUI/src/com/android/systemui/controls/ControlsServiceInfo.kt
index 66e5d7c4..dbe301d 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/ControlsServiceInfo.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/ControlsServiceInfo.kt
@@ -69,12 +69,14 @@
     private var resolved: Boolean = false
 
     @WorkerThread
-    fun resolvePanelActivity() {
+    fun resolvePanelActivity(
+            allowAllApps: Boolean = false
+    ) {
         if (resolved) return
         resolved = true
         val validPackages = context.resources
                 .getStringArray(R.array.config_controlsPreferredPackages)
-        if (componentName.packageName !in validPackages) return
+        if (componentName.packageName !in validPackages && !allowAllApps) return
         panelActivity = _panelActivity?.let {
             val resolveInfos = mPm.queryIntentActivitiesAsUser(
                     Intent().setComponent(it),
diff --git a/packages/SystemUI/src/com/android/systemui/controls/dagger/ControlsComponent.kt b/packages/SystemUI/src/com/android/systemui/controls/dagger/ControlsComponent.kt
index 77d0496e4..27466d4 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/dagger/ControlsComponent.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/dagger/ControlsComponent.kt
@@ -19,7 +19,7 @@
 import android.content.Context
 import com.android.internal.widget.LockPatternUtils
 import com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT
-import com.android.systemui.controls.ControlsSettingsRepository
+import com.android.systemui.controls.settings.ControlsSettingsRepository
 import com.android.systemui.controls.controller.ControlsController
 import com.android.systemui.controls.controller.ControlsTileResourceConfiguration
 import com.android.systemui.controls.controller.ControlsTileResourceConfigurationImpl
diff --git a/packages/SystemUI/src/com/android/systemui/controls/dagger/ControlsModule.kt b/packages/SystemUI/src/com/android/systemui/controls/dagger/ControlsModule.kt
index 9ae605e..6d6410d 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/dagger/ControlsModule.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/dagger/ControlsModule.kt
@@ -20,8 +20,8 @@
 import android.content.pm.PackageManager
 import com.android.systemui.controls.ControlsMetricsLogger
 import com.android.systemui.controls.ControlsMetricsLoggerImpl
-import com.android.systemui.controls.ControlsSettingsRepository
-import com.android.systemui.controls.ControlsSettingsRepositoryImpl
+import com.android.systemui.controls.settings.ControlsSettingsRepository
+import com.android.systemui.controls.settings.ControlsSettingsRepositoryImpl
 import com.android.systemui.controls.controller.ControlsBindingController
 import com.android.systemui.controls.controller.ControlsBindingControllerImpl
 import com.android.systemui.controls.controller.ControlsController
@@ -34,6 +34,8 @@
 import com.android.systemui.controls.management.ControlsListingControllerImpl
 import com.android.systemui.controls.management.ControlsProviderSelectorActivity
 import com.android.systemui.controls.management.ControlsRequestDialog
+import com.android.systemui.controls.settings.ControlsSettingsDialogManager
+import com.android.systemui.controls.settings.ControlsSettingsDialogManagerImpl
 import com.android.systemui.controls.ui.ControlActionCoordinator
 import com.android.systemui.controls.ui.ControlActionCoordinatorImpl
 import com.android.systemui.controls.ui.ControlsActivity
@@ -90,6 +92,11 @@
     ): ControlsSettingsRepository
 
     @Binds
+    abstract fun provideDialogManager(
+            manager: ControlsSettingsDialogManagerImpl
+    ): ControlsSettingsDialogManager
+
+    @Binds
     abstract fun provideMetricsLogger(logger: ControlsMetricsLoggerImpl): ControlsMetricsLogger
 
     @Binds
diff --git a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsAnimations.kt b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsAnimations.kt
index 4aa597e..8d0edf8 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsAnimations.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsAnimations.kt
@@ -50,7 +50,12 @@
      * Setup an activity to handle enter/exit animations. [view] should be the root of the content.
      * Fade and translate together.
      */
-    fun observerForAnimations(view: ViewGroup, window: Window, intent: Intent): LifecycleObserver {
+    fun observerForAnimations(
+            view: ViewGroup,
+            window: Window,
+            intent: Intent,
+            animateY: Boolean = true
+    ): LifecycleObserver {
         return object : LifecycleObserver {
             var showAnimation = intent.getBooleanExtra(ControlsUiController.EXTRA_ANIMATE, false)
 
@@ -61,8 +66,12 @@
                 view.transitionAlpha = 0.0f
 
                 if (translationY == -1f) {
-                    translationY = view.context.resources.getDimensionPixelSize(
-                        R.dimen.global_actions_controls_y_translation).toFloat()
+                    if (animateY) {
+                        translationY = view.context.resources.getDimensionPixelSize(
+                                R.dimen.global_actions_controls_y_translation).toFloat()
+                    } else {
+                        translationY = 0f
+                    }
                 }
             }
 
diff --git a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt
index c6428ef..c81a2c7 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt
@@ -98,7 +98,9 @@
         backgroundExecutor.execute {
             if (userChangeInProgress.get() > 0) return@execute
             if (featureFlags.isEnabled(Flags.USE_APP_PANELS)) {
-                newServices.forEach(ControlsServiceInfo::resolvePanelActivity)
+                val allowAllApps = featureFlags.isEnabled(Flags.APP_PANELS_ALL_APPS_ALLOWED)
+                newServices.forEach {
+                    it.resolvePanelActivity(allowAllApps) }
             }
 
             if (newServices != availableServices) {
diff --git a/packages/SystemUI/src/com/android/systemui/controls/settings/ControlsSettingsDialogManager.kt b/packages/SystemUI/src/com/android/systemui/controls/settings/ControlsSettingsDialogManager.kt
new file mode 100644
index 0000000..bb2e2d7
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/controls/settings/ControlsSettingsDialogManager.kt
@@ -0,0 +1,231 @@
+/*
+ * 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.systemui.controls.settings
+
+import android.app.AlertDialog
+import android.content.Context
+import android.content.Context.MODE_PRIVATE
+import android.content.DialogInterface
+import android.content.SharedPreferences
+import android.provider.Settings
+import androidx.annotation.VisibleForTesting
+import com.android.systemui.R
+import com.android.systemui.controls.settings.ControlsSettingsDialogManager.Companion.MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG
+import com.android.systemui.controls.settings.ControlsSettingsDialogManager.Companion.PREFS_SETTINGS_DIALOG_ATTEMPTS
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.plugins.ActivityStarter
+import com.android.systemui.settings.UserFileManager
+import com.android.systemui.settings.UserTracker
+import com.android.systemui.statusbar.phone.SystemUIDialog
+import com.android.systemui.statusbar.policy.DeviceControlsControllerImpl
+import com.android.systemui.util.settings.SecureSettings
+import javax.inject.Inject
+
+/**
+ * Manager to display a dialog to prompt user to enable controls related Settings:
+ *
+ * * [Settings.Secure.LOCKSCREEN_SHOW_CONTROLS]
+ * * [Settings.Secure.LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS]
+ */
+interface ControlsSettingsDialogManager {
+
+    /**
+     * Shows the corresponding dialog. In order for a dialog to appear, the following must be true
+     *
+     * * At least one of the Settings in [ControlsSettingsRepository] are `false`.
+     * * The dialog has not been seen by the user too many times (as defined by
+     * [MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG]).
+     *
+     * When the dialogs are shown, the following outcomes are possible:
+     * * User cancels the dialog by clicking outside or going back: we register that the dialog was
+     * seen but the settings don't change.
+     * * User responds negatively to the dialog: we register that the user doesn't want to change
+     * the settings (dialog will not appear again) and the settings don't change.
+     * * User responds positively to the dialog: the settings are set to `true` and the dialog will
+     * not appear again.
+     * * SystemUI closes the dialogs (for example, the activity showing it is closed). In this case,
+     * we don't modify anything.
+     *
+     * Of those four scenarios, only the first three will cause [onAttemptCompleted] to be called.
+     * It will also be called if the dialogs are not shown.
+     */
+    fun maybeShowDialog(activityContext: Context, onAttemptCompleted: () -> Unit)
+
+    /**
+     * Closes the dialog without registering anything from the user. The state of the settings after
+     * this is called will be the same as before the dialogs were shown.
+     */
+    fun closeDialog()
+
+    companion object {
+        @VisibleForTesting internal const val MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG = 2
+        @VisibleForTesting
+        internal const val PREFS_SETTINGS_DIALOG_ATTEMPTS = "show_settings_attempts"
+    }
+}
+
+@SysUISingleton
+class ControlsSettingsDialogManagerImpl
+@VisibleForTesting
+internal constructor(
+    private val secureSettings: SecureSettings,
+    private val userFileManager: UserFileManager,
+    private val controlsSettingsRepository: ControlsSettingsRepository,
+    private val userTracker: UserTracker,
+    private val activityStarter: ActivityStarter,
+    private val dialogProvider: (context: Context, theme: Int) -> AlertDialog
+) : ControlsSettingsDialogManager {
+
+    @Inject
+    constructor(
+        secureSettings: SecureSettings,
+        userFileManager: UserFileManager,
+        controlsSettingsRepository: ControlsSettingsRepository,
+        userTracker: UserTracker,
+        activityStarter: ActivityStarter
+    ) : this(
+        secureSettings,
+        userFileManager,
+        controlsSettingsRepository,
+        userTracker,
+        activityStarter,
+        { context, theme -> SettingsDialog(context, theme) }
+    )
+
+    private var dialog: AlertDialog? = null
+        private set
+
+    private val showDeviceControlsInLockscreen: Boolean
+        get() = controlsSettingsRepository.canShowControlsInLockscreen.value
+
+    private val allowTrivialControls: Boolean
+        get() = controlsSettingsRepository.allowActionOnTrivialControlsInLockscreen.value
+
+    override fun maybeShowDialog(activityContext: Context, onAttemptCompleted: () -> Unit) {
+        closeDialog()
+
+        val prefs =
+            userFileManager.getSharedPreferences(
+                DeviceControlsControllerImpl.PREFS_CONTROLS_FILE,
+                MODE_PRIVATE,
+                userTracker.userId
+            )
+        val attempts = prefs.getInt(PREFS_SETTINGS_DIALOG_ATTEMPTS, 0)
+        if (
+            attempts >= MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG ||
+                (showDeviceControlsInLockscreen && allowTrivialControls)
+        ) {
+            onAttemptCompleted()
+            return
+        }
+
+        val listener = DialogListener(prefs, attempts, onAttemptCompleted)
+        val d =
+            dialogProvider(activityContext, R.style.Theme_SystemUI_Dialog).apply {
+                setIcon(R.drawable.ic_warning)
+                setOnCancelListener(listener)
+                setNeutralButton(R.string.controls_settings_dialog_neutral_button, listener)
+                setPositiveButton(R.string.controls_settings_dialog_positive_button, listener)
+                if (showDeviceControlsInLockscreen) {
+                    setTitle(R.string.controls_settings_trivial_controls_dialog_title)
+                    setMessage(R.string.controls_settings_trivial_controls_dialog_message)
+                } else {
+                    setTitle(R.string.controls_settings_show_controls_dialog_title)
+                    setMessage(R.string.controls_settings_show_controls_dialog_message)
+                }
+            }
+
+        SystemUIDialog.registerDismissListener(d) { dialog = null }
+        SystemUIDialog.setDialogSize(d)
+        SystemUIDialog.setShowForAllUsers(d, true)
+        dialog = d
+        d.show()
+    }
+
+    private fun turnOnSettingSecurely(settings: List<String>) {
+        val action =
+            ActivityStarter.OnDismissAction {
+                settings.forEach { setting ->
+                    secureSettings.putIntForUser(setting, 1, userTracker.userId)
+                }
+                true
+            }
+        activityStarter.dismissKeyguardThenExecute(
+            action,
+            /* cancel */ null,
+            /* afterKeyguardGone */ true
+        )
+    }
+
+    override fun closeDialog() {
+        dialog?.dismiss()
+    }
+
+    private inner class DialogListener(
+        private val prefs: SharedPreferences,
+        private val attempts: Int,
+        private val onComplete: () -> Unit
+    ) : DialogInterface.OnClickListener, DialogInterface.OnCancelListener {
+        override fun onClick(dialog: DialogInterface?, which: Int) {
+            if (dialog == null) return
+            if (which == DialogInterface.BUTTON_POSITIVE) {
+                val settings = mutableListOf(Settings.Secure.LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS)
+                if (!showDeviceControlsInLockscreen) {
+                    settings.add(Settings.Secure.LOCKSCREEN_SHOW_CONTROLS)
+                }
+                turnOnSettingSecurely(settings)
+            }
+            if (attempts != MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG) {
+                prefs
+                    .edit()
+                    .putInt(PREFS_SETTINGS_DIALOG_ATTEMPTS, MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG)
+                    .apply()
+            }
+            onComplete()
+        }
+
+        override fun onCancel(dialog: DialogInterface?) {
+            if (dialog == null) return
+            if (attempts < MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG) {
+                prefs.edit().putInt(PREFS_SETTINGS_DIALOG_ATTEMPTS, attempts + 1).apply()
+            }
+            onComplete()
+        }
+    }
+
+    private fun AlertDialog.setNeutralButton(
+        msgId: Int,
+        listener: DialogInterface.OnClickListener
+    ) {
+        setButton(DialogInterface.BUTTON_NEUTRAL, context.getText(msgId), listener)
+    }
+
+    private fun AlertDialog.setPositiveButton(
+        msgId: Int,
+        listener: DialogInterface.OnClickListener
+    ) {
+        setButton(DialogInterface.BUTTON_POSITIVE, context.getText(msgId), listener)
+    }
+
+    private fun AlertDialog.setMessage(msgId: Int) {
+        setMessage(context.getText(msgId))
+    }
+
+    /** This is necessary because the constructors are `protected`. */
+    private class SettingsDialog(context: Context, theme: Int) : AlertDialog(context, theme)
+}
diff --git a/packages/SystemUI/src/com/android/systemui/controls/ControlsSettingsRepository.kt b/packages/SystemUI/src/com/android/systemui/controls/settings/ControlsSettingsRepository.kt
similarity index 95%
rename from packages/SystemUI/src/com/android/systemui/controls/ControlsSettingsRepository.kt
rename to packages/SystemUI/src/com/android/systemui/controls/settings/ControlsSettingsRepository.kt
index 3d10ab9..df2831c 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/ControlsSettingsRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/settings/ControlsSettingsRepository.kt
@@ -15,7 +15,7 @@
  *
  */
 
-package com.android.systemui.controls
+package com.android.systemui.controls.settings
 
 import kotlinx.coroutines.flow.StateFlow
 
diff --git a/packages/SystemUI/src/com/android/systemui/controls/ControlsSettingsRepositoryImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/settings/ControlsSettingsRepositoryImpl.kt
similarity index 98%
rename from packages/SystemUI/src/com/android/systemui/controls/ControlsSettingsRepositoryImpl.kt
rename to packages/SystemUI/src/com/android/systemui/controls/settings/ControlsSettingsRepositoryImpl.kt
index 9dc422a..8e3b510 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/ControlsSettingsRepositoryImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/settings/ControlsSettingsRepositoryImpl.kt
@@ -15,7 +15,7 @@
  *
  */
 
-package com.android.systemui.controls
+package com.android.systemui.controls.settings
 
 import android.provider.Settings
 import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlActionCoordinatorImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlActionCoordinatorImpl.kt
index 041ed1d..99a10a3 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlActionCoordinatorImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlActionCoordinatorImpl.kt
@@ -19,15 +19,12 @@
 import android.annotation.AnyThread
 import android.annotation.MainThread
 import android.app.Activity
-import android.app.AlertDialog
 import android.app.Dialog
 import android.app.PendingIntent
 import android.content.Context
 import android.content.pm.PackageManager
 import android.content.pm.ResolveInfo
-import android.os.UserHandle
 import android.os.VibrationEffect
-import android.provider.Settings.Secure
 import android.service.controls.Control
 import android.service.controls.actions.BooleanAction
 import android.service.controls.actions.CommandAction
@@ -35,39 +32,36 @@
 import android.util.Log
 import android.view.HapticFeedbackConstants
 import com.android.internal.annotations.VisibleForTesting
-import com.android.systemui.R
 import com.android.systemui.broadcast.BroadcastSender
 import com.android.systemui.controls.ControlsMetricsLogger
-import com.android.systemui.controls.ControlsSettingsRepository
+import com.android.systemui.controls.settings.ControlsSettingsDialogManager
+import com.android.systemui.controls.settings.ControlsSettingsRepository
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.dagger.qualifiers.Main
+import com.android.systemui.flags.FeatureFlags
+import com.android.systemui.flags.Flags
 import com.android.systemui.plugins.ActivityStarter
-import com.android.systemui.settings.UserContextProvider
 import com.android.systemui.statusbar.VibratorHelper
-import com.android.systemui.statusbar.phone.SystemUIDialog
-import com.android.systemui.statusbar.policy.DeviceControlsControllerImpl.Companion.PREFS_CONTROLS_FILE
-import com.android.systemui.statusbar.policy.DeviceControlsControllerImpl.Companion.PREFS_SETTINGS_DIALOG_ATTEMPTS
 import com.android.systemui.statusbar.policy.KeyguardStateController
 import com.android.systemui.util.concurrency.DelayableExecutor
-import com.android.systemui.util.settings.SecureSettings
 import com.android.wm.shell.TaskViewFactory
 import java.util.Optional
 import javax.inject.Inject
 
 @SysUISingleton
 class ControlActionCoordinatorImpl @Inject constructor(
-    private val context: Context,
-    private val bgExecutor: DelayableExecutor,
-    @Main private val uiExecutor: DelayableExecutor,
-    private val activityStarter: ActivityStarter,
-    private val broadcastSender: BroadcastSender,
-    private val keyguardStateController: KeyguardStateController,
-    private val taskViewFactory: Optional<TaskViewFactory>,
-    private val controlsMetricsLogger: ControlsMetricsLogger,
-    private val vibrator: VibratorHelper,
-    private val secureSettings: SecureSettings,
-    private val userContextProvider: UserContextProvider,
-    private val controlsSettingsRepository: ControlsSettingsRepository,
+        private val context: Context,
+        private val bgExecutor: DelayableExecutor,
+        @Main private val uiExecutor: DelayableExecutor,
+        private val activityStarter: ActivityStarter,
+        private val broadcastSender: BroadcastSender,
+        private val keyguardStateController: KeyguardStateController,
+        private val taskViewFactory: Optional<TaskViewFactory>,
+        private val controlsMetricsLogger: ControlsMetricsLogger,
+        private val vibrator: VibratorHelper,
+        private val controlsSettingsRepository: ControlsSettingsRepository,
+        private val controlsSettingsDialogManager: ControlsSettingsDialogManager,
+        private val featureFlags: FeatureFlags,
 ) : ControlActionCoordinator {
     private var dialog: Dialog? = null
     private var pendingAction: Action? = null
@@ -76,16 +70,16 @@
         get() = !keyguardStateController.isUnlocked()
     private val allowTrivialControls: Boolean
         get() = controlsSettingsRepository.allowActionOnTrivialControlsInLockscreen.value
-    private val showDeviceControlsInLockscreen: Boolean
-        get() = controlsSettingsRepository.canShowControlsInLockscreen.value
     override lateinit var activityContext: Context
 
     companion object {
         private const val RESPONSE_TIMEOUT_IN_MILLIS = 3000L
-        private const val MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG = 2
     }
 
     override fun closeDialogs() {
+        if (!featureFlags.isEnabled(Flags.USE_APP_PANELS)) {
+            controlsSettingsDialogManager.closeDialog()
+        }
         val isActivityFinishing =
             (activityContext as? Activity)?.let { it.isFinishing || it.isDestroyed }
         if (isActivityFinishing == true) {
@@ -253,71 +247,9 @@
         if (action.authIsRequired) {
             return
         }
-        val prefs = userContextProvider.userContext.getSharedPreferences(
-                PREFS_CONTROLS_FILE, Context.MODE_PRIVATE)
-        val attempts = prefs.getInt(PREFS_SETTINGS_DIALOG_ATTEMPTS, 0)
-        if (attempts >= MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG ||
-                (showDeviceControlsInLockscreen && allowTrivialControls)) {
-            return
+        if (!featureFlags.isEnabled(Flags.USE_APP_PANELS)) {
+            controlsSettingsDialogManager.maybeShowDialog(activityContext) {}
         }
-        val builder = AlertDialog
-                .Builder(activityContext, R.style.Theme_SystemUI_Dialog)
-                .setIcon(R.drawable.ic_warning)
-                .setOnCancelListener {
-                    if (attempts < MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG) {
-                        prefs.edit().putInt(PREFS_SETTINGS_DIALOG_ATTEMPTS, attempts + 1)
-                                .commit()
-                    }
-                    true
-                }
-                .setNeutralButton(R.string.controls_settings_dialog_neutral_button) { _, _ ->
-                    if (attempts != MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG) {
-                        prefs.edit().putInt(PREFS_SETTINGS_DIALOG_ATTEMPTS,
-                                MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG)
-                                .commit()
-                    }
-                    true
-                }
-
-        if (showDeviceControlsInLockscreen) {
-            dialog = builder
-                    .setTitle(R.string.controls_settings_trivial_controls_dialog_title)
-                    .setMessage(R.string.controls_settings_trivial_controls_dialog_message)
-                    .setPositiveButton(R.string.controls_settings_dialog_positive_button) { _, _ ->
-                        if (attempts != MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG) {
-                            prefs.edit().putInt(PREFS_SETTINGS_DIALOG_ATTEMPTS,
-                                    MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG)
-                                    .commit()
-                        }
-                        secureSettings.putIntForUser(Secure.LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS, 1,
-                                UserHandle.USER_CURRENT)
-                        true
-                    }
-                    .create()
-        } else {
-            dialog = builder
-                    .setTitle(R.string.controls_settings_show_controls_dialog_title)
-                    .setMessage(R.string.controls_settings_show_controls_dialog_message)
-                    .setPositiveButton(R.string.controls_settings_dialog_positive_button) { _, _ ->
-                        if (attempts != MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG) {
-                            prefs.edit().putInt(PREFS_SETTINGS_DIALOG_ATTEMPTS,
-                                    MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG)
-                                    .commit()
-                        }
-                        secureSettings.putIntForUser(Secure.LOCKSCREEN_SHOW_CONTROLS,
-                                1, UserHandle.USER_CURRENT)
-                        secureSettings.putIntForUser(Secure.LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS,
-                                1, UserHandle.USER_CURRENT)
-                        true
-                    }
-                    .create()
-        }
-
-        SystemUIDialog.registerDismissListener(dialog)
-        SystemUIDialog.setDialogSize(dialog)
-
-        dialog?.create()
-        dialog?.show()
     }
 
     @VisibleForTesting
diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsActivity.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsActivity.kt
index bd704c1..d8d8c0e 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsActivity.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsActivity.kt
@@ -32,8 +32,10 @@
 import com.android.systemui.R
 import com.android.systemui.broadcast.BroadcastDispatcher
 import com.android.systemui.controls.management.ControlsAnimations
+import com.android.systemui.controls.settings.ControlsSettingsDialogManager
 import com.android.systemui.flags.FeatureFlags
 import com.android.systemui.flags.Flags
+import com.android.systemui.statusbar.policy.KeyguardStateController
 import javax.inject.Inject
 
 /**
@@ -47,7 +49,9 @@
     private val uiController: ControlsUiController,
     private val broadcastDispatcher: BroadcastDispatcher,
     private val dreamManager: IDreamManager,
-    private val featureFlags: FeatureFlags
+    private val featureFlags: FeatureFlags,
+    private val controlsSettingsDialogManager: ControlsSettingsDialogManager,
+    private val keyguardStateController: KeyguardStateController
 ) : ComponentActivity() {
 
     private lateinit var parent: ViewGroup
@@ -66,7 +70,8 @@
             ControlsAnimations.observerForAnimations(
                 requireViewById<ViewGroup>(R.id.control_detail_root),
                 window,
-                intent
+                intent,
+                !featureFlags.isEnabled(Flags.USE_APP_PANELS)
             )
         )
 
@@ -92,7 +97,13 @@
 
         parent = requireViewById<ViewGroup>(R.id.global_actions_controls)
         parent.alpha = 0f
-        uiController.show(parent, { finishOrReturnToDream() }, this)
+        if (featureFlags.isEnabled(Flags.USE_APP_PANELS) && !keyguardStateController.isUnlocked) {
+            controlsSettingsDialogManager.maybeShowDialog(this) {
+                uiController.show(parent, { finishOrReturnToDream() }, this)
+            }
+        } else {
+            uiController.show(parent, { finishOrReturnToDream() }, this)
+        }
 
         ControlsAnimations.enterAnimation(parent).start()
     }
@@ -124,6 +135,7 @@
         mExitToDream = false
 
         uiController.hide()
+        controlsSettingsDialogManager.closeDialog()
     }
 
     override fun onDestroy() {
diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt
index 4c8e1ac..1e3e5cd 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt
@@ -28,6 +28,7 @@
 import android.graphics.drawable.Drawable
 import android.graphics.drawable.LayerDrawable
 import android.service.controls.Control
+import android.service.controls.ControlsProviderService
 import android.util.Log
 import android.view.ContextThemeWrapper
 import android.view.LayoutInflater
@@ -48,6 +49,7 @@
 import com.android.systemui.R
 import com.android.systemui.controls.ControlsMetricsLogger
 import com.android.systemui.controls.ControlsServiceInfo
+import com.android.systemui.controls.settings.ControlsSettingsRepository
 import com.android.systemui.controls.CustomIconCache
 import com.android.systemui.controls.controller.ControlsController
 import com.android.systemui.controls.controller.StructureInfo
@@ -96,6 +98,7 @@
         private val userFileManager: UserFileManager,
         private val userTracker: UserTracker,
         private val taskViewFactory: Optional<TaskViewFactory>,
+        private val controlsSettingsRepository: ControlsSettingsRepository,
         dumpManager: DumpManager
 ) : ControlsUiController, Dumpable {
 
@@ -183,7 +186,7 @@
         val allStructures = controlsController.get().getFavorites()
         val selected = getPreferredSelectedItem(allStructures)
         val anyPanels = controlsListingController.get().getCurrentServices()
-                .none { it.panelActivity != null }
+                .any { it.panelActivity != null }
 
         return if (controlsController.get().addSeedingFavoritesCallback(onSeedingComplete)) {
             ControlsActivity::class.java
@@ -354,7 +357,6 @@
                 } else {
                     items[0]
                 }
-
         maybeUpdateSelectedItem(selectionItem)
 
         createControlsSpaceFrame()
@@ -374,11 +376,20 @@
     }
 
     private fun createPanelView(componentName: ComponentName) {
-        val pendingIntent = PendingIntent.getActivity(
+        val setting = controlsSettingsRepository
+                .allowActionOnTrivialControlsInLockscreen.value
+        val pendingIntent = PendingIntent.getActivityAsUser(
                 context,
                 0,
-                Intent().setComponent(componentName),
-                PendingIntent.FLAG_IMMUTABLE
+                Intent()
+                        .setComponent(componentName)
+                        .putExtra(
+                                ControlsProviderService.EXTRA_LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS,
+                                setting
+                        ),
+                PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
+                null,
+                userTracker.userHandle
         )
 
         parent.requireViewById<View>(R.id.controls_scroll_view).visibility = View.GONE
@@ -698,6 +709,8 @@
             println("hidden: $hidden")
             println("selectedItem: $selectedItem")
             println("lastSelections: $lastSelections")
+            println("setting: ${controlsSettingsRepository
+                    .allowActionOnTrivialControlsInLockscreen.value}")
         }
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/PanelTaskViewController.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/PanelTaskViewController.kt
index 7143be2..f5764c2 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/ui/PanelTaskViewController.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/ui/PanelTaskViewController.kt
@@ -24,6 +24,10 @@
 import android.content.ComponentName
 import android.content.Context
 import android.content.Intent
+import android.graphics.Color
+import android.graphics.drawable.ShapeDrawable
+import android.graphics.drawable.shapes.RoundRectShape
+import com.android.systemui.R
 import com.android.systemui.util.boundsOnScreen
 import com.android.wm.shell.TaskView
 import java.util.concurrent.Executor
@@ -64,6 +68,16 @@
                 options.taskAlwaysOnTop = true
 
                 taskView.post {
+                    val roundedCorner =
+                        activityContext.resources.getDimensionPixelSize(
+                            R.dimen.notification_corner_radius
+                        )
+                    val radii = FloatArray(8) { roundedCorner.toFloat() }
+                    taskView.background =
+                        ShapeDrawable(RoundRectShape(radii, null, null)).apply {
+                            setTint(Color.TRANSPARENT)
+                        }
+                    taskView.clipToOutline = true
                     taskView.startActivity(
                         pendingIntent,
                         fillInIntent,
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java b/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java
index 8b4b30c..3644d42 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java
@@ -36,6 +36,8 @@
 import android.app.role.RoleManager;
 import android.app.smartspace.SmartspaceManager;
 import android.app.trust.TrustManager;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothManager;
 import android.content.ClipboardManager;
 import android.content.ContentResolver;
 import android.content.Context;
@@ -616,4 +618,16 @@
     static CameraManager provideCameraManager(Context context) {
         return context.getSystemService(CameraManager.class);
     }
+
+    @Provides
+    @Singleton
+    static BluetoothManager provideBluetoothManager(Context context) {
+        return context.getSystemService(BluetoothManager.class);
+    }
+
+    @Provides
+    @Singleton
+    static BluetoothAdapter provideBluetoothAdapter(BluetoothManager bluetoothManager) {
+        return bluetoothManager.getAdapter();
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java b/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java
index 6dc4f5c..68f4dbe 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java
@@ -125,10 +125,10 @@
     default void init() {
         // Initialize components that have no direct tie to the dagger dependency graph,
         // but are critical to this component's operation
-        // TODO(b/205034537): I think this is a good idea?
         getSysUIUnfoldComponent().ifPresent(c -> {
             c.getUnfoldLightRevealOverlayAnimation().init();
             c.getUnfoldTransitionWallpaperController().init();
+            c.getUnfoldHapticsPlayer();
         });
         getNaturalRotationUnfoldProgressProvider().ifPresent(o -> o.init());
         // No init method needed, just needs to be gotten so that it's created.
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java
index 3a59f4b..2465286 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java
@@ -40,6 +40,7 @@
 import com.android.systemui.dagger.qualifiers.Main;
 import com.android.systemui.demomode.dagger.DemoModeModule;
 import com.android.systemui.doze.dagger.DozeComponent;
+import com.android.systemui.dreams.complication.dagger.ComplicationComponent;
 import com.android.systemui.dreams.dagger.DreamModule;
 import com.android.systemui.dump.DumpManager;
 import com.android.systemui.flags.FeatureFlags;
@@ -163,6 +164,7 @@
         },
         subcomponents = {
             CentralSurfacesComponent.class,
+            ComplicationComponent.class,
             NavigationBarComponent.class,
             NotificationRowComponent.class,
             DozeComponent.class,
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java b/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java
index 0c14ed5..5d21349 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java
@@ -28,6 +28,8 @@
 import com.android.systemui.dump.DumpManager;
 import com.android.systemui.statusbar.policy.DevicePostureController;
 
+import com.google.errorprone.annotations.CompileTimeConstant;
+
 import java.io.PrintWriter;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
@@ -80,6 +82,13 @@
     }
 
     /**
+     * Log debug message to LogBuffer.
+     */
+    public void d(@CompileTimeConstant String msg) {
+        mLogger.log(msg);
+    }
+
+    /**
      * Appends pickup wakeup event to the logs
      */
     public void tracePickupWakeUp(boolean withinVibrationThreshold) {
@@ -88,6 +97,10 @@
                 : mPickupPulseNotNearVibrationStats).append();
     }
 
+    public void traceSetIgnoreTouchWhilePulsing(boolean ignoreTouch) {
+        mLogger.logSetIgnoreTouchWhilePulsing(ignoreTouch);
+    }
+
     /**
      * Appends pulse started event to the logs.
      * @param reason why the pulse started
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeLogger.kt b/packages/SystemUI/src/com/android/systemui/doze/DozeLogger.kt
index b5dbe21..d19c6ec 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeLogger.kt
@@ -364,6 +364,14 @@
         })
     }
 
+    fun logSetIgnoreTouchWhilePulsing(ignoreTouchWhilePulsing: Boolean) {
+        buffer.log(TAG, DEBUG, {
+            bool1 = ignoreTouchWhilePulsing
+        }, {
+            "Prox changed while pulsing. setIgnoreTouchWhilePulsing=$bool1"
+        })
+    }
+
     fun log(@CompileTimeConstant msg: String) {
         buffer.log(TAG, DEBUG, msg)
     }
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java b/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
index 5daf1ce..3f9f14c 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
@@ -333,15 +333,18 @@
                     }
                     gentleWakeUp(pulseReason);
                 } else if (isUdfpsLongPress) {
-                    final State state = mMachine.getState();
-                    if (state == State.DOZE_AOD || state == State.DOZE) {
+                    if (canPulse(mMachine.getState(), true)) {
+                        mDozeLog.d("updfsLongPress - setting aodInterruptRunnable to run when "
+                                + "the display is on");
                         // Since the gesture won't be received by the UDFPS view, we need to
                         // manually inject an event once the display is ON
                         mAodInterruptRunnable = () ->
-                            mAuthController.onAodInterrupt((int) screenX, (int) screenY,
-                                rawValues[3] /* major */, rawValues[4] /* minor */);
+                                mAuthController.onAodInterrupt((int) screenX, (int) screenY,
+                                        rawValues[3] /* major */, rawValues[4] /* minor */);
+                    } else {
+                        mDozeLog.d("udfpsLongPress - Not sending aodInterrupt. "
+                                + "Unsupported doze state.");
                     }
-
                     requestPulse(DozeLog.REASON_SENSOR_UDFPS_LONG_PRESS, true, null);
                 } else {
                     mDozeHost.extendPulse(pulseReason);
@@ -380,7 +383,7 @@
         // when a new event is arriving. This means that a state transition might have happened
         // and the proximity check is now obsolete.
         if (mMachine.isExecutingTransition()) {
-            Log.w(TAG, "onProximityFar called during transition. Ignoring sensor response.");
+            mDozeLog.d("onProximityFar called during transition. Ignoring sensor response.");
             return;
         }
 
@@ -392,21 +395,15 @@
 
         if (state == DozeMachine.State.DOZE_PULSING
                 || state == DozeMachine.State.DOZE_PULSING_BRIGHT) {
-            if (DEBUG) {
-                Log.i(TAG, "Prox changed, ignore touch = " + near);
-            }
+            mDozeLog.traceSetIgnoreTouchWhilePulsing(near);
             mDozeHost.onIgnoreTouchWhilePulsing(near);
         }
 
         if (far && (paused || pausing)) {
-            if (DEBUG) {
-                Log.i(TAG, "Prox FAR, unpausing AOD");
-            }
+            mDozeLog.d("Prox FAR, unpausing AOD");
             mMachine.requestState(DozeMachine.State.DOZE_AOD);
         } else if (near && aod) {
-            if (DEBUG) {
-                Log.i(TAG, "Prox NEAR, pausing AOD");
-            }
+            mDozeLog.d("Prox NEAR, starting pausing AOD countdown");
             mMachine.requestState(DozeMachine.State.DOZE_AOD_PAUSING);
         }
     }
@@ -551,12 +548,13 @@
             return;
         }
 
-        if (!mAllowPulseTriggers || mDozeHost.isPulsePending() || !canPulse(dozeState)) {
+        if (!mAllowPulseTriggers || mDozeHost.isPulsePending()
+                || !canPulse(dozeState, performedProxCheck)) {
             if (!mAllowPulseTriggers) {
                 mDozeLog.tracePulseDropped("requestPulse - !mAllowPulseTriggers");
             } else if (mDozeHost.isPulsePending()) {
                 mDozeLog.tracePulseDropped("requestPulse - pulsePending");
-            } else if (!canPulse(dozeState)) {
+            } else if (!canPulse(dozeState, performedProxCheck)) {
                 mDozeLog.tracePulseDropped("requestPulse - dozeState cannot pulse", dozeState);
             }
             runIfNotNull(onPulseSuppressedListener);
@@ -574,14 +572,15 @@
                 // not in pocket, continue pulsing
                 final boolean isPulsePending = mDozeHost.isPulsePending();
                 mDozeHost.setPulsePending(false);
-                if (!isPulsePending || mDozeHost.isPulsingBlocked() || !canPulse(dozeState)) {
+                if (!isPulsePending || mDozeHost.isPulsingBlocked()
+                        || !canPulse(dozeState, performedProxCheck)) {
                     if (!isPulsePending) {
                         mDozeLog.tracePulseDropped("continuePulseRequest - pulse no longer"
                                 + " pending, pulse was cancelled before it could start"
                                 + " transitioning to pulsing state.");
                     } else if (mDozeHost.isPulsingBlocked()) {
                         mDozeLog.tracePulseDropped("continuePulseRequest - pulsingBlocked");
-                    } else if (!canPulse(dozeState)) {
+                    } else if (!canPulse(dozeState, performedProxCheck)) {
                         mDozeLog.tracePulseDropped("continuePulseRequest"
                                 + " - doze state cannot pulse", dozeState);
                     }
@@ -598,10 +597,13 @@
                 .ifPresent(uiEventEnum -> mUiEventLogger.log(uiEventEnum, getKeyguardSessionId()));
     }
 
-    private boolean canPulse(DozeMachine.State dozeState) {
+    private boolean canPulse(DozeMachine.State dozeState, boolean pulsePerformedProximityCheck) {
+        final boolean dozePausedOrPausing = dozeState == State.DOZE_AOD_PAUSED
+                || dozeState == State.DOZE_AOD_PAUSING;
         return dozeState == DozeMachine.State.DOZE
                 || dozeState == DozeMachine.State.DOZE_AOD
-                || dozeState == DozeMachine.State.DOZE_AOD_DOCKED;
+                || dozeState == DozeMachine.State.DOZE_AOD_DOCKED
+                || (dozePausedOrPausing && pulsePerformedProximityCheck);
     }
 
     @Nullable
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayLifecycleOwner.kt b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayLifecycleOwner.kt
new file mode 100644
index 0000000..8325356
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayLifecycleOwner.kt
@@ -0,0 +1,34 @@
+/*
+ * 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.systemui.dreams
+
+import androidx.lifecycle.Lifecycle
+import androidx.lifecycle.LifecycleOwner
+import androidx.lifecycle.LifecycleRegistry
+import javax.inject.Inject
+
+/**
+ * {@link DreamOverlayLifecycleOwner} is a concrete implementation of {@link LifecycleOwner}, which
+ * provides access to an associated {@link LifecycleRegistry}.
+ */
+class DreamOverlayLifecycleOwner @Inject constructor() : LifecycleOwner {
+    val registry: LifecycleRegistry = LifecycleRegistry(this)
+
+    override fun getLifecycle(): Lifecycle {
+        return registry
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayRegistrant.java b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayRegistrant.java
index d145f5c..87c5f51 100644
--- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayRegistrant.java
+++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayRegistrant.java
@@ -16,6 +16,8 @@
 
 package com.android.systemui.dreams;
 
+import static com.android.systemui.dreams.dagger.DreamModule.DREAM_OVERLAY_SERVICE_COMPONENT;
+
 import android.content.BroadcastReceiver;
 import android.content.ComponentName;
 import android.content.Context;
@@ -35,6 +37,7 @@
 import com.android.systemui.dagger.qualifiers.Main;
 
 import javax.inject.Inject;
+import javax.inject.Named;
 
 /**
  * {@link DreamOverlayRegistrant} is responsible for telling system server that SystemUI should be
@@ -98,12 +101,13 @@
     }
 
     @Inject
-    public DreamOverlayRegistrant(Context context, @Main Resources resources) {
+    public DreamOverlayRegistrant(Context context, @Main Resources resources,
+            @Named(DREAM_OVERLAY_SERVICE_COMPONENT) ComponentName dreamOverlayServiceComponent) {
         mContext = context;
         mResources = resources;
         mDreamManager = IDreamManager.Stub.asInterface(
                 ServiceManager.getService(DreamService.DREAM_SERVICE));
-        mOverlayServiceComponent = new ComponentName(mContext, DreamOverlayService.class);
+        mOverlayServiceComponent = dreamOverlayServiceComponent;
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java
index e76d5b3..16b4f99 100644
--- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java
+++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java
@@ -30,6 +30,7 @@
 import androidx.annotation.Nullable;
 import androidx.annotation.VisibleForTesting;
 import androidx.lifecycle.Lifecycle;
+import androidx.lifecycle.LifecycleOwner;
 import androidx.lifecycle.LifecycleRegistry;
 import androidx.lifecycle.ViewModelStore;
 
@@ -41,9 +42,13 @@
 import com.android.keyguard.KeyguardUpdateMonitorCallback;
 import com.android.systemui.dagger.qualifiers.Main;
 import com.android.systemui.dreams.complication.Complication;
+import com.android.systemui.dreams.complication.dagger.ComplicationComponent;
 import com.android.systemui.dreams.dagger.DreamOverlayComponent;
 import com.android.systemui.dreams.touch.DreamOverlayTouchMonitor;
+import com.android.systemui.touch.TouchInsetManager;
 
+import java.util.Arrays;
+import java.util.HashSet;
 import java.util.concurrent.Executor;
 
 import javax.inject.Inject;
@@ -80,8 +85,14 @@
     // True if the service has been destroyed.
     private boolean mDestroyed = false;
 
+    private final ComplicationComponent mComplicationComponent;
+
+    private final com.android.systemui.dreams.dreamcomplication.dagger.ComplicationComponent
+            mDreamComplicationComponent;
+
     private final DreamOverlayComponent mDreamOverlayComponent;
 
+    private final DreamOverlayLifecycleOwner mLifecycleOwner;
     private final LifecycleRegistry mLifecycleRegistry;
 
     private DreamOverlayTouchMonitor mDreamOverlayTouchMonitor;
@@ -127,11 +138,16 @@
     public DreamOverlayService(
             Context context,
             @Main Executor executor,
+            DreamOverlayLifecycleOwner lifecycleOwner,
             WindowManager windowManager,
+            ComplicationComponent.Factory complicationComponentFactory,
+            com.android.systemui.dreams.dreamcomplication.dagger.ComplicationComponent.Factory
+                    dreamComplicationComponentFactory,
             DreamOverlayComponent.Factory dreamOverlayComponentFactory,
             DreamOverlayStateController stateController,
             KeyguardUpdateMonitor keyguardUpdateMonitor,
             UiEventLogger uiEventLogger,
+            TouchInsetManager touchInsetManager,
             @Nullable @Named(LowLightDreamModule.LOW_LIGHT_DREAM_COMPONENT)
                     ComponentName lowLightDreamComponent) {
         mContext = context;
@@ -146,8 +162,17 @@
         final ViewModelStore viewModelStore = new ViewModelStore();
         final Complication.Host host =
                 () -> mExecutor.execute(DreamOverlayService.this::requestExit);
-        mDreamOverlayComponent = dreamOverlayComponentFactory.create(viewModelStore, host);
-        mLifecycleRegistry = mDreamOverlayComponent.getLifecycleRegistry();
+
+        mComplicationComponent = complicationComponentFactory.create(lifecycleOwner, host,
+                viewModelStore, touchInsetManager);
+        mDreamComplicationComponent = dreamComplicationComponentFactory.create(
+                mComplicationComponent.getVisibilityController(), touchInsetManager);
+        mDreamOverlayComponent = dreamOverlayComponentFactory.create(lifecycleOwner,
+                mComplicationComponent.getComplicationHostViewController(), touchInsetManager,
+                new HashSet<>(Arrays.asList(
+                        mDreamComplicationComponent.getHideComplicationTouchHandler())));
+        mLifecycleOwner = lifecycleOwner;
+        mLifecycleRegistry = mLifecycleOwner.getRegistry();
 
         mExecutor.execute(() -> setCurrentStateLocked(Lifecycle.State.CREATED));
     }
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayStateController.java b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayStateController.java
index 5f942b6..ccfdd096 100644
--- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayStateController.java
+++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayStateController.java
@@ -16,6 +16,8 @@
 
 package com.android.systemui.dreams;
 
+import static com.android.systemui.dreams.dagger.DreamModule.DREAM_OVERLAY_ENABLED;
+
 import android.service.dreams.DreamService;
 import android.util.Log;
 
@@ -37,6 +39,7 @@
 import java.util.stream.Collectors;
 
 import javax.inject.Inject;
+import javax.inject.Named;
 
 /**
  * {@link DreamOverlayStateController} is the source of truth for Dream overlay configurations and
@@ -83,6 +86,7 @@
     }
 
     private final Executor mExecutor;
+    private final boolean mOverlayEnabled;
     private final ArrayList<Callback> mCallbacks = new ArrayList<>();
 
     @Complication.ComplicationType
@@ -94,14 +98,27 @@
 
     @VisibleForTesting
     @Inject
-    public DreamOverlayStateController(@Main Executor executor) {
+    public DreamOverlayStateController(@Main Executor executor,
+            @Named(DREAM_OVERLAY_ENABLED) boolean overlayEnabled) {
         mExecutor = executor;
+        mOverlayEnabled = overlayEnabled;
+        if (DEBUG) {
+            Log.d(TAG, "Dream overlay enabled:" + mOverlayEnabled);
+        }
     }
 
     /**
      * Adds a complication to be included on the dream overlay.
      */
     public void addComplication(Complication complication) {
+        if (!mOverlayEnabled) {
+            if (DEBUG) {
+                Log.d(TAG,
+                        "Ignoring adding complication due to overlay disabled:" + complication);
+            }
+            return;
+        }
+
         mExecutor.execute(() -> {
             if (mComplications.add(complication)) {
                 if (DEBUG) {
@@ -116,6 +133,14 @@
      * Removes a complication from inclusion on the dream overlay.
      */
     public void removeComplication(Complication complication) {
+        if (!mOverlayEnabled) {
+            if (DEBUG) {
+                Log.d(TAG,
+                        "Ignoring removing complication due to overlay disabled:" + complication);
+            }
+            return;
+        }
+
         mExecutor.execute(() -> {
             if (mComplications.remove(complication)) {
                 if (DEBUG) {
@@ -193,7 +218,7 @@
      * @return {@code true} if overlay is active, {@code false} otherwise.
      */
     public boolean isOverlayActive() {
-        return containsState(STATE_DREAM_OVERLAY_ACTIVE);
+        return mOverlayEnabled && containsState(STATE_DREAM_OVERLAY_ACTIVE);
     }
 
     /**
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationHostViewController.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationHostViewController.java
index 100ccc3..a2e11b2 100644
--- a/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationHostViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationHostViewController.java
@@ -138,19 +138,27 @@
                     final ComplicationId id = complication.getId();
                     final Complication.ViewHolder viewHolder = complication.getComplication()
                             .createView(complication);
+
+                    final View view = viewHolder.getView();
+
+                    if (view == null) {
+                        Log.e(TAG, "invalid complication view. null view supplied by ViewHolder");
+                        return;
+                    }
+
                     // Complications to be added before dream entry animations are finished are set
                     // to invisible and are animated in.
                     if (!mEntryAnimationsFinished) {
-                        viewHolder.getView().setVisibility(View.INVISIBLE);
+                        view.setVisibility(View.INVISIBLE);
                     }
                     mComplications.put(id, viewHolder);
-                    if (viewHolder.getView().getParent() != null) {
+                    if (view.getParent() != null) {
                         Log.e(TAG, "View for complication "
                                 + complication.getComplication().getClass()
                                 + " already has a parent. Make sure not to reuse complication "
                                 + "views!");
                     }
-                    mLayoutEngine.addComplication(id, viewHolder.getView(),
+                    mLayoutEngine.addComplication(id, view,
                             viewHolder.getLayoutParams(), viewHolder.getCategory());
                 });
     }
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutEngine.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutEngine.java
index 46ce7a9..3e9b010 100644
--- a/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutEngine.java
+++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutEngine.java
@@ -30,7 +30,7 @@
 
 import com.android.systemui.R;
 import com.android.systemui.dreams.complication.ComplicationLayoutParams.Position;
-import com.android.systemui.dreams.dagger.DreamOverlayComponent;
+import com.android.systemui.dreams.complication.dagger.ComplicationModule;
 import com.android.systemui.statusbar.CrossFadeHelper;
 import com.android.systemui.touch.TouchInsetManager;
 
@@ -50,7 +50,7 @@
  * their layout parameters and attributes. The management of this set is done by
  * {@link ComplicationHostViewController}.
  */
-@DreamOverlayComponent.DreamOverlayScope
+@ComplicationModule.ComplicationScope
 public class ComplicationLayoutEngine implements Complication.VisibilityController {
     public static final String TAG = "ComplicationLayoutEng";
 
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/DreamHomeControlsComplication.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/DreamHomeControlsComplication.java
index ee00512..1065b94 100644
--- a/packages/SystemUI/src/com/android/systemui/dreams/complication/DreamHomeControlsComplication.java
+++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/DreamHomeControlsComplication.java
@@ -136,8 +136,15 @@
             final boolean hasFavorites = mControlsComponent.getControlsController()
                     .map(c -> !c.getFavorites().isEmpty())
                     .orElse(false);
+            boolean hasPanels = false;
+            for (int i = 0; i < controlsServices.size(); i++) {
+                if (controlsServices.get(i).getPanelActivity() != null) {
+                    hasPanels = true;
+                    break;
+                }
+            }
             final ControlsComponent.Visibility visibility = mControlsComponent.getVisibility();
-            return hasFavorites && visibility != UNAVAILABLE;
+            return (hasFavorites || hasPanels) && visibility != UNAVAILABLE;
         }
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/ComplicationComponent.kt b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/ComplicationComponent.kt
new file mode 100644
index 0000000..8d133bd
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/ComplicationComponent.kt
@@ -0,0 +1,29 @@
+package com.android.systemui.dreams.complication.dagger
+
+import androidx.lifecycle.LifecycleOwner
+import androidx.lifecycle.ViewModelStore
+import com.android.systemui.dreams.complication.Complication
+import com.android.systemui.dreams.complication.ComplicationHostViewController
+import com.android.systemui.dreams.complication.ComplicationLayoutEngine
+import com.android.systemui.touch.TouchInsetManager
+import dagger.BindsInstance
+import dagger.Subcomponent
+
+@Subcomponent(modules = [ComplicationModule::class])
+@ComplicationModule.ComplicationScope
+interface ComplicationComponent {
+    /** Factory for generating [ComplicationComponent]. */
+    @Subcomponent.Factory
+    interface Factory {
+        fun create(
+            @BindsInstance lifecycleOwner: LifecycleOwner,
+            @BindsInstance host: Complication.Host,
+            @BindsInstance viewModelStore: ViewModelStore,
+            @BindsInstance touchInsetManager: TouchInsetManager
+        ): ComplicationComponent
+    }
+
+    fun getComplicationHostViewController(): ComplicationHostViewController
+
+    fun getVisibilityController(): ComplicationLayoutEngine
+}
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/ComplicationHostViewModule.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/ComplicationHostViewModule.java
index 09cc7c5..797906f 100644
--- a/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/ComplicationHostViewModule.java
+++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/ComplicationHostViewModule.java
@@ -24,13 +24,12 @@
 import com.android.internal.util.Preconditions;
 import com.android.systemui.R;
 import com.android.systemui.dagger.qualifiers.Main;
-import com.android.systemui.dreams.dagger.DreamOverlayComponent;
-
-import javax.inject.Named;
 
 import dagger.Module;
 import dagger.Provides;
 
+import javax.inject.Named;
+
 /**
  * Module for providing a scoped host view.
  */
@@ -49,7 +48,7 @@
      */
     @Provides
     @Named(SCOPED_COMPLICATIONS_LAYOUT)
-    @DreamOverlayComponent.DreamOverlayScope
+    @ComplicationModule.ComplicationScope
     static ConstraintLayout providesComplicationHostView(
             LayoutInflater layoutInflater) {
         return Preconditions.checkNotNull((ConstraintLayout)
@@ -60,7 +59,6 @@
 
     @Provides
     @Named(COMPLICATION_MARGIN_DEFAULT)
-    @DreamOverlayComponent.DreamOverlayScope
     static int providesComplicationPadding(@Main Resources resources) {
         return resources.getDimensionPixelSize(R.dimen.dream_overlay_complication_margin);
     }
@@ -70,7 +68,6 @@
      */
     @Provides
     @Named(COMPLICATIONS_FADE_OUT_DURATION)
-    @DreamOverlayComponent.DreamOverlayScope
     static int providesComplicationsFadeOutDuration(@Main Resources resources) {
         return resources.getInteger(R.integer.complicationFadeOutMs);
     }
@@ -80,7 +77,6 @@
      */
     @Provides
     @Named(COMPLICATIONS_FADE_OUT_DELAY)
-    @DreamOverlayComponent.DreamOverlayScope
     static int providesComplicationsFadeOutDelay(@Main Resources resources) {
         return resources.getInteger(R.integer.complicationFadeOutDelayMs);
     }
@@ -90,7 +86,6 @@
      */
     @Provides
     @Named(COMPLICATIONS_FADE_IN_DURATION)
-    @DreamOverlayComponent.DreamOverlayScope
     static int providesComplicationsFadeInDuration(@Main Resources resources) {
         return resources.getInteger(R.integer.complicationFadeInMs);
     }
@@ -100,7 +95,6 @@
      */
     @Provides
     @Named(COMPLICATIONS_RESTORE_TIMEOUT)
-    @DreamOverlayComponent.DreamOverlayScope
     static int providesComplicationsRestoreTimeout(@Main Resources resources) {
         return resources.getInteger(R.integer.complicationRestoreMs);
     }
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/ComplicationModule.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/ComplicationModule.java
index 5c2fdf5..dbf5ab0 100644
--- a/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/ComplicationModule.java
+++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/ComplicationModule.java
@@ -24,16 +24,16 @@
 import com.android.systemui.dreams.complication.Complication;
 import com.android.systemui.dreams.complication.ComplicationCollectionViewModel;
 import com.android.systemui.dreams.complication.ComplicationLayoutEngine;
+import com.android.systemui.touch.TouchInsetManager;
+
+import dagger.Module;
+import dagger.Provides;
 
 import java.lang.annotation.Documented;
 import java.lang.annotation.Retention;
 
 import javax.inject.Named;
 import javax.inject.Scope;
-
-import dagger.Module;
-import dagger.Provides;
-
 /**
  * Module for housing components related to rendering complications.
  */
@@ -73,4 +73,13 @@
             ComplicationLayoutEngine engine) {
         return engine;
     }
+
+    /**
+     * Provides a new touch inset session instance for complication logic.
+     */
+    @Provides
+    static TouchInsetManager.TouchInsetSession providesTouchInsetSession(
+            TouchInsetManager manager) {
+        return manager.createSession();
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/dagger/DreamModule.java b/packages/SystemUI/src/com/android/systemui/dreams/dagger/DreamModule.java
index 101f4a4..8770cd1 100644
--- a/packages/SystemUI/src/com/android/systemui/dreams/dagger/DreamModule.java
+++ b/packages/SystemUI/src/com/android/systemui/dreams/dagger/DreamModule.java
@@ -16,7 +16,9 @@
 
 package com.android.systemui.dreams.dagger;
 
+import android.content.ComponentName;
 import android.content.Context;
+import android.content.pm.PackageManager;
 import android.content.res.Resources;
 
 import com.android.dream.lowlight.dagger.LowLightDreamModule;
@@ -24,14 +26,17 @@
 import com.android.systemui.dagger.SysUISingleton;
 import com.android.systemui.dagger.qualifiers.Main;
 import com.android.systemui.dreams.DreamOverlayNotificationCountProvider;
+import com.android.systemui.dreams.DreamOverlayService;
 import com.android.systemui.dreams.complication.dagger.RegisteredComplicationsModule;
+import com.android.systemui.dreams.dreamcomplication.dagger.ComplicationComponent;
+
+import dagger.Module;
+import dagger.Provides;
 
 import java.util.Optional;
 
 import javax.inject.Named;
 
-import dagger.Module;
-import dagger.Provides;
 
 /**
  * Dagger Module providing Dream-related functionality.
@@ -41,14 +46,40 @@
             LowLightDreamModule.class,
         },
         subcomponents = {
+            ComplicationComponent.class,
             DreamOverlayComponent.class,
         })
 public interface DreamModule {
     String DREAM_ONLY_ENABLED_FOR_DOCK_USER = "dream_only_enabled_for_dock_user";
+    String DREAM_OVERLAY_SERVICE_COMPONENT = "dream_overlay_service_component";
+    String DREAM_OVERLAY_ENABLED = "dream_overlay_enabled";
 
     String DREAM_SUPPORTED = "dream_supported";
 
     /**
+     * Provides the dream component
+     */
+    @Provides
+    @Named(DREAM_OVERLAY_SERVICE_COMPONENT)
+    static ComponentName providesDreamOverlayService(Context context) {
+        return new ComponentName(context, DreamOverlayService.class);
+    }
+
+    /**
+     * Provides whether dream overlay is enabled.
+     */
+    @Provides
+    @Named(DREAM_OVERLAY_ENABLED)
+    static Boolean providesDreamOverlayEnabled(PackageManager packageManager,
+            @Named(DREAM_OVERLAY_SERVICE_COMPONENT) ComponentName component) {
+        try {
+            return packageManager.getServiceInfo(component, PackageManager.GET_META_DATA).enabled;
+        } catch (PackageManager.NameNotFoundException e) {
+            return false;
+        }
+    }
+
+    /**
      * Provides an instance of the dream backend.
      */
     @Provides
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/dagger/DreamOverlayComponent.java b/packages/SystemUI/src/com/android/systemui/dreams/dagger/DreamOverlayComponent.java
index f927ba6..0332f88 100644
--- a/packages/SystemUI/src/com/android/systemui/dreams/dagger/DreamOverlayComponent.java
+++ b/packages/SystemUI/src/com/android/systemui/dreams/dagger/DreamOverlayComponent.java
@@ -16,41 +16,49 @@
 
 package com.android.systemui.dreams.dagger;
 
+import static com.android.systemui.dreams.dagger.DreamOverlayModule.DREAM_TOUCH_HANDLERS;
+
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
+import android.annotation.Nullable;
+
 import androidx.lifecycle.LifecycleOwner;
-import androidx.lifecycle.LifecycleRegistry;
-import androidx.lifecycle.ViewModelStore;
 
 import com.android.systemui.dreams.DreamOverlayContainerViewController;
-import com.android.systemui.dreams.complication.Complication;
-import com.android.systemui.dreams.complication.dagger.ComplicationModule;
+import com.android.systemui.dreams.complication.ComplicationHostViewController;
 import com.android.systemui.dreams.touch.DreamOverlayTouchMonitor;
+import com.android.systemui.dreams.touch.DreamTouchHandler;
 import com.android.systemui.dreams.touch.dagger.DreamTouchModule;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Retention;
-
-import javax.inject.Scope;
+import com.android.systemui.touch.TouchInsetManager;
 
 import dagger.BindsInstance;
 import dagger.Subcomponent;
 
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.util.Set;
+
+import javax.inject.Named;
+import javax.inject.Scope;
+
 /**
  * Dagger subcomponent for {@link DreamOverlayModule}.
  */
 @Subcomponent(modules = {
         DreamTouchModule.class,
         DreamOverlayModule.class,
-        ComplicationModule.class,
 })
 @DreamOverlayComponent.DreamOverlayScope
 public interface DreamOverlayComponent {
     /** Simple factory for {@link DreamOverlayComponent}. */
     @Subcomponent.Factory
     interface Factory {
-        DreamOverlayComponent create(@BindsInstance ViewModelStore store,
-                @BindsInstance Complication.Host host);
+        DreamOverlayComponent create(
+                @BindsInstance LifecycleOwner lifecycleOwner,
+                @BindsInstance ComplicationHostViewController complicationHostViewController,
+                @BindsInstance TouchInsetManager touchInsetManager,
+                @BindsInstance @Named(DREAM_TOUCH_HANDLERS) @Nullable
+                        Set<DreamTouchHandler> dreamTouchHandlers);
     }
 
     /** Scope annotation for singleton items within the {@link DreamOverlayComponent}. */
@@ -62,12 +70,6 @@
     /** Builds a {@link DreamOverlayContainerViewController}. */
     DreamOverlayContainerViewController getDreamOverlayContainerViewController();
 
-    /** Builds a {@link androidx.lifecycle.LifecycleRegistry} */
-    LifecycleRegistry getLifecycleRegistry();
-
-    /** Builds a {@link androidx.lifecycle.LifecycleOwner} */
-    LifecycleOwner getLifecycleOwner();
-
     /** Builds a {@link DreamOverlayTouchMonitor} */
     DreamOverlayTouchMonitor getDreamOverlayTouchMonitor();
 }
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/dagger/DreamOverlayModule.java b/packages/SystemUI/src/com/android/systemui/dreams/dagger/DreamOverlayModule.java
index ed0e1d9..4485381 100644
--- a/packages/SystemUI/src/com/android/systemui/dreams/dagger/DreamOverlayModule.java
+++ b/packages/SystemUI/src/com/android/systemui/dreams/dagger/DreamOverlayModule.java
@@ -16,32 +16,35 @@
 
 package com.android.systemui.dreams.dagger;
 
+import android.annotation.Nullable;
 import android.content.res.Resources;
 import android.view.LayoutInflater;
 import android.view.ViewGroup;
 
 import androidx.lifecycle.Lifecycle;
 import androidx.lifecycle.LifecycleOwner;
-import androidx.lifecycle.LifecycleRegistry;
 
 import com.android.internal.util.Preconditions;
 import com.android.systemui.R;
 import com.android.systemui.dagger.qualifiers.Main;
 import com.android.systemui.dreams.DreamOverlayContainerView;
 import com.android.systemui.dreams.DreamOverlayStatusBarView;
+import com.android.systemui.dreams.touch.DreamTouchHandler;
 import com.android.systemui.touch.TouchInsetManager;
 
-import java.util.concurrent.Executor;
-
-import javax.inject.Named;
-
-import dagger.Lazy;
 import dagger.Module;
 import dagger.Provides;
+import dagger.multibindings.ElementsIntoSet;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.inject.Named;
 
 /** Dagger module for {@link DreamOverlayComponent}. */
 @Module
 public abstract class DreamOverlayModule {
+    public static final String DREAM_TOUCH_HANDLERS = "dream_touch_handlers";
     public static final String DREAM_OVERLAY_CONTENT_VIEW = "dream_overlay_content_view";
     public static final String MAX_BURN_IN_OFFSET = "max_burn_in_offset";
     public static final String BURN_IN_PROTECTION_UPDATE_INTERVAL =
@@ -101,14 +104,6 @@
     /** */
     @Provides
     @DreamOverlayComponent.DreamOverlayScope
-    public static TouchInsetManager providesTouchInsetManager(@Main Executor executor,
-            DreamOverlayContainerView view) {
-        return new TouchInsetManager(executor, view);
-    }
-
-    /** */
-    @Provides
-    @DreamOverlayComponent.DreamOverlayScope
     public static DreamOverlayStatusBarView providesDreamOverlayStatusBarView(
             DreamOverlayContainerView view) {
         return Preconditions.checkNotNull(view.findViewById(R.id.dream_overlay_status_bar),
@@ -246,19 +241,14 @@
 
     @Provides
     @DreamOverlayComponent.DreamOverlayScope
-    static LifecycleOwner providesLifecycleOwner(Lazy<LifecycleRegistry> lifecycleRegistryLazy) {
-        return () -> lifecycleRegistryLazy.get();
-    }
-
-    @Provides
-    @DreamOverlayComponent.DreamOverlayScope
-    static LifecycleRegistry providesLifecycleRegistry(LifecycleOwner lifecycleOwner) {
-        return new LifecycleRegistry(lifecycleOwner);
-    }
-
-    @Provides
-    @DreamOverlayComponent.DreamOverlayScope
     static Lifecycle providesLifecycle(LifecycleOwner lifecycleOwner) {
         return lifecycleOwner.getLifecycle();
     }
+
+    @Provides
+    @ElementsIntoSet
+    static Set<DreamTouchHandler> providesDreamTouchHandlers(
+            @Named(DREAM_TOUCH_HANDLERS) @Nullable Set<DreamTouchHandler> touchHandlers) {
+        return touchHandlers != null ? touchHandlers : new HashSet<>();
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/touch/HideComplicationTouchHandler.java b/packages/SystemUI/src/com/android/systemui/dreams/dreamcomplication/HideComplicationTouchHandler.java
similarity index 94%
rename from packages/SystemUI/src/com/android/systemui/dreams/touch/HideComplicationTouchHandler.java
rename to packages/SystemUI/src/com/android/systemui/dreams/dreamcomplication/HideComplicationTouchHandler.java
index e276e0c..3a4578b 100644
--- a/packages/SystemUI/src/com/android/systemui/dreams/touch/HideComplicationTouchHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/dreams/dreamcomplication/HideComplicationTouchHandler.java
@@ -14,10 +14,10 @@
  * limitations under the License.
  */
 
-package com.android.systemui.dreams.touch;
+package com.android.systemui.dreams.dreamcomplication;
 
-import static com.android.systemui.dreams.complication.dagger.ComplicationHostViewModule.COMPLICATIONS_FADE_OUT_DELAY;
-import static com.android.systemui.dreams.complication.dagger.ComplicationHostViewModule.COMPLICATIONS_RESTORE_TIMEOUT;
+import static com.android.systemui.dreams.dreamcomplication.dagger.ComplicationModule.COMPLICATIONS_FADE_OUT_DELAY;
+import static com.android.systemui.dreams.dreamcomplication.dagger.ComplicationModule.COMPLICATIONS_RESTORE_TIMEOUT;
 
 import android.util.Log;
 import android.view.MotionEvent;
@@ -28,6 +28,8 @@
 import com.android.systemui.dagger.qualifiers.Main;
 import com.android.systemui.dreams.DreamOverlayStateController;
 import com.android.systemui.dreams.complication.Complication;
+import com.android.systemui.dreams.touch.DreamOverlayTouchMonitor;
+import com.android.systemui.dreams.touch.DreamTouchHandler;
 import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
 import com.android.systemui.touch.TouchInsetManager;
 import com.android.systemui.util.concurrency.DelayableExecutor;
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/dreamcomplication/dagger/ComplicationComponent.kt b/packages/SystemUI/src/com/android/systemui/dreams/dreamcomplication/dagger/ComplicationComponent.kt
new file mode 100644
index 0000000..f2fb48d
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/dreams/dreamcomplication/dagger/ComplicationComponent.kt
@@ -0,0 +1,21 @@
+package com.android.systemui.dreams.dreamcomplication.dagger
+
+import com.android.systemui.dreams.complication.Complication
+import com.android.systemui.dreams.dreamcomplication.HideComplicationTouchHandler
+import com.android.systemui.touch.TouchInsetManager
+import dagger.BindsInstance
+import dagger.Subcomponent
+
+@Subcomponent(modules = [ComplicationModule::class])
+interface ComplicationComponent {
+    /** Factory for generating [ComplicationComponent]. */
+    @Subcomponent.Factory
+    interface Factory {
+        fun create(
+            @BindsInstance visibilityController: Complication.VisibilityController,
+            @BindsInstance touchInsetManager: TouchInsetManager
+        ): ComplicationComponent
+    }
+
+    fun getHideComplicationTouchHandler(): HideComplicationTouchHandler
+}
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/dreamcomplication/dagger/ComplicationModule.kt b/packages/SystemUI/src/com/android/systemui/dreams/dreamcomplication/dagger/ComplicationModule.kt
new file mode 100644
index 0000000..ef75ce1
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/dreams/dreamcomplication/dagger/ComplicationModule.kt
@@ -0,0 +1,28 @@
+package com.android.systemui.dreams.dreamcomplication.dagger
+
+import android.content.res.Resources
+import com.android.systemui.R
+import com.android.systemui.dagger.qualifiers.Main
+import dagger.Module
+import dagger.Provides
+import javax.inject.Named
+
+@Module
+object ComplicationModule {
+    const val COMPLICATIONS_RESTORE_TIMEOUT = "complication_restore_timeout"
+    const val COMPLICATIONS_FADE_OUT_DELAY = "complication_fade_out_delay"
+
+    /** Provides the delay to wait for before fading out complications. */
+    @Provides
+    @Named(COMPLICATIONS_FADE_OUT_DELAY)
+    fun providesComplicationsFadeOutDelay(@Main resources: Resources): Int {
+        return resources.getInteger(R.integer.complicationFadeOutDelayMs)
+    }
+
+    /** Provides the timeout for restoring complication visibility. */
+    @Provides
+    @Named(COMPLICATIONS_RESTORE_TIMEOUT)
+    fun providesComplicationsRestoreTimeout(@Main resources: Resources): Int {
+        return resources.getInteger(R.integer.complicationRestoreMs)
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/touch/dagger/DreamTouchModule.java b/packages/SystemUI/src/com/android/systemui/dreams/touch/dagger/DreamTouchModule.java
index 7338ecb..dad0004 100644
--- a/packages/SystemUI/src/com/android/systemui/dreams/touch/dagger/DreamTouchModule.java
+++ b/packages/SystemUI/src/com/android/systemui/dreams/touch/dagger/DreamTouchModule.java
@@ -23,7 +23,6 @@
  */
 @Module(includes = {
             BouncerSwipeModule.class,
-            HideComplicationModule.class,
         }, subcomponents = {
             InputSessionComponent.class,
 })
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/touch/dagger/HideComplicationModule.java b/packages/SystemUI/src/com/android/systemui/dreams/touch/dagger/HideComplicationModule.java
deleted file mode 100644
index 3800ff7..0000000
--- a/packages/SystemUI/src/com/android/systemui/dreams/touch/dagger/HideComplicationModule.java
+++ /dev/null
@@ -1,40 +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.systemui.dreams.touch.dagger;
-
-import com.android.systemui.dreams.touch.DreamTouchHandler;
-import com.android.systemui.dreams.touch.HideComplicationTouchHandler;
-
-import dagger.Module;
-import dagger.Provides;
-import dagger.multibindings.IntoSet;
-
-/**
- * Module for {@link HideComplicationTouchHandler}.
- */
-@Module
-public class HideComplicationModule {
-    /**
-     * Provides {@link HideComplicationTouchHandler} for inclusion in touch handling over the dream.
-     */
-    @Provides
-    @IntoSet
-    public static DreamTouchHandler providesHideComplicationTouchHandler(
-            HideComplicationTouchHandler touchHandler) {
-        return touchHandler;
-    }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsDebug.java b/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsDebug.java
index 81df4ed..267e036 100644
--- a/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsDebug.java
+++ b/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsDebug.java
@@ -87,7 +87,7 @@
             new ServerFlagReader.ChangeListener() {
                 @Override
                 public void onChange() {
-                    mRestarter.restart();
+                    mRestarter.restartSystemUI();
                 }
             };
 
@@ -327,9 +327,7 @@
             Log.i(TAG, "SystemUI Restart Suppressed");
             return;
         }
-        Log.i(TAG, "Restarting SystemUI");
-        // SysUI starts back when up exited. Is there a better way to do this?
-        System.exit(0);
+        mRestarter.restartSystemUI();
     }
 
     private void restartAndroid(boolean requestSuppress) {
@@ -337,7 +335,7 @@
             Log.i(TAG, "Android Restart Suppressed");
             return;
         }
-        mRestarter.restart();
+        mRestarter.restartAndroid();
     }
 
     void setBooleanFlagInternal(Flag<?> flag, boolean value) {
diff --git a/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsDebugRestarter.kt b/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsDebugRestarter.kt
index 3d9f627..069e612 100644
--- a/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsDebugRestarter.kt
+++ b/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsDebugRestarter.kt
@@ -28,6 +28,8 @@
     private val systemExitRestarter: SystemExitRestarter,
 ) : Restarter {
 
+    private var androidRestartRequested = false
+
     val observer =
         object : WakefulnessLifecycle.Observer {
             override fun onFinishedGoingToSleep() {
@@ -36,8 +38,18 @@
             }
         }
 
-    override fun restart() {
-        Log.d(FeatureFlagsDebug.TAG, "Restart requested. Restarting on next screen off.")
+    override fun restartSystemUI() {
+        Log.d(FeatureFlagsDebug.TAG, "SystemUI Restart requested. Restarting on next screen off.")
+        scheduleRestart()
+    }
+
+    override fun restartAndroid() {
+        Log.d(FeatureFlagsDebug.TAG, "Android Restart requested. Restarting on next screen off.")
+        androidRestartRequested = true
+        scheduleRestart()
+    }
+
+    fun scheduleRestart() {
         if (wakefulnessLifecycle.wakefulness == WakefulnessLifecycle.WAKEFULNESS_ASLEEP) {
             restartNow()
         } else {
@@ -46,6 +58,10 @@
     }
 
     private fun restartNow() {
-        systemExitRestarter.restart()
+        if (androidRestartRequested) {
+            systemExitRestarter.restartAndroid()
+        } else {
+            systemExitRestarter.restartSystemUI()
+        }
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsDebugStartable.kt b/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsDebugStartable.kt
index 7189f00..b94d781 100644
--- a/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsDebugStartable.kt
+++ b/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsDebugStartable.kt
@@ -16,7 +16,9 @@
 
 package com.android.systemui.flags
 
+import android.content.Intent
 import com.android.systemui.CoreStartable
+import com.android.systemui.broadcast.BroadcastSender
 import com.android.systemui.dump.DumpManager
 import com.android.systemui.statusbar.commandline.CommandRegistry
 import dagger.Binds
@@ -31,7 +33,8 @@
     dumpManager: DumpManager,
     private val commandRegistry: CommandRegistry,
     private val flagCommand: FlagCommand,
-    private val featureFlags: FeatureFlagsDebug
+    private val featureFlags: FeatureFlagsDebug,
+    private val broadcastSender: BroadcastSender
 ) : CoreStartable {
 
     init {
@@ -43,6 +46,8 @@
     override fun start() {
         featureFlags.init()
         commandRegistry.registerCommand(FlagCommand.FLAG_COMMAND) { flagCommand }
+        val intent = Intent(FlagManager.ACTION_SYSUI_STARTED)
+        broadcastSender.sendBroadcast(intent)
     }
 }
 
diff --git a/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsRelease.java b/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsRelease.java
index 3c83682..8bddacc 100644
--- a/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsRelease.java
+++ b/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsRelease.java
@@ -61,7 +61,7 @@
             new ServerFlagReader.ChangeListener() {
                 @Override
                 public void onChange() {
-                    mRestarter.restart();
+                    mRestarter.restartSystemUI();
                 }
             };
 
diff --git a/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsReleaseRestarter.kt b/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsReleaseRestarter.kt
index a3f0f66..7ff3876 100644
--- a/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsReleaseRestarter.kt
+++ b/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsReleaseRestarter.kt
@@ -34,35 +34,48 @@
     @Background private val bgExecutor: DelayableExecutor,
     private val systemExitRestarter: SystemExitRestarter
 ) : Restarter {
-    var shouldRestart = false
+    var listenersAdded = false
     var pendingRestart: Runnable? = null
+    var androidRestartRequested = false
 
     val observer =
         object : WakefulnessLifecycle.Observer {
             override fun onFinishedGoingToSleep() {
-                maybeScheduleRestart()
+                scheduleRestart()
             }
         }
 
     val batteryCallback =
         object : BatteryController.BatteryStateChangeCallback {
             override fun onBatteryLevelChanged(level: Int, pluggedIn: Boolean, charging: Boolean) {
-                maybeScheduleRestart()
+                scheduleRestart()
             }
         }
 
-    override fun restart() {
-        Log.d(FeatureFlagsDebug.TAG, "Restart requested. Restarting when plugged in and idle.")
-        if (!shouldRestart) {
-            // Don't bother scheduling twice.
-            shouldRestart = true
-            wakefulnessLifecycle.addObserver(observer)
-            batteryController.addCallback(batteryCallback)
-            maybeScheduleRestart()
-        }
+    override fun restartSystemUI() {
+        Log.d(
+            FeatureFlagsDebug.TAG,
+            "SystemUI Restart requested. Restarting when plugged in and idle."
+        )
+        scheduleRestart()
     }
 
-    private fun maybeScheduleRestart() {
+    override fun restartAndroid() {
+        Log.d(
+            FeatureFlagsDebug.TAG,
+            "Android Restart requested. Restarting when plugged in and idle."
+        )
+        androidRestartRequested = true
+        scheduleRestart()
+    }
+
+    private fun scheduleRestart() {
+        // Don't bother adding listeners twice.
+        if (!listenersAdded) {
+            listenersAdded = true
+            wakefulnessLifecycle.addObserver(observer)
+            batteryController.addCallback(batteryCallback)
+        }
         if (
             wakefulnessLifecycle.wakefulness == WAKEFULNESS_ASLEEP && batteryController.isPluggedIn
         ) {
@@ -77,6 +90,10 @@
 
     private fun restartNow() {
         Log.d(FeatureFlagsRelease.TAG, "Restarting due to systemui flag change")
-        systemExitRestarter.restart()
+        if (androidRestartRequested) {
+            systemExitRestarter.restartAndroid()
+        } else {
+            systemExitRestarter.restartSystemUI()
+        }
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/flags/Flags.kt b/packages/SystemUI/src/com/android/systemui/flags/Flags.kt
index ae2e1d1..d4cd57f 100644
--- a/packages/SystemUI/src/com/android/systemui/flags/Flags.kt
+++ b/packages/SystemUI/src/com/android/systemui/flags/Flags.kt
@@ -71,6 +71,9 @@
     val NOTIFICATION_MEMORY_MONITOR_ENABLED =
         releasedFlag(112, "notification_memory_monitor_enabled")
 
+    val NOTIFICATION_MEMORY_LOGGING_ENABLED =
+        unreleasedFlag(119, "notification_memory_logging_enabled", teamfood = true)
+
     // TODO(b/254512731): Tracking Bug
     @JvmField
     val NOTIFICATION_DISMISSAL_FADE =
@@ -80,7 +83,7 @@
     val STABILITY_INDEX_FIX = releasedFlag(114, "stability_index_fix")
 
     // TODO(b/259559750): Tracking Bug
-    val SEMI_STABLE_SORT = unreleasedFlag(115, "semi_stable_sort", teamfood = true)
+    val SEMI_STABLE_SORT = releasedFlag(115, "semi_stable_sort")
 
     @JvmField
     val USE_ROUNDNESS_SOURCETYPES = unreleasedFlag(116, "use_roundness_sourcetype", teamfood = true)
@@ -91,14 +94,14 @@
         unreleasedFlag(259217907, "notification_group_dismissal_animation", teamfood = true)
 
     // TODO(b/257506350): Tracking Bug
-    val FSI_CHROME = unreleasedFlag(117, "fsi_chrome")
+    @JvmField val FSI_CHROME = unreleasedFlag(117, "fsi_chrome")
 
     @JvmField
     val SIMPLIFIED_APPEAR_FRACTION =
         unreleasedFlag(259395680, "simplified_appear_fraction", teamfood = true)
 
     // TODO(b/257315550): Tracking Bug
-    val NO_HUN_FOR_OLD_WHEN = unreleasedFlag(118, "no_hun_for_old_when")
+    val NO_HUN_FOR_OLD_WHEN = unreleasedFlag(118, "no_hun_for_old_when", teamfood = true)
 
     val FILTER_UNSEEN_NOTIFS_ON_KEYGUARD =
         unreleasedFlag(254647461, "filter_unseen_notifs_on_keyguard", teamfood = true)
@@ -134,7 +137,8 @@
      * Whether the clock on a wide lock screen should use the new "stepping" animation for moving
      * the digits when the clock moves.
      */
-    @JvmField val STEP_CLOCK_ANIMATION = unreleasedFlag(212, "step_clock_animation")
+    @JvmField
+    val STEP_CLOCK_ANIMATION = unreleasedFlag(212, "step_clock_animation", teamfood = true)
 
     /**
      * Migration from the legacy isDozing/dozeAmount paths to the new KeyguardTransitionRepository
@@ -168,7 +172,7 @@
      * new KeyguardTransitionRepository.
      */
     @JvmField
-    val LIGHT_REVEAL_MIGRATION = unreleasedFlag(218, "light_reveal_migration", teamfood = true)
+    val LIGHT_REVEAL_MIGRATION = unreleasedFlag(218, "light_reveal_migration", teamfood = false)
 
     // 300 - power menu
     // TODO(b/254512600): Tracking Bug
@@ -204,9 +208,6 @@
             "full_screen_user_switcher"
         )
 
-    // TODO(b/254512678): Tracking Bug
-    @JvmField val NEW_FOOTER_ACTIONS = releasedFlag(507, "new_footer_actions")
-
     // TODO(b/244064524): Tracking Bug
     @JvmField val QS_SECONDARY_DATA_SUB_INFO = releasedFlag(508, "qs_secondary_data_sub_info")
 
@@ -249,11 +250,7 @@
 
     // 801 - region sampling
     // TODO(b/254512848): Tracking Bug
-    val REGION_SAMPLING = unreleasedFlag(801, "region_sampling")
-
-    // 802 - wallpaper rendering
-    // TODO(b/254512923): Tracking Bug
-    @JvmField val USE_CANVAS_RENDERER = unreleasedFlag(802, "use_canvas_renderer")
+    val REGION_SAMPLING = unreleasedFlag(801, "region_sampling", teamfood = true)
 
     // 803 - screen contents translation
     // TODO(b/254513187): Tracking Bug
@@ -286,7 +283,11 @@
     // TODO(b/254513168): Tracking Bug
     @JvmField val UMO_SURFACE_RIPPLE = unreleasedFlag(907, "umo_surface_ripple")
 
-    @JvmField val MEDIA_FALSING_PENALTY = unreleasedFlag(908, "media_falsing_media")
+    @JvmField
+    val MEDIA_FALSING_PENALTY = unreleasedFlag(908, "media_falsing_media", teamfood = true)
+
+    // TODO(b/261734857): Tracking Bug
+    @JvmField val UMO_TURBULENCE_NOISE = unreleasedFlag(909, "umo_turbulence_noise")
 
     // 1000 - dock
     val SIMULATE_DOCK_THROUGH_CHARGING = releasedFlag(1000, "simulate_dock_through_charging")
@@ -398,9 +399,10 @@
     val CHOOSER_UNBUNDLED = unreleasedFlag(1500, "chooser_unbundled", teamfood = true)
 
     // 1600 - accessibility
+    // TODO(b/262224538): Tracking Bug
     @JvmField
     val A11Y_FLOATING_MENU_FLING_SPRING_ANIMATIONS =
-        unreleasedFlag(1600, "a11y_floating_menu_fling_spring_animations", teamfood = true)
+        releasedFlag(1600, "a11y_floating_menu_fling_spring_animations")
 
     // 1700 - clipboard
     @JvmField val CLIPBOARD_OVERLAY_REFACTOR = releasedFlag(1700, "clipboard_overlay_refactor")
@@ -417,6 +419,10 @@
     // 2000 - device controls
     @Keep @JvmField val USE_APP_PANELS = unreleasedFlag(2000, "use_app_panels", teamfood = true)
 
+    @JvmField
+    val APP_PANELS_ALL_APPS_ALLOWED =
+        unreleasedFlag(2001, "app_panels_all_apps_allowed", teamfood = true)
+
     // 2100 - Falsing Manager
     @JvmField val FALSING_FOR_LONG_TAPS = releasedFlag(2100, "falsing_for_long_taps")
 
@@ -428,6 +434,9 @@
 
     // 2300 - stylus
     @JvmField val TRACK_STYLUS_EVER_USED = unreleasedFlag(2300, "track_stylus_ever_used")
+    @JvmField val ENABLE_STYLUS_CHARGING_UI = unreleasedFlag(2301, "enable_stylus_charging_ui")
+    @JvmField
+    val ENABLE_USI_BATTERY_NOTIFICATIONS = unreleasedFlag(2302, "enable_usi_battery_notifications")
 
     // 2400 - performance tools and debugging info
     // TODO(b/238923086): Tracking Bug
@@ -435,6 +444,11 @@
     val WARN_ON_BLOCKING_BINDER_TRANSACTIONS =
         unreleasedFlag(2400, "warn_on_blocking_binder_transactions")
 
+    // 2500 - output switcher
+    // TODO(b/261538825): Tracking Bug
+    @JvmField
+    val OUTPUT_SWITCHER_ADVANCED_LAYOUT = unreleasedFlag(2500, "output_switcher_advanced_layout")
+
     // TODO(b259590361): Tracking bug
     val EXPERIMENTAL_FLAG = unreleasedFlag(2, "exp_flag_release")
 }
diff --git a/packages/SystemUI/src/com/android/systemui/flags/Restarter.kt b/packages/SystemUI/src/com/android/systemui/flags/Restarter.kt
index 8f095a2..ce8b821 100644
--- a/packages/SystemUI/src/com/android/systemui/flags/Restarter.kt
+++ b/packages/SystemUI/src/com/android/systemui/flags/Restarter.kt
@@ -16,5 +16,7 @@
 package com.android.systemui.flags
 
 interface Restarter {
-    fun restart()
-}
\ No newline at end of file
+    fun restartSystemUI()
+
+    fun restartAndroid()
+}
diff --git a/packages/SystemUI/src/com/android/systemui/flags/SystemExitRestarter.kt b/packages/SystemUI/src/com/android/systemui/flags/SystemExitRestarter.kt
index f1b1be4..89daa64 100644
--- a/packages/SystemUI/src/com/android/systemui/flags/SystemExitRestarter.kt
+++ b/packages/SystemUI/src/com/android/systemui/flags/SystemExitRestarter.kt
@@ -16,10 +16,19 @@
 
 package com.android.systemui.flags
 
+import com.android.internal.statusbar.IStatusBarService
 import javax.inject.Inject
 
-class SystemExitRestarter @Inject constructor() : Restarter {
-    override fun restart() {
+class SystemExitRestarter
+@Inject
+constructor(
+    private val barService: IStatusBarService,
+) : Restarter {
+    override fun restartAndroid() {
+        barService.restart()
+    }
+
+    override fun restartSystemUI() {
         System.exit(0)
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java
index db2cd91..c3e163f 100644
--- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java
+++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java
@@ -733,7 +733,7 @@
     @VisibleForTesting
     boolean shouldDisplayBugReport(UserInfo currentUser) {
         return mGlobalSettings.getInt(Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0
-                && (currentUser == null || currentUser.isPrimary());
+                && (currentUser == null || currentUser.isAdmin());
     }
 
     @Override
@@ -1058,8 +1058,9 @@
 
         @Override
         public boolean showBeforeProvisioning() {
-            return Build.isDebuggable() && mGlobalSettings.getInt(
-                    Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0;
+            return Build.isDebuggable() && mGlobalSettings.getIntForUser(
+                    Settings.Global.BUGREPORT_IN_POWER_MENU, 0, getCurrentUser().id) != 0
+                    && getCurrentUser().isAdmin();
         }
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardUnlockAnimationController.kt b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardUnlockAnimationController.kt
index c4eac1c..c0d6cc9 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardUnlockAnimationController.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardUnlockAnimationController.kt
@@ -824,7 +824,11 @@
         surfaceBehindEntryAnimator.cancel()
         surfaceBehindAlpha = 1f
         setSurfaceBehindAppearAmount(1f)
-        launcherUnlockController?.setUnlockAmount(1f, false /* forceIfAnimating */)
+        try {
+            launcherUnlockController?.setUnlockAmount(1f, false /* forceIfAnimating */)
+        }  catch (e: RemoteException) {
+            Log.e(TAG, "Remote exception in notifyFinishedKeyguardExitAnimation", e)
+        }
 
         // That target is no longer valid since the animation finished, null it out.
         surfaceBehindRemoteAnimationTargets = null
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
index 36c939d..d6418d0 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
@@ -1614,7 +1614,7 @@
         // TODO: Rename all screen off/on references to interactive/sleeping
         synchronized (this) {
             mDeviceInteractive = true;
-            if (mPendingLock && !cameraGestureTriggered) {
+            if (mPendingLock && !cameraGestureTriggered && !mWakeAndUnlocking) {
                 doKeyguardLocked(null);
             }
             mAnimatingScreenOff = false;
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/HomeControlsKeyguardQuickAffordanceConfig.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/HomeControlsKeyguardQuickAffordanceConfig.kt
index 2558fab..394426d 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/HomeControlsKeyguardQuickAffordanceConfig.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/HomeControlsKeyguardQuickAffordanceConfig.kt
@@ -130,6 +130,7 @@
                             state(
                                 isFeatureEnabled = component.isEnabled(),
                                 hasFavorites = favorites?.isNotEmpty() == true,
+                                hasPanels = serviceInfos.any { it.panelActivity != null },
                                 hasServiceInfos = serviceInfos.isNotEmpty(),
                                 iconResourceId = component.getTileImageId(),
                                 visibility = component.getVisibility(),
@@ -148,13 +149,14 @@
     private fun state(
         isFeatureEnabled: Boolean,
         hasFavorites: Boolean,
+        hasPanels: Boolean,
         hasServiceInfos: Boolean,
         visibility: ControlsComponent.Visibility,
         @DrawableRes iconResourceId: Int?,
     ): KeyguardQuickAffordanceConfig.LockScreenState {
         return if (
             isFeatureEnabled &&
-                hasFavorites &&
+                (hasFavorites || hasPanels) &&
                 hasServiceInfos &&
                 iconResourceId != null &&
                 visibility == ControlsComponent.Visibility.AVAILABLE
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardBouncerRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardBouncerRepository.kt
index 783f752..90f3c7d 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardBouncerRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardBouncerRepository.kt
@@ -16,23 +16,36 @@
 
 package com.android.systemui.keyguard.data.repository
 
-import com.android.keyguard.KeyguardUpdateMonitor
+import android.os.Build
 import com.android.keyguard.ViewMediatorCallback
 import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.dagger.qualifiers.Application
 import com.android.systemui.keyguard.shared.model.BouncerShowMessageModel
 import com.android.systemui.keyguard.shared.model.KeyguardBouncerModel
+import com.android.systemui.log.dagger.BouncerLog
+import com.android.systemui.log.table.TableLogBuffer
+import com.android.systemui.log.table.logDiffsForTable
 import com.android.systemui.statusbar.phone.KeyguardBouncer
 import javax.inject.Inject
+import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.flow.MutableStateFlow
 import kotlinx.coroutines.flow.asStateFlow
+import kotlinx.coroutines.flow.filterNotNull
+import kotlinx.coroutines.flow.launchIn
+import kotlinx.coroutines.flow.map
 
-/** Encapsulates app state for the lock screen primary and alternate bouncer. */
+/**
+ * Encapsulates app state for the lock screen primary and alternate bouncer.
+ *
+ * Make sure to add newly added flows to the logger.
+ */
 @SysUISingleton
 class KeyguardBouncerRepository
 @Inject
 constructor(
     private val viewMediatorCallback: ViewMediatorCallback,
-    keyguardUpdateMonitor: KeyguardUpdateMonitor,
+    @Application private val applicationScope: CoroutineScope,
+    @BouncerLog private val buffer: TableLogBuffer,
 ) {
     /** Values associated with the PrimaryBouncer (pin/pattern/password) input. */
     private val _primaryBouncerVisible = MutableStateFlow(false)
@@ -77,6 +90,10 @@
     val bouncerErrorMessage: CharSequence?
         get() = viewMediatorCallback.consumeCustomMessage()
 
+    init {
+        setUpLogging()
+    }
+
     fun setPrimaryScrimmed(isScrimmed: Boolean) {
         _primaryBouncerScrimmed.value = isScrimmed
     }
@@ -132,4 +149,57 @@
     fun setOnScreenTurnedOff(onScreenTurnedOff: Boolean) {
         _onScreenTurnedOff.value = onScreenTurnedOff
     }
+
+    /** Sets up logs for state flows. */
+    private fun setUpLogging() {
+        if (!Build.IS_DEBUGGABLE) {
+            return
+        }
+
+        primaryBouncerVisible
+            .logDiffsForTable(buffer, "", "PrimaryBouncerVisible", false)
+            .launchIn(applicationScope)
+        primaryBouncerShow
+            .map { it != null }
+            .logDiffsForTable(buffer, "", "PrimaryBouncerShow", false)
+            .launchIn(applicationScope)
+        primaryBouncerShowingSoon
+            .logDiffsForTable(buffer, "", "PrimaryBouncerShowingSoon", false)
+            .launchIn(applicationScope)
+        primaryBouncerHide
+            .logDiffsForTable(buffer, "", "PrimaryBouncerHide", false)
+            .launchIn(applicationScope)
+        primaryBouncerStartingToHide
+            .logDiffsForTable(buffer, "", "PrimaryBouncerStartingToHide", false)
+            .launchIn(applicationScope)
+        primaryBouncerStartingDisappearAnimation
+            .map { it != null }
+            .logDiffsForTable(buffer, "", "PrimaryBouncerStartingDisappearAnimation", false)
+            .launchIn(applicationScope)
+        primaryBouncerScrimmed
+            .logDiffsForTable(buffer, "", "PrimaryBouncerScrimmed", false)
+            .launchIn(applicationScope)
+        panelExpansionAmount
+            .map { (it * 1000).toInt() }
+            .logDiffsForTable(buffer, "", "PanelExpansionAmountMillis", -1)
+            .launchIn(applicationScope)
+        keyguardPosition
+            .map { it.toInt() }
+            .logDiffsForTable(buffer, "", "KeyguardPosition", -1)
+            .launchIn(applicationScope)
+        onScreenTurnedOff
+            .logDiffsForTable(buffer, "", "OnScreenTurnedOff", false)
+            .launchIn(applicationScope)
+        isBackButtonEnabled
+            .filterNotNull()
+            .logDiffsForTable(buffer, "", "IsBackButtonEnabled", false)
+            .launchIn(applicationScope)
+        showMessage
+            .map { it?.message }
+            .logDiffsForTable(buffer, "", "ShowMessage", null)
+            .launchIn(applicationScope)
+        resourceUpdateRequests
+            .logDiffsForTable(buffer, "", "ResourceUpdateRequests", false)
+            .launchIn(applicationScope)
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/log/SessionTracker.java b/packages/SystemUI/src/com/android/systemui/log/SessionTracker.java
index c7e4c5e..b98a92f 100644
--- a/packages/SystemUI/src/com/android/systemui/log/SessionTracker.java
+++ b/packages/SystemUI/src/com/android/systemui/log/SessionTracker.java
@@ -49,7 +49,9 @@
 @SysUISingleton
 public class SessionTracker implements CoreStartable {
     private static final String TAG = "SessionTracker";
-    private static final boolean DEBUG = false;
+
+    // To enable logs: `adb shell setprop log.tag.SessionTracker DEBUG` & restart sysui
+    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
 
     // At most 20 bits: ~1m possibilities, ~0.5% probability of collision in 100 values
     private final InstanceIdSequence mInstanceIdGenerator = new InstanceIdSequence(1 << 20);
@@ -81,8 +83,8 @@
         mKeyguardUpdateMonitor.registerCallback(mKeyguardUpdateMonitorCallback);
         mKeyguardStateController.addCallback(mKeyguardStateCallback);
 
-        mKeyguardSessionStarted = mKeyguardStateController.isShowing();
-        if (mKeyguardSessionStarted) {
+        if (mKeyguardStateController.isShowing()) {
+            mKeyguardSessionStarted = true;
             startSession(SESSION_KEYGUARD);
         }
     }
@@ -136,12 +138,11 @@
             new KeyguardUpdateMonitorCallback() {
         @Override
         public void onStartedGoingToSleep(int why) {
-            // we need to register to the KeyguardUpdateMonitor lifecycle b/c it gets called
-            // before the WakefulnessLifecycle
             if (mKeyguardSessionStarted) {
-                return;
+                endSession(SESSION_KEYGUARD);
             }
 
+            // Start a new session whenever the device goes to sleep
             mKeyguardSessionStarted = true;
             startSession(SESSION_KEYGUARD);
         }
@@ -154,6 +155,9 @@
             boolean wasSessionStarted = mKeyguardSessionStarted;
             boolean keyguardShowing = mKeyguardStateController.isShowing();
             if (keyguardShowing && !wasSessionStarted) {
+                // the keyguard can start showing without the device going to sleep (ie: lockdown
+                // from the power button), so we start a new keyguard session when the keyguard is
+                // newly shown in addition to when the device starts going to sleep
                 mKeyguardSessionStarted = true;
                 startSession(SESSION_KEYGUARD);
             } else if (!keyguardShowing && wasSessionStarted) {
diff --git a/services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt b/packages/SystemUI/src/com/android/systemui/log/dagger/BouncerLog.kt
similarity index 64%
copy from services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt
copy to packages/SystemUI/src/com/android/systemui/log/dagger/BouncerLog.kt
index 528680e7..2251a7b 100644
--- a/services/permission/java/com/android/server/permission/access/external/RoSystemProperties.kt
+++ b/packages/SystemUI/src/com/android/systemui/log/dagger/BouncerLog.kt
@@ -14,11 +14,12 @@
  * limitations under the License.
  */
 
-package com.android.server.permission.access.external
+package com.android.systemui.log.dagger
 
-class RoSystemProperties {
-    companion object {
-        const val CONTROL_PRIVAPP_PERMISSIONS_DISABLE = false
-        const val CONTROL_PRIVAPP_PERMISSIONS_ENFORCE = false
-    }
-}
+import java.lang.annotation.Documented
+import java.lang.annotation.Retention
+import java.lang.annotation.RetentionPolicy
+import javax.inject.Qualifier
+
+/** Logger for the primary and alternative bouncers. */
+@Qualifier @Documented @Retention(RetentionPolicy.RUNTIME) annotation class BouncerLog
diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java b/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java
index f5a97ce..a7d60a1 100644
--- a/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java
+++ b/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java
@@ -23,6 +23,8 @@
 import com.android.systemui.dagger.SysUISingleton;
 import com.android.systemui.dagger.qualifiers.Main;
 import com.android.systemui.log.LogBufferFactory;
+import com.android.systemui.log.table.TableLogBuffer;
+import com.android.systemui.log.table.TableLogBufferFactory;
 import com.android.systemui.plugins.log.LogBuffer;
 import com.android.systemui.plugins.log.LogcatEchoTracker;
 import com.android.systemui.plugins.log.LogcatEchoTrackerDebug;
@@ -345,6 +347,14 @@
         return factory.create("BluetoothLog", 50);
     }
 
+    /** Provides a logging buffer for the primary bouncer. */
+    @Provides
+    @SysUISingleton
+    @BouncerLog
+    public static TableLogBuffer provideBouncerLogBuffer(TableLogBufferFactory factory) {
+        return factory.create("BouncerLog", 250);
+    }
+
     /**
      * Provides a {@link LogBuffer} for Udfps logs.
      */
diff --git a/packages/SystemUI/src/com/android/systemui/log/table/Diffable.kt b/packages/SystemUI/src/com/android/systemui/log/table/Diffable.kt
index bb04b6b4..348d941 100644
--- a/packages/SystemUI/src/com/android/systemui/log/table/Diffable.kt
+++ b/packages/SystemUI/src/com/android/systemui/log/table/Diffable.kt
@@ -100,3 +100,46 @@
         newVal
     }
 }
+/**
+ * Each time the Int flow is updated with a new value that's different from the previous value, logs
+ * the new value to the given [tableLogBuffer].
+ */
+fun Flow<Int>.logDiffsForTable(
+    tableLogBuffer: TableLogBuffer,
+    columnPrefix: String,
+    columnName: String,
+    initialValue: Int,
+): Flow<Int> {
+    val initialValueFun = {
+        tableLogBuffer.logChange(columnPrefix, columnName, initialValue)
+        initialValue
+    }
+    return this.pairwiseBy(initialValueFun) { prevVal, newVal: Int ->
+        if (prevVal != newVal) {
+            tableLogBuffer.logChange(columnPrefix, columnName, newVal)
+        }
+        newVal
+    }
+}
+
+/**
+ * Each time the String? flow is updated with a new value that's different from the previous value,
+ * logs the new value to the given [tableLogBuffer].
+ */
+fun Flow<String?>.logDiffsForTable(
+    tableLogBuffer: TableLogBuffer,
+    columnPrefix: String,
+    columnName: String,
+    initialValue: String?,
+): Flow<String?> {
+    val initialValueFun = {
+        tableLogBuffer.logChange(columnPrefix, columnName, initialValue)
+        initialValue
+    }
+    return this.pairwiseBy(initialValueFun) { prevVal, newVal: String? ->
+        if (prevVal != newVal) {
+            tableLogBuffer.logChange(columnPrefix, columnName, newVal)
+        }
+        newVal
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/log/table/TableLogBuffer.kt b/packages/SystemUI/src/com/android/systemui/log/table/TableLogBuffer.kt
index 9d0b833..2c299d6 100644
--- a/packages/SystemUI/src/com/android/systemui/log/table/TableLogBuffer.kt
+++ b/packages/SystemUI/src/com/android/systemui/log/table/TableLogBuffer.kt
@@ -127,11 +127,21 @@
         rowInitializer(row)
     }
 
+    /** Logs a String? change. */
+    fun logChange(prefix: String, columnName: String, value: String?) {
+        logChange(systemClock.currentTimeMillis(), prefix, columnName, value)
+    }
+
     /** Logs a boolean change. */
     fun logChange(prefix: String, columnName: String, value: Boolean) {
         logChange(systemClock.currentTimeMillis(), prefix, columnName, value)
     }
 
+    /** Logs a Int change. */
+    fun logChange(prefix: String, columnName: String, value: Int) {
+        logChange(systemClock.currentTimeMillis(), prefix, columnName, value)
+    }
+
     // Keep these individual [logChange] methods private (don't let clients give us their own
     // timestamps.)
 
diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt
index 3012bb4..2dd339d 100644
--- a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt
@@ -422,6 +422,7 @@
                     appUid = appUid
                 )
             mediaEntries.put(packageName, resumeData)
+            logSingleVsMultipleMediaAdded(appUid, packageName, instanceId)
             logger.logResumeMediaAdded(appUid, packageName, instanceId)
         }
         backgroundExecutor.execute {
@@ -812,6 +813,7 @@
         val appUid = appInfo?.uid ?: Process.INVALID_UID
 
         if (logEvent) {
+            logSingleVsMultipleMediaAdded(appUid, sbn.packageName, instanceId)
             logger.logActiveMediaAdded(appUid, sbn.packageName, instanceId, playbackLocation)
         } else if (playbackLocation != currentEntry?.playbackLocation) {
             logger.logPlaybackLocationChange(appUid, sbn.packageName, instanceId, playbackLocation)
@@ -855,6 +857,20 @@
         }
     }
 
+    private fun logSingleVsMultipleMediaAdded(
+        appUid: Int,
+        packageName: String,
+        instanceId: InstanceId
+    ) {
+        if (mediaEntries.size == 1) {
+            logger.logSingleMediaPlayerInCarousel(appUid, packageName, instanceId)
+        } else if (mediaEntries.size == 2) {
+            // Since this method is only called when there is a new media session added.
+            // logging needed once there is more than one media session in carousel.
+            logger.logMultipleMediaPlayersInCarousel(appUid, packageName, instanceId)
+        }
+    }
+
     private fun getAppInfoFromPackage(packageName: String): ApplicationInfo? {
         try {
             return context.packageManager.getApplicationInfo(packageName, 0)
diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaControlPanel.java b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaControlPanel.java
index df8fb91..db7a145 100644
--- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaControlPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaControlPanel.java
@@ -224,6 +224,8 @@
     private TurbulenceNoiseController mTurbulenceNoiseController;
     private FeatureFlags mFeatureFlags;
     private TurbulenceNoiseAnimationConfig mTurbulenceNoiseAnimationConfig = null;
+    @VisibleForTesting
+    MultiRippleController.Companion.RipplesFinishedListener mRipplesFinishedListener = null;
 
     /**
      * Initialize a new control panel
@@ -404,15 +406,17 @@
         MultiRippleView multiRippleView = vh.getMultiRippleView();
         mMultiRippleController = new MultiRippleController(multiRippleView);
         mTurbulenceNoiseController = new TurbulenceNoiseController(vh.getTurbulenceNoiseView());
-        multiRippleView.addRipplesFinishedListener(
-                () -> {
-                    if (mTurbulenceNoiseAnimationConfig == null) {
-                        mTurbulenceNoiseAnimationConfig = createLingeringNoiseAnimation();
-                    }
-                    // Color will be correctly updated in ColorSchemeTransition.
-                    mTurbulenceNoiseController.play(mTurbulenceNoiseAnimationConfig);
+        if (mFeatureFlags.isEnabled(Flags.UMO_TURBULENCE_NOISE)) {
+            mRipplesFinishedListener = () -> {
+                if (mTurbulenceNoiseAnimationConfig == null) {
+                    mTurbulenceNoiseAnimationConfig = createLingeringNoiseAnimation();
                 }
-        );
+                // Color will be correctly updated in ColorSchemeTransition.
+                mTurbulenceNoiseController.play(mTurbulenceNoiseAnimationConfig);
+            };
+            mMultiRippleController.addRipplesFinishedListener(mRipplesFinishedListener);
+        }
+
         mColorSchemeTransition = new ColorSchemeTransition(
                 mContext, mMediaViewHolder, mMultiRippleController, mTurbulenceNoiseController);
         mMetadataAnimationHandler = new MetadataAnimationHandler(exit, enter);
diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/util/MediaUiEventLogger.kt b/packages/SystemUI/src/com/android/systemui/media/controls/util/MediaUiEventLogger.kt
index 3ad8c21..ea943be 100644
--- a/packages/SystemUI/src/com/android/systemui/media/controls/util/MediaUiEventLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/controls/util/MediaUiEventLogger.kt
@@ -213,6 +213,24 @@
             instanceId
         )
     }
+
+    fun logSingleMediaPlayerInCarousel(uid: Int, packageName: String, instanceId: InstanceId) {
+        logger.logWithInstanceId(
+            MediaUiEvent.MEDIA_CAROUSEL_SINGLE_PLAYER,
+            uid,
+            packageName,
+            instanceId
+        )
+    }
+
+    fun logMultipleMediaPlayersInCarousel(uid: Int, packageName: String, instanceId: InstanceId) {
+        logger.logWithInstanceId(
+            MediaUiEvent.MEDIA_CAROUSEL_MULTIPLE_PLAYERS,
+            uid,
+            packageName,
+            instanceId
+        )
+    }
 }
 
 enum class MediaUiEvent(val metricId: Int) : UiEventLogger.UiEventEnum {
@@ -269,7 +287,11 @@
     @UiEvent(doc = "User tapped on a media recommendation card")
     MEDIA_RECOMMENDATION_CARD_TAP(1045),
     @UiEvent(doc = "User opened the broadcast dialog from a media control")
-    MEDIA_OPEN_BROADCAST_DIALOG(1079);
+    MEDIA_OPEN_BROADCAST_DIALOG(1079),
+    @UiEvent(doc = "The media carousel contains one media player card")
+    MEDIA_CAROUSEL_SINGLE_PLAYER(1244),
+    @UiEvent(doc = "The media carousel contains multiple media player cards")
+    MEDIA_CAROUSEL_MULTIPLE_PLAYERS(1245);
 
     override fun getId() = metricId
 }
diff --git a/packages/SystemUI/src/com/android/systemui/media/dagger/MediaModule.java b/packages/SystemUI/src/com/android/systemui/media/dagger/MediaModule.java
index 3e5d337..bb833df 100644
--- a/packages/SystemUI/src/com/android/systemui/media/dagger/MediaModule.java
+++ b/packages/SystemUI/src/com/android/systemui/media/dagger/MediaModule.java
@@ -30,9 +30,11 @@
 import com.android.systemui.media.taptotransfer.MediaTttCommandLineHelper;
 import com.android.systemui.media.taptotransfer.MediaTttFlags;
 import com.android.systemui.media.taptotransfer.common.MediaTttLogger;
+import com.android.systemui.media.taptotransfer.receiver.ChipReceiverInfo;
 import com.android.systemui.media.taptotransfer.receiver.MediaTttReceiverLogger;
 import com.android.systemui.media.taptotransfer.sender.MediaTttSenderLogger;
 import com.android.systemui.plugins.log.LogBuffer;
+import com.android.systemui.temporarydisplay.chipbar.ChipbarInfo;
 
 import java.util.Optional;
 
@@ -95,19 +97,19 @@
     @Provides
     @SysUISingleton
     @MediaTttSenderLogger
-    static MediaTttLogger providesMediaTttSenderLogger(
+    static MediaTttLogger<ChipbarInfo> providesMediaTttSenderLogger(
             @MediaTttSenderLogBuffer LogBuffer buffer
     ) {
-        return new MediaTttLogger("Sender", buffer);
+        return new MediaTttLogger<>("Sender", buffer);
     }
 
     @Provides
     @SysUISingleton
     @MediaTttReceiverLogger
-    static MediaTttLogger providesMediaTttReceiverLogger(
+    static MediaTttLogger<ChipReceiverInfo> providesMediaTttReceiverLogger(
             @MediaTttReceiverLogBuffer LogBuffer buffer
     ) {
-        return new MediaTttLogger("Receiver", buffer);
+        return new MediaTttLogger<>("Receiver", buffer);
     }
 
     /** */
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaItem.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaItem.java
new file mode 100644
index 0000000..875a010
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaItem.java
@@ -0,0 +1,97 @@
+/*
+ * 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.systemui.media.dialog;
+
+import androidx.annotation.IntDef;
+
+import com.android.settingslib.media.MediaDevice;
+import com.android.systemui.R;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.util.Optional;
+
+/**
+ * MediaItem represents an item in OutputSwitcher list (could be a MediaDevice, group divider or
+ * connect new device item).
+ */
+public class MediaItem {
+    private final Optional<MediaDevice> mMediaDeviceOptional;
+    private final String mTitle;
+    @MediaItemType
+    private final int mMediaItemType;
+
+    @Retention(RetentionPolicy.SOURCE)
+    @IntDef({
+            MediaItemType.TYPE_DEVICE,
+            MediaItemType.TYPE_GROUP_DIVIDER,
+            MediaItemType.TYPE_PAIR_NEW_DEVICE})
+    public @interface MediaItemType {
+        int TYPE_DEVICE = 0;
+        int TYPE_GROUP_DIVIDER = 1;
+        int TYPE_PAIR_NEW_DEVICE = 2;
+    }
+
+    public MediaItem() {
+        this.mMediaDeviceOptional = Optional.empty();
+        this.mTitle = null;
+        this.mMediaItemType = MediaItemType.TYPE_PAIR_NEW_DEVICE;
+    }
+
+    public MediaItem(String title, int mediaItemType) {
+        this.mMediaDeviceOptional = Optional.empty();
+        this.mTitle = title;
+        this.mMediaItemType = mediaItemType;
+    }
+
+    public MediaItem(MediaDevice mediaDevice) {
+        this.mMediaDeviceOptional = Optional.of(mediaDevice);
+        this.mTitle = mediaDevice.getName();
+        this.mMediaItemType = MediaItemType.TYPE_DEVICE;
+    }
+
+    public Optional<MediaDevice> getMediaDevice() {
+        return mMediaDeviceOptional;
+    }
+
+    /**
+     * Get layout id based on media item Type.
+     */
+    public static int getMediaLayoutId(int mediaItemType) {
+        switch (mediaItemType) {
+            case MediaItemType.TYPE_DEVICE:
+            case MediaItemType.TYPE_PAIR_NEW_DEVICE:
+                return R.layout.media_output_list_item_advanced;
+            case MediaItemType.TYPE_GROUP_DIVIDER:
+            default:
+                return R.layout.media_output_list_group_divider;
+        }
+    }
+
+    public String getTitle() {
+        return mTitle;
+    }
+
+    public boolean isMutingExpectedDevice() {
+        return mMediaDeviceOptional.isPresent()
+                && mMediaDeviceOptional.get().isMutingExpectedDevice();
+    }
+
+    public int getMediaItemType() {
+        return mMediaItemType;
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapter.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapter.java
index ee59561..fb47d97 100644
--- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapter.java
+++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapter.java
@@ -16,7 +16,6 @@
 
 package com.android.systemui.media.dialog;
 
-import android.annotation.DrawableRes;
 import android.content.res.ColorStateList;
 import android.graphics.PorterDuff;
 import android.graphics.PorterDuffColorFilter;
@@ -25,9 +24,11 @@
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.CheckBox;
+import android.widget.TextView;
 
 import androidx.annotation.NonNull;
 import androidx.core.widget.CompoundButtonCompat;
+import androidx.recyclerview.widget.RecyclerView;
 
 import com.android.settingslib.media.LocalMediaManager.MediaDeviceState;
 import com.android.settingslib.media.MediaDevice;
@@ -49,29 +50,68 @@
     }
 
     @Override
-    public MediaDeviceBaseViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup,
+    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup,
             int viewType) {
         super.onCreateViewHolder(viewGroup, viewType);
-        return new MediaDeviceViewHolder(mHolderView);
+        if (mController.isAdvancedLayoutSupported()) {
+            switch (viewType) {
+                case MediaItem.MediaItemType.TYPE_GROUP_DIVIDER:
+                    return new MediaGroupDividerViewHolder(mHolderView);
+                case MediaItem.MediaItemType.TYPE_PAIR_NEW_DEVICE:
+                case MediaItem.MediaItemType.TYPE_DEVICE:
+                default:
+                    return new MediaDeviceViewHolder(mHolderView);
+            }
+        } else {
+            return new MediaDeviceViewHolder(mHolderView);
+        }
     }
 
     @Override
-    public void onBindViewHolder(@NonNull MediaDeviceBaseViewHolder viewHolder, int position) {
-        final int size = mController.getMediaDevices().size();
-        if (position == size) {
-            viewHolder.onBind(CUSTOMIZED_ITEM_PAIR_NEW, false /* topMargin */,
-                    true /* bottomMargin */);
-        } else if (position < size) {
-            viewHolder.onBind(((List<MediaDevice>) (mController.getMediaDevices())).get(position),
-                    position == 0 /* topMargin */, position == (size - 1) /* bottomMargin */,
-                    position);
-        } else if (DEBUG) {
-            Log.d(TAG, "Incorrect position: " + position);
+    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
+        if (mController.isAdvancedLayoutSupported()) {
+            MediaItem currentMediaItem = mController.getMediaItemList().get(position);
+            switch (currentMediaItem.getMediaItemType()) {
+                case MediaItem.MediaItemType.TYPE_GROUP_DIVIDER:
+                    ((MediaGroupDividerViewHolder) viewHolder).onBind(currentMediaItem.getTitle());
+                    break;
+                case MediaItem.MediaItemType.TYPE_PAIR_NEW_DEVICE:
+                    ((MediaDeviceViewHolder) viewHolder).onBind(CUSTOMIZED_ITEM_PAIR_NEW);
+                    break;
+                case MediaItem.MediaItemType.TYPE_DEVICE:
+                    ((MediaDeviceViewHolder) viewHolder).onBind(
+                            currentMediaItem.getMediaDevice().get(),
+                            position);
+                    break;
+                default:
+                    Log.d(TAG, "Incorrect position: " + position);
+            }
+        } else {
+            final int size = mController.getMediaDevices().size();
+            if (position == size) {
+                ((MediaDeviceViewHolder) viewHolder).onBind(CUSTOMIZED_ITEM_PAIR_NEW);
+            } else if (position < size) {
+                ((MediaDeviceViewHolder) viewHolder).onBind(
+                        ((List<MediaDevice>) (mController.getMediaDevices())).get(position),
+                        position);
+            } else if (DEBUG) {
+                Log.d(TAG, "Incorrect position: " + position);
+            }
         }
     }
 
     @Override
     public long getItemId(int position) {
+        if (mController.isAdvancedLayoutSupported()) {
+            if (position >= mController.getMediaItemList().size()) {
+                Log.d(TAG, "Incorrect position for item id: " + position);
+                return position;
+            }
+            MediaItem currentMediaItem = mController.getMediaItemList().get(position);
+            return currentMediaItem.getMediaDevice().isPresent()
+                    ? currentMediaItem.getMediaDevice().get().getId().hashCode()
+                    : position;
+        }
         final int size = mController.getMediaDevices().size();
         if (position == size) {
             return -1;
@@ -85,9 +125,18 @@
     }
 
     @Override
+    public int getItemViewType(int position) {
+        return mController.isAdvancedLayoutSupported()
+                ? mController.getMediaItemList().get(position).getMediaItemType()
+                : super.getItemViewType(position);
+    }
+
+    @Override
     public int getItemCount() {
         // Add extra one for "pair new"
-        return mController.getMediaDevices().size() + 1;
+        return mController.isAdvancedLayoutSupported()
+                ? mController.getMediaItemList().size()
+                : mController.getMediaDevices().size() + 1;
     }
 
     class MediaDeviceViewHolder extends MediaDeviceBaseViewHolder {
@@ -97,8 +146,8 @@
         }
 
         @Override
-        void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin, int position) {
-            super.onBind(device, topMargin, bottomMargin, position);
+        void onBind(MediaDevice device, int position) {
+            super.onBind(device, position);
             boolean isMutingExpectedDeviceExist = mController.hasMutingExpectedDevice();
             final boolean currentlyConnected = isCurrentlyConnected(device);
             boolean isCurrentSeekbarInvisible = mSeekBar.getVisibility() == View.GONE;
@@ -122,17 +171,19 @@
                 // Set different layout for each device
                 if (device.isMutingExpectedDevice()
                         && !mController.isCurrentConnectedDeviceRemote()) {
-                    updateTitleIcon(R.drawable.media_output_icon_volume,
-                            mController.getColorItemContent());
+                    if (!mController.isAdvancedLayoutSupported()) {
+                        updateTitleIcon(R.drawable.media_output_icon_volume,
+                                mController.getColorItemContent());
+                    }
                     initMutingExpectedDevice();
                     mCurrentActivePosition = position;
-                    updateContainerClickListener(v -> onItemClick(v, device));
+                    updateFullItemClickListener(v -> onItemClick(v, device));
                     setSingleLineLayout(getItemTitle(device));
                 } else if (device.getState() == MediaDeviceState.STATE_CONNECTING_FAILED) {
                     setUpDeviceIcon(device);
                     updateConnectionFailedStatusIcon();
                     mSubTitleText.setText(R.string.media_output_dialog_connect_failed);
-                    updateContainerClickListener(v -> onItemClick(v, device));
+                    updateFullItemClickListener(v -> onItemClick(v, device));
                     setTwoLineLayout(device, false /* bFocused */, false /* showSeekBar */,
                             false /* showProgressBar */, true /* showSubtitle */,
                             true /* showStatus */);
@@ -146,8 +197,10 @@
                         && isDeviceIncluded(mController.getSelectedMediaDevice(), device)) {
                     boolean isDeviceDeselectable = isDeviceIncluded(
                             mController.getDeselectableMediaDevice(), device);
-                    updateTitleIcon(R.drawable.media_output_icon_volume,
-                            mController.getColorItemContent());
+                    if (!mController.isAdvancedLayoutSupported()) {
+                        updateTitleIcon(R.drawable.media_output_icon_volume,
+                                mController.getColorItemContent());
+                    }
                     updateGroupableCheckBox(true, isDeviceDeselectable, device);
                     updateEndClickArea(device, isDeviceDeselectable);
                     setUpContentDescriptionForView(mContainerLayout, false, device);
@@ -161,8 +214,22 @@
                             && !mController.isCurrentConnectedDeviceRemote()) {
                         // mark as disconnected and set special click listener
                         setUpDeviceIcon(device);
-                        updateContainerClickListener(v -> cancelMuteAwaitConnection());
+                        updateFullItemClickListener(v -> cancelMuteAwaitConnection());
                         setSingleLineLayout(getItemTitle(device));
+                    } else if (mController.isCurrentConnectedDeviceRemote()
+                            && !mController.getSelectableMediaDevice().isEmpty()
+                            && mController.isAdvancedLayoutSupported()) {
+                        //If device is connected and there's other selectable devices, layout as
+                        // one of selected devices.
+                        boolean isDeviceDeselectable = isDeviceIncluded(
+                                mController.getDeselectableMediaDevice(), device);
+                        updateGroupableCheckBox(true, isDeviceDeselectable, device);
+                        updateEndClickArea(device, isDeviceDeselectable);
+                        setUpContentDescriptionForView(mContainerLayout, false, device);
+                        setSingleLineLayout(getItemTitle(device), true /* showSeekBar */,
+                                false /* showProgressBar */, true /* showCheckBox */,
+                                true /* showEndTouchArea */);
+                        initSeekbar(device, isCurrentSeekbarInvisible);
                     } else {
                         updateTitleIcon(R.drawable.media_output_icon_volume,
                                 mController.getColorItemContent());
@@ -176,14 +243,19 @@
                 } else if (isDeviceIncluded(mController.getSelectableMediaDevice(), device)) {
                     setUpDeviceIcon(device);
                     updateGroupableCheckBox(false, true, device);
-                    updateContainerClickListener(v -> onGroupActionTriggered(true, device));
+                    if (mController.isAdvancedLayoutSupported()) {
+                        updateEndClickArea(device, true);
+                    }
+                    updateFullItemClickListener(mController.isAdvancedLayoutSupported()
+                            ? v -> onItemClick(v, device)
+                            : v -> onGroupActionTriggered(true, device));
                     setSingleLineLayout(getItemTitle(device), false /* showSeekBar */,
                             false /* showProgressBar */, true /* showCheckBox */,
                             true /* showEndTouchArea */);
                 } else {
                     setUpDeviceIcon(device);
                     setSingleLineLayout(getItemTitle(device));
-                    updateContainerClickListener(v -> onItemClick(v, device));
+                    updateFullItemClickListener(v -> onItemClick(v, device));
                 }
             }
         }
@@ -214,6 +286,11 @@
                     isDeviceDeselectable ? (v) -> mCheckBox.performClick() : null);
             mEndTouchArea.setImportantForAccessibility(
                     View.IMPORTANT_FOR_ACCESSIBILITY_YES);
+            if (mController.isAdvancedLayoutSupported()) {
+                mEndTouchArea.getBackground().setColorFilter(
+                        new PorterDuffColorFilter(mController.getColorItemBackground(),
+                                PorterDuff.Mode.SRC_IN));
+            }
             setUpContentDescriptionForView(mEndTouchArea, true, device);
         }
 
@@ -228,17 +305,13 @@
             setCheckBoxColor(mCheckBox, mController.getColorItemContent());
         }
 
-        private void updateTitleIcon(@DrawableRes int id, int color) {
-            mTitleIcon.setImageDrawable(mContext.getDrawable(id));
-            mTitleIcon.setColorFilter(color);
-        }
-
-        private void updateContainerClickListener(View.OnClickListener listener) {
+        private void updateFullItemClickListener(View.OnClickListener listener) {
             mContainerLayout.setOnClickListener(listener);
+            updateIconAreaClickListener(listener);
         }
 
         @Override
-        void onBind(int customizedItem, boolean topMargin, boolean bottomMargin) {
+        void onBind(int customizedItem) {
             if (customizedItem == CUSTOMIZED_ITEM_PAIR_NEW) {
                 mTitleText.setTextColor(mController.getColorItemContent());
                 mCheckBox.setVisibility(View.GONE);
@@ -246,6 +319,11 @@
                 final Drawable addDrawable = mContext.getDrawable(R.drawable.ic_add);
                 mTitleIcon.setImageDrawable(addDrawable);
                 mTitleIcon.setColorFilter(mController.getColorItemContent());
+                if (mController.isAdvancedLayoutSupported()) {
+                    mIconAreaLayout.getBackground().setColorFilter(
+                            new PorterDuffColorFilter(mController.getColorItemBackground(),
+                                    PorterDuff.Mode.SRC_IN));
+                }
                 mContainerLayout.setOnClickListener(mController::launchBluetoothPairing);
             }
         }
@@ -290,4 +368,18 @@
                             : R.string.accessibility_cast_name, device.getName()));
         }
     }
+
+    class MediaGroupDividerViewHolder extends RecyclerView.ViewHolder {
+        final TextView mTitleText;
+
+        MediaGroupDividerViewHolder(@NonNull View itemView) {
+            super(itemView);
+            mTitleText = itemView.requireViewById(R.id.title);
+        }
+
+        void onBind(String groupDividerTitle) {
+            mTitleText.setTextColor(mController.getColorItemContent());
+            mTitleText.setText(groupDividerTitle);
+        }
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseAdapter.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseAdapter.java
index 3f7b226..3b1d861 100644
--- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseAdapter.java
+++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseAdapter.java
@@ -16,8 +16,11 @@
 
 package com.android.systemui.media.dialog;
 
+import static com.android.systemui.media.dialog.MediaOutputSeekbar.VOLUME_PERCENTAGE_SCALE_SIZE;
+
 import android.animation.Animator;
 import android.animation.ValueAnimator;
+import android.annotation.DrawableRes;
 import android.app.WallpaperColors;
 import android.content.Context;
 import android.graphics.PorterDuff;
@@ -55,7 +58,7 @@
  * Base adapter for media output dialog.
  */
 public abstract class MediaOutputBaseAdapter extends
-        RecyclerView.Adapter<MediaOutputBaseAdapter.MediaDeviceBaseViewHolder> {
+        RecyclerView.Adapter<RecyclerView.ViewHolder> {
 
     static final int CUSTOMIZED_ITEM_PAIR_NEW = 1;
     static final int CUSTOMIZED_ITEM_GROUP = 2;
@@ -77,11 +80,13 @@
     }
 
     @Override
-    public MediaDeviceBaseViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup,
+    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup,
             int viewType) {
         mContext = viewGroup.getContext();
-        mHolderView = LayoutInflater.from(mContext).inflate(R.layout.media_output_list_item,
-                viewGroup, false);
+        mHolderView = LayoutInflater.from(mContext).inflate(
+                mController.isAdvancedLayoutSupported() ? MediaItem.getMediaLayoutId(
+                        viewType) /*R.layout.media_output_list_item_advanced*/
+                        : R.layout.media_output_list_item, viewGroup, false);
 
         return null;
     }
@@ -129,18 +134,20 @@
 
         private static final int ANIM_DURATION = 500;
 
-        final LinearLayout mContainerLayout;
+        final ViewGroup mContainerLayout;
         final FrameLayout mItemLayout;
+        final FrameLayout mIconAreaLayout;
         final TextView mTitleText;
         final TextView mTwoLineTitleText;
         final TextView mSubTitleText;
+        final TextView mVolumeValueText;
         final ImageView mTitleIcon;
         final ProgressBar mProgressBar;
         final MediaOutputSeekbar mSeekBar;
         final LinearLayout mTwoLineLayout;
         final ImageView mStatusIcon;
         final CheckBox mCheckBox;
-        final LinearLayout mEndTouchArea;
+        final ViewGroup mEndTouchArea;
         private String mDeviceId;
         private ValueAnimator mCornerAnimator;
         private ValueAnimator mVolumeAnimator;
@@ -159,10 +166,17 @@
             mStatusIcon = view.requireViewById(R.id.media_output_item_status);
             mCheckBox = view.requireViewById(R.id.check_box);
             mEndTouchArea = view.requireViewById(R.id.end_action_area);
+            if (mController.isAdvancedLayoutSupported()) {
+                mVolumeValueText = view.requireViewById(R.id.volume_value);
+                mIconAreaLayout = view.requireViewById(R.id.icon_area);
+            } else {
+                mVolumeValueText = null;
+                mIconAreaLayout = null;
+            }
             initAnimator();
         }
 
-        void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin, int position) {
+        void onBind(MediaDevice device, int position) {
             mDeviceId = device.getId();
             mCheckBox.setVisibility(View.GONE);
             mStatusIcon.setVisibility(View.GONE);
@@ -170,15 +184,20 @@
             mEndTouchArea.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
             mContainerLayout.setOnClickListener(null);
             mContainerLayout.setContentDescription(null);
+            mTitleIcon.setOnClickListener(null);
             mTitleText.setTextColor(mController.getColorItemContent());
             mSubTitleText.setTextColor(mController.getColorItemContent());
             mTwoLineTitleText.setTextColor(mController.getColorItemContent());
+            if (mController.isAdvancedLayoutSupported()) {
+                mIconAreaLayout.setOnClickListener(null);
+                mVolumeValueText.setTextColor(mController.getColorItemContent());
+            }
             mSeekBar.getProgressDrawable().setColorFilter(
                     new PorterDuffColorFilter(mController.getColorSeekbarProgress(),
                             PorterDuff.Mode.SRC_IN));
         }
 
-        abstract void onBind(int customizedItem, boolean topMargin, boolean bottomMargin);
+        abstract void onBind(int customizedItem);
 
         void setSingleLineLayout(CharSequence title) {
             setSingleLineLayout(title, false, false, false, false);
@@ -203,13 +222,28 @@
                                     .findDrawableByLayerId(android.R.id.progress);
                     final GradientDrawable progressDrawable =
                             (GradientDrawable) clipDrawable.getDrawable();
-                    progressDrawable.setCornerRadius(mController.getActiveRadius());
+                    if (mController.isAdvancedLayoutSupported()) {
+                        progressDrawable.setCornerRadii(
+                                new float[]{0, 0, mController.getActiveRadius(),
+                                        mController.getActiveRadius(),
+                                        mController.getActiveRadius(),
+                                        mController.getActiveRadius(), 0, 0});
+                    } else {
+                        progressDrawable.setCornerRadius(mController.getActiveRadius());
+                    }
                 }
             }
             mItemLayout.getBackground().setColorFilter(new PorterDuffColorFilter(
                     isActive ? mController.getColorConnectedItemBackground()
                             : mController.getColorItemBackground(),
                     PorterDuff.Mode.SRC_IN));
+            if (mController.isAdvancedLayoutSupported()) {
+                mIconAreaLayout.getBackground().setColorFilter(new PorterDuffColorFilter(
+                        showSeekBar ? mController.getColorSeekbarProgress()
+                                : showProgressBar ? mController.getColorConnectedItemBackground()
+                                        : mController.getColorItemBackground(),
+                        PorterDuff.Mode.SRC_IN));
+            }
             mProgressBar.setVisibility(showProgressBar ? View.VISIBLE : View.GONE);
             mSeekBar.setAlpha(1);
             mSeekBar.setVisibility(showSeekBar ? View.VISIBLE : View.GONE);
@@ -220,6 +254,13 @@
             mTitleText.setVisibility(View.VISIBLE);
             mCheckBox.setVisibility(showCheckBox ? View.VISIBLE : View.GONE);
             mEndTouchArea.setVisibility(showEndTouchArea ? View.VISIBLE : View.GONE);
+            if (mController.isAdvancedLayoutSupported()) {
+                ViewGroup.MarginLayoutParams params =
+                        (ViewGroup.MarginLayoutParams) mItemLayout.getLayoutParams();
+                params.rightMargin = showEndTouchArea ? mController.getItemMarginEndSelectable()
+                        : mController.getItemMarginEndDefault();
+            }
+            mTitleIcon.setColorFilter(mController.getColorItemContent());
         }
 
         void setTwoLineLayout(MediaDevice device, boolean bFocused, boolean showSeekBar,
@@ -263,42 +304,134 @@
             final int currentVolume = device.getCurrentVolume();
             if (mSeekBar.getVolume() != currentVolume) {
                 if (isCurrentSeekbarInvisible && !mIsInitVolumeFirstTime) {
+                    if (mController.isAdvancedLayoutSupported()) {
+                        updateTitleIcon(currentVolume == 0 ? R.drawable.media_output_icon_volume_off
+                                        : R.drawable.media_output_icon_volume,
+                                mController.getColorItemContent());
+                    }
                     animateCornerAndVolume(mSeekBar.getProgress(),
                             MediaOutputSeekbar.scaleVolumeToProgress(currentVolume));
                 } else {
                     if (!mVolumeAnimator.isStarted()) {
+                        if (mController.isAdvancedLayoutSupported()) {
+                            int percentage =
+                                    (int) ((double) currentVolume * VOLUME_PERCENTAGE_SCALE_SIZE
+                                            / (double) mSeekBar.getMax());
+                            if (percentage == 0) {
+                                updateMutedVolumeIcon();
+                            } else {
+                                updateUnmutedVolumeIcon();
+                            }
+                        }
                         mSeekBar.setVolume(currentVolume);
                     }
                 }
+            } else if (mController.isAdvancedLayoutSupported() && currentVolume == 0) {
+                mSeekBar.resetVolume();
+                updateMutedVolumeIcon();
             }
             if (mIsInitVolumeFirstTime) {
                 mIsInitVolumeFirstTime = false;
             }
+            if (mController.isAdvancedLayoutSupported()) {
+                updateIconAreaClickListener((v) -> {
+                    mSeekBar.resetVolume();
+                    mController.adjustVolume(device, 0);
+                    updateMutedVolumeIcon();
+                });
+            }
             mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                 @Override
                 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                     if (device == null || !fromUser) {
                         return;
                     }
-                    int currentVolume = MediaOutputSeekbar.scaleProgressToVolume(progress);
+                    int progressToVolume = MediaOutputSeekbar.scaleProgressToVolume(progress);
                     int deviceVolume = device.getCurrentVolume();
-                    if (currentVolume != deviceVolume) {
-                        mController.adjustVolume(device, currentVolume);
+                    if (mController.isAdvancedLayoutSupported()) {
+                        int percentage =
+                                (int) ((double) progressToVolume * VOLUME_PERCENTAGE_SCALE_SIZE
+                                        / (double) seekBar.getMax());
+                        mVolumeValueText.setText(mContext.getResources().getString(
+                                R.string.media_output_dialog_volume_percentage, percentage));
+                        mVolumeValueText.setVisibility(View.VISIBLE);
+                    }
+                    if (progressToVolume != deviceVolume) {
+                        mController.adjustVolume(device, progressToVolume);
+                        if (mController.isAdvancedLayoutSupported() && deviceVolume == 0) {
+                            updateUnmutedVolumeIcon();
+                        }
                     }
                 }
 
                 @Override
                 public void onStartTrackingTouch(SeekBar seekBar) {
+                    if (mController.isAdvancedLayoutSupported()) {
+                        mTitleIcon.setVisibility(View.INVISIBLE);
+                        mVolumeValueText.setVisibility(View.VISIBLE);
+                    }
                     mIsDragging = true;
                 }
 
                 @Override
                 public void onStopTrackingTouch(SeekBar seekBar) {
+                    if (mController.isAdvancedLayoutSupported()) {
+                        int currentVolume = MediaOutputSeekbar.scaleProgressToVolume(
+                                seekBar.getProgress());
+                        int percentage =
+                                (int) ((double) currentVolume * VOLUME_PERCENTAGE_SCALE_SIZE
+                                        / (double) seekBar.getMax());
+                        if (percentage == 0) {
+                            seekBar.setProgress(0);
+                            updateMutedVolumeIcon();
+                        } else {
+                            updateUnmutedVolumeIcon();
+                        }
+                        mTitleIcon.setVisibility(View.VISIBLE);
+                        mVolumeValueText.setVisibility(View.GONE);
+                    }
                     mIsDragging = false;
                 }
             });
         }
 
+        void updateMutedVolumeIcon() {
+            updateTitleIcon(R.drawable.media_output_icon_volume_off,
+                    mController.getColorItemContent());
+            final GradientDrawable iconAreaBackgroundDrawable =
+                    (GradientDrawable) mIconAreaLayout.getBackground();
+            iconAreaBackgroundDrawable.setCornerRadius(mController.getActiveRadius());
+        }
+
+        void updateUnmutedVolumeIcon() {
+            updateTitleIcon(R.drawable.media_output_icon_volume,
+                    mController.getColorItemContent());
+            final GradientDrawable iconAreaBackgroundDrawable =
+                    (GradientDrawable) mIconAreaLayout.getBackground();
+            iconAreaBackgroundDrawable.setCornerRadii(new float[]{
+                    mController.getActiveRadius(),
+                    mController.getActiveRadius(),
+                    0, 0, 0, 0, mController.getActiveRadius(), mController.getActiveRadius()
+            });
+        }
+
+        void updateTitleIcon(@DrawableRes int id, int color) {
+            mTitleIcon.setImageDrawable(mContext.getDrawable(id));
+            mTitleIcon.setColorFilter(color);
+            if (mController.isAdvancedLayoutSupported()) {
+                mIconAreaLayout.getBackground().setColorFilter(
+                        new PorterDuffColorFilter(mController.getColorSeekbarProgress(),
+                                PorterDuff.Mode.SRC_IN));
+            }
+        }
+
+        void updateIconAreaClickListener(View.OnClickListener listener) {
+            if (mController.isAdvancedLayoutSupported()) {
+                mIconAreaLayout.setOnClickListener(listener);
+            }
+            mTitleIcon.setOnClickListener(listener);
+        }
+
         void initMutingExpectedDevice() {
             disableSeekBar();
             final Drawable backgroundDrawable = mContext.getDrawable(
@@ -316,11 +449,26 @@
             final ClipDrawable clipDrawable =
                     (ClipDrawable) ((LayerDrawable) mSeekBar.getProgressDrawable())
                             .findDrawableByLayerId(android.R.id.progress);
-            final GradientDrawable progressDrawable = (GradientDrawable) clipDrawable.getDrawable();
+            final GradientDrawable targetBackgroundDrawable =
+                    (GradientDrawable) (mController.isAdvancedLayoutSupported()
+                            ? mIconAreaLayout.getBackground()
+                            : clipDrawable.getDrawable());
             mCornerAnimator.addUpdateListener(animation -> {
                 float value = (float) animation.getAnimatedValue();
                 layoutBackgroundDrawable.setCornerRadius(value);
-                progressDrawable.setCornerRadius(value);
+                if (mController.isAdvancedLayoutSupported()) {
+                    if (toProgress == 0) {
+                        targetBackgroundDrawable.setCornerRadius(value);
+                    } else {
+                        targetBackgroundDrawable.setCornerRadii(new float[]{
+                                value,
+                                value,
+                                0, 0, 0, 0, value, value
+                        });
+                    }
+                } else {
+                    targetBackgroundDrawable.setCornerRadius(value);
+                }
             });
             mVolumeAnimator.setIntValues(fromProgress, toProgress);
             mVolumeAnimator.start();
@@ -391,6 +539,7 @@
                         return;
                     }
                     mTitleIcon.setImageIcon(icon);
+                    mTitleIcon.setColorFilter(mController.getColorItemContent());
                 });
             });
         }
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogFactory.kt b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogFactory.kt
index 2b5d6fd..cdd00f9 100644
--- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogFactory.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogFactory.kt
@@ -26,6 +26,7 @@
 import com.android.settingslib.bluetooth.LocalBluetoothManager
 import com.android.systemui.animation.DialogLaunchAnimator
 import com.android.systemui.broadcast.BroadcastSender
+import com.android.systemui.flags.FeatureFlags
 import com.android.systemui.media.nearby.NearbyMediaDevicesManager
 import com.android.systemui.plugins.ActivityStarter
 import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
@@ -47,7 +48,8 @@
     private val nearbyMediaDevicesManagerOptional: Optional<NearbyMediaDevicesManager>,
     private val audioManager: AudioManager,
     private val powerExemptionManager: PowerExemptionManager,
-    private val keyGuardManager: KeyguardManager
+    private val keyGuardManager: KeyguardManager,
+    private val featureFlags: FeatureFlags
 ) {
     var mediaOutputBroadcastDialog: MediaOutputBroadcastDialog? = null
 
@@ -59,7 +61,7 @@
         val controller = MediaOutputController(context, packageName,
                 mediaSessionManager, lbm, starter, notifCollection,
                 dialogLaunchAnimator, nearbyMediaDevicesManagerOptional, audioManager,
-                powerExemptionManager, keyGuardManager)
+                powerExemptionManager, keyGuardManager, featureFlags)
         val dialog =
                 MediaOutputBroadcastDialog(context, aboveStatusBar, broadcastSender, controller)
         mediaOutputBroadcastDialog = dialog
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java
index 19b401d..b436562 100644
--- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java
+++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java
@@ -73,6 +73,8 @@
 import com.android.systemui.animation.ActivityLaunchAnimator;
 import com.android.systemui.animation.DialogLaunchAnimator;
 import com.android.systemui.broadcast.BroadcastSender;
+import com.android.systemui.flags.FeatureFlags;
+import com.android.systemui.flags.Flags;
 import com.android.systemui.media.nearby.NearbyMediaDevicesManager;
 import com.android.systemui.monet.ColorScheme;
 import com.android.systemui.plugins.ActivityStarter;
@@ -91,6 +93,7 @@
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.Executor;
+import java.util.stream.Collectors;
 
 import javax.inject.Inject;
 
@@ -119,6 +122,7 @@
     @VisibleForTesting
     final List<MediaDevice> mMediaDevices = new CopyOnWriteArrayList<>();
     final List<MediaDevice> mCachedMediaDevices = new CopyOnWriteArrayList<>();
+    private final List<MediaItem> mMediaItemList = new CopyOnWriteArrayList<>();
     private final AudioManager mAudioManager;
     private final PowerExemptionManager mPowerExemptionManager;
     private final KeyguardManager mKeyGuardManager;
@@ -145,8 +149,11 @@
     private int mColorConnectedItemBackground;
     private int mColorPositiveButtonText;
     private int mColorDialogBackground;
+    private int mItemMarginEndDefault;
+    private int mItemMarginEndSelectable;
     private float mInactiveRadius;
     private float mActiveRadius;
+    private FeatureFlags mFeatureFlags;
 
     public enum BroadcastNotifyDialog {
         ACTION_FIRST_LAUNCH,
@@ -162,7 +169,8 @@
             Optional<NearbyMediaDevicesManager> nearbyMediaDevicesManagerOptional,
             AudioManager audioManager,
             PowerExemptionManager powerExemptionManager,
-            KeyguardManager keyGuardManager) {
+            KeyguardManager keyGuardManager,
+            FeatureFlags featureFlags) {
         mContext = context;
         mPackageName = packageName;
         mMediaSessionManager = mediaSessionManager;
@@ -172,6 +180,7 @@
         mAudioManager = audioManager;
         mPowerExemptionManager = powerExemptionManager;
         mKeyGuardManager = keyGuardManager;
+        mFeatureFlags = featureFlags;
         InfoMediaManager imm = new InfoMediaManager(mContext, packageName, null, lbm);
         mLocalMediaManager = new LocalMediaManager(mContext, lbm, imm, packageName);
         mMetricLogger = new MediaOutputMetricLogger(mContext, mPackageName);
@@ -195,12 +204,17 @@
                 R.dimen.media_output_dialog_active_background_radius);
         mColorDialogBackground = Utils.getColorStateListDefaultColor(mContext,
                 R.color.media_dialog_background);
+        mItemMarginEndDefault = (int) mContext.getResources().getDimension(
+                R.dimen.media_output_dialog_default_margin_end);
+        mItemMarginEndSelectable = (int) mContext.getResources().getDimension(
+                R.dimen.media_output_dialog_selectable_margin_end);
     }
 
     void start(@NonNull Callback cb) {
         synchronized (mMediaDevicesLock) {
             mCachedMediaDevices.clear();
             mMediaDevices.clear();
+            mMediaItemList.clear();
         }
         mNearbyDeviceInfoMap.clear();
         if (mNearbyMediaDevicesManager != null) {
@@ -251,6 +265,7 @@
         synchronized (mMediaDevicesLock) {
             mCachedMediaDevices.clear();
             mMediaDevices.clear();
+            mMediaItemList.clear();
         }
         if (mNearbyMediaDevicesManager != null) {
             mNearbyMediaDevicesManager.unregisterNearbyDevicesCallback(this);
@@ -276,7 +291,11 @@
     public void onSelectedDeviceStateChanged(MediaDevice device,
             @LocalMediaManager.MediaDeviceState int state) {
         mCallback.onRouteChanged();
-        mMetricLogger.logOutputSuccess(device.toString(), new ArrayList<>(mMediaDevices));
+        if (isAdvancedLayoutSupported()) {
+            mMetricLogger.logOutputItemSuccess(device.toString(), new ArrayList<>(mMediaItemList));
+        } else {
+            mMetricLogger.logOutputSuccess(device.toString(), new ArrayList<>(mMediaDevices));
+        }
     }
 
     @Override
@@ -287,7 +306,11 @@
     @Override
     public void onRequestFailed(int reason) {
         mCallback.onRouteChanged();
-        mMetricLogger.logOutputFailure(new ArrayList<>(mMediaDevices), reason);
+        if (isAdvancedLayoutSupported()) {
+            mMetricLogger.logOutputItemFailure(new ArrayList<>(mMediaItemList), reason);
+        } else {
+            mMetricLogger.logOutputFailure(new ArrayList<>(mMediaDevices), reason);
+        }
     }
 
     /**
@@ -307,6 +330,7 @@
         try {
             synchronized (mMediaDevicesLock) {
                 mMediaDevices.removeIf(MediaDevice::isMutingExpectedDevice);
+                mMediaItemList.removeIf((MediaItem::isMutingExpectedDevice));
             }
             mAudioManager.cancelMuteAwaitConnection(mAudioManager.getMutingExpectedDevice());
         } catch (Exception e) {
@@ -527,7 +551,23 @@
         return mActiveRadius;
     }
 
+    public int getItemMarginEndDefault() {
+        return mItemMarginEndDefault;
+    }
+
+    public int getItemMarginEndSelectable() {
+        return mItemMarginEndSelectable;
+    }
+
     private void buildMediaDevices(List<MediaDevice> devices) {
+        if (isAdvancedLayoutSupported()) {
+            buildMediaItems(devices);
+        } else {
+            buildDefaultMediaDevices(devices);
+        }
+    }
+
+    private void buildDefaultMediaDevices(List<MediaDevice> devices) {
         synchronized (mMediaDevicesLock) {
             attachRangeInfo(devices);
             Collections.sort(devices, Comparator.naturalOrder());
@@ -584,6 +624,81 @@
         }
     }
 
+    private void buildMediaItems(List<MediaDevice> devices) {
+        synchronized (mMediaDevicesLock) {
+            //TODO(b/257851968): do the organization only when there's no suggested sorted order
+            // we get from application
+            attachRangeInfo(devices);
+            Collections.sort(devices, Comparator.naturalOrder());
+            // For the first time building list, to make sure the top device is the connected
+            // device.
+            if (mMediaItemList.isEmpty()) {
+                boolean needToHandleMutingExpectedDevice =
+                        hasMutingExpectedDevice() && !isCurrentConnectedDeviceRemote();
+                final MediaDevice connectedMediaDevice =
+                        needToHandleMutingExpectedDevice ? null
+                                : getCurrentConnectedMediaDevice();
+                if (connectedMediaDevice == null) {
+                    if (DEBUG) {
+                        Log.d(TAG, "No connected media device or muting expected device exist.");
+                    }
+                    if (needToHandleMutingExpectedDevice) {
+                        for (MediaDevice device : devices) {
+                            if (device.isMutingExpectedDevice()) {
+                                mMediaItemList.add(0, new MediaItem(device));
+                            } else {
+                                mMediaItemList.add(new MediaItem(device));
+                            }
+                        }
+                    } else {
+                        mMediaItemList.addAll(
+                                devices.stream().map(MediaItem::new).collect(Collectors.toList()));
+                    }
+
+                    categorizeMediaItems();
+                    return;
+                }
+                // selected device exist
+                for (MediaDevice device : devices) {
+                    if (TextUtils.equals(device.getId(), connectedMediaDevice.getId())) {
+                        mMediaItemList.add(0, new MediaItem(device));
+                    } else {
+                        mMediaItemList.add(new MediaItem(device));
+                    }
+                }
+                categorizeMediaItems();
+                return;
+            }
+            // To keep the same list order
+            final List<MediaDevice> targetMediaDevices = new ArrayList<>();
+            for (MediaItem originalMediaItem : mMediaItemList) {
+                for (MediaDevice newDevice : devices) {
+                    if (originalMediaItem.getMediaDevice().isPresent()
+                            && TextUtils.equals(originalMediaItem.getMediaDevice().get().getId(),
+                            newDevice.getId())) {
+                        targetMediaDevices.add(newDevice);
+                        break;
+                    }
+                }
+            }
+            if (targetMediaDevices.size() != devices.size()) {
+                devices.removeAll(targetMediaDevices);
+                targetMediaDevices.addAll(devices);
+            }
+            mMediaItemList.clear();
+            mMediaItemList.addAll(
+                    targetMediaDevices.stream().map(MediaItem::new).collect(Collectors.toList()));
+            categorizeMediaItems();
+        }
+    }
+
+    private void categorizeMediaItems() {
+        synchronized (mMediaDevicesLock) {
+            //TODO(255124239): do the categorization here
+            mMediaItemList.add(new MediaItem());
+        }
+    }
+
     private void attachRangeInfo(List<MediaDevice> devices) {
         for (MediaDevice mediaDevice : devices) {
             if (mNearbyDeviceInfoMap.containsKey(mediaDevice.getId())) {
@@ -599,6 +714,10 @@
                 currentConnectedMediaDevice);
     }
 
+    public boolean isAdvancedLayoutSupported() {
+        return mFeatureFlags.isEnabled(Flags.OUTPUT_SWITCHER_ADVANCED_LAYOUT);
+    }
+
     List<MediaDevice> getGroupMediaDevices() {
         final List<MediaDevice> selectedDevices = getSelectedMediaDevice();
         final List<MediaDevice> selectableDevices = getSelectableMediaDevice();
@@ -647,6 +766,10 @@
         return mMediaDevices;
     }
 
+    public List<MediaItem> getMediaItemList() {
+        return mMediaItemList;
+    }
+
     MediaDevice getCurrentConnectedMediaDevice() {
         return mLocalMediaManager.getCurrentConnectedDevice();
     }
@@ -726,9 +849,19 @@
 
     boolean isAnyDeviceTransferring() {
         synchronized (mMediaDevicesLock) {
-            for (MediaDevice device : mMediaDevices) {
-                if (device.getState() == LocalMediaManager.MediaDeviceState.STATE_CONNECTING) {
-                    return true;
+            if (isAdvancedLayoutSupported()) {
+                for (MediaItem mediaItem : mMediaItemList) {
+                    if (mediaItem.getMediaDevice().isPresent()
+                            && mediaItem.getMediaDevice().get().getState()
+                            == LocalMediaManager.MediaDeviceState.STATE_CONNECTING) {
+                        return true;
+                    }
+                }
+            } else {
+                for (MediaDevice device : mMediaDevices) {
+                    if (device.getState() == LocalMediaManager.MediaDeviceState.STATE_CONNECTING) {
+                        return true;
+                    }
                 }
             }
         }
@@ -792,7 +925,7 @@
         MediaOutputController controller = new MediaOutputController(mContext, mPackageName,
                 mMediaSessionManager, mLocalBluetoothManager, mActivityStarter,
                 mNotifCollection, mDialogLaunchAnimator, Optional.of(mNearbyMediaDevicesManager),
-                mAudioManager, mPowerExemptionManager, mKeyGuardManager);
+                mAudioManager, mPowerExemptionManager, mKeyGuardManager, mFeatureFlags);
         MediaOutputBroadcastDialog dialog = new MediaOutputBroadcastDialog(mContext, true,
                 broadcastSender, controller);
         mDialogLaunchAnimator.showFromView(dialog, mediaOutputDialog);
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialogFactory.kt b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialogFactory.kt
index 543efed..7dbf876 100644
--- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialogFactory.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialogFactory.kt
@@ -31,6 +31,7 @@
 import com.android.systemui.media.nearby.NearbyMediaDevicesManager
 import com.android.systemui.plugins.ActivityStarter
 import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
+import com.android.systemui.flags.FeatureFlags
 import java.util.Optional
 import javax.inject.Inject
 
@@ -49,7 +50,8 @@
     private val nearbyMediaDevicesManagerOptional: Optional<NearbyMediaDevicesManager>,
     private val audioManager: AudioManager,
     private val powerExemptionManager: PowerExemptionManager,
-    private val keyGuardManager: KeyguardManager
+    private val keyGuardManager: KeyguardManager,
+    private val featureFlags: FeatureFlags
 ) {
     companion object {
         private const val INTERACTION_JANK_TAG = "media_output"
@@ -65,7 +67,7 @@
             context, packageName,
             mediaSessionManager, lbm, starter, notifCollection,
             dialogLaunchAnimator, nearbyMediaDevicesManagerOptional, audioManager,
-            powerExemptionManager, keyGuardManager)
+            powerExemptionManager, keyGuardManager, featureFlags)
         val dialog =
             MediaOutputDialog(context, aboveStatusBar, broadcastSender, controller, uiEventLogger)
         mediaOutputDialog = dialog
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputMetricLogger.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputMetricLogger.java
index 7d3e82c..2250d72 100644
--- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputMetricLogger.java
+++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputMetricLogger.java
@@ -96,6 +96,31 @@
     }
 
     /**
+     * Do the metric logging of content switching success.
+     * @param selectedDeviceType string representation of the target media device
+     * @param deviceItemList media item list for device count updating
+     */
+    public void logOutputItemSuccess(String selectedDeviceType, List<MediaItem> deviceItemList) {
+        if (DEBUG) {
+            Log.d(TAG, "logOutputSuccess - selected device: " + selectedDeviceType);
+        }
+
+        updateLoggingMediaItemCount(deviceItemList);
+
+        SysUiStatsLog.write(
+                SysUiStatsLog.MEDIAOUTPUT_OP_SWITCH_REPORTED,
+                getLoggingDeviceType(mSourceDevice, true),
+                getLoggingDeviceType(mTargetDevice, false),
+                SysUiStatsLog.MEDIA_OUTPUT_OP_SWITCH_REPORTED__RESULT__OK,
+                SysUiStatsLog.MEDIA_OUTPUT_OP_SWITCH_REPORTED__SUBRESULT__NO_ERROR,
+                getLoggingPackageName(),
+                mWiredDeviceCount,
+                mConnectedBluetoothDeviceCount,
+                mRemoteDeviceCount,
+                mAppliedDeviceCountWithinRemoteGroup);
+    }
+
+    /**
      * Do the metric logging of volume adjustment.
      * @param source the device been adjusted
      */
@@ -166,6 +191,31 @@
                 mAppliedDeviceCountWithinRemoteGroup);
     }
 
+    /**
+     * Do the metric logging of content switching failure.
+     * @param deviceItemList media item list for device count updating
+     * @param reason the reason of content switching failure
+     */
+    public void logOutputItemFailure(List<MediaItem> deviceItemList, int reason) {
+        if (DEBUG) {
+            Log.e(TAG, "logRequestFailed - " + reason);
+        }
+
+        updateLoggingMediaItemCount(deviceItemList);
+
+        SysUiStatsLog.write(
+                SysUiStatsLog.MEDIAOUTPUT_OP_SWITCH_REPORTED,
+                getLoggingDeviceType(mSourceDevice, true),
+                getLoggingDeviceType(mTargetDevice, false),
+                SysUiStatsLog.MEDIA_OUTPUT_OP_SWITCH_REPORTED__RESULT__ERROR,
+                getLoggingSwitchOpSubResult(reason),
+                getLoggingPackageName(),
+                mWiredDeviceCount,
+                mConnectedBluetoothDeviceCount,
+                mRemoteDeviceCount,
+                mAppliedDeviceCountWithinRemoteGroup);
+    }
+
     private void updateLoggingDeviceCount(List<MediaDevice> deviceList) {
         mWiredDeviceCount = mConnectedBluetoothDeviceCount = mRemoteDeviceCount = 0;
         mAppliedDeviceCountWithinRemoteGroup = 0;
@@ -196,6 +246,37 @@
         }
     }
 
+    private void updateLoggingMediaItemCount(List<MediaItem> deviceItemList) {
+        mWiredDeviceCount = mConnectedBluetoothDeviceCount = mRemoteDeviceCount = 0;
+        mAppliedDeviceCountWithinRemoteGroup = 0;
+
+        for (MediaItem mediaItem: deviceItemList) {
+            if (mediaItem.getMediaDevice().isPresent()
+                    && mediaItem.getMediaDevice().get().isConnected()) {
+                switch (mediaItem.getMediaDevice().get().getDeviceType()) {
+                    case MediaDevice.MediaDeviceType.TYPE_3POINT5_MM_AUDIO_DEVICE:
+                    case MediaDevice.MediaDeviceType.TYPE_USB_C_AUDIO_DEVICE:
+                        mWiredDeviceCount++;
+                        break;
+                    case MediaDevice.MediaDeviceType.TYPE_BLUETOOTH_DEVICE:
+                        mConnectedBluetoothDeviceCount++;
+                        break;
+                    case MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE:
+                    case MediaDevice.MediaDeviceType.TYPE_CAST_GROUP_DEVICE:
+                        mRemoteDeviceCount++;
+                        break;
+                    default:
+                }
+            }
+        }
+
+        if (DEBUG) {
+            Log.d(TAG, "connected devices:" + " wired: " + mWiredDeviceCount
+                    + " bluetooth: " + mConnectedBluetoothDeviceCount
+                    + " remote: " + mRemoteDeviceCount);
+        }
+    }
+
     private int getLoggingDeviceType(MediaDevice device, boolean isSourceDevice) {
         if (device == null) {
             return isSourceDevice
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputSeekbar.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputSeekbar.java
index 4ff79d6..253c3c7 100644
--- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputSeekbar.java
+++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputSeekbar.java
@@ -26,6 +26,7 @@
  */
 public class MediaOutputSeekbar extends SeekBar {
     private static final int SCALE_SIZE = 1000;
+    public static final int VOLUME_PERCENTAGE_SCALE_SIZE = 100000;
 
     public MediaOutputSeekbar(Context context, AttributeSet attrs) {
         super(context, attrs);
diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttLogger.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttLogger.kt
index b55bedd..8aef938 100644
--- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttLogger.kt
@@ -18,17 +18,21 @@
 
 import com.android.systemui.plugins.log.LogBuffer
 import com.android.systemui.plugins.log.LogLevel
+import com.android.systemui.temporarydisplay.TemporaryViewInfo
 import com.android.systemui.temporarydisplay.TemporaryViewLogger
 
 /**
  * A logger for media tap-to-transfer events.
  *
  * @param deviceTypeTag the type of device triggering the logs -- "Sender" or "Receiver".
+ *
+ * TODO(b/245610654): We should de-couple the sender and receiver loggers, since they're vastly
+ * different experiences.
  */
-class MediaTttLogger(
+class MediaTttLogger<T : TemporaryViewInfo>(
     deviceTypeTag: String,
     buffer: LogBuffer
-) : TemporaryViewLogger(buffer, BASE_TAG + deviceTypeTag) {
+) : TemporaryViewLogger<T>(buffer, BASE_TAG + deviceTypeTag) {
     /** Logs a change in the chip state for the given [mediaRouteId]. */
     fun logStateChange(stateName: String, mediaRouteId: String, packageName: String?) {
         buffer.log(
diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttUtils.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttUtils.kt
index 769494a..066c185 100644
--- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttUtils.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttUtils.kt
@@ -19,10 +19,13 @@
 import android.content.Context
 import android.content.pm.PackageManager
 import android.graphics.drawable.Drawable
-import com.android.settingslib.Utils
+import androidx.annotation.AttrRes
+import androidx.annotation.DrawableRes
 import com.android.systemui.R
 import com.android.systemui.common.shared.model.ContentDescription
 import com.android.systemui.common.shared.model.Icon
+import com.android.systemui.common.shared.model.TintedIcon
+import com.android.systemui.temporarydisplay.TemporaryViewInfo
 
 /** Utility methods for media tap-to-transfer. */
 class MediaTttUtils {
@@ -34,23 +37,6 @@
         const val WAKE_REASON_RECEIVER = "MEDIA_TRANSFER_ACTIVATED_RECEIVER"
 
         /**
-         * Returns the information needed to display the icon in [Icon] form.
-         *
-         * See [getIconInfoFromPackageName].
-         */
-        fun getIconFromPackageName(
-            context: Context,
-            appPackageName: String?,
-            logger: MediaTttLogger,
-        ): Icon {
-            val iconInfo = getIconInfoFromPackageName(context, appPackageName, logger)
-            return Icon.Loaded(
-                iconInfo.drawable,
-                ContentDescription.Loaded(iconInfo.contentDescription)
-            )
-        }
-
-        /**
          * Returns the information needed to display the icon.
          *
          * The information will either contain app name and icon of the app playing media, or a
@@ -62,21 +48,25 @@
         fun getIconInfoFromPackageName(
             context: Context,
             appPackageName: String?,
-            logger: MediaTttLogger
+            logger: MediaTttLogger<out TemporaryViewInfo>
         ): IconInfo {
             if (appPackageName != null) {
+                val packageManager = context.packageManager
                 try {
                     val contentDescription =
-                        context.packageManager
-                            .getApplicationInfo(
-                                appPackageName,
-                                PackageManager.ApplicationInfoFlags.of(0)
-                            )
-                            .loadLabel(context.packageManager)
-                            .toString()
+                        ContentDescription.Loaded(
+                            packageManager
+                                .getApplicationInfo(
+                                    appPackageName,
+                                    PackageManager.ApplicationInfoFlags.of(0)
+                                )
+                                .loadLabel(packageManager)
+                                .toString()
+                        )
                     return IconInfo(
                         contentDescription,
-                        drawable = context.packageManager.getApplicationIcon(appPackageName),
+                        MediaTttIcon.Loaded(packageManager.getApplicationIcon(appPackageName)),
+                        tintAttr = null,
                         isAppIcon = true
                     )
                 } catch (e: PackageManager.NameNotFoundException) {
@@ -84,25 +74,41 @@
                 }
             }
             return IconInfo(
-                contentDescription =
-                    context.getString(R.string.media_output_dialog_unknown_launch_app_name),
-                drawable =
-                    context.resources.getDrawable(R.drawable.ic_cast).apply {
-                        this.setTint(
-                            Utils.getColorAttrDefaultColor(context, android.R.attr.textColorPrimary)
-                        )
-                    },
+                ContentDescription.Resource(R.string.media_output_dialog_unknown_launch_app_name),
+                MediaTttIcon.Resource(R.drawable.ic_cast),
+                tintAttr = android.R.attr.textColorPrimary,
                 isAppIcon = false
             )
         }
     }
 }
 
+/** Stores all the information for an icon shown with media TTT. */
 data class IconInfo(
-    val contentDescription: String,
-    val drawable: Drawable,
+    val contentDescription: ContentDescription,
+    val icon: MediaTttIcon,
+    @AttrRes val tintAttr: Int?,
     /**
      * True if [drawable] is the app's icon, and false if [drawable] is some generic default icon.
      */
     val isAppIcon: Boolean
-)
+) {
+    /** Converts this into a [TintedIcon]. */
+    fun toTintedIcon(): TintedIcon {
+        val iconOutput =
+            when (icon) {
+                is MediaTttIcon.Loaded -> Icon.Loaded(icon.drawable, contentDescription)
+                is MediaTttIcon.Resource -> Icon.Resource(icon.res, contentDescription)
+            }
+        return TintedIcon(iconOutput, tintAttr)
+    }
+}
+
+/**
+ * Mimics [com.android.systemui.common.shared.model.Icon] but without the content description, since
+ * the content description may need to be overridden.
+ */
+sealed interface MediaTttIcon {
+    data class Loaded(val drawable: Drawable) : MediaTttIcon
+    data class Resource(@DrawableRes val res: Int) : MediaTttIcon
+}
diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt
index cc5e256..9ca5fad 100644
--- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt
@@ -33,17 +33,22 @@
 import com.android.internal.widget.CachingIconView
 import com.android.settingslib.Utils
 import com.android.systemui.R
+import com.android.systemui.common.shared.model.ContentDescription
+import com.android.systemui.common.ui.binder.TintedIconViewBinder
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.dagger.qualifiers.Main
 import com.android.systemui.media.taptotransfer.MediaTttFlags
+import com.android.systemui.media.taptotransfer.common.MediaTttIcon
 import com.android.systemui.media.taptotransfer.common.MediaTttLogger
 import com.android.systemui.media.taptotransfer.common.MediaTttUtils
 import com.android.systemui.statusbar.CommandQueue
 import com.android.systemui.statusbar.policy.ConfigurationController
 import com.android.systemui.temporarydisplay.TemporaryViewDisplayController
 import com.android.systemui.temporarydisplay.TemporaryViewInfo
+import com.android.systemui.temporarydisplay.ViewPriority
 import com.android.systemui.util.animation.AnimationUtil.Companion.frames
 import com.android.systemui.util.concurrency.DelayableExecutor
+import com.android.systemui.util.time.SystemClock
 import com.android.systemui.util.view.ViewUtil
 import com.android.systemui.util.wakelock.WakeLock
 import javax.inject.Inject
@@ -59,7 +64,7 @@
 open class MediaTttChipControllerReceiver @Inject constructor(
         private val commandQueue: CommandQueue,
         context: Context,
-        @MediaTttReceiverLogger logger: MediaTttLogger,
+        @MediaTttReceiverLogger logger: MediaTttLogger<ChipReceiverInfo>,
         windowManager: WindowManager,
         mainExecutor: DelayableExecutor,
         accessibilityManager: AccessibilityManager,
@@ -70,7 +75,8 @@
         private val uiEventLogger: MediaTttReceiverUiEventLogger,
         private val viewUtil: ViewUtil,
         wakeLockBuilder: WakeLock.Builder,
-) : TemporaryViewDisplayController<ChipReceiverInfo, MediaTttLogger>(
+        systemClock: SystemClock,
+) : TemporaryViewDisplayController<ChipReceiverInfo, MediaTttLogger<ChipReceiverInfo>>(
         context,
         logger,
         windowManager,
@@ -80,6 +86,7 @@
         powerManager,
         R.layout.media_ttt_chip_receiver,
         wakeLockBuilder,
+        systemClock,
 ) {
     @SuppressLint("WrongConstant") // We're allowed to use LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
     override val windowLayoutParams = commonWindowLayoutParams.apply {
@@ -161,11 +168,23 @@
     }
 
     override fun updateView(newInfo: ChipReceiverInfo, currentView: ViewGroup) {
-        val iconInfo = MediaTttUtils.getIconInfoFromPackageName(
+        var iconInfo = MediaTttUtils.getIconInfoFromPackageName(
             context, newInfo.routeInfo.clientPackageName, logger
         )
-        val iconDrawable = newInfo.appIconDrawableOverride ?: iconInfo.drawable
-        val iconContentDescription = newInfo.appNameOverride ?: iconInfo.contentDescription
+
+        if (newInfo.appNameOverride != null) {
+            iconInfo = iconInfo.copy(
+                contentDescription = ContentDescription.Loaded(newInfo.appNameOverride.toString())
+            )
+        }
+
+        if (newInfo.appIconDrawableOverride != null) {
+            iconInfo = iconInfo.copy(
+                icon = MediaTttIcon.Loaded(newInfo.appIconDrawableOverride),
+                isAppIcon = true,
+            )
+        }
+
         val iconPadding =
             if (iconInfo.isAppIcon) {
                 0
@@ -175,8 +194,7 @@
 
         val iconView = currentView.getAppIconView()
         iconView.setPadding(iconPadding, iconPadding, iconPadding, iconPadding)
-        iconView.setImageDrawable(iconDrawable)
-        iconView.contentDescription = iconContentDescription
+        TintedIconViewBinder.bind(iconInfo.toTintedIcon(), iconView)
     }
 
     override fun animateViewIn(view: ViewGroup) {
@@ -276,4 +294,5 @@
     override val windowTitle: String = MediaTttUtils.WINDOW_TITLE_RECEIVER,
     override val wakeReason: String = MediaTttUtils.WAKE_REASON_RECEIVER,
     override val id: String,
+    override val priority: ViewPriority = ViewPriority.NORMAL,
 ) : TemporaryViewInfo()
diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinator.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinator.kt
index e34b0cb..9f44d98 100644
--- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinator.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinator.kt
@@ -30,6 +30,7 @@
 import com.android.systemui.media.taptotransfer.common.MediaTttLogger
 import com.android.systemui.media.taptotransfer.common.MediaTttUtils
 import com.android.systemui.statusbar.CommandQueue
+import com.android.systemui.temporarydisplay.ViewPriority
 import com.android.systemui.temporarydisplay.chipbar.ChipbarCoordinator
 import com.android.systemui.temporarydisplay.chipbar.ChipbarEndItem
 import com.android.systemui.temporarydisplay.chipbar.ChipbarInfo
@@ -46,7 +47,7 @@
     private val chipbarCoordinator: ChipbarCoordinator,
     private val commandQueue: CommandQueue,
     private val context: Context,
-    @MediaTttSenderLogger private val logger: MediaTttLogger,
+    @MediaTttSenderLogger private val logger: MediaTttLogger<ChipbarInfo>,
     private val mediaTttFlags: MediaTttFlags,
     private val uiEventLogger: MediaTttSenderUiEventLogger,
 ) : CoreStartable {
@@ -146,14 +147,16 @@
         routeInfo: MediaRoute2Info,
         undoCallback: IUndoMediaTransferCallback?,
         context: Context,
-        logger: MediaTttLogger,
+        logger: MediaTttLogger<ChipbarInfo>,
     ): ChipbarInfo {
         val packageName = routeInfo.clientPackageName
         val otherDeviceName = routeInfo.name.toString()
 
         return ChipbarInfo(
             // Display the app's icon as the start icon
-            startIcon = MediaTttUtils.getIconFromPackageName(context, packageName, logger),
+            startIcon =
+                MediaTttUtils.getIconInfoFromPackageName(context, packageName, logger)
+                    .toTintedIcon(),
             text = chipStateSender.getChipTextString(context, otherDeviceName),
             endItem =
                 when (chipStateSender.endItem) {
@@ -178,6 +181,7 @@
             wakeReason = MediaTttUtils.WAKE_REASON_SENDER,
             timeoutMs = chipStateSender.timeout,
             id = routeInfo.id,
+            priority = ViewPriority.NORMAL,
         )
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java
index e2f55f0..9791e82 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java
@@ -98,7 +98,7 @@
 
     // Tracks config changes that will actually recreate the nav bar
     private final InterestingConfigChanges mConfigChanges = new InterestingConfigChanges(
-            ActivityInfo.CONFIG_FONT_SCALE | ActivityInfo.CONFIG_SCREEN_LAYOUT
+            ActivityInfo.CONFIG_FONT_SCALE
                     | ActivityInfo.CONFIG_UI_MODE);
 
     @Inject
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/TaskbarDelegate.java b/packages/SystemUI/src/com/android/systemui/navigationbar/TaskbarDelegate.java
index ac7c70b..f60d7ea 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/TaskbarDelegate.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/TaskbarDelegate.java
@@ -55,6 +55,7 @@
 import android.view.WindowInsetsController.Behavior;
 
 import androidx.annotation.NonNull;
+import androidx.annotation.VisibleForTesting;
 
 import com.android.internal.statusbar.LetterboxDetails;
 import com.android.internal.view.AppearanceRegion;
@@ -125,7 +126,7 @@
     private final DisplayManager mDisplayManager;
     private Context mWindowContext;
     private ScreenPinningNotify mScreenPinningNotify;
-    private int mNavigationMode;
+    private int mNavigationMode = -1;
     private final Consumer<Rect> mPipListener;
 
     /**
@@ -217,8 +218,7 @@
         parseCurrentSysuiState();
         mCommandQueue.addCallback(this);
         mOverviewProxyService.addCallback(this);
-        mEdgeBackGestureHandler.onNavigationModeChanged(
-                mNavigationModeController.addListener(this));
+        onNavigationModeChanged(mNavigationModeController.addListener(this));
         mNavBarHelper.registerNavTaskStateUpdater(mNavbarTaskbarStateUpdater);
         mNavBarHelper.init();
         mEdgeBackGestureHandler.onNavBarAttached();
@@ -492,6 +492,11 @@
                 !QuickStepContract.isGesturalMode(mNavigationMode));
     }
 
+    @VisibleForTesting
+    int getNavigationMode() {
+        return mNavigationMode;
+    }
+
     @Override
     public void dump(@NonNull PrintWriter pw, @NonNull String[] args) {
         pw.println("TaskbarDelegate (displayId=" + mDisplayId + "):");
diff --git a/packages/SystemUI/src/com/android/systemui/qs/FgsManagerController.kt b/packages/SystemUI/src/com/android/systemui/qs/FgsManagerController.kt
index 3c10778..930de13 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/FgsManagerController.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/FgsManagerController.kt
@@ -122,10 +122,6 @@
     /** Remove a [OnDialogDismissedListener]. */
     fun removeOnDialogDismissedListener(listener: OnDialogDismissedListener)
 
-    /** Whether we should update the footer visibility. */
-    // TODO(b/242040009): Remove this.
-    fun shouldUpdateFooterVisibility(): Boolean
-
     @VisibleForTesting
     fun visibleButtonsCount(): Int
 
@@ -375,8 +371,6 @@
         }
     }
 
-    override fun shouldUpdateFooterVisibility() = dialog == null
-
     override fun showDialog(expandable: Expandable?) {
         synchronized(lock) {
             if (dialog == null) {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/FooterActionsController.kt b/packages/SystemUI/src/com/android/systemui/qs/FooterActionsController.kt
index a9943e8..b52233f 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/FooterActionsController.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/FooterActionsController.kt
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2021 The Android Open Source Project
+ * 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.
@@ -16,261 +16,17 @@
 
 package com.android.systemui.qs
 
-import android.content.Intent
-import android.content.res.Configuration
-import android.os.Handler
-import android.os.UserManager
-import android.provider.Settings
-import android.provider.Settings.Global.USER_SWITCHER_ENABLED
-import android.view.View
-import android.view.ViewGroup
-import androidx.annotation.VisibleForTesting
-import com.android.internal.jank.InteractionJankMonitor
-import com.android.internal.logging.MetricsLogger
-import com.android.internal.logging.UiEventLogger
-import com.android.internal.logging.nano.MetricsProto
-import com.android.keyguard.KeyguardUpdateMonitor
-import com.android.systemui.R
-import com.android.systemui.animation.ActivityLaunchAnimator
-import com.android.systemui.animation.Expandable
-import com.android.systemui.globalactions.GlobalActionsDialogLite
-import com.android.systemui.plugins.ActivityStarter
-import com.android.systemui.plugins.FalsingManager
-import com.android.systemui.qs.dagger.QSFlagsModule.PM_LITE_ENABLED
-import com.android.systemui.qs.dagger.QSScope
-import com.android.systemui.settings.UserTracker
-import com.android.systemui.statusbar.phone.MultiUserSwitchController
-import com.android.systemui.statusbar.policy.ConfigurationController
-import com.android.systemui.statusbar.policy.DeviceProvisionedController
-import com.android.systemui.statusbar.policy.UserInfoController
-import com.android.systemui.statusbar.policy.UserInfoController.OnUserInfoChangedListener
-import com.android.systemui.util.LargeScreenUtils
-import com.android.systemui.util.ViewController
-import com.android.systemui.util.settings.GlobalSettings
+import com.android.systemui.dagger.SysUISingleton
 import javax.inject.Inject
-import javax.inject.Named
-import javax.inject.Provider
 
-/**
- * Manages [FooterActionsView] behaviour, both when it's placed in QS or QQS (split shade).
- * Main difference between QS and QQS behaviour is condition when buttons should be visible,
- * determined by [buttonsVisibleState]
- */
-@QSScope
-// TODO(b/242040009): Remove this file.
-internal class FooterActionsController @Inject constructor(
-    view: FooterActionsView,
-    multiUserSwitchControllerFactory: MultiUserSwitchController.Factory,
-    private val activityStarter: ActivityStarter,
-    private val userManager: UserManager,
-    private val userTracker: UserTracker,
-    private val userInfoController: UserInfoController,
-    private val deviceProvisionedController: DeviceProvisionedController,
-    private val securityFooterController: QSSecurityFooter,
-    private val fgsManagerFooterController: QSFgsManagerFooter,
-    private val falsingManager: FalsingManager,
-    private val metricsLogger: MetricsLogger,
-    private val globalActionsDialogProvider: Provider<GlobalActionsDialogLite>,
-    private val uiEventLogger: UiEventLogger,
-    @Named(PM_LITE_ENABLED) private val showPMLiteButton: Boolean,
-    private val globalSetting: GlobalSettings,
-    private val handler: Handler,
-    private val configurationController: ConfigurationController,
-) : ViewController<FooterActionsView>(view) {
-
-    private var globalActionsDialog: GlobalActionsDialogLite? = null
-
-    private var lastExpansion = -1f
-    private var listening: Boolean = false
-    private var inSplitShade = false
-
-    private val singleShadeAnimator by lazy {
-        // In single shade, the actions footer should only appear at the end of the expansion,
-        // so that it doesn't overlap with the notifications panel.
-        TouchAnimator.Builder().addFloat(mView, "alpha", 0f, 1f).setStartDelay(0.9f).build()
-    }
-
-    private val splitShadeAnimator by lazy {
-        // The Actions footer view has its own background which is the same color as the qs panel's
-        // background.
-        // We don't want it to fade in at the same time as the rest of the panel, otherwise it is
-        // more opaque than the rest of the panel's background. Only applies to split shade.
-        val alphaAnimator = TouchAnimator.Builder().addFloat(mView, "alpha", 0f, 1f).build()
-        val bgAlphaAnimator =
-            TouchAnimator.Builder()
-                .addFloat(mView, "backgroundAlpha", 0f, 1f)
-                .setStartDelay(0.9f)
-                .build()
-        // In split shade, we want the actions footer to fade in exactly at the same time as the
-        // rest of the shade, as there is no overlap.
-        TouchAnimator.Builder()
-            .addFloat(alphaAnimator, "position", 0f, 1f)
-            .addFloat(bgAlphaAnimator, "position", 0f, 1f)
-            .build()
-    }
-
-    private val animators: TouchAnimator
-        get() = if (inSplitShade) splitShadeAnimator else singleShadeAnimator
-
-    var visible = true
-        set(value) {
-            field = value
-            updateVisibility()
-        }
-
-    private val settingsButtonContainer: View = view.findViewById(R.id.settings_button_container)
-    private val securityFootersContainer: ViewGroup? =
-        view.findViewById(R.id.security_footers_container)
-    private val powerMenuLite: View = view.findViewById(R.id.pm_lite)
-    private val multiUserSwitchController = multiUserSwitchControllerFactory.create(view)
-
-    @VisibleForTesting
-    internal val securityFootersSeparator = View(context).apply { visibility = View.GONE }
-
-    private val onUserInfoChangedListener = OnUserInfoChangedListener { _, picture, _ ->
-        val isGuestUser: Boolean = userManager.isGuestUser(KeyguardUpdateMonitor.getCurrentUser())
-        mView.onUserInfoChanged(picture, isGuestUser)
-    }
-
-    private val multiUserSetting =
-            object : SettingObserver(
-                    globalSetting, handler, USER_SWITCHER_ENABLED, userTracker.userId) {
-                override fun handleValueChanged(value: Int, observedChange: Boolean) {
-                    if (observedChange) {
-                        updateView()
-                    }
-                }
-            }
-
-    private val onClickListener = View.OnClickListener { v ->
-        // Don't do anything if the tap looks suspicious.
-        if (!visible || falsingManager.isFalseTap(FalsingManager.LOW_PENALTY)) {
-            return@OnClickListener
-        }
-        if (v === settingsButtonContainer) {
-            if (!deviceProvisionedController.isCurrentUserSetup) {
-                // If user isn't setup just unlock the device and dump them back at SUW.
-                activityStarter.postQSRunnableDismissingKeyguard {}
-                return@OnClickListener
-            }
-            metricsLogger.action(MetricsProto.MetricsEvent.ACTION_QS_EXPANDED_SETTINGS_LAUNCH)
-            startSettingsActivity()
-        } else if (v === powerMenuLite) {
-            uiEventLogger.log(GlobalActionsDialogLite.GlobalActionsEvent.GA_OPEN_QS)
-            globalActionsDialog?.showOrHideDialog(false, true, Expandable.fromView(powerMenuLite))
-        }
-    }
-
-    private val configurationListener =
-        object : ConfigurationController.ConfigurationListener {
-            override fun onConfigChanged(newConfig: Configuration?) {
-                updateResources()
-            }
-        }
-
-    private fun updateResources() {
-        inSplitShade = LargeScreenUtils.shouldUseSplitNotificationShade(resources)
-    }
-
-    override fun onInit() {
-        multiUserSwitchController.init()
-        securityFooterController.init()
-        fgsManagerFooterController.init()
-    }
-
-    private fun updateVisibility() {
-        val previousVisibility = mView.visibility
-        mView.visibility = if (visible) View.VISIBLE else View.INVISIBLE
-        if (previousVisibility != mView.visibility) updateView()
-    }
-
-    private fun startSettingsActivity() {
-        val animationController = settingsButtonContainer?.let {
-            ActivityLaunchAnimator.Controller.fromView(
-                    it,
-                    InteractionJankMonitor.CUJ_SHADE_APP_LAUNCH_FROM_SETTINGS_BUTTON)
-            }
-        activityStarter.startActivity(Intent(Settings.ACTION_SETTINGS),
-                true /* dismissShade */, animationController)
-    }
-
-    @VisibleForTesting
-    public override fun onViewAttached() {
-        globalActionsDialog = globalActionsDialogProvider.get()
-        if (showPMLiteButton) {
-            powerMenuLite.visibility = View.VISIBLE
-            powerMenuLite.setOnClickListener(onClickListener)
-        } else {
-            powerMenuLite.visibility = View.GONE
-        }
-        settingsButtonContainer.setOnClickListener(onClickListener)
-        multiUserSetting.isListening = true
-
-        val securityFooter = securityFooterController.view
-        securityFootersContainer?.addView(securityFooter)
-        val separatorWidth = resources.getDimensionPixelSize(R.dimen.qs_footer_action_inset)
-        securityFootersContainer?.addView(securityFootersSeparator, separatorWidth, 1)
-
-        val fgsFooter = fgsManagerFooterController.view
-        securityFootersContainer?.addView(fgsFooter)
-
-        val visibilityListener =
-            VisibilityChangedDispatcher.OnVisibilityChangedListener { visibility ->
-                if (securityFooter.visibility == View.VISIBLE &&
-                    fgsFooter.visibility == View.VISIBLE) {
-                    securityFootersSeparator.visibility = View.VISIBLE
-                } else {
-                    securityFootersSeparator.visibility = View.GONE
-                }
-                fgsManagerFooterController
-                    .setCollapsed(securityFooter.visibility == View.VISIBLE)
-            }
-        securityFooterController.setOnVisibilityChangedListener(visibilityListener)
-        fgsManagerFooterController.setOnVisibilityChangedListener(visibilityListener)
-
-        configurationController.addCallback(configurationListener)
-
-        updateResources()
-        updateView()
-    }
-
-    private fun updateView() {
-        mView.updateEverything(multiUserSwitchController.isMultiUserEnabled)
-    }
-
-    override fun onViewDetached() {
-        globalActionsDialog?.destroy()
-        globalActionsDialog = null
-        setListening(false)
-        multiUserSetting.isListening = false
-        configurationController.removeCallback(configurationListener)
-    }
-
-    fun setListening(listening: Boolean) {
-        if (this.listening == listening) {
-            return
-        }
-        this.listening = listening
-        if (this.listening) {
-            userInfoController.addCallback(onUserInfoChangedListener)
-            updateView()
-        } else {
-            userInfoController.removeCallback(onUserInfoChangedListener)
-        }
-
-        fgsManagerFooterController.setListening(listening)
-        securityFooterController.setListening(listening)
-    }
-
-    fun disable(state2: Int) {
-        mView.disable(state2, multiUserSwitchController.isMultiUserEnabled)
-    }
-
-    fun setExpansion(headerExpansionFraction: Float) {
-        animators.setPosition(headerExpansionFraction)
-    }
-
-    fun setKeyguardShowing(showing: Boolean) {
-        setExpansion(lastExpansion)
+/** Controller for the footer actions. This manages the initialization of its dependencies. */
+@SysUISingleton
+class FooterActionsController
+@Inject
+constructor(
+    private val fgsManagerController: FgsManagerController,
+) {
+    fun init() {
+        fgsManagerController.init()
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/qs/FooterActionsView.kt b/packages/SystemUI/src/com/android/systemui/qs/FooterActionsView.kt
deleted file mode 100644
index d602b0b..0000000
--- a/packages/SystemUI/src/com/android/systemui/qs/FooterActionsView.kt
+++ /dev/null
@@ -1,135 +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.systemui.qs
-
-import android.app.StatusBarManager
-import android.content.Context
-import android.graphics.PorterDuff
-import android.graphics.drawable.Drawable
-import android.graphics.drawable.RippleDrawable
-import android.os.UserManager
-import android.util.AttributeSet
-import android.util.Log
-import android.view.MotionEvent
-import android.view.View
-import android.widget.ImageView
-import android.widget.LinearLayout
-import androidx.annotation.Keep
-import com.android.settingslib.Utils
-import com.android.settingslib.drawable.UserIconDrawable
-import com.android.systemui.R
-import com.android.systemui.statusbar.phone.MultiUserSwitch
-
-/**
- * Quick Settings bottom buttons placed in footer (aka utility bar) - always visible in expanded QS,
- * in split shade mode visible also in collapsed state. May contain up to 5 buttons: settings,
- * edit tiles, power off and conditionally: user switch and tuner
- */
-// TODO(b/242040009): Remove this file.
-class FooterActionsView(context: Context?, attrs: AttributeSet?) : LinearLayout(context, attrs) {
-    private lateinit var settingsContainer: View
-    private lateinit var multiUserSwitch: MultiUserSwitch
-    private lateinit var multiUserAvatar: ImageView
-
-    private var qsDisabled = false
-    private var expansionAmount = 0f
-
-    /**
-     * Sets the alpha of the background of this view.
-     *
-     * Used from a [TouchAnimator] in the controller.
-     */
-    var backgroundAlpha: Float = 1f
-        @Keep
-        set(value) {
-            field = value
-            background?.alpha = (value * 255).toInt()
-        }
-        @Keep get
-
-    override fun onFinishInflate() {
-        super.onFinishInflate()
-        settingsContainer = findViewById(R.id.settings_button_container)
-        multiUserSwitch = findViewById(R.id.multi_user_switch)
-        multiUserAvatar = multiUserSwitch.findViewById(R.id.multi_user_avatar)
-
-        // RenderThread is doing more harm than good when touching the header (to expand quick
-        // settings), so disable it for this view
-        if (settingsContainer.background is RippleDrawable) {
-            (settingsContainer.background as RippleDrawable).setForceSoftware(true)
-        }
-        importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_YES
-    }
-
-    fun disable(
-        state2: Int,
-        multiUserEnabled: Boolean
-    ) {
-        val disabled = state2 and StatusBarManager.DISABLE2_QUICK_SETTINGS != 0
-        if (disabled == qsDisabled) return
-        qsDisabled = disabled
-        updateEverything(multiUserEnabled)
-    }
-
-    fun updateEverything(
-        multiUserEnabled: Boolean
-    ) {
-        post {
-            updateVisibilities(multiUserEnabled)
-            updateClickabilities()
-            isClickable = false
-        }
-    }
-
-    private fun updateClickabilities() {
-        multiUserSwitch.isClickable = multiUserSwitch.visibility == VISIBLE
-        settingsContainer.isClickable = settingsContainer.visibility == VISIBLE
-    }
-
-    private fun updateVisibilities(
-        multiUserEnabled: Boolean
-    ) {
-        settingsContainer.visibility = if (qsDisabled) GONE else VISIBLE
-        multiUserSwitch.visibility = if (multiUserEnabled) VISIBLE else GONE
-        val isDemo = UserManager.isDeviceInDemoMode(context)
-        settingsContainer.visibility = if (isDemo) INVISIBLE else VISIBLE
-    }
-
-    fun onUserInfoChanged(picture: Drawable?, isGuestUser: Boolean) {
-        var pictureToSet = picture
-        if (picture != null && isGuestUser && picture !is UserIconDrawable) {
-            pictureToSet = picture.constantState.newDrawable(resources).mutate()
-            pictureToSet.setColorFilter(
-                    Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorForeground),
-                    PorterDuff.Mode.SRC_IN)
-        }
-        multiUserAvatar.setImageDrawable(pictureToSet)
-    }
-
-    override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
-        if (VERBOSE) Log.d(TAG, "FooterActionsView onInterceptTouchEvent ${ev?.string}")
-        return super.onInterceptTouchEvent(ev)
-    }
-
-    override fun onTouchEvent(event: MotionEvent?): Boolean {
-        if (VERBOSE) Log.d(TAG, "FooterActionsView onTouchEvent ${event?.string}")
-        return super.onTouchEvent(event)
-    }
-}
-private const val TAG = "FooterActionsView"
-private val VERBOSE = Log.isLoggable(TAG, Log.VERBOSE)
-private val MotionEvent.string
-    get() = "($id): ($x,$y)"
diff --git a/packages/SystemUI/src/com/android/systemui/qs/NewFooterActionsController.kt b/packages/SystemUI/src/com/android/systemui/qs/NewFooterActionsController.kt
deleted file mode 100644
index 7c67d9f..0000000
--- a/packages/SystemUI/src/com/android/systemui/qs/NewFooterActionsController.kt
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.systemui.qs
-
-import com.android.systemui.dagger.SysUISingleton
-import javax.inject.Inject
-
-/** Controller for the footer actions. This manages the initialization of its dependencies. */
-@SysUISingleton
-class NewFooterActionsController
-@Inject
-// TODO(b/242040009): Rename this to FooterActionsController.
-constructor(
-    private val fgsManagerController: FgsManagerController,
-) {
-    fun init() {
-        fgsManagerController.init()
-    }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java
index f92bbf7..8ceee1a 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java
@@ -741,6 +741,14 @@
         }
     };
 
+    /**
+     * Force all tiles to be redistributed across pages.
+     * Should be called when one of the following changes: rows, columns, number of tiles.
+     */
+    public void forceTilesRedistribution() {
+        mDistributeTiles = true;
+    }
+
     public interface PageListener {
         int INVALID_PAGE = -1;
 
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSContainerImpl.java b/packages/SystemUI/src/com/android/systemui/qs/QSContainerImpl.java
index dc9dcc2..0c242d9 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSContainerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSContainerImpl.java
@@ -215,7 +215,7 @@
                 // Some views are always full width or have dependent padding
                 continue;
             }
-            if (!(view instanceof FooterActionsView)) {
+            if (view.getId() != R.id.qs_footer_actions) {
                 // Only padding for FooterActionsView, no margin. That way, the background goes
                 // all the way to the edge.
                 LayoutParams lp = (LayoutParams) view.getLayoutParams();
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSFgsManagerFooter.java b/packages/SystemUI/src/com/android/systemui/qs/QSFgsManagerFooter.java
deleted file mode 100644
index b1b9dd7..0000000
--- a/packages/SystemUI/src/com/android/systemui/qs/QSFgsManagerFooter.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * 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.systemui.qs;
-
-import static com.android.systemui.qs.dagger.QSFragmentModule.QS_FGS_MANAGER_FOOTER_VIEW;
-import static com.android.systemui.util.PluralMessageFormaterKt.icuMessageFormat;
-
-import android.content.Context;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-
-import androidx.annotation.Nullable;
-
-import com.android.systemui.R;
-import com.android.systemui.animation.Expandable;
-import com.android.systemui.dagger.qualifiers.Background;
-import com.android.systemui.dagger.qualifiers.Main;
-import com.android.systemui.qs.dagger.QSScope;
-
-import java.util.concurrent.Executor;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-/**
- * Footer entry point for the foreground service manager
- */
-// TODO(b/242040009): Remove this file.
-@QSScope
-public class QSFgsManagerFooter implements View.OnClickListener,
-        FgsManagerController.OnDialogDismissedListener,
-        FgsManagerController.OnNumberOfPackagesChangedListener,
-        VisibilityChangedDispatcher {
-
-    private final View mRootView;
-    private final TextView mFooterText;
-    private final Context mContext;
-    private final Executor mMainExecutor;
-    private final Executor mExecutor;
-
-    private final FgsManagerController mFgsManagerController;
-
-    private boolean mIsInitialized = false;
-    private int mNumPackages;
-
-    private final View mTextContainer;
-    private final View mNumberContainer;
-    private final TextView mNumberView;
-    private final ImageView mDotView;
-    private final ImageView mCollapsedDotView;
-
-    @Nullable
-    private VisibilityChangedDispatcher.OnVisibilityChangedListener mVisibilityChangedListener;
-
-    @Inject
-    QSFgsManagerFooter(@Named(QS_FGS_MANAGER_FOOTER_VIEW) View rootView,
-            @Main Executor mainExecutor, @Background Executor executor,
-            FgsManagerController fgsManagerController) {
-        mRootView = rootView;
-        mFooterText = mRootView.findViewById(R.id.footer_text);
-        mTextContainer = mRootView.findViewById(R.id.fgs_text_container);
-        mNumberContainer = mRootView.findViewById(R.id.fgs_number_container);
-        mNumberView = mRootView.findViewById(R.id.fgs_number);
-        mDotView = mRootView.findViewById(R.id.fgs_new);
-        mCollapsedDotView = mRootView.findViewById(R.id.fgs_collapsed_new);
-        mContext = rootView.getContext();
-        mMainExecutor = mainExecutor;
-        mExecutor = executor;
-        mFgsManagerController = fgsManagerController;
-    }
-
-    /**
-     * Whether to show the footer in collapsed mode (just a number) or not (text).
-     * @param collapsed
-     */
-    public void setCollapsed(boolean collapsed) {
-        mTextContainer.setVisibility(collapsed ? View.GONE : View.VISIBLE);
-        mNumberContainer.setVisibility(collapsed ? View.VISIBLE : View.GONE);
-        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mRootView.getLayoutParams();
-        lp.width = collapsed ? ViewGroup.LayoutParams.WRAP_CONTENT : 0;
-        lp.weight = collapsed ? 0f : 1f;
-        mRootView.setLayoutParams(lp);
-    }
-
-    public void init() {
-        if (mIsInitialized) {
-            return;
-        }
-
-        mFgsManagerController.init();
-
-        mRootView.setOnClickListener(this);
-
-        mIsInitialized = true;
-    }
-
-    public void setListening(boolean listening) {
-        if (listening) {
-            mFgsManagerController.addOnDialogDismissedListener(this);
-            mFgsManagerController.addOnNumberOfPackagesChangedListener(this);
-            mNumPackages = mFgsManagerController.getNumRunningPackages();
-            refreshState();
-        } else {
-            mFgsManagerController.removeOnDialogDismissedListener(this);
-            mFgsManagerController.removeOnNumberOfPackagesChangedListener(this);
-        }
-    }
-
-    @Override
-    public void setOnVisibilityChangedListener(
-            @Nullable OnVisibilityChangedListener onVisibilityChangedListener) {
-        mVisibilityChangedListener = onVisibilityChangedListener;
-    }
-
-    @Override
-    public void onClick(View view) {
-        mFgsManagerController.showDialog(Expandable.fromView(view));
-    }
-
-    public void refreshState() {
-        mExecutor.execute(this::handleRefreshState);
-    }
-
-    public View getView() {
-        return mRootView;
-    }
-
-    public void handleRefreshState() {
-        mMainExecutor.execute(() -> {
-            CharSequence text = icuMessageFormat(mContext.getResources(),
-                    R.string.fgs_manager_footer_label, mNumPackages);
-            mFooterText.setText(text);
-            mNumberView.setText(Integer.toString(mNumPackages));
-            mNumberView.setContentDescription(text);
-            if (mFgsManagerController.shouldUpdateFooterVisibility()) {
-                mRootView.setVisibility(mNumPackages > 0
-                        && mFgsManagerController.isAvailable().getValue() ? View.VISIBLE
-                        : View.GONE);
-                int dotVis = mFgsManagerController.getShowFooterDot().getValue()
-                        && mFgsManagerController.getNewChangesSinceDialogWasDismissed()
-                        ? View.VISIBLE : View.GONE;
-                mDotView.setVisibility(dotVis);
-                mCollapsedDotView.setVisibility(dotVis);
-                if (mVisibilityChangedListener != null) {
-                    mVisibilityChangedListener.onVisibilityChanged(mRootView.getVisibility());
-                }
-            }
-        });
-    }
-
-    @Override
-    public void onDialogDismissed() {
-        refreshState();
-    }
-
-    @Override
-    public void onNumberOfPackagesChanged(int numPackages) {
-        mNumPackages = numPackages;
-        refreshState();
-    }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java b/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java
index c0533ba..893574a 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java
@@ -33,6 +33,7 @@
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.ViewTreeObserver;
+import android.widget.LinearLayout;
 
 import androidx.annotation.FloatRange;
 import androidx.annotation.Nullable;
@@ -48,7 +49,6 @@
 import com.android.systemui.animation.ShadeInterpolation;
 import com.android.systemui.dump.DumpManager;
 import com.android.systemui.flags.FeatureFlags;
-import com.android.systemui.flags.Flags;
 import com.android.systemui.media.controls.ui.MediaHost;
 import com.android.systemui.plugins.FalsingManager;
 import com.android.systemui.plugins.qs.QS;
@@ -114,7 +114,7 @@
     private final QSFragmentDisableFlagsLogger mQsFragmentDisableFlagsLogger;
     private final QSTileHost mHost;
     private final FeatureFlags mFeatureFlags;
-    private final NewFooterActionsController mNewFooterActionsController;
+    private final FooterActionsController mFooterActionsController;
     private final FooterActionsViewModel.Factory mFooterActionsViewModelFactory;
     private final ListeningAndVisibilityLifecycleOwner mListeningAndVisibilityLifecycleOwner;
     private boolean mShowCollapsedOnKeyguard;
@@ -132,9 +132,6 @@
     private QSPanelController mQSPanelController;
     private QuickQSPanelController mQuickQSPanelController;
     private QSCustomizerController mQSCustomizerController;
-    @Nullable
-    private FooterActionsController mQSFooterActionController;
-    @Nullable
     private FooterActionsViewModel mQSFooterActionsViewModel;
     @Nullable
     private ScrollListener mScrollListener;
@@ -185,7 +182,7 @@
             QSFragmentComponent.Factory qsComponentFactory,
             QSFragmentDisableFlagsLogger qsFragmentDisableFlagsLogger,
             FalsingManager falsingManager, DumpManager dumpManager, FeatureFlags featureFlags,
-            NewFooterActionsController newFooterActionsController,
+            FooterActionsController footerActionsController,
             FooterActionsViewModel.Factory footerActionsViewModelFactory) {
         mRemoteInputQuickSettingsDisabler = remoteInputQsDisabler;
         mQsMediaHost = qsMediaHost;
@@ -199,7 +196,7 @@
         mStatusBarStateController = statusBarStateController;
         mDumpManager = dumpManager;
         mFeatureFlags = featureFlags;
-        mNewFooterActionsController = newFooterActionsController;
+        mFooterActionsController = footerActionsController;
         mFooterActionsViewModelFactory = footerActionsViewModelFactory;
         mListeningAndVisibilityLifecycleOwner = new ListeningAndVisibilityLifecycleOwner();
     }
@@ -226,18 +223,12 @@
         mQSPanelController.init();
         mQuickQSPanelController.init();
 
-        if (mFeatureFlags.isEnabled(Flags.NEW_FOOTER_ACTIONS)) {
-            mQSFooterActionsViewModel = mFooterActionsViewModelFactory.create(/* lifecycleOwner */
-                    this);
-            FooterActionsView footerActionsView = view.findViewById(R.id.qs_footer_actions);
-            FooterActionsViewBinder.bind(footerActionsView, mQSFooterActionsViewModel,
-                    mListeningAndVisibilityLifecycleOwner);
-
-            mNewFooterActionsController.init();
-        } else {
-            mQSFooterActionController = qsFragmentComponent.getQSFooterActionController();
-            mQSFooterActionController.init();
-        }
+        mQSFooterActionsViewModel = mFooterActionsViewModelFactory.create(/* lifecycleOwner */
+                this);
+        LinearLayout footerActionsView = view.findViewById(R.id.qs_footer_actions);
+        FooterActionsViewBinder.bind(footerActionsView, mQSFooterActionsViewModel,
+                mListeningAndVisibilityLifecycleOwner);
+        mFooterActionsController.init();
 
         mQSPanelScrollView = view.findViewById(R.id.expanded_qs_scroll_view);
         mQSPanelScrollView.addOnLayoutChangeListener(
@@ -436,9 +427,6 @@
         mContainer.disable(state1, state2, animate);
         mHeader.disable(state1, state2, animate);
         mFooter.disable(state1, state2, animate);
-        if (mQSFooterActionController != null) {
-            mQSFooterActionController.disable(state2);
-        }
         updateQsState();
     }
 
@@ -457,11 +445,7 @@
         boolean footerVisible = qsPanelVisible && (mQsExpanded || !keyguardShowing
                 || mHeaderAnimating || mShowCollapsedOnKeyguard);
         mFooter.setVisibility(footerVisible ? View.VISIBLE : View.INVISIBLE);
-        if (mQSFooterActionController != null) {
-            mQSFooterActionController.setVisible(footerVisible);
-        } else {
-            mQSFooterActionsViewModel.onVisibilityChangeRequested(footerVisible);
-        }
+        mQSFooterActionsViewModel.onVisibilityChangeRequested(footerVisible);
         mFooter.setExpanded((keyguardShowing && !mHeaderAnimating && !mShowCollapsedOnKeyguard)
                 || (mQsExpanded && !mStackScrollerOverscrolling));
         mQSPanelController.setVisibility(qsPanelVisible ? View.VISIBLE : View.INVISIBLE);
@@ -534,9 +518,6 @@
         }
 
         mFooter.setKeyguardShowing(keyguardShowing);
-        if (mQSFooterActionController != null) {
-            mQSFooterActionController.setKeyguardShowing(keyguardShowing);
-        }
         updateQsState();
     }
 
@@ -552,9 +533,6 @@
         if (DEBUG) Log.d(TAG, "setListening " + listening);
         mListening = listening;
         mQSContainerImplController.setListening(listening && mQsVisible);
-        if (mQSFooterActionController != null) {
-            mQSFooterActionController.setListening(listening && mQsVisible);
-        }
         mListeningAndVisibilityLifecycleOwner.updateState();
         updateQsPanelControllerListening();
     }
@@ -665,12 +643,8 @@
         mFooter.setExpansion(onKeyguardAndExpanded ? 1 : expansion);
         float footerActionsExpansion =
                 onKeyguardAndExpanded ? 1 : mInSplitShade ? alphaProgress : expansion;
-        if (mQSFooterActionController != null) {
-            mQSFooterActionController.setExpansion(footerActionsExpansion);
-        } else {
-            mQSFooterActionsViewModel.onQuickSettingsExpansionChanged(footerActionsExpansion,
-                    mInSplitShade);
-        }
+        mQSFooterActionsViewModel.onQuickSettingsExpansionChanged(footerActionsExpansion,
+                mInSplitShade);
         mQSPanelController.setRevealExpansion(expansion);
         mQSPanelController.getTileLayout().setExpansion(expansion, proposedTranslation);
         mQuickQSPanelController.getTileLayout().setExpansion(expansion, proposedTranslation);
@@ -835,11 +809,7 @@
         boolean customizing = isCustomizing();
         mQSPanelScrollView.setVisibility(!customizing ? View.VISIBLE : View.INVISIBLE);
         mFooter.setVisibility(!customizing ? View.VISIBLE : View.INVISIBLE);
-        if (mQSFooterActionController != null) {
-            mQSFooterActionController.setVisible(!customizing);
-        } else {
-            mQSFooterActionsViewModel.onVisibilityChangeRequested(!customizing);
-        }
+        mQSFooterActionsViewModel.onVisibilityChangeRequested(!customizing);
         mHeader.setVisibility(!customizing ? View.VISIBLE : View.INVISIBLE);
         // Let the panel know the position changed and it needs to update where notifications
         // and whatnot are.
@@ -927,6 +897,11 @@
         updateShowCollapsedOnKeyguard();
     }
 
+    @VisibleForTesting
+    public ListeningAndVisibilityLifecycleOwner getListeningAndVisibilityLifecycleOwner() {
+        return mListeningAndVisibilityLifecycleOwner;
+    }
+
     @Override
     public void dump(PrintWriter pw, String[] args) {
         IndentingPrintWriter indentingPw = new IndentingPrintWriter(pw, /* singleIndent= */ "  ");
@@ -994,7 +969,8 @@
      *  - STARTED when mListening == true && mQsVisible == false.
      *  - RESUMED when mListening == true && mQsVisible == true.
      */
-    private class ListeningAndVisibilityLifecycleOwner implements LifecycleOwner {
+    @VisibleForTesting
+    class ListeningAndVisibilityLifecycleOwner implements LifecycleOwner {
         private final LifecycleRegistry mLifecycleRegistry = new LifecycleRegistry(this);
         private boolean mDestroyed = false;
 
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java
index 1827eaf..b2ca6b7 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java
@@ -148,6 +148,11 @@
         }
     }
 
+    @Override
+    protected void onSplitShadeChanged() {
+        ((PagedTileLayout) mView.getOrCreateTileLayout()).forceTilesRedistribution();
+    }
+
     /** */
     public void setVisibility(int visibility) {
         mView.setVisibility(visibility);
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java
index dd88c83..60d2c17 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java
@@ -96,17 +96,23 @@
                         /* newOrientation= */ newConfig.orientation,
                         /* containerName= */ mView.getDumpableTag());
 
+                    boolean previousSplitShadeState = mShouldUseSplitNotificationShade;
                     mShouldUseSplitNotificationShade =
                         LargeScreenUtils.shouldUseSplitNotificationShade(getResources());
                     mLastOrientation = newConfig.orientation;
 
                     switchTileLayoutIfNeeded();
                     onConfigurationChanged();
+                    if (previousSplitShadeState != mShouldUseSplitNotificationShade) {
+                        onSplitShadeChanged();
+                    }
                 }
             };
 
     protected void onConfigurationChanged() { }
 
+    protected void onSplitShadeChanged() { }
+
     private final Function1<Boolean, Unit> mMediaHostVisibilityListener = (visible) -> {
         if (mMediaVisibilityChangedListener != null) {
             mMediaVisibilityChangedListener.accept(visible);
@@ -264,14 +270,6 @@
             }
         }
     }
-    protected QSTile getTile(String subPanel) {
-        for (int i = 0; i < mRecords.size(); i++) {
-            if (subPanel.equals(mRecords.get(i).tile.getTileSpec())) {
-                return mRecords.get(i).tile;
-            }
-        }
-        return mHost.createTile(subPanel);
-    }
 
     boolean areThereTiles() {
         return !mRecords.isEmpty();
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java b/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java
deleted file mode 100644
index 6c1e956..0000000
--- a/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Copyright (C) 2014 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.systemui.qs;
-
-import static com.android.systemui.qs.dagger.QSFragmentModule.QS_SECURITY_FOOTER_VIEW;
-
-import android.app.admin.DevicePolicyEventLogger;
-import android.app.admin.DevicePolicyManager;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.res.Resources;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Message;
-import android.os.UserHandle;
-import android.util.Log;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.ImageView;
-import android.widget.TextView;
-
-import androidx.annotation.Nullable;
-
-import com.android.internal.util.FrameworkStatsLog;
-import com.android.systemui.FontSizeUtils;
-import com.android.systemui.R;
-import com.android.systemui.animation.Expandable;
-import com.android.systemui.broadcast.BroadcastDispatcher;
-import com.android.systemui.common.shared.model.Icon;
-import com.android.systemui.dagger.qualifiers.Background;
-import com.android.systemui.dagger.qualifiers.Main;
-import com.android.systemui.qs.dagger.QSScope;
-import com.android.systemui.qs.footer.domain.model.SecurityButtonConfig;
-import com.android.systemui.security.data.model.SecurityModel;
-import com.android.systemui.statusbar.policy.SecurityController;
-import com.android.systemui.util.ViewController;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-/** ViewController for the footer actions. */
-// TODO(b/242040009): Remove this class.
-@QSScope
-public class QSSecurityFooter extends ViewController<View>
-        implements OnClickListener, VisibilityChangedDispatcher {
-    protected static final String TAG = "QSSecurityFooter";
-
-    private final TextView mFooterText;
-    private final ImageView mPrimaryFooterIcon;
-    private Context mContext;
-    private final Callback mCallback = new Callback();
-    private final SecurityController mSecurityController;
-    private final Handler mMainHandler;
-    private final BroadcastDispatcher mBroadcastDispatcher;
-    private final QSSecurityFooterUtils mQSSecurityFooterUtils;
-
-    protected H mHandler;
-
-    private boolean mIsVisible;
-    private boolean mIsClickable;
-    @Nullable
-    private CharSequence mFooterTextContent = null;
-    private Icon mFooterIcon;
-
-    @Nullable
-    private VisibilityChangedDispatcher.OnVisibilityChangedListener mVisibilityChangedListener;
-
-    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            if (intent.getAction().equals(
-                    DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG)) {
-                showDeviceMonitoringDialog();
-            }
-        }
-    };
-
-    @Inject
-    QSSecurityFooter(@Named(QS_SECURITY_FOOTER_VIEW) View rootView,
-            @Main Handler mainHandler, SecurityController securityController,
-            @Background Looper bgLooper, BroadcastDispatcher broadcastDispatcher,
-            QSSecurityFooterUtils qSSecurityFooterUtils) {
-        super(rootView);
-        mFooterText = mView.findViewById(R.id.footer_text);
-        mPrimaryFooterIcon = mView.findViewById(R.id.primary_footer_icon);
-        mFooterIcon = new Icon.Resource(
-                R.drawable.ic_info_outline, /* contentDescription= */ null);
-        mContext = rootView.getContext();
-        mSecurityController = securityController;
-        mMainHandler = mainHandler;
-        mHandler = new H(bgLooper);
-        mBroadcastDispatcher = broadcastDispatcher;
-        mQSSecurityFooterUtils = qSSecurityFooterUtils;
-    }
-
-    @Override
-    protected void onViewAttached() {
-        // Use background handler, as it's the same thread that handleClick is called on.
-        mBroadcastDispatcher.registerReceiverWithHandler(mReceiver,
-                new IntentFilter(DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG),
-                mHandler, UserHandle.ALL);
-        mView.setOnClickListener(this);
-    }
-
-    @Override
-    protected void onViewDetached() {
-        mBroadcastDispatcher.unregisterReceiver(mReceiver);
-        mView.setOnClickListener(null);
-    }
-
-    public void setListening(boolean listening) {
-        if (listening) {
-            mSecurityController.addCallback(mCallback);
-            refreshState();
-        } else {
-            mSecurityController.removeCallback(mCallback);
-        }
-    }
-
-    @Override
-    public void setOnVisibilityChangedListener(
-            @Nullable OnVisibilityChangedListener onVisibilityChangedListener) {
-        mVisibilityChangedListener = onVisibilityChangedListener;
-    }
-
-    public void onConfigurationChanged() {
-        FontSizeUtils.updateFontSize(mFooterText, R.dimen.qs_tile_text_size);
-        Resources r = mContext.getResources();
-
-        int padding = r.getDimensionPixelSize(R.dimen.qs_footer_padding);
-        mView.setPaddingRelative(padding, 0, padding, 0);
-        mView.setBackground(mContext.getDrawable(R.drawable.qs_security_footer_background));
-    }
-
-    public View getView() {
-        return mView;
-    }
-
-    public boolean hasFooter() {
-        return mView.getVisibility() != View.GONE;
-    }
-
-    @Override
-    public void onClick(View v) {
-        if (!hasFooter()) return;
-        mHandler.sendEmptyMessage(H.CLICK);
-    }
-
-    private void handleClick() {
-        showDeviceMonitoringDialog();
-        DevicePolicyEventLogger
-                .createEvent(FrameworkStatsLog.DEVICE_POLICY_EVENT__EVENT_ID__DO_USER_INFO_CLICKED)
-                .write();
-    }
-
-    // TODO(b/242040009): Remove this.
-    public void showDeviceMonitoringDialog() {
-        mQSSecurityFooterUtils.showDeviceMonitoringDialog(mContext, Expandable.fromView(mView));
-    }
-
-    public void refreshState() {
-        mHandler.sendEmptyMessage(H.REFRESH_STATE);
-    }
-
-    private void handleRefreshState() {
-        SecurityModel securityModel = SecurityModel.create(mSecurityController);
-        SecurityButtonConfig buttonConfig = mQSSecurityFooterUtils.getButtonConfig(securityModel);
-
-        if (buttonConfig == null) {
-            mIsVisible = false;
-        } else {
-            mIsVisible = true;
-            mIsClickable = buttonConfig.isClickable();
-            mFooterTextContent = buttonConfig.getText();
-            mFooterIcon = buttonConfig.getIcon();
-        }
-
-        // Update the UI.
-        mMainHandler.post(mUpdatePrimaryIcon);
-        mMainHandler.post(mUpdateDisplayState);
-    }
-
-    private final Runnable mUpdatePrimaryIcon = new Runnable() {
-        @Override
-        public void run() {
-            if (mFooterIcon instanceof Icon.Loaded) {
-                mPrimaryFooterIcon.setImageDrawable(((Icon.Loaded) mFooterIcon).getDrawable());
-            } else if (mFooterIcon instanceof Icon.Resource) {
-                mPrimaryFooterIcon.setImageResource(((Icon.Resource) mFooterIcon).getRes());
-            }
-        }
-    };
-
-    private final Runnable mUpdateDisplayState = new Runnable() {
-        @Override
-        public void run() {
-            if (mFooterTextContent != null) {
-                mFooterText.setText(mFooterTextContent);
-            }
-            mView.setVisibility(mIsVisible ? View.VISIBLE : View.GONE);
-            if (mVisibilityChangedListener != null) {
-                mVisibilityChangedListener.onVisibilityChanged(mView.getVisibility());
-            }
-
-            if (mIsVisible && mIsClickable) {
-                mView.setClickable(true);
-                mView.findViewById(R.id.footer_icon).setVisibility(View.VISIBLE);
-            } else {
-                mView.setClickable(false);
-                mView.findViewById(R.id.footer_icon).setVisibility(View.GONE);
-            }
-        }
-    };
-
-    private class Callback implements SecurityController.SecurityControllerCallback {
-        @Override
-        public void onStateChanged() {
-            refreshState();
-        }
-    }
-
-    private class H extends Handler {
-        private static final int CLICK = 0;
-        private static final int REFRESH_STATE = 1;
-
-        private H(Looper looper) {
-            super(looper);
-        }
-
-        @Override
-        public void handleMessage(Message msg) {
-            String name = null;
-            try {
-                if (msg.what == REFRESH_STATE) {
-                    name = "handleRefreshState";
-                    handleRefreshState();
-                } else if (msg.what == CLICK) {
-                    name = "handleClick";
-                    handleClick();
-                }
-            } catch (Throwable t) {
-                final String error = "Error in " + name;
-                Log.w(TAG, error, t);
-            }
-        }
-    }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooterUtils.java b/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooterUtils.java
index 5dbf0f8..0bce1f7 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooterUtils.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooterUtils.java
@@ -57,6 +57,7 @@
 import android.os.Handler;
 import android.os.Looper;
 import android.os.UserManager;
+import android.provider.DeviceConfig;
 import android.provider.Settings;
 import android.text.SpannableStringBuilder;
 import android.text.method.LinkMovementMethod;
@@ -770,13 +771,6 @@
         }
     }
 
-    private boolean isFinancedDevice() {
-        return mSecurityController.isDeviceManaged()
-                && mSecurityController.getDeviceOwnerType(
-                mSecurityController.getDeviceOwnerComponentOnAnyUser())
-                == DEVICE_OWNER_TYPE_FINANCED;
-    }
-
     protected class VpnSpan extends ClickableSpan {
         @Override
         public void onClick(View widget) {
@@ -797,4 +791,18 @@
             return 314159257; // prime
         }
     }
+
+    // TODO(b/259908270): remove and inline direct call to mSecurityController.isFinancedDevice()
+    private boolean isFinancedDevice() {
+        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER,
+                DevicePolicyManager.ADD_ISFINANCED_DEVICE_FLAG,
+                DevicePolicyManager.ADD_ISFINANCED_FEVICE_DEFAULT)) {
+            return mSecurityController.isFinancedDevice();
+        } else {
+            return mSecurityController.isDeviceManaged()
+                    && mSecurityController.getDeviceOwnerType(
+                    mSecurityController.getDeviceOwnerComponentOnAnyUser())
+                    == DEVICE_OWNER_TYPE_FINANCED;
+        }
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/qs/dagger/QSFragmentModule.java b/packages/SystemUI/src/com/android/systemui/qs/dagger/QSFragmentModule.java
index aa505fb..01eb636 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/dagger/QSFragmentModule.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/dagger/QSFragmentModule.java
@@ -28,7 +28,6 @@
 import com.android.systemui.dagger.qualifiers.RootView;
 import com.android.systemui.plugins.qs.QS;
 import com.android.systemui.privacy.OngoingPrivacyChip;
-import com.android.systemui.qs.FooterActionsView;
 import com.android.systemui.qs.QSContainerImpl;
 import com.android.systemui.qs.QSFooter;
 import com.android.systemui.qs.QSFooterView;
@@ -51,8 +50,6 @@
  */
 @Module
 public interface QSFragmentModule {
-    String QS_FGS_MANAGER_FOOTER_VIEW = "qs_fgs_manager_footer";
-    String QS_SECURITY_FOOTER_VIEW = "qs_security_footer";
     String QS_USING_MEDIA_PLAYER = "qs_using_media_player";
     String QS_USING_COLLAPSED_LANDSCAPE_MEDIA = "qs_using_collapsed_landscape_media";
 
@@ -119,16 +116,6 @@
         return view.findViewById(R.id.qs_footer);
     }
 
-    /**
-     * Provides a {@link FooterActionsView}.
-     *
-     * This will replace a ViewStub either in {@link QSFooterView} or in {@link QSContainerImpl}.
-     */
-    @Provides
-    static FooterActionsView providesQSFooterActionsView(@RootView View view) {
-        return view.findViewById(R.id.qs_footer_actions);
-    }
-
     /** */
     @Provides
     @QSScope
@@ -146,18 +133,6 @@
 
     /** */
     @Provides
-    @QSScope
-    @Named(QS_SECURITY_FOOTER_VIEW)
-    static View providesQSSecurityFooterView(
-            @QSThemedContext LayoutInflater layoutInflater,
-            FooterActionsView footerActionsView
-    ) {
-        return layoutInflater.inflate(R.layout.quick_settings_security_footer, footerActionsView,
-                false);
-    }
-
-    /** */
-    @Provides
     @Named(QS_USING_MEDIA_PLAYER)
     static boolean providesQSUsingMediaPlayer(Context context) {
         return useQsMediaPlayer(context);
@@ -183,15 +158,4 @@
     static StatusIconContainer providesStatusIconContainer(QuickStatusBarHeader qsHeader) {
         return qsHeader.findViewById(R.id.statusIcons);
     }
-
-    /** */
-    @Provides
-    @QSScope
-    @Named(QS_FGS_MANAGER_FOOTER_VIEW)
-    static View providesQSFgsManagerFooterView(
-            @QSThemedContext LayoutInflater layoutInflater,
-            FooterActionsView footerActionsView
-    ) {
-        return layoutInflater.inflate(R.layout.fgs_footer, footerActionsView, false);
-    }
 }
\ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/qs/footer/ui/binder/FooterActionsViewBinder.kt b/packages/SystemUI/src/com/android/systemui/qs/footer/ui/binder/FooterActionsViewBinder.kt
index 3e39c8e..6db3c99 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/footer/ui/binder/FooterActionsViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/footer/ui/binder/FooterActionsViewBinder.kt
@@ -35,35 +35,31 @@
 import com.android.systemui.common.ui.binder.IconViewBinder
 import com.android.systemui.lifecycle.repeatWhenAttached
 import com.android.systemui.people.ui.view.PeopleViewBinder.bind
-import com.android.systemui.qs.FooterActionsView
 import com.android.systemui.qs.footer.ui.viewmodel.FooterActionsButtonViewModel
 import com.android.systemui.qs.footer.ui.viewmodel.FooterActionsForegroundServicesButtonViewModel
 import com.android.systemui.qs.footer.ui.viewmodel.FooterActionsSecurityButtonViewModel
 import com.android.systemui.qs.footer.ui.viewmodel.FooterActionsViewModel
+import kotlin.math.roundToInt
 import kotlinx.coroutines.flow.collect
 import kotlinx.coroutines.launch
 
 /** A ViewBinder for [FooterActionsViewBinder]. */
 object FooterActionsViewBinder {
-    /**
-     * Create a [FooterActionsView] that can later be [bound][bind] to a [FooterActionsViewModel].
-     */
+    /** Create a view that can later be [bound][bind] to a [FooterActionsViewModel]. */
     @JvmStatic
-    fun create(context: Context): FooterActionsView {
+    fun create(context: Context): LinearLayout {
         return LayoutInflater.from(context).inflate(R.layout.footer_actions, /* root= */ null)
-            as FooterActionsView
+            as LinearLayout
     }
 
     /** Bind [view] to [viewModel]. */
     @JvmStatic
     fun bind(
-        view: FooterActionsView,
+        view: LinearLayout,
         viewModel: FooterActionsViewModel,
         qsVisibilityLifecycleOwner: LifecycleOwner,
     ) {
-        // Remove all children of the FooterActionsView that are used by the old implementation.
-        // TODO(b/242040009): Clean up the XML once the old implementation is removed.
-        view.removeAllViews()
+        view.importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_YES
 
         // Add the views used by this new implementation.
         val context = view.context
@@ -117,7 +113,11 @@
                 }
 
                 launch { viewModel.alpha.collect { view.alpha = it } }
-                launch { viewModel.backgroundAlpha.collect { view.backgroundAlpha = it } }
+                launch {
+                    viewModel.backgroundAlpha.collect {
+                        view.background?.alpha = (it * 255).roundToInt()
+                    }
+                }
             }
 
             // Listen for model changes only when QS are visible.
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/InternetTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/InternetTile.java
index 9542a02..28dd986 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/InternetTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/InternetTile.java
@@ -333,7 +333,14 @@
             mCellularInfo.mAirplaneModeEnabled = icon.visible;
             mWifiInfo.mAirplaneModeEnabled = icon.visible;
             if (!mSignalCallback.mEthernetInfo.mConnected) {
-                if (mWifiInfo.mEnabled && (mWifiInfo.mWifiSignalIconId > 0)
+                // Always use mWifiInfo to refresh the Internet Tile if airplane mode is enabled,
+                // because Internet Tile will show different information depending on whether WiFi
+                // is enabled or not.
+                if (mWifiInfo.mAirplaneModeEnabled) {
+                    refreshState(mWifiInfo);
+                // If airplane mode is disabled, we will use mWifiInfo to refresh the Internet Tile
+                // if WiFi is currently connected to avoid any icon flickering.
+                } else if (mWifiInfo.mEnabled && (mWifiInfo.mWifiSignalIconId > 0)
                         && (mWifiInfo.mSsid != null)) {
                     refreshState(mWifiInfo);
                 } else {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialog.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialog.java
index 9743c3e..206a620 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialog.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialog.java
@@ -358,6 +358,9 @@
                     if (!isChecked && shouldShowMobileDialog()) {
                         showTurnOffMobileDialog();
                     } else if (!shouldShowMobileDialog()) {
+                        if (mInternetDialogController.isMobileDataEnabled() == isChecked) {
+                            return;
+                        }
                         mInternetDialogController.setMobileDataEnabled(mContext, mDefaultDataSubId,
                                 isChecked, false);
                     }
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java
index fae938d..9c7718d 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java
@@ -881,6 +881,13 @@
     }
 
     void addQuickShareChip(Notification.Action quickShareAction) {
+        if (mQuickShareChip != null) {
+            mSmartChips.remove(mQuickShareChip);
+            mActionsView.removeView(mQuickShareChip);
+        }
+        if (mPendingInteraction == PendingInteraction.QUICK_SHARE) {
+            mPendingInteraction = null;
+        }
         if (mPendingInteraction == null) {
             LayoutInflater inflater = LayoutInflater.from(mContext);
             mQuickShareChip = (OverlayActionChip) inflater.inflate(
diff --git a/packages/SystemUI/src/com/android/systemui/security/data/model/SecurityModel.kt b/packages/SystemUI/src/com/android/systemui/security/data/model/SecurityModel.kt
index 50af260..1cf5a8f 100644
--- a/packages/SystemUI/src/com/android/systemui/security/data/model/SecurityModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/security/data/model/SecurityModel.kt
@@ -17,6 +17,7 @@
 package com.android.systemui.security.data.model
 
 import android.graphics.drawable.Drawable
+import androidx.annotation.VisibleForTesting
 import com.android.systemui.dagger.qualifiers.Background
 import com.android.systemui.statusbar.policy.SecurityController
 import kotlinx.coroutines.CoroutineDispatcher
@@ -55,8 +56,8 @@
          * Important: This method should be called from a background thread as this will do a lot of
          * binder calls.
          */
-        // TODO(b/242040009): Remove this.
         @JvmStatic
+        @VisibleForTesting
         fun create(securityController: SecurityController): SecurityModel {
             val deviceAdminInfo =
                 if (securityController.isParentalControlsEnabled) {
diff --git a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessController.java b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessController.java
index 5880003..6bd9158 100644
--- a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessController.java
+++ b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessController.java
@@ -67,11 +67,6 @@
 
     private static final Uri BRIGHTNESS_MODE_URI =
             Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS_MODE);
-    private static final Uri BRIGHTNESS_FOR_VR_FLOAT_URI =
-            Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS_FOR_VR_FLOAT);
-
-    private final float mMinimumBacklightForVr;
-    private final float mMaximumBacklightForVr;
 
     private final int mDisplayId;
     private final Context mContext;
@@ -126,8 +121,6 @@
             if (BRIGHTNESS_MODE_URI.equals(uri)) {
                 mBackgroundHandler.post(mUpdateModeRunnable);
                 mBackgroundHandler.post(mUpdateSliderRunnable);
-            } else if (BRIGHTNESS_FOR_VR_FLOAT_URI.equals(uri)) {
-                mBackgroundHandler.post(mUpdateSliderRunnable);
             } else {
                 mBackgroundHandler.post(mUpdateModeRunnable);
                 mBackgroundHandler.post(mUpdateSliderRunnable);
@@ -140,9 +133,6 @@
             cr.registerContentObserver(
                     BRIGHTNESS_MODE_URI,
                     false, this, UserHandle.USER_ALL);
-            cr.registerContentObserver(
-                    BRIGHTNESS_FOR_VR_FLOAT_URI,
-                    false, this, UserHandle.USER_ALL);
             mDisplayManager.registerDisplayListener(mDisplayListener, mHandler,
                     DisplayManager.EVENT_FLAG_DISPLAY_BRIGHTNESS);
         }
@@ -304,10 +294,6 @@
 
         mDisplayId = mContext.getDisplayId();
         PowerManager pm = context.getSystemService(PowerManager.class);
-        mMinimumBacklightForVr = pm.getBrightnessConstraint(
-                PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM_VR);
-        mMaximumBacklightForVr = pm.getBrightnessConstraint(
-                PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MAXIMUM_VR);
 
         mDisplayManager = context.getSystemService(DisplayManager.class);
         mVrManager = IVrManager.Stub.asInterface(ServiceManager.getService(
@@ -336,17 +322,12 @@
         final float maxBacklight;
         final int metric;
 
-        if (mIsVrModeEnabled) {
-            metric = MetricsEvent.ACTION_BRIGHTNESS_FOR_VR;
-            minBacklight = mMinimumBacklightForVr;
-            maxBacklight = mMaximumBacklightForVr;
-        } else {
-            metric = mAutomatic
-                    ? MetricsEvent.ACTION_BRIGHTNESS_AUTO
-                    : MetricsEvent.ACTION_BRIGHTNESS;
-            minBacklight = mBrightnessMin;
-            maxBacklight = mBrightnessMax;
-        }
+
+        metric = mAutomatic
+                ? MetricsEvent.ACTION_BRIGHTNESS_AUTO
+                : MetricsEvent.ACTION_BRIGHTNESS;
+        minBacklight = mBrightnessMin;
+        maxBacklight = mBrightnessMax;
         final float valFloat = MathUtils.min(
                 convertGammaToLinearFloat(value, minBacklight, maxBacklight),
                 maxBacklight);
@@ -398,15 +379,8 @@
     }
 
     private void updateSlider(float brightnessValue, boolean inVrMode) {
-        final float min;
-        final float max;
-        if (inVrMode) {
-            min = mMinimumBacklightForVr;
-            max = mMaximumBacklightForVr;
-        } else {
-            min = mBrightnessMin;
-            max = mBrightnessMax;
-        }
+        final float min = mBrightnessMin;
+        final float max = mBrightnessMax;
 
         // Ensure the slider is in a fixed position first, then check if we should animate.
         if (mSliderAnimator != null && mSliderAnimator.isStarted()) {
diff --git a/packages/SystemUI/src/com/android/systemui/shade/LargeScreenShadeHeaderController.kt b/packages/SystemUI/src/com/android/systemui/shade/LargeScreenShadeHeaderController.kt
index b511b54..7fc0a5f 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/LargeScreenShadeHeaderController.kt
+++ b/packages/SystemUI/src/com/android/systemui/shade/LargeScreenShadeHeaderController.kt
@@ -101,6 +101,8 @@
         @VisibleForTesting
         internal val HEADER_TRANSITION_ID = R.id.header_transition
         @VisibleForTesting
+        internal val LARGE_SCREEN_HEADER_TRANSITION_ID = R.id.large_screen_header_transition
+        @VisibleForTesting
         internal val QQS_HEADER_CONSTRAINT = R.id.qqs_header_constraint
         @VisibleForTesting
         internal val QS_HEADER_CONSTRAINT = R.id.qs_header_constraint
@@ -429,8 +431,11 @@
         }
         header as MotionLayout
         if (largeScreenActive) {
-            header.getConstraintSet(LARGE_SCREEN_HEADER_CONSTRAINT).applyTo(header)
+            logInstantEvent("Large screen constraints set")
+            header.setTransition(HEADER_TRANSITION_ID)
+            header.transitionToStart()
         } else {
+            logInstantEvent("Small screen constraints set")
             header.setTransition(HEADER_TRANSITION_ID)
             header.transitionToStart()
             updatePosition()
@@ -440,15 +445,19 @@
 
     private fun updatePosition() {
         if (header is MotionLayout && !largeScreenActive && visible) {
-            Trace.instantForTrack(
-                TRACE_TAG_APP,
-                "LargeScreenHeaderController - updatePosition",
-                "position: $qsExpandedFraction"
-            )
+            logInstantEvent("updatePosition: $qsExpandedFraction")
             header.progress = qsExpandedFraction
         }
     }
 
+    private fun logInstantEvent(message: String) {
+        Trace.instantForTrack(
+                TRACE_TAG_APP,
+                "LargeScreenHeaderController",
+                message
+        )
+    }
+
     private fun updateListeners() {
         qsCarrierGroupController.setListening(visible)
         if (visible) {
diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
index 507dec6..5c2c1b6 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
@@ -40,6 +40,7 @@
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_QUICK_SETTINGS_EXPANDED;
 import static com.android.systemui.statusbar.StatusBarState.KEYGUARD;
 import static com.android.systemui.statusbar.StatusBarState.SHADE;
+import static com.android.systemui.statusbar.StatusBarState.SHADE_LOCKED;
 import static com.android.systemui.statusbar.VibratorHelper.TOUCH_VIBRATION_ATTRIBUTES;
 import static com.android.systemui.statusbar.notification.stack.StackStateAnimator.ANIMATION_DURATION_FOLD_TO_AOD;
 import static com.android.systemui.util.DumpUtilsKt.asIndenting;
@@ -2141,7 +2142,6 @@
                 if ((h > touchSlop || (h < -touchSlop && mQsExpanded))
                         && Math.abs(h) > Math.abs(x - mInitialTouchX)
                         && shouldQuickSettingsIntercept(mInitialTouchX, mInitialTouchY, h)) {
-                    debugLog("onQsIntercept - start tracking expansion");
                     mView.getParent().requestDisallowInterceptTouchEvent(true);
                     mShadeLog.onQsInterceptMoveQsTrackingEnabled(h);
                     mQsTracking = true;
@@ -2326,7 +2326,7 @@
 
 
     private boolean handleQsTouch(MotionEvent event) {
-        if (mSplitShadeEnabled && touchXOutsideOfQs(event.getX())) {
+        if (isSplitShadeAndTouchXOutsideQs(event.getX())) {
             return false;
         }
         final int action = event.getActionMasked();
@@ -2352,7 +2352,7 @@
         if (!mSplitShadeEnabled
                 && computeQsExpansionFraction() <= 0.01 && getExpandedFraction() < 1.0) {
             mShadeLog.logMotionEvent(event,
-                    "handleQsTouch: QQS touched while shade collapsing");
+                    "handleQsTouch: QQS touched while shade collapsing, QS tracking disabled");
             mQsTracking = false;
         }
         if (!mQsExpandImmediate && mQsTracking) {
@@ -2383,12 +2383,14 @@
         return false;
     }
 
-    private boolean touchXOutsideOfQs(float touchX) {
-        return touchX < mQsFrame.getX() || touchX > mQsFrame.getX() + mQsFrame.getWidth();
+    /** Returns whether split shade is enabled and an x coordinate is outside of the QS frame. */
+    private boolean isSplitShadeAndTouchXOutsideQs(float touchX) {
+        return mSplitShadeEnabled && (touchX < mQsFrame.getX()
+                || touchX > mQsFrame.getX() + mQsFrame.getWidth());
     }
 
     private boolean isInQsArea(float x, float y) {
-        if (touchXOutsideOfQs(x)) {
+        if (isSplitShadeAndTouchXOutsideQs(x)) {
             return false;
         }
         // Let's reject anything at the very bottom around the home handle in gesture nav
@@ -4721,6 +4723,7 @@
             if (!openingWithTouch || !mHasVibratedOnOpen) {
                 mVibratorHelper.vibrate(VibrationEffect.EFFECT_TICK);
                 mHasVibratedOnOpen = true;
+                mShadeLog.v("Vibrating on opening, mHasVibratedOnOpen=true");
             }
         }
     }
@@ -5317,7 +5320,7 @@
         @Override
         public void flingTopOverscroll(float velocity, boolean open) {
             // in split shade mode we want to expand/collapse QS only when touch happens within QS
-            if (mSplitShadeEnabled && touchXOutsideOfQs(mInitialTouchX)) {
+            if (isSplitShadeAndTouchXOutsideQs(mInitialTouchX)) {
                 return;
             }
             mLastOverscroll = 0f;
@@ -5478,6 +5481,15 @@
             mBarState = statusBarState;
             mKeyguardShowing = keyguardShowing;
 
+            boolean fromShadeToKeyguard = statusBarState == KEYGUARD
+                    && (oldState == SHADE || oldState == SHADE_LOCKED);
+            if (mSplitShadeEnabled && fromShadeToKeyguard) {
+                // user can go to keyguard from different shade states and closing animation
+                // may not fully run - we always want to make sure we close QS when that happens
+                // as we never need QS open in fresh keyguard state
+                closeQs();
+            }
+
             if (oldState == KEYGUARD && (goingToFullShade
                     || statusBarState == StatusBarState.SHADE_LOCKED)) {
 
@@ -5497,27 +5509,12 @@
                 mKeyguardStatusBarViewController.animateKeyguardStatusBarIn();
 
                 mNotificationStackScrollLayoutController.resetScrollPosition();
-                // Only animate header if the header is visible. If not, it will partially
-                // animate out
-                // the top of QS
-                if (!mQsExpanded) {
-                    // TODO(b/185683835) Nicer clipping when using new spacial model
-                    if (mSplitShadeEnabled) {
-                        mQs.animateHeaderSlidingOut();
-                    }
-                }
             } else {
                 // this else branch means we are doing one of:
                 //  - from KEYGUARD to SHADE (but not fully expanded as when swiping from the top)
                 //  - from SHADE to KEYGUARD
                 //  - from SHADE_LOCKED to SHADE
                 //  - getting notified again about the current SHADE or KEYGUARD state
-                if (mSplitShadeEnabled && oldState == SHADE && statusBarState == KEYGUARD) {
-                    // user can go to keyguard from different shade states and closing animation
-                    // may not fully run - we always want to make sure we close QS when that happens
-                    // as we never need QS open in fresh keyguard state
-                    closeQs();
-                }
                 final boolean animatingUnlockedShadeToKeyguard = oldState == SHADE
                         && statusBarState == KEYGUARD
                         && mScreenOffAnimationController.isKeyguardShowDelayed();
@@ -5796,12 +5793,9 @@
         /** @see ViewGroup#onInterceptTouchEvent(MotionEvent) */
         public boolean onInterceptTouchEvent(MotionEvent event) {
             mShadeLog.logMotionEvent(event, "NPVC onInterceptTouchEvent");
-            if (SPEW_LOGCAT) {
-                Log.v(TAG,
-                        "NPVC onInterceptTouchEvent (" + event.getId() + "): (" + event.getX()
-                                + "," + event.getY() + ")");
-            }
             if (mQs.disallowPanelTouches()) {
+                mShadeLog.logMotionEvent(event,
+                        "NPVC not intercepting touch, panel touches disallowed");
                 return false;
             }
             initDownStates(event);
@@ -5834,8 +5828,15 @@
                         + "QsIntercept");
                 return true;
             }
-            if (mInstantExpanding || !mNotificationsDragEnabled || mTouchDisabled || (mMotionAborted
-                    && event.getActionMasked() != MotionEvent.ACTION_DOWN)) {
+
+            if (mInstantExpanding || !mNotificationsDragEnabled || mTouchDisabled) {
+                mShadeLog.logNotInterceptingTouchInstantExpanding(mInstantExpanding,
+                        !mNotificationsDragEnabled, mTouchDisabled);
+                return false;
+            }
+            if (mMotionAborted && event.getActionMasked() != MotionEvent.ACTION_DOWN) {
+                mShadeLog.logMotionEventStatusBarState(event, mStatusBarStateController.getState(),
+                        "NPVC MotionEvent not intercepted: non-down action, motion was aborted");
                 return false;
             }
 
@@ -5890,6 +5891,9 @@
                     }
                     break;
                 case MotionEvent.ACTION_POINTER_DOWN:
+                    mShadeLog.logMotionEventStatusBarState(event,
+                            mStatusBarStateController.getState(),
+                            "onInterceptTouchEvent: pointer down action");
                     if (mStatusBarStateController.getState() == StatusBarState.KEYGUARD) {
                         mMotionAborted = true;
                         mVelocityTracker.clear();
@@ -5931,7 +5935,8 @@
                     // events are received in this handler with identical downTimes. Until the
                     // source of the issue can be located, detect this case and ignore.
                     // see b/193350347
-                    Log.w(TAG, "Duplicate down event detected... ignoring");
+                    mShadeLog.logMotionEvent(event,
+                            "onTouch: duplicate down event detected... ignoring");
                     return true;
                 }
                 mLastTouchDownTime = event.getDownTime();
@@ -5939,6 +5944,8 @@
 
 
             if (mQsFullyExpanded && mQs != null && mQs.disallowPanelTouches()) {
+                mShadeLog.logMotionEvent(event,
+                        "onTouch: ignore touch, panel touches disallowed and qs fully expanded");
                 return false;
             }
 
@@ -5946,6 +5953,8 @@
             // otherwise user would be able to pull down QS or expand the shade.
             if (mCentralSurfaces.isBouncerShowingScrimmed()
                     || mCentralSurfaces.isBouncerShowingOverDream()) {
+                mShadeLog.logMotionEvent(event,
+                        "onTouch: ignore touch, bouncer scrimmed or showing over dream");
                 return false;
             }
 
@@ -6003,15 +6012,17 @@
 
         private boolean handleTouch(MotionEvent event) {
             if (mInstantExpanding) {
-                mShadeLog.logMotionEvent(event, "onTouch: touch ignored due to instant expanding");
+                mShadeLog.logMotionEvent(event,
+                        "handleTouch: touch ignored due to instant expanding");
                 return false;
             }
             if (mTouchDisabled && event.getActionMasked() != MotionEvent.ACTION_CANCEL) {
-                mShadeLog.logMotionEvent(event, "onTouch: non-cancel action, touch disabled");
+                mShadeLog.logMotionEvent(event, "handleTouch: non-cancel action, touch disabled");
                 return false;
             }
             if (mMotionAborted && event.getActionMasked() != MotionEvent.ACTION_DOWN) {
-                mShadeLog.logMotionEvent(event, "onTouch: non-down action, motion was aborted");
+                mShadeLog.logMotionEventStatusBarState(event, mStatusBarStateController.getState(),
+                        "handleTouch: non-down action, motion was aborted");
                 return false;
             }
 
@@ -6021,7 +6032,7 @@
                     // Turn off tracking if it's on or the shade can get stuck in the down position.
                     onTrackingStopped(true /* expand */);
                 }
-                mShadeLog.logMotionEvent(event, "onTouch: drag not enabled");
+                mShadeLog.logMotionEvent(event, "handleTouch: drag not enabled");
                 return false;
             }
 
@@ -6094,6 +6105,9 @@
                     }
                     break;
                 case MotionEvent.ACTION_POINTER_DOWN:
+                    mShadeLog.logMotionEventStatusBarState(event,
+                            mStatusBarStateController.getState(),
+                            "handleTouch: pointer down action");
                     if (mStatusBarStateController.getState() == StatusBarState.KEYGUARD) {
                         mMotionAborted = true;
                         endMotionEvent(event, x, y, true /* forceCancel */);
@@ -6104,6 +6118,7 @@
                     if (isFullyCollapsed()) {
                         // If panel is fully collapsed, reset haptic effect before adding movement.
                         mHasVibratedOnOpen = false;
+                        mShadeLog.logHasVibrated(mHasVibratedOnOpen, mExpandedFraction);
                     }
                     addMovement(event);
                     if (!isFullyCollapsed()) {
diff --git a/packages/SystemUI/src/com/android/systemui/shade/ShadeLogger.kt b/packages/SystemUI/src/com/android/systemui/shade/ShadeLogger.kt
index 40ed40a..5fedbeb 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/ShadeLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/shade/ShadeLogger.kt
@@ -98,6 +98,29 @@
         )
     }
 
+    fun logMotionEventStatusBarState(event: MotionEvent, statusBarState: Int, message: String) {
+        log(
+                LogLevel.VERBOSE,
+                {
+                    str1 = message
+                    long1 = event.eventTime
+                    long2 = event.downTime
+                    int1 = event.action
+                    int2 = statusBarState
+                    double1 = event.y.toDouble()
+                },
+                {
+                    "$str1\neventTime=$long1,downTime=$long2,y=$double1,action=$int1," +
+                            "statusBarState=${when (int2) {
+                                0 -> "SHADE"
+                                1 -> "KEYGUARD"
+                                2 -> "SHADE_LOCKED"
+                                else -> "UNKNOWN:$int2"
+                            }}"
+                }
+        )
+    }
+
     fun logExpansionChanged(
             message: String,
             fraction: Float,
@@ -117,6 +140,15 @@
         })
     }
 
+    fun logHasVibrated(hasVibratedOnOpen: Boolean, fraction: Float) {
+        log(LogLevel.VERBOSE, {
+            bool1 = hasVibratedOnOpen
+            double1 = fraction.toDouble()
+        }, {
+            "hasVibratedOnOpen=$bool1, expansionFraction=$double1"
+        })
+    }
+
     fun logQsExpansionChanged(
             message: String,
             qsExpanded: Boolean,
@@ -164,4 +196,19 @@
                     "tap to be detected: proximityIsNotNear: $bool1, isNotFalseTap: $bool2"
         })
     }
+
+    fun logNotInterceptingTouchInstantExpanding(
+            instantExpanding: Boolean,
+            notificationsDragEnabled: Boolean,
+            touchDisabled: Boolean
+    ) {
+        log(LogLevel.VERBOSE, {
+            bool1 = instantExpanding
+            bool2 = notificationsDragEnabled
+            bool3 = touchDisabled
+        }, {
+            "NPVC not intercepting touch, instantExpanding: $bool1, " +
+                    "!notificationsDragEnabled: $bool2, touchDisabled: $bool3"
+        })
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java
index 0f27420..e39879d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java
@@ -61,6 +61,7 @@
 import android.os.RemoteException;
 import android.os.UserHandle;
 import android.os.UserManager;
+import android.provider.DeviceConfig;
 import android.text.TextUtils;
 import android.text.format.Formatter;
 import android.view.View;
@@ -413,14 +414,25 @@
 
     private CharSequence getDisclosureText(@Nullable CharSequence organizationName) {
         final Resources packageResources = mContext.getResources();
+
+        // TODO(b/259908270): remove and inline
+        boolean isFinanced;
+        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER,
+                DevicePolicyManager.ADD_ISFINANCED_DEVICE_FLAG,
+                DevicePolicyManager.ADD_ISFINANCED_FEVICE_DEFAULT)) {
+            isFinanced = mDevicePolicyManager.isFinancedDevice();
+        } else {
+            isFinanced = mDevicePolicyManager.isDeviceManaged()
+                    && mDevicePolicyManager.getDeviceOwnerType(
+                    mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser())
+                    == DEVICE_OWNER_TYPE_FINANCED;
+        }
+
         if (organizationName == null) {
             return mDevicePolicyManager.getResources().getString(
                     KEYGUARD_MANAGEMENT_DISCLOSURE,
                     () -> packageResources.getString(R.string.do_disclosure_generic));
-        } else if (mDevicePolicyManager.isDeviceManaged()
-                && mDevicePolicyManager.getDeviceOwnerType(
-                mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser())
-                == DEVICE_OWNER_TYPE_FINANCED) {
+        } else if (isFinanced) {
             return packageResources.getString(R.string.do_financed_disclosure_with_name,
                     organizationName);
         } else {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/connectivity/NetworkControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/connectivity/NetworkControllerImpl.java
index 336356e..b9074f0 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/connectivity/NetworkControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/connectivity/NetworkControllerImpl.java
@@ -68,7 +68,7 @@
 import com.android.systemui.R;
 import com.android.systemui.broadcast.BroadcastDispatcher;
 import com.android.systemui.dagger.SysUISingleton;
-import com.android.systemui.dagger.qualifiers.LongRunning;
+import com.android.systemui.dagger.qualifiers.Background;
 import com.android.systemui.dagger.qualifiers.Main;
 import com.android.systemui.demomode.DemoMode;
 import com.android.systemui.demomode.DemoModeController;
@@ -225,15 +225,12 @@
 
     /**
      * Construct this controller object and register for updates.
-     *
-     * {@code @LongRunning} looper and bgExecutor instead {@code @Background} ones are used to
-     * address the b/246456655. This can be reverted after b/240663726 is fixed.
      */
     @Inject
     public NetworkControllerImpl(
             Context context,
-            @LongRunning Looper bgLooper,
-            @LongRunning Executor bgExecutor,
+            @Background Looper bgLooper,
+            @Background Executor bgExecutor,
             SubscriptionManager subscriptionManager,
             CallbackHandler callbackHandler,
             DeviceProvisionedController deviceProvisionedController,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt
index 6bd9502..56d3b7c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt
@@ -17,6 +17,7 @@
 package com.android.systemui.statusbar.lockscreen
 
 import android.app.PendingIntent
+import android.app.WallpaperManager
 import android.app.smartspace.SmartspaceConfig
 import android.app.smartspace.SmartspaceManager
 import android.app.smartspace.SmartspaceSession
@@ -102,6 +103,8 @@
     private var showSensitiveContentForManagedUser = false
     private var managedUserHandle: UserHandle? = null
 
+    // TODO(b/202758428): refactor so that we can test color updates via region samping, similar to
+    //  how we test color updates when theme changes (See testThemeChangeUpdatesTextColor).
     private val updateFun: UpdateColorCallback = { updateTextColorFromRegionSampler() }
 
     // TODO: Move logic into SmartspaceView
@@ -109,16 +112,19 @@
         override fun onViewAttachedToWindow(v: View) {
             smartspaceViews.add(v as SmartspaceView)
 
-            var regionSampler = RegionSampler(
-                    v,
-                    uiExecutor,
-                    bgExecutor,
-                    regionSamplingEnabled,
-                    updateFun
-            )
-            initializeTextColors(regionSampler)
-            regionSampler.startRegionSampler()
-            regionSamplers.put(v, regionSampler)
+            if (regionSamplingEnabled) {
+                var regionSampler = RegionSampler(
+                        v,
+                        uiExecutor,
+                        bgExecutor,
+                        regionSamplingEnabled,
+                        updateFun
+                )
+                initializeTextColors(regionSampler)
+                regionSampler.startRegionSampler()
+                regionSamplers.put(v, regionSampler)
+            }
+
             connectSession()
 
             updateTextColorFromWallpaper()
@@ -128,9 +134,11 @@
         override fun onViewDetachedFromWindow(v: View) {
             smartspaceViews.remove(v as SmartspaceView)
 
-            var regionSampler = regionSamplers.getValue(v)
-            regionSampler.stopRegionSampler()
-            regionSamplers.remove(v)
+            if (regionSamplingEnabled) {
+                var regionSampler = regionSamplers.getValue(v)
+                regionSampler.stopRegionSampler()
+                regionSamplers.remove(v)
+            }
 
             if (smartspaceViews.isEmpty()) {
                 disconnect()
@@ -383,7 +391,8 @@
     }
 
     private fun updateTextColorFromWallpaper() {
-        if (!regionSamplingEnabled) {
+        val wallpaperManager = WallpaperManager.getInstance(context)
+        if (!regionSamplingEnabled || wallpaperManager.lockScreenWallpaperExists()) {
             val wallpaperTextColor =
                     Utils.getColorAttrDefaultColor(context, R.attr.wallpaperTextColor)
             smartspaceViews.forEach { it.setPrimaryTextColor(wallpaperTextColor) }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotifPipelineFlags.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotifPipelineFlags.kt
index 39daa13..3072c81 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotifPipelineFlags.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotifPipelineFlags.kt
@@ -33,6 +33,8 @@
     fun fullScreenIntentRequiresKeyguard(): Boolean =
         featureFlags.isEnabled(Flags.FSI_REQUIRES_KEYGUARD)
 
+    fun fsiOnDNDUpdate(): Boolean = featureFlags.isEnabled(Flags.FSI_ON_DND_UPDATE)
+
     val isStabilityIndexFixEnabled: Boolean by lazy {
         featureFlags.isEnabled(Flags.STABILITY_INDEX_FIX)
     }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationWakeUpCoordinator.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationWakeUpCoordinator.kt
index 3e2dd05..aeae89c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationWakeUpCoordinator.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationWakeUpCoordinator.kt
@@ -244,7 +244,7 @@
     }
 
     override fun onDozeAmountChanged(linear: Float, eased: Float) {
-        logger.logOnDozeAmountChanged(linear, eased)
+        logger.logOnDozeAmountChanged(linear = linear, eased = eased)
         if (overrideDozeAmountIfAnimatingScreenOff(linear)) {
             return
         }
@@ -263,6 +263,7 @@
 
     fun setDozeAmount(linear: Float, eased: Float, source: String) {
         val changed = linear != mLinearDozeAmount
+        logger.logSetDozeAmount(linear, eased, source, statusBarStateController.state, changed)
         mLinearDozeAmount = linear
         mDozeAmount = eased
         mDozeAmountSource = source
@@ -276,7 +277,7 @@
     }
 
     override fun onStateChanged(newState: Int) {
-        logger.logOnStateChanged(newState)
+        logger.logOnStateChanged(newState = newState, storedState = state)
         if (state == StatusBarState.SHADE && newState == StatusBarState.SHADE) {
             // The SHADE -> SHADE transition is only possible as part of cancelling the screen-off
             // animation (e.g. by fingerprint unlock).  This is done because the system is in an
@@ -324,12 +325,8 @@
     private fun overrideDozeAmountIfBypass(): Boolean {
         if (bypassController.bypassEnabled) {
             if (statusBarStateController.state == StatusBarState.KEYGUARD) {
-                logger.logSetDozeAmount("1.0", "1.0",
-                        "Override: bypass (keyguard)", StatusBarState.KEYGUARD)
                 setDozeAmount(1f, 1f, source = "Override: bypass (keyguard)")
             } else {
-                logger.logSetDozeAmount("0.0", "0.0",
-                        "Override: bypass (shade)", statusBarStateController.state)
                 setDozeAmount(0f, 0f, source = "Override: bypass (shade)")
             }
             return true
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationWakeUpCoordinatorLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationWakeUpCoordinatorLogger.kt
index b40ce25..de18b0c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationWakeUpCoordinatorLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationWakeUpCoordinatorLogger.kt
@@ -16,22 +16,33 @@
 import com.android.systemui.log.dagger.NotificationLog
 import com.android.systemui.plugins.log.LogBuffer
 import com.android.systemui.plugins.log.LogLevel.DEBUG
+import com.android.systemui.statusbar.StatusBarState
 import javax.inject.Inject
 
 class NotificationWakeUpCoordinatorLogger
 @Inject
 constructor(@NotificationLog private val buffer: LogBuffer) {
-    fun logSetDozeAmount(linear: String, eased: String, source: String, state: Int) {
+    fun logSetDozeAmount(
+        linear: Float,
+        eased: Float,
+        source: String,
+        state: Int,
+        changed: Boolean,
+    ) {
         buffer.log(
             TAG,
             DEBUG,
             {
-                str1 = linear
-                str2 = eased
+                double1 = linear.toDouble()
+                str2 = eased.toString()
                 str3 = source
                 int1 = state
+                bool1 = changed
             },
-            { "setDozeAmount: linear: $str1, eased: $str2, source: $str3, state: $int1" }
+            {
+                "setDozeAmount(linear=$double1, eased=$str2, source=$str3)" +
+                    " state=${StatusBarState.toString(int1)} changed=$bool1"
+            }
         )
     }
 
@@ -43,12 +54,23 @@
                 double1 = linear.toDouble()
                 str2 = eased.toString()
             },
-            { "onDozeAmountChanged($double1, $str2)" }
+            { "onDozeAmountChanged(linear=$double1, eased=$str2)" }
         )
     }
 
-    fun logOnStateChanged(newState: Int) {
-        buffer.log(TAG, DEBUG, { int1 = newState }, { "onStateChanged($int1)" })
+    fun logOnStateChanged(newState: Int, storedState: Int) {
+        buffer.log(
+            TAG,
+            DEBUG,
+            {
+                int1 = newState
+                int2 = storedState
+            },
+            {
+                "onStateChanged(newState=${StatusBarState.toString(int1)})" +
+                    " stored=${StatusBarState.toString(int2)}"
+            }
+        )
     }
 }
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinator.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinator.kt
index 5dbb4f9..1004ec1 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinator.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinator.kt
@@ -22,6 +22,7 @@
 import com.android.internal.annotations.VisibleForTesting
 import com.android.systemui.dagger.qualifiers.Main
 import com.android.systemui.statusbar.NotificationRemoteInputManager
+import com.android.systemui.statusbar.notification.NotifPipelineFlags
 import com.android.systemui.statusbar.notification.collection.GroupEntry
 import com.android.systemui.statusbar.notification.collection.ListEntry
 import com.android.systemui.statusbar.notification.collection.NotifPipeline
@@ -38,6 +39,7 @@
 import com.android.systemui.statusbar.notification.dagger.IncomingHeader
 import com.android.systemui.statusbar.notification.interruption.HeadsUpViewBinder
 import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider
+import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider.FullScreenIntentDecision
 import com.android.systemui.statusbar.notification.logKey
 import com.android.systemui.statusbar.notification.stack.BUCKET_HEADS_UP
 import com.android.systemui.statusbar.policy.HeadsUpManager
@@ -70,11 +72,13 @@
     private val mNotificationInterruptStateProvider: NotificationInterruptStateProvider,
     private val mRemoteInputManager: NotificationRemoteInputManager,
     private val mLaunchFullScreenIntentProvider: LaunchFullScreenIntentProvider,
+    private val mFlags: NotifPipelineFlags,
     @IncomingHeader private val mIncomingHeaderController: NodeController,
     @Main private val mExecutor: DelayableExecutor,
 ) : Coordinator {
     private val mEntriesBindingUntil = ArrayMap<String, Long>()
     private val mEntriesUpdateTimes = ArrayMap<String, Long>()
+    private val mFSIUpdateCandidates = ArrayMap<String, Long>()
     private var mEndLifetimeExtension: OnEndLifetimeExtensionCallback? = null
     private lateinit var mNotifPipeline: NotifPipeline
     private var mNow: Long = -1
@@ -278,7 +282,7 @@
         mPostedEntries.clear()
 
         // Also take this opportunity to clean up any stale entry update times
-        cleanUpEntryUpdateTimes()
+        cleanUpEntryTimes()
     }
 
     /**
@@ -384,8 +388,15 @@
         override fun onEntryAdded(entry: NotificationEntry) {
             // First check whether this notification should launch a full screen intent, and
             // launch it if needed.
-            if (mNotificationInterruptStateProvider.shouldLaunchFullScreenIntentWhenAdded(entry)) {
+            val fsiDecision = mNotificationInterruptStateProvider.getFullScreenIntentDecision(entry)
+            if (fsiDecision != null && fsiDecision.shouldLaunch) {
+                mNotificationInterruptStateProvider.logFullScreenIntentDecision(entry, fsiDecision)
                 mLaunchFullScreenIntentProvider.launchFullScreenIntent(entry)
+            } else if (mFlags.fsiOnDNDUpdate() &&
+                fsiDecision.equals(FullScreenIntentDecision.NO_FSI_SUPPRESSED_ONLY_BY_DND)) {
+                // If DND was the only reason this entry was suppressed, note it for potential
+                // reconsideration on later ranking updates.
+                addForFSIReconsideration(entry, mSystemClock.currentTimeMillis())
             }
 
             // shouldHeadsUp includes check for whether this notification should be filtered
@@ -488,11 +499,32 @@
                 if (!isNewEnoughForRankingUpdate(entry)) continue
 
                 // The only entries we consider alerting for here are entries that have never
-                // interrupted and that now say they should heads up; if they've alerted in the
-                // past, we don't want to incorrectly alert a second time if there wasn't an
+                // interrupted and that now say they should heads up or FSI; if they've alerted in
+                // the past, we don't want to incorrectly alert a second time if there wasn't an
                 // explicit notification update.
                 if (entry.hasInterrupted()) continue
 
+                // Before potentially allowing heads-up, check for any candidates for a FSI launch.
+                // Any entry that is a candidate meets two criteria:
+                //   - was suppressed from FSI launch only by a DND suppression
+                //   - is within the recency window for reconsideration
+                // If any of these entries are no longer suppressed, launch the FSI now.
+                if (mFlags.fsiOnDNDUpdate() && isCandidateForFSIReconsideration(entry)) {
+                    val decision =
+                        mNotificationInterruptStateProvider.getFullScreenIntentDecision(entry)
+                    if (decision.shouldLaunch) {
+                        // Log both the launch of the full screen and also that this was via a
+                        // ranking update.
+                        mLogger.logEntryUpdatedToFullScreen(entry.key)
+                        mNotificationInterruptStateProvider.logFullScreenIntentDecision(
+                            entry, decision)
+                        mLaunchFullScreenIntentProvider.launchFullScreenIntent(entry)
+
+                        // if we launch the FSI then this is no longer a candidate for HUN
+                        continue
+                    }
+                }
+
                 // The cases where we should consider this notification to be updated:
                 // - if this entry is not present in PostedEntries, and is now in a shouldHeadsUp
                 //   state
@@ -528,6 +560,15 @@
     }
 
     /**
+     * Add the entry to the list of entries potentially considerable for FSI ranking update, where
+     * the provided time is the time the entry was added.
+     */
+    @VisibleForTesting
+    fun addForFSIReconsideration(entry: NotificationEntry, time: Long) {
+        mFSIUpdateCandidates[entry.key] = time
+    }
+
+    /**
      * Checks whether the entry is new enough to be updated via ranking update.
      * We want to avoid updating an entry too long after it was originally posted/updated when we're
      * only reacting to a ranking change, as relevant ranking updates are expected to come in
@@ -541,17 +582,38 @@
         return (mSystemClock.currentTimeMillis() - updateTime) <= MAX_RANKING_UPDATE_DELAY_MS
     }
 
-    private fun cleanUpEntryUpdateTimes() {
+    /**
+     * Checks whether the entry is present new enough for reconsideration for full screen launch.
+     * The time window is the same as for ranking update, but this doesn't allow a potential update
+     * to an entry with full screen intent to count for timing purposes.
+     */
+    private fun isCandidateForFSIReconsideration(entry: NotificationEntry): Boolean {
+        val addedTime = mFSIUpdateCandidates[entry.key] ?: return false
+        return (mSystemClock.currentTimeMillis() - addedTime) <= MAX_RANKING_UPDATE_DELAY_MS
+    }
+
+    private fun cleanUpEntryTimes() {
         // Because we won't update entries that are older than this amount of time anyway, clean
-        // up any entries that are too old to notify.
+        // up any entries that are too old to notify from both the general and FSI specific lists.
+
+        // Anything newer than this time is still within the window.
+        val timeThreshold = mSystemClock.currentTimeMillis() - MAX_RANKING_UPDATE_DELAY_MS
+
         val toRemove = ArraySet<String>()
         for ((key, updateTime) in mEntriesUpdateTimes) {
-            if (updateTime == null ||
-                    (mSystemClock.currentTimeMillis() - updateTime) > MAX_RANKING_UPDATE_DELAY_MS) {
+            if (updateTime == null || timeThreshold > updateTime) {
                 toRemove.add(key)
             }
         }
         mEntriesUpdateTimes.removeAll(toRemove)
+
+        val toRemoveForFSI = ArraySet<String>()
+        for ((key, addedTime) in mFSIUpdateCandidates) {
+            if (addedTime == null || timeThreshold > addedTime) {
+                toRemoveForFSI.add(key)
+            }
+        }
+        mFSIUpdateCandidates.removeAll(toRemoveForFSI)
     }
 
     /** When an action is pressed on a notification, end HeadsUp lifetime extension. */
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinatorLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinatorLogger.kt
index 473c35d..2c6bf6b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinatorLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinatorLogger.kt
@@ -70,6 +70,14 @@
         })
     }
 
+    fun logEntryUpdatedToFullScreen(key: String) {
+        buffer.log(TAG, LogLevel.DEBUG, {
+            str1 = key
+        }, {
+            "updating entry to launch full screen intent: $str1"
+        })
+    }
+
     fun logSummaryMarkedInterrupted(summaryKey: String, childKey: String) {
         buffer.log(TAG, LogLevel.DEBUG, {
             str1 = summaryKey
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinator.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinator.kt
index 9da94ce..4133802 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinator.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinator.kt
@@ -119,6 +119,9 @@
                     // Don't apply the filter to (non-promoted) group summaries
                     //  - summary will be pruned if necessary, depending on if children are filtered
                     entry.parent?.summary == entry -> false
+                    // Check that the entry satisfies certain characteristics that would bypass the
+                    // filter
+                    shouldIgnoreUnseenCheck(entry) -> false
                     else -> true
                 }.also { hasFiltered -> hasFilteredAnyNotifs = hasFilteredAnyNotifs || hasFiltered }
 
@@ -134,6 +137,13 @@
                 keyguardNotificationVisibilityProvider.shouldHideNotification(entry)
         }
 
+    private fun shouldIgnoreUnseenCheck(entry: NotificationEntry): Boolean =
+        when {
+            entry.isMediaNotification -> true
+            entry.sbn.isOngoing -> true
+            else -> false
+        }
+
     // TODO(b/206118999): merge this class with SensitiveContentCoordinator which also depends on
     //  these same updates
     private fun setupInvalidateNotifListCallbacks() {}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/fsi/FsiDebug.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/fsi/FsiDebug.kt
new file mode 100644
index 0000000..d9e3f8f
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/fsi/FsiDebug.kt
@@ -0,0 +1,16 @@
+package com.android.systemui.statusbar.notification.fsi
+
+class FsiDebug {
+
+    companion object {
+        private const val debugTag = "FsiDebug"
+        private const val debug = true
+
+        fun log(s: Any) {
+            if (!debug) {
+                return
+            }
+            android.util.Log.d(debugTag, "$s")
+        }
+    }
+}
\ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProvider.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProvider.java
index 6cf4bf3..7136cad 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProvider.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProvider.java
@@ -25,6 +25,79 @@
  */
 public interface NotificationInterruptStateProvider {
     /**
+     * Enum representing a decision of whether to show a full screen intent. While many of the
+     * relevant properties could overlap, the decision represents the deciding factor for whether
+     * the full screen intent should or shouldn't launch.
+     */
+    enum FullScreenIntentDecision {
+        /**
+         * No full screen intent included, so there is nothing to show.
+         */
+        NO_FULL_SCREEN_INTENT(false),
+        /**
+         * Suppressed by DND settings.
+         */
+        NO_FSI_SUPPRESSED_BY_DND(false),
+        /**
+         * Full screen intent was suppressed *only* by DND, and if not for DND would have shown. We
+         * track this separately in order to allow the intent to be shown if the DND decision
+         * changes.
+         */
+        NO_FSI_SUPPRESSED_ONLY_BY_DND(false),
+        /**
+         * Notification importance not high enough to show FSI.
+         */
+        NO_FSI_NOT_IMPORTANT_ENOUGH(false),
+        /**
+         * Notification should not FSI due to having suppressive GroupAlertBehavior. This blocks a
+         * potentially malicious use of flags that previously allowed apps to escalate a HUN to an
+         * FSI even while the device was unlocked.
+         */
+        NO_FSI_SUPPRESSIVE_GROUP_ALERT_BEHAVIOR(false),
+        /**
+         * Device screen is off, so the FSI should launch.
+         */
+        FSI_DEVICE_NOT_INTERACTIVE(true),
+        /**
+         * Device is currently dreaming, so FSI should launch.
+         */
+        FSI_DEVICE_IS_DREAMING(true),
+        /**
+         * Keyguard is showing, so FSI should launch.
+         */
+        FSI_KEYGUARD_SHOWING(true),
+        /**
+         * The notification is expected to show heads-up, so FSI is not needed.
+         */
+        NO_FSI_EXPECTED_TO_HUN(false),
+        /**
+         * The notification is not expected to HUN while the keyguard is occluded, so show FSI.
+         */
+        FSI_KEYGUARD_OCCLUDED(true),
+        /**
+         * The notification is not expected to HUN when the keyguard is showing but not occluded,
+         * which likely means that the shade is showing over the lockscreen; show FSI in this case.
+         */
+        FSI_LOCKED_SHADE(true),
+        /**
+         * FSI requires keyguard to be showing, but there is no keyguard. This is a (potentially
+         * malicious) warning state where we suppress the FSI because the device is in use knowing
+         * that the HUN will probably not display.
+         */
+        NO_FSI_NO_HUN_OR_KEYGUARD(false),
+        /**
+         * No conditions blocking FSI launch.
+         */
+        FSI_EXPECTED_NOT_TO_HUN(true);
+
+        public final boolean shouldLaunch;
+
+        FullScreenIntentDecision(boolean shouldLaunch) {
+            this.shouldLaunch = shouldLaunch;
+        }
+    }
+
+    /**
      * If the device is awake (not dozing):
      *  Whether the notification should peek in from the top and alert the user.
      *
@@ -66,6 +139,27 @@
     boolean shouldLaunchFullScreenIntentWhenAdded(NotificationEntry entry);
 
     /**
+     * Whether an entry's full screen intent would be launched.
+     *
+     * This method differs from shouldLaunchFullScreenIntentWhenAdded by returning more information
+     * on the decision, and only optionally logging the outcome. It should be used in cases where
+     * the caller needs to know what the decision would be, but may not actually launch the full
+     * screen intent.
+     *
+     * @param entry the entry to evaluate
+     * @return FullScreenIntentDecision representing the decision for whether to show the intent
+     */
+    FullScreenIntentDecision getFullScreenIntentDecision(NotificationEntry entry);
+
+    /**
+     * Write the full screen launch decision for the given entry to logs.
+     *
+     * @param entry the NotificationEntry for which the decision applies
+     * @param decision reason for launch or no-launch of FSI for entry
+     */
+    void logFullScreenIntentDecision(NotificationEntry entry, FullScreenIntentDecision decision);
+
+    /**
      * Add a component that can suppress visual interruptions.
      */
     void addSuppressor(NotificationInterruptSuppressor suppressor);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImpl.java
index ec5bd68..d9dacfd 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImpl.java
@@ -211,20 +211,49 @@
      */
     @Override
     public boolean shouldLaunchFullScreenIntentWhenAdded(NotificationEntry entry) {
-        if (entry.getSbn().getNotification().fullScreenIntent == null) {
-            return false;
+        FullScreenIntentDecision decision = getFullScreenIntentDecision(entry);
+        logFullScreenIntentDecision(entry, decision);
+        return decision.shouldLaunch;
+    }
+
+    // Given whether the relevant entry was suppressed by DND, and the full screen intent launch
+    // decision independent of the DND decision, returns the combined FullScreenIntentDecision that
+    // results. If the entry was suppressed by DND but the decision otherwise would launch the
+    // FSI, then it is suppressed *only* by DND, whereas (because the DND decision happens before
+    // all others) if the entry would not otherwise have launched the FSI, DND is the effective
+    // suppressor.
+    //
+    // If the entry was not suppressed by DND, just returns the given decision.
+    private FullScreenIntentDecision getDecisionGivenSuppression(FullScreenIntentDecision decision,
+            boolean suppressedByDND) {
+        if (suppressedByDND) {
+            return decision.shouldLaunch
+                    ? FullScreenIntentDecision.NO_FSI_SUPPRESSED_ONLY_BY_DND
+                    : FullScreenIntentDecision.NO_FSI_SUPPRESSED_BY_DND;
         }
+        return decision;
+    }
+
+    @Override
+    public FullScreenIntentDecision getFullScreenIntentDecision(NotificationEntry entry) {
+        if (entry.getSbn().getNotification().fullScreenIntent == null) {
+            return FullScreenIntentDecision.NO_FULL_SCREEN_INTENT;
+        }
+
+        // Boolean indicating whether this FSI would have been suppressed by DND. Because we
+        // want to be able to identify when something would have shown an FSI if not for being
+        // suppressed, we need to keep track of this value for future decisions.
+        boolean suppressedByDND = false;
 
         // Never show FSI when suppressed by DND
         if (entry.shouldSuppressFullScreenIntent()) {
-            mLogger.logNoFullscreen(entry, "Suppressed by DND");
-            return false;
+            suppressedByDND = true;
         }
 
         // Never show FSI if importance is not HIGH
         if (entry.getImportance() < NotificationManager.IMPORTANCE_HIGH) {
-            mLogger.logNoFullscreen(entry, "Not important enough");
-            return false;
+            return getDecisionGivenSuppression(FullScreenIntentDecision.NO_FSI_NOT_IMPORTANT_ENOUGH,
+                    suppressedByDND);
         }
 
         // If the notification has suppressive GroupAlertBehavior, block FSI and warn.
@@ -232,36 +261,35 @@
         if (sbn.isGroup() && sbn.getNotification().suppressAlertingDueToGrouping()) {
             // b/231322873: Detect and report an event when a notification has both an FSI and a
             // suppressive groupAlertBehavior, and now correctly block the FSI from firing.
-            final int uid = entry.getSbn().getUid();
-            final String packageName = entry.getSbn().getPackageName();
-            android.util.EventLog.writeEvent(0x534e4554, "231322873", uid, "groupAlertBehavior");
-            mUiEventLogger.log(FSI_SUPPRESSED_SUPPRESSIVE_GROUP_ALERT_BEHAVIOR, uid, packageName);
-            mLogger.logNoFullscreenWarning(entry, "GroupAlertBehavior will prevent HUN");
-            return false;
+            return getDecisionGivenSuppression(
+                    FullScreenIntentDecision.NO_FSI_SUPPRESSIVE_GROUP_ALERT_BEHAVIOR,
+                    suppressedByDND);
         }
 
         // If the screen is off, then launch the FullScreenIntent
         if (!mPowerManager.isInteractive()) {
-            mLogger.logFullscreen(entry, "Device is not interactive");
-            return true;
+            return getDecisionGivenSuppression(FullScreenIntentDecision.FSI_DEVICE_NOT_INTERACTIVE,
+                    suppressedByDND);
         }
 
         // If the device is currently dreaming, then launch the FullScreenIntent
         if (isDreaming()) {
-            mLogger.logFullscreen(entry, "Device is dreaming");
-            return true;
+            return getDecisionGivenSuppression(FullScreenIntentDecision.FSI_DEVICE_IS_DREAMING,
+                    suppressedByDND);
         }
 
         // If the keyguard is showing, then launch the FullScreenIntent
         if (mStatusBarStateController.getState() == StatusBarState.KEYGUARD) {
-            mLogger.logFullscreen(entry, "Keyguard is showing");
-            return true;
+            return getDecisionGivenSuppression(FullScreenIntentDecision.FSI_KEYGUARD_SHOWING,
+                    suppressedByDND);
         }
 
         // If the notification should HUN, then we don't need FSI
-        if (shouldHeadsUp(entry)) {
-            mLogger.logNoFullscreen(entry, "Expected to HUN");
-            return false;
+        // Because this is not the heads-up decision-making point, and checking whether it would
+        // HUN, don't log this specific check.
+        if (checkHeadsUp(entry, /* log= */ false)) {
+            return getDecisionGivenSuppression(FullScreenIntentDecision.NO_FSI_EXPECTED_TO_HUN,
+                    suppressedByDND);
         }
 
         // Check whether FSI requires the keyguard to be showing.
@@ -270,27 +298,77 @@
             // If notification won't HUN and keyguard is showing, launch the FSI.
             if (mKeyguardStateController.isShowing()) {
                 if (mKeyguardStateController.isOccluded()) {
-                    mLogger.logFullscreen(entry, "Expected not to HUN while keyguard occluded");
+                    return getDecisionGivenSuppression(
+                            FullScreenIntentDecision.FSI_KEYGUARD_OCCLUDED,
+                            suppressedByDND);
                 } else {
                     // Likely LOCKED_SHADE, but launch FSI anyway
-                    mLogger.logFullscreen(entry, "Keyguard is showing and not occluded");
+                    return getDecisionGivenSuppression(FullScreenIntentDecision.FSI_LOCKED_SHADE,
+                            suppressedByDND);
                 }
-                return true;
             }
 
             // Detect the case determined by b/231322873 to launch FSI while device is in use,
             // as blocked by the correct implementation, and report the event.
-            final int uid = entry.getSbn().getUid();
-            final String packageName = entry.getSbn().getPackageName();
-            android.util.EventLog.writeEvent(0x534e4554, "231322873", uid, "no hun or keyguard");
-            mUiEventLogger.log(FSI_SUPPRESSED_NO_HUN_OR_KEYGUARD, uid, packageName);
-            mLogger.logNoFullscreenWarning(entry, "Expected not to HUN while not on keyguard");
-            return false;
+            return getDecisionGivenSuppression(FullScreenIntentDecision.NO_FSI_NO_HUN_OR_KEYGUARD,
+                    suppressedByDND);
         }
 
         // If the notification won't HUN for some other reason (DND/snooze/etc), launch FSI.
-        mLogger.logFullscreen(entry, "Expected not to HUN");
-        return true;
+        return getDecisionGivenSuppression(FullScreenIntentDecision.FSI_EXPECTED_NOT_TO_HUN,
+                suppressedByDND);
+    }
+
+    @Override
+    public void logFullScreenIntentDecision(NotificationEntry entry,
+            FullScreenIntentDecision decision) {
+        final int uid = entry.getSbn().getUid();
+        final String packageName = entry.getSbn().getPackageName();
+        switch (decision) {
+            case NO_FULL_SCREEN_INTENT:
+                return;
+            case NO_FSI_SUPPRESSED_BY_DND:
+            case NO_FSI_SUPPRESSED_ONLY_BY_DND:
+                mLogger.logNoFullscreen(entry, "Suppressed by DND");
+                return;
+            case NO_FSI_NOT_IMPORTANT_ENOUGH:
+                mLogger.logNoFullscreen(entry, "Not important enough");
+                return;
+            case NO_FSI_SUPPRESSIVE_GROUP_ALERT_BEHAVIOR:
+                android.util.EventLog.writeEvent(0x534e4554, "231322873", uid,
+                        "groupAlertBehavior");
+                mUiEventLogger.log(FSI_SUPPRESSED_SUPPRESSIVE_GROUP_ALERT_BEHAVIOR, uid,
+                        packageName);
+                mLogger.logNoFullscreenWarning(entry, "GroupAlertBehavior will prevent HUN");
+                return;
+            case FSI_DEVICE_NOT_INTERACTIVE:
+                mLogger.logFullscreen(entry, "Device is not interactive");
+                return;
+            case FSI_DEVICE_IS_DREAMING:
+                mLogger.logFullscreen(entry, "Device is dreaming");
+                return;
+            case FSI_KEYGUARD_SHOWING:
+                mLogger.logFullscreen(entry, "Keyguard is showing");
+                return;
+            case NO_FSI_EXPECTED_TO_HUN:
+                mLogger.logNoFullscreen(entry, "Expected to HUN");
+                return;
+            case FSI_KEYGUARD_OCCLUDED:
+                mLogger.logFullscreen(entry,
+                        "Expected not to HUN while keyguard occluded");
+                return;
+            case FSI_LOCKED_SHADE:
+                mLogger.logFullscreen(entry, "Keyguard is showing and not occluded");
+                return;
+            case NO_FSI_NO_HUN_OR_KEYGUARD:
+                android.util.EventLog.writeEvent(0x534e4554, "231322873", uid,
+                        "no hun or keyguard");
+                mUiEventLogger.log(FSI_SUPPRESSED_NO_HUN_OR_KEYGUARD, uid, packageName);
+                mLogger.logNoFullscreenWarning(entry, "Expected not to HUN while not on keyguard");
+                return;
+            case FSI_EXPECTED_NOT_TO_HUN:
+                mLogger.logFullscreen(entry, "Expected not to HUN");
+        }
     }
 
     private boolean isDreaming() {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemory.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemory.kt
index 0380fff..1fcf17f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemory.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemory.kt
@@ -17,10 +17,14 @@
 
 package com.android.systemui.statusbar.notification.logging
 
+import android.app.Notification
+
 /** Describes usage of a notification. */
 data class NotificationMemoryUsage(
     val packageName: String,
+    val uid: Int,
     val notificationKey: String,
+    val notification: Notification,
     val objectUsage: NotificationObjectUsage,
     val viewUsage: List<NotificationViewUsage>
 )
@@ -34,7 +38,8 @@
     val smallIcon: Int,
     val largeIcon: Int,
     val extras: Int,
-    val style: String?,
+    /** Style type, integer from [android.stats.sysui.NotificationEnums] */
+    val style: Int,
     val styleIcon: Int,
     val bigPicture: Int,
     val extender: Int,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryDumper.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryDumper.kt
new file mode 100644
index 0000000..ffd931c
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryDumper.kt
@@ -0,0 +1,173 @@
+/*
+ *
+ * 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.systemui.statusbar.notification.logging
+
+import android.stats.sysui.NotificationEnums
+import com.android.systemui.Dumpable
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.dump.DumpManager
+import com.android.systemui.statusbar.notification.collection.NotifPipeline
+import java.io.PrintWriter
+import javax.inject.Inject
+
+/** Dumps current notification memory use to bug reports for easier debugging. */
+@SysUISingleton
+class NotificationMemoryDumper
+@Inject
+constructor(val dumpManager: DumpManager, val notificationPipeline: NotifPipeline) : Dumpable {
+
+    fun init() {
+        dumpManager.registerNormalDumpable(javaClass.simpleName, this)
+    }
+
+    override fun dump(pw: PrintWriter, args: Array<out String>) {
+        val memoryUse =
+            NotificationMemoryMeter.notificationMemoryUse(notificationPipeline.allNotifs)
+                .sortedWith(compareBy({ it.packageName }, { it.notificationKey }))
+        dumpNotificationObjects(pw, memoryUse)
+        dumpNotificationViewUsage(pw, memoryUse)
+    }
+
+    /** Renders a table of notification object usage into passed [PrintWriter]. */
+    private fun dumpNotificationObjects(pw: PrintWriter, memoryUse: List<NotificationMemoryUsage>) {
+        pw.println("Notification Object Usage")
+        pw.println("-----------")
+        pw.println(
+            "Package".padEnd(35) +
+                "\t\tSmall\tLarge\t${"Style".padEnd(15)}\t\tStyle\tBig\tExtend.\tExtras\tCustom"
+        )
+        pw.println("".padEnd(35) + "\t\tIcon\tIcon\t${"".padEnd(15)}\t\tIcon\tPicture\t \t \tView")
+        pw.println()
+
+        memoryUse.forEach { use ->
+            pw.println(
+                use.packageName.padEnd(35) +
+                    "\t\t" +
+                    "${use.objectUsage.smallIcon}\t${use.objectUsage.largeIcon}\t" +
+                    (styleEnumToString(use.objectUsage.style).take(15) ?: "").padEnd(15) +
+                    "\t\t${use.objectUsage.styleIcon}\t" +
+                    "${use.objectUsage.bigPicture}\t${use.objectUsage.extender}\t" +
+                    "${use.objectUsage.extras}\t${use.objectUsage.hasCustomView}\t" +
+                    use.notificationKey
+            )
+        }
+
+        // Calculate totals for easily glanceable summary.
+        data class Totals(
+            var smallIcon: Int = 0,
+            var largeIcon: Int = 0,
+            var styleIcon: Int = 0,
+            var bigPicture: Int = 0,
+            var extender: Int = 0,
+            var extras: Int = 0,
+        )
+
+        val totals =
+            memoryUse.fold(Totals()) { t, usage ->
+                t.smallIcon += usage.objectUsage.smallIcon
+                t.largeIcon += usage.objectUsage.largeIcon
+                t.styleIcon += usage.objectUsage.styleIcon
+                t.bigPicture += usage.objectUsage.bigPicture
+                t.extender += usage.objectUsage.extender
+                t.extras += usage.objectUsage.extras
+                t
+            }
+
+        pw.println()
+        pw.println("TOTALS")
+        pw.println(
+            "".padEnd(35) +
+                "\t\t" +
+                "${toKb(totals.smallIcon)}\t${toKb(totals.largeIcon)}\t" +
+                "".padEnd(15) +
+                "\t\t${toKb(totals.styleIcon)}\t" +
+                "${toKb(totals.bigPicture)}\t${toKb(totals.extender)}\t" +
+                toKb(totals.extras)
+        )
+        pw.println()
+    }
+
+    /** Renders a table of notification view usage into passed [PrintWriter] */
+    private fun dumpNotificationViewUsage(
+        pw: PrintWriter,
+        memoryUse: List<NotificationMemoryUsage>,
+    ) {
+
+        data class Totals(
+            var smallIcon: Int = 0,
+            var largeIcon: Int = 0,
+            var style: Int = 0,
+            var customViews: Int = 0,
+            var softwareBitmapsPenalty: Int = 0,
+        )
+
+        val totals = Totals()
+        pw.println("Notification View Usage")
+        pw.println("-----------")
+        pw.println("View Type".padEnd(24) + "\tSmall\tLarge\tStyle\tCustom\tSoftware")
+        pw.println("".padEnd(24) + "\tIcon\tIcon\tUse\tView\tBitmaps")
+        pw.println()
+        memoryUse
+            .filter { it.viewUsage.isNotEmpty() }
+            .forEach { use ->
+                pw.println(use.packageName + " " + use.notificationKey)
+                use.viewUsage.forEach { view ->
+                    pw.println(
+                        "  ${view.viewType.toString().padEnd(24)}\t${view.smallIcon}" +
+                            "\t${view.largeIcon}\t${view.style}" +
+                            "\t${view.customViews}\t${view.softwareBitmapsPenalty}"
+                    )
+
+                    if (view.viewType == ViewType.TOTAL) {
+                        totals.smallIcon += view.smallIcon
+                        totals.largeIcon += view.largeIcon
+                        totals.style += view.style
+                        totals.customViews += view.customViews
+                        totals.softwareBitmapsPenalty += view.softwareBitmapsPenalty
+                    }
+                }
+            }
+        pw.println()
+        pw.println("TOTALS")
+        pw.println(
+            "  ${"".padEnd(24)}\t${toKb(totals.smallIcon)}" +
+                "\t${toKb(totals.largeIcon)}\t${toKb(totals.style)}" +
+                "\t${toKb(totals.customViews)}\t${toKb(totals.softwareBitmapsPenalty)}"
+        )
+        pw.println()
+    }
+
+    private fun styleEnumToString(styleEnum: Int): String =
+        when (styleEnum) {
+            NotificationEnums.STYLE_UNSPECIFIED -> "Unspecified"
+            NotificationEnums.STYLE_NONE -> "None"
+            NotificationEnums.STYLE_BIG_PICTURE -> "BigPicture"
+            NotificationEnums.STYLE_BIG_TEXT -> "BigText"
+            NotificationEnums.STYLE_CALL -> "Call"
+            NotificationEnums.STYLE_DECORATED_CUSTOM_VIEW -> "DCustomView"
+            NotificationEnums.STYLE_INBOX -> "Inbox"
+            NotificationEnums.STYLE_MEDIA -> "Media"
+            NotificationEnums.STYLE_MESSAGING -> "Messaging"
+            NotificationEnums.STYLE_RANKER_GROUP -> "RankerGroup"
+            else -> "Unknown"
+        }
+
+    private fun toKb(bytes: Int): String {
+        return (bytes / 1024).toString() + " KB"
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryLogger.kt
new file mode 100644
index 0000000..ec8501a
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryLogger.kt
@@ -0,0 +1,194 @@
+/*
+ *
+ * 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.systemui.statusbar.notification.logging
+
+import android.app.StatsManager
+import android.util.StatsEvent
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.dagger.qualifiers.Background
+import com.android.systemui.dagger.qualifiers.Main
+import com.android.systemui.shared.system.SysUiStatsLog
+import com.android.systemui.statusbar.notification.collection.NotifPipeline
+import com.android.systemui.util.traceSection
+import java.util.concurrent.Executor
+import javax.inject.Inject
+import kotlin.math.roundToInt
+import kotlinx.coroutines.CoroutineDispatcher
+import kotlinx.coroutines.runBlocking
+
+/** Periodically logs current state of notification memory consumption. */
+@SysUISingleton
+class NotificationMemoryLogger
+@Inject
+constructor(
+    private val notificationPipeline: NotifPipeline,
+    private val statsManager: StatsManager,
+    @Main private val mainDispatcher: CoroutineDispatcher,
+    @Background private val backgroundExecutor: Executor
+) : StatsManager.StatsPullAtomCallback {
+
+    /**
+     * This class is used to accumulate and aggregate data - the fields mirror values in statd Atom
+     * with ONE IMPORTANT difference - the values are in bytes, not KB!
+     */
+    internal data class NotificationMemoryUseAtomBuilder(val uid: Int, val style: Int) {
+        var count: Int = 0
+        var countWithInflatedViews: Int = 0
+        var smallIconObject: Int = 0
+        var smallIconBitmapCount: Int = 0
+        var largeIconObject: Int = 0
+        var largeIconBitmapCount: Int = 0
+        var bigPictureObject: Int = 0
+        var bigPictureBitmapCount: Int = 0
+        var extras: Int = 0
+        var extenders: Int = 0
+        var smallIconViews: Int = 0
+        var largeIconViews: Int = 0
+        var systemIconViews: Int = 0
+        var styleViews: Int = 0
+        var customViews: Int = 0
+        var softwareBitmaps: Int = 0
+        var seenCount = 0
+    }
+
+    fun init() {
+        statsManager.setPullAtomCallback(
+            SysUiStatsLog.NOTIFICATION_MEMORY_USE,
+            null,
+            backgroundExecutor,
+            this
+        )
+    }
+
+    /** Called by statsd to pull data. */
+    override fun onPullAtom(atomTag: Int, data: MutableList<StatsEvent>): Int =
+        traceSection("NML#onPullAtom") {
+            if (atomTag != SysUiStatsLog.NOTIFICATION_MEMORY_USE) {
+                return StatsManager.PULL_SKIP
+            }
+
+            // Notifications can only be retrieved on the main thread, so switch to that thread.
+            val notifications = getAllNotificationsOnMainThread()
+            val notificationMemoryUse =
+                NotificationMemoryMeter.notificationMemoryUse(notifications)
+                    .sortedWith(
+                        compareBy(
+                            { it.packageName },
+                            { it.objectUsage.style },
+                            { it.notificationKey }
+                        )
+                    )
+            val usageData = aggregateMemoryUsageData(notificationMemoryUse)
+            usageData.forEach { (_, use) ->
+                data.add(
+                    SysUiStatsLog.buildStatsEvent(
+                        SysUiStatsLog.NOTIFICATION_MEMORY_USE,
+                        use.uid,
+                        use.style,
+                        use.count,
+                        use.countWithInflatedViews,
+                        toKb(use.smallIconObject),
+                        use.smallIconBitmapCount,
+                        toKb(use.largeIconObject),
+                        use.largeIconBitmapCount,
+                        toKb(use.bigPictureObject),
+                        use.bigPictureBitmapCount,
+                        toKb(use.extras),
+                        toKb(use.extenders),
+                        toKb(use.smallIconViews),
+                        toKb(use.largeIconViews),
+                        toKb(use.systemIconViews),
+                        toKb(use.styleViews),
+                        toKb(use.customViews),
+                        toKb(use.softwareBitmaps),
+                        use.seenCount
+                    )
+                )
+            }
+
+            return StatsManager.PULL_SUCCESS
+        }
+
+    private fun getAllNotificationsOnMainThread() =
+        runBlocking(mainDispatcher) {
+            traceSection("NML#getNotifications") { notificationPipeline.allNotifs }
+        }
+
+    /** Aggregates memory usage data by package and style, returning sums. */
+    private fun aggregateMemoryUsageData(
+        notificationMemoryUse: List<NotificationMemoryUsage>
+    ): Map<Pair<String, Int>, NotificationMemoryUseAtomBuilder> {
+        return notificationMemoryUse
+            .groupingBy { Pair(it.packageName, it.objectUsage.style) }
+            .aggregate {
+                _,
+                accumulator: NotificationMemoryUseAtomBuilder?,
+                element: NotificationMemoryUsage,
+                first ->
+                val use =
+                    if (first) {
+                        NotificationMemoryUseAtomBuilder(element.uid, element.objectUsage.style)
+                    } else {
+                        accumulator!!
+                    }
+
+                use.count++
+                // If the views of the notification weren't inflated, the list of memory usage
+                // parameters will be empty.
+                if (element.viewUsage.isNotEmpty()) {
+                    use.countWithInflatedViews++
+                }
+
+                use.smallIconObject += element.objectUsage.smallIcon
+                if (element.objectUsage.smallIcon > 0) {
+                    use.smallIconBitmapCount++
+                }
+
+                use.largeIconObject += element.objectUsage.largeIcon
+                if (element.objectUsage.largeIcon > 0) {
+                    use.largeIconBitmapCount++
+                }
+
+                use.bigPictureObject += element.objectUsage.bigPicture
+                if (element.objectUsage.bigPicture > 0) {
+                    use.bigPictureBitmapCount++
+                }
+
+                use.extras += element.objectUsage.extras
+                use.extenders += element.objectUsage.extender
+
+                // Use totals count which are more accurate when aggregated
+                // in this manner.
+                element.viewUsage
+                    .firstOrNull { vu -> vu.viewType == ViewType.TOTAL }
+                    ?.let {
+                        use.smallIconViews += it.smallIcon
+                        use.largeIconViews += it.largeIcon
+                        use.systemIconViews += it.systemIcons
+                        use.styleViews += it.style
+                        use.customViews += it.style
+                        use.softwareBitmaps += it.softwareBitmapsPenalty
+                    }
+
+                return@aggregate use
+            }
+    }
+
+    /** Rounds the passed value to the nearest KB - e.g. 700B rounds to 1KB. */
+    private fun toKb(value: Int): Int = (value.toFloat() / 1024f).roundToInt()
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryMeter.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryMeter.kt
index 7d39e18..41fb91e 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryMeter.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryMeter.kt
@@ -1,12 +1,20 @@
 package com.android.systemui.statusbar.notification.logging
 
 import android.app.Notification
+import android.app.Notification.BigPictureStyle
+import android.app.Notification.BigTextStyle
+import android.app.Notification.CallStyle
+import android.app.Notification.DecoratedCustomViewStyle
+import android.app.Notification.InboxStyle
+import android.app.Notification.MediaStyle
+import android.app.Notification.MessagingStyle
 import android.app.Person
 import android.graphics.Bitmap
 import android.graphics.drawable.Icon
 import android.os.Bundle
 import android.os.Parcel
 import android.os.Parcelable
+import android.stats.sysui.NotificationEnums
 import androidx.annotation.WorkerThread
 import com.android.systemui.statusbar.notification.NotificationUtils
 import com.android.systemui.statusbar.notification.collection.NotificationEntry
@@ -19,6 +27,7 @@
     private const val TV_EXTENSIONS = "android.tv.EXTENSIONS"
     private const val WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"
     private const val WEARABLE_EXTENSIONS_BACKGROUND = "background"
+    private const val AUTOGROUP_KEY = "ranker_group"
 
     /** Returns a list of memory use entries for currently shown notifications. */
     @WorkerThread
@@ -29,12 +38,15 @@
             .asSequence()
             .map { entry ->
                 val packageName = entry.sbn.packageName
+                val uid = entry.sbn.uid
                 val notificationObjectUsage =
                     notificationMemoryUse(entry.sbn.notification, hashSetOf())
                 val notificationViewUsage = NotificationMemoryViewWalker.getViewUsage(entry.row)
                 NotificationMemoryUsage(
                     packageName,
+                    uid,
                     NotificationUtils.logKey(entry.sbn.key),
+                    entry.sbn.notification,
                     notificationObjectUsage,
                     notificationViewUsage
                 )
@@ -49,7 +61,9 @@
     ): NotificationMemoryUsage {
         return NotificationMemoryUsage(
             entry.sbn.packageName,
+            entry.sbn.uid,
             NotificationUtils.logKey(entry.sbn.key),
+            entry.sbn.notification,
             notificationMemoryUse(entry.sbn.notification, seenBitmaps),
             NotificationMemoryViewWalker.getViewUsage(entry.row)
         )
@@ -116,7 +130,13 @@
         val wearExtenderBackground =
             computeParcelableUse(wearExtender, WEARABLE_EXTENSIONS_BACKGROUND, seenBitmaps)
 
-        val style = notification.notificationStyle
+        val style =
+            if (notification.group == AUTOGROUP_KEY) {
+                NotificationEnums.STYLE_RANKER_GROUP
+            } else {
+                styleEnum(notification.notificationStyle)
+            }
+
         val hasCustomView = notification.contentView != null || notification.bigContentView != null
         val extrasSize = computeBundleSize(extras)
 
@@ -124,7 +144,7 @@
             smallIcon = smallIconUse,
             largeIcon = largeIconUse,
             extras = extrasSize,
-            style = style?.simpleName,
+            style = style,
             styleIcon =
                 bigPictureIconUse +
                     peopleUse +
@@ -144,6 +164,25 @@
     }
 
     /**
+     * Returns logging style enum based on current style class.
+     *
+     * @return style value in [NotificationEnums]
+     */
+    private fun styleEnum(style: Class<out Notification.Style>?): Int =
+        when (style?.name) {
+            null -> NotificationEnums.STYLE_NONE
+            BigTextStyle::class.java.name -> NotificationEnums.STYLE_BIG_TEXT
+            BigPictureStyle::class.java.name -> NotificationEnums.STYLE_BIG_PICTURE
+            InboxStyle::class.java.name -> NotificationEnums.STYLE_INBOX
+            MediaStyle::class.java.name -> NotificationEnums.STYLE_MEDIA
+            DecoratedCustomViewStyle::class.java.name ->
+                NotificationEnums.STYLE_DECORATED_CUSTOM_VIEW
+            MessagingStyle::class.java.name -> NotificationEnums.STYLE_MESSAGING
+            CallStyle::class.java.name -> NotificationEnums.STYLE_CALL
+            else -> NotificationEnums.STYLE_UNSPECIFIED
+        }
+
+    /**
      * Calculates size of the bundle data (excluding FDs and other shared objects like ashmem
      * bitmaps). Can be slow.
      */
@@ -176,7 +215,7 @@
      *
      * @return memory usage in bytes or 0 if the icon is Uri/Resource based
      */
-    private fun computeIconUse(icon: Icon?, seenBitmaps: HashSet<Int>) =
+    private fun computeIconUse(icon: Icon?, seenBitmaps: HashSet<Int>): Int =
         when (icon?.type) {
             Icon.TYPE_BITMAP -> computeBitmapUse(icon.bitmap, seenBitmaps)
             Icon.TYPE_ADAPTIVE_BITMAP -> computeBitmapUse(icon.bitmap, seenBitmaps)
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryMonitor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryMonitor.kt
index c09cc43..f38c1e5 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryMonitor.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryMonitor.kt
@@ -18,11 +18,10 @@
 package com.android.systemui.statusbar.notification.logging
 
 import android.util.Log
-import com.android.systemui.Dumpable
 import com.android.systemui.dagger.SysUISingleton
-import com.android.systemui.dump.DumpManager
-import com.android.systemui.statusbar.notification.collection.NotifPipeline
-import java.io.PrintWriter
+import com.android.systemui.flags.FeatureFlags
+import com.android.systemui.flags.Flags
+import dagger.Lazy
 import javax.inject.Inject
 
 /** This class monitors and logs current Notification memory use. */
@@ -30,9 +29,10 @@
 class NotificationMemoryMonitor
 @Inject
 constructor(
-    val notificationPipeline: NotifPipeline,
-    val dumpManager: DumpManager,
-) : Dumpable {
+    private val featureFlags: FeatureFlags,
+    private val notificationMemoryDumper: NotificationMemoryDumper,
+    private val notificationMemoryLogger: Lazy<NotificationMemoryLogger>,
+) {
 
     companion object {
         private const val TAG = "NotificationMemory"
@@ -40,127 +40,10 @@
 
     fun init() {
         Log.d(TAG, "NotificationMemoryMonitor initialized.")
-        dumpManager.registerDumpable(javaClass.simpleName, this)
-    }
-
-    override fun dump(pw: PrintWriter, args: Array<out String>) {
-        val memoryUse =
-            NotificationMemoryMeter.notificationMemoryUse(notificationPipeline.allNotifs)
-                .sortedWith(compareBy({ it.packageName }, { it.notificationKey }))
-        dumpNotificationObjects(pw, memoryUse)
-        dumpNotificationViewUsage(pw, memoryUse)
-    }
-
-    /** Renders a table of notification object usage into passed [PrintWriter]. */
-    private fun dumpNotificationObjects(pw: PrintWriter, memoryUse: List<NotificationMemoryUsage>) {
-        pw.println("Notification Object Usage")
-        pw.println("-----------")
-        pw.println(
-            "Package".padEnd(35) +
-                "\t\tSmall\tLarge\t${"Style".padEnd(15)}\t\tStyle\tBig\tExtend.\tExtras\tCustom"
-        )
-        pw.println("".padEnd(35) + "\t\tIcon\tIcon\t${"".padEnd(15)}\t\tIcon\tPicture\t \t \tView")
-        pw.println()
-
-        memoryUse.forEach { use ->
-            pw.println(
-                use.packageName.padEnd(35) +
-                    "\t\t" +
-                    "${use.objectUsage.smallIcon}\t${use.objectUsage.largeIcon}\t" +
-                    (use.objectUsage.style?.take(15) ?: "").padEnd(15) +
-                    "\t\t${use.objectUsage.styleIcon}\t" +
-                    "${use.objectUsage.bigPicture}\t${use.objectUsage.extender}\t" +
-                    "${use.objectUsage.extras}\t${use.objectUsage.hasCustomView}\t" +
-                    use.notificationKey
-            )
+        notificationMemoryDumper.init()
+        if (featureFlags.isEnabled(Flags.NOTIFICATION_MEMORY_LOGGING_ENABLED)) {
+            Log.d(TAG, "Notification memory logging enabled.")
+            notificationMemoryLogger.get().init()
         }
-
-        // Calculate totals for easily glanceable summary.
-        data class Totals(
-            var smallIcon: Int = 0,
-            var largeIcon: Int = 0,
-            var styleIcon: Int = 0,
-            var bigPicture: Int = 0,
-            var extender: Int = 0,
-            var extras: Int = 0,
-        )
-
-        val totals =
-            memoryUse.fold(Totals()) { t, usage ->
-                t.smallIcon += usage.objectUsage.smallIcon
-                t.largeIcon += usage.objectUsage.largeIcon
-                t.styleIcon += usage.objectUsage.styleIcon
-                t.bigPicture += usage.objectUsage.bigPicture
-                t.extender += usage.objectUsage.extender
-                t.extras += usage.objectUsage.extras
-                t
-            }
-
-        pw.println()
-        pw.println("TOTALS")
-        pw.println(
-            "".padEnd(35) +
-                "\t\t" +
-                "${toKb(totals.smallIcon)}\t${toKb(totals.largeIcon)}\t" +
-                "".padEnd(15) +
-                "\t\t${toKb(totals.styleIcon)}\t" +
-                "${toKb(totals.bigPicture)}\t${toKb(totals.extender)}\t" +
-                toKb(totals.extras)
-        )
-        pw.println()
-    }
-
-    /** Renders a table of notification view usage into passed [PrintWriter] */
-    private fun dumpNotificationViewUsage(
-        pw: PrintWriter,
-        memoryUse: List<NotificationMemoryUsage>,
-    ) {
-
-        data class Totals(
-            var smallIcon: Int = 0,
-            var largeIcon: Int = 0,
-            var style: Int = 0,
-            var customViews: Int = 0,
-            var softwareBitmapsPenalty: Int = 0,
-        )
-
-        val totals = Totals()
-        pw.println("Notification View Usage")
-        pw.println("-----------")
-        pw.println("View Type".padEnd(24) + "\tSmall\tLarge\tStyle\tCustom\tSoftware")
-        pw.println("".padEnd(24) + "\tIcon\tIcon\tUse\tView\tBitmaps")
-        pw.println()
-        memoryUse
-            .filter { it.viewUsage.isNotEmpty() }
-            .forEach { use ->
-                pw.println(use.packageName + " " + use.notificationKey)
-                use.viewUsage.forEach { view ->
-                    pw.println(
-                        "  ${view.viewType.toString().padEnd(24)}\t${view.smallIcon}" +
-                            "\t${view.largeIcon}\t${view.style}" +
-                            "\t${view.customViews}\t${view.softwareBitmapsPenalty}"
-                    )
-
-                    if (view.viewType == ViewType.TOTAL) {
-                        totals.smallIcon += view.smallIcon
-                        totals.largeIcon += view.largeIcon
-                        totals.style += view.style
-                        totals.customViews += view.customViews
-                        totals.softwareBitmapsPenalty += view.softwareBitmapsPenalty
-                    }
-                }
-            }
-        pw.println()
-        pw.println("TOTALS")
-        pw.println(
-            "  ${"".padEnd(24)}\t${toKb(totals.smallIcon)}" +
-                "\t${toKb(totals.largeIcon)}\t${toKb(totals.style)}" +
-                "\t${toKb(totals.customViews)}\t${toKb(totals.softwareBitmapsPenalty)}"
-        )
-        pw.println()
-    }
-
-    private fun toKb(bytes: Int): String {
-        return (bytes / 1024).toString() + " KB"
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryViewWalker.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryViewWalker.kt
index a0bee15..2d04211 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryViewWalker.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryViewWalker.kt
@@ -50,7 +50,11 @@
 
     /**
      * Returns memory usage of public and private views contained in passed
-     * [ExpandableNotificationRow]
+     * [ExpandableNotificationRow]. Each entry will correspond to one of the [ViewType] values with
+     * [ViewType.TOTAL] totalling all memory use. If a type of view is missing, the corresponding
+     * entry will not appear in resulting list.
+     *
+     * This will return an empty list if the ExpandableNotificationRow has no views inflated.
      */
     fun getViewUsage(row: ExpandableNotificationRow?): List<NotificationViewUsage> {
         if (row == null) {
@@ -58,42 +62,72 @@
         }
 
         // The ordering here is significant since it determines deduplication of seen drawables.
-        return listOf(
-            getViewUsage(ViewType.PRIVATE_EXPANDED_VIEW, row.privateLayout?.expandedChild),
-            getViewUsage(ViewType.PRIVATE_CONTRACTED_VIEW, row.privateLayout?.contractedChild),
-            getViewUsage(ViewType.PRIVATE_HEADS_UP_VIEW, row.privateLayout?.headsUpChild),
-            getViewUsage(ViewType.PUBLIC_VIEW, row.publicLayout),
-            getTotalUsage(row)
-        )
+        val perViewUsages =
+            listOf(
+                    getViewUsage(ViewType.PRIVATE_EXPANDED_VIEW, row.privateLayout?.expandedChild),
+                    getViewUsage(
+                        ViewType.PRIVATE_CONTRACTED_VIEW,
+                        row.privateLayout?.contractedChild
+                    ),
+                    getViewUsage(ViewType.PRIVATE_HEADS_UP_VIEW, row.privateLayout?.headsUpChild),
+                    getViewUsage(
+                        ViewType.PUBLIC_VIEW,
+                        row.publicLayout?.expandedChild,
+                        row.publicLayout?.contractedChild,
+                        row.publicLayout?.headsUpChild
+                    ),
+                )
+                .filterNotNull()
+
+        return if (perViewUsages.isNotEmpty()) {
+            // Attach summed totals field only if there was any view actually measured.
+            // This reduces bug report noise and makes checks for collapsed views easier.
+            val totals = getTotalUsage(row)
+            if (totals == null) {
+                perViewUsages
+            } else {
+                perViewUsages + totals
+            }
+        } else {
+            listOf()
+        }
     }
 
     /**
      * Calculate total usage of all views - we need to do a separate traversal to make sure we don't
      * double count fields.
      */
-    private fun getTotalUsage(row: ExpandableNotificationRow): NotificationViewUsage {
-        val totalUsage = UsageBuilder()
+    private fun getTotalUsage(row: ExpandableNotificationRow): NotificationViewUsage? {
         val seenObjects = hashSetOf<Int>()
-
-        row.publicLayout?.let { computeViewHierarchyUse(it, totalUsage, seenObjects) }
-        row.privateLayout?.let { child ->
-            for (view in listOf(child.expandedChild, child.contractedChild, child.headsUpChild)) {
-                (view as? ViewGroup)?.let { v ->
-                    computeViewHierarchyUse(v, totalUsage, seenObjects)
-                }
-            }
-        }
-        return totalUsage.build(ViewType.TOTAL)
+        return getViewUsage(
+            ViewType.TOTAL,
+            row.privateLayout?.expandedChild,
+            row.privateLayout?.contractedChild,
+            row.privateLayout?.headsUpChild,
+            row.publicLayout?.expandedChild,
+            row.publicLayout?.contractedChild,
+            row.publicLayout?.headsUpChild,
+            seenObjects = seenObjects
+        )
     }
 
     private fun getViewUsage(
         type: ViewType,
-        rootView: View?,
+        vararg rootViews: View?,
         seenObjects: HashSet<Int> = hashSetOf()
-    ): NotificationViewUsage {
-        val usageBuilder = UsageBuilder()
-        (rootView as? ViewGroup)?.let { computeViewHierarchyUse(it, usageBuilder, seenObjects) }
-        return usageBuilder.build(type)
+    ): NotificationViewUsage? {
+        val usageBuilder = lazy { UsageBuilder() }
+        rootViews.forEach { rootView ->
+            (rootView as? ViewGroup)?.let { rootViewGroup ->
+                computeViewHierarchyUse(rootViewGroup, usageBuilder.value, seenObjects)
+            }
+        }
+
+        return if (usageBuilder.isInitialized()) {
+            usageBuilder.value.build(type)
+        } else {
+            null
+        }
     }
 
     private fun computeViewHierarchyUse(
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithm.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithm.java
index aff7b4c..b6cf948 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithm.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithm.java
@@ -871,8 +871,7 @@
         }
 
         for (int i = childCount - 1; i >= 0; i--) {
-            childrenOnTop = updateChildZValue(i, childrenOnTop,
-                    algorithmState, ambientState, i == topHunIndex);
+            updateChildZValue(i, algorithmState, ambientState, i == topHunIndex);
         }
     }
 
@@ -882,15 +881,11 @@
      *
      * @param isTopHun      Whether the child is a top HUN. A top HUN means a HUN that shows on the
      *                      vertically top of screen. Top HUNs should have drop shadows
-     * @param childrenOnTop It is greater than 0 when there's an existing HUN that is elevated
-     * @return childrenOnTop The decimal part represents the fraction of the elevated HUN's height
-     *                      that overlaps with QQS Panel. The integer part represents the count of
-     *                      previous HUNs whose Z positions are greater than 0.
      */
-    protected float updateChildZValue(int i, float childrenOnTop,
-                                      StackScrollAlgorithmState algorithmState,
-                                      AmbientState ambientState,
-                                      boolean isTopHun) {
+    protected void updateChildZValue(int i,
+                                     StackScrollAlgorithmState algorithmState,
+                                     AmbientState ambientState,
+                                     boolean isTopHun) {
         ExpandableView child = algorithmState.visibleChildren.get(i);
         ExpandableViewState childViewState = child.getViewState();
         float baseZ = ambientState.getBaseZHeight();
@@ -904,22 +899,16 @@
             // Handles HUN shadow when Shade is opened, and AmbientState.mScrollY > 0
             // Calculate the HUN's z-value based on its overlapping fraction with QQS Panel.
             // When scrolling down shade to make HUN back to in-position in Notification Panel,
-            // The over-lapping fraction goes to 0, and shadows hides gradually.
-            if (childrenOnTop != 0.0f) {
-                // To elevate the later HUN over previous HUN
-                childrenOnTop++;
-            } else {
-                float overlap = ambientState.getTopPadding()
-                        + ambientState.getStackTranslation() - childViewState.getYTranslation();
-                // To prevent over-shadow during HUN entry
-                childrenOnTop += Math.min(
-                        1.0f,
-                        overlap / childViewState.height
-                );
-                MathUtils.saturate(childrenOnTop);
+            // the overlapFraction goes to 0, and the pinned HUN's shadows hides gradually.
+            float overlap = ambientState.getTopPadding()
+                    + ambientState.getStackTranslation() - childViewState.getYTranslation();
+
+            if (childViewState.height > 0) { // To avoid 0/0 problems
+                // To prevent over-shadow
+                float overlapFraction = MathUtils.saturate(overlap / childViewState.height);
+                childViewState.setZTranslation(baseZ
+                        + overlapFraction * mPinnedZTranslationExtra);
             }
-            childViewState.setZTranslation(baseZ
-                    + childrenOnTop * mPinnedZTranslationExtra);
         } else if (isTopHun) {
             // In case this is a new view that has never been measured before, we don't want to
             // elevate if we are currently expanded more than the notification
@@ -947,15 +936,14 @@
         }
 
         // Handles HUN shadow when shade is closed.
-        // While HUN is showing and Shade is closed: headerVisibleAmount stays 0, shadow stays.
+        // While shade is closed, and during HUN's entry: headerVisibleAmount stays 0, shadow stays.
+        // While shade is closed, and HUN is showing: headerVisibleAmount stays 0, shadow stays.
         // During HUN-to-Shade (eg. dragging down HUN to open Shade): headerVisibleAmount goes
         // gradually from 0 to 1, shadow hides gradually.
         // Header visibility is a deprecated concept, we are using headerVisibleAmount only because
         // this value nicely goes from 0 to 1 during the HUN-to-Shade process.
-
         childViewState.setZTranslation(childViewState.getZTranslation()
                 + (1.0f - child.getHeaderVisibleAmount()) * mPinnedZTranslationExtra);
-        return childrenOnTop;
     }
 
     public void setIsExpanded(boolean isExpanded) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesCommandQueueCallbacks.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesCommandQueueCallbacks.java
index 6b72e96..936589c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesCommandQueueCallbacks.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesCommandQueueCallbacks.java
@@ -371,6 +371,7 @@
 
         if (!mKeyguardStateController.isShowing()) {
             final Intent cameraIntent = CameraIntents.getInsecureCameraIntent(mContext);
+            cameraIntent.putExtra(CameraIntents.EXTRA_LAUNCH_SOURCE, source);
             mCentralSurfaces.startActivityDismissingKeyguard(cameraIntent,
                     false /* onlyProvisioned */, true /* dismissShade */,
                     true /* disallowEnterPictureInPictureWhileLaunching */, null /* callback */, 0,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/DemoStatusIcons.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/DemoStatusIcons.java
index 1169d3f..c7be219 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/DemoStatusIcons.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/DemoStatusIcons.java
@@ -40,6 +40,8 @@
 import com.android.systemui.statusbar.connectivity.ui.MobileContextProvider;
 import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.MobileIconState;
 import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.WifiIconState;
+import com.android.systemui.statusbar.pipeline.mobile.ui.view.ModernStatusBarMobileView;
+import com.android.systemui.statusbar.pipeline.mobile.ui.viewmodel.MobileIconsViewModel;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -50,20 +52,25 @@
 
     private final LinearLayout mStatusIcons;
     private final ArrayList<StatusBarMobileView> mMobileViews = new ArrayList<>();
+    private final ArrayList<ModernStatusBarMobileView> mModernMobileViews = new ArrayList<>();
     private final int mIconSize;
 
     private StatusBarWifiView mWifiView;
     private boolean mDemoMode;
     private int mColor;
 
+    private final MobileIconsViewModel mMobileIconsViewModel;
+
     public DemoStatusIcons(
             LinearLayout statusIcons,
+            MobileIconsViewModel mobileIconsViewModel,
             int iconSize
     ) {
         super(statusIcons.getContext());
         mStatusIcons = statusIcons;
         mIconSize = iconSize;
         mColor = DarkIconDispatcher.DEFAULT_ICON_TINT;
+        mMobileIconsViewModel = mobileIconsViewModel;
 
         if (statusIcons instanceof StatusIconContainer) {
             setShouldRestrictIcons(((StatusIconContainer) statusIcons).isRestrictingIcons());
@@ -71,7 +78,7 @@
             setShouldRestrictIcons(false);
         }
         setLayoutParams(mStatusIcons.getLayoutParams());
-        setPadding(mStatusIcons.getPaddingLeft(),mStatusIcons.getPaddingTop(),
+        setPadding(mStatusIcons.getPaddingLeft(), mStatusIcons.getPaddingTop(),
                 mStatusIcons.getPaddingRight(), mStatusIcons.getPaddingBottom());
         setOrientation(mStatusIcons.getOrientation());
         setGravity(Gravity.CENTER_VERTICAL); // no LL.getGravity()
@@ -115,6 +122,8 @@
     public void onDemoModeFinished() {
         mDemoMode = false;
         mStatusIcons.setVisibility(View.VISIBLE);
+        mModernMobileViews.clear();
+        mMobileViews.clear();
         setVisibility(View.GONE);
     }
 
@@ -269,6 +278,24 @@
     }
 
     /**
+     * Add a {@link ModernStatusBarMobileView}
+     * @param mobileContext possibly mcc/mnc overridden mobile context
+     * @param subId the subscriptionId for this mobile view
+     */
+    public void addModernMobileView(Context mobileContext, int subId) {
+        Log.d(TAG, "addModernMobileView (subId=" + subId + ")");
+        ModernStatusBarMobileView view = ModernStatusBarMobileView.constructAndBind(
+                mobileContext,
+                "mobile",
+                mMobileIconsViewModel.viewModelForSub(subId)
+        );
+
+        // mobile always goes at the end
+        mModernMobileViews.add(view);
+        addView(view, getChildCount(), createLayoutParams());
+    }
+
+    /**
      * Apply an update to a mobile icon view for the given {@link MobileIconState}. For
      * compatibility with {@link MobileContextProvider}, we have to recreate the view every time we
      * update it, since the context (and thus the {@link Configuration}) may have changed
@@ -292,12 +319,19 @@
         if (view.getSlot().equals("wifi")) {
             removeView(mWifiView);
             mWifiView = null;
-        } else {
+        } else if (view instanceof StatusBarMobileView) {
             StatusBarMobileView mobileView = matchingMobileView(view);
             if (mobileView != null) {
                 removeView(mobileView);
                 mMobileViews.remove(mobileView);
             }
+        } else if (view instanceof ModernStatusBarMobileView) {
+            ModernStatusBarMobileView mobileView = matchingModernMobileView(
+                    (ModernStatusBarMobileView) view);
+            if (mobileView != null) {
+                removeView(mobileView);
+                mModernMobileViews.remove(mobileView);
+            }
         }
     }
 
@@ -316,6 +350,16 @@
         return null;
     }
 
+    private ModernStatusBarMobileView matchingModernMobileView(ModernStatusBarMobileView other) {
+        for (ModernStatusBarMobileView v : mModernMobileViews) {
+            if (v.getSubId() == other.getSubId()) {
+                return v;
+            }
+        }
+
+        return null;
+    }
+
     private LayoutParams createLayoutParams() {
         return new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, mIconSize);
     }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceController.java
index c217ab3..69f7c71 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceController.java
@@ -22,6 +22,8 @@
 import android.util.MathUtils;
 import android.view.View;
 
+import androidx.annotation.NonNull;
+
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.widget.ViewClippingUtil;
 import com.android.systemui.R;
@@ -197,6 +199,11 @@
         updateHeadsUpAndPulsingRoundness(entry);
     }
 
+    @Override
+    public void onHeadsUpStateChanged(@NonNull NotificationEntry entry, boolean isHeadsUp) {
+        updateHeadsUpAndPulsingRoundness(entry);
+    }
+
     private void updateTopEntry() {
         NotificationEntry newEntry = null;
         if (shouldBeVisible()) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewController.java
index d4dc1dc..3483574 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewController.java
@@ -475,9 +475,6 @@
             newAlpha = Math.min(getKeyguardContentsAlpha(), alphaQsExpansion)
                     * mKeyguardStatusBarAnimateAlpha
                     * (1.0f - mKeyguardHeadsUpShowingAmount);
-            if (newAlpha != mView.getAlpha() && (newAlpha == 0 || newAlpha == 1)) {
-                mLogger.logStatusBarCalculatedAlpha(newAlpha);
-            }
         }
 
         boolean hideForBypass =
@@ -500,10 +497,6 @@
         if (mDisableStateTracker.isDisabled()) {
             visibility = View.INVISIBLE;
         }
-        if (visibility != mView.getVisibility()) {
-            mLogger.logStatusBarAlphaVisibility(visibility, alpha,
-                    StatusBarState.toString(mStatusBarState));
-        }
         mView.setAlpha(alpha);
         mView.setVisibility(visibility);
     }
@@ -608,10 +601,6 @@
      * @param alpha a value between 0 and 1. -1 if the value is to be reset/ignored.
      */
     public void setAlpha(float alpha) {
-        if (mExplicitAlpha != alpha && (mExplicitAlpha == -1 || alpha == -1)) {
-            // logged if value changed to ignored or from ignored
-            mLogger.logStatusBarExplicitAlpha(alpha);
-        }
         mExplicitAlpha = alpha;
         updateViewState();
     }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/MultiUserSwitchController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/MultiUserSwitchController.java
deleted file mode 100644
index 5e2a7c8..0000000
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/MultiUserSwitchController.java
+++ /dev/null
@@ -1,171 +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.systemui.statusbar.phone;
-
-import static com.android.systemui.DejankUtils.whitelistIpcs;
-
-import android.content.Intent;
-import android.os.UserHandle;
-import android.os.UserManager;
-import android.view.View;
-import android.view.ViewGroup;
-
-import com.android.systemui.R;
-import com.android.systemui.animation.ActivityLaunchAnimator;
-import com.android.systemui.animation.Expandable;
-import com.android.systemui.flags.FeatureFlags;
-import com.android.systemui.flags.Flags;
-import com.android.systemui.plugins.ActivityStarter;
-import com.android.systemui.plugins.FalsingManager;
-import com.android.systemui.qs.FooterActionsView;
-import com.android.systemui.qs.dagger.QSScope;
-import com.android.systemui.qs.user.UserSwitchDialogController;
-import com.android.systemui.statusbar.policy.BaseUserSwitcherAdapter;
-import com.android.systemui.statusbar.policy.UserSwitcherController;
-import com.android.systemui.user.UserSwitcherActivity;
-import com.android.systemui.util.ViewController;
-
-import javax.inject.Inject;
-
-/** View Controller for {@link MultiUserSwitch}. */
-// TODO(b/242040009): Remove this file.
-public class MultiUserSwitchController extends ViewController<MultiUserSwitch> {
-    private final UserManager mUserManager;
-    private final UserSwitcherController mUserSwitcherController;
-    private final FalsingManager mFalsingManager;
-    private final UserSwitchDialogController mUserSwitchDialogController;
-    private final ActivityStarter mActivityStarter;
-    private final FeatureFlags mFeatureFlags;
-
-    private BaseUserSwitcherAdapter mUserListener;
-
-    private final View.OnClickListener mOnClickListener = new View.OnClickListener() {
-        @Override
-        public void onClick(View v) {
-            if (mFalsingManager.isFalseTap(FalsingManager.LOW_PENALTY)) {
-                return;
-            }
-
-            if (mFeatureFlags.isEnabled(Flags.FULL_SCREEN_USER_SWITCHER)) {
-                Intent intent = new Intent(v.getContext(), UserSwitcherActivity.class);
-                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
-
-                mActivityStarter.startActivity(intent, true /* dismissShade */,
-                        ActivityLaunchAnimator.Controller.fromView(v, null),
-                        true /* showOverlockscreenwhenlocked */, UserHandle.SYSTEM);
-            } else {
-                mUserSwitchDialogController.showDialog(v.getContext(), Expandable.fromView(v));
-            }
-        }
-    };
-
-    @QSScope
-    public static class Factory {
-        private final UserManager mUserManager;
-        private final UserSwitcherController mUserSwitcherController;
-        private final FalsingManager mFalsingManager;
-        private final UserSwitchDialogController mUserSwitchDialogController;
-        private final ActivityStarter mActivityStarter;
-        private final FeatureFlags mFeatureFlags;
-
-        @Inject
-        public Factory(UserManager userManager, UserSwitcherController userSwitcherController,
-                FalsingManager falsingManager,
-                UserSwitchDialogController userSwitchDialogController, FeatureFlags featureFlags,
-                ActivityStarter activityStarter) {
-            mUserManager = userManager;
-            mUserSwitcherController = userSwitcherController;
-            mFalsingManager = falsingManager;
-            mUserSwitchDialogController = userSwitchDialogController;
-            mActivityStarter = activityStarter;
-            mFeatureFlags = featureFlags;
-        }
-
-        public MultiUserSwitchController create(FooterActionsView view) {
-            return new MultiUserSwitchController(view.findViewById(R.id.multi_user_switch),
-                    mUserManager, mUserSwitcherController,
-                    mFalsingManager, mUserSwitchDialogController, mFeatureFlags,
-                    mActivityStarter);
-        }
-    }
-
-    private MultiUserSwitchController(MultiUserSwitch view, UserManager userManager,
-            UserSwitcherController userSwitcherController,
-            FalsingManager falsingManager, UserSwitchDialogController userSwitchDialogController,
-            FeatureFlags featureFlags, ActivityStarter activityStarter) {
-        super(view);
-        mUserManager = userManager;
-        mUserSwitcherController = userSwitcherController;
-        mFalsingManager = falsingManager;
-        mUserSwitchDialogController = userSwitchDialogController;
-        mFeatureFlags = featureFlags;
-        mActivityStarter = activityStarter;
-    }
-
-    @Override
-    protected void onInit() {
-        registerListener();
-        mView.refreshContentDescription(getCurrentUser());
-    }
-
-    @Override
-    protected void onViewAttached() {
-        mView.setOnClickListener(mOnClickListener);
-    }
-
-    @Override
-    protected void onViewDetached() {
-        mView.setOnClickListener(null);
-    }
-
-    private void registerListener() {
-        if (mUserManager.isUserSwitcherEnabled() && mUserListener == null) {
-
-            final UserSwitcherController controller = mUserSwitcherController;
-            if (controller != null) {
-                mUserListener = new BaseUserSwitcherAdapter(controller) {
-                    @Override
-                    public void notifyDataSetChanged() {
-                        mView.refreshContentDescription(getCurrentUser());
-                    }
-
-                    @Override
-                    public View getView(int position, View convertView, ViewGroup parent) {
-                        return null;
-                    }
-                };
-                mView.refreshContentDescription(getCurrentUser());
-            }
-        }
-    }
-
-    private String getCurrentUser() {
-        // TODO(b/138661450)
-        if (whitelistIpcs(() -> mUserManager.isUserSwitcherEnabled())) {
-            return mUserSwitcherController.getCurrentUserName();
-        }
-
-        return null;
-    }
-
-    /** Returns true if view should be made visible. */
-    public boolean isMultiUserEnabled() {
-        // TODO(b/138661450) Move IPC calls to background
-        return whitelistIpcs(() -> mUserManager.isUserSwitcherEnabled(
-                getResources().getBoolean(R.bool.qs_show_user_switcher_for_single_user)));
-    }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconController.java
index 0a0ded2..df3ab49 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconController.java
@@ -536,8 +536,7 @@
             mGroup.addView(view, index, onCreateLayoutParams());
 
             if (mIsInDemoMode) {
-                // TODO (b/249790009): demo mode should be handled at the data layer in the
-                //  new pipeline
+                mDemoStatusIcons.addModernMobileView(mContext, subId);
             }
 
             return view;
@@ -565,11 +564,13 @@
 
         private ModernStatusBarMobileView onCreateModernStatusBarMobileView(
                 String slot, int subId) {
+            Context mobileContext = mMobileContextProvider.getMobileContextForSub(subId, mContext);
             return ModernStatusBarMobileView
                     .constructAndBind(
-                            mContext,
+                            mobileContext,
                             slot,
-                            mMobileIconsViewModel.viewModelForSub(subId));
+                            mMobileIconsViewModel.viewModelForSub(subId)
+                        );
         }
 
         protected LinearLayout.LayoutParams onCreateLayoutParams() {
@@ -704,7 +705,7 @@
         }
 
         protected DemoStatusIcons createDemoStatusIcons() {
-            return new DemoStatusIcons((LinearLayout) mGroup, mIconSize);
+            return new DemoStatusIcons((LinearLayout) mGroup, mMobileIconsViewModel, mIconSize);
         }
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconControllerImpl.java
index 674e574..9fbe6cb 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconControllerImpl.java
@@ -276,6 +276,11 @@
         String slotName = mContext.getString(com.android.internal.R.string.status_bar_mobile);
         Slot mobileSlot = mStatusBarIconList.getSlot(slotName);
 
+        // Because of the way we cache the icon holders, we need to remove everything any time
+        // we get a new set of subscriptions. This might change in the future, but is required
+        // to support demo mode for now
+        removeAllIconsForSlot(slotName);
+
         Collections.reverse(subIds);
 
         for (Integer subId : subIds) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/MobileSubscriptionModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/MobileConnectionModel.kt
similarity index 93%
rename from packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/MobileSubscriptionModel.kt
rename to packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/MobileConnectionModel.kt
index 6341a11..1d00c33 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/MobileSubscriptionModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/MobileConnectionModel.kt
@@ -27,7 +27,6 @@
 import android.telephony.TelephonyCallback.SignalStrengthsListener
 import android.telephony.TelephonyDisplayInfo
 import android.telephony.TelephonyManager
-import android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN
 import com.android.systemui.statusbar.pipeline.mobile.data.model.DataConnectionState.Disconnected
 
 /**
@@ -39,7 +38,7 @@
  * any new field that needs to be tracked should be copied into this data class rather than
  * threading complex system objects through the pipeline.
  */
-data class MobileSubscriptionModel(
+data class MobileConnectionModel(
     /** From [ServiceStateListener.onServiceStateChanged] */
     val isEmergencyOnly: Boolean = false,
 
@@ -65,5 +64,5 @@
      * [resolvedNetworkType] is the [TelephonyDisplayInfo.getOverrideNetworkType] if it exists or
      * [TelephonyDisplayInfo.getNetworkType]. This is used to look up the proper network type icon
      */
-    val resolvedNetworkType: ResolvedNetworkType = DefaultNetworkType(NETWORK_TYPE_UNKNOWN),
+    val resolvedNetworkType: ResolvedNetworkType = ResolvedNetworkType.UnknownNetworkType,
 )
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/ResolvedNetworkType.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/ResolvedNetworkType.kt
index f385806..dd93541 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/ResolvedNetworkType.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/ResolvedNetworkType.kt
@@ -17,6 +17,7 @@
 package com.android.systemui.statusbar.pipeline.mobile.data.model
 
 import android.telephony.Annotation.NetworkType
+import android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN
 import com.android.systemui.statusbar.pipeline.mobile.util.MobileMappingsProxy
 
 /**
@@ -26,8 +27,20 @@
  */
 sealed interface ResolvedNetworkType {
     @NetworkType val type: Int
+    val lookupKey: String
+
+    object UnknownNetworkType : ResolvedNetworkType {
+        override val type: Int = NETWORK_TYPE_UNKNOWN
+        override val lookupKey: String = "unknown"
+    }
+
+    data class DefaultNetworkType(
+        @NetworkType override val type: Int,
+        override val lookupKey: String,
+    ) : ResolvedNetworkType
+
+    data class OverrideNetworkType(
+        @NetworkType override val type: Int,
+        override val lookupKey: String,
+    ) : ResolvedNetworkType
 }
-
-data class DefaultNetworkType(@NetworkType override val type: Int) : ResolvedNetworkType
-
-data class OverrideNetworkType(@NetworkType override val type: Int) : ResolvedNetworkType
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/SubscriptionModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/SubscriptionModel.kt
new file mode 100644
index 0000000..2f34516
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/model/SubscriptionModel.kt
@@ -0,0 +1,32 @@
+/*
+ * 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.systemui.statusbar.pipeline.mobile.data.model
+
+/**
+ * SystemUI representation of [SubscriptionInfo]. Currently we only use two fields on the
+ * subscriptions themselves: subscriptionId and isOpportunistic. Any new fields that we need can be
+ * added below and provided in the repository classes
+ */
+data class SubscriptionModel(
+    val subscriptionId: Int,
+    /**
+     * True if the subscription that this model represents has [SubscriptionInfo.isOpportunistic].
+     * Opportunistic networks are networks with limited coverage, and we use this bit to determine
+     * filtering in certain cases. See [MobileIconsInteractor] for the filtering logic
+     */
+    val isOpportunistic: Boolean = false,
+)
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionRepository.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionRepository.kt
index f094563..2621f997 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionRepository.kt
@@ -20,7 +20,7 @@
 import android.telephony.SubscriptionManager
 import android.telephony.TelephonyCallback
 import android.telephony.TelephonyManager
-import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileSubscriptionModel
+import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectionModel
 import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.StateFlow
 
@@ -36,11 +36,13 @@
  * eventually becomes a single icon in the status bar.
  */
 interface MobileConnectionRepository {
+    /** The subscriptionId that this connection represents */
+    val subId: Int
     /**
      * A flow that aggregates all necessary callbacks from [TelephonyCallback] into a single
      * listener + model.
      */
-    val subscriptionModelFlow: Flow<MobileSubscriptionModel>
+    val connectionInfo: Flow<MobileConnectionModel>
     /** Observable tracking [TelephonyManager.isDataConnectionAllowed] */
     val dataEnabled: StateFlow<Boolean>
     /**
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionsRepository.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionsRepository.kt
index 14200f0..aea85eb 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionsRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileConnectionsRepository.kt
@@ -17,11 +17,10 @@
 package com.android.systemui.statusbar.pipeline.mobile.data.repository
 
 import android.provider.Settings
-import android.telephony.SubscriptionInfo
 import android.telephony.SubscriptionManager
-import com.android.settingslib.mobile.MobileMappings
-import com.android.settingslib.mobile.MobileMappings.Config
+import com.android.settingslib.SignalIcon.MobileIconGroup
 import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel
+import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
 import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.StateFlow
 
@@ -31,14 +30,11 @@
  */
 interface MobileConnectionsRepository {
     /** Observable list of current mobile subscriptions */
-    val subscriptionsFlow: Flow<List<SubscriptionInfo>>
+    val subscriptions: StateFlow<List<SubscriptionModel>>
 
     /** Observable for the subscriptionId of the current mobile data connection */
     val activeMobileDataSubscriptionId: StateFlow<Int>
 
-    /** Observable for [MobileMappings.Config] tracking the defaults */
-    val defaultDataSubRatConfig: StateFlow<Config>
-
     /** Tracks [SubscriptionManager.getDefaultDataSubscriptionId] */
     val defaultDataSubId: StateFlow<Int>
 
@@ -50,4 +46,10 @@
 
     /** Observe changes to the [Settings.Global.MOBILE_DATA] setting */
     val globalMobileDataSettingChangedEvent: Flow<Unit>
+
+    /** The icon mapping from network type to [MobileIconGroup] for the default subscription */
+    val defaultMobileIconMapping: Flow<Map<String, MobileIconGroup>>
+
+    /** Fallback [MobileIconGroup] in the case where there is no icon in the mapping */
+    val defaultMobileIconGroup: Flow<MobileIconGroup>
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileRepositorySwitcher.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileRepositorySwitcher.kt
index e214005..d8e0e81 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileRepositorySwitcher.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileRepositorySwitcher.kt
@@ -17,14 +17,14 @@
 package com.android.systemui.statusbar.pipeline.mobile.data.repository
 
 import android.os.Bundle
-import android.telephony.SubscriptionInfo
 import androidx.annotation.VisibleForTesting
-import com.android.settingslib.mobile.MobileMappings
+import com.android.settingslib.SignalIcon
 import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
 import com.android.systemui.dagger.qualifiers.Application
 import com.android.systemui.demomode.DemoMode
 import com.android.systemui.demomode.DemoModeController
 import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel
+import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.demo.DemoMobileConnectionsRepository
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.prod.MobileConnectionsRepositoryImpl
 import javax.inject.Inject
@@ -109,14 +109,10 @@
             }
             .stateIn(scope, SharingStarted.WhileSubscribed(), realRepository)
 
-    override val subscriptionsFlow: StateFlow<List<SubscriptionInfo>> =
+    override val subscriptions: StateFlow<List<SubscriptionModel>> =
         activeRepo
-            .flatMapLatest { it.subscriptionsFlow }
-            .stateIn(
-                scope,
-                SharingStarted.WhileSubscribed(),
-                realRepository.subscriptionsFlow.value
-            )
+            .flatMapLatest { it.subscriptions }
+            .stateIn(scope, SharingStarted.WhileSubscribed(), realRepository.subscriptions.value)
 
     override val activeMobileDataSubscriptionId: StateFlow<Int> =
         activeRepo
@@ -127,14 +123,11 @@
                 realRepository.activeMobileDataSubscriptionId.value
             )
 
-    override val defaultDataSubRatConfig: StateFlow<MobileMappings.Config> =
-        activeRepo
-            .flatMapLatest { it.defaultDataSubRatConfig }
-            .stateIn(
-                scope,
-                SharingStarted.WhileSubscribed(),
-                realRepository.defaultDataSubRatConfig.value
-            )
+    override val defaultMobileIconMapping: Flow<Map<String, SignalIcon.MobileIconGroup>> =
+        activeRepo.flatMapLatest { it.defaultMobileIconMapping }
+
+    override val defaultMobileIconGroup: Flow<SignalIcon.MobileIconGroup> =
+        activeRepo.flatMapLatest { it.defaultMobileIconGroup }
 
     override val defaultDataSubId: StateFlow<Int> =
         activeRepo
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepository.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepository.kt
index 5f2feb2..1e7fae7 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepository.kt
@@ -17,26 +17,18 @@
 package com.android.systemui.statusbar.pipeline.mobile.data.repository.demo
 
 import android.content.Context
-import android.telephony.Annotation
-import android.telephony.SubscriptionInfo
 import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID
-import android.telephony.TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED
-import android.telephony.TelephonyManager.NETWORK_TYPE_GSM
-import android.telephony.TelephonyManager.NETWORK_TYPE_LTE
-import android.telephony.TelephonyManager.NETWORK_TYPE_NR
-import android.telephony.TelephonyManager.NETWORK_TYPE_UMTS
-import android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN
 import android.util.Log
 import com.android.settingslib.SignalIcon
 import com.android.settingslib.mobile.MobileMappings
 import com.android.settingslib.mobile.TelephonyIcons
 import com.android.systemui.dagger.qualifiers.Application
 import com.android.systemui.statusbar.pipeline.mobile.data.model.DataConnectionState
-import com.android.systemui.statusbar.pipeline.mobile.data.model.DefaultNetworkType
+import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectionModel
 import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel
-import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileSubscriptionModel
-import com.android.systemui.statusbar.pipeline.mobile.data.model.OverrideNetworkType
 import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType
+import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType.DefaultNetworkType
+import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionRepository
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionsRepository
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.demo.model.FakeNetworkEventModel
@@ -49,7 +41,9 @@
 import kotlinx.coroutines.flow.MutableSharedFlow
 import kotlinx.coroutines.flow.MutableStateFlow
 import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.StateFlow
 import kotlinx.coroutines.flow.filterNotNull
+import kotlinx.coroutines.flow.flowOf
 import kotlinx.coroutines.flow.mapLatest
 import kotlinx.coroutines.flow.onEach
 import kotlinx.coroutines.flow.stateIn
@@ -67,61 +61,40 @@
 
     private var demoCommandJob: Job? = null
 
-    private val connectionRepoCache = mutableMapOf<Int, DemoMobileConnectionRepository>()
-    private val subscriptionInfoCache = mutableMapOf<Int, SubscriptionInfo>()
+    private var connectionRepoCache = mutableMapOf<Int, DemoMobileConnectionRepository>()
+    private val subscriptionInfoCache = mutableMapOf<Int, SubscriptionModel>()
     val demoModeFinishedEvent = MutableSharedFlow<Unit>(extraBufferCapacity = 1)
 
-    private val _subscriptions = MutableStateFlow<List<SubscriptionInfo>>(listOf())
-    override val subscriptionsFlow =
+    private val _subscriptions = MutableStateFlow<List<SubscriptionModel>>(listOf())
+    override val subscriptions =
         _subscriptions
             .onEach { infos -> dropUnusedReposFromCache(infos) }
             .stateIn(scope, SharingStarted.WhileSubscribed(), _subscriptions.value)
 
-    private fun dropUnusedReposFromCache(newInfos: List<SubscriptionInfo>) {
+    private fun dropUnusedReposFromCache(newInfos: List<SubscriptionModel>) {
         // Remove any connection repository from the cache that isn't in the new set of IDs. They
         // will get garbage collected once their subscribers go away
         val currentValidSubscriptionIds = newInfos.map { it.subscriptionId }
 
-        connectionRepoCache.keys.forEach {
-            if (!currentValidSubscriptionIds.contains(it)) {
-                connectionRepoCache.remove(it)
-            }
-        }
+        connectionRepoCache =
+            connectionRepoCache
+                .filter { currentValidSubscriptionIds.contains(it.key) }
+                .toMutableMap()
     }
 
     private fun maybeCreateSubscription(subId: Int) {
         if (!subscriptionInfoCache.containsKey(subId)) {
-            createSubscriptionForSubId(subId, subId).also { subscriptionInfoCache[subId] = it }
+            SubscriptionModel(subscriptionId = subId, isOpportunistic = false).also {
+                subscriptionInfoCache[subId] = it
+            }
 
             _subscriptions.value = subscriptionInfoCache.values.toList()
         }
     }
 
-    /** Mimics the old NetworkControllerImpl for now */
-    private fun createSubscriptionForSubId(subId: Int, slotIndex: Int): SubscriptionInfo {
-        return SubscriptionInfo(
-            subId,
-            "",
-            slotIndex,
-            "",
-            "",
-            0,
-            0,
-            "",
-            0,
-            null,
-            null,
-            null,
-            "",
-            false,
-            null,
-            null,
-        )
-    }
-
     // TODO(b/261029387): add a command for this value
     override val activeMobileDataSubscriptionId =
-        subscriptionsFlow
+        subscriptions
             .mapLatest { infos ->
                 // For now, active is just the first in the list
                 infos.firstOrNull()?.subscriptionId ?: INVALID_SUBSCRIPTION_ID
@@ -129,12 +102,35 @@
             .stateIn(
                 scope,
                 SharingStarted.WhileSubscribed(),
-                subscriptionsFlow.value.firstOrNull()?.subscriptionId ?: INVALID_SUBSCRIPTION_ID
+                subscriptions.value.firstOrNull()?.subscriptionId ?: INVALID_SUBSCRIPTION_ID
             )
 
     /** Demo mode doesn't currently support modifications to the mobile mappings */
-    override val defaultDataSubRatConfig =
-        MutableStateFlow(MobileMappings.Config.readConfig(context))
+    val defaultDataSubRatConfig = MutableStateFlow(MobileMappings.Config.readConfig(context))
+
+    override val defaultMobileIconGroup = flowOf(TelephonyIcons.THREE_G)
+
+    override val defaultMobileIconMapping = MutableStateFlow(TelephonyIcons.ICON_NAME_TO_ICON)
+
+    /**
+     * In order to maintain compatibility with the old demo mode shell command API, reverse the
+     * [MobileMappings] lookup from (NetworkType: String -> Icon: MobileIconGroup), so that we can
+     * parse the string from the command line into a preferred icon group, and send _a_ valid
+     * network type for that icon through the pipeline.
+     *
+     * Note: collisions don't matter here, because the data source (the command line) only cares
+     * about the resulting icon, not the underlying network type.
+     */
+    private val mobileMappingsReverseLookup: StateFlow<Map<SignalIcon.MobileIconGroup, String>> =
+        defaultMobileIconMapping
+            .mapLatest { networkToIconMap -> networkToIconMap.reverse() }
+            .stateIn(
+                scope,
+                SharingStarted.WhileSubscribed(),
+                defaultMobileIconMapping.value.reverse()
+            )
+
+    private fun <K, V> Map<K, V>.reverse() = entries.associateBy({ it.value }) { it.key }
 
     // TODO(b/261029387): add a command for this value
     override val defaultDataSubId =
@@ -189,7 +185,7 @@
         connection.dataEnabled.value = true
         connection.isDefaultDataSubscription.value = state.dataType != null
 
-        connection.subscriptionModelFlow.value = state.toMobileSubscriptionModel()
+        connection.connectionInfo.value = state.toMobileConnectionModel()
     }
 
     private fun processDisabledMobileState(state: MobileDisabled) {
@@ -229,47 +225,36 @@
     private fun subIdsString(): String =
         _subscriptions.value.joinToString(",") { it.subscriptionId.toString() }
 
+    private fun Mobile.toMobileConnectionModel(): MobileConnectionModel {
+        return MobileConnectionModel(
+            isEmergencyOnly = false, // TODO(b/261029387): not yet supported
+            isGsm = false, // TODO(b/261029387): not yet supported
+            cdmaLevel = level ?: 0,
+            primaryLevel = level ?: 0,
+            dataConnectionState =
+                DataConnectionState.Connected, // TODO(b/261029387): not yet supported
+            dataActivityDirection = activity,
+            carrierNetworkChangeActive = carrierNetworkChange,
+            resolvedNetworkType = dataType.toResolvedNetworkType()
+        )
+    }
+
+    private fun SignalIcon.MobileIconGroup?.toResolvedNetworkType(): ResolvedNetworkType {
+        val key = mobileMappingsReverseLookup.value[this] ?: "dis"
+        return DefaultNetworkType(DEMO_NET_TYPE, key)
+    }
+
     companion object {
         private const val TAG = "DemoMobileConnectionsRepo"
 
         private const val DEFAULT_SUB_ID = 1
+
+        private const val DEMO_NET_TYPE = 1234
     }
 }
 
-private fun Mobile.toMobileSubscriptionModel(): MobileSubscriptionModel {
-    return MobileSubscriptionModel(
-        isEmergencyOnly = false, // TODO(b/261029387): not yet supported
-        isGsm = false, // TODO(b/261029387): not yet supported
-        cdmaLevel = level ?: 0,
-        primaryLevel = level ?: 0,
-        dataConnectionState = DataConnectionState.Connected, // TODO(b/261029387): not yet supported
-        dataActivityDirection = activity,
-        carrierNetworkChangeActive = carrierNetworkChange,
-        // TODO(b/261185097): once mobile mappings can be mocked at this layer, we can build our
-        //  own demo map
-        resolvedNetworkType = dataType.toResolvedNetworkType()
-    )
-}
-
-@Annotation.NetworkType
-private fun SignalIcon.MobileIconGroup?.toNetworkType(): Int =
-    when (this) {
-        TelephonyIcons.THREE_G -> NETWORK_TYPE_GSM
-        TelephonyIcons.LTE -> NETWORK_TYPE_LTE
-        TelephonyIcons.FOUR_G -> NETWORK_TYPE_UMTS
-        TelephonyIcons.NR_5G -> NETWORK_TYPE_NR
-        TelephonyIcons.NR_5G_PLUS -> OVERRIDE_NETWORK_TYPE_NR_ADVANCED
-        else -> NETWORK_TYPE_UNKNOWN
-    }
-
-private fun SignalIcon.MobileIconGroup?.toResolvedNetworkType(): ResolvedNetworkType =
-    when (this) {
-        TelephonyIcons.NR_5G_PLUS -> OverrideNetworkType(toNetworkType())
-        else -> DefaultNetworkType(toNetworkType())
-    }
-
-class DemoMobileConnectionRepository(val subId: Int) : MobileConnectionRepository {
-    override val subscriptionModelFlow = MutableStateFlow(MobileSubscriptionModel())
+class DemoMobileConnectionRepository(override val subId: Int) : MobileConnectionRepository {
+    override val connectionInfo = MutableStateFlow(MobileConnectionModel())
 
     override val dataEnabled = MutableStateFlow(true)
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryImpl.kt
index 4c1cf4a..15505fd 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryImpl.kt
@@ -27,18 +27,20 @@
 import android.telephony.TelephonyDisplayInfo
 import android.telephony.TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE
 import android.telephony.TelephonyManager
+import android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN
 import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
 import com.android.systemui.dagger.qualifiers.Application
 import com.android.systemui.dagger.qualifiers.Background
-import com.android.systemui.statusbar.pipeline.mobile.data.model.DefaultNetworkType
-import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileSubscriptionModel
-import com.android.systemui.statusbar.pipeline.mobile.data.model.OverrideNetworkType
+import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectionModel
+import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType.DefaultNetworkType
+import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType.OverrideNetworkType
+import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType.UnknownNetworkType
 import com.android.systemui.statusbar.pipeline.mobile.data.model.toDataConnectionType
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionRepository
+import com.android.systemui.statusbar.pipeline.mobile.util.MobileMappingsProxy
 import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger
 import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger.Companion.logOutputChange
 import com.android.systemui.util.settings.GlobalSettings
-import java.lang.IllegalStateException
 import javax.inject.Inject
 import kotlinx.coroutines.CoroutineDispatcher
 import kotlinx.coroutines.CoroutineScope
@@ -58,11 +60,12 @@
 @OptIn(ExperimentalCoroutinesApi::class)
 class MobileConnectionRepositoryImpl(
     private val context: Context,
-    private val subId: Int,
+    override val subId: Int,
     private val telephonyManager: TelephonyManager,
     private val globalSettings: GlobalSettings,
     defaultDataSubId: StateFlow<Int>,
     globalMobileDataSettingChangedEvent: Flow<Unit>,
+    mobileMappingsProxy: MobileMappingsProxy,
     bgDispatcher: CoroutineDispatcher,
     logger: ConnectivityPipelineLogger,
     scope: CoroutineScope,
@@ -78,8 +81,8 @@
 
     private val telephonyCallbackEvent = MutableSharedFlow<Unit>(extraBufferCapacity = 1)
 
-    override val subscriptionModelFlow: StateFlow<MobileSubscriptionModel> = run {
-        var state = MobileSubscriptionModel()
+    override val connectionInfo: StateFlow<MobileConnectionModel> = run {
+        var state = MobileConnectionModel()
         conflatedCallbackFlow {
                 // TODO (b/240569788): log all of these into the connectivity logger
                 val callback =
@@ -141,14 +144,27 @@
                         override fun onDisplayInfoChanged(
                             telephonyDisplayInfo: TelephonyDisplayInfo
                         ) {
+
                             val networkType =
-                                if (
+                                if (telephonyDisplayInfo.networkType == NETWORK_TYPE_UNKNOWN) {
+                                    UnknownNetworkType
+                                } else if (
                                     telephonyDisplayInfo.overrideNetworkType ==
                                         OVERRIDE_NETWORK_TYPE_NONE
                                 ) {
-                                    DefaultNetworkType(telephonyDisplayInfo.networkType)
+                                    DefaultNetworkType(
+                                        telephonyDisplayInfo.networkType,
+                                        mobileMappingsProxy.toIconKey(
+                                            telephonyDisplayInfo.networkType
+                                        )
+                                    )
                                 } else {
-                                    OverrideNetworkType(telephonyDisplayInfo.overrideNetworkType)
+                                    OverrideNetworkType(
+                                        telephonyDisplayInfo.overrideNetworkType,
+                                        mobileMappingsProxy.toIconKeyOverride(
+                                            telephonyDisplayInfo.overrideNetworkType
+                                        )
+                                    )
                                 }
                             state = state.copy(resolvedNetworkType = networkType)
                             trySend(state)
@@ -211,6 +227,7 @@
         private val telephonyManager: TelephonyManager,
         private val logger: ConnectivityPipelineLogger,
         private val globalSettings: GlobalSettings,
+        private val mobileMappingsProxy: MobileMappingsProxy,
         @Background private val bgDispatcher: CoroutineDispatcher,
         @Application private val scope: CoroutineScope,
     ) {
@@ -226,6 +243,7 @@
                 globalSettings,
                 defaultDataSubId,
                 globalMobileDataSettingChangedEvent,
+                mobileMappingsProxy,
                 bgDispatcher,
                 logger,
                 scope,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryImpl.kt
index 08d6010..f27a9c9 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryImpl.kt
@@ -36,6 +36,7 @@
 import android.telephony.TelephonyManager
 import androidx.annotation.VisibleForTesting
 import com.android.internal.telephony.PhoneConstants
+import com.android.settingslib.SignalIcon.MobileIconGroup
 import com.android.settingslib.mobile.MobileMappings
 import com.android.settingslib.mobile.MobileMappings.Config
 import com.android.systemui.broadcast.BroadcastDispatcher
@@ -44,8 +45,10 @@
 import com.android.systemui.dagger.qualifiers.Application
 import com.android.systemui.dagger.qualifiers.Background
 import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel
+import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionRepository
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionsRepository
+import com.android.systemui.statusbar.pipeline.mobile.util.MobileMappingsProxy
 import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger
 import com.android.systemui.util.settings.GlobalSettings
 import javax.inject.Inject
@@ -59,6 +62,7 @@
 import kotlinx.coroutines.flow.SharingStarted
 import kotlinx.coroutines.flow.StateFlow
 import kotlinx.coroutines.flow.distinctUntilChanged
+import kotlinx.coroutines.flow.map
 import kotlinx.coroutines.flow.mapLatest
 import kotlinx.coroutines.flow.merge
 import kotlinx.coroutines.flow.onEach
@@ -75,6 +79,7 @@
     private val subscriptionManager: SubscriptionManager,
     private val telephonyManager: TelephonyManager,
     private val logger: ConnectivityPipelineLogger,
+    mobileMappingsProxy: MobileMappingsProxy,
     broadcastDispatcher: BroadcastDispatcher,
     private val globalSettings: GlobalSettings,
     private val context: Context,
@@ -82,14 +87,14 @@
     @Application private val scope: CoroutineScope,
     private val mobileConnectionRepositoryFactory: MobileConnectionRepositoryImpl.Factory
 ) : MobileConnectionsRepository {
-    private val subIdRepositoryCache: MutableMap<Int, MobileConnectionRepository> = mutableMapOf()
+    private var subIdRepositoryCache: MutableMap<Int, MobileConnectionRepository> = mutableMapOf()
 
     /**
      * State flow that emits the set of mobile data subscriptions, each represented by its own
      * [SubscriptionInfo]. We probably only need the [SubscriptionInfo.getSubscriptionId] of each
      * info object, but for now we keep track of the infos themselves.
      */
-    override val subscriptionsFlow: StateFlow<List<SubscriptionInfo>> =
+    override val subscriptions: StateFlow<List<SubscriptionModel>> =
         conflatedCallbackFlow {
                 val callback =
                     object : SubscriptionManager.OnSubscriptionsChangedListener() {
@@ -105,7 +110,7 @@
 
                 awaitClose { subscriptionManager.removeOnSubscriptionsChangedListener(callback) }
             }
-            .mapLatest { fetchSubscriptionsList() }
+            .mapLatest { fetchSubscriptionsList().map { it.toSubscriptionModel() } }
             .onEach { infos -> dropUnusedReposFromCache(infos) }
             .stateIn(scope, started = SharingStarted.WhileSubscribed(), listOf())
 
@@ -157,7 +162,7 @@
      *
      * This flow will produce whenever the default data subscription or the carrier config changes.
      */
-    override val defaultDataSubRatConfig: StateFlow<Config> =
+    private val defaultDataSubRatConfig: StateFlow<Config> =
         merge(defaultDataSubIdChangeEvent, carrierConfigChangedEvent)
             .mapLatest { Config.readConfig(context) }
             .stateIn(
@@ -166,6 +171,12 @@
                 initialValue = Config.readConfig(context)
             )
 
+    override val defaultMobileIconMapping: Flow<Map<String, MobileIconGroup>> =
+        defaultDataSubRatConfig.map { mobileMappingsProxy.mapIconSets(it) }
+
+    override val defaultMobileIconGroup: Flow<MobileIconGroup> =
+        defaultDataSubRatConfig.map { mobileMappingsProxy.getDefaultIcons(it) }
+
     override fun getRepoForSubId(subId: Int): MobileConnectionRepository {
         if (!isValidSubId(subId)) {
             throw IllegalArgumentException(
@@ -229,7 +240,7 @@
             .stateIn(scope, SharingStarted.WhileSubscribed(), MobileConnectivityModel())
 
     private fun isValidSubId(subId: Int): Boolean {
-        subscriptionsFlow.value.forEach {
+        subscriptions.value.forEach {
             if (it.subscriptionId == subId) {
                 return true
             }
@@ -248,18 +259,23 @@
         )
     }
 
-    private fun dropUnusedReposFromCache(newInfos: List<SubscriptionInfo>) {
+    private fun dropUnusedReposFromCache(newInfos: List<SubscriptionModel>) {
         // Remove any connection repository from the cache that isn't in the new set of IDs. They
         // will get garbage collected once their subscribers go away
         val currentValidSubscriptionIds = newInfos.map { it.subscriptionId }
 
-        subIdRepositoryCache.keys.forEach {
-            if (!currentValidSubscriptionIds.contains(it)) {
-                subIdRepositoryCache.remove(it)
-            }
-        }
+        subIdRepositoryCache =
+            subIdRepositoryCache
+                .filter { currentValidSubscriptionIds.contains(it.key) }
+                .toMutableMap()
     }
 
     private suspend fun fetchSubscriptionsList(): List<SubscriptionInfo> =
         withContext(bgDispatcher) { subscriptionManager.completeActiveSubscriptionInfoList }
+
+    private fun SubscriptionInfo.toSubscriptionModel(): SubscriptionModel =
+        SubscriptionModel(
+            subscriptionId = subscriptionId,
+            isOpportunistic = isOpportunistic,
+        )
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractor.kt
index 0da84f0..8e1197c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractor.kt
@@ -20,10 +20,7 @@
 import com.android.settingslib.SignalIcon.MobileIconGroup
 import com.android.systemui.dagger.qualifiers.Application
 import com.android.systemui.statusbar.pipeline.mobile.data.model.DataConnectionState.Connected
-import com.android.systemui.statusbar.pipeline.mobile.data.model.DefaultNetworkType
-import com.android.systemui.statusbar.pipeline.mobile.data.model.OverrideNetworkType
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionRepository
-import com.android.systemui.statusbar.pipeline.mobile.util.MobileMappingsProxy
 import com.android.systemui.util.CarrierConfigTracker
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -70,10 +67,9 @@
     defaultMobileIconMapping: StateFlow<Map<String, MobileIconGroup>>,
     defaultMobileIconGroup: StateFlow<MobileIconGroup>,
     override val isDefaultConnectionFailed: StateFlow<Boolean>,
-    mobileMappingsProxy: MobileMappingsProxy,
     connectionRepository: MobileConnectionRepository,
 ) : MobileIconInteractor {
-    private val mobileStatusInfo = connectionRepository.subscriptionModelFlow
+    private val connectionInfo = connectionRepository.connectionInfo
 
     override val isDataEnabled: StateFlow<Boolean> = connectionRepository.dataEnabled
 
@@ -82,33 +78,27 @@
     /** Observable for the current RAT indicator icon ([MobileIconGroup]) */
     override val networkTypeIconGroup: StateFlow<MobileIconGroup> =
         combine(
-                mobileStatusInfo,
+                connectionInfo,
                 defaultMobileIconMapping,
                 defaultMobileIconGroup,
             ) { info, mapping, defaultGroup ->
-                val lookupKey =
-                    when (val resolved = info.resolvedNetworkType) {
-                        is DefaultNetworkType -> mobileMappingsProxy.toIconKey(resolved.type)
-                        is OverrideNetworkType ->
-                            mobileMappingsProxy.toIconKeyOverride(resolved.type)
-                    }
-                mapping[lookupKey] ?: defaultGroup
+                mapping[info.resolvedNetworkType.lookupKey] ?: defaultGroup
             }
             .stateIn(scope, SharingStarted.WhileSubscribed(), defaultMobileIconGroup.value)
 
     override val isEmergencyOnly: StateFlow<Boolean> =
-        mobileStatusInfo
+        connectionInfo
             .mapLatest { it.isEmergencyOnly }
             .stateIn(scope, SharingStarted.WhileSubscribed(), false)
 
     override val level: StateFlow<Int> =
-        mobileStatusInfo
-            .mapLatest { mobileModel ->
+        connectionInfo
+            .mapLatest { connection ->
                 // TODO: incorporate [MobileMappings.Config.alwaysShowCdmaRssi]
-                if (mobileModel.isGsm) {
-                    mobileModel.primaryLevel
+                if (connection.isGsm) {
+                    connection.primaryLevel
                 } else {
-                    mobileModel.cdmaLevel
+                    connection.cdmaLevel
                 }
             }
             .stateIn(scope, SharingStarted.WhileSubscribed(), 0)
@@ -120,7 +110,7 @@
     override val numberOfLevels: StateFlow<Int> = MutableStateFlow(4)
 
     override val isDataConnected: StateFlow<Boolean> =
-        mobileStatusInfo
-            .mapLatest { subscriptionModel -> subscriptionModel.dataConnectionState == Connected }
+        connectionInfo
+            .mapLatest { connection -> connection.dataConnectionState == Connected }
             .stateIn(scope, SharingStarted.WhileSubscribed(), false)
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractor.kt
index a4175c3..6f8fb2e 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractor.kt
@@ -17,17 +17,16 @@
 package com.android.systemui.statusbar.pipeline.mobile.domain.interactor
 
 import android.telephony.CarrierConfigManager
-import android.telephony.SubscriptionInfo
 import android.telephony.SubscriptionManager
 import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID
 import com.android.settingslib.SignalIcon.MobileIconGroup
 import com.android.settingslib.mobile.TelephonyIcons
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.dagger.qualifiers.Application
+import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionRepository
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionsRepository
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.UserSetupRepository
-import com.android.systemui.statusbar.pipeline.mobile.util.MobileMappingsProxy
 import com.android.systemui.util.CarrierConfigTracker
 import javax.inject.Inject
 import kotlinx.coroutines.CoroutineScope
@@ -53,7 +52,7 @@
  */
 interface MobileIconsInteractor {
     /** List of subscriptions, potentially filtered for CBRS */
-    val filteredSubscriptions: Flow<List<SubscriptionInfo>>
+    val filteredSubscriptions: Flow<List<SubscriptionModel>>
     /** True if the active mobile data subscription has data enabled */
     val activeDataConnectionHasDataEnabled: StateFlow<Boolean>
     /** The icon mapping from network type to [MobileIconGroup] for the default subscription */
@@ -79,7 +78,6 @@
 constructor(
     private val mobileConnectionsRepo: MobileConnectionsRepository,
     private val carrierConfigTracker: CarrierConfigTracker,
-    private val mobileMappingsProxy: MobileMappingsProxy,
     userSetupRepo: UserSetupRepository,
     @Application private val scope: CoroutineScope,
 ) : MobileIconsInteractor {
@@ -102,8 +100,8 @@
             .flatMapLatest { it?.dataEnabled ?: flowOf(false) }
             .stateIn(scope, SharingStarted.WhileSubscribed(), false)
 
-    private val unfilteredSubscriptions: Flow<List<SubscriptionInfo>> =
-        mobileConnectionsRepo.subscriptionsFlow
+    private val unfilteredSubscriptions: Flow<List<SubscriptionModel>> =
+        mobileConnectionsRepo.subscriptions
 
     /**
      * Generally, SystemUI wants to show iconography for each subscription that is listed by
@@ -118,7 +116,7 @@
      * [CarrierConfigManager.KEY_ALWAYS_SHOW_PRIMARY_SIGNAL_BAR_IN_OPPORTUNISTIC_NETWORK_BOOLEAN],
      * and by checking which subscription is opportunistic, or which one is active.
      */
-    override val filteredSubscriptions: Flow<List<SubscriptionInfo>> =
+    override val filteredSubscriptions: Flow<List<SubscriptionModel>> =
         combine(unfilteredSubscriptions, activeMobileDataSubscriptionId) { unfilteredSubs, activeId
             ->
             // Based on the old logic,
@@ -154,15 +152,19 @@
      * subscription Id. This mapping is the same for every subscription.
      */
     override val defaultMobileIconMapping: StateFlow<Map<String, MobileIconGroup>> =
-        mobileConnectionsRepo.defaultDataSubRatConfig
-            .mapLatest { mobileMappingsProxy.mapIconSets(it) }
-            .stateIn(scope, SharingStarted.WhileSubscribed(), initialValue = mapOf())
+        mobileConnectionsRepo.defaultMobileIconMapping.stateIn(
+            scope,
+            SharingStarted.WhileSubscribed(),
+            initialValue = mapOf()
+        )
 
     /** If there is no mapping in [defaultMobileIconMapping], then use this default icon group */
     override val defaultMobileIconGroup: StateFlow<MobileIconGroup> =
-        mobileConnectionsRepo.defaultDataSubRatConfig
-            .mapLatest { mobileMappingsProxy.getDefaultIcons(it) }
-            .stateIn(scope, SharingStarted.WhileSubscribed(), initialValue = TelephonyIcons.G)
+        mobileConnectionsRepo.defaultMobileIconGroup.stateIn(
+            scope,
+            SharingStarted.WhileSubscribed(),
+            initialValue = TelephonyIcons.G
+        )
 
     /**
      * We want to show an error state when cellular has actually failed to validate, but not if some
@@ -189,7 +191,6 @@
             defaultMobileIconMapping,
             defaultMobileIconGroup,
             isDefaultConnectionFailed,
-            mobileMappingsProxy,
             mobileConnectionsRepo.getRepoForSubId(subId),
         )
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/MobileUiAdapter.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/MobileUiAdapter.kt
index d9487bf..62fa723 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/MobileUiAdapter.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/MobileUiAdapter.kt
@@ -56,8 +56,8 @@
     private val statusBarPipelineFlags: StatusBarPipelineFlags,
 ) : CoreStartable {
     private val mobileSubIds: Flow<List<Int>> =
-        interactor.filteredSubscriptions.mapLatest { infos ->
-            infos.map { subscriptionInfo -> subscriptionInfo.subscriptionId }
+        interactor.filteredSubscriptions.mapLatest { subscriptions ->
+            subscriptions.map { subscriptionModel -> subscriptionModel.subscriptionId }
         }
 
     /**
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/view/ModernStatusBarMobileView.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/view/ModernStatusBarMobileView.kt
index ec4fa9c..0ab7bcd 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/view/ModernStatusBarMobileView.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/view/ModernStatusBarMobileView.kt
@@ -32,6 +32,8 @@
     attrs: AttributeSet?,
 ) : BaseStatusBarFrameLayout(context, attrs) {
 
+    var subId: Int = -1
+
     private lateinit var slot: String
     override fun getSlot() = slot
 
@@ -76,6 +78,7 @@
                     as ModernStatusBarMobileView)
                 .also {
                     it.slot = slot
+                    it.subId = viewModel.subscriptionId
                     MobileIconBinder.bind(it, viewModel)
                 }
         }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconsViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconsViewModel.kt
index 24c1db9..2349cb7 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconsViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/mobile/ui/viewmodel/MobileIconsViewModel.kt
@@ -23,7 +23,7 @@
 import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger
 import javax.inject.Inject
 import kotlinx.coroutines.InternalCoroutinesApi
-import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.StateFlow
 
 /**
  * View model for describing the system's current mobile cellular connections. The result is a list
@@ -33,7 +33,7 @@
 class MobileIconsViewModel
 @Inject
 constructor(
-    val subscriptionIdsFlow: Flow<List<Int>>,
+    val subscriptionIdsFlow: StateFlow<List<Int>>,
     private val interactor: MobileIconsInteractor,
     private val logger: ConnectivityPipelineLogger,
 ) {
@@ -51,7 +51,7 @@
         private val interactor: MobileIconsInteractor,
         private val logger: ConnectivityPipelineLogger,
     ) {
-        fun create(subscriptionIdsFlow: Flow<List<Int>>): MobileIconsViewModel {
+        fun create(subscriptionIdsFlow: StateFlow<List<Int>>): MobileIconsViewModel {
             return MobileIconsViewModel(
                 subscriptionIdsFlow,
                 interactor,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/ui/binder/WifiViewBinder.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/ui/binder/WifiViewBinder.kt
index f5b5950..cc67c84 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/ui/binder/WifiViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/ui/binder/WifiViewBinder.kt
@@ -46,6 +46,7 @@
  * view-model to be reused for multiple view/view-binder bindings.
  */
 @OptIn(InternalCoroutinesApi::class)
+@Suppress("EXPERIMENTAL_IS_NOT_ENABLED")
 object WifiViewBinder {
 
     /**
@@ -59,6 +60,12 @@
 
         /** Notifies that the visibility state has changed. */
         fun onVisibilityStateChanged(@StatusBarIconView.VisibleState state: Int)
+
+        /** Notifies that the icon tint has been updated. */
+        fun onIconTintChanged(newTint: Int)
+
+        /** Notifies that the decor tint has been updated (used only for the dot). */
+        fun onDecorTintChanged(newTint: Int)
     }
 
     /** Binds the view to the view-model, continuing to update the former based on the latter. */
@@ -82,6 +89,9 @@
         @StatusBarIconView.VisibleState
         val visibilityState: MutableStateFlow<Int> = MutableStateFlow(STATE_HIDDEN)
 
+        val iconTint: MutableStateFlow<Int> = MutableStateFlow(viewModel.defaultColor)
+        val decorTint: MutableStateFlow<Int> = MutableStateFlow(viewModel.defaultColor)
+
         view.repeatWhenAttached {
             repeatOnLifecycle(Lifecycle.State.STARTED) {
                 launch {
@@ -101,7 +111,7 @@
                 }
 
                 launch {
-                    viewModel.tint.collect { tint ->
+                    iconTint.collect { tint ->
                         val tintList = ColorStateList.valueOf(tint)
                         iconView.imageTintList = tintList
                         activityInView.imageTintList = tintList
@@ -110,6 +120,8 @@
                     }
                 }
 
+                launch { decorTint.collect { tint -> dotView.setDecorColor(tint) } }
+
                 launch {
                     viewModel.isActivityInViewVisible.distinctUntilChanged().collect { visible ->
                         activityInView.isVisible = visible
@@ -144,6 +156,20 @@
             override fun onVisibilityStateChanged(@StatusBarIconView.VisibleState state: Int) {
                 visibilityState.value = state
             }
+
+            override fun onIconTintChanged(newTint: Int) {
+                if (viewModel.useDebugColoring) {
+                    return
+                }
+                iconTint.value = newTint
+            }
+
+            override fun onDecorTintChanged(newTint: Int) {
+                if (viewModel.useDebugColoring) {
+                    return
+                }
+                decorTint.value = newTint
+            }
         }
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/ui/view/ModernStatusBarWifiView.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/ui/view/ModernStatusBarWifiView.kt
index a45076b..be7782c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/ui/view/ModernStatusBarWifiView.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/ui/view/ModernStatusBarWifiView.kt
@@ -22,6 +22,7 @@
 import android.view.Gravity
 import android.view.LayoutInflater
 import com.android.systemui.R
+import com.android.systemui.plugins.DarkIconDispatcher
 import com.android.systemui.statusbar.BaseStatusBarFrameLayout
 import com.android.systemui.statusbar.StatusBarIconView
 import com.android.systemui.statusbar.StatusBarIconView.STATE_DOT
@@ -51,18 +52,20 @@
             binding.onVisibilityStateChanged(value)
         }
 
-    override fun onDarkChanged(areas: ArrayList<Rect>?, darkIntensity: Float, tint: Int) {
-        // TODO(b/238425913)
-    }
-
     override fun getSlot() = slot
 
+    override fun onDarkChanged(areas: ArrayList<Rect>?, darkIntensity: Float, tint: Int) {
+        val newTint = DarkIconDispatcher.getTint(areas, this, tint)
+        binding.onIconTintChanged(newTint)
+        binding.onDecorTintChanged(newTint)
+    }
+
     override fun setStaticDrawableColor(color: Int) {
-        // TODO(b/238425913)
+        binding.onIconTintChanged(color)
     }
 
     override fun setDecorColor(color: Int) {
-        // TODO(b/238425913)
+        binding.onDecorTintChanged(color)
     }
 
     override fun setVisibleState(@StatusBarIconView.VisibleState state: Int, animate: Boolean) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/ui/viewmodel/LocationBasedWifiViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/ui/viewmodel/LocationBasedWifiViewModel.kt
index e35a8fe..a4615cc 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/ui/viewmodel/LocationBasedWifiViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/ui/viewmodel/LocationBasedWifiViewModel.kt
@@ -21,7 +21,6 @@
 import com.android.systemui.statusbar.pipeline.wifi.ui.model.WifiIcon
 import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.StateFlow
-import kotlinx.coroutines.flow.flowOf
 
 /**
  * A view model for a wifi icon in a specific location. This allows us to control parameters that
@@ -48,24 +47,12 @@
     /** True if the airplane spacer view should be visible. */
     val isAirplaneSpacerVisible: Flow<Boolean>,
 ) {
-    /** The color that should be used to tint the icon. */
-    val tint: Flow<Int> =
-        flowOf(
-            if (statusBarPipelineFlags.useWifiDebugColoring()) {
-                debugTint
-            } else {
-                DEFAULT_TINT
-            }
-        )
+    val useDebugColoring: Boolean = statusBarPipelineFlags.useWifiDebugColoring()
 
-    companion object {
-        /**
-         * A default icon tint.
-         *
-         * TODO(b/238425913): The tint is actually controlled by
-         * [com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager]. We
-         * should use that logic instead of white as a default.
-         */
-        private const val DEFAULT_TINT = Color.WHITE
-    }
+    val defaultColor: Int =
+        if (useDebugColoring) {
+            debugTint
+        } else {
+            Color.WHITE
+        }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceControlsControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceControlsControllerImpl.kt
index 6c66f0b..341eb3b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceControlsControllerImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceControlsControllerImpl.kt
@@ -68,7 +68,6 @@
 
         internal const val PREFS_CONTROLS_SEEDING_COMPLETED = "SeedingCompleted"
         const val PREFS_CONTROLS_FILE = "controls_prefs"
-        internal const val PREFS_SETTINGS_DIALOG_ATTEMPTS = "show_settings_attempts"
         private const val SEEDING_MAX = 2
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityController.java
index 2a93844..3be14bc 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityController.java
@@ -36,9 +36,14 @@
     String getProfileOwnerName();
     CharSequence getDeviceOwnerOrganizationName();
     CharSequence getWorkProfileOrganizationName();
+
+    boolean isFinancedDevice();
+
     /** Device owner component even if not on this user. **/
     ComponentName getDeviceOwnerComponentOnAnyUser();
+    // TODO(b/259908270): remove
     /** Device owner type for a device owner. **/
+    @Deprecated
     int getDeviceOwnerType(ComponentName admin);
     boolean isNetworkLoggingEnabled();
     boolean isVpnEnabled();
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java
index ba94714..03656f0 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java
@@ -254,6 +254,7 @@
         return mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser();
     }
 
+    // TODO(b/259908270): remove
     @Override
     @DeviceOwnerType
     public int getDeviceOwnerType(@NonNull ComponentName admin) {
@@ -261,6 +262,11 @@
     }
 
     @Override
+    public boolean isFinancedDevice() {
+        return mDevicePolicyManager.isFinancedDevice();
+    }
+
+    @Override
     public boolean isNetworkLoggingEnabled() {
         return mDevicePolicyManager.isNetworkLoggingEnabled(null);
     }
diff --git a/packages/SystemUI/src/com/android/systemui/stylus/OWNERS b/packages/SystemUI/src/com/android/systemui/stylus/OWNERS
new file mode 100644
index 0000000..7ccb316
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/stylus/OWNERS
@@ -0,0 +1,8 @@
+# Bug component: 1254381
+azappone@google.com
+achalke@google.com
+juliacr@google.com
+madym@google.com
+mgalhardo@google.com
+petrcermak@google.com
+vanjan@google.com
\ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/stylus/StylusManager.kt b/packages/SystemUI/src/com/android/systemui/stylus/StylusManager.kt
new file mode 100644
index 0000000..3e111e6
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/stylus/StylusManager.kt
@@ -0,0 +1,199 @@
+/*
+ * 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.systemui.stylus
+
+import android.bluetooth.BluetoothAdapter
+import android.bluetooth.BluetoothDevice
+import android.hardware.input.InputManager
+import android.os.Handler
+import android.util.ArrayMap
+import android.util.Log
+import android.view.InputDevice
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.dagger.qualifiers.Background
+import java.util.concurrent.CopyOnWriteArrayList
+import java.util.concurrent.Executor
+import javax.inject.Inject
+
+/**
+ * A class which keeps track of InputDevice events related to stylus devices, and notifies
+ * registered callbacks of stylus events.
+ */
+@SysUISingleton
+class StylusManager
+@Inject
+constructor(
+    private val inputManager: InputManager,
+    private val bluetoothAdapter: BluetoothAdapter,
+    @Background private val handler: Handler,
+    @Background private val executor: Executor,
+) : InputManager.InputDeviceListener, BluetoothAdapter.OnMetadataChangedListener {
+
+    private val stylusCallbacks: CopyOnWriteArrayList<StylusCallback> = CopyOnWriteArrayList()
+    private val stylusBatteryCallbacks: CopyOnWriteArrayList<StylusBatteryCallback> =
+        CopyOnWriteArrayList()
+    // This map should only be accessed on the handler
+    private val inputDeviceAddressMap: MutableMap<Int, String?> = ArrayMap()
+
+    /**
+     * Starts listening to InputManager InputDevice events. Will also load the InputManager snapshot
+     * at time of starting.
+     */
+    fun startListener() {
+        addExistingStylusToMap()
+        inputManager.registerInputDeviceListener(this, handler)
+    }
+
+    /** Registers a StylusCallback to listen to stylus events. */
+    fun registerCallback(callback: StylusCallback) {
+        stylusCallbacks.add(callback)
+    }
+
+    /** Unregisters a StylusCallback. If StylusCallback is not registered, is a no-op. */
+    fun unregisterCallback(callback: StylusCallback) {
+        stylusCallbacks.remove(callback)
+    }
+
+    fun registerBatteryCallback(callback: StylusBatteryCallback) {
+        stylusBatteryCallbacks.add(callback)
+    }
+
+    fun unregisterBatteryCallback(callback: StylusBatteryCallback) {
+        stylusBatteryCallbacks.remove(callback)
+    }
+
+    override fun onInputDeviceAdded(deviceId: Int) {
+        val device: InputDevice = inputManager.getInputDevice(deviceId) ?: return
+        if (!device.supportsSource(InputDevice.SOURCE_STYLUS)) return
+
+        // TODO(b/257936830): get address once input api available
+        val btAddress: String? = null
+        inputDeviceAddressMap[deviceId] = btAddress
+        executeStylusCallbacks { cb -> cb.onStylusAdded(deviceId) }
+
+        if (btAddress != null) {
+            onStylusBluetoothConnected(btAddress)
+            executeStylusCallbacks { cb -> cb.onStylusBluetoothConnected(deviceId, btAddress) }
+        }
+    }
+
+    override fun onInputDeviceChanged(deviceId: Int) {
+        val device: InputDevice = inputManager.getInputDevice(deviceId) ?: return
+        if (!device.supportsSource(InputDevice.SOURCE_STYLUS)) return
+
+        // TODO(b/257936830): get address once input api available
+        val currAddress: String? = null
+        val prevAddress: String? = inputDeviceAddressMap[deviceId]
+        inputDeviceAddressMap[deviceId] = currAddress
+
+        if (prevAddress == null && currAddress != null) {
+            onStylusBluetoothConnected(currAddress)
+            executeStylusCallbacks { cb -> cb.onStylusBluetoothConnected(deviceId, currAddress) }
+        }
+
+        if (prevAddress != null && currAddress == null) {
+            onStylusBluetoothDisconnected(prevAddress)
+            executeStylusCallbacks { cb -> cb.onStylusBluetoothDisconnected(deviceId, prevAddress) }
+        }
+    }
+
+    override fun onInputDeviceRemoved(deviceId: Int) {
+        if (!inputDeviceAddressMap.contains(deviceId)) return
+
+        val btAddress: String? = inputDeviceAddressMap[deviceId]
+        inputDeviceAddressMap.remove(deviceId)
+        if (btAddress != null) {
+            onStylusBluetoothDisconnected(btAddress)
+            executeStylusCallbacks { cb -> cb.onStylusBluetoothDisconnected(deviceId, btAddress) }
+        }
+        executeStylusCallbacks { cb -> cb.onStylusRemoved(deviceId) }
+    }
+
+    override fun onMetadataChanged(device: BluetoothDevice, key: Int, value: ByteArray?) {
+        handler.post executeMetadataChanged@{
+            if (key != BluetoothDevice.METADATA_MAIN_CHARGING || value == null)
+                return@executeMetadataChanged
+
+            val inputDeviceId: Int =
+                inputDeviceAddressMap.filterValues { it == device.address }.keys.firstOrNull()
+                    ?: return@executeMetadataChanged
+
+            val isCharging = String(value) == "true"
+
+            executeStylusBatteryCallbacks { cb ->
+                cb.onStylusBluetoothChargingStateChanged(inputDeviceId, device, isCharging)
+            }
+        }
+    }
+
+    private fun onStylusBluetoothConnected(btAddress: String) {
+        val device: BluetoothDevice = bluetoothAdapter.getRemoteDevice(btAddress) ?: return
+        try {
+            bluetoothAdapter.addOnMetadataChangedListener(device, executor, this)
+        } catch (e: IllegalArgumentException) {
+            Log.e(TAG, "$e: Metadata listener already registered for device. Ignoring.")
+        }
+    }
+
+    private fun onStylusBluetoothDisconnected(btAddress: String) {
+        val device: BluetoothDevice = bluetoothAdapter.getRemoteDevice(btAddress) ?: return
+        try {
+            bluetoothAdapter.removeOnMetadataChangedListener(device, this)
+        } catch (e: IllegalArgumentException) {
+            Log.e(TAG, "$e: Metadata listener does not exist for device. Ignoring.")
+        }
+    }
+
+    private fun executeStylusCallbacks(run: (cb: StylusCallback) -> Unit) {
+        stylusCallbacks.forEach(run)
+    }
+
+    private fun executeStylusBatteryCallbacks(run: (cb: StylusBatteryCallback) -> Unit) {
+        stylusBatteryCallbacks.forEach(run)
+    }
+
+    private fun addExistingStylusToMap() {
+        for (deviceId: Int in inputManager.inputDeviceIds) {
+            val device: InputDevice = inputManager.getInputDevice(deviceId) ?: continue
+            if (device.supportsSource(InputDevice.SOURCE_STYLUS)) {
+                // TODO(b/257936830): get address once input api available
+                inputDeviceAddressMap[deviceId] = null
+            }
+        }
+    }
+
+    /** Callback interface to receive events from the StylusManager. */
+    interface StylusCallback {
+        fun onStylusAdded(deviceId: Int) {}
+        fun onStylusRemoved(deviceId: Int) {}
+        fun onStylusBluetoothConnected(deviceId: Int, btAddress: String) {}
+        fun onStylusBluetoothDisconnected(deviceId: Int, btAddress: String) {}
+    }
+
+    /** Callback interface to receive stylus battery events from the StylusManager. */
+    interface StylusBatteryCallback {
+        fun onStylusBluetoothChargingStateChanged(
+            inputDeviceId: Int,
+            btDevice: BluetoothDevice,
+            isCharging: Boolean
+        ) {}
+    }
+
+    companion object {
+        private val TAG = StylusManager::class.simpleName.orEmpty()
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayController.kt b/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayController.kt
index ea40208..db7315f 100644
--- a/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayController.kt
+++ b/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayController.kt
@@ -34,6 +34,7 @@
 import com.android.systemui.dagger.qualifiers.Main
 import com.android.systemui.statusbar.policy.ConfigurationController
 import com.android.systemui.util.concurrency.DelayableExecutor
+import com.android.systemui.util.time.SystemClock
 import com.android.systemui.util.wakelock.WakeLock
 
 /**
@@ -44,8 +45,24 @@
  *
  * The generic type T is expected to contain all the information necessary for the subclasses to
  * display the view in a certain state, since they receive <T> in [updateView].
+ *
+ * Some information about display ordering:
+ *
+ * [ViewPriority] defines different priorities for the incoming views. The incoming view will be
+ * displayed so long as its priority is equal to or greater than the currently displayed view.
+ * (Concretely, this means that a [ViewPriority.NORMAL] won't be displayed if a
+ * [ViewPriority.CRITICAL] is currently displayed. But otherwise, the incoming view will get
+ * displayed and kick out the old view).
+ *
+ * Once the currently displayed view times out, we *may* display a previously requested view if it
+ * still has enough time left before its own timeout. The same priority ordering applies.
+ *
+ * Note: [TemporaryViewInfo.id] is the identifier that we use to determine if a call to
+ * [displayView] will just update the current view with new information, or display a completely new
+ * view. This means that you *cannot* change the [TemporaryViewInfo.priority] or
+ * [TemporaryViewInfo.windowTitle] while using the same ID.
  */
-abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : TemporaryViewLogger>(
+abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : TemporaryViewLogger<T>>(
     internal val context: Context,
     internal val logger: U,
     internal val windowManager: WindowManager,
@@ -55,6 +72,7 @@
     private val powerManager: PowerManager,
     @LayoutRes private val viewLayoutRes: Int,
     private val wakeLockBuilder: WakeLock.Builder,
+    private val systemClock: SystemClock,
 ) : CoreStartable {
     /**
      * Window layout params that will be used as a starting point for the [windowLayoutParams] of
@@ -78,27 +96,18 @@
      */
     internal abstract val windowLayoutParams: WindowManager.LayoutParams
 
-    /** A container for all the display-related objects. Null if the view is not being displayed. */
-    private var displayInfo: DisplayInfo? = null
-
-    /** A [Runnable] that, when run, will cancel the pending timeout of the view. */
-    private var cancelViewTimeout: Runnable? = null
-
     /**
-     * A wakelock that is acquired when view is displayed and screen off,
-     * then released when view is removed.
+     * A list of the currently active views, ordered from highest priority in the beginning to
+     * lowest priority at the end.
+     *
+     * Whenever the current view disappears, the next-priority view will be displayed if it's still
+     * valid.
      */
-    private var wakeLock: WakeLock? = null
+    internal val activeViews: MutableList<DisplayInfo> = mutableListOf()
 
-    /** A string that keeps track of wakelock reason once it is acquired till it gets released */
-    private var wakeReasonAcquired: String? = null
-
-    /**
-     * A stack of pairs of device id and temporary view info. This is used when there may be
-     * multiple devices in range, and we want to always display the chip for the most recently
-     * active device.
-     */
-    internal val activeViews: ArrayDeque<Pair<String, T>> = ArrayDeque()
+    private fun getCurrentDisplayInfo(): DisplayInfo? {
+        return activeViews.getOrNull(0)
+    }
 
     /**
      * Displays the view with the provided [newInfo].
@@ -107,94 +116,139 @@
      * display the correct information in the view.
      * @param onViewTimeout a runnable that runs after the view timeout.
      */
+    @Synchronized
     fun displayView(newInfo: T, onViewTimeout: Runnable? = null) {
-        val currentDisplayInfo = displayInfo
-
-        // Update our list of active devices by removing it if necessary, then adding back at the
-        // front of the list
-        val id = newInfo.id
-        val position = findAndRemoveFromActiveViewsList(id)
-        activeViews.addFirst(Pair(id, newInfo))
-
-        if (currentDisplayInfo != null &&
-            currentDisplayInfo.info.windowTitle == newInfo.windowTitle) {
-            // We're already displaying information in the correctly-titled window, so we just need
-            // to update the view.
-            currentDisplayInfo.info = newInfo
-            updateView(currentDisplayInfo.info, currentDisplayInfo.view)
-        } else {
-            if (currentDisplayInfo != null) {
-                // We're already displaying information but that information is under a different
-                // window title. So, we need to remove the old window with the old title and add a
-                // new window with the new title.
-                removeView(
-                    id,
-                    removalReason = "New info has new window title: ${newInfo.windowTitle}"
-                )
-            }
-
-            // At this point, we're guaranteed to no longer be displaying a view.
-            // So, set up all our callbacks and inflate the view.
-            configurationController.addCallback(displayScaleListener)
-
-            wakeLock = if (!powerManager.isScreenOn) {
-                // If the screen is off, fully wake it so the user can see the view.
-                wakeLockBuilder
-                    .setTag(newInfo.windowTitle)
-                    .setLevelsAndFlags(
-                            PowerManager.FULL_WAKE_LOCK or
-                                PowerManager.ACQUIRE_CAUSES_WAKEUP
-                    )
-                    .build()
-            } else {
-                // Per b/239426653, we want the view to show over the dream state.
-                // If the screen is on, using screen bright level will leave screen on the dream
-                // state but ensure the screen will not go off before wake lock is released.
-                wakeLockBuilder
-                    .setTag(newInfo.windowTitle)
-                    .setLevelsAndFlags(PowerManager.SCREEN_BRIGHT_WAKE_LOCK)
-                    .build()
-            }
-            wakeLock?.acquire(newInfo.wakeReason)
-            wakeReasonAcquired = newInfo.wakeReason
-            logger.logViewAddition(id, newInfo.windowTitle)
-            inflateAndUpdateView(newInfo)
-        }
-
-        // Cancel and re-set the view timeout each time we get a new state.
         val timeout = accessibilityManager.getRecommendedTimeoutMillis(
             newInfo.timeoutMs,
             // Not all views have controls so FLAG_CONTENT_CONTROLS might be superfluous, but
             // include it just to be safe.
             FLAG_CONTENT_ICONS or FLAG_CONTENT_TEXT or FLAG_CONTENT_CONTROLS
-       )
+        )
+        val timeExpirationMillis = systemClock.currentTimeMillis() + timeout
 
-        // Only cancel timeout of the most recent view displayed, as it will be reset.
-        if (position == 0) {
-            cancelViewTimeout?.run()
+        val currentDisplayInfo = getCurrentDisplayInfo()
+
+        // We're current displaying a chipbar with the same ID, we just need to update its info
+        if (currentDisplayInfo != null && currentDisplayInfo.info.id == newInfo.id) {
+            val view = checkNotNull(currentDisplayInfo.view) {
+                "First item in activeViews list must have a valid view"
+            }
+            logger.logViewUpdate(newInfo)
+            currentDisplayInfo.info = newInfo
+            currentDisplayInfo.timeExpirationMillis = timeExpirationMillis
+            updateTimeout(currentDisplayInfo, timeout, onViewTimeout)
+            updateView(newInfo, view)
+            return
         }
-        cancelViewTimeout = mainExecutor.executeDelayed(
+
+        val newDisplayInfo = DisplayInfo(
+            info = newInfo,
+            onViewTimeout = onViewTimeout,
+            timeExpirationMillis = timeExpirationMillis,
+            // Null values will be updated to non-null if/when this view actually gets displayed
+            view = null,
+            wakeLock = null,
+            cancelViewTimeout = null,
+        )
+
+        // We're not displaying anything, so just render this new info
+        if (currentDisplayInfo == null) {
+            addCallbacks()
+            activeViews.add(newDisplayInfo)
+            showNewView(newDisplayInfo, timeout)
+            return
+        }
+
+        // The currently displayed info takes higher priority than the new one.
+        // So, just store the new one in case the current one disappears.
+        if (currentDisplayInfo.info.priority > newInfo.priority) {
+            logger.logViewAdditionDelayed(newInfo)
+            // Remove any old information for this id (if it exists) and re-add it to the list in
+            // the right priority spot
+            removeFromActivesIfNeeded(newInfo.id)
+            var insertIndex = 0
+            while (insertIndex < activeViews.size &&
+                activeViews[insertIndex].info.priority > newInfo.priority) {
+                insertIndex++
+            }
+            activeViews.add(insertIndex, newDisplayInfo)
+            return
+        }
+
+        // Else: The newInfo should be displayed and the currentInfo should be hidden
+        hideView(currentDisplayInfo)
+        // Remove any old information for this id (if it exists) and put this info at the beginning
+        removeFromActivesIfNeeded(newDisplayInfo.info.id)
+        activeViews.add(0, newDisplayInfo)
+        showNewView(newDisplayInfo, timeout)
+    }
+
+    private fun showNewView(newDisplayInfo: DisplayInfo, timeout: Int) {
+        logger.logViewAddition(newDisplayInfo.info)
+        createAndAcquireWakeLock(newDisplayInfo)
+        updateTimeout(newDisplayInfo, timeout, newDisplayInfo.onViewTimeout)
+        inflateAndUpdateView(newDisplayInfo)
+    }
+
+    private fun createAndAcquireWakeLock(displayInfo: DisplayInfo) {
+        // TODO(b/262009503): Migrate off of isScrenOn, since it's deprecated.
+        val newWakeLock = if (!powerManager.isScreenOn) {
+            // If the screen is off, fully wake it so the user can see the view.
+            wakeLockBuilder
+                .setTag(displayInfo.info.windowTitle)
+                .setLevelsAndFlags(
+                    PowerManager.FULL_WAKE_LOCK or
+                        PowerManager.ACQUIRE_CAUSES_WAKEUP
+                )
+                .build()
+        } else {
+            // Per b/239426653, we want the view to show over the dream state.
+            // If the screen is on, using screen bright level will leave screen on the dream
+            // state but ensure the screen will not go off before wake lock is released.
+            wakeLockBuilder
+                .setTag(displayInfo.info.windowTitle)
+                .setLevelsAndFlags(PowerManager.SCREEN_BRIGHT_WAKE_LOCK)
+                .build()
+        }
+        displayInfo.wakeLock = newWakeLock
+        newWakeLock.acquire(displayInfo.info.wakeReason)
+    }
+
+    /**
+     * Creates a runnable that will remove [displayInfo] in [timeout] ms from now.
+     *
+     * @param onViewTimeout an optional runnable that will be run if the view times out.
+     * @return a runnable that, when run, will *cancel* the view's timeout.
+     */
+    private fun updateTimeout(displayInfo: DisplayInfo, timeout: Int, onViewTimeout: Runnable?) {
+        val cancelViewTimeout = mainExecutor.executeDelayed(
             {
-                removeView(id, REMOVAL_REASON_TIMEOUT)
+                removeView(displayInfo.info.id, REMOVAL_REASON_TIMEOUT)
                 onViewTimeout?.run()
             },
             timeout.toLong()
         )
+
+        displayInfo.onViewTimeout = onViewTimeout
+        // Cancel old view timeout and re-set it.
+        displayInfo.cancelViewTimeout?.run()
+        displayInfo.cancelViewTimeout = cancelViewTimeout
     }
 
-    /** Inflates a new view, updates it with [newInfo], and adds the view to the window. */
-    private fun inflateAndUpdateView(newInfo: T) {
+    /** Inflates a new view, updates it with [DisplayInfo.info], and adds the view to the window. */
+    private fun inflateAndUpdateView(displayInfo: DisplayInfo) {
+        val newInfo = displayInfo.info
         val newView = LayoutInflater
                 .from(context)
                 .inflate(viewLayoutRes, null) as ViewGroup
-        val newViewController = TouchableRegionViewController(newView, this::getTouchableRegion)
-        newViewController.init()
+        displayInfo.view = newView
 
         // We don't need to hold on to the view controller since we never set anything additional
         // on it -- it will be automatically cleaned up when the view is detached.
-        val newDisplayInfo = DisplayInfo(newView, newInfo)
-        displayInfo = newDisplayInfo
-        updateView(newDisplayInfo.info, newDisplayInfo.view)
+        val newViewController = TouchableRegionViewController(newView, this::getTouchableRegion)
+        newViewController.init()
+
+        updateView(newInfo, newView)
 
         val paramsWithTitle = WindowManager.LayoutParams().also {
             it.copyFrom(windowLayoutParams)
@@ -206,11 +260,15 @@
     }
 
     /** Removes then re-inflates the view. */
+    @Synchronized
     private fun reinflateView() {
-        val currentViewInfo = displayInfo ?: return
+        val currentDisplayInfo = getCurrentDisplayInfo() ?: return
 
-        windowManager.removeView(currentViewInfo.view)
-        inflateAndUpdateView(currentViewInfo.info)
+        val view = checkNotNull(currentDisplayInfo.view) {
+            "First item in activeViews list must have a valid view"
+        }
+        windowManager.removeView(view)
+        inflateAndUpdateView(currentDisplayInfo)
     }
 
     private val displayScaleListener = object : ConfigurationController.ConfigurationListener {
@@ -219,68 +277,109 @@
         }
     }
 
+    private fun addCallbacks() {
+        configurationController.addCallback(displayScaleListener)
+    }
+
+    private fun removeCallbacks() {
+        configurationController.removeCallback(displayScaleListener)
+    }
+
     /**
-     * Hides the view given its [id].
+     * Completely removes the view for the given [id], both visually and from our internal store.
      *
      * @param id the id of the device responsible of displaying the temp view.
      * @param removalReason a short string describing why the view was removed (timeout, state
      *     change, etc.)
      */
+    @Synchronized
     fun removeView(id: String, removalReason: String) {
-        val currentDisplayInfo = displayInfo ?: return
-
-        val removalPosition = findAndRemoveFromActiveViewsList(id)
-        if (removalPosition == null) {
-            logger.logViewRemovalIgnored(id, "view not found in the list")
-            return
-        }
-        if (removalPosition != 0) {
-            logger.logViewRemovalIgnored(id, "most recent view is being displayed.")
-            return
-        }
         logger.logViewRemoval(id, removalReason)
 
-        val newViewToDisplay = if (activeViews.isEmpty()) {
-            null
-        } else {
-            activeViews[0].second
+        val displayInfo = activeViews.firstOrNull { it.info.id == id }
+        if (displayInfo == null) {
+            logger.logViewRemovalIgnored(id, "View not found in list")
+            return
         }
 
-        val currentView = currentDisplayInfo.view
-        animateViewOut(currentView) {
-            windowManager.removeView(currentView)
-            wakeLock?.release(wakeReasonAcquired)
-        }
+        val currentlyDisplayedView = activeViews[0]
+        // Remove immediately (instead as part of the animation end runnable) so that if a new view
+        // event comes in while this view is animating out, we still display the new view
+        // appropriately.
+        activeViews.remove(displayInfo)
 
-        configurationController.removeCallback(displayScaleListener)
-        // Re-set to null immediately (instead as part of the animation end runnable) so
-        // that if a new view event comes in while this view is animating out, we still display
-        // the new view appropriately.
-        displayInfo = null
         // No need to time the view out since it's already gone
-        cancelViewTimeout?.run()
+        displayInfo.cancelViewTimeout?.run()
+
+        if (displayInfo.view == null) {
+            logger.logViewRemovalIgnored(id, "No view to remove")
+            return
+        }
+
+        if (currentlyDisplayedView.info.id != id) {
+            logger.logViewRemovalIgnored(id, "View isn't the currently displayed view")
+            return
+        }
+
+        removeViewFromWindow(displayInfo)
+
+        // Prune anything that's already timed out before determining if we should re-display a
+        // different chipbar.
+        removeTimedOutViews()
+        val newViewToDisplay = getCurrentDisplayInfo()
 
         if (newViewToDisplay != null) {
-            mainExecutor.executeDelayed({ displayView(newViewToDisplay)}, DISPLAY_VIEW_DELAY)
+            val timeout = newViewToDisplay.timeExpirationMillis - systemClock.currentTimeMillis()
+            // TODO(b/258019006): We may want to have a delay before showing the new view so
+            // that the UI translation looks a bit smoother. But, we expect this to happen
+            // rarely so it may not be worth the extra complexity.
+            showNewView(newViewToDisplay, timeout.toInt())
+        } else {
+            removeCallbacks()
         }
     }
 
     /**
-     * Finds and removes the active view with the given [id] from the stack, or null if there is no
-     * active view with that ID
-     *
-     * @param id that temporary view belonged to.
-     *
-     * @return index of the view in the stack , otherwise null.
+     * Hides the view from the window, but keeps [displayInfo] around in [activeViews] in case it
+     * should be re-displayed later.
      */
-    private fun findAndRemoveFromActiveViewsList(id: String): Int? {
-        for (i in 0 until activeViews.size) {
-            if (activeViews[i].first == id) {
-                activeViews.removeAt(i)
-                return i
-            }
+    private fun hideView(displayInfo: DisplayInfo) {
+        logger.logViewHidden(displayInfo.info)
+        removeViewFromWindow(displayInfo)
+    }
+
+    private fun removeViewFromWindow(displayInfo: DisplayInfo) {
+        val view = displayInfo.view
+        if (view == null) {
+            logger.logViewRemovalIgnored(displayInfo.info.id, "View is null")
+            return
         }
-        return null
+        displayInfo.view = null // Need other places??
+        animateViewOut(view) {
+            windowManager.removeView(view)
+            displayInfo.wakeLock?.release(displayInfo.info.wakeReason)
+        }
+    }
+
+    @Synchronized
+    private fun removeTimedOutViews() {
+        val invalidViews = activeViews
+            .filter { it.timeExpirationMillis <
+                systemClock.currentTimeMillis() + MIN_REQUIRED_TIME_FOR_REDISPLAY }
+
+        invalidViews.forEach {
+            activeViews.remove(it)
+            logger.logViewExpiration(it.info)
+        }
+    }
+
+    @Synchronized
+    private fun removeFromActivesIfNeeded(id: String) {
+        val toRemove = activeViews.find { it.info.id == id }
+        toRemove?.let {
+            it.cancelViewTimeout?.run()
+            activeViews.remove(it)
+        }
     }
 
     /**
@@ -311,17 +410,47 @@
     }
 
     /** A container for all the display-related state objects. */
-    private inner class DisplayInfo(
-        /** The view currently being displayed. */
-        val view: ViewGroup,
+    inner class DisplayInfo(
+        /**
+         * The view currently being displayed.
+         *
+         * Null if this info isn't currently being displayed.
+         */
+        var view: ViewGroup?,
 
-        /** The info currently being displayed. */
+        /** The info that should be displayed if/when this is the highest priority view. */
         var info: T,
+
+        /**
+         * The system time at which this display info should expire and never be displayed again.
+         */
+        var timeExpirationMillis: Long,
+
+        /**
+         * The wake lock currently held by this view. Must be released when the view disappears.
+         *
+         * Null if this info isn't currently being displayed.
+         */
+        var wakeLock: WakeLock?,
+
+        /**
+         * See [displayView].
+         */
+        var onViewTimeout: Runnable?,
+
+        /**
+         * A runnable that, when run, will cancel this view's timeout.
+         *
+         * Null if this info isn't currently being displayed.
+         */
+        var cancelViewTimeout: Runnable?,
     )
+
+    // TODO(b/258019006): Add a dump method that dumps the currently active views.
 }
 
 private const val REMOVAL_REASON_TIMEOUT = "TIMEOUT"
-const val DISPLAY_VIEW_DELAY = 50L
+private const val MIN_REQUIRED_TIME_FOR_REDISPLAY = 1000
 
 private data class IconInfo(
     val iconName: String,
diff --git a/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewInfo.kt b/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewInfo.kt
index df83960..5596cf6 100644
--- a/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewInfo.kt
+++ b/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewInfo.kt
@@ -42,6 +42,20 @@
      * The id of the temporary view.
      */
     abstract val id: String
+
+    /** The priority for this view. */
+    abstract val priority: ViewPriority
 }
 
 const val DEFAULT_TIMEOUT_MILLIS = 10000
+
+/**
+ * The priority of the view being displayed.
+ *
+ * Must be ordered from lowest priority to highest priority. (CRITICAL is currently the highest
+ * priority.)
+ */
+enum class ViewPriority {
+    NORMAL,
+    CRITICAL,
+}
diff --git a/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewLogger.kt b/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewLogger.kt
index 133a384..ec6965a 100644
--- a/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewLogger.kt
@@ -20,20 +20,79 @@
 import com.android.systemui.plugins.log.LogLevel
 
 /** A logger for temporary view changes -- see [TemporaryViewDisplayController]. */
-open class TemporaryViewLogger(
+open class TemporaryViewLogger<T : TemporaryViewInfo>(
     internal val buffer: LogBuffer,
     internal val tag: String,
 ) {
-    /** Logs that we added the view with the given [id] in a window titled [windowTitle]. */
-    fun logViewAddition(id: String, windowTitle: String) {
+    fun logViewExpiration(info: T) {
         buffer.log(
             tag,
             LogLevel.DEBUG,
             {
-                str1 = windowTitle
-                str2 = id
+                str1 = info.id
+                str2 = info.windowTitle
+                str3 = info.priority.name
             },
-            { "View added. window=$str1 id=$str2" }
+            { "View timeout has already expired; removing. id=$str1 window=$str2 priority=$str3" }
+        )
+    }
+
+    fun logViewUpdate(info: T) {
+        buffer.log(
+            tag,
+            LogLevel.DEBUG,
+            {
+                str1 = info.id
+                str2 = info.windowTitle
+                str3 = info.priority.name
+            },
+            { "Existing view updated with new data. id=$str1 window=$str2 priority=$str3" }
+        )
+    }
+
+    fun logViewAdditionDelayed(info: T) {
+        buffer.log(
+            tag,
+            LogLevel.DEBUG,
+            {
+                str1 = info.id
+                str2 = info.windowTitle
+                str3 = info.priority.name
+            },
+            {
+                "New view can't be displayed because higher priority view is currently " +
+                    "displayed. New view id=$str1 window=$str2 priority=$str3"
+            }
+        )
+    }
+
+    /** Logs that we added the view with the given information. */
+    fun logViewAddition(info: T) {
+        buffer.log(
+            tag,
+            LogLevel.DEBUG,
+            {
+                str1 = info.id
+                str2 = info.windowTitle
+                str3 = info.priority.name
+            },
+            { "View added. id=$str1 window=$str2 priority=$str3" }
+        )
+    }
+
+    fun logViewHidden(info: T) {
+        buffer.log(
+            tag,
+            LogLevel.DEBUG,
+            {
+                str1 = info.id
+                str2 = info.windowTitle
+                str3 = info.priority.name
+            },
+            {
+                "View hidden in favor of newer view. " +
+                    "Hidden view id=$str1 window=$str2 priority=$str3"
+            }
         )
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinator.kt b/packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinator.kt
index fb17b69..14ba63a 100644
--- a/packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinator.kt
+++ b/packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinator.kt
@@ -34,8 +34,8 @@
 import com.android.systemui.classifier.FalsingCollector
 import com.android.systemui.common.shared.model.ContentDescription.Companion.loadContentDescription
 import com.android.systemui.common.shared.model.Text.Companion.loadText
-import com.android.systemui.common.ui.binder.IconViewBinder
 import com.android.systemui.common.ui.binder.TextViewBinder
+import com.android.systemui.common.ui.binder.TintedIconViewBinder
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.dagger.qualifiers.Main
 import com.android.systemui.plugins.FalsingManager
@@ -43,6 +43,7 @@
 import com.android.systemui.statusbar.policy.ConfigurationController
 import com.android.systemui.temporarydisplay.TemporaryViewDisplayController
 import com.android.systemui.util.concurrency.DelayableExecutor
+import com.android.systemui.util.time.SystemClock
 import com.android.systemui.util.view.ViewUtil
 import com.android.systemui.util.wakelock.WakeLock
 import javax.inject.Inject
@@ -77,6 +78,7 @@
         private val viewUtil: ViewUtil,
         private val vibratorHelper: VibratorHelper,
         wakeLockBuilder: WakeLock.Builder,
+        systemClock: SystemClock,
 ) : TemporaryViewDisplayController<ChipbarInfo, ChipbarLogger>(
         context,
         logger,
@@ -87,6 +89,7 @@
         powerManager,
         R.layout.chipbar,
         wakeLockBuilder,
+        systemClock,
 ) {
 
     private lateinit var parent: ChipbarRootView
@@ -121,7 +124,7 @@
 
         // ---- Start icon ----
         val iconView = currentView.requireViewById<CachingIconView>(R.id.start_icon)
-        IconViewBinder.bind(newInfo.startIcon, iconView)
+        TintedIconViewBinder.bind(newInfo.startIcon, iconView)
 
         // ---- Text ----
         val textView = currentView.requireViewById<TextView>(R.id.text)
@@ -156,11 +159,14 @@
         }
 
         // ---- Overall accessibility ----
-        currentView.requireViewById<ViewGroup>(
-                R.id.chipbar_inner
-        ).contentDescription =
-            "${newInfo.startIcon.contentDescription.loadContentDescription(context)} " +
-                "${newInfo.text.loadText(context)}"
+        val iconDesc = newInfo.startIcon.icon.contentDescription
+        val loadedIconDesc = if (iconDesc != null) {
+            "${iconDesc.loadContentDescription(context)} "
+        } else {
+            ""
+        }
+        currentView.requireViewById<ViewGroup>(R.id.chipbar_inner).contentDescription =
+            "$loadedIconDesc${newInfo.text.loadText(context)}"
 
         // ---- Haptics ----
         newInfo.vibrationEffect?.let {
diff --git a/packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarInfo.kt b/packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarInfo.kt
index b92e0ec..dd4bd26 100644
--- a/packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarInfo.kt
+++ b/packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarInfo.kt
@@ -18,9 +18,11 @@
 
 import android.os.VibrationEffect
 import android.view.View
-import com.android.systemui.common.shared.model.Icon
+import androidx.annotation.AttrRes
 import com.android.systemui.common.shared.model.Text
+import com.android.systemui.common.shared.model.TintedIcon
 import com.android.systemui.temporarydisplay.TemporaryViewInfo
+import com.android.systemui.temporarydisplay.ViewPriority
 
 /**
  * A container for all the state needed to display a chipbar via [ChipbarCoordinator].
@@ -33,7 +35,7 @@
  * @property vibrationEffect an optional vibration effect when the chipbar is displayed
  */
 data class ChipbarInfo(
-    val startIcon: Icon,
+    val startIcon: TintedIcon,
     val text: Text,
     val endItem: ChipbarEndItem?,
     val vibrationEffect: VibrationEffect? = null,
@@ -41,7 +43,12 @@
     override val wakeReason: String,
     override val timeoutMs: Int,
     override val id: String,
-) : TemporaryViewInfo()
+    override val priority: ViewPriority,
+) : TemporaryViewInfo() {
+    companion object {
+        @AttrRes const val DEFAULT_ICON_TINT_ATTR = android.R.attr.textColorPrimary
+    }
+}
 
 /** The possible items to display at the end of the chipbar. */
 sealed class ChipbarEndItem {
diff --git a/packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarLogger.kt b/packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarLogger.kt
index e477cd6..fcfbe0a 100644
--- a/packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/temporarydisplay/chipbar/ChipbarLogger.kt
@@ -29,7 +29,7 @@
 @Inject
 constructor(
     @ChipbarLog buffer: LogBuffer,
-) : TemporaryViewLogger(buffer, "ChipbarLog") {
+) : TemporaryViewLogger<ChipbarInfo>(buffer, "ChipbarLog") {
     /**
      * Logs that the chipbar was updated to display in a window named [windowTitle], with [text] and
      * [endItemDesc].
diff --git a/packages/SystemUI/src/com/android/systemui/touch/TouchInsetManager.java b/packages/SystemUI/src/com/android/systemui/touch/TouchInsetManager.java
index 3d07491..166ac9e 100644
--- a/packages/SystemUI/src/com/android/systemui/touch/TouchInsetManager.java
+++ b/packages/SystemUI/src/com/android/systemui/touch/TouchInsetManager.java
@@ -18,41 +18,58 @@
 
 import android.graphics.Rect;
 import android.graphics.Region;
+import android.util.Log;
+import android.view.AttachedSurfaceControl;
 import android.view.View;
-import android.view.ViewRootImpl;
 
 import androidx.concurrent.futures.CallbackToFutureAdapter;
 
+import com.android.systemui.dagger.qualifiers.Main;
+
 import com.google.common.util.concurrent.ListenableFuture;
 
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.concurrent.Executor;
 
+import javax.inject.Inject;
+
 /**
  * {@link TouchInsetManager} handles setting the touchable inset regions for a given View. This
  * is useful for passing through touch events for all but select areas.
  */
 public class TouchInsetManager {
+    private static final String TAG = "TouchInsetManager";
     /**
      * {@link TouchInsetSession} provides an individualized session with the
      * {@link TouchInsetManager}, linking any action to the client.
      */
     public static class TouchInsetSession {
         private final TouchInsetManager mManager;
-
         private final HashSet<View> mTrackedViews;
         private final Executor mExecutor;
 
         private final View.OnLayoutChangeListener mOnLayoutChangeListener =
                 (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom)
-                        -> updateTouchRegion();
+                        -> updateTouchRegions();
+
+        private final View.OnAttachStateChangeListener mAttachListener =
+                new View.OnAttachStateChangeListener() {
+                    @Override
+                    public void onViewAttachedToWindow(View v) {
+                        updateTouchRegions();
+                    }
+
+                    @Override
+                    public void onViewDetachedFromWindow(View v) {
+                        updateTouchRegions();
+                    }
+                };
 
         /**
          * Default constructor
          * @param manager The parent {@link TouchInsetManager} which will be affected by actions on
          *                this session.
-         * @param rootView The parent of views that will be tracked.
          * @param executor An executor for marshalling operations.
          */
         TouchInsetSession(TouchInsetManager manager, Executor executor) {
@@ -68,8 +85,9 @@
         public void addViewToTracking(View view) {
             mExecutor.execute(() -> {
                 mTrackedViews.add(view);
+                view.addOnAttachStateChangeListener(mAttachListener);
                 view.addOnLayoutChangeListener(mOnLayoutChangeListener);
-                updateTouchRegion();
+                updateTouchRegions();
             });
         }
 
@@ -81,22 +99,30 @@
             mExecutor.execute(() -> {
                 mTrackedViews.remove(view);
                 view.removeOnLayoutChangeListener(mOnLayoutChangeListener);
-                updateTouchRegion();
+                view.removeOnAttachStateChangeListener(mAttachListener);
+                updateTouchRegions();
             });
         }
 
-        private void updateTouchRegion() {
-            final Region cumulativeRegion = Region.obtain();
+        private void updateTouchRegions() {
+            mExecutor.execute(() -> {
+                final HashMap<AttachedSurfaceControl, Region> affectedSurfaces = new HashMap<>();
+                mTrackedViews.stream().forEach(view -> {
+                    if (!view.isAttachedToWindow()) {
+                        return;
+                    }
 
-            mTrackedViews.stream().forEach(view -> {
-                final Rect boundaries = new Rect();
-                view.getBoundsOnScreen(boundaries);
-                cumulativeRegion.op(boundaries, Region.Op.UNION);
+                    final AttachedSurfaceControl surface = view.getRootSurfaceControl();
+
+                    if (!affectedSurfaces.containsKey(surface)) {
+                        affectedSurfaces.put(surface, Region.obtain());
+                    }
+                    final Rect boundaries = new Rect();
+                    view.getBoundsOnScreen(boundaries);
+                    affectedSurfaces.get(surface).op(boundaries, Region.Op.UNION);
+                });
+                mManager.setTouchRegions(this, affectedSurfaces);
             });
-
-            mManager.setTouchRegion(this, cumulativeRegion);
-
-            cumulativeRegion.recycle();
         }
 
         /**
@@ -110,32 +136,18 @@
         }
     }
 
-    private final HashMap<TouchInsetSession, Region> mDefinedRegions = new HashMap<>();
+    private final HashMap<TouchInsetSession, HashMap<AttachedSurfaceControl, Region>>
+            mSessionRegions = new HashMap<>();
+    private final HashMap<AttachedSurfaceControl, Region> mLastAffectedSurfaces = new HashMap();
     private final Executor mExecutor;
-    private final View mRootView;
-
-    private final View.OnAttachStateChangeListener mAttachListener =
-            new View.OnAttachStateChangeListener() {
-                @Override
-                public void onViewAttachedToWindow(View v) {
-                    updateTouchInset();
-                }
-
-                @Override
-                public void onViewDetachedFromWindow(View v) {
-                }
-            };
 
     /**
      * Default constructor.
      * @param executor An {@link Executor} to marshal all operations on.
-     * @param rootView The root {@link View} for all views in sessions.
      */
-    public TouchInsetManager(Executor executor, View rootView) {
+    @Inject
+    public TouchInsetManager(@Main Executor executor) {
         mExecutor = executor;
-        mRootView = rootView;
-        mRootView.addOnAttachStateChangeListener(mAttachListener);
-
     }
 
     /**
@@ -151,47 +163,68 @@
     public ListenableFuture<Boolean> checkWithinTouchRegion(int x, int y) {
         return CallbackToFutureAdapter.getFuture(completer -> {
             mExecutor.execute(() -> completer.set(
-                    mDefinedRegions.values().stream().anyMatch(region -> region.contains(x, y))));
+                    mLastAffectedSurfaces.values().stream().anyMatch(
+                            region -> region.contains(x, y))));
 
             return "DreamOverlayTouchMonitor::checkWithinTouchRegion";
         });
     }
 
-    private void updateTouchInset() {
-        final ViewRootImpl viewRootImpl = mRootView.getViewRootImpl();
+    private void updateTouchInsets() {
+        // Get affected
+        final HashMap<AttachedSurfaceControl, Region> affectedSurfaces = new HashMap<>();
+        mSessionRegions.values().stream().forEach(regionMapping -> {
+            regionMapping.entrySet().stream().forEach(entry -> {
+                final AttachedSurfaceControl surface = entry.getKey();
+                if (!affectedSurfaces.containsKey(surface)) {
+                    affectedSurfaces.put(surface, Region.obtain());
+                }
 
-        if (viewRootImpl == null) {
+                affectedSurfaces.get(surface).op(entry.getValue(), Region.Op.UNION);
+            });
+        });
+
+        affectedSurfaces.entrySet().stream().forEach(entry -> {
+            entry.getKey().setTouchableRegion(entry.getValue());
+        });
+
+        mLastAffectedSurfaces.entrySet().forEach(entry -> {
+            final AttachedSurfaceControl surface = entry.getKey();
+            if (!affectedSurfaces.containsKey(surface)) {
+                surface.setTouchableRegion(null);
+            }
+            entry.getValue().recycle();
+        });
+
+        mLastAffectedSurfaces.clear();
+        mLastAffectedSurfaces.putAll(affectedSurfaces);
+    }
+
+    protected void setTouchRegions(TouchInsetSession session,
+            HashMap<AttachedSurfaceControl, Region> regions) {
+        mExecutor.execute(() -> {
+            recycleRegions(session);
+            mSessionRegions.put(session, regions);
+            updateTouchInsets();
+        });
+    }
+
+    private void recycleRegions(TouchInsetSession session) {
+        if (!mSessionRegions.containsKey(session)) {
+            Log.w(TAG,  "Removing a session with no regions:" + session);
             return;
         }
 
-        final Region aggregateRegion = Region.obtain();
-
-        for (Region region : mDefinedRegions.values()) {
-            aggregateRegion.op(region, Region.Op.UNION);
+        for (Region region : mSessionRegions.get(session).values()) {
+            region.recycle();
         }
-
-        viewRootImpl.setTouchableRegion(aggregateRegion);
-
-        aggregateRegion.recycle();
-    }
-
-    protected void setTouchRegion(TouchInsetSession session, Region region) {
-        final Region introducedRegion = Region.obtain(region);
-        mExecutor.execute(() -> {
-            mDefinedRegions.put(session, introducedRegion);
-            updateTouchInset();
-        });
     }
 
     private void clearRegion(TouchInsetSession session) {
         mExecutor.execute(() -> {
-            final Region storedRegion = mDefinedRegions.remove(session);
-
-            if (storedRegion != null) {
-                storedRegion.recycle();
-            }
-
-            updateTouchInset();
+            recycleRegions(session);
+            mSessionRegions.remove(session);
+            updateTouchInsets();
         });
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/unfold/SysUIUnfoldModule.kt b/packages/SystemUI/src/com/android/systemui/unfold/SysUIUnfoldModule.kt
index 13ac39c..209d93f 100644
--- a/packages/SystemUI/src/com/android/systemui/unfold/SysUIUnfoldModule.kt
+++ b/packages/SystemUI/src/com/android/systemui/unfold/SysUIUnfoldModule.kt
@@ -92,5 +92,7 @@
 
     fun getUnfoldTransitionWallpaperController(): UnfoldTransitionWallpaperController
 
+    fun getUnfoldHapticsPlayer(): UnfoldHapticsPlayer
+
     fun getUnfoldLightRevealOverlayAnimation(): UnfoldLightRevealOverlayAnimation
 }
diff --git a/packages/SystemUI/src/com/android/systemui/unfold/UnfoldHapticsPlayer.kt b/packages/SystemUI/src/com/android/systemui/unfold/UnfoldHapticsPlayer.kt
new file mode 100644
index 0000000..7726d09
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/unfold/UnfoldHapticsPlayer.kt
@@ -0,0 +1,93 @@
+package com.android.systemui.unfold
+
+import android.os.SystemProperties
+import android.os.VibrationEffect
+import android.os.Vibrator
+import com.android.systemui.unfold.UnfoldTransitionProgressProvider.TransitionProgressListener
+import javax.inject.Inject
+
+/**
+ * Class that plays a haptics effect during unfolding a foldable device
+ */
+@SysUIUnfoldScope
+class UnfoldHapticsPlayer
+@Inject
+constructor(
+    unfoldTransitionProgressProvider: UnfoldTransitionProgressProvider,
+    private val vibrator: Vibrator?
+) : TransitionProgressListener {
+
+    init {
+        if (vibrator != null) {
+            // We don't need to remove the callback because we should listen to it
+            // the whole time when SystemUI process is alive
+            unfoldTransitionProgressProvider.addCallback(this)
+        }
+    }
+
+    private var lastTransitionProgress = TRANSITION_PROGRESS_FULL_OPEN
+
+    override fun onTransitionStarted() {
+        lastTransitionProgress = TRANSITION_PROGRESS_CLOSED
+    }
+
+    override fun onTransitionProgress(progress: Float) {
+        lastTransitionProgress = progress
+    }
+
+    override fun onTransitionFinishing() {
+        // Run haptics only if the animation is long enough to notice
+        if (lastTransitionProgress < TRANSITION_NOTICEABLE_THRESHOLD) {
+            playHaptics()
+        }
+    }
+
+    override fun onTransitionFinished() {
+        lastTransitionProgress = TRANSITION_PROGRESS_FULL_OPEN
+    }
+
+    private fun playHaptics() {
+        vibrator?.vibrate(effect)
+    }
+
+    private val hapticsScale: Float
+        get() {
+            val intensityString = SystemProperties.get("persist.unfold.haptics_scale", "0.1")
+            return intensityString.toFloatOrNull() ?: 0.1f
+        }
+
+    private val hapticsScaleTick: Float
+        get() {
+            val intensityString =
+                SystemProperties.get("persist.unfold.haptics_scale_end_tick", "0.6")
+            return intensityString.toFloatOrNull() ?: 0.6f
+        }
+
+    private val primitivesCount: Int
+        get() {
+            val count = SystemProperties.get("persist.unfold.primitives_count", "18")
+            return count.toIntOrNull() ?: 18
+        }
+
+    private val effect: VibrationEffect by lazy {
+        val composition =
+            VibrationEffect.startComposition()
+                .addPrimitive(VibrationEffect.Composition.PRIMITIVE_TICK, 0F, 0)
+
+        repeat(primitivesCount) {
+            composition.addPrimitive(
+                VibrationEffect.Composition.PRIMITIVE_LOW_TICK,
+                hapticsScale,
+                0
+            )
+        }
+
+        composition
+            .addPrimitive(VibrationEffect.Composition.PRIMITIVE_TICK, hapticsScaleTick)
+            .compose()
+    }
+}
+
+private const val TRANSITION_PROGRESS_CLOSED = 0f
+private const val TRANSITION_PROGRESS_FULL_OPEN = 1f
+private const val TRANSITION_NOTICEABLE_THRESHOLD = 0.9f
diff --git a/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserInteractor.kt b/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserInteractor.kt
index 512fadf..74295f0 100644
--- a/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserInteractor.kt
@@ -31,6 +31,7 @@
 import android.os.UserManager
 import android.provider.Settings
 import android.util.Log
+import com.android.internal.logging.UiEventLogger
 import com.android.internal.util.UserIcons
 import com.android.systemui.R
 import com.android.systemui.SystemUISecondaryUserService
@@ -54,6 +55,7 @@
 import com.android.systemui.user.legacyhelper.data.LegacyUserDataHelper
 import com.android.systemui.user.shared.model.UserActionModel
 import com.android.systemui.user.shared.model.UserModel
+import com.android.systemui.user.utils.MultiUserActionsEvent
 import com.android.systemui.util.kotlin.pairwise
 import java.io.PrintWriter
 import javax.inject.Inject
@@ -93,6 +95,7 @@
     private val activityManager: ActivityManager,
     private val refreshUsersScheduler: RefreshUsersScheduler,
     private val guestUserInteractor: GuestUserInteractor,
+    private val uiEventLogger: UiEventLogger,
 ) {
     /**
      * Defines interface for classes that can be notified when the state of users on the device is
@@ -115,9 +118,7 @@
     private val callbackMutex = Mutex()
     private val callbacks = mutableSetOf<UserCallback>()
     private val userInfos: Flow<List<UserInfo>> =
-        repository.userInfos.map { userInfos ->
-            userInfos.filter { it.isFull }
-        }
+        repository.userInfos.map { userInfos -> userInfos.filter { it.isFull } }
 
     /** List of current on-device users to select from. */
     val users: Flow<List<UserModel>>
@@ -427,14 +428,17 @@
         dialogShower: UserSwitchDialogController.DialogShower? = null,
     ) {
         when (action) {
-            UserActionModel.ENTER_GUEST_MODE ->
+            UserActionModel.ENTER_GUEST_MODE -> {
+                uiEventLogger.log(MultiUserActionsEvent.CREATE_GUEST_FROM_USER_SWITCHER)
                 guestUserInteractor.createAndSwitchTo(
                     this::showDialog,
                     this::dismissDialog,
                 ) { userId ->
                     selectUser(userId, dialogShower)
                 }
+            }
             UserActionModel.ADD_USER -> {
+                uiEventLogger.log(MultiUserActionsEvent.CREATE_USER_FROM_USER_SWITCHER)
                 val currentUser = repository.getSelectedUserInfo()
                 showDialog(
                     ShowDialogRequestModel.ShowAddUserDialog(
@@ -445,7 +449,8 @@
                     )
                 )
             }
-            UserActionModel.ADD_SUPERVISED_USER ->
+            UserActionModel.ADD_SUPERVISED_USER -> {
+                uiEventLogger.log(MultiUserActionsEvent.CREATE_RESTRICTED_USER_FROM_USER_SWITCHER)
                 activityStarter.startActivity(
                     Intent()
                         .setAction(UserManager.ACTION_CREATE_SUPERVISED_USER)
@@ -453,6 +458,7 @@
                         .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
                     /* dismissShade= */ true,
                 )
+            }
             UserActionModel.NAVIGATE_TO_USER_MANAGEMENT ->
                 activityStarter.startActivity(
                     Intent(Settings.ACTION_USER_SETTINGS),
diff --git a/packages/SystemUI/src/com/android/systemui/user/utils/MultiUserActionsEvent.kt b/packages/SystemUI/src/com/android/systemui/user/utils/MultiUserActionsEvent.kt
new file mode 100644
index 0000000..bfedac9
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/user/utils/MultiUserActionsEvent.kt
@@ -0,0 +1,31 @@
+/*
+ * 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.systemui.user.utils
+
+import com.android.internal.logging.UiEvent
+import com.android.internal.logging.UiEventLogger
+
+enum class MultiUserActionsEvent(val value: Int) : UiEventLogger.UiEventEnum {
+    @UiEvent(doc = "Add User tap from User Switcher.") CREATE_USER_FROM_USER_SWITCHER(1257),
+    @UiEvent(doc = "Add Guest tap from User Switcher.") CREATE_GUEST_FROM_USER_SWITCHER(1258),
+    @UiEvent(doc = "Add Restricted User tap from User Switcher.")
+    CREATE_RESTRICTED_USER_FROM_USER_SWITCHER(1259);
+
+    override fun getId(): Int {
+        return value
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java
index 1bc0d08..fa3c73a 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java
@@ -115,9 +115,11 @@
 import com.android.internal.jank.InteractionJankMonitor;
 import com.android.internal.view.RotationPolicy;
 import com.android.settingslib.Utils;
+import com.android.systemui.Dumpable;
 import com.android.systemui.Prefs;
 import com.android.systemui.R;
 import com.android.systemui.animation.Interpolators;
+import com.android.systemui.dump.DumpManager;
 import com.android.systemui.media.dialog.MediaOutputDialogFactory;
 import com.android.systemui.plugins.ActivityStarter;
 import com.android.systemui.plugins.VolumeDialog;
@@ -146,7 +148,7 @@
  *
  * Methods ending in "H" must be called on the (ui) handler.
  */
-public class VolumeDialogImpl implements VolumeDialog,
+public class VolumeDialogImpl implements VolumeDialog, Dumpable,
         ConfigurationController.ConfigurationListener,
         ViewTreeObserver.OnComputeInternalInsetsListener {
     private static final String TAG = Util.logTag(VolumeDialogImpl.class);
@@ -302,7 +304,8 @@
             ActivityStarter activityStarter,
             InteractionJankMonitor interactionJankMonitor,
             DeviceConfigProxy deviceConfigProxy,
-            Executor executor) {
+            Executor executor,
+            DumpManager dumpManager) {
         mContext =
                 new ContextThemeWrapper(context, R.style.volume_dialog_theme);
         mController = volumeDialogController;
@@ -329,6 +332,8 @@
             mContext.getResources().getBoolean(R.bool.config_volumeDialogUseBackgroundBlur);
         mInteractionJankMonitor = interactionJankMonitor;
 
+        dumpManager.registerDumpable("VolumeDialogImpl", this);
+
         if (mUseBackgroundBlur) {
             final int dialogRowsViewColorAboveBlur = mContext.getColor(
                     R.color.volume_dialog_background_color_above_blur);
@@ -793,7 +798,10 @@
         return null;
     }
 
-    public void dump(PrintWriter writer) {
+    /**
+     * Print dump info for debugging.
+     */
+    public void dump(PrintWriter writer, String[] unusedArgs) {
         writer.println(VolumeDialogImpl.class.getSimpleName() + " state:");
         writer.print("  mShowing: "); writer.println(mShowing);
         writer.print("  mActiveStream: "); writer.println(mActiveStream);
diff --git a/packages/SystemUI/src/com/android/systemui/volume/dagger/VolumeModule.java b/packages/SystemUI/src/com/android/systemui/volume/dagger/VolumeModule.java
index 8f10fa6..0ab6c69 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/dagger/VolumeModule.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/dagger/VolumeModule.java
@@ -21,6 +21,7 @@
 
 import com.android.internal.jank.InteractionJankMonitor;
 import com.android.systemui.dagger.qualifiers.Main;
+import com.android.systemui.dump.DumpManager;
 import com.android.systemui.media.dialog.MediaOutputDialogFactory;
 import com.android.systemui.plugins.ActivityStarter;
 import com.android.systemui.plugins.VolumeDialog;
@@ -61,7 +62,8 @@
             ActivityStarter activityStarter,
             InteractionJankMonitor interactionJankMonitor,
             DeviceConfigProxy deviceConfigProxy,
-            @Main Executor executor) {
+            @Main Executor executor,
+            DumpManager dumpManager) {
         VolumeDialogImpl impl = new VolumeDialogImpl(
                 context,
                 volumeDialogController,
@@ -73,7 +75,8 @@
                 activityStarter,
                 interactionJankMonitor,
                 deviceConfigProxy,
-                executor);
+                executor,
+                dumpManager);
         impl.setStreamImportant(AudioManager.STREAM_SYSTEM, false);
         impl.setAutomute(true);
         impl.setSilentMode(false);
diff --git a/packages/SystemUI/src/com/android/systemui/wallpapers/ImageWallpaper.java b/packages/SystemUI/src/com/android/systemui/wallpapers/ImageWallpaper.java
index 5df4a5b..51742990 100644
--- a/packages/SystemUI/src/com/android/systemui/wallpapers/ImageWallpaper.java
+++ b/packages/SystemUI/src/com/android/systemui/wallpapers/ImageWallpaper.java
@@ -16,8 +16,6 @@
 
 package com.android.systemui.wallpapers;
 
-import static com.android.systemui.flags.Flags.USE_CANVAS_RENDERER;
-
 import android.app.WallpaperColors;
 import android.app.WallpaperManager;
 import android.graphics.Bitmap;
@@ -27,17 +25,12 @@
 import android.graphics.RectF;
 import android.hardware.display.DisplayManager;
 import android.hardware.display.DisplayManager.DisplayListener;
-import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.Looper;
-import android.os.SystemClock;
 import android.os.Trace;
 import android.os.UserHandle;
 import android.service.wallpaper.WallpaperService;
-import android.util.ArraySet;
 import android.util.Log;
-import android.util.MathUtils;
-import android.util.Size;
 import android.view.Surface;
 import android.view.SurfaceHolder;
 import android.view.WindowManager;
@@ -46,19 +39,11 @@
 
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.systemui.dagger.qualifiers.Background;
-import com.android.systemui.dagger.qualifiers.Main;
-import com.android.systemui.flags.FeatureFlags;
 import com.android.systemui.util.concurrency.DelayableExecutor;
-import com.android.systemui.wallpapers.canvas.WallpaperLocalColorExtractor;
-import com.android.systemui.wallpapers.gl.EglHelper;
-import com.android.systemui.wallpapers.gl.ImageWallpaperRenderer;
 
 import java.io.FileDescriptor;
-import java.io.IOException;
 import java.io.PrintWriter;
-import java.util.ArrayList;
 import java.util.List;
-import java.util.concurrent.Executor;
 
 import javax.inject.Inject;
 
@@ -67,39 +52,29 @@
  */
 @SuppressWarnings({"UnusedDeclaration"})
 public class ImageWallpaper extends WallpaperService {
+
     private static final String TAG = ImageWallpaper.class.getSimpleName();
-    // We delayed destroy render context that subsequent render requests have chance to cancel it.
-    // This is to avoid destroying then recreating render context in a very short time.
-    private static final int DELAY_FINISH_RENDERING = 1000;
-    private static final @android.annotation.NonNull RectF LOCAL_COLOR_BOUNDS =
-            new RectF(0, 0, 1, 1);
     private static final boolean DEBUG = false;
 
-    private final ArrayList<RectF> mLocalColorsToAdd = new ArrayList<>();
-    private final ArraySet<RectF> mColorAreas = new ArraySet<>();
+    // keep track of the number of pages of the launcher for local color extraction purposes
     private volatile int mPages = 1;
     private boolean mPagesComputed = false;
-    private HandlerThread mWorker;
-    // scaled down version
-    private Bitmap mMiniBitmap;
-    private final FeatureFlags mFeatureFlags;
 
-    // used in canvasEngine to load/unload the bitmap and extract the colors
+    // used to handle WallpaperService messages (e.g. DO_ATTACH, MSG_UPDATE_SURFACE)
+    // and to receive WallpaperService callbacks (e.g. onCreateEngine, onSurfaceRedrawNeeded)
+    private HandlerThread mWorker;
+
+    // used for most tasks (call canvas.drawBitmap, load/unload the bitmap)
     @Background
     private final DelayableExecutor mBackgroundExecutor;
+
+    // wait at least this duration before unloading the bitmap
     private static final int DELAY_UNLOAD_BITMAP = 2000;
 
-    @Main
-    private final Executor mMainExecutor;
-
     @Inject
-    public ImageWallpaper(FeatureFlags featureFlags,
-            @Background DelayableExecutor backgroundExecutor,
-            @Main Executor mainExecutor) {
+    public ImageWallpaper(@Background DelayableExecutor backgroundExecutor) {
         super();
-        mFeatureFlags = featureFlags;
         mBackgroundExecutor = backgroundExecutor;
-        mMainExecutor = mainExecutor;
     }
 
     @Override
@@ -120,416 +95,9 @@
 
     @Override
     public Engine onCreateEngine() {
-        return mFeatureFlags.isEnabled(USE_CANVAS_RENDERER) ? new CanvasEngine() : new GLEngine();
+        return new CanvasEngine();
     }
 
-    @Override
-    public void onDestroy() {
-        super.onDestroy();
-        mWorker.quitSafely();
-        mWorker = null;
-        mMiniBitmap = null;
-    }
-
-    class GLEngine extends Engine implements DisplayListener {
-        // Surface is rejected if size below a threshold on some devices (ie. 8px on elfin)
-        // set min to 64 px (CTS covers this), please refer to ag/4867989 for detail.
-        @VisibleForTesting
-        static final int MIN_SURFACE_WIDTH = 128;
-        @VisibleForTesting
-        static final int MIN_SURFACE_HEIGHT = 128;
-
-        private ImageWallpaperRenderer mRenderer;
-        private EglHelper mEglHelper;
-        private final Runnable mFinishRenderingTask = this::finishRendering;
-        private boolean mNeedRedraw;
-
-        private boolean mDisplaySizeValid = false;
-        private int mDisplayWidth = 1;
-        private int mDisplayHeight = 1;
-
-        private int mImgWidth = 1;
-        private int mImgHeight = 1;
-
-        GLEngine() { }
-
-        @VisibleForTesting
-        GLEngine(Handler handler) {
-            super(SystemClock::elapsedRealtime, handler);
-        }
-
-        @Override
-        public void onCreate(SurfaceHolder surfaceHolder) {
-            Trace.beginSection("ImageWallpaper.Engine#onCreate");
-            mEglHelper = getEglHelperInstance();
-            // Deferred init renderer because we need to get wallpaper by display context.
-            mRenderer = getRendererInstance();
-            setFixedSizeAllowed(true);
-            updateSurfaceSize();
-            setShowForAllUsers(true);
-
-            mRenderer.setOnBitmapChanged(b -> {
-                mLocalColorsToAdd.addAll(mColorAreas);
-                if (mLocalColorsToAdd.size() > 0) {
-                    updateMiniBitmapAndNotify(b);
-                }
-            });
-            getDisplayContext().getSystemService(DisplayManager.class)
-                    .registerDisplayListener(this, mWorker.getThreadHandler());
-            Trace.endSection();
-        }
-
-        @Override
-        public void onDisplayAdded(int displayId) { }
-
-        @Override
-        public void onDisplayRemoved(int displayId) { }
-
-        @Override
-        public void onDisplayChanged(int displayId) {
-            if (displayId == getDisplayContext().getDisplayId()) {
-                mDisplaySizeValid = false;
-            }
-        }
-
-        EglHelper getEglHelperInstance() {
-            return new EglHelper();
-        }
-
-        ImageWallpaperRenderer getRendererInstance() {
-            return new ImageWallpaperRenderer(getDisplayContext());
-        }
-
-        @Override
-        public void onOffsetsChanged(float xOffset, float yOffset,
-                float xOffsetStep, float yOffsetStep,
-                int xPixelOffset, int yPixelOffset) {
-            final int pages;
-            if (xOffsetStep > 0 && xOffsetStep <= 1) {
-                pages = (int) Math.round(1 / xOffsetStep) + 1;
-            } else {
-                pages = 1;
-            }
-            if (pages == mPages) return;
-            mPages = pages;
-            if (mMiniBitmap == null || mMiniBitmap.isRecycled()) return;
-            mWorker.getThreadHandler().post(() ->
-                    computeAndNotifyLocalColors(new ArrayList<>(mColorAreas), mMiniBitmap));
-        }
-
-        private void updateMiniBitmapAndNotify(Bitmap b) {
-            if (b == null) return;
-            int size = Math.min(b.getWidth(), b.getHeight());
-            float scale = 1.0f;
-            if (size > MIN_SURFACE_WIDTH) {
-                scale = (float) MIN_SURFACE_WIDTH / (float) size;
-            }
-            mImgHeight = b.getHeight();
-            mImgWidth = b.getWidth();
-            mMiniBitmap = Bitmap.createScaledBitmap(b,  (int) Math.max(scale * b.getWidth(), 1),
-                    (int) Math.max(scale * b.getHeight(), 1), false);
-            computeAndNotifyLocalColors(mLocalColorsToAdd, mMiniBitmap);
-            mLocalColorsToAdd.clear();
-        }
-
-        private void updateSurfaceSize() {
-            Trace.beginSection("ImageWallpaper#updateSurfaceSize");
-            SurfaceHolder holder = getSurfaceHolder();
-            Size frameSize = mRenderer.reportSurfaceSize();
-            int width = Math.max(MIN_SURFACE_WIDTH, frameSize.getWidth());
-            int height = Math.max(MIN_SURFACE_HEIGHT, frameSize.getHeight());
-            holder.setFixedSize(width, height);
-            Trace.endSection();
-        }
-
-        @Override
-        public boolean shouldZoomOutWallpaper() {
-            return true;
-        }
-
-        @Override
-        public boolean shouldWaitForEngineShown() {
-            return true;
-        }
-
-        @Override
-        public void onDestroy() {
-            getDisplayContext().getSystemService(DisplayManager.class)
-                    .unregisterDisplayListener(this);
-            mMiniBitmap = null;
-            mWorker.getThreadHandler().post(() -> {
-                mRenderer.finish();
-                mRenderer = null;
-                mEglHelper.finish();
-                mEglHelper = null;
-            });
-        }
-
-        @Override
-        public boolean supportsLocalColorExtraction() {
-            return true;
-        }
-
-        @Override
-        public void addLocalColorsAreas(@NonNull List<RectF> regions) {
-            mWorker.getThreadHandler().post(() -> {
-                if (mColorAreas.size() + mLocalColorsToAdd.size() == 0) {
-                    setOffsetNotificationsEnabled(true);
-                }
-                Bitmap bitmap = mMiniBitmap;
-                if (bitmap == null) {
-                    mLocalColorsToAdd.addAll(regions);
-                    if (mRenderer != null) mRenderer.use(this::updateMiniBitmapAndNotify);
-                } else {
-                    computeAndNotifyLocalColors(regions, bitmap);
-                }
-            });
-        }
-
-        private void computeAndNotifyLocalColors(@NonNull List<RectF> regions, Bitmap b) {
-            List<WallpaperColors> colors = getLocalWallpaperColors(regions, b);
-            mColorAreas.addAll(regions);
-            try {
-                notifyLocalColorsChanged(regions, colors);
-            } catch (RuntimeException e) {
-                Log.e(TAG, e.getMessage(), e);
-            }
-        }
-
-        @Override
-        public void removeLocalColorsAreas(@NonNull List<RectF> regions) {
-            mWorker.getThreadHandler().post(() -> {
-                mColorAreas.removeAll(regions);
-                mLocalColorsToAdd.removeAll(regions);
-                if (mColorAreas.size() + mLocalColorsToAdd.size() == 0) {
-                    setOffsetNotificationsEnabled(false);
-                }
-            });
-        }
-
-        /**
-         * Transform the logical coordinates into wallpaper coordinates.
-         *
-         * Logical coordinates are organised such that the various pages are non-overlapping. So,
-         * if there are n pages, the first page will have its X coordinate on the range [0-1/n].
-         *
-         * The real pages are overlapping. If the Wallpaper are a width Ww and the screen a width
-         * Ws, the relative width of a page Wr is Ws/Ww. This does not change if the number of
-         * pages increase.
-         * If there are n pages, the page k starts at the offset k * (1 - Wr) / (n - 1), as the
-         * last page is at position (1-Wr) and the others are regularly spread on the range [0-
-         * (1-Wr)].
-         */
-        private RectF pageToImgRect(RectF area) {
-            if (!mDisplaySizeValid) {
-                Rect window = getDisplayContext()
-                        .getSystemService(WindowManager.class)
-                        .getCurrentWindowMetrics()
-                        .getBounds();
-                mDisplayWidth = window.width();
-                mDisplayHeight = window.height();
-                mDisplaySizeValid = true;
-            }
-
-            // Width of a page for the caller of this API.
-            float virtualPageWidth = 1f / (float) mPages;
-            float leftPosOnPage = (area.left % virtualPageWidth) / virtualPageWidth;
-            float rightPosOnPage = (area.right % virtualPageWidth) / virtualPageWidth;
-            int currentPage = (int) Math.floor(area.centerX() / virtualPageWidth);
-
-            RectF imgArea = new RectF();
-
-            if (mImgWidth == 0 || mImgHeight == 0 || mDisplayWidth <= 0 || mDisplayHeight <= 0) {
-                return imgArea;
-            }
-
-            imgArea.bottom = area.bottom;
-            imgArea.top = area.top;
-
-            float imageScale = Math.min(((float) mImgHeight) / mDisplayHeight, 1);
-            float mappedScreenWidth = mDisplayWidth * imageScale;
-            float pageWidth = Math.min(1.0f,
-                    mImgWidth > 0 ? mappedScreenWidth / (float) mImgWidth : 1.f);
-            float pageOffset = (1 - pageWidth) / (float) (mPages - 1);
-
-            imgArea.left = MathUtils.constrain(
-                    leftPosOnPage * pageWidth + currentPage * pageOffset, 0, 1);
-            imgArea.right = MathUtils.constrain(
-                    rightPosOnPage * pageWidth + currentPage * pageOffset, 0, 1);
-            if (imgArea.left > imgArea.right) {
-                // take full page
-                imgArea.left = 0;
-                imgArea.right = 1;
-            }
-            return imgArea;
-        }
-
-        private List<WallpaperColors> getLocalWallpaperColors(@NonNull List<RectF> areas,
-                Bitmap b) {
-            List<WallpaperColors> colors = new ArrayList<>(areas.size());
-            for (int i = 0; i < areas.size(); i++) {
-                RectF area = pageToImgRect(areas.get(i));
-                if (area == null || !LOCAL_COLOR_BOUNDS.contains(area)) {
-                    colors.add(null);
-                    continue;
-                }
-                Rect subImage = new Rect(
-                        (int) Math.floor(area.left * b.getWidth()),
-                        (int) Math.floor(area.top * b.getHeight()),
-                        (int) Math.ceil(area.right * b.getWidth()),
-                        (int) Math.ceil(area.bottom * b.getHeight()));
-                if (subImage.isEmpty()) {
-                    // Do not notify client. treat it as too small to sample
-                    colors.add(null);
-                    continue;
-                }
-                Bitmap colorImg = Bitmap.createBitmap(b,
-                        subImage.left, subImage.top, subImage.width(), subImage.height());
-                WallpaperColors color = WallpaperColors.fromBitmap(colorImg);
-                colors.add(color);
-            }
-            return colors;
-        }
-
-        @Override
-        public void onSurfaceCreated(SurfaceHolder holder) {
-            if (mWorker == null) return;
-            mWorker.getThreadHandler().post(() -> {
-                Trace.beginSection("ImageWallpaper#onSurfaceCreated");
-                mEglHelper.init(holder, needSupportWideColorGamut());
-                mRenderer.onSurfaceCreated();
-                Trace.endSection();
-            });
-        }
-
-        @Override
-        public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
-            if (mWorker == null) return;
-            mWorker.getThreadHandler().post(() -> mRenderer.onSurfaceChanged(width, height));
-        }
-
-        @Override
-        public void onSurfaceRedrawNeeded(SurfaceHolder holder) {
-            if (mWorker == null) return;
-            mWorker.getThreadHandler().post(this::drawFrame);
-        }
-
-        private void drawFrame() {
-            Trace.beginSection("ImageWallpaper#drawFrame");
-            preRender();
-            requestRender();
-            postRender();
-            Trace.endSection();
-        }
-
-        public void preRender() {
-            // This method should only be invoked from worker thread.
-            Trace.beginSection("ImageWallpaper#preRender");
-            preRenderInternal();
-            Trace.endSection();
-        }
-
-        private void preRenderInternal() {
-            boolean contextRecreated = false;
-            Rect frame = getSurfaceHolder().getSurfaceFrame();
-            cancelFinishRenderingTask();
-
-            // Check if we need to recreate egl context.
-            if (!mEglHelper.hasEglContext()) {
-                mEglHelper.destroyEglSurface();
-                if (!mEglHelper.createEglContext()) {
-                    Log.w(TAG, "recreate egl context failed!");
-                } else {
-                    contextRecreated = true;
-                }
-            }
-
-            // Check if we need to recreate egl surface.
-            if (mEglHelper.hasEglContext() && !mEglHelper.hasEglSurface()) {
-                if (!mEglHelper.createEglSurface(getSurfaceHolder(), needSupportWideColorGamut())) {
-                    Log.w(TAG, "recreate egl surface failed!");
-                }
-            }
-
-            // If we recreate egl context, notify renderer to setup again.
-            if (mEglHelper.hasEglContext() && mEglHelper.hasEglSurface() && contextRecreated) {
-                mRenderer.onSurfaceCreated();
-                mRenderer.onSurfaceChanged(frame.width(), frame.height());
-            }
-        }
-
-        public void requestRender() {
-            // This method should only be invoked from worker thread.
-            Trace.beginSection("ImageWallpaper#requestRender");
-            requestRenderInternal();
-            Trace.endSection();
-        }
-
-        private void requestRenderInternal() {
-            Rect frame = getSurfaceHolder().getSurfaceFrame();
-            boolean readyToRender = mEglHelper.hasEglContext() && mEglHelper.hasEglSurface()
-                    && frame.width() > 0 && frame.height() > 0;
-
-            if (readyToRender) {
-                mRenderer.onDrawFrame();
-                if (!mEglHelper.swapBuffer()) {
-                    Log.e(TAG, "drawFrame failed!");
-                }
-            } else {
-                Log.e(TAG, "requestRender: not ready, has context=" + mEglHelper.hasEglContext()
-                        + ", has surface=" + mEglHelper.hasEglSurface()
-                        + ", frame=" + frame);
-            }
-        }
-
-        public void postRender() {
-            // This method should only be invoked from worker thread.
-            scheduleFinishRendering();
-            reportEngineShown(false /* waitForEngineShown */);
-        }
-
-        private void cancelFinishRenderingTask() {
-            if (mWorker == null) return;
-            mWorker.getThreadHandler().removeCallbacks(mFinishRenderingTask);
-        }
-
-        private void scheduleFinishRendering() {
-            if (mWorker == null) return;
-            cancelFinishRenderingTask();
-            mWorker.getThreadHandler().postDelayed(mFinishRenderingTask, DELAY_FINISH_RENDERING);
-        }
-
-        private void finishRendering() {
-            Trace.beginSection("ImageWallpaper#finishRendering");
-            if (mEglHelper != null) {
-                mEglHelper.destroyEglSurface();
-                mEglHelper.destroyEglContext();
-            }
-            Trace.endSection();
-        }
-
-        private boolean needSupportWideColorGamut() {
-            return mRenderer.isWcgContent();
-        }
-
-        @Override
-        protected void dump(String prefix, FileDescriptor fd, PrintWriter out, String[] args) {
-            super.dump(prefix, fd, out, args);
-            out.print(prefix); out.print("Engine="); out.println(this);
-            out.print(prefix); out.print("valid surface=");
-            out.println(getSurfaceHolder() != null && getSurfaceHolder().getSurface() != null
-                    ? getSurfaceHolder().getSurface().isValid()
-                    : "null");
-
-            out.print(prefix); out.print("surface frame=");
-            out.println(getSurfaceHolder() != null ? getSurfaceHolder().getSurfaceFrame() : "null");
-
-            mEglHelper.dump(prefix, fd, out, args);
-            mRenderer.dump(prefix, fd, out, args);
-        }
-    }
-
-
     class CanvasEngine extends WallpaperService.Engine implements DisplayListener {
         private WallpaperManager mWallpaperManager;
         private final WallpaperLocalColorExtractor mWallpaperLocalColorExtractor;
@@ -672,13 +240,9 @@
                 loadWallpaperAndDrawFrameInternal();
             } else {
                 mBitmapUsages++;
-
-                // drawing is done on the main thread
-                mMainExecutor.execute(() -> {
-                    drawFrameOnCanvas(mBitmap);
-                    reportEngineShown(false);
-                    unloadBitmapIfNotUsed();
-                });
+                drawFrameOnCanvas(mBitmap);
+                reportEngineShown(false);
+                unloadBitmapIfNotUsedInternal();
             }
         }
 
@@ -716,11 +280,15 @@
 
         private void unloadBitmapIfNotUsedSynchronized() {
             synchronized (mLock) {
-                mBitmapUsages -= 1;
-                if (mBitmapUsages <= 0) {
-                    mBitmapUsages = 0;
-                    unloadBitmapInternal();
-                }
+                unloadBitmapIfNotUsedInternal();
+            }
+        }
+
+        private void unloadBitmapIfNotUsedInternal() {
+            mBitmapUsages -= 1;
+            if (mBitmapUsages <= 0) {
+                mBitmapUsages = 0;
+                unloadBitmapInternal();
             }
         }
 
@@ -753,13 +321,8 @@
                 // be loaded, we will go into a cycle. Don't do a build where the
                 // default wallpaper can't be loaded.
                 Log.w(TAG, "Unable to load wallpaper!", exception);
-                try {
-                    mWallpaperManager.clear(WallpaperManager.FLAG_SYSTEM);
-                } catch (IOException ex) {
-                    // now we're really screwed.
-                    Log.w(TAG, "Unable reset to default wallpaper!", ex);
-                }
-
+                mWallpaperManager.clearWallpaper(
+                        WallpaperManager.FLAG_SYSTEM, UserHandle.USER_CURRENT);
                 try {
                     bitmap = mWallpaperManager.getBitmapAsUser(UserHandle.USER_CURRENT, false);
                 } catch (RuntimeException | OutOfMemoryError e) {
@@ -885,7 +448,6 @@
             mWallpaperLocalColorExtractor.setDisplayDimensions(window.width(), window.height());
         }
 
-
         @Override
         protected void dump(String prefix, FileDescriptor fd, PrintWriter out, String[] args) {
             super.dump(prefix, fd, out, args);
diff --git a/packages/SystemUI/src/com/android/systemui/wallpapers/canvas/WallpaperLocalColorExtractor.java b/packages/SystemUI/src/com/android/systemui/wallpapers/WallpaperLocalColorExtractor.java
similarity index 99%
rename from packages/SystemUI/src/com/android/systemui/wallpapers/canvas/WallpaperLocalColorExtractor.java
rename to packages/SystemUI/src/com/android/systemui/wallpapers/WallpaperLocalColorExtractor.java
index 6cac5c9..988fd71 100644
--- a/packages/SystemUI/src/com/android/systemui/wallpapers/canvas/WallpaperLocalColorExtractor.java
+++ b/packages/SystemUI/src/com/android/systemui/wallpapers/WallpaperLocalColorExtractor.java
@@ -15,7 +15,7 @@
  */
 
 
-package com.android.systemui.wallpapers.canvas;
+package com.android.systemui.wallpapers;
 
 import android.app.WallpaperColors;
 import android.graphics.Bitmap;
@@ -31,7 +31,6 @@
 
 import com.android.systemui.dagger.qualifiers.Background;
 import com.android.systemui.util.Assert;
-import com.android.systemui.wallpapers.ImageWallpaper;
 
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
diff --git a/packages/SystemUI/src/com/android/systemui/wallpapers/gl/EglHelper.java b/packages/SystemUI/src/com/android/systemui/wallpapers/gl/EglHelper.java
deleted file mode 100644
index f9ddce8..0000000
--- a/packages/SystemUI/src/com/android/systemui/wallpapers/gl/EglHelper.java
+++ /dev/null
@@ -1,380 +0,0 @@
-/*
- * Copyright (C) 2019 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.systemui.wallpapers.gl;
-
-import static android.opengl.EGL14.EGL_ALPHA_SIZE;
-import static android.opengl.EGL14.EGL_BLUE_SIZE;
-import static android.opengl.EGL14.EGL_CONFIG_CAVEAT;
-import static android.opengl.EGL14.EGL_CONTEXT_CLIENT_VERSION;
-import static android.opengl.EGL14.EGL_DEFAULT_DISPLAY;
-import static android.opengl.EGL14.EGL_DEPTH_SIZE;
-import static android.opengl.EGL14.EGL_EXTENSIONS;
-import static android.opengl.EGL14.EGL_GREEN_SIZE;
-import static android.opengl.EGL14.EGL_NONE;
-import static android.opengl.EGL14.EGL_NO_CONTEXT;
-import static android.opengl.EGL14.EGL_NO_DISPLAY;
-import static android.opengl.EGL14.EGL_NO_SURFACE;
-import static android.opengl.EGL14.EGL_OPENGL_ES2_BIT;
-import static android.opengl.EGL14.EGL_RED_SIZE;
-import static android.opengl.EGL14.EGL_RENDERABLE_TYPE;
-import static android.opengl.EGL14.EGL_STENCIL_SIZE;
-import static android.opengl.EGL14.EGL_SUCCESS;
-import static android.opengl.EGL14.eglChooseConfig;
-import static android.opengl.EGL14.eglCreateContext;
-import static android.opengl.EGL14.eglCreateWindowSurface;
-import static android.opengl.EGL14.eglDestroyContext;
-import static android.opengl.EGL14.eglDestroySurface;
-import static android.opengl.EGL14.eglGetDisplay;
-import static android.opengl.EGL14.eglGetError;
-import static android.opengl.EGL14.eglInitialize;
-import static android.opengl.EGL14.eglMakeCurrent;
-import static android.opengl.EGL14.eglQueryString;
-import static android.opengl.EGL14.eglSwapBuffers;
-import static android.opengl.EGL14.eglTerminate;
-
-import android.opengl.EGLConfig;
-import android.opengl.EGLContext;
-import android.opengl.EGLDisplay;
-import android.opengl.EGLSurface;
-import android.opengl.GLUtils;
-import android.text.TextUtils;
-import android.util.Log;
-import android.view.SurfaceHolder;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * A helper class to handle EGL management.
- */
-public class EglHelper {
-    private static final String TAG = EglHelper.class.getSimpleName();
-    private static final int OPENGLES_VERSION = 2;
-    // Below two constants make drawing at low priority, so other things can preempt our drawing.
-    private static final int EGL_CONTEXT_PRIORITY_LEVEL_IMG = 0x3100;
-    private static final int EGL_CONTEXT_PRIORITY_LOW_IMG = 0x3103;
-    private static final boolean DEBUG = true;
-
-    private static final int EGL_GL_COLORSPACE_KHR = 0x309D;
-    private static final int EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT = 0x3490;
-
-    private static final String EGL_IMG_CONTEXT_PRIORITY = "EGL_IMG_context_priority";
-
-    /**
-     * https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_gl_colorspace.txt
-     */
-    private static final String KHR_GL_COLOR_SPACE = "EGL_KHR_gl_colorspace";
-
-    /**
-     * https://www.khronos.org/registry/EGL/extensions/EXT/EGL_EXT_gl_colorspace_display_p3_passthrough.txt
-     */
-    private static final String EXT_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH =
-            "EGL_EXT_gl_colorspace_display_p3_passthrough";
-
-    private EGLDisplay mEglDisplay;
-    private EGLConfig mEglConfig;
-    private EGLContext mEglContext;
-    private EGLSurface mEglSurface;
-    private final int[] mEglVersion = new int[2];
-    private boolean mEglReady;
-    private final Set<String> mExts;
-
-    public EglHelper() {
-        mExts = new HashSet<>();
-        connectDisplay();
-    }
-
-    /**
-     * Initialize render context.
-     * @param surfaceHolder surface holder.
-     * @param wideColorGamut claim if a wcg surface is necessary.
-     * @return true if the render context is ready.
-     */
-    public boolean init(SurfaceHolder surfaceHolder, boolean wideColorGamut) {
-        if (!hasEglDisplay() && !connectDisplay()) {
-            Log.w(TAG, "Can not connect display, abort!");
-            return false;
-        }
-
-        if (!eglInitialize(mEglDisplay, mEglVersion, 0 /* majorOffset */,
-                    mEglVersion, 1 /* minorOffset */)) {
-            Log.w(TAG, "eglInitialize failed: " + GLUtils.getEGLErrorString(eglGetError()));
-            return false;
-        }
-
-        mEglConfig = chooseEglConfig();
-        if (mEglConfig == null) {
-            Log.w(TAG, "eglConfig not initialized!");
-            return false;
-        }
-
-        if (!createEglContext()) {
-            Log.w(TAG, "Can't create EGLContext!");
-            return false;
-        }
-
-        if (!createEglSurface(surfaceHolder, wideColorGamut)) {
-            Log.w(TAG, "Can't create EGLSurface!");
-            return false;
-        }
-
-        mEglReady = true;
-        return true;
-    }
-
-    private boolean connectDisplay() {
-        mExts.clear();
-        mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
-        if (!hasEglDisplay()) {
-            Log.w(TAG, "eglGetDisplay failed: " + GLUtils.getEGLErrorString(eglGetError()));
-            return false;
-        }
-        String queryString = eglQueryString(mEglDisplay, EGL_EXTENSIONS);
-        if (!TextUtils.isEmpty(queryString)) {
-            Collections.addAll(mExts, queryString.split(" "));
-        }
-        return true;
-    }
-
-    boolean checkExtensionCapability(String extName) {
-        return mExts.contains(extName);
-    }
-
-    int getWcgCapability() {
-        if (checkExtensionCapability(EXT_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH)) {
-            return EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT;
-        }
-        return 0;
-    }
-
-    private EGLConfig chooseEglConfig() {
-        int[] configsCount = new int[1];
-        EGLConfig[] configs = new EGLConfig[1];
-        int[] configSpec = getConfig();
-        if (!eglChooseConfig(mEglDisplay, configSpec, 0, configs, 0, 1, configsCount, 0)) {
-            Log.w(TAG, "eglChooseConfig failed: " + GLUtils.getEGLErrorString(eglGetError()));
-            return null;
-        } else {
-            if (configsCount[0] <= 0) {
-                Log.w(TAG, "eglChooseConfig failed, invalid configs count: " + configsCount[0]);
-                return null;
-            } else {
-                return configs[0];
-            }
-        }
-    }
-
-    private int[] getConfig() {
-        return new int[] {
-            EGL_RED_SIZE, 8,
-            EGL_GREEN_SIZE, 8,
-            EGL_BLUE_SIZE, 8,
-            EGL_ALPHA_SIZE, 0,
-            EGL_DEPTH_SIZE, 0,
-            EGL_STENCIL_SIZE, 0,
-            EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
-            EGL_CONFIG_CAVEAT, EGL_NONE,
-            EGL_NONE
-        };
-    }
-
-    /**
-     * Prepare an EglSurface.
-     * @param surfaceHolder surface holder.
-     * @param wcg if need to support wcg.
-     * @return true if EglSurface is ready.
-     */
-    public boolean createEglSurface(SurfaceHolder surfaceHolder, boolean wcg) {
-        if (DEBUG) {
-            Log.d(TAG, "createEglSurface start");
-        }
-
-        if (hasEglDisplay() && surfaceHolder.getSurface().isValid()) {
-            int[] attrs = null;
-            int wcgCapability = getWcgCapability();
-            if (wcg && checkExtensionCapability(KHR_GL_COLOR_SPACE) && wcgCapability > 0) {
-                attrs = new int[] {EGL_GL_COLORSPACE_KHR, wcgCapability, EGL_NONE};
-            }
-            mEglSurface = askCreatingEglWindowSurface(surfaceHolder, attrs, 0 /* offset */);
-        } else {
-            Log.w(TAG, "Create EglSurface failed: hasEglDisplay=" + hasEglDisplay()
-                    + ", has valid surface=" + surfaceHolder.getSurface().isValid());
-            return false;
-        }
-
-        if (!hasEglSurface()) {
-            Log.w(TAG, "createWindowSurface failed: " + GLUtils.getEGLErrorString(eglGetError()));
-            return false;
-        }
-
-        if (!eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
-            Log.w(TAG, "eglMakeCurrent failed: " + GLUtils.getEGLErrorString(eglGetError()));
-            return false;
-        }
-
-        if (DEBUG) {
-            Log.d(TAG, "createEglSurface done");
-        }
-        return true;
-    }
-
-    EGLSurface askCreatingEglWindowSurface(SurfaceHolder holder, int[] attrs, int offset) {
-        return eglCreateWindowSurface(mEglDisplay, mEglConfig, holder, attrs, offset);
-    }
-
-    /**
-     * Destroy EglSurface.
-     */
-    public void destroyEglSurface() {
-        if (hasEglSurface()) {
-            eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
-            eglDestroySurface(mEglDisplay, mEglSurface);
-            mEglSurface = EGL_NO_SURFACE;
-        }
-    }
-
-    /**
-     * Check if we have a valid EglSurface.
-     * @return true if EglSurface is ready.
-     */
-    public boolean hasEglSurface() {
-        return mEglSurface != null && mEglSurface != EGL_NO_SURFACE;
-    }
-
-    /**
-     * Prepare EglContext.
-     * @return true if EglContext is ready.
-     */
-    public boolean createEglContext() {
-        if (DEBUG) {
-            Log.d(TAG, "createEglContext start");
-        }
-
-        int[] attrib_list = new int[5];
-        int idx = 0;
-        attrib_list[idx++] = EGL_CONTEXT_CLIENT_VERSION;
-        attrib_list[idx++] = OPENGLES_VERSION;
-        if (checkExtensionCapability(EGL_IMG_CONTEXT_PRIORITY)) {
-            attrib_list[idx++] = EGL_CONTEXT_PRIORITY_LEVEL_IMG;
-            attrib_list[idx++] = EGL_CONTEXT_PRIORITY_LOW_IMG;
-        }
-        attrib_list[idx] = EGL_NONE;
-        if (hasEglDisplay()) {
-            mEglContext = eglCreateContext(mEglDisplay, mEglConfig, EGL_NO_CONTEXT, attrib_list, 0);
-        } else {
-            Log.w(TAG, "mEglDisplay is null");
-            return false;
-        }
-
-        if (!hasEglContext()) {
-            Log.w(TAG, "eglCreateContext failed: " + GLUtils.getEGLErrorString(eglGetError()));
-            return false;
-        }
-
-        if (DEBUG) {
-            Log.d(TAG, "createEglContext done");
-        }
-        return true;
-    }
-
-    /**
-     * Destroy EglContext.
-     */
-    public void destroyEglContext() {
-        if (hasEglContext()) {
-            eglDestroyContext(mEglDisplay, mEglContext);
-            mEglContext = EGL_NO_CONTEXT;
-        }
-    }
-
-    /**
-     * Check if we have EglContext.
-     * @return true if EglContext is ready.
-     */
-    public boolean hasEglContext() {
-        return mEglContext != null && mEglContext != EGL_NO_CONTEXT;
-    }
-
-    /**
-     * Check if we have EglDisplay.
-     * @return true if EglDisplay is ready.
-     */
-    public boolean hasEglDisplay() {
-        return mEglDisplay != null && mEglDisplay != EGL_NO_DISPLAY;
-    }
-
-    /**
-     * Swap buffer to display.
-     * @return true if swap successfully.
-     */
-    public boolean swapBuffer() {
-        boolean status = eglSwapBuffers(mEglDisplay, mEglSurface);
-        int error = eglGetError();
-        if (error != EGL_SUCCESS) {
-            Log.w(TAG, "eglSwapBuffers failed: " + GLUtils.getEGLErrorString(error));
-        }
-        return status;
-    }
-
-    /**
-     * Destroy EglSurface and EglContext, then terminate EGL.
-     */
-    public void finish() {
-        if (hasEglSurface()) {
-            destroyEglSurface();
-        }
-        if (hasEglContext()) {
-            destroyEglContext();
-        }
-        if (hasEglDisplay()) {
-            terminateEglDisplay();
-        }
-        mEglReady = false;
-    }
-
-    void terminateEglDisplay() {
-        eglTerminate(mEglDisplay);
-        mEglDisplay = EGL_NO_DISPLAY;
-    }
-
-    /**
-     * Called to dump current state.
-     * @param prefix prefix.
-     * @param fd fd.
-     * @param out out.
-     * @param args args.
-     */
-    public void dump(String prefix, FileDescriptor fd, PrintWriter out, String[] args) {
-        String eglVersion = mEglVersion[0] + "." + mEglVersion[1];
-        out.print(prefix); out.print("EGL version="); out.print(eglVersion);
-        out.print(", "); out.print("EGL ready="); out.print(mEglReady);
-        out.print(", "); out.print("has EglContext="); out.print(hasEglContext());
-        out.print(", "); out.print("has EglSurface="); out.println(hasEglSurface());
-
-        int[] configs = getConfig();
-        StringBuilder sb = new StringBuilder();
-        sb.append('{');
-        for (int egl : configs) {
-            sb.append("0x").append(Integer.toHexString(egl)).append(",");
-        }
-        sb.setCharAt(sb.length() - 1, '}');
-        out.print(prefix); out.print("EglConfig="); out.println(sb.toString());
-    }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/wallpapers/gl/GLWallpaperRenderer.java b/packages/SystemUI/src/com/android/systemui/wallpapers/gl/GLWallpaperRenderer.java
deleted file mode 100644
index 692ced0..0000000
--- a/packages/SystemUI/src/com/android/systemui/wallpapers/gl/GLWallpaperRenderer.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2019 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.systemui.wallpapers.gl;
-
-import android.util.Size;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-
-/**
- * A renderer which is responsible for making OpenGL calls to render a frame.
- */
-public interface GLWallpaperRenderer {
-
-    /**
-     * Check if the content to render is a WCG content.
-     */
-    boolean isWcgContent();
-
-    /**
-     * Called when the surface is created or recreated.
-     */
-    void onSurfaceCreated();
-
-    /**
-     * Called when the surface changed size.
-     * @param width surface width.
-     * @param height surface height.
-     */
-    void onSurfaceChanged(int width, int height);
-
-    /**
-     * Called to draw the current frame.
-     */
-    void onDrawFrame();
-
-    /**
-     * Ask renderer to report the surface size it needs.
-     */
-    Size reportSurfaceSize();
-
-    /**
-     * Called when no need to render any more.
-     */
-    void finish();
-
-    /**
-     * Called to dump current state.
-     * @param prefix prefix.
-     * @param fd fd.
-     * @param out out.
-     * @param args args.
-     */
-    void dump(String prefix, FileDescriptor fd, PrintWriter out, String[] args);
-
-}
diff --git a/packages/SystemUI/src/com/android/systemui/wallpapers/gl/ImageGLProgram.java b/packages/SystemUI/src/com/android/systemui/wallpapers/gl/ImageGLProgram.java
deleted file mode 100644
index d34eca4..0000000
--- a/packages/SystemUI/src/com/android/systemui/wallpapers/gl/ImageGLProgram.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (C) 2019 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.systemui.wallpapers.gl;
-
-import static android.opengl.GLES20.GL_FRAGMENT_SHADER;
-import static android.opengl.GLES20.GL_VERTEX_SHADER;
-import static android.opengl.GLES20.glAttachShader;
-import static android.opengl.GLES20.glCompileShader;
-import static android.opengl.GLES20.glCreateProgram;
-import static android.opengl.GLES20.glCreateShader;
-import static android.opengl.GLES20.glGetAttribLocation;
-import static android.opengl.GLES20.glGetUniformLocation;
-import static android.opengl.GLES20.glLinkProgram;
-import static android.opengl.GLES20.glShaderSource;
-import static android.opengl.GLES20.glUseProgram;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.util.Log;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-
-/**
- * This class takes charge of linking shader codes and then return a handle for OpenGL ES program.
- */
-class ImageGLProgram {
-    private static final String TAG = ImageGLProgram.class.getSimpleName();
-
-    private Context mContext;
-    private int mProgramHandle;
-
-    ImageGLProgram(Context context) {
-        mContext = context.getApplicationContext();
-    }
-
-    private int loadShaderProgram(int vertexId, int fragmentId) {
-        final String vertexSrc = getShaderResource(vertexId);
-        final String fragmentSrc = getShaderResource(fragmentId);
-        final int vertexHandle = getShaderHandle(GL_VERTEX_SHADER, vertexSrc);
-        final int fragmentHandle = getShaderHandle(GL_FRAGMENT_SHADER, fragmentSrc);
-        return getProgramHandle(vertexHandle, fragmentHandle);
-    }
-
-    private String getShaderResource(int shaderId) {
-        Resources res = mContext.getResources();
-        StringBuilder code = new StringBuilder();
-
-        try (BufferedReader reader = new BufferedReader(
-                new InputStreamReader(res.openRawResource(shaderId)))) {
-            String nextLine;
-            while ((nextLine = reader.readLine()) != null) {
-                code.append(nextLine).append("\n");
-            }
-        } catch (IOException | Resources.NotFoundException ex) {
-            Log.d(TAG, "Can not read the shader source", ex);
-            code = null;
-        }
-
-        return code == null ? "" : code.toString();
-    }
-
-    private int getShaderHandle(int type, String src) {
-        final int shader = glCreateShader(type);
-        if (shader == 0) {
-            Log.d(TAG, "Create shader failed, type=" + type);
-            return 0;
-        }
-        glShaderSource(shader, src);
-        glCompileShader(shader);
-        return shader;
-    }
-
-    private int getProgramHandle(int vertexHandle, int fragmentHandle) {
-        final int program = glCreateProgram();
-        if (program == 0) {
-            Log.d(TAG, "Can not create OpenGL ES program");
-            return 0;
-        }
-
-        glAttachShader(program, vertexHandle);
-        glAttachShader(program, fragmentHandle);
-        glLinkProgram(program);
-        return program;
-    }
-
-    boolean useGLProgram(int vertexResId, int fragmentResId) {
-        mProgramHandle = loadShaderProgram(vertexResId, fragmentResId);
-        glUseProgram(mProgramHandle);
-        return true;
-    }
-
-    int getAttributeHandle(String name) {
-        return glGetAttribLocation(mProgramHandle, name);
-    }
-
-    int getUniformHandle(String name) {
-        return glGetUniformLocation(mProgramHandle, name);
-    }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/wallpapers/gl/ImageGLWallpaper.java b/packages/SystemUI/src/com/android/systemui/wallpapers/gl/ImageGLWallpaper.java
deleted file mode 100644
index f1659b9..0000000
--- a/packages/SystemUI/src/com/android/systemui/wallpapers/gl/ImageGLWallpaper.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Copyright (C) 2019 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.systemui.wallpapers.gl;
-
-import static android.opengl.GLES20.GL_FLOAT;
-import static android.opengl.GLES20.GL_LINEAR;
-import static android.opengl.GLES20.GL_TEXTURE0;
-import static android.opengl.GLES20.GL_TEXTURE_2D;
-import static android.opengl.GLES20.GL_TEXTURE_MAG_FILTER;
-import static android.opengl.GLES20.GL_TEXTURE_MIN_FILTER;
-import static android.opengl.GLES20.GL_TRIANGLES;
-import static android.opengl.GLES20.glActiveTexture;
-import static android.opengl.GLES20.glBindTexture;
-import static android.opengl.GLES20.glDrawArrays;
-import static android.opengl.GLES20.glEnableVertexAttribArray;
-import static android.opengl.GLES20.glGenTextures;
-import static android.opengl.GLES20.glTexParameteri;
-import static android.opengl.GLES20.glUniform1i;
-import static android.opengl.GLES20.glVertexAttribPointer;
-
-import android.graphics.Bitmap;
-import android.opengl.GLUtils;
-import android.util.Log;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.FloatBuffer;
-
-/**
- * This class takes charge of the geometry data like vertices and texture coordinates.
- * It delivers these data to opengl runtime and triggers draw calls if necessary.
- */
-class ImageGLWallpaper {
-    private static final String TAG = ImageGLWallpaper.class.getSimpleName();
-
-    private static final String A_POSITION = "aPosition";
-    private static final String A_TEXTURE_COORDINATES = "aTextureCoordinates";
-    private static final String U_TEXTURE = "uTexture";
-    private static final int POSITION_COMPONENT_COUNT = 2;
-    private static final int TEXTURE_COMPONENT_COUNT = 2;
-    private static final int BYTES_PER_FLOAT = 4;
-
-    // Vertices to define the square with 2 triangles.
-    private static final float[] VERTICES = {
-            -1.0f,  -1.0f,
-            +1.0f,  -1.0f,
-            +1.0f,  +1.0f,
-            +1.0f,  +1.0f,
-            -1.0f,  +1.0f,
-            -1.0f,  -1.0f
-    };
-
-    // Texture coordinates that maps to vertices.
-    private static final float[] TEXTURES = {
-            0f, 1f,
-            1f, 1f,
-            1f, 0f,
-            1f, 0f,
-            0f, 0f,
-            0f, 1f
-    };
-
-    private final FloatBuffer mVertexBuffer;
-    private final FloatBuffer mTextureBuffer;
-    private final ImageGLProgram mProgram;
-
-    private int mAttrPosition;
-    private int mAttrTextureCoordinates;
-    private int mUniTexture;
-    private int mTextureId;
-
-    ImageGLWallpaper(ImageGLProgram program) {
-        mProgram = program;
-
-        // Create an float array in opengles runtime (native) and put vertex data.
-        mVertexBuffer = ByteBuffer.allocateDirect(VERTICES.length * BYTES_PER_FLOAT)
-            .order(ByteOrder.nativeOrder())
-            .asFloatBuffer();
-        mVertexBuffer.put(VERTICES);
-        mVertexBuffer.position(0);
-
-        // Create an float array in opengles runtime (native) and put texture data.
-        mTextureBuffer = ByteBuffer.allocateDirect(TEXTURES.length * BYTES_PER_FLOAT)
-            .order(ByteOrder.nativeOrder())
-            .asFloatBuffer();
-        mTextureBuffer.put(TEXTURES);
-        mTextureBuffer.position(0);
-    }
-
-    void setup(Bitmap bitmap) {
-        setupAttributes();
-        setupUniforms();
-        setupTexture(bitmap);
-    }
-
-    private void setupAttributes() {
-        mAttrPosition = mProgram.getAttributeHandle(A_POSITION);
-        mVertexBuffer.position(0);
-        glVertexAttribPointer(mAttrPosition, POSITION_COMPONENT_COUNT, GL_FLOAT,
-                false, 0, mVertexBuffer);
-        glEnableVertexAttribArray(mAttrPosition);
-
-        mAttrTextureCoordinates = mProgram.getAttributeHandle(A_TEXTURE_COORDINATES);
-        mTextureBuffer.position(0);
-        glVertexAttribPointer(mAttrTextureCoordinates, TEXTURE_COMPONENT_COUNT, GL_FLOAT,
-                false, 0, mTextureBuffer);
-        glEnableVertexAttribArray(mAttrTextureCoordinates);
-    }
-
-    private void setupUniforms() {
-        mUniTexture = mProgram.getUniformHandle(U_TEXTURE);
-    }
-
-    void draw() {
-        glDrawArrays(GL_TRIANGLES, 0, VERTICES.length / 2);
-    }
-
-    private void setupTexture(Bitmap bitmap) {
-        final int[] tids = new int[1];
-
-        if (bitmap == null || bitmap.isRecycled()) {
-            Log.w(TAG, "setupTexture: invalid bitmap");
-            return;
-        }
-
-        // Generate one texture object and store the id in tids[0].
-        glGenTextures(1, tids, 0);
-        if (tids[0] == 0) {
-            Log.w(TAG, "setupTexture: glGenTextures() failed");
-            return;
-        }
-
-        try {
-            // Bind a named texture to a target.
-            glBindTexture(GL_TEXTURE_2D, tids[0]);
-            // Load the bitmap data and copy it over into the texture object
-            // that is currently bound.
-            GLUtils.texImage2D(GL_TEXTURE_2D, 0, bitmap, 0);
-            // Use bilinear texture filtering when minification.
-            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-            // Use bilinear texture filtering when magnification.
-            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-            mTextureId = tids[0];
-        } catch (IllegalArgumentException e) {
-            Log.w(TAG, "Failed uploading texture: " + e.getLocalizedMessage());
-        }
-    }
-
-    void useTexture() {
-        // Set the active texture unit to texture unit 0.
-        glActiveTexture(GL_TEXTURE0);
-        // Bind the texture to this unit.
-        glBindTexture(GL_TEXTURE_2D, mTextureId);
-        // Let the texture sampler in fragment shader to read form this texture unit.
-        glUniform1i(mUniTexture, 0);
-    }
-
-    /**
-     * Called to dump current state.
-     * @param prefix prefix.
-     * @param fd fd.
-     * @param out out.
-     * @param args args.
-     */
-    public void dump(String prefix, FileDescriptor fd, PrintWriter out, String[] args) {
-    }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/wallpapers/gl/ImageWallpaperRenderer.java b/packages/SystemUI/src/com/android/systemui/wallpapers/gl/ImageWallpaperRenderer.java
deleted file mode 100644
index e393786..0000000
--- a/packages/SystemUI/src/com/android/systemui/wallpapers/gl/ImageWallpaperRenderer.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Copyright (C) 2019 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.systemui.wallpapers.gl;
-
-import static android.opengl.GLES20.GL_COLOR_BUFFER_BIT;
-import static android.opengl.GLES20.glClear;
-import static android.opengl.GLES20.glClearColor;
-import static android.opengl.GLES20.glViewport;
-
-import android.app.WallpaperManager;
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Rect;
-import android.os.UserHandle;
-import android.util.Log;
-import android.util.Size;
-
-import com.android.systemui.R;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.function.Consumer;
-
-/**
- * A GL renderer for image wallpaper.
- */
-public class ImageWallpaperRenderer implements GLWallpaperRenderer {
-    private static final String TAG = ImageWallpaperRenderer.class.getSimpleName();
-    private static final boolean DEBUG = false;
-
-    private final ImageGLProgram mProgram;
-    private final ImageGLWallpaper mWallpaper;
-    private final Rect mSurfaceSize = new Rect();
-    private final WallpaperTexture mTexture;
-    private Consumer<Bitmap> mOnBitmapUpdated;
-
-    public ImageWallpaperRenderer(Context context) {
-        final WallpaperManager wpm = context.getSystemService(WallpaperManager.class);
-        if (wpm == null) {
-            Log.w(TAG, "WallpaperManager not available");
-        }
-
-        mTexture = new WallpaperTexture(wpm);
-        mProgram = new ImageGLProgram(context);
-        mWallpaper = new ImageGLWallpaper(mProgram);
-    }
-
-    /**
-     * @hide
-     */
-    public void setOnBitmapChanged(Consumer<Bitmap> c) {
-        mOnBitmapUpdated = c;
-    }
-
-    /**
-     * @hide
-     */
-    public void use(Consumer<Bitmap> c) {
-        mTexture.use(c);
-    }
-
-    @Override
-    public boolean isWcgContent() {
-        return mTexture.isWcgContent();
-    }
-
-    @Override
-    public void onSurfaceCreated() {
-        glClearColor(0f, 0f, 0f, 1.0f);
-        mProgram.useGLProgram(
-                R.raw.image_wallpaper_vertex_shader, R.raw.image_wallpaper_fragment_shader);
-
-        mTexture.use(bitmap -> {
-            if (bitmap == null) {
-                Log.w(TAG, "reload texture failed!");
-            } else if (mOnBitmapUpdated != null) {
-                mOnBitmapUpdated.accept(bitmap);
-            }
-            mWallpaper.setup(bitmap);
-        });
-    }
-
-    @Override
-    public void onSurfaceChanged(int width, int height) {
-        glViewport(0, 0, width, height);
-    }
-
-    @Override
-    public void onDrawFrame() {
-        glClear(GL_COLOR_BUFFER_BIT);
-        glViewport(0, 0, mSurfaceSize.width(), mSurfaceSize.height());
-        mWallpaper.useTexture();
-        mWallpaper.draw();
-    }
-
-    @Override
-    public Size reportSurfaceSize() {
-        mSurfaceSize.set(mTexture.getTextureDimensions());
-        return new Size(mSurfaceSize.width(), mSurfaceSize.height());
-    }
-
-    @Override
-    public void finish() {
-    }
-
-    @Override
-    public void dump(String prefix, FileDescriptor fd, PrintWriter out, String[] args) {
-        out.print(prefix); out.print("mSurfaceSize="); out.print(mSurfaceSize);
-        out.print(prefix); out.print("mWcgContent="); out.print(isWcgContent());
-        mWallpaper.dump(prefix, fd, out, args);
-    }
-
-    static class WallpaperTexture {
-        private final AtomicInteger mRefCount;
-        private final Rect mDimensions;
-        private final WallpaperManager mWallpaperManager;
-        private Bitmap mBitmap;
-        private boolean mWcgContent;
-        private boolean mTextureUsed;
-
-        private WallpaperTexture(WallpaperManager wallpaperManager) {
-            mWallpaperManager = wallpaperManager;
-            mRefCount = new AtomicInteger();
-            mDimensions = new Rect();
-        }
-
-        public void use(Consumer<Bitmap> consumer) {
-            mRefCount.incrementAndGet();
-            synchronized (mRefCount) {
-                if (mBitmap == null) {
-                    mBitmap = mWallpaperManager.getBitmapAsUser(UserHandle.USER_CURRENT,
-                            false /* hardware */);
-                    mWcgContent = mWallpaperManager.wallpaperSupportsWcg(
-                            WallpaperManager.FLAG_SYSTEM);
-                    mWallpaperManager.forgetLoadedWallpaper();
-                    if (mBitmap != null) {
-                        mDimensions.set(0, 0, mBitmap.getWidth(), mBitmap.getHeight());
-                        mTextureUsed = true;
-                    } else {
-                        Log.w(TAG, "Can't get bitmap");
-                    }
-                }
-            }
-            if (consumer != null) {
-                consumer.accept(mBitmap);
-            }
-            synchronized (mRefCount) {
-                final int count = mRefCount.decrementAndGet();
-                if (count == 0 && mBitmap != null) {
-                    if (DEBUG) {
-                        Log.v(TAG, "WallpaperTexture: release 0x" + getHash()
-                                + ", refCount=" + count);
-                    }
-                    mBitmap.recycle();
-                    mBitmap = null;
-                }
-            }
-        }
-
-        private boolean isWcgContent() {
-            return mWcgContent;
-        }
-
-        private String getHash() {
-            return mBitmap != null ? Integer.toHexString(mBitmap.hashCode()) : "null";
-        }
-
-        private Rect getTextureDimensions() {
-            if (!mTextureUsed) {
-                mDimensions.set(mWallpaperManager.peekBitmapDimensions());
-            }
-            return mDimensions;
-        }
-
-        @Override
-        public String toString() {
-            return "{" + getHash() + ", " + mRefCount.get() + "}";
-        }
-    }
-}
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardAbsKeyInputViewControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardAbsKeyInputViewControllerTest.java
index 8bbaf3d..1059543 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardAbsKeyInputViewControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardAbsKeyInputViewControllerTest.java
@@ -19,6 +19,7 @@
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.reset;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyZeroInteractions;
@@ -87,6 +88,7 @@
         when(mAbsKeyInputView.isAttachedToWindow()).thenReturn(true);
         when(mAbsKeyInputView.requireViewById(R.id.bouncer_message_area))
                 .thenReturn(mKeyguardMessageArea);
+        when(mAbsKeyInputView.getResources()).thenReturn(getContext().getResources());
         mKeyguardAbsKeyInputViewController = new KeyguardAbsKeyInputViewController(mAbsKeyInputView,
                 mKeyguardUpdateMonitor, mSecurityMode, mLockPatternUtils, mKeyguardSecurityCallback,
                 mKeyguardMessageAreaControllerFactory, mLatencyTracker, mFalsingCollector,
@@ -99,6 +101,11 @@
             public void onResume(int reason) {
                 super.onResume(reason);
             }
+
+            @Override
+            protected int getInitialMessageResId() {
+                return 0;
+            }
         };
         mKeyguardAbsKeyInputViewController.init();
         reset(mKeyguardMessageAreaController);  // Clear out implicit call to init.
@@ -125,4 +132,22 @@
         verifyZeroInteractions(mKeyguardSecurityCallback);
         verifyZeroInteractions(mKeyguardMessageAreaController);
     }
+
+    @Test
+    public void onPromptReasonNone_doesNotSetMessage() {
+        mKeyguardAbsKeyInputViewController.showPromptReason(0);
+        verify(mKeyguardMessageAreaController, never()).setMessage(
+                getContext().getResources().getString(R.string.kg_prompt_reason_restart_password),
+                false);
+    }
+
+    @Test
+    public void onPromptReason_setsMessage() {
+        when(mAbsKeyInputView.getPromptReasonStringRes(1)).thenReturn(
+                R.string.kg_prompt_reason_restart_password);
+        mKeyguardAbsKeyInputViewController.showPromptReason(1);
+        verify(mKeyguardMessageAreaController).setMessage(
+                getContext().getResources().getString(R.string.kg_prompt_reason_restart_password),
+                false);
+    }
 }
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java
index 61c7bb5..c8e7538 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java
@@ -29,7 +29,6 @@
 
 import android.content.res.Resources;
 import android.database.ContentObserver;
-import android.graphics.Rect;
 import android.net.Uri;
 import android.os.UserHandle;
 import android.provider.Settings;
@@ -47,6 +46,8 @@
 import com.android.systemui.keyguard.KeyguardUnlockAnimationController;
 import com.android.systemui.plugins.ClockAnimations;
 import com.android.systemui.plugins.ClockController;
+import com.android.systemui.plugins.ClockEvents;
+import com.android.systemui.plugins.ClockFaceController;
 import com.android.systemui.plugins.statusbar.StatusBarStateController;
 import com.android.systemui.shared.clocks.AnimatableClockView;
 import com.android.systemui.shared.clocks.ClockRegistry;
@@ -88,7 +89,15 @@
     @Mock
     KeyguardUnlockAnimationController mKeyguardUnlockAnimationController;
     @Mock
-    private ClockController mClock;
+    private ClockController mClockController;
+    @Mock
+    private ClockFaceController mLargeClockController;
+    @Mock
+    private ClockFaceController mSmallClockController;
+    @Mock
+    private ClockAnimations mClockAnimations;
+    @Mock
+    private ClockEvents mClockEvents;
     @Mock
     DumpManager mDumpManager;
     @Mock
@@ -97,10 +106,12 @@
     @Mock
     private NotificationIconContainer mNotificationIcons;
     @Mock
-    private AnimatableClockView mClockView;
+    private AnimatableClockView mSmallClockView;
     @Mock
     private AnimatableClockView mLargeClockView;
     @Mock
+    private FrameLayout mSmallClockFrame;
+    @Mock
     private FrameLayout mLargeClockFrame;
     @Mock
     private SecureSettings mSecureSettings;
@@ -121,9 +132,14 @@
                 mock(RelativeLayout.LayoutParams.class));
         when(mView.getContext()).thenReturn(getContext());
         when(mView.getResources()).thenReturn(mResources);
+        when(mResources.getDimensionPixelSize(R.dimen.keyguard_clock_top_margin))
+                .thenReturn(100);
+        when(mResources.getDimensionPixelSize(R.dimen.keyguard_large_clock_top_margin))
+                .thenReturn(-200);
 
         when(mView.findViewById(R.id.lockscreen_clock_view_large)).thenReturn(mLargeClockFrame);
-        when(mClockView.getContext()).thenReturn(getContext());
+        when(mView.findViewById(R.id.lockscreen_clock_view)).thenReturn(mSmallClockFrame);
+        when(mSmallClockView.getContext()).thenReturn(getContext());
         when(mLargeClockView.getContext()).thenReturn(getContext());
 
         when(mView.isAttachedToWindow()).thenReturn(true);
@@ -144,7 +160,14 @@
         );
 
         when(mStatusBarStateController.getState()).thenReturn(StatusBarState.SHADE);
-        when(mClockRegistry.createCurrentClock()).thenReturn(mClock);
+        when(mLargeClockController.getView()).thenReturn(mLargeClockView);
+        when(mSmallClockController.getView()).thenReturn(mSmallClockView);
+        when(mClockController.getLargeClock()).thenReturn(mLargeClockController);
+        when(mClockController.getSmallClock()).thenReturn(mSmallClockController);
+        when(mClockController.getEvents()).thenReturn(mClockEvents);
+        when(mClockController.getAnimations()).thenReturn(mClockAnimations);
+        when(mClockRegistry.createCurrentClock()).thenReturn(mClockController);
+        when(mClockEventController.getClock()).thenReturn(mClockController);
 
         mSliceView = new View(getContext());
         when(mView.findViewById(R.id.keyguard_slice_view)).thenReturn(mSliceView);
@@ -203,8 +226,8 @@
         verify(mClockRegistry).registerClockChangeListener(listenerArgumentCaptor.capture());
 
         listenerArgumentCaptor.getValue().onClockChanged();
-        verify(mView, times(2)).setClock(mClock, StatusBarState.SHADE);
-        verify(mClockEventController, times(2)).setClock(mClock);
+        verify(mView, times(2)).setClock(mClockController, StatusBarState.SHADE);
+        verify(mClockEventController, times(2)).setClock(mClockController);
     }
 
     @Test
@@ -262,17 +285,40 @@
 
     @Test
     public void testGetClockAnimationsForwardsToClock() {
-        ClockController mockClockController = mock(ClockController.class);
-        ClockAnimations mockClockAnimations = mock(ClockAnimations.class);
-        when(mClockEventController.getClock()).thenReturn(mockClockController);
-        when(mockClockController.getAnimations()).thenReturn(mockClockAnimations);
-
-        Rect r1 = new Rect(1, 2, 3, 4);
-        Rect r2 = new Rect(5, 6, 7, 8);
-        mController.getClockAnimations().onPositionUpdated(r1, r2, 0.2f);
-        verify(mockClockAnimations).onPositionUpdated(r1, r2, 0.2f);
+        assertEquals(mClockAnimations, mController.getClockAnimations());
     }
 
+    @Test
+    public void testGetLargeClockBottom_returnsExpectedValue() {
+        when(mLargeClockFrame.getVisibility()).thenReturn(View.VISIBLE);
+        when(mLargeClockFrame.getHeight()).thenReturn(100);
+        when(mSmallClockFrame.getHeight()).thenReturn(50);
+        when(mLargeClockView.getHeight()).thenReturn(40);
+        when(mSmallClockView.getHeight()).thenReturn(20);
+        mController.init();
+
+        assertEquals(170, mController.getClockBottom(1000));
+    }
+
+    @Test
+    public void testGetSmallLargeClockBottom_returnsExpectedValue() {
+        when(mLargeClockFrame.getVisibility()).thenReturn(View.GONE);
+        when(mLargeClockFrame.getHeight()).thenReturn(100);
+        when(mSmallClockFrame.getHeight()).thenReturn(50);
+        when(mLargeClockView.getHeight()).thenReturn(40);
+        when(mSmallClockView.getHeight()).thenReturn(20);
+        mController.init();
+
+        assertEquals(1120, mController.getClockBottom(1000));
+    }
+
+    @Test
+    public void testGetClockBottom_nullClock_returnsZero() {
+        when(mClockEventController.getClock()).thenReturn(null);
+        assertEquals(0, mController.getClockBottom(10));
+    }
+
+
     private void verifyAttachment(VerificationMode times) {
         verify(mClockRegistry, times).registerClockChangeListener(
                 any(ClockRegistry.ClockChangeListener.class));
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPasswordViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPasswordViewControllerTest.kt
index d20be56..d912793 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPasswordViewControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPasswordViewControllerTest.kt
@@ -30,64 +30,54 @@
 import org.junit.Before
 import org.junit.Test
 import org.junit.runner.RunWith
+import org.mockito.ArgumentMatchers.anyBoolean
+import org.mockito.ArgumentMatchers.anyString
 import org.mockito.Mock
 import org.mockito.Mockito
-import org.mockito.Mockito.`when`
 import org.mockito.Mockito.never
 import org.mockito.Mockito.verify
+import org.mockito.Mockito.`when`
 import org.mockito.MockitoAnnotations
 
 @SmallTest
 @RunWith(AndroidTestingRunner::class)
 @TestableLooper.RunWithLooper
 class KeyguardPasswordViewControllerTest : SysuiTestCase() {
-    @Mock
-    private lateinit var keyguardPasswordView: KeyguardPasswordView
-    @Mock
-    private lateinit var passwordEntry: EditText
-    @Mock
-    lateinit var keyguardUpdateMonitor: KeyguardUpdateMonitor
-    @Mock
-    lateinit var securityMode: KeyguardSecurityModel.SecurityMode
-    @Mock
-    lateinit var lockPatternUtils: LockPatternUtils
-    @Mock
-    lateinit var keyguardSecurityCallback: KeyguardSecurityCallback
-    @Mock
-    lateinit var messageAreaControllerFactory: KeyguardMessageAreaController.Factory
-    @Mock
-    lateinit var latencyTracker: LatencyTracker
-    @Mock
-    lateinit var inputMethodManager: InputMethodManager
-    @Mock
-    lateinit var emergencyButtonController: EmergencyButtonController
-    @Mock
-    lateinit var mainExecutor: DelayableExecutor
-    @Mock
-    lateinit var falsingCollector: FalsingCollector
-    @Mock
-    lateinit var keyguardViewController: KeyguardViewController
-    @Mock
-    private lateinit var mKeyguardMessageArea: BouncerKeyguardMessageArea
-    @Mock
-    private lateinit var mKeyguardMessageAreaController:
-        KeyguardMessageAreaController<BouncerKeyguardMessageArea>
+  @Mock private lateinit var keyguardPasswordView: KeyguardPasswordView
+  @Mock private lateinit var passwordEntry: EditText
+  @Mock lateinit var keyguardUpdateMonitor: KeyguardUpdateMonitor
+  @Mock lateinit var securityMode: KeyguardSecurityModel.SecurityMode
+  @Mock lateinit var lockPatternUtils: LockPatternUtils
+  @Mock lateinit var keyguardSecurityCallback: KeyguardSecurityCallback
+  @Mock lateinit var messageAreaControllerFactory: KeyguardMessageAreaController.Factory
+  @Mock lateinit var latencyTracker: LatencyTracker
+  @Mock lateinit var inputMethodManager: InputMethodManager
+  @Mock lateinit var emergencyButtonController: EmergencyButtonController
+  @Mock lateinit var mainExecutor: DelayableExecutor
+  @Mock lateinit var falsingCollector: FalsingCollector
+  @Mock lateinit var keyguardViewController: KeyguardViewController
+  @Mock private lateinit var mKeyguardMessageArea: BouncerKeyguardMessageArea
+  @Mock
+  private lateinit var mKeyguardMessageAreaController:
+      KeyguardMessageAreaController<BouncerKeyguardMessageArea>
 
-    private lateinit var keyguardPasswordViewController: KeyguardPasswordViewController
+  private lateinit var keyguardPasswordViewController: KeyguardPasswordViewController
 
-    @Before
-    fun setup() {
-        MockitoAnnotations.initMocks(this)
-        Mockito.`when`(
-            keyguardPasswordView
-                .requireViewById<BouncerKeyguardMessageArea>(R.id.bouncer_message_area)
-        ).thenReturn(mKeyguardMessageArea)
-        Mockito.`when`(messageAreaControllerFactory.create(mKeyguardMessageArea))
-            .thenReturn(mKeyguardMessageAreaController)
-        Mockito.`when`(keyguardPasswordView.passwordTextViewId).thenReturn(R.id.passwordEntry)
-        Mockito.`when`(keyguardPasswordView.findViewById<EditText>(R.id.passwordEntry)
-        ).thenReturn(passwordEntry)
-        keyguardPasswordViewController = KeyguardPasswordViewController(
+  @Before
+  fun setup() {
+    MockitoAnnotations.initMocks(this)
+    Mockito.`when`(
+            keyguardPasswordView.requireViewById<BouncerKeyguardMessageArea>(
+                R.id.bouncer_message_area))
+        .thenReturn(mKeyguardMessageArea)
+    Mockito.`when`(messageAreaControllerFactory.create(mKeyguardMessageArea))
+        .thenReturn(mKeyguardMessageAreaController)
+    Mockito.`when`(keyguardPasswordView.passwordTextViewId).thenReturn(R.id.passwordEntry)
+    Mockito.`when`(keyguardPasswordView.findViewById<EditText>(R.id.passwordEntry))
+        .thenReturn(passwordEntry)
+    `when`(keyguardPasswordView.resources).thenReturn(context.resources)
+    keyguardPasswordViewController =
+        KeyguardPasswordViewController(
             keyguardPasswordView,
             keyguardUpdateMonitor,
             securityMode,
@@ -100,51 +90,48 @@
             mainExecutor,
             mContext.resources,
             falsingCollector,
-            keyguardViewController
-        )
-    }
+            keyguardViewController)
+  }
 
-    @Test
-    fun testFocusWhenBouncerIsShown() {
-        Mockito.`when`(keyguardViewController.isBouncerShowing).thenReturn(true)
-        Mockito.`when`(keyguardPasswordView.isShown).thenReturn(true)
-        keyguardPasswordViewController.onResume(KeyguardSecurityView.VIEW_REVEALED)
-        keyguardPasswordView.post {
-            verify(keyguardPasswordView).requestFocus()
-            verify(keyguardPasswordView).showKeyboard()
-        }
+  @Test
+  fun testFocusWhenBouncerIsShown() {
+    Mockito.`when`(keyguardViewController.isBouncerShowing).thenReturn(true)
+    Mockito.`when`(keyguardPasswordView.isShown).thenReturn(true)
+    keyguardPasswordViewController.onResume(KeyguardSecurityView.VIEW_REVEALED)
+    keyguardPasswordView.post {
+      verify(keyguardPasswordView).requestFocus()
+      verify(keyguardPasswordView).showKeyboard()
     }
+  }
 
-    @Test
-    fun testDoNotFocusWhenBouncerIsHidden() {
-        Mockito.`when`(keyguardViewController.isBouncerShowing).thenReturn(false)
-        Mockito.`when`(keyguardPasswordView.isShown).thenReturn(true)
-        keyguardPasswordViewController.onResume(KeyguardSecurityView.VIEW_REVEALED)
-        verify(keyguardPasswordView, never()).requestFocus()
-    }
+  @Test
+  fun testDoNotFocusWhenBouncerIsHidden() {
+    Mockito.`when`(keyguardViewController.isBouncerShowing).thenReturn(false)
+    Mockito.`when`(keyguardPasswordView.isShown).thenReturn(true)
+    keyguardPasswordViewController.onResume(KeyguardSecurityView.VIEW_REVEALED)
+    verify(keyguardPasswordView, never()).requestFocus()
+  }
 
-    @Test
-    fun testHideKeyboardWhenOnPause() {
-        keyguardPasswordViewController.onPause()
-        keyguardPasswordView.post {
-            verify(keyguardPasswordView).clearFocus()
-            verify(keyguardPasswordView).hideKeyboard()
-        }
+  @Test
+  fun testHideKeyboardWhenOnPause() {
+    keyguardPasswordViewController.onPause()
+    keyguardPasswordView.post {
+      verify(keyguardPasswordView).clearFocus()
+      verify(keyguardPasswordView).hideKeyboard()
     }
+  }
 
-    @Test
-    fun startAppearAnimation() {
-        keyguardPasswordViewController.startAppearAnimation()
-        verify(mKeyguardMessageAreaController).setMessage(R.string.keyguard_enter_your_password)
-    }
+  @Test
+  fun startAppearAnimation() {
+    keyguardPasswordViewController.startAppearAnimation()
+    verify(mKeyguardMessageAreaController)
+        .setMessage(context.resources.getString(R.string.keyguard_enter_your_password), false)
+  }
 
-    @Test
-    fun startAppearAnimation_withExistingMessage() {
-        `when`(mKeyguardMessageAreaController.message).thenReturn("Unlock to continue.")
-        keyguardPasswordViewController.startAppearAnimation()
-        verify(
-            mKeyguardMessageAreaController,
-            never()
-        ).setMessage(R.string.keyguard_enter_your_password)
-    }
+  @Test
+  fun startAppearAnimation_withExistingMessage() {
+    `when`(mKeyguardMessageAreaController.message).thenReturn("Unlock to continue.")
+    keyguardPasswordViewController.startAppearAnimation()
+    verify(mKeyguardMessageAreaController, never()).setMessage(anyString(), anyBoolean())
+  }
 }
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt
index b3d1c8f..85dbdb8 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt
@@ -30,97 +30,93 @@
 import org.junit.Before
 import org.junit.Test
 import org.junit.runner.RunWith
+import org.mockito.ArgumentMatchers.anyBoolean
+import org.mockito.ArgumentMatchers.anyString
 import org.mockito.Mock
+import org.mockito.Mockito.never
 import org.mockito.Mockito.verify
 import org.mockito.Mockito.`when`
-import org.mockito.Mockito.never
 import org.mockito.MockitoAnnotations
 
 @SmallTest
 @RunWith(AndroidTestingRunner::class)
 @TestableLooper.RunWithLooper
 class KeyguardPatternViewControllerTest : SysuiTestCase() {
-    @Mock
-    private lateinit var mKeyguardPatternView: KeyguardPatternView
+  @Mock private lateinit var mKeyguardPatternView: KeyguardPatternView
 
-    @Mock
-    private lateinit var mKeyguardUpdateMonitor: KeyguardUpdateMonitor
+  @Mock private lateinit var mKeyguardUpdateMonitor: KeyguardUpdateMonitor
 
-    @Mock
-    private lateinit var mSecurityMode: KeyguardSecurityModel.SecurityMode
+  @Mock private lateinit var mSecurityMode: KeyguardSecurityModel.SecurityMode
 
-    @Mock
-    private lateinit var mLockPatternUtils: LockPatternUtils
+  @Mock private lateinit var mLockPatternUtils: LockPatternUtils
 
-    @Mock
-    private lateinit var mKeyguardSecurityCallback: KeyguardSecurityCallback
+  @Mock private lateinit var mKeyguardSecurityCallback: KeyguardSecurityCallback
 
-    @Mock
-    private lateinit var mLatencyTracker: LatencyTracker
-    private var mFalsingCollector: FalsingCollector = FalsingCollectorFake()
+  @Mock private lateinit var mLatencyTracker: LatencyTracker
+  private var mFalsingCollector: FalsingCollector = FalsingCollectorFake()
 
-    @Mock
-    private lateinit var mEmergencyButtonController: EmergencyButtonController
+  @Mock private lateinit var mEmergencyButtonController: EmergencyButtonController
 
-    @Mock
-    private lateinit
-    var mKeyguardMessageAreaControllerFactory: KeyguardMessageAreaController.Factory
+  @Mock
+  private lateinit var mKeyguardMessageAreaControllerFactory: KeyguardMessageAreaController.Factory
 
-    @Mock
-    private lateinit var mKeyguardMessageArea: BouncerKeyguardMessageArea
+  @Mock private lateinit var mKeyguardMessageArea: BouncerKeyguardMessageArea
 
-    @Mock
-    private lateinit var mKeyguardMessageAreaController:
-        KeyguardMessageAreaController<BouncerKeyguardMessageArea>
+  @Mock
+  private lateinit var mKeyguardMessageAreaController:
+      KeyguardMessageAreaController<BouncerKeyguardMessageArea>
 
-    @Mock
-    private lateinit var mLockPatternView: LockPatternView
+  @Mock private lateinit var mLockPatternView: LockPatternView
 
-    @Mock
-    private lateinit var mPostureController: DevicePostureController
+  @Mock private lateinit var mPostureController: DevicePostureController
 
-    private lateinit var mKeyguardPatternViewController: KeyguardPatternViewController
+  private lateinit var mKeyguardPatternViewController: KeyguardPatternViewController
 
-    @Before
-    fun setup() {
-        MockitoAnnotations.initMocks(this)
-        `when`(mKeyguardPatternView.isAttachedToWindow).thenReturn(true)
-        `when`(mKeyguardPatternView
-            .requireViewById<BouncerKeyguardMessageArea>(R.id.bouncer_message_area))
-            .thenReturn(mKeyguardMessageArea)
-        `when`(mKeyguardPatternView.findViewById<LockPatternView>(R.id.lockPatternView))
-            .thenReturn(mLockPatternView)
-        `when`(mKeyguardMessageAreaControllerFactory.create(mKeyguardMessageArea))
-            .thenReturn(mKeyguardMessageAreaController)
-        mKeyguardPatternViewController = KeyguardPatternViewController(
+  @Before
+  fun setup() {
+    MockitoAnnotations.initMocks(this)
+    `when`(mKeyguardPatternView.isAttachedToWindow).thenReturn(true)
+    `when`(
+            mKeyguardPatternView.requireViewById<BouncerKeyguardMessageArea>(
+                R.id.bouncer_message_area))
+        .thenReturn(mKeyguardMessageArea)
+    `when`(mKeyguardPatternView.findViewById<LockPatternView>(R.id.lockPatternView))
+        .thenReturn(mLockPatternView)
+    `when`(mKeyguardMessageAreaControllerFactory.create(mKeyguardMessageArea))
+        .thenReturn(mKeyguardMessageAreaController)
+    `when`(mKeyguardPatternView.resources).thenReturn(context.resources)
+    mKeyguardPatternViewController =
+        KeyguardPatternViewController(
             mKeyguardPatternView,
-            mKeyguardUpdateMonitor, mSecurityMode, mLockPatternUtils, mKeyguardSecurityCallback,
-            mLatencyTracker, mFalsingCollector, mEmergencyButtonController,
-            mKeyguardMessageAreaControllerFactory, mPostureController
-        )
-    }
+            mKeyguardUpdateMonitor,
+            mSecurityMode,
+            mLockPatternUtils,
+            mKeyguardSecurityCallback,
+            mLatencyTracker,
+            mFalsingCollector,
+            mEmergencyButtonController,
+            mKeyguardMessageAreaControllerFactory,
+            mPostureController)
+  }
 
-    @Test
-    fun onPause_resetsText() {
-        mKeyguardPatternViewController.init()
-        mKeyguardPatternViewController.onPause()
-        verify(mKeyguardMessageAreaController).setMessage(R.string.keyguard_enter_your_pattern)
-    }
+  @Test
+  fun onPause_resetsText() {
+    mKeyguardPatternViewController.init()
+    mKeyguardPatternViewController.onPause()
+    verify(mKeyguardMessageAreaController).setMessage(R.string.keyguard_enter_your_pattern)
+  }
 
+  @Test
+  fun startAppearAnimation() {
+    mKeyguardPatternViewController.startAppearAnimation()
+    verify(mKeyguardMessageAreaController)
+        .setMessage(context.resources.getString(R.string.keyguard_enter_your_pattern), false)
+  }
 
-    @Test
-    fun startAppearAnimation() {
-        mKeyguardPatternViewController.startAppearAnimation()
-        verify(mKeyguardMessageAreaController).setMessage(R.string.keyguard_enter_your_pattern)
-    }
-
-    @Test
-    fun startAppearAnimation_withExistingMessage() {
-        `when`(mKeyguardMessageAreaController.message).thenReturn("Unlock to continue.")
-        mKeyguardPatternViewController.startAppearAnimation()
-        verify(
-            mKeyguardMessageAreaController,
-            never()
-        ).setMessage(R.string.keyguard_enter_your_password)
-    }
+  @Test
+  fun startAppearAnimation_withExistingMessage() {
+    `when`(mKeyguardMessageAreaController.message).thenReturn("Unlock to continue.")
+    mKeyguardPatternViewController.startAppearAnimation()
+    verify(mKeyguardMessageAreaController, never()).setMessage(anyString(), anyBoolean())
+  }
 }
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewControllerTest.java
index ce1101f..b742100 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewControllerTest.java
@@ -16,6 +16,8 @@
 
 package com.android.keyguard;
 
+import static com.google.common.truth.Truth.assertThat;
+
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -113,4 +115,9 @@
         mKeyguardPinViewController.onResume(KeyguardSecurityView.SCREEN_ON);
         verify(mPasswordEntry).requestFocus();
     }
+
+    @Test
+    public void testGetInitialMessageResId() {
+        assertThat(mKeyguardPinViewController.getInitialMessageResId()).isNotEqualTo(0);
+    }
 }
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinViewControllerTest.kt
index 8bcfe6f..cdb7bbb 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinViewControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinViewControllerTest.kt
@@ -31,10 +31,13 @@
 import org.junit.Before
 import org.junit.Test
 import org.junit.runner.RunWith
+import org.mockito.ArgumentMatchers.anyBoolean
+import org.mockito.ArgumentMatchers.anyString
 import org.mockito.Mock
 import org.mockito.Mockito
 import org.mockito.Mockito.any
 import org.mockito.Mockito.verify
+import org.mockito.Mockito.`when`
 import org.mockito.MockitoAnnotations
 
 @SmallTest
@@ -79,6 +82,7 @@
                 keyguardMessageAreaControllerFactory.create(any(KeyguardMessageArea::class.java))
             )
             .thenReturn(keyguardMessageAreaController)
+        `when`(keyguardPinView.resources).thenReturn(context.resources)
         pinViewController =
             KeyguardPinViewController(
                 keyguardPinView,
@@ -98,14 +102,14 @@
     @Test
     fun startAppearAnimation() {
         pinViewController.startAppearAnimation()
-        verify(keyguardMessageAreaController).setMessage(R.string.keyguard_enter_your_pin)
+        verify(keyguardMessageAreaController)
+            .setMessage(context.resources.getString(R.string.keyguard_enter_your_pin), false)
     }
 
     @Test
     fun startAppearAnimation_withExistingMessage() {
         Mockito.`when`(keyguardMessageAreaController.message).thenReturn("Unlock to continue.")
         pinViewController.startAppearAnimation()
-        verify(keyguardMessageAreaController, Mockito.never())
-            .setMessage(R.string.keyguard_enter_your_password)
+        verify(keyguardMessageAreaController, Mockito.never()).setMessage(anyString(), anyBoolean())
     }
 }
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java
index 002da55..0f4cf41 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java
@@ -31,6 +31,7 @@
 import static com.android.keyguard.FaceAuthApiRequestReason.NOTIFICATION_PANEL_CLICKED;
 import static com.android.keyguard.KeyguardUpdateMonitor.BIOMETRIC_STATE_CANCELLING_RESTARTING;
 import static com.android.keyguard.KeyguardUpdateMonitor.DEFAULT_CANCEL_SIGNAL_TIMEOUT;
+import static com.android.keyguard.KeyguardUpdateMonitor.HAL_POWER_PRESS_TIMEOUT;
 import static com.android.keyguard.KeyguardUpdateMonitor.getCurrentUser;
 
 import static com.google.common.truth.Truth.assertThat;
@@ -855,12 +856,21 @@
     }
 
     @Test
-    public void testFingerprintPowerPressed_restartsFingerprintListeningStateImmediately() {
+    public void testFingerprintPowerPressed_restartsFingerprintListeningStateWithDelay() {
         mKeyguardUpdateMonitor.mFingerprintAuthenticationCallback
                 .onAuthenticationError(FingerprintManager.BIOMETRIC_ERROR_POWER_PRESSED, "");
 
-        verify(mFingerprintManager).authenticate(any(), any(), any(), any(), anyInt(), anyInt(),
-                anyInt());
+        // THEN doesn't authenticate immediately
+        verify(mFingerprintManager, never()).authenticate(any(),
+                any(), any(), any(), anyInt(), anyInt(), anyInt());
+
+        // WHEN all messages (with delays) are processed
+        mTestableLooper.moveTimeForward(HAL_POWER_PRESS_TIMEOUT);
+        mTestableLooper.processAllMessages();
+
+        // THEN fingerprint manager attempts to authenticate again
+        verify(mFingerprintManager).authenticate(any(),
+                any(), any(), any(), anyInt(), anyInt(), anyInt());
     }
 
     @Test
@@ -2073,6 +2083,96 @@
         assertThat(mKeyguardUpdateMonitor.shouldListenForFace()).isFalse();
     }
 
+    @Test
+    public void fingerprintFailure_requestActiveUnlock_dismissKeyguard()
+            throws RemoteException {
+        // GIVEN shouldTriggerActiveUnlock
+        bouncerFullyVisible();
+        when(mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())).thenReturn(true);
+
+        // GIVEN active unlock triggers on biometric failures
+        when(mActiveUnlockConfig.shouldAllowActiveUnlockFromOrigin(
+                ActiveUnlockConfig.ACTIVE_UNLOCK_REQUEST_ORIGIN.BIOMETRIC_FAIL))
+                .thenReturn(true);
+
+        // WHEN fingerprint fails
+        mKeyguardUpdateMonitor.mFingerprintAuthenticationCallback.onAuthenticationFailed();
+
+        // ALWAYS request unlock with a keyguard dismissal
+        verify(mTrustManager).reportUserRequestedUnlock(eq(KeyguardUpdateMonitor.getCurrentUser()),
+                eq(true));
+    }
+
+    @Test
+    public void faceNonBypassFailure_requestActiveUnlock_doesNotDismissKeyguard()
+            throws RemoteException {
+        // GIVEN shouldTriggerActiveUnlock
+        when(mAuthController.isUdfpsFingerDown()).thenReturn(false);
+        keyguardIsVisible();
+        keyguardNotGoingAway();
+        statusBarShadeIsNotLocked();
+        when(mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())).thenReturn(true);
+
+        // GIVEN active unlock triggers on biometric failures
+        when(mActiveUnlockConfig.shouldAllowActiveUnlockFromOrigin(
+                ActiveUnlockConfig.ACTIVE_UNLOCK_REQUEST_ORIGIN.BIOMETRIC_FAIL))
+                .thenReturn(true);
+
+        // WHEN face fails & bypass is not allowed
+        lockscreenBypassIsNotAllowed();
+        mKeyguardUpdateMonitor.mFaceAuthenticationCallback.onAuthenticationFailed();
+
+        // THEN request unlock with NO keyguard dismissal
+        verify(mTrustManager).reportUserRequestedUnlock(eq(KeyguardUpdateMonitor.getCurrentUser()),
+                eq(false));
+    }
+
+    @Test
+    public void faceBypassFailure_requestActiveUnlock_dismissKeyguard()
+            throws RemoteException {
+        // GIVEN shouldTriggerActiveUnlock
+        when(mAuthController.isUdfpsFingerDown()).thenReturn(false);
+        keyguardIsVisible();
+        keyguardNotGoingAway();
+        statusBarShadeIsNotLocked();
+        when(mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())).thenReturn(true);
+
+        // GIVEN active unlock triggers on biometric failures
+        when(mActiveUnlockConfig.shouldAllowActiveUnlockFromOrigin(
+                ActiveUnlockConfig.ACTIVE_UNLOCK_REQUEST_ORIGIN.BIOMETRIC_FAIL))
+                .thenReturn(true);
+
+        // WHEN face fails & bypass is not allowed
+        lockscreenBypassIsAllowed();
+        mKeyguardUpdateMonitor.mFaceAuthenticationCallback.onAuthenticationFailed();
+
+        // THEN request unlock with a keyguard dismissal
+        verify(mTrustManager).reportUserRequestedUnlock(eq(KeyguardUpdateMonitor.getCurrentUser()),
+                eq(true));
+    }
+
+    @Test
+    public void faceNonBypassFailure_requestActiveUnlock_dismissKeyguard()
+            throws RemoteException {
+        // GIVEN shouldTriggerActiveUnlock
+        when(mAuthController.isUdfpsFingerDown()).thenReturn(false);
+        lockscreenBypassIsNotAllowed();
+        when(mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())).thenReturn(true);
+
+        // GIVEN active unlock triggers on biometric failures
+        when(mActiveUnlockConfig.shouldAllowActiveUnlockFromOrigin(
+                ActiveUnlockConfig.ACTIVE_UNLOCK_REQUEST_ORIGIN.BIOMETRIC_FAIL))
+                .thenReturn(true);
+
+        // WHEN face fails & on the bouncer
+        bouncerFullyVisible();
+        mKeyguardUpdateMonitor.mFaceAuthenticationCallback.onAuthenticationFailed();
+
+        // THEN request unlock with a keyguard dismissal
+        verify(mTrustManager).reportUserRequestedUnlock(eq(KeyguardUpdateMonitor.getCurrentUser()),
+                eq(true));
+    }
+
     private void userDeviceLockDown() {
         when(mStrongAuthTracker.isUnlockingWithBiometricAllowed(anyBoolean())).thenReturn(false);
         when(mStrongAuthTracker.getStrongAuthForUser(mCurrentUserId))
@@ -2090,6 +2190,9 @@
     }
 
     private void mockCanBypassLockscreen(boolean canBypass) {
+        // force update the isFaceEnrolled cache:
+        mKeyguardUpdateMonitor.isFaceAuthEnabledForUser(getCurrentUser());
+
         mKeyguardUpdateMonitor.setKeyguardBypassController(mKeyguardBypassController);
         when(mKeyguardBypassController.canBypass()).thenReturn(canBypass);
     }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/MenuAnimationControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/MenuAnimationControllerTest.java
index b2c5266..0cdd6e2 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/MenuAnimationControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/MenuAnimationControllerTest.java
@@ -20,8 +20,10 @@
 
 import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
 
 import android.graphics.PointF;
 import android.testing.AndroidTestingRunner;
@@ -30,6 +32,10 @@
 import android.view.ViewPropertyAnimator;
 import android.view.WindowManager;
 
+import androidx.dynamicanimation.animation.DynamicAnimation;
+import androidx.dynamicanimation.animation.FlingAnimation;
+import androidx.dynamicanimation.animation.SpringAnimation;
+import androidx.dynamicanimation.animation.SpringForce;
 import androidx.test.filters.SmallTest;
 
 import com.android.systemui.Prefs;
@@ -39,6 +45,9 @@
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+
+import java.util.Optional;
 
 /** Tests for {@link MenuAnimationController}. */
 @RunWith(AndroidTestingRunner.class)
@@ -47,9 +56,10 @@
 public class MenuAnimationControllerTest extends SysuiTestCase {
 
     private boolean mLastIsMoveToTucked;
+    private ArgumentCaptor<DynamicAnimation.OnAnimationEndListener> mEndListenerCaptor;
     private ViewPropertyAnimator mViewPropertyAnimator;
     private MenuView mMenuView;
-    private MenuAnimationController mMenuAnimationController;
+    private TestMenuAnimationController mMenuAnimationController;
 
     @Before
     public void setUp() throws Exception {
@@ -62,15 +72,17 @@
         mViewPropertyAnimator = spy(mMenuView.animate());
         doReturn(mViewPropertyAnimator).when(mMenuView).animate();
 
-        mMenuAnimationController = new MenuAnimationController(mMenuView);
+        mMenuAnimationController = new TestMenuAnimationController(mMenuView);
         mLastIsMoveToTucked = Prefs.getBoolean(mContext,
                 Prefs.Key.HAS_ACCESSIBILITY_FLOATING_MENU_TUCKED, /* defaultValue= */ false);
+        mEndListenerCaptor = ArgumentCaptor.forClass(DynamicAnimation.OnAnimationEndListener.class);
     }
 
     @After
     public void tearDown() throws Exception {
         Prefs.putBoolean(mContext, Prefs.Key.HAS_ACCESSIBILITY_FLOATING_MENU_TUCKED,
                 mLastIsMoveToTucked);
+        mEndListenerCaptor.getAllValues().clear();
     }
 
     @Test
@@ -122,4 +134,115 @@
 
         assertThat(isMoveToTucked).isFalse();
     }
+
+    @Test
+    public void startTuckedAnimationPreview_hasAnimation() {
+        mMenuView.clearAnimation();
+
+        mMenuAnimationController.startTuckedAnimationPreview();
+
+        assertThat(mMenuView.getAnimation()).isNotNull();
+    }
+
+    @Test
+    public void startSpringAnimationsAndEndOneAnimation_notTriggerEndAction() {
+        final Runnable onSpringAnimationsEndCallback = mock(Runnable.class);
+        mMenuAnimationController.setSpringAnimationsEndAction(onSpringAnimationsEndCallback);
+
+        setupAndRunSpringAnimations();
+        final Optional<DynamicAnimation> anyAnimation =
+                mMenuAnimationController.mPositionAnimations.values().stream().findAny();
+        anyAnimation.ifPresent(this::skipAnimationToEnd);
+
+        verifyZeroInteractions(onSpringAnimationsEndCallback);
+    }
+
+    @Test
+    public void startAndEndSpringAnimations_triggerEndAction() {
+        final Runnable onSpringAnimationsEndCallback = mock(Runnable.class);
+        mMenuAnimationController.setSpringAnimationsEndAction(onSpringAnimationsEndCallback);
+
+        setupAndRunSpringAnimations();
+        mMenuAnimationController.mPositionAnimations.values().forEach(this::skipAnimationToEnd);
+
+        verify(onSpringAnimationsEndCallback).run();
+    }
+
+    @Test
+    public void flingThenSpringAnimationsAreEnded_triggerEndAction() {
+        final Runnable onSpringAnimationsEndCallback = mock(Runnable.class);
+        mMenuAnimationController.setSpringAnimationsEndAction(onSpringAnimationsEndCallback);
+
+        mMenuAnimationController.flingMenuThenSpringToEdge(/* x= */ 0, /* velocityX= */
+                100, /* velocityY= */ 100);
+        mMenuAnimationController.mPositionAnimations.values()
+                .forEach(animation -> verify((FlingAnimation) animation).addEndListener(
+                        mEndListenerCaptor.capture()));
+        mEndListenerCaptor.getAllValues()
+                .forEach(listener -> listener.onAnimationEnd(mock(DynamicAnimation.class),
+                        /* canceled */ false, /* endValue */ 0, /* endVelocity */ 0));
+        mMenuAnimationController.mPositionAnimations.values().forEach(this::skipAnimationToEnd);
+
+        verify(onSpringAnimationsEndCallback).run();
+    }
+
+    @Test
+    public void existFlingIsRunningAndTheOtherAreEnd_notTriggerEndAction() {
+        final Runnable onSpringAnimationsEndCallback = mock(Runnable.class);
+        mMenuAnimationController.setSpringAnimationsEndAction(onSpringAnimationsEndCallback);
+
+        mMenuAnimationController.flingMenuThenSpringToEdge(/* x= */ 0, /* velocityX= */
+                200, /* velocityY= */ 200);
+        mMenuAnimationController.mPositionAnimations.values()
+                .forEach(animation -> verify((FlingAnimation) animation).addEndListener(
+                        mEndListenerCaptor.capture()));
+        final Optional<DynamicAnimation.OnAnimationEndListener> anyAnimation =
+                mEndListenerCaptor.getAllValues().stream().findAny();
+        anyAnimation.ifPresent(
+                listener -> listener.onAnimationEnd(mock(DynamicAnimation.class), /* canceled */
+                        false, /* endValue */ 0, /* endVelocity */ 0));
+        mMenuAnimationController.mPositionAnimations.values()
+                .stream()
+                .filter(animation -> animation instanceof SpringAnimation)
+                .forEach(this::skipAnimationToEnd);
+
+        verifyZeroInteractions(onSpringAnimationsEndCallback);
+    }
+
+    private void setupAndRunSpringAnimations() {
+        final float stiffness = 700f;
+        final float dampingRatio = 0.85f;
+        final float velocity = 100f;
+        final float finalPosition = 300f;
+
+        mMenuAnimationController.springMenuWith(DynamicAnimation.TRANSLATION_X, new SpringForce()
+                .setStiffness(stiffness)
+                .setDampingRatio(dampingRatio), velocity, finalPosition);
+        mMenuAnimationController.springMenuWith(DynamicAnimation.TRANSLATION_Y, new SpringForce()
+                .setStiffness(stiffness)
+                .setDampingRatio(dampingRatio), velocity, finalPosition);
+    }
+
+    private void skipAnimationToEnd(DynamicAnimation animation) {
+        final SpringAnimation springAnimation = ((SpringAnimation) animation);
+        // The doAnimationFrame function is used for skipping animation to the end.
+        springAnimation.doAnimationFrame(100);
+        springAnimation.skipToEnd();
+        springAnimation.doAnimationFrame(200);
+    }
+
+    /**
+     * Wrapper class for testing.
+     */
+    private static class TestMenuAnimationController extends MenuAnimationController {
+        TestMenuAnimationController(MenuView menuView) {
+            super(menuView);
+        }
+
+        @Override
+        FlingAnimation createFlingAnimation(MenuView menuView,
+                MenuPositionProperty menuPositionProperty) {
+            return spy(super.createFlingAnimation(menuView, menuPositionProperty));
+        }
+    }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/MenuEduTooltipViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/MenuEduTooltipViewTest.java
new file mode 100644
index 0000000..42b610a
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/MenuEduTooltipViewTest.java
@@ -0,0 +1,105 @@
+/*
+ * 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.systemui.accessibility.floatingmenu;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.res.Resources;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
+import android.view.WindowManager;
+import android.widget.TextView;
+
+import androidx.test.filters.SmallTest;
+
+import com.android.systemui.R;
+import com.android.systemui.SysuiTestCase;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/** Tests for {@link MenuEduTooltipView}. */
+@SmallTest
+@RunWith(AndroidTestingRunner.class)
+@TestableLooper.RunWithLooper
+public class MenuEduTooltipViewTest extends SysuiTestCase {
+    private MenuViewAppearance mMenuViewAppearance;
+    private MenuEduTooltipView mMenuEduTooltipView;
+
+    @Before
+    public void setUp() throws Exception {
+        final WindowManager windowManager = mContext.getSystemService(WindowManager.class);
+        mMenuViewAppearance = new MenuViewAppearance(mContext, windowManager);
+        mMenuEduTooltipView = new MenuEduTooltipView(mContext, mMenuViewAppearance);
+    }
+
+    @Test
+    public void show_matchMessageText() {
+        final CharSequence text = "Message";
+
+        mMenuEduTooltipView.show(text);
+
+        final TextView messageView = mMenuEduTooltipView.findViewById(R.id.text);
+        assertThat(messageView.getText().toString().contentEquals(text)).isTrue();
+    }
+
+    @Test
+    public void show_menuOnLeft_onRightOfAnchor() {
+        mMenuViewAppearance.setPercentagePosition(
+                new Position(/* percentageX= */ 0.0f, /* percentageY= */ 0.0f));
+        final CharSequence text = "Message";
+
+        mMenuEduTooltipView.show(text);
+        final int tooltipViewX = (int) (mMenuViewAppearance.getMenuPosition().x
+                + mMenuViewAppearance.getMenuWidth());
+
+        assertThat(mMenuEduTooltipView.getX()).isEqualTo(tooltipViewX);
+    }
+
+    @Test
+    public void show_menuCloseToLeftOfCenter_onLeftOfAnchor() {
+        mMenuViewAppearance.setPercentagePosition(
+                new Position(/* percentageX= */ 0.4f, /* percentageY= */ 0.0f));
+        final CharSequence text = "Message";
+
+        mMenuEduTooltipView.show(text);
+        final int tooltipViewX = (int) (mMenuViewAppearance.getMenuPosition().x
+                + mMenuViewAppearance.getMenuWidth());
+
+        assertThat(mMenuEduTooltipView.getX()).isEqualTo(tooltipViewX);
+    }
+
+    @Test
+    public void show_menuOnRight_onLeftOfAnchor() {
+        mMenuViewAppearance.setPercentagePosition(
+                new Position(/* percentageX= */ 1.0f, /* percentageY= */ 0.0f));
+        final Resources res = getContext().getResources();
+        final int arrowWidth =
+                res.getDimensionPixelSize(R.dimen.accessibility_floating_tooltip_arrow_width);
+        final int arrowMargin =
+                res.getDimensionPixelSize(R.dimen.accessibility_floating_tooltip_arrow_margin);
+        final CharSequence text = "Message";
+
+        mMenuEduTooltipView.show(text);
+        final TextView messageView = mMenuEduTooltipView.findViewById(R.id.text);
+        final int layoutWidth = messageView.getMeasuredWidth() + arrowWidth + arrowMargin;
+
+        assertThat(mMenuEduTooltipView.getX()).isEqualTo(
+                mMenuViewAppearance.getMenuPosition().x - layoutWidth);
+    }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/MenuListViewTouchHandlerTest.java b/packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/MenuListViewTouchHandlerTest.java
index 4acb394..d29ebb8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/MenuListViewTouchHandlerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/MenuListViewTouchHandlerTest.java
@@ -181,6 +181,20 @@
         verify(mMenuAnimationController).moveToEdgeAndHide();
     }
 
+    @Test
+    public void receiveActionDownMotionEvent_verifyOnActionDownEnd() {
+        final Runnable onActionDownEnd = mock(Runnable.class);
+        mTouchHandler.setOnActionDownEndListener(onActionDownEnd);
+
+        final MotionEvent stubDownEvent =
+                mMotionEventHelper.obtainMotionEvent(/* downTime= */ 0, /* eventTime= */ 1,
+                        MotionEvent.ACTION_DOWN, mStubMenuView.getTranslationX(),
+                        mStubMenuView.getTranslationY());
+        mTouchHandler.onInterceptTouchEvent(mStubListView, stubDownEvent);
+
+        verify(onActionDownEnd).run();
+    }
+
     @After
     public void tearDown() {
         mMotionEventHelper.recycleEvents();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerTest.java
index b267a5c..b061eb3 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerTest.java
@@ -16,6 +16,7 @@
 
 package com.android.systemui.biometrics;
 
+import static android.hardware.biometrics.BiometricFingerprintConstants.FINGERPRINT_ACQUIRED_GOOD;
 import static android.view.MotionEvent.ACTION_DOWN;
 import static android.view.MotionEvent.ACTION_MOVE;
 import static android.view.MotionEvent.ACTION_UP;
@@ -23,6 +24,8 @@
 import static com.android.internal.util.FunctionalUtils.ThrowingConsumer;
 
 import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
 
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyBoolean;
@@ -110,6 +113,8 @@
 import java.util.List;
 import java.util.Optional;
 
+import javax.inject.Provider;
+
 @SmallTest
 @RunWith(AndroidTestingRunner.class)
 @RunWithLooper(setAsMainLooper = true)
@@ -122,7 +127,7 @@
     // Unit under test
     private UdfpsController mUdfpsController;
     // Dependencies
-    private FakeExecutor mBiometricsExecutor;
+    private FakeExecutor mBiometricExecutor;
     @Mock
     private LayoutInflater mLayoutInflater;
     @Mock
@@ -210,6 +215,8 @@
     private ArgumentCaptor<Runnable> mOnDisplayConfiguredCaptor;
     @Captor
     private ArgumentCaptor<ScreenLifecycle.Observer> mScreenObserverCaptor;
+    @Captor
+    private ArgumentCaptor<UdfpsController.UdfpsOverlayController> mUdfpsOverlayControllerCaptor;
     private ScreenLifecycle.Observer mScreenObserver;
     private FingerprintSensorPropertiesInternal mOpticalProps;
     private FingerprintSensorPropertiesInternal mUltrasonicProps;
@@ -256,11 +263,12 @@
         mFgExecutor = new FakeExecutor(new FakeSystemClock());
 
         // Create a fake background executor.
-        mBiometricsExecutor = new FakeExecutor(new FakeSystemClock());
+        mBiometricExecutor = new FakeExecutor(new FakeSystemClock());
 
         initUdfpsController(true /* hasAlternateTouchProvider */);
     }
 
+
     private void initUdfpsController(boolean hasAlternateTouchProvider) {
         initUdfpsController(mOpticalProps, hasAlternateTouchProvider);
     }
@@ -270,8 +278,10 @@
         reset(mFingerprintManager);
         reset(mScreenLifecycle);
 
-        final Optional<AlternateUdfpsTouchProvider> alternateTouchProvider =
-                hasAlternateTouchProvider ? Optional.of(mAlternateTouchProvider) : Optional.empty();
+        final Optional<Provider<AlternateUdfpsTouchProvider>> alternateTouchProvider =
+                hasAlternateTouchProvider ? Optional.of(
+                        (Provider<AlternateUdfpsTouchProvider>) () -> mAlternateTouchProvider)
+                        : Optional.empty();
 
         mUdfpsController = new UdfpsController(mContext, new FakeExecution(), mLayoutInflater,
                 mFingerprintManager, mWindowManager, mStatusBarStateController, mFgExecutor,
@@ -281,7 +291,7 @@
                 mVibrator, mUdfpsHapticsSimulator, mUdfpsShell, mKeyguardStateController,
                 mDisplayManager, mHandler, mConfigurationController, mSystemClock,
                 mUnlockedScreenOffAnimationController, mSystemUIDialogManager, mLatencyTracker,
-                mActivityLaunchAnimator, alternateTouchProvider, mBiometricsExecutor,
+                mActivityLaunchAnimator, alternateTouchProvider, mBiometricExecutor,
                 mPrimaryBouncerInteractor, mSinglePointerTouchProcessor);
         verify(mFingerprintManager).setUdfpsOverlayController(mOverlayCaptor.capture());
         mOverlayController = mOverlayCaptor.getValue();
@@ -317,7 +327,7 @@
         verify(mUdfpsView).setOnTouchListener(mTouchListenerCaptor.capture());
         MotionEvent downEvent = MotionEvent.obtain(0, 0, ACTION_DOWN, 0, 0, 0);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, downEvent);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         downEvent.recycle();
 
         // THEN notify keyguard authenticate to dismiss the keyguard
@@ -355,7 +365,7 @@
             mFgExecutor.runAllReady();
         }
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, moveEvent);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         moveEvent.recycle();
 
         // THEN notify keyguard authenticate to dismiss the keyguard
@@ -379,12 +389,12 @@
         verify(mUdfpsView).setOnTouchListener(mTouchListenerCaptor.capture());
         MotionEvent downEvent = MotionEvent.obtain(0, 0, ACTION_DOWN, 0, 0, 0);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, downEvent);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         downEvent.recycle();
         MotionEvent moveEvent = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 0, 0, 0);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, moveEvent);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, moveEvent);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         moveEvent.recycle();
 
         // THEN notify keyguard authenticate to dismiss the keyguard
@@ -573,11 +583,11 @@
         MotionEvent event = obtainMotionEvent(ACTION_DOWN, displayWidth, displayHeight, touchMinor,
                 touchMajor);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, event);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         event.recycle();
         event = obtainMotionEvent(ACTION_MOVE, displayWidth, displayHeight, touchMinor, touchMajor);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, event);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         event.recycle();
         if (testParams.hasAlternateTouchProvider) {
             verify(mAlternateTouchProvider).onPointerDown(eq(TEST_REQUEST_ID), eq(expectedX),
@@ -596,11 +606,11 @@
                         scaleFactor, Surface.ROTATION_90));
         event = obtainMotionEvent(ACTION_DOWN, displayHeight, 0, touchMinor, touchMajor);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, event);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         event.recycle();
         event = obtainMotionEvent(ACTION_MOVE, displayHeight, 0, touchMinor, touchMajor);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, event);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         event.recycle();
         if (testParams.hasAlternateTouchProvider) {
             verify(mAlternateTouchProvider).onPointerDown(eq(TEST_REQUEST_ID), eq(expectedX),
@@ -619,11 +629,11 @@
                         scaleFactor, Surface.ROTATION_270));
         event = obtainMotionEvent(ACTION_DOWN, 0, displayWidth, touchMinor, touchMajor);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, event);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         event.recycle();
         event = obtainMotionEvent(ACTION_MOVE, 0, displayWidth, touchMinor, touchMajor);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, event);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         event.recycle();
         if (testParams.hasAlternateTouchProvider) {
             verify(mAlternateTouchProvider).onPointerDown(eq(TEST_REQUEST_ID), eq(expectedX),
@@ -643,11 +653,11 @@
         // ROTATION_180 is not supported. It should be treated like ROTATION_0.
         event = obtainMotionEvent(ACTION_DOWN, displayWidth, displayHeight, touchMinor, touchMajor);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, event);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         event.recycle();
         event = obtainMotionEvent(ACTION_MOVE, displayWidth, displayHeight, touchMinor, touchMajor);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, event);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         event.recycle();
         if (testParams.hasAlternateTouchProvider) {
             verify(mAlternateTouchProvider).onPointerDown(eq(TEST_REQUEST_ID), eq(expectedX),
@@ -682,12 +692,12 @@
         // WHEN ACTION_DOWN is received
         MotionEvent downEvent = MotionEvent.obtain(0, 0, ACTION_DOWN, 0, 0, 0);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, downEvent);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         downEvent.recycle();
 
         MotionEvent moveEvent = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 0, 0, 0);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, moveEvent);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         moveEvent.recycle();
 
         mFgExecutor.runAllReady();
@@ -720,7 +730,7 @@
         if (testParams.sensorProps.sensorType == FingerprintSensorProperties.TYPE_UDFPS_OPTICAL) {
             // AND onDisplayConfigured notifies FingerprintManager about onUiReady
             mOnDisplayConfiguredCaptor.getValue().run();
-            mBiometricsExecutor.runAllReady();
+            mBiometricExecutor.runAllReady();
             if (testParams.hasAlternateTouchProvider) {
                 InOrder inOrder = inOrder(mAlternateTouchProvider, mLatencyTracker);
                 inOrder.verify(mAlternateTouchProvider).onUiReady();
@@ -743,13 +753,15 @@
         }
     }
 
+
+
     @Test
     public void aodInterrupt() {
         runWithAllParams(this::aodInterruptParameterized);
     }
 
     private void aodInterruptParameterized(TestParams testParams) throws RemoteException {
-        mUdfpsController.cancelAodInterrupt();
+        mUdfpsController.cancelAodSendFingerUpAction();
         reset(mUdfpsView, mAlternateTouchProvider, mFingerprintManager, mKeyguardUpdateMonitor);
         when(mKeyguardUpdateMonitor.isFingerprintDetectionRunning()).thenReturn(true);
 
@@ -769,7 +781,7 @@
         } else {
             verify(mUdfpsView, never()).configureDisplay(mOnDisplayConfiguredCaptor.capture());
         }
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
 
         if (testParams.hasAlternateTouchProvider) {
             verify(mAlternateTouchProvider).onPointerDown(eq(TEST_REQUEST_ID), eq(0), eq(0),
@@ -787,7 +799,7 @@
     }
 
     @Test
-    public void cancelAodInterrupt() {
+    public void tryAodSendFingerUp_displayConfigurationChanges() {
         runWithAllParams(this::cancelAodInterruptParameterized);
     }
 
@@ -803,13 +815,89 @@
         if (testParams.sensorProps.sensorType == FingerprintSensorProperties.TYPE_UDFPS_OPTICAL) {
             when(mUdfpsView.isDisplayConfigured()).thenReturn(true);
             // WHEN it is cancelled
-            mUdfpsController.cancelAodInterrupt();
+            mUdfpsController.tryAodSendFingerUp();
             // THEN the display is unconfigured
             verify(mUdfpsView).unconfigureDisplay();
         } else {
             when(mUdfpsView.isDisplayConfigured()).thenReturn(false);
             // WHEN it is cancelled
-            mUdfpsController.cancelAodInterrupt();
+            mUdfpsController.tryAodSendFingerUp();
+            // THEN the display configuration is unchanged.
+            verify(mUdfpsView, never()).unconfigureDisplay();
+        }
+    }
+
+    @Test
+    public void onFingerUp_displayConfigurationChange() {
+        runWithAllParams(this::onFingerUp_displayConfigurationParameterized);
+    }
+
+    private void onFingerUp_displayConfigurationParameterized(TestParams testParams)
+            throws RemoteException {
+        reset(mUdfpsView);
+
+        // GIVEN AOD interrupt
+        mOverlayController.showUdfpsOverlay(TEST_REQUEST_ID, testParams.sensorProps.sensorId,
+                BiometricOverlayConstants.REASON_AUTH_KEYGUARD, mUdfpsOverlayControllerCallback);
+        mScreenObserver.onScreenTurnedOn();
+        mFgExecutor.runAllReady();
+        mUdfpsController.onAodInterrupt(0, 0, 0f, 0f);
+        if (testParams.sensorProps.sensorType == FingerprintSensorProperties.TYPE_UDFPS_OPTICAL) {
+            when(mUdfpsView.isDisplayConfigured()).thenReturn(true);
+
+            // WHEN up-action received
+            verify(mUdfpsView).setOnTouchListener(mTouchListenerCaptor.capture());
+            MotionEvent upEvent = MotionEvent.obtain(0, 0, ACTION_UP, 0, 0, 0);
+            mTouchListenerCaptor.getValue().onTouch(mUdfpsView, upEvent);
+            mBiometricExecutor.runAllReady();
+            upEvent.recycle();
+            mFgExecutor.runAllReady();
+
+            // THEN the display is unconfigured
+            verify(mUdfpsView).unconfigureDisplay();
+        } else {
+            when(mUdfpsView.isDisplayConfigured()).thenReturn(false);
+
+            // WHEN up-action received
+            verify(mUdfpsView).setOnTouchListener(mTouchListenerCaptor.capture());
+            MotionEvent upEvent = MotionEvent.obtain(0, 0, ACTION_UP, 0, 0, 0);
+            mTouchListenerCaptor.getValue().onTouch(mUdfpsView, upEvent);
+            mBiometricExecutor.runAllReady();
+            upEvent.recycle();
+            mFgExecutor.runAllReady();
+
+            // THEN the display configuration is unchanged.
+            verify(mUdfpsView, never()).unconfigureDisplay();
+        }
+    }
+
+    @Test
+    public void onAcquiredGood_displayConfigurationChange() {
+        runWithAllParams(this::onAcquiredGood_displayConfigurationParameterized);
+    }
+
+    private void onAcquiredGood_displayConfigurationParameterized(TestParams testParams)
+            throws RemoteException {
+        reset(mUdfpsView);
+
+        // GIVEN overlay is showing
+        mOverlayController.showUdfpsOverlay(TEST_REQUEST_ID, testParams.sensorProps.sensorId,
+                BiometricOverlayConstants.REASON_AUTH_KEYGUARD, mUdfpsOverlayControllerCallback);
+        mFgExecutor.runAllReady();
+        if (testParams.sensorProps.sensorType == FingerprintSensorProperties.TYPE_UDFPS_OPTICAL) {
+            when(mUdfpsView.isDisplayConfigured()).thenReturn(true);
+            // WHEN ACQUIRED_GOOD received
+            mOverlayController.onAcquired(testParams.sensorProps.sensorId,
+                    BiometricFingerprintConstants.FINGERPRINT_ACQUIRED_GOOD);
+            mFgExecutor.runAllReady();
+            // THEN the display is unconfigured
+            verify(mUdfpsView).unconfigureDisplay();
+        } else {
+            when(mUdfpsView.isDisplayConfigured()).thenReturn(false);
+            // WHEN ACQUIRED_GOOD received
+            mOverlayController.onAcquired(testParams.sensorProps.sensorId,
+                    BiometricFingerprintConstants.FINGERPRINT_ACQUIRED_GOOD);
+            mFgExecutor.runAllReady();
             // THEN the display configuration is unchanged.
             verify(mUdfpsView, never()).unconfigureDisplay();
         }
@@ -876,7 +964,7 @@
         verify(mUdfpsView).setOnTouchListener(mTouchListenerCaptor.capture());
         MotionEvent upEvent = MotionEvent.obtain(0, 0, ACTION_UP, 0, 0, 0);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, upEvent);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         upEvent.recycle();
 
         // Configure UdfpsView to accept the ACTION_DOWN event
@@ -885,80 +973,13 @@
         // WHEN ACTION_DOWN is received
         MotionEvent downEvent = MotionEvent.obtain(0, 0, ACTION_DOWN, 0, 0, 0);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, downEvent);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         downEvent.recycle();
 
         // WHEN ACTION_MOVE is received
         MotionEvent moveEvent = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 0, 0, 0);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, moveEvent);
-        mBiometricsExecutor.runAllReady();
-        moveEvent.recycle();
-        mFgExecutor.runAllReady();
-
-        if (testParams.sensorProps.sensorType == FingerprintSensorProperties.TYPE_UDFPS_OPTICAL) {
-            // Configure UdfpsView to accept the finger up event
-            when(mUdfpsView.isDisplayConfigured()).thenReturn(true);
-        } else {
-            when(mUdfpsView.isDisplayConfigured()).thenReturn(false);
-        }
-
-        // WHEN it times out
-        mFgExecutor.advanceClockToNext();
-        mFgExecutor.runAllReady();
-
-        if (testParams.sensorProps.sensorType == FingerprintSensorProperties.TYPE_UDFPS_OPTICAL) {
-            // THEN the display should be unconfigured once. If the timeout action is not
-            // cancelled, the display would be unconfigured twice which would cause two
-            // FP attempts.
-            verify(mUdfpsView, times(1)).unconfigureDisplay();
-        } else {
-            verify(mUdfpsView, never()).unconfigureDisplay();
-        }
-    }
-
-    @Test
-    public void aodInterruptCancelTimeoutActionOnAcquired() {
-        runWithAllParams(this::aodInterruptCancelTimeoutActionOnAcquiredParameterized);
-    }
-
-    private void aodInterruptCancelTimeoutActionOnAcquiredParameterized(TestParams testParams)
-            throws RemoteException {
-        reset(mUdfpsView);
-        when(mUdfpsView.isWithinSensorArea(anyFloat(), anyFloat())).thenReturn(true);
-
-        // GIVEN AOD interrupt
-        mOverlayController.showUdfpsOverlay(TEST_REQUEST_ID, testParams.sensorProps.sensorId,
-                BiometricOverlayConstants.REASON_AUTH_KEYGUARD, mUdfpsOverlayControllerCallback);
-        mScreenObserver.onScreenTurnedOn();
-        mFgExecutor.runAllReady();
-        mUdfpsController.onAodInterrupt(0, 0, 0f, 0f);
-        mFgExecutor.runAllReady();
-
-        if (testParams.sensorProps.sensorType == FingerprintSensorProperties.TYPE_UDFPS_OPTICAL) {
-            // Configure UdfpsView to accept the acquired event
-            when(mUdfpsView.isDisplayConfigured()).thenReturn(true);
-        } else {
-            when(mUdfpsView.isDisplayConfigured()).thenReturn(false);
-        }
-
-        // WHEN acquired is received
-        mOverlayController.onAcquired(testParams.sensorProps.sensorId,
-                BiometricFingerprintConstants.FINGERPRINT_ACQUIRED_GOOD);
-
-        // Configure UdfpsView to accept the ACTION_DOWN event
-        when(mUdfpsView.isDisplayConfigured()).thenReturn(false);
-
-        // WHEN ACTION_DOWN is received
-        verify(mUdfpsView).setOnTouchListener(mTouchListenerCaptor.capture());
-        MotionEvent downEvent = MotionEvent.obtain(0, 0, ACTION_DOWN, 0, 0, 0);
-        mTouchListenerCaptor.getValue().onTouch(mUdfpsView, downEvent);
-        mBiometricsExecutor.runAllReady();
-        downEvent.recycle();
-
-        // WHEN ACTION_MOVE is received
-        MotionEvent moveEvent = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 0, 0, 0);
-        mTouchListenerCaptor.getValue().onTouch(mUdfpsView, moveEvent);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         moveEvent.recycle();
         mFgExecutor.runAllReady();
 
@@ -1078,11 +1099,11 @@
         verify(mUdfpsView).setOnTouchListener(mTouchListenerCaptor.capture());
         MotionEvent downEvent = MotionEvent.obtain(0, 0, ACTION_DOWN, 0, 0, 0);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, downEvent);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         downEvent.recycle();
         MotionEvent moveEvent = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 0, 0, 0);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, moveEvent);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         moveEvent.recycle();
 
         // THEN NO haptic played
@@ -1118,19 +1139,19 @@
         // WHEN ACTION_DOWN is received
         MotionEvent downEvent = MotionEvent.obtain(0, 0, ACTION_DOWN, 0, 0, 0);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, downEvent);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         downEvent.recycle();
 
         // AND ACTION_MOVE is received
         MotionEvent moveEvent = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 0, 0, 0);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, moveEvent);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         moveEvent.recycle();
 
         // AND ACTION_UP is received
         MotionEvent upEvent = MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, 0, 0, 0);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, upEvent);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         upEvent.recycle();
 
         // THEN the old FingerprintManager path is invoked.
@@ -1140,7 +1161,7 @@
     }
 
     @Test
-    public void onTouch_withNewTouchDetection_shouldCallOldFingerprintManagerPath()
+    public void onTouch_withNewTouchDetection_shouldCallNewFingerprintManagerPath()
             throws RemoteException {
         final NormalizedTouchData touchData = new NormalizedTouchData(0, 0f, 0f, 0f, 0f, 0f, 0L,
                 0L);
@@ -1172,7 +1193,7 @@
                 processorResultDown);
         MotionEvent downEvent = MotionEvent.obtain(0, 0, ACTION_DOWN, 0, 0, 0);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, downEvent);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         downEvent.recycle();
 
         // AND ACTION_UP is received
@@ -1180,7 +1201,7 @@
                 processorResultUp);
         MotionEvent upEvent = MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, 0, 0, 0);
         mTouchListenerCaptor.getValue().onTouch(mUdfpsView, upEvent);
-        mBiometricsExecutor.runAllReady();
+        mBiometricExecutor.runAllReady();
         upEvent.recycle();
 
         // THEN the new FingerprintManager path is invoked.
@@ -1189,4 +1210,31 @@
         verify(mFingerprintManager).onPointerUp(anyLong(), anyInt(), anyInt(), anyFloat(),
                 anyFloat(), anyFloat(), anyFloat(), anyFloat(), anyLong(), anyLong(), anyBoolean());
     }
+
+    @Test
+    public void onAodInterrupt_onAcquiredGood_fingerNoLongerDown() throws RemoteException {
+        // GIVEN UDFPS overlay is showing
+        mOverlayController.showUdfpsOverlay(TEST_REQUEST_ID, mOpticalProps.sensorId,
+                BiometricOverlayConstants.REASON_AUTH_KEYGUARD, mUdfpsOverlayControllerCallback);
+        mFgExecutor.runAllReady();
+
+        // GIVEN there's been an AoD interrupt
+        when(mKeyguardUpdateMonitor.isFingerprintDetectionRunning()).thenReturn(true);
+        mScreenObserver.onScreenTurnedOn();
+        mUdfpsController.onAodInterrupt(0, 0, 0, 0);
+
+        // THEN finger is considered down
+        assertTrue(mUdfpsController.isFingerDown());
+
+        // WHEN udfps receives an ACQUIRED_GOOD after the display is configured
+        when(mUdfpsView.isDisplayConfigured()).thenReturn(true);
+        verify(mFingerprintManager).setUdfpsOverlayController(
+                mUdfpsOverlayControllerCaptor.capture());
+        mUdfpsOverlayControllerCaptor.getValue().onAcquired(0, FINGERPRINT_ACQUIRED_GOOD);
+        mFgExecutor.runAllReady();
+
+        // THEN is fingerDown should be FALSE
+        assertFalse(mUdfpsController.isFingerDown());
+
+    }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewControllerWithCoroutinesTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewControllerWithCoroutinesTest.kt
index 517e27a..2d412dc 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewControllerWithCoroutinesTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewControllerWithCoroutinesTest.kt
@@ -27,16 +27,19 @@
 import com.android.systemui.keyguard.data.repository.KeyguardBouncerRepository
 import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerCallbackInteractor
 import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerInteractor
+import com.android.systemui.log.table.TableLogBuffer
 import com.android.systemui.statusbar.StatusBarState
 import com.android.systemui.statusbar.phone.KeyguardBouncer
 import com.android.systemui.statusbar.phone.KeyguardBypassController
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.runBlocking
+import kotlinx.coroutines.test.TestCoroutineScope
 import kotlinx.coroutines.yield
 import org.junit.Assert.assertTrue
 import org.junit.Before
 import org.junit.Test
 import org.junit.runner.RunWith
+import org.mockito.Mock
 import org.mockito.Mockito.mock
 import org.mockito.MockitoAnnotations
 
@@ -45,6 +48,7 @@
 @TestableLooper.RunWithLooper
 class UdfpsKeyguardViewControllerWithCoroutinesTest : UdfpsKeyguardViewControllerBaseTest() {
     lateinit var keyguardBouncerRepository: KeyguardBouncerRepository
+    @Mock private lateinit var bouncerLogger: TableLogBuffer
 
     @Before
     override fun setUp() {
@@ -53,7 +57,8 @@
         keyguardBouncerRepository =
             KeyguardBouncerRepository(
                 mock(com.android.keyguard.ViewMediatorCallback::class.java),
-                mKeyguardUpdateMonitor
+                TestCoroutineScope(),
+                bouncerLogger,
             )
         super.setUp()
     }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/camera/CameraGestureHelperTest.kt b/packages/SystemUI/tests/src/com/android/systemui/camera/CameraGestureHelperTest.kt
index ca94ea8..262b4b8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/camera/CameraGestureHelperTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/camera/CameraGestureHelperTest.kt
@@ -301,7 +301,7 @@
         val intent = intentCaptor.value
 
         assertThat(CameraIntents.isSecureCameraIntent(intent)).isEqualTo(isSecure)
-        assertThat(intent.getIntExtra(CameraGestureHelper.EXTRA_CAMERA_LAUNCH_SOURCE, -1))
+        assertThat(intent.getIntExtra(CameraIntents.EXTRA_LAUNCH_SOURCE, -1))
             .isEqualTo(source)
     }
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlActionCoordinatorImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlActionCoordinatorImplTest.kt
index 1d00d6b..16fb50c 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlActionCoordinatorImplTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlActionCoordinatorImplTest.kt
@@ -16,21 +16,19 @@
 
 package com.android.systemui.controls.ui
 
-import android.content.Context
-import android.content.SharedPreferences
 import android.test.suitebuilder.annotation.SmallTest
 import android.testing.AndroidTestingRunner
 import com.android.systemui.SysuiTestCase
 import com.android.systemui.broadcast.BroadcastSender
 import com.android.systemui.controls.ControlsMetricsLogger
-import com.android.systemui.controls.FakeControlsSettingsRepository
+import com.android.systemui.controls.settings.ControlsSettingsDialogManager
+import com.android.systemui.controls.settings.FakeControlsSettingsRepository
+import com.android.systemui.flags.FeatureFlags
+import com.android.systemui.flags.Flags
 import com.android.systemui.plugins.ActivityStarter
-import com.android.systemui.settings.UserContextProvider
 import com.android.systemui.statusbar.VibratorHelper
-import com.android.systemui.statusbar.policy.DeviceControlsControllerImpl
 import com.android.systemui.statusbar.policy.KeyguardStateController
 import com.android.systemui.util.concurrency.DelayableExecutor
-import com.android.systemui.util.settings.SecureSettings
 import com.android.wm.shell.TaskViewFactory
 import org.junit.Before
 import org.junit.Test
@@ -40,8 +38,8 @@
 import org.mockito.Mockito
 import org.mockito.Mockito.`when`
 import org.mockito.Mockito.anyBoolean
+import org.mockito.Mockito.doNothing
 import org.mockito.Mockito.doReturn
-import org.mockito.Mockito.mock
 import org.mockito.Mockito.never
 import org.mockito.Mockito.reset
 import org.mockito.Mockito.spy
@@ -71,9 +69,9 @@
     @Mock
     private lateinit var metricsLogger: ControlsMetricsLogger
     @Mock
-    private lateinit var secureSettings: SecureSettings
+    private lateinit var featureFlags: FeatureFlags
     @Mock
-    private lateinit var userContextProvider: UserContextProvider
+    private lateinit var controlsSettingsDialogManager: ControlsSettingsDialogManager
 
     companion object {
         fun <T> any(): T = Mockito.any<T>()
@@ -103,23 +101,16 @@
                 taskViewFactory,
                 metricsLogger,
                 vibratorHelper,
-                secureSettings,
-                userContextProvider,
-                controlsSettingsRepository
+                controlsSettingsRepository,
+                controlsSettingsDialogManager,
+                featureFlags
         ))
-
-        val userContext = mock(Context::class.java)
-        val pref = mock(SharedPreferences::class.java)
-        `when`(userContextProvider.userContext).thenReturn(userContext)
-        `when`(userContext.getSharedPreferences(
-                DeviceControlsControllerImpl.PREFS_CONTROLS_FILE, Context.MODE_PRIVATE))
-                .thenReturn(pref)
-        // Just return 2 so we don't test any Dialog logic which requires a launched activity.
-        `when`(pref.getInt(DeviceControlsControllerImpl.PREFS_SETTINGS_DIALOG_ATTEMPTS, 0))
-                .thenReturn(2)
+        coordinator.activityContext = mContext
 
         `when`(cvh.cws.ci.controlId).thenReturn(ID)
         `when`(cvh.cws.control?.isAuthRequired()).thenReturn(true)
+        `when`(featureFlags.isEnabled(Flags.USE_APP_PANELS)).thenReturn(false)
+
         action = spy(coordinator.Action(ID, {}, false, true))
         doReturn(action).`when`(coordinator).createAction(any(), any(), anyBoolean(), anyBoolean())
     }
@@ -160,15 +151,31 @@
         doReturn(action).`when`(coordinator).createAction(any(), any(), anyBoolean(), anyBoolean())
 
         `when`(keyguardStateController.isShowing()).thenReturn(true)
-        `when`(keyguardStateController.isUnlocked()).thenReturn(false)
 
         coordinator.toggle(cvh, "", true)
 
         verify(coordinator).bouncerOrRun(action)
+        verify(controlsSettingsDialogManager).maybeShowDialog(any(), any())
         verify(action).invoke()
     }
 
     @Test
+    fun testToggleWhenLockedDoesNotTriggerDialog_featureFlagEnabled() {
+        `when`(featureFlags.isEnabled(Flags.USE_APP_PANELS)).thenReturn(true)
+        action = spy(coordinator.Action(ID, {}, false, false))
+        doReturn(action).`when`(coordinator).createAction(any(), any(), anyBoolean(), anyBoolean())
+
+        `when`(keyguardStateController.isShowing()).thenReturn(true)
+        `when`(keyguardStateController.isUnlocked()).thenReturn(false)
+        doNothing().`when`(controlsSettingsDialogManager).maybeShowDialog(any(), any())
+
+        coordinator.toggle(cvh, "", true)
+
+        verify(coordinator).bouncerOrRun(action)
+        verify(controlsSettingsDialogManager, never()).maybeShowDialog(any(), any())
+    }
+
+    @Test
     fun testToggleDoesNotRunsWhenLockedAndAuthRequired() {
         action = spy(coordinator.Action(ID, {}, false, true))
         doReturn(action).`when`(coordinator).createAction(any(), any(), anyBoolean(), anyBoolean())
diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/dagger/ControlsComponentTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/dagger/ControlsComponentTest.kt
index 48fc46b..9144b13 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/controls/dagger/ControlsComponentTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/controls/dagger/ControlsComponentTest.kt
@@ -22,7 +22,7 @@
 import com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED
 import com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT
 import com.android.systemui.SysuiTestCase
-import com.android.systemui.controls.FakeControlsSettingsRepository
+import com.android.systemui.controls.settings.FakeControlsSettingsRepository
 import com.android.systemui.controls.controller.ControlsController
 import com.android.systemui.controls.controller.ControlsTileResourceConfiguration
 import com.android.systemui.controls.management.ControlsListingController
diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsListingControllerImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsListingControllerImplTest.kt
index c677f19..35cd3d2 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsListingControllerImplTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsListingControllerImplTest.kt
@@ -36,6 +36,7 @@
 import com.android.systemui.controls.ControlsServiceInfo
 import com.android.systemui.dump.DumpManager
 import com.android.systemui.flags.FeatureFlags
+import com.android.systemui.flags.Flags.APP_PANELS_ALL_APPS_ALLOWED
 import com.android.systemui.flags.Flags.USE_APP_PANELS
 import com.android.systemui.settings.UserTracker
 import com.android.systemui.util.concurrency.FakeExecutor
@@ -119,6 +120,8 @@
 
         // Return true by default, we'll test the false path
         `when`(featureFlags.isEnabled(USE_APP_PANELS)).thenReturn(true)
+        // Return false by default, we'll test the true path
+        `when`(featureFlags.isEnabled(APP_PANELS_ALL_APPS_ALLOWED)).thenReturn(false)
 
         val wrapper = object : ContextWrapper(mContext) {
             override fun createContextAsUser(user: UserHandle, flags: Int): Context {
@@ -518,6 +521,37 @@
     }
 
     @Test
+    fun testPackageNotPreferred_allowAllApps_correctPanel() {
+        `when`(featureFlags.isEnabled(APP_PANELS_ALL_APPS_ALLOWED)).thenReturn(true)
+
+        mContext.orCreateTestableResources
+                .addOverride(R.array.config_controlsPreferredPackages, arrayOf<String>())
+
+        val serviceInfo = ServiceInfo(
+                componentName,
+                activityName
+        )
+
+        `when`(packageManager.getComponentEnabledSetting(eq(activityName)))
+                .thenReturn(PackageManager.COMPONENT_ENABLED_STATE_ENABLED)
+
+        setUpQueryResult(listOf(
+                ActivityInfo(
+                        activityName,
+                        exported = true,
+                        permission = Manifest.permission.BIND_CONTROLS
+                )
+        ))
+
+        val list = listOf(serviceInfo)
+        serviceListingCallbackCaptor.value.onServicesReloaded(list)
+
+        executor.runAllReady()
+
+        assertEquals(activityName, controller.getCurrentServices()[0].panelActivity)
+    }
+
+    @Test
     fun testListingsNotModifiedByCallback() {
         // This test checks that if the list passed to the callback is modified, it has no effect
         // in the resulting services
diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/settings/ControlsSettingsDialogManagerImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/settings/ControlsSettingsDialogManagerImplTest.kt
new file mode 100644
index 0000000..0c9986d
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/controls/settings/ControlsSettingsDialogManagerImplTest.kt
@@ -0,0 +1,328 @@
+/*
+ * 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.systemui.controls.settings
+
+import android.content.DialogInterface
+import android.content.SharedPreferences
+import android.database.ContentObserver
+import android.provider.Settings.Secure.LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS
+import android.provider.Settings.Secure.LOCKSCREEN_SHOW_CONTROLS
+import android.testing.AndroidTestingRunner
+import android.testing.TestableLooper
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.controls.settings.ControlsSettingsDialogManager.Companion.PREFS_SETTINGS_DIALOG_ATTEMPTS
+import com.android.systemui.plugins.ActivityStarter
+import com.android.systemui.settings.UserFileManager
+import com.android.systemui.settings.UserTracker
+import com.android.systemui.statusbar.policy.DeviceControlsControllerImpl
+import com.android.systemui.util.FakeSharedPreferences
+import com.android.systemui.util.TestableAlertDialog
+import com.android.systemui.util.mockito.any
+import com.android.systemui.util.mockito.eq
+import com.android.systemui.util.mockito.nullable
+import com.android.systemui.util.settings.FakeSettings
+import com.google.common.truth.Truth.assertThat
+import org.junit.After
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.ArgumentMatchers.anyBoolean
+import org.mockito.Mock
+import org.mockito.Mockito.anyInt
+import org.mockito.Mockito.never
+import org.mockito.Mockito.verify
+import org.mockito.Mockito.`when`
+import org.mockito.MockitoAnnotations
+
+@SmallTest
+@RunWith(AndroidTestingRunner::class)
+@TestableLooper.RunWithLooper
+class ControlsSettingsDialogManagerImplTest : SysuiTestCase() {
+
+    companion object {
+        private const val SETTING_SHOW = LOCKSCREEN_SHOW_CONTROLS
+        private const val SETTING_ACTION = LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS
+        private const val MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG = 2
+    }
+
+    @Mock private lateinit var userFileManager: UserFileManager
+    @Mock private lateinit var userTracker: UserTracker
+    @Mock private lateinit var activityStarter: ActivityStarter
+    @Mock private lateinit var completedRunnable: () -> Unit
+
+    private lateinit var controlsSettingsRepository: FakeControlsSettingsRepository
+    private lateinit var sharedPreferences: FakeSharedPreferences
+    private lateinit var secureSettings: FakeSettings
+
+    private lateinit var underTest: ControlsSettingsDialogManagerImpl
+
+    private var dialog: TestableAlertDialog? = null
+
+    @Before
+    fun setUp() {
+        MockitoAnnotations.initMocks(this)
+
+        controlsSettingsRepository = FakeControlsSettingsRepository()
+        sharedPreferences = FakeSharedPreferences()
+        secureSettings = FakeSettings()
+
+        `when`(userTracker.userId).thenReturn(0)
+        secureSettings.userId = userTracker.userId
+        `when`(
+                userFileManager.getSharedPreferences(
+                    eq(DeviceControlsControllerImpl.PREFS_CONTROLS_FILE),
+                    anyInt(),
+                    anyInt()
+                )
+            )
+            .thenReturn(sharedPreferences)
+
+        `when`(activityStarter.dismissKeyguardThenExecute(any(), nullable(), anyBoolean()))
+            .thenAnswer { (it.arguments[0] as ActivityStarter.OnDismissAction).onDismiss() }
+
+        attachRepositoryToSettings()
+        underTest =
+            ControlsSettingsDialogManagerImpl(
+                secureSettings,
+                userFileManager,
+                controlsSettingsRepository,
+                userTracker,
+                activityStarter
+            ) { context, _ -> TestableAlertDialog(context).also { dialog = it } }
+    }
+
+    @After
+    fun tearDown() {
+        underTest.closeDialog()
+    }
+
+    @Test
+    fun dialogNotShownIfPrefsAtMaximum() {
+        sharedPreferences.putAttempts(MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG)
+
+        underTest.maybeShowDialog(context, completedRunnable)
+
+        assertThat(dialog?.isShowing ?: false).isFalse()
+        verify(completedRunnable).invoke()
+    }
+
+    @Test
+    fun dialogNotShownIfSettingsAreTrue() {
+        sharedPreferences.putAttempts(0)
+        secureSettings.putBool(SETTING_SHOW, true)
+        secureSettings.putBool(SETTING_ACTION, true)
+
+        underTest.maybeShowDialog(context, completedRunnable)
+
+        assertThat(dialog?.isShowing ?: false).isFalse()
+        verify(completedRunnable).invoke()
+    }
+
+    @Test
+    fun dialogShownIfAllowTrivialControlsFalse() {
+        sharedPreferences.putAttempts(0)
+        secureSettings.putBool(SETTING_SHOW, true)
+        secureSettings.putBool(SETTING_ACTION, false)
+
+        underTest.maybeShowDialog(context, completedRunnable)
+
+        assertThat(dialog?.isShowing ?: false).isTrue()
+    }
+
+    @Test
+    fun dialogDispossedAfterClosing() {
+        sharedPreferences.putAttempts(0)
+        secureSettings.putBool(SETTING_SHOW, true)
+        secureSettings.putBool(SETTING_ACTION, false)
+
+        underTest.maybeShowDialog(context, completedRunnable)
+        underTest.closeDialog()
+
+        assertThat(dialog?.isShowing ?: false).isFalse()
+    }
+
+    @Test
+    fun dialogNeutralButtonDoesntChangeSetting() {
+        sharedPreferences.putAttempts(0)
+        secureSettings.putBool(SETTING_SHOW, true)
+        secureSettings.putBool(SETTING_ACTION, false)
+
+        underTest.maybeShowDialog(context, completedRunnable)
+        clickButton(DialogInterface.BUTTON_NEUTRAL)
+
+        assertThat(secureSettings.getBool(SETTING_ACTION, false)).isFalse()
+    }
+
+    @Test
+    fun dialogNeutralButtonPutsMaxAttempts() {
+        sharedPreferences.putAttempts(0)
+        secureSettings.putBool(SETTING_SHOW, true)
+        secureSettings.putBool(SETTING_ACTION, false)
+
+        underTest.maybeShowDialog(context, completedRunnable)
+        clickButton(DialogInterface.BUTTON_NEUTRAL)
+
+        assertThat(sharedPreferences.getInt(PREFS_SETTINGS_DIALOG_ATTEMPTS, 0))
+            .isEqualTo(MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG)
+    }
+
+    @Test
+    fun dialogNeutralButtonCallsOnComplete() {
+        sharedPreferences.putAttempts(0)
+        secureSettings.putBool(SETTING_SHOW, true)
+        secureSettings.putBool(SETTING_ACTION, false)
+
+        underTest.maybeShowDialog(context, completedRunnable)
+        clickButton(DialogInterface.BUTTON_NEUTRAL)
+
+        verify(completedRunnable).invoke()
+    }
+
+    @Test
+    fun dialogPositiveButtonChangesSetting() {
+        sharedPreferences.putAttempts(0)
+        secureSettings.putBool(SETTING_SHOW, true)
+        secureSettings.putBool(SETTING_ACTION, false)
+
+        underTest.maybeShowDialog(context, completedRunnable)
+        clickButton(DialogInterface.BUTTON_POSITIVE)
+
+        assertThat(secureSettings.getBool(SETTING_ACTION, false)).isTrue()
+    }
+
+    @Test
+    fun dialogPositiveButtonPutsMaxAttempts() {
+        sharedPreferences.putAttempts(0)
+        secureSettings.putBool(SETTING_SHOW, true)
+        secureSettings.putBool(SETTING_ACTION, false)
+
+        underTest.maybeShowDialog(context, completedRunnable)
+        clickButton(DialogInterface.BUTTON_POSITIVE)
+
+        assertThat(sharedPreferences.getInt(PREFS_SETTINGS_DIALOG_ATTEMPTS, 0))
+            .isEqualTo(MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG)
+    }
+
+    @Test
+    fun dialogPositiveButtonCallsOnComplete() {
+        sharedPreferences.putAttempts(0)
+        secureSettings.putBool(SETTING_SHOW, true)
+        secureSettings.putBool(SETTING_ACTION, false)
+
+        underTest.maybeShowDialog(context, completedRunnable)
+        clickButton(DialogInterface.BUTTON_POSITIVE)
+
+        verify(completedRunnable).invoke()
+    }
+
+    @Test
+    fun dialogCancelDoesntChangeSetting() {
+        sharedPreferences.putAttempts(0)
+        secureSettings.putBool(SETTING_SHOW, true)
+        secureSettings.putBool(SETTING_ACTION, false)
+
+        underTest.maybeShowDialog(context, completedRunnable)
+        dialog?.cancel()
+
+        assertThat(secureSettings.getBool(SETTING_ACTION, false)).isFalse()
+    }
+
+    @Test
+    fun dialogCancelPutsOneExtraAttempt() {
+        val attempts = 0
+        sharedPreferences.putAttempts(attempts)
+        secureSettings.putBool(SETTING_SHOW, true)
+        secureSettings.putBool(SETTING_ACTION, false)
+
+        underTest.maybeShowDialog(context, completedRunnable)
+        dialog?.cancel()
+
+        assertThat(sharedPreferences.getInt(PREFS_SETTINGS_DIALOG_ATTEMPTS, 0))
+            .isEqualTo(attempts + 1)
+    }
+
+    @Test
+    fun dialogCancelCallsOnComplete() {
+        sharedPreferences.putAttempts(0)
+        secureSettings.putBool(SETTING_SHOW, true)
+        secureSettings.putBool(SETTING_ACTION, false)
+
+        underTest.maybeShowDialog(context, completedRunnable)
+        dialog?.cancel()
+
+        verify(completedRunnable).invoke()
+    }
+
+    @Test
+    fun closeDialogDoesNotCallOnComplete() {
+        sharedPreferences.putAttempts(0)
+        secureSettings.putBool(SETTING_SHOW, true)
+        secureSettings.putBool(SETTING_ACTION, false)
+
+        underTest.maybeShowDialog(context, completedRunnable)
+        underTest.closeDialog()
+
+        verify(completedRunnable, never()).invoke()
+    }
+
+    @Test
+    fun dialogPositiveWithBothSettingsFalseTogglesBothSettings() {
+        sharedPreferences.putAttempts(0)
+        secureSettings.putBool(SETTING_SHOW, false)
+        secureSettings.putBool(SETTING_ACTION, false)
+
+        underTest.maybeShowDialog(context, completedRunnable)
+        clickButton(DialogInterface.BUTTON_POSITIVE)
+
+        assertThat(secureSettings.getBool(SETTING_SHOW)).isTrue()
+        assertThat(secureSettings.getBool(SETTING_ACTION)).isTrue()
+    }
+
+    private fun clickButton(which: Int) {
+        dialog?.clickButton(which)
+    }
+
+    private fun attachRepositoryToSettings() {
+        secureSettings.registerContentObserver(
+            SETTING_SHOW,
+            object : ContentObserver(null) {
+                override fun onChange(selfChange: Boolean) {
+                    controlsSettingsRepository.setCanShowControlsInLockscreen(
+                        secureSettings.getBool(SETTING_SHOW, false)
+                    )
+                }
+            }
+        )
+
+        secureSettings.registerContentObserver(
+            SETTING_ACTION,
+            object : ContentObserver(null) {
+                override fun onChange(selfChange: Boolean) {
+                    controlsSettingsRepository.setAllowActionOnTrivialControlsInLockscreen(
+                        secureSettings.getBool(SETTING_ACTION, false)
+                    )
+                }
+            }
+        )
+    }
+
+    private fun SharedPreferences.putAttempts(value: Int) {
+        edit().putInt(PREFS_SETTINGS_DIALOG_ATTEMPTS, value).commit()
+    }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/ControlsSettingsRepositoryImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/settings/ControlsSettingsRepositoryImplTest.kt
similarity index 98%
rename from packages/SystemUI/tests/src/com/android/systemui/controls/ControlsSettingsRepositoryImplTest.kt
rename to packages/SystemUI/tests/src/com/android/systemui/controls/settings/ControlsSettingsRepositoryImplTest.kt
index 4b88b44..b904ac1 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/controls/ControlsSettingsRepositoryImplTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/controls/settings/ControlsSettingsRepositoryImplTest.kt
@@ -15,7 +15,7 @@
  *
  */
 
-package com.android.systemui.controls
+package com.android.systemui.controls.settings
 
 import android.content.pm.UserInfo
 import android.provider.Settings
diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/FakeControlsSettingsRepository.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/settings/FakeControlsSettingsRepository.kt
similarity index 96%
rename from packages/SystemUI/tests/src/com/android/systemui/controls/FakeControlsSettingsRepository.kt
rename to packages/SystemUI/tests/src/com/android/systemui/controls/settings/FakeControlsSettingsRepository.kt
index 8a1bed2..b6628db 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/controls/FakeControlsSettingsRepository.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/controls/settings/FakeControlsSettingsRepository.kt
@@ -15,7 +15,7 @@
  *
  */
 
-package com.android.systemui.controls
+package com.android.systemui.controls.settings
 
 import kotlinx.coroutines.flow.MutableStateFlow
 import kotlinx.coroutines.flow.asStateFlow
diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/ui/ControlsUiControllerImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/ui/ControlsUiControllerImplTest.kt
index e679b13..d172c9a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/controls/ui/ControlsUiControllerImplTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/controls/ui/ControlsUiControllerImplTest.kt
@@ -16,18 +16,30 @@
 
 package com.android.systemui.controls.ui
 
+import android.app.PendingIntent
 import android.content.ComponentName
 import android.content.Context
+import android.content.pm.ApplicationInfo
+import android.content.pm.ServiceInfo
+import android.os.UserHandle
+import android.service.controls.ControlsProviderService
 import android.testing.AndroidTestingRunner
 import android.testing.TestableLooper
+import android.util.AttributeSet
+import android.view.LayoutInflater
+import android.view.View
 import android.widget.FrameLayout
 import androidx.test.filters.SmallTest
+import com.android.systemui.R
 import com.android.systemui.SysuiTestCase
 import com.android.systemui.controls.ControlsMetricsLogger
+import com.android.systemui.controls.ControlsServiceInfo
 import com.android.systemui.controls.CustomIconCache
 import com.android.systemui.controls.controller.ControlsController
 import com.android.systemui.controls.controller.StructureInfo
 import com.android.systemui.controls.management.ControlsListingController
+import com.android.systemui.controls.management.ControlsProviderSelectorActivity
+import com.android.systemui.controls.settings.FakeControlsSettingsRepository
 import com.android.systemui.dump.DumpManager
 import com.android.systemui.plugins.ActivityStarter
 import com.android.systemui.settings.UserFileManager
@@ -38,19 +50,27 @@
 import com.android.systemui.util.FakeSharedPreferences
 import com.android.systemui.util.concurrency.FakeExecutor
 import com.android.systemui.util.mockito.any
+import com.android.systemui.util.mockito.argumentCaptor
+import com.android.systemui.util.mockito.capture
+import com.android.systemui.util.mockito.eq
+import com.android.systemui.util.mockito.mock
+import com.android.systemui.util.mockito.whenever
 import com.android.systemui.util.time.FakeSystemClock
+import com.android.wm.shell.TaskView
 import com.android.wm.shell.TaskViewFactory
 import com.google.common.truth.Truth.assertThat
 import dagger.Lazy
 import java.util.Optional
+import java.util.function.Consumer
 import org.junit.Before
 import org.junit.Test
 import org.junit.runner.RunWith
 import org.mockito.Mock
 import org.mockito.Mockito.anyInt
 import org.mockito.Mockito.anyString
-import org.mockito.Mockito.mock
+import org.mockito.Mockito.clearInvocations
 import org.mockito.Mockito.never
+import org.mockito.Mockito.spy
 import org.mockito.Mockito.verify
 import org.mockito.Mockito.`when`
 import org.mockito.MockitoAnnotations
@@ -70,9 +90,9 @@
     @Mock lateinit var userFileManager: UserFileManager
     @Mock lateinit var userTracker: UserTracker
     @Mock lateinit var taskViewFactory: TaskViewFactory
-    @Mock lateinit var activityContext: Context
     @Mock lateinit var dumpManager: DumpManager
     val sharedPreferences = FakeSharedPreferences()
+    lateinit var controlsSettingsRepository: FakeControlsSettingsRepository
 
     var uiExecutor = FakeExecutor(FakeSystemClock())
     var bgExecutor = FakeExecutor(FakeSystemClock())
@@ -83,6 +103,17 @@
     fun setup() {
         MockitoAnnotations.initMocks(this)
 
+        controlsSettingsRepository = FakeControlsSettingsRepository()
+
+        // This way, it won't be cloned every time `LayoutInflater.fromContext` is called, but we
+        // need to clone it once so we don't modify the original one.
+        mContext.addMockSystemService(
+            Context.LAYOUT_INFLATER_SERVICE,
+            mContext.baseContext
+                .getSystemService(LayoutInflater::class.java)!!
+                .cloneInContext(mContext)
+        )
+
         parent = FrameLayout(mContext)
 
         underTest =
@@ -100,6 +131,7 @@
                 userFileManager,
                 userTracker,
                 Optional.of(taskViewFactory),
+                controlsSettingsRepository,
                 dumpManager
             )
         `when`(
@@ -113,11 +145,12 @@
         `when`(userFileManager.getSharedPreferences(anyString(), anyInt(), anyInt()))
             .thenReturn(sharedPreferences)
         `when`(userTracker.userId).thenReturn(0)
+        `when`(userTracker.userHandle).thenReturn(UserHandle.of(0))
     }
 
     @Test
     fun testGetPreferredStructure() {
-        val structureInfo = mock(StructureInfo::class.java)
+        val structureInfo = mock<StructureInfo>()
         underTest.getPreferredSelectedItem(listOf(structureInfo))
         verify(userFileManager)
             .getSharedPreferences(
@@ -189,14 +222,234 @@
     @Test
     fun testPanelDoesNotRefreshControls() {
         val panel = SelectedItem.PanelItem("App name", ComponentName("pkg", "cls"))
+        setUpPanel(panel)
+
+        underTest.show(parent, {}, context)
+        verify(controlsController, never()).refreshStatus(any(), any())
+    }
+
+    @Test
+    fun testPanelCallsTaskViewFactoryCreate() {
+        mockLayoutInflater()
+        val panel = SelectedItem.PanelItem("App name", ComponentName("pkg", "cls"))
+        val serviceInfo = setUpPanel(panel)
+
+        underTest.show(parent, {}, context)
+
+        val captor = argumentCaptor<ControlsListingController.ControlsListingCallback>()
+
+        verify(controlsListingController).addCallback(capture(captor))
+
+        captor.value.onServicesUpdated(listOf(serviceInfo))
+        FakeExecutor.exhaustExecutors(uiExecutor, bgExecutor)
+
+        verify(taskViewFactory).create(eq(context), eq(uiExecutor), any())
+    }
+
+    @Test
+    fun testPanelControllerStartActivityWithCorrectArguments() {
+        mockLayoutInflater()
+        controlsSettingsRepository.setAllowActionOnTrivialControlsInLockscreen(true)
+
+        val panel = SelectedItem.PanelItem("App name", ComponentName("pkg", "cls"))
+        val serviceInfo = setUpPanel(panel)
+
+        underTest.show(parent, {}, context)
+
+        val captor = argumentCaptor<ControlsListingController.ControlsListingCallback>()
+
+        verify(controlsListingController).addCallback(capture(captor))
+
+        captor.value.onServicesUpdated(listOf(serviceInfo))
+        FakeExecutor.exhaustExecutors(uiExecutor, bgExecutor)
+
+        val pendingIntent = verifyPanelCreatedAndStartTaskView()
+
+        with(pendingIntent) {
+            assertThat(isActivity).isTrue()
+            assertThat(intent.component).isEqualTo(serviceInfo.panelActivity)
+            assertThat(
+                    intent.getBooleanExtra(
+                        ControlsProviderService.EXTRA_LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS,
+                        false
+                    )
+                )
+                .isTrue()
+        }
+    }
+
+    @Test
+    fun testPendingIntentExtrasAreModified() {
+        mockLayoutInflater()
+        controlsSettingsRepository.setAllowActionOnTrivialControlsInLockscreen(true)
+
+        val panel = SelectedItem.PanelItem("App name", ComponentName("pkg", "cls"))
+        val serviceInfo = setUpPanel(panel)
+
+        underTest.show(parent, {}, context)
+
+        val captor = argumentCaptor<ControlsListingController.ControlsListingCallback>()
+
+        verify(controlsListingController).addCallback(capture(captor))
+
+        captor.value.onServicesUpdated(listOf(serviceInfo))
+        FakeExecutor.exhaustExecutors(uiExecutor, bgExecutor)
+
+        val pendingIntent = verifyPanelCreatedAndStartTaskView()
+        assertThat(
+                pendingIntent.intent.getBooleanExtra(
+                    ControlsProviderService.EXTRA_LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS,
+                    false
+                )
+            )
+            .isTrue()
+
+        underTest.hide()
+
+        clearInvocations(controlsListingController, taskViewFactory)
+        controlsSettingsRepository.setAllowActionOnTrivialControlsInLockscreen(false)
+        underTest.show(parent, {}, context)
+
+        verify(controlsListingController).addCallback(capture(captor))
+        captor.value.onServicesUpdated(listOf(serviceInfo))
+        FakeExecutor.exhaustExecutors(uiExecutor, bgExecutor)
+
+        val newPendingIntent = verifyPanelCreatedAndStartTaskView()
+        assertThat(
+                newPendingIntent.intent.getBooleanExtra(
+                    ControlsProviderService.EXTRA_LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS,
+                    false
+                )
+            )
+            .isFalse()
+    }
+
+    @Test
+    fun testResolveActivityWhileSeeding_ControlsActivity() {
+        whenever(controlsController.addSeedingFavoritesCallback(any())).thenReturn(true)
+        assertThat(underTest.resolveActivity()).isEqualTo(ControlsActivity::class.java)
+    }
+
+    @Test
+    fun testResolveActivityNotSeedingNoFavoritesNoPanels_ControlsProviderSelectorActivity() {
+        whenever(controlsController.addSeedingFavoritesCallback(any())).thenReturn(false)
+        whenever(controlsController.getFavorites()).thenReturn(emptyList())
+
+        val selectedItems =
+            listOf(
+                SelectedItem.StructureItem(
+                    StructureInfo(ComponentName.unflattenFromString("pkg/.cls1"), "a", ArrayList())
+                ),
+            )
+        sharedPreferences
+            .edit()
+            .putString("controls_component", selectedItems[0].componentName.flattenToString())
+            .putString("controls_structure", selectedItems[0].name.toString())
+            .commit()
+
+        assertThat(underTest.resolveActivity())
+            .isEqualTo(ControlsProviderSelectorActivity::class.java)
+    }
+
+    @Test
+    fun testResolveActivityNotSeedingNoDefaultNoFavoritesPanel_ControlsActivity() {
+        val panel = SelectedItem.PanelItem("App name", ComponentName("pkg", "cls"))
+        val activity = ComponentName("pkg", "activity")
+        val csi = ControlsServiceInfo(panel.componentName, panel.appName, activity)
+        whenever(controlsController.addSeedingFavoritesCallback(any())).thenReturn(true)
+        whenever(controlsController.getFavorites()).thenReturn(emptyList())
+        whenever(controlsListingController.getCurrentServices()).thenReturn(listOf(csi))
+
+        assertThat(underTest.resolveActivity()).isEqualTo(ControlsActivity::class.java)
+    }
+
+    private fun setUpPanel(panel: SelectedItem.PanelItem): ControlsServiceInfo {
+        val activity = ComponentName("pkg", "activity")
         sharedPreferences
             .edit()
             .putString("controls_component", panel.componentName.flattenToString())
             .putString("controls_structure", panel.appName.toString())
             .putBoolean("controls_is_panel", true)
             .commit()
+        return ControlsServiceInfo(panel.componentName, panel.appName, activity)
+    }
 
-        underTest.show(parent, {}, activityContext)
-        verify(controlsController, never()).refreshStatus(any(), any())
+    private fun verifyPanelCreatedAndStartTaskView(): PendingIntent {
+        val taskViewConsumerCaptor = argumentCaptor<Consumer<TaskView>>()
+        verify(taskViewFactory).create(eq(context), eq(uiExecutor), capture(taskViewConsumerCaptor))
+
+        val taskView: TaskView = mock {
+            `when`(this.post(any())).thenAnswer {
+                uiExecutor.execute(it.arguments[0] as Runnable)
+                true
+            }
+        }
+        // calls PanelTaskViewController#launchTaskView
+        taskViewConsumerCaptor.value.accept(taskView)
+        val listenerCaptor = argumentCaptor<TaskView.Listener>()
+        verify(taskView).setListener(any(), capture(listenerCaptor))
+        listenerCaptor.value.onInitialized()
+        FakeExecutor.exhaustExecutors(uiExecutor, bgExecutor)
+
+        val pendingIntentCaptor = argumentCaptor<PendingIntent>()
+        verify(taskView).startActivity(capture(pendingIntentCaptor), any(), any(), any())
+        return pendingIntentCaptor.value
+    }
+
+    private fun ControlsServiceInfo(
+        componentName: ComponentName,
+        label: CharSequence,
+        panelComponentName: ComponentName? = null
+    ): ControlsServiceInfo {
+        val serviceInfo =
+            ServiceInfo().apply {
+                applicationInfo = ApplicationInfo()
+                packageName = componentName.packageName
+                name = componentName.className
+            }
+        return spy(ControlsServiceInfo(mContext, serviceInfo)).apply {
+            `when`(loadLabel()).thenReturn(label)
+            `when`(loadIcon()).thenReturn(mock())
+            `when`(panelActivity).thenReturn(panelComponentName)
+        }
+    }
+
+    private fun mockLayoutInflater() {
+        LayoutInflater.from(context)
+            .setPrivateFactory(
+                object : LayoutInflater.Factory2 {
+                    override fun onCreateView(
+                        view: View?,
+                        name: String,
+                        context: Context,
+                        attrs: AttributeSet
+                    ): View? {
+                        return onCreateView(name, context, attrs)
+                    }
+
+                    override fun onCreateView(
+                        name: String,
+                        context: Context,
+                        attrs: AttributeSet
+                    ): View? {
+                        if (FrameLayout::class.java.simpleName.equals(name)) {
+                            val mock: FrameLayout = mock {
+                                `when`(this.context).thenReturn(context)
+                                `when`(this.id).thenReturn(R.id.controls_panel)
+                                `when`(this.requireViewById<View>(any())).thenCallRealMethod()
+                                `when`(this.findViewById<View>(R.id.controls_panel))
+                                    .thenReturn(this)
+                                `when`(this.post(any())).thenAnswer {
+                                    uiExecutor.execute(it.arguments[0] as Runnable)
+                                    true
+                                }
+                            }
+                            return mock
+                        } else {
+                            return null
+                        }
+                    }
+                }
+            )
     }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/ui/PanelTaskViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/ui/PanelTaskViewControllerTest.kt
index 5cd2ace..de04ef8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/controls/ui/PanelTaskViewControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/controls/ui/PanelTaskViewControllerTest.kt
@@ -75,6 +75,7 @@
             uiExecutor.execute(it.arguments[0] as Runnable)
             true
         }
+        whenever(activityContext.resources).thenReturn(context.resources)
 
         uiExecutor = FakeExecutor(FakeSystemClock())
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java
index 82432ce..b66a454 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java
@@ -357,6 +357,44 @@
         verify(mDozeLog).tracePulseDropped(anyString(), eq(null));
     }
 
+    @Test
+    public void udfpsLongPress_triggeredWhenAodPaused() {
+        // GIVEN device is DOZE_AOD_PAUSED
+        when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE_AOD_PAUSED);
+
+        // WHEN udfps long-press is triggered
+        mTriggers.onSensor(DozeLog.REASON_SENSOR_UDFPS_LONG_PRESS, 100, 100,
+                new float[]{0, 1, 2, 3, 4});
+
+        // THEN the pulse is NOT dropped
+        verify(mDozeLog, never()).tracePulseDropped(anyString(), any());
+
+        // WHEN the screen state is ON
+        mTriggers.onScreenState(Display.STATE_ON);
+
+        // THEN aod interrupt is sent
+        verify(mAuthController).onAodInterrupt(anyInt(), anyInt(), anyFloat(), anyFloat());
+    }
+
+    @Test
+    public void udfpsLongPress_triggeredWhenAodPausing() {
+        // GIVEN device is DOZE_AOD_PAUSED
+        when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE_AOD_PAUSING);
+
+        // WHEN udfps long-press is triggered
+        mTriggers.onSensor(DozeLog.REASON_SENSOR_UDFPS_LONG_PRESS, 100, 100,
+                new float[]{0, 1, 2, 3, 4});
+
+        // THEN the pulse is NOT dropped
+        verify(mDozeLog, never()).tracePulseDropped(anyString(), any());
+
+        // WHEN the screen state is ON
+        mTriggers.onScreenState(Display.STATE_ON);
+
+        // THEN aod interrupt is sent
+        verify(mAuthController).onAodInterrupt(anyInt(), anyInt(), anyFloat(), anyFloat());
+    }
+
     private void waitForSensorManager() {
         mExecutor.runAllReady();
     }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayServiceTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayServiceTest.java
index ffb8342..430575c 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayServiceTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayServiceTest.java
@@ -38,15 +38,18 @@
 import android.view.WindowManagerImpl;
 
 import androidx.lifecycle.Lifecycle;
-import androidx.lifecycle.LifecycleOwner;
 import androidx.lifecycle.LifecycleRegistry;
 import androidx.test.filters.SmallTest;
 
 import com.android.internal.logging.UiEventLogger;
 import com.android.keyguard.KeyguardUpdateMonitor;
 import com.android.systemui.SysuiTestCase;
+import com.android.systemui.dreams.complication.ComplicationLayoutEngine;
+import com.android.systemui.dreams.complication.dagger.ComplicationComponent;
 import com.android.systemui.dreams.dagger.DreamOverlayComponent;
+import com.android.systemui.dreams.dreamcomplication.HideComplicationTouchHandler;
 import com.android.systemui.dreams.touch.DreamOverlayTouchMonitor;
+import com.android.systemui.touch.TouchInsetManager;
 import com.android.systemui.util.concurrency.FakeExecutor;
 import com.android.systemui.util.time.FakeSystemClock;
 import com.android.systemui.utils.leaks.LeakCheckedTest;
@@ -70,7 +73,7 @@
     private final FakeExecutor mMainExecutor = new FakeExecutor(mFakeSystemClock);
 
     @Mock
-    LifecycleOwner mLifecycleOwner;
+    DreamOverlayLifecycleOwner mLifecycleOwner;
 
     @Mock
     LifecycleRegistry mLifecycleRegistry;
@@ -87,6 +90,26 @@
     WindowManagerImpl mWindowManager;
 
     @Mock
+    ComplicationComponent.Factory mComplicationComponentFactory;
+
+    @Mock
+    ComplicationComponent mComplicationComponent;
+
+    @Mock
+    ComplicationLayoutEngine mComplicationVisibilityController;
+
+    @Mock
+    com.android.systemui.dreams.dreamcomplication.dagger.ComplicationComponent.Factory
+            mDreamComplicationComponentFactory;
+
+    @Mock
+    com.android.systemui.dreams.dreamcomplication.dagger.ComplicationComponent
+            mDreamComplicationComponent;
+
+    @Mock
+    HideComplicationTouchHandler mHideComplicationTouchHandler;
+
+    @Mock
     DreamOverlayComponent.Factory mDreamOverlayComponentFactory;
 
     @Mock
@@ -111,6 +134,9 @@
     ViewGroup mDreamOverlayContainerViewParent;
 
     @Mock
+    TouchInsetManager mTouchInsetManager;
+
+    @Mock
     UiEventLogger mUiEventLogger;
 
     @Captor
@@ -124,23 +150,38 @@
 
         when(mDreamOverlayComponent.getDreamOverlayContainerViewController())
                 .thenReturn(mDreamOverlayContainerViewController);
-        when(mDreamOverlayComponent.getLifecycleOwner())
-                .thenReturn(mLifecycleOwner);
-        when(mDreamOverlayComponent.getLifecycleRegistry())
+        when(mLifecycleOwner.getRegistry())
                 .thenReturn(mLifecycleRegistry);
         when(mDreamOverlayComponent.getDreamOverlayTouchMonitor())
                 .thenReturn(mDreamOverlayTouchMonitor);
-        when(mDreamOverlayComponentFactory
+        when(mComplicationComponentFactory
+                .create(any(), any(), any(), any()))
+                .thenReturn(mComplicationComponent);
+        when(mComplicationComponent.getVisibilityController())
+                .thenReturn(mComplicationVisibilityController);
+        when(mDreamComplicationComponent.getHideComplicationTouchHandler())
+                .thenReturn(mHideComplicationTouchHandler);
+        when(mDreamComplicationComponentFactory
                 .create(any(), any()))
+                .thenReturn(mDreamComplicationComponent);
+        when(mDreamOverlayComponentFactory
+                .create(any(), any(), any(), any()))
                 .thenReturn(mDreamOverlayComponent);
         when(mDreamOverlayContainerViewController.getContainerView())
                 .thenReturn(mDreamOverlayContainerView);
 
-        mService = new DreamOverlayService(mContext, mMainExecutor, mWindowManager,
+        mService = new DreamOverlayService(
+                mContext,
+                mMainExecutor,
+                mLifecycleOwner,
+                mWindowManager,
+                mComplicationComponentFactory,
+                mDreamComplicationComponentFactory,
                 mDreamOverlayComponentFactory,
                 mStateController,
                 mKeyguardUpdateMonitor,
                 mUiEventLogger,
+                mTouchInsetManager,
                 LOW_LIGHT_COMPONENT);
     }
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java
index c21c7a2..ee989d1 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java
@@ -63,7 +63,7 @@
     @Test
     public void testStateChange_overlayActive() {
         final DreamOverlayStateController stateController = new DreamOverlayStateController(
-                mExecutor);
+                mExecutor, true);
         stateController.addCallback(mCallback);
         stateController.setOverlayActive(true);
         mExecutor.runAllReady();
@@ -85,7 +85,7 @@
     @Test
     public void testCallback() {
         final DreamOverlayStateController stateController = new DreamOverlayStateController(
-                mExecutor);
+                mExecutor, true);
         stateController.addCallback(mCallback);
 
         // Add complication and verify callback is notified.
@@ -111,7 +111,7 @@
     @Test
     public void testNotifyOnCallbackAdd() {
         final DreamOverlayStateController stateController =
-                new DreamOverlayStateController(mExecutor);
+                new DreamOverlayStateController(mExecutor, true);
 
         stateController.addComplication(mComplication);
         mExecutor.runAllReady();
@@ -123,9 +123,24 @@
     }
 
     @Test
+    public void testNotifyOnCallbackAddOverlayDisabled() {
+        final DreamOverlayStateController stateController =
+                new DreamOverlayStateController(mExecutor, false);
+
+        stateController.addComplication(mComplication);
+        mExecutor.runAllReady();
+
+        // Verify callback occurs on add when an overlay is already present.
+        stateController.addCallback(mCallback);
+        mExecutor.runAllReady();
+        verify(mCallback, never()).onComplicationsChanged();
+    }
+
+
+    @Test
     public void testComplicationFilteringWhenShouldShowComplications() {
         final DreamOverlayStateController stateController =
-                new DreamOverlayStateController(mExecutor);
+                new DreamOverlayStateController(mExecutor, true);
         stateController.setShouldShowComplications(true);
 
         final Complication alwaysAvailableComplication = Mockito.mock(Complication.class);
@@ -165,7 +180,7 @@
     @Test
     public void testComplicationFilteringWhenShouldHideComplications() {
         final DreamOverlayStateController stateController =
-                new DreamOverlayStateController(mExecutor);
+                new DreamOverlayStateController(mExecutor, true);
         stateController.setShouldShowComplications(true);
 
         final Complication alwaysAvailableComplication = Mockito.mock(Complication.class);
@@ -212,7 +227,7 @@
     public void testComplicationWithNoTypeNotFiltered() {
         final Complication complication = Mockito.mock(Complication.class);
         final DreamOverlayStateController stateController =
-                new DreamOverlayStateController(mExecutor);
+                new DreamOverlayStateController(mExecutor, true);
         stateController.addComplication(complication);
         mExecutor.runAllReady();
         assertThat(stateController.getComplications(true).contains(complication))
@@ -222,7 +237,7 @@
     @Test
     public void testNotifyLowLightChanged() {
         final DreamOverlayStateController stateController =
-                new DreamOverlayStateController(mExecutor);
+                new DreamOverlayStateController(mExecutor, true);
 
         stateController.addCallback(mCallback);
         mExecutor.runAllReady();
@@ -238,7 +253,7 @@
     @Test
     public void testNotifyEntryAnimationsFinishedChanged() {
         final DreamOverlayStateController stateController =
-                new DreamOverlayStateController(mExecutor);
+                new DreamOverlayStateController(mExecutor, true);
 
         stateController.addCallback(mCallback);
         mExecutor.runAllReady();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/ComplicationHostViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/ComplicationHostViewControllerTest.java
index b477592..dcd8736 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/ComplicationHostViewControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/ComplicationHostViewControllerTest.java
@@ -15,6 +15,8 @@
  */
 package com.android.systemui.dreams.complication;
 
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
@@ -139,6 +141,21 @@
     }
 
     @Test
+    public void testMalformedComplicationAddition() {
+        final Observer<Collection<ComplicationViewModel>> observer =
+                captureComplicationViewModelsObserver();
+
+        // Add a complication and ensure it is added to the view.
+        final HashSet<ComplicationViewModel> complications = new HashSet<>(
+                Collections.singletonList(mComplicationViewModel));
+        when(mViewHolder.getView()).thenReturn(null);
+        observer.onChanged(complications);
+
+        verify(mLayoutEngine, never()).addComplication(any(), any(), any(), anyInt());
+
+    }
+
+    @Test
     public void testNewComplicationsBeforeEntryAnimationsFinishSetToInvisible() {
         final Observer<Collection<ComplicationViewModel>> observer =
                 captureComplicationViewModelsObserver();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/DreamHomeControlsComplicationTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/DreamHomeControlsComplicationTest.java
index e6d3a69..89c7280 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/DreamHomeControlsComplicationTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/DreamHomeControlsComplicationTest.java
@@ -27,6 +27,7 @@
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import android.content.ComponentName;
 import android.content.Context;
 import android.testing.AndroidTestingRunner;
 import android.view.View;
@@ -54,6 +55,7 @@
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
 
@@ -147,6 +149,19 @@
     }
 
     @Test
+    public void complicationAvailability_serviceAvailable_noFavorites_panel_addComplication() {
+        final DreamHomeControlsComplication.Registrant registrant =
+                new DreamHomeControlsComplication.Registrant(mComplication,
+                        mDreamOverlayStateController, mControlsComponent);
+        registrant.start();
+
+        setHaveFavorites(false);
+        setServiceWithPanel();
+
+        verify(mDreamOverlayStateController).addComplication(mComplication);
+    }
+
+    @Test
     public void complicationAvailability_serviceNotAvailable_haveFavorites_doNotAddComplication() {
         final DreamHomeControlsComplication.Registrant registrant =
                 new DreamHomeControlsComplication.Registrant(mComplication,
@@ -232,6 +247,15 @@
         triggerControlsListingCallback(serviceInfos);
     }
 
+    private void setServiceWithPanel() {
+        final List<ControlsServiceInfo> serviceInfos = new ArrayList<>();
+        ControlsServiceInfo csi = mock(ControlsServiceInfo.class);
+        serviceInfos.add(csi);
+        when(csi.getPanelActivity()).thenReturn(new ComponentName("a", "b"));
+        when(mControlsListingController.getCurrentServices()).thenReturn(serviceInfos);
+        triggerControlsListingCallback(serviceInfos);
+    }
+
     private void setDreamOverlayActive(boolean value) {
         when(mDreamOverlayStateController.isOverlayActive()).thenReturn(value);
         verify(mDreamOverlayStateController).addCallback(mStateCallbackCaptor.capture());
diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/touch/HideComplicationTouchHandlerTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/dreamcomplication/HideComplicationTouchHandlerTest.java
similarity index 98%
rename from packages/SystemUI/tests/src/com/android/systemui/dreams/touch/HideComplicationTouchHandlerTest.java
rename to packages/SystemUI/tests/src/com/android/systemui/dreams/dreamcomplication/HideComplicationTouchHandlerTest.java
index 4e3aca7..d68f032 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/dreams/touch/HideComplicationTouchHandlerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/dreamcomplication/HideComplicationTouchHandlerTest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.systemui.dreams.touch;
+package com.android.systemui.dreams.dreamcomplication;
 
 import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.ArgumentMatchers.eq;
@@ -33,6 +33,7 @@
 import com.android.systemui.SysuiTestCase;
 import com.android.systemui.dreams.DreamOverlayStateController;
 import com.android.systemui.dreams.complication.Complication;
+import com.android.systemui.dreams.touch.DreamTouchHandler;
 import com.android.systemui.shared.system.InputChannelCompat;
 import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
 import com.android.systemui.touch.TouchInsetManager;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/flags/FeatureFlagsDebugRestarterTest.kt b/packages/SystemUI/tests/src/com/android/systemui/flags/FeatureFlagsDebugRestarterTest.kt
index 1e7b1f2..ed16721 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/flags/FeatureFlagsDebugRestarterTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/flags/FeatureFlagsDebugRestarterTest.kt
@@ -48,22 +48,22 @@
     @Test
     fun testRestart_ImmediateWhenAsleep() {
         whenever(wakefulnessLifecycle.wakefulness).thenReturn(WAKEFULNESS_ASLEEP)
-        restarter.restart()
-        verify(systemExitRestarter).restart()
+        restarter.restartSystemUI()
+        verify(systemExitRestarter).restartSystemUI()
     }
 
     @Test
     fun testRestart_WaitsForSceenOff() {
         whenever(wakefulnessLifecycle.wakefulness).thenReturn(WAKEFULNESS_AWAKE)
 
-        restarter.restart()
-        verify(systemExitRestarter, never()).restart()
+        restarter.restartSystemUI()
+        verify(systemExitRestarter, never()).restartSystemUI()
 
         val captor = ArgumentCaptor.forClass(WakefulnessLifecycle.Observer::class.java)
         verify(wakefulnessLifecycle).addObserver(captor.capture())
 
         captor.value.onFinishedGoingToSleep()
 
-        verify(systemExitRestarter).restart()
+        verify(systemExitRestarter).restartSystemUI()
     }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/flags/FeatureFlagsReleaseRestarterTest.kt b/packages/SystemUI/tests/src/com/android/systemui/flags/FeatureFlagsReleaseRestarterTest.kt
index 68ca48d..7d807e2 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/flags/FeatureFlagsReleaseRestarterTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/flags/FeatureFlagsReleaseRestarterTest.kt
@@ -63,7 +63,7 @@
         whenever(batteryController.isPluggedIn).thenReturn(true)
 
         assertThat(executor.numPending()).isEqualTo(0)
-        restarter.restart()
+        restarter.restartSystemUI()
         assertThat(executor.numPending()).isEqualTo(1)
     }
 
@@ -72,11 +72,11 @@
         whenever(wakefulnessLifecycle.wakefulness).thenReturn(WAKEFULNESS_ASLEEP)
         whenever(batteryController.isPluggedIn).thenReturn(true)
 
-        restarter.restart()
-        verify(systemExitRestarter, never()).restart()
+        restarter.restartSystemUI()
+        verify(systemExitRestarter, never()).restartSystemUI()
         executor.advanceClockToLast()
         executor.runAllReady()
-        verify(systemExitRestarter).restart()
+        verify(systemExitRestarter).restartSystemUI()
     }
 
     @Test
@@ -85,7 +85,7 @@
         whenever(batteryController.isPluggedIn).thenReturn(true)
 
         assertThat(executor.numPending()).isEqualTo(0)
-        restarter.restart()
+        restarter.restartSystemUI()
         assertThat(executor.numPending()).isEqualTo(0)
     }
 
@@ -95,7 +95,7 @@
         whenever(batteryController.isPluggedIn).thenReturn(false)
 
         assertThat(executor.numPending()).isEqualTo(0)
-        restarter.restart()
+        restarter.restartSystemUI()
         assertThat(executor.numPending()).isEqualTo(0)
     }
 
@@ -105,8 +105,8 @@
         whenever(batteryController.isPluggedIn).thenReturn(true)
 
         assertThat(executor.numPending()).isEqualTo(0)
-        restarter.restart()
-        restarter.restart()
+        restarter.restartSystemUI()
+        restarter.restartSystemUI()
         assertThat(executor.numPending()).isEqualTo(1)
     }
 
@@ -115,7 +115,7 @@
         whenever(wakefulnessLifecycle.wakefulness).thenReturn(WAKEFULNESS_AWAKE)
         whenever(batteryController.isPluggedIn).thenReturn(true)
         assertThat(executor.numPending()).isEqualTo(0)
-        restarter.restart()
+        restarter.restartSystemUI()
 
         val captor = ArgumentCaptor.forClass(WakefulnessLifecycle.Observer::class.java)
         verify(wakefulnessLifecycle).addObserver(captor.capture())
@@ -131,7 +131,7 @@
         whenever(wakefulnessLifecycle.wakefulness).thenReturn(WAKEFULNESS_ASLEEP)
         whenever(batteryController.isPluggedIn).thenReturn(false)
         assertThat(executor.numPending()).isEqualTo(0)
-        restarter.restart()
+        restarter.restartSystemUI()
 
         val captor =
             ArgumentCaptor.forClass(BatteryController.BatteryStateChangeCallback::class.java)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogLiteTest.java b/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogLiteTest.java
index d52616b..c8a352d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogLiteTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogLiteTest.java
@@ -16,11 +16,12 @@
 
 package com.android.systemui.globalactions;
 
+import static android.content.pm.UserInfo.FLAG_ADMIN;
+
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.spy;
@@ -32,11 +33,13 @@
 import android.app.admin.DevicePolicyManager;
 import android.app.trust.TrustManager;
 import android.content.pm.PackageManager;
+import android.content.pm.UserInfo;
 import android.content.res.Resources;
 import android.graphics.Color;
 import android.media.AudioManager;
 import android.os.Handler;
 import android.os.UserManager;
+import android.provider.Settings;
 import android.service.dreams.IDreamManager;
 import android.testing.AndroidTestingRunner;
 import android.testing.TestableLooper;
@@ -552,10 +555,32 @@
 
     @Test
     public void testBugreportAction_whenDebugMode_shouldOfferBugreportButtonBeforeProvisioning() {
-        doReturn(1).when(mGlobalSettings).getInt(anyString(), anyInt());
+        UserInfo currentUser = mockCurrentUser(FLAG_ADMIN);
+
+        when(mGlobalActionsDialogLite.getCurrentUser()).thenReturn(currentUser);
+        doReturn(1).when(mGlobalSettings)
+                .getIntForUser(Settings.Global.BUGREPORT_IN_POWER_MENU, 0, currentUser.id);
 
         GlobalActionsDialogLite.BugReportAction bugReportAction =
                 mGlobalActionsDialogLite.makeBugReportActionForTesting();
         assertThat(bugReportAction.showBeforeProvisioning()).isTrue();
     }
+
+    @Test
+    public void testBugreportAction_whenUserIsNotAdmin_noBugReportActionBeforeProvisioning() {
+        UserInfo currentUser = mockCurrentUser(0);
+
+        when(mGlobalActionsDialogLite.getCurrentUser()).thenReturn(currentUser);
+        doReturn(1).when(mGlobalSettings)
+                .getIntForUser(Settings.Global.BUGREPORT_IN_POWER_MENU, 0, currentUser.id);
+
+        GlobalActionsDialogLite.BugReportAction bugReportAction =
+                mGlobalActionsDialogLite.makeBugReportActionForTesting();
+        assertThat(bugReportAction.showBeforeProvisioning()).isFalse();
+    }
+
+    private UserInfo mockCurrentUser(int flags) {
+        return new UserInfo(10, "A User", flags);
+
+    }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java
index 798839d..804960d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java
@@ -168,6 +168,45 @@
     }
 
     @Test
+    @TestableLooper.RunWithLooper(setAsMainLooper = true)
+    public void testOnStartedWakingUp_whileSleeping_ifWakeAndUnlocking_doesNotShowKeyguard() {
+        when(mLockPatternUtils.isLockScreenDisabled(anyInt())).thenReturn(false);
+        when(mLockPatternUtils.getPowerButtonInstantlyLocks(anyInt())).thenReturn(true);
+        mViewMediator.onSystemReady();
+        TestableLooper.get(this).processAllMessages();
+
+        mViewMediator.setShowingLocked(false);
+        TestableLooper.get(this).processAllMessages();
+
+        mViewMediator.onStartedGoingToSleep(OFF_BECAUSE_OF_USER);
+        mViewMediator.onWakeAndUnlocking();
+        mViewMediator.onStartedWakingUp(OFF_BECAUSE_OF_USER, false);
+        TestableLooper.get(this).processAllMessages();
+
+        assertFalse(mViewMediator.isShowingAndNotOccluded());
+        verify(mKeyguardStateController, never()).notifyKeyguardState(eq(true), anyBoolean());
+    }
+
+    @Test
+    @TestableLooper.RunWithLooper(setAsMainLooper = true)
+    public void testOnStartedWakingUp_whileSleeping_ifNotWakeAndUnlocking_showsKeyguard() {
+        when(mLockPatternUtils.isLockScreenDisabled(anyInt())).thenReturn(false);
+        when(mLockPatternUtils.getPowerButtonInstantlyLocks(anyInt())).thenReturn(true);
+        mViewMediator.onSystemReady();
+        TestableLooper.get(this).processAllMessages();
+
+        mViewMediator.setShowingLocked(false);
+        TestableLooper.get(this).processAllMessages();
+
+        mViewMediator.onStartedGoingToSleep(OFF_BECAUSE_OF_USER);
+        mViewMediator.onStartedWakingUp(OFF_BECAUSE_OF_USER, false);
+
+        TestableLooper.get(this).processAllMessages();
+
+        assertTrue(mViewMediator.isShowingAndNotOccluded());
+    }
+
+    @Test
     public void testRegisterDumpable() {
         verify(mDumpManager).registerDumpable(KeyguardViewMediator.class.getName(), mViewMediator);
         verify(mStatusBarKeyguardViewManager, never()).setKeyguardGoingAwayState(anyBoolean());
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/HomeControlsKeyguardQuickAffordanceConfigParameterizedStateTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/HomeControlsKeyguardQuickAffordanceConfigParameterizedStateTest.kt
index 322014a..f8cb408 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/HomeControlsKeyguardQuickAffordanceConfigParameterizedStateTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/HomeControlsKeyguardQuickAffordanceConfigParameterizedStateTest.kt
@@ -20,13 +20,14 @@
 import androidx.test.filters.SmallTest
 import com.android.systemui.R
 import com.android.systemui.SysuiTestCase
+import com.android.systemui.controls.ControlsServiceInfo
 import com.android.systemui.controls.controller.ControlsController
 import com.android.systemui.controls.dagger.ControlsComponent
 import com.android.systemui.controls.management.ControlsListingController
 import com.android.systemui.util.mockito.mock
 import com.android.systemui.util.mockito.whenever
 import com.google.common.truth.Truth.assertThat
-import java.util.*
+import java.util.Optional
 import kotlinx.coroutines.flow.MutableStateFlow
 import kotlinx.coroutines.flow.launchIn
 import kotlinx.coroutines.flow.onEach
@@ -50,20 +51,22 @@
     companion object {
         @Parameters(
             name =
-                "feature enabled = {0}, has favorites = {1}, has service infos = {2}, can show" +
-                    " while locked = {3}, visibility is AVAILABLE {4} - expected visible = {5}"
+                "feature enabled = {0}, has favorites = {1}, has panels = {2}, " +
+                    "has service infos = {3}, can show while locked = {4}, " +
+                    "visibility is AVAILABLE {5} - expected visible = {6}"
         )
         @JvmStatic
         fun data() =
-            (0 until 32)
+            (0 until 64)
                 .map { combination ->
                     arrayOf(
-                        /* isFeatureEnabled= */ combination and 0b10000 != 0,
-                        /* hasFavorites= */ combination and 0b01000 != 0,
-                        /* hasServiceInfos= */ combination and 0b00100 != 0,
-                        /* canShowWhileLocked= */ combination and 0b00010 != 0,
-                        /* visibilityAvailable= */ combination and 0b00001 != 0,
-                        /* isVisible= */ combination == 0b11111,
+                        /* isFeatureEnabled= */ combination and 0b100000 != 0,
+                        /* hasFavorites = */ combination and 0b010000 != 0,
+                        /* hasPanels = */ combination and 0b001000 != 0,
+                        /* hasServiceInfos= */ combination and 0b000100 != 0,
+                        /* canShowWhileLocked= */ combination and 0b000010 != 0,
+                        /* visibilityAvailable= */ combination and 0b000001 != 0,
+                        /* isVisible= */ combination in setOf(0b111111, 0b110111, 0b101111),
                     )
                 }
                 .toList()
@@ -72,6 +75,7 @@
     @Mock private lateinit var component: ControlsComponent
     @Mock private lateinit var controlsController: ControlsController
     @Mock private lateinit var controlsListingController: ControlsListingController
+    @Mock private lateinit var controlsServiceInfo: ControlsServiceInfo
     @Captor
     private lateinit var callbackCaptor:
         ArgumentCaptor<ControlsListingController.ControlsListingCallback>
@@ -80,10 +84,11 @@
 
     @JvmField @Parameter(0) var isFeatureEnabled: Boolean = false
     @JvmField @Parameter(1) var hasFavorites: Boolean = false
-    @JvmField @Parameter(2) var hasServiceInfos: Boolean = false
-    @JvmField @Parameter(3) var canShowWhileLocked: Boolean = false
-    @JvmField @Parameter(4) var isVisibilityAvailable: Boolean = false
-    @JvmField @Parameter(5) var isVisibleExpected: Boolean = false
+    @JvmField @Parameter(2) var hasPanels: Boolean = false
+    @JvmField @Parameter(3) var hasServiceInfos: Boolean = false
+    @JvmField @Parameter(4) var canShowWhileLocked: Boolean = false
+    @JvmField @Parameter(5) var isVisibilityAvailable: Boolean = false
+    @JvmField @Parameter(6) var isVisibleExpected: Boolean = false
 
     @Before
     fun setUp() {
@@ -93,10 +98,13 @@
         whenever(component.getControlsController()).thenReturn(Optional.of(controlsController))
         whenever(component.getControlsListingController())
             .thenReturn(Optional.of(controlsListingController))
+        if (hasPanels) {
+            whenever(controlsServiceInfo.panelActivity).thenReturn(mock())
+        }
         whenever(controlsListingController.getCurrentServices())
             .thenReturn(
                 if (hasServiceInfos) {
-                    listOf(mock(), mock())
+                    listOf(controlsServiceInfo, mock())
                 } else {
                     emptyList()
                 }
@@ -134,10 +142,15 @@
         val job = underTest.lockScreenState.onEach(values::add).launchIn(this)
 
         if (canShowWhileLocked) {
+            val serviceInfoMock: ControlsServiceInfo = mock {
+                if (hasPanels) {
+                    whenever(panelActivity).thenReturn(mock())
+                }
+            }
             verify(controlsListingController).addCallback(callbackCaptor.capture())
             callbackCaptor.value.onServicesUpdated(
                 if (hasServiceInfos) {
-                    listOf(mock())
+                    listOf(serviceInfoMock)
                 } else {
                     emptyList()
                 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardBouncerRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardBouncerRepositoryTest.kt
new file mode 100644
index 0000000..9970a67
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardBouncerRepositoryTest.kt
@@ -0,0 +1,54 @@
+/*
+ * 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.systemui.keyguard.data.repository
+
+import androidx.test.filters.SmallTest
+import com.android.keyguard.ViewMediatorCallback
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.log.table.TableLogBuffer
+import kotlinx.coroutines.runBlocking
+import kotlinx.coroutines.test.TestCoroutineScope
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+import org.mockito.Mock
+import org.mockito.Mockito.verify
+import org.mockito.MockitoAnnotations
+
+@SmallTest
+@RunWith(JUnit4::class)
+class KeyguardBouncerRepositoryTest : SysuiTestCase() {
+
+    @Mock private lateinit var viewMediatorCallback: ViewMediatorCallback
+    @Mock private lateinit var bouncerLogger: TableLogBuffer
+    lateinit var underTest: KeyguardBouncerRepository
+
+    @Before
+    fun setup() {
+        MockitoAnnotations.initMocks(this)
+        val testCoroutineScope = TestCoroutineScope()
+        underTest =
+            KeyguardBouncerRepository(viewMediatorCallback, testCoroutineScope, bouncerLogger)
+    }
+
+    @Test
+    fun changingFlowValueTriggersLogging() = runBlocking {
+        underTest.setPrimaryHide(true)
+        verify(bouncerLogger).logChange("", "PrimaryBouncerHide", false)
+    }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/log/SessionTrackerTest.java b/packages/SystemUI/tests/src/com/android/systemui/log/SessionTrackerTest.java
index dc5522e..aa54a1c 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/log/SessionTrackerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/log/SessionTrackerTest.java
@@ -23,8 +23,10 @@
 import static junit.framework.Assert.assertNotNull;
 import static junit.framework.Assert.assertNull;
 
+import static org.junit.Assert.assertNotEquals;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -171,6 +173,34 @@
     }
 
     @Test
+    public void testKeyguardSessionOnDeviceStartsSleepingTwiceInARow_startsNewKeyguardSession()
+            throws RemoteException {
+        // GIVEN session tracker started w/o any sessions
+        mSessionTracker.start();
+        captureKeyguardUpdateMonitorCallback();
+
+        // WHEN device starts going to sleep
+        mKeyguardUpdateMonitorCallback.onStartedGoingToSleep(0);
+
+        // THEN the keyguard session has a session id
+        final InstanceId firstSessionId = mSessionTracker.getSessionId(SESSION_KEYGUARD);
+        assertNotNull(firstSessionId);
+
+        // WHEN device starts going to sleep a second time
+        mKeyguardUpdateMonitorCallback.onStartedGoingToSleep(0);
+
+        // THEN there's a new keyguard session with a unique session id
+        final InstanceId secondSessionId = mSessionTracker.getSessionId(SESSION_KEYGUARD);
+        assertNotNull(secondSessionId);
+        assertNotEquals(firstSessionId, secondSessionId);
+
+        // THEN session start event gets sent to status bar service twice (once per going to
+        // sleep signal)
+        verify(mStatusBarService, times(2)).onSessionStarted(
+                eq(SESSION_KEYGUARD), any(InstanceId.class));
+    }
+
+    @Test
     public void testKeyguardSessionOnKeyguardShowingChange() throws RemoteException {
         // GIVEN session tracker started w/o any sessions
         mSessionTracker.start();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaControlPanelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaControlPanelTest.kt
index fdef344..b65f5cb 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaControlPanelTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaControlPanelTest.kt
@@ -214,6 +214,7 @@
     private val fakeFeatureFlag =
         FakeFeatureFlags().apply {
             this.set(Flags.UMO_SURFACE_RIPPLE, false)
+            this.set(Flags.UMO_TURBULENCE_NOISE, false)
             this.set(Flags.MEDIA_FALSING_PENALTY, true)
         }
 
@@ -2062,6 +2063,26 @@
         assertThat(viewHolder.multiRippleView.ripples.size).isEqualTo(0)
     }
 
+    @Test
+    fun onButtonClick_turbulenceNoiseFlagEnabled_createsRipplesFinishedListener() {
+        fakeFeatureFlag.set(Flags.UMO_SURFACE_RIPPLE, true)
+        fakeFeatureFlag.set(Flags.UMO_TURBULENCE_NOISE, true)
+
+        player.attachPlayer(viewHolder)
+
+        assertThat(player.mRipplesFinishedListener).isNotNull()
+    }
+
+    @Test
+    fun onButtonClick_turbulenceNoiseFlagDisabled_doesNotCreateRipplesFinishedListener() {
+        fakeFeatureFlag.set(Flags.UMO_SURFACE_RIPPLE, true)
+        fakeFeatureFlag.set(Flags.UMO_TURBULENCE_NOISE, false)
+
+        player.attachPlayer(viewHolder)
+
+        assertThat(player.mRipplesFinishedListener).isNull()
+    }
+
     private fun getScrubbingChangeListener(): SeekBarViewModel.ScrubbingChangeListener =
         withArgCaptor {
             verify(seekBarViewModel).setScrubbingChangeListener(capture())
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputAdapterTest.java b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputAdapterTest.java
index 5f64336..7c3c9d2 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputAdapterTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputAdapterTest.java
@@ -38,12 +38,15 @@
 import com.android.systemui.R;
 import com.android.systemui.SysuiTestCase;
 
+import com.google.common.collect.ImmutableList;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @SmallTest
 @RunWith(AndroidTestingRunner.class)
@@ -69,15 +72,13 @@
     private MediaOutputAdapter mMediaOutputAdapter;
     private MediaOutputAdapter.MediaDeviceViewHolder mViewHolder;
     private List<MediaDevice> mMediaDevices = new ArrayList<>();
+    private List<MediaItem> mMediaItems = new ArrayList<>();
     MediaOutputSeekbar mSpyMediaOutputSeekbar;
 
     @Before
     public void setUp() {
-        mMediaOutputAdapter = new MediaOutputAdapter(mMediaOutputController);
-        mViewHolder = (MediaOutputAdapter.MediaDeviceViewHolder) mMediaOutputAdapter
-                .onCreateViewHolder(new LinearLayout(mContext), 0);
-        mSpyMediaOutputSeekbar = spy(mViewHolder.mSeekBar);
-
+        when(mMediaOutputController.isAdvancedLayoutSupported()).thenReturn(false);
+        when(mMediaOutputController.getMediaItemList()).thenReturn(mMediaItems);
         when(mMediaOutputController.getMediaDevices()).thenReturn(mMediaDevices);
         when(mMediaOutputController.hasAdjustVolumeUserRestriction()).thenReturn(false);
         when(mMediaOutputController.isAnyDeviceTransferring()).thenReturn(false);
@@ -96,6 +97,13 @@
                 LocalMediaManager.MediaDeviceState.STATE_DISCONNECTED);
         mMediaDevices.add(mMediaDevice1);
         mMediaDevices.add(mMediaDevice2);
+        mMediaItems.add(new MediaItem(mMediaDevice1));
+        mMediaItems.add(new MediaItem(mMediaDevice2));
+
+        mMediaOutputAdapter = new MediaOutputAdapter(mMediaOutputController);
+        mViewHolder = (MediaOutputAdapter.MediaDeviceViewHolder) mMediaOutputAdapter
+                .onCreateViewHolder(new LinearLayout(mContext), 0);
+        mSpyMediaOutputSeekbar = spy(mViewHolder.mSeekBar);
     }
 
     @Test
@@ -116,6 +124,26 @@
     }
 
     @Test
+    public void advanced_getItemCount_returnsMediaItemSize() {
+        when(mMediaOutputController.isAdvancedLayoutSupported()).thenReturn(true);
+        assertThat(mMediaOutputAdapter.getItemCount()).isEqualTo(mMediaItems.size());
+    }
+
+    @Test
+    public void advanced_getItemId_validPosition_returnCorrespondingId() {
+        when(mMediaOutputController.isAdvancedLayoutSupported()).thenReturn(true);
+        assertThat(mMediaOutputAdapter.getItemId(0)).isEqualTo(mMediaItems.get(
+                0).getMediaDevice().get().getId().hashCode());
+    }
+
+    @Test
+    public void advanced_getItemId_invalidPosition_returnPosition() {
+        when(mMediaOutputController.isAdvancedLayoutSupported()).thenReturn(true);
+        int invalidPosition = mMediaItems.size() + 1;
+        assertThat(mMediaOutputAdapter.getItemId(invalidPosition)).isEqualTo(invalidPosition);
+    }
+
+    @Test
     public void onBindViewHolder_bindPairNew_verifyView() {
         mMediaOutputAdapter.onBindViewHolder(mViewHolder, 2);
 
@@ -156,6 +184,63 @@
     }
 
     @Test
+    public void advanced_onBindViewHolder_bindPairNew_verifyView() {
+        when(mMediaOutputController.isAdvancedLayoutSupported()).thenReturn(true);
+        mMediaOutputAdapter = new MediaOutputAdapter(mMediaOutputController);
+        mViewHolder = (MediaOutputAdapter.MediaDeviceViewHolder) mMediaOutputAdapter
+                .onCreateViewHolder(new LinearLayout(mContext), 0);
+        mMediaItems.add(new MediaItem());
+        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 2);
+
+        assertThat(mViewHolder.mTitleText.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(mViewHolder.mTwoLineLayout.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mViewHolder.mProgressBar.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mViewHolder.mCheckBox.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mViewHolder.mTitleText.getText()).isEqualTo(mContext.getText(
+                R.string.media_output_dialog_pairing_new));
+    }
+
+    @Test
+    public void advanced_onBindViewHolder_bindGroup_withSessionName_verifyView() {
+        when(mMediaOutputController.isAdvancedLayoutSupported()).thenReturn(true);
+        when(mMediaOutputController.getSelectedMediaDevice()).thenReturn(
+                mMediaItems.stream().map((item) -> item.getMediaDevice().get()).collect(
+                        Collectors.toList()));
+        when(mMediaOutputController.getSessionName()).thenReturn(TEST_SESSION_NAME);
+        mMediaOutputAdapter = new MediaOutputAdapter(mMediaOutputController);
+        mViewHolder = (MediaOutputAdapter.MediaDeviceViewHolder) mMediaOutputAdapter
+                .onCreateViewHolder(new LinearLayout(mContext), 0);
+        mMediaOutputAdapter.getItemCount();
+        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0);
+
+        assertThat(mViewHolder.mSeekBar.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(mViewHolder.mTwoLineLayout.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mViewHolder.mTitleText.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(mViewHolder.mProgressBar.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mViewHolder.mCheckBox.getVisibility()).isEqualTo(View.VISIBLE);
+    }
+
+    @Test
+    public void advanced_onBindViewHolder_bindGroup_noSessionName_verifyView() {
+        when(mMediaOutputController.isAdvancedLayoutSupported()).thenReturn(true);
+        when(mMediaOutputController.getSelectedMediaDevice()).thenReturn(
+                mMediaItems.stream().map((item) -> item.getMediaDevice().get()).collect(
+                        Collectors.toList()));
+        when(mMediaOutputController.getSessionName()).thenReturn(null);
+        mMediaOutputAdapter = new MediaOutputAdapter(mMediaOutputController);
+        mViewHolder = (MediaOutputAdapter.MediaDeviceViewHolder) mMediaOutputAdapter
+                .onCreateViewHolder(new LinearLayout(mContext), 0);
+        mMediaOutputAdapter.getItemCount();
+        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0);
+
+        assertThat(mViewHolder.mSeekBar.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(mViewHolder.mTwoLineLayout.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mViewHolder.mTitleText.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(mViewHolder.mProgressBar.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mViewHolder.mCheckBox.getVisibility()).isEqualTo(View.VISIBLE);
+    }
+
+    @Test
     public void onBindViewHolder_bindConnectedDevice_verifyView() {
         mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0);
 
@@ -169,6 +254,63 @@
     }
 
     @Test
+    public void advanced_onBindViewHolder_bindNonRemoteConnectedDevice_verifyView() {
+        when(mMediaOutputController.isAdvancedLayoutSupported()).thenReturn(true);
+        when(mMediaOutputController.isActiveRemoteDevice(mMediaDevice1)).thenReturn(false);
+        mViewHolder = (MediaOutputAdapter.MediaDeviceViewHolder) mMediaOutputAdapter
+                .onCreateViewHolder(new LinearLayout(mContext), 0);
+        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0);
+
+        assertThat(mViewHolder.mTitleText.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(mViewHolder.mTitleText.getText().toString()).isEqualTo(TEST_DEVICE_NAME_1);
+        assertThat(mViewHolder.mSubTitleText.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mViewHolder.mProgressBar.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mViewHolder.mCheckBox.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mViewHolder.mTwoLineLayout.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mViewHolder.mSeekBar.getVisibility()).isEqualTo(View.VISIBLE);
+    }
+
+    @Test
+    public void advanced_onBindViewHolder_bindConnectedRemoteDevice_verifyView() {
+        when(mMediaOutputController.isAdvancedLayoutSupported()).thenReturn(true);
+        when(mMediaOutputController.getSelectableMediaDevice()).thenReturn(
+                ImmutableList.of(mMediaDevice2));
+        when(mMediaOutputController.isCurrentConnectedDeviceRemote()).thenReturn(true);
+        mViewHolder = (MediaOutputAdapter.MediaDeviceViewHolder) mMediaOutputAdapter
+                .onCreateViewHolder(new LinearLayout(mContext), 0);
+        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0);
+
+        assertThat(mViewHolder.mTitleText.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(mViewHolder.mTitleText.getText().toString()).isEqualTo(TEST_DEVICE_NAME_1);
+        assertThat(mViewHolder.mSubTitleText.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mViewHolder.mProgressBar.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mViewHolder.mCheckBox.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(mViewHolder.mTwoLineLayout.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mViewHolder.mSeekBar.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(mViewHolder.mEndTouchArea.getVisibility()).isEqualTo(View.VISIBLE);
+    }
+
+    @Test
+    public void advanced_onBindViewHolder_bindSingleConnectedRemoteDevice_verifyView() {
+        when(mMediaOutputController.isAdvancedLayoutSupported()).thenReturn(true);
+        when(mMediaOutputController.getSelectableMediaDevice()).thenReturn(
+                ImmutableList.of());
+        when(mMediaOutputController.isCurrentConnectedDeviceRemote()).thenReturn(true);
+        mViewHolder = (MediaOutputAdapter.MediaDeviceViewHolder) mMediaOutputAdapter
+                .onCreateViewHolder(new LinearLayout(mContext), 0);
+        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0);
+
+        assertThat(mViewHolder.mTitleText.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(mViewHolder.mTitleText.getText().toString()).isEqualTo(TEST_DEVICE_NAME_1);
+        assertThat(mViewHolder.mSubTitleText.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mViewHolder.mProgressBar.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mViewHolder.mCheckBox.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mViewHolder.mTwoLineLayout.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mViewHolder.mSeekBar.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(mViewHolder.mEndTouchArea.getVisibility()).isEqualTo(View.GONE);
+    }
+
+    @Test
     public void onBindViewHolder_bindConnectedDeviceWithMutingExpectedDeviceExist_verifyView() {
         when(mMediaOutputController.hasMutingExpectedDevice()).thenReturn(true);
         when(mMediaOutputController.isCurrentConnectedDeviceRemote()).thenReturn(false);
@@ -316,6 +458,19 @@
     }
 
     @Test
+    public void advanced_onItemClick_clickPairNew_verifyLaunchBluetoothPairing() {
+        when(mMediaOutputController.isAdvancedLayoutSupported()).thenReturn(true);
+        mMediaOutputAdapter = new MediaOutputAdapter(mMediaOutputController);
+        mViewHolder = (MediaOutputAdapter.MediaDeviceViewHolder) mMediaOutputAdapter
+                .onCreateViewHolder(new LinearLayout(mContext), 0);
+        mMediaItems.add(new MediaItem());
+        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 2);
+        mViewHolder.mContainerLayout.performClick();
+
+        verify(mMediaOutputController).launchBluetoothPairing(mViewHolder.mContainerLayout);
+    }
+
+    @Test
     public void onItemClick_clickDevice_verifyConnectDevice() {
         assertThat(mMediaDevice2.getState()).isEqualTo(
                 LocalMediaManager.MediaDeviceState.STATE_DISCONNECTED);
@@ -352,6 +507,38 @@
     }
 
     @Test
+    public void advanced_onGroupActionTriggered_clicksEndAreaOfSelectableDevice_triggerGrouping() {
+        when(mMediaOutputController.isAdvancedLayoutSupported()).thenReturn(true);
+        List<MediaDevice> selectableDevices = new ArrayList<>();
+        selectableDevices.add(mMediaDevice2);
+        when(mMediaOutputController.getSelectableMediaDevice()).thenReturn(selectableDevices);
+        mViewHolder = (MediaOutputAdapter.MediaDeviceViewHolder) mMediaOutputAdapter
+                .onCreateViewHolder(new LinearLayout(mContext), 0);
+        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 1);
+
+        mViewHolder.mEndTouchArea.performClick();
+
+        verify(mMediaOutputController).addDeviceToPlayMedia(mMediaDevice2);
+    }
+
+    @Test
+    public void advanced_onGroupActionTriggered_clickSelectedRemoteDevice_triggerUngrouping() {
+        when(mMediaOutputController.isAdvancedLayoutSupported()).thenReturn(true);
+        when(mMediaOutputController.getSelectableMediaDevice()).thenReturn(
+                ImmutableList.of(mMediaDevice2));
+        when(mMediaOutputController.getDeselectableMediaDevice()).thenReturn(
+                ImmutableList.of(mMediaDevice1));
+        when(mMediaOutputController.isCurrentConnectedDeviceRemote()).thenReturn(true);
+        mViewHolder = (MediaOutputAdapter.MediaDeviceViewHolder) mMediaOutputAdapter
+                .onCreateViewHolder(new LinearLayout(mContext), 0);
+        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0);
+
+        mViewHolder.mEndTouchArea.performClick();
+
+        verify(mMediaOutputController).removeDeviceFromPlayMedia(mMediaDevice1);
+    }
+
+    @Test
     public void onItemClick_onGroupActionTriggered_verifySeekbarDisabled() {
         when(mMediaOutputController.getSelectedMediaDevice()).thenReturn(mMediaDevices);
         List<MediaDevice> selectableDevices = new ArrayList<>();
@@ -366,6 +553,26 @@
     }
 
     @Test
+    public void advanced_onItemClick_onGroupActionTriggered_verifySeekbarDisabled() {
+        when(mMediaOutputController.isAdvancedLayoutSupported()).thenReturn(true);
+        when(mMediaOutputController.getSelectedMediaDevice()).thenReturn(
+                mMediaItems.stream().map((item) -> item.getMediaDevice().get()).collect(
+                        Collectors.toList()));
+        mMediaOutputAdapter = new MediaOutputAdapter(mMediaOutputController);
+        mViewHolder = (MediaOutputAdapter.MediaDeviceViewHolder) mMediaOutputAdapter
+                .onCreateViewHolder(new LinearLayout(mContext), 0);
+        List<MediaDevice> selectableDevices = new ArrayList<>();
+        selectableDevices.add(mMediaDevice1);
+        when(mMediaOutputController.getSelectableMediaDevice()).thenReturn(selectableDevices);
+        when(mMediaOutputController.hasAdjustVolumeUserRestriction()).thenReturn(true);
+        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0);
+
+        mViewHolder.mContainerLayout.performClick();
+
+        assertThat(mViewHolder.mSeekBar.isEnabled()).isFalse();
+    }
+
+    @Test
     public void onBindViewHolder_volumeControlChangeToEnabled_enableSeekbarAgain() {
         when(mMediaOutputController.isVolumeControlEnabled(mMediaDevice1)).thenReturn(false);
         mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBaseDialogTest.java b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBaseDialogTest.java
index 9be201e..094d69a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBaseDialogTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBaseDialogTest.java
@@ -51,6 +51,7 @@
 import com.android.systemui.SysuiTestCase;
 import com.android.systemui.animation.DialogLaunchAnimator;
 import com.android.systemui.broadcast.BroadcastSender;
+import com.android.systemui.flags.FeatureFlags;
 import com.android.systemui.media.nearby.NearbyMediaDevicesManager;
 import com.android.systemui.plugins.ActivityStarter;
 import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection;
@@ -89,6 +90,7 @@
     private final AudioManager mAudioManager = mock(AudioManager.class);
     private PowerExemptionManager mPowerExemptionManager = mock(PowerExemptionManager.class);
     private KeyguardManager mKeyguardManager = mock(KeyguardManager.class);
+    private FeatureFlags mFlags = mock(FeatureFlags.class);
 
     private List<MediaController> mMediaControllers = new ArrayList<>();
     private MediaOutputBaseDialogImpl mMediaOutputBaseDialogImpl;
@@ -121,7 +123,7 @@
                 mMediaSessionManager, mLocalBluetoothManager, mStarter,
                 mNotifCollection, mDialogLaunchAnimator,
                 Optional.of(mNearbyMediaDevicesManager), mAudioManager, mPowerExemptionManager,
-                mKeyguardManager);
+                mKeyguardManager, mFlags);
         mMediaOutputBaseDialogImpl = new MediaOutputBaseDialogImpl(mContext, mBroadcastSender,
                 mMediaOutputController);
         mMediaOutputBaseDialogImpl.onCreate(new Bundle());
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputControllerTest.java
index cb31fde..71c300c 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputControllerTest.java
@@ -62,6 +62,8 @@
 import com.android.systemui.SysuiTestCase;
 import com.android.systemui.animation.ActivityLaunchAnimator;
 import com.android.systemui.animation.DialogLaunchAnimator;
+import com.android.systemui.flags.FeatureFlags;
+import com.android.systemui.flags.Flags;
 import com.android.systemui.media.nearby.NearbyMediaDevicesManager;
 import com.android.systemui.plugins.ActivityStarter;
 import com.android.systemui.statusbar.notification.collection.NotificationEntry;
@@ -110,6 +112,7 @@
     private PowerExemptionManager mPowerExemptionManager = mock(PowerExemptionManager.class);
     private CommonNotifCollection mNotifCollection = mock(CommonNotifCollection.class);
     private final DialogLaunchAnimator mDialogLaunchAnimator = mock(DialogLaunchAnimator.class);
+    private FeatureFlags mFlags = mock(FeatureFlags.class);
     private final ActivityLaunchAnimator.Controller mActivityLaunchAnimatorController = mock(
             ActivityLaunchAnimator.Controller.class);
     private final NearbyMediaDevicesManager mNearbyMediaDevicesManager = mock(
@@ -141,7 +144,8 @@
                 mMediaSessionManager, mLocalBluetoothManager, mStarter,
                 mNotifCollection, mDialogLaunchAnimator,
                 Optional.of(mNearbyMediaDevicesManager), mAudioManager, mPowerExemptionManager,
-                mKeyguardManager);
+                mKeyguardManager, mFlags);
+        when(mFlags.isEnabled(Flags.OUTPUT_SWITCHER_ADVANCED_LAYOUT)).thenReturn(false);
         mLocalMediaManager = spy(mMediaOutputController.mLocalMediaManager);
         mMediaOutputController.mLocalMediaManager = mLocalMediaManager;
         MediaDescription.Builder builder = new MediaDescription.Builder();
@@ -194,7 +198,7 @@
                 mMediaSessionManager, mLocalBluetoothManager, mStarter,
                 mNotifCollection, mDialogLaunchAnimator,
                 Optional.of(mNearbyMediaDevicesManager), mAudioManager, mPowerExemptionManager,
-                mKeyguardManager);
+                mKeyguardManager, mFlags);
 
         mMediaOutputController.start(mCb);
 
@@ -224,7 +228,7 @@
                 mMediaSessionManager, mLocalBluetoothManager, mStarter,
                 mNotifCollection, mDialogLaunchAnimator,
                 Optional.of(mNearbyMediaDevicesManager), mAudioManager, mPowerExemptionManager,
-                mKeyguardManager);
+                mKeyguardManager, mFlags);
 
         mMediaOutputController.start(mCb);
 
@@ -280,6 +284,25 @@
     }
 
     @Test
+    public void advanced_onDeviceListUpdate_verifyDeviceListCallback() {
+        when(mFlags.isEnabled(Flags.OUTPUT_SWITCHER_ADVANCED_LAYOUT)).thenReturn(true);
+        mMediaOutputController.start(mCb);
+        reset(mCb);
+
+        mMediaOutputController.onDeviceListUpdate(mMediaDevices);
+        final List<MediaDevice> devices = new ArrayList<>();
+        for (MediaItem item : mMediaOutputController.getMediaItemList()) {
+            if (item.getMediaDevice().isPresent()) {
+                devices.add(item.getMediaDevice().get());
+            }
+        }
+
+        assertThat(devices.containsAll(mMediaDevices)).isTrue();
+        assertThat(devices.size()).isEqualTo(mMediaDevices.size());
+        verify(mCb).onDeviceListChanged();
+    }
+
+    @Test
     public void onDeviceListUpdate_isRefreshing_updatesNeedRefreshToTrue() {
         mMediaOutputController.start(mCb);
         reset(mCb);
@@ -318,7 +341,7 @@
                 mMediaSessionManager, mLocalBluetoothManager, mStarter,
                 mNotifCollection, mDialogLaunchAnimator,
                 Optional.of(mNearbyMediaDevicesManager), mAudioManager, mPowerExemptionManager,
-                mKeyguardManager);
+                mKeyguardManager, mFlags);
         testMediaOutputController.start(mCb);
         reset(mCb);
 
@@ -341,7 +364,7 @@
                 mMediaSessionManager, mLocalBluetoothManager, mStarter,
                 mNotifCollection, mDialogLaunchAnimator,
                 Optional.of(mNearbyMediaDevicesManager), mAudioManager, mPowerExemptionManager,
-                mKeyguardManager);
+                mKeyguardManager, mFlags);
         testMediaOutputController.start(mCb);
         reset(mCb);
 
@@ -377,7 +400,7 @@
                 mMediaSessionManager, mLocalBluetoothManager, mStarter,
                 mNotifCollection, mDialogLaunchAnimator,
                 Optional.of(mNearbyMediaDevicesManager), mAudioManager, mPowerExemptionManager,
-                mKeyguardManager);
+                mKeyguardManager, mFlags);
 
         LocalMediaManager testLocalMediaManager = spy(testMediaOutputController.mLocalMediaManager);
         testMediaOutputController.mLocalMediaManager = testLocalMediaManager;
@@ -394,7 +417,7 @@
                 mMediaSessionManager, mLocalBluetoothManager, mStarter,
                 mNotifCollection, mDialogLaunchAnimator,
                 Optional.of(mNearbyMediaDevicesManager), mAudioManager, mPowerExemptionManager,
-                mKeyguardManager);
+                mKeyguardManager, mFlags);
 
         LocalMediaManager testLocalMediaManager = spy(testMediaOutputController.mLocalMediaManager);
         testMediaOutputController.mLocalMediaManager = testLocalMediaManager;
@@ -671,7 +694,7 @@
                 mMediaSessionManager, mLocalBluetoothManager, mStarter,
                 mNotifCollection, mDialogLaunchAnimator,
                 Optional.of(mNearbyMediaDevicesManager), mAudioManager, mPowerExemptionManager,
-                mKeyguardManager);
+                mKeyguardManager, mFlags);
 
         assertThat(mMediaOutputController.getNotificationIcon()).isNull();
     }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputDialogTest.java b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputDialogTest.java
index bae3569..31866a8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputDialogTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputDialogTest.java
@@ -50,6 +50,7 @@
 import com.android.systemui.SysuiTestCase;
 import com.android.systemui.animation.DialogLaunchAnimator;
 import com.android.systemui.broadcast.BroadcastSender;
+import com.android.systemui.flags.FeatureFlags;
 import com.android.systemui.media.nearby.NearbyMediaDevicesManager;
 import com.android.systemui.plugins.ActivityStarter;
 import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection;
@@ -93,6 +94,7 @@
     private final AudioManager mAudioManager = mock(AudioManager.class);
     private PowerExemptionManager mPowerExemptionManager = mock(PowerExemptionManager.class);
     private KeyguardManager mKeyguardManager = mock(KeyguardManager.class);
+    private FeatureFlags mFlags = mock(FeatureFlags.class);
 
     private List<MediaController> mMediaControllers = new ArrayList<>();
     private MediaOutputDialog mMediaOutputDialog;
@@ -115,7 +117,7 @@
                 mMediaSessionManager, mLocalBluetoothManager, mStarter,
                 mNotifCollection, mDialogLaunchAnimator,
                 Optional.of(mNearbyMediaDevicesManager), mAudioManager, mPowerExemptionManager,
-                mKeyguardManager);
+                mKeyguardManager, mFlags);
         mMediaOutputController.mLocalMediaManager = mLocalMediaManager;
         mMediaOutputDialog = new MediaOutputDialog(mContext, false, mBroadcastSender,
                 mMediaOutputController, mUiEventLogger);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttLoggerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttLoggerTest.kt
index e009e86..0e7bf8d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttLoggerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttLoggerTest.kt
@@ -22,6 +22,7 @@
 import com.android.systemui.log.LogBufferFactory
 import com.android.systemui.plugins.log.LogBuffer
 import com.android.systemui.plugins.log.LogcatEchoTracker
+import com.android.systemui.temporarydisplay.TemporaryViewInfo
 import com.google.common.truth.Truth.assertThat
 import java.io.PrintWriter
 import java.io.StringWriter
@@ -33,7 +34,7 @@
 class MediaTttLoggerTest : SysuiTestCase() {
 
     private lateinit var buffer: LogBuffer
-    private lateinit var logger: MediaTttLogger
+    private lateinit var logger: MediaTttLogger<TemporaryViewInfo>
 
     @Before
     fun setUp () {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttUtilsTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttUtilsTest.kt
index 6a4c0f6..561867f 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttUtilsTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttUtilsTest.kt
@@ -25,6 +25,7 @@
 import com.android.systemui.common.shared.model.ContentDescription
 import com.android.systemui.common.shared.model.ContentDescription.Companion.loadContentDescription
 import com.android.systemui.common.shared.model.Icon
+import com.android.systemui.temporarydisplay.TemporaryViewInfo
 import com.android.systemui.util.mockito.any
 import com.google.common.truth.Truth.assertThat
 import org.junit.Before
@@ -40,7 +41,7 @@
     private lateinit var appIconFromPackageName: Drawable
     @Mock private lateinit var packageManager: PackageManager
     @Mock private lateinit var applicationInfo: ApplicationInfo
-    @Mock private lateinit var logger: MediaTttLogger
+    @Mock private lateinit var logger: MediaTttLogger<TemporaryViewInfo>
 
     @Before
     fun setUp() {
@@ -65,41 +66,14 @@
     }
 
     @Test
-    fun getIconFromPackageName_nullPackageName_returnsDefault() {
-        val icon = MediaTttUtils.getIconFromPackageName(context, appPackageName = null, logger)
-
-        val expectedDesc =
-            ContentDescription.Resource(R.string.media_output_dialog_unknown_launch_app_name)
-                .loadContentDescription(context)
-        assertThat(icon.contentDescription.loadContentDescription(context)).isEqualTo(expectedDesc)
-    }
-
-    @Test
-    fun getIconFromPackageName_invalidPackageName_returnsDefault() {
-        val icon = MediaTttUtils.getIconFromPackageName(context, "fakePackageName", logger)
-
-        val expectedDesc =
-            ContentDescription.Resource(R.string.media_output_dialog_unknown_launch_app_name)
-                .loadContentDescription(context)
-        assertThat(icon.contentDescription.loadContentDescription(context)).isEqualTo(expectedDesc)
-    }
-
-    @Test
-    fun getIconFromPackageName_validPackageName_returnsAppInfo() {
-        val icon = MediaTttUtils.getIconFromPackageName(context, PACKAGE_NAME, logger)
-
-        assertThat(icon)
-            .isEqualTo(Icon.Loaded(appIconFromPackageName, ContentDescription.Loaded(APP_NAME)))
-    }
-
-    @Test
     fun getIconInfoFromPackageName_nullPackageName_returnsDefault() {
         val iconInfo =
             MediaTttUtils.getIconInfoFromPackageName(context, appPackageName = null, logger)
 
         assertThat(iconInfo.isAppIcon).isFalse()
-        assertThat(iconInfo.contentDescription)
+        assertThat(iconInfo.contentDescription.loadContentDescription(context))
             .isEqualTo(context.getString(R.string.media_output_dialog_unknown_launch_app_name))
+        assertThat(iconInfo.icon).isEqualTo(MediaTttIcon.Resource(R.drawable.ic_cast))
     }
 
     @Test
@@ -107,8 +81,9 @@
         val iconInfo = MediaTttUtils.getIconInfoFromPackageName(context, "fakePackageName", logger)
 
         assertThat(iconInfo.isAppIcon).isFalse()
-        assertThat(iconInfo.contentDescription)
+        assertThat(iconInfo.contentDescription.loadContentDescription(context))
             .isEqualTo(context.getString(R.string.media_output_dialog_unknown_launch_app_name))
+        assertThat(iconInfo.icon).isEqualTo(MediaTttIcon.Resource(R.drawable.ic_cast))
     }
 
     @Test
@@ -116,8 +91,48 @@
         val iconInfo = MediaTttUtils.getIconInfoFromPackageName(context, PACKAGE_NAME, logger)
 
         assertThat(iconInfo.isAppIcon).isTrue()
-        assertThat(iconInfo.drawable).isEqualTo(appIconFromPackageName)
-        assertThat(iconInfo.contentDescription).isEqualTo(APP_NAME)
+        assertThat(iconInfo.icon).isEqualTo(MediaTttIcon.Loaded(appIconFromPackageName))
+        assertThat(iconInfo.contentDescription.loadContentDescription(context)).isEqualTo(APP_NAME)
+    }
+
+    @Test
+    fun iconInfo_toTintedIcon_loaded() {
+        val contentDescription = ContentDescription.Loaded("test")
+        val drawable = context.getDrawable(R.drawable.ic_cake)!!
+        val tintAttr = android.R.attr.textColorTertiary
+
+        val iconInfo =
+            IconInfo(
+                contentDescription,
+                MediaTttIcon.Loaded(drawable),
+                tintAttr,
+                isAppIcon = false,
+            )
+
+        val tinted = iconInfo.toTintedIcon()
+
+        assertThat(tinted.icon).isEqualTo(Icon.Loaded(drawable, contentDescription))
+        assertThat(tinted.tintAttr).isEqualTo(tintAttr)
+    }
+
+    @Test
+    fun iconInfo_toTintedIcon_resource() {
+        val contentDescription = ContentDescription.Loaded("test")
+        val drawableRes = R.drawable.ic_cake
+        val tintAttr = android.R.attr.textColorTertiary
+
+        val iconInfo =
+            IconInfo(
+                contentDescription,
+                MediaTttIcon.Resource(drawableRes),
+                tintAttr,
+                isAppIcon = false
+            )
+
+        val tinted = iconInfo.toTintedIcon()
+
+        assertThat(tinted.icon).isEqualTo(Icon.Resource(drawableRes, contentDescription))
+        assertThat(tinted.tintAttr).isEqualTo(tintAttr)
     }
 }
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/receiver/FakeMediaTttChipControllerReceiver.kt b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/receiver/FakeMediaTttChipControllerReceiver.kt
index 4aa982e..bad3f03 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/receiver/FakeMediaTttChipControllerReceiver.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/receiver/FakeMediaTttChipControllerReceiver.kt
@@ -27,13 +27,14 @@
 import com.android.systemui.statusbar.CommandQueue
 import com.android.systemui.statusbar.policy.ConfigurationController
 import com.android.systemui.util.concurrency.DelayableExecutor
+import com.android.systemui.util.time.SystemClock
 import com.android.systemui.util.view.ViewUtil
 import com.android.systemui.util.wakelock.WakeLock
 
 class FakeMediaTttChipControllerReceiver(
     commandQueue: CommandQueue,
     context: Context,
-    logger: MediaTttLogger,
+    logger: MediaTttLogger<ChipReceiverInfo>,
     windowManager: WindowManager,
     mainExecutor: DelayableExecutor,
     accessibilityManager: AccessibilityManager,
@@ -44,6 +45,7 @@
     uiEventLogger: MediaTttReceiverUiEventLogger,
     viewUtil: ViewUtil,
     wakeLockBuilder: WakeLock.Builder,
+    systemClock: SystemClock,
 ) :
     MediaTttChipControllerReceiver(
         commandQueue,
@@ -59,6 +61,7 @@
         uiEventLogger,
         viewUtil,
         wakeLockBuilder,
+        systemClock,
     ) {
     override fun animateViewOut(view: ViewGroup, onAnimationEnd: Runnable) {
         // Just bypass the animation in tests
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiverTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiverTest.kt
index 23f7cdb..ffa261a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiverTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiverTest.kt
@@ -67,7 +67,7 @@
     @Mock
     private lateinit var applicationInfo: ApplicationInfo
     @Mock
-    private lateinit var logger: MediaTttLogger
+    private lateinit var logger: MediaTttLogger<ChipReceiverInfo>
     @Mock
     private lateinit var accessibilityManager: AccessibilityManager
     @Mock
@@ -128,6 +128,7 @@
             receiverUiEventLogger,
             viewUtil,
             fakeWakeLockBuilder,
+            fakeClock,
         )
         controllerReceiver.start()
 
@@ -155,6 +156,7 @@
             receiverUiEventLogger,
             viewUtil,
             fakeWakeLockBuilder,
+            fakeClock,
         )
         controllerReceiver.start()
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinatorTest.kt
index 311740e..b03a545 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinatorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinatorTest.kt
@@ -45,6 +45,7 @@
 import com.android.systemui.statusbar.VibratorHelper
 import com.android.systemui.statusbar.policy.ConfigurationController
 import com.android.systemui.temporarydisplay.chipbar.ChipbarCoordinator
+import com.android.systemui.temporarydisplay.chipbar.ChipbarInfo
 import com.android.systemui.temporarydisplay.chipbar.ChipbarLogger
 import com.android.systemui.temporarydisplay.chipbar.FakeChipbarCoordinator
 import com.android.systemui.util.concurrency.FakeExecutor
@@ -83,7 +84,7 @@
     @Mock private lateinit var falsingManager: FalsingManager
     @Mock private lateinit var falsingCollector: FalsingCollector
     @Mock private lateinit var chipbarLogger: ChipbarLogger
-    @Mock private lateinit var logger: MediaTttLogger
+    @Mock private lateinit var logger: MediaTttLogger<ChipbarInfo>
     @Mock private lateinit var mediaTttFlags: MediaTttFlags
     @Mock private lateinit var packageManager: PackageManager
     @Mock private lateinit var powerManager: PowerManager
@@ -142,6 +143,7 @@
                 viewUtil,
                 vibratorHelper,
                 fakeWakeLockBuilder,
+                fakeClock,
             )
         chipbarCoordinator.start()
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/navigationbar/TaskbarDelegateTest.kt b/packages/SystemUI/tests/src/com/android/systemui/navigationbar/TaskbarDelegateTest.kt
new file mode 100644
index 0000000..1742c69
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/navigationbar/TaskbarDelegateTest.kt
@@ -0,0 +1,93 @@
+package com.android.systemui.navigationbar
+
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.dump.DumpManager
+import com.android.systemui.model.SysUiState
+import com.android.systemui.navigationbar.gestural.EdgeBackGestureHandler
+import com.android.systemui.recents.OverviewProxyService
+import com.android.systemui.statusbar.CommandQueue
+import com.android.systemui.statusbar.phone.AutoHideController
+import com.android.systemui.statusbar.phone.LightBarController
+import com.android.systemui.statusbar.phone.LightBarTransitionsController
+import com.android.wm.shell.back.BackAnimation
+import com.android.wm.shell.pip.Pip
+import org.junit.Before
+import org.junit.Test
+import org.mockito.Mock
+import org.mockito.Mockito.`when`
+import org.mockito.Mockito.any
+import org.mockito.Mockito.anyBoolean
+import org.mockito.Mockito.anyInt
+import org.mockito.Mockito.times
+import org.mockito.Mockito.verify
+import org.mockito.MockitoAnnotations
+import java.util.Optional
+
+@SmallTest
+class TaskbarDelegateTest : SysuiTestCase() {
+    val DISPLAY_ID = 0;
+    val MODE_GESTURE = 0;
+    val MODE_THREE_BUTTON = 1;
+
+    private lateinit var mTaskbarDelegate: TaskbarDelegate
+    @Mock
+    lateinit var mEdgeBackGestureHandlerFactory : EdgeBackGestureHandler.Factory
+    @Mock
+    lateinit var mEdgeBackGestureHandler : EdgeBackGestureHandler
+    @Mock
+    lateinit var mLightBarControllerFactory : LightBarTransitionsController.Factory
+    @Mock
+    lateinit var mLightBarTransitionController: LightBarTransitionsController
+    @Mock
+    lateinit var mCommandQueue: CommandQueue
+    @Mock
+    lateinit var mOverviewProxyService: OverviewProxyService
+    @Mock
+    lateinit var mNavBarHelper: NavBarHelper
+    @Mock
+    lateinit var mNavigationModeController: NavigationModeController
+    @Mock
+    lateinit var mSysUiState: SysUiState
+    @Mock
+    lateinit var mDumpManager: DumpManager
+    @Mock
+    lateinit var mAutoHideController: AutoHideController
+    @Mock
+    lateinit var mLightBarController: LightBarController
+    @Mock
+    lateinit var mOptionalPip: Optional<Pip>
+    @Mock
+    lateinit var mBackAnimation: BackAnimation
+    @Mock
+    lateinit var mCurrentSysUiState: NavBarHelper.CurrentSysuiState
+
+    @Before
+    fun setup() {
+        MockitoAnnotations.initMocks(this)
+        `when`(mEdgeBackGestureHandlerFactory.create(context)).thenReturn(mEdgeBackGestureHandler)
+        `when`(mLightBarControllerFactory.create(any())).thenReturn(mLightBarTransitionController)
+        `when`(mNavBarHelper.currentSysuiState).thenReturn(mCurrentSysUiState)
+        `when`(mSysUiState.setFlag(anyInt(), anyBoolean())).thenReturn(mSysUiState)
+        mTaskbarDelegate = TaskbarDelegate(context, mEdgeBackGestureHandlerFactory,
+                mLightBarControllerFactory)
+        mTaskbarDelegate.setDependencies(mCommandQueue, mOverviewProxyService, mNavBarHelper,
+        mNavigationModeController, mSysUiState, mDumpManager, mAutoHideController,
+                mLightBarController, mOptionalPip, mBackAnimation)
+    }
+
+    @Test
+    fun navigationModeInitialized() {
+        `when`(mNavigationModeController.addListener(any())).thenReturn(MODE_THREE_BUTTON)
+        assert(mTaskbarDelegate.navigationMode == -1)
+        mTaskbarDelegate.init(DISPLAY_ID)
+        assert(mTaskbarDelegate.navigationMode == MODE_THREE_BUTTON)
+    }
+
+    @Test
+    fun navigationModeInitialized_notifyEdgeBackHandler() {
+        `when`(mNavigationModeController.addListener(any())).thenReturn(MODE_GESTURE)
+        mTaskbarDelegate.init(DISPLAY_ID)
+        verify(mEdgeBackGestureHandler, times(1)).onNavigationModeChanged(MODE_GESTURE)
+    }
+}
\ No newline at end of file
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/FooterActionsControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/FooterActionsControllerTest.kt
deleted file mode 100644
index 2ba8782..0000000
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/FooterActionsControllerTest.kt
+++ /dev/null
@@ -1,440 +0,0 @@
-package com.android.systemui.qs
-
-import android.content.Intent
-import android.os.Handler
-import android.os.UserManager
-import android.provider.Settings
-import android.testing.AndroidTestingRunner
-import android.testing.TestableLooper
-import android.testing.ViewUtils
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
-import androidx.test.filters.SmallTest
-import com.android.internal.logging.MetricsLogger
-import com.android.internal.logging.UiEventLogger
-import com.android.internal.logging.testing.FakeMetricsLogger
-import com.android.systemui.R
-import com.android.systemui.animation.ActivityLaunchAnimator
-import com.android.systemui.classifier.FalsingManagerFake
-import com.android.systemui.globalactions.GlobalActionsDialogLite
-import com.android.systemui.plugins.ActivityStarter
-import com.android.systemui.settings.UserTracker
-import com.android.systemui.statusbar.phone.MultiUserSwitchController
-import com.android.systemui.statusbar.policy.DeviceProvisionedController
-import com.android.systemui.statusbar.policy.FakeConfigurationController
-import com.android.systemui.statusbar.policy.UserInfoController
-import com.android.systemui.util.mockito.capture
-import com.android.systemui.util.settings.FakeSettings
-import com.android.systemui.utils.leaks.LeakCheckedTest
-import com.google.common.truth.Expect
-import com.google.common.truth.Truth.assertThat
-import javax.inject.Provider
-import org.junit.After
-import org.junit.Before
-import org.junit.Rule
-import org.junit.Test
-import org.junit.runner.RunWith
-import org.mockito.ArgumentCaptor
-import org.mockito.ArgumentMatchers.any
-import org.mockito.ArgumentMatchers.anyBoolean
-import org.mockito.Captor
-import org.mockito.Mock
-import org.mockito.Mockito
-import org.mockito.Mockito.atLeastOnce
-import org.mockito.Mockito.clearInvocations
-import org.mockito.Mockito.never
-import org.mockito.Mockito.reset
-import org.mockito.Mockito.verify
-import org.mockito.Mockito.`when` as whenever
-import org.mockito.MockitoAnnotations
-
-@SmallTest
-@TestableLooper.RunWithLooper(setAsMainLooper = true)
-@RunWith(AndroidTestingRunner::class)
-class FooterActionsControllerTest : LeakCheckedTest() {
-
-    @get:Rule var expect: Expect = Expect.create()
-
-    @Mock private lateinit var userManager: UserManager
-    @Mock private lateinit var userTracker: UserTracker
-    @Mock private lateinit var activityStarter: ActivityStarter
-    @Mock private lateinit var deviceProvisionedController: DeviceProvisionedController
-    @Mock private lateinit var userInfoController: UserInfoController
-    @Mock private lateinit var multiUserSwitchControllerFactory: MultiUserSwitchController.Factory
-    @Mock private lateinit var multiUserSwitchController: MultiUserSwitchController
-    @Mock private lateinit var globalActionsDialogProvider: Provider<GlobalActionsDialogLite>
-    @Mock private lateinit var globalActionsDialog: GlobalActionsDialogLite
-    @Mock private lateinit var uiEventLogger: UiEventLogger
-    @Mock private lateinit var securityFooterController: QSSecurityFooter
-    @Mock private lateinit var fgsManagerController: QSFgsManagerFooter
-    @Captor
-    private lateinit var visibilityChangedCaptor:
-        ArgumentCaptor<VisibilityChangedDispatcher.OnVisibilityChangedListener>
-
-    private lateinit var controller: FooterActionsController
-
-    private val configurationController = FakeConfigurationController()
-    private val metricsLogger: MetricsLogger = FakeMetricsLogger()
-    private val falsingManager: FalsingManagerFake = FalsingManagerFake()
-    private lateinit var view: FooterActionsView
-    private lateinit var testableLooper: TestableLooper
-    private lateinit var fakeSettings: FakeSettings
-    private lateinit var securityFooter: View
-    private lateinit var fgsFooter: View
-
-    @Before
-    fun setUp() {
-        // We want to make sure testable resources are always used
-        context.ensureTestableResources()
-
-        MockitoAnnotations.initMocks(this)
-        testableLooper = TestableLooper.get(this)
-        fakeSettings = FakeSettings()
-
-        whenever(multiUserSwitchControllerFactory.create(any()))
-            .thenReturn(multiUserSwitchController)
-        whenever(globalActionsDialogProvider.get()).thenReturn(globalActionsDialog)
-
-        securityFooter = View(mContext)
-        fgsFooter = View(mContext)
-
-        whenever(securityFooterController.view).thenReturn(securityFooter)
-        whenever(fgsManagerController.view).thenReturn(fgsFooter)
-
-        view = inflateView()
-
-        controller = constructFooterActionsController(view)
-        controller.init()
-        ViewUtils.attachView(view)
-        // View looper is the testable looper associated with the test
-        testableLooper.processAllMessages()
-    }
-
-    @After
-    fun tearDown() {
-        if (view.isAttachedToWindow) {
-            ViewUtils.detachView(view)
-        }
-    }
-
-    @Test
-    fun testInitializesControllers() {
-        verify(multiUserSwitchController).init()
-        verify(fgsManagerController).init()
-        verify(securityFooterController).init()
-    }
-
-    @Test
-    fun testLogPowerMenuClick() {
-        controller.visible = true
-        falsingManager.setFalseTap(false)
-
-        view.findViewById<View>(R.id.pm_lite).performClick()
-        // Verify clicks are logged
-        verify(uiEventLogger, Mockito.times(1))
-            .log(GlobalActionsDialogLite.GlobalActionsEvent.GA_OPEN_QS)
-    }
-
-    @Test
-    fun testSettings() {
-        val captor = ArgumentCaptor.forClass(Intent::class.java)
-        whenever(deviceProvisionedController.isCurrentUserSetup).thenReturn(true)
-        view.findViewById<View>(R.id.settings_button_container).performClick()
-
-        verify(activityStarter)
-            .startActivity(capture(captor), anyBoolean(), any<ActivityLaunchAnimator.Controller>())
-
-        assertThat(captor.value.action).isEqualTo(Settings.ACTION_SETTINGS)
-    }
-
-    @Test
-    fun testSettings_UserNotSetup() {
-        whenever(deviceProvisionedController.isCurrentUserSetup).thenReturn(false)
-        view.findViewById<View>(R.id.settings_button_container).performClick()
-        // Verify Settings wasn't launched.
-        verify(activityStarter, never())
-            .startActivity(any(), anyBoolean(), any<ActivityLaunchAnimator.Controller>())
-    }
-
-    @Test
-    fun testMultiUserSwitchUpdatedWhenExpansionStarts() {
-        // When expansion starts, listening is set to true
-        val multiUserSwitch = view.requireViewById<View>(R.id.multi_user_switch)
-
-        assertThat(multiUserSwitch.visibility).isNotEqualTo(View.VISIBLE)
-
-        whenever(multiUserSwitchController.isMultiUserEnabled).thenReturn(true)
-
-        controller.setListening(true)
-        testableLooper.processAllMessages()
-
-        assertThat(multiUserSwitch.visibility).isEqualTo(View.VISIBLE)
-    }
-
-    @Test
-    fun testMultiUserSwitchUpdatedWhenSettingChanged() {
-        // Always listening to setting while View is attached
-        testableLooper.processAllMessages()
-
-        val multiUserSwitch = view.requireViewById<View>(R.id.multi_user_switch)
-        assertThat(multiUserSwitch.visibility).isNotEqualTo(View.VISIBLE)
-
-        // The setting is only used as an indicator for whether the view should refresh. The actual
-        // value of the setting is ignored; isMultiUserEnabled is the source of truth
-        whenever(multiUserSwitchController.isMultiUserEnabled).thenReturn(true)
-
-        // Changing the value of USER_SWITCHER_ENABLED should cause the view to update
-        fakeSettings.putIntForUser(Settings.Global.USER_SWITCHER_ENABLED, 1, userTracker.userId)
-        testableLooper.processAllMessages()
-
-        assertThat(multiUserSwitch.visibility).isEqualTo(View.VISIBLE)
-    }
-
-    @Test
-    fun testMultiUserSettingNotListenedAfterDetach() {
-        testableLooper.processAllMessages()
-
-        val multiUserSwitch = view.requireViewById<View>(R.id.multi_user_switch)
-        assertThat(multiUserSwitch.visibility).isNotEqualTo(View.VISIBLE)
-
-        ViewUtils.detachView(view)
-
-        // The setting is only used as an indicator for whether the view should refresh. The actual
-        // value of the setting is ignored; isMultiUserEnabled is the source of truth
-        whenever(multiUserSwitchController.isMultiUserEnabled).thenReturn(true)
-
-        // Changing the value of USER_SWITCHER_ENABLED should cause the view to update
-        fakeSettings.putIntForUser(Settings.Global.USER_SWITCHER_ENABLED, 1, userTracker.userId)
-        testableLooper.processAllMessages()
-
-        assertThat(multiUserSwitch.visibility).isNotEqualTo(View.VISIBLE)
-    }
-
-    @Test
-    fun testCleanUpGAD() {
-        reset(globalActionsDialogProvider)
-        // We are creating a new controller, so detach the views from it
-        (securityFooter.parent as ViewGroup).removeView(securityFooter)
-        (fgsFooter.parent as ViewGroup).removeView(fgsFooter)
-
-        whenever(globalActionsDialogProvider.get()).thenReturn(globalActionsDialog)
-        val view = inflateView()
-        controller = constructFooterActionsController(view)
-        controller.init()
-        verify(globalActionsDialogProvider, never()).get()
-
-        // GAD is constructed during attachment
-        ViewUtils.attachView(view)
-        testableLooper.processAllMessages()
-        verify(globalActionsDialogProvider).get()
-
-        ViewUtils.detachView(view)
-        testableLooper.processAllMessages()
-        verify(globalActionsDialog).destroy()
-    }
-
-    @Test
-    fun testSeparatorVisibility_noneVisible_gone() {
-        verify(securityFooterController)
-            .setOnVisibilityChangedListener(capture(visibilityChangedCaptor))
-        val listener = visibilityChangedCaptor.value
-        val separator = controller.securityFootersSeparator
-
-        setVisibilities(securityFooterVisible = false, fgsFooterVisible = false, listener)
-        assertThat(separator.visibility).isEqualTo(View.GONE)
-    }
-
-    @Test
-    fun testSeparatorVisibility_onlySecurityFooterVisible_gone() {
-        verify(securityFooterController)
-            .setOnVisibilityChangedListener(capture(visibilityChangedCaptor))
-        val listener = visibilityChangedCaptor.value
-        val separator = controller.securityFootersSeparator
-
-        setVisibilities(securityFooterVisible = true, fgsFooterVisible = false, listener)
-        assertThat(separator.visibility).isEqualTo(View.GONE)
-    }
-
-    @Test
-    fun testSeparatorVisibility_onlyFgsFooterVisible_gone() {
-        verify(securityFooterController)
-            .setOnVisibilityChangedListener(capture(visibilityChangedCaptor))
-        val listener = visibilityChangedCaptor.value
-        val separator = controller.securityFootersSeparator
-
-        setVisibilities(securityFooterVisible = false, fgsFooterVisible = true, listener)
-        assertThat(separator.visibility).isEqualTo(View.GONE)
-    }
-
-    @Test
-    fun testSeparatorVisibility_bothVisible_visible() {
-        verify(securityFooterController)
-            .setOnVisibilityChangedListener(capture(visibilityChangedCaptor))
-        val listener = visibilityChangedCaptor.value
-        val separator = controller.securityFootersSeparator
-
-        setVisibilities(securityFooterVisible = true, fgsFooterVisible = true, listener)
-        assertThat(separator.visibility).isEqualTo(View.VISIBLE)
-    }
-
-    @Test
-    fun testFgsFooterCollapsed() {
-        verify(securityFooterController)
-            .setOnVisibilityChangedListener(capture(visibilityChangedCaptor))
-        val listener = visibilityChangedCaptor.value
-
-        val booleanCaptor = ArgumentCaptor.forClass(Boolean::class.java)
-
-        clearInvocations(fgsManagerController)
-        setVisibilities(securityFooterVisible = false, fgsFooterVisible = true, listener)
-        verify(fgsManagerController, atLeastOnce()).setCollapsed(capture(booleanCaptor))
-        assertThat(booleanCaptor.allValues.last()).isFalse()
-
-        clearInvocations(fgsManagerController)
-        setVisibilities(securityFooterVisible = true, fgsFooterVisible = true, listener)
-        verify(fgsManagerController, atLeastOnce()).setCollapsed(capture(booleanCaptor))
-        assertThat(booleanCaptor.allValues.last()).isTrue()
-    }
-
-    @Test
-    fun setExpansion_inSplitShade_alphaFollowsExpansion() {
-        enableSplitShade()
-
-        controller.setExpansion(0f)
-        expect.that(view.alpha).isEqualTo(0f)
-
-        controller.setExpansion(0.25f)
-        expect.that(view.alpha).isEqualTo(0.25f)
-
-        controller.setExpansion(0.5f)
-        expect.that(view.alpha).isEqualTo(0.5f)
-
-        controller.setExpansion(0.75f)
-        expect.that(view.alpha).isEqualTo(0.75f)
-
-        controller.setExpansion(1f)
-        expect.that(view.alpha).isEqualTo(1f)
-    }
-
-    @Test
-    fun setExpansion_inSplitShade_backgroundAlphaFollowsExpansion_with_0_9_delay() {
-        enableSplitShade()
-
-        controller.setExpansion(0f)
-        expect.that(view.backgroundAlphaFraction).isEqualTo(0f)
-
-        controller.setExpansion(0.5f)
-        expect.that(view.backgroundAlphaFraction).isEqualTo(0f)
-
-        controller.setExpansion(0.9f)
-        expect.that(view.backgroundAlphaFraction).isEqualTo(0f)
-
-        controller.setExpansion(0.91f)
-        expect.that(view.backgroundAlphaFraction).isWithin(FLOAT_TOLERANCE).of(0.1f)
-
-        controller.setExpansion(0.95f)
-        expect.that(view.backgroundAlphaFraction).isWithin(FLOAT_TOLERANCE).of(0.5f)
-
-        controller.setExpansion(1f)
-        expect.that(view.backgroundAlphaFraction).isEqualTo(1f)
-    }
-
-    @Test
-    fun setExpansion_inSingleShade_alphaFollowsExpansion_with_0_9_delay() {
-        disableSplitShade()
-
-        controller.setExpansion(0f)
-        expect.that(view.alpha).isEqualTo(0f)
-
-        controller.setExpansion(0.5f)
-        expect.that(view.alpha).isEqualTo(0f)
-
-        controller.setExpansion(0.9f)
-        expect.that(view.alpha).isEqualTo(0f)
-
-        controller.setExpansion(0.91f)
-        expect.that(view.alpha).isWithin(FLOAT_TOLERANCE).of(0.1f)
-
-        controller.setExpansion(0.95f)
-        expect.that(view.alpha).isWithin(FLOAT_TOLERANCE).of(0.5f)
-
-        controller.setExpansion(1f)
-        expect.that(view.alpha).isEqualTo(1f)
-    }
-
-    @Test
-    fun setExpansion_inSingleShade_backgroundAlphaAlways1() {
-        disableSplitShade()
-
-        controller.setExpansion(0f)
-        expect.that(view.backgroundAlphaFraction).isEqualTo(1f)
-
-        controller.setExpansion(0.5f)
-        expect.that(view.backgroundAlphaFraction).isEqualTo(1f)
-
-        controller.setExpansion(1f)
-        expect.that(view.backgroundAlphaFraction).isEqualTo(1f)
-    }
-
-    private fun setVisibilities(
-        securityFooterVisible: Boolean,
-        fgsFooterVisible: Boolean,
-        listener: VisibilityChangedDispatcher.OnVisibilityChangedListener
-    ) {
-        securityFooter.visibility = if (securityFooterVisible) View.VISIBLE else View.GONE
-        listener.onVisibilityChanged(securityFooter.visibility)
-        fgsFooter.visibility = if (fgsFooterVisible) View.VISIBLE else View.GONE
-        listener.onVisibilityChanged(fgsFooter.visibility)
-    }
-
-    private fun inflateView(): FooterActionsView {
-        return LayoutInflater.from(context).inflate(R.layout.footer_actions, null)
-            as FooterActionsView
-    }
-
-    private fun constructFooterActionsController(view: FooterActionsView): FooterActionsController {
-        return FooterActionsController(
-            view,
-            multiUserSwitchControllerFactory,
-            activityStarter,
-            userManager,
-            userTracker,
-            userInfoController,
-            deviceProvisionedController,
-            securityFooterController,
-            fgsManagerController,
-            falsingManager,
-            metricsLogger,
-            globalActionsDialogProvider,
-            uiEventLogger,
-            showPMLiteButton = true,
-            fakeSettings,
-            Handler(testableLooper.looper),
-            configurationController)
-    }
-
-    private fun enableSplitShade() {
-        setSplitShadeEnabled(true)
-    }
-
-    private fun disableSplitShade() {
-        setSplitShadeEnabled(false)
-    }
-
-    private fun setSplitShadeEnabled(enabled: Boolean) {
-        overrideResource(R.bool.config_use_split_notification_shade, enabled)
-        configurationController.notifyConfigurationChanged()
-    }
-}
-
-private const val FLOAT_TOLERANCE = 0.01f
-
-private val View.backgroundAlphaFraction: Float?
-    get() {
-        return if (background != null) {
-            background.alpha / 255f
-        } else {
-            null
-        }
-    }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java
index aedb935..ffe918d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java
@@ -25,6 +25,7 @@
 import static org.mockito.ArgumentMatchers.anyBoolean;
 import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.nullable;
 import static org.mockito.Mockito.clearInvocations;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
@@ -32,6 +33,7 @@
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import android.annotation.Nullable;
 import android.app.Fragment;
 import android.content.Context;
 import android.graphics.Rect;
@@ -42,6 +44,7 @@
 import android.view.View;
 import android.view.ViewGroup;
 
+import androidx.lifecycle.Lifecycle;
 import androidx.test.filters.SmallTest;
 
 import com.android.keyguard.BouncerPanelExpansionCalculator;
@@ -50,12 +53,12 @@
 import com.android.systemui.animation.ShadeInterpolation;
 import com.android.systemui.dump.DumpManager;
 import com.android.systemui.flags.FakeFeatureFlags;
-import com.android.systemui.flags.Flags;
 import com.android.systemui.media.controls.ui.MediaHost;
 import com.android.systemui.plugins.FalsingManager;
 import com.android.systemui.qs.customize.QSCustomizerController;
 import com.android.systemui.qs.dagger.QSFragmentComponent;
 import com.android.systemui.qs.external.TileServiceRequestController;
+import com.android.systemui.qs.footer.ui.binder.FooterActionsViewBinder;
 import com.android.systemui.qs.footer.ui.viewmodel.FooterActionsViewModel;
 import com.android.systemui.statusbar.CommandQueue;
 import com.android.systemui.statusbar.StatusBarState;
@@ -99,6 +102,8 @@
     @Mock private QSAnimator mQSAnimator;
     @Mock private SysuiStatusBarStateController mStatusBarStateController;
     @Mock private QSSquishinessController mSquishinessController;
+    @Mock private FooterActionsViewModel mFooterActionsViewModel;
+    @Mock private FooterActionsViewModel.Factory mFooterActionsViewModelFactory;
     private View mQsFragmentView;
 
     public QSFragmentTest() {
@@ -245,7 +250,8 @@
         fragment.setQsExpansion(expansion, panelExpansionFraction, proposedTranslation,
                 squishinessFraction);
 
-        verify(mQSFooterActionController).setExpansion(panelExpansionFraction);
+        verify(mFooterActionsViewModel).onQuickSettingsExpansionChanged(
+                panelExpansionFraction, /* isInSplitShade= */ true);
     }
 
     @Test
@@ -262,7 +268,8 @@
         fragment.setQsExpansion(expansion, panelExpansionFraction, proposedTranslation,
                 squishinessFraction);
 
-        verify(mQSFooterActionController).setExpansion(expansion);
+        verify(mFooterActionsViewModel).onQuickSettingsExpansionChanged(
+                expansion, /* isInSplitShade= */ false);
     }
 
     @Test
@@ -379,6 +386,13 @@
         assertThat(mQsFragmentView.getTranslationY()).isEqualTo(0);
     }
 
+    private Lifecycle.State getListeningAndVisibilityLifecycleState() {
+        return getFragment()
+                .getListeningAndVisibilityLifecycleOwner()
+                .getLifecycle()
+                .getCurrentState();
+    }
+
     @Test
     public void setListeningFalse_notVisible() {
         QSFragment fragment = resumeAndGetFragment();
@@ -387,7 +401,7 @@
 
         fragment.setListening(false);
         verify(mQSContainerImplController).setListening(false);
-        verify(mQSFooterActionController).setListening(false);
+        assertThat(getListeningAndVisibilityLifecycleState()).isEqualTo(Lifecycle.State.CREATED);
         verify(mQSPanelController).setListening(eq(false), anyBoolean());
     }
 
@@ -399,7 +413,7 @@
 
         fragment.setListening(true);
         verify(mQSContainerImplController).setListening(false);
-        verify(mQSFooterActionController).setListening(false);
+        assertThat(getListeningAndVisibilityLifecycleState()).isEqualTo(Lifecycle.State.STARTED);
         verify(mQSPanelController).setListening(eq(false), anyBoolean());
     }
 
@@ -411,7 +425,7 @@
 
         fragment.setListening(false);
         verify(mQSContainerImplController).setListening(false);
-        verify(mQSFooterActionController).setListening(false);
+        assertThat(getListeningAndVisibilityLifecycleState()).isEqualTo(Lifecycle.State.CREATED);
         verify(mQSPanelController).setListening(eq(false), anyBoolean());
     }
 
@@ -423,7 +437,7 @@
 
         fragment.setListening(true);
         verify(mQSContainerImplController).setListening(true);
-        verify(mQSFooterActionController).setListening(true);
+        assertThat(getListeningAndVisibilityLifecycleState()).isEqualTo(Lifecycle.State.RESUMED);
         verify(mQSPanelController).setListening(eq(true), anyBoolean());
     }
 
@@ -480,7 +494,6 @@
         setUpOther();
 
         FakeFeatureFlags featureFlags = new FakeFeatureFlags();
-        featureFlags.set(Flags.NEW_FOOTER_ACTIONS, false);
         return new QSFragment(
                 new RemoteInputQuickSettingsDisabler(
                         context, commandQueue, mock(ConfigurationController.class)),
@@ -495,8 +508,8 @@
                 mFalsingManager,
                 mock(DumpManager.class),
                 featureFlags,
-                mock(NewFooterActionsController.class),
-                mock(FooterActionsViewModel.Factory.class));
+                mock(FooterActionsController.class),
+                mFooterActionsViewModelFactory);
     }
 
     private void setUpOther() {
@@ -505,6 +518,7 @@
         when(mQSContainerImplController.getView()).thenReturn(mContainer);
         when(mQSPanelController.getTileLayout()).thenReturn(mQQsTileLayout);
         when(mQuickQSPanelController.getTileLayout()).thenReturn(mQsTileLayout);
+        when(mFooterActionsViewModelFactory.create(any())).thenReturn(mFooterActionsViewModel);
     }
 
     private void setUpMedia() {
@@ -519,15 +533,40 @@
                 .thenReturn(mQSPanelScrollView);
         when(mQsFragmentView.findViewById(R.id.header)).thenReturn(mHeader);
         when(mQsFragmentView.findViewById(android.R.id.edit)).thenReturn(new View(mContext));
+        when(mQsFragmentView.findViewById(R.id.qs_footer_actions)).thenAnswer(
+                invocation -> FooterActionsViewBinder.create(mContext));
     }
 
     private void setUpInflater() {
+        LayoutInflater realInflater = LayoutInflater.from(mContext);
+
         when(mLayoutInflater.cloneInContext(any(Context.class))).thenReturn(mLayoutInflater);
-        when(mLayoutInflater.inflate(anyInt(), any(ViewGroup.class), anyBoolean()))
-                .thenReturn(mQsFragmentView);
+        when(mLayoutInflater.inflate(anyInt(), nullable(ViewGroup.class), anyBoolean()))
+                .thenAnswer((invocation) -> inflate(realInflater, (int) invocation.getArgument(0),
+                        (ViewGroup) invocation.getArgument(1),
+                        (boolean) invocation.getArgument(2)));
+        when(mLayoutInflater.inflate(anyInt(), nullable(ViewGroup.class)))
+                .thenAnswer((invocation) -> inflate(realInflater, (int) invocation.getArgument(0),
+                        (ViewGroup) invocation.getArgument(1)));
         mContext.addMockSystemService(Context.LAYOUT_INFLATER_SERVICE, mLayoutInflater);
     }
 
+    private View inflate(LayoutInflater realInflater, int layoutRes, @Nullable ViewGroup root) {
+        return inflate(realInflater, layoutRes, root, root != null);
+    }
+
+    private View inflate(LayoutInflater realInflater, int layoutRes, @Nullable ViewGroup root,
+            boolean attachToRoot) {
+        if (layoutRes == R.layout.footer_actions
+                || layoutRes == R.layout.footer_actions_text_button
+                || layoutRes == R.layout.footer_actions_number_button
+                || layoutRes == R.layout.footer_actions_icon_button) {
+            return realInflater.inflate(layoutRes, root, attachToRoot);
+        }
+
+        return mQsFragmentView;
+    }
+
     private void setupQsComponent() {
         when(mQsComponentFactory.create(any(QSFragment.class))).thenReturn(mQsFragmentComponent);
         when(mQsFragmentComponent.getQSPanelController()).thenReturn(mQSPanelController);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerTest.kt
index 9f28708..5e082f6 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerTest.kt
@@ -1,9 +1,12 @@
 package com.android.systemui.qs
 
+import android.content.res.Configuration
 import android.test.suitebuilder.annotation.SmallTest
 import android.testing.AndroidTestingRunner
+import android.testing.TestableResources
 import com.android.internal.logging.MetricsLogger
 import com.android.internal.logging.UiEventLogger
+import com.android.systemui.R
 import com.android.systemui.SysuiTestCase
 import com.android.systemui.dump.DumpManager
 import com.android.systemui.flags.FeatureFlags
@@ -26,10 +29,11 @@
 import org.mockito.Mock
 import org.mockito.Mockito
 import org.mockito.Mockito.any
+import org.mockito.Mockito.never
 import org.mockito.Mockito.reset
 import org.mockito.Mockito.verify
-import org.mockito.Mockito.`when` as whenever
 import org.mockito.MockitoAnnotations
+import org.mockito.Mockito.`when` as whenever
 
 @SmallTest
 @RunWith(AndroidTestingRunner::class)
@@ -54,8 +58,11 @@
     @Mock private lateinit var otherTile: QSTile
     @Mock private lateinit var statusBarKeyguardViewManager: StatusBarKeyguardViewManager
     @Mock private lateinit var featureFlags: FeatureFlags
+    @Mock private lateinit var configuration: Configuration
+    @Mock private lateinit var pagedTileLayout: PagedTileLayout
 
     private lateinit var controller: QSPanelController
+    private val testableResources: TestableResources = mContext.orCreateTestableResources
 
     @Before
     fun setUp() {
@@ -63,7 +70,9 @@
 
         whenever(brightnessSliderFactory.create(any(), any())).thenReturn(brightnessSlider)
         whenever(brightnessControllerFactory.create(any())).thenReturn(brightnessController)
-        whenever(qsPanel.resources).thenReturn(mContext.orCreateTestableResources.resources)
+        testableResources.addOverride(R.bool.config_use_split_notification_shade, false)
+        whenever(qsPanel.resources).thenReturn(testableResources.resources)
+        whenever(qsPanel.getOrCreateTileLayout()).thenReturn(pagedTileLayout)
         whenever(statusBarKeyguardViewManager.isPrimaryBouncerInTransit()).thenReturn(false)
         whenever(qsPanel.setListening(anyBoolean())).then {
             whenever(qsPanel.isListening).thenReturn(it.getArgument(0))
@@ -121,4 +130,15 @@
         whenever(statusBarKeyguardViewManager.isPrimaryBouncerInTransit()).thenReturn(false)
         assertThat(controller.isBouncerInTransit()).isEqualTo(false)
     }
+
+    @Test
+    fun configurationChange_onlySplitShadeConfigChanges_tileAreRedistributed() {
+        testableResources.addOverride(R.bool.config_use_split_notification_shade, false)
+        controller.mOnConfigurationChangedListener.onConfigurationChange(configuration)
+        verify(pagedTileLayout, never()).forceTilesRedistribution()
+
+        testableResources.addOverride(R.bool.config_use_split_notification_shade, true)
+        controller.mOnConfigurationChangedListener.onConfigurationChange(configuration)
+        verify(pagedTileLayout).forceTilesRedistribution()
+    }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java
index 906c20b..88d7e9c 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java
@@ -17,52 +17,54 @@
 import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_DEFAULT;
 import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_FINANCED;
 
+import static com.google.common.truth.Truth.assertThat;
+
 import static junit.framework.Assert.assertEquals;
 import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertNull;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import android.annotation.IdRes;
 import android.app.AlertDialog;
 import android.app.admin.DevicePolicyManager;
-import android.content.BroadcastReceiver;
 import android.content.ComponentName;
 import android.content.DialogInterface;
-import android.content.Intent;
 import android.content.pm.UserInfo;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.VectorDrawable;
 import android.os.Handler;
 import android.os.Looper;
+import android.provider.DeviceConfig;
 import android.provider.Settings;
 import android.test.suitebuilder.annotation.SmallTest;
 import android.testing.AndroidTestingRunner;
-import android.testing.LayoutInflaterBuilder;
-import android.testing.TestableImageView;
 import android.testing.TestableLooper;
 import android.testing.TestableLooper.RunWithLooper;
-import android.testing.ViewUtils;
 import android.text.SpannableStringBuilder;
 import android.view.LayoutInflater;
 import android.view.View;
-import android.view.ViewGroup;
-import android.widget.FrameLayout;
 import android.widget.TextView;
 
+import androidx.annotation.Nullable;
+
 import com.android.systemui.R;
 import com.android.systemui.SysuiTestCase;
 import com.android.systemui.animation.DialogLaunchAnimator;
+import com.android.systemui.animation.Expandable;
 import com.android.systemui.broadcast.BroadcastDispatcher;
+import com.android.systemui.common.shared.model.Icon;
 import com.android.systemui.plugins.ActivityStarter;
+import com.android.systemui.qs.footer.domain.model.SecurityButtonConfig;
+import com.android.systemui.security.data.model.SecurityModel;
 import com.android.systemui.settings.UserTracker;
 import com.android.systemui.statusbar.policy.SecurityController;
 
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -71,8 +73,6 @@
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 
-import java.util.concurrent.atomic.AtomicInteger;
-
 /*
  * Compile and run the whole SystemUI test suite:
    runtest --path frameworks/base/packages/SystemUI/tests
@@ -96,11 +96,6 @@
             new ComponentName("TestDPC", "Test");
     private static final int DEFAULT_ICON_ID = R.drawable.ic_info_outline;
 
-    private ViewGroup mRootView;
-    private ViewGroup mSecurityFooterView;
-    private TextView mFooterText;
-    private TestableImageView mPrimaryFooterIcon;
-    private QSSecurityFooter mFooter;
     private QSSecurityFooterUtils mFooterUtils;
     @Mock
     private SecurityController mSecurityController;
@@ -121,59 +116,60 @@
         mTestableLooper = TestableLooper.get(this);
         Looper looper = mTestableLooper.getLooper();
         Handler mainHandler = new Handler(looper);
+        // TODO(b/259908270): remove
+        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER,
+                DevicePolicyManager.ADD_ISFINANCED_DEVICE_FLAG, "true",
+                /* makeDefault= */ false);
         when(mUserTracker.getUserInfo()).thenReturn(mock(UserInfo.class));
-        mSecurityFooterView = (ViewGroup) new LayoutInflaterBuilder(mContext)
-                .replace("ImageView", TestableImageView.class)
-                .build().inflate(R.layout.quick_settings_security_footer, null, false);
         mFooterUtils = new QSSecurityFooterUtils(getContext(),
                 getContext().getSystemService(DevicePolicyManager.class), mUserTracker,
                 mainHandler, mActivityStarter, mSecurityController, looper, mDialogLaunchAnimator);
-        mFooter = new QSSecurityFooter(mSecurityFooterView, mainHandler, mSecurityController,
-                looper, mBroadcastDispatcher, mFooterUtils);
-        mFooterText = mSecurityFooterView.findViewById(R.id.footer_text);
-        mPrimaryFooterIcon = mSecurityFooterView.findViewById(R.id.primary_footer_icon);
 
         when(mSecurityController.getDeviceOwnerComponentOnAnyUser())
                 .thenReturn(DEVICE_OWNER_COMPONENT);
+        when(mSecurityController.isFinancedDevice()).thenReturn(false);
+        // TODO(b/259908270): remove
         when(mSecurityController.getDeviceOwnerType(DEVICE_OWNER_COMPONENT))
                 .thenReturn(DEVICE_OWNER_TYPE_DEFAULT);
-
-        // mSecurityFooterView must have a ViewGroup parent so that
-        // DialogLaunchAnimator.Controller.fromView() does not return null.
-        mRootView = new FrameLayout(mContext);
-        mRootView.addView(mSecurityFooterView);
-        ViewUtils.attachView(mRootView);
-
-        mFooter.init();
     }
 
-    @After
-    public void tearDown() {
-        ViewUtils.detachView(mRootView);
+    @Nullable
+    private SecurityButtonConfig getButtonConfig() {
+        SecurityModel securityModel = SecurityModel.create(mSecurityController);
+        return mFooterUtils.getButtonConfig(securityModel);
+    }
+
+    private void assertIsDefaultIcon(Icon icon) {
+        assertIsIconResource(icon, DEFAULT_ICON_ID);
+    }
+
+    private void assertIsIconResource(Icon icon, @IdRes int res) {
+        assertThat(icon).isInstanceOf(Icon.Resource.class);
+        assertEquals(res, ((Icon.Resource) icon).getRes());
+    }
+
+    private void assertIsIconDrawable(Icon icon, Drawable drawable) {
+        assertThat(icon).isInstanceOf(Icon.Loaded.class);
+        assertEquals(drawable, ((Icon.Loaded) icon).getDrawable());
     }
 
     @Test
     public void testUnmanaged() {
         when(mSecurityController.isDeviceManaged()).thenReturn(false);
         when(mSecurityController.isProfileOwnerOfOrganizationOwnedDevice()).thenReturn(false);
-        mFooter.refreshState();
-
-        TestableLooper.get(this).processAllMessages();
-        assertEquals(View.GONE, mSecurityFooterView.getVisibility());
+        assertNull(getButtonConfig());
     }
 
     @Test
     public void testManagedNoOwnerName() {
         when(mSecurityController.isDeviceManaged()).thenReturn(true);
         when(mSecurityController.getDeviceOwnerOrganizationName()).thenReturn(null);
-        mFooter.refreshState();
 
-        TestableLooper.get(this).processAllMessages();
+        SecurityButtonConfig buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
         assertEquals(mContext.getString(R.string.quick_settings_disclosure_management),
-                     mFooterText.getText());
-        assertEquals(View.VISIBLE, mSecurityFooterView.getVisibility());
-        assertEquals(View.VISIBLE, mPrimaryFooterIcon.getVisibility());
-        assertEquals(DEFAULT_ICON_ID, mPrimaryFooterIcon.getLastImageResource());
+                     buttonConfig.getText());
+        assertIsDefaultIcon(buttonConfig.getIcon());
     }
 
     @Test
@@ -181,15 +177,13 @@
         when(mSecurityController.isDeviceManaged()).thenReturn(true);
         when(mSecurityController.getDeviceOwnerOrganizationName())
                 .thenReturn(MANAGING_ORGANIZATION);
-        mFooter.refreshState();
 
-        TestableLooper.get(this).processAllMessages();
+        SecurityButtonConfig buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
         assertEquals(mContext.getString(R.string.quick_settings_disclosure_named_management,
-                                        MANAGING_ORGANIZATION),
-                mFooterText.getText());
-        assertEquals(View.VISIBLE, mSecurityFooterView.getVisibility());
-        assertEquals(View.VISIBLE, mPrimaryFooterIcon.getVisibility());
-        assertEquals(DEFAULT_ICON_ID, mPrimaryFooterIcon.getLastImageResource());
+                        MANAGING_ORGANIZATION),
+                buttonConfig.getText());
+        assertIsDefaultIcon(buttonConfig.getIcon());
     }
 
     @Test
@@ -197,18 +191,18 @@
         when(mSecurityController.isDeviceManaged()).thenReturn(true);
         when(mSecurityController.getDeviceOwnerOrganizationName())
                 .thenReturn(MANAGING_ORGANIZATION);
+        when(mSecurityController.isFinancedDevice()).thenReturn(true);
+        // TODO(b/259908270): remove
         when(mSecurityController.getDeviceOwnerType(DEVICE_OWNER_COMPONENT))
                 .thenReturn(DEVICE_OWNER_TYPE_FINANCED);
 
-        mFooter.refreshState();
-
-        TestableLooper.get(this).processAllMessages();
+        SecurityButtonConfig buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
         assertEquals(mContext.getString(
-                R.string.quick_settings_financed_disclosure_named_management,
-                MANAGING_ORGANIZATION), mFooterText.getText());
-        assertEquals(View.VISIBLE, mSecurityFooterView.getVisibility());
-        assertEquals(View.VISIBLE, mPrimaryFooterIcon.getVisibility());
-        assertEquals(DEFAULT_ICON_ID, mPrimaryFooterIcon.getLastImageResource());
+                        R.string.quick_settings_financed_disclosure_named_management,
+                        MANAGING_ORGANIZATION),
+                buttonConfig.getText());
+        assertIsDefaultIcon(buttonConfig.getIcon());
     }
 
     @Test
@@ -220,21 +214,16 @@
         when(mUserTracker.getUserInfo()).thenReturn(mockUserInfo);
         Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.DEVICE_DEMO_MODE, 1);
 
-        mFooter.refreshState();
-
-        TestableLooper.get(this).processAllMessages();
-        assertEquals(View.GONE, mSecurityFooterView.getVisibility());
+        assertNull(getButtonConfig());
     }
 
     @Test
     public void testUntappableView_profileOwnerOfOrgOwnedDevice() {
         when(mSecurityController.isProfileOwnerOfOrganizationOwnedDevice()).thenReturn(true);
 
-        mFooter.refreshState();
-
-        TestableLooper.get(this).processAllMessages();
-        assertFalse(mSecurityFooterView.isClickable());
-        assertEquals(View.GONE, mSecurityFooterView.findViewById(R.id.footer_icon).getVisibility());
+        SecurityButtonConfig buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
+        assertFalse(buttonConfig.isClickable());
     }
 
     @Test
@@ -244,12 +233,9 @@
         when(mSecurityController.isWorkProfileOn()).thenReturn(true);
         when(mSecurityController.hasWorkProfile()).thenReturn(true);
 
-        mFooter.refreshState();
-
-        TestableLooper.get(this).processAllMessages();
-        assertTrue(mSecurityFooterView.isClickable());
-        assertEquals(View.VISIBLE,
-                mSecurityFooterView.findViewById(R.id.footer_icon).getVisibility());
+        SecurityButtonConfig buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
+        assertTrue(buttonConfig.isClickable());
     }
 
     @Test
@@ -258,35 +244,31 @@
         when(mSecurityController.isNetworkLoggingEnabled()).thenReturn(true);
         when(mSecurityController.isWorkProfileOn()).thenReturn(false);
 
-        mFooter.refreshState();
-
-        TestableLooper.get(this).processAllMessages();
-        assertFalse(mSecurityFooterView.isClickable());
-        assertEquals(View.GONE, mSecurityFooterView.findViewById(R.id.footer_icon).getVisibility());
+        SecurityButtonConfig buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
+        assertFalse(buttonConfig.isClickable());
     }
 
     @Test
     public void testNetworkLoggingEnabled_deviceOwner() {
         when(mSecurityController.isDeviceManaged()).thenReturn(true);
         when(mSecurityController.isNetworkLoggingEnabled()).thenReturn(true);
-        mFooter.refreshState();
 
-        TestableLooper.get(this).processAllMessages();
+        SecurityButtonConfig buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
         assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_monitoring),
-                mFooterText.getText());
-        assertEquals(View.VISIBLE, mPrimaryFooterIcon.getVisibility());
-        assertEquals(DEFAULT_ICON_ID, mPrimaryFooterIcon.getLastImageResource());
+                buttonConfig.getText());
+        assertIsDefaultIcon(buttonConfig.getIcon());
 
         // Same situation, but with organization name set
         when(mSecurityController.getDeviceOwnerOrganizationName())
                 .thenReturn(MANAGING_ORGANIZATION);
-        mFooter.refreshState();
-
-        TestableLooper.get(this).processAllMessages();
+        buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
         assertEquals(mContext.getString(
-                             R.string.quick_settings_disclosure_named_management_monitoring,
-                             MANAGING_ORGANIZATION),
-                     mFooterText.getText());
+                        R.string.quick_settings_disclosure_named_management_monitoring,
+                        MANAGING_ORGANIZATION),
+                buttonConfig.getText());
     }
 
     @Test
@@ -294,12 +276,12 @@
         when(mSecurityController.hasWorkProfile()).thenReturn(true);
         when(mSecurityController.isNetworkLoggingEnabled()).thenReturn(true);
         when(mSecurityController.isWorkProfileOn()).thenReturn(true);
-        mFooter.refreshState();
 
-        TestableLooper.get(this).processAllMessages();
+        SecurityButtonConfig buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
         assertEquals(mContext.getString(
-                R.string.quick_settings_disclosure_managed_profile_network_activity),
-                mFooterText.getText());
+                        R.string.quick_settings_disclosure_managed_profile_network_activity),
+                buttonConfig.getText());
     }
 
     @Test
@@ -307,21 +289,19 @@
         when(mSecurityController.hasWorkProfile()).thenReturn(true);
         when(mSecurityController.isNetworkLoggingEnabled()).thenReturn(true);
         when(mSecurityController.isWorkProfileOn()).thenReturn(false);
-        mFooter.refreshState();
 
-        TestableLooper.get(this).processAllMessages();
-        assertEquals("", mFooterText.getText());
+        assertNull(getButtonConfig());
     }
 
     @Test
     public void testManagedCACertsInstalled() {
         when(mSecurityController.isDeviceManaged()).thenReturn(true);
         when(mSecurityController.hasCACertInCurrentUser()).thenReturn(true);
-        mFooter.refreshState();
 
-        TestableLooper.get(this).processAllMessages();
+        SecurityButtonConfig buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
         assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_monitoring),
-                mFooterText.getText());
+                buttonConfig.getText());
     }
 
     @Test
@@ -329,25 +309,23 @@
         when(mSecurityController.isDeviceManaged()).thenReturn(true);
         when(mSecurityController.isVpnEnabled()).thenReturn(true);
         when(mSecurityController.getPrimaryVpnName()).thenReturn(VPN_PACKAGE);
-        mFooter.refreshState();
 
-        TestableLooper.get(this).processAllMessages();
+        SecurityButtonConfig buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
         assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_named_vpn,
-                                        VPN_PACKAGE),
-                     mFooterText.getText());
-        assertEquals(View.VISIBLE, mPrimaryFooterIcon.getVisibility());
-        assertEquals(R.drawable.stat_sys_vpn_ic, mPrimaryFooterIcon.getLastImageResource());
+                        VPN_PACKAGE),
+                buttonConfig.getText());
+        assertIsIconResource(buttonConfig.getIcon(), R.drawable.stat_sys_vpn_ic);
 
         // Same situation, but with organization name set
         when(mSecurityController.getDeviceOwnerOrganizationName())
                 .thenReturn(MANAGING_ORGANIZATION);
-        mFooter.refreshState();
-
-        TestableLooper.get(this).processAllMessages();
+        buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
         assertEquals(mContext.getString(
-                              R.string.quick_settings_disclosure_named_management_named_vpn,
-                              MANAGING_ORGANIZATION, VPN_PACKAGE),
-                     mFooterText.getText());
+                        R.string.quick_settings_disclosure_named_management_named_vpn,
+                        MANAGING_ORGANIZATION, VPN_PACKAGE),
+                buttonConfig.getText());
     }
 
     @Test
@@ -356,23 +334,21 @@
         when(mSecurityController.isVpnEnabled()).thenReturn(true);
         when(mSecurityController.getPrimaryVpnName()).thenReturn(VPN_PACKAGE);
         when(mSecurityController.getWorkProfileVpnName()).thenReturn(VPN_PACKAGE_2);
-        mFooter.refreshState();
 
-        TestableLooper.get(this).processAllMessages();
+        SecurityButtonConfig buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
         assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_vpns),
-                     mFooterText.getText());
-        assertEquals(View.VISIBLE, mPrimaryFooterIcon.getVisibility());
-        assertEquals(R.drawable.stat_sys_vpn_ic, mPrimaryFooterIcon.getLastImageResource());
+                     buttonConfig.getText());
+        assertIsIconResource(buttonConfig.getIcon(), R.drawable.stat_sys_vpn_ic);
 
         // Same situation, but with organization name set
         when(mSecurityController.getDeviceOwnerOrganizationName())
                 .thenReturn(MANAGING_ORGANIZATION);
-        mFooter.refreshState();
-
-        TestableLooper.get(this).processAllMessages();
+        buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
         assertEquals(mContext.getString(R.string.quick_settings_disclosure_named_management_vpns,
                                         MANAGING_ORGANIZATION),
-                     mFooterText.getText());
+                     buttonConfig.getText());
     }
 
     @Test
@@ -381,13 +357,12 @@
         when(mSecurityController.isNetworkLoggingEnabled()).thenReturn(true);
         when(mSecurityController.isVpnEnabled()).thenReturn(true);
         when(mSecurityController.getPrimaryVpnName()).thenReturn("VPN Test App");
-        mFooter.refreshState();
 
-        TestableLooper.get(this).processAllMessages();
-        assertEquals(View.VISIBLE, mPrimaryFooterIcon.getVisibility());
-        assertEquals(R.drawable.stat_sys_vpn_ic, mPrimaryFooterIcon.getLastImageResource());
+        SecurityButtonConfig buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
+        assertIsIconResource(buttonConfig.getIcon(), R.drawable.stat_sys_vpn_ic);
         assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_monitoring),
-                mFooterText.getText());
+                buttonConfig.getText());
     }
 
     @Test
@@ -395,24 +370,23 @@
         when(mSecurityController.isDeviceManaged()).thenReturn(false);
         when(mSecurityController.hasCACertInWorkProfile()).thenReturn(true);
         when(mSecurityController.isWorkProfileOn()).thenReturn(true);
-        mFooter.refreshState();
 
-        TestableLooper.get(this).processAllMessages();
-        assertEquals(DEFAULT_ICON_ID, mPrimaryFooterIcon.getLastImageResource());
+        SecurityButtonConfig buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
+        assertIsDefaultIcon(buttonConfig.getIcon());
         assertEquals(mContext.getString(
                              R.string.quick_settings_disclosure_managed_profile_monitoring),
-                     mFooterText.getText());
+                     buttonConfig.getText());
 
         // Same situation, but with organization name set
         when(mSecurityController.getWorkProfileOrganizationName())
                 .thenReturn(MANAGING_ORGANIZATION);
-        mFooter.refreshState();
-
-        TestableLooper.get(this).processAllMessages();
+        buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
         assertEquals(mContext.getString(
                              R.string.quick_settings_disclosure_named_managed_profile_monitoring,
                              MANAGING_ORGANIZATION),
-                     mFooterText.getText());
+                     buttonConfig.getText());
     }
 
     @Test
@@ -420,22 +394,20 @@
         when(mSecurityController.isDeviceManaged()).thenReturn(false);
         when(mSecurityController.hasCACertInWorkProfile()).thenReturn(true);
         when(mSecurityController.isWorkProfileOn()).thenReturn(false);
-        mFooter.refreshState();
 
-        TestableLooper.get(this).processAllMessages();
-        assertEquals("", mFooterText.getText());
+        assertNull(getButtonConfig());
     }
 
     @Test
     public void testCACertsInstalled() {
         when(mSecurityController.isDeviceManaged()).thenReturn(false);
         when(mSecurityController.hasCACertInCurrentUser()).thenReturn(true);
-        mFooter.refreshState();
 
-        TestableLooper.get(this).processAllMessages();
-        assertEquals(DEFAULT_ICON_ID, mPrimaryFooterIcon.getLastImageResource());
+        SecurityButtonConfig buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
+        assertIsDefaultIcon(buttonConfig.getIcon());
         assertEquals(mContext.getString(R.string.quick_settings_disclosure_monitoring),
-                     mFooterText.getText());
+                     buttonConfig.getText());
     }
 
     @Test
@@ -443,12 +415,12 @@
         when(mSecurityController.isVpnEnabled()).thenReturn(true);
         when(mSecurityController.getPrimaryVpnName()).thenReturn(VPN_PACKAGE);
         when(mSecurityController.getWorkProfileVpnName()).thenReturn(VPN_PACKAGE_2);
-        mFooter.refreshState();
 
-        TestableLooper.get(this).processAllMessages();
-        assertEquals(R.drawable.stat_sys_vpn_ic, mPrimaryFooterIcon.getLastImageResource());
+        SecurityButtonConfig buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
+        assertIsIconResource(buttonConfig.getIcon(), R.drawable.stat_sys_vpn_ic);
         assertEquals(mContext.getString(R.string.quick_settings_disclosure_vpns),
-                     mFooterText.getText());
+                     buttonConfig.getText());
     }
 
     @Test
@@ -456,14 +428,14 @@
         when(mSecurityController.isVpnEnabled()).thenReturn(true);
         when(mSecurityController.getWorkProfileVpnName()).thenReturn(VPN_PACKAGE_2);
         when(mSecurityController.isWorkProfileOn()).thenReturn(true);
-        mFooter.refreshState();
 
-        TestableLooper.get(this).processAllMessages();
-        assertEquals(R.drawable.stat_sys_vpn_ic, mPrimaryFooterIcon.getLastImageResource());
+        SecurityButtonConfig buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
+        assertIsIconResource(buttonConfig.getIcon(), R.drawable.stat_sys_vpn_ic);
         assertEquals(mContext.getString(
                              R.string.quick_settings_disclosure_managed_profile_named_vpn,
                              VPN_PACKAGE_2),
-                     mFooterText.getText());
+                     buttonConfig.getText());
     }
 
     @Test
@@ -471,22 +443,19 @@
         when(mSecurityController.isVpnEnabled()).thenReturn(true);
         when(mSecurityController.getWorkProfileVpnName()).thenReturn(VPN_PACKAGE_2);
         when(mSecurityController.isWorkProfileOn()).thenReturn(false);
-        mFooter.refreshState();
 
-        TestableLooper.get(this).processAllMessages();
-        assertEquals("", mFooterText.getText());
+        assertNull(getButtonConfig());
     }
 
     @Test
     public void testProfileOwnerOfOrganizationOwnedDeviceNoName() {
         when(mSecurityController.isProfileOwnerOfOrganizationOwnedDevice()).thenReturn(true);
 
-        mFooter.refreshState();
-        TestableLooper.get(this).processAllMessages();
-
+        SecurityButtonConfig buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
         assertEquals(mContext.getString(
                 R.string.quick_settings_disclosure_management),
-                mFooterText.getText());
+                buttonConfig.getText());
     }
 
     @Test
@@ -495,35 +464,33 @@
         when(mSecurityController.getWorkProfileOrganizationName())
                 .thenReturn(MANAGING_ORGANIZATION);
 
-        mFooter.refreshState();
-        TestableLooper.get(this).processAllMessages();
-
+        SecurityButtonConfig buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
         assertEquals(mContext.getString(
                 R.string.quick_settings_disclosure_named_management,
                 MANAGING_ORGANIZATION),
-                mFooterText.getText());
+                buttonConfig.getText());
     }
 
     @Test
     public void testVpnEnabled() {
         when(mSecurityController.isVpnEnabled()).thenReturn(true);
         when(mSecurityController.getPrimaryVpnName()).thenReturn(VPN_PACKAGE);
-        mFooter.refreshState();
 
-        TestableLooper.get(this).processAllMessages();
-        assertEquals(R.drawable.stat_sys_vpn_ic, mPrimaryFooterIcon.getLastImageResource());
+        SecurityButtonConfig buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
+        assertIsIconResource(buttonConfig.getIcon(), R.drawable.stat_sys_vpn_ic);
         assertEquals(mContext.getString(R.string.quick_settings_disclosure_named_vpn,
                                         VPN_PACKAGE),
-                     mFooterText.getText());
+                     buttonConfig.getText());
 
         when(mSecurityController.hasWorkProfile()).thenReturn(true);
-        mFooter.refreshState();
-
-        TestableLooper.get(this).processAllMessages();
+        buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
         assertEquals(mContext.getString(
                              R.string.quick_settings_disclosure_personal_profile_named_vpn,
                              VPN_PACKAGE),
-                     mFooterText.getText());
+                     buttonConfig.getText());
     }
 
     @Test
@@ -537,6 +504,8 @@
     @Test
     public void testGetManagementTitleForFinancedDevice() {
         when(mSecurityController.isDeviceManaged()).thenReturn(true);
+        when(mSecurityController.isFinancedDevice()).thenReturn(true);
+        // TODO(b/259908270): remove
         when(mSecurityController.getDeviceOwnerType(DEVICE_OWNER_COMPONENT))
                 .thenReturn(DEVICE_OWNER_TYPE_FINANCED);
 
@@ -566,6 +535,8 @@
     @Test
     public void testGetManagementMessage_deviceOwner_asFinancedDevice() {
         when(mSecurityController.isDeviceManaged()).thenReturn(true);
+        when(mSecurityController.isFinancedDevice()).thenReturn(true);
+        // TODO(b/259908270): remove
         when(mSecurityController.getDeviceOwnerType(DEVICE_OWNER_COMPONENT))
                 .thenReturn(DEVICE_OWNER_TYPE_FINANCED);
 
@@ -687,19 +658,6 @@
     }
 
     @Test
-    public void testNoClickWhenGone() {
-        mFooter.refreshState();
-
-        TestableLooper.get(this).processAllMessages();
-
-        assertFalse(mFooter.hasFooter());
-        mFooter.onClick(mFooter.getView());
-
-        // Proxy for dialog being created
-        verify(mDialogLaunchAnimator, never()).showFromView(any(), any());
-    }
-
-    @Test
     public void testParentalControls() {
         // Make sure the security footer is visible, so that the images are updated.
         when(mSecurityController.isProfileOwnerOfOrganizationOwnedDevice()).thenReturn(true);
@@ -707,29 +665,26 @@
 
         // We use the default icon when there is no admin icon.
         when(mSecurityController.getIcon(any())).thenReturn(null);
-        mFooter.refreshState();
-        TestableLooper.get(this).processAllMessages();
+        SecurityButtonConfig buttonConfig = getButtonConfig();
         assertEquals(mContext.getString(R.string.quick_settings_disclosure_parental_controls),
-                mFooterText.getText());
-        assertEquals(DEFAULT_ICON_ID, mPrimaryFooterIcon.getLastImageResource());
+                buttonConfig.getText());
+        assertIsDefaultIcon(buttonConfig.getIcon());
 
         Drawable testDrawable = new VectorDrawable();
         when(mSecurityController.getIcon(any())).thenReturn(testDrawable);
         assertNotNull(mSecurityController.getIcon(null));
 
-        mFooter.refreshState();
-        TestableLooper.get(this).processAllMessages();
-
+        buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
         assertEquals(mContext.getString(R.string.quick_settings_disclosure_parental_controls),
-                mFooterText.getText());
-        assertEquals(View.VISIBLE, mPrimaryFooterIcon.getVisibility());
-        assertEquals(testDrawable, mPrimaryFooterIcon.getDrawable());
+                buttonConfig.getText());
+        assertIsIconDrawable(buttonConfig.getIcon(), testDrawable);
 
         // Ensure the primary icon is back to default after parental controls are gone
         when(mSecurityController.isParentalControlsEnabled()).thenReturn(false);
-        mFooter.refreshState();
-        TestableLooper.get(this).processAllMessages();
-        assertEquals(DEFAULT_ICON_ID, mPrimaryFooterIcon.getLastImageResource());
+        buttonConfig = getButtonConfig();
+        assertNotNull(buttonConfig);
+        assertIsDefaultIcon(buttonConfig.getIcon());
     }
 
     @Test
@@ -743,20 +698,12 @@
     }
 
     @Test
-    public void testDialogUsesDialogLauncher() {
-        when(mSecurityController.isDeviceManaged()).thenReturn(true);
-        mFooter.onClick(mSecurityFooterView);
-
-        mTestableLooper.processAllMessages();
-
-        verify(mDialogLaunchAnimator).show(any(), any());
-    }
-
-    @Test
     public void testCreateDialogViewForFinancedDevice() {
         when(mSecurityController.isDeviceManaged()).thenReturn(true);
         when(mSecurityController.getDeviceOwnerOrganizationName())
                 .thenReturn(MANAGING_ORGANIZATION);
+        when(mSecurityController.isFinancedDevice()).thenReturn(true);
+        // TODO(b/259908270): remove
         when(mSecurityController.getDeviceOwnerType(DEVICE_OWNER_COMPONENT))
                 .thenReturn(DEVICE_OWNER_TYPE_FINANCED);
 
@@ -779,10 +726,15 @@
         when(mSecurityController.isDeviceManaged()).thenReturn(true);
         when(mSecurityController.getDeviceOwnerOrganizationName())
                 .thenReturn(MANAGING_ORGANIZATION);
+        when(mSecurityController.isFinancedDevice()).thenReturn(true);
+        // TODO(b/259908270): remove
         when(mSecurityController.getDeviceOwnerType(DEVICE_OWNER_COMPONENT))
                 .thenReturn(DEVICE_OWNER_TYPE_FINANCED);
 
-        mFooter.showDeviceMonitoringDialog();
+        Expandable expandable = mock(Expandable.class);
+        when(expandable.dialogLaunchController(any())).thenReturn(
+                mock(DialogLaunchAnimator.Controller.class));
+        mFooterUtils.showDeviceMonitoringDialog(getContext(), expandable);
         ArgumentCaptor<AlertDialog> dialogCaptor = ArgumentCaptor.forClass(AlertDialog.class);
 
         mTestableLooper.processAllMessages();
@@ -797,47 +749,6 @@
         dialog.dismiss();
     }
 
-    @Test
-    public void testVisibilityListener() {
-        final AtomicInteger lastVisibility = new AtomicInteger(-1);
-        VisibilityChangedDispatcher.OnVisibilityChangedListener listener = lastVisibility::set;
-
-        mFooter.setOnVisibilityChangedListener(listener);
-
-        when(mSecurityController.isDeviceManaged()).thenReturn(true);
-        mFooter.refreshState();
-        mTestableLooper.processAllMessages();
-        assertEquals(View.VISIBLE, lastVisibility.get());
-
-        when(mSecurityController.isDeviceManaged()).thenReturn(false);
-        mFooter.refreshState();
-        mTestableLooper.processAllMessages();
-        assertEquals(View.GONE, lastVisibility.get());
-    }
-
-    @Test
-    public void testBroadcastShowsDialog() {
-        // Setup dialog content
-        when(mSecurityController.isDeviceManaged()).thenReturn(true);
-        when(mSecurityController.getDeviceOwnerOrganizationName())
-                .thenReturn(MANAGING_ORGANIZATION);
-        when(mSecurityController.getDeviceOwnerType(DEVICE_OWNER_COMPONENT))
-                .thenReturn(DEVICE_OWNER_TYPE_FINANCED);
-
-        ArgumentCaptor<BroadcastReceiver> captor = ArgumentCaptor.forClass(BroadcastReceiver.class);
-        verify(mBroadcastDispatcher).registerReceiverWithHandler(captor.capture(), any(), any(),
-                any());
-
-        // Pretend view is not attached anymore.
-        mRootView.removeView(mSecurityFooterView);
-        captor.getValue().onReceive(mContext,
-                new Intent(DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG));
-        mTestableLooper.processAllMessages();
-
-        assertTrue(mFooterUtils.getDialog().isShowing());
-        mFooterUtils.getDialog().dismiss();
-    }
-
     private CharSequence addLink(CharSequence description) {
         final SpannableStringBuilder message = new SpannableStringBuilder();
         message.append(description);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/footer/ui/viewmodel/FooterActionsViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/footer/ui/viewmodel/FooterActionsViewModelTest.kt
index 47afa70..01411c9 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/footer/ui/viewmodel/FooterActionsViewModelTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/footer/ui/viewmodel/FooterActionsViewModelTest.kt
@@ -385,4 +385,86 @@
         underTest.onVisibilityChangeRequested(visible = true)
         assertThat(underTest.isVisible.value).isTrue()
     }
+
+    @Test
+    fun alpha_inSplitShade_followsExpansion() {
+        val underTest = utils.footerActionsViewModel()
+
+        underTest.onQuickSettingsExpansionChanged(0f, isInSplitShade = true)
+        assertThat(underTest.alpha.value).isEqualTo(0f)
+
+        underTest.onQuickSettingsExpansionChanged(0.25f, isInSplitShade = true)
+        assertThat(underTest.alpha.value).isEqualTo(0.25f)
+
+        underTest.onQuickSettingsExpansionChanged(0.5f, isInSplitShade = true)
+        assertThat(underTest.alpha.value).isEqualTo(0.5f)
+
+        underTest.onQuickSettingsExpansionChanged(0.75f, isInSplitShade = true)
+        assertThat(underTest.alpha.value).isEqualTo(0.75f)
+
+        underTest.onQuickSettingsExpansionChanged(1f, isInSplitShade = true)
+        assertThat(underTest.alpha.value).isEqualTo(1f)
+    }
+
+    @Test
+    fun backgroundAlpha_inSplitShade_followsExpansion_with_0_99_delay() {
+        val underTest = utils.footerActionsViewModel()
+        val floatTolerance = 0.01f
+
+        underTest.onQuickSettingsExpansionChanged(0f, isInSplitShade = true)
+        assertThat(underTest.backgroundAlpha.value).isEqualTo(0f)
+
+        underTest.onQuickSettingsExpansionChanged(0.5f, isInSplitShade = true)
+        assertThat(underTest.backgroundAlpha.value).isEqualTo(0f)
+
+        underTest.onQuickSettingsExpansionChanged(0.9f, isInSplitShade = true)
+        assertThat(underTest.backgroundAlpha.value).isEqualTo(0f)
+
+        underTest.onQuickSettingsExpansionChanged(0.991f, isInSplitShade = true)
+        assertThat(underTest.backgroundAlpha.value).isWithin(floatTolerance).of(0.1f)
+
+        underTest.onQuickSettingsExpansionChanged(0.995f, isInSplitShade = true)
+        assertThat(underTest.backgroundAlpha.value).isWithin(floatTolerance).of(0.5f)
+
+        underTest.onQuickSettingsExpansionChanged(1f, isInSplitShade = true)
+        assertThat(underTest.backgroundAlpha.value).isEqualTo(1f)
+    }
+
+    @Test
+    fun alpha_inSingleShade_followsExpansion_with_0_9_delay() {
+        val underTest = utils.footerActionsViewModel()
+        val floatTolerance = 0.01f
+
+        underTest.onQuickSettingsExpansionChanged(0f, isInSplitShade = false)
+        assertThat(underTest.alpha.value).isEqualTo(0f)
+
+        underTest.onQuickSettingsExpansionChanged(0.5f, isInSplitShade = false)
+        assertThat(underTest.alpha.value).isEqualTo(0f)
+
+        underTest.onQuickSettingsExpansionChanged(0.9f, isInSplitShade = false)
+        assertThat(underTest.alpha.value).isEqualTo(0f)
+
+        underTest.onQuickSettingsExpansionChanged(0.91f, isInSplitShade = false)
+        assertThat(underTest.alpha.value).isWithin(floatTolerance).of(0.1f)
+
+        underTest.onQuickSettingsExpansionChanged(0.95f, isInSplitShade = false)
+        assertThat(underTest.alpha.value).isWithin(floatTolerance).of(0.5f)
+
+        underTest.onQuickSettingsExpansionChanged(1f, isInSplitShade = false)
+        assertThat(underTest.alpha.value).isEqualTo(1f)
+    }
+
+    @Test
+    fun backgroundAlpha_inSingleShade_always1() {
+        val underTest = utils.footerActionsViewModel()
+
+        underTest.onQuickSettingsExpansionChanged(0f, isInSplitShade = false)
+        assertThat(underTest.backgroundAlpha.value).isEqualTo(1f)
+
+        underTest.onQuickSettingsExpansionChanged(0.5f, isInSplitShade = false)
+        assertThat(underTest.backgroundAlpha.value).isEqualTo(1f)
+
+        underTest.onQuickSettingsExpansionChanged(1f, isInSplitShade = false)
+        assertThat(underTest.backgroundAlpha.value).isEqualTo(1f)
+    }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/InternetTileTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/InternetTileTest.java
index d91baa5..80c39cf 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/InternetTileTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/InternetTileTest.java
@@ -23,6 +23,7 @@
 
 
 import android.os.Handler;
+import android.service.quicksettings.Tile;
 import android.testing.AndroidTestingRunner;
 import android.testing.TestableLooper;
 
@@ -38,6 +39,7 @@
 import com.android.systemui.qs.logging.QSLogger;
 import com.android.systemui.qs.tiles.dialog.InternetDialogFactory;
 import com.android.systemui.statusbar.connectivity.AccessPointController;
+import com.android.systemui.statusbar.connectivity.IconState;
 import com.android.systemui.statusbar.connectivity.NetworkController;
 
 import org.junit.Before;
@@ -113,4 +115,24 @@
             .isNotEqualTo(mContext.getString(R.string.quick_settings_networks_available));
         assertThat(mTile.getLastTileState()).isEqualTo(-1);
     }
+
+    @Test
+    public void setIsAirplaneMode_APM_enabled_wifi_disabled() {
+        IconState state = new IconState(true, 0, "");
+        mTile.mSignalCallback.setIsAirplaneMode(state);
+        mTestableLooper.processAllMessages();
+        assertThat(mTile.getState().state).isEqualTo(Tile.STATE_INACTIVE);
+        assertThat(mTile.getState().secondaryLabel)
+            .isEqualTo(mContext.getString(R.string.status_bar_airplane));
+    }
+
+    @Test
+    public void setIsAirplaneMode_APM_enabled_wifi_enabled() {
+        IconState state = new IconState(false, 0, "");
+        mTile.mSignalCallback.setIsAirplaneMode(state);
+        mTestableLooper.processAllMessages();
+        assertThat(mTile.getState().state).isEqualTo(Tile.STATE_ACTIVE);
+        assertThat(mTile.getState().secondaryLabel)
+            .isNotEqualTo(mContext.getString(R.string.status_bar_airplane));
+    }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogTest.java
index 3ae8428..b59005a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogTest.java
@@ -86,7 +86,8 @@
     private View mDialogView;
     private View mSubTitle;
     private LinearLayout mEthernet;
-    private LinearLayout mMobileDataToggle;
+    private LinearLayout mMobileDataLayout;
+    private Switch mMobileToggleSwitch;
     private LinearLayout mWifiToggle;
     private Switch mWifiToggleSwitch;
     private TextView mWifiToggleSummary;
@@ -135,7 +136,8 @@
         mDialogView = mInternetDialog.mDialogView;
         mSubTitle = mDialogView.requireViewById(R.id.internet_dialog_subtitle);
         mEthernet = mDialogView.requireViewById(R.id.ethernet_layout);
-        mMobileDataToggle = mDialogView.requireViewById(R.id.mobile_network_layout);
+        mMobileDataLayout = mDialogView.requireViewById(R.id.mobile_network_layout);
+        mMobileToggleSwitch = mDialogView.requireViewById(R.id.mobile_toggle);
         mWifiToggle = mDialogView.requireViewById(R.id.turn_on_wifi_layout);
         mWifiToggleSwitch = mDialogView.requireViewById(R.id.wifi_toggle);
         mWifiToggleSummary = mDialogView.requireViewById(R.id.wifi_toggle_summary);
@@ -236,7 +238,7 @@
 
         mInternetDialog.updateDialog(true);
 
-        assertThat(mMobileDataToggle.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mMobileDataLayout.getVisibility()).isEqualTo(View.GONE);
     }
 
     @Test
@@ -248,7 +250,7 @@
 
         mInternetDialog.updateDialog(true);
 
-        assertThat(mMobileDataToggle.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mMobileDataLayout.getVisibility()).isEqualTo(View.GONE);
 
         // Carrier network should be visible if airplane mode ON and Wi-Fi is ON.
         when(mInternetDialogController.isCarrierNetworkActive()).thenReturn(true);
@@ -257,7 +259,7 @@
 
         mInternetDialog.updateDialog(true);
 
-        assertThat(mMobileDataToggle.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(mMobileDataLayout.getVisibility()).isEqualTo(View.VISIBLE);
     }
 
     @Test
@@ -267,7 +269,7 @@
 
         mInternetDialog.updateDialog(true);
 
-        assertThat(mMobileDataToggle.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mMobileDataLayout.getVisibility()).isEqualTo(View.GONE);
     }
 
     @Test
@@ -279,7 +281,7 @@
 
         mInternetDialog.updateDialog(true);
 
-        assertThat(mMobileDataToggle.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(mMobileDataLayout.getVisibility()).isEqualTo(View.VISIBLE);
         assertThat(mAirplaneModeSummaryText.getVisibility()).isEqualTo(View.VISIBLE);
     }
 
@@ -316,6 +318,30 @@
     }
 
     @Test
+    public void updateDialog_mobileDataIsEnabled_checkMobileDataSwitch() {
+        doReturn(true).when(mInternetDialogController).hasActiveSubId();
+        when(mInternetDialogController.isCarrierNetworkActive()).thenReturn(true);
+        when(mInternetDialogController.isMobileDataEnabled()).thenReturn(true);
+        mMobileToggleSwitch.setChecked(false);
+
+        mInternetDialog.updateDialog(true);
+
+        assertThat(mMobileToggleSwitch.isChecked()).isTrue();
+    }
+
+    @Test
+    public void updateDialog_mobileDataIsNotChanged_checkMobileDataSwitch() {
+        doReturn(true).when(mInternetDialogController).hasActiveSubId();
+        when(mInternetDialogController.isCarrierNetworkActive()).thenReturn(true);
+        when(mInternetDialogController.isMobileDataEnabled()).thenReturn(false);
+        mMobileToggleSwitch.setChecked(false);
+
+        mInternetDialog.updateDialog(true);
+
+        assertThat(mMobileToggleSwitch.isChecked()).isFalse();
+    }
+
+    @Test
     public void updateDialog_wifiOnAndHasInternetWifi_showConnectedWifi() {
         mInternetDialog.dismissDialog();
         doReturn(true).when(mInternetDialogController).hasActiveSubId();
@@ -695,7 +721,7 @@
     private void setNetworkVisible(boolean ethernetVisible, boolean mobileDataVisible,
             boolean connectedWifiVisible) {
         mEthernet.setVisibility(ethernetVisible ? View.VISIBLE : View.GONE);
-        mMobileDataToggle.setVisibility(mobileDataVisible ? View.VISIBLE : View.GONE);
+        mMobileDataLayout.setVisibility(mobileDataVisible ? View.VISIBLE : View.GONE);
         mConnectedWifi.setVisibility(connectedWifiVisible ? View.VISIBLE : View.GONE);
     }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java
index 56a840c..3512749 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java
@@ -173,6 +173,7 @@
 
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
@@ -611,6 +612,7 @@
     }
 
     @Test
+    @Ignore("b/261472011 - Test appears inconsistent across environments")
     public void getVerticalSpaceForLockscreenNotifications_useLockIconBottomPadding_returnsSpaceAvailable() {
         setBottomPadding(/* stackScrollLayoutBottom= */ 180,
                 /* lockIconPadding= */ 20,
@@ -622,6 +624,7 @@
     }
 
     @Test
+    @Ignore("b/261472011 - Test appears inconsistent across environments")
     public void getVerticalSpaceForLockscreenNotifications_useIndicationBottomPadding_returnsSpaceAvailable() {
         setBottomPadding(/* stackScrollLayoutBottom= */ 180,
                 /* lockIconPadding= */ 0,
@@ -633,6 +636,7 @@
     }
 
     @Test
+    @Ignore("b/261472011 - Test appears inconsistent across environments")
     public void getVerticalSpaceForLockscreenNotifications_useAmbientBottomPadding_returnsSpaceAvailable() {
         setBottomPadding(/* stackScrollLayoutBottom= */ 180,
                 /* lockIconPadding= */ 0,
@@ -1098,6 +1102,17 @@
 
         mStatusBarStateController.setState(KEYGUARD);
 
+        assertThat(mNotificationPanelViewController.isQsExpanded()).isEqualTo(false);
+        assertThat(mNotificationPanelViewController.isQsExpandImmediate()).isEqualTo(false);
+    }
+
+    @Test
+    public void testLockedSplitShadeTransitioningToKeyguard_closesQS() {
+        enableSplitShade(true);
+        mStatusBarStateController.setState(SHADE_LOCKED);
+        mNotificationPanelViewController.setQsExpanded(true);
+
+        mStatusBarStateController.setState(KEYGUARD);
 
         assertThat(mNotificationPanelViewController.isQsExpanded()).isEqualTo(false);
         assertThat(mNotificationPanelViewController.isQsExpandImmediate()).isEqualTo(false);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/util/condition/ConditionMonitorTest.java b/packages/SystemUI/tests/src/com/android/systemui/shared/condition/ConditionMonitorTest.java
similarity index 92%
rename from packages/SystemUI/tests/src/com/android/systemui/util/condition/ConditionMonitorTest.java
rename to packages/SystemUI/tests/src/com/android/systemui/shared/condition/ConditionMonitorTest.java
index 17d81c8..7693fee 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/util/condition/ConditionMonitorTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/shared/condition/ConditionMonitorTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2021 The Android Open Source Project
+ * 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.
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.systemui.util.condition;
+package com.android.systemui.shared.condition;
 
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
@@ -68,13 +68,15 @@
         mConditionMonitor = new Monitor(mExecutor);
     }
 
-    public Monitor.Subscription.Builder getDefaultBuilder(Monitor.Callback callback) {
+    public Monitor.Subscription.Builder getDefaultBuilder(
+            Monitor.Callback callback) {
         return new Monitor.Subscription.Builder(callback)
                 .addConditions(mConditions);
     }
 
     private Condition createMockCondition() {
-        final Condition condition = Mockito.mock(Condition.class);
+        final Condition condition = Mockito.mock(
+                Condition.class);
         when(condition.isConditionSet()).thenReturn(true);
         return condition;
     }
@@ -83,11 +85,14 @@
     public void testOverridingCondition() {
         final Condition overridingCondition = createMockCondition();
         final Condition regularCondition = createMockCondition();
-        final Monitor.Callback callback = Mockito.mock(Monitor.Callback.class);
+        final Monitor.Callback callback = Mockito.mock(
+                Monitor.Callback.class);
 
-        final Monitor.Callback referenceCallback = Mockito.mock(Monitor.Callback.class);
+        final Monitor.Callback referenceCallback = Mockito.mock(
+                Monitor.Callback.class);
 
-        final Monitor monitor = new Monitor(mExecutor);
+        final Monitor
+                monitor = new Monitor(mExecutor);
 
         monitor.addSubscription(getDefaultBuilder(callback)
                 .addCondition(overridingCondition)
@@ -136,9 +141,11 @@
         final Condition overridingCondition = createMockCondition();
         final Condition overridingCondition2 = createMockCondition();
         final Condition regularCondition = createMockCondition();
-        final Monitor.Callback callback = Mockito.mock(Monitor.Callback.class);
+        final Monitor.Callback callback = Mockito.mock(
+                Monitor.Callback.class);
 
-        final Monitor monitor = new Monitor(mExecutor);
+        final Monitor
+                monitor = new Monitor(mExecutor);
 
         monitor.addSubscription(getDefaultBuilder(callback)
                 .addCondition(overridingCondition)
@@ -211,9 +218,11 @@
     public void addCallback_addSecondCallback_reportWithExistingValue() {
         final Monitor.Callback callback1 =
                 mock(Monitor.Callback.class);
-        final Condition condition = mock(Condition.class);
+        final Condition condition = mock(
+                Condition.class);
         when(condition.isConditionMet()).thenReturn(true);
-        final Monitor monitor = new Monitor(mExecutor);
+        final Monitor
+                monitor = new Monitor(mExecutor);
         monitor.addSubscription(new Monitor.Subscription.Builder(callback1)
                 .addCondition(condition)
                 .build());
@@ -229,8 +238,10 @@
 
     @Test
     public void addCallback_noConditions_reportAllConditionsMet() {
-        final Monitor monitor = new Monitor(mExecutor);
-        final Monitor.Callback callback = mock(Monitor.Callback.class);
+        final Monitor
+                monitor = new Monitor(mExecutor);
+        final Monitor.Callback callback = mock(
+                Monitor.Callback.class);
 
         monitor.addSubscription(new Monitor.Subscription.Builder(callback).build());
         mExecutor.runAllReady();
@@ -239,8 +250,10 @@
 
     @Test
     public void removeCallback_noFailureOnDoubleRemove() {
-        final Condition condition = mock(Condition.class);
-        final Monitor monitor = new Monitor(mExecutor);
+        final Condition condition = mock(
+                Condition.class);
+        final Monitor
+                monitor = new Monitor(mExecutor);
         final Monitor.Callback callback =
                 mock(Monitor.Callback.class);
         final Monitor.Subscription.Token token = monitor.addSubscription(
@@ -255,8 +268,10 @@
 
     @Test
     public void removeCallback_shouldNoLongerReceiveUpdate() {
-        final Condition condition = mock(Condition.class);
-        final Monitor monitor = new Monitor(mExecutor);
+        final Condition condition = mock(
+                Condition.class);
+        final Monitor
+                monitor = new Monitor(mExecutor);
         final Monitor.Callback callback =
                 mock(Monitor.Callback.class);
         final Monitor.Subscription.Token token = monitor.addSubscription(
diff --git a/packages/SystemUI/tests/src/com/android/systemui/util/condition/ConditionTest.java b/packages/SystemUI/tests/src/com/android/systemui/shared/condition/ConditionTest.java
similarity index 81%
rename from packages/SystemUI/tests/src/com/android/systemui/util/condition/ConditionTest.java
rename to packages/SystemUI/tests/src/com/android/systemui/shared/condition/ConditionTest.java
index 2878864..8443221 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/util/condition/ConditionTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/shared/condition/ConditionTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2021 The Android Open Source Project
+ * 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.
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.systemui.util.condition;
+package com.android.systemui.shared.condition;
 
 import static com.google.common.truth.Truth.assertThat;
 
@@ -47,16 +47,20 @@
 
     @Test
     public void addCallback_addFirstCallback_triggerStart() {
-        final Condition.Callback callback = mock(Condition.Callback.class);
+        final Condition.Callback callback = mock(
+                Condition.Callback.class);
         mCondition.addCallback(callback);
         verify(mCondition).start();
     }
 
     @Test
     public void addCallback_addMultipleCallbacks_triggerStartOnlyOnce() {
-        final Condition.Callback callback1 = mock(Condition.Callback.class);
-        final Condition.Callback callback2 = mock(Condition.Callback.class);
-        final Condition.Callback callback3 = mock(Condition.Callback.class);
+        final Condition.Callback callback1 = mock(
+                Condition.Callback.class);
+        final Condition.Callback callback2 = mock(
+                Condition.Callback.class);
+        final Condition.Callback callback3 = mock(
+                Condition.Callback.class);
 
         mCondition.addCallback(callback1);
         mCondition.addCallback(callback2);
@@ -67,12 +71,14 @@
 
     @Test
     public void addCallback_alreadyStarted_triggerUpdate() {
-        final Condition.Callback callback1 = mock(Condition.Callback.class);
+        final Condition.Callback callback1 = mock(
+                Condition.Callback.class);
         mCondition.addCallback(callback1);
 
         mCondition.fakeUpdateCondition(true);
 
-        final Condition.Callback callback2 = mock(Condition.Callback.class);
+        final Condition.Callback callback2 = mock(
+                Condition.Callback.class);
         mCondition.addCallback(callback2);
         verify(callback2).onConditionChanged(mCondition);
         assertThat(mCondition.isConditionMet()).isTrue();
@@ -80,7 +86,8 @@
 
     @Test
     public void removeCallback_removeLastCallback_triggerStop() {
-        final Condition.Callback callback = mock(Condition.Callback.class);
+        final Condition.Callback callback = mock(
+                Condition.Callback.class);
         mCondition.addCallback(callback);
         verify(mCondition, never()).stop();
 
@@ -92,7 +99,8 @@
     public void updateCondition_falseToTrue_reportTrue() {
         mCondition.fakeUpdateCondition(false);
 
-        final Condition.Callback callback = mock(Condition.Callback.class);
+        final Condition.Callback callback = mock(
+                Condition.Callback.class);
         mCondition.addCallback(callback);
 
         mCondition.fakeUpdateCondition(true);
@@ -104,7 +112,8 @@
     public void updateCondition_trueToFalse_reportFalse() {
         mCondition.fakeUpdateCondition(true);
 
-        final Condition.Callback callback = mock(Condition.Callback.class);
+        final Condition.Callback callback = mock(
+                Condition.Callback.class);
         mCondition.addCallback(callback);
 
         mCondition.fakeUpdateCondition(false);
@@ -116,7 +125,8 @@
     public void updateCondition_trueToTrue_reportNothing() {
         mCondition.fakeUpdateCondition(true);
 
-        final Condition.Callback callback = mock(Condition.Callback.class);
+        final Condition.Callback callback = mock(
+                Condition.Callback.class);
         mCondition.addCallback(callback);
 
         mCondition.fakeUpdateCondition(true);
@@ -127,7 +137,8 @@
     public void updateCondition_falseToFalse_reportNothing() {
         mCondition.fakeUpdateCondition(false);
 
-        final Condition.Callback callback = mock(Condition.Callback.class);
+        final Condition.Callback callback = mock(
+                Condition.Callback.class);
         mCondition.addCallback(callback);
 
         mCondition.fakeUpdateCondition(false);
@@ -149,7 +160,8 @@
         final Condition combinedCondition = mCondition.or(
                 new FakeCondition(/* initialValue= */ false));
 
-        final Condition.Callback callback = mock(Condition.Callback.class);
+        final Condition.Callback callback = mock(
+                Condition.Callback.class);
         combinedCondition.addCallback(callback);
 
         assertThat(combinedCondition.isConditionSet()).isTrue();
@@ -164,7 +176,8 @@
         final Condition combinedCondition = mCondition.or(
                 new FakeCondition(/* initialValue= */ true));
 
-        final Condition.Callback callback = mock(Condition.Callback.class);
+        final Condition.Callback callback = mock(
+                Condition.Callback.class);
         combinedCondition.addCallback(callback);
 
         assertThat(combinedCondition.isConditionSet()).isTrue();
@@ -179,7 +192,8 @@
         final Condition combinedCondition = mCondition.or(
                 new FakeCondition(/* initialValue= */ true));
 
-        final Condition.Callback callback = mock(Condition.Callback.class);
+        final Condition.Callback callback = mock(
+                Condition.Callback.class);
         combinedCondition.addCallback(callback);
 
         assertThat(combinedCondition.isConditionSet()).isTrue();
@@ -195,7 +209,8 @@
         final Condition combinedCondition = mCondition.or(
                 new FakeCondition(/* initialValue= */ null));
 
-        final Condition.Callback callback = mock(Condition.Callback.class);
+        final Condition.Callback callback = mock(
+                Condition.Callback.class);
         combinedCondition.addCallback(callback);
 
         assertThat(combinedCondition.isConditionSet()).isTrue();
@@ -211,7 +226,8 @@
         final Condition combinedCondition = mCondition.or(
                 new FakeCondition(/* initialValue= */ null));
 
-        final Condition.Callback callback = mock(Condition.Callback.class);
+        final Condition.Callback callback = mock(
+                Condition.Callback.class);
         combinedCondition.addCallback(callback);
 
         assertThat(combinedCondition.isConditionSet()).isFalse();
@@ -226,7 +242,8 @@
         final Condition combinedCondition = mCondition.and(
                 new FakeCondition(/* initialValue= */ false));
 
-        final Condition.Callback callback = mock(Condition.Callback.class);
+        final Condition.Callback callback = mock(
+                Condition.Callback.class);
         combinedCondition.addCallback(callback);
 
         assertThat(combinedCondition.isConditionSet()).isTrue();
@@ -241,7 +258,8 @@
         final Condition combinedCondition = mCondition.and(
                 new FakeCondition(/* initialValue= */ true));
 
-        final Condition.Callback callback = mock(Condition.Callback.class);
+        final Condition.Callback callback = mock(
+                Condition.Callback.class);
         combinedCondition.addCallback(callback);
 
         assertThat(combinedCondition.isConditionSet()).isTrue();
@@ -256,7 +274,8 @@
         final Condition combinedCondition = mCondition.and(
                 new FakeCondition(/* initialValue= */ false));
 
-        final Condition.Callback callback = mock(Condition.Callback.class);
+        final Condition.Callback callback = mock(
+                Condition.Callback.class);
         combinedCondition.addCallback(callback);
 
         assertThat(combinedCondition.isConditionSet()).isTrue();
@@ -272,7 +291,8 @@
         final Condition combinedCondition = mCondition.and(
                 new FakeCondition(/* initialValue= */ null));
 
-        final Condition.Callback callback = mock(Condition.Callback.class);
+        final Condition.Callback callback = mock(
+                Condition.Callback.class);
         combinedCondition.addCallback(callback);
 
         assertThat(combinedCondition.isConditionSet()).isFalse();
@@ -288,7 +308,8 @@
         final Condition combinedCondition = mCondition.and(
                 new FakeCondition(/* initialValue= */ null));
 
-        final Condition.Callback callback = mock(Condition.Callback.class);
+        final Condition.Callback callback = mock(
+                Condition.Callback.class);
         combinedCondition.addCallback(callback);
 
         assertThat(combinedCondition.isConditionSet()).isTrue();
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/util/condition/FakeCondition.java b/packages/SystemUI/tests/src/com/android/systemui/shared/condition/FakeCondition.java
similarity index 91%
rename from packages/SystemUI/tests/utils/src/com/android/systemui/util/condition/FakeCondition.java
rename to packages/SystemUI/tests/src/com/android/systemui/shared/condition/FakeCondition.java
index 07ed110..55a6d39 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/util/condition/FakeCondition.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/shared/condition/FakeCondition.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2021 The Android Open Source Project
+ * 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.
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.systemui.util.condition;
+package com.android.systemui.shared.condition;
 
 /**
  * Fake implementation of {@link Condition}, and provides a way for tests to update
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java
index c8a392b..63065a5 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java
@@ -75,6 +75,7 @@
 import android.os.Looper;
 import android.os.RemoteException;
 import android.os.UserManager;
+import android.provider.DeviceConfig;
 import android.testing.AndroidTestingRunner;
 import android.testing.TestableLooper;
 import android.view.ViewGroup;
@@ -217,6 +218,10 @@
         mTextView = new KeyguardIndicationTextView(mContext);
         mTextView.setAnimationsEnabled(false);
 
+        // TODO(b/259908270): remove
+        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER,
+                DevicePolicyManager.ADD_ISFINANCED_DEVICE_FLAG, "true",
+                /* makeDefault= */ false);
         mContext.addMockSystemService(Context.DEVICE_POLICY_SERVICE, mDevicePolicyManager);
         mContext.addMockSystemService(UserManager.class, mUserManager);
         mContext.addMockSystemService(Context.TRUST_SERVICE, mock(TrustManager.class));
@@ -238,8 +243,12 @@
         when(mDevicePolicyManager.getResources()).thenReturn(mDevicePolicyResourcesManager);
         when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser())
                 .thenReturn(DEVICE_OWNER_COMPONENT);
+        when(mDevicePolicyManager.isFinancedDevice()).thenReturn(false);
+        // TODO(b/259908270): remove
         when(mDevicePolicyManager.getDeviceOwnerType(DEVICE_OWNER_COMPONENT))
                 .thenReturn(DEVICE_OWNER_TYPE_DEFAULT);
+
+
         when(mDevicePolicyResourcesManager.getString(anyString(), any()))
                 .thenReturn(mDisclosureGeneric);
         when(mDevicePolicyResourcesManager.getString(anyString(), any(), anyString()))
@@ -489,6 +498,8 @@
         when(mKeyguardStateController.isShowing()).thenReturn(true);
         when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
         when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(ORGANIZATION_NAME);
+        when(mDevicePolicyManager.isFinancedDevice()).thenReturn(true);
+        // TODO(b/259908270): remove
         when(mDevicePolicyManager.getDeviceOwnerType(DEVICE_OWNER_COMPONENT))
                 .thenReturn(DEVICE_OWNER_TYPE_FINANCED);
         sendUpdateDisclosureBroadcast();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinatorTest.kt
index aa1114b..cb4f119 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinatorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinatorTest.kt
@@ -23,6 +23,7 @@
 import com.android.systemui.SysuiTestCase
 import com.android.systemui.dump.logcatLogBuffer
 import com.android.systemui.statusbar.NotificationRemoteInputManager
+import com.android.systemui.statusbar.notification.NotifPipelineFlags
 import com.android.systemui.statusbar.notification.collection.GroupEntryBuilder
 import com.android.systemui.statusbar.notification.collection.NotifPipeline
 import com.android.systemui.statusbar.notification.collection.NotificationEntry
@@ -38,6 +39,7 @@
 import com.android.systemui.statusbar.notification.collection.render.NodeController
 import com.android.systemui.statusbar.notification.interruption.HeadsUpViewBinder
 import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider
+import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider.FullScreenIntentDecision
 import com.android.systemui.statusbar.notification.row.NotifBindPipeline.BindCallback
 import com.android.systemui.statusbar.phone.NotificationGroupTestHelper
 import com.android.systemui.statusbar.policy.HeadsUpManager
@@ -88,6 +90,7 @@
     private val mEndLifetimeExtension: OnEndLifetimeExtensionCallback = mock()
     private val mHeaderController: NodeController = mock()
     private val mLaunchFullScreenIntentProvider: LaunchFullScreenIntentProvider = mock()
+    private val mFlags: NotifPipelineFlags = mock()
 
     private lateinit var mEntry: NotificationEntry
     private lateinit var mGroupSummary: NotificationEntry
@@ -113,6 +116,7 @@
             mNotificationInterruptStateProvider,
             mRemoteInputManager,
             mLaunchFullScreenIntentProvider,
+            mFlags,
             mHeaderController,
             mExecutor)
         mCoordinator.attach(mNotifPipeline)
@@ -246,14 +250,14 @@
 
     @Test
     fun testOnEntryAdded_shouldFullScreen() {
-        setShouldFullScreen(mEntry)
+        setShouldFullScreen(mEntry, FullScreenIntentDecision.FSI_EXPECTED_NOT_TO_HUN)
         mCollectionListener.onEntryAdded(mEntry)
         verify(mLaunchFullScreenIntentProvider).launchFullScreenIntent(mEntry)
     }
 
     @Test
     fun testOnEntryAdded_shouldNotFullScreen() {
-        setShouldFullScreen(mEntry, should = false)
+        setShouldFullScreen(mEntry, FullScreenIntentDecision.NO_FULL_SCREEN_INTENT)
         mCollectionListener.onEntryAdded(mEntry)
         verify(mLaunchFullScreenIntentProvider, never()).launchFullScreenIntent(any())
     }
@@ -805,15 +809,96 @@
         verify(mHeadsUpManager, never()).showNotification(any())
     }
 
+    @Test
+    fun testOnRankingApplied_noFSIOnUpdateWhenFlagOff() {
+        // Ensure the feature flag is off
+        whenever(mFlags.fsiOnDNDUpdate()).thenReturn(false)
+
+        // GIVEN that mEntry was previously suppressed from full-screen only by DND
+        setShouldFullScreen(mEntry, FullScreenIntentDecision.NO_FSI_SUPPRESSED_ONLY_BY_DND)
+        mCollectionListener.onEntryAdded(mEntry)
+
+        // and it is then updated to allow full screen
+        setShouldFullScreen(mEntry, FullScreenIntentDecision.FSI_DEVICE_NOT_INTERACTIVE)
+        whenever(mNotifPipeline.allNotifs).thenReturn(listOf(mEntry))
+        mCollectionListener.onRankingApplied()
+
+        // THEN it should not full screen because the feature is off
+        verify(mLaunchFullScreenIntentProvider, never()).launchFullScreenIntent(mEntry)
+    }
+
+    @Test
+    fun testOnRankingApplied_updateToFullScreen() {
+        // Turn on the feature
+        whenever(mFlags.fsiOnDNDUpdate()).thenReturn(true)
+
+        // GIVEN that mEntry was previously suppressed from full-screen only by DND
+        setShouldFullScreen(mEntry, FullScreenIntentDecision.NO_FSI_SUPPRESSED_ONLY_BY_DND)
+        mCollectionListener.onEntryAdded(mEntry)
+
+        // at this point, it should not have full screened
+        verify(mLaunchFullScreenIntentProvider, never()).launchFullScreenIntent(mEntry)
+
+        // and it is then updated to allow full screen AND HUN
+        setShouldFullScreen(mEntry, FullScreenIntentDecision.FSI_DEVICE_NOT_INTERACTIVE)
+        setShouldHeadsUp(mEntry)
+        whenever(mNotifPipeline.allNotifs).thenReturn(listOf(mEntry))
+        mCollectionListener.onRankingApplied()
+        mBeforeTransformGroupsListener.onBeforeTransformGroups(listOf(mEntry))
+        mBeforeFinalizeFilterListener.onBeforeFinalizeFilter(listOf(mEntry))
+
+        // THEN it should full screen but it should NOT HUN
+        verify(mLaunchFullScreenIntentProvider).launchFullScreenIntent(mEntry)
+        verify(mHeadsUpViewBinder, never()).bindHeadsUpView(any(), any())
+        verify(mHeadsUpManager, never()).showNotification(any())
+    }
+
+    @Test
+    fun testOnRankingApplied_noFSIWhenAlsoSuppressedForOtherReasons() {
+        // Feature on
+        whenever(mFlags.fsiOnDNDUpdate()).thenReturn(true)
+
+        // GIVEN that mEntry is suppressed by DND (functionally), but not *only* DND
+        setShouldFullScreen(mEntry, FullScreenIntentDecision.NO_FSI_SUPPRESSED_BY_DND)
+        mCollectionListener.onEntryAdded(mEntry)
+
+        // and it is updated to full screen later
+        setShouldFullScreen(mEntry, FullScreenIntentDecision.FSI_DEVICE_NOT_INTERACTIVE)
+        mCollectionListener.onRankingApplied()
+
+        // THEN it should still not full screen because something else was blocking it before
+        verify(mLaunchFullScreenIntentProvider, never()).launchFullScreenIntent(mEntry)
+    }
+
+    @Test
+    fun testOnRankingApplied_noFSIWhenTooOld() {
+        // Feature on
+        whenever(mFlags.fsiOnDNDUpdate()).thenReturn(true)
+
+        // GIVEN that mEntry is suppressed only by DND
+        setShouldFullScreen(mEntry, FullScreenIntentDecision.NO_FSI_SUPPRESSED_ONLY_BY_DND)
+        mCollectionListener.onEntryAdded(mEntry)
+
+        // but it's >10s old
+        mCoordinator.addForFSIReconsideration(mEntry, mSystemClock.currentTimeMillis() - 10000)
+
+        // and it is updated to full screen later
+        setShouldFullScreen(mEntry, FullScreenIntentDecision.FSI_EXPECTED_NOT_TO_HUN)
+        mCollectionListener.onRankingApplied()
+
+        // THEN it should still not full screen because it's too old
+        verify(mLaunchFullScreenIntentProvider, never()).launchFullScreenIntent(mEntry)
+    }
+
     private fun setShouldHeadsUp(entry: NotificationEntry, should: Boolean = true) {
         whenever(mNotificationInterruptStateProvider.shouldHeadsUp(entry)).thenReturn(should)
         whenever(mNotificationInterruptStateProvider.checkHeadsUp(eq(entry), any()))
                 .thenReturn(should)
     }
 
-    private fun setShouldFullScreen(entry: NotificationEntry, should: Boolean = true) {
-        whenever(mNotificationInterruptStateProvider.shouldLaunchFullScreenIntentWhenAdded(entry))
-            .thenReturn(should)
+    private fun setShouldFullScreen(entry: NotificationEntry, decision: FullScreenIntentDecision) {
+        whenever(mNotificationInterruptStateProvider.getFullScreenIntentDecision(entry))
+            .thenReturn(decision)
     }
 
     private fun finishBind(entry: NotificationEntry) {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinatorTest.kt
index 7f73856..5f19fac 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinatorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinatorTest.kt
@@ -17,6 +17,7 @@
 
 package com.android.systemui.statusbar.notification.collection.coordinator
 
+import android.app.Notification
 import android.testing.AndroidTestingRunner
 import androidx.test.filters.SmallTest
 import com.android.systemui.SysuiTestCase
@@ -33,6 +34,7 @@
 import com.android.systemui.statusbar.notification.collection.provider.SeenNotificationsProvider
 import com.android.systemui.statusbar.notification.collection.provider.SeenNotificationsProviderImpl
 import com.android.systemui.statusbar.notification.interruption.KeyguardNotificationVisibilityProvider
+import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
 import com.android.systemui.util.mockito.eq
 import com.android.systemui.util.mockito.mock
 import com.android.systemui.util.mockito.withArgCaptor
@@ -105,6 +107,50 @@
     }
 
     @Test
+    fun unseenFilterDoesNotSuppressSeenOngoingNotifWhileKeyguardShowing() {
+        whenever(notifPipelineFlags.shouldFilterUnseenNotifsOnKeyguard).thenReturn(true)
+
+        // GIVEN: Keyguard is not showing, and an ongoing notification is present
+        keyguardRepository.setKeyguardShowing(false)
+        runKeyguardCoordinatorTest {
+            val fakeEntry = NotificationEntryBuilder()
+                .setNotification(Notification.Builder(mContext).setOngoing(true).build())
+                .build()
+            collectionListener.onEntryAdded(fakeEntry)
+
+            // WHEN: The keyguard is now showing
+            keyguardRepository.setKeyguardShowing(true)
+            testScheduler.runCurrent()
+
+            // THEN: The notification is recognized as "ongoing" and is not filtered out.
+            assertThat(unseenFilter.shouldFilterOut(fakeEntry, 0L)).isFalse()
+        }
+    }
+
+    @Test
+    fun unseenFilterDoesNotSuppressSeenMediaNotifWhileKeyguardShowing() {
+        whenever(notifPipelineFlags.shouldFilterUnseenNotifsOnKeyguard).thenReturn(true)
+
+        // GIVEN: Keyguard is not showing, and a media notification is present
+        keyguardRepository.setKeyguardShowing(false)
+        runKeyguardCoordinatorTest {
+            val fakeEntry = NotificationEntryBuilder().build().apply {
+                row = mock<ExpandableNotificationRow>().apply {
+                    whenever(isMediaRow).thenReturn(true)
+                }
+            }
+            collectionListener.onEntryAdded(fakeEntry)
+
+            // WHEN: The keyguard is now showing
+            keyguardRepository.setKeyguardShowing(true)
+            testScheduler.runCurrent()
+
+            // THEN: The notification is recognized as "media" and is not filtered out.
+            assertThat(unseenFilter.shouldFilterOut(fakeEntry, 0L)).isFalse()
+        }
+    }
+
+    @Test
     fun unseenFilterUpdatesSeenProviderWhenSuppressing() {
         whenever(notifPipelineFlags.shouldFilterUnseenNotifsOnKeyguard).thenReturn(true)
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImplTest.java
index 21aae00..601771d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImplTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderImplTest.java
@@ -23,6 +23,7 @@
 import static android.app.NotificationManager.IMPORTANCE_HIGH;
 import static android.app.NotificationManager.IMPORTANCE_LOW;
 import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT;
+import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT;
 import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK;
 
 import static com.android.systemui.statusbar.NotificationEntryHelper.modifyRanking;
@@ -61,6 +62,7 @@
 import com.android.systemui.statusbar.notification.NotifPipelineFlags;
 import com.android.systemui.statusbar.notification.collection.NotificationEntry;
 import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder;
+import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider.FullScreenIntentDecision;
 import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProviderImpl.NotificationInterruptEvent;
 import com.android.systemui.statusbar.policy.BatteryController;
 import com.android.systemui.statusbar.policy.HeadsUpManager;
@@ -527,6 +529,8 @@
         when(mDreamManager.isDreaming()).thenReturn(false);
         when(mStatusBarStateController.getState()).thenReturn(SHADE);
 
+        assertThat(mNotifInterruptionStateProvider.getFullScreenIntentDecision(entry))
+                .isEqualTo(FullScreenIntentDecision.NO_FULL_SCREEN_INTENT);
         assertThat(mNotifInterruptionStateProvider.shouldLaunchFullScreenIntentWhenAdded(entry))
                 .isFalse();
         verify(mLogger, never()).logNoFullscreen(any(), any());
@@ -535,6 +539,44 @@
     }
 
     @Test
+    public void testShouldNotFullScreen_suppressedOnlyByDND() throws RemoteException {
+        NotificationEntry entry = createFsiNotification(IMPORTANCE_HIGH, /* silenced */ false);
+        modifyRanking(entry)
+                .setSuppressedVisualEffects(SUPPRESSED_EFFECT_FULL_SCREEN_INTENT)
+                .build();
+        when(mPowerManager.isInteractive()).thenReturn(false);
+        when(mDreamManager.isDreaming()).thenReturn(false);
+        when(mStatusBarStateController.getState()).thenReturn(SHADE);
+
+        assertThat(mNotifInterruptionStateProvider.getFullScreenIntentDecision(entry))
+                .isEqualTo(FullScreenIntentDecision.NO_FSI_SUPPRESSED_ONLY_BY_DND);
+        assertThat(mNotifInterruptionStateProvider.shouldLaunchFullScreenIntentWhenAdded(entry))
+                .isFalse();
+        verify(mLogger, never()).logFullscreen(any(), any());
+        verify(mLogger, never()).logNoFullscreenWarning(any(), any());
+        verify(mLogger).logNoFullscreen(entry, "Suppressed by DND");
+    }
+
+    @Test
+    public void testShouldNotFullScreen_suppressedByDNDAndOther() throws RemoteException {
+        NotificationEntry entry = createFsiNotification(IMPORTANCE_LOW, /* silenced */ false);
+        modifyRanking(entry)
+                .setSuppressedVisualEffects(SUPPRESSED_EFFECT_FULL_SCREEN_INTENT)
+                .build();
+        when(mPowerManager.isInteractive()).thenReturn(false);
+        when(mDreamManager.isDreaming()).thenReturn(false);
+        when(mStatusBarStateController.getState()).thenReturn(SHADE);
+
+        assertThat(mNotifInterruptionStateProvider.getFullScreenIntentDecision(entry))
+                .isEqualTo(FullScreenIntentDecision.NO_FSI_SUPPRESSED_BY_DND);
+        assertThat(mNotifInterruptionStateProvider.shouldLaunchFullScreenIntentWhenAdded(entry))
+                .isFalse();
+        verify(mLogger, never()).logFullscreen(any(), any());
+        verify(mLogger, never()).logNoFullscreenWarning(any(), any());
+        verify(mLogger).logNoFullscreen(entry, "Suppressed by DND");
+    }
+
+    @Test
     public void testShouldNotFullScreen_notHighImportance_withStrictFlag() throws Exception {
         when(mFlags.fullScreenIntentRequiresKeyguard()).thenReturn(true);
         testShouldNotFullScreen_notHighImportance();
@@ -547,6 +589,8 @@
         when(mDreamManager.isDreaming()).thenReturn(false);
         when(mStatusBarStateController.getState()).thenReturn(SHADE);
 
+        assertThat(mNotifInterruptionStateProvider.getFullScreenIntentDecision(entry))
+                .isEqualTo(FullScreenIntentDecision.NO_FSI_NOT_IMPORTANT_ENOUGH);
         assertThat(mNotifInterruptionStateProvider.shouldLaunchFullScreenIntentWhenAdded(entry))
                 .isFalse();
         verify(mLogger).logNoFullscreen(entry, "Not important enough");
@@ -567,6 +611,8 @@
         when(mDreamManager.isDreaming()).thenReturn(true);
         when(mStatusBarStateController.getState()).thenReturn(KEYGUARD);
 
+        assertThat(mNotifInterruptionStateProvider.getFullScreenIntentDecision(entry))
+                .isEqualTo(FullScreenIntentDecision.NO_FSI_SUPPRESSIVE_GROUP_ALERT_BEHAVIOR);
         assertThat(mNotifInterruptionStateProvider.shouldLaunchFullScreenIntentWhenAdded(entry))
                 .isFalse();
         verify(mLogger, never()).logNoFullscreen(any(), any());
@@ -594,6 +640,8 @@
         when(mDreamManager.isDreaming()).thenReturn(false);
         when(mStatusBarStateController.getState()).thenReturn(SHADE);
 
+        assertThat(mNotifInterruptionStateProvider.getFullScreenIntentDecision(entry))
+                .isEqualTo(FullScreenIntentDecision.FSI_DEVICE_NOT_INTERACTIVE);
         assertThat(mNotifInterruptionStateProvider.shouldLaunchFullScreenIntentWhenAdded(entry))
                 .isTrue();
         verify(mLogger, never()).logNoFullscreen(any(), any());
@@ -614,6 +662,8 @@
         when(mDreamManager.isDreaming()).thenReturn(true);
         when(mStatusBarStateController.getState()).thenReturn(SHADE);
 
+        assertThat(mNotifInterruptionStateProvider.getFullScreenIntentDecision(entry))
+                .isEqualTo(FullScreenIntentDecision.FSI_DEVICE_IS_DREAMING);
         assertThat(mNotifInterruptionStateProvider.shouldLaunchFullScreenIntentWhenAdded(entry))
                 .isTrue();
         verify(mLogger, never()).logNoFullscreen(any(), any());
@@ -634,6 +684,8 @@
         when(mDreamManager.isDreaming()).thenReturn(false);
         when(mStatusBarStateController.getState()).thenReturn(KEYGUARD);
 
+        assertThat(mNotifInterruptionStateProvider.getFullScreenIntentDecision(entry))
+                .isEqualTo(FullScreenIntentDecision.FSI_KEYGUARD_SHOWING);
         assertThat(mNotifInterruptionStateProvider.shouldLaunchFullScreenIntentWhenAdded(entry))
                 .isTrue();
         verify(mLogger, never()).logNoFullscreen(any(), any());
@@ -655,6 +707,8 @@
         when(mDreamManager.isDreaming()).thenReturn(false);
         when(mStatusBarStateController.getState()).thenReturn(SHADE);
 
+        assertThat(mNotifInterruptionStateProvider.getFullScreenIntentDecision(entry))
+                .isEqualTo(FullScreenIntentDecision.NO_FSI_EXPECTED_TO_HUN);
         assertThat(mNotifInterruptionStateProvider.shouldLaunchFullScreenIntentWhenAdded(entry))
                 .isFalse();
         verify(mLogger).logNoFullscreen(entry, "Expected to HUN");
@@ -671,9 +725,10 @@
         when(mStatusBarStateController.getState()).thenReturn(SHADE);
         when(mHeadsUpManager.isSnoozed("a")).thenReturn(true);
 
+        assertThat(mNotifInterruptionStateProvider.getFullScreenIntentDecision(entry))
+                .isEqualTo(FullScreenIntentDecision.FSI_EXPECTED_NOT_TO_HUN);
         assertThat(mNotifInterruptionStateProvider.shouldLaunchFullScreenIntentWhenAdded(entry))
                 .isTrue();
-        verify(mLogger).logNoHeadsUpPackageSnoozed(entry);
         verify(mLogger, never()).logNoFullscreen(any(), any());
         verify(mLogger, never()).logNoFullscreenWarning(any(), any());
         verify(mLogger).logFullscreen(entry, "Expected not to HUN");
@@ -691,9 +746,10 @@
         when(mKeyguardStateController.isShowing()).thenReturn(true);
         when(mKeyguardStateController.isOccluded()).thenReturn(true);
 
+        assertThat(mNotifInterruptionStateProvider.getFullScreenIntentDecision(entry))
+                .isEqualTo(FullScreenIntentDecision.FSI_KEYGUARD_OCCLUDED);
         assertThat(mNotifInterruptionStateProvider.shouldLaunchFullScreenIntentWhenAdded(entry))
                 .isTrue();
-        verify(mLogger).logNoHeadsUpPackageSnoozed(entry);
         verify(mLogger, never()).logNoFullscreen(any(), any());
         verify(mLogger, never()).logNoFullscreenWarning(any(), any());
         verify(mLogger).logFullscreen(entry, "Expected not to HUN while keyguard occluded");
@@ -711,9 +767,10 @@
         when(mKeyguardStateController.isShowing()).thenReturn(true);
         when(mKeyguardStateController.isOccluded()).thenReturn(false);
 
+        assertThat(mNotifInterruptionStateProvider.getFullScreenIntentDecision(entry))
+                .isEqualTo(FullScreenIntentDecision.FSI_LOCKED_SHADE);
         assertThat(mNotifInterruptionStateProvider.shouldLaunchFullScreenIntentWhenAdded(entry))
                 .isTrue();
-        verify(mLogger).logNoHeadsUpPackageSnoozed(entry);
         verify(mLogger, never()).logNoFullscreen(any(), any());
         verify(mLogger, never()).logNoFullscreenWarning(any(), any());
         verify(mLogger).logFullscreen(entry, "Keyguard is showing and not occluded");
@@ -731,9 +788,10 @@
         when(mKeyguardStateController.isShowing()).thenReturn(false);
         when(mKeyguardStateController.isOccluded()).thenReturn(false);
 
+        assertThat(mNotifInterruptionStateProvider.getFullScreenIntentDecision(entry))
+                .isEqualTo(FullScreenIntentDecision.NO_FSI_NO_HUN_OR_KEYGUARD);
         assertThat(mNotifInterruptionStateProvider.shouldLaunchFullScreenIntentWhenAdded(entry))
                 .isFalse();
-        verify(mLogger).logNoHeadsUpPackageSnoozed(entry);
         verify(mLogger, never()).logNoFullscreen(any(), any());
         verify(mLogger).logNoFullscreenWarning(entry, "Expected not to HUN while not on keyguard");
         verify(mLogger, never()).logFullscreen(any(), any());
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryLoggerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryLoggerTest.kt
new file mode 100644
index 0000000..33b94e3
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryLoggerTest.kt
@@ -0,0 +1,127 @@
+/*
+ * 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.systemui.statusbar.notification.logging
+
+import android.app.Notification
+import android.app.StatsManager
+import android.graphics.Bitmap
+import android.graphics.drawable.Icon
+import android.testing.AndroidTestingRunner
+import android.util.StatsEvent
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.shared.system.SysUiStatsLog
+import com.android.systemui.statusbar.notification.collection.NotifPipeline
+import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder
+import com.android.systemui.util.concurrency.FakeExecutor
+import com.android.systemui.util.mockito.mock
+import com.android.systemui.util.mockito.whenever
+import com.android.systemui.util.time.FakeSystemClock
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.Dispatchers
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.Mock
+import org.mockito.Mockito.verify
+import org.mockito.MockitoAnnotations
+
+@SmallTest
+@RunWith(AndroidTestingRunner::class)
+class NotificationMemoryLoggerTest : SysuiTestCase() {
+
+    private val bgExecutor = FakeExecutor(FakeSystemClock())
+    private val immediate = Dispatchers.Main.immediate
+
+    @Mock private lateinit var statsManager: StatsManager
+
+    @Before
+    fun setUp() {
+        MockitoAnnotations.initMocks(this)
+    }
+
+    @Test
+    fun onInit_registersCallback() {
+        val logger = createLoggerWithNotifications(listOf())
+        logger.init()
+        verify(statsManager)
+            .setPullAtomCallback(SysUiStatsLog.NOTIFICATION_MEMORY_USE, null, bgExecutor, logger)
+    }
+
+    @Test
+    fun onPullAtom_wrongAtomId_returnsSkip() {
+        val logger = createLoggerWithNotifications(listOf())
+        val data: MutableList<StatsEvent> = mutableListOf()
+        assertThat(logger.onPullAtom(111, data)).isEqualTo(StatsManager.PULL_SKIP)
+        assertThat(data).isEmpty()
+    }
+
+    @Test
+    fun onPullAtom_emptyNotifications_returnsZeros() {
+        val logger = createLoggerWithNotifications(listOf())
+        val data: MutableList<StatsEvent> = mutableListOf()
+        assertThat(logger.onPullAtom(SysUiStatsLog.NOTIFICATION_MEMORY_USE, data))
+            .isEqualTo(StatsManager.PULL_SUCCESS)
+        assertThat(data).isEmpty()
+    }
+
+    @Test
+    fun onPullAtom_notificationPassed_populatesData() {
+        val icon = Icon.createWithBitmap(Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888))
+        val notification =
+            Notification.Builder(context).setSmallIcon(icon).setContentTitle("title").build()
+        val logger = createLoggerWithNotifications(listOf(notification))
+        val data: MutableList<StatsEvent> = mutableListOf()
+
+        assertThat(logger.onPullAtom(SysUiStatsLog.NOTIFICATION_MEMORY_USE, data))
+            .isEqualTo(StatsManager.PULL_SUCCESS)
+        assertThat(data).hasSize(1)
+    }
+
+    @Test
+    fun onPullAtom_multipleNotificationsPassed_populatesData() {
+        val icon = Icon.createWithBitmap(Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888))
+        val notification =
+            Notification.Builder(context).setSmallIcon(icon).setContentTitle("title").build()
+        val iconTwo = Icon.createWithBitmap(Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888))
+
+        val notificationTwo =
+            Notification.Builder(context)
+                .setStyle(Notification.BigTextStyle().bigText("text"))
+                .setSmallIcon(iconTwo)
+                .setContentTitle("titleTwo")
+                .build()
+        val logger = createLoggerWithNotifications(listOf(notification, notificationTwo))
+        val data: MutableList<StatsEvent> = mutableListOf()
+
+        assertThat(logger.onPullAtom(SysUiStatsLog.NOTIFICATION_MEMORY_USE, data))
+            .isEqualTo(StatsManager.PULL_SUCCESS)
+        assertThat(data).hasSize(2)
+    }
+
+    private fun createLoggerWithNotifications(
+        notifications: List<Notification>
+    ): NotificationMemoryLogger {
+        val pipeline: NotifPipeline = mock()
+        val notifications =
+            notifications.map { notification ->
+                NotificationEntryBuilder().setTag("test").setNotification(notification).build()
+            }
+        whenever(pipeline.allNotifs).thenReturn(notifications)
+        return NotificationMemoryLogger(pipeline, statsManager, immediate, bgExecutor)
+    }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryMeterTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryMeterTest.kt
index f69839b..072a497 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryMeterTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryMeterTest.kt
@@ -23,6 +23,7 @@
 import android.content.Intent
 import android.graphics.Bitmap
 import android.graphics.drawable.Icon
+import android.stats.sysui.NotificationEnums
 import android.testing.AndroidTestingRunner
 import android.widget.RemoteViews
 import androidx.test.filters.SmallTest
@@ -50,7 +51,27 @@
             extras = 3316,
             bigPicture = 0,
             extender = 0,
-            style = null,
+            style = NotificationEnums.STYLE_NONE,
+            styleIcon = 0,
+            hasCustomView = false,
+        )
+    }
+
+    @Test
+    fun currentNotificationMemoryUse_rankerGroupNotification() {
+        val notification = createBasicNotification().build()
+        val memoryUse =
+            NotificationMemoryMeter.notificationMemoryUse(
+                createNotificationEntry(createBasicNotification().setGroup("ranker_group").build())
+            )
+        assertNotificationObjectSizes(
+            memoryUse,
+            smallIcon = notification.smallIcon.bitmap.allocationByteCount,
+            largeIcon = notification.getLargeIcon().bitmap.allocationByteCount,
+            extras = 3316,
+            bigPicture = 0,
+            extender = 0,
+            style = NotificationEnums.STYLE_RANKER_GROUP,
             styleIcon = 0,
             hasCustomView = false,
         )
@@ -69,7 +90,7 @@
             extras = 3316,
             bigPicture = 0,
             extender = 0,
-            style = null,
+            style = NotificationEnums.STYLE_NONE,
             styleIcon = 0,
             hasCustomView = false,
         )
@@ -92,7 +113,7 @@
             extras = 3384,
             bigPicture = 0,
             extender = 0,
-            style = null,
+            style = NotificationEnums.STYLE_NONE,
             styleIcon = 0,
             hasCustomView = true,
         )
@@ -112,7 +133,7 @@
             extras = 3212,
             bigPicture = 0,
             extender = 0,
-            style = null,
+            style = NotificationEnums.STYLE_NONE,
             styleIcon = 0,
             hasCustomView = false,
         )
@@ -141,7 +162,7 @@
             extras = 4092,
             bigPicture = bigPicture.bitmap.allocationByteCount,
             extender = 0,
-            style = "BigPictureStyle",
+            style = NotificationEnums.STYLE_BIG_PICTURE,
             styleIcon = bigPictureIcon.bitmap.allocationByteCount,
             hasCustomView = false,
         )
@@ -167,7 +188,7 @@
             extras = 4084,
             bigPicture = 0,
             extender = 0,
-            style = "CallStyle",
+            style = NotificationEnums.STYLE_CALL,
             styleIcon = personIcon.bitmap.allocationByteCount,
             hasCustomView = false,
         )
@@ -203,7 +224,7 @@
             extras = 5024,
             bigPicture = 0,
             extender = 0,
-            style = "MessagingStyle",
+            style = NotificationEnums.STYLE_MESSAGING,
             styleIcon =
                 personIcon.bitmap.allocationByteCount +
                     historicPersonIcon.bitmap.allocationByteCount,
@@ -225,7 +246,7 @@
             extras = 3612,
             bigPicture = 0,
             extender = 556656,
-            style = null,
+            style = NotificationEnums.STYLE_NONE,
             styleIcon = 0,
             hasCustomView = false,
         )
@@ -246,7 +267,7 @@
             extras = 3820,
             bigPicture = 0,
             extender = 388 + wearBackground.allocationByteCount,
-            style = null,
+            style = NotificationEnums.STYLE_NONE,
             styleIcon = 0,
             hasCustomView = false,
         )
@@ -272,7 +293,7 @@
         extras: Int,
         bigPicture: Int,
         extender: Int,
-        style: String?,
+        style: Int,
         styleIcon: Int,
         hasCustomView: Boolean,
     ) {
@@ -282,11 +303,7 @@
         assertThat(memoryUse.objectUsage.smallIcon).isEqualTo(smallIcon)
         assertThat(memoryUse.objectUsage.largeIcon).isEqualTo(largeIcon)
         assertThat(memoryUse.objectUsage.bigPicture).isEqualTo(bigPicture)
-        if (style == null) {
-            assertThat(memoryUse.objectUsage.style).isNull()
-        } else {
-            assertThat(memoryUse.objectUsage.style).isEqualTo(style)
-        }
+        assertThat(memoryUse.objectUsage.style).isEqualTo(style)
         assertThat(memoryUse.objectUsage.styleIcon).isEqualTo(styleIcon)
         assertThat(memoryUse.objectUsage.hasCustomView).isEqualTo(hasCustomView)
     }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryViewWalkerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryViewWalkerTest.kt
index 3a16fb3..a0f5048 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryViewWalkerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryViewWalkerTest.kt
@@ -8,6 +8,7 @@
 import android.widget.RemoteViews
 import androidx.test.filters.SmallTest
 import com.android.systemui.SysuiTestCase
+import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder
 import com.android.systemui.statusbar.notification.row.NotificationTestHelper
 import com.android.systemui.tests.R
 import com.google.common.truth.Truth.assertThat
@@ -39,16 +40,84 @@
     fun testViewWalker_plainNotification() {
         val row = testHelper.createRow()
         val result = NotificationMemoryViewWalker.getViewUsage(row)
-        assertThat(result).hasSize(5)
-        assertThat(result).contains(NotificationViewUsage(ViewType.PUBLIC_VIEW, 0, 0, 0, 0, 0, 0))
-        assertThat(result)
-            .contains(NotificationViewUsage(ViewType.PRIVATE_HEADS_UP_VIEW, 0, 0, 0, 0, 0, 0))
+        assertThat(result).hasSize(3)
         assertThat(result)
             .contains(NotificationViewUsage(ViewType.PRIVATE_EXPANDED_VIEW, 0, 0, 0, 0, 0, 0))
         assertThat(result)
             .contains(NotificationViewUsage(ViewType.PRIVATE_CONTRACTED_VIEW, 0, 0, 0, 0, 0, 0))
+        assertThat(result).contains(NotificationViewUsage(ViewType.TOTAL, 0, 0, 0, 0, 0, 0))
+    }
+
+    @Test
+    fun testViewWalker_plainNotification_withPublicView() {
+        val icon = Icon.createWithBitmap(Bitmap.createBitmap(20, 20, Bitmap.Config.ARGB_8888))
+        val publicIcon = Icon.createWithBitmap(Bitmap.createBitmap(40, 40, Bitmap.Config.ARGB_8888))
+        testHelper.setDefaultInflationFlags(NotificationRowContentBinder.FLAG_CONTENT_VIEW_ALL)
+        val row =
+            testHelper.createRow(
+                Notification.Builder(mContext)
+                    .setContentText("Test")
+                    .setContentTitle("title")
+                    .setSmallIcon(icon)
+                    .setPublicVersion(
+                        Notification.Builder(mContext)
+                            .setContentText("Public Test")
+                            .setContentTitle("title")
+                            .setSmallIcon(publicIcon)
+                            .build()
+                    )
+                    .build()
+            )
+        val result = NotificationMemoryViewWalker.getViewUsage(row)
+        assertThat(result).hasSize(4)
         assertThat(result)
-            .contains(NotificationViewUsage(ViewType.PRIVATE_HEADS_UP_VIEW, 0, 0, 0, 0, 0, 0))
+            .contains(
+                NotificationViewUsage(
+                    ViewType.PRIVATE_EXPANDED_VIEW,
+                    icon.bitmap.allocationByteCount,
+                    0,
+                    0,
+                    0,
+                    0,
+                    icon.bitmap.allocationByteCount
+                )
+            )
+        assertThat(result)
+            .contains(
+                NotificationViewUsage(
+                    ViewType.PRIVATE_CONTRACTED_VIEW,
+                    icon.bitmap.allocationByteCount,
+                    0,
+                    0,
+                    0,
+                    0,
+                    icon.bitmap.allocationByteCount
+                )
+            )
+        assertThat(result)
+            .contains(
+                NotificationViewUsage(
+                    ViewType.PUBLIC_VIEW,
+                    publicIcon.bitmap.allocationByteCount,
+                    0,
+                    0,
+                    0,
+                    0,
+                    publicIcon.bitmap.allocationByteCount
+                )
+            )
+        assertThat(result)
+            .contains(
+                NotificationViewUsage(
+                    ViewType.TOTAL,
+                    icon.bitmap.allocationByteCount + publicIcon.bitmap.allocationByteCount,
+                    0,
+                    0,
+                    0,
+                    0,
+                    icon.bitmap.allocationByteCount + publicIcon.bitmap.allocationByteCount
+                )
+            )
     }
 
     @Test
@@ -67,7 +136,7 @@
                     .build()
             )
         val result = NotificationMemoryViewWalker.getViewUsage(row)
-        assertThat(result).hasSize(5)
+        assertThat(result).hasSize(3)
         assertThat(result)
             .contains(
                 NotificationViewUsage(
@@ -95,8 +164,20 @@
                     icon.bitmap.allocationByteCount + largeIcon.bitmap.allocationByteCount
                 )
             )
-        // Due to deduplication, this should all be 0.
-        assertThat(result).contains(NotificationViewUsage(ViewType.PUBLIC_VIEW, 0, 0, 0, 0, 0, 0))
+        assertThat(result)
+            .contains(
+                NotificationViewUsage(
+                    ViewType.TOTAL,
+                    icon.bitmap.allocationByteCount,
+                    largeIcon.bitmap.allocationByteCount,
+                    0,
+                    bigPicture.allocationByteCount,
+                    0,
+                    bigPicture.allocationByteCount +
+                        icon.bitmap.allocationByteCount +
+                        largeIcon.bitmap.allocationByteCount
+                )
+            )
     }
 
     @Test
@@ -117,7 +198,7 @@
                     .build()
             )
         val result = NotificationMemoryViewWalker.getViewUsage(row)
-        assertThat(result).hasSize(5)
+        assertThat(result).hasSize(3)
         assertThat(result)
             .contains(
                 NotificationViewUsage(
@@ -142,7 +223,17 @@
                     bitmap.allocationByteCount + icon.bitmap.allocationByteCount
                 )
             )
-        // Due to deduplication, this should all be 0.
-        assertThat(result).contains(NotificationViewUsage(ViewType.PUBLIC_VIEW, 0, 0, 0, 0, 0, 0))
+        assertThat(result)
+            .contains(
+                NotificationViewUsage(
+                    ViewType.TOTAL,
+                    icon.bitmap.allocationByteCount,
+                    0,
+                    0,
+                    0,
+                    bitmap.allocationByteCount,
+                    bitmap.allocationByteCount + icon.bitmap.allocationByteCount
+                )
+            )
     }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithmTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithmTest.kt
index 4d9db8c..5832569 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithmTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithmTest.kt
@@ -518,7 +518,7 @@
         val childHunView = createHunViewMock(
                 isShadeOpen = true,
                 fullyVisible = false,
-                headerVisibleAmount = 1f
+                headerVisibleAmount = 1f,
         )
         val algorithmState = StackScrollAlgorithm.StackScrollAlgorithmState()
         algorithmState.visibleChildren.add(childHunView)
@@ -526,7 +526,6 @@
         // When: updateChildZValue() is called for the top HUN
         stackScrollAlgorithm.updateChildZValue(
                 /* i= */ 0,
-                /* childrenOnTop= */ 0.0f,
                 /* StackScrollAlgorithmState= */ algorithmState,
                 /* ambientState= */ ambientState,
                 /* shouldElevateHun= */ true
@@ -546,7 +545,7 @@
         val childHunView = createHunViewMock(
                 isShadeOpen = true,
                 fullyVisible = false,
-                headerVisibleAmount = 1f
+                headerVisibleAmount = 1f,
         )
         // Use half of the HUN's height as overlap
         childHunView.viewState.yTranslation = (childHunView.viewState.height + 1 shr 1).toFloat()
@@ -556,7 +555,6 @@
         // When: updateChildZValue() is called for the top HUN
         stackScrollAlgorithm.updateChildZValue(
                 /* i= */ 0,
-                /* childrenOnTop= */ 0.0f,
                 /* StackScrollAlgorithmState= */ algorithmState,
                 /* ambientState= */ ambientState,
                 /* shouldElevateHun= */ true
@@ -580,7 +578,7 @@
         val childHunView = createHunViewMock(
                 isShadeOpen = true,
                 fullyVisible = true,
-                headerVisibleAmount = 1f
+                headerVisibleAmount = 1f,
         )
         // HUN doesn't overlap with QQS Panel
         childHunView.viewState.yTranslation = ambientState.topPadding +
@@ -591,7 +589,6 @@
         // When: updateChildZValue() is called for the top HUN
         stackScrollAlgorithm.updateChildZValue(
                 /* i= */ 0,
-                /* childrenOnTop= */ 0.0f,
                 /* StackScrollAlgorithmState= */ algorithmState,
                 /* ambientState= */ ambientState,
                 /* shouldElevateHun= */ true
@@ -611,7 +608,7 @@
         val childHunView = createHunViewMock(
                 isShadeOpen = false,
                 fullyVisible = false,
-                headerVisibleAmount = 0f
+                headerVisibleAmount = 0f,
         )
         childHunView.viewState.yTranslation = 0f
         // Shade is closed, thus childHunView's headerVisibleAmount is 0
@@ -622,7 +619,6 @@
         // When: updateChildZValue() is called for the top HUN
         stackScrollAlgorithm.updateChildZValue(
                 /* i= */ 0,
-                /* childrenOnTop= */ 0.0f,
                 /* StackScrollAlgorithmState= */ algorithmState,
                 /* ambientState= */ ambientState,
                 /* shouldElevateHun= */ true
@@ -642,7 +638,7 @@
         val childHunView = createHunViewMock(
                 isShadeOpen = false,
                 fullyVisible = false,
-                headerVisibleAmount = 0.5f
+                headerVisibleAmount = 0.5f,
         )
         childHunView.viewState.yTranslation = 0f
         // Shade is being opened, thus childHunView's headerVisibleAmount is between 0 and 1
@@ -654,7 +650,6 @@
         // When: updateChildZValue() is called for the top HUN
         stackScrollAlgorithm.updateChildZValue(
                 /* i= */ 0,
-                /* childrenOnTop= */ 0.0f,
                 /* StackScrollAlgorithmState= */ algorithmState,
                 /* ambientState= */ ambientState,
                 /* shouldElevateHun= */ true
@@ -669,7 +664,7 @@
     private fun createHunViewMock(
             isShadeOpen: Boolean,
             fullyVisible: Boolean,
-            headerVisibleAmount: Float
+            headerVisibleAmount: Float,
     ) =
             mock<ExpandableNotificationRow>().apply {
                 val childViewStateMock = createHunChildViewState(isShadeOpen, fullyVisible)
@@ -680,7 +675,10 @@
             }
 
 
-    private fun createHunChildViewState(isShadeOpen: Boolean, fullyVisible: Boolean) =
+    private fun createHunChildViewState(
+            isShadeOpen: Boolean,
+            fullyVisible: Boolean,
+    ) =
             ExpandableViewState().apply {
                 // Mock the HUN's height with ambientState.topPadding +
                 // ambientState.stackTranslation
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java
index 9727b6c5..e5e5d94 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java
@@ -16,6 +16,8 @@
 
 package com.android.systemui.statusbar.phone;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.isNull;
 import static org.mockito.Mockito.mock;
@@ -33,12 +35,14 @@
 
 import com.android.systemui.SysuiTestCase;
 import com.android.systemui.flags.FeatureFlags;
+import com.android.systemui.flags.Flags;
 import com.android.systemui.plugins.DarkIconDispatcher;
 import com.android.systemui.plugins.statusbar.StatusBarStateController;
 import com.android.systemui.shade.NotificationPanelViewController;
 import com.android.systemui.statusbar.CommandQueue;
 import com.android.systemui.statusbar.HeadsUpStatusBarView;
 import com.android.systemui.statusbar.notification.NotificationWakeUpCoordinator;
+import com.android.systemui.statusbar.notification.collection.NotificationEntry;
 import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
 import com.android.systemui.statusbar.notification.row.NotificationTestHelper;
 import com.android.systemui.statusbar.notification.stack.NotificationRoundnessManager;
@@ -64,7 +68,9 @@
             mock(NotificationPanelViewController.class);
     private final DarkIconDispatcher mDarkIconDispatcher = mock(DarkIconDispatcher.class);
     private HeadsUpAppearanceController mHeadsUpAppearanceController;
-    private ExpandableNotificationRow mFirst;
+    private NotificationTestHelper mTestHelper;
+    private ExpandableNotificationRow mRow;
+    private NotificationEntry mEntry;
     private HeadsUpStatusBarView mHeadsUpStatusBarView;
     private HeadsUpManagerPhone mHeadsUpManager;
     private View mOperatorNameView;
@@ -79,11 +85,12 @@
     @Before
     public void setUp() throws Exception {
         allowTestableLooperAsMainThread();
-        NotificationTestHelper testHelper = new NotificationTestHelper(
+        mTestHelper = new NotificationTestHelper(
                 mContext,
                 mDependency,
                 TestableLooper.get(this));
-        mFirst = testHelper.createRow();
+        mRow = mTestHelper.createRow();
+        mEntry = mRow.getEntry();
         mHeadsUpStatusBarView = new HeadsUpStatusBarView(mContext, mock(View.class),
                 mock(TextView.class));
         mHeadsUpManager = mock(HeadsUpManagerPhone.class);
@@ -95,6 +102,7 @@
         mCommandQueue = mock(CommandQueue.class);
         mNotificationRoundnessManager = mock(NotificationRoundnessManager.class);
         mFeatureFlag = mock(FeatureFlags.class);
+        when(mFeatureFlag.isEnabled(Flags.USE_ROUNDNESS_SOURCETYPES)).thenReturn(true);
         mHeadsUpAppearanceController = new HeadsUpAppearanceController(
                 mock(NotificationIconAreaController.class),
                 mHeadsUpManager,
@@ -116,60 +124,60 @@
 
     @Test
     public void testShowinEntryUpdated() {
-        mFirst.setPinned(true);
+        mRow.setPinned(true);
         when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true);
-        when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry());
-        mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry());
-        Assert.assertEquals(mFirst.getEntry(), mHeadsUpStatusBarView.getShowingEntry());
+        when(mHeadsUpManager.getTopEntry()).thenReturn(mEntry);
+        mHeadsUpAppearanceController.onHeadsUpPinned(mEntry);
+        assertEquals(mRow.getEntry(), mHeadsUpStatusBarView.getShowingEntry());
 
-        mFirst.setPinned(false);
+        mRow.setPinned(false);
         when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
-        mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry());
-        Assert.assertEquals(null, mHeadsUpStatusBarView.getShowingEntry());
+        mHeadsUpAppearanceController.onHeadsUpUnPinned(mEntry);
+        assertEquals(null, mHeadsUpStatusBarView.getShowingEntry());
     }
 
     @Test
     public void testShownUpdated() {
-        mFirst.setPinned(true);
+        mRow.setPinned(true);
         when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true);
-        when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry());
-        mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry());
-        Assert.assertTrue(mHeadsUpAppearanceController.isShown());
+        when(mHeadsUpManager.getTopEntry()).thenReturn(mEntry);
+        mHeadsUpAppearanceController.onHeadsUpPinned(mEntry);
+        assertTrue(mHeadsUpAppearanceController.isShown());
 
-        mFirst.setPinned(false);
+        mRow.setPinned(false);
         when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
-        mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry());
+        mHeadsUpAppearanceController.onHeadsUpUnPinned(mEntry);
         Assert.assertFalse(mHeadsUpAppearanceController.isShown());
     }
 
     @Test
     public void testHeaderUpdated() {
-        mFirst.setPinned(true);
+        mRow.setPinned(true);
         when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true);
-        when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry());
-        mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry());
-        Assert.assertEquals(mFirst.getHeaderVisibleAmount(), 0.0f, 0.0f);
+        when(mHeadsUpManager.getTopEntry()).thenReturn(mEntry);
+        mHeadsUpAppearanceController.onHeadsUpPinned(mEntry);
+        assertEquals(mRow.getHeaderVisibleAmount(), 0.0f, 0.0f);
 
-        mFirst.setPinned(false);
+        mRow.setPinned(false);
         when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
-        mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry());
-        Assert.assertEquals(mFirst.getHeaderVisibleAmount(), 1.0f, 0.0f);
+        mHeadsUpAppearanceController.onHeadsUpUnPinned(mEntry);
+        assertEquals(mRow.getHeaderVisibleAmount(), 1.0f, 0.0f);
     }
 
     @Test
     public void testOperatorNameViewUpdated() {
         mHeadsUpAppearanceController.setAnimationsEnabled(false);
 
-        mFirst.setPinned(true);
+        mRow.setPinned(true);
         when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true);
-        when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry());
-        mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry());
-        Assert.assertEquals(View.INVISIBLE, mOperatorNameView.getVisibility());
+        when(mHeadsUpManager.getTopEntry()).thenReturn(mEntry);
+        mHeadsUpAppearanceController.onHeadsUpPinned(mEntry);
+        assertEquals(View.INVISIBLE, mOperatorNameView.getVisibility());
 
-        mFirst.setPinned(false);
+        mRow.setPinned(false);
         when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
-        mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry());
-        Assert.assertEquals(View.VISIBLE, mOperatorNameView.getVisibility());
+        mHeadsUpAppearanceController.onHeadsUpUnPinned(mEntry);
+        assertEquals(View.VISIBLE, mOperatorNameView.getVisibility());
     }
 
     @Test
@@ -196,8 +204,8 @@
                 new Clock(mContext, null),
                 Optional.empty());
 
-        Assert.assertEquals(expandedHeight, newController.mExpandedHeight, 0.0f);
-        Assert.assertEquals(appearFraction, newController.mAppearFraction, 0.0f);
+        assertEquals(expandedHeight, newController.mExpandedHeight, 0.0f);
+        assertEquals(appearFraction, newController.mAppearFraction, 0.0f);
     }
 
     @Test
@@ -215,4 +223,68 @@
         verify(mPanelView).setHeadsUpAppearanceController(isNull());
         verify(mStackScrollerController).removeOnExpandedHeightChangedListener(any());
     }
+
+    @Test
+    public void testPulsingRoundness_onUpdateHeadsUpAndPulsingRoundness() {
+        // Pulsing: Enable flag and dozing
+        when(mNotificationRoundnessManager.shouldRoundNotificationPulsing()).thenReturn(true);
+        when(mTestHelper.getStatusBarStateController().isDozing()).thenReturn(true);
+
+        // Pulsing: Enabled
+        mRow.setHeadsUp(true);
+        mHeadsUpAppearanceController.updateHeadsUpAndPulsingRoundness(mEntry);
+
+        String debugString = mRow.getRoundableState().debugString();
+        assertEquals(
+                "If Pulsing is enabled, roundness should be set to 1. Value: " + debugString,
+                /* expected = */ 1,
+                /* actual = */ mRow.getTopRoundness(),
+                /* delta = */ 0.001
+        );
+        assertTrue(debugString.contains("Pulsing"));
+
+        // Pulsing: Disabled
+        mRow.setHeadsUp(false);
+        mHeadsUpAppearanceController.updateHeadsUpAndPulsingRoundness(mEntry);
+
+        assertEquals(
+                "If Pulsing is disabled, roundness should be set to 0. Value: "
+                        + mRow.getRoundableState().debugString(),
+                /* expected = */ 0,
+                /* actual = */ mRow.getTopRoundness(),
+                /* delta = */ 0.001
+        );
+    }
+
+    @Test
+    public void testPulsingRoundness_onHeadsUpStateChanged() {
+        // Pulsing: Enable flag and dozing
+        when(mNotificationRoundnessManager.shouldRoundNotificationPulsing()).thenReturn(true);
+        when(mTestHelper.getStatusBarStateController().isDozing()).thenReturn(true);
+
+        // Pulsing: Enabled
+        mEntry.setHeadsUp(true);
+        mHeadsUpAppearanceController.onHeadsUpStateChanged(mEntry, true);
+
+        String debugString = mRow.getRoundableState().debugString();
+        assertEquals(
+                "If Pulsing is enabled, roundness should be set to 1. Value: " + debugString,
+                /* expected = */ 1,
+                /* actual = */ mRow.getTopRoundness(),
+                /* delta = */ 0.001
+        );
+        assertTrue(debugString.contains("Pulsing"));
+
+        // Pulsing: Disabled
+        mEntry.setHeadsUp(false);
+        mHeadsUpAppearanceController.onHeadsUpStateChanged(mEntry, false);
+
+        assertEquals(
+                "If Pulsing is disabled, roundness should be set to 0. Value: "
+                        + mRow.getRoundableState().debugString(),
+                /* expected = */ 0,
+                /* actual = */ mRow.getTopRoundness(),
+                /* delta = */ 0.001
+        );
+    }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java
index 471f8d3..14a319b 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2018 The Android Open Source Project
+ * 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.
@@ -11,7 +11,7 @@
  * 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
+ * limitations under the License.
  */
 
 package com.android.systemui.statusbar.phone;
@@ -105,7 +105,6 @@
     @Mock private KeyguardBouncer.Factory mKeyguardBouncerFactory;
     @Mock private KeyguardMessageAreaController.Factory mKeyguardMessageAreaFactory;
     @Mock private KeyguardMessageAreaController mKeyguardMessageAreaController;
-    @Mock private KeyguardBouncer mPrimaryBouncer;
     @Mock private StatusBarKeyguardViewManager.AlternateBouncer mAlternateBouncer;
     @Mock private KeyguardMessageArea mKeyguardMessageArea;
     @Mock private ShadeController mShadeController;
@@ -133,16 +132,14 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        when(mKeyguardBouncerFactory.create(
-                any(ViewGroup.class),
-                any(KeyguardBouncer.PrimaryBouncerExpansionCallback.class)))
-                .thenReturn(mPrimaryBouncer);
         when(mCentralSurfaces.getBouncerContainer()).thenReturn(mContainer);
         when(mContainer.findViewById(anyInt())).thenReturn(mKeyguardMessageArea);
         when(mKeyguardMessageAreaFactory.create(any(KeyguardMessageArea.class)))
                 .thenReturn(mKeyguardMessageAreaController);
         when(mBouncerView.getDelegate()).thenReturn(mBouncerViewDelegate);
 
+        when(mFeatureFlags.isEnabled(MODERN_BOUNCER)).thenReturn(true);
+
         mStatusBarKeyguardViewManager =
                 new StatusBarKeyguardViewManager(
                         getContext(),
@@ -184,7 +181,7 @@
         mStatusBarKeyguardViewManager.show(null);
         ArgumentCaptor<KeyguardBouncer.PrimaryBouncerExpansionCallback> callbackArgumentCaptor =
                 ArgumentCaptor.forClass(KeyguardBouncer.PrimaryBouncerExpansionCallback.class);
-        verify(mKeyguardBouncerFactory).create(any(ViewGroup.class),
+        verify(mPrimaryBouncerCallbackInteractor).addBouncerExpansionCallback(
                 callbackArgumentCaptor.capture());
         mBouncerExpansionCallback = callbackArgumentCaptor.getValue();
     }
@@ -195,87 +192,87 @@
         Runnable cancelAction = () -> {};
         mStatusBarKeyguardViewManager.dismissWithAction(
                 action, cancelAction, false /* afterKeyguardGone */);
-        verify(mPrimaryBouncer).showWithDismissAction(eq(action), eq(cancelAction));
+        verify(mPrimaryBouncerInteractor).setDismissAction(eq(action), eq(cancelAction));
+        verify(mPrimaryBouncerInteractor).show(eq(true));
     }
 
     @Test
     public void showBouncer_onlyWhenShowing() {
         mStatusBarKeyguardViewManager.hide(0 /* startTime */, 0 /* fadeoutDuration */);
         mStatusBarKeyguardViewManager.showPrimaryBouncer(true /* scrimmed */);
-        verify(mPrimaryBouncer, never()).show(anyBoolean(), anyBoolean());
-        verify(mPrimaryBouncer, never()).show(anyBoolean());
+        verify(mPrimaryBouncerInteractor, never()).show(anyBoolean());
     }
 
     @Test
     public void showBouncer_notWhenBouncerAlreadyShowing() {
         mStatusBarKeyguardViewManager.hide(0 /* startTime */, 0 /* fadeoutDuration */);
-        when(mPrimaryBouncer.isSecure()).thenReturn(true);
+        when(mKeyguardSecurityModel.getSecurityMode(anyInt())).thenReturn(
+                KeyguardSecurityModel.SecurityMode.Password);
         mStatusBarKeyguardViewManager.showPrimaryBouncer(true /* scrimmed */);
-        verify(mPrimaryBouncer, never()).show(anyBoolean(), anyBoolean());
-        verify(mPrimaryBouncer, never()).show(anyBoolean());
+        verify(mPrimaryBouncerInteractor, never()).show(anyBoolean());
     }
 
     @Test
     public void showBouncer_showsTheBouncer() {
         mStatusBarKeyguardViewManager.showPrimaryBouncer(true /* scrimmed */);
-        verify(mPrimaryBouncer).show(anyBoolean(), eq(true));
+        verify(mPrimaryBouncerInteractor).show(eq(true));
     }
 
     @Test
     public void onPanelExpansionChanged_neverShowsDuringHintAnimation() {
         when(mNotificationPanelView.isUnlockHintRunning()).thenReturn(true);
         mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
-        verify(mPrimaryBouncer, never()).setExpansion(anyFloat());
+        verify(mPrimaryBouncerInteractor, never()).setPanelExpansion(anyFloat());
     }
 
     @Test
     public void onPanelExpansionChanged_propagatesToBouncerOnlyIfShowing() {
         mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
-        verify(mPrimaryBouncer, never()).setExpansion(eq(0.5f));
+        verify(mPrimaryBouncerInteractor, never()).setPanelExpansion(eq(0.5f));
 
-        when(mPrimaryBouncer.isShowing()).thenReturn(true);
+        when(mPrimaryBouncerInteractor.isFullyShowing()).thenReturn(true);
         mStatusBarKeyguardViewManager.onPanelExpansionChanged(
                 expansionEvent(/* fraction= */ 0.6f, /* expanded= */ false, /* tracking= */ true));
-        verify(mPrimaryBouncer).setExpansion(eq(0.6f));
+        verify(mPrimaryBouncerInteractor).setPanelExpansion(eq(0.6f));
     }
 
     @Test
     public void onPanelExpansionChanged_duplicateEventsAreIgnored() {
-        when(mPrimaryBouncer.isShowing()).thenReturn(true);
+        when(mPrimaryBouncerInteractor.isFullyShowing()).thenReturn(true);
         mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
-        verify(mPrimaryBouncer).setExpansion(eq(0.5f));
+        verify(mPrimaryBouncerInteractor).setPanelExpansion(eq(0.5f));
 
-        reset(mPrimaryBouncer);
+        reset(mPrimaryBouncerInteractor);
         mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
-        verify(mPrimaryBouncer, never()).setExpansion(eq(0.5f));
+        verify(mPrimaryBouncerInteractor, never()).setPanelExpansion(eq(0.5f));
     }
 
     @Test
     public void onPanelExpansionChanged_hideBouncer_afterKeyguardHidden() {
         mStatusBarKeyguardViewManager.hide(0, 0);
-        when(mPrimaryBouncer.inTransit()).thenReturn(true);
+        when(mPrimaryBouncerInteractor.isInTransit()).thenReturn(true);
 
         mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
-        verify(mPrimaryBouncer).setExpansion(eq(KeyguardBouncer.EXPANSION_HIDDEN));
+        verify(mPrimaryBouncerInteractor).setPanelExpansion(eq(KeyguardBouncer.EXPANSION_HIDDEN));
     }
 
     @Test
     public void onPanelExpansionChanged_showsBouncerWhenSwiping() {
         mKeyguardStateController.setCanDismissLockScreen(false);
         mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
-        verify(mPrimaryBouncer).show(eq(false), eq(false));
+        verify(mPrimaryBouncerInteractor).show(eq(false));
 
         // But not when it's already visible
-        reset(mPrimaryBouncer);
-        when(mPrimaryBouncer.isShowing()).thenReturn(true);
+        reset(mPrimaryBouncerInteractor);
+        when(mPrimaryBouncerInteractor.isFullyShowing()).thenReturn(true);
         mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
-        verify(mPrimaryBouncer, never()).show(eq(false), eq(false));
+        verify(mPrimaryBouncerInteractor, never()).show(eq(false));
 
         // Or animating away
-        reset(mPrimaryBouncer);
-        when(mPrimaryBouncer.isAnimatingAway()).thenReturn(true);
+        reset(mPrimaryBouncerInteractor);
+        when(mPrimaryBouncerInteractor.isAnimatingAway()).thenReturn(true);
         mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
-        verify(mPrimaryBouncer, never()).show(eq(false), eq(false));
+        verify(mPrimaryBouncerInteractor, never()).show(eq(false));
     }
 
     @Test
@@ -287,7 +284,7 @@
                         /* fraction= */ KeyguardBouncer.EXPANSION_VISIBLE,
                         /* expanded= */ true,
                         /* tracking= */ false));
-        verify(mPrimaryBouncer, never()).setExpansion(anyFloat());
+        verify(mPrimaryBouncerInteractor, never()).setPanelExpansion(anyFloat());
     }
 
     @Test
@@ -304,7 +301,7 @@
                         /* fraction= */ KeyguardBouncer.EXPANSION_VISIBLE,
                         /* expanded= */ true,
                         /* tracking= */ false));
-        verify(mPrimaryBouncer, never()).setExpansion(anyFloat());
+        verify(mPrimaryBouncerInteractor, never()).setPanelExpansion(anyFloat());
     }
 
     @Test
@@ -315,7 +312,7 @@
                         /* fraction= */ KeyguardBouncer.EXPANSION_VISIBLE,
                         /* expanded= */ true,
                         /* tracking= */ false));
-        verify(mPrimaryBouncer, never()).setExpansion(anyFloat());
+        verify(mPrimaryBouncerInteractor, never()).setPanelExpansion(anyFloat());
     }
 
     @Test
@@ -332,7 +329,7 @@
                         /* fraction= */ KeyguardBouncer.EXPANSION_VISIBLE,
                         /* expanded= */ true,
                         /* tracking= */ false));
-        verify(mPrimaryBouncer, never()).setExpansion(anyFloat());
+        verify(mPrimaryBouncerInteractor, never()).setPanelExpansion(anyFloat());
     }
 
     @Test
@@ -343,7 +340,7 @@
                         /* fraction= */ KeyguardBouncer.EXPANSION_VISIBLE,
                         /* expanded= */ true,
                         /* tracking= */ false));
-        verify(mPrimaryBouncer, never()).setExpansion(anyFloat());
+        verify(mPrimaryBouncerInteractor, never()).setPanelExpansion(anyFloat());
     }
 
     @Test
@@ -351,7 +348,7 @@
         mStatusBarKeyguardViewManager.setOccluded(false /* occluded */, true /* animated */);
         verify(mCentralSurfaces).animateKeyguardUnoccluding();
 
-        when(mPrimaryBouncer.isShowing()).thenReturn(true);
+        when(mPrimaryBouncerInteractor.isFullyShowing()).thenReturn(true);
         clearInvocations(mCentralSurfaces);
         mStatusBarKeyguardViewManager.setOccluded(false /* occluded */, true /* animated */);
         verify(mCentralSurfaces, never()).animateKeyguardUnoccluding();
@@ -402,7 +399,7 @@
         mStatusBarKeyguardViewManager.dismissWithAction(
                 action, cancelAction, true /* afterKeyguardGone */);
 
-        when(mPrimaryBouncer.isShowing()).thenReturn(false);
+        when(mPrimaryBouncerInteractor.isFullyShowing()).thenReturn(false);
         mStatusBarKeyguardViewManager.hideBouncer(true);
         mStatusBarKeyguardViewManager.hide(0, 30);
         verify(action, never()).onDismiss();
@@ -416,7 +413,7 @@
         mStatusBarKeyguardViewManager.dismissWithAction(
                 action, cancelAction, true /* afterKeyguardGone */);
 
-        when(mPrimaryBouncer.isShowing()).thenReturn(false);
+        when(mPrimaryBouncerInteractor.isFullyShowing()).thenReturn(false);
         mStatusBarKeyguardViewManager.hideBouncer(true);
 
         verify(action, never()).onDismiss();
@@ -438,7 +435,7 @@
     @Test
     public void testShowing_whenAlternateAuthShowing() {
         mStatusBarKeyguardViewManager.setAlternateBouncer(mAlternateBouncer);
-        when(mPrimaryBouncer.isShowing()).thenReturn(false);
+        when(mPrimaryBouncerInteractor.isFullyShowing()).thenReturn(false);
         when(mAlternateBouncer.isShowingAlternateBouncer()).thenReturn(true);
         assertTrue(
                 "Is showing not accurate when alternative auth showing",
@@ -448,7 +445,7 @@
     @Test
     public void testWillBeShowing_whenAlternateAuthShowing() {
         mStatusBarKeyguardViewManager.setAlternateBouncer(mAlternateBouncer);
-        when(mPrimaryBouncer.isShowing()).thenReturn(false);
+        when(mPrimaryBouncerInteractor.isFullyShowing()).thenReturn(false);
         when(mAlternateBouncer.isShowingAlternateBouncer()).thenReturn(true);
         assertTrue(
                 "Is or will be showing not accurate when alternative auth showing",
@@ -459,7 +456,7 @@
     public void testHideAlternateBouncer_onShowBouncer() {
         // GIVEN alt auth is showing
         mStatusBarKeyguardViewManager.setAlternateBouncer(mAlternateBouncer);
-        when(mPrimaryBouncer.isShowing()).thenReturn(false);
+        when(mPrimaryBouncerInteractor.isFullyShowing()).thenReturn(false);
         when(mAlternateBouncer.isShowingAlternateBouncer()).thenReturn(true);
         reset(mAlternateBouncer);
 
@@ -472,8 +469,8 @@
 
     @Test
     public void testBouncerIsOrWillBeShowing_whenBouncerIsInTransit() {
-        when(mPrimaryBouncer.isShowing()).thenReturn(false);
-        when(mPrimaryBouncer.inTransit()).thenReturn(true);
+        when(mPrimaryBouncerInteractor.isFullyShowing()).thenReturn(false);
+        when(mPrimaryBouncerInteractor.isInTransit()).thenReturn(true);
 
         assertTrue(
                 "Is or will be showing should be true when bouncer is in transit",
@@ -484,7 +481,7 @@
     public void testShowAltAuth_unlockingWithBiometricNotAllowed() {
         // GIVEN alt auth exists, unlocking with biometric isn't allowed
         mStatusBarKeyguardViewManager.setAlternateBouncer(mAlternateBouncer);
-        when(mPrimaryBouncer.isShowing()).thenReturn(false);
+        when(mPrimaryBouncerInteractor.isFullyShowing()).thenReturn(false);
         when(mKeyguardUpdateMonitor.isUnlockingWithBiometricAllowed(anyBoolean()))
                 .thenReturn(false);
 
@@ -493,7 +490,7 @@
         mStatusBarKeyguardViewManager.showBouncer(scrimmed);
 
         // THEN regular bouncer is shown
-        verify(mPrimaryBouncer).show(anyBoolean(), eq(scrimmed));
+        verify(mPrimaryBouncerInteractor).show(eq(scrimmed));
         verify(mAlternateBouncer, never()).showAlternateBouncer();
     }
 
@@ -501,7 +498,7 @@
     public void testShowAlternateBouncer_unlockingWithBiometricAllowed() {
         // GIVEN alt auth exists, unlocking with biometric is allowed
         mStatusBarKeyguardViewManager.setAlternateBouncer(mAlternateBouncer);
-        when(mPrimaryBouncer.isShowing()).thenReturn(false);
+        when(mPrimaryBouncerInteractor.isFullyShowing()).thenReturn(false);
         when(mKeyguardUpdateMonitor.isUnlockingWithBiometricAllowed(anyBoolean())).thenReturn(true);
 
         // WHEN showGenericBouncer is called
@@ -509,30 +506,28 @@
 
         // THEN alt auth bouncer is shown
         verify(mAlternateBouncer).showAlternateBouncer();
-        verify(mPrimaryBouncer, never()).show(anyBoolean(), anyBoolean());
+        verify(mPrimaryBouncerInteractor, never()).show(anyBoolean());
     }
 
     @Test
     public void testUpdateResources_delegatesToBouncer() {
         mStatusBarKeyguardViewManager.updateResources();
 
-        verify(mPrimaryBouncer).updateResources();
+        verify(mPrimaryBouncerInteractor).updateResources();
     }
 
     @Test
     public void updateKeyguardPosition_delegatesToBouncer() {
         mStatusBarKeyguardViewManager.updateKeyguardPosition(1.0f);
 
-        verify(mPrimaryBouncer).updateKeyguardPosition(1.0f);
+        verify(mPrimaryBouncerInteractor).setKeyguardPosition(1.0f);
     }
 
     @Test
     public void testIsBouncerInTransit() {
-        when(mPrimaryBouncer.inTransit()).thenReturn(true);
+        when(mPrimaryBouncerInteractor.isInTransit()).thenReturn(true);
         Truth.assertThat(mStatusBarKeyguardViewManager.isPrimaryBouncerInTransit()).isTrue();
-        when(mPrimaryBouncer.inTransit()).thenReturn(false);
-        Truth.assertThat(mStatusBarKeyguardViewManager.isPrimaryBouncerInTransit()).isFalse();
-        mPrimaryBouncer = null;
+        when(mPrimaryBouncerInteractor.isInTransit()).thenReturn(false);
         Truth.assertThat(mStatusBarKeyguardViewManager.isPrimaryBouncerInTransit()).isFalse();
     }
 
@@ -564,7 +559,7 @@
                 eq(OnBackInvokedDispatcher.PRIORITY_OVERLAY),
                 mOnBackInvokedCallback.capture());
 
-        when(mPrimaryBouncer.isShowing()).thenReturn(true);
+        when(mPrimaryBouncerInteractor.isFullyShowing()).thenReturn(true);
         when(mCentralSurfaces.shouldKeyguardHideImmediately()).thenReturn(true);
         /* invoke the back callback directly */
         mOnBackInvokedCallback.getValue().onBackInvoked();
@@ -594,13 +589,6 @@
     }
 
     @Test
-    public void flag_off_DoesNotCallBouncerInteractor() {
-        when(mFeatureFlags.isEnabled(MODERN_BOUNCER)).thenReturn(false);
-        mStatusBarKeyguardViewManager.hideBouncer(false);
-        verify(mPrimaryBouncerInteractor, never()).hide();
-    }
-
-    @Test
     public void hideAlternateBouncer_beforeCentralSurfacesRegistered() {
         mStatusBarKeyguardViewManager =
                 new StatusBarKeyguardViewManager(
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest_Old.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest_Old.java
new file mode 100644
index 0000000..96fba39
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest_Old.java
@@ -0,0 +1,641 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.statusbar.phone;
+
+import static com.android.systemui.flags.Flags.MODERN_BOUNCER;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyFloat;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.clearInvocations;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewRootImpl;
+import android.window.OnBackInvokedCallback;
+import android.window.OnBackInvokedDispatcher;
+import android.window.WindowOnBackInvokedDispatcher;
+
+import androidx.test.filters.SmallTest;
+
+import com.android.internal.util.LatencyTracker;
+import com.android.internal.widget.LockPatternUtils;
+import com.android.keyguard.KeyguardMessageArea;
+import com.android.keyguard.KeyguardMessageAreaController;
+import com.android.keyguard.KeyguardSecurityModel;
+import com.android.keyguard.KeyguardUpdateMonitor;
+import com.android.keyguard.ViewMediatorCallback;
+import com.android.systemui.SysuiTestCase;
+import com.android.systemui.dock.DockManager;
+import com.android.systemui.dreams.DreamOverlayStateController;
+import com.android.systemui.flags.FeatureFlags;
+import com.android.systemui.keyguard.data.BouncerView;
+import com.android.systemui.keyguard.data.BouncerViewDelegate;
+import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerCallbackInteractor;
+import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerInteractor;
+import com.android.systemui.navigationbar.NavigationModeController;
+import com.android.systemui.plugins.ActivityStarter.OnDismissAction;
+import com.android.systemui.shade.NotificationPanelViewController;
+import com.android.systemui.shade.ShadeController;
+import com.android.systemui.shade.ShadeExpansionChangeEvent;
+import com.android.systemui.shade.ShadeExpansionStateManager;
+import com.android.systemui.statusbar.NotificationMediaManager;
+import com.android.systemui.statusbar.NotificationShadeWindowController;
+import com.android.systemui.statusbar.StatusBarState;
+import com.android.systemui.statusbar.SysuiStatusBarStateController;
+import com.android.systemui.statusbar.policy.ConfigurationController;
+import com.android.systemui.unfold.SysUIUnfoldComponent;
+
+import com.google.common.truth.Truth;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+
+import java.util.Optional;
+
+/**
+ * StatusBarKeyguardViewManager Test with deprecated KeyguardBouncer.java.
+ * TODO: Delete when deleting {@link KeyguardBouncer}
+ */
+@SmallTest
+@RunWith(AndroidTestingRunner.class)
+@TestableLooper.RunWithLooper
+public class StatusBarKeyguardViewManagerTest_Old extends SysuiTestCase {
+    private static final ShadeExpansionChangeEvent EXPANSION_EVENT =
+            expansionEvent(/* fraction= */ 0.5f, /* expanded= */ false, /* tracking= */ true);
+
+    @Mock private ViewMediatorCallback mViewMediatorCallback;
+    @Mock private LockPatternUtils mLockPatternUtils;
+    @Mock private CentralSurfaces mCentralSurfaces;
+    @Mock private ViewGroup mContainer;
+    @Mock private NotificationPanelViewController mNotificationPanelView;
+    @Mock private BiometricUnlockController mBiometricUnlockController;
+    @Mock private SysuiStatusBarStateController mStatusBarStateController;
+    @Mock private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
+    @Mock private View mNotificationContainer;
+    @Mock private KeyguardBypassController mBypassController;
+    @Mock private KeyguardBouncer.Factory mKeyguardBouncerFactory;
+    @Mock private KeyguardMessageAreaController.Factory mKeyguardMessageAreaFactory;
+    @Mock private KeyguardMessageAreaController mKeyguardMessageAreaController;
+    @Mock private KeyguardBouncer mPrimaryBouncer;
+    @Mock private StatusBarKeyguardViewManager.AlternateBouncer mAlternateBouncer;
+    @Mock private KeyguardMessageArea mKeyguardMessageArea;
+    @Mock private ShadeController mShadeController;
+    @Mock private SysUIUnfoldComponent mSysUiUnfoldComponent;
+    @Mock private DreamOverlayStateController mDreamOverlayStateController;
+    @Mock private LatencyTracker mLatencyTracker;
+    @Mock private FeatureFlags mFeatureFlags;
+    @Mock private KeyguardSecurityModel mKeyguardSecurityModel;
+    @Mock private PrimaryBouncerCallbackInteractor mPrimaryBouncerCallbackInteractor;
+    @Mock private PrimaryBouncerInteractor mPrimaryBouncerInteractor;
+    @Mock private BouncerView mBouncerView;
+    @Mock private BouncerViewDelegate mBouncerViewDelegate;
+
+    private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
+    private KeyguardBouncer.PrimaryBouncerExpansionCallback mBouncerExpansionCallback;
+    private FakeKeyguardStateController mKeyguardStateController =
+            spy(new FakeKeyguardStateController());
+
+    @Mock private ViewRootImpl mViewRootImpl;
+    @Mock private WindowOnBackInvokedDispatcher mOnBackInvokedDispatcher;
+    @Captor
+    private ArgumentCaptor<OnBackInvokedCallback> mOnBackInvokedCallback;
+
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        when(mKeyguardBouncerFactory.create(
+                any(ViewGroup.class),
+                any(KeyguardBouncer.PrimaryBouncerExpansionCallback.class)))
+                .thenReturn(mPrimaryBouncer);
+        when(mCentralSurfaces.getBouncerContainer()).thenReturn(mContainer);
+        when(mContainer.findViewById(anyInt())).thenReturn(mKeyguardMessageArea);
+        when(mKeyguardMessageAreaFactory.create(any(KeyguardMessageArea.class)))
+                .thenReturn(mKeyguardMessageAreaController);
+        when(mBouncerView.getDelegate()).thenReturn(mBouncerViewDelegate);
+
+        mStatusBarKeyguardViewManager =
+                new StatusBarKeyguardViewManager(
+                        getContext(),
+                        mViewMediatorCallback,
+                        mLockPatternUtils,
+                        mStatusBarStateController,
+                        mock(ConfigurationController.class),
+                        mKeyguardUpdateMonitor,
+                        mDreamOverlayStateController,
+                        mock(NavigationModeController.class),
+                        mock(DockManager.class),
+                        mock(NotificationShadeWindowController.class),
+                        mKeyguardStateController,
+                        mock(NotificationMediaManager.class),
+                        mKeyguardBouncerFactory,
+                        mKeyguardMessageAreaFactory,
+                        Optional.of(mSysUiUnfoldComponent),
+                        () -> mShadeController,
+                        mLatencyTracker,
+                        mKeyguardSecurityModel,
+                        mFeatureFlags,
+                        mPrimaryBouncerCallbackInteractor,
+                        mPrimaryBouncerInteractor,
+                        mBouncerView) {
+                    @Override
+                    public ViewRootImpl getViewRootImpl() {
+                        return mViewRootImpl;
+                    }
+                };
+        when(mViewRootImpl.getOnBackInvokedDispatcher())
+                .thenReturn(mOnBackInvokedDispatcher);
+        mStatusBarKeyguardViewManager.registerCentralSurfaces(
+                mCentralSurfaces,
+                mNotificationPanelView,
+                new ShadeExpansionStateManager(),
+                mBiometricUnlockController,
+                mNotificationContainer,
+                mBypassController);
+        mStatusBarKeyguardViewManager.show(null);
+        ArgumentCaptor<KeyguardBouncer.PrimaryBouncerExpansionCallback> callbackArgumentCaptor =
+                ArgumentCaptor.forClass(KeyguardBouncer.PrimaryBouncerExpansionCallback.class);
+        verify(mKeyguardBouncerFactory).create(any(ViewGroup.class),
+                callbackArgumentCaptor.capture());
+        mBouncerExpansionCallback = callbackArgumentCaptor.getValue();
+    }
+
+    @Test
+    public void dismissWithAction_AfterKeyguardGoneSetToFalse() {
+        OnDismissAction action = () -> false;
+        Runnable cancelAction = () -> {};
+        mStatusBarKeyguardViewManager.dismissWithAction(
+                action, cancelAction, false /* afterKeyguardGone */);
+        verify(mPrimaryBouncer).showWithDismissAction(eq(action), eq(cancelAction));
+    }
+
+    @Test
+    public void showBouncer_onlyWhenShowing() {
+        mStatusBarKeyguardViewManager.hide(0 /* startTime */, 0 /* fadeoutDuration */);
+        mStatusBarKeyguardViewManager.showPrimaryBouncer(true /* scrimmed */);
+        verify(mPrimaryBouncer, never()).show(anyBoolean(), anyBoolean());
+        verify(mPrimaryBouncer, never()).show(anyBoolean());
+    }
+
+    @Test
+    public void showBouncer_notWhenBouncerAlreadyShowing() {
+        mStatusBarKeyguardViewManager.hide(0 /* startTime */, 0 /* fadeoutDuration */);
+        when(mPrimaryBouncer.isSecure()).thenReturn(true);
+        mStatusBarKeyguardViewManager.showPrimaryBouncer(true /* scrimmed */);
+        verify(mPrimaryBouncer, never()).show(anyBoolean(), anyBoolean());
+        verify(mPrimaryBouncer, never()).show(anyBoolean());
+    }
+
+    @Test
+    public void showBouncer_showsTheBouncer() {
+        mStatusBarKeyguardViewManager.showPrimaryBouncer(true /* scrimmed */);
+        verify(mPrimaryBouncer).show(anyBoolean(), eq(true));
+    }
+
+    @Test
+    public void onPanelExpansionChanged_neverShowsDuringHintAnimation() {
+        when(mNotificationPanelView.isUnlockHintRunning()).thenReturn(true);
+        mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
+        verify(mPrimaryBouncer, never()).setExpansion(anyFloat());
+    }
+
+    @Test
+    public void onPanelExpansionChanged_propagatesToBouncerOnlyIfShowing() {
+        mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
+        verify(mPrimaryBouncer, never()).setExpansion(eq(0.5f));
+
+        when(mPrimaryBouncer.isShowing()).thenReturn(true);
+        mStatusBarKeyguardViewManager.onPanelExpansionChanged(
+                expansionEvent(/* fraction= */ 0.6f, /* expanded= */ false, /* tracking= */ true));
+        verify(mPrimaryBouncer).setExpansion(eq(0.6f));
+    }
+
+    @Test
+    public void onPanelExpansionChanged_duplicateEventsAreIgnored() {
+        when(mPrimaryBouncer.isShowing()).thenReturn(true);
+        mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
+        verify(mPrimaryBouncer).setExpansion(eq(0.5f));
+
+        reset(mPrimaryBouncer);
+        mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
+        verify(mPrimaryBouncer, never()).setExpansion(eq(0.5f));
+    }
+
+    @Test
+    public void onPanelExpansionChanged_hideBouncer_afterKeyguardHidden() {
+        mStatusBarKeyguardViewManager.hide(0, 0);
+        when(mPrimaryBouncer.inTransit()).thenReturn(true);
+
+        mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
+        verify(mPrimaryBouncer).setExpansion(eq(KeyguardBouncer.EXPANSION_HIDDEN));
+    }
+
+    @Test
+    public void onPanelExpansionChanged_showsBouncerWhenSwiping() {
+        mKeyguardStateController.setCanDismissLockScreen(false);
+        mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
+        verify(mPrimaryBouncer).show(eq(false), eq(false));
+
+        // But not when it's already visible
+        reset(mPrimaryBouncer);
+        when(mPrimaryBouncer.isShowing()).thenReturn(true);
+        mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
+        verify(mPrimaryBouncer, never()).show(eq(false), eq(false));
+
+        // Or animating away
+        reset(mPrimaryBouncer);
+        when(mPrimaryBouncer.isAnimatingAway()).thenReturn(true);
+        mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
+        verify(mPrimaryBouncer, never()).show(eq(false), eq(false));
+    }
+
+    @Test
+    public void onPanelExpansionChanged_neverTranslatesBouncerWhenWakeAndUnlock() {
+        when(mBiometricUnlockController.getMode())
+                .thenReturn(BiometricUnlockController.MODE_WAKE_AND_UNLOCK);
+        mStatusBarKeyguardViewManager.onPanelExpansionChanged(
+                expansionEvent(
+                        /* fraction= */ KeyguardBouncer.EXPANSION_VISIBLE,
+                        /* expanded= */ true,
+                        /* tracking= */ false));
+        verify(mPrimaryBouncer, never()).setExpansion(anyFloat());
+    }
+
+    @Test
+    public void onPanelExpansionChanged_neverTranslatesBouncerWhenDismissBouncer() {
+        // Since KeyguardBouncer.EXPANSION_VISIBLE = 0 panel expansion, if the unlock is dismissing
+        // the bouncer, there may be an onPanelExpansionChanged(0) call to collapse the panel
+        // which would mistakenly cause the bouncer to show briefly before its visibility
+        // is set to hide. Therefore, we don't want to propagate panelExpansionChanged to the
+        // bouncer if the bouncer is dismissing as a result of a biometric unlock.
+        when(mBiometricUnlockController.getMode())
+                .thenReturn(BiometricUnlockController.MODE_DISMISS_BOUNCER);
+        mStatusBarKeyguardViewManager.onPanelExpansionChanged(
+                expansionEvent(
+                        /* fraction= */ KeyguardBouncer.EXPANSION_VISIBLE,
+                        /* expanded= */ true,
+                        /* tracking= */ false));
+        verify(mPrimaryBouncer, never()).setExpansion(anyFloat());
+    }
+
+    @Test
+    public void onPanelExpansionChanged_neverTranslatesBouncerWhenOccluded() {
+        when(mKeyguardStateController.isOccluded()).thenReturn(true);
+        mStatusBarKeyguardViewManager.onPanelExpansionChanged(
+                expansionEvent(
+                        /* fraction= */ KeyguardBouncer.EXPANSION_VISIBLE,
+                        /* expanded= */ true,
+                        /* tracking= */ false));
+        verify(mPrimaryBouncer, never()).setExpansion(anyFloat());
+    }
+
+    @Test
+    public void onPanelExpansionChanged_neverTranslatesBouncerWhenShowBouncer() {
+        // Since KeyguardBouncer.EXPANSION_VISIBLE = 0 panel expansion, if the unlock is dismissing
+        // the bouncer, there may be an onPanelExpansionChanged(0) call to collapse the panel
+        // which would mistakenly cause the bouncer to show briefly before its visibility
+        // is set to hide. Therefore, we don't want to propagate panelExpansionChanged to the
+        // bouncer if the bouncer is dismissing as a result of a biometric unlock.
+        when(mBiometricUnlockController.getMode())
+                .thenReturn(BiometricUnlockController.MODE_SHOW_BOUNCER);
+        mStatusBarKeyguardViewManager.onPanelExpansionChanged(
+                expansionEvent(
+                        /* fraction= */ KeyguardBouncer.EXPANSION_VISIBLE,
+                        /* expanded= */ true,
+                        /* tracking= */ false));
+        verify(mPrimaryBouncer, never()).setExpansion(anyFloat());
+    }
+
+    @Test
+    public void onPanelExpansionChanged_neverTranslatesBouncerWhenShadeLocked() {
+        when(mStatusBarStateController.getState()).thenReturn(StatusBarState.SHADE_LOCKED);
+        mStatusBarKeyguardViewManager.onPanelExpansionChanged(
+                expansionEvent(
+                        /* fraction= */ KeyguardBouncer.EXPANSION_VISIBLE,
+                        /* expanded= */ true,
+                        /* tracking= */ false));
+        verify(mPrimaryBouncer, never()).setExpansion(anyFloat());
+    }
+
+    @Test
+    public void setOccluded_animatesPanelExpansion_onlyIfBouncerHidden() {
+        mStatusBarKeyguardViewManager.setOccluded(false /* occluded */, true /* animated */);
+        verify(mCentralSurfaces).animateKeyguardUnoccluding();
+
+        when(mPrimaryBouncer.isShowing()).thenReturn(true);
+        clearInvocations(mCentralSurfaces);
+        mStatusBarKeyguardViewManager.setOccluded(false /* occluded */, true /* animated */);
+        verify(mCentralSurfaces, never()).animateKeyguardUnoccluding();
+    }
+
+    @Test
+    public void setOccluded_onKeyguardOccludedChangedCalled() {
+        clearInvocations(mKeyguardStateController);
+        clearInvocations(mKeyguardUpdateMonitor);
+
+        mStatusBarKeyguardViewManager.setOccluded(false /* occluded */, false /* animated */);
+        verify(mKeyguardStateController).notifyKeyguardState(true, false);
+
+        clearInvocations(mKeyguardUpdateMonitor);
+        clearInvocations(mKeyguardStateController);
+
+        mStatusBarKeyguardViewManager.setOccluded(true /* occluded */, false /* animated */);
+        verify(mKeyguardStateController).notifyKeyguardState(true, true);
+
+        clearInvocations(mKeyguardUpdateMonitor);
+        clearInvocations(mKeyguardStateController);
+
+        mStatusBarKeyguardViewManager.setOccluded(false /* occluded */, false /* animated */);
+        verify(mKeyguardStateController).notifyKeyguardState(true, false);
+    }
+
+    @Test
+    public void setOccluded_isInLaunchTransition_onKeyguardOccludedChangedCalled() {
+        mStatusBarKeyguardViewManager.show(null);
+
+        mStatusBarKeyguardViewManager.setOccluded(true /* occluded */, false /* animated */);
+        verify(mKeyguardStateController).notifyKeyguardState(true, true);
+    }
+
+    @Test
+    public void setOccluded_isLaunchingActivityOverLockscreen_onKeyguardOccludedChangedCalled() {
+        when(mCentralSurfaces.isLaunchingActivityOverLockscreen()).thenReturn(true);
+        mStatusBarKeyguardViewManager.show(null);
+
+        mStatusBarKeyguardViewManager.setOccluded(true /* occluded */, false /* animated */);
+        verify(mKeyguardStateController).notifyKeyguardState(true, true);
+    }
+
+    @Test
+    public void testHiding_cancelsGoneRunnable() {
+        OnDismissAction action = mock(OnDismissAction.class);
+        Runnable cancelAction = mock(Runnable.class);
+        mStatusBarKeyguardViewManager.dismissWithAction(
+                action, cancelAction, true /* afterKeyguardGone */);
+
+        when(mPrimaryBouncer.isShowing()).thenReturn(false);
+        mStatusBarKeyguardViewManager.hideBouncer(true);
+        mStatusBarKeyguardViewManager.hide(0, 30);
+        verify(action, never()).onDismiss();
+        verify(cancelAction).run();
+    }
+
+    @Test
+    public void testHidingBouncer_cancelsGoneRunnable() {
+        OnDismissAction action = mock(OnDismissAction.class);
+        Runnable cancelAction = mock(Runnable.class);
+        mStatusBarKeyguardViewManager.dismissWithAction(
+                action, cancelAction, true /* afterKeyguardGone */);
+
+        when(mPrimaryBouncer.isShowing()).thenReturn(false);
+        mStatusBarKeyguardViewManager.hideBouncer(true);
+
+        verify(action, never()).onDismiss();
+        verify(cancelAction).run();
+    }
+
+    @Test
+    public void testHiding_doesntCancelWhenShowing() {
+        OnDismissAction action = mock(OnDismissAction.class);
+        Runnable cancelAction = mock(Runnable.class);
+        mStatusBarKeyguardViewManager.dismissWithAction(
+                action, cancelAction, true /* afterKeyguardGone */);
+
+        mStatusBarKeyguardViewManager.hide(0, 30);
+        verify(action).onDismiss();
+        verify(cancelAction, never()).run();
+    }
+
+    @Test
+    public void testShowing_whenAlternateAuthShowing() {
+        mStatusBarKeyguardViewManager.setAlternateBouncer(mAlternateBouncer);
+        when(mPrimaryBouncer.isShowing()).thenReturn(false);
+        when(mAlternateBouncer.isShowingAlternateBouncer()).thenReturn(true);
+        assertTrue(
+                "Is showing not accurate when alternative auth showing",
+                mStatusBarKeyguardViewManager.isBouncerShowing());
+    }
+
+    @Test
+    public void testWillBeShowing_whenAlternateAuthShowing() {
+        mStatusBarKeyguardViewManager.setAlternateBouncer(mAlternateBouncer);
+        when(mPrimaryBouncer.isShowing()).thenReturn(false);
+        when(mAlternateBouncer.isShowingAlternateBouncer()).thenReturn(true);
+        assertTrue(
+                "Is or will be showing not accurate when alternative auth showing",
+                mStatusBarKeyguardViewManager.primaryBouncerIsOrWillBeShowing());
+    }
+
+    @Test
+    public void testHideAlternateBouncer_onShowBouncer() {
+        // GIVEN alt auth is showing
+        mStatusBarKeyguardViewManager.setAlternateBouncer(mAlternateBouncer);
+        when(mPrimaryBouncer.isShowing()).thenReturn(false);
+        when(mAlternateBouncer.isShowingAlternateBouncer()).thenReturn(true);
+        reset(mAlternateBouncer);
+
+        // WHEN showBouncer is called
+        mStatusBarKeyguardViewManager.showPrimaryBouncer(true);
+
+        // THEN alt bouncer should be hidden
+        verify(mAlternateBouncer).hideAlternateBouncer();
+    }
+
+    @Test
+    public void testBouncerIsOrWillBeShowing_whenBouncerIsInTransit() {
+        when(mPrimaryBouncer.isShowing()).thenReturn(false);
+        when(mPrimaryBouncer.inTransit()).thenReturn(true);
+
+        assertTrue(
+                "Is or will be showing should be true when bouncer is in transit",
+                mStatusBarKeyguardViewManager.primaryBouncerIsOrWillBeShowing());
+    }
+
+    @Test
+    public void testShowAltAuth_unlockingWithBiometricNotAllowed() {
+        // GIVEN alt auth exists, unlocking with biometric isn't allowed
+        mStatusBarKeyguardViewManager.setAlternateBouncer(mAlternateBouncer);
+        when(mPrimaryBouncer.isShowing()).thenReturn(false);
+        when(mKeyguardUpdateMonitor.isUnlockingWithBiometricAllowed(anyBoolean()))
+                .thenReturn(false);
+
+        // WHEN showGenericBouncer is called
+        final boolean scrimmed = true;
+        mStatusBarKeyguardViewManager.showBouncer(scrimmed);
+
+        // THEN regular bouncer is shown
+        verify(mPrimaryBouncer).show(anyBoolean(), eq(scrimmed));
+        verify(mAlternateBouncer, never()).showAlternateBouncer();
+    }
+
+    @Test
+    public void testShowAlternateBouncer_unlockingWithBiometricAllowed() {
+        // GIVEN alt auth exists, unlocking with biometric is allowed
+        mStatusBarKeyguardViewManager.setAlternateBouncer(mAlternateBouncer);
+        when(mPrimaryBouncer.isShowing()).thenReturn(false);
+        when(mKeyguardUpdateMonitor.isUnlockingWithBiometricAllowed(anyBoolean())).thenReturn(true);
+
+        // WHEN showGenericBouncer is called
+        mStatusBarKeyguardViewManager.showBouncer(true);
+
+        // THEN alt auth bouncer is shown
+        verify(mAlternateBouncer).showAlternateBouncer();
+        verify(mPrimaryBouncer, never()).show(anyBoolean(), anyBoolean());
+    }
+
+    @Test
+    public void testUpdateResources_delegatesToBouncer() {
+        mStatusBarKeyguardViewManager.updateResources();
+
+        verify(mPrimaryBouncer).updateResources();
+    }
+
+    @Test
+    public void updateKeyguardPosition_delegatesToBouncer() {
+        mStatusBarKeyguardViewManager.updateKeyguardPosition(1.0f);
+
+        verify(mPrimaryBouncer).updateKeyguardPosition(1.0f);
+    }
+
+    @Test
+    public void testIsBouncerInTransit() {
+        when(mPrimaryBouncer.inTransit()).thenReturn(true);
+        Truth.assertThat(mStatusBarKeyguardViewManager.isPrimaryBouncerInTransit()).isTrue();
+        when(mPrimaryBouncer.inTransit()).thenReturn(false);
+        Truth.assertThat(mStatusBarKeyguardViewManager.isPrimaryBouncerInTransit()).isFalse();
+        mPrimaryBouncer = null;
+        Truth.assertThat(mStatusBarKeyguardViewManager.isPrimaryBouncerInTransit()).isFalse();
+    }
+
+    private static ShadeExpansionChangeEvent expansionEvent(
+            float fraction, boolean expanded, boolean tracking) {
+        return new ShadeExpansionChangeEvent(
+                fraction, expanded, tracking, /* dragDownPxAmount= */ 0f);
+    }
+
+    @Test
+    public void testPredictiveBackCallback_registration() {
+        /* verify that a predictive back callback is registered when the bouncer becomes visible */
+        mBouncerExpansionCallback.onVisibilityChanged(true);
+        verify(mOnBackInvokedDispatcher).registerOnBackInvokedCallback(
+                eq(OnBackInvokedDispatcher.PRIORITY_OVERLAY),
+                mOnBackInvokedCallback.capture());
+
+        /* verify that the same callback is unregistered when the bouncer becomes invisible */
+        mBouncerExpansionCallback.onVisibilityChanged(false);
+        verify(mOnBackInvokedDispatcher).unregisterOnBackInvokedCallback(
+                eq(mOnBackInvokedCallback.getValue()));
+    }
+
+    @Test
+    public void testPredictiveBackCallback_invocationHidesBouncer() {
+        mBouncerExpansionCallback.onVisibilityChanged(true);
+        /* capture the predictive back callback during registration */
+        verify(mOnBackInvokedDispatcher).registerOnBackInvokedCallback(
+                eq(OnBackInvokedDispatcher.PRIORITY_OVERLAY),
+                mOnBackInvokedCallback.capture());
+
+        when(mPrimaryBouncer.isShowing()).thenReturn(true);
+        when(mCentralSurfaces.shouldKeyguardHideImmediately()).thenReturn(true);
+        /* invoke the back callback directly */
+        mOnBackInvokedCallback.getValue().onBackInvoked();
+
+        /* verify that the bouncer will be hidden as a result of the invocation */
+        verify(mCentralSurfaces).setBouncerShowing(eq(false));
+    }
+
+    @Test
+    public void testReportBouncerOnDreamWhenVisible() {
+        mBouncerExpansionCallback.onVisibilityChanged(true);
+        verify(mCentralSurfaces).setBouncerShowingOverDream(false);
+        Mockito.clearInvocations(mCentralSurfaces);
+        when(mDreamOverlayStateController.isOverlayActive()).thenReturn(true);
+        mBouncerExpansionCallback.onVisibilityChanged(true);
+        verify(mCentralSurfaces).setBouncerShowingOverDream(true);
+    }
+
+    @Test
+    public void testReportBouncerOnDreamWhenNotVisible() {
+        mBouncerExpansionCallback.onVisibilityChanged(false);
+        verify(mCentralSurfaces).setBouncerShowingOverDream(false);
+        Mockito.clearInvocations(mCentralSurfaces);
+        when(mDreamOverlayStateController.isOverlayActive()).thenReturn(true);
+        mBouncerExpansionCallback.onVisibilityChanged(false);
+        verify(mCentralSurfaces).setBouncerShowingOverDream(false);
+    }
+
+    @Test
+    public void flag_off_DoesNotCallBouncerInteractor() {
+        when(mFeatureFlags.isEnabled(MODERN_BOUNCER)).thenReturn(false);
+        mStatusBarKeyguardViewManager.hideBouncer(false);
+        verify(mPrimaryBouncerInteractor, never()).hide();
+    }
+
+    @Test
+    public void hideAlternateBouncer_beforeCentralSurfacesRegistered() {
+        mStatusBarKeyguardViewManager =
+                new StatusBarKeyguardViewManager(
+                        getContext(),
+                        mViewMediatorCallback,
+                        mLockPatternUtils,
+                        mStatusBarStateController,
+                        mock(ConfigurationController.class),
+                        mKeyguardUpdateMonitor,
+                        mDreamOverlayStateController,
+                        mock(NavigationModeController.class),
+                        mock(DockManager.class),
+                        mock(NotificationShadeWindowController.class),
+                        mKeyguardStateController,
+                        mock(NotificationMediaManager.class),
+                        mKeyguardBouncerFactory,
+                        mKeyguardMessageAreaFactory,
+                        Optional.of(mSysUiUnfoldComponent),
+                        () -> mShadeController,
+                        mLatencyTracker,
+                        mKeyguardSecurityModel,
+                        mFeatureFlags,
+                        mPrimaryBouncerCallbackInteractor,
+                        mPrimaryBouncerInteractor,
+                        mBouncerView) {
+                    @Override
+                    public ViewRootImpl getViewRootImpl() {
+                        return mViewRootImpl;
+                    }
+                };
+
+        // the following call before registering centralSurfaces should NOT throw a NPE:
+        mStatusBarKeyguardViewManager.hideAlternateBouncer(true);
+    }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/FakeMobileConnectionRepository.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/FakeMobileConnectionRepository.kt
index 288f54c..5265ec6 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/FakeMobileConnectionRepository.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/FakeMobileConnectionRepository.kt
@@ -16,12 +16,13 @@
 
 package com.android.systemui.statusbar.pipeline.mobile.data.repository
 
-import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileSubscriptionModel
+import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectionModel
 import kotlinx.coroutines.flow.MutableStateFlow
 
-class FakeMobileConnectionRepository : MobileConnectionRepository {
-    private val _subscriptionsModelFlow = MutableStateFlow(MobileSubscriptionModel())
-    override val subscriptionModelFlow = _subscriptionsModelFlow
+// TODO(b/261632894): remove this in favor of the real impl or DemoMobileConnectionRepository
+class FakeMobileConnectionRepository(override val subId: Int) : MobileConnectionRepository {
+    private val _connectionInfo = MutableStateFlow(MobileConnectionModel())
+    override val connectionInfo = _connectionInfo
 
     private val _dataEnabled = MutableStateFlow(true)
     override val dataEnabled = _dataEnabled
@@ -29,8 +30,8 @@
     private val _isDefaultDataSubscription = MutableStateFlow(true)
     override val isDefaultDataSubscription = _isDefaultDataSubscription
 
-    fun setMobileSubscriptionModel(model: MobileSubscriptionModel) {
-        _subscriptionsModelFlow.value = model
+    fun setConnectionInfo(model: MobileConnectionModel) {
+        _connectionInfo.value = model
     }
 
     fun setDataEnabled(enabled: Boolean) {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/FakeMobileConnectionsRepository.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/FakeMobileConnectionsRepository.kt
index 533d5d9..d6af0e6 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/FakeMobileConnectionsRepository.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/FakeMobileConnectionsRepository.kt
@@ -16,23 +16,43 @@
 
 package com.android.systemui.statusbar.pipeline.mobile.data.repository
 
-import android.telephony.SubscriptionInfo
 import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID
-import com.android.settingslib.mobile.MobileMappings.Config
+import android.telephony.TelephonyDisplayInfo
+import android.telephony.TelephonyManager
+import com.android.settingslib.SignalIcon
+import com.android.settingslib.mobile.TelephonyIcons
 import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel
-import kotlinx.coroutines.flow.Flow
+import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
+import com.android.systemui.statusbar.pipeline.mobile.util.MobileMappingsProxy
 import kotlinx.coroutines.flow.MutableStateFlow
 
-class FakeMobileConnectionsRepository : MobileConnectionsRepository {
-    private val _subscriptionsFlow = MutableStateFlow<List<SubscriptionInfo>>(listOf())
-    override val subscriptionsFlow: Flow<List<SubscriptionInfo>> = _subscriptionsFlow
+// TODO(b/261632894): remove this in favor of the real impl or DemoMobileConnectionsRepository
+class FakeMobileConnectionsRepository(mobileMappings: MobileMappingsProxy) :
+    MobileConnectionsRepository {
+    val GSM_KEY = mobileMappings.toIconKey(GSM)
+    val LTE_KEY = mobileMappings.toIconKey(LTE)
+    val UMTS_KEY = mobileMappings.toIconKey(UMTS)
+    val LTE_ADVANCED_KEY = mobileMappings.toIconKeyOverride(LTE_ADVANCED_PRO)
+
+    /**
+     * To avoid a reliance on [MobileMappings], we'll build a simpler map from network type to
+     * mobile icon. See TelephonyManager.NETWORK_TYPES for a list of types and [TelephonyIcons] for
+     * the exhaustive set of icons
+     */
+    val TEST_MAPPING: Map<String, SignalIcon.MobileIconGroup> =
+        mapOf(
+            GSM_KEY to TelephonyIcons.THREE_G,
+            LTE_KEY to TelephonyIcons.LTE,
+            UMTS_KEY to TelephonyIcons.FOUR_G,
+            LTE_ADVANCED_KEY to TelephonyIcons.NR_5G,
+        )
+
+    private val _subscriptions = MutableStateFlow<List<SubscriptionModel>>(listOf())
+    override val subscriptions = _subscriptions
 
     private val _activeMobileDataSubscriptionId = MutableStateFlow(INVALID_SUBSCRIPTION_ID)
     override val activeMobileDataSubscriptionId = _activeMobileDataSubscriptionId
 
-    private val _defaultDataSubRatConfig = MutableStateFlow(Config())
-    override val defaultDataSubRatConfig = _defaultDataSubRatConfig
-
     private val _defaultDataSubId = MutableStateFlow(INVALID_SUBSCRIPTION_ID)
     override val defaultDataSubId = _defaultDataSubId
 
@@ -41,18 +61,21 @@
 
     private val subIdRepos = mutableMapOf<Int, MobileConnectionRepository>()
     override fun getRepoForSubId(subId: Int): MobileConnectionRepository {
-        return subIdRepos[subId] ?: FakeMobileConnectionRepository().also { subIdRepos[subId] = it }
+        return subIdRepos[subId]
+            ?: FakeMobileConnectionRepository(subId).also { subIdRepos[subId] = it }
     }
 
     private val _globalMobileDataSettingChangedEvent = MutableStateFlow(Unit)
     override val globalMobileDataSettingChangedEvent = _globalMobileDataSettingChangedEvent
 
-    fun setSubscriptions(subs: List<SubscriptionInfo>) {
-        _subscriptionsFlow.value = subs
-    }
+    private val _defaultMobileIconMapping = MutableStateFlow(TEST_MAPPING)
+    override val defaultMobileIconMapping = _defaultMobileIconMapping
 
-    fun setDefaultDataSubRatConfig(config: Config) {
-        _defaultDataSubRatConfig.value = config
+    private val _defaultMobileIconGroup = MutableStateFlow(DEFAULT_ICON)
+    override val defaultMobileIconGroup = _defaultMobileIconGroup
+
+    fun setSubscriptions(subs: List<SubscriptionModel>) {
+        _subscriptions.value = subs
     }
 
     fun setDefaultDataSubId(id: Int) {
@@ -74,4 +97,14 @@
     fun setMobileConnectionRepositoryMap(connections: Map<Int, MobileConnectionRepository>) {
         connections.forEach { entry -> subIdRepos[entry.key] = entry.value }
     }
+
+    companion object {
+        val DEFAULT_ICON = TelephonyIcons.G
+
+        // Use [MobileMappings] to define some simple definitions
+        const val GSM = TelephonyManager.NETWORK_TYPE_GSM
+        const val LTE = TelephonyManager.NETWORK_TYPE_LTE
+        const val UMTS = TelephonyManager.NETWORK_TYPE_UMTS
+        const val LTE_ADVANCED_PRO = TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_LTE_ADVANCED_PRO
+    }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileRepositorySwitcherTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileRepositorySwitcherTest.kt
index 96a280a..18ae90d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileRepositorySwitcherTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/MobileRepositorySwitcherTest.kt
@@ -24,11 +24,13 @@
 import com.android.systemui.SysuiTestCase
 import com.android.systemui.demomode.DemoMode
 import com.android.systemui.demomode.DemoModeController
+import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.demo.DemoMobileConnectionsRepository
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.demo.DemoModeMobileConnectionDataSource
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.demo.model.FakeNetworkEventModel
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.demo.validMobileEvent
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.prod.MobileConnectionsRepositoryImpl
+import com.android.systemui.statusbar.pipeline.mobile.util.FakeMobileMappingsProxy
 import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger
 import com.android.systemui.util.mockito.any
 import com.android.systemui.util.mockito.kotlinArgumentCaptor
@@ -76,6 +78,7 @@
 
     private val globalSettings = FakeSettings()
     private val fakeNetworkEventsFlow = MutableStateFlow<FakeNetworkEventModel?>(null)
+    private val mobileMappings = FakeMobileMappingsProxy()
 
     private val scope = CoroutineScope(IMMEDIATE)
 
@@ -97,6 +100,7 @@
                 subscriptionManager,
                 telephonyManager,
                 logger,
+                mobileMappings,
                 fakeBroadcastDispatcher,
                 globalSettings,
                 context,
@@ -155,15 +159,15 @@
             whenever(subscriptionManager.completeActiveSubscriptionInfoList)
                 .thenReturn(listOf(SUB_1, SUB_2))
 
-            var latest: List<SubscriptionInfo>? = null
-            val job = underTest.subscriptionsFlow.onEach { latest = it }.launchIn(this)
+            var latest: List<SubscriptionModel>? = null
+            val job = underTest.subscriptions.onEach { latest = it }.launchIn(this)
 
             // The real subscriptions has 2 subs
             whenever(subscriptionManager.completeActiveSubscriptionInfoList)
                 .thenReturn(listOf(SUB_1, SUB_2))
             getSubscriptionCallback().onSubscriptionsChanged()
 
-            assertThat(latest).isEqualTo(listOf(SUB_1, SUB_2))
+            assertThat(latest).isEqualTo(listOf(MODEL_1, MODEL_2))
 
             // Demo mode turns on, and we should see only the demo subscriptions
             startDemoMode()
@@ -176,7 +180,7 @@
 
             finishDemoMode()
 
-            assertThat(latest).isEqualTo(listOf(SUB_1, SUB_2))
+            assertThat(latest).isEqualTo(listOf(MODEL_1, MODEL_2))
 
             job.cancel()
         }
@@ -211,9 +215,11 @@
         private const val SUB_1_ID = 1
         private val SUB_1 =
             mock<SubscriptionInfo>().also { whenever(it.subscriptionId).thenReturn(SUB_1_ID) }
+        private val MODEL_1 = SubscriptionModel(subscriptionId = SUB_1_ID)
 
         private const val SUB_2_ID = 2
         private val SUB_2 =
             mock<SubscriptionInfo>().also { whenever(it.subscriptionId).thenReturn(SUB_2_ID) }
+        private val MODEL_2 = SubscriptionModel(subscriptionId = SUB_2_ID)
     }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionParameterizedTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionParameterizedTest.kt
index bf5ecd8..e943de2 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionParameterizedTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionParameterizedTest.kt
@@ -23,7 +23,7 @@
 import com.android.settingslib.mobile.TelephonyIcons
 import com.android.systemui.SysuiTestCase
 import com.android.systemui.statusbar.pipeline.mobile.data.model.DataConnectionState
-import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileSubscriptionModel
+import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectionModel
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.demo.model.FakeNetworkEventModel
 import com.android.systemui.util.mockito.mock
 import com.android.systemui.util.mockito.whenever
@@ -109,18 +109,18 @@
     ) {
         when (model) {
             is FakeNetworkEventModel.Mobile -> {
-                val subscriptionModel: MobileSubscriptionModel = conn.subscriptionModelFlow.value
+                val connectionInfo: MobileConnectionModel = conn.connectionInfo.value
                 assertThat(conn.subId).isEqualTo(model.subId)
-                assertThat(subscriptionModel.cdmaLevel).isEqualTo(model.level)
-                assertThat(subscriptionModel.primaryLevel).isEqualTo(model.level)
-                assertThat(subscriptionModel.dataActivityDirection).isEqualTo(model.activity)
-                assertThat(subscriptionModel.carrierNetworkChangeActive)
+                assertThat(connectionInfo.cdmaLevel).isEqualTo(model.level)
+                assertThat(connectionInfo.primaryLevel).isEqualTo(model.level)
+                assertThat(connectionInfo.dataActivityDirection).isEqualTo(model.activity)
+                assertThat(connectionInfo.carrierNetworkChangeActive)
                     .isEqualTo(model.carrierNetworkChange)
 
                 // TODO(b/261029387): check these once we start handling them
-                assertThat(subscriptionModel.isEmergencyOnly).isFalse()
-                assertThat(subscriptionModel.isGsm).isFalse()
-                assertThat(subscriptionModel.dataConnectionState)
+                assertThat(connectionInfo.isEmergencyOnly).isFalse()
+                assertThat(connectionInfo.isGsm).isFalse()
+                assertThat(connectionInfo.dataConnectionState)
                     .isEqualTo(DataConnectionState.Connected)
             }
             // MobileDisabled isn't combinatorial in nature, and is tested in
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepositoryTest.kt
index a8f6993..32d0410 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepositoryTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/demo/DemoMobileConnectionsRepositoryTest.kt
@@ -16,7 +16,6 @@
 
 package com.android.systemui.statusbar.pipeline.mobile.data.repository.demo
 
-import android.telephony.SubscriptionInfo
 import android.telephony.TelephonyManager.DATA_ACTIVITY_INOUT
 import android.telephony.TelephonyManager.UNKNOWN_CARRIER_ID
 import androidx.test.filters.SmallTest
@@ -24,7 +23,8 @@
 import com.android.settingslib.mobile.TelephonyIcons.THREE_G
 import com.android.systemui.SysuiTestCase
 import com.android.systemui.statusbar.pipeline.mobile.data.model.DataConnectionState
-import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileSubscriptionModel
+import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectionModel
+import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.demo.model.FakeNetworkEventModel
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.demo.model.FakeNetworkEventModel.MobileDisabled
 import com.android.systemui.util.mockito.mock
@@ -73,8 +73,8 @@
     @Test
     fun `network event - create new subscription`() =
         testScope.runTest {
-            var latest: List<SubscriptionInfo>? = null
-            val job = underTest.subscriptionsFlow.onEach { latest = it }.launchIn(this)
+            var latest: List<SubscriptionModel>? = null
+            val job = underTest.subscriptions.onEach { latest = it }.launchIn(this)
 
             assertThat(latest).isEmpty()
 
@@ -89,8 +89,8 @@
     @Test
     fun `network event - reuses subscription when same Id`() =
         testScope.runTest {
-            var latest: List<SubscriptionInfo>? = null
-            val job = underTest.subscriptionsFlow.onEach { latest = it }.launchIn(this)
+            var latest: List<SubscriptionModel>? = null
+            val job = underTest.subscriptions.onEach { latest = it }.launchIn(this)
 
             assertThat(latest).isEmpty()
 
@@ -111,8 +111,8 @@
     @Test
     fun `multiple subscriptions`() =
         testScope.runTest {
-            var latest: List<SubscriptionInfo>? = null
-            val job = underTest.subscriptionsFlow.onEach { latest = it }.launchIn(this)
+            var latest: List<SubscriptionModel>? = null
+            val job = underTest.subscriptions.onEach { latest = it }.launchIn(this)
 
             fakeNetworkEventFlow.value = validMobileEvent(subId = 1)
             fakeNetworkEventFlow.value = validMobileEvent(subId = 2)
@@ -125,8 +125,8 @@
     @Test
     fun `mobile disabled event - disables connection - subId specified - single conn`() =
         testScope.runTest {
-            var latest: List<SubscriptionInfo>? = null
-            val job = underTest.subscriptionsFlow.onEach { latest = it }.launchIn(this)
+            var latest: List<SubscriptionModel>? = null
+            val job = underTest.subscriptions.onEach { latest = it }.launchIn(this)
 
             fakeNetworkEventFlow.value = validMobileEvent(subId = 1, level = 1)
 
@@ -140,8 +140,8 @@
     @Test
     fun `mobile disabled event - disables connection - subId not specified - single conn`() =
         testScope.runTest {
-            var latest: List<SubscriptionInfo>? = null
-            val job = underTest.subscriptionsFlow.onEach { latest = it }.launchIn(this)
+            var latest: List<SubscriptionModel>? = null
+            val job = underTest.subscriptions.onEach { latest = it }.launchIn(this)
 
             fakeNetworkEventFlow.value = validMobileEvent(subId = 1, level = 1)
 
@@ -155,8 +155,8 @@
     @Test
     fun `mobile disabled event - disables connection - subId specified - multiple conn`() =
         testScope.runTest {
-            var latest: List<SubscriptionInfo>? = null
-            val job = underTest.subscriptionsFlow.onEach { latest = it }.launchIn(this)
+            var latest: List<SubscriptionModel>? = null
+            val job = underTest.subscriptions.onEach { latest = it }.launchIn(this)
 
             fakeNetworkEventFlow.value = validMobileEvent(subId = 1, level = 1)
             fakeNetworkEventFlow.value = validMobileEvent(subId = 2, level = 1)
@@ -171,8 +171,8 @@
     @Test
     fun `mobile disabled event - subId not specified - multiple conn - ignores command`() =
         testScope.runTest {
-            var latest: List<SubscriptionInfo>? = null
-            val job = underTest.subscriptionsFlow.onEach { latest = it }.launchIn(this)
+            var latest: List<SubscriptionModel>? = null
+            val job = underTest.subscriptions.onEach { latest = it }.launchIn(this)
 
             fakeNetworkEventFlow.value = validMobileEvent(subId = 1, level = 1)
             fakeNetworkEventFlow.value = validMobileEvent(subId = 2, level = 1)
@@ -184,13 +184,32 @@
             job.cancel()
         }
 
+    /** Regression test for b/261706421 */
+    @Test
+    fun `multiple connections - remove all - does not throw`() =
+        testScope.runTest {
+            var latest: List<SubscriptionModel>? = null
+            val job = underTest.subscriptions.onEach { latest = it }.launchIn(this)
+
+            // Two subscriptions are added
+            fakeNetworkEventFlow.value = validMobileEvent(subId = 1, level = 1)
+            fakeNetworkEventFlow.value = validMobileEvent(subId = 2, level = 1)
+
+            // Then both are removed by turning off demo mode
+            underTest.stopProcessingCommands()
+
+            assertThat(latest).isEmpty()
+
+            job.cancel()
+        }
+
     @Test
     fun `demo connection - single subscription`() =
         testScope.runTest {
             var currentEvent: FakeNetworkEventModel = validMobileEvent(subId = 1)
             var connections: List<DemoMobileConnectionRepository>? = null
             val job =
-                underTest.subscriptionsFlow
+                underTest.subscriptions
                     .onEach { infos ->
                         connections =
                             infos.map { info -> underTest.getRepoForSubId(info.subscriptionId) }
@@ -222,7 +241,7 @@
             var connection2: DemoMobileConnectionRepository? = null
             var connections: List<DemoMobileConnectionRepository>? = null
             val job =
-                underTest.subscriptionsFlow
+                underTest.subscriptions
                     .onEach { infos ->
                         connections =
                             infos.map { info -> underTest.getRepoForSubId(info.subscriptionId) }
@@ -266,18 +285,18 @@
     ) {
         when (model) {
             is FakeNetworkEventModel.Mobile -> {
-                val subscriptionModel: MobileSubscriptionModel = conn.subscriptionModelFlow.value
+                val connectionInfo: MobileConnectionModel = conn.connectionInfo.value
                 assertThat(conn.subId).isEqualTo(model.subId)
-                assertThat(subscriptionModel.cdmaLevel).isEqualTo(model.level)
-                assertThat(subscriptionModel.primaryLevel).isEqualTo(model.level)
-                assertThat(subscriptionModel.dataActivityDirection).isEqualTo(model.activity)
-                assertThat(subscriptionModel.carrierNetworkChangeActive)
+                assertThat(connectionInfo.cdmaLevel).isEqualTo(model.level)
+                assertThat(connectionInfo.primaryLevel).isEqualTo(model.level)
+                assertThat(connectionInfo.dataActivityDirection).isEqualTo(model.activity)
+                assertThat(connectionInfo.carrierNetworkChangeActive)
                     .isEqualTo(model.carrierNetworkChange)
 
                 // TODO(b/261029387) check these once we start handling them
-                assertThat(subscriptionModel.isEmergencyOnly).isFalse()
-                assertThat(subscriptionModel.isGsm).isFalse()
-                assertThat(subscriptionModel.dataConnectionState)
+                assertThat(connectionInfo.isEmergencyOnly).isFalse()
+                assertThat(connectionInfo.isGsm).isFalse()
+                assertThat(connectionInfo.dataConnectionState)
                     .isEqualTo(DataConnectionState.Connected)
             }
             else -> {}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt
index c8df5ac..1fc9c60 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt
@@ -37,10 +37,12 @@
 import androidx.test.filters.SmallTest
 import com.android.systemui.SysuiTestCase
 import com.android.systemui.statusbar.pipeline.mobile.data.model.DataConnectionState
-import com.android.systemui.statusbar.pipeline.mobile.data.model.DefaultNetworkType
-import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileSubscriptionModel
-import com.android.systemui.statusbar.pipeline.mobile.data.model.OverrideNetworkType
+import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectionModel
+import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType.DefaultNetworkType
+import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType.OverrideNetworkType
+import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType.UnknownNetworkType
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.FakeMobileConnectionsRepository
+import com.android.systemui.statusbar.pipeline.mobile.util.FakeMobileMappingsProxy
 import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger
 import com.android.systemui.util.mockito.any
 import com.android.systemui.util.mockito.argumentCaptor
@@ -72,8 +74,9 @@
     @Mock private lateinit var logger: ConnectivityPipelineLogger
 
     private val scope = CoroutineScope(IMMEDIATE)
+    private val mobileMappings = FakeMobileMappingsProxy()
     private val globalSettings = FakeSettings()
-    private val connectionsRepo = FakeMobileConnectionsRepository()
+    private val connectionsRepo = FakeMobileConnectionsRepository(mobileMappings)
 
     @Before
     fun setUp() {
@@ -89,6 +92,7 @@
                 globalSettings,
                 connectionsRepo.defaultDataSubId,
                 connectionsRepo.globalMobileDataSettingChangedEvent,
+                mobileMappings,
                 IMMEDIATE,
                 logger,
                 scope,
@@ -103,10 +107,10 @@
     @Test
     fun testFlowForSubId_default() =
         runBlocking(IMMEDIATE) {
-            var latest: MobileSubscriptionModel? = null
-            val job = underTest.subscriptionModelFlow.onEach { latest = it }.launchIn(this)
+            var latest: MobileConnectionModel? = null
+            val job = underTest.connectionInfo.onEach { latest = it }.launchIn(this)
 
-            assertThat(latest).isEqualTo(MobileSubscriptionModel())
+            assertThat(latest).isEqualTo(MobileConnectionModel())
 
             job.cancel()
         }
@@ -114,8 +118,8 @@
     @Test
     fun testFlowForSubId_emergencyOnly() =
         runBlocking(IMMEDIATE) {
-            var latest: MobileSubscriptionModel? = null
-            val job = underTest.subscriptionModelFlow.onEach { latest = it }.launchIn(this)
+            var latest: MobileConnectionModel? = null
+            val job = underTest.connectionInfo.onEach { latest = it }.launchIn(this)
 
             val serviceState = ServiceState()
             serviceState.isEmergencyOnly = true
@@ -130,8 +134,8 @@
     @Test
     fun testFlowForSubId_emergencyOnly_toggles() =
         runBlocking(IMMEDIATE) {
-            var latest: MobileSubscriptionModel? = null
-            val job = underTest.subscriptionModelFlow.onEach { latest = it }.launchIn(this)
+            var latest: MobileConnectionModel? = null
+            val job = underTest.connectionInfo.onEach { latest = it }.launchIn(this)
 
             val callback = getTelephonyCallbackForType<ServiceStateListener>()
             val serviceState = ServiceState()
@@ -148,8 +152,8 @@
     @Test
     fun testFlowForSubId_signalStrengths_levelsUpdate() =
         runBlocking(IMMEDIATE) {
-            var latest: MobileSubscriptionModel? = null
-            val job = underTest.subscriptionModelFlow.onEach { latest = it }.launchIn(this)
+            var latest: MobileConnectionModel? = null
+            val job = underTest.connectionInfo.onEach { latest = it }.launchIn(this)
 
             val callback = getTelephonyCallbackForType<TelephonyCallback.SignalStrengthsListener>()
             val strength = signalStrength(gsmLevel = 1, cdmaLevel = 2, isGsm = true)
@@ -165,8 +169,8 @@
     @Test
     fun testFlowForSubId_dataConnectionState_connected() =
         runBlocking(IMMEDIATE) {
-            var latest: MobileSubscriptionModel? = null
-            val job = underTest.subscriptionModelFlow.onEach { latest = it }.launchIn(this)
+            var latest: MobileConnectionModel? = null
+            val job = underTest.connectionInfo.onEach { latest = it }.launchIn(this)
 
             val callback =
                 getTelephonyCallbackForType<TelephonyCallback.DataConnectionStateListener>()
@@ -180,8 +184,8 @@
     @Test
     fun testFlowForSubId_dataConnectionState_connecting() =
         runBlocking(IMMEDIATE) {
-            var latest: MobileSubscriptionModel? = null
-            val job = underTest.subscriptionModelFlow.onEach { latest = it }.launchIn(this)
+            var latest: MobileConnectionModel? = null
+            val job = underTest.connectionInfo.onEach { latest = it }.launchIn(this)
 
             val callback =
                 getTelephonyCallbackForType<TelephonyCallback.DataConnectionStateListener>()
@@ -195,8 +199,8 @@
     @Test
     fun testFlowForSubId_dataConnectionState_disconnected() =
         runBlocking(IMMEDIATE) {
-            var latest: MobileSubscriptionModel? = null
-            val job = underTest.subscriptionModelFlow.onEach { latest = it }.launchIn(this)
+            var latest: MobileConnectionModel? = null
+            val job = underTest.connectionInfo.onEach { latest = it }.launchIn(this)
 
             val callback =
                 getTelephonyCallbackForType<TelephonyCallback.DataConnectionStateListener>()
@@ -210,8 +214,8 @@
     @Test
     fun testFlowForSubId_dataConnectionState_disconnecting() =
         runBlocking(IMMEDIATE) {
-            var latest: MobileSubscriptionModel? = null
-            val job = underTest.subscriptionModelFlow.onEach { latest = it }.launchIn(this)
+            var latest: MobileConnectionModel? = null
+            val job = underTest.connectionInfo.onEach { latest = it }.launchIn(this)
 
             val callback =
                 getTelephonyCallbackForType<TelephonyCallback.DataConnectionStateListener>()
@@ -225,8 +229,8 @@
     @Test
     fun testFlowForSubId_dataConnectionState_unknown() =
         runBlocking(IMMEDIATE) {
-            var latest: MobileSubscriptionModel? = null
-            val job = underTest.subscriptionModelFlow.onEach { latest = it }.launchIn(this)
+            var latest: MobileConnectionModel? = null
+            val job = underTest.connectionInfo.onEach { latest = it }.launchIn(this)
 
             val callback =
                 getTelephonyCallbackForType<TelephonyCallback.DataConnectionStateListener>()
@@ -240,8 +244,8 @@
     @Test
     fun testFlowForSubId_dataActivity() =
         runBlocking(IMMEDIATE) {
-            var latest: MobileSubscriptionModel? = null
-            val job = underTest.subscriptionModelFlow.onEach { latest = it }.launchIn(this)
+            var latest: MobileConnectionModel? = null
+            val job = underTest.connectionInfo.onEach { latest = it }.launchIn(this)
 
             val callback = getTelephonyCallbackForType<TelephonyCallback.DataActivityListener>()
             callback.onDataActivity(3)
@@ -254,8 +258,8 @@
     @Test
     fun testFlowForSubId_carrierNetworkChange() =
         runBlocking(IMMEDIATE) {
-            var latest: MobileSubscriptionModel? = null
-            val job = underTest.subscriptionModelFlow.onEach { latest = it }.launchIn(this)
+            var latest: MobileConnectionModel? = null
+            val job = underTest.connectionInfo.onEach { latest = it }.launchIn(this)
 
             val callback = getTelephonyCallbackForType<TelephonyCallback.CarrierNetworkListener>()
             callback.onCarrierNetworkChange(true)
@@ -268,11 +272,11 @@
     @Test
     fun subscriptionFlow_networkType_default() =
         runBlocking(IMMEDIATE) {
-            var latest: MobileSubscriptionModel? = null
-            val job = underTest.subscriptionModelFlow.onEach { latest = it }.launchIn(this)
+            var latest: MobileConnectionModel? = null
+            val job = underTest.connectionInfo.onEach { latest = it }.launchIn(this)
 
             val type = NETWORK_TYPE_UNKNOWN
-            val expected = DefaultNetworkType(type)
+            val expected = UnknownNetworkType
 
             assertThat(latest?.resolvedNetworkType).isEqualTo(expected)
 
@@ -282,12 +286,12 @@
     @Test
     fun subscriptionFlow_networkType_updatesUsingDefault() =
         runBlocking(IMMEDIATE) {
-            var latest: MobileSubscriptionModel? = null
-            val job = underTest.subscriptionModelFlow.onEach { latest = it }.launchIn(this)
+            var latest: MobileConnectionModel? = null
+            val job = underTest.connectionInfo.onEach { latest = it }.launchIn(this)
 
             val callback = getTelephonyCallbackForType<TelephonyCallback.DisplayInfoListener>()
             val type = NETWORK_TYPE_LTE
-            val expected = DefaultNetworkType(type)
+            val expected = DefaultNetworkType(type, mobileMappings.toIconKey(type))
             val ti = mock<TelephonyDisplayInfo>().also { whenever(it.networkType).thenReturn(type) }
             callback.onDisplayInfoChanged(ti)
 
@@ -299,14 +303,15 @@
     @Test
     fun subscriptionFlow_networkType_updatesUsingOverride() =
         runBlocking(IMMEDIATE) {
-            var latest: MobileSubscriptionModel? = null
-            val job = underTest.subscriptionModelFlow.onEach { latest = it }.launchIn(this)
+            var latest: MobileConnectionModel? = null
+            val job = underTest.connectionInfo.onEach { latest = it }.launchIn(this)
 
             val callback = getTelephonyCallbackForType<TelephonyCallback.DisplayInfoListener>()
             val type = OVERRIDE_NETWORK_TYPE_LTE_CA
-            val expected = OverrideNetworkType(type)
+            val expected = OverrideNetworkType(type, mobileMappings.toIconKeyOverride(type))
             val ti =
                 mock<TelephonyDisplayInfo>().also {
+                    whenever(it.networkType).thenReturn(type)
                     whenever(it.overrideNetworkType).thenReturn(type)
                 }
             callback.onDisplayInfoChanged(ti)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryTest.kt
index 359ea18..4b82b39 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryTest.kt
@@ -32,6 +32,8 @@
 import com.android.internal.telephony.PhoneConstants
 import com.android.systemui.SysuiTestCase
 import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel
+import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
+import com.android.systemui.statusbar.pipeline.mobile.util.FakeMobileMappingsProxy
 import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger
 import com.android.systemui.util.mockito.any
 import com.android.systemui.util.mockito.argumentCaptor
@@ -50,6 +52,7 @@
 import org.junit.Assert.assertThrows
 import org.junit.Before
 import org.junit.Test
+import org.mockito.ArgumentMatchers.anyInt
 import org.mockito.Mock
 import org.mockito.Mockito.verify
 import org.mockito.MockitoAnnotations
@@ -65,6 +68,8 @@
     @Mock private lateinit var telephonyManager: TelephonyManager
     @Mock private lateinit var logger: ConnectivityPipelineLogger
 
+    private val mobileMappings = FakeMobileMappingsProxy()
+
     private val scope = CoroutineScope(IMMEDIATE)
     private val globalSettings = FakeSettings()
 
@@ -72,18 +77,37 @@
     fun setUp() {
         MockitoAnnotations.initMocks(this)
 
+        // Set up so the individual connection repositories
+        whenever(telephonyManager.createForSubscriptionId(anyInt())).thenAnswer { invocation ->
+            telephonyManager.also {
+                whenever(telephonyManager.subscriptionId).thenReturn(invocation.getArgument(0))
+            }
+        }
+
+        val connectionFactory: MobileConnectionRepositoryImpl.Factory =
+            MobileConnectionRepositoryImpl.Factory(
+                context = context,
+                telephonyManager = telephonyManager,
+                bgDispatcher = IMMEDIATE,
+                globalSettings = globalSettings,
+                logger = logger,
+                mobileMappingsProxy = mobileMappings,
+                scope = scope,
+            )
+
         underTest =
             MobileConnectionsRepositoryImpl(
                 connectivityManager,
                 subscriptionManager,
                 telephonyManager,
                 logger,
+                mobileMappings,
                 fakeBroadcastDispatcher,
                 globalSettings,
                 context,
                 IMMEDIATE,
                 scope,
-                mock(),
+                connectionFactory,
             )
     }
 
@@ -95,21 +119,21 @@
     @Test
     fun testSubscriptions_initiallyEmpty() =
         runBlocking(IMMEDIATE) {
-            assertThat(underTest.subscriptionsFlow.value).isEqualTo(listOf<SubscriptionInfo>())
+            assertThat(underTest.subscriptions.value).isEqualTo(listOf<SubscriptionModel>())
         }
 
     @Test
     fun testSubscriptions_listUpdates() =
         runBlocking(IMMEDIATE) {
-            var latest: List<SubscriptionInfo>? = null
+            var latest: List<SubscriptionModel>? = null
 
-            val job = underTest.subscriptionsFlow.onEach { latest = it }.launchIn(this)
+            val job = underTest.subscriptions.onEach { latest = it }.launchIn(this)
 
             whenever(subscriptionManager.completeActiveSubscriptionInfoList)
                 .thenReturn(listOf(SUB_1, SUB_2))
             getSubscriptionCallback().onSubscriptionsChanged()
 
-            assertThat(latest).isEqualTo(listOf(SUB_1, SUB_2))
+            assertThat(latest).isEqualTo(listOf(MODEL_1, MODEL_2))
 
             job.cancel()
         }
@@ -117,9 +141,9 @@
     @Test
     fun testSubscriptions_removingSub_updatesList() =
         runBlocking(IMMEDIATE) {
-            var latest: List<SubscriptionInfo>? = null
+            var latest: List<SubscriptionModel>? = null
 
-            val job = underTest.subscriptionsFlow.onEach { latest = it }.launchIn(this)
+            val job = underTest.subscriptions.onEach { latest = it }.launchIn(this)
 
             // WHEN 2 networks show up
             whenever(subscriptionManager.completeActiveSubscriptionInfoList)
@@ -132,7 +156,7 @@
             getSubscriptionCallback().onSubscriptionsChanged()
 
             // THEN the subscriptions list represents the newest change
-            assertThat(latest).isEqualTo(listOf(SUB_2))
+            assertThat(latest).isEqualTo(listOf(MODEL_2))
 
             job.cancel()
         }
@@ -162,7 +186,7 @@
     @Test
     fun testConnectionRepository_validSubId_isCached() =
         runBlocking(IMMEDIATE) {
-            val job = underTest.subscriptionsFlow.launchIn(this)
+            val job = underTest.subscriptions.launchIn(this)
 
             whenever(subscriptionManager.completeActiveSubscriptionInfoList)
                 .thenReturn(listOf(SUB_1))
@@ -179,7 +203,7 @@
     @Test
     fun testConnectionCache_clearsInvalidSubscriptions() =
         runBlocking(IMMEDIATE) {
-            val job = underTest.subscriptionsFlow.launchIn(this)
+            val job = underTest.subscriptions.launchIn(this)
 
             whenever(subscriptionManager.completeActiveSubscriptionInfoList)
                 .thenReturn(listOf(SUB_1, SUB_2))
@@ -202,10 +226,36 @@
             job.cancel()
         }
 
+    /** Regression test for b/261706421 */
+    @Test
+    fun testConnectionsCache_clearMultipleSubscriptionsAtOnce_doesNotThrow() =
+        runBlocking(IMMEDIATE) {
+            val job = underTest.subscriptions.launchIn(this)
+
+            whenever(subscriptionManager.completeActiveSubscriptionInfoList)
+                .thenReturn(listOf(SUB_1, SUB_2))
+            getSubscriptionCallback().onSubscriptionsChanged()
+
+            // Get repos to trigger caching
+            val repo1 = underTest.getRepoForSubId(SUB_1_ID)
+            val repo2 = underTest.getRepoForSubId(SUB_2_ID)
+
+            assertThat(underTest.getSubIdRepoCache())
+                .containsExactly(SUB_1_ID, repo1, SUB_2_ID, repo2)
+
+            // All subscriptions disappear
+            whenever(subscriptionManager.completeActiveSubscriptionInfoList).thenReturn(listOf())
+            getSubscriptionCallback().onSubscriptionsChanged()
+
+            assertThat(underTest.getSubIdRepoCache()).isEmpty()
+
+            job.cancel()
+        }
+
     @Test
     fun testConnectionRepository_invalidSubId_throws() =
         runBlocking(IMMEDIATE) {
-            val job = underTest.subscriptionsFlow.launchIn(this)
+            val job = underTest.subscriptions.launchIn(this)
 
             assertThrows(IllegalArgumentException::class.java) {
                 underTest.getRepoForSubId(SUB_1_ID)
@@ -371,10 +421,12 @@
         private const val SUB_1_ID = 1
         private val SUB_1 =
             mock<SubscriptionInfo>().also { whenever(it.subscriptionId).thenReturn(SUB_1_ID) }
+        private val MODEL_1 = SubscriptionModel(subscriptionId = SUB_1_ID)
 
         private const val SUB_2_ID = 2
         private val SUB_2 =
             mock<SubscriptionInfo>().also { whenever(it.subscriptionId).thenReturn(SUB_2_ID) }
+        private val MODEL_2 = SubscriptionModel(subscriptionId = SUB_2_ID)
 
         private const val NET_ID = 123
         private val NETWORK = mock<Network>().apply { whenever(getNetId()).thenReturn(NET_ID) }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconsInteractor.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconsInteractor.kt
index 061c3b54..0d4044d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconsInteractor.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/FakeMobileIconsInteractor.kt
@@ -16,14 +16,15 @@
 
 package com.android.systemui.statusbar.pipeline.mobile.domain.interactor
 
-import android.telephony.SubscriptionInfo
 import android.telephony.TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_LTE_ADVANCED_PRO
 import android.telephony.TelephonyManager.NETWORK_TYPE_GSM
 import android.telephony.TelephonyManager.NETWORK_TYPE_LTE
 import android.telephony.TelephonyManager.NETWORK_TYPE_UMTS
 import com.android.settingslib.SignalIcon.MobileIconGroup
 import com.android.settingslib.mobile.TelephonyIcons
+import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
 import com.android.systemui.statusbar.pipeline.mobile.util.MobileMappingsProxy
+import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.MutableStateFlow
 
 class FakeMobileIconsInteractor(mobileMappings: MobileMappingsProxy) : MobileIconsInteractor {
@@ -47,8 +48,8 @@
 
     override val isDefaultConnectionFailed = MutableStateFlow(false)
 
-    private val _filteredSubscriptions = MutableStateFlow<List<SubscriptionInfo>>(listOf())
-    override val filteredSubscriptions = _filteredSubscriptions
+    private val _filteredSubscriptions = MutableStateFlow<List<SubscriptionModel>>(listOf())
+    override val filteredSubscriptions: Flow<List<SubscriptionModel>> = _filteredSubscriptions
 
     private val _activeDataConnectionHasDataEnabled = MutableStateFlow(false)
     override val activeDataConnectionHasDataEnabled = _activeDataConnectionHasDataEnabled
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractorTest.kt
index 7fc1c0f..fd41b5b 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconInteractorTest.kt
@@ -24,9 +24,9 @@
 import com.android.settingslib.mobile.TelephonyIcons
 import com.android.systemui.SysuiTestCase
 import com.android.systemui.statusbar.pipeline.mobile.data.model.DataConnectionState
-import com.android.systemui.statusbar.pipeline.mobile.data.model.DefaultNetworkType
-import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileSubscriptionModel
-import com.android.systemui.statusbar.pipeline.mobile.data.model.OverrideNetworkType
+import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectionModel
+import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType.DefaultNetworkType
+import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType.OverrideNetworkType
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.FakeMobileConnectionRepository
 import com.android.systemui.statusbar.pipeline.mobile.domain.interactor.FakeMobileIconsInteractor.Companion.FIVE_G_OVERRIDE
 import com.android.systemui.statusbar.pipeline.mobile.domain.interactor.FakeMobileIconsInteractor.Companion.FOUR_G
@@ -49,7 +49,7 @@
     private lateinit var underTest: MobileIconInteractor
     private val mobileMappingsProxy = FakeMobileMappingsProxy()
     private val mobileIconsInteractor = FakeMobileIconsInteractor(mobileMappingsProxy)
-    private val connectionRepository = FakeMobileConnectionRepository()
+    private val connectionRepository = FakeMobileConnectionRepository(SUB_1_ID)
 
     private val scope = CoroutineScope(IMMEDIATE)
 
@@ -62,7 +62,6 @@
                 mobileIconsInteractor.defaultMobileIconMapping,
                 mobileIconsInteractor.defaultMobileIconGroup,
                 mobileIconsInteractor.isDefaultConnectionFailed,
-                mobileMappingsProxy,
                 connectionRepository,
             )
     }
@@ -70,8 +69,8 @@
     @Test
     fun gsm_level_default_unknown() =
         runBlocking(IMMEDIATE) {
-            connectionRepository.setMobileSubscriptionModel(
-                MobileSubscriptionModel(isGsm = true),
+            connectionRepository.setConnectionInfo(
+                MobileConnectionModel(isGsm = true),
             )
 
             var latest: Int? = null
@@ -85,8 +84,8 @@
     @Test
     fun gsm_usesGsmLevel() =
         runBlocking(IMMEDIATE) {
-            connectionRepository.setMobileSubscriptionModel(
-                MobileSubscriptionModel(
+            connectionRepository.setConnectionInfo(
+                MobileConnectionModel(
                     isGsm = true,
                     primaryLevel = GSM_LEVEL,
                     cdmaLevel = CDMA_LEVEL
@@ -104,8 +103,8 @@
     @Test
     fun cdma_level_default_unknown() =
         runBlocking(IMMEDIATE) {
-            connectionRepository.setMobileSubscriptionModel(
-                MobileSubscriptionModel(isGsm = false),
+            connectionRepository.setConnectionInfo(
+                MobileConnectionModel(isGsm = false),
             )
 
             var latest: Int? = null
@@ -118,8 +117,8 @@
     @Test
     fun cdma_usesCdmaLevel() =
         runBlocking(IMMEDIATE) {
-            connectionRepository.setMobileSubscriptionModel(
-                MobileSubscriptionModel(
+            connectionRepository.setConnectionInfo(
+                MobileConnectionModel(
                     isGsm = false,
                     primaryLevel = GSM_LEVEL,
                     cdmaLevel = CDMA_LEVEL
@@ -137,8 +136,11 @@
     @Test
     fun iconGroup_three_g() =
         runBlocking(IMMEDIATE) {
-            connectionRepository.setMobileSubscriptionModel(
-                MobileSubscriptionModel(resolvedNetworkType = DefaultNetworkType(THREE_G)),
+            connectionRepository.setConnectionInfo(
+                MobileConnectionModel(
+                    resolvedNetworkType =
+                        DefaultNetworkType(THREE_G, mobileMappingsProxy.toIconKey(THREE_G))
+                ),
             )
 
             var latest: MobileIconGroup? = null
@@ -152,16 +154,23 @@
     @Test
     fun iconGroup_updates_on_change() =
         runBlocking(IMMEDIATE) {
-            connectionRepository.setMobileSubscriptionModel(
-                MobileSubscriptionModel(resolvedNetworkType = DefaultNetworkType(THREE_G)),
+            connectionRepository.setConnectionInfo(
+                MobileConnectionModel(
+                    resolvedNetworkType =
+                        DefaultNetworkType(THREE_G, mobileMappingsProxy.toIconKey(THREE_G))
+                ),
             )
 
             var latest: MobileIconGroup? = null
             val job = underTest.networkTypeIconGroup.onEach { latest = it }.launchIn(this)
 
-            connectionRepository.setMobileSubscriptionModel(
-                MobileSubscriptionModel(
-                    resolvedNetworkType = DefaultNetworkType(FOUR_G),
+            connectionRepository.setConnectionInfo(
+                MobileConnectionModel(
+                    resolvedNetworkType =
+                        DefaultNetworkType(
+                            FOUR_G,
+                            mobileMappingsProxy.toIconKey(FOUR_G),
+                        ),
                 ),
             )
             yield()
@@ -174,8 +183,14 @@
     @Test
     fun iconGroup_5g_override_type() =
         runBlocking(IMMEDIATE) {
-            connectionRepository.setMobileSubscriptionModel(
-                MobileSubscriptionModel(resolvedNetworkType = OverrideNetworkType(FIVE_G_OVERRIDE)),
+            connectionRepository.setConnectionInfo(
+                MobileConnectionModel(
+                    resolvedNetworkType =
+                        OverrideNetworkType(
+                            FIVE_G_OVERRIDE,
+                            mobileMappingsProxy.toIconKeyOverride(FIVE_G_OVERRIDE)
+                        )
+                ),
             )
 
             var latest: MobileIconGroup? = null
@@ -189,9 +204,13 @@
     @Test
     fun iconGroup_default_if_no_lookup() =
         runBlocking(IMMEDIATE) {
-            connectionRepository.setMobileSubscriptionModel(
-                MobileSubscriptionModel(
-                    resolvedNetworkType = DefaultNetworkType(NETWORK_TYPE_UNKNOWN),
+            connectionRepository.setConnectionInfo(
+                MobileConnectionModel(
+                    resolvedNetworkType =
+                        DefaultNetworkType(
+                            NETWORK_TYPE_UNKNOWN,
+                            mobileMappingsProxy.toIconKey(NETWORK_TYPE_UNKNOWN)
+                        ),
                 ),
             )
 
@@ -238,8 +257,8 @@
             var latest: Boolean? = null
             val job = underTest.isDataConnected.onEach { latest = it }.launchIn(this)
 
-            connectionRepository.setMobileSubscriptionModel(
-                MobileSubscriptionModel(dataConnectionState = DataConnectionState.Connected)
+            connectionRepository.setConnectionInfo(
+                MobileConnectionModel(dataConnectionState = DataConnectionState.Connected)
             )
             yield()
 
@@ -254,8 +273,8 @@
             var latest: Boolean? = null
             val job = underTest.isDataConnected.onEach { latest = it }.launchIn(this)
 
-            connectionRepository.setMobileSubscriptionModel(
-                MobileSubscriptionModel(dataConnectionState = DataConnectionState.Disconnected)
+            connectionRepository.setConnectionInfo(
+                MobileConnectionModel(dataConnectionState = DataConnectionState.Disconnected)
             )
 
             assertThat(latest).isFalse()
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractorTest.kt
index b56dcd7..58e57e2 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/domain/interactor/MobileIconsInteractorTest.kt
@@ -16,17 +16,16 @@
 
 package com.android.systemui.statusbar.pipeline.mobile.domain.interactor
 
-import android.telephony.SubscriptionInfo
 import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID
 import androidx.test.filters.SmallTest
 import com.android.systemui.SysuiTestCase
 import com.android.systemui.statusbar.pipeline.mobile.data.model.MobileConnectivityModel
+import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.FakeMobileConnectionRepository
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.FakeMobileConnectionsRepository
 import com.android.systemui.statusbar.pipeline.mobile.data.repository.FakeUserSetupRepository
 import com.android.systemui.statusbar.pipeline.mobile.util.FakeMobileMappingsProxy
 import com.android.systemui.util.CarrierConfigTracker
-import com.android.systemui.util.mockito.mock
 import com.android.systemui.util.mockito.whenever
 import com.google.common.truth.Truth.assertThat
 import kotlinx.coroutines.CoroutineScope
@@ -45,8 +44,8 @@
 class MobileIconsInteractorTest : SysuiTestCase() {
     private lateinit var underTest: MobileIconsInteractor
     private val userSetupRepository = FakeUserSetupRepository()
-    private val connectionsRepository = FakeMobileConnectionsRepository()
     private val mobileMappingsProxy = FakeMobileMappingsProxy()
+    private val connectionsRepository = FakeMobileConnectionsRepository(mobileMappingsProxy)
     private val scope = CoroutineScope(IMMEDIATE)
 
     @Mock private lateinit var carrierConfigTracker: CarrierConfigTracker
@@ -69,7 +68,6 @@
             MobileIconsInteractorImpl(
                 connectionsRepository,
                 carrierConfigTracker,
-                mobileMappingsProxy,
                 userSetupRepository,
                 scope
             )
@@ -80,10 +78,10 @@
     @Test
     fun filteredSubscriptions_default() =
         runBlocking(IMMEDIATE) {
-            var latest: List<SubscriptionInfo>? = null
+            var latest: List<SubscriptionModel>? = null
             val job = underTest.filteredSubscriptions.onEach { latest = it }.launchIn(this)
 
-            assertThat(latest).isEqualTo(listOf<SubscriptionInfo>())
+            assertThat(latest).isEqualTo(listOf<SubscriptionModel>())
 
             job.cancel()
         }
@@ -93,7 +91,7 @@
         runBlocking(IMMEDIATE) {
             connectionsRepository.setSubscriptions(listOf(SUB_1, SUB_2))
 
-            var latest: List<SubscriptionInfo>? = null
+            var latest: List<SubscriptionModel>? = null
             val job = underTest.filteredSubscriptions.onEach { latest = it }.launchIn(this)
 
             assertThat(latest).isEqualTo(listOf(SUB_1, SUB_2))
@@ -109,7 +107,7 @@
             whenever(carrierConfigTracker.alwaysShowPrimarySignalBarInOpportunisticNetworkDefault)
                 .thenReturn(false)
 
-            var latest: List<SubscriptionInfo>? = null
+            var latest: List<SubscriptionModel>? = null
             val job = underTest.filteredSubscriptions.onEach { latest = it }.launchIn(this)
 
             // Filtered subscriptions should show the active one when the config is false
@@ -126,7 +124,7 @@
             whenever(carrierConfigTracker.alwaysShowPrimarySignalBarInOpportunisticNetworkDefault)
                 .thenReturn(false)
 
-            var latest: List<SubscriptionInfo>? = null
+            var latest: List<SubscriptionModel>? = null
             val job = underTest.filteredSubscriptions.onEach { latest = it }.launchIn(this)
 
             // Filtered subscriptions should show the active one when the config is false
@@ -143,7 +141,7 @@
             whenever(carrierConfigTracker.alwaysShowPrimarySignalBarInOpportunisticNetworkDefault)
                 .thenReturn(true)
 
-            var latest: List<SubscriptionInfo>? = null
+            var latest: List<SubscriptionModel>? = null
             val job = underTest.filteredSubscriptions.onEach { latest = it }.launchIn(this)
 
             // Filtered subscriptions should show the primary (non-opportunistic) if the config is
@@ -161,7 +159,7 @@
             whenever(carrierConfigTracker.alwaysShowPrimarySignalBarInOpportunisticNetworkDefault)
                 .thenReturn(true)
 
-            var latest: List<SubscriptionInfo>? = null
+            var latest: List<SubscriptionModel>? = null
             val job = underTest.filteredSubscriptions.onEach { latest = it }.launchIn(this)
 
             // Filtered subscriptions should show the primary (non-opportunistic) if the config is
@@ -261,29 +259,19 @@
         private val IMMEDIATE = Dispatchers.Main.immediate
 
         private const val SUB_1_ID = 1
-        private val SUB_1 =
-            mock<SubscriptionInfo>().also { whenever(it.subscriptionId).thenReturn(SUB_1_ID) }
-        private val CONNECTION_1 = FakeMobileConnectionRepository()
+        private val SUB_1 = SubscriptionModel(subscriptionId = SUB_1_ID)
+        private val CONNECTION_1 = FakeMobileConnectionRepository(SUB_1_ID)
 
         private const val SUB_2_ID = 2
-        private val SUB_2 =
-            mock<SubscriptionInfo>().also { whenever(it.subscriptionId).thenReturn(SUB_2_ID) }
-        private val CONNECTION_2 = FakeMobileConnectionRepository()
+        private val SUB_2 = SubscriptionModel(subscriptionId = SUB_2_ID)
+        private val CONNECTION_2 = FakeMobileConnectionRepository(SUB_2_ID)
 
         private const val SUB_3_ID = 3
-        private val SUB_3_OPP =
-            mock<SubscriptionInfo>().also {
-                whenever(it.subscriptionId).thenReturn(SUB_3_ID)
-                whenever(it.isOpportunistic).thenReturn(true)
-            }
-        private val CONNECTION_3 = FakeMobileConnectionRepository()
+        private val SUB_3_OPP = SubscriptionModel(subscriptionId = SUB_3_ID, isOpportunistic = true)
+        private val CONNECTION_3 = FakeMobileConnectionRepository(SUB_3_ID)
 
         private const val SUB_4_ID = 4
-        private val SUB_4_OPP =
-            mock<SubscriptionInfo>().also {
-                whenever(it.subscriptionId).thenReturn(SUB_4_ID)
-                whenever(it.isOpportunistic).thenReturn(true)
-            }
-        private val CONNECTION_4 = FakeMobileConnectionRepository()
+        private val SUB_4_OPP = SubscriptionModel(subscriptionId = SUB_4_ID, isOpportunistic = true)
+        private val CONNECTION_4 = FakeMobileConnectionRepository(SUB_4_ID)
     }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/ui/view/ModernStatusBarWifiViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/ui/view/ModernStatusBarWifiViewTest.kt
index 3d9fd96..22c0ea1 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/ui/view/ModernStatusBarWifiViewTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/ui/view/ModernStatusBarWifiViewTest.kt
@@ -16,11 +16,14 @@
 
 package com.android.systemui.statusbar.pipeline.wifi.ui.view
 
+import android.content.res.ColorStateList
+import android.graphics.Rect
 import android.testing.AndroidTestingRunner
 import android.testing.TestableLooper
 import android.testing.TestableLooper.RunWithLooper
 import android.testing.ViewUtils
 import android.view.View
+import android.widget.ImageView
 import androidx.test.filters.SmallTest
 import com.android.systemui.R
 import com.android.systemui.SysuiTestCase
@@ -44,6 +47,7 @@
 import com.android.systemui.statusbar.pipeline.wifi.shared.WifiConstants
 import com.android.systemui.statusbar.pipeline.wifi.ui.viewmodel.LocationBasedWifiViewModel
 import com.android.systemui.statusbar.pipeline.wifi.ui.viewmodel.WifiViewModel
+import com.android.systemui.util.mockito.whenever
 import com.google.common.truth.Truth.assertThat
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.Dispatchers
@@ -229,10 +233,43 @@
         ViewUtils.detachView(view)
     }
 
+    @Test
+    fun onDarkChanged_iconHasNewColor() {
+        whenever(statusBarPipelineFlags.useWifiDebugColoring()).thenReturn(false)
+        val view = ModernStatusBarWifiView.constructAndBind(context, SLOT_NAME, viewModel)
+        ViewUtils.attachView(view)
+        testableLooper.processAllMessages()
+
+        val areas = ArrayList(listOf(Rect(0, 0, 1000, 1000)))
+        val color = 0x12345678
+        view.onDarkChanged(areas, 1.0f, color)
+        testableLooper.processAllMessages()
+
+        assertThat(view.getIconView().imageTintList).isEqualTo(ColorStateList.valueOf(color))
+    }
+
+    @Test
+    fun setStaticDrawableColor_iconHasNewColor() {
+        whenever(statusBarPipelineFlags.useWifiDebugColoring()).thenReturn(false)
+        val view = ModernStatusBarWifiView.constructAndBind(context, SLOT_NAME, viewModel)
+        ViewUtils.attachView(view)
+        testableLooper.processAllMessages()
+
+        val color = 0x23456789
+        view.setStaticDrawableColor(color)
+        testableLooper.processAllMessages()
+
+        assertThat(view.getIconView().imageTintList).isEqualTo(ColorStateList.valueOf(color))
+    }
+
     private fun View.getIconGroupView(): View {
         return this.requireViewById(R.id.wifi_group)
     }
 
+    private fun View.getIconView(): ImageView {
+        return this.requireViewById(R.id.wifi_signal)
+    }
+
     private fun View.getDotView(): View {
         return this.requireViewById(R.id.status_bar_dot)
     }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SecurityControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SecurityControllerTest.java
index 15235b6..c35bc69 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SecurityControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SecurityControllerTest.java
@@ -149,11 +149,12 @@
     }
 
     @Test
-    public void testGetDeviceOwnerType() {
+    public void testIsFinancedDevice() {
+        when(mDevicePolicyManager.isFinancedDevice()).thenReturn(true);
+        // TODO(b/259908270): remove
         when(mDevicePolicyManager.getDeviceOwnerType(DEVICE_OWNER_COMPONENT))
                 .thenReturn(DEVICE_OWNER_TYPE_FINANCED);
-        assertEquals(mSecurityController.getDeviceOwnerType(DEVICE_OWNER_COMPONENT),
-                DEVICE_OWNER_TYPE_FINANCED);
+        assertEquals(mSecurityController.isFinancedDevice(), true);
     }
 
     @Test
diff --git a/packages/SystemUI/tests/src/com/android/systemui/stylus/StylusManagerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/stylus/StylusManagerTest.kt
new file mode 100644
index 0000000..58b5560
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/stylus/StylusManagerTest.kt
@@ -0,0 +1,338 @@
+/*
+ * 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.systemui.stylus
+
+import android.bluetooth.BluetoothAdapter
+import android.bluetooth.BluetoothDevice
+import android.hardware.input.InputManager
+import android.os.Handler
+import android.testing.AndroidTestingRunner
+import android.view.InputDevice
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.util.mockito.any
+import com.android.systemui.util.mockito.whenever
+import java.util.concurrent.Executor
+import org.junit.Before
+import org.junit.Ignore
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.Mock
+import org.mockito.Mockito.inOrder
+import org.mockito.Mockito.never
+import org.mockito.Mockito.times
+import org.mockito.Mockito.verify
+import org.mockito.Mockito.verifyNoMoreInteractions
+import org.mockito.MockitoAnnotations
+
+@RunWith(AndroidTestingRunner::class)
+@SmallTest
+@Ignore("b/257936830 until bt APIs")
+class StylusManagerTest : SysuiTestCase() {
+    @Mock lateinit var inputManager: InputManager
+
+    @Mock lateinit var stylusDevice: InputDevice
+
+    @Mock lateinit var btStylusDevice: InputDevice
+
+    @Mock lateinit var otherDevice: InputDevice
+
+    @Mock lateinit var bluetoothAdapter: BluetoothAdapter
+
+    @Mock lateinit var bluetoothDevice: BluetoothDevice
+
+    @Mock lateinit var handler: Handler
+
+    @Mock lateinit var stylusCallback: StylusManager.StylusCallback
+
+    @Mock lateinit var otherStylusCallback: StylusManager.StylusCallback
+
+    @Mock lateinit var stylusBatteryCallback: StylusManager.StylusBatteryCallback
+
+    @Mock lateinit var otherStylusBatteryCallback: StylusManager.StylusBatteryCallback
+
+    private lateinit var stylusManager: StylusManager
+
+    @Before
+    fun setUp() {
+        MockitoAnnotations.initMocks(this)
+
+        whenever(handler.post(any())).thenAnswer {
+            (it.arguments[0] as Runnable).run()
+            true
+        }
+
+        stylusManager = StylusManager(inputManager, bluetoothAdapter, handler, EXECUTOR)
+
+        stylusManager.registerCallback(stylusCallback)
+
+        stylusManager.registerBatteryCallback(stylusBatteryCallback)
+
+        whenever(otherDevice.supportsSource(InputDevice.SOURCE_STYLUS)).thenReturn(false)
+        whenever(stylusDevice.supportsSource(InputDevice.SOURCE_STYLUS)).thenReturn(true)
+        whenever(btStylusDevice.supportsSource(InputDevice.SOURCE_STYLUS)).thenReturn(true)
+
+        // whenever(stylusDevice.bluetoothAddress).thenReturn(null)
+        // whenever(btStylusDevice.bluetoothAddress).thenReturn(STYLUS_BT_ADDRESS)
+
+        whenever(inputManager.getInputDevice(OTHER_DEVICE_ID)).thenReturn(otherDevice)
+        whenever(inputManager.getInputDevice(STYLUS_DEVICE_ID)).thenReturn(stylusDevice)
+        whenever(inputManager.getInputDevice(BT_STYLUS_DEVICE_ID)).thenReturn(btStylusDevice)
+        whenever(inputManager.inputDeviceIds).thenReturn(intArrayOf(STYLUS_DEVICE_ID))
+
+        whenever(bluetoothAdapter.getRemoteDevice(STYLUS_BT_ADDRESS)).thenReturn(bluetoothDevice)
+        whenever(bluetoothDevice.address).thenReturn(STYLUS_BT_ADDRESS)
+    }
+
+    @Test
+    fun startListener_registersInputDeviceListener() {
+        stylusManager.startListener()
+
+        verify(inputManager, times(1)).registerInputDeviceListener(any(), any())
+    }
+
+    @Test
+    fun onInputDeviceAdded_multipleRegisteredCallbacks_callsAll() {
+        stylusManager.registerCallback(otherStylusCallback)
+
+        stylusManager.onInputDeviceAdded(STYLUS_DEVICE_ID)
+
+        verify(stylusCallback, times(1)).onStylusAdded(STYLUS_DEVICE_ID)
+        verifyNoMoreInteractions(stylusCallback)
+        verify(otherStylusCallback, times(1)).onStylusAdded(STYLUS_DEVICE_ID)
+        verifyNoMoreInteractions(otherStylusCallback)
+    }
+
+    @Test
+    fun onInputDeviceAdded_stylus_callsCallbacksOnStylusAdded() {
+        stylusManager.onInputDeviceAdded(STYLUS_DEVICE_ID)
+
+        verify(stylusCallback, times(1)).onStylusAdded(STYLUS_DEVICE_ID)
+        verifyNoMoreInteractions(stylusCallback)
+    }
+
+    @Test
+    fun onInputDeviceAdded_btStylus_callsCallbacksWithAddress() {
+        stylusManager.onInputDeviceAdded(BT_STYLUS_DEVICE_ID)
+
+        inOrder(stylusCallback).let {
+            it.verify(stylusCallback, times(1)).onStylusAdded(BT_STYLUS_DEVICE_ID)
+            it.verify(stylusCallback, times(1))
+                .onStylusBluetoothConnected(BT_STYLUS_DEVICE_ID, STYLUS_BT_ADDRESS)
+        }
+    }
+
+    @Test
+    fun onInputDeviceAdded_notStylus_doesNotCallCallbacks() {
+        stylusManager.onInputDeviceAdded(OTHER_DEVICE_ID)
+
+        verifyNoMoreInteractions(stylusCallback)
+    }
+
+    @Test
+    fun onInputDeviceChanged_multipleRegisteredCallbacks_callsAll() {
+        stylusManager.onInputDeviceAdded(STYLUS_DEVICE_ID)
+        // whenever(stylusDevice.bluetoothAddress).thenReturn(STYLUS_BT_ADDRESS)
+        stylusManager.registerCallback(otherStylusCallback)
+
+        stylusManager.onInputDeviceChanged(STYLUS_DEVICE_ID)
+
+        verify(stylusCallback, times(1))
+            .onStylusBluetoothConnected(STYLUS_DEVICE_ID, STYLUS_BT_ADDRESS)
+        verify(otherStylusCallback, times(1))
+            .onStylusBluetoothConnected(STYLUS_DEVICE_ID, STYLUS_BT_ADDRESS)
+    }
+
+    @Test
+    fun onInputDeviceChanged_stylusNewBtConnection_callsCallbacks() {
+        stylusManager.onInputDeviceAdded(STYLUS_DEVICE_ID)
+        // whenever(stylusDevice.bluetoothAddress).thenReturn(STYLUS_BT_ADDRESS)
+
+        stylusManager.onInputDeviceChanged(STYLUS_DEVICE_ID)
+
+        verify(stylusCallback, times(1))
+            .onStylusBluetoothConnected(STYLUS_DEVICE_ID, STYLUS_BT_ADDRESS)
+    }
+
+    @Test
+    fun onInputDeviceChanged_stylusLostBtConnection_callsCallbacks() {
+        stylusManager.onInputDeviceAdded(BT_STYLUS_DEVICE_ID)
+        // whenever(btStylusDevice.bluetoothAddress).thenReturn(null)
+
+        stylusManager.onInputDeviceChanged(BT_STYLUS_DEVICE_ID)
+
+        verify(stylusCallback, times(1))
+            .onStylusBluetoothDisconnected(BT_STYLUS_DEVICE_ID, STYLUS_BT_ADDRESS)
+    }
+
+    @Test
+    fun onInputDeviceChanged_btConnection_stylusAlreadyBtConnected_onlyCallsListenersOnce() {
+        stylusManager.onInputDeviceAdded(BT_STYLUS_DEVICE_ID)
+
+        stylusManager.onInputDeviceChanged(BT_STYLUS_DEVICE_ID)
+
+        verify(stylusCallback, times(1))
+            .onStylusBluetoothConnected(BT_STYLUS_DEVICE_ID, STYLUS_BT_ADDRESS)
+    }
+
+    @Test
+    fun onInputDeviceChanged_noBtConnection_stylusNeverBtConnected_doesNotCallCallbacks() {
+        stylusManager.onInputDeviceAdded(STYLUS_DEVICE_ID)
+
+        stylusManager.onInputDeviceChanged(STYLUS_DEVICE_ID)
+
+        verify(stylusCallback, never()).onStylusBluetoothDisconnected(any(), any())
+    }
+
+    @Test
+    fun onInputDeviceRemoved_multipleRegisteredCallbacks_callsAll() {
+        stylusManager.onInputDeviceAdded(STYLUS_DEVICE_ID)
+        stylusManager.registerCallback(otherStylusCallback)
+
+        stylusManager.onInputDeviceAdded(STYLUS_DEVICE_ID)
+
+        verify(stylusCallback, times(1)).onStylusRemoved(STYLUS_DEVICE_ID)
+        verify(otherStylusCallback, times(1)).onStylusRemoved(STYLUS_DEVICE_ID)
+    }
+
+    @Test
+    fun onInputDeviceRemoved_stylus_callsCallbacks() {
+        stylusManager.onInputDeviceAdded(STYLUS_DEVICE_ID)
+
+        stylusManager.onInputDeviceRemoved(STYLUS_DEVICE_ID)
+
+        verify(stylusCallback, times(1)).onStylusRemoved(STYLUS_DEVICE_ID)
+        verify(stylusCallback, never()).onStylusBluetoothDisconnected(any(), any())
+    }
+
+    @Test
+    fun onInputDeviceRemoved_btStylus_callsCallbacks() {
+        stylusManager.onInputDeviceAdded(BT_STYLUS_DEVICE_ID)
+
+        stylusManager.onInputDeviceRemoved(BT_STYLUS_DEVICE_ID)
+
+        inOrder(stylusCallback).let {
+            it.verify(stylusCallback, times(1))
+                .onStylusBluetoothDisconnected(BT_STYLUS_DEVICE_ID, STYLUS_BT_ADDRESS)
+            it.verify(stylusCallback, times(1)).onStylusRemoved(BT_STYLUS_DEVICE_ID)
+        }
+    }
+
+    @Test
+    fun onStylusBluetoothConnected_registersMetadataListener() {
+        stylusManager.onInputDeviceAdded(BT_STYLUS_DEVICE_ID)
+
+        verify(bluetoothAdapter, times(1)).addOnMetadataChangedListener(any(), any(), any())
+    }
+
+    @Test
+    fun onStylusBluetoothConnected_noBluetoothDevice_doesNotRegisterMetadataListener() {
+        whenever(bluetoothAdapter.getRemoteDevice(STYLUS_BT_ADDRESS)).thenReturn(null)
+
+        stylusManager.onInputDeviceAdded(BT_STYLUS_DEVICE_ID)
+
+        verify(bluetoothAdapter, never()).addOnMetadataChangedListener(any(), any(), any())
+    }
+
+    @Test
+    fun onStylusBluetoothDisconnected_unregistersMetadataListener() {
+        stylusManager.onInputDeviceAdded(BT_STYLUS_DEVICE_ID)
+
+        stylusManager.onInputDeviceRemoved(BT_STYLUS_DEVICE_ID)
+
+        verify(bluetoothAdapter, times(1)).removeOnMetadataChangedListener(any(), any())
+    }
+
+    @Test
+    fun onMetadataChanged_multipleRegisteredBatteryCallbacks_executesAll() {
+        stylusManager.onInputDeviceAdded(BT_STYLUS_DEVICE_ID)
+        stylusManager.registerBatteryCallback(otherStylusBatteryCallback)
+
+        stylusManager.onMetadataChanged(
+            bluetoothDevice,
+            BluetoothDevice.METADATA_MAIN_CHARGING,
+            "true".toByteArray()
+        )
+
+        verify(stylusBatteryCallback, times(1))
+            .onStylusBluetoothChargingStateChanged(BT_STYLUS_DEVICE_ID, bluetoothDevice, true)
+        verify(otherStylusBatteryCallback, times(1))
+            .onStylusBluetoothChargingStateChanged(BT_STYLUS_DEVICE_ID, bluetoothDevice, true)
+    }
+
+    @Test
+    fun onMetadataChanged_chargingStateTrue_executesBatteryCallbacks() {
+        stylusManager.onInputDeviceAdded(BT_STYLUS_DEVICE_ID)
+
+        stylusManager.onMetadataChanged(
+            bluetoothDevice,
+            BluetoothDevice.METADATA_MAIN_CHARGING,
+            "true".toByteArray()
+        )
+
+        verify(stylusBatteryCallback, times(1))
+            .onStylusBluetoothChargingStateChanged(BT_STYLUS_DEVICE_ID, bluetoothDevice, true)
+    }
+
+    @Test
+    fun onMetadataChanged_chargingStateFalse_executesBatteryCallbacks() {
+        stylusManager.onInputDeviceAdded(BT_STYLUS_DEVICE_ID)
+
+        stylusManager.onMetadataChanged(
+            bluetoothDevice,
+            BluetoothDevice.METADATA_MAIN_CHARGING,
+            "false".toByteArray()
+        )
+
+        verify(stylusBatteryCallback, times(1))
+            .onStylusBluetoothChargingStateChanged(BT_STYLUS_DEVICE_ID, bluetoothDevice, false)
+    }
+
+    @Test
+    fun onMetadataChanged_chargingStateNoDevice_doesNotExecuteBatteryCallbacks() {
+        stylusManager.onMetadataChanged(
+            bluetoothDevice,
+            BluetoothDevice.METADATA_MAIN_CHARGING,
+            "true".toByteArray()
+        )
+
+        verifyNoMoreInteractions(stylusBatteryCallback)
+    }
+
+    @Test
+    fun onMetadataChanged_notChargingState_doesNotExecuteBatteryCallbacks() {
+        stylusManager.onInputDeviceAdded(BT_STYLUS_DEVICE_ID)
+
+        stylusManager.onMetadataChanged(
+            bluetoothDevice,
+            BluetoothDevice.METADATA_DEVICE_TYPE,
+            "true".toByteArray()
+        )
+
+        verify(stylusBatteryCallback, never())
+            .onStylusBluetoothChargingStateChanged(any(), any(), any())
+    }
+
+    companion object {
+        private val EXECUTOR = Executor { r -> r.run() }
+
+        private const val OTHER_DEVICE_ID = 0
+        private const val STYLUS_DEVICE_ID = 1
+        private const val BT_STYLUS_DEVICE_ID = 2
+
+        private const val STYLUS_BT_ADDRESS = "SOME:ADDRESS"
+    }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/surfaceeffects/ripple/MultiRippleControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/surfaceeffects/ripple/MultiRippleControllerTest.kt
index 0d19ab1..056e386 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/surfaceeffects/ripple/MultiRippleControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/surfaceeffects/ripple/MultiRippleControllerTest.kt
@@ -101,4 +101,52 @@
             assertThat(multiRippleView.ripples.size).isEqualTo(0)
         }
     }
+
+    @Test
+    fun play_onFinishesAllRipples_triggersRipplesFinished() {
+        var isTriggered = false
+        val listener =
+            object : MultiRippleController.Companion.RipplesFinishedListener {
+                override fun onRipplesFinish() {
+                    isTriggered = true
+                }
+            }
+        multiRippleController.addRipplesFinishedListener(listener)
+
+        fakeExecutor.execute {
+            multiRippleController.play(RippleAnimation(RippleAnimationConfig(duration = 1000)))
+            multiRippleController.play(RippleAnimation(RippleAnimationConfig(duration = 2000)))
+
+            assertThat(multiRippleView.ripples.size).isEqualTo(2)
+
+            fakeSystemClock.advanceTime(2000L)
+
+            assertThat(multiRippleView.ripples.size).isEqualTo(0)
+            assertThat(isTriggered).isTrue()
+        }
+    }
+
+    @Test
+    fun play_notAllRipplesFinished_doesNotTriggerRipplesFinished() {
+        var isTriggered = false
+        val listener =
+            object : MultiRippleController.Companion.RipplesFinishedListener {
+                override fun onRipplesFinish() {
+                    isTriggered = true
+                }
+            }
+        multiRippleController.addRipplesFinishedListener(listener)
+
+        fakeExecutor.execute {
+            multiRippleController.play(RippleAnimation(RippleAnimationConfig(duration = 1000)))
+            multiRippleController.play(RippleAnimation(RippleAnimationConfig(duration = 2000)))
+
+            assertThat(multiRippleView.ripples.size).isEqualTo(2)
+
+            fakeSystemClock.advanceTime(1000L)
+
+            assertThat(multiRippleView.ripples.size).isEqualTo(1)
+            assertThat(isTriggered).isFalse()
+        }
+    }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/surfaceeffects/ripple/MultiRippleViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/surfaceeffects/ripple/MultiRippleViewTest.kt
deleted file mode 100644
index 2024d53..0000000
--- a/packages/SystemUI/tests/src/com/android/systemui/surfaceeffects/ripple/MultiRippleViewTest.kt
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.systemui.surfaceeffects.ripple
-
-import android.testing.AndroidTestingRunner
-import androidx.test.filters.SmallTest
-import com.android.systemui.SysuiTestCase
-import com.android.systemui.util.concurrency.FakeExecutor
-import com.android.systemui.util.time.FakeSystemClock
-import com.google.common.truth.Truth.assertThat
-import org.junit.Test
-import org.junit.runner.RunWith
-
-@SmallTest
-@RunWith(AndroidTestingRunner::class)
-class MultiRippleViewTest : SysuiTestCase() {
-    private val fakeSystemClock = FakeSystemClock()
-    // FakeExecutor is needed to run animator.
-    private val fakeExecutor = FakeExecutor(fakeSystemClock)
-
-    @Test
-    fun onRippleFinishes_triggersRippleFinished() {
-        val multiRippleView = MultiRippleView(context, null)
-        val multiRippleController = MultiRippleController(multiRippleView)
-        val rippleAnimationConfig = RippleAnimationConfig(duration = 1000L)
-
-        var isTriggered = false
-        val listener =
-            object : MultiRippleView.Companion.RipplesFinishedListener {
-                override fun onRipplesFinish() {
-                    isTriggered = true
-                }
-            }
-        multiRippleView.addRipplesFinishedListener(listener)
-
-        fakeExecutor.execute {
-            val rippleAnimation = RippleAnimation(rippleAnimationConfig)
-            multiRippleController.play(rippleAnimation)
-
-            fakeSystemClock.advanceTime(rippleAnimationConfig.duration)
-
-            assertThat(isTriggered).isTrue()
-        }
-    }
-}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayControllerTest.kt
index 09f0d4a..82153d5 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayControllerTest.kt
@@ -35,6 +35,7 @@
 import com.android.systemui.util.mockito.argumentCaptor
 import com.android.systemui.util.mockito.capture
 import com.android.systemui.util.time.FakeSystemClock
+import com.android.systemui.util.time.SystemClock
 import com.android.systemui.util.wakelock.WakeLock
 import com.android.systemui.util.wakelock.WakeLockFake
 import com.google.common.truth.Truth.assertThat
@@ -59,7 +60,7 @@
     private lateinit var fakeWakeLock: WakeLockFake
 
     @Mock
-    private lateinit var logger: TemporaryViewLogger
+    private lateinit var logger: TemporaryViewLogger<ViewInfo>
     @Mock
     private lateinit var accessibilityManager: AccessibilityManager
     @Mock
@@ -74,7 +75,7 @@
         MockitoAnnotations.initMocks(this)
 
         whenever(accessibilityManager.getRecommendedTimeoutMillis(any(), any()))
-            .thenReturn(TIMEOUT_MS.toInt())
+            .thenAnswer { it.arguments[0] }
 
         fakeClock = FakeSystemClock()
         fakeExecutor = FakeExecutor(fakeClock)
@@ -84,14 +85,15 @@
         fakeWakeLockBuilder.setWakeLock(fakeWakeLock)
 
         underTest = TestController(
-                context,
-                logger,
-                windowManager,
-                fakeExecutor,
-                accessibilityManager,
-                configurationController,
-                powerManager,
-                fakeWakeLockBuilder,
+            context,
+            logger,
+            windowManager,
+            fakeExecutor,
+            accessibilityManager,
+            configurationController,
+            powerManager,
+            fakeWakeLockBuilder,
+            fakeClock,
         )
         underTest.start()
     }
@@ -112,14 +114,14 @@
 
     @Test
     fun displayView_logged() {
-        underTest.displayView(
-            ViewInfo(
-                name = "name",
-                windowTitle = "Fake Window Title",
-            )
+        val info = ViewInfo(
+            name = "name",
+            windowTitle = "Fake Window Title",
         )
 
-        verify(logger).logViewAddition("id", "Fake Window Title")
+        underTest.displayView(info)
+
+        verify(logger).logViewAddition(info)
     }
 
     @Test
@@ -168,10 +170,11 @@
     }
 
     @Test
-    fun displayView_twiceWithDifferentWindowTitles_oldViewRemovedNewViewAdded() {
+    fun displayView_twiceWithDifferentIds_oldViewRemovedNewViewAdded() {
         underTest.displayView(
             ViewInfo(
                 name = "name",
+                id = "First",
                 windowTitle = "First Fake Window Title",
             )
         )
@@ -179,6 +182,7 @@
         underTest.displayView(
             ViewInfo(
                 name = "name",
+                id = "Second",
                 windowTitle = "Second Fake Window Title",
             )
         )
@@ -263,19 +267,69 @@
     }
 
     @Test
+    fun viewUpdatedWithNewOnViewTimeoutRunnable_newRunnableUsed() {
+        var runnable1Run = false
+        underTest.displayView(ViewInfo(name = "name", id = "id1", windowTitle = "1")) {
+            runnable1Run = true
+        }
+
+        var runnable2Run = false
+        underTest.displayView(ViewInfo(name = "name", id = "id1", windowTitle = "1")) {
+            runnable2Run = true
+        }
+
+        fakeClock.advanceTime(TIMEOUT_MS + 1)
+
+        assertThat(runnable1Run).isFalse()
+        assertThat(runnable2Run).isTrue()
+    }
+
+    @Test
+    fun multipleViewsWithDifferentIds_moreRecentReplacesOlder() {
+        underTest.displayView(
+            ViewInfo(
+                name = "name",
+                windowTitle = "First Fake Window Title",
+                id = "id1"
+            )
+        )
+
+        underTest.displayView(
+            ViewInfo(
+                name = "name",
+                windowTitle = "Second Fake Window Title",
+                id = "id2"
+            )
+        )
+
+        val viewCaptor = argumentCaptor<View>()
+        val windowParamsCaptor = argumentCaptor<WindowManager.LayoutParams>()
+
+        verify(windowManager, times(2)).addView(capture(viewCaptor), capture(windowParamsCaptor))
+
+        assertThat(windowParamsCaptor.allValues[0].title).isEqualTo("First Fake Window Title")
+        assertThat(windowParamsCaptor.allValues[1].title).isEqualTo("Second Fake Window Title")
+        verify(windowManager).removeView(viewCaptor.allValues[0])
+        verify(configurationController, never()).removeCallback(any())
+    }
+
+    @Test
     fun multipleViewsWithDifferentIds_recentActiveViewIsDisplayed() {
         underTest.displayView(ViewInfo("First name", id = "id1"))
 
         verify(windowManager).addView(any(), any())
-
         reset(windowManager)
+
         underTest.displayView(ViewInfo("Second name", id = "id2"))
+
+        verify(windowManager).removeView(any())
+        verify(windowManager).addView(any(), any())
+        reset(windowManager)
+
         underTest.removeView("id2", "test reason")
 
         verify(windowManager).removeView(any())
-
-        fakeClock.advanceTime(DISPLAY_VIEW_DELAY + 1)
-
+        verify(windowManager).addView(any(), any())
         assertThat(underTest.mostRecentViewInfo?.id).isEqualTo("id1")
         assertThat(underTest.mostRecentViewInfo?.name).isEqualTo("First name")
 
@@ -284,6 +338,7 @@
 
         verify(windowManager).removeView(any())
         assertThat(underTest.activeViews.size).isEqualTo(0)
+        verify(configurationController).removeCallback(any())
     }
 
     @Test
@@ -291,19 +346,28 @@
         underTest.displayView(ViewInfo("First name", id = "id1"))
 
         verify(windowManager).addView(any(), any())
-
         reset(windowManager)
+
         underTest.displayView(ViewInfo("Second name", id = "id2"))
+
+        verify(windowManager).removeView(any())
+        verify(windowManager).addView(any(), any())
+        reset(windowManager)
+
+        // WHEN an old view is removed
         underTest.removeView("id1", "test reason")
 
+        // THEN we don't update anything
         verify(windowManager, never()).removeView(any())
         assertThat(underTest.mostRecentViewInfo?.id).isEqualTo("id2")
         assertThat(underTest.mostRecentViewInfo?.name).isEqualTo("Second name")
+        verify(configurationController, never()).removeCallback(any())
 
         fakeClock.advanceTime(TIMEOUT_MS + 1)
 
         verify(windowManager).removeView(any())
         assertThat(underTest.activeViews.size).isEqualTo(0)
+        verify(configurationController).removeCallback(any())
     }
 
     @Test
@@ -312,33 +376,31 @@
         underTest.displayView(ViewInfo("Second name", id = "id2"))
         underTest.displayView(ViewInfo("Third name", id = "id3"))
 
-        verify(windowManager).addView(any(), any())
+        verify(windowManager, times(3)).addView(any(), any())
+        verify(windowManager, times(2)).removeView(any())
 
         reset(windowManager)
         underTest.removeView("id3", "test reason")
 
         verify(windowManager).removeView(any())
-
-        fakeClock.advanceTime(DISPLAY_VIEW_DELAY + 1)
-
         assertThat(underTest.mostRecentViewInfo?.id).isEqualTo("id2")
         assertThat(underTest.mostRecentViewInfo?.name).isEqualTo("Second name")
+        verify(configurationController, never()).removeCallback(any())
 
         reset(windowManager)
         underTest.removeView("id2", "test reason")
 
         verify(windowManager).removeView(any())
-
-        fakeClock.advanceTime(DISPLAY_VIEW_DELAY + 1)
-
         assertThat(underTest.mostRecentViewInfo?.id).isEqualTo("id1")
         assertThat(underTest.mostRecentViewInfo?.name).isEqualTo("First name")
+        verify(configurationController, never()).removeCallback(any())
 
         reset(windowManager)
         fakeClock.advanceTime(TIMEOUT_MS + 1)
 
         verify(windowManager).removeView(any())
         assertThat(underTest.activeViews.size).isEqualTo(0)
+        verify(configurationController).removeCallback(any())
     }
 
     @Test
@@ -347,18 +409,21 @@
         underTest.displayView(ViewInfo("New name", id = "id1"))
 
         verify(windowManager).addView(any(), any())
-
         reset(windowManager)
+
         underTest.displayView(ViewInfo("Second name", id = "id2"))
+
+        verify(windowManager).removeView(any())
+        verify(windowManager).addView(any(), any())
+        reset(windowManager)
+
         underTest.removeView("id2", "test reason")
 
         verify(windowManager).removeView(any())
-
-        fakeClock.advanceTime(DISPLAY_VIEW_DELAY + 1)
-
+        verify(windowManager).addView(any(), any())
         assertThat(underTest.mostRecentViewInfo?.id).isEqualTo("id1")
         assertThat(underTest.mostRecentViewInfo?.name).isEqualTo("New name")
-        assertThat(underTest.activeViews[0].second.name).isEqualTo("New name")
+        assertThat(underTest.activeViews[0].info.name).isEqualTo("New name")
 
         reset(windowManager)
         fakeClock.advanceTime(TIMEOUT_MS + 1)
@@ -368,19 +433,523 @@
     }
 
     @Test
-    fun multipleViewsWithDifferentIds_viewsTimeouts_noViewLeftToDisplay() {
-        underTest.displayView(ViewInfo("First name", id = "id1"))
-        fakeClock.advanceTime(TIMEOUT_MS / 3)
-        underTest.displayView(ViewInfo("Second name", id = "id2"))
-        fakeClock.advanceTime(TIMEOUT_MS / 3)
-        underTest.displayView(ViewInfo("Third name", id = "id3"))
+    fun multipleViews_mostRecentViewRemoved_otherViewsTimedOutAndNotDisplayed() {
+        underTest.displayView(ViewInfo("First name", id = "id1", timeoutMs = 4000))
+        fakeClock.advanceTime(1000)
+        underTest.displayView(ViewInfo("Second name", id = "id2", timeoutMs = 4000))
+        fakeClock.advanceTime(1000)
+        underTest.displayView(ViewInfo("Third name", id = "id3", timeoutMs = 20000))
 
         reset(windowManager)
-        fakeClock.advanceTime(TIMEOUT_MS + 1)
+        fakeClock.advanceTime(20000 + 1)
 
         verify(windowManager).removeView(any())
         verify(windowManager, never()).addView(any(), any())
         assertThat(underTest.activeViews.size).isEqualTo(0)
+        verify(configurationController).removeCallback(any())
+    }
+
+    @Test
+    fun multipleViews_mostRecentViewRemoved_viewWithShortTimeLeftNotDisplayed() {
+        underTest.displayView(ViewInfo("First name", id = "id1", timeoutMs = 4000))
+        fakeClock.advanceTime(1000)
+        underTest.displayView(ViewInfo("Second name", id = "id2", timeoutMs = 2500))
+
+        reset(windowManager)
+        fakeClock.advanceTime(2500 + 1)
+        // At this point, 3501ms have passed, so id1 only has 499ms left which is not enough.
+        // So, it shouldn't be displayed.
+
+        verify(windowManager, never()).addView(any(), any())
+        assertThat(underTest.activeViews.size).isEqualTo(0)
+        verify(configurationController).removeCallback(any())
+    }
+
+    @Test
+    fun lowerThenHigherPriority_higherReplacesLower() {
+        underTest.displayView(
+            ViewInfo(
+                name = "normal",
+                windowTitle = "Normal Window Title",
+                id = "normal",
+                priority = ViewPriority.NORMAL,
+            )
+        )
+
+        val viewCaptor = argumentCaptor<View>()
+        val windowParamsCaptor = argumentCaptor<WindowManager.LayoutParams>()
+        verify(windowManager).addView(capture(viewCaptor), capture(windowParamsCaptor))
+        assertThat(windowParamsCaptor.value.title).isEqualTo("Normal Window Title")
+        reset(windowManager)
+
+        underTest.displayView(
+            ViewInfo(
+                name = "critical",
+                windowTitle = "Critical Window Title",
+                id = "critical",
+                priority = ViewPriority.CRITICAL,
+            )
+        )
+
+        verify(windowManager).removeView(viewCaptor.value)
+        verify(windowManager).addView(capture(viewCaptor), capture(windowParamsCaptor))
+        assertThat(windowParamsCaptor.value.title).isEqualTo("Critical Window Title")
+        verify(configurationController, never()).removeCallback(any())
+    }
+
+    @Test
+    fun lowerThenHigherPriority_lowerPriorityRedisplayed() {
+        underTest.displayView(
+            ViewInfo(
+                name = "normal",
+                windowTitle = "Normal Window Title",
+                id = "normal",
+                priority = ViewPriority.NORMAL,
+                timeoutMs = 10000
+            )
+        )
+
+        underTest.displayView(
+            ViewInfo(
+                name = "critical",
+                windowTitle = "Critical Window Title",
+                id = "critical",
+                priority = ViewPriority.CRITICAL,
+                timeoutMs = 2000
+            )
+        )
+
+        val viewCaptor = argumentCaptor<View>()
+        val windowParamsCaptor = argumentCaptor<WindowManager.LayoutParams>()
+        verify(windowManager, times(2)).addView(capture(viewCaptor), capture(windowParamsCaptor))
+        assertThat(windowParamsCaptor.allValues[0].title).isEqualTo("Normal Window Title")
+        assertThat(windowParamsCaptor.allValues[1].title).isEqualTo("Critical Window Title")
+        verify(windowManager).removeView(viewCaptor.allValues[0])
+
+        reset(windowManager)
+
+        // WHEN the critical's timeout has expired
+        fakeClock.advanceTime(2000 + 1)
+
+        // THEN the normal view is re-displayed
+        verify(windowManager).removeView(viewCaptor.allValues[1])
+        verify(windowManager).addView(any(), capture(windowParamsCaptor))
+        assertThat(windowParamsCaptor.value.title).isEqualTo("Normal Window Title")
+        verify(configurationController, never()).removeCallback(any())
+    }
+
+    @Test
+    fun lowerThenHigherPriority_lowerPriorityNotRedisplayedBecauseTimedOut() {
+        underTest.displayView(
+            ViewInfo(
+                name = "normal",
+                windowTitle = "Normal Window Title",
+                id = "normal",
+                priority = ViewPriority.NORMAL,
+                timeoutMs = 1000
+            )
+        )
+
+        underTest.displayView(
+            ViewInfo(
+                name = "critical",
+                windowTitle = "Critical Window Title",
+                id = "critical",
+                priority = ViewPriority.CRITICAL,
+                timeoutMs = 2000
+            )
+        )
+        reset(windowManager)
+
+        // WHEN the critical's timeout has expired
+        fakeClock.advanceTime(2000 + 1)
+
+        // THEN the normal view is not re-displayed since it already timed out
+        verify(windowManager).removeView(any())
+        verify(windowManager, never()).addView(any(), any())
+        assertThat(underTest.activeViews).isEmpty()
+        verify(configurationController).removeCallback(any())
+    }
+
+    @Test
+    fun higherThenLowerPriority_higherStaysDisplayed() {
+        underTest.displayView(
+            ViewInfo(
+                name = "critical",
+                windowTitle = "Critical Window Title",
+                id = "critical",
+                priority = ViewPriority.CRITICAL,
+            )
+        )
+
+        val viewCaptor = argumentCaptor<View>()
+        val windowParamsCaptor = argumentCaptor<WindowManager.LayoutParams>()
+        verify(windowManager).addView(capture(viewCaptor), capture(windowParamsCaptor))
+        assertThat(windowParamsCaptor.value.title).isEqualTo("Critical Window Title")
+        reset(windowManager)
+
+        underTest.displayView(
+            ViewInfo(
+                name = "normal",
+                windowTitle = "Normal Window Title",
+                id = "normal",
+                priority = ViewPriority.NORMAL,
+            )
+        )
+
+        verify(windowManager, never()).removeView(viewCaptor.value)
+        verify(windowManager, never()).addView(any(), any())
+        assertThat(underTest.activeViews.size).isEqualTo(2)
+        verify(configurationController, never()).removeCallback(any())
+    }
+
+    @Test
+    fun higherThenLowerPriority_lowerEventuallyDisplayed() {
+        underTest.displayView(
+            ViewInfo(
+                name = "critical",
+                windowTitle = "Critical Window Title",
+                id = "critical",
+                priority = ViewPriority.CRITICAL,
+                timeoutMs = 3000,
+            )
+        )
+
+        val viewCaptor = argumentCaptor<View>()
+        val windowParamsCaptor = argumentCaptor<WindowManager.LayoutParams>()
+        verify(windowManager).addView(capture(viewCaptor), capture(windowParamsCaptor))
+        assertThat(windowParamsCaptor.value.title).isEqualTo("Critical Window Title")
+        reset(windowManager)
+
+        underTest.displayView(
+            ViewInfo(
+                name = "normal",
+                windowTitle = "Normal Window Title",
+                id = "normal",
+                priority = ViewPriority.NORMAL,
+                timeoutMs = 5000,
+            )
+        )
+
+        verify(windowManager, never()).removeView(viewCaptor.value)
+        verify(windowManager, never()).addView(any(), any())
+        assertThat(underTest.activeViews.size).isEqualTo(2)
+
+        // WHEN the first critical view has timed out
+        fakeClock.advanceTime(3000 + 1)
+
+        // THEN the second normal view is displayed
+        verify(windowManager).removeView(viewCaptor.value)
+        verify(windowManager).addView(capture(viewCaptor), capture(windowParamsCaptor))
+        assertThat(windowParamsCaptor.value.title).isEqualTo("Normal Window Title")
+        assertThat(underTest.activeViews.size).isEqualTo(1)
+        verify(configurationController, never()).removeCallback(any())
+    }
+
+    @Test
+    fun higherThenLowerPriority_lowerNotDisplayedBecauseTimedOut() {
+        underTest.displayView(
+            ViewInfo(
+                name = "critical",
+                windowTitle = "Critical Window Title",
+                id = "critical",
+                priority = ViewPriority.CRITICAL,
+                timeoutMs = 3000,
+            )
+        )
+
+        val viewCaptor = argumentCaptor<View>()
+        val windowParamsCaptor = argumentCaptor<WindowManager.LayoutParams>()
+        verify(windowManager).addView(capture(viewCaptor), capture(windowParamsCaptor))
+        assertThat(windowParamsCaptor.value.title).isEqualTo("Critical Window Title")
+        reset(windowManager)
+
+        underTest.displayView(
+            ViewInfo(
+                name = "normal",
+                windowTitle = "Normal Window Title",
+                id = "normal",
+                priority = ViewPriority.NORMAL,
+                timeoutMs = 200,
+            )
+        )
+
+        verify(windowManager, never()).removeView(viewCaptor.value)
+        verify(windowManager, never()).addView(any(), any())
+        assertThat(underTest.activeViews.size).isEqualTo(2)
+        reset(windowManager)
+
+        // WHEN the first critical view has timed out
+        fakeClock.advanceTime(3000 + 1)
+
+        // THEN the second normal view is not displayed because it's already timed out
+        verify(windowManager).removeView(viewCaptor.value)
+        verify(windowManager, never()).addView(any(), any())
+        assertThat(underTest.activeViews).isEmpty()
+        verify(configurationController).removeCallback(any())
+    }
+
+    @Test
+    fun criticalThenNewCritical_newCriticalDisplayed() {
+        underTest.displayView(
+            ViewInfo(
+                name = "critical 1",
+                windowTitle = "Critical Window Title 1",
+                id = "critical1",
+                priority = ViewPriority.CRITICAL,
+            )
+        )
+
+        val viewCaptor = argumentCaptor<View>()
+        val windowParamsCaptor = argumentCaptor<WindowManager.LayoutParams>()
+        verify(windowManager).addView(capture(viewCaptor), capture(windowParamsCaptor))
+        assertThat(windowParamsCaptor.value.title).isEqualTo("Critical Window Title 1")
+        reset(windowManager)
+
+        underTest.displayView(
+            ViewInfo(
+                name = "critical 2",
+                windowTitle = "Critical Window Title 2",
+                id = "critical2",
+                priority = ViewPriority.CRITICAL,
+            )
+        )
+
+        verify(windowManager).removeView(viewCaptor.value)
+        verify(windowManager).addView(capture(viewCaptor), capture(windowParamsCaptor))
+        assertThat(windowParamsCaptor.value.title).isEqualTo("Critical Window Title 2")
+        assertThat(underTest.activeViews.size).isEqualTo(2)
+        verify(configurationController, never()).removeCallback(any())
+    }
+
+    @Test
+    fun normalThenNewNormal_newNormalDisplayed() {
+        underTest.displayView(
+            ViewInfo(
+                name = "normal 1",
+                windowTitle = "Normal Window Title 1",
+                id = "normal1",
+                priority = ViewPriority.NORMAL,
+            )
+        )
+
+        val viewCaptor = argumentCaptor<View>()
+        val windowParamsCaptor = argumentCaptor<WindowManager.LayoutParams>()
+        verify(windowManager).addView(capture(viewCaptor), capture(windowParamsCaptor))
+        assertThat(windowParamsCaptor.value.title).isEqualTo("Normal Window Title 1")
+        reset(windowManager)
+
+        underTest.displayView(
+            ViewInfo(
+                name = "normal 2",
+                windowTitle = "Normal Window Title 2",
+                id = "normal2",
+                priority = ViewPriority.NORMAL,
+            )
+        )
+
+        verify(windowManager).removeView(viewCaptor.value)
+        verify(windowManager).addView(capture(viewCaptor), capture(windowParamsCaptor))
+        assertThat(windowParamsCaptor.value.title).isEqualTo("Normal Window Title 2")
+        assertThat(underTest.activeViews.size).isEqualTo(2)
+        verify(configurationController, never()).removeCallback(any())
+    }
+
+    @Test
+    fun lowerPriorityViewUpdatedWhileHigherPriorityDisplayed_eventuallyDisplaysUpdated() {
+        // First, display a lower priority view
+        underTest.displayView(
+            ViewInfo(
+                name = "normal",
+                windowTitle = "Normal Window Title",
+                id = "normal",
+                priority = ViewPriority.NORMAL,
+                // At the end of the test, we'll verify that this information isn't re-displayed.
+                // Use a super long timeout so that, when we verify it wasn't re-displayed, we know
+                // that it wasn't because the view just timed out.
+                timeoutMs = 100000,
+            )
+        )
+
+        val viewCaptor = argumentCaptor<View>()
+        val windowParamsCaptor = argumentCaptor<WindowManager.LayoutParams>()
+        verify(windowManager).addView(capture(viewCaptor), capture(windowParamsCaptor))
+        assertThat(windowParamsCaptor.value.title).isEqualTo("Normal Window Title")
+        reset(windowManager)
+
+        // Then, display a higher priority view
+        fakeClock.advanceTime(1000)
+        underTest.displayView(
+            ViewInfo(
+                name = "critical",
+                windowTitle = "Critical Window Title",
+                id = "critical",
+                priority = ViewPriority.CRITICAL,
+                timeoutMs = 3000,
+            )
+        )
+
+        verify(windowManager).removeView(viewCaptor.value)
+        verify(windowManager).addView(capture(viewCaptor), capture(windowParamsCaptor))
+        assertThat(windowParamsCaptor.value.title).isEqualTo("Critical Window Title")
+        assertThat(underTest.activeViews.size).isEqualTo(2)
+        reset(windowManager)
+
+        // While the higher priority view is displayed, update the lower priority view with new
+        // information
+        fakeClock.advanceTime(1000)
+        val updatedViewInfo = ViewInfo(
+            name = "normal with update",
+            windowTitle = "Normal Window Title",
+            id = "normal",
+            priority = ViewPriority.NORMAL,
+            timeoutMs = 4000,
+        )
+        underTest.displayView(updatedViewInfo)
+
+        verify(windowManager, never()).removeView(viewCaptor.value)
+        verify(windowManager, never()).addView(any(), any())
+        assertThat(underTest.activeViews.size).isEqualTo(2)
+        reset(windowManager)
+
+        // WHEN the higher priority view times out
+        fakeClock.advanceTime(2001)
+
+        // THEN the higher priority view disappears and the lower priority view *with the updated
+        // information* gets displayed.
+        verify(windowManager).removeView(viewCaptor.value)
+        verify(windowManager).addView(capture(viewCaptor), capture(windowParamsCaptor))
+        assertThat(windowParamsCaptor.value.title).isEqualTo("Normal Window Title")
+        assertThat(underTest.activeViews.size).isEqualTo(1)
+        assertThat(underTest.mostRecentViewInfo).isEqualTo(updatedViewInfo)
+        reset(windowManager)
+
+        // WHEN the updated view times out
+        fakeClock.advanceTime(2001)
+
+        // THEN the old information is never displayed
+        verify(windowManager).removeView(viewCaptor.value)
+        verify(windowManager, never()).addView(any(), any())
+        assertThat(underTest.activeViews.size).isEqualTo(0)
+    }
+
+    @Test
+    fun oldViewUpdatedWhileNewViewDisplayed_eventuallyDisplaysUpdated() {
+        // First, display id1 view
+        underTest.displayView(
+            ViewInfo(
+                name = "name 1",
+                windowTitle = "Name 1 Title",
+                id = "id1",
+                priority = ViewPriority.NORMAL,
+                // At the end of the test, we'll verify that this information isn't re-displayed.
+                // Use a super long timeout so that, when we verify it wasn't re-displayed, we know
+                // that it wasn't because the view just timed out.
+                timeoutMs = 100000,
+            )
+        )
+
+        val viewCaptor = argumentCaptor<View>()
+        val windowParamsCaptor = argumentCaptor<WindowManager.LayoutParams>()
+        verify(windowManager).addView(capture(viewCaptor), capture(windowParamsCaptor))
+        assertThat(windowParamsCaptor.value.title).isEqualTo("Name 1 Title")
+        reset(windowManager)
+
+        // Then, display a new id2 view
+        fakeClock.advanceTime(1000)
+        underTest.displayView(
+            ViewInfo(
+                name = "name 2",
+                windowTitle = "Name 2 Title",
+                id = "id2",
+                priority = ViewPriority.NORMAL,
+                timeoutMs = 3000,
+            )
+        )
+
+        verify(windowManager).removeView(viewCaptor.value)
+        verify(windowManager).addView(capture(viewCaptor), capture(windowParamsCaptor))
+        assertThat(windowParamsCaptor.value.title).isEqualTo("Name 2 Title")
+        assertThat(underTest.activeViews.size).isEqualTo(2)
+        reset(windowManager)
+
+        // While the id2 view is displayed, re-display the id1 view with new information
+        fakeClock.advanceTime(1000)
+        val updatedViewInfo = ViewInfo(
+            name = "name 1 with update",
+            windowTitle = "Name 1 Title",
+            id = "id1",
+            priority = ViewPriority.NORMAL,
+            timeoutMs = 3000,
+        )
+        underTest.displayView(updatedViewInfo)
+
+        verify(windowManager).removeView(viewCaptor.value)
+        verify(windowManager).addView(capture(viewCaptor), capture(windowParamsCaptor))
+        assertThat(windowParamsCaptor.value.title).isEqualTo("Name 1 Title")
+        assertThat(underTest.activeViews.size).isEqualTo(2)
+        reset(windowManager)
+
+        // WHEN the id1 view with new information times out
+        fakeClock.advanceTime(3001)
+
+        // THEN the id1 view disappears and the old id1 information is never displayed
+        verify(windowManager).removeView(viewCaptor.value)
+        verify(windowManager, never()).addView(any(), any())
+        assertThat(underTest.activeViews.size).isEqualTo(0)
+    }
+
+    @Test
+    fun oldViewUpdatedWhileNewViewDisplayed_usesNewTimeout() {
+        // First, display id1 view
+        underTest.displayView(
+            ViewInfo(
+                name = "name 1",
+                windowTitle = "Name 1 Title",
+                id = "id1",
+                priority = ViewPriority.NORMAL,
+                timeoutMs = 5000,
+            )
+        )
+
+        // Then, display a new id2 view
+        fakeClock.advanceTime(1000)
+        underTest.displayView(
+            ViewInfo(
+                name = "name 2",
+                windowTitle = "Name 2 Title",
+                id = "id2",
+                priority = ViewPriority.NORMAL,
+                timeoutMs = 3000,
+            )
+        )
+        reset(windowManager)
+
+        // While the id2 view is displayed, re-display the id1 view with new information *and a
+        // longer timeout*
+        fakeClock.advanceTime(1000)
+        val updatedViewInfo = ViewInfo(
+            name = "name 1 with update",
+            windowTitle = "Name 1 Title",
+            id = "id1",
+            priority = ViewPriority.NORMAL,
+            timeoutMs = 30000,
+        )
+        underTest.displayView(updatedViewInfo)
+
+        val viewCaptor = argumentCaptor<View>()
+        val windowParamsCaptor = argumentCaptor<WindowManager.LayoutParams>()
+        verify(windowManager).addView(capture(viewCaptor), capture(windowParamsCaptor))
+        assertThat(windowParamsCaptor.value.title).isEqualTo("Name 1 Title")
+        assertThat(underTest.activeViews.size).isEqualTo(2)
+        reset(windowManager)
+
+        // WHEN id1's *old* timeout occurs
+        fakeClock.advanceTime(3001)
+
+        // THEN id1 is still displayed because it was updated with a new timeout
+        verify(windowManager, never()).removeView(viewCaptor.value)
+        assertThat(underTest.activeViews.size).isEqualTo(1)
     }
 
     @Test
@@ -395,6 +964,7 @@
 
         verify(windowManager).removeView(any())
         verify(logger).logViewRemoval(deviceId, reason)
+        verify(configurationController).removeCallback(any())
     }
 
     @Test
@@ -414,14 +984,15 @@
 
     inner class TestController(
         context: Context,
-        logger: TemporaryViewLogger,
+        logger: TemporaryViewLogger<ViewInfo>,
         windowManager: WindowManager,
         @Main mainExecutor: DelayableExecutor,
         accessibilityManager: AccessibilityManager,
         configurationController: ConfigurationController,
         powerManager: PowerManager,
         wakeLockBuilder: WakeLock.Builder,
-    ) : TemporaryViewDisplayController<ViewInfo, TemporaryViewLogger>(
+        systemClock: SystemClock,
+    ) : TemporaryViewDisplayController<ViewInfo, TemporaryViewLogger<ViewInfo>>(
         context,
         logger,
         windowManager,
@@ -431,6 +1002,7 @@
         powerManager,
         R.layout.chipbar,
         wakeLockBuilder,
+        systemClock,
     ) {
         var mostRecentViewInfo: ViewInfo? = null
 
@@ -447,12 +1019,13 @@
         override fun start() {}
     }
 
-    inner class ViewInfo(
+    data class ViewInfo(
         val name: String,
         override val windowTitle: String = "Window Title",
         override val wakeReason: String = "WAKE_REASON",
-        override val timeoutMs: Int = 1,
+        override val timeoutMs: Int = TIMEOUT_MS.toInt(),
         override val id: String = "id",
+        override val priority: ViewPriority = ViewPriority.NORMAL,
     ) : TemporaryViewInfo()
 }
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewLoggerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewLoggerTest.kt
index 116b8fe..2e66b20 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewLoggerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/TemporaryViewLoggerTest.kt
@@ -32,7 +32,7 @@
 @SmallTest
 class TemporaryViewLoggerTest : SysuiTestCase() {
     private lateinit var buffer: LogBuffer
-    private lateinit var logger: TemporaryViewLogger
+    private lateinit var logger: TemporaryViewLogger<TemporaryViewInfo>
 
     @Before
     fun setUp() {
@@ -44,13 +44,22 @@
 
     @Test
     fun logViewAddition_bufferHasLog() {
-        logger.logViewAddition("test id", "Test Window Title")
+        val info =
+            object : TemporaryViewInfo() {
+                override val id: String = "test id"
+                override val priority: ViewPriority = ViewPriority.CRITICAL
+                override val windowTitle: String = "Test Window Title"
+                override val wakeReason: String = "wake reason"
+            }
+
+        logger.logViewAddition(info)
 
         val stringWriter = StringWriter()
         buffer.dump(PrintWriter(stringWriter), tailLength = 0)
         val actualString = stringWriter.toString()
 
         assertThat(actualString).contains(TAG)
+        assertThat(actualString).contains("test id")
         assertThat(actualString).contains("Test Window Title")
     }
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinatorTest.kt
index 47c84ab..2e4d8e7 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinatorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinatorTest.kt
@@ -35,9 +35,11 @@
 import com.android.systemui.common.shared.model.ContentDescription.Companion.loadContentDescription
 import com.android.systemui.common.shared.model.Icon
 import com.android.systemui.common.shared.model.Text
+import com.android.systemui.common.shared.model.TintedIcon
 import com.android.systemui.plugins.FalsingManager
 import com.android.systemui.statusbar.VibratorHelper
 import com.android.systemui.statusbar.policy.ConfigurationController
+import com.android.systemui.temporarydisplay.ViewPriority
 import com.android.systemui.util.concurrency.FakeExecutor
 import com.android.systemui.util.mockito.any
 import com.android.systemui.util.mockito.eq
@@ -104,11 +106,41 @@
                 viewUtil,
                 vibratorHelper,
                 fakeWakeLockBuilder,
+                fakeClock,
             )
         underTest.start()
     }
 
     @Test
+    fun displayView_contentDescription_iconHasDescription() {
+        underTest.displayView(
+            createChipbarInfo(
+                Icon.Resource(R.drawable.ic_cake, ContentDescription.Loaded("loadedCD")),
+                Text.Loaded("text"),
+                endItem = null,
+            )
+        )
+
+        val contentDescView = getChipbarView().requireViewById<ViewGroup>(R.id.chipbar_inner)
+        assertThat(contentDescView.contentDescription.toString()).contains("loadedCD")
+        assertThat(contentDescView.contentDescription.toString()).contains("text")
+    }
+
+    @Test
+    fun displayView_contentDescription_iconHasNoDescription() {
+        underTest.displayView(
+            createChipbarInfo(
+                Icon.Resource(R.drawable.ic_cake, contentDescription = null),
+                Text.Loaded("text"),
+                endItem = null,
+            )
+        )
+
+        val contentDescView = getChipbarView().requireViewById<ViewGroup>(R.id.chipbar_inner)
+        assertThat(contentDescView.contentDescription.toString()).isEqualTo("text")
+    }
+
+    @Test
     fun displayView_loadedIcon_correctlyRendered() {
         val drawable = context.getDrawable(R.drawable.ic_celebration)!!
 
@@ -370,7 +402,7 @@
         vibrationEffect: VibrationEffect? = null,
     ): ChipbarInfo {
         return ChipbarInfo(
-            startIcon,
+            TintedIcon(startIcon, tintAttr = null),
             text,
             endItem,
             vibrationEffect,
@@ -378,6 +410,7 @@
             wakeReason = WAKE_REASON,
             timeoutMs = TIMEOUT,
             id = DEVICE_ID,
+            priority = ViewPriority.NORMAL,
         )
     }
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/FakeChipbarCoordinator.kt b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/FakeChipbarCoordinator.kt
index beedf9f..d5167b3 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/FakeChipbarCoordinator.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/FakeChipbarCoordinator.kt
@@ -26,6 +26,7 @@
 import com.android.systemui.statusbar.VibratorHelper
 import com.android.systemui.statusbar.policy.ConfigurationController
 import com.android.systemui.util.concurrency.DelayableExecutor
+import com.android.systemui.util.time.SystemClock
 import com.android.systemui.util.view.ViewUtil
 import com.android.systemui.util.wakelock.WakeLock
 
@@ -43,6 +44,7 @@
     viewUtil: ViewUtil,
     vibratorHelper: VibratorHelper,
     wakeLockBuilder: WakeLock.Builder,
+    systemClock: SystemClock,
 ) :
     ChipbarCoordinator(
         context,
@@ -57,6 +59,7 @@
         viewUtil,
         vibratorHelper,
         wakeLockBuilder,
+        systemClock,
     ) {
     override fun animateViewOut(view: ViewGroup, onAnimationEnd: Runnable) {
         // Just bypass the animation in tests
diff --git a/packages/SystemUI/tests/src/com/android/systemui/touch/TouchInsetManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/touch/TouchInsetManagerTest.java
index 14b9bfb..a707222 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/touch/TouchInsetManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/touch/TouchInsetManagerTest.java
@@ -26,8 +26,8 @@
 import android.graphics.Rect;
 import android.graphics.Region;
 import android.testing.AndroidTestingRunner;
+import android.view.AttachedSurfaceControl;
 import android.view.View;
-import android.view.ViewRootImpl;
 
 import androidx.test.filters.SmallTest;
 
@@ -47,41 +47,78 @@
 @RunWith(AndroidTestingRunner.class)
 public class TouchInsetManagerTest extends SysuiTestCase {
     @Mock
-    private View mRootView;
-
-    @Mock
-    private ViewRootImpl mRootViewImpl;
+    private AttachedSurfaceControl mAttachedSurfaceControl;
 
     private FakeExecutor mFakeExecutor = new FakeExecutor(new FakeSystemClock());
 
     @Before
     public void setup() {
         MockitoAnnotations.initMocks(this);
-        when(mRootView.getViewRootImpl()).thenReturn(mRootViewImpl);
     }
 
     @Test
-    public void testRootViewOnAttachedHandling() {
+    public void testViewOnAttachedHandling() {
         // Create inset manager
-        final TouchInsetManager insetManager = new TouchInsetManager(mFakeExecutor,
-                mRootView);
+        final TouchInsetManager insetManager = new TouchInsetManager(mFakeExecutor);
 
         final ArgumentCaptor<View.OnAttachStateChangeListener> listener =
                 ArgumentCaptor.forClass(View.OnAttachStateChangeListener.class);
+        final View view = createView(new Rect(0, 0, 0, 0));
+        when(view.isAttachedToWindow()).thenReturn(false);
 
+
+        // Create session
+        final TouchInsetManager.TouchInsetSession session = insetManager.createSession();
+        session.addViewToTracking(view);
+
+        mFakeExecutor.runAllReady();
         // Ensure manager has registered to listen to attached state of root view.
-        verify(mRootView).addOnAttachStateChangeListener(listener.capture());
+        verify(view).addOnAttachStateChangeListener(listener.capture());
+
+        clearInvocations(mAttachedSurfaceControl);
+        when(view.isAttachedToWindow()).thenReturn(true);
 
         // Trigger attachment and verify touchable region is set.
-        listener.getValue().onViewAttachedToWindow(mRootView);
-        verify(mRootViewImpl).setTouchableRegion(any());
+        listener.getValue().onViewAttachedToWindow(view);
+
+        mFakeExecutor.runAllReady();
+
+        verify(mAttachedSurfaceControl).setTouchableRegion(any());
+    }
+
+    @Test
+    public void testViewOnDetachedHandling() {
+        // Create inset manager
+        final TouchInsetManager insetManager = new TouchInsetManager(mFakeExecutor);
+
+        final ArgumentCaptor<View.OnAttachStateChangeListener> listener =
+                ArgumentCaptor.forClass(View.OnAttachStateChangeListener.class);
+        final View view = createView(new Rect(0, 0, 0, 0));
+        when(view.isAttachedToWindow()).thenReturn(true);
+
+        // Create session
+        final TouchInsetManager.TouchInsetSession session = insetManager.createSession();
+        session.addViewToTracking(view);
+
+        mFakeExecutor.runAllReady();
+        // Ensure manager has registered to listen to attached state of root view.
+        verify(view).addOnAttachStateChangeListener(listener.capture());
+
+        clearInvocations(mAttachedSurfaceControl);
+        when(view.isAttachedToWindow()).thenReturn(false);
+
+        // Trigger detachment and verify touchable region is set.
+        listener.getValue().onViewDetachedFromWindow(view);
+
+        mFakeExecutor.runAllReady();
+
+        verify(mAttachedSurfaceControl).setTouchableRegion(any());
     }
 
     @Test
     public void testInsetRegionPropagation() {
         // Create inset manager
-        final TouchInsetManager insetManager = new TouchInsetManager(mFakeExecutor,
-                mRootView);
+        final TouchInsetManager insetManager = new TouchInsetManager(mFakeExecutor);
 
         // Create session
         final TouchInsetManager.TouchInsetSession session = insetManager.createSession();
@@ -95,14 +132,13 @@
         // Check to see if view was properly accounted for.
         final Region expectedRegion = Region.obtain();
         expectedRegion.op(rect, Region.Op.UNION);
-        verify(mRootViewImpl).setTouchableRegion(eq(expectedRegion));
+        verify(mAttachedSurfaceControl).setTouchableRegion(eq(expectedRegion));
     }
 
     @Test
     public void testMultipleRegions() {
         // Create inset manager
-        final TouchInsetManager insetManager = new TouchInsetManager(mFakeExecutor,
-                mRootView);
+        final TouchInsetManager insetManager = new TouchInsetManager(mFakeExecutor);
 
         // Create session
         final TouchInsetManager.TouchInsetSession session = insetManager.createSession();
@@ -112,7 +148,7 @@
         session.addViewToTracking(createView(firstBounds));
 
         mFakeExecutor.runAllReady();
-        clearInvocations(mRootViewImpl);
+        clearInvocations(mAttachedSurfaceControl);
 
         // Create second session
         final TouchInsetManager.TouchInsetSession secondSession = insetManager.createSession();
@@ -128,27 +164,26 @@
             final Region expectedRegion = Region.obtain();
             expectedRegion.op(firstBounds, Region.Op.UNION);
             expectedRegion.op(secondBounds, Region.Op.UNION);
-            verify(mRootViewImpl).setTouchableRegion(eq(expectedRegion));
+            verify(mAttachedSurfaceControl).setTouchableRegion(eq(expectedRegion));
         }
 
 
-        clearInvocations(mRootViewImpl);
+        clearInvocations(mAttachedSurfaceControl);
 
         // clear first session, ensure second session is still reflected.
         session.clear();
         mFakeExecutor.runAllReady();
         {
             final Region expectedRegion = Region.obtain();
-            expectedRegion.op(firstBounds, Region.Op.UNION);
-            verify(mRootViewImpl).setTouchableRegion(eq(expectedRegion));
+            expectedRegion.op(secondBounds, Region.Op.UNION);
+            verify(mAttachedSurfaceControl).setTouchableRegion(eq(expectedRegion));
         }
     }
 
     @Test
     public void testMultipleViews() {
         // Create inset manager
-        final TouchInsetManager insetManager = new TouchInsetManager(mFakeExecutor,
-                mRootView);
+        final TouchInsetManager insetManager = new TouchInsetManager(mFakeExecutor);
 
         // Create session
         final TouchInsetManager.TouchInsetSession session = insetManager.createSession();
@@ -159,7 +194,7 @@
 
         // only capture second invocation.
         mFakeExecutor.runAllReady();
-        clearInvocations(mRootViewImpl);
+        clearInvocations(mAttachedSurfaceControl);
 
         // Add a second view to the session
         final Rect secondViewBounds = new Rect(4, 4, 9, 10);
@@ -173,20 +208,20 @@
             final Region expectedRegion = Region.obtain();
             expectedRegion.op(firstViewBounds, Region.Op.UNION);
             expectedRegion.op(secondViewBounds, Region.Op.UNION);
-            verify(mRootViewImpl).setTouchableRegion(eq(expectedRegion));
+            verify(mAttachedSurfaceControl).setTouchableRegion(eq(expectedRegion));
         }
 
         // Remove second view.
         session.removeViewFromTracking(secondView);
 
-        clearInvocations(mRootViewImpl);
+        clearInvocations(mAttachedSurfaceControl);
         mFakeExecutor.runAllReady();
 
         // Ensure first view still reflected in touch region.
         {
             final Region expectedRegion = Region.obtain();
             expectedRegion.op(firstViewBounds, Region.Op.UNION);
-            verify(mRootViewImpl).setTouchableRegion(eq(expectedRegion));
+            verify(mAttachedSurfaceControl).setTouchableRegion(eq(expectedRegion));
         }
     }
 
@@ -197,6 +232,8 @@
             ((Rect) invocation.getArgument(0)).set(rect);
             return null;
         }).when(view).getBoundsOnScreen(any());
+        when(view.isAttachedToWindow()).thenReturn(true);
+        when(view.getRootSurfaceControl()).thenReturn(mAttachedSurfaceControl);
 
         return view;
     }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/unfold/progress/PhysicsBasedUnfoldTransitionProgressProviderTest.kt b/packages/SystemUI/tests/src/com/android/systemui/unfold/progress/PhysicsBasedUnfoldTransitionProgressProviderTest.kt
index 03fd624..abbdab0 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/unfold/progress/PhysicsBasedUnfoldTransitionProgressProviderTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/unfold/progress/PhysicsBasedUnfoldTransitionProgressProviderTest.kt
@@ -69,6 +69,22 @@
     }
 
     @Test
+    fun testUnfold_emitsFinishingEvent() {
+        runOnMainThreadWithInterval(
+            { foldStateProvider.sendFoldUpdate(FOLD_UPDATE_START_OPENING) },
+            { foldStateProvider.sendHingeAngleUpdate(10f) },
+            { foldStateProvider.sendFoldUpdate(FOLD_UPDATE_UNFOLDED_SCREEN_AVAILABLE) },
+            { foldStateProvider.sendHingeAngleUpdate(90f) },
+            { foldStateProvider.sendHingeAngleUpdate(180f) },
+            { foldStateProvider.sendFoldUpdate(FOLD_UPDATE_FINISH_FULL_OPEN) },
+        )
+
+        with(listener.ensureTransitionFinished()) {
+            assertHasSingleFinishingEvent()
+        }
+    }
+
+    @Test
     fun testUnfold_screenAvailableOnlyAfterFullUnfold_emitsIncreasingTransitionEvents() {
         runOnMainThreadWithInterval(
             { foldStateProvider.sendFoldUpdate(FOLD_UPDATE_START_OPENING) },
@@ -157,6 +173,12 @@
             currentRecording!!.addProgress(progress)
         }
 
+        override fun onTransitionFinishing() {
+            assertWithMessage("Received transition finishing event when it's not started")
+                    .that(currentRecording).isNotNull()
+            currentRecording!!.onFinishing()
+        }
+
         override fun onTransitionFinished() {
             assertWithMessage("Received transition finish event when it's not started")
                 .that(currentRecording).isNotNull()
@@ -171,6 +193,7 @@
 
         class UnfoldTransitionRecording {
             private val progressHistory: MutableList<Float> = arrayListOf()
+            private var finishingInvocations: Int = 0
 
             fun addProgress(progress: Float) {
                 assertThat(progress).isAtMost(1.0f)
@@ -179,6 +202,10 @@
                 progressHistory += progress
             }
 
+            fun onFinishing() {
+                finishingInvocations++
+            }
+
             fun assertIncreasingProgress() {
                 assertThat(progressHistory.size).isGreaterThan(MIN_ANIMATION_EVENTS)
                 assertThat(progressHistory).isInOrder()
@@ -206,6 +233,11 @@
                     .isInOrder(Comparator.reverseOrder<Float>())
                 assertThat(progressHistory.last()).isEqualTo(0.0f)
             }
+
+            fun assertHasSingleFinishingEvent() {
+                assertWithMessage("onTransitionFinishing callback should be invoked exactly " +
+                        "one time").that(finishingInvocations).isEqualTo(1)
+            }
         }
 
         private companion object {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt
index 5beb2b3..ffa4e2d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt
@@ -52,6 +52,7 @@
 import com.android.systemui.user.domain.model.ShowDialogRequestModel
 import com.android.systemui.user.shared.model.UserActionModel
 import com.android.systemui.user.shared.model.UserModel
+import com.android.systemui.user.utils.MultiUserActionsEvent
 import com.android.systemui.util.mockito.any
 import com.android.systemui.util.mockito.argumentCaptor
 import com.android.systemui.util.mockito.eq
@@ -74,6 +75,7 @@
 import org.mockito.ArgumentMatchers.anyInt
 import org.mockito.Mock
 import org.mockito.Mockito.never
+import org.mockito.Mockito.times
 import org.mockito.Mockito.verify
 import org.mockito.MockitoAnnotations
 
@@ -158,6 +160,7 @@
                         resumeSessionReceiver = resumeSessionReceiver,
                         resetOrExitSessionReceiver = resetOrExitSessionReceiver,
                     ),
+                uiEventLogger = uiEventLogger,
                 featureFlags = featureFlags,
             )
     }
@@ -457,6 +460,9 @@
             val dialogShower: UserSwitchDialogController.DialogShower = mock()
 
             underTest.executeAction(UserActionModel.ADD_USER, dialogShower)
+
+            verify(uiEventLogger, times(1))
+                .log(MultiUserActionsEvent.CREATE_USER_FROM_USER_SWITCHER)
             assertThat(dialogRequest)
                 .isEqualTo(
                     ShowDialogRequestModel.ShowAddUserDialog(
@@ -478,6 +484,8 @@
         runBlocking(IMMEDIATE) {
             underTest.executeAction(UserActionModel.ADD_SUPERVISED_USER)
 
+            verify(uiEventLogger, times(1))
+                .log(MultiUserActionsEvent.CREATE_RESTRICTED_USER_FROM_USER_SWITCHER)
             val intentCaptor = kotlinArgumentCaptor<Intent>()
             verify(activityStarter).startActivity(intentCaptor.capture(), eq(true))
             assertThat(intentCaptor.value.action)
@@ -525,6 +533,8 @@
 
             underTest.executeAction(UserActionModel.ENTER_GUEST_MODE)
 
+            verify(uiEventLogger, times(1))
+                .log(MultiUserActionsEvent.CREATE_GUEST_FROM_USER_SWITCHER)
             assertThat(dialogRequests)
                 .contains(
                     ShowDialogRequestModel.ShowUserCreationDialog(isGuest = true),
diff --git a/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/StatusBarUserChipViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/StatusBarUserChipViewModelTest.kt
index 108fa62..5d4c1cc 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/StatusBarUserChipViewModelTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/StatusBarUserChipViewModelTest.kt
@@ -255,6 +255,7 @@
                     activityManager = activityManager,
                     refreshUsersScheduler = refreshUsersScheduler,
                     guestUserInteractor = guestUserInteractor,
+                    uiEventLogger = uiEventLogger,
                 )
         )
     }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModelTest.kt
index 784a26b..0efede1 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModelTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/user/ui/viewmodel/UserSwitcherViewModelTest.kt
@@ -158,6 +158,7 @@
                             activityManager = activityManager,
                             refreshUsersScheduler = refreshUsersScheduler,
                             guestUserInteractor = guestUserInteractor,
+                            uiEventLogger = uiEventLogger,
                         ),
                     powerInteractor =
                         PowerInteractor(
diff --git a/packages/SystemUI/tests/src/com/android/systemui/util/TestableAlertDialogTest.kt b/packages/SystemUI/tests/src/com/android/systemui/util/TestableAlertDialogTest.kt
new file mode 100644
index 0000000..01dd60a
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/util/TestableAlertDialogTest.kt
@@ -0,0 +1,333 @@
+/*
+ * 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.systemui.util
+
+import android.content.DialogInterface
+import android.content.DialogInterface.BUTTON_NEGATIVE
+import android.content.DialogInterface.BUTTON_NEUTRAL
+import android.content.DialogInterface.BUTTON_POSITIVE
+import android.testing.AndroidTestingRunner
+import android.testing.TestableLooper
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.util.mockito.any
+import com.android.systemui.util.mockito.mock
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.Mockito.anyInt
+import org.mockito.Mockito.inOrder
+import org.mockito.Mockito.never
+import org.mockito.Mockito.verify
+
+@SmallTest
+@RunWith(AndroidTestingRunner::class)
+@TestableLooper.RunWithLooper
+class TestableAlertDialogTest : SysuiTestCase() {
+
+    @Test
+    fun dialogNotShowingWhenCreated() {
+        val dialog = TestableAlertDialog(context)
+
+        assertThat(dialog.isShowing).isFalse()
+    }
+
+    @Test
+    fun dialogShownDoesntCrash() {
+        val dialog = TestableAlertDialog(context)
+
+        dialog.show()
+    }
+
+    @Test
+    fun dialogShowing() {
+        val dialog = TestableAlertDialog(context)
+
+        dialog.show()
+
+        assertThat(dialog.isShowing).isTrue()
+    }
+
+    @Test
+    fun showListenerCalled() {
+        val dialog = TestableAlertDialog(context)
+        val listener: DialogInterface.OnShowListener = mock()
+        dialog.setOnShowListener(listener)
+
+        dialog.show()
+
+        verify(listener).onShow(dialog)
+    }
+
+    @Test
+    fun showListenerRemoved() {
+        val dialog = TestableAlertDialog(context)
+        val listener: DialogInterface.OnShowListener = mock()
+        dialog.setOnShowListener(listener)
+        dialog.setOnShowListener(null)
+
+        dialog.show()
+
+        verify(listener, never()).onShow(any())
+    }
+
+    @Test
+    fun dialogHiddenNotShowing() {
+        val dialog = TestableAlertDialog(context)
+
+        dialog.show()
+        dialog.hide()
+
+        assertThat(dialog.isShowing).isFalse()
+    }
+
+    @Test
+    fun dialogDismissNotShowing() {
+        val dialog = TestableAlertDialog(context)
+
+        dialog.show()
+        dialog.dismiss()
+
+        assertThat(dialog.isShowing).isFalse()
+    }
+
+    @Test
+    fun dismissListenerCalled_ifShowing() {
+        val dialog = TestableAlertDialog(context)
+        val listener: DialogInterface.OnDismissListener = mock()
+        dialog.setOnDismissListener(listener)
+
+        dialog.show()
+        dialog.dismiss()
+
+        verify(listener).onDismiss(dialog)
+    }
+
+    @Test
+    fun dismissListenerNotCalled_ifNotShowing() {
+        val dialog = TestableAlertDialog(context)
+        val listener: DialogInterface.OnDismissListener = mock()
+        dialog.setOnDismissListener(listener)
+
+        dialog.dismiss()
+
+        verify(listener, never()).onDismiss(any())
+    }
+
+    @Test
+    fun dismissListenerRemoved() {
+        val dialog = TestableAlertDialog(context)
+        val listener: DialogInterface.OnDismissListener = mock()
+        dialog.setOnDismissListener(listener)
+        dialog.setOnDismissListener(null)
+
+        dialog.show()
+        dialog.dismiss()
+
+        verify(listener, never()).onDismiss(any())
+    }
+
+    @Test
+    fun cancelListenerCalled_showing() {
+        val dialog = TestableAlertDialog(context)
+        val listener: DialogInterface.OnCancelListener = mock()
+        dialog.setOnCancelListener(listener)
+
+        dialog.show()
+        dialog.cancel()
+
+        verify(listener).onCancel(dialog)
+    }
+
+    @Test
+    fun cancelListenerCalled_notShowing() {
+        val dialog = TestableAlertDialog(context)
+        val listener: DialogInterface.OnCancelListener = mock()
+        dialog.setOnCancelListener(listener)
+
+        dialog.cancel()
+
+        verify(listener).onCancel(dialog)
+    }
+
+    @Test
+    fun dismissCalledOnCancel_showing() {
+        val dialog = TestableAlertDialog(context)
+        val listener: DialogInterface.OnDismissListener = mock()
+        dialog.setOnDismissListener(listener)
+
+        dialog.show()
+        dialog.cancel()
+
+        verify(listener).onDismiss(dialog)
+    }
+
+    @Test
+    fun dialogCancelNotShowing() {
+        val dialog = TestableAlertDialog(context)
+
+        dialog.show()
+        dialog.cancel()
+
+        assertThat(dialog.isShowing).isFalse()
+    }
+
+    @Test
+    fun cancelListenerRemoved() {
+        val dialog = TestableAlertDialog(context)
+        val listener: DialogInterface.OnCancelListener = mock()
+        dialog.setOnCancelListener(listener)
+        dialog.setOnCancelListener(null)
+
+        dialog.show()
+        dialog.cancel()
+
+        verify(listener, never()).onCancel(any())
+    }
+
+    @Test
+    fun positiveButtonClick() {
+        val dialog = TestableAlertDialog(context)
+        val listener: DialogInterface.OnClickListener = mock()
+        dialog.setButton(BUTTON_POSITIVE, "", listener)
+
+        dialog.show()
+        dialog.clickButton(BUTTON_POSITIVE)
+
+        verify(listener).onClick(dialog, BUTTON_POSITIVE)
+    }
+
+    @Test
+    fun positiveButtonListener_noCalledWhenClickOtherButtons() {
+        val dialog = TestableAlertDialog(context)
+        val listener: DialogInterface.OnClickListener = mock()
+        dialog.setButton(BUTTON_POSITIVE, "", listener)
+
+        dialog.show()
+        dialog.clickButton(BUTTON_NEUTRAL)
+        dialog.clickButton(BUTTON_NEGATIVE)
+
+        verify(listener, never()).onClick(any(), anyInt())
+    }
+
+    @Test
+    fun negativeButtonClick() {
+        val dialog = TestableAlertDialog(context)
+        val listener: DialogInterface.OnClickListener = mock()
+        dialog.setButton(BUTTON_NEGATIVE, "", listener)
+
+        dialog.show()
+        dialog.clickButton(BUTTON_NEGATIVE)
+
+        verify(listener).onClick(dialog, DialogInterface.BUTTON_NEGATIVE)
+    }
+
+    @Test
+    fun negativeButtonListener_noCalledWhenClickOtherButtons() {
+        val dialog = TestableAlertDialog(context)
+        val listener: DialogInterface.OnClickListener = mock()
+        dialog.setButton(BUTTON_NEGATIVE, "", listener)
+
+        dialog.show()
+        dialog.clickButton(BUTTON_NEUTRAL)
+        dialog.clickButton(BUTTON_POSITIVE)
+
+        verify(listener, never()).onClick(any(), anyInt())
+    }
+
+    @Test
+    fun neutralButtonClick() {
+        val dialog = TestableAlertDialog(context)
+        val listener: DialogInterface.OnClickListener = mock()
+        dialog.setButton(BUTTON_NEUTRAL, "", listener)
+
+        dialog.show()
+        dialog.clickButton(BUTTON_NEUTRAL)
+
+        verify(listener).onClick(dialog, BUTTON_NEUTRAL)
+    }
+
+    @Test
+    fun neutralButtonListener_noCalledWhenClickOtherButtons() {
+        val dialog = TestableAlertDialog(context)
+        val listener: DialogInterface.OnClickListener = mock()
+        dialog.setButton(BUTTON_NEUTRAL, "", listener)
+
+        dialog.show()
+        dialog.clickButton(BUTTON_POSITIVE)
+        dialog.clickButton(BUTTON_NEGATIVE)
+
+        verify(listener, never()).onClick(any(), anyInt())
+    }
+
+    @Test
+    fun sameClickListenerCalledCorrectly() {
+        val dialog = TestableAlertDialog(context)
+        val listener: DialogInterface.OnClickListener = mock()
+        dialog.setButton(BUTTON_POSITIVE, "", listener)
+        dialog.setButton(BUTTON_NEUTRAL, "", listener)
+        dialog.setButton(BUTTON_NEGATIVE, "", listener)
+
+        dialog.show()
+        dialog.clickButton(BUTTON_POSITIVE)
+        dialog.clickButton(BUTTON_NEGATIVE)
+        dialog.clickButton(BUTTON_NEUTRAL)
+
+        val inOrder = inOrder(listener)
+        inOrder.verify(listener).onClick(dialog, BUTTON_POSITIVE)
+        inOrder.verify(listener).onClick(dialog, BUTTON_NEGATIVE)
+        inOrder.verify(listener).onClick(dialog, BUTTON_NEUTRAL)
+    }
+
+    @Test(expected = IllegalArgumentException::class)
+    fun clickBadButton() {
+        val dialog = TestableAlertDialog(context)
+
+        dialog.clickButton(10000)
+    }
+
+    @Test
+    fun clickButtonDismisses_positive() {
+        val dialog = TestableAlertDialog(context)
+
+        dialog.show()
+        dialog.clickButton(BUTTON_POSITIVE)
+
+        assertThat(dialog.isShowing).isFalse()
+    }
+
+    @Test
+    fun clickButtonDismisses_negative() {
+        val dialog = TestableAlertDialog(context)
+
+        dialog.show()
+        dialog.clickButton(BUTTON_NEGATIVE)
+
+        assertThat(dialog.isShowing).isFalse()
+    }
+
+    @Test
+    fun clickButtonDismisses_neutral() {
+        val dialog = TestableAlertDialog(context)
+
+        dialog.show()
+        dialog.clickButton(BUTTON_NEUTRAL)
+
+        assertThat(dialog.isShowing).isFalse()
+    }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogImplTest.java
index a0b4eab..c3c6975 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogImplTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogImplTest.java
@@ -45,6 +45,7 @@
 import com.android.systemui.Prefs;
 import com.android.systemui.R;
 import com.android.systemui.SysuiTestCase;
+import com.android.systemui.dump.DumpManager;
 import com.android.systemui.media.dialog.MediaOutputDialogFactory;
 import com.android.systemui.plugins.ActivityStarter;
 import com.android.systemui.plugins.VolumeDialogController;
@@ -98,6 +99,8 @@
     ActivityStarter mActivityStarter;
     @Mock
     InteractionJankMonitor mInteractionJankMonitor;
+    @Mock
+    private DumpManager mDumpManager;
 
     @Before
     public void setup() throws Exception {
@@ -119,7 +122,9 @@
                 mActivityStarter,
                 mInteractionJankMonitor,
                 mDeviceConfigProxy,
-                mExecutor);
+                mExecutor,
+                mDumpManager
+            );
         mDialog.init(0, null);
         State state = createShellState();
         mDialog.onStateChangedH(state);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/ImageWallpaperTest.java b/packages/SystemUI/tests/src/com/android/systemui/wallpapers/ImageWallpaperTest.java
index 379bb28..0fdcb95 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/ImageWallpaperTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/wallpapers/ImageWallpaperTest.java
@@ -19,15 +19,13 @@
 import static com.google.common.truth.Truth.assertThat;
 import static com.google.common.truth.Truth.assertWithMessage;
 
-import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.hamcrest.Matchers.equalTo;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyBoolean;
 import static org.mockito.Mockito.clearInvocations;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.eq;
-import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
@@ -36,19 +34,13 @@
 
 import android.app.WallpaperManager;
 import android.content.Context;
-import android.content.res.Configuration;
-import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.ColorSpace;
 import android.graphics.Rect;
 import android.hardware.display.DisplayManager;
-import android.hardware.display.DisplayManagerGlobal;
-import android.os.Handler;
 import android.os.UserHandle;
 import android.testing.AndroidTestingRunner;
 import android.testing.TestableLooper;
-import android.view.Display;
-import android.view.DisplayInfo;
 import android.view.Surface;
 import android.view.SurfaceHolder;
 import android.view.WindowManager;
@@ -57,28 +49,21 @@
 import androidx.test.filters.SmallTest;
 
 import com.android.systemui.SysuiTestCase;
-import com.android.systemui.flags.FeatureFlags;
 import com.android.systemui.util.concurrency.FakeExecutor;
 import com.android.systemui.util.time.FakeSystemClock;
-import com.android.systemui.wallpapers.gl.ImageWallpaperRenderer;
 
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
-import java.util.concurrent.CountDownLatch;
-
 @SmallTest
 @RunWith(AndroidTestingRunner.class)
 @TestableLooper.RunWithLooper
 public class ImageWallpaperTest extends SysuiTestCase {
     private static final int LOW_BMP_WIDTH = 128;
     private static final int LOW_BMP_HEIGHT = 128;
-    private static final int INVALID_BMP_WIDTH = 1;
-    private static final int INVALID_BMP_HEIGHT = 1;
     private static final int DISPLAY_WIDTH = 1920;
     private static final int DISPLAY_HEIGHT = 1080;
 
@@ -99,20 +84,9 @@
 
     @Mock
     private Bitmap mWallpaperBitmap;
-    private int mBitmapWidth = 1;
-    private int mBitmapHeight = 1;
-
-    @Mock
-    private Handler mHandler;
-    @Mock
-    private FeatureFlags mFeatureFlags;
-
     FakeSystemClock mFakeSystemClock = new FakeSystemClock();
-    FakeExecutor mFakeMainExecutor = new FakeExecutor(mFakeSystemClock);
     FakeExecutor mFakeBackgroundExecutor = new FakeExecutor(mFakeSystemClock);
 
-    private CountDownLatch mEventCountdown;
-
     @Before
     public void setUp() throws Exception {
         allowTestableLooperAsMainThread();
@@ -132,12 +106,8 @@
         // set up bitmap
         when(mWallpaperBitmap.getColorSpace()).thenReturn(ColorSpace.get(ColorSpace.Named.SRGB));
         when(mWallpaperBitmap.getConfig()).thenReturn(Bitmap.Config.ARGB_8888);
-        when(mWallpaperBitmap.getWidth()).thenReturn(mBitmapWidth);
-        when(mWallpaperBitmap.getHeight()).thenReturn(mBitmapHeight);
 
         // set up wallpaper manager
-        when(mWallpaperManager.peekBitmapDimensions())
-                .thenReturn(new Rect(0, 0, mBitmapWidth, mBitmapHeight));
         when(mWallpaperManager.getBitmapAsUser(eq(UserHandle.USER_CURRENT), anyBoolean()))
                 .thenReturn(mWallpaperBitmap);
         when(mMockContext.getSystemService(WallpaperManager.class)).thenReturn(mWallpaperManager);
@@ -145,104 +115,62 @@
         // set up surface
         when(mSurfaceHolder.getSurface()).thenReturn(mSurface);
         doNothing().when(mSurface).hwuiDestroy();
-
-        // TODO remove code below. Outdated, used in only in old GL tests (that are ignored)
-        Resources resources = mock(Resources.class);
-        when(resources.getConfiguration()).thenReturn(mock(Configuration.class));
-        when(mMockContext.getResources()).thenReturn(resources);
-        DisplayInfo displayInfo = new DisplayInfo();
-        displayInfo.logicalWidth = DISPLAY_WIDTH;
-        displayInfo.logicalHeight = DISPLAY_HEIGHT;
-        when(mMockContext.getDisplay()).thenReturn(
-                new Display(mock(DisplayManagerGlobal.class), 0, displayInfo, (Resources) null));
-    }
-
-    private void setBitmapDimensions(int bitmapWidth, int bitmapHeight) {
-        mBitmapWidth = bitmapWidth;
-        mBitmapHeight = bitmapHeight;
-    }
-
-    private ImageWallpaper createImageWallpaper() {
-        return new ImageWallpaper(mFeatureFlags, mFakeBackgroundExecutor, mFakeMainExecutor) {
-            @Override
-            public Engine onCreateEngine() {
-                return new GLEngine(mHandler) {
-                    @Override
-                    public Context getDisplayContext() {
-                        return mMockContext;
-                    }
-
-                    @Override
-                    public SurfaceHolder getSurfaceHolder() {
-                        return mSurfaceHolder;
-                    }
-
-                    @Override
-                    public void setFixedSizeAllowed(boolean allowed) {
-                        super.setFixedSizeAllowed(allowed);
-                        assertWithMessage("mFixedSizeAllowed should be true").that(
-                                allowed).isTrue();
-                        mEventCountdown.countDown();
-                    }
-                };
-            }
-        };
     }
 
     @Test
-    @Ignore
     public void testBitmapWallpaper_normal() {
         // Will use a image wallpaper with dimensions DISPLAY_WIDTH x DISPLAY_WIDTH.
         // Then we expect the surface size will be also DISPLAY_WIDTH x DISPLAY_WIDTH.
-        verifySurfaceSize(DISPLAY_WIDTH /* bmpWidth */,
-                DISPLAY_WIDTH /* bmpHeight */,
-                DISPLAY_WIDTH /* surfaceWidth */,
-                DISPLAY_WIDTH /* surfaceHeight */);
+        int bitmapSide = DISPLAY_WIDTH;
+        testSurfaceHelper(
+                bitmapSide /* bitmapWidth */,
+                bitmapSide /* bitmapHeight */,
+                bitmapSide /* expectedSurfaceWidth */,
+                bitmapSide /* expectedSurfaceHeight */);
     }
 
     @Test
-    @Ignore
     public void testBitmapWallpaper_low_resolution() {
         // Will use a image wallpaper with dimensions BMP_WIDTH x BMP_HEIGHT.
         // Then we expect the surface size will be also BMP_WIDTH x BMP_HEIGHT.
-        verifySurfaceSize(LOW_BMP_WIDTH /* bmpWidth */,
-                LOW_BMP_HEIGHT /* bmpHeight */,
-                LOW_BMP_WIDTH /* surfaceWidth */,
-                LOW_BMP_HEIGHT /* surfaceHeight */);
+        testSurfaceHelper(LOW_BMP_WIDTH /* bitmapWidth */,
+                LOW_BMP_HEIGHT /* bitmapHeight */,
+                LOW_BMP_WIDTH /* expectedSurfaceWidth */,
+                LOW_BMP_HEIGHT /* expectedSurfaceHeight */);
     }
 
     @Test
-    @Ignore
     public void testBitmapWallpaper_too_small() {
-        // Will use a image wallpaper with dimensions INVALID_BMP_WIDTH x INVALID_BMP_HEIGHT.
-        // Then we expect the surface size will be also MIN_SURFACE_WIDTH x MIN_SURFACE_HEIGHT.
-        verifySurfaceSize(INVALID_BMP_WIDTH /* bmpWidth */,
-                INVALID_BMP_HEIGHT /* bmpHeight */,
-                ImageWallpaper.GLEngine.MIN_SURFACE_WIDTH /* surfaceWidth */,
-                ImageWallpaper.GLEngine.MIN_SURFACE_HEIGHT /* surfaceHeight */);
+
+        // test that the surface is always at least MIN_SURFACE_WIDTH x MIN_SURFACE_HEIGHT
+        testMinSurfaceHelper(8, 8);
+        testMinSurfaceHelper(100, 2000);
+        testMinSurfaceHelper(200, 1);
     }
 
-    private void verifySurfaceSize(int bmpWidth, int bmpHeight,
-            int surfaceWidth, int surfaceHeight) {
-        ImageWallpaper.GLEngine wallpaperEngine =
-                (ImageWallpaper.GLEngine) createImageWallpaper().onCreateEngine();
+    @Test
+    public void testLoadDrawAndUnloadBitmap() {
+        setBitmapDimensions(LOW_BMP_WIDTH, LOW_BMP_HEIGHT);
 
-        ImageWallpaper.GLEngine engineSpy = spy(wallpaperEngine);
+        ImageWallpaper.CanvasEngine spyEngine = getSpyEngine();
+        spyEngine.onCreate(mSurfaceHolder);
+        spyEngine.onSurfaceRedrawNeeded(mSurfaceHolder);
+        assertThat(mFakeBackgroundExecutor.numPending()).isAtLeast(1);
 
-        setBitmapDimensions(bmpWidth, bmpHeight);
+        int n = 0;
+        while (mFakeBackgroundExecutor.numPending() >= 1) {
+            n++;
+            assertThat(n).isAtMost(10);
+            mFakeBackgroundExecutor.runNextReady();
+            mFakeSystemClock.advanceTime(1000);
+        }
 
-        ImageWallpaperRenderer renderer = new ImageWallpaperRenderer(mMockContext);
-        doReturn(renderer).when(engineSpy).getRendererInstance();
-        engineSpy.onCreate(engineSpy.getSurfaceHolder());
-
-        verify(mSurfaceHolder, times(1)).setFixedSize(surfaceWidth, surfaceHeight);
-        assertWithMessage("setFixedSizeAllowed should have been called.").that(
-                mEventCountdown.getCount()).isEqualTo(0);
+        verify(spyEngine, times(1)).drawFrameOnCanvas(mWallpaperBitmap);
+        assertThat(spyEngine.isBitmapLoaded()).isFalse();
     }
 
-
-    private ImageWallpaper createImageWallpaperCanvas() {
-        return new ImageWallpaper(mFeatureFlags, mFakeBackgroundExecutor, mFakeMainExecutor) {
+    private ImageWallpaper createImageWallpaper() {
+        return new ImageWallpaper(mFakeBackgroundExecutor) {
             @Override
             public Engine onCreateEngine() {
                 return new CanvasEngine() {
@@ -268,7 +196,7 @@
     }
 
     private ImageWallpaper.CanvasEngine getSpyEngine() {
-        ImageWallpaper imageWallpaper = createImageWallpaperCanvas();
+        ImageWallpaper imageWallpaper = createImageWallpaper();
         ImageWallpaper.CanvasEngine engine =
                 (ImageWallpaper.CanvasEngine) imageWallpaper.onCreateEngine();
         ImageWallpaper.CanvasEngine spyEngine = spy(engine);
@@ -281,49 +209,32 @@
         return spyEngine;
     }
 
-    @Test
-    public void testMinSurface() {
-
-        // test that the surface is always at least MIN_SURFACE_WIDTH x MIN_SURFACE_HEIGHT
-        testMinSurfaceHelper(8, 8);
-        testMinSurfaceHelper(100, 2000);
-        testMinSurfaceHelper(200, 1);
+    private void setBitmapDimensions(int bitmapWidth, int bitmapHeight) {
+        when(mWallpaperManager.peekBitmapDimensions())
+                .thenReturn(new Rect(0, 0, bitmapWidth, bitmapHeight));
+        when(mWallpaperBitmap.getWidth()).thenReturn(bitmapWidth);
+        when(mWallpaperBitmap.getHeight()).thenReturn(bitmapHeight);
     }
 
     private void testMinSurfaceHelper(int bitmapWidth, int bitmapHeight) {
+        testSurfaceHelper(bitmapWidth, bitmapHeight,
+                Math.max(ImageWallpaper.CanvasEngine.MIN_SURFACE_WIDTH, bitmapWidth),
+                Math.max(ImageWallpaper.CanvasEngine.MIN_SURFACE_HEIGHT, bitmapHeight));
+    }
+
+    private void testSurfaceHelper(int bitmapWidth, int bitmapHeight,
+            int expectedSurfaceWidth, int expectedSurfaceHeight) {
 
         clearInvocations(mSurfaceHolder);
         setBitmapDimensions(bitmapWidth, bitmapHeight);
 
-        ImageWallpaper imageWallpaper = createImageWallpaperCanvas();
+        ImageWallpaper imageWallpaper = createImageWallpaper();
         ImageWallpaper.CanvasEngine engine =
                 (ImageWallpaper.CanvasEngine) imageWallpaper.onCreateEngine();
         engine.onCreate(mSurfaceHolder);
 
         verify(mSurfaceHolder, times(1)).setFixedSize(
-                intThat(greaterThanOrEqualTo(ImageWallpaper.CanvasEngine.MIN_SURFACE_WIDTH)),
-                intThat(greaterThanOrEqualTo(ImageWallpaper.CanvasEngine.MIN_SURFACE_HEIGHT)));
-    }
-
-    @Test
-    public void testLoadDrawAndUnloadBitmap() {
-        setBitmapDimensions(LOW_BMP_WIDTH, LOW_BMP_HEIGHT);
-
-        ImageWallpaper.CanvasEngine spyEngine = getSpyEngine();
-        spyEngine.onCreate(mSurfaceHolder);
-        spyEngine.onSurfaceRedrawNeeded(mSurfaceHolder);
-        assertThat(mFakeBackgroundExecutor.numPending()).isAtLeast(1);
-
-        int n = 0;
-        while (mFakeBackgroundExecutor.numPending() + mFakeMainExecutor.numPending() >= 1) {
-            n++;
-            assertThat(n).isAtMost(10);
-            mFakeBackgroundExecutor.runNextReady();
-            mFakeMainExecutor.runNextReady();
-            mFakeSystemClock.advanceTime(1000);
-        }
-
-        verify(spyEngine, times(1)).drawFrameOnCanvas(mWallpaperBitmap);
-        assertThat(spyEngine.isBitmapLoaded()).isFalse();
+                intThat(equalTo(expectedSurfaceWidth)),
+                intThat(equalTo(expectedSurfaceHeight)));
     }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/canvas/WallpaperLocalColorExtractorTest.java b/packages/SystemUI/tests/src/com/android/systemui/wallpapers/WallpaperLocalColorExtractorTest.java
similarity index 99%
rename from packages/SystemUI/tests/src/com/android/systemui/wallpapers/canvas/WallpaperLocalColorExtractorTest.java
rename to packages/SystemUI/tests/src/com/android/systemui/wallpapers/WallpaperLocalColorExtractorTest.java
index 7e8ffeb..fc5f782 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/canvas/WallpaperLocalColorExtractorTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/wallpapers/WallpaperLocalColorExtractorTest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.systemui.wallpapers.canvas;
+package com.android.systemui.wallpapers;
 
 import static com.google.common.truth.Truth.assertThat;
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/gl/EglHelperTest.java b/packages/SystemUI/tests/src/com/android/systemui/wallpapers/gl/EglHelperTest.java
deleted file mode 100644
index a42bade..0000000
--- a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/gl/EglHelperTest.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (C) 2019 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.systemui.wallpapers.gl;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.atMost;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.graphics.PixelFormat;
-import android.testing.AndroidTestingRunner;
-import android.view.Surface;
-import android.view.SurfaceControl;
-import android.view.SurfaceHolder;
-import android.view.SurfaceSession;
-
-import androidx.test.filters.SmallTest;
-
-import com.android.systemui.SysuiTestCase;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.mockito.Spy;
-
-@SmallTest
-@RunWith(AndroidTestingRunner.class)
-@Ignore
-public class EglHelperTest extends SysuiTestCase {
-
-    @Spy
-    private EglHelper mEglHelper;
-
-    @Mock
-    private SurfaceHolder mSurfaceHolder;
-
-    @Before
-    public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
-        prepareSurface();
-    }
-
-    @After
-    public void tearDown() {
-        mSurfaceHolder.getSurface().destroy();
-        mSurfaceHolder = null;
-    }
-
-    private void prepareSurface() {
-        final SurfaceSession session = new SurfaceSession();
-        final SurfaceControl control = new SurfaceControl.Builder(session)
-                .setName("Test")
-                .setBufferSize(100, 100)
-                .setFormat(PixelFormat.RGB_888)
-                .build();
-        final Surface surface = new Surface();
-        surface.copyFrom(control);
-        when(mSurfaceHolder.getSurface()).thenReturn(surface);
-        assertThat(mSurfaceHolder.getSurface()).isNotNull();
-        assertThat(mSurfaceHolder.getSurface().isValid()).isTrue();
-    }
-
-    @Test
-    public void testInit_normal() {
-        mEglHelper.init(mSurfaceHolder, false /* wideColorGamut */);
-        assertThat(mEglHelper.hasEglDisplay()).isTrue();
-        assertThat(mEglHelper.hasEglContext()).isTrue();
-        assertThat(mEglHelper.hasEglSurface()).isTrue();
-        verify(mEglHelper).askCreatingEglWindowSurface(
-                any(SurfaceHolder.class), eq(null), anyInt());
-    }
-
-    @Test
-    public void testInit_wide_gamut() {
-        // In EglHelper, EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT = 0x3490;
-        doReturn(0x3490).when(mEglHelper).getWcgCapability();
-        // In EglHelper, KHR_GL_COLOR_SPACE = "EGL_KHR_gl_colorspace";
-        doReturn(true).when(mEglHelper).checkExtensionCapability("EGL_KHR_gl_colorspace");
-        ArgumentCaptor<int[]> ac = ArgumentCaptor.forClass(int[].class);
-        // {EGL_GL_COLORSPACE_KHR, EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT, EGL_NONE}
-        final int[] expectedArgument = new int[] {0x309D, 0x3490, 0x3038};
-
-        mEglHelper.init(mSurfaceHolder, true /* wideColorGamut */);
-        verify(mEglHelper)
-                .askCreatingEglWindowSurface(any(SurfaceHolder.class), ac.capture(), anyInt());
-        assertThat(ac.getValue()).isNotNull();
-        assertThat(ac.getValue()).isEqualTo(expectedArgument);
-    }
-
-    @Test
-    @Ignore
-    public void testFinish_shouldNotCrash() {
-        mEglHelper.terminateEglDisplay();
-        assertThat(mEglHelper.hasEglDisplay()).isFalse();
-        assertThat(mEglHelper.hasEglSurface()).isFalse();
-        assertThat(mEglHelper.hasEglContext()).isFalse();
-
-        mEglHelper.finish();
-        verify(mEglHelper, never()).destroyEglContext();
-        verify(mEglHelper, never()).destroyEglSurface();
-        verify(mEglHelper, atMost(1)).terminateEglDisplay();
-    }
-}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/gl/ImageWallpaperRendererTest.java b/packages/SystemUI/tests/src/com/android/systemui/wallpapers/gl/ImageWallpaperRendererTest.java
deleted file mode 100644
index 89b2222..0000000
--- a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/gl/ImageWallpaperRendererTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (C) 2020 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.systemui.wallpapers.gl;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.spy;
-
-import android.app.WallpaperManager;
-import android.app.WallpaperManager.ColorManagementProxy;
-import android.graphics.Bitmap;
-import android.graphics.ColorSpace;
-import android.testing.AndroidTestingRunner;
-import android.testing.TestableLooper;
-
-import androidx.test.filters.SmallTest;
-
-import com.android.systemui.SysuiTestCase;
-
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.Set;
-
-@SmallTest
-@RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper(setAsMainLooper = true)
-@Ignore
-public class ImageWallpaperRendererTest extends SysuiTestCase {
-
-    private WallpaperManager mWpmSpy;
-
-    @Before
-    public void setUp() throws Exception {
-        final WallpaperManager wpm = mContext.getSystemService(WallpaperManager.class);
-        mWpmSpy = spy(wpm);
-        mContext.addMockSystemService(WallpaperManager.class, mWpmSpy);
-    }
-
-    @Test
-    public void testWcgContent() throws IOException {
-        final Bitmap srgbBitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
-        final Bitmap p3Bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888,
-                false /* hasAlpha */, ColorSpace.get(ColorSpace.Named.DISPLAY_P3));
-
-        final ColorManagementProxy proxy = new ColorManagementProxy(mContext);
-        final ColorManagementProxy cmProxySpy = spy(proxy);
-        final Set<ColorSpace> supportedWideGamuts = new HashSet<>();
-        supportedWideGamuts.add(ColorSpace.get(ColorSpace.Named.DISPLAY_P3));
-
-        try {
-            doReturn(true).when(mWpmSpy).shouldEnableWideColorGamut();
-            doReturn(cmProxySpy).when(mWpmSpy).getColorManagementProxy();
-            doReturn(supportedWideGamuts).when(cmProxySpy).getSupportedColorSpaces();
-
-            mWpmSpy.setBitmap(p3Bitmap);
-            ImageWallpaperRenderer rendererP3 = new ImageWallpaperRenderer(mContext);
-            rendererP3.reportSurfaceSize();
-            assertThat(rendererP3.isWcgContent()).isTrue();
-
-            mWpmSpy.setBitmap(srgbBitmap);
-            ImageWallpaperRenderer renderer = new ImageWallpaperRenderer(mContext);
-            assertThat(renderer.isWcgContent()).isFalse();
-        } finally {
-            srgbBitmap.recycle();
-            p3Bitmap.recycle();
-        }
-    }
-
-}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/qs/FakeFgsManagerController.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/qs/FakeFgsManagerController.kt
index b31f119..ced7955 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/qs/FakeFgsManagerController.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/qs/FakeFgsManagerController.kt
@@ -77,7 +77,5 @@
         dialogDismissedListeners.remove(listener)
     }
 
-    override fun shouldUpdateFooterVisibility(): Boolean = false
-
     override fun visibleButtonsCount(): Int = 0
 }
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/FakeSecurityController.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/FakeSecurityController.kt
index c6aa395..021e7df 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/FakeSecurityController.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/FakeSecurityController.kt
@@ -67,6 +67,8 @@
 
     override fun getDeviceOwnerType(admin: ComponentName?): Int = 0
 
+    override fun isFinancedDevice(): Boolean = false
+
     override fun isNetworkLoggingEnabled(): Boolean = fakeState.isNetworkLoggingEnabled
 
     override fun isVpnEnabled(): Boolean = fakeState.isVpnEnabled
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/util/TestableAlertDialog.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/util/TestableAlertDialog.kt
new file mode 100644
index 0000000..4d79554
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/util/TestableAlertDialog.kt
@@ -0,0 +1,141 @@
+/*
+ * 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.systemui.util
+
+import android.app.AlertDialog
+import android.content.Context
+import android.content.DialogInterface
+import java.lang.IllegalArgumentException
+
+/**
+ * [AlertDialog] that is easier to test. Due to [AlertDialog] being a class and not an interface,
+ * there are some things that cannot be avoided, like the creation of a [Handler] on the main thread
+ * (and therefore needing a prepared [Looper] in the test).
+ *
+ * It bypasses calls to show, clicks on buttons, cancel and dismiss so it all can happen bounded in
+ * the test. It tries to be as close in behavior as a real [AlertDialog].
+ *
+ * It will only call [onCreate] as part of its lifecycle, but not any of the other lifecycle methods
+ * in [Dialog].
+ *
+ * In order to test clicking on buttons, use [clickButton] instead of calling [View.callOnClick] on
+ * the view returned by [getButton] to bypass the internal [Handler].
+ */
+class TestableAlertDialog(context: Context) : AlertDialog(context) {
+
+    private var _onDismissListener: DialogInterface.OnDismissListener? = null
+    private var _onCancelListener: DialogInterface.OnCancelListener? = null
+    private var _positiveButtonClickListener: DialogInterface.OnClickListener? = null
+    private var _negativeButtonClickListener: DialogInterface.OnClickListener? = null
+    private var _neutralButtonClickListener: DialogInterface.OnClickListener? = null
+    private var _onShowListener: DialogInterface.OnShowListener? = null
+    private var _dismissOverride: Runnable? = null
+
+    private var showing = false
+    private var visible = false
+    private var created = false
+
+    override fun show() {
+        if (!created) {
+            created = true
+            onCreate(null)
+        }
+        if (isShowing) return
+        showing = true
+        visible = true
+        _onShowListener?.onShow(this)
+    }
+
+    override fun hide() {
+        visible = false
+    }
+
+    override fun isShowing(): Boolean {
+        return visible && showing
+    }
+
+    override fun dismiss() {
+        if (!showing) {
+            return
+        }
+        if (_dismissOverride != null) {
+            _dismissOverride?.run()
+            return
+        }
+        _onDismissListener?.onDismiss(this)
+        showing = false
+    }
+
+    override fun cancel() {
+        _onCancelListener?.onCancel(this)
+        dismiss()
+    }
+
+    override fun setOnDismissListener(listener: DialogInterface.OnDismissListener?) {
+        _onDismissListener = listener
+    }
+
+    override fun setOnCancelListener(listener: DialogInterface.OnCancelListener?) {
+        _onCancelListener = listener
+    }
+
+    override fun setOnShowListener(listener: DialogInterface.OnShowListener?) {
+        _onShowListener = listener
+    }
+
+    override fun takeCancelAndDismissListeners(
+        msg: String?,
+        cancel: DialogInterface.OnCancelListener?,
+        dismiss: DialogInterface.OnDismissListener?
+    ): Boolean {
+        _onCancelListener = cancel
+        _onDismissListener = dismiss
+        return true
+    }
+
+    override fun setButton(
+        whichButton: Int,
+        text: CharSequence?,
+        listener: DialogInterface.OnClickListener?
+    ) {
+        super.setButton(whichButton, text, listener)
+        when (whichButton) {
+            DialogInterface.BUTTON_POSITIVE -> _positiveButtonClickListener = listener
+            DialogInterface.BUTTON_NEGATIVE -> _negativeButtonClickListener = listener
+            DialogInterface.BUTTON_NEUTRAL -> _neutralButtonClickListener = listener
+            else -> Unit
+        }
+    }
+
+    /**
+     * Click one of the buttons in the [AlertDialog] and call the corresponding listener.
+     *
+     * Button ids are from [DialogInterface].
+     */
+    fun clickButton(whichButton: Int) {
+        val listener =
+            when (whichButton) {
+                DialogInterface.BUTTON_POSITIVE -> _positiveButtonClickListener
+                DialogInterface.BUTTON_NEGATIVE -> _negativeButtonClickListener
+                DialogInterface.BUTTON_NEUTRAL -> _neutralButtonClickListener
+                else -> throw IllegalArgumentException("Wrong button $whichButton")
+            }
+        listener?.onClick(this, whichButton)
+        dismiss()
+    }
+}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/utils/leaks/FakeSecurityController.java b/packages/SystemUI/tests/utils/src/com/android/systemui/utils/leaks/FakeSecurityController.java
index d5348dc..76199e3 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/utils/leaks/FakeSecurityController.java
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/utils/leaks/FakeSecurityController.java
@@ -84,6 +84,11 @@
     }
 
     @Override
+    public boolean isFinancedDevice() {
+        return false;
+    }
+
+    @Override
     public boolean isNetworkLoggingEnabled() {
         return false;
     }
diff --git a/packages/SystemUI/unfold/Android.bp b/packages/SystemUI/unfold/Android.bp
index 108295b..180b611 100644
--- a/packages/SystemUI/unfold/Android.bp
+++ b/packages/SystemUI/unfold/Android.bp
@@ -33,6 +33,7 @@
         "dagger2",
         "jsr330",
     ],
+    kotlincflags: ["-Xjvm-default=enable"],
     java_version: "1.8",
     min_sdk_version: "current",
     plugins: ["dagger2-compiler"],
diff --git a/packages/SystemUI/unfold/src/com/android/systemui/unfold/UnfoldTransitionProgressProvider.kt b/packages/SystemUI/unfold/src/com/android/systemui/unfold/UnfoldTransitionProgressProvider.kt
index 7117aaf..fee485d 100644
--- a/packages/SystemUI/unfold/src/com/android/systemui/unfold/UnfoldTransitionProgressProvider.kt
+++ b/packages/SystemUI/unfold/src/com/android/systemui/unfold/UnfoldTransitionProgressProvider.kt
@@ -34,8 +34,28 @@
     fun destroy()
 
     interface TransitionProgressListener {
+        /** Called when transition is started */
+        @JvmDefault
         fun onTransitionStarted() {}
-        fun onTransitionFinished() {}
+
+        /**
+         * Called whenever transition progress is updated, [progress] is a value of the animation
+         * where 0 is fully folded, 1 is fully unfolded
+         */
+        @JvmDefault
         fun onTransitionProgress(@FloatRange(from = 0.0, to = 1.0) progress: Float) {}
+
+        /**
+         * Called when the progress provider determined that the transition is about to finish soon.
+         *
+         * For example, in [PhysicsBasedUnfoldTransitionProgressProvider] this could happen when the
+         * animation is not tied to the hinge angle anymore and it is about to run fixed animation.
+         */
+        @JvmDefault
+        fun onTransitionFinishing() {}
+
+        /** Called when transition is completely finished */
+        @JvmDefault
+        fun onTransitionFinished() {}
     }
 }
diff --git a/packages/SystemUI/unfold/src/com/android/systemui/unfold/progress/FixedTimingTransitionProgressProvider.kt b/packages/SystemUI/unfold/src/com/android/systemui/unfold/progress/FixedTimingTransitionProgressProvider.kt
index 4c85b05..fa59cb4 100644
--- a/packages/SystemUI/unfold/src/com/android/systemui/unfold/progress/FixedTimingTransitionProgressProvider.kt
+++ b/packages/SystemUI/unfold/src/com/android/systemui/unfold/progress/FixedTimingTransitionProgressProvider.kt
@@ -88,6 +88,7 @@
 
         override fun onAnimationStart(animator: Animator) {
             listeners.forEach { it.onTransitionStarted() }
+            listeners.forEach { it.onTransitionFinishing() }
         }
 
         override fun onAnimationEnd(animator: Animator) {
diff --git a/packages/SystemUI/unfold/src/com/android/systemui/unfold/progress/PhysicsBasedUnfoldTransitionProgressProvider.kt b/packages/SystemUI/unfold/src/com/android/systemui/unfold/progress/PhysicsBasedUnfoldTransitionProgressProvider.kt
index b568186..ecc029d 100644
--- a/packages/SystemUI/unfold/src/com/android/systemui/unfold/progress/PhysicsBasedUnfoldTransitionProgressProvider.kt
+++ b/packages/SystemUI/unfold/src/com/android/systemui/unfold/progress/PhysicsBasedUnfoldTransitionProgressProvider.kt
@@ -31,6 +31,7 @@
 import com.android.systemui.unfold.updates.FoldStateProvider
 import com.android.systemui.unfold.updates.FoldStateProvider.FoldUpdate
 import com.android.systemui.unfold.updates.FoldStateProvider.FoldUpdatesListener
+import com.android.systemui.unfold.updates.name
 
 /** Maps fold updates to unfold transition progress using DynamicAnimation. */
 class PhysicsBasedUnfoldTransitionProgressProvider(
@@ -117,13 +118,17 @@
         }
 
         if (DEBUG) {
-            Log.d(TAG, "onFoldUpdate = $update")
+            Log.d(TAG, "onFoldUpdate = ${update.name()}")
             Trace.traceCounter(Trace.TRACE_TAG_APP, "fold_update", update)
         }
     }
 
     private fun cancelTransition(endValue: Float, animate: Boolean) {
         if (isTransitionRunning && animate) {
+            if (endValue == 1.0f && !isAnimatedCancelRunning) {
+                listeners.forEach { it.onTransitionFinishing() }
+            }
+
             isAnimatedCancelRunning = true
             springAnimation.animateToFinalPosition(endValue)
         } else {
diff --git a/packages/SystemUI/unfold/src/com/android/systemui/unfold/util/ScopedUnfoldTransitionProgressProvider.kt b/packages/SystemUI/unfold/src/com/android/systemui/unfold/util/ScopedUnfoldTransitionProgressProvider.kt
index 8491f83..b7bab3e 100644
--- a/packages/SystemUI/unfold/src/com/android/systemui/unfold/util/ScopedUnfoldTransitionProgressProvider.kt
+++ b/packages/SystemUI/unfold/src/com/android/systemui/unfold/util/ScopedUnfoldTransitionProgressProvider.kt
@@ -110,6 +110,12 @@
         lastTransitionProgress = progress
     }
 
+    override fun onTransitionFinishing() {
+        if (isReadyToHandleTransition) {
+            listeners.forEach { it.onTransitionFinishing() }
+        }
+    }
+
     override fun onTransitionFinished() {
         if (isReadyToHandleTransition) {
             listeners.forEach { it.onTransitionFinished() }
diff --git a/packages/services/CameraExtensionsProxy/src/com/android/cameraextensions/CameraExtensionsProxyService.java b/packages/services/CameraExtensionsProxy/src/com/android/cameraextensions/CameraExtensionsProxyService.java
index 2ad2119..dd9f1d8 100644
--- a/packages/services/CameraExtensionsProxy/src/com/android/cameraextensions/CameraExtensionsProxyService.java
+++ b/packages/services/CameraExtensionsProxy/src/com/android/cameraextensions/CameraExtensionsProxyService.java
@@ -48,6 +48,7 @@
 import android.hardware.camera2.extension.IRequestProcessorImpl;
 import android.hardware.camera2.extension.IRequestUpdateProcessorImpl;
 import android.hardware.camera2.extension.ISessionProcessorImpl;
+import android.hardware.camera2.extension.LatencyPair;
 import android.hardware.camera2.extension.LatencyRange;
 import android.hardware.camera2.extension.OutputConfigId;
 import android.hardware.camera2.extension.OutputSurface;
@@ -1266,6 +1267,21 @@
         public int startCapture(ICaptureCallback callback) {
             return mSessionProcessor.startCapture(new CaptureCallbackStub(callback, mCameraId));
         }
+
+        @Override
+        public LatencyPair getRealtimeCaptureLatency() {
+            if (LATENCY_IMPROVEMENTS_SUPPORTED) {
+                Pair<Long, Long> latency = mSessionProcessor.getRealtimeCaptureLatency();
+                if (latency != null) {
+                    LatencyPair ret = new LatencyPair();
+                    ret.first = latency.first;
+                    ret.second = latency.second;
+                    return ret;
+                }
+            }
+
+            return null;
+        }
     }
 
     private class OutputSurfaceConfigurationImplStub implements OutputSurfaceConfigurationImpl {
@@ -1578,6 +1594,21 @@
         }
 
         @Override
+        public LatencyPair getRealtimeCaptureLatency() {
+            if (LATENCY_IMPROVEMENTS_SUPPORTED) {
+                Pair<Long, Long> latency = mImageExtender.getRealtimeCaptureLatency();
+                if (latency != null) {
+                    LatencyPair ret = new LatencyPair();
+                    ret.first = latency.first;
+                    ret.second = latency.second;
+                    return ret;
+                }
+            }
+
+            return null;
+        }
+
+        @Override
         public CameraMetadataNative getAvailableCaptureRequestKeys() {
             if (RESULT_API_SUPPORTED) {
                 List<CaptureRequest.Key> supportedCaptureKeys =
diff --git a/services/Android.bp b/services/Android.bp
index f6570e9..3f3ba06 100644
--- a/services/Android.bp
+++ b/services/Android.bp
@@ -187,6 +187,7 @@
         "framework-tethering.stubs.module_lib",
         "service-art.stubs.system_server",
         "service-permission.stubs.system_server",
+        "service-rkp.stubs.system_server",
         "service-sdksandbox.stubs.system_server",
     ],
 
diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
index 3145139..59c1c54 100644
--- a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
+++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
@@ -26,8 +26,11 @@
 import static android.accessibilityservice.AccessibilityTrace.FLAGS_WINDOW_MAGNIFICATION_CONNECTION;
 import static android.accessibilityservice.AccessibilityTrace.FLAGS_WINDOW_MANAGER_INTERNAL;
 import static android.provider.Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED;
+import static android.provider.Settings.Secure.CONTRAST_LEVEL;
 import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_BUTTON;
 import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_SHORTCUT_KEY;
+import static android.view.accessibility.AccessibilityManager.CONTRAST_DEFAULT_VALUE;
+import static android.view.accessibility.AccessibilityManager.CONTRAST_NOT_SET;
 import static android.view.accessibility.AccessibilityManager.ShortcutType;
 
 import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_COMPONENT_NAME;
@@ -1018,10 +1021,13 @@
     }
 
     private void dispatchAccessibilityEventLocked(AccessibilityEvent event) {
-        notifyAccessibilityServicesDelayedLocked(event, false);
-        notifyAccessibilityServicesDelayedLocked(event, true);
+        if (mProxyManager.isProxyed(event.getDisplayId())) {
+            mProxyManager.sendAccessibilityEventLocked(event);
+        } else {
+            notifyAccessibilityServicesDelayedLocked(event, false);
+            notifyAccessibilityServicesDelayedLocked(event, true);
+        }
         mUiAutomationManager.sendAccessibilityEventLocked(event);
-        mProxyManager.sendAccessibilityEvent(event);
     }
 
     private void sendAccessibilityEventToInputFilter(AccessibilityEvent event) {
@@ -1162,7 +1168,7 @@
             }
             List<AccessibilityServiceConnection> services =
                     getUserStateLocked(resolvedUserId).mBoundServices;
-            int numServices = services.size() + mProxyManager.getNumProxys();
+            int numServices = services.size() + mProxyManager.getNumProxysLocked();
             interfacesToInterrupt = new ArrayList<>(numServices);
             for (int i = 0; i < services.size(); i++) {
                 AccessibilityServiceConnection service = services.get(i);
@@ -1172,7 +1178,7 @@
                     interfacesToInterrupt.add(a11yServiceInterface);
                 }
             }
-            mProxyManager.addServiceInterfaces(interfacesToInterrupt);
+            mProxyManager.addServiceInterfacesLocked(interfacesToInterrupt);
         }
         for (int i = 0, count = interfacesToInterrupt.size(); i < count; i++) {
             try {
@@ -1899,6 +1905,16 @@
         return false;
     }
 
+    private boolean readUiContrastLocked(AccessibilityUserState userState) {
+        float contrast = Settings.Secure.getFloatForUser(mContext.getContentResolver(),
+                CONTRAST_LEVEL, CONTRAST_DEFAULT_VALUE, userState.mUserId);
+        if (Math.abs(userState.getUiContrastLocked() - contrast) >= 1e-10) {
+            userState.setUiContrastLocked(contrast);
+            return true;
+        }
+        return false;
+    }
+
     /**
      * Performs {@link AccessibilityService}s delayed notification. The delay is configurable
      * and denotes the period after the last event before notifying the service.
@@ -1963,7 +1979,7 @@
                 mUiAutomationManager.getServiceInfo(), client)
                 ? mUiAutomationManager.getRelevantEventTypes()
                 : 0;
-        relevantEventTypes |= mProxyManager.getRelevantEventTypes();
+        relevantEventTypes |= mProxyManager.getRelevantEventTypesLocked();
         return relevantEventTypes;
     }
 
@@ -2565,6 +2581,7 @@
         somethingChanged |= readMagnificationModeForDefaultDisplayLocked(userState);
         somethingChanged |= readMagnificationCapabilitiesLocked(userState);
         somethingChanged |= readMagnificationFollowTypingLocked(userState);
+        somethingChanged |= readUiContrastLocked(userState);
         return somethingChanged;
     }
 
@@ -3706,6 +3723,19 @@
         return mProxyManager.unregisterProxy(displayId);
     }
 
+    @Override public float getUiContrast() {
+        if (mTraceManager.isA11yTracingEnabledForTypes(FLAGS_ACCESSIBILITY_MANAGER)) {
+            mTraceManager.logTrace(LOG_TAG + ".getUiContrast", FLAGS_ACCESSIBILITY_MANAGER);
+        }
+        synchronized (mLock) {
+            AccessibilityUserState userState = getCurrentUserStateLocked();
+            float contrast = userState.getUiContrastLocked();
+            if (contrast != CONTRAST_NOT_SET) return contrast;
+            readUiContrastLocked(userState);
+            return userState.getUiContrastLocked();
+        }
+    }
+
     @Override
     public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
         if (!DumpUtils.checkDumpPermission(mContext, LOG_TAG, pw)) return;
@@ -4153,6 +4183,9 @@
         private final Uri mMagnificationFollowTypingUri = Settings.Secure.getUriFor(
                 Settings.Secure.ACCESSIBILITY_MAGNIFICATION_FOLLOW_TYPING_ENABLED);
 
+        private final Uri mUiContrastUri = Settings.Secure.getUriFor(
+                CONTRAST_LEVEL);
+
         public AccessibilityContentObserver(Handler handler) {
             super(handler);
         }
@@ -4193,6 +4226,8 @@
                     mMagnificationCapabilityUri, false, this, UserHandle.USER_ALL);
             contentResolver.registerContentObserver(
                     mMagnificationFollowTypingUri, false, this, UserHandle.USER_ALL);
+            contentResolver.registerContentObserver(
+                    mUiContrastUri, false, this, UserHandle.USER_ALL);
         }
 
         @Override
@@ -4262,6 +4297,10 @@
                     }
                 } else if (mMagnificationFollowTypingUri.equals(uri)) {
                     readMagnificationFollowTypingLocked(userState);
+                } else if (mUiContrastUri.equals(uri)) {
+                    if (readUiContrastLocked(userState)) {
+                        updateUiContrastLocked(userState);
+                    }
                 }
             }
         }
@@ -4551,7 +4590,22 @@
                         userState.getFocusColorLocked());
             }));
         });
+    }
 
+    private void updateUiContrastLocked(AccessibilityUserState userState) {
+        if (userState.mUserId != mCurrentUserId) {
+            return;
+        }
+        if (mTraceManager.isA11yTracingEnabledForTypes(FLAGS_ACCESSIBILITY_SERVICE_CLIENT)) {
+            mTraceManager.logTrace(LOG_TAG + ".updateUiContrastLocked",
+                    FLAGS_ACCESSIBILITY_SERVICE_CLIENT, "userState=" + userState);
+        }
+        float contrast = userState.getUiContrastLocked();
+        mMainHandler.post(() -> {
+            broadcastToClients(userState, ignoreRemoteException(client -> {
+                client.mCallback.setUiContrast(contrast);
+            }));
+        });
     }
 
     public AccessibilityTraceManager getTraceManager() {
diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityUserState.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityUserState.java
index 0db169f..43730fc 100644
--- a/services/accessibility/java/com/android/server/accessibility/AccessibilityUserState.java
+++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityUserState.java
@@ -26,6 +26,8 @@
 import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_NONE;
 import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_BUTTON;
 import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_SHORTCUT_KEY;
+import static android.view.accessibility.AccessibilityManager.CONTRAST_DEFAULT_VALUE;
+import static android.view.accessibility.AccessibilityManager.CONTRAST_NOT_SET;
 import static android.view.accessibility.AccessibilityManager.ShortcutType;
 
 import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_CONTROLLER_NAME;
@@ -143,6 +145,8 @@
     private final int mFocusStrokeWidthDefaultValue;
     // The default value of the focus color.
     private final int mFocusColorDefaultValue;
+    /** The color contrast in [-1, 1] */
+    private float mUiContrast = CONTRAST_DEFAULT_VALUE;
 
     private Context mContext;
 
@@ -217,6 +221,7 @@
         mFocusStrokeWidth = mFocusStrokeWidthDefaultValue;
         mFocusColor = mFocusColorDefaultValue;
         mMagnificationFollowTypingEnabled = true;
+        mUiContrast = CONTRAST_NOT_SET;
     }
 
     void addServiceLocked(AccessibilityServiceConnection serviceConnection) {
@@ -983,6 +988,7 @@
         return mFocusColor;
     }
 
+
     /**
      * Sets the stroke width and color of the focus rectangle.
      *
@@ -1008,4 +1014,20 @@
         }
         return false;
     }
+
+    /**
+     * Get the color contrast
+     * @return color contrast in [-1, 1]
+     */
+    public float getUiContrastLocked() {
+        return mUiContrast;
+    }
+
+    /**
+     * Set the color contrast
+     * @param contrast the new color contrast in [-1, 1]
+     */
+    public void setUiContrastLocked(float contrast) {
+        mUiContrast = contrast;
+    }
 }
diff --git a/services/accessibility/java/com/android/server/accessibility/ProxyManager.java b/services/accessibility/java/com/android/server/accessibility/ProxyManager.java
index 2184878..f28191f 100644
--- a/services/accessibility/java/com/android/server/accessibility/ProxyManager.java
+++ b/services/accessibility/java/com/android/server/accessibility/ProxyManager.java
@@ -37,6 +37,7 @@
  * proxy connection will belong to a separate user state.
  *
  * TODO(241117292): Remove or cut down during simultaneous user refactoring.
+ * TODO(262244375): Add unit tests.
  */
 public class ProxyManager {
     // Names used to populate ComponentName and ResolveInfo in connection.mA11yServiceInfo and in
@@ -84,7 +85,9 @@
                         windowManagerInternal,
                         awm, displayId);
 
-        mProxyA11yServiceConnections.put(displayId, connection);
+        synchronized (mLock) {
+            mProxyA11yServiceConnections.put(displayId, connection);
+        }
 
         // If the client dies, make sure to remove the connection.
         IBinder.DeathRecipient deathRecipient =
@@ -98,7 +101,9 @@
         client.asBinder().linkToDeath(deathRecipient, 0);
         // Notify apps that the service state has changed.
         // A11yManager#A11yServicesStateChangeListener
-        connection.mSystemSupport.onClientChangeLocked(true);
+        synchronized (mLock) {
+            connection.mSystemSupport.onClientChangeLocked(true);
+        }
 
         connection.initializeServiceInterface(client);
     }
@@ -111,9 +116,11 @@
     }
 
     private boolean clearConnection(int displayId) {
-        if (mProxyA11yServiceConnections.contains(displayId)) {
-            mProxyA11yServiceConnections.remove(displayId);
-            return true;
+        synchronized (mLock) {
+            if (mProxyA11yServiceConnections.contains(displayId)) {
+                mProxyA11yServiceConnections.remove(displayId);
+                return true;
+            }
         }
         return false;
     }
@@ -122,7 +129,9 @@
      * Checks if a display id is being proxy-ed.
      */
     public boolean isProxyed(int displayId) {
-        return mProxyA11yServiceConnections.contains(displayId);
+        synchronized (mLock) {
+            return mProxyA11yServiceConnections.contains(displayId);
+        }
     }
 
     /**
@@ -130,10 +139,10 @@
      * {@link android.view.accessibility.AccessibilityDisplayProxy} will filter based on display.
      * TODO(b/250929565): Filtering should happen in the system, not in the proxy.
      */
-    public void sendAccessibilityEvent(AccessibilityEvent event) {
-        for (int i = 0; i < mProxyA11yServiceConnections.size(); i++) {
-            ProxyAccessibilityServiceConnection proxy =
-                    mProxyA11yServiceConnections.valueAt(i);
+    public void sendAccessibilityEventLocked(AccessibilityEvent event) {
+        final ProxyAccessibilityServiceConnection proxy =
+                mProxyA11yServiceConnections.get(event.getDisplayId());
+        if (proxy != null) {
             proxy.notifyAccessibilityEvent(event);
         }
     }
@@ -187,7 +196,7 @@
      * Returns the relevant event types of every proxy.
      * TODO(254545943): When A11yManager is separated, return based on the A11yManager display.
      */
-    public int getRelevantEventTypes() {
+    public int getRelevantEventTypesLocked() {
         int relevantEventTypes = 0;
         for (int i = 0; i < mProxyA11yServiceConnections.size(); i++) {
             ProxyAccessibilityServiceConnection proxy =
@@ -201,7 +210,7 @@
      * Gets the number of current proxy connections.
      * @return
      */
-    public int getNumProxys() {
+    public int getNumProxysLocked() {
         return mProxyA11yServiceConnections.size();
     }
 
@@ -209,7 +218,7 @@
      * Adds the service interfaces to a list.
      * @param interfaces
      */
-    public void addServiceInterfaces(List<IAccessibilityServiceClient> interfaces) {
+    public void addServiceInterfacesLocked(List<IAccessibilityServiceClient> interfaces) {
         for (int i = 0; i < mProxyA11yServiceConnections.size(); i++) {
             final ProxyAccessibilityServiceConnection proxy =
                     mProxyA11yServiceConnections.valueAt(i);
diff --git a/services/api/current.txt b/services/api/current.txt
index 18b1df3..da5b1fc 100644
--- a/services/api/current.txt
+++ b/services/api/current.txt
@@ -57,7 +57,6 @@
 
   public static interface PackageManagerLocal.FilteredSnapshot extends java.lang.AutoCloseable {
     method public void close();
-    method public void forAllPackageStates(@NonNull java.util.function.Consumer<com.android.server.pm.pkg.PackageState>);
     method @Nullable public com.android.server.pm.pkg.PackageState getPackageState(@NonNull String);
     method @NonNull public java.util.Map<java.lang.String,com.android.server.pm.pkg.PackageState> getPackageStates();
   }
@@ -130,13 +129,6 @@
 
 }
 
-package com.android.server.pm.snapshot {
-
-  public interface PackageDataSnapshot {
-  }
-
-}
-
 package com.android.server.role {
 
   public interface RoleServicePlatformHelper {
diff --git a/services/companion/java/com/android/server/companion/MetricUtils.java b/services/companion/java/com/android/server/companion/MetricUtils.java
index 09238d8..cf867b6 100644
--- a/services/companion/java/com/android/server/companion/MetricUtils.java
+++ b/services/companion/java/com/android/server/companion/MetricUtils.java
@@ -19,6 +19,8 @@
 import static android.companion.AssociationRequest.DEVICE_PROFILE_APP_STREAMING;
 import static android.companion.AssociationRequest.DEVICE_PROFILE_AUTOMOTIVE_PROJECTION;
 import static android.companion.AssociationRequest.DEVICE_PROFILE_COMPUTER;
+import static android.companion.AssociationRequest.DEVICE_PROFILE_GLASSES;
+import static android.companion.AssociationRequest.DEVICE_PROFILE_NEARBY_DEVICE_STREAMING;
 import static android.companion.AssociationRequest.DEVICE_PROFILE_WATCH;
 
 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION;
@@ -27,6 +29,8 @@
 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_APP_STREAMING;
 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_AUTO_PROJECTION;
 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_COMPUTER;
+import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_GLASSES;
+import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_NEARBY_DEVICE_STREAMING;
 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_NULL;
 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_WATCH;
 import static com.android.internal.util.FrameworkStatsLog.write;
@@ -59,6 +63,14 @@
                 DEVICE_PROFILE_COMPUTER,
                 CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_COMPUTER
         );
+        map.put(
+                DEVICE_PROFILE_GLASSES,
+                CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_GLASSES
+        );
+        map.put(
+                DEVICE_PROFILE_NEARBY_DEVICE_STREAMING,
+                CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_NEARBY_DEVICE_STREAMING
+        );
 
         METRIC_DEVICE_PROFILE = unmodifiableMap(map);
     }
diff --git a/services/companion/java/com/android/server/companion/PermissionsUtils.java b/services/companion/java/com/android/server/companion/PermissionsUtils.java
index a41ac03..0ff3fb7 100644
--- a/services/companion/java/com/android/server/companion/PermissionsUtils.java
+++ b/services/companion/java/com/android/server/companion/PermissionsUtils.java
@@ -23,6 +23,8 @@
 import static android.companion.AssociationRequest.DEVICE_PROFILE_APP_STREAMING;
 import static android.companion.AssociationRequest.DEVICE_PROFILE_AUTOMOTIVE_PROJECTION;
 import static android.companion.AssociationRequest.DEVICE_PROFILE_COMPUTER;
+import static android.companion.AssociationRequest.DEVICE_PROFILE_GLASSES;
+import static android.companion.AssociationRequest.DEVICE_PROFILE_NEARBY_DEVICE_STREAMING;
 import static android.companion.AssociationRequest.DEVICE_PROFILE_WATCH;
 import static android.content.pm.PackageManager.PERMISSION_GRANTED;
 import static android.os.Binder.getCallingPid;
@@ -65,6 +67,9 @@
         map.put(DEVICE_PROFILE_AUTOMOTIVE_PROJECTION,
                 Manifest.permission.REQUEST_COMPANION_PROFILE_AUTOMOTIVE_PROJECTION);
         map.put(DEVICE_PROFILE_COMPUTER, Manifest.permission.REQUEST_COMPANION_PROFILE_COMPUTER);
+        map.put(DEVICE_PROFILE_GLASSES, Manifest.permission.REQUEST_COMPANION_PROFILE_GLASSES);
+        map.put(DEVICE_PROFILE_NEARBY_DEVICE_STREAMING,
+                Manifest.permission.REQUEST_COMPANION_PROFILE_NEARBY_DEVICE_STREAMING);
 
         DEVICE_PROFILE_TO_PERMISSION = unmodifiableMap(map);
     }
diff --git a/services/companion/java/com/android/server/companion/virtual/InputController.java b/services/companion/java/com/android/server/companion/virtual/InputController.java
index 96c71e5..97b5d6d 100644
--- a/services/companion/java/com/android/server/companion/virtual/InputController.java
+++ b/services/companion/java/com/android/server/companion/virtual/InputController.java
@@ -61,15 +61,19 @@
 
     private static final AtomicLong sNextPhysId = new AtomicLong(1);
 
+    static final String NAVIGATION_TOUCHPAD_DEVICE_TYPE = "touchNavigation";
+
     static final String PHYS_TYPE_DPAD = "Dpad";
     static final String PHYS_TYPE_KEYBOARD = "Keyboard";
     static final String PHYS_TYPE_MOUSE = "Mouse";
     static final String PHYS_TYPE_TOUCHSCREEN = "Touchscreen";
+    static final String PHYS_TYPE_NAVIGATION_TOUCHPAD = "NavigationTouchpad";
     @StringDef(prefix = { "PHYS_TYPE_" }, value = {
             PHYS_TYPE_DPAD,
             PHYS_TYPE_KEYBOARD,
             PHYS_TYPE_MOUSE,
             PHYS_TYPE_TOUCHSCREEN,
+            PHYS_TYPE_NAVIGATION_TOUCHPAD,
     })
     @Retention(RetentionPolicy.SOURCE)
     @interface PhysType {
@@ -78,9 +82,8 @@
     final Object mLock;
 
     /* Token -> file descriptor associations. */
-    @VisibleForTesting
     @GuardedBy("mLock")
-    final Map<IBinder, InputDeviceDescriptor> mInputDeviceDescriptors = new ArrayMap<>();
+    private final Map<IBinder, InputDeviceDescriptor> mInputDeviceDescriptors = new ArrayMap<>();
 
     private final Handler mHandler;
     private final NativeWrapper mNativeWrapper;
@@ -191,6 +194,28 @@
         }
     }
 
+    void createNavigationTouchpad(
+            @NonNull String deviceName,
+            int vendorId,
+            int productId,
+            @NonNull IBinder deviceToken,
+            int displayId,
+            int touchpadHeight,
+            int touchpadWidth) {
+        final String phys = createPhys(PHYS_TYPE_NAVIGATION_TOUCHPAD);
+        mInputManagerInternal.setTypeAssociation(phys, NAVIGATION_TOUCHPAD_DEVICE_TYPE);
+        try {
+            createDeviceInternal(InputDeviceDescriptor.TYPE_NAVIGATION_TOUCHPAD, deviceName,
+                    vendorId, productId, deviceToken, displayId, phys,
+                    () -> mNativeWrapper.openUinputTouchscreen(deviceName, vendorId, productId,
+                            phys, touchpadHeight, touchpadWidth));
+        } catch (DeviceCreationException e) {
+            mInputManagerInternal.unsetTypeAssociation(phys);
+            throw new RuntimeException(
+                    "Failed to create virtual navigation touchpad device '" + deviceName + "'.", e);
+        }
+    }
+
     void unregisterInputDevice(@NonNull IBinder token) {
         synchronized (mLock) {
             final InputDeviceDescriptor inputDeviceDescriptor = mInputDeviceDescriptors.remove(
@@ -208,7 +233,13 @@
             InputDeviceDescriptor inputDeviceDescriptor) {
         token.unlinkToDeath(inputDeviceDescriptor.getDeathRecipient(), /* flags= */ 0);
         mNativeWrapper.closeUinput(inputDeviceDescriptor.getFileDescriptor());
+
         InputManager.getInstance().removeUniqueIdAssociation(inputDeviceDescriptor.getPhys());
+        // Type associations are added in the case of navigation touchpads. Those should be removed
+        // once the input device gets closed.
+        if (inputDeviceDescriptor.getType() == InputDeviceDescriptor.TYPE_NAVIGATION_TOUCHPAD) {
+            mInputManagerInternal.unsetTypeAssociation(inputDeviceDescriptor.getPhys());
+        }
 
         // Reset values to the default if all virtual mice are unregistered, or set display
         // id if there's another mouse (choose the most recent). The inputDeviceDescriptor must be
@@ -510,11 +541,13 @@
         static final int TYPE_MOUSE = 2;
         static final int TYPE_TOUCHSCREEN = 3;
         static final int TYPE_DPAD = 4;
+        static final int TYPE_NAVIGATION_TOUCHPAD = 5;
         @IntDef(prefix = { "TYPE_" }, value = {
                 TYPE_KEYBOARD,
                 TYPE_MOUSE,
                 TYPE_TOUCHSCREEN,
                 TYPE_DPAD,
+                TYPE_NAVIGATION_TOUCHPAD,
         })
         @Retention(RetentionPolicy.SOURCE)
         @interface Type {
diff --git a/services/companion/java/com/android/server/companion/virtual/VirtualDeviceImpl.java b/services/companion/java/com/android/server/companion/virtual/VirtualDeviceImpl.java
index 5819861..12ad9f1 100644
--- a/services/companion/java/com/android/server/companion/virtual/VirtualDeviceImpl.java
+++ b/services/companion/java/com/android/server/companion/virtual/VirtualDeviceImpl.java
@@ -53,6 +53,7 @@
 import android.hardware.input.VirtualMouseConfig;
 import android.hardware.input.VirtualMouseRelativeEvent;
 import android.hardware.input.VirtualMouseScrollEvent;
+import android.hardware.input.VirtualNavigationTouchpadConfig;
 import android.hardware.input.VirtualTouchEvent;
 import android.hardware.input.VirtualTouchscreenConfig;
 import android.os.Binder;
@@ -108,7 +109,7 @@
     private VirtualAudioController mVirtualAudioController;
     @VisibleForTesting
     final Set<Integer> mVirtualDisplayIds = new ArraySet<>();
-    private final OnDeviceCloseListener mListener;
+    private final OnDeviceCloseListener mOnDeviceCloseListener;
     private final IBinder mAppToken;
     private final VirtualDeviceParams mParams;
     private final Map<Integer, PowerManager.WakeLock> mPerDisplayWakelocks = new ArrayMap<>();
@@ -155,7 +156,7 @@
             IBinder token,
             int ownerUid,
             int deviceId,
-            OnDeviceCloseListener listener,
+            OnDeviceCloseListener onDeviceCloseListener,
             PendingTrampolineCallback pendingTrampolineCallback,
             IVirtualDeviceActivityListener activityListener,
             Consumer<ArraySet<Integer>> runningAppsChangedCallback,
@@ -168,7 +169,7 @@
                 deviceId,
                 /* inputController= */ null,
                 /* sensorController= */ null,
-                listener,
+                onDeviceCloseListener,
                 pendingTrampolineCallback,
                 activityListener,
                 runningAppsChangedCallback,
@@ -184,7 +185,7 @@
             int deviceId,
             InputController inputController,
             SensorController sensorController,
-            OnDeviceCloseListener listener,
+            OnDeviceCloseListener onDeviceCloseListener,
             PendingTrampolineCallback pendingTrampolineCallback,
             IVirtualDeviceActivityListener activityListener,
             Consumer<ArraySet<Integer>> runningAppsChangedCallback,
@@ -212,7 +213,7 @@
         } else {
             mSensorController = sensorController;
         }
-        mListener = listener;
+        mOnDeviceCloseListener = onDeviceCloseListener;
         try {
             token.linkToDeath(this, 0);
         } catch (RemoteException e) {
@@ -330,7 +331,7 @@
                 mVirtualAudioController = null;
             }
         }
-        mListener.onClose(mAssociationInfo.getId());
+        mOnDeviceCloseListener.onClose(mDeviceId);
         mAppToken.unlinkToDeath(this, 0);
 
         final long ident = Binder.clearCallingIdentity();
@@ -491,6 +492,38 @@
     }
 
     @Override // Binder call
+    public void createVirtualNavigationTouchpad(VirtualNavigationTouchpadConfig config,
+            @NonNull IBinder deviceToken) {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.CREATE_VIRTUAL_DEVICE,
+                "Permission required to create a virtual navigation touchpad");
+        synchronized (mVirtualDeviceLock) {
+            if (!mVirtualDisplayIds.contains(config.getAssociatedDisplayId())) {
+                throw new SecurityException(
+                        "Cannot create a virtual navigation touchpad for a display not associated "
+                                + "with this virtual device");
+            }
+        }
+        int touchpadHeight = config.getHeight();
+        int touchpadWidth = config.getWidth();
+        if (touchpadHeight <= 0 || touchpadWidth <= 0) {
+            throw new IllegalArgumentException(
+                "Cannot create a virtual navigation touchpad, touchpad dimensions must be positive."
+                    + " Got: (" + touchpadHeight + ", " + touchpadWidth + ")");
+        }
+
+        final long ident = Binder.clearCallingIdentity();
+        try {
+            mInputController.createNavigationTouchpad(
+                    config.getInputDeviceName(), config.getVendorId(),
+                    config.getProductId(), deviceToken, config.getAssociatedDisplayId(),
+                    touchpadHeight, touchpadWidth);
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    @Override // Binder call
     public void unregisterInputDevice(IBinder token) {
         mContext.enforceCallingOrSelfPermission(
                 android.Manifest.permission.CREATE_VIRTUAL_DEVICE,
@@ -650,6 +683,7 @@
     @Override
     protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) {
         fout.println("  VirtualDevice: ");
+        fout.println("    mDeviceId: " + mDeviceId);
         fout.println("    mAssociationId: " + mAssociationInfo.getId());
         fout.println("    mParams: " + mParams);
         fout.println("    mVirtualDisplayIds: ");
@@ -839,7 +873,7 @@
     }
 
     interface OnDeviceCloseListener {
-        void onClose(int associationId);
+        void onClose(int deviceId);
     }
 
     interface PendingTrampolineCallback {
diff --git a/services/companion/java/com/android/server/companion/virtual/VirtualDeviceManagerService.java b/services/companion/java/com/android/server/companion/virtual/VirtualDeviceManagerService.java
index 2b62f69..da2c516 100644
--- a/services/companion/java/com/android/server/companion/virtual/VirtualDeviceManagerService.java
+++ b/services/companion/java/com/android/server/companion/virtual/VirtualDeviceManagerService.java
@@ -41,12 +41,14 @@
 import android.os.IBinder;
 import android.os.Looper;
 import android.os.Parcel;
+import android.os.Process;
 import android.os.RemoteException;
 import android.os.UserHandle;
 import android.util.ArraySet;
 import android.util.ExceptionUtils;
 import android.util.Slog;
 import android.util.SparseArray;
+import android.view.Display;
 import android.widget.Toast;
 
 import com.android.internal.annotations.GuardedBy;
@@ -61,6 +63,7 @@
 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -77,7 +80,7 @@
     private final PendingTrampolineMap mPendingTrampolines = new PendingTrampolineMap(mHandler);
 
     private static AtomicInteger sNextUniqueIndex = new AtomicInteger(
-            VirtualDeviceManager.DEFAULT_DEVICE_ID + 1);
+            VirtualDeviceManager.DEVICE_ID_DEFAULT + 1);
 
     /**
      * Mapping from user IDs to CameraAccessControllers.
@@ -87,14 +90,20 @@
             new SparseArray<>();
 
     /**
-     * Mapping from CDM association IDs to virtual devices. Only one virtual device is allowed for
-     * each CDM associated device.
+     * Mapping from device IDs to CameraAccessControllers.
+     */
+    @GuardedBy("mVirtualDeviceManagerLock")
+    private final SparseArray<CameraAccessController> mCameraAccessControllersByDeviceId =
+            new SparseArray<>();
+
+    /**
+     * Mapping from device IDs to virtual devices.
      */
     @GuardedBy("mVirtualDeviceManagerLock")
     private final SparseArray<VirtualDeviceImpl> mVirtualDevices = new SparseArray<>();
 
     /**
-     * Mapping from CDM association IDs to app UIDs running on the corresponding virtual device.
+     * Mapping from device IDs to app UIDs running on the corresponding virtual device.
      */
     @GuardedBy("mVirtualDeviceManagerLock")
     private final SparseArray<ArraySet<Integer>> mAppsOnVirtualDevices = new SparseArray<>();
@@ -157,7 +166,7 @@
     @GuardedBy("mVirtualDeviceManagerLock")
     private boolean isValidVirtualDeviceLocked(IVirtualDevice virtualDevice) {
         try {
-            return mVirtualDevices.contains(virtualDevice.getAssociationId());
+            return mVirtualDevices.contains(virtualDevice.getDeviceId());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -227,9 +236,9 @@
     }
 
     @VisibleForTesting
-    void notifyRunningAppsChanged(int associationId, ArraySet<Integer> uids) {
+    void notifyRunningAppsChanged(int deviceId, ArraySet<Integer> uids) {
         synchronized (mVirtualDeviceManagerLock) {
-            mAppsOnVirtualDevices.put(associationId, uids);
+            mAppsOnVirtualDevices.put(deviceId, uids);
         }
         mLocalService.onAppsOnVirtualDeviceChanged();
     }
@@ -237,7 +246,7 @@
     @VisibleForTesting
     void addVirtualDevice(VirtualDeviceImpl virtualDevice) {
         synchronized (mVirtualDeviceManagerLock) {
-            mVirtualDevices.put(virtualDevice.getAssociationId(), virtualDevice);
+            mVirtualDevices.put(virtualDevice.getDeviceId(), virtualDevice);
         }
     }
 
@@ -265,60 +274,26 @@
                 throw new IllegalArgumentException("No association with ID " + associationId);
             }
             synchronized (mVirtualDeviceManagerLock) {
-                if (mVirtualDevices.contains(associationId)) {
-                    throw new IllegalStateException(
-                            "Virtual device for association ID " + associationId
-                                    + " already exists");
-                }
                 final int userId = UserHandle.getUserId(callingUid);
                 final CameraAccessController cameraAccessController =
                         mCameraAccessControllers.get(userId);
-                final int uniqueId = sNextUniqueIndex.getAndIncrement();
-
+                final int deviceId = sNextUniqueIndex.getAndIncrement();
                 VirtualDeviceImpl virtualDevice = new VirtualDeviceImpl(getContext(),
-                        associationInfo, token, callingUid, uniqueId,
-                        new VirtualDeviceImpl.OnDeviceCloseListener() {
-                            @Override
-                            public void onClose(int associationId) {
-                                synchronized (mVirtualDeviceManagerLock) {
-                                    VirtualDeviceImpl removedDevice =
-                                            mVirtualDevices.removeReturnOld(associationId);
-                                    if (removedDevice != null) {
-                                        Intent i = new Intent(
-                                                VirtualDeviceManager.ACTION_VIRTUAL_DEVICE_REMOVED);
-                                        i.putExtra(
-                                                VirtualDeviceManager.EXTRA_VIRTUAL_DEVICE_ID,
-                                                removedDevice.getDeviceId());
-                                        i.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
-                                        final long identity = Binder.clearCallingIdentity();
-                                        try {
-                                            getContext().sendBroadcastAsUser(i, UserHandle.ALL);
-                                        } finally {
-                                            Binder.restoreCallingIdentity(identity);
-                                        }
-                                    }
-                                    mAppsOnVirtualDevices.remove(associationId);
-                                    if (cameraAccessController != null) {
-                                        cameraAccessController.stopObservingIfNeeded();
-                                    } else {
-                                        Slog.w(TAG, "cameraAccessController not found for user "
-                                                + userId);
-                                    }
-                                }
-                            }
-                        },
+                        associationInfo, token, callingUid, deviceId,
+                        /* onDeviceCloseListener= */ this::onDeviceClosed,
                         this, activityListener,
                         runningUids -> {
                             cameraAccessController.blockCameraAccessIfNeeded(runningUids);
-                            notifyRunningAppsChanged(associationInfo.getId(), runningUids);
+                            notifyRunningAppsChanged(deviceId, runningUids);
                         },
                         params);
                 if (cameraAccessController != null) {
                     cameraAccessController.startObservingIfNeeded();
+                    mCameraAccessControllersByDeviceId.put(deviceId, cameraAccessController);
                 } else {
                     Slog.w(TAG, "cameraAccessController not found for user " + userId);
                 }
-                mVirtualDevices.put(associationInfo.getId(), virtualDevice);
+                mVirtualDevices.put(deviceId, virtualDevice);
                 return virtualDevice;
             }
         }
@@ -335,7 +310,7 @@
             }
             VirtualDeviceImpl virtualDeviceImpl;
             synchronized (mVirtualDeviceManagerLock) {
-                virtualDeviceImpl = mVirtualDevices.get(virtualDevice.getAssociationId());
+                virtualDeviceImpl = mVirtualDevices.get(virtualDevice.getDeviceId());
                 if (virtualDeviceImpl == null) {
                     throw new SecurityException("Invalid VirtualDevice");
                 }
@@ -385,14 +360,38 @@
         @Override // BinderCall
         @VirtualDeviceParams.DevicePolicy
         public int getDevicePolicy(int deviceId, @VirtualDeviceParams.PolicyType int policyType) {
-            return mLocalService.getDevicePolicy(deviceId, policyType);
+            synchronized (mVirtualDeviceManagerLock) {
+                for (int i = 0; i < mVirtualDevices.size(); i++) {
+                    final VirtualDeviceImpl device = mVirtualDevices.valueAt(i);
+                    if (device.getDeviceId() == deviceId) {
+                        return device.getDevicePolicy(policyType);
+                    }
+                }
+            }
+            return VirtualDeviceParams.DEVICE_POLICY_DEFAULT;
+        }
+
+
+        @Override // Binder call
+        public int getDeviceIdForDisplayId(int displayId) {
+            if (displayId == Display.INVALID_DISPLAY || displayId == Display.DEFAULT_DISPLAY) {
+                return VirtualDeviceManager.DEVICE_ID_DEFAULT;
+            }
+            synchronized (mVirtualDeviceManagerLock) {
+                for (int i = 0; i < mVirtualDevices.size(); i++) {
+                    VirtualDeviceImpl virtualDevice = mVirtualDevices.valueAt(i);
+                    if (virtualDevice.isDisplayOwnedByVirtualDevice(displayId)) {
+                        return virtualDevice.getDeviceId();
+                    }
+                }
+            }
+            return VirtualDeviceManager.DEVICE_ID_DEFAULT;
         }
 
         @Nullable
         private AssociationInfo getAssociationInfo(String packageName, int associationId) {
             final int callingUserId = getCallingUserHandle().getIdentifier();
-            final List<AssociationInfo> associations =
-                    mAllAssociations.get(callingUserId);
+            final List<AssociationInfo> associations = mAllAssociations.get(callingUserId);
             if (associations != null) {
                 final int associationSize = associations.size();
                 for (int i = 0; i < associationSize; i++) {
@@ -408,6 +407,29 @@
             return null;
         }
 
+        private void onDeviceClosed(int deviceId) {
+            synchronized (mVirtualDeviceManagerLock) {
+                mVirtualDevices.remove(deviceId);
+                Intent i = new Intent(VirtualDeviceManager.ACTION_VIRTUAL_DEVICE_REMOVED);
+                i.putExtra(VirtualDeviceManager.EXTRA_VIRTUAL_DEVICE_ID, deviceId);
+                i.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+                final long identity = Binder.clearCallingIdentity();
+                try {
+                    getContext().sendBroadcastAsUser(i, UserHandle.ALL);
+                } finally {
+                    Binder.restoreCallingIdentity(identity);
+                }
+                mAppsOnVirtualDevices.remove(deviceId);
+                final CameraAccessController cameraAccessController =
+                        mCameraAccessControllersByDeviceId.removeReturnOld(deviceId);
+                if (cameraAccessController != null) {
+                    cameraAccessController.stopObservingIfNeeded();
+                } else {
+                    Slog.w(TAG, "cameraAccessController not found for device Id " + deviceId);
+                }
+            }
+        }
+
         @Override
         public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
                 throws RemoteException {
@@ -469,17 +491,32 @@
         }
 
         @Override
-        @VirtualDeviceParams.DevicePolicy
-        public int getDevicePolicy(int deviceId, @VirtualDeviceParams.PolicyType int policyType) {
+        public int getDeviceOwnerUid(int deviceId) {
             synchronized (mVirtualDeviceManagerLock) {
-                for (int i = 0; i < mVirtualDevices.size(); i++) {
-                    final VirtualDeviceImpl device = mVirtualDevices.valueAt(i);
+                int size = mVirtualDevices.size();
+                for (int i = 0; i < size; i++) {
+                    VirtualDeviceImpl device = mVirtualDevices.valueAt(i);
                     if (device.getDeviceId() == deviceId) {
-                        return device.getDevicePolicy(policyType);
+                        return device.getOwnerUid();
                     }
                 }
             }
-            return VirtualDeviceParams.DEVICE_POLICY_DEFAULT;
+            return Process.INVALID_UID;
+        }
+
+        @Override
+        public @NonNull Set<Integer> getDeviceIdsForUid(int uid) {
+            ArraySet<Integer> result = new ArraySet<>();
+            synchronized (mVirtualDeviceManagerLock) {
+                int size = mVirtualDevices.size();
+                for (int i = 0; i < size; i++) {
+                    VirtualDeviceImpl device = mVirtualDevices.valueAt(i);
+                    if (device.isAppRunningOnVirtualDevice(uid)) {
+                        result.add(device.getDeviceId());
+                    }
+                }
+            }
+            return result;
         }
 
         @Override
@@ -543,19 +580,6 @@
         }
 
         @Override
-        public boolean isAppOwnerOfAnyVirtualDevice(int uid) {
-            synchronized (mVirtualDeviceManagerLock) {
-                int size = mVirtualDevices.size();
-                for (int i = 0; i < size; i++) {
-                    if (mVirtualDevices.valueAt(i).getOwnerUid() == uid) {
-                        return true;
-                    }
-                }
-                return false;
-            }
-        }
-
-        @Override
         public boolean isAppRunningOnAnyVirtualDevice(int uid) {
             synchronized (mVirtualDeviceManagerLock) {
                 int size = mVirtualDevices.size();
diff --git a/services/core/Android.bp b/services/core/Android.bp
index a61a61b..1e1d610 100644
--- a/services/core/Android.bp
+++ b/services/core/Android.bp
@@ -132,6 +132,7 @@
         "framework-tethering.stubs.module_lib",
         "service-art.stubs.system_server",
         "service-permission.stubs.system_server",
+        "service-rkp.stubs.system_server",
         "service-sdksandbox.stubs.system_server",
     ],
     plugins: ["ImmutabilityAnnotationProcessor"],
@@ -144,6 +145,7 @@
 
     static_libs: [
         "android.hardware.authsecret-V1.0-java",
+        "android.hardware.authsecret-V1-java",
         "android.hardware.boot-V1.0-java",
         "android.hardware.boot-V1.1-java",
         "android.hardware.boot-V1.2-java",
diff --git a/services/core/java/com/android/server/BinaryTransparencyService.java b/services/core/java/com/android/server/BinaryTransparencyService.java
index 6cd7ce8..17002d5 100644
--- a/services/core/java/com/android/server/BinaryTransparencyService.java
+++ b/services/core/java/com/android/server/BinaryTransparencyService.java
@@ -19,6 +19,8 @@
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.annotation.SuppressLint;
+import android.apex.ApexInfo;
+import android.apex.IApexService;
 import android.app.job.JobInfo;
 import android.app.job.JobParameters;
 import android.app.job.JobScheduler;
@@ -39,6 +41,7 @@
 import android.content.pm.parsing.result.ParseInput;
 import android.content.pm.parsing.result.ParseResult;
 import android.content.pm.parsing.result.ParseTypeImpl;
+import android.os.Binder;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.IBinder;
@@ -61,7 +64,6 @@
 
 import libcore.util.HexEncoding;
 
-import java.io.File;
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
 import java.security.PublicKey;
@@ -73,7 +75,6 @@
 import java.util.Set;
 import java.util.concurrent.Executors;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 /**
  * @hide
@@ -105,7 +106,6 @@
     @VisibleForTesting
     static final String BUNDLE_CONTENT_DIGEST = "content-digest";
 
-    static final String APEX_PRELOAD_LOCATION = "/system/apex/";
     static final String APEX_PRELOAD_LOCATION_ERROR = "could-not-be-determined";
 
     // used for indicating any type of error during MBA measurement
@@ -119,7 +119,7 @@
     // used for indicating newly installed MBAs that are updated (but unused currently)
     static final int MBA_STATUS_UPDATED_NEW_INSTALL = 4;
 
-    private static final boolean DEBUG = true;     // set this to false upon submission
+    private static final boolean DEBUG = false;     // toggle this for local debug
 
     private final Context mContext;
     private String mVbmetaDigest;
@@ -320,9 +320,7 @@
                     FrameworkStatsLog.write(FrameworkStatsLog.MOBILE_BUNDLED_APP_INFO_GATHERED,
                             packageInfo.packageName,
                             packageInfo.getLongVersionCode(),
-                            (cDigest != null) ? HexEncoding.encodeToString(
-                                    packageMeasurement.getByteArray(BUNDLE_CONTENT_DIGEST),
-                                    false) : null,
+                            (cDigest != null) ? HexEncoding.encodeToString(cDigest, false) : null,
                             packageMeasurement.getInt(BUNDLE_CONTENT_DIGEST_ALGORITHM),
                             signerDigestHexStrings, // signer_cert_digest
                             mba_status,             // mba_status
@@ -381,9 +379,7 @@
                     FrameworkStatsLog.write(FrameworkStatsLog.MOBILE_BUNDLED_APP_INFO_GATHERED,
                             packageInfo.packageName,
                             packageInfo.getLongVersionCode(),
-                            (cDigest != null) ? HexEncoding.encodeToString(
-                                    packageMeasurement.getByteArray(BUNDLE_CONTENT_DIGEST),
-                                    false) : null,
+                            (cDigest != null) ? HexEncoding.encodeToString(cDigest, false) : null,
                             packageMeasurement.getInt(BUNDLE_CONTENT_DIGEST_ALGORITHM),
                             signerDigestHexStrings,
                             MBA_STATUS_NEW_INSTALL,   // mba_status
@@ -476,6 +472,7 @@
                 }
 
                 private void printPackageMeasurements(PackageInfo packageInfo,
+                                                      boolean useSha256,
                                                       final PrintWriter pw) {
                     Map<Integer, byte[]> contentDigests = computeApkContentDigest(
                             packageInfo.applicationInfo.sourceDir);
@@ -485,6 +482,14 @@
                         return;
                     }
 
+                    if (useSha256) {
+                        byte[] fileBuff = PackageUtils.createLargeFileBuffer();
+                        String hexEncodedSha256Digest =
+                                PackageUtils.computeSha256DigestForLargeFile(
+                                        packageInfo.applicationInfo.sourceDir, fileBuff);
+                        pw.print(hexEncodedSha256Digest + ",");
+                    }
+
                     for (Map.Entry<Integer, byte[]> entry : contentDigests.entrySet()) {
                         Integer algorithmId = entry.getKey();
                         byte[] contentDigest = entry.getValue();
@@ -497,6 +502,7 @@
                 }
 
                 private void printPackageInstallationInfo(PackageInfo packageInfo,
+                                                          boolean useSha256,
                                                           final PrintWriter pw) {
                     pw.println("--- Package Installation Info ---");
                     pw.println("Current install location: "
@@ -507,11 +513,13 @@
                         pw.println("|--> Pre-installed package install location: "
                                 + origPackageFilepath);
 
-                        // TODO(b/259347186): revive this with the proper cmd options.
-                        /*
-                        String digest = PackageUtils.computeSha256DigestForLargeFile(
-                        origPackageFilepath, PackageUtils.createLargeFileBuffer());
-                         */
+                        if (useSha256) {
+                            String sha256Digest = PackageUtils.computeSha256DigestForLargeFile(
+                                    origPackageFilepath, PackageUtils.createLargeFileBuffer());
+                            pw.println("|--> Pre-installed package SHA-256 digest: "
+                                    + sha256Digest);
+                        }
+
 
                         Map<Integer, byte[]> contentDigests = computeApkContentDigest(
                                 origPackageFilepath);
@@ -530,7 +538,9 @@
                         }
                     }
                     pw.println("First install time (ms): " + packageInfo.firstInstallTime);
-                    pw.println("Last update time (ms): " + packageInfo.lastUpdateTime);
+                    pw.println("Last update time (ms):   " + packageInfo.lastUpdateTime);
+                    // TODO(b/261493591): Determination of whether a package is preinstalled can be
+                    // made more robust
                     boolean isPreloaded = (packageInfo.firstInstallTime
                             == packageInfo.lastUpdateTime);
                     pw.println("Is preloaded: " + isPreloaded);
@@ -562,6 +572,8 @@
                     }
                     pw.println("--- Package Signer Info ---");
                     pw.println("Has multiple signers: " + signerInfo.hasMultipleSigners());
+                    pw.println("Signing key has been rotated: "
+                            + signerInfo.hasPastSigningCertificates());
                     Signature[] packageSigners = signerInfo.getApkContentsSigners();
                     for (Signature packageSigner : packageSigners) {
                         byte[] packageSignerDigestBytes =
@@ -575,8 +587,31 @@
                         } catch (CertificateException e) {
                             Slog.e(TAG,
                                     "Failed to obtain public key of signer for cert with hash: "
-                                    + packageSignerDigestHextring);
-                            e.printStackTrace();
+                                    + packageSignerDigestHextring, e);
+                        }
+                    }
+
+                    if (!signerInfo.hasMultipleSigners()
+                            && signerInfo.hasPastSigningCertificates()) {
+                        pw.println("== Signing Cert Lineage (Excluding The Most Recent) ==");
+                        pw.println("(Certs are sorted in the order of rotation, beginning with the "
+                                   + "original signing cert)");
+                        Signature[] signingCertHistory = signerInfo.getSigningCertificateHistory();
+                        for (int i = 0; i < (signingCertHistory.length - 1); i++) {
+                            Signature signature = signingCertHistory[i];
+                            byte[] signatureDigestBytes = PackageUtils.computeSha256DigestBytes(
+                                    signature.toByteArray());
+                            String certHashHexString = HexEncoding.encodeToString(
+                                    signatureDigestBytes, false);
+                            pw.println("  ++ Signer cert #" + (i + 1) + " ++");
+                            pw.println("  Cert SHA256-digest: " + certHashHexString);
+                            try {
+                                PublicKey publicKey = signature.getPublicKey();
+                                pw.println("  Signing key algorithm: " + publicKey.getAlgorithm());
+                            } catch (CertificateException e) {
+                                Slog.e(TAG, "Failed to obtain public key of signer for cert "
+                                        + "with hash: " + certHashHexString, e);
+                            }
                         }
                     }
 
@@ -615,7 +650,7 @@
                     pw.println("Component factory: "
                             + packageInfo.applicationInfo.appComponentFactory);
                     pw.println("Process name: " + packageInfo.applicationInfo.processName);
-                    pw.println("Task affinity : " + packageInfo.applicationInfo.taskAffinity);
+                    pw.println("Task affinity: " + packageInfo.applicationInfo.taskAffinity);
                     pw.println("UID: " + packageInfo.applicationInfo.uid);
                     pw.println("Shared UID: " + packageInfo.sharedUserId);
 
@@ -669,15 +704,35 @@
 
                 }
 
+                private void printHeadersHelper(@NonNull String packageType,
+                                          boolean useSha256,
+                                          @NonNull final PrintWriter pw) {
+                    pw.print(packageType + " Info [Format: package_name,package_version,");
+                    if (useSha256) {
+                        pw.print("package_sha256_digest,");
+                    }
+                    pw.print("content_digest_algorithm:content_digest]:\n");
+                }
+
                 private int printAllApexs() {
                     final PrintWriter pw = getOutPrintWriter();
                     boolean verbose = false;
+                    boolean useSha256 = false;
+                    boolean printHeaders = true;
                     String opt;
                     while ((opt = getNextOption()) != null) {
                         switch (opt) {
                             case "-v":
+                            case "--verbose":
                                 verbose = true;
                                 break;
+                            case "-o":
+                            case "--old":
+                                useSha256 = true;
+                                break;
+                            case "--no-headers":
+                                printHeaders = false;
+                                break;
                             default:
                                 pw.println("ERROR: Unknown option: " + opt);
                                 return 1;
@@ -690,23 +745,17 @@
                         return -1;
                     }
 
-                    if (!verbose) {
-                        pw.println("APEX Info [Format: package_name,package_version,"
-                                // TODO(b/259347186): revive via special cmd line option
-                                //+ "package_sha256_digest,"
-                                + "content_digest_algorithm:content_digest]:");
+                    if (!verbose && printHeaders) {
+                        printHeadersHelper("APEX", useSha256, pw);
                     }
                     for (PackageInfo packageInfo : getCurrentInstalledApexs()) {
-                        if (verbose) {
-                            pw.println("APEX Info [Format: package_name,package_version,"
-                                    // TODO(b/259347186): revive via special cmd line option
-                                    //+ "package_sha256_digest,"
-                                    + "content_digest_algorithm:content_digest]:");
+                        if (verbose && printHeaders) {
+                            printHeadersHelper("APEX", useSha256, pw);
                         }
                         String packageName = packageInfo.packageName;
                         pw.print(packageName + ","
                                 + packageInfo.getLongVersionCode() + ",");
-                        printPackageMeasurements(packageInfo, pw);
+                        printPackageMeasurements(packageInfo, useSha256, pw);
 
                         if (verbose) {
                             ModuleInfo moduleInfo;
@@ -718,7 +767,7 @@
                                 pw.println("Is a module: false");
                             }
 
-                            printPackageInstallationInfo(packageInfo, pw);
+                            printPackageInstallationInfo(packageInfo, useSha256, pw);
                             printPackageSignerDetails(packageInfo.signingInfo, pw);
                             pw.println("");
                         }
@@ -729,12 +778,22 @@
                 private int printAllModules() {
                     final PrintWriter pw = getOutPrintWriter();
                     boolean verbose = false;
+                    boolean useSha256 = false;
+                    boolean printHeaders = true;
                     String opt;
                     while ((opt = getNextOption()) != null) {
                         switch (opt) {
                             case "-v":
+                            case "--verbose":
                                 verbose = true;
                                 break;
+                            case "-o":
+                            case "--old":
+                                useSha256 = true;
+                                break;
+                            case "--no-headers":
+                                printHeaders = false;
+                                break;
                             default:
                                 pw.println("ERROR: Unknown option: " + opt);
                                 return 1;
@@ -747,32 +806,25 @@
                         return -1;
                     }
 
-                    if (!verbose) {
-                        pw.println("Module Info [Format: package_name,package_version,"
-                                // TODO(b/259347186): revive via special cmd line option
-                                //+ "package_sha256_digest,"
-                                + "content_digest_algorithm:content_digest]:");
+                    if (!verbose && printHeaders) {
+                        printHeadersHelper("Module", useSha256, pw);
                     }
                     for (ModuleInfo module : pm.getInstalledModules(PackageManager.MATCH_ALL)) {
                         String packageName = module.getPackageName();
-                        if (verbose) {
-                            pw.println("Module Info [Format: package_name,package_version,"
-                                    // TODO(b/259347186): revive via special cmd line option
-                                    //+ "package_sha256_digest,"
-                                    + "content_digest_algorithm:content_digest]:");
+                        if (verbose && printHeaders) {
+                            printHeadersHelper("Module", useSha256, pw);
                         }
                         try {
                             PackageInfo packageInfo = pm.getPackageInfo(packageName,
                                     PackageManager.MATCH_APEX
                                             | PackageManager.GET_SIGNING_CERTIFICATES);
-                            //pw.print("package:");
                             pw.print(packageInfo.packageName + ",");
                             pw.print(packageInfo.getLongVersionCode() + ",");
-                            printPackageMeasurements(packageInfo, pw);
+                            printPackageMeasurements(packageInfo, useSha256, pw);
 
                             if (verbose) {
                                 printModuleDetails(module, pw);
-                                printPackageInstallationInfo(packageInfo, pw);
+                                printPackageInstallationInfo(packageInfo, useSha256, pw);
                                 printPackageSignerDetails(packageInfo.signingInfo, pw);
                                 pw.println("");
                             }
@@ -793,41 +845,45 @@
                     final PrintWriter pw = getOutPrintWriter();
                     boolean verbose = false;
                     boolean printLibraries = false;
+                    boolean useSha256 = false;
+                    boolean printHeaders = true;
                     String opt;
                     while ((opt = getNextOption()) != null) {
                         switch (opt) {
                             case "-v":
+                            case "--verbose":
                                 verbose = true;
                                 break;
                             case "-l":
                                 printLibraries = true;
                                 break;
+                            case "-o":
+                            case "--old":
+                                useSha256 = true;
+                                break;
+                            case "--no-headers":
+                                printHeaders = false;
+                                break;
                             default:
                                 pw.println("ERROR: Unknown option: " + opt);
                                 return 1;
                         }
                     }
 
-                    if (!verbose) {
-                        pw.println("MBA Info [Format: package_name,package_version,"
-                                // TODO(b/259347186): revive via special cmd line option
-                                //+ "package_sha256_digest,"
-                                + "content_digest_algorithm:content_digest]:");
+                    if (!verbose && printHeaders) {
+                        printHeadersHelper("MBA", useSha256, pw);
                     }
                     for (PackageInfo packageInfo : getNewlyInstalledMbas()) {
-                        if (verbose) {
-                            pw.println("MBA Info [Format: package_name,package_version,"
-                                    // TODO(b/259347186): revive via special cmd line option
-                                    //+ "package_sha256_digest,"
-                                    + "content_digest_algorithm:content_digest]:");
+                        if (verbose && printHeaders) {
+                            printHeadersHelper("MBA", useSha256, pw);
                         }
                         pw.print(packageInfo.packageName + ",");
                         pw.print(packageInfo.getLongVersionCode() + ",");
-                        printPackageMeasurements(packageInfo, pw);
+                        printPackageMeasurements(packageInfo, useSha256, pw);
 
                         if (verbose) {
                             printAppDetails(packageInfo, printLibraries, pw);
-                            printPackageInstallationInfo(packageInfo, pw);
+                            printPackageInstallationInfo(packageInfo, useSha256, pw);
                             printPackageSignerDetails(packageInfo.signingInfo, pw);
                             pw.println("");
                         }
@@ -894,27 +950,39 @@
                 private void printHelpMenu() {
                     final PrintWriter pw = getOutPrintWriter();
                     pw.println("Transparency manager (transparency) commands:");
-                    pw.println("    help");
-                    pw.println("        Print this help text.");
+                    pw.println("  help");
+                    pw.println("    Print this help text.");
                     pw.println("");
-                    pw.println("    get image_info [-a]");
-                    pw.println("        Print information about loaded image (firmware). Options:");
-                    pw.println("            -a: lists all other identifiable partitions.");
+                    pw.println("  get image_info [-a]");
+                    pw.println("    Print information about loaded image (firmware). Options:");
+                    pw.println("        -a: lists all other identifiable partitions.");
                     pw.println("");
-                    pw.println("    get apex_info [-v]");
-                    pw.println("        Print information about installed APEXs on device.");
-                    pw.println("            -v: lists more verbose information about each APEX.");
+                    pw.println("  get apex_info [-o] [-v] [--no-headers]");
+                    pw.println("    Print information about installed APEXs on device.");
+                    pw.println("      -o: also uses the old digest scheme (SHA256) to compute "
+                               + "APEX hashes. WARNING: This can be a very slow and CPU-intensive "
+                               + "computation.");
+                    pw.println("      -v: lists more verbose information about each APEX.");
+                    pw.println("      --no-headers: does not print the header if specified");
                     pw.println("");
-                    pw.println("    get module_info [-v]");
-                    pw.println("        Print information about installed modules on device.");
-                    pw.println("            -v: lists more verbose information about each module.");
+                    pw.println("  get module_info [-o] [-v] [--no-headers]");
+                    pw.println("    Print information about installed modules on device.");
+                    pw.println("      -o: also uses the old digest scheme (SHA256) to compute "
+                               + "module hashes. WARNING: This can be a very slow and "
+                               + "CPU-intensive computation.");
+                    pw.println("      -v: lists more verbose information about each module.");
+                    pw.println("      --no-headers: does not print the header if specified");
                     pw.println("");
-                    pw.println("    get mba_info [-v] [-l]");
-                    pw.println("        Print information about installed mobile bundle apps "
+                    pw.println("  get mba_info [-o] [-v] [-l] [--no-headers]");
+                    pw.println("    Print information about installed mobile bundle apps "
                                + "(MBAs on device).");
-                    pw.println("            -v: lists more verbose information about each app.");
-                    pw.println("            -l: lists shared library info. This will only be "
-                               + "listed with -v");
+                    pw.println("      -o: also uses the old digest scheme (SHA256) to compute "
+                               + "MBA hashes. WARNING: This can be a very slow and CPU-intensive "
+                               + "computation.");
+                    pw.println("      -v: lists more verbose information about each app.");
+                    pw.println("      -l: lists shared library info. (This option only works "
+                               + "when -v option is also specified)");
+                    pw.println("      --no-headers: does not print the header if specified");
                     pw.println("");
                 }
 
@@ -1096,19 +1164,18 @@
 
     @NonNull
     private String getOriginalApexPreinstalledLocation(String packageName,
-                                                   String currentInstalledLocation) {
-        // get a listing of all apex files in /system/apex/
-        Set<String> originalApexs = Stream.of(new File(APEX_PRELOAD_LOCATION).listFiles())
-                                        .filter(f -> !f.isDirectory())
-                                        .map(File::getName)
-                                        .collect(Collectors.toSet());
-
-        for (String originalApex : originalApexs) {
-            if (originalApex.startsWith(packageName)) {
-                return APEX_PRELOAD_LOCATION + originalApex;
+            String currentInstalledLocation) {
+        try {
+            IApexService apexService = IApexService.Stub.asInterface(
+                    Binder.allowBlocking(ServiceManager.waitForService("apexservice")));
+            for (ApexInfo info : apexService.getAllPackages()) {
+                if (packageName.equals(info.moduleName)) {
+                    return info.preinstalledModulePath;
+                }
             }
+        } catch (RemoteException e) {
+            Slog.e(TAG, "Unable to get package list from apexservice", e);
         }
-
         return APEX_PRELOAD_LOCATION_ERROR;
     }
 
diff --git a/services/core/java/com/android/server/BootReceiver.java b/services/core/java/com/android/server/BootReceiver.java
index 84c033c..572e9c2 100644
--- a/services/core/java/com/android/server/BootReceiver.java
+++ b/services/core/java/com/android/server/BootReceiver.java
@@ -337,12 +337,10 @@
             return;
         }
 
-        // Check if we should rate limit and abort early if needed. Do this for both proto and
-        // non-proto tombstones, even though proto tombstones do not support including the counter
-        // of events dropped since rate limiting activated yet.
+        // Check if we should rate limit and abort early if needed.
         DropboxRateLimiter.RateLimitResult rateLimitResult =
                 sDropboxRateLimiter.shouldRateLimit(
-                       proto ? TAG_TOMBSTONE_PROTO : TAG_TOMBSTONE, processName);
+                        proto ? TAG_TOMBSTONE_PROTO_WITH_HEADERS : TAG_TOMBSTONE, processName);
         if (rateLimitResult.shouldRateLimit()) return;
 
         HashMap<String, Long> timestamps = readTimestamps();
diff --git a/services/core/java/com/android/server/CountryDetectorService.java b/services/core/java/com/android/server/CountryDetectorService.java
index a2a7dd3..a654925 100644
--- a/services/core/java/com/android/server/CountryDetectorService.java
+++ b/services/core/java/com/android/server/CountryDetectorService.java
@@ -148,6 +148,10 @@
             Receiver r = new Receiver(listener);
             try {
                 listener.asBinder().linkToDeath(r, 0);
+                final Country country = detectCountry();
+                if (country != null) {
+                    listener.onCountryDetected(country);
+                }
                 mReceivers.put(listener.asBinder(), r);
                 if (mReceivers.size() == 1) {
                     Slog.d(TAG, "The first listener is added");
diff --git a/services/core/java/com/android/server/NetworkManagementService.java b/services/core/java/com/android/server/NetworkManagementService.java
index 5d54b6c..fc26f09 100644
--- a/services/core/java/com/android/server/NetworkManagementService.java
+++ b/services/core/java/com/android/server/NetworkManagementService.java
@@ -17,9 +17,6 @@
 package com.android.server;
 
 import static android.Manifest.permission.CONNECTIVITY_INTERNAL;
-import static android.Manifest.permission.NETWORK_SETTINGS;
-import static android.Manifest.permission.OBSERVE_NETWORK_POLICY;
-import static android.Manifest.permission.SHUTDOWN;
 import static android.net.ConnectivityManager.FIREWALL_CHAIN_DOZABLE;
 import static android.net.ConnectivityManager.FIREWALL_CHAIN_LOW_POWER_STANDBY;
 import static android.net.ConnectivityManager.FIREWALL_CHAIN_POWERSAVE;
@@ -63,6 +60,7 @@
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.INetworkManagementService;
+import android.os.PermissionEnforcer;
 import android.os.Process;
 import android.os.RemoteCallbackList;
 import android.os.RemoteException;
@@ -230,6 +228,7 @@
      */
     private NetworkManagementService(
             Context context, Dependencies deps) {
+        super(PermissionEnforcer.fromContext(context));
         mContext = context;
         mDeps = deps;
 
diff --git a/services/core/java/com/android/server/PersistentDataBlockService.java b/services/core/java/com/android/server/PersistentDataBlockService.java
index b2fc574..5eb0db1 100644
--- a/services/core/java/com/android/server/PersistentDataBlockService.java
+++ b/services/core/java/com/android/server/PersistentDataBlockService.java
@@ -36,6 +36,7 @@
 import com.android.internal.R;
 import com.android.internal.annotations.GuardedBy;
 import com.android.internal.util.DumpUtils;
+import com.android.server.pm.UserManagerInternal;
 
 import libcore.io.IoUtils;
 
@@ -156,14 +157,19 @@
         mBlockDeviceSize = -1; // Load lazily
     }
 
-    private int getAllowedUid(int userHandle) {
+    private int getAllowedUid() {
+        final UserManagerInternal umInternal = LocalServices.getService(UserManagerInternal.class);
+        final int mainUserId = umInternal.getMainUserId();
+        if (mainUserId < 0) {
+            return -1;
+        }
         String allowedPackage = mContext.getResources()
                 .getString(R.string.config_persistentDataPackageName);
         int allowedUid = -1;
         if (!TextUtils.isEmpty(allowedPackage)) {
             try {
                 allowedUid = mContext.getPackageManager().getPackageUidAsUser(
-                        allowedPackage, PackageManager.MATCH_SYSTEM_ONLY, userHandle);
+                        allowedPackage, PackageManager.MATCH_SYSTEM_ONLY, mainUserId);
             } catch (PackageManager.NameNotFoundException e) {
                 // not expected
                 Slog.e(TAG, "not able to find package " + allowedPackage, e);
@@ -176,7 +182,7 @@
     public void onStart() {
         // Do init on a separate thread, will join in PHASE_ACTIVITY_MANAGER_READY
         SystemServerInitThreadPool.submit(() -> {
-            mAllowedUid = getAllowedUid(UserHandle.USER_SYSTEM);
+            mAllowedUid = getAllowedUid();
             enforceChecksumValidity();
             formatIfOemUnlockEnabled();
             publishBinderService(Context.PERSISTENT_DATA_BLOCK_SERVICE, mService);
diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java
index 6b6351f..6435869 100644
--- a/services/core/java/com/android/server/StorageManagerService.java
+++ b/services/core/java/com/android/server/StorageManagerService.java
@@ -672,6 +672,7 @@
     private static final int H_COMPLETE_UNLOCK_USER = 14;
     private static final int H_VOLUME_STATE_CHANGED = 15;
     private static final int H_CLOUD_MEDIA_PROVIDER_CHANGED = 16;
+    private static final int H_SECURE_KEYGUARD_STATE_CHANGED = 17;
 
     class StorageManagerServiceHandler extends Handler {
         public StorageManagerServiceHandler(Looper looper) {
@@ -819,6 +820,14 @@
                     }
                     break;
                 }
+                case H_SECURE_KEYGUARD_STATE_CHANGED: {
+                    try {
+                        mVold.onSecureKeyguardStateChanged((boolean) msg.obj);
+                    } catch (Exception e) {
+                        Slog.wtf(TAG, e);
+                    }
+                    break;
+                }
             }
         }
     }
@@ -836,7 +845,15 @@
                 if (Intent.ACTION_USER_ADDED.equals(action)) {
                     final UserManager um = mContext.getSystemService(UserManager.class);
                     final int userSerialNumber = um.getUserSerialNumber(userId);
-                    mVold.onUserAdded(userId, userSerialNumber);
+                    final UserInfo userInfo = um.getUserInfo(userId);
+                    if (userInfo.isCloneProfile()) {
+                        // Only clone profiles share storage with their parent
+                        mVold.onUserAdded(userId, userSerialNumber,
+                                userInfo.profileGroupId /* sharesStorageWithUserId */);
+                    } else {
+                        mVold.onUserAdded(userId, userSerialNumber,
+                                -1 /* shareStorageWithUserId */);
+                    }
                 } else if (Intent.ACTION_USER_REMOVED.equals(action)) {
                     synchronized (mLock) {
                         final int size = mVolumes.size();
@@ -1050,7 +1067,11 @@
 
                 // Tell vold about all existing and started users
                 for (UserInfo user : users) {
-                    mVold.onUserAdded(user.id, user.serialNumber);
+                    if (user.isCloneProfile()) {
+                        mVold.onUserAdded(user.id, user.serialNumber, user.profileGroupId);
+                    } else {
+                        mVold.onUserAdded(user.id, user.serialNumber, -1);
+                    }
                 }
                 for (int userId : systemUnlockedUsers) {
                     mVold.onUserStarted(userId);
@@ -1242,12 +1263,12 @@
     public void onKeyguardStateChanged(boolean isShowing) {
         // Push down current secure keyguard status so that we ignore malicious
         // USB devices while locked.
-        mSecureKeyguardShowing = isShowing
+        boolean isSecureKeyguardShowing = isShowing
                 && mContext.getSystemService(KeyguardManager.class).isDeviceSecure(mCurrentUserId);
-        try {
-            mVold.onSecureKeyguardStateChanged(mSecureKeyguardShowing);
-        } catch (Exception e) {
-            Slog.wtf(TAG, e);
+        if (mSecureKeyguardShowing != isSecureKeyguardShowing) {
+            mSecureKeyguardShowing = isSecureKeyguardShowing;
+            mHandler.obtainMessage(H_SECURE_KEYGUARD_STATE_CHANGED, mSecureKeyguardShowing)
+                    .sendToTarget();
         }
     }
 
diff --git a/services/core/java/com/android/server/SystemConfig.java b/services/core/java/com/android/server/SystemConfig.java
index b7f8d38..75788f2 100644
--- a/services/core/java/com/android/server/SystemConfig.java
+++ b/services/core/java/com/android/server/SystemConfig.java
@@ -47,6 +47,7 @@
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.util.XmlUtils;
 import com.android.modules.utils.build.UnboundedSdkLevel;
+import com.android.server.pm.permission.PermissionAllowlist;
 
 import libcore.io.IoUtils;
 import libcore.util.EmptyArray;
@@ -304,24 +305,7 @@
     final ArrayMap<String, List<CarrierAssociatedAppEntry>>
             mDisabledUntilUsedPreinstalledCarrierAssociatedApps = new ArrayMap<>();
 
-    final ArrayMap<String, ArraySet<String>> mPrivAppPermissions = new ArrayMap<>();
-    final ArrayMap<String, ArraySet<String>> mPrivAppDenyPermissions = new ArrayMap<>();
-
-    final ArrayMap<String, ArraySet<String>> mVendorPrivAppPermissions = new ArrayMap<>();
-    final ArrayMap<String, ArraySet<String>> mVendorPrivAppDenyPermissions = new ArrayMap<>();
-
-    final ArrayMap<String, ArraySet<String>> mProductPrivAppPermissions = new ArrayMap<>();
-    final ArrayMap<String, ArraySet<String>> mProductPrivAppDenyPermissions = new ArrayMap<>();
-
-    final ArrayMap<String, ArraySet<String>> mSystemExtPrivAppPermissions = new ArrayMap<>();
-    final ArrayMap<String, ArraySet<String>> mSystemExtPrivAppDenyPermissions = new ArrayMap<>();
-
-    final ArrayMap<String, ArrayMap<String, ArraySet<String>>> mApexPrivAppPermissions =
-            new ArrayMap<>();
-    final ArrayMap<String, ArrayMap<String, ArraySet<String>>> mApexPrivAppDenyPermissions =
-            new ArrayMap<>();
-
-    final ArrayMap<String, ArrayMap<String, Boolean>> mOemPermissions = new ArrayMap<>();
+    private final PermissionAllowlist mPermissionAllowlist = new PermissionAllowlist();
 
     // Allowed associations between applications.  If there are any entries
     // for an app, those are the only associations allowed; otherwise, all associations
@@ -459,64 +443,8 @@
         return mDisabledUntilUsedPreinstalledCarrierAssociatedApps;
     }
 
-    public ArraySet<String> getPrivAppPermissions(String packageName) {
-        return mPrivAppPermissions.get(packageName);
-    }
-
-    public ArraySet<String> getPrivAppDenyPermissions(String packageName) {
-        return mPrivAppDenyPermissions.get(packageName);
-    }
-
-    /** Get privapp permission allowlist for an apk-in-apex. */
-    public ArraySet<String> getApexPrivAppPermissions(String apexName, String apkPackageName) {
-        return mApexPrivAppPermissions.getOrDefault(apexName, EMPTY_PERMISSIONS)
-                .get(apkPackageName);
-    }
-
-    /** Get privapp permissions denylist for an apk-in-apex. */
-    public ArraySet<String> getApexPrivAppDenyPermissions(String apexName, String apkPackageName) {
-        return mApexPrivAppDenyPermissions.getOrDefault(apexName, EMPTY_PERMISSIONS)
-                .get(apkPackageName);
-    }
-
-    public ArraySet<String> getVendorPrivAppPermissions(String packageName) {
-        return mVendorPrivAppPermissions.get(packageName);
-    }
-
-    public ArraySet<String> getVendorPrivAppDenyPermissions(String packageName) {
-        return mVendorPrivAppDenyPermissions.get(packageName);
-    }
-
-    public ArraySet<String> getProductPrivAppPermissions(String packageName) {
-        return mProductPrivAppPermissions.get(packageName);
-    }
-
-    public ArraySet<String> getProductPrivAppDenyPermissions(String packageName) {
-        return mProductPrivAppDenyPermissions.get(packageName);
-    }
-
-    /**
-     * Read from "permission" tags in /system_ext/etc/permissions/*.xml
-     * @return Set of privileged permissions that are explicitly granted.
-     */
-    public ArraySet<String> getSystemExtPrivAppPermissions(String packageName) {
-        return mSystemExtPrivAppPermissions.get(packageName);
-    }
-
-    /**
-     * Read from "deny-permission" tags in /system_ext/etc/permissions/*.xml
-     * @return Set of privileged permissions that are explicitly denied.
-     */
-    public ArraySet<String> getSystemExtPrivAppDenyPermissions(String packageName) {
-        return mSystemExtPrivAppDenyPermissions.get(packageName);
-    }
-
-    public Map<String, Boolean> getOemPermissions(String packageName) {
-        final Map<String, Boolean> oemPermissions = mOemPermissions.get(packageName);
-        if (oemPermissions != null) {
-            return oemPermissions;
-        }
-        return Collections.emptyMap();
+    public PermissionAllowlist getPermissionAllowlist() {
+        return mPermissionAllowlist;
     }
 
     public ArrayMap<String, ArraySet<String>> getAllowedAssociations() {
@@ -1253,20 +1181,20 @@
                                     Environment.getApexDirectory().toPath() + "/")
                                     && ApexProperties.updatable().orElse(false);
                             if (vendor) {
-                                readPrivAppPermissions(parser, mVendorPrivAppPermissions,
-                                        mVendorPrivAppDenyPermissions);
+                                readPrivAppPermissions(parser,
+                                        mPermissionAllowlist.getVendorPrivilegedAppAllowlist());
                             } else if (product) {
-                                readPrivAppPermissions(parser, mProductPrivAppPermissions,
-                                        mProductPrivAppDenyPermissions);
+                                readPrivAppPermissions(parser,
+                                        mPermissionAllowlist.getProductPrivilegedAppAllowlist());
                             } else if (systemExt) {
-                                readPrivAppPermissions(parser, mSystemExtPrivAppPermissions,
-                                        mSystemExtPrivAppDenyPermissions);
+                                readPrivAppPermissions(parser,
+                                        mPermissionAllowlist.getSystemExtPrivilegedAppAllowlist());
                             } else if (apex) {
                                 readApexPrivAppPermissions(parser, permFile,
                                         Environment.getApexDirectory().toPath());
                             } else {
-                                readPrivAppPermissions(parser, mPrivAppPermissions,
-                                        mPrivAppDenyPermissions);
+                                readPrivAppPermissions(parser,
+                                        mPermissionAllowlist.getPrivilegedAppAllowlist());
                             }
                         } else {
                             logNotAllowedInPartition(name, permFile, parser);
@@ -1589,50 +1517,10 @@
         }
     }
 
-    private void readPrivAppPermissions(XmlPullParser parser,
-            ArrayMap<String, ArraySet<String>> grantMap,
-            ArrayMap<String, ArraySet<String>> denyMap)
+    private void readPrivAppPermissions(@NonNull XmlPullParser parser,
+            @NonNull ArrayMap<String, ArrayMap<String, Boolean>> allowlist)
             throws IOException, XmlPullParserException {
-        String packageName = parser.getAttributeValue(null, "package");
-        if (TextUtils.isEmpty(packageName)) {
-            Slog.w(TAG, "package is required for <privapp-permissions> in "
-                    + parser.getPositionDescription());
-            return;
-        }
-
-        ArraySet<String> permissions = grantMap.get(packageName);
-        if (permissions == null) {
-            permissions = new ArraySet<>();
-        }
-        ArraySet<String> denyPermissions = denyMap.get(packageName);
-        int depth = parser.getDepth();
-        while (XmlUtils.nextElementWithin(parser, depth)) {
-            String name = parser.getName();
-            if ("permission".equals(name)) {
-                String permName = parser.getAttributeValue(null, "name");
-                if (TextUtils.isEmpty(permName)) {
-                    Slog.w(TAG, "name is required for <permission> in "
-                            + parser.getPositionDescription());
-                    continue;
-                }
-                permissions.add(permName);
-            } else if ("deny-permission".equals(name)) {
-                String permName = parser.getAttributeValue(null, "name");
-                if (TextUtils.isEmpty(permName)) {
-                    Slog.w(TAG, "name is required for <deny-permission> in "
-                            + parser.getPositionDescription());
-                    continue;
-                }
-                if (denyPermissions == null) {
-                    denyPermissions = new ArraySet<>();
-                }
-                denyPermissions.add(permName);
-            }
-        }
-        grantMap.put(packageName, permissions);
-        if (denyPermissions != null) {
-            denyMap.put(packageName, denyPermissions);
-        }
+        readPermissionAllowlist(parser, allowlist, "privapp-permissions");
     }
 
     private void readInstallInUserType(XmlPullParser parser,
@@ -1683,14 +1571,21 @@
     }
 
     void readOemPermissions(XmlPullParser parser) throws IOException, XmlPullParserException {
+        readPermissionAllowlist(parser, mPermissionAllowlist.getOemAppAllowlist(),
+                "oem-permissions");
+    }
+
+    private static void readPermissionAllowlist(@NonNull XmlPullParser parser,
+            @NonNull ArrayMap<String, ArrayMap<String, Boolean>> allowlist, @NonNull String tagName)
+            throws IOException, XmlPullParserException {
         final String packageName = parser.getAttributeValue(null, "package");
         if (TextUtils.isEmpty(packageName)) {
-            Slog.w(TAG, "package is required for <oem-permissions> in "
+            Slog.w(TAG, "package is required for <" + tagName + "> in "
                     + parser.getPositionDescription());
             return;
         }
 
-        ArrayMap<String, Boolean> permissions = mOemPermissions.get(packageName);
+        ArrayMap<String, Boolean> permissions = allowlist.get(packageName);
         if (permissions == null) {
             permissions = new ArrayMap<>();
         }
@@ -1698,24 +1593,24 @@
         while (XmlUtils.nextElementWithin(parser, depth)) {
             final String name = parser.getName();
             if ("permission".equals(name)) {
-                final String permName = parser.getAttributeValue(null, "name");
-                if (TextUtils.isEmpty(permName)) {
+                final String permissionName = parser.getAttributeValue(null, "name");
+                if (TextUtils.isEmpty(permissionName)) {
                     Slog.w(TAG, "name is required for <permission> in "
                             + parser.getPositionDescription());
                     continue;
                 }
-                permissions.put(permName, Boolean.TRUE);
+                permissions.put(permissionName, Boolean.TRUE);
             } else if ("deny-permission".equals(name)) {
-                String permName = parser.getAttributeValue(null, "name");
-                if (TextUtils.isEmpty(permName)) {
+                String permissionName = parser.getAttributeValue(null, "name");
+                if (TextUtils.isEmpty(permissionName)) {
                     Slog.w(TAG, "name is required for <deny-permission> in "
                             + parser.getPositionDescription());
                     continue;
                 }
-                permissions.put(permName, Boolean.FALSE);
+                permissions.put(permissionName, Boolean.FALSE);
             }
         }
-        mOemPermissions.put(packageName, permissions);
+        allowlist.put(packageName, permissions);
     }
 
     private void readSplitPermission(XmlPullParser parser, File permFile)
@@ -1865,21 +1760,14 @@
             Path apexDirectoryPath) throws IOException, XmlPullParserException {
         final String moduleName =
                 getApexModuleNameFromFilePath(permFile.toPath(), apexDirectoryPath);
-        final ArrayMap<String, ArraySet<String>> privAppPermissions;
-        if (mApexPrivAppPermissions.containsKey(moduleName)) {
-            privAppPermissions = mApexPrivAppPermissions.get(moduleName);
-        } else {
-            privAppPermissions = new ArrayMap<>();
-            mApexPrivAppPermissions.put(moduleName, privAppPermissions);
+        final ArrayMap<String, ArrayMap<String, ArrayMap<String, Boolean>>> allowlists =
+                mPermissionAllowlist.getApexPrivilegedAppAllowlists();
+        ArrayMap<String, ArrayMap<String, Boolean>> allowlist = allowlists.get(moduleName);
+        if (allowlist == null) {
+            allowlist = new ArrayMap<>();
+            allowlists.put(moduleName, allowlist);
         }
-        final ArrayMap<String, ArraySet<String>> privAppDenyPermissions;
-        if (mApexPrivAppDenyPermissions.containsKey(moduleName)) {
-            privAppDenyPermissions = mApexPrivAppDenyPermissions.get(moduleName);
-        } else {
-            privAppDenyPermissions = new ArrayMap<>();
-            mApexPrivAppDenyPermissions.put(moduleName, privAppDenyPermissions);
-        }
-        readPrivAppPermissions(parser, privAppPermissions, privAppDenyPermissions);
+        readPrivAppPermissions(parser, allowlist);
     }
 
     private static boolean isSystemProcess() {
diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java
index 32afcca..ee922f9 100644
--- a/services/core/java/com/android/server/TelephonyRegistry.java
+++ b/services/core/java/com/android/server/TelephonyRegistry.java
@@ -92,6 +92,7 @@
 
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.app.IBatteryStats;
+import com.android.internal.telephony.ICarrierConfigChangeListener;
 import com.android.internal.telephony.ICarrierPrivilegesCallback;
 import com.android.internal.telephony.IOnSubscriptionsChangedListener;
 import com.android.internal.telephony.IPhoneStateListener;
@@ -155,6 +156,7 @@
         IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
         IOnSubscriptionsChangedListener onOpportunisticSubscriptionsChangedListenerCallback;
         ICarrierPrivilegesCallback carrierPrivilegesCallback;
+        ICarrierConfigChangeListener carrierConfigChangeListener;
 
         int callerUid;
         int callerPid;
@@ -183,6 +185,10 @@
             return carrierPrivilegesCallback != null;
         }
 
+        boolean matchCarrierConfigChangeListener() {
+            return carrierConfigChangeListener != null;
+        }
+
         boolean canReadCallLog() {
             try {
                 return TelephonyPermissions.checkReadCallLog(
@@ -201,6 +207,7 @@
                     + " onOpportunisticSubscriptionsChangedListenererCallback="
                     + onOpportunisticSubscriptionsChangedListenerCallback
                     + " carrierPrivilegesCallback=" + carrierPrivilegesCallback
+                    + " carrierConfigChangeListener=" + carrierConfigChangeListener
                     + " subId=" + subId + " phoneId=" + phoneId + " events=" + eventList + "}";
         }
     }
@@ -3044,6 +3051,82 @@
         }
     }
 
+    @Override
+    public void addCarrierConfigChangeListener(ICarrierConfigChangeListener listener,
+            String pkg, String featureId) {
+        final int callerUserId = UserHandle.getCallingUserId();
+        mAppOps.checkPackage(Binder.getCallingUid(), pkg);
+        if (VDBG) {
+            log("addCarrierConfigChangeListener pkg=" + pii(pkg) + " uid=" + Binder.getCallingUid()
+                    + " myUserId=" + UserHandle.myUserId() + " callerUerId" + callerUserId
+                    + " listener=" + listener + " listener.asBinder=" + listener.asBinder());
+        }
+
+        synchronized (mRecords) {
+            IBinder b = listener.asBinder();
+            boolean doesLimitApply = doesLimitApplyForListeners(Binder.getCallingUid(),
+                    Process.myUid());
+            Record r = add(b, Binder.getCallingUid(), Binder.getCallingPid(), doesLimitApply);
+
+            if (r == null) {
+                loge("Can not create Record instance!");
+                return;
+            }
+
+            r.context = mContext;
+            r.carrierConfigChangeListener = listener;
+            r.callingPackage = pkg;
+            r.callingFeatureId = featureId;
+            r.callerUid = Binder.getCallingUid();
+            r.callerPid = Binder.getCallingPid();
+            r.eventList = new ArraySet<>();
+            if (DBG) {
+                log("addCarrierConfigChangeListener:  Register r=" + r);
+            }
+        }
+    }
+
+    @Override
+    public void removeCarrierConfigChangeListener(ICarrierConfigChangeListener listener,
+            String pkg) {
+        if (DBG) log("removeCarrierConfigChangeListener listener=" + listener + ", pkg=" + pkg);
+        mAppOps.checkPackage(Binder.getCallingUid(), pkg);
+        remove(listener.asBinder());
+    }
+
+    @Override
+    public void notifyCarrierConfigChanged(int phoneId, int subId, int carrierId,
+            int specificCarrierId) {
+        if (!validatePhoneId(phoneId)) {
+            throw new IllegalArgumentException("Invalid phoneId: " + phoneId);
+        }
+        if (!checkNotifyPermission("notifyCarrierConfigChanged")) {
+            loge("Caller has no notify permission!");
+            return;
+        }
+        if (VDBG) {
+            log("notifyCarrierConfigChanged: phoneId=" + phoneId + ", subId=" + subId
+                    + ", carrierId=" + carrierId + ", specificCarrierId=" + specificCarrierId);
+        }
+
+        synchronized (mRecords) {
+            mRemoveList.clear();
+            for (Record r : mRecords) {
+                // Listeners are "global", neither per-slot nor per-sub, so no idMatch check here
+                if (!r.matchCarrierConfigChangeListener()) {
+                    continue;
+                }
+                try {
+                    r.carrierConfigChangeListener.onCarrierConfigChanged(phoneId, subId, carrierId,
+                            specificCarrierId);
+                } catch (RemoteException re) {
+                    mRemoveList.add(r.binder);
+                }
+            }
+            handleRemoveListLocked();
+        }
+    }
+
     @NeverCompile // Avoid size overhead of debugging code.
     @Override
     public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
diff --git a/services/core/java/com/android/server/VcnManagementService.java b/services/core/java/com/android/server/VcnManagementService.java
index 61f7f30..f652cb0 100644
--- a/services/core/java/com/android/server/VcnManagementService.java
+++ b/services/core/java/com/android/server/VcnManagementService.java
@@ -371,8 +371,9 @@
             return new LocationPermissionChecker(context);
         }
 
-        /** Gets the transports that need to be marked as restricted by the VCN */
-        public Set<Integer> getRestrictedTransports(
+        /** Gets transports that need to be marked as restricted by the VCN from CarrierConfig */
+        @VisibleForTesting(visibility = Visibility.PRIVATE)
+        public Set<Integer> getRestrictedTransportsFromCarrierConfig(
                 ParcelUuid subGrp, TelephonySubscriptionSnapshot lastSnapshot) {
             if (!Build.IS_ENG && !Build.IS_USERDEBUG) {
                 return RESTRICTED_TRANSPORTS_DEFAULT;
@@ -398,6 +399,22 @@
             }
             return restrictedTransports;
         }
+
+        /** Gets the transports that need to be marked as restricted by the VCN */
+        public Set<Integer> getRestrictedTransports(
+                ParcelUuid subGrp,
+                TelephonySubscriptionSnapshot lastSnapshot,
+                VcnConfig vcnConfig) {
+            final Set<Integer> restrictedTransports = new ArraySet<>();
+            restrictedTransports.addAll(vcnConfig.getRestrictedUnderlyingNetworkTransports());
+
+            // TODO: b/262269892 Remove the ability to configure restricted transports
+            // via CarrierConfig
+            restrictedTransports.addAll(
+                    getRestrictedTransportsFromCarrierConfig(subGrp, lastSnapshot));
+
+            return restrictedTransports;
+        }
     }
 
     /** Notifies the VcnManagementService that external dependencies can be set up. */
@@ -719,6 +736,7 @@
         if (mVcns.containsKey(subscriptionGroup)) {
             final Vcn vcn = mVcns.get(subscriptionGroup);
             vcn.updateConfig(config);
+            notifyAllPolicyListenersLocked();
         } else {
             // TODO(b/193687515): Support multiple VCNs active at the same time
             if (isActiveSubGroup(subscriptionGroup, mLastSnapshot)) {
@@ -936,7 +954,6 @@
     }
 
     /** Adds the provided listener for receiving VcnUnderlyingNetworkPolicy updates. */
-    @GuardedBy("mLock")
     @Override
     public void addVcnUnderlyingNetworkPolicyListener(
             @NonNull IVcnUnderlyingNetworkPolicyListener listener) {
@@ -963,16 +980,7 @@
         });
     }
 
-    @VisibleForTesting(visibility = Visibility.PRIVATE)
-    void addVcnUnderlyingNetworkPolicyListenerForTest(
-            @NonNull IVcnUnderlyingNetworkPolicyListener listener) {
-        synchronized (mLock) {
-            addVcnUnderlyingNetworkPolicyListener(listener);
-        }
-    }
-
     /** Removes the provided listener from receiving VcnUnderlyingNetworkPolicy updates. */
-    @GuardedBy("mLock")
     @Override
     public void removeVcnUnderlyingNetworkPolicyListener(
             @NonNull IVcnUnderlyingNetworkPolicyListener listener) {
@@ -1062,8 +1070,8 @@
                         isVcnManagedNetwork = true;
                     }
 
-                    final Set<Integer> restrictedTransports =
-                            mDeps.getRestrictedTransports(subGrp, mLastSnapshot);
+                    final Set<Integer> restrictedTransports = mDeps.getRestrictedTransports(
+                            subGrp, mLastSnapshot, mConfigs.get(subGrp));
                     for (int restrictedTransport : restrictedTransports) {
                         if (ncCopy.hasTransport(restrictedTransport)) {
                             if (restrictedTransport == TRANSPORT_CELLULAR) {
diff --git a/services/core/java/com/android/server/accounts/AccountManagerService.java b/services/core/java/com/android/server/accounts/AccountManagerService.java
index a2755be..88492ed 100644
--- a/services/core/java/com/android/server/accounts/AccountManagerService.java
+++ b/services/core/java/com/android/server/accounts/AccountManagerService.java
@@ -3558,8 +3558,7 @@
             Bundle.setDefusable(result, true);
             mNumResults++;
             Intent intent = null;
-            if (result != null
-                    && (intent = result.getParcelable(AccountManager.KEY_INTENT, android.content.Intent.class)) != null) {
+            if (result != null) {
                 if (!checkKeyIntent(
                         Binder.getCallingUid(),
                         result)) {
@@ -4928,8 +4927,10 @@
                 EventLog.writeEvent(0x534e4554, "250588548", authUid, "");
                 return false;
             }
-
             Intent intent = bundle.getParcelable(AccountManager.KEY_INTENT, Intent.class);
+            if (intent == null) {
+                return true;
+            }
             // Explicitly set an empty ClipData to ensure that we don't offer to
             // promote any Uris contained inside for granting purposes
             if (intent.getClipData() == null) {
@@ -4979,8 +4980,12 @@
             Bundle simulateBundle = p.readBundle();
             p.recycle();
             Intent intent = bundle.getParcelable(AccountManager.KEY_INTENT, Intent.class);
-            return (intent.filterEquals(simulateBundle.getParcelable(AccountManager.KEY_INTENT,
-                Intent.class)));
+            Intent simulateIntent = simulateBundle.getParcelable(AccountManager.KEY_INTENT,
+                    Intent.class);
+            if (intent == null) {
+                return (simulateIntent == null);
+            }
+            return intent.filterEquals(simulateIntent);
         }
 
         private boolean isExportedSystemActivity(ActivityInfo activityInfo) {
@@ -5129,8 +5134,7 @@
                     }
                 }
             }
-            if (result != null
-                    && (intent = result.getParcelable(AccountManager.KEY_INTENT, android.content.Intent.class)) != null) {
+            if (result != null) {
                 if (!checkKeyIntent(
                         Binder.getCallingUid(),
                         result)) {
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index 0d672bd..f72321c 100644
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -2787,8 +2787,8 @@
             }
         }
 
-        private final AppOpsManager.OnOpNotedListener mOpNotedCallback =
-                new AppOpsManager.OnOpNotedListener() {
+        private final AppOpsManager.OnOpNotedInternalListener mOpNotedCallback =
+                new AppOpsManager.OnOpNotedInternalListener() {
                     @Override
                     public void onOpNoted(int op, int uid, String pkgName,
                             String attributionTag, int flags, int result) {
@@ -2939,6 +2939,8 @@
 
     void unscheduleShortFgsTimeoutLocked(ServiceRecord sr) {
         mAm.mHandler.removeMessages(ActivityManagerService.SERVICE_SHORT_FGS_ANR_TIMEOUT_MSG, sr);
+        mAm.mHandler.removeMessages(ActivityManagerService.SERVICE_SHORT_FGS_PROCSTATE_TIMEOUT_MSG,
+                sr);
         mAm.mHandler.removeMessages(ActivityManagerService.SERVICE_SHORT_FGS_TIMEOUT_MSG, sr);
     }
 
@@ -2981,6 +2983,9 @@
     void onShortFgsTimeout(ServiceRecord sr) {
         synchronized (mAm) {
             if (!sr.shouldTriggerShortFgsTimeout()) {
+                if (DEBUG_SHORT_SERVICE) {
+                    Slog.d(TAG_SERVICE, "[STALE] Short FGS timed out: " + sr);
+                }
                 return;
             }
             Slog.e(TAG_SERVICE, "Short FGS timed out: " + sr);
@@ -2989,10 +2994,19 @@
             } catch (RemoteException e) {
                 // TODO(short-service): Anything to do here?
             }
-            // Schedule the ANR timeout.
-            final Message msg = mAm.mHandler.obtainMessage(
-                    ActivityManagerService.SERVICE_SHORT_FGS_ANR_TIMEOUT_MSG, sr);
-            mAm.mHandler.sendMessageAtTime(msg, sr.getShortFgsInfo().getAnrTime());
+            // Schedule the procstate demotion timeout and ANR timeout.
+            {
+                final Message msg = mAm.mHandler.obtainMessage(
+                        ActivityManagerService.SERVICE_SHORT_FGS_PROCSTATE_TIMEOUT_MSG, sr);
+                mAm.mHandler.sendMessageAtTime(
+                        msg, sr.getShortFgsInfo().getProcStateDemoteTime());
+            }
+
+            {
+                final Message msg = mAm.mHandler.obtainMessage(
+                        ActivityManagerService.SERVICE_SHORT_FGS_ANR_TIMEOUT_MSG, sr);
+                mAm.mHandler.sendMessageAtTime(msg, sr.getShortFgsInfo().getAnrTime());
+            }
         }
     }
 
@@ -3010,6 +3024,21 @@
         }
     }
 
+    void onShortFgsProcstateTimeout(ServiceRecord sr) {
+        synchronized (mAm) {
+            if (!sr.shouldDemoteShortFgsProcState()) {
+                if (DEBUG_SHORT_SERVICE) {
+                    Slog.d(TAG_SERVICE, "[STALE] Short FGS procstate demotion: " + sr);
+                }
+                return;
+            }
+
+            Slog.e(TAG_SERVICE, "Short FGS procstate demoted: " + sr);
+
+            mAm.updateOomAdjLocked(sr.app, OomAdjuster.OOM_ADJ_REASON_SHORT_FGS_TIMEOUT);
+        }
+    }
+
     void onShortFgsAnrTimeout(ServiceRecord sr) {
         final String reason = "A foreground service of FOREGROUND_SERVICE_TYPE_SHORT_SERVICE"
                 + " did not stop within a timeout: " + sr.getComponentName();
@@ -3021,6 +3050,9 @@
             tr.mLatencyTracker.waitingOnAMSLockEnded();
 
             if (!sr.shouldTriggerShortFgsAnr()) {
+                if (DEBUG_SHORT_SERVICE) {
+                    Slog.d(TAG_SERVICE, "[STALE] Short FGS ANR'ed: " + sr);
+                }
                 return;
             }
 
@@ -7713,4 +7745,35 @@
             Slog.e(TAG, "stopForegroundServiceDelegateLocked delegate does not exist");
         }
     }
+
+    private static void getClientPackages(ServiceRecord sr, ArraySet<String> output) {
+        var connections = sr.getConnections();
+        for (int conni = connections.size() - 1; conni >= 0; conni--) {
+            var connl = connections.valueAt(conni);
+            for (int i = 0, size = connl.size(); i < size; i++) {
+                var conn = connl.get(i);
+                if (conn.binding.client != null) {
+                    output.add(conn.binding.client.info.packageName);
+                }
+            }
+        }
+    }
+
+    /**
+     * Return all client package names of a service.
+     */
+    ArraySet<String> getClientPackagesLocked(@NonNull String servicePackageName) {
+        var results = new ArraySet<String>();
+        int[] users = mAm.mUserController.getUsers();
+        for (int ui = 0; ui < users.length; ui++) {
+            ArrayMap<ComponentName, ServiceRecord> alls = getServicesLocked(users[ui]);
+            for (int i = 0, size = alls.size(); i < size; i++) {
+                ServiceRecord sr = alls.valueAt(i);
+                if (sr.name.getPackageName().equals(servicePackageName)) {
+                    getClientPackages(sr, results);
+                }
+            }
+        }
+        return results;
+    }
 }
diff --git a/services/core/java/com/android/server/am/ActivityManagerConstants.java b/services/core/java/com/android/server/am/ActivityManagerConstants.java
index 2d69667..70f07a9 100644
--- a/services/core/java/com/android/server/am/ActivityManagerConstants.java
+++ b/services/core/java/com/android/server/am/ActivityManagerConstants.java
@@ -513,7 +513,7 @@
 
     // Allow app just moving from TOP to FOREGROUND_SERVICE to stay in a higher adj value for
     // this long.
-    public long TOP_TO_FGS_GRACE_DURATION = DEFAULT_TOP_TO_FGS_GRACE_DURATION;
+    public volatile long TOP_TO_FGS_GRACE_DURATION = DEFAULT_TOP_TO_FGS_GRACE_DURATION;
 
     /**
      * Allow app just leaving TOP with an already running ALMOST_PERCEPTIBLE service to stay in
@@ -1142,6 +1142,8 @@
                             case KEY_LOW_SWAP_THRESHOLD_PERCENT:
                                 updateLowSwapThresholdPercent();
                                 break;
+                            case KEY_TOP_TO_FGS_GRACE_DURATION:
+                                updateTopToFgsGraceDuration();
                             default:
                                 break;
                         }
@@ -1359,8 +1361,6 @@
                     DEFAULT_PROCESS_START_ASYNC);
             MEMORY_INFO_THROTTLE_TIME = mParser.getLong(KEY_MEMORY_INFO_THROTTLE_TIME,
                     DEFAULT_MEMORY_INFO_THROTTLE_TIME);
-            TOP_TO_FGS_GRACE_DURATION = mParser.getDurationMillis(KEY_TOP_TO_FGS_GRACE_DURATION,
-                    DEFAULT_TOP_TO_FGS_GRACE_DURATION);
             TOP_TO_ALMOST_PERCEPTIBLE_GRACE_DURATION = mParser.getDurationMillis(
                     KEY_TOP_TO_ALMOST_PERCEPTIBLE_GRACE_DURATION,
                     DEFAULT_TOP_TO_ALMOST_PERCEPTIBLE_GRACE_DURATION);
@@ -1790,6 +1790,13 @@
                 DEFAULT_LOW_SWAP_THRESHOLD_PERCENT);
     }
 
+    private void updateTopToFgsGraceDuration() {
+        TOP_TO_FGS_GRACE_DURATION = DeviceConfig.getLong(
+                DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
+                KEY_TOP_TO_FGS_GRACE_DURATION,
+                DEFAULT_TOP_TO_FGS_GRACE_DURATION);
+    }
+
     private void updateMinAssocLogDuration() {
         MIN_ASSOC_LOG_DURATION = DeviceConfig.getLong(
                 DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, KEY_MIN_ASSOC_LOG_DURATION,
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index efe14f4..045c757 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -137,6 +137,8 @@
 import static com.android.server.am.ProcessProfileRecord.HOSTING_COMPONENT_TYPE_SYSTEM;
 import static com.android.server.net.NetworkPolicyManagerInternal.updateBlockedReasonsWithProcState;
 import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;
+import static com.android.server.pm.UserManagerInternal.USER_START_MODE_BACKGROUND;
+import static com.android.server.pm.UserManagerInternal.USER_START_MODE_FOREGROUND;
 import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CLEANUP;
 import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SWITCH;
 import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CONFIGURATION;
@@ -220,6 +222,7 @@
 import android.compat.annotation.ChangeId;
 import android.compat.annotation.EnabledAfter;
 import android.compat.annotation.EnabledSince;
+import android.compat.annotation.Overridable;
 import android.content.AttributionSource;
 import android.content.AutofillOptions;
 import android.content.BroadcastReceiver;
@@ -328,6 +331,7 @@
 import android.util.ArraySet;
 import android.util.EventLog;
 import android.util.FeatureFlagUtils;
+import android.util.IndentingPrintWriter;
 import android.util.IntArray;
 import android.util.Log;
 import android.util.Pair;
@@ -606,6 +610,7 @@
      * This applies specifically to activities and broadcasts.
      */
     @ChangeId
+    @Overridable
     @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
     public static final long IMPLICIT_INTENTS_ONLY_MATCH_EXPORTED_COMPONENTS = 229362273;
 
@@ -759,6 +764,9 @@
     final AppErrors mAppErrors;
     final PackageWatchdog mPackageWatchdog;
 
+    @GuardedBy("mDeliveryGroupPolicyIgnoredActions")
+    private final ArraySet<String> mDeliveryGroupPolicyIgnoredActions = new ArraySet();
+
     /**
      * Uids of apps with current active camera sessions.  Access synchronized on
      * the IntArray instance itself, and no other locks must be acquired while that
@@ -1538,7 +1546,8 @@
     static final int DISPATCH_SENDING_BROADCAST_EVENT = 74;
     static final int DISPATCH_BINDING_SERVICE_EVENT = 75;
     static final int SERVICE_SHORT_FGS_TIMEOUT_MSG = 76;
-    static final int SERVICE_SHORT_FGS_ANR_TIMEOUT_MSG = 77;
+    static final int SERVICE_SHORT_FGS_PROCSTATE_TIMEOUT_MSG = 77;
+    static final int SERVICE_SHORT_FGS_ANR_TIMEOUT_MSG = 78;
 
     static final int FIRST_BROADCAST_QUEUE_MSG = 200;
 
@@ -1876,6 +1885,9 @@
                 case SERVICE_SHORT_FGS_TIMEOUT_MSG: {
                     mServices.onShortFgsTimeout((ServiceRecord) msg.obj);
                 } break;
+                case SERVICE_SHORT_FGS_PROCSTATE_TIMEOUT_MSG: {
+                    mServices.onShortFgsProcstateTimeout((ServiceRecord) msg.obj);
+                } break;
                 case SERVICE_SHORT_FGS_ANR_TIMEOUT_MSG: {
                     mServices.onShortFgsAnrTimeout((ServiceRecord) msg.obj);
                 } break;
@@ -12667,7 +12679,7 @@
      * @param platformCompat the instance of platform compat
      */
     private static void filterNonExportedComponents(Intent intent, int callingUid,
-            List query, PlatformCompat platformCompat, String callerPackage) {
+            List query, PlatformCompat platformCompat, String callerPackage, String resolvedType) {
         if (query == null
                 || intent.getPackage() != null
                 || intent.getComponent() != null
@@ -12694,19 +12706,24 @@
             } else {
                 continue;
             }
-            if (!platformCompat.isChangeEnabledByUid(
-                    IMPLICIT_INTENTS_ONLY_MATCH_EXPORTED_COMPONENTS, callingUid)) {
-                Slog.w(TAG, "Non-exported component not filtered out "
-                        + "(will be filtered out once the app targets U+)- intent: "
-                        + intent.getAction() + ", component: "
-                        + componentInfo + ", sender: "
-                        + callerPackage);
+            boolean hasToBeExportedToMatch = platformCompat.isChangeEnabledByUid(
+                    ActivityManagerService.IMPLICIT_INTENTS_ONLY_MATCH_EXPORTED_COMPONENTS,
+                    callingUid);
+            String[] categories = intent.getCategories() == null ? new String[0]
+                    : intent.getCategories().toArray(String[]::new);
+            FrameworkStatsLog.write(FrameworkStatsLog.UNSAFE_INTENT_EVENT_REPORTED,
+                    FrameworkStatsLog.UNSAFE_INTENT_EVENT_REPORTED__EVENT_TYPE__INTERNAL_NON_EXPORTED_COMPONENT_MATCH,
+                    callingUid,
+                    componentInfo,
+                    callerPackage,
+                    intent.getAction(),
+                    categories,
+                    resolvedType,
+                    intent.getScheme(),
+                    hasToBeExportedToMatch);
+            if (!hasToBeExportedToMatch) {
                 return;
             }
-            Slog.w(TAG, "Non-exported component filtered out - intent: "
-                    + intent.getAction() + ", component: "
-                    + componentInfo + ", sender: "
-                    + callerPackage);
             query.remove(i);
         }
     }
@@ -13560,9 +13577,10 @@
             // updating their receivers to be exempt from this requirement until their receivers
             // are flagged.
             if (requireExplicitFlagForDynamicReceivers) {
-                if ("com.google.android.apps.messaging".equals(callerPackage)) {
-                    // Note, a versionCode check for this package is not performed because it could
-                    // cause breakage with a subsequent update outside the system image.
+                if ("com.shannon.imsservice".equals(callerPackage)) {
+                    // Note, a versionCode check for this package is not performed because this
+                    // package consumes the SecurityException, so it wouldn't be caught during
+                    // presubmit.
                     requireExplicitFlagForDynamicReceivers = false;
                 }
             }
@@ -14620,7 +14638,7 @@
         }
 
         filterNonExportedComponents(intent, callingUid, registeredReceivers,
-                mPlatformCompat, callerPackage);
+                mPlatformCompat, callerPackage, resolvedType);
         int NR = registeredReceivers != null ? registeredReceivers.size() : 0;
         if (!ordered && NR > 0 && !mEnableModernQueue) {
             // If we are not serializing this broadcast, then send the
@@ -14726,7 +14744,7 @@
                 || resultTo != null) {
             BroadcastQueue queue = broadcastQueueForIntent(intent);
             filterNonExportedComponents(intent, callingUid, receivers,
-                    mPlatformCompat, callerPackage);
+                    mPlatformCompat, callerPackage, resolvedType);
             BroadcastRecord r = new BroadcastRecord(queue, intent, callerApp, callerPackage,
                     callerFeatureId, callingPid, callingUid, callerInstantApp, resolvedType,
                     requiredPermissions, excludedPermissions, excludedPackages, appOp, brOptions,
@@ -16566,14 +16584,14 @@
     @Override
     public boolean startUserInBackgroundWithListener(final int userId,
                 @Nullable IProgressListener unlockListener) {
-        return mUserController.startUser(userId, /* foreground */ false, unlockListener);
+        return mUserController.startUser(userId, USER_START_MODE_BACKGROUND, unlockListener);
     }
 
     @Override
     public boolean startUserInForegroundWithListener(final int userId,
             @Nullable IProgressListener unlockListener) {
         // Permission check done inside UserController.
-        return mUserController.startUser(userId, /* foreground */ true, unlockListener);
+        return mUserController.startUser(userId, USER_START_MODE_FOREGROUND, unlockListener);
     }
 
     @Override
@@ -18191,6 +18209,13 @@
                 mServices.stopForegroundServiceDelegateLocked(connection);
             }
         }
+
+        @Override
+        public ArraySet<String> getClientPackages(String servicePackageName) {
+            synchronized (ActivityManagerService.this) {
+                return mServices.getClientPackagesLocked(servicePackageName);
+            }
+        }
     }
 
     long inputDispatchingTimedOut(int pid, final boolean aboveSystem, TimeoutRecord timeoutRecord) {
@@ -18322,14 +18347,66 @@
         }
     }
 
-    public void waitForBroadcastBarrier(@Nullable PrintWriter pw) {
+    public void waitForBroadcastBarrier(@Nullable PrintWriter pw, boolean flushBroadcastLoopers) {
         enforceCallingPermission(permission.DUMP, "waitForBroadcastBarrier()");
-        BroadcastLoopers.waitForBarrier(pw);
+        if (flushBroadcastLoopers) {
+            BroadcastLoopers.waitForBarrier(pw);
+        }
         for (BroadcastQueue queue : mBroadcastQueues) {
             queue.waitForBarrier(pw);
         }
     }
 
+    void setIgnoreDeliveryGroupPolicy(@NonNull String broadcastAction) {
+        Objects.requireNonNull(broadcastAction);
+        enforceCallingPermission(permission.DUMP, "waitForBroadcastBarrier()");
+        synchronized (mDeliveryGroupPolicyIgnoredActions) {
+            mDeliveryGroupPolicyIgnoredActions.add(broadcastAction);
+        }
+    }
+
+    void clearIgnoreDeliveryGroupPolicy(@NonNull String broadcastAction) {
+        Objects.requireNonNull(broadcastAction);
+        enforceCallingPermission(permission.DUMP, "waitForBroadcastBarrier()");
+        synchronized (mDeliveryGroupPolicyIgnoredActions) {
+            mDeliveryGroupPolicyIgnoredActions.remove(broadcastAction);
+        }
+    }
+
+    boolean shouldIgnoreDeliveryGroupPolicy(@Nullable String broadcastAction) {
+        if (broadcastAction == null) {
+            return false;
+        }
+        synchronized (mDeliveryGroupPolicyIgnoredActions) {
+            return mDeliveryGroupPolicyIgnoredActions.contains(broadcastAction);
+        }
+    }
+
+    void dumpDeliveryGroupPolicyIgnoredActions(IndentingPrintWriter ipw) {
+        synchronized (mDeliveryGroupPolicyIgnoredActions) {
+            ipw.println(mDeliveryGroupPolicyIgnoredActions);
+        }
+    }
+
+    @Override
+    public void forceDelayBroadcastDelivery(@NonNull String targetPackage,
+            long delayedDurationMs) {
+        Objects.requireNonNull(targetPackage);
+        Preconditions.checkArgumentNonnegative(delayedDurationMs);
+        Preconditions.checkState(mEnableModernQueue, "Not valid in legacy queue");
+        enforceCallingPermission(permission.DUMP, "forceDelayBroadcastDelivery()");
+
+        for (BroadcastQueue queue : mBroadcastQueues) {
+            queue.forceDelayBroadcastDelivery(targetPackage, delayedDurationMs);
+        }
+    }
+
+    @Override
+    public boolean isModernBroadcastQueueEnabled() {
+        enforceCallingPermission(permission.DUMP, "isModernBroadcastQueueEnabled()");
+        return mEnableModernQueue;
+    }
+
     @Override
     @ReasonCode
     public int getBackgroundRestrictionExemptionReason(int uid) {
@@ -18486,7 +18563,7 @@
 
     @Override
     public int restartUserInBackground(final int userId) {
-        return mUserController.restartUser(userId, /* foreground */ false);
+        return mUserController.restartUser(userId, USER_START_MODE_BACKGROUND);
     }
 
     @Override
diff --git a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java
index 0b94798..4a6e5a3 100644
--- a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java
+++ b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java
@@ -345,6 +345,10 @@
                     return runWaitForBroadcastIdle(pw);
                 case "wait-for-broadcast-barrier":
                     return runWaitForBroadcastBarrier(pw);
+                case "set-ignore-delivery-group-policy":
+                    return runSetIgnoreDeliveryGroupPolicy(pw);
+                case "clear-ignore-delivery-group-policy":
+                    return runClearIgnoreDeliveryGroupPolicy(pw);
                 case "compat":
                     return runCompat(pw);
                 case "refresh-settings-cache":
@@ -1409,6 +1413,7 @@
                 mPw.println("shortMsg: " + shortMsg);
                 mPw.println("longMsg: " + longMsg);
                 mPw.println("timeMillis: " + timeMillis);
+                mPw.println("uptime: " + SystemClock.uptimeMillis());
                 mPw.println("stack:");
                 mPw.print(stackTrace);
                 mPw.println("#");
@@ -1425,6 +1430,7 @@
                 mPw.println("processName: " + processName);
                 mPw.println("processPid: " + pid);
                 mPw.println("annotation: " + annotation);
+                mPw.println("uptime: " + SystemClock.uptimeMillis());
                 mPw.flush();
                 int result = waitControllerLocked(pid, STATE_EARLY_ANR);
                 if (result == RESULT_EARLY_ANR_KILL) return -1;
@@ -1438,6 +1444,7 @@
                 mPw.println("** ERROR: PROCESS NOT RESPONDING");
                 mPw.println("processName: " + processName);
                 mPw.println("processPid: " + pid);
+                mPw.println("uptime: " + SystemClock.uptimeMillis());
                 mPw.println("processStats:");
                 mPw.print(processStats);
                 mPw.println("#");
@@ -2006,12 +2013,6 @@
     }
 
     int runSwitchUser(PrintWriter pw) throws RemoteException {
-        UserManager userManager = mInternal.mContext.getSystemService(UserManager.class);
-        final int userSwitchable = userManager.getUserSwitchability();
-        if (userSwitchable != UserManager.SWITCHABILITY_STATUS_OK) {
-            getErrPrintWriter().println("Error: " + userSwitchable);
-            return -1;
-        }
         boolean wait = false;
         String opt;
         while ((opt = getNextOption()) != null) {
@@ -2024,6 +2025,14 @@
         }
 
         int userId = Integer.parseInt(getNextArgRequired());
+
+        UserManager userManager = mInternal.mContext.getSystemService(UserManager.class);
+        final int userSwitchable = userManager.getUserSwitchability(UserHandle.of(userId));
+        if (userSwitchable != UserManager.SWITCHABILITY_STATUS_OK) {
+            getErrPrintWriter().println("Error: UserSwitchabilityResult=" + userSwitchable);
+            return -1;
+        }
+
         boolean switched;
         Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "shell_runSwitchUser");
         try {
@@ -3131,7 +3140,29 @@
     }
 
     int runWaitForBroadcastBarrier(PrintWriter pw) throws RemoteException {
-        mInternal.waitForBroadcastBarrier(pw);
+        boolean flushBroadcastLoopers = false;
+        String opt;
+        while ((opt = getNextOption()) != null) {
+            if (opt.equals("--flush-broadcast-loopers")) {
+                flushBroadcastLoopers = true;
+            } else {
+                getErrPrintWriter().println("Error: Unknown option: " + opt);
+                return -1;
+            }
+        }
+        mInternal.waitForBroadcastBarrier(pw, flushBroadcastLoopers);
+        return 0;
+    }
+
+    int runSetIgnoreDeliveryGroupPolicy(PrintWriter pw) throws RemoteException {
+        final String broadcastAction = getNextArgRequired();
+        mInternal.setIgnoreDeliveryGroupPolicy(broadcastAction);
+        return 0;
+    }
+
+    int runClearIgnoreDeliveryGroupPolicy(PrintWriter pw) throws RemoteException {
+        final String broadcastAction = getNextArgRequired();
+        mInternal.clearIgnoreDeliveryGroupPolicy(broadcastAction);
         return 0;
     }
 
@@ -4019,7 +4050,10 @@
                     + "background.");
             pw.println("  set-foreground-service-delegate [--user <USER_ID>] <PACKAGE> start|stop");
             pw.println("         Start/stop an app's foreground service delegate.");
-            pw.println();
+            pw.println("  set-ignore-delivery-group-policy <ACTION>");
+            pw.println("         Start ignoring delivery group policy set for a broadcast action");
+            pw.println("  clear-ignore-delivery-group-policy <ACTION>");
+            pw.println("         Stop ignoring delivery group policy set for a broadcast action");
             Intent.printIntentArgsHelp(pw, "");
         }
     }
diff --git a/services/core/java/com/android/server/am/BroadcastConstants.java b/services/core/java/com/android/server/am/BroadcastConstants.java
index f5d1c10..fe5888d 100644
--- a/services/core/java/com/android/server/am/BroadcastConstants.java
+++ b/services/core/java/com/android/server/am/BroadcastConstants.java
@@ -236,6 +236,15 @@
     private static final int DEFAULT_MAX_HISTORY_SUMMARY_SIZE =
             ActivityManager.isLowRamDeviceStatic() ? 25 : 300;
 
+    /**
+     * For {@link BroadcastQueueModernImpl}: Maximum number of broadcast receivers to process in a
+     * single synchronized block.  Up to this many messages may be dispatched in a single binder
+     * call.  Set this to 1 (or zero) for pre-batch behavior.
+     */
+    public int MAX_BROADCAST_BATCH_SIZE = DEFAULT_MAX_BROADCAST_BATCH_SIZE;
+    private static final String KEY_MAX_BROADCAST_BATCH_SIZE = "bcast_max_batch_size";
+    private static final int DEFAULT_MAX_BROADCAST_BATCH_SIZE = 1;
+
     // Settings override tracking for this instance
     private String mSettingsKey;
     private SettingsObserver mSettingsObserver;
@@ -373,6 +382,8 @@
                     DEFAULT_MAX_HISTORY_COMPLETE_SIZE);
             MAX_HISTORY_SUMMARY_SIZE = getDeviceConfigInt(KEY_MAX_HISTORY_SUMMARY_SIZE,
                     DEFAULT_MAX_HISTORY_SUMMARY_SIZE);
+            MAX_BROADCAST_BATCH_SIZE = getDeviceConfigInt(KEY_MAX_BROADCAST_BATCH_SIZE,
+                    DEFAULT_MAX_BROADCAST_BATCH_SIZE);
         }
     }
 
@@ -418,6 +429,7 @@
                     MAX_CONSECUTIVE_URGENT_DISPATCHES).println();
             pw.print(KEY_MAX_CONSECUTIVE_NORMAL_DISPATCHES,
                     MAX_CONSECUTIVE_NORMAL_DISPATCHES).println();
+            pw.print(KEY_MAX_BROADCAST_BATCH_SIZE, MAX_BROADCAST_BATCH_SIZE).println();
             pw.decreaseIndent();
             pw.println();
         }
diff --git a/services/core/java/com/android/server/am/BroadcastProcessQueue.java b/services/core/java/com/android/server/am/BroadcastProcessQueue.java
index 672392d..fceefad 100644
--- a/services/core/java/com/android/server/am/BroadcastProcessQueue.java
+++ b/services/core/java/com/android/server/am/BroadcastProcessQueue.java
@@ -170,6 +170,8 @@
     private int mCountInstrumented;
     private int mCountManifest;
 
+    private boolean mPrioritizeEarliest;
+
     private @UptimeMillisLong long mRunnableAt = Long.MAX_VALUE;
     private @Reason int mRunnableAtReason = REASON_EMPTY;
     private boolean mRunnableAtInvalidated;
@@ -181,6 +183,11 @@
     private String mCachedToString;
     private String mCachedToShortString;
 
+    /**
+     * The duration by which any broadcasts to this process need to be delayed
+     */
+    private long mForcedDelayedDurationMs;
+
     public BroadcastProcessQueue(@NonNull BroadcastConstants constants,
             @NonNull String processName, int uid) {
         this.constants = Objects.requireNonNull(constants);
@@ -273,7 +280,7 @@
      */
     @FunctionalInterface
     public interface BroadcastPredicate {
-        public boolean test(@NonNull BroadcastRecord r, int index);
+        boolean test(@NonNull BroadcastRecord r, int index);
     }
 
     /**
@@ -282,7 +289,7 @@
      */
     @FunctionalInterface
     public interface BroadcastConsumer {
-        public void accept(@NonNull BroadcastRecord r, int index);
+        void accept(@NonNull BroadcastRecord r, int index);
     }
 
     /**
@@ -416,6 +423,13 @@
     }
 
     /**
+     * Get package name of the first application loaded into this process.
+     */
+    public String getPackageName() {
+        return app.getApplicationInfo().packageName;
+    }
+
+    /**
      * Set the currently active broadcast to the next pending broadcast.
      */
     public void makeActiveNextPending() {
@@ -518,15 +532,13 @@
     }
 
     public void traceActiveBegin() {
-        final int cookie = mActive.receivers.get(mActiveIndex).hashCode();
         Trace.asyncTraceForTrackBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER,
-                runningTraceTrackName, mActive.toShortString() + " scheduled", cookie);
+                runningTraceTrackName, mActive.toShortString() + " scheduled", hashCode());
     }
 
     public void traceActiveEnd() {
-        final int cookie = mActive.receivers.get(mActiveIndex).hashCode();
         Trace.asyncTraceForTrackEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER,
-                runningTraceTrackName, cookie);
+                runningTraceTrackName, hashCode());
     }
 
     /**
@@ -553,6 +565,10 @@
         return mActive != null;
     }
 
+    void forceDelayBroadcastDelivery(long delayedDurationMs) {
+        mForcedDelayedDurationMs = delayedDurationMs;
+    }
+
     /**
      * Will thrown an exception if there are no pending broadcasts; relies on
      * {@link #isEmpty()} being false.
@@ -605,10 +621,11 @@
         final BroadcastRecord nextLPRecord = (BroadcastRecord) nextLPArgs.arg1;
         final int nextLPRecordIndex = nextLPArgs.argi1;
         final BroadcastRecord nextHPRecord = (BroadcastRecord) highPriorityQueue.peekFirst().arg1;
-        final boolean isLPQueueEligible =
-                consecutiveHighPriorityCount >= maxHighPriorityDispatchLimit
-                        && nextLPRecord.enqueueTime <= nextHPRecord.enqueueTime
-                        && !blockedOnOrderedDispatch(nextLPRecord, nextLPRecordIndex);
+        final boolean shouldConsiderLPQueue = (mPrioritizeEarliest
+                || consecutiveHighPriorityCount >= maxHighPriorityDispatchLimit);
+        final boolean isLPQueueEligible = shouldConsiderLPQueue
+                && nextLPRecord.enqueueTime <= nextHPRecord.enqueueTime
+                && !blockedOnOrderedDispatch(nextLPRecord, nextLPRecordIndex);
         return isLPQueueEligible ? lowPriorityQueue : highPriorityQueue;
     }
 
@@ -617,6 +634,17 @@
     }
 
     /**
+     * When {@code prioritizeEarliest} is set to {@code true}, then earliest enqueued
+     * broadcasts would be prioritized for dispatching, even if there are urgent broadcasts
+     * waiting. This is typically used in case there are callers waiting for "barrier" to be
+     * reached.
+     */
+    @VisibleForTesting
+    void setPrioritizeEarliest(boolean prioritizeEarliest) {
+        mPrioritizeEarliest = prioritizeEarliest;
+    }
+
+    /**
      * Returns null if there are no pending broadcasts
      */
     @Nullable SomeArgs peekNextBroadcast() {
@@ -715,6 +743,7 @@
     static final int REASON_BLOCKED = 4;
     static final int REASON_INSTRUMENTED = 5;
     static final int REASON_PERSISTENT = 6;
+    static final int REASON_FORCE_DELAYED = 7;
     static final int REASON_CONTAINS_FOREGROUND = 10;
     static final int REASON_CONTAINS_ORDERED = 11;
     static final int REASON_CONTAINS_ALARM = 12;
@@ -732,6 +761,7 @@
             REASON_BLOCKED,
             REASON_INSTRUMENTED,
             REASON_PERSISTENT,
+            REASON_FORCE_DELAYED,
             REASON_CONTAINS_FOREGROUND,
             REASON_CONTAINS_ORDERED,
             REASON_CONTAINS_ALARM,
@@ -753,6 +783,7 @@
             case REASON_BLOCKED: return "BLOCKED";
             case REASON_INSTRUMENTED: return "INSTRUMENTED";
             case REASON_PERSISTENT: return "PERSISTENT";
+            case REASON_FORCE_DELAYED: return "FORCE_DELAYED";
             case REASON_CONTAINS_FOREGROUND: return "CONTAINS_FOREGROUND";
             case REASON_CONTAINS_ORDERED: return "CONTAINS_ORDERED";
             case REASON_CONTAINS_ALARM: return "CONTAINS_ALARM";
@@ -782,6 +813,7 @@
      */
     private void updateRunnableAt() {
         final SomeArgs next = peekNextBroadcast();
+        mRunnableAtInvalidated = false;
         if (next != null) {
             final BroadcastRecord r = (BroadcastRecord) next.arg1;
             final int index = next.argi1;
@@ -795,7 +827,10 @@
                 return;
             }
 
-            if (mCountForeground > 0) {
+            if (mForcedDelayedDurationMs > 0) {
+                mRunnableAt = runnableAt + mForcedDelayedDurationMs;
+                mRunnableAtReason = REASON_FORCE_DELAYED;
+            } else if (mCountForeground > 0) {
                 mRunnableAt = runnableAt + constants.DELAY_URGENT_MILLIS;
                 mRunnableAtReason = REASON_CONTAINS_FOREGROUND;
             } else if (mCountInteractive > 0) {
diff --git a/services/core/java/com/android/server/am/BroadcastQueue.java b/services/core/java/com/android/server/am/BroadcastQueue.java
index 153ad1e..75e9336 100644
--- a/services/core/java/com/android/server/am/BroadcastQueue.java
+++ b/services/core/java/com/android/server/am/BroadcastQueue.java
@@ -233,6 +233,16 @@
     public abstract void waitForBarrier(@Nullable PrintWriter pw);
 
     /**
+     * Delays delivering broadcasts to the specified package.
+     *
+     * <p> Note that this is only valid for modern queue.
+     */
+    public void forceDelayBroadcastDelivery(@NonNull String targetPackage,
+            long delayedDurationMs) {
+        // No default implementation.
+    }
+
+    /**
      * Brief summary of internal state, useful for debugging purposes.
      */
     @GuardedBy("mService")
diff --git a/services/core/java/com/android/server/am/BroadcastQueueImpl.java b/services/core/java/com/android/server/am/BroadcastQueueImpl.java
index 1a72fef..8946ada1 100644
--- a/services/core/java/com/android/server/am/BroadcastQueueImpl.java
+++ b/services/core/java/com/android/server/am/BroadcastQueueImpl.java
@@ -73,6 +73,7 @@
 import android.util.SparseIntArray;
 import android.util.proto.ProtoOutputStream;
 
+import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.os.TimeoutRecord;
 import com.android.internal.util.FrameworkStatsLog;
 import com.android.server.LocalServices;
@@ -186,6 +187,14 @@
         }
     }
 
+    /**
+     * This single object allows the queue to dispatch receivers using scheduleReceiverList
+     * without constantly allocating new ReceiverInfo objects or ArrayLists.  This queue
+     * implementation is known to have a maximum size of one entry.
+     */
+    @VisibleForTesting
+    final BroadcastReceiverBatch mReceiverBatch = new BroadcastReceiverBatch(1);
+
     BroadcastQueueImpl(ActivityManagerService service, Handler handler,
             String name, BroadcastConstants constants, boolean allowDelayBehindServices,
             int schedGroup) {
@@ -388,10 +397,11 @@
                     + ": " + r);
             mService.notifyPackageUse(r.intent.getComponent().getPackageName(),
                                       PackageManager.NOTIFY_PACKAGE_USE_BROADCAST_RECEIVER);
-            thread.scheduleReceiver(prepareReceiverIntent(r.intent, r.curFilteredExtras),
+            thread.scheduleReceiverList(mReceiverBatch.manifestReceiver(
+                    prepareReceiverIntent(r.intent, r.curFilteredExtras),
                     r.curReceiver, null /* compatInfo (unused but need to keep method signature) */,
                     r.resultCode, r.resultData, r.resultExtras, r.ordered, r.userId,
-                    app.mState.getReportedProcState());
+                    app.mState.getReportedProcState()));
             if (DEBUG_BROADCAST)  Slog.v(TAG_BROADCAST,
                     "Process cur broadcast " + r + " DELIVERED for app " + app);
             started = true;
@@ -725,9 +735,10 @@
                 // If we have an app thread, do the call through that so it is
                 // correctly ordered with other one-way calls.
                 try {
-                    thread.scheduleRegisteredReceiver(receiver, intent, resultCode,
+                    thread.scheduleReceiverList(mReceiverBatch.registeredReceiver(
+                            receiver, intent, resultCode,
                             data, extras, ordered, sticky, sendingUser,
-                            app.mState.getReportedProcState());
+                            app.mState.getReportedProcState()));
                 } catch (RemoteException ex) {
                     // Failed to call into the process. It's either dying or wedged. Kill it gently.
                     synchronized (mService) {
diff --git a/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java b/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java
index e9340e9..a850c8a 100644
--- a/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java
+++ b/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java
@@ -87,10 +87,12 @@
 import java.io.PrintWriter;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
 import java.util.function.BooleanSupplier;
+import java.util.function.Consumer;
 import java.util.function.Predicate;
 
 /**
@@ -139,6 +141,11 @@
         // We configure runnable size only once at boot; it'd be too complex to
         // try resizing dynamically at runtime
         mRunning = new BroadcastProcessQueue[mConstants.getMaxRunningQueues()];
+
+        // Set up the statistics for batched broadcasts.
+        final int batchSize = mConstants.MAX_BROADCAST_BATCH_SIZE;
+        mReceiverBatch = new BroadcastReceiverBatch(batchSize);
+        Slog.i(TAG, "maximum broadcast batch size " + batchSize);
     }
 
     /**
@@ -201,6 +208,15 @@
     private final BroadcastConstants mBgConstants;
 
     /**
+     * The sole instance of BroadcastReceiverBatch that is used by scheduleReceiverWarmLocked().
+     * The class is not a true singleton but only one instance is needed for the broadcast queue.
+     * Although this is guarded by mService, it should never be accessed by any other function.
+     */
+    @VisibleForTesting
+    @GuardedBy("mService")
+    final BroadcastReceiverBatch mReceiverBatch;
+
+    /**
      * Timestamp when last {@link #testAllProcessQueues} failure was observed;
      * used for throttling log messages.
      */
@@ -567,7 +583,7 @@
         if (queue != null) {
             // If queue was running a broadcast, fail it
             if (queue.isActive()) {
-                finishReceiverLocked(queue, BroadcastRecord.DELIVERY_FAILURE,
+                finishReceiverActiveLocked(queue, BroadcastRecord.DELIVERY_FAILURE,
                         "onApplicationCleanupLocked");
             }
 
@@ -647,6 +663,9 @@
     }
 
     private void applyDeliveryGroupPolicy(@NonNull BroadcastRecord r) {
+        if (mService.shouldIgnoreDeliveryGroupPolicy(r.intent.getAction())) {
+            return;
+        }
         final int policy = (r.options != null)
                 ? r.options.getDeliveryGroupPolicy() : BroadcastOptions.DELIVERY_GROUP_POLICY_ALL;
         final BroadcastConsumer broadcastConsumer;
@@ -737,58 +756,62 @@
      * case where a broadcast is handled by a remote app, and the case where the
      * broadcast was finished locally without the remote app being involved.
      */
+    @GuardedBy("mService")
     private void scheduleReceiverWarmLocked(@NonNull BroadcastProcessQueue queue) {
         checkState(queue.isActive(), "isActive");
+        BroadcastReceiverBatch batch = mReceiverBatch;
+        batch.reset();
 
-        final BroadcastRecord r = queue.getActive();
-        final int index = queue.getActiveIndex();
-
-        if (r.terminalCount == 0) {
-            r.dispatchTime = SystemClock.uptimeMillis();
-            r.dispatchRealTime = SystemClock.elapsedRealtime();
-            r.dispatchClockTime = System.currentTimeMillis();
+        while (collectReceiverList(queue, batch)) {
+            if (batch.isFull()) {
+                break;
+            }
+            if (!shouldContinueScheduling(queue)) {
+                break;
+             }
+            if (queue.isEmpty()) {
+                break;
+            }
+            queue.makeActiveNextPending();
         }
-
-        if (maybeSkipReceiver(queue, r, index)) {
-            return;
-        }
-        dispatchReceivers(queue, r, index);
+        processReceiverList(queue, batch);
     }
 
     /**
      * Examine a receiver and possibly skip it.  The method returns true if the receiver is
      * skipped (and therefore no more work is required).
      */
-    private boolean maybeSkipReceiver(BroadcastProcessQueue queue, BroadcastRecord r, int index) {
+    private boolean maybeSkipReceiver(@NonNull BroadcastProcessQueue queue,
+            @NonNull BroadcastReceiverBatch batch, @NonNull BroadcastRecord r, int index) {
         final int oldDeliveryState = getDeliveryState(r, index);
         final ProcessRecord app = queue.app;
         final Object receiver = r.receivers.get(index);
 
         // If someone already finished this broadcast, finish immediately
         if (isDeliveryStateTerminal(oldDeliveryState)) {
-            enqueueFinishReceiver(queue, oldDeliveryState, "already terminal state");
+            batch.finish(r, index, oldDeliveryState, "already terminal state");
             return true;
         }
 
         // Consider additional cases where we'd want to finish immediately
         if (app.isInFullBackup()) {
-            enqueueFinishReceiver(queue, BroadcastRecord.DELIVERY_SKIPPED, "isInFullBackup");
+            batch.finish(r, index, BroadcastRecord.DELIVERY_SKIPPED, "isInFullBackup");
             return true;
         }
         if (mSkipPolicy.shouldSkip(r, receiver)) {
-            enqueueFinishReceiver(queue, BroadcastRecord.DELIVERY_SKIPPED, "mSkipPolicy");
+            batch.finish(r, index, BroadcastRecord.DELIVERY_SKIPPED, "mSkipPolicy");
             return true;
         }
         final Intent receiverIntent = r.getReceiverIntent(receiver);
         if (receiverIntent == null) {
-            enqueueFinishReceiver(queue, BroadcastRecord.DELIVERY_SKIPPED, "getReceiverIntent");
+            batch.finish(r, index, BroadcastRecord.DELIVERY_SKIPPED, "getReceiverIntent");
             return true;
         }
 
         // Ignore registered receivers from a previous PID
         if ((receiver instanceof BroadcastFilter)
                 && ((BroadcastFilter) receiver).receiverList.pid != app.getPid()) {
-            enqueueFinishReceiver(queue, BroadcastRecord.DELIVERY_SKIPPED,
+            batch.finish(r, index, BroadcastRecord.DELIVERY_SKIPPED,
                     "BroadcastFilter for mismatched PID");
             return true;
         }
@@ -797,6 +820,133 @@
     }
 
     /**
+     * Collect receivers into a list, to be dispatched in a single receiver list call.  Return
+     * true if remaining receivers in the queue should be examined, and false if the current list
+     * is complete.
+     */
+    private boolean collectReceiverList(@NonNull BroadcastProcessQueue queue,
+            @NonNull BroadcastReceiverBatch batch) {
+        final ProcessRecord app = queue.app;
+        final BroadcastRecord r = queue.getActive();
+        final int index = queue.getActiveIndex();
+        final Object receiver = r.receivers.get(index);
+        final Intent receiverIntent = r.getReceiverIntent(receiver);
+
+        if (r.terminalCount == 0) {
+            r.dispatchTime = SystemClock.uptimeMillis();
+            r.dispatchRealTime = SystemClock.elapsedRealtime();
+            r.dispatchClockTime = System.currentTimeMillis();
+        }
+        if (maybeSkipReceiver(queue, batch, r, index)) {
+            return true;
+        }
+
+        final IApplicationThread thread = app.getOnewayThread();
+        if (thread == null) {
+            batch.finish(r, index, BroadcastRecord.DELIVERY_FAILURE, "missing IApplicationThread");
+            return true;
+        }
+
+        if (receiver instanceof BroadcastFilter) {
+            batch.schedule(((BroadcastFilter) receiver).receiverList.receiver,
+                    receiverIntent, r.resultCode, r.resultData, r.resultExtras,
+                    r.ordered, r.initialSticky, r.userId,
+                    app.mState.getReportedProcState(), r, index);
+            // TODO: consider making registered receivers of unordered
+            // broadcasts report results to detect ANRs
+            if (!r.ordered) {
+                batch.success(r, index, BroadcastRecord.DELIVERY_DELIVERED, "assuming delivered");
+                return true;
+            }
+        } else {
+            batch.schedule(receiverIntent, ((ResolveInfo) receiver).activityInfo,
+                    null, r.resultCode, r.resultData, r.resultExtras, r.ordered, r.userId,
+                    app.mState.getReportedProcState(), r, index);
+        }
+
+        return false;
+    }
+
+    /**
+     * Process the information in a BroadcastReceiverBatch.  Elements in the finish and success
+     * lists are sent to enqueueFinishReceiver().  Elements in the receivers list are transmitted
+     * to the target in a single binder call.
+     */
+    private void processReceiverList(@NonNull BroadcastProcessQueue queue,
+            @NonNull BroadcastReceiverBatch batch) {
+        // Transmit the receiver list.
+        final ProcessRecord app = queue.app;
+        final IApplicationThread thread = app.getOnewayThread();
+
+        batch.recordBatch(thread instanceof SameProcessApplicationThread);
+
+        // Mark all the receivers that were discarded.  None of these have actually been scheduled.
+        for (int i = 0; i < batch.finished().size(); i++) {
+            final var finish = batch.finished().get(i);
+            enqueueFinishReceiver(queue, finish.r, finish.index, finish.deliveryState,
+                    finish.reason);
+        }
+        // Prepare for delivery of all receivers that are about to be scheduled.
+        for (int i = 0; i < batch.cookies().size(); i++) {
+            final var cookie = batch.cookies().get(i);
+            prepareToDispatch(queue, cookie.r, cookie.index);
+        }
+
+        // Notify on dispatch.  Note that receiver/cookies are recorded only if the thread is
+        // non-null and the list will therefore be sent.
+        for (int i = 0; i < batch.cookies().size(); i++) {
+            // Cookies and receivers are 1:1
+            final var cookie = batch.cookies().get(i);
+            final BroadcastRecord r = cookie.r;
+            final int index = cookie.index;
+            final Object receiver = r.receivers.get(index);
+            if (receiver instanceof BroadcastFilter) {
+                notifyScheduleRegisteredReceiver(queue.app, r, (BroadcastFilter) receiver);
+            } else {
+                notifyScheduleReceiver(queue.app, r, (ResolveInfo) receiver);
+            }
+        }
+
+        // Transmit the enqueued receivers.  The thread cannot be null because the lock has been
+        // held since collectReceiverList(), which will not add any receivers if the thread is null.
+        boolean remoteFailed = false;
+        if (batch.receivers().size()  > 0) {
+            try {
+                thread.scheduleReceiverList(batch.receivers());
+            } catch (RemoteException e) {
+                // Log the failure of the first receiver in the list.  Note that there must be at
+                // least one receiver/cookie to reach this point in the code, which means
+                // cookie[0] is a valid element.
+                final var info = batch.cookies().get(0);
+                final BroadcastRecord r = info.r;
+                final int index = info.index;
+                final Object receiver = r.receivers.get(index);
+                final String msg = "Failed to schedule " + r + " to " + receiver
+                                   + " via " + app + ": " + e;
+                logw(msg);
+                app.killLocked("Can't deliver broadcast", ApplicationExitInfo.REASON_OTHER, true);
+                remoteFailed = true;
+            }
+        }
+
+        if (!remoteFailed) {
+            // If transmission succeed, report all receivers that are assumed to be delivered.
+            for (int i = 0; i < batch.success().size(); i++) {
+                final var finish = batch.success().get(i);
+                enqueueFinishReceiver(queue, finish.r, finish.index, finish.deliveryState,
+                        finish.reason);
+            }
+        } else {
+            // If transmission failed, fail all receivers in the list.
+            for (int i = 0; i < batch.cookies().size(); i++) {
+                final var cookie = batch.cookies().get(i);
+                enqueueFinishReceiver(queue, cookie.r, cookie.index,
+                        BroadcastRecord.DELIVERY_FAILURE, "remote app");
+            }
+        }
+    }
+
+    /**
      * Return true if this receiver should be assumed to have been delivered.
      */
     private boolean isAssumedDelivered(BroadcastRecord r, int index) {
@@ -806,7 +956,8 @@
     /**
      * A receiver is about to be dispatched.  Start ANR timers, if necessary.
      */
-    private void dispatchReceivers(BroadcastProcessQueue queue, BroadcastRecord r, int index) {
+    private void prepareToDispatch(@NonNull BroadcastProcessQueue queue,
+            @NonNull BroadcastRecord r, int index) {
         final ProcessRecord app = queue.app;
         final Object receiver = r.receivers.get(index);
 
@@ -844,42 +995,6 @@
         if (DEBUG_BROADCAST) logv("Scheduling " + r + " to warm " + app);
         setDeliveryState(queue, app, r, index, receiver, BroadcastRecord.DELIVERY_SCHEDULED,
                 "scheduleReceiverWarmLocked");
-
-        final Intent receiverIntent = r.getReceiverIntent(receiver);
-        final IApplicationThread thread = app.getOnewayThread();
-        if (thread != null) {
-            try {
-                if (receiver instanceof BroadcastFilter) {
-                    notifyScheduleRegisteredReceiver(app, r, (BroadcastFilter) receiver);
-                    thread.scheduleRegisteredReceiver(
-                            ((BroadcastFilter) receiver).receiverList.receiver, receiverIntent,
-                            r.resultCode, r.resultData, r.resultExtras, r.ordered, r.initialSticky,
-                            r.userId, app.mState.getReportedProcState());
-
-                    // TODO: consider making registered receivers of unordered
-                    // broadcasts report results to detect ANRs
-                    if (assumeDelivered) {
-                        enqueueFinishReceiver(queue, BroadcastRecord.DELIVERY_DELIVERED,
-                                "assuming delivered");
-                    }
-                } else {
-                    notifyScheduleReceiver(app, r, (ResolveInfo) receiver);
-                    thread.scheduleReceiver(receiverIntent, ((ResolveInfo) receiver).activityInfo,
-                            null, r.resultCode, r.resultData, r.resultExtras, r.ordered, r.userId,
-                            app.mState.getReportedProcState());
-                }
-            } catch (RemoteException e) {
-                final String msg = "Failed to schedule " + r + " to " + receiver
-                        + " via " + app + ": " + e;
-                logw(msg);
-                app.killLocked("Can't deliver broadcast", ApplicationExitInfo.REASON_OTHER,
-                        ApplicationExitInfo.SUBREASON_UNDELIVERED_BROADCAST, true);
-                enqueueFinishReceiver(queue, BroadcastRecord.DELIVERY_FAILURE, "remote app");
-            }
-        } else {
-            enqueueFinishReceiver(queue, BroadcastRecord.DELIVERY_FAILURE,
-                    "missing IApplicationThread");
-        }
     }
 
     /**
@@ -894,9 +1009,10 @@
             mService.mOomAdjuster.mCachedAppOptimizer.unfreezeTemporarily(
                     app, OOM_ADJ_REASON_FINISH_RECEIVER);
             try {
-                thread.scheduleRegisteredReceiver(r.resultTo, r.intent,
+                thread.scheduleReceiverList(mReceiverBatch.registeredReceiver(
+                        r.resultTo, r.intent,
                         r.resultCode, r.resultData, r.resultExtras, false, r.initialSticky,
-                        r.userId, app.mState.getReportedProcState());
+                        r.userId, app.mState.getReportedProcState()));
             } catch (RemoteException e) {
                 final String msg = "Failed to schedule result of " + r + " via " + app + ": " + e;
                 logw(msg);
@@ -925,7 +1041,7 @@
     }
 
     private void deliveryTimeoutHardLocked(@NonNull BroadcastProcessQueue queue) {
-        finishReceiverLocked(queue, BroadcastRecord.DELIVERY_TIMEOUT,
+        finishReceiverActiveLocked(queue, BroadcastRecord.DELIVERY_TIMEOUT,
                 "deliveryTimeoutHardLocked");
     }
 
@@ -958,7 +1074,7 @@
             }
         }
 
-        return finishReceiverLocked(queue, BroadcastRecord.DELIVERY_DELIVERED, "remote app");
+        return finishReceiverActiveLocked(queue, BroadcastRecord.DELIVERY_DELIVERED, "remote app");
     }
 
     /**
@@ -974,7 +1090,10 @@
         return queue.isRunnable() && queue.isProcessWarm() && !shouldRetire;
     }
 
-    private boolean finishReceiverLocked(@NonNull BroadcastProcessQueue queue,
+    /**
+     * Terminate all active broadcasts on the queue.
+     */
+    private boolean finishReceiverActiveLocked(@NonNull BroadcastProcessQueue queue,
             @DeliveryState int deliveryState, @NonNull String reason) {
         if (!queue.isActive()) {
             logw("Ignoring finish; no active broadcast for " + queue);
@@ -1000,16 +1119,25 @@
 
         setDeliveryState(queue, app, r, index, receiver, deliveryState, reason);
 
+        final boolean early = r != queue.getActive() || index != queue.getActiveIndex();
+
         if (deliveryState == BroadcastRecord.DELIVERY_TIMEOUT) {
             r.anrCount++;
             if (app != null && !app.isDebugging()) {
                 mService.appNotResponding(queue.app, TimeoutRecord.forBroadcastReceiver(r.intent));
             }
-        } else {
+        } else if (!early) {
             mLocalHandler.removeMessages(MSG_DELIVERY_TIMEOUT_SOFT, queue);
             mLocalHandler.removeMessages(MSG_DELIVERY_TIMEOUT_HARD, queue);
         }
 
+        if (early) {
+            // This is an early receiver that was transmitted as part of a group.  The delivery
+            // state has been updated but don't make any further decisions.
+            traceEnd(cookie);
+            return false;
+        }
+
         final boolean res = shouldContinueScheduling(queue);
         if (res) {
             // We're on a roll; move onto the next broadcast for this process
@@ -1224,6 +1352,21 @@
         return didSomething;
     }
 
+    private void forEachMatchingQueue(
+            @NonNull Predicate<BroadcastProcessQueue> queuePredicate,
+            @NonNull Consumer<BroadcastProcessQueue> queueConsumer) {
+        for (int i = 0; i < mProcessQueues.size(); i++) {
+            BroadcastProcessQueue leaf = mProcessQueues.valueAt(i);
+            while (leaf != null) {
+                if (queuePredicate.test(leaf)) {
+                    queueConsumer.accept(leaf);
+                    updateRunnableList(leaf);
+                }
+                leaf = leaf.processNameNext;
+            }
+        }
+    }
+
     @Override
     public void start(@NonNull ContentResolver resolver) {
         mFgConstants.startObserving(mHandler, resolver);
@@ -1282,12 +1425,31 @@
         final CountDownLatch latch = new CountDownLatch(1);
         synchronized (mService) {
             mWaitingFor.add(Pair.create(condition, latch));
+            forEachMatchingQueue(QUEUE_PREDICATE_ANY,
+                    (q) -> q.setPrioritizeEarliest(true));
         }
         enqueueUpdateRunningList();
         try {
             latch.await();
         } catch (InterruptedException e) {
             throw new RuntimeException(e);
+        } finally {
+            synchronized (mService) {
+                if (mWaitingFor.isEmpty()) {
+                    forEachMatchingQueue(QUEUE_PREDICATE_ANY,
+                            (q) -> q.setPrioritizeEarliest(false));
+                }
+            }
+        }
+    }
+
+    @Override
+    public void forceDelayBroadcastDelivery(@NonNull String targetPackage,
+            long delayedDurationMs) {
+        synchronized (mService) {
+            forEachMatchingQueue(
+                    (q) -> targetPackage.equals(q.getPackageName()),
+                    (q) -> q.forceDelayBroadcastDelivery(delayedDurationMs));
         }
     }
 
@@ -1666,6 +1828,23 @@
         ipw.decreaseIndent();
         ipw.println();
 
+        ipw.println(" Broadcasts with ignored delivery group policies:");
+        ipw.increaseIndent();
+        mService.dumpDeliveryGroupPolicyIgnoredActions(ipw);
+        ipw.decreaseIndent();
+        ipw.println();
+
+        ipw.println("Batch statistics:");
+        ipw.increaseIndent();
+        {
+            final var stats = mReceiverBatch.getStatistics();
+            ipw.println("Finished         " + Arrays.toString(stats.finish));
+            ipw.println("DispatchedLocal  " + Arrays.toString(stats.local));
+            ipw.println("DispatchedRemote " + Arrays.toString(stats.remote));
+        }
+        ipw.decreaseIndent();
+        ipw.println();
+
         if (dumpConstants) {
             mConstants.dump(ipw);
         }
diff --git a/services/core/java/com/android/server/am/BroadcastReceiverBatch.java b/services/core/java/com/android/server/am/BroadcastReceiverBatch.java
new file mode 100644
index 0000000..a826458
--- /dev/null
+++ b/services/core/java/com/android/server/am/BroadcastReceiverBatch.java
@@ -0,0 +1,346 @@
+/*
+ * 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.server.am;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.app.ReceiverInfo;
+import android.content.Intent;
+import android.content.IIntentReceiver;
+import android.content.pm.ActivityInfo;
+import android.content.res.CompatibilityInfo;
+import android.os.Bundle;
+
+import com.android.internal.annotations.VisibleForTesting;
+
+import java.util.ArrayList;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * A batch of receiver instructions. This includes a list of finish requests and a list of
+ * receivers.  The instructions are for a single queue.  It is constructed and consumed in a single
+ * call to {@link BroadcastQueueModernImpl#scheduleReceiverWarmLocked}.  The list size is bounded by
+ * {@link BroadcastConstants#MAX_BROADCAST_BATCH_SIZE}.  Because this class is ephemeral and its use
+ * is bounded, it is pre-allocated to avoid allocating new objects every time it is used.
+ *
+ * The {@link #single} methods support the use of this class in {@link BroadcastQueueImpl}.  These
+ * methods simplify the use of {@link IApplicationThread#scheduleReceiverList} as a replacement
+ * for scheduleReceiver and scheduleRegisteredReceiver.
+ *
+ * This class is designed to be allocated once and constantly reused (call {@link #reset} between
+ * uses).  Objects needed by the instance are kept in a pool - all object allocation occurs when
+ * the instance is created, and no allocation occurs thereafter.  However, if the variable
+ * mDeepReceiverCopy is set true (it is false by default) then the method {@link #receivers} always
+ * returns newly allocated objects.  This is required for mock testing.
+ *
+ * This class is not thread-safe.  Instances must be protected by the caller.
+ * @hide
+ */
+final class BroadcastReceiverBatch {
+
+    /**
+     * If this is true then receivers() returns a deep copy of the ReceiveInfo array.  If this is
+     * false, receivers() returns a reference to the array.  A deep copy is needed only for the
+     * broadcast queue mocking tests.
+     */
+    @VisibleForTesting
+    boolean mDeepReceiverCopy = false;
+
+    /**
+     * A private pool implementation this class.
+     */
+    private static class Pool<T> {
+        final int size;
+        final ArrayList<T> pool;
+        int next;
+        Pool(int n, @NonNull Class<T> c) {
+            size = n;
+            pool = new ArrayList<>(size);
+            try {
+                for (int i = 0; i < size; i++) {
+                    pool.add(c.getDeclaredConstructor().newInstance());
+                }
+            } catch (Exception e) {
+                // This class is only used locally.  Turn any exceptions into something fatal.
+                throw new RuntimeException(e);
+            }
+        }
+        T next() {
+            return pool.get(next++);
+        }
+        void reset() {
+            next = 0;
+        }
+    }
+
+    /**
+     * The information needed to finish off a receiver.  This is valid only in the context of
+     * a queue.
+     */
+    static class FinishInfo {
+        BroadcastRecord r = null;
+        int index = 0;
+        int deliveryState = 0;
+        String reason = null;
+        FinishInfo set(@Nullable BroadcastRecord r, int index,
+                int deliveryState, @Nullable String reason) {
+            this.r = r;
+            this.index = index;
+            this.deliveryState = deliveryState;
+            this.reason = reason;
+            return this;
+        }
+    }
+
+    /**
+     * The information needed to recreate a receiver info.  The broadcast record can be null if the
+     * caller does not expect to need it later.
+     */
+    static class ReceiverCookie {
+        BroadcastRecord r = null;
+        int index = 0;
+        ReceiverCookie set(@Nullable BroadcastRecord r, int index) {
+            this.r = r;
+            this.index = index;
+            return this;
+        }
+    }
+
+    // The object pools.
+    final int mSize;
+    private final Pool<ReceiverInfo> receiverPool;
+    private final Pool<FinishInfo> finishPool;
+    private final Pool<ReceiverCookie> cookiePool;
+
+    // The accumulated data.  The receivers should be an ArrayList to be directly compatible
+    // with scheduleReceiverList().  The receivers array is not final because a new array must
+    // be created for every new call to scheduleReceiverList().
+    private final ArrayList<ReceiverInfo> mReceivers;
+    private final ArrayList<ReceiverCookie> mCookies;
+    private final ArrayList<FinishInfo> mFinished;
+    // The list of finish records to complete if the binder succeeds or fails.
+    private final ArrayList<FinishInfo> mSuccess;
+
+    BroadcastReceiverBatch(int size) {
+        mSize = size;
+        mReceivers = new ArrayList<>(mSize);
+        mCookies = new ArrayList<>(mSize);
+        mFinished = new ArrayList<>(mSize);
+        mSuccess = new ArrayList<>(mSize);
+
+        receiverPool = new Pool<>(mSize, ReceiverInfo.class);
+        finishPool = new Pool<>(mSize, FinishInfo.class);
+        cookiePool = new Pool<>(mSize, ReceiverCookie.class);
+        mStats = new Statistics(mSize);
+        reset();
+    }
+
+    void reset() {
+        mReceivers.clear();
+        mCookies.clear();
+        mFinished.clear();
+        mSuccess.clear();
+
+        receiverPool.reset();
+        finishPool.reset();
+        cookiePool.reset();
+    }
+
+    void finish(@Nullable BroadcastRecord r, int index,
+            int deliveryState, @Nullable String reason) {
+        mFinished.add(finishPool.next().set(r, index, deliveryState, reason));
+    }
+    void success(@Nullable BroadcastRecord r, int index,
+            int deliveryState, @Nullable String reason) {
+        mSuccess.add(finishPool.next().set(r, index, deliveryState, reason));
+    }
+    // Add a ReceiverInfo for a registered receiver.
+    void schedule(@Nullable IIntentReceiver receiver, Intent intent,
+            int resultCode, @Nullable String data, @Nullable Bundle extras, boolean ordered,
+            boolean sticky, int sendingUser, int processState,
+            @Nullable BroadcastRecord r, int index) {
+        ReceiverInfo ri = new ReceiverInfo();
+        ri.intent = intent;
+        ri.data = data;
+        ri.extras = extras;
+        ri.sendingUser = sendingUser;
+        ri.processState = processState;
+        ri.resultCode = resultCode;
+        ri.registered = true;
+        ri.receiver = receiver;
+        ri.ordered = ordered;
+        ri.sticky = sticky;
+        mReceivers.add(ri);
+        mCookies.add(cookiePool.next().set(r, index));
+    }
+    // Add a ReceiverInfo for a manifest receiver.
+    void schedule(@Nullable Intent intent, @Nullable ActivityInfo activityInfo,
+            @Nullable CompatibilityInfo compatInfo, int resultCode, @Nullable String data,
+            @Nullable Bundle extras, boolean sync, int sendingUser, int processState,
+            @Nullable BroadcastRecord r, int index) {
+        ReceiverInfo ri = new ReceiverInfo();
+        ri.intent = intent;
+        ri.data = data;
+        ri.extras = extras;
+        ri.sendingUser = sendingUser;
+        ri.processState = processState;
+        ri.resultCode = resultCode;
+        ri.registered = false;
+        ri.activityInfo = activityInfo;
+        ri.compatInfo = compatInfo;
+        ri.sync = sync;
+        mReceivers.add(ri);
+        mCookies.add(cookiePool.next().set(r, index));
+    }
+
+    /**
+     * Two convenience functions for dispatching a single receiver.  The functions start with a
+     * reset.  Then they create the ReceiverInfo array and return it.  Statistics are not
+     * collected.
+     */
+    ArrayList<ReceiverInfo> registeredReceiver(@Nullable IIntentReceiver receiver,
+            @Nullable Intent intent, int resultCode, @Nullable String data,
+            @Nullable Bundle extras, boolean ordered, boolean sticky,
+            int sendingUser, int processState) {
+        reset();
+        schedule(receiver, intent, resultCode, data, extras, ordered, sticky,
+                sendingUser, processState, null, 0);
+        return receivers();
+    }
+
+    ArrayList<ReceiverInfo> manifestReceiver(@Nullable Intent intent,
+            @Nullable ActivityInfo activityInfo, @Nullable CompatibilityInfo compatInfo,
+            int resultCode, @Nullable String data, @Nullable Bundle extras, boolean sync,
+            int sendingUser, int processState) {
+        reset();
+        schedule(intent, activityInfo, compatInfo, resultCode, data, extras, sync,
+                sendingUser, processState, null, 0);
+        return receivers();
+    }
+
+    // Return true if the batch is full.  Adding any more entries will throw an exception.
+    boolean isFull() {
+        return (mFinished.size() + mReceivers.size()) >= mSize;
+    }
+    int finishCount() {
+        return mFinished.size() + mSuccess.size();
+    }
+    int receiverCount() {
+        return mReceivers.size();
+    }
+
+    /**
+     * Create a deep copy of the receiver list.  This is only for testing which is confused when
+     * objects are reused.
+     */
+    private ArrayList<ReceiverInfo> copyReceiverInfo() {
+        ArrayList<ReceiverInfo> copy = new ArrayList<>();
+        for (int i = 0; i < mReceivers.size(); i++) {
+            final ReceiverInfo r = mReceivers.get(i);
+            final ReceiverInfo n = new ReceiverInfo();
+            n.intent = r.intent;
+            n.data = r.data;
+            n.extras = r.extras;
+            n.sendingUser = r.sendingUser;
+            n.processState = r.processState;
+            n.resultCode = r.resultCode;
+            n.registered = r.registered;
+            n.receiver = r.receiver;
+            n.ordered = r.ordered;
+            n.sticky = r.sticky;
+            n.activityInfo = r.activityInfo;
+            n.compatInfo = r.compatInfo;
+            n.sync = r.sync;
+            copy.add(n);
+        }
+        return copy;
+    }
+
+    /**
+     * Accessors for the accumulated instructions.  The important accessor is receivers(), since
+     * it can be modified to return a deep copy of the mReceivers array.
+     */
+    @NonNull
+    ArrayList<ReceiverInfo> receivers() {
+        if (!mDeepReceiverCopy) {
+            return mReceivers;
+        } else {
+            return copyReceiverInfo();
+        }
+    }
+    @NonNull
+    ArrayList<ReceiverCookie> cookies() {
+        return mCookies;
+    }
+    @NonNull
+    ArrayList<FinishInfo> finished() {
+        return mFinished;
+    }
+    @NonNull
+    ArrayList<FinishInfo> success() {
+        return mSuccess;
+    }
+
+    /**
+     * A simple POD for statistics.  The parameter is the size of the BroadcastReceiverBatch.
+     */
+    static class Statistics {
+        final int[] finish;
+        final int[] local;
+        final int[] remote;
+        Statistics(int size) {
+            finish = new int[size+1];
+            local = new int[size+1];
+            remote = new int[size+1];
+        }
+    }
+
+    private final Statistics mStats;
+
+    /**
+     * A unique counter that identifies individual transmission groups.  This is only used for
+     * debugging.  It is used to determine which receivers were sent in the same batch, and in
+     * which order.  This is static to distinguish between batches across all queues in the
+     * system.
+     */
+    private static final AtomicInteger sTransmitGroup = new AtomicInteger(0);
+
+    /**
+     * Record statistics for this batch of instructions.  This updates the local statistics and it
+     * updates the transmitGroup and transmitOrder fields of the BroadcastRecords being
+     * dispatched.
+     */
+    void recordBatch(boolean local) {
+        final int group = sTransmitGroup.addAndGet(1);
+        for (int i = 0; i < cookies().size(); i++) {
+            final var cookie = cookies().get(i);
+            cookie.r.transmitGroup[cookie.index] = group;
+            cookie.r.transmitOrder[cookie.index] = i;
+        }
+        mStats.finish[finishCount()]++;
+        if (local) {
+            mStats.local[receiverCount()]++;
+        } else {
+            mStats.remote[receiverCount()]++;
+        }
+    }
+
+    @NonNull
+    Statistics getStatistics() {
+        return mStats;
+    }
+}
diff --git a/services/core/java/com/android/server/am/BroadcastRecord.java b/services/core/java/com/android/server/am/BroadcastRecord.java
index 100b2db..24cf3d2 100644
--- a/services/core/java/com/android/server/am/BroadcastRecord.java
+++ b/services/core/java/com/android/server/am/BroadcastRecord.java
@@ -113,6 +113,8 @@
     @UptimeMillisLong       long finishTime;         // when broadcast finished
     final @UptimeMillisLong long[] scheduledTime;    // when each receiver was scheduled
     final @UptimeMillisLong long[] terminalTime;     // when each receiver was terminal
+    final                   int[] transmitGroup;     // the batch group for each receiver
+    final                   int[] transmitOrder;     // the position of the receiver in the group
     final boolean timeoutExempt;  // true if this broadcast is not subject to receiver timeouts
     int resultCode;         // current result code value.
     @Nullable String resultData;      // current result data value.
@@ -380,6 +382,8 @@
         blockedUntilTerminalCount = calculateBlockedUntilTerminalCount(receivers, _serialized);
         scheduledTime = new long[delivery.length];
         terminalTime = new long[delivery.length];
+        transmitGroup = new int[delivery.length];
+        transmitOrder = new int[delivery.length];
         resultToApp = _resultToApp;
         resultTo = _resultTo;
         resultCode = _resultCode;
@@ -433,6 +437,8 @@
         blockedUntilTerminalCount = from.blockedUntilTerminalCount;
         scheduledTime = from.scheduledTime;
         terminalTime = from.terminalTime;
+        transmitGroup = from.transmitGroup;
+        transmitOrder = from.transmitOrder;
         resultToApp = from.resultToApp;
         resultTo = from.resultTo;
         enqueueTime = from.enqueueTime;
diff --git a/services/core/java/com/android/server/am/ContentProviderHelper.java b/services/core/java/com/android/server/am/ContentProviderHelper.java
index 16055b9..d2fb7b5 100644
--- a/services/core/java/com/android/server/am/ContentProviderHelper.java
+++ b/services/core/java/com/android/server/am/ContentProviderHelper.java
@@ -22,6 +22,10 @@
 import static android.os.Process.PROC_SPACE_TERM;
 import static android.os.Process.SYSTEM_UID;
 
+import static com.android.internal.util.FrameworkStatsLog.GET_TYPE_ACCESSED_WITHOUT_PERMISSION;
+import static com.android.internal.util.FrameworkStatsLog.GET_TYPE_ACCESSED_WITHOUT_PERMISSION__LOCATION__AM_CHECK_URI_PERMISSION;
+import static com.android.internal.util.FrameworkStatsLog.GET_TYPE_ACCESSED_WITHOUT_PERMISSION__LOCATION__AM_ERROR;
+import static com.android.internal.util.FrameworkStatsLog.GET_TYPE_ACCESSED_WITHOUT_PERMISSION__LOCATION__AM_FRAMEWORK_PERMISSION;
 import static com.android.internal.util.FrameworkStatsLog.PROVIDER_ACQUISITION_EVENT_REPORTED;
 import static com.android.internal.util.FrameworkStatsLog.PROVIDER_ACQUISITION_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_COLD;
 import static com.android.internal.util.FrameworkStatsLog.PROVIDER_ACQUISITION_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM;
@@ -46,6 +50,7 @@
 import android.content.Context;
 import android.content.IContentProvider;
 import android.content.Intent;
+import android.content.PermissionChecker;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
@@ -1003,7 +1008,11 @@
                 };
                 mService.mHandler.postDelayed(providerNotResponding, 1000);
                 try {
-                    return holder.provider.getType(uri);
+                    final String type = holder.provider.getType(uri);
+                    if (type != null) {
+                        backgroundLogging(callingUid, callingPid, userId, uri, holder, type);
+                    }
+                    return type;
                 } finally {
                     mService.mHandler.removeCallbacks(providerNotResponding);
                     // We need to clear the identity to call removeContentProviderExternalUnchecked
@@ -1060,6 +1069,10 @@
                         Binder.restoreCallingIdentity(identity);
                     }
                     resultCallback.sendResult(result);
+                    final String type = result.getPairValue();
+                    if (type != null) {
+                        backgroundLogging(callingUid, callingPid, userId, uri, holder, type);
+                    }
                 }));
             } else {
                 resultCallback.sendResult(Bundle.EMPTY);
@@ -1070,6 +1083,63 @@
         }
     }
 
+    private void backgroundLogging(int callingUid, int callingPid, int userId, Uri uri,
+            ContentProviderHolder holder, String type) {
+        // Push the logging code in a different handlerThread.
+        try {
+            mService.mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    logGetTypeData(callingUid, callingPid, userId,
+                            uri, holder, type);
+                }
+            });
+        } catch (Exception e) {
+            // To ensure logging does not break the getType calls.
+        }
+    }
+
+    // Utility function to log the getTypeData calls
+    private void logGetTypeData(int callingUid, int callingPid, int userId, Uri uri,
+            ContentProviderHolder holder, String type) {
+        try {
+            boolean checkUser = true;
+            final String authority = uri.getAuthority();
+            if (isAuthorityRedirectedForCloneProfile(authority)) {
+                UserManagerInternal umInternal =
+                        LocalServices.getService(UserManagerInternal.class);
+                UserInfo userInfo = umInternal.getUserInfo(userId);
+
+                if (userInfo != null && userInfo.isCloneProfile()) {
+                    userId = umInternal.getProfileParentId(userId);
+                    checkUser = false;
+                }
+            }
+            final ProviderInfo cpi = holder.info;
+            final AttributionSource attributionSource =
+                    new AttributionSource.Builder(callingUid).build();
+            final String permissionCheck =
+                    checkContentProviderPermission(cpi, callingPid, callingUid,
+                            userId, checkUser, null);
+            if (permissionCheck != null) {
+                FrameworkStatsLog.write(GET_TYPE_ACCESSED_WITHOUT_PERMISSION,
+                        GET_TYPE_ACCESSED_WITHOUT_PERMISSION__LOCATION__AM_FRAMEWORK_PERMISSION,
+                        callingUid, authority, type);
+            } else if (cpi.forceUriPermissions
+                    && holder.provider.checkUriPermission(attributionSource,
+                            uri, callingUid, Intent.FLAG_GRANT_READ_URI_PERMISSION)
+                            != PermissionChecker.PERMISSION_GRANTED) {
+                FrameworkStatsLog.write(GET_TYPE_ACCESSED_WITHOUT_PERMISSION,
+                        GET_TYPE_ACCESSED_WITHOUT_PERMISSION__LOCATION__AM_CHECK_URI_PERMISSION,
+                        callingUid, authority, type);
+            }
+        } catch (Exception e) {
+            FrameworkStatsLog.write(GET_TYPE_ACCESSED_WITHOUT_PERMISSION,
+                    GET_TYPE_ACCESSED_WITHOUT_PERMISSION__LOCATION__AM_ERROR, callingUid,
+                    uri.getAuthority(), type);
+        }
+    }
+
     private boolean canClearIdentity(int callingPid, int callingUid, int userId) {
         if (UserHandle.getUserId(callingUid) == userId) {
             return true;
diff --git a/services/core/java/com/android/server/am/OomAdjuster.java b/services/core/java/com/android/server/am/OomAdjuster.java
index 66a8bab..dbd58eb 100644
--- a/services/core/java/com/android/server/am/OomAdjuster.java
+++ b/services/core/java/com/android/server/am/OomAdjuster.java
@@ -163,6 +163,7 @@
     static final int OOM_ADJ_REASON_ALLOWLIST = 10;
     static final int OOM_ADJ_REASON_PROCESS_BEGIN = 11;
     static final int OOM_ADJ_REASON_PROCESS_END = 12;
+    static final int OOM_ADJ_REASON_SHORT_FGS_TIMEOUT = 13;
 
     @IntDef(prefix = {"OOM_ADJ_REASON_"},
             value = {OOM_ADJ_REASON_NONE, OOM_ADJ_REASON_ACTIVITY, OOM_ADJ_REASON_FINISH_RECEIVER,
@@ -170,7 +171,8 @@
                     OOM_ADJ_REASON_UNBIND_SERVICE, OOM_ADJ_REASON_START_SERVICE,
                     OOM_ADJ_REASON_GET_PROVIDER, OOM_ADJ_REASON_REMOVE_PROVIDER,
                     OOM_ADJ_REASON_UI_VISIBILITY, OOM_ADJ_REASON_ALLOWLIST,
-                    OOM_ADJ_REASON_PROCESS_BEGIN, OOM_ADJ_REASON_PROCESS_END})
+                    OOM_ADJ_REASON_PROCESS_BEGIN, OOM_ADJ_REASON_PROCESS_END,
+                    OOM_ADJ_REASON_SHORT_FGS_TIMEOUT})
     @Retention(RetentionPolicy.SOURCE)
     public @interface OomAdjReason {}
 
@@ -202,6 +204,7 @@
                 return AppProtoEnums.OOM_ADJ_REASON_PROCESS_BEGIN;
             case OOM_ADJ_REASON_PROCESS_END:
                 return AppProtoEnums.OOM_ADJ_REASON_PROCESS_END;
+            case OOM_ADJ_REASON_SHORT_FGS_TIMEOUT: // TODO(short-service) add value to AppProtoEnums
             default:
                 return AppProtoEnums.OOM_ADJ_REASON_UNKNOWN_TO_PROTO;
         }
@@ -236,6 +239,8 @@
                 return OOM_ADJ_REASON_METHOD + "_processBegin";
             case OOM_ADJ_REASON_PROCESS_END:
                 return OOM_ADJ_REASON_METHOD + "_processEnd";
+            case OOM_ADJ_REASON_SHORT_FGS_TIMEOUT:
+                return OOM_ADJ_REASON_METHOD + "_shortFgs";
             default:
                 return "_unknown";
         }
@@ -704,7 +709,9 @@
                 ConnectionRecord cr = psr.getConnectionAt(i);
                 ProcessRecord service = (cr.flags & ServiceInfo.FLAG_ISOLATED_PROCESS) != 0
                         ? cr.binding.service.isolationHostProc : cr.binding.service.app;
-                if (service == null || service == pr) {
+                if (service == null || service == pr
+                        || ((service.mState.getMaxAdj() >= ProcessList.SYSTEM_ADJ)
+                                && (service.mState.getMaxAdj() < FOREGROUND_APP_ADJ))) {
                     continue;
                 }
                 containsCycle |= service.mState.isReachable();
@@ -724,7 +731,9 @@
             for (int i = ppr.numberOfProviderConnections() - 1; i >= 0; i--) {
                 ContentProviderConnection cpc = ppr.getProviderConnectionAt(i);
                 ProcessRecord provider = cpc.provider.proc;
-                if (provider == null || provider == pr) {
+                if (provider == null || provider == pr
+                        || ((provider.mState.getMaxAdj() >= ProcessList.SYSTEM_ADJ)
+                                && (provider.mState.getMaxAdj() < FOREGROUND_APP_ADJ))) {
                     continue;
                 }
                 containsCycle |= provider.mState.isReachable();
diff --git a/services/core/java/com/android/server/am/ProcessRecord.java b/services/core/java/com/android/server/am/ProcessRecord.java
index 4706c268..33d7f9d 100644
--- a/services/core/java/com/android/server/am/ProcessRecord.java
+++ b/services/core/java/com/android/server/am/ProcessRecord.java
@@ -1016,6 +1016,11 @@
         return mWindowProcessController.hasRecentTasks();
     }
 
+    @GuardedBy("mService")
+    public ApplicationInfo getApplicationInfo() {
+        return info;
+    }
+
     @GuardedBy({"mService", "mProcLock"})
     boolean onCleanupApplicationRecordLSP(ProcessStatsService processStats, boolean allowRestart,
             boolean unlinkDeath) {
diff --git a/services/core/java/com/android/server/am/ProcessStatsService.java b/services/core/java/com/android/server/am/ProcessStatsService.java
index 438a2d43..bac9253 100644
--- a/services/core/java/com/android/server/am/ProcessStatsService.java
+++ b/services/core/java/com/android/server/am/ProcessStatsService.java
@@ -634,7 +634,6 @@
             if (files != null) {
                 String highWaterMarkStr =
                         DateFormat.format("yyyy-MM-dd-HH-mm-ss", highWaterMarkMs).toString();
-                ProcessStats stats = new ProcessStats(false);
                 for (int i = files.size() - 1; i >= 0; i--) {
                     String fileName = files.get(i);
                     try {
@@ -647,7 +646,7 @@
                                     new File(fileName),
                                     ParcelFileDescriptor.MODE_READ_ONLY);
                             InputStream is = new ParcelFileDescriptor.AutoCloseInputStream(pfd);
-                            stats.reset();
+                            final ProcessStats stats = new ProcessStats(false);
                             stats.read(is);
                             is.close();
                             if (stats.mTimePeriodStartClock > newHighWaterMark) {
diff --git a/services/core/java/com/android/server/am/SameProcessApplicationThread.java b/services/core/java/com/android/server/am/SameProcessApplicationThread.java
index a3c0111..62fd6e9 100644
--- a/services/core/java/com/android/server/am/SameProcessApplicationThread.java
+++ b/services/core/java/com/android/server/am/SameProcessApplicationThread.java
@@ -18,6 +18,7 @@
 
 import android.annotation.NonNull;
 import android.app.IApplicationThread;
+import android.app.ReceiverInfo;
 import android.content.IIntentReceiver;
 import android.content.Intent;
 import android.content.pm.ActivityInfo;
@@ -26,6 +27,7 @@
 import android.os.Handler;
 import android.os.RemoteException;
 
+import java.util.List;
 import java.util.Objects;
 
 /**
@@ -70,4 +72,20 @@
             }
         });
     }
+
+    @Override
+    public void scheduleReceiverList(List<ReceiverInfo> info) {
+        for (int i = 0; i < info.size(); i++) {
+            ReceiverInfo r = info.get(i);
+            if (r.registered) {
+                scheduleRegisteredReceiver(r.receiver, r.intent,
+                        r.resultCode, r.data, r.extras, r.ordered, r.sticky,
+                        r.sendingUser, r.processState);
+            } else {
+                scheduleReceiver(r.intent, r.activityInfo, r.compatInfo,
+                        r.resultCode, r.data, r.extras, r.sync,
+                        r.sendingUser, r.processState);
+            }
+        }
+    }
 }
diff --git a/services/core/java/com/android/server/am/ServiceRecord.java b/services/core/java/com/android/server/am/ServiceRecord.java
index ef195aa..05726f4 100644
--- a/services/core/java/com/android/server/am/ServiceRecord.java
+++ b/services/core/java/com/android/server/am/ServiceRecord.java
@@ -1416,7 +1416,21 @@
                 || !mShortFgsInfo.isCurrent()) {
             return false;
         }
-        return mShortFgsInfo.getTimeoutTime() < SystemClock.uptimeMillis();
+        return mShortFgsInfo.getTimeoutTime() <= SystemClock.uptimeMillis();
+    }
+
+    /**
+     * @return true if it's a short FGS's procstate should be demoted.
+     */
+    public boolean shouldDemoteShortFgsProcState() {
+        if (!isAppAlive()) {
+            return false;
+        }
+        if (!this.startRequested || !isShortFgs() || mShortFgsInfo == null
+                || !mShortFgsInfo.isCurrent()) {
+            return false;
+        }
+        return mShortFgsInfo.getProcStateDemoteTime() <= SystemClock.uptimeMillis();
     }
 
     /**
@@ -1431,7 +1445,7 @@
                 || !mShortFgsInfo.isCurrent()) {
             return false;
         }
-        return mShortFgsInfo.getAnrTime() < SystemClock.uptimeMillis();
+        return mShortFgsInfo.getAnrTime() <= SystemClock.uptimeMillis();
     }
 
     private boolean isAppAlive() {
diff --git a/services/core/java/com/android/server/am/TEST_MAPPING b/services/core/java/com/android/server/am/TEST_MAPPING
index 2a69363..4e1d1ca 100644
--- a/services/core/java/com/android/server/am/TEST_MAPPING
+++ b/services/core/java/com/android/server/am/TEST_MAPPING
@@ -97,6 +97,15 @@
         { "include-filter": "com.android.server.am.BroadcastQueueTest" },
         { "include-filter": "com.android.server.am.BroadcastQueueModernImplTest" }
       ]
+    },
+    {
+      "file_patterns": ["Broadcast"],
+      "name": "CtsBroadcastTestCases",
+      "options": [
+        { "exclude-annotation": "androidx.test.filters.LargeTest" },
+        { "exclude-annotation": "androidx.test.filters.FlakyTest" },
+        { "exclude-annotation": "org.junit.Ignore" }
+      ]
     }
   ],
   "presubmit-large": [
diff --git a/services/core/java/com/android/server/am/UserController.java b/services/core/java/com/android/server/am/UserController.java
index aefa2f5..e5123ef 100644
--- a/services/core/java/com/android/server/am/UserController.java
+++ b/services/core/java/com/android/server/am/UserController.java
@@ -46,6 +46,11 @@
 import static com.android.server.am.UserState.STATE_RUNNING_LOCKED;
 import static com.android.server.am.UserState.STATE_RUNNING_UNLOCKED;
 import static com.android.server.am.UserState.STATE_RUNNING_UNLOCKING;
+import static com.android.server.pm.UserManagerInternal.USER_ASSIGNMENT_RESULT_FAILURE;
+import static com.android.server.pm.UserManagerInternal.USER_START_MODE_BACKGROUND_VISIBLE;
+import static com.android.server.pm.UserManagerInternal.USER_START_MODE_FOREGROUND;
+import static com.android.server.pm.UserManagerInternal.userAssignmentResultToString;
+import static com.android.server.pm.UserManagerInternal.userStartModeToString;
 
 import android.annotation.IntDef;
 import android.annotation.NonNull;
@@ -119,6 +124,7 @@
 import com.android.server.am.UserState.KeyEvictedCallback;
 import com.android.server.pm.UserManagerInternal;
 import com.android.server.pm.UserManagerInternal.UserLifecycleListener;
+import com.android.server.pm.UserManagerInternal.UserStartMode;
 import com.android.server.pm.UserManagerService;
 import com.android.server.utils.Slogf;
 import com.android.server.utils.TimingsTraceAndSlog;
@@ -903,14 +909,14 @@
         });
     }
 
-    int restartUser(final int userId, final boolean foreground) {
+    int restartUser(final int userId, @UserStartMode int userStartMode) {
         return stopUser(userId, /* force= */ true, /* allowDelayedLocking= */ false,
                 /* stopUserCallback= */ null, new KeyEvictedCallback() {
                     @Override
                     public void keyEvicted(@UserIdInt int userId) {
                         // Post to the same handler that this callback is called from to ensure
                         // the user cleanup is complete before restarting.
-                        mHandler.post(() -> UserController.this.startUser(userId, foreground));
+                        mHandler.post(() -> UserController.this.startUser(userId, userStartMode));
                     }
                 });
     }
@@ -1267,7 +1273,7 @@
                 if (userStart.userId == userId) {
                     Slogf.i(TAG, "resumePendingUserStart for" + userStart);
                     mHandler.post(() -> startUser(userStart.userId,
-                            userStart.isForeground, userStart.unlockListener));
+                            userStart.userStartMode, userStart.unlockListener));
 
                     handledUserStarts.add(userStart);
                 }
@@ -1450,7 +1456,7 @@
         for (; i < profilesToStartSize && i < (getMaxRunningUsers() - 1); ++i) {
             // NOTE: this method is setting the profiles of the current user - which is always
             // assigned to the default display
-            startUser(profilesToStart.get(i).id, /* foreground= */ false);
+            startUser(profilesToStart.get(i).id, USER_START_MODE_BACKGROUND_VISIBLE);
         }
         if (i < profilesToStartSize) {
             Slogf.w(TAG, "More profiles than MAX_RUNNING_USERS");
@@ -1492,18 +1498,20 @@
             return false;
         }
 
-        return startUserNoChecks(userId, Display.DEFAULT_DISPLAY, /* foreground= */ false,
-                /* unlockListener= */ null);
+        return startUserNoChecks(userId, Display.DEFAULT_DISPLAY,
+                USER_START_MODE_BACKGROUND_VISIBLE, /* unlockListener= */ null);
     }
 
     @VisibleForTesting
-    boolean startUser(final @UserIdInt int userId, final boolean foreground) {
-        return startUser(userId, foreground, null);
+    boolean startUser(@UserIdInt int userId, @UserStartMode int userStartMode) {
+        return startUser(userId, userStartMode, /* unlockListener= */ null);
     }
 
     /**
      * Start user, if its not already running.
-     * <p>The user will be brought to the foreground, if {@code foreground} parameter is set.
+     *
+     * <p>The user will be brought to the foreground, if {@code userStartMode} parameter is
+     * set to {@link UserManagerInternal#USER_START_MODE_FOREGROUND}
      * When starting the user, multiple intents will be broadcast in the following order:</p>
      * <ul>
      *     <li>{@link Intent#ACTION_USER_STARTED} - sent to registered receivers of the new user
@@ -1529,17 +1537,15 @@
      * </ul>
      *
      * @param userId ID of the user to start
-     * @param foreground true if user should be brought to the foreground
+     * @param userStartMode user starting mode
      * @param unlockListener Listener to be informed when the user has started and unlocked.
      * @return true if the user has been successfully started
      */
-    boolean startUser(
-            final @UserIdInt int userId,
-            final boolean foreground,
+    boolean startUser(@UserIdInt int userId, @UserStartMode int userStartMode,
             @Nullable IProgressListener unlockListener) {
         checkCallingPermission(INTERACT_ACROSS_USERS_FULL, "startUser");
 
-        return startUserNoChecks(userId, Display.DEFAULT_DISPLAY, foreground, unlockListener);
+        return startUserNoChecks(userId, Display.DEFAULT_DISPLAY, userStartMode, unlockListener);
     }
 
     /**
@@ -1565,14 +1571,8 @@
         checkCallingHasOneOfThosePermissions("startUserOnSecondaryDisplay",
                 MANAGE_USERS, INTERACT_ACROSS_USERS);
 
-        // DEFAULT_DISPLAY is used for the current foreground user only
-        // TODO(b/245939659): might need to move this check to UserVisibilityMediator to support
-        // passenger-only screens
-        Preconditions.checkArgument(displayId != Display.DEFAULT_DISPLAY,
-                "Cannot use DEFAULT_DISPLAY");
-
         try {
-            return startUserNoChecks(userId, displayId, /* foreground= */ false,
+            return startUserNoChecks(userId, displayId, USER_START_MODE_BACKGROUND_VISIBLE,
                     /* unlockListener= */ null);
         } catch (RuntimeException e) {
             Slogf.e(TAG, "startUserOnSecondaryDisplay(%d, %d) failed: %s", userId, displayId, e);
@@ -1580,26 +1580,29 @@
         }
     }
 
-    private boolean startUserNoChecks(@UserIdInt int userId, int displayId, boolean foreground,
-            @Nullable IProgressListener unlockListener) {
+    private boolean startUserNoChecks(@UserIdInt int userId, int displayId,
+            @UserStartMode int userStartMode, @Nullable IProgressListener unlockListener) {
         TimingsTraceAndSlog t = new TimingsTraceAndSlog();
 
         t.traceBegin("UserController.startUser-" + userId
                 + (displayId == Display.DEFAULT_DISPLAY ? "" : "-display-" + displayId)
-                + "-" + (foreground ? "fg" : "bg"));
+                + "-" + (userStartMode == USER_START_MODE_FOREGROUND ? "fg" : "bg")
+                + "-start-mode-" + userStartMode);
         try {
-            return startUserInternal(userId, displayId, foreground, unlockListener, t);
+            return startUserInternal(userId, displayId, userStartMode, unlockListener, t);
         } finally {
             t.traceEnd();
         }
     }
 
-    private boolean startUserInternal(@UserIdInt int userId, int displayId, boolean foreground,
-            @Nullable IProgressListener unlockListener, @NonNull TimingsTraceAndSlog t) {
+    private boolean startUserInternal(@UserIdInt int userId, int displayId,
+            @UserStartMode int userStartMode, @Nullable IProgressListener unlockListener,
+            TimingsTraceAndSlog t) {
         if (DEBUG_MU) {
-            Slogf.i(TAG, "Starting user %d on display %d%s", userId, displayId,
-                    foreground ? " in foreground" : "");
+            Slogf.i(TAG, "Starting user %d on display %d with mode  %s", userId, displayId,
+                    userStartModeToString(userStartMode));
         }
+        boolean foreground = userStartMode == USER_START_MODE_FOREGROUND;
 
         boolean onSecondaryDisplay = displayId != Display.DEFAULT_DISPLAY;
         if (onSecondaryDisplay) {
@@ -1664,13 +1667,13 @@
 
             t.traceBegin("assignUserToDisplayOnStart");
             int result = mInjector.getUserManagerInternal().assignUserToDisplayOnStart(userId,
-                    userInfo.profileGroupId, foreground, displayId);
+                    userInfo.profileGroupId, userStartMode, displayId);
             t.traceEnd();
 
-            if (result == UserManagerInternal.USER_ASSIGNMENT_RESULT_FAILURE) {
+            if (result == USER_ASSIGNMENT_RESULT_FAILURE) {
                 Slogf.e(TAG, "%s user(%d) / display (%d) assignment failed: %s",
-                        (foreground ? "fg" : "bg"), userId, displayId,
-                        UserManagerInternal.userAssignmentResultToString(result));
+                        userStartModeToString(userStartMode), userId, displayId,
+                        userAssignmentResultToString(result));
                 return false;
             }
 
@@ -1700,8 +1703,8 @@
                 } else if (uss.state == UserState.STATE_SHUTDOWN) {
                     Slogf.i(TAG, "User #" + userId
                             + " is shutting down - will start after full shutdown");
-                    mPendingUserStarts.add(new PendingUserStart(userId,
-                            foreground, unlockListener));
+                    mPendingUserStarts.add(new PendingUserStart(userId, userStartMode,
+                            unlockListener));
                     t.traceEnd(); // updateStartedUserArrayStarting
                     return true;
                 }
@@ -1862,8 +1865,8 @@
     /**
      * Start user, if its not already running, and bring it to foreground.
      */
-    void startUserInForeground(final int targetUserId) {
-        boolean success = startUser(targetUserId, /* foreground */ true);
+    void startUserInForeground(@UserIdInt int targetUserId) {
+        boolean success = startUser(targetUserId, USER_START_MODE_FOREGROUND);
         if (!success) {
             mInjector.getWindowManager().setSwitchingUser(false);
         }
@@ -3433,13 +3436,13 @@
      */
     private static class PendingUserStart {
         public final @UserIdInt int userId;
-        public final boolean isForeground;
+        public final @UserStartMode int userStartMode;
         public final IProgressListener unlockListener;
 
-        PendingUserStart(int userId, boolean foreground,
+        PendingUserStart(int userId, @UserStartMode int userStartMode,
                 IProgressListener unlockListener) {
             this.userId = userId;
-            this.isForeground = foreground;
+            this.userStartMode = userStartMode;
             this.unlockListener = unlockListener;
         }
 
@@ -3447,7 +3450,7 @@
         public String toString() {
             return "PendingUserStart{"
                     + "userId=" + userId
-                    + ", isForeground=" + isForeground
+                    + ", userStartMode=" + userStartModeToString(userStartMode)
                     + ", unlockListener=" + unlockListener
                     + '}';
         }
diff --git a/services/core/java/com/android/server/app/GameManagerService.java b/services/core/java/com/android/server/app/GameManagerService.java
index cda18b0..46d3ff1 100644
--- a/services/core/java/com/android/server/app/GameManagerService.java
+++ b/services/core/java/com/android/server/app/GameManagerService.java
@@ -524,8 +524,8 @@
         private final ArrayMap<Integer, GameModeConfiguration> mModeConfigs = new ArrayMap<>();
         // if adding new properties or make any of the below overridable, the method
         // copyAndApplyOverride should be updated accordingly
-        private boolean mPerfModeOptedIn = false;
-        private boolean mBatteryModeOptedIn = false;
+        private boolean mPerfModeOverridden = false;
+        private boolean mBatteryModeOverridden = false;
         private boolean mAllowDownscale = true;
         private boolean mAllowAngle = true;
         private boolean mAllowFpsOverride = true;
@@ -542,8 +542,8 @@
                         PackageManager.GET_META_DATA, userId);
                 if (!parseInterventionFromXml(packageManager, ai, packageName)
                             && ai.metaData != null) {
-                    mPerfModeOptedIn = ai.metaData.getBoolean(METADATA_PERFORMANCE_MODE_ENABLE);
-                    mBatteryModeOptedIn = ai.metaData.getBoolean(METADATA_BATTERY_MODE_ENABLE);
+                    mPerfModeOverridden = ai.metaData.getBoolean(METADATA_PERFORMANCE_MODE_ENABLE);
+                    mBatteryModeOverridden = ai.metaData.getBoolean(METADATA_BATTERY_MODE_ENABLE);
                     mAllowDownscale = ai.metaData.getBoolean(METADATA_WM_ALLOW_DOWNSCALE, true);
                     mAllowAngle = ai.metaData.getBoolean(METADATA_ANGLE_ALLOW_ANGLE, true);
                 }
@@ -595,9 +595,9 @@
                     } else {
                         final TypedArray array = resources.obtainAttributes(attributeSet,
                                 com.android.internal.R.styleable.GameModeConfig);
-                        mPerfModeOptedIn = array.getBoolean(
+                        mPerfModeOverridden = array.getBoolean(
                                 GameModeConfig_supportsPerformanceGameMode, false);
-                        mBatteryModeOptedIn = array.getBoolean(
+                        mBatteryModeOverridden = array.getBoolean(
                                 GameModeConfig_supportsBatteryGameMode,
                                 false);
                         mAllowDownscale = array.getBoolean(GameModeConfig_allowGameDownscaling,
@@ -610,8 +610,8 @@
                 }
             } catch (NameNotFoundException | XmlPullParserException | IOException ex) {
                 // set flag back to default values when parsing fails
-                mPerfModeOptedIn = false;
-                mBatteryModeOptedIn = false;
+                mPerfModeOverridden = false;
+                mBatteryModeOverridden = false;
                 mAllowDownscale = true;
                 mAllowAngle = true;
                 mAllowFpsOverride = true;
@@ -667,8 +667,8 @@
 
             GameModeConfiguration(KeyValueListParser parser) {
                 mGameMode = parser.getInt(MODE_KEY, GameManager.GAME_MODE_UNSUPPORTED);
-                // isGameModeOptedIn() returns if an app will handle all of the changes necessary
-                // for a particular game mode. If so, the Android framework (i.e.
+                // willGamePerformOptimizations() returns if an app will handle all of the changes
+                // necessary for a particular game mode. If so, the Android framework (i.e.
                 // GameManagerService) will not do anything for the app (like window scaling or
                 // using ANGLE).
                 mScaling = !mAllowDownscale || willGamePerformOptimizations(mGameMode)
@@ -775,8 +775,8 @@
          * "com.android.app.gamemode.battery.enabled" with a value of "true"
          */
         public boolean willGamePerformOptimizations(@GameMode int gameMode) {
-            return (mBatteryModeOptedIn && gameMode == GameManager.GAME_MODE_BATTERY)
-                    || (mPerfModeOptedIn && gameMode == GameManager.GAME_MODE_PERFORMANCE);
+            return (mBatteryModeOverridden && gameMode == GameManager.GAME_MODE_BATTERY)
+                    || (mPerfModeOverridden && gameMode == GameManager.GAME_MODE_PERFORMANCE);
         }
 
         private int getAvailableGameModesBitfield() {
@@ -787,10 +787,10 @@
                     field |= modeToBitmask(mode);
                 }
             }
-            if (mBatteryModeOptedIn) {
+            if (mBatteryModeOverridden) {
                 field |= modeToBitmask(GameManager.GAME_MODE_BATTERY);
             }
-            if (mPerfModeOptedIn) {
+            if (mPerfModeOverridden) {
                 field |= modeToBitmask(GameManager.GAME_MODE_PERFORMANCE);
             }
             return field;
@@ -814,14 +814,14 @@
         }
 
         /**
-         * Get an array of a package's opted-in game modes.
+         * Get an array of a package's overridden game modes.
          */
-        public @GameMode int[] getOptedInGameModes() {
-            if (mBatteryModeOptedIn && mPerfModeOptedIn) {
+        public @GameMode int[] getOverriddenGameModes() {
+            if (mBatteryModeOverridden && mPerfModeOverridden) {
                 return new int[]{GameManager.GAME_MODE_BATTERY, GameManager.GAME_MODE_PERFORMANCE};
-            } else if (mBatteryModeOptedIn) {
+            } else if (mBatteryModeOverridden) {
                 return new int[]{GameManager.GAME_MODE_BATTERY};
-            } else if (mPerfModeOptedIn) {
+            } else if (mPerfModeOverridden) {
                 return new int[]{GameManager.GAME_MODE_PERFORMANCE};
             } else {
                 return new int[]{};
@@ -864,18 +864,18 @@
 
         public boolean isActive() {
             synchronized (mModeConfigLock) {
-                return mModeConfigs.size() > 0 || mBatteryModeOptedIn || mPerfModeOptedIn;
+                return mModeConfigs.size() > 0 || mBatteryModeOverridden || mPerfModeOverridden;
             }
         }
 
         GamePackageConfiguration copyAndApplyOverride(GamePackageConfiguration overrideConfig) {
             GamePackageConfiguration copy = new GamePackageConfiguration(mPackageName);
             // if a game mode is overridden, we treat it with the highest priority and reset any
-            // opt-in game modes so that interventions are always executed.
-            copy.mPerfModeOptedIn = mPerfModeOptedIn && !(overrideConfig != null
+            // overridden game modes so that interventions are always executed.
+            copy.mPerfModeOverridden = mPerfModeOverridden && !(overrideConfig != null
                     && overrideConfig.getGameModeConfiguration(GameManager.GAME_MODE_PERFORMANCE)
                     != null);
-            copy.mBatteryModeOptedIn = mBatteryModeOptedIn && !(overrideConfig != null
+            copy.mBatteryModeOverridden = mBatteryModeOverridden && !(overrideConfig != null
                     && overrideConfig.getGameModeConfiguration(GameManager.GAME_MODE_BATTERY)
                     != null);
 
@@ -1092,12 +1092,12 @@
         final @GameMode int activeGameMode = getGameModeFromSettingsUnchecked(packageName, userId);
         final GamePackageConfiguration config = getConfig(packageName, userId);
         if (config != null) {
-            final @GameMode int[] optedInGameModes = config.getOptedInGameModes();
+            final @GameMode int[] overriddenGameModes = config.getOverriddenGameModes();
             final @GameMode int[] availableGameModes = config.getAvailableGameModes();
             GameModeInfo.Builder gameModeInfoBuilder = new GameModeInfo.Builder()
                     .setActiveGameMode(activeGameMode)
                     .setAvailableGameModes(availableGameModes)
-                    .setOptedInGameModes(optedInGameModes)
+                    .setOverriddenGameModes(overriddenGameModes)
                     .setDownscalingAllowed(config.mAllowDownscale)
                     .setFpsOverrideAllowed(config.mAllowFpsOverride);
             for (int gameMode : availableGameModes) {
@@ -2059,7 +2059,7 @@
                 if (atomTag == FrameworkStatsLog.GAME_MODE_INFO) {
                     data.add(
                             FrameworkStatsLog.buildStatsEvent(FrameworkStatsLog.GAME_MODE_INFO, uid,
-                                    gameModesToStatsdGameModes(config.getOptedInGameModes()),
+                                    gameModesToStatsdGameModes(config.getOverriddenGameModes()),
                                     gameModesToStatsdGameModes(config.getAvailableGameModes())));
                 } else if (atomTag == FrameworkStatsLog.GAME_MODE_CONFIGURATION) {
                     for (int gameMode : config.getAvailableGameModes()) {
diff --git a/services/core/java/com/android/server/appop/AppOpsCheckingServiceImpl.java b/services/core/java/com/android/server/appop/AppOpsCheckingServiceImpl.java
index 587fb04..ac25f4e 100644
--- a/services/core/java/com/android/server/appop/AppOpsCheckingServiceImpl.java
+++ b/services/core/java/com/android/server/appop/AppOpsCheckingServiceImpl.java
@@ -20,7 +20,7 @@
 import static android.app.AppOpsManager.WATCH_FOREGROUND_CHANGES;
 import static android.app.AppOpsManager.opRestrictsRead;
 
-import static com.android.server.appop.AppOpsServiceImpl.ModeCallback.ALL_OPS;
+import static com.android.server.appop.AppOpsService.ModeCallback.ALL_OPS;
 
 import android.Manifest;
 import android.annotation.NonNull;
@@ -85,8 +85,8 @@
 
 
     AppOpsCheckingServiceImpl(PersistenceScheduler persistenceScheduler,
-                              @NonNull Object lock, Handler handler, Context context,
-                              SparseArray<int[]> switchedOps) {
+            @NonNull Object lock, Handler handler, Context context,
+            SparseArray<int[]> switchedOps) {
         this.mPersistenceScheduler = persistenceScheduler;
         this.mLock = lock;
         this.mHandler = handler;
@@ -218,7 +218,7 @@
     }
 
     @Override
-    public boolean arePackageModesDefault(@NonNull String packageMode, @UserIdInt int userId) {
+    public boolean arePackageModesDefault(String packageMode, @UserIdInt int userId) {
         synchronized (mLock) {
             ArrayMap<String, SparseIntArray> packageModes = mUserPackageModes.get(userId, null);
             if (packageModes == null) {
@@ -490,16 +490,15 @@
     }
 
     @Override
-    public SparseBooleanArray evalForegroundUidOps(int uid,
-            @Nullable SparseBooleanArray foregroundOps) {
+    public SparseBooleanArray evalForegroundUidOps(int uid, SparseBooleanArray foregroundOps) {
         synchronized (mLock) {
             return evalForegroundOps(mUidModes.get(uid), foregroundOps);
         }
     }
 
     @Override
-    public SparseBooleanArray evalForegroundPackageOps(@NonNull String packageName,
-            @Nullable SparseBooleanArray foregroundOps, @UserIdInt int userId) {
+    public SparseBooleanArray evalForegroundPackageOps(String packageName,
+            SparseBooleanArray foregroundOps, @UserIdInt int userId) {
         synchronized (mLock) {
             ArrayMap<String, SparseIntArray> packageModes = mUserPackageModes.get(userId, null);
             return evalForegroundOps(packageModes == null ? null : packageModes.get(packageName),
@@ -538,8 +537,8 @@
     }
 
     @Override
-    public boolean dumpListeners(int dumpOp, int dumpUid, @Nullable String dumpPackage,
-            @NonNull PrintWriter printWriter) {
+    public boolean dumpListeners(int dumpOp, int dumpUid, String dumpPackage,
+            PrintWriter printWriter) {
         boolean needSep = false;
         if (mOpModeWatchers.size() > 0) {
             boolean printedHeader = false;
diff --git a/services/core/java/com/android/server/appop/AppOpsCheckingServiceInterface.java b/services/core/java/com/android/server/appop/AppOpsCheckingServiceInterface.java
index ef3e368..d8d0d48 100644
--- a/services/core/java/com/android/server/appop/AppOpsCheckingServiceInterface.java
+++ b/services/core/java/com/android/server/appop/AppOpsCheckingServiceInterface.java
@@ -103,7 +103,7 @@
      * @param packageName package name.
      * @param userId user id associated with the package.
      */
-    boolean arePackageModesDefault(@NonNull String packageName, @UserIdInt int userId);
+    boolean arePackageModesDefault(String packageName, @UserIdInt int userId);
 
     /**
      * Stop tracking app-op modes for all uid and packages.
@@ -184,7 +184,7 @@
      * @param foregroundOps boolean array where app-ops that have MODE_FOREGROUND are marked true.
      * @return  foregroundOps.
      */
-    SparseBooleanArray evalForegroundUidOps(int uid, @Nullable SparseBooleanArray foregroundOps);
+    SparseBooleanArray evalForegroundUidOps(int uid, SparseBooleanArray foregroundOps);
 
     /**
      * Go over the list of app-ops for the package name and mark app-ops with MODE_FOREGROUND in
@@ -194,8 +194,8 @@
      * @param userId user id associated with the package.
      * @return foregroundOps.
      */
-    SparseBooleanArray evalForegroundPackageOps(@NonNull String packageName,
-            @Nullable SparseBooleanArray foregroundOps, @UserIdInt int userId);
+    SparseBooleanArray evalForegroundPackageOps(String packageName,
+            SparseBooleanArray foregroundOps, @UserIdInt int userId);
 
     /**
      * Dump op mode and package mode listeners and their details.
@@ -205,6 +205,5 @@
      * @param dumpPackage if not null and if dumpOp is -1, dumps watchers for the package name.
      * @param printWriter writer to dump to.
      */
-    boolean dumpListeners(int dumpOp, int dumpUid, @Nullable String dumpPackage,
-            @NonNull PrintWriter printWriter);
+    boolean dumpListeners(int dumpOp, int dumpUid, String dumpPackage, PrintWriter printWriter);
 }
diff --git a/services/core/java/com/android/server/appop/AppOpsRestrictionsImpl.java b/services/core/java/com/android/server/appop/AppOpsRestrictionsImpl.java
index af5b07e..f51200f2 100644
--- a/services/core/java/com/android/server/appop/AppOpsRestrictionsImpl.java
+++ b/services/core/java/com/android/server/appop/AppOpsRestrictionsImpl.java
@@ -42,7 +42,7 @@
 
     private Context mContext;
     private Handler mHandler;
-    private AppOpsCheckingServiceInterface mAppOpsServiceInterface;
+    private AppOpsCheckingServiceInterface mAppOpsCheckingServiceInterface;
 
     // Map from (Object token) to (int code) to (boolean restricted)
     private final ArrayMap<Object, SparseBooleanArray> mGlobalRestrictions = new ArrayMap<>();
@@ -56,10 +56,10 @@
             mUserRestrictionExcludedPackageTags = new ArrayMap<>();
 
     public AppOpsRestrictionsImpl(Context context, Handler handler,
-            AppOpsCheckingServiceInterface appOpsServiceInterface) {
+            AppOpsCheckingServiceInterface appOpsCheckingServiceInterface) {
         mContext = context;
         mHandler = handler;
-        mAppOpsServiceInterface = appOpsServiceInterface;
+        mAppOpsCheckingServiceInterface = appOpsCheckingServiceInterface;
     }
 
     @Override
@@ -219,7 +219,7 @@
         int restrictedCodesSize = allUserRestrictedCodes.size();
         for (int j = 0; j < restrictedCodesSize; j++) {
             int code = allUserRestrictedCodes.keyAt(j);
-            mHandler.post(() -> mAppOpsServiceInterface.notifyWatchersOfChange(code, UID_ANY));
+            mHandler.post(() -> mAppOpsCheckingServiceInterface.notifyWatchersOfChange(code, UID_ANY));
         }
     }
 
diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java
index 39338c6..9345422 100644
--- a/services/core/java/com/android/server/appop/AppOpsService.java
+++ b/services/core/java/com/android/server/appop/AppOpsService.java
@@ -18,22 +18,56 @@
 
 import static android.app.AppOpsManager.ATTRIBUTION_CHAIN_ID_NONE;
 import static android.app.AppOpsManager.ATTRIBUTION_FLAG_TRUSTED;
+import static android.app.AppOpsManager.CALL_BACK_ON_SWITCHED_OP;
+import static android.app.AppOpsManager.FILTER_BY_ATTRIBUTION_TAG;
+import static android.app.AppOpsManager.FILTER_BY_OP_NAMES;
+import static android.app.AppOpsManager.FILTER_BY_PACKAGE_NAME;
+import static android.app.AppOpsManager.FILTER_BY_UID;
+import static android.app.AppOpsManager.HISTORY_FLAG_GET_ATTRIBUTION_CHAINS;
+import static android.app.AppOpsManager.HistoricalOpsRequestFilter;
+import static android.app.AppOpsManager.KEY_BG_STATE_SETTLE_TIME;
+import static android.app.AppOpsManager.KEY_FG_SERVICE_STATE_SETTLE_TIME;
+import static android.app.AppOpsManager.KEY_TOP_STATE_SETTLE_TIME;
 import static android.app.AppOpsManager.MODE_ALLOWED;
 import static android.app.AppOpsManager.MODE_DEFAULT;
+import static android.app.AppOpsManager.MODE_ERRORED;
+import static android.app.AppOpsManager.MODE_FOREGROUND;
+import static android.app.AppOpsManager.MODE_IGNORED;
+import static android.app.AppOpsManager.OP_CAMERA;
 import static android.app.AppOpsManager.OP_FLAGS_ALL;
 import static android.app.AppOpsManager.OP_FLAG_SELF;
 import static android.app.AppOpsManager.OP_FLAG_TRUSTED_PROXIED;
 import static android.app.AppOpsManager.OP_NONE;
+import static android.app.AppOpsManager.OP_PLAY_AUDIO;
+import static android.app.AppOpsManager.OP_RECEIVE_AMBIENT_TRIGGER_AUDIO;
+import static android.app.AppOpsManager.OP_RECORD_AUDIO;
+import static android.app.AppOpsManager.OP_RECORD_AUDIO_HOTWORD;
+import static android.app.AppOpsManager.OP_SCHEDULE_EXACT_ALARM;
+import static android.app.AppOpsManager.OP_VIBRATE;
+import static android.app.AppOpsManager.OnOpStartedListener.START_TYPE_FAILED;
+import static android.app.AppOpsManager.OnOpStartedListener.START_TYPE_STARTED;
+import static android.app.AppOpsManager.OpEventProxyInfo;
+import static android.app.AppOpsManager.RestrictionBypass;
 import static android.app.AppOpsManager.SAMPLING_STRATEGY_BOOT_TIME_SAMPLING;
 import static android.app.AppOpsManager.SAMPLING_STRATEGY_RARELY_USED;
 import static android.app.AppOpsManager.SAMPLING_STRATEGY_UNIFORM;
 import static android.app.AppOpsManager.SAMPLING_STRATEGY_UNIFORM_OPS;
+import static android.app.AppOpsManager.SECURITY_EXCEPTION_ON_INVALID_ATTRIBUTION_TAG_CHANGE;
 import static android.app.AppOpsManager._NUM_OP;
+import static android.app.AppOpsManager.extractFlagsFromKey;
+import static android.app.AppOpsManager.extractUidStateFromKey;
+import static android.app.AppOpsManager.modeToName;
+import static android.app.AppOpsManager.opAllowSystemBypassRestriction;
 import static android.app.AppOpsManager.opRestrictsRead;
+import static android.app.AppOpsManager.opToName;
 import static android.app.AppOpsManager.opToPublicName;
+import static android.content.Intent.ACTION_PACKAGE_REMOVED;
+import static android.content.Intent.EXTRA_REPLACING;
 import static android.content.pm.PermissionInfo.PROTECTION_DANGEROUS;
 import static android.content.pm.PermissionInfo.PROTECTION_FLAG_APPOP;
 
+import static com.android.server.appop.AppOpsService.ModeCallback.ALL_OPS;
+
 import android.Manifest;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
@@ -42,16 +76,21 @@
 import android.app.ActivityManagerInternal;
 import android.app.AppGlobals;
 import android.app.AppOpsManager;
+import android.app.AppOpsManager.AttributedOpEntry;
 import android.app.AppOpsManager.AttributionFlags;
 import android.app.AppOpsManager.HistoricalOps;
+import android.app.AppOpsManager.Mode;
+import android.app.AppOpsManager.OpEntry;
 import android.app.AppOpsManager.OpFlags;
 import android.app.AppOpsManagerInternal;
 import android.app.AppOpsManagerInternal.CheckOpsDelegate;
 import android.app.AsyncNotedAppOp;
 import android.app.RuntimeAppOpAccessMessage;
 import android.app.SyncNotedAppOp;
+import android.app.admin.DevicePolicyManagerInternal;
 import android.content.AttributionSource;
 import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
@@ -59,11 +98,15 @@
 import android.content.pm.PackageManager;
 import android.content.pm.PackageManagerInternal;
 import android.content.pm.PermissionInfo;
+import android.database.ContentObserver;
 import android.hardware.camera2.CameraDevice.CAMERA_AUDIO_RESTRICTION;
+import android.net.Uri;
 import android.os.AsyncTask;
 import android.os.Binder;
+import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
+import android.os.HandlerExecutor;
 import android.os.IBinder;
 import android.os.PackageTagsList;
 import android.os.Process;
@@ -74,14 +117,22 @@
 import android.os.ServiceManager;
 import android.os.ShellCallback;
 import android.os.ShellCommand;
+import android.os.SystemClock;
 import android.os.UserHandle;
+import android.os.storage.StorageManagerInternal;
+import android.permission.PermissionManager;
+import android.provider.Settings;
 import android.util.ArrayMap;
 import android.util.ArraySet;
+import android.util.AtomicFile;
+import android.util.KeyValueListParser;
 import android.util.Pair;
 import android.util.Slog;
 import android.util.SparseArray;
+import android.util.SparseBooleanArray;
 import android.util.SparseIntArray;
 import android.util.TimeUtils;
+import android.util.Xml;
 
 import com.android.internal.annotations.GuardedBy;
 import com.android.internal.annotations.Immutable;
@@ -93,37 +144,61 @@
 import com.android.internal.app.IAppOpsService;
 import com.android.internal.app.IAppOpsStartedCallback;
 import com.android.internal.app.MessageSamplingConfig;
+import com.android.internal.compat.IPlatformCompat;
+import com.android.internal.os.Clock;
+import com.android.internal.util.ArrayUtils;
+import com.android.internal.util.DumpUtils;
 import com.android.internal.util.Preconditions;
+import com.android.internal.util.XmlUtils;
 import com.android.internal.util.function.pooled.PooledLambda;
+import com.android.modules.utils.TypedXmlPullParser;
+import com.android.modules.utils.TypedXmlSerializer;
 import com.android.server.LocalServices;
+import com.android.server.LockGuard;
+import com.android.server.SystemServerInitThreadPool;
 import com.android.server.SystemServiceManager;
 import com.android.server.pm.PackageList;
+import com.android.server.pm.UserManagerInternal;
+import com.android.server.pm.permission.PermissionManagerServiceInternal;
+import com.android.server.pm.pkg.AndroidPackage;
+import com.android.server.pm.pkg.component.ParsedAttribution;
 import com.android.server.policy.AppOpsPolicy;
 
+import dalvik.annotation.optimization.NeverCompile;
+
+import libcore.util.EmptyArray;
+
 import org.json.JSONException;
 import org.json.JSONObject;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
 
 import java.io.File;
 import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.text.SimpleDateFormat;
 import java.time.Instant;
 import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Objects;
 import java.util.Scanner;
+import java.util.Set;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.function.Consumer;
 
-/**
- * The system service component to {@link AppOpsManager}.
- */
-public class AppOpsService extends IAppOpsService.Stub {
-
-    private final AppOpsServiceInterface mAppOpsService;
-
+public class AppOpsService extends IAppOpsService.Stub implements PersistenceScheduler {
     static final String TAG = "AppOps";
     static final boolean DEBUG = false;
 
@@ -132,19 +207,74 @@
      */
     private final ArraySet<NoteOpTrace> mNoteOpCallerStacktraces = new ArraySet<>();
 
+    /**
+     * Sentinel integer version to denote that there was no appops.xml found on boot.
+     * This will happen when a device boots with no existing userdata.
+     */
+    private static final int NO_FILE_VERSION = -2;
+
+    /**
+     * Sentinel integer version to denote that there was no version in the appops.xml found on boot.
+     * This means the file is coming from a build before versioning was added.
+     */
+    private static final int NO_VERSION = -1;
+
+    /** Increment by one every time and add the corresponding upgrade logic in
+     *  {@link #upgradeLocked(int)} below. The first version was 1 */
+    static final int CURRENT_VERSION = 2;
+
+    /**
+     * This stores the version of appops.xml seen at boot. If this is smaller than
+     * {@link #CURRENT_VERSION}, then we will run {@link #upgradeLocked(int)} on startup.
+     */
+    private int mVersionAtBoot = NO_FILE_VERSION;
+
+    // Write at most every 30 minutes.
+    static final long WRITE_DELAY = DEBUG ? 1000 : 30*60*1000;
+
     // Constant meaning that any UID should be matched when dispatching callbacks
     private static final int UID_ANY = -2;
 
-    private static final int MAX_UNFORWARDED_OPS = 10;
+    private static final int[] OPS_RESTRICTED_ON_SUSPEND = {
+            OP_PLAY_AUDIO,
+            OP_RECORD_AUDIO,
+            OP_CAMERA,
+            OP_VIBRATE,
+    };
 
+    private static final int MAX_UNFORWARDED_OPS = 10;
+    private static final int MAX_UNUSED_POOLED_OBJECTS = 3;
     private static final int RARELY_USED_PACKAGES_INITIALIZATION_DELAY_MILLIS = 300000;
 
     final Context mContext;
+    final AtomicFile mFile;
     private final @Nullable File mNoteOpCallerStacktracesFile;
     final Handler mHandler;
 
+    /**
+     * Pool for {@link AttributedOp.OpEventProxyInfoPool} to avoid to constantly reallocate new
+     * objects
+     */
+    @GuardedBy("this")
+    final AttributedOp.OpEventProxyInfoPool mOpEventProxyInfoPool =
+            new AttributedOp.OpEventProxyInfoPool(MAX_UNUSED_POOLED_OBJECTS);
+
+    /**
+     * Pool for {@link AttributedOp.InProgressStartOpEventPool} to avoid to constantly reallocate
+     * new objects
+     */
+    @GuardedBy("this")
+    final AttributedOp.InProgressStartOpEventPool mInProgressStartOpEventPool =
+            new AttributedOp.InProgressStartOpEventPool(mOpEventProxyInfoPool,
+                    MAX_UNUSED_POOLED_OBJECTS);
+
     private final AppOpsManagerInternalImpl mAppOpsManagerInternal
             = new AppOpsManagerInternalImpl();
+    @Nullable private final DevicePolicyManagerInternal dpmi =
+            LocalServices.getService(DevicePolicyManagerInternal.class);
+
+    private final IPlatformCompat mPlatformCompat = IPlatformCompat.Stub.asInterface(
+            ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE));
 
     /**
      * Registered callbacks, called from {@link #collectAsyncNotedOp}.
@@ -171,9 +301,54 @@
 
     boolean mWriteNoteOpsScheduled;
 
+    boolean mWriteScheduled;
+    boolean mFastWriteScheduled;
+    final Runnable mWriteRunner = new Runnable() {
+        public void run() {
+            synchronized (AppOpsService.this) {
+                mWriteScheduled = false;
+                mFastWriteScheduled = false;
+                AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
+                    @Override protected Void doInBackground(Void... params) {
+                        writeState();
+                        return null;
+                    }
+                };
+                task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[])null);
+            }
+        }
+    };
+
+    @GuardedBy("this")
+    @VisibleForTesting
+    final SparseArray<UidState> mUidStates = new SparseArray<>();
+
+    volatile @NonNull HistoricalRegistry mHistoricalRegistry = new HistoricalRegistry(this);
+
+    /*
+     * These are app op restrictions imposed per user from various parties.
+     */
+    private final ArrayMap<IBinder, ClientUserRestrictionState> mOpUserRestrictions =
+            new ArrayMap<>();
+
+    /*
+     * These are app op restrictions imposed globally from various parties within the system.
+     */
+    private final ArrayMap<IBinder, ClientGlobalRestrictionState> mOpGlobalRestrictions =
+            new ArrayMap<>();
+
+    SparseIntArray mProfileOwners;
+
     private volatile CheckOpsDelegateDispatcher mCheckOpsDelegateDispatcher =
             new CheckOpsDelegateDispatcher(/*policy*/ null, /*delegate*/ null);
 
+    /**
+      * Reverse lookup for {@link AppOpsManager#opToSwitch(int)}. Initialized once and never
+      * changed
+      */
+    private final SparseArray<int[]> mSwitchedOps = new SparseArray<>();
+
+    private ActivityManagerInternal mActivityManagerInternal;
 
     /** Package sampled for message collection in the current session */
     @GuardedBy("this")
@@ -207,8 +382,546 @@
     /** Package Manager internal. Access via {@link #getPackageManagerInternal()} */
     private @Nullable PackageManagerInternal mPackageManagerInternal;
 
+    /** Interface for app-op modes.*/
+    @VisibleForTesting
+    AppOpsCheckingServiceInterface mAppOpsCheckingService;
+
+    /** Interface for app-op restrictions.*/
+    @VisibleForTesting AppOpsRestrictions mAppOpsRestrictions;
+
+    private AppOpsUidStateTracker mUidStateTracker;
+
+    /** Hands the definition of foreground and uid states */
+    @GuardedBy("this")
+    public AppOpsUidStateTracker getUidStateTracker() {
+        if (mUidStateTracker == null) {
+            mUidStateTracker = new AppOpsUidStateTrackerImpl(
+                    LocalServices.getService(ActivityManagerInternal.class),
+                    mHandler,
+                    r -> {
+                        synchronized (AppOpsService.this) {
+                            r.run();
+                        }
+                    },
+                    Clock.SYSTEM_CLOCK, mConstants);
+
+            mUidStateTracker.addUidStateChangedCallback(new HandlerExecutor(mHandler),
+                    this::onUidStateChanged);
+        }
+        return mUidStateTracker;
+    }
+
+    /**
+     * All times are in milliseconds. These constants are kept synchronized with the system
+     * global Settings. Any access to this class or its fields should be done while
+     * holding the AppOpsService lock.
+     */
+    final class Constants extends ContentObserver {
+
+        /**
+         * How long we want for a drop in uid state from top to settle before applying it.
+         * @see Settings.Global#APP_OPS_CONSTANTS
+         * @see AppOpsManager#KEY_TOP_STATE_SETTLE_TIME
+         */
+        public long TOP_STATE_SETTLE_TIME;
+
+        /**
+         * How long we want for a drop in uid state from foreground to settle before applying it.
+         * @see Settings.Global#APP_OPS_CONSTANTS
+         * @see AppOpsManager#KEY_FG_SERVICE_STATE_SETTLE_TIME
+         */
+        public long FG_SERVICE_STATE_SETTLE_TIME;
+
+        /**
+         * How long we want for a drop in uid state from background to settle before applying it.
+         * @see Settings.Global#APP_OPS_CONSTANTS
+         * @see AppOpsManager#KEY_BG_STATE_SETTLE_TIME
+         */
+        public long BG_STATE_SETTLE_TIME;
+
+        private final KeyValueListParser mParser = new KeyValueListParser(',');
+        private ContentResolver mResolver;
+
+        public Constants(Handler handler) {
+            super(handler);
+            updateConstants();
+        }
+
+        public void startMonitoring(ContentResolver resolver) {
+            mResolver = resolver;
+            mResolver.registerContentObserver(
+                    Settings.Global.getUriFor(Settings.Global.APP_OPS_CONSTANTS),
+                    false, this);
+            updateConstants();
+        }
+
+        @Override
+        public void onChange(boolean selfChange, Uri uri) {
+            updateConstants();
+        }
+
+        private void updateConstants() {
+            String value = mResolver != null ? Settings.Global.getString(mResolver,
+                    Settings.Global.APP_OPS_CONSTANTS) : "";
+
+            synchronized (AppOpsService.this) {
+                try {
+                    mParser.setString(value);
+                } catch (IllegalArgumentException e) {
+                    // Failed to parse the settings string, log this and move on
+                    // with defaults.
+                    Slog.e(TAG, "Bad app ops settings", e);
+                }
+                TOP_STATE_SETTLE_TIME = mParser.getDurationMillis(
+                        KEY_TOP_STATE_SETTLE_TIME, 5 * 1000L);
+                FG_SERVICE_STATE_SETTLE_TIME = mParser.getDurationMillis(
+                        KEY_FG_SERVICE_STATE_SETTLE_TIME, 5 * 1000L);
+                BG_STATE_SETTLE_TIME = mParser.getDurationMillis(
+                        KEY_BG_STATE_SETTLE_TIME, 1 * 1000L);
+            }
+        }
+
+        void dump(PrintWriter pw) {
+            pw.println("  Settings:");
+
+            pw.print("    "); pw.print(KEY_TOP_STATE_SETTLE_TIME); pw.print("=");
+            TimeUtils.formatDuration(TOP_STATE_SETTLE_TIME, pw);
+            pw.println();
+            pw.print("    "); pw.print(KEY_FG_SERVICE_STATE_SETTLE_TIME); pw.print("=");
+            TimeUtils.formatDuration(FG_SERVICE_STATE_SETTLE_TIME, pw);
+            pw.println();
+            pw.print("    "); pw.print(KEY_BG_STATE_SETTLE_TIME); pw.print("=");
+            TimeUtils.formatDuration(BG_STATE_SETTLE_TIME, pw);
+            pw.println();
+        }
+    }
+
+    @VisibleForTesting
+    final Constants mConstants;
+
+    @VisibleForTesting
+    final class UidState {
+        public final int uid;
+
+        public ArrayMap<String, Ops> pkgOps;
+
+        // true indicates there is an interested observer, false there isn't but it has such an op
+        //TODO: Move foregroundOps and hasForegroundWatchers into the AppOpsServiceInterface.
+        public SparseBooleanArray foregroundOps;
+        public boolean hasForegroundWatchers;
+
+        public UidState(int uid) {
+            this.uid = uid;
+        }
+
+        public void clear() {
+            mAppOpsCheckingService.removeUid(uid);
+            if (pkgOps != null) {
+                for (String packageName : pkgOps.keySet()) {
+                    mAppOpsCheckingService.removePackage(packageName, UserHandle.getUserId(uid));
+                }
+            }
+            pkgOps = null;
+        }
+
+        public boolean isDefault() {
+            boolean areAllPackageModesDefault = true;
+            if (pkgOps != null) {
+                for (String packageName : pkgOps.keySet()) {
+                    if (!mAppOpsCheckingService.arePackageModesDefault(packageName,
+                            UserHandle.getUserId(uid))) {
+                        areAllPackageModesDefault = false;
+                        break;
+                    }
+                }
+            }
+            return (pkgOps == null || pkgOps.isEmpty())
+                    && mAppOpsCheckingService.areUidModesDefault(uid)
+                    && areAllPackageModesDefault;
+        }
+
+        // Functions for uid mode access and manipulation.
+        public SparseIntArray getNonDefaultUidModes() {
+            return mAppOpsCheckingService.getNonDefaultUidModes(uid);
+        }
+
+        public int getUidMode(int op) {
+            return mAppOpsCheckingService.getUidMode(uid, op);
+        }
+
+        public boolean setUidMode(int op, int mode) {
+            return mAppOpsCheckingService.setUidMode(uid, op, mode);
+        }
+
+        @SuppressWarnings("GuardedBy")
+        int evalMode(int op, int mode) {
+            return getUidStateTracker().evalMode(uid, op, mode);
+        }
+
+        public void evalForegroundOps() {
+            foregroundOps = null;
+            foregroundOps = mAppOpsCheckingService.evalForegroundUidOps(uid, foregroundOps);
+            if (pkgOps != null) {
+                for (int i = pkgOps.size() - 1; i >= 0; i--) {
+                    foregroundOps = mAppOpsCheckingService
+                            .evalForegroundPackageOps(pkgOps.valueAt(i).packageName, foregroundOps,
+                                    UserHandle.getUserId(uid));
+                }
+            }
+            hasForegroundWatchers = false;
+            if (foregroundOps != null) {
+                for (int i = 0;  i < foregroundOps.size(); i++) {
+                    if (foregroundOps.valueAt(i)) {
+                        hasForegroundWatchers = true;
+                        break;
+                    }
+                }
+            }
+        }
+
+        @SuppressWarnings("GuardedBy")
+        public int getState() {
+            return getUidStateTracker().getUidState(uid);
+        }
+
+        @SuppressWarnings("GuardedBy")
+        public void dump(PrintWriter pw, long nowElapsed) {
+            getUidStateTracker().dumpUidState(pw, uid, nowElapsed);
+        }
+    }
+
+    final static class Ops extends SparseArray<Op> {
+        final String packageName;
+        final UidState uidState;
+
+        /**
+         * The restriction properties of the package. If {@code null} it could not have been read
+         * yet and has to be refreshed.
+         */
+        @Nullable RestrictionBypass bypass;
+
+        /** Lazily populated cache of attributionTags of this package */
+        final @NonNull ArraySet<String> knownAttributionTags = new ArraySet<>();
+
+        /**
+         * Lazily populated cache of <b>valid</b> attributionTags of this package, a set smaller
+         * than or equal to {@link #knownAttributionTags}.
+         */
+        final @NonNull ArraySet<String> validAttributionTags = new ArraySet<>();
+
+        Ops(String _packageName, UidState _uidState) {
+            packageName = _packageName;
+            uidState = _uidState;
+        }
+    }
+
+    /** Returned from {@link #verifyAndGetBypass(int, String, String, String)}. */
+    private static final class PackageVerificationResult {
+
+        final RestrictionBypass bypass;
+        final boolean isAttributionTagValid;
+
+        PackageVerificationResult(RestrictionBypass bypass, boolean isAttributionTagValid) {
+            this.bypass = bypass;
+            this.isAttributionTagValid = isAttributionTagValid;
+        }
+    }
+
+    final class Op {
+        int op;
+        int uid;
+        final UidState uidState;
+        final @NonNull String packageName;
+
+        /** attributionTag -> AttributedOp */
+        final ArrayMap<String, AttributedOp> mAttributions = new ArrayMap<>(1);
+
+        Op(UidState uidState, String packageName, int op, int uid) {
+            this.op = op;
+            this.uid = uid;
+            this.uidState = uidState;
+            this.packageName = packageName;
+        }
+
+        @Mode int getMode() {
+            return mAppOpsCheckingService.getPackageMode(packageName, this.op,
+                    UserHandle.getUserId(this.uid));
+        }
+        void setMode(@Mode int mode) {
+            mAppOpsCheckingService.setPackageMode(packageName, this.op, mode,
+                    UserHandle.getUserId(this.uid));
+        }
+
+        void removeAttributionsWithNoTime() {
+            for (int i = mAttributions.size() - 1; i >= 0; i--) {
+                if (!mAttributions.valueAt(i).hasAnyTime()) {
+                    mAttributions.removeAt(i);
+                }
+            }
+        }
+
+        private @NonNull AttributedOp getOrCreateAttribution(@NonNull Op parent,
+                @Nullable String attributionTag) {
+            AttributedOp attributedOp;
+
+            attributedOp = mAttributions.get(attributionTag);
+            if (attributedOp == null) {
+                attributedOp = new AttributedOp(AppOpsService.this, attributionTag, parent);
+                mAttributions.put(attributionTag, attributedOp);
+            }
+
+            return attributedOp;
+        }
+
+        @NonNull OpEntry createEntryLocked() {
+            final int numAttributions = mAttributions.size();
+
+            final ArrayMap<String, AppOpsManager.AttributedOpEntry> attributionEntries =
+                    new ArrayMap<>(numAttributions);
+            for (int i = 0; i < numAttributions; i++) {
+                attributionEntries.put(mAttributions.keyAt(i),
+                        mAttributions.valueAt(i).createAttributedOpEntryLocked());
+            }
+
+            return new OpEntry(op, getMode(), attributionEntries);
+        }
+
+        @NonNull OpEntry createSingleAttributionEntryLocked(@Nullable String attributionTag) {
+            final int numAttributions = mAttributions.size();
+
+            final ArrayMap<String, AttributedOpEntry> attributionEntries = new ArrayMap<>(1);
+            for (int i = 0; i < numAttributions; i++) {
+                if (Objects.equals(mAttributions.keyAt(i), attributionTag)) {
+                    attributionEntries.put(mAttributions.keyAt(i),
+                            mAttributions.valueAt(i).createAttributedOpEntryLocked());
+                    break;
+                }
+            }
+
+            return new OpEntry(op, getMode(), attributionEntries);
+        }
+
+        boolean isRunning() {
+            final int numAttributions = mAttributions.size();
+            for (int i = 0; i < numAttributions; i++) {
+                if (mAttributions.valueAt(i).isRunning()) {
+                    return true;
+                }
+            }
+
+            return false;
+        }
+    }
+
+    final ArrayMap<IBinder, ModeCallback> mModeWatchers = new ArrayMap<>();
+    final ArrayMap<IBinder, SparseArray<ActiveCallback>> mActiveWatchers = new ArrayMap<>();
+    final ArrayMap<IBinder, SparseArray<StartedCallback>> mStartedWatchers = new ArrayMap<>();
+    final ArrayMap<IBinder, SparseArray<NotedCallback>> mNotedWatchers = new ArrayMap<>();
     final AudioRestrictionManager mAudioRestrictionManager = new AudioRestrictionManager();
 
+    final class ModeCallback extends OnOpModeChangedListener implements DeathRecipient  {
+        /** If mWatchedOpCode==ALL_OPS notify for ops affected by the switch-op */
+        public static final int ALL_OPS = -2;
+
+        // Need to keep this only because stopWatchingMode needs an IAppOpsCallback.
+        // Otherwise we can just use the IBinder object.
+        private final IAppOpsCallback mCallback;
+
+        ModeCallback(IAppOpsCallback callback, int watchingUid, int flags, int watchedOpCode,
+                int callingUid, int callingPid) {
+            super(watchingUid, flags, watchedOpCode, callingUid, callingPid);
+            this.mCallback = callback;
+            try {
+                mCallback.asBinder().linkToDeath(this, 0);
+            } catch (RemoteException e) {
+                /*ignored*/
+            }
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder(128);
+            sb.append("ModeCallback{");
+            sb.append(Integer.toHexString(System.identityHashCode(this)));
+            sb.append(" watchinguid=");
+            UserHandle.formatUid(sb, getWatchingUid());
+            sb.append(" flags=0x");
+            sb.append(Integer.toHexString(getFlags()));
+            switch (getWatchedOpCode()) {
+                case OP_NONE:
+                    break;
+                case ALL_OPS:
+                    sb.append(" op=(all)");
+                    break;
+                default:
+                    sb.append(" op=");
+                    sb.append(opToName(getWatchedOpCode()));
+                    break;
+            }
+            sb.append(" from uid=");
+            UserHandle.formatUid(sb, getCallingUid());
+            sb.append(" pid=");
+            sb.append(getCallingPid());
+            sb.append('}');
+            return sb.toString();
+        }
+
+        void unlinkToDeath() {
+            mCallback.asBinder().unlinkToDeath(this, 0);
+        }
+
+        @Override
+        public void binderDied() {
+            stopWatchingMode(mCallback);
+        }
+
+        @Override
+        public void onOpModeChanged(int op, int uid, String packageName) throws RemoteException {
+            mCallback.opChanged(op, uid, packageName);
+        }
+    }
+
+    final class ActiveCallback implements DeathRecipient {
+        final IAppOpsActiveCallback mCallback;
+        final int mWatchingUid;
+        final int mCallingUid;
+        final int mCallingPid;
+
+        ActiveCallback(IAppOpsActiveCallback callback, int watchingUid, int callingUid,
+                int callingPid) {
+            mCallback = callback;
+            mWatchingUid = watchingUid;
+            mCallingUid = callingUid;
+            mCallingPid = callingPid;
+            try {
+                mCallback.asBinder().linkToDeath(this, 0);
+            } catch (RemoteException e) {
+                /*ignored*/
+            }
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder(128);
+            sb.append("ActiveCallback{");
+            sb.append(Integer.toHexString(System.identityHashCode(this)));
+            sb.append(" watchinguid=");
+            UserHandle.formatUid(sb, mWatchingUid);
+            sb.append(" from uid=");
+            UserHandle.formatUid(sb, mCallingUid);
+            sb.append(" pid=");
+            sb.append(mCallingPid);
+            sb.append('}');
+            return sb.toString();
+        }
+
+        void destroy() {
+            mCallback.asBinder().unlinkToDeath(this, 0);
+        }
+
+        @Override
+        public void binderDied() {
+            stopWatchingActive(mCallback);
+        }
+    }
+
+    final class StartedCallback implements DeathRecipient {
+        final IAppOpsStartedCallback mCallback;
+        final int mWatchingUid;
+        final int mCallingUid;
+        final int mCallingPid;
+
+        StartedCallback(IAppOpsStartedCallback callback, int watchingUid, int callingUid,
+                int callingPid) {
+            mCallback = callback;
+            mWatchingUid = watchingUid;
+            mCallingUid = callingUid;
+            mCallingPid = callingPid;
+            try {
+                mCallback.asBinder().linkToDeath(this, 0);
+            } catch (RemoteException e) {
+                /*ignored*/
+            }
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder(128);
+            sb.append("StartedCallback{");
+            sb.append(Integer.toHexString(System.identityHashCode(this)));
+            sb.append(" watchinguid=");
+            UserHandle.formatUid(sb, mWatchingUid);
+            sb.append(" from uid=");
+            UserHandle.formatUid(sb, mCallingUid);
+            sb.append(" pid=");
+            sb.append(mCallingPid);
+            sb.append('}');
+            return sb.toString();
+        }
+
+        void destroy() {
+            mCallback.asBinder().unlinkToDeath(this, 0);
+        }
+
+        @Override
+        public void binderDied() {
+            stopWatchingStarted(mCallback);
+        }
+    }
+
+    final class NotedCallback implements DeathRecipient {
+        final IAppOpsNotedCallback mCallback;
+        final int mWatchingUid;
+        final int mCallingUid;
+        final int mCallingPid;
+
+        NotedCallback(IAppOpsNotedCallback callback, int watchingUid, int callingUid,
+                int callingPid) {
+            mCallback = callback;
+            mWatchingUid = watchingUid;
+            mCallingUid = callingUid;
+            mCallingPid = callingPid;
+            try {
+                mCallback.asBinder().linkToDeath(this, 0);
+            } catch (RemoteException e) {
+                /*ignored*/
+            }
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder(128);
+            sb.append("NotedCallback{");
+            sb.append(Integer.toHexString(System.identityHashCode(this)));
+            sb.append(" watchinguid=");
+            UserHandle.formatUid(sb, mWatchingUid);
+            sb.append(" from uid=");
+            UserHandle.formatUid(sb, mCallingUid);
+            sb.append(" pid=");
+            sb.append(mCallingPid);
+            sb.append('}');
+            return sb.toString();
+        }
+
+        void destroy() {
+            mCallback.asBinder().unlinkToDeath(this, 0);
+        }
+
+        @Override
+        public void binderDied() {
+            stopWatchingNoted(mCallback);
+        }
+    }
+
+    /**
+     * Call {@link AttributedOp#onClientDeath attributedOp.onClientDeath(clientId)}.
+     */
+    static void onClientDeath(@NonNull AttributedOp attributedOp,
+            @NonNull IBinder clientId) {
+        attributedOp.onClientDeath(clientId);
+    }
+
+
     /**
      * Loads the OpsValidation file results into a hashmap {@link #mNoteOpCallerStacktraces}
      * so that we do not log the same operation twice between instances
@@ -233,12 +946,20 @@
     }
 
     public AppOpsService(File storagePath, Handler handler, Context context) {
-        this(handler, context, new AppOpsServiceImpl(storagePath, handler, context));
-    }
+        mContext = context;
 
-    @VisibleForTesting
-    public AppOpsService(Handler handler, Context context,
-            AppOpsServiceInterface appOpsServiceInterface) {
+        for (int switchedCode = 0; switchedCode < _NUM_OP; switchedCode++) {
+            int switchCode = AppOpsManager.opToSwitch(switchedCode);
+            mSwitchedOps.put(switchCode,
+                    ArrayUtils.appendInt(mSwitchedOps.get(switchCode), switchedCode));
+        }
+        mAppOpsCheckingService =
+                new AppOpsCheckingServiceImpl(this, this, handler, context, mSwitchedOps);
+        mAppOpsRestrictions = new AppOpsRestrictionsImpl(context, handler,
+                mAppOpsCheckingService);
+
+        LockGuard.installLock(this, LockGuard.INDEX_APP_OPS);
+        mFile = new AtomicFile(storagePath, "appops");
         if (AppOpsManager.NOTE_OP_COLLECTION_ENABLED) {
             mNoteOpCallerStacktracesFile = new File(SystemServiceManager.ensureSystemDir(),
                     "noteOpStackTraces.json");
@@ -246,25 +967,189 @@
         } else {
             mNoteOpCallerStacktracesFile = null;
         }
-
-        mAppOpsService = appOpsServiceInterface;
-        mContext = context;
         mHandler = handler;
+        mConstants = new Constants(mHandler);
+        readState();
     }
 
-    /**
-     * Publishes binder and local service.
-     */
     public void publish() {
         ServiceManager.addService(Context.APP_OPS_SERVICE, asBinder());
         LocalServices.addService(AppOpsManagerInternal.class, mAppOpsManagerInternal);
     }
 
-    /**
-     * Finishes boot sequence.
-     */
+    /** Handler for work when packages are removed or updated */
+    private BroadcastReceiver mOnPackageUpdatedReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            String action = intent.getAction();
+            String pkgName = intent.getData().getEncodedSchemeSpecificPart();
+            int uid = intent.getIntExtra(Intent.EXTRA_UID, Process.INVALID_UID);
+
+            if (action.equals(ACTION_PACKAGE_REMOVED) && !intent.hasExtra(EXTRA_REPLACING)) {
+                synchronized (AppOpsService.this) {
+                    UidState uidState = mUidStates.get(uid);
+                    if (uidState == null || uidState.pkgOps == null) {
+                        return;
+                    }
+                    mAppOpsCheckingService.removePackage(pkgName, UserHandle.getUserId(uid));
+                    Ops removedOps = uidState.pkgOps.remove(pkgName);
+                    if (removedOps != null) {
+                        scheduleFastWriteLocked();
+                    }
+                }
+            } else if (action.equals(Intent.ACTION_PACKAGE_REPLACED)) {
+                AndroidPackage pkg = getPackageManagerInternal().getPackage(pkgName);
+                if (pkg == null) {
+                    return;
+                }
+
+                ArrayMap<String, String> dstAttributionTags = new ArrayMap<>();
+                ArraySet<String> attributionTags = new ArraySet<>();
+                attributionTags.add(null);
+                if (pkg.getAttributions() != null) {
+                    int numAttributions = pkg.getAttributions().size();
+                    for (int attributionNum = 0; attributionNum < numAttributions;
+                            attributionNum++) {
+                        ParsedAttribution attribution = pkg.getAttributions().get(attributionNum);
+                        attributionTags.add(attribution.getTag());
+
+                        int numInheritFrom = attribution.getInheritFrom().size();
+                        for (int inheritFromNum = 0; inheritFromNum < numInheritFrom;
+                                inheritFromNum++) {
+                            dstAttributionTags.put(attribution.getInheritFrom().get(inheritFromNum),
+                                    attribution.getTag());
+                        }
+                    }
+                }
+
+                synchronized (AppOpsService.this) {
+                    UidState uidState = mUidStates.get(uid);
+                    if (uidState == null || uidState.pkgOps == null) {
+                        return;
+                    }
+
+                    Ops ops = uidState.pkgOps.get(pkgName);
+                    if (ops == null) {
+                        return;
+                    }
+
+                    // Reset cached package properties to re-initialize when needed
+                    ops.bypass = null;
+                    ops.knownAttributionTags.clear();
+
+                    // Merge data collected for removed attributions into their successor
+                    // attributions
+                    int numOps = ops.size();
+                    for (int opNum = 0; opNum < numOps; opNum++) {
+                        Op op = ops.valueAt(opNum);
+
+                        int numAttributions = op.mAttributions.size();
+                        for (int attributionNum = numAttributions - 1; attributionNum >= 0;
+                                attributionNum--) {
+                            String attributionTag = op.mAttributions.keyAt(attributionNum);
+
+                            if (attributionTags.contains(attributionTag)) {
+                                // attribution still exist after upgrade
+                                continue;
+                            }
+
+                            String newAttributionTag = dstAttributionTags.get(attributionTag);
+
+                            AttributedOp newAttributedOp = op.getOrCreateAttribution(op,
+                                    newAttributionTag);
+                            newAttributedOp.add(op.mAttributions.valueAt(attributionNum));
+                            op.mAttributions.removeAt(attributionNum);
+
+                            scheduleFastWriteLocked();
+                        }
+                    }
+                }
+            }
+        }
+    };
+
     public void systemReady() {
-        mAppOpsService.systemReady();
+        synchronized (this) {
+            upgradeLocked(mVersionAtBoot);
+        }
+
+        mConstants.startMonitoring(mContext.getContentResolver());
+        mHistoricalRegistry.systemReady(mContext.getContentResolver());
+
+        IntentFilter packageUpdateFilter = new IntentFilter();
+        packageUpdateFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
+        packageUpdateFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
+        packageUpdateFilter.addDataScheme("package");
+
+        mContext.registerReceiverAsUser(mOnPackageUpdatedReceiver, UserHandle.ALL,
+                packageUpdateFilter, null, null);
+
+        synchronized (this) {
+            for (int uidNum = mUidStates.size() - 1; uidNum >= 0; uidNum--) {
+                int uid = mUidStates.keyAt(uidNum);
+                UidState uidState = mUidStates.valueAt(uidNum);
+
+                String[] pkgsInUid = getPackagesForUid(uidState.uid);
+                if (ArrayUtils.isEmpty(pkgsInUid)) {
+                    uidState.clear();
+                    mUidStates.removeAt(uidNum);
+                    scheduleFastWriteLocked();
+                    continue;
+                }
+
+                ArrayMap<String, Ops> pkgs = uidState.pkgOps;
+                if (pkgs == null) {
+                    continue;
+                }
+
+                int numPkgs = pkgs.size();
+                for (int pkgNum = 0; pkgNum < numPkgs; pkgNum++) {
+                    String pkg = pkgs.keyAt(pkgNum);
+
+                    String action;
+                    if (!ArrayUtils.contains(pkgsInUid, pkg)) {
+                        action = Intent.ACTION_PACKAGE_REMOVED;
+                    } else {
+                        action = Intent.ACTION_PACKAGE_REPLACED;
+                    }
+
+                    SystemServerInitThreadPool.submit(
+                            () -> mOnPackageUpdatedReceiver.onReceive(mContext, new Intent(action)
+                                    .setData(Uri.fromParts("package", pkg, null))
+                                    .putExtra(Intent.EXTRA_UID, uid)),
+                            "Update app-ops uidState in case package " + pkg + " changed");
+                }
+            }
+        }
+
+        final IntentFilter packageSuspendFilter = new IntentFilter();
+        packageSuspendFilter.addAction(Intent.ACTION_PACKAGES_UNSUSPENDED);
+        packageSuspendFilter.addAction(Intent.ACTION_PACKAGES_SUSPENDED);
+        mContext.registerReceiverAsUser(new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                final int[] changedUids = intent.getIntArrayExtra(Intent.EXTRA_CHANGED_UID_LIST);
+                final String[] changedPkgs = intent.getStringArrayExtra(
+                        Intent.EXTRA_CHANGED_PACKAGE_LIST);
+                for (int code : OPS_RESTRICTED_ON_SUSPEND) {
+                    ArraySet<OnOpModeChangedListener> onModeChangedListeners;
+                    synchronized (AppOpsService.this) {
+                        onModeChangedListeners =
+                                mAppOpsCheckingService.getOpModeChangedListeners(code);
+                        if (onModeChangedListeners == null) {
+                            continue;
+                        }
+                    }
+                    for (int i = 0; i < changedUids.length; i++) {
+                        final int changedUid = changedUids[i];
+                        final String changedPkg = changedPkgs[i];
+                        // We trust packagemanager to insert matching uid and packageNames in the
+                        // extras
+                        notifyOpChanged(onModeChangedListeners, code, changedUid, changedPkg);
+                    }
+                }
+            }
+        }, UserHandle.ALL, packageSuspendFilter, null, null);
 
         final IntentFilter packageAddedFilter = new IntentFilter();
         packageAddedFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
@@ -272,8 +1157,9 @@
         mContext.registerReceiver(new BroadcastReceiver() {
             @Override
             public void onReceive(Context context, Intent intent) {
+                final Uri data = intent.getData();
 
-                final String packageName = intent.getData().getSchemeSpecificPart();
+                final String packageName = data.getSchemeSpecificPart();
                 PackageInfo pi = getPackageManagerInternal().getPackageInfo(packageName,
                         PackageManager.GET_PERMISSIONS, Process.myUid(), mContext.getUserId());
                 if (isSamplingTarget(pi)) {
@@ -308,6 +1194,8 @@
                         }
                     }
                 });
+
+        mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
     }
 
     /**
@@ -322,18 +1210,132 @@
         mCheckOpsDelegateDispatcher = new CheckOpsDelegateDispatcher(policy, delegate);
     }
 
-    /**
-     * Notify when a package is removed
-     */
     public void packageRemoved(int uid, String packageName) {
-        mAppOpsService.packageRemoved(uid, packageName);
+        synchronized (this) {
+            UidState uidState = mUidStates.get(uid);
+            if (uidState == null) {
+                return;
+            }
+
+            Ops removedOps = null;
+
+            // Remove any package state if such.
+            if (uidState.pkgOps != null) {
+                removedOps = uidState.pkgOps.remove(packageName);
+                mAppOpsCheckingService.removePackage(packageName, UserHandle.getUserId(uid));
+            }
+
+            // If we just nuked the last package state check if the UID is valid.
+            if (removedOps != null && uidState.pkgOps.isEmpty()
+                    && getPackagesForUid(uid).length <= 0) {
+                uidState.clear();
+                mUidStates.remove(uid);
+            }
+
+            if (removedOps != null) {
+                scheduleFastWriteLocked();
+
+                final int numOps = removedOps.size();
+                for (int opNum = 0; opNum < numOps; opNum++) {
+                    final Op op = removedOps.valueAt(opNum);
+
+                    final int numAttributions = op.mAttributions.size();
+                    for (int attributionNum = 0; attributionNum < numAttributions;
+                            attributionNum++) {
+                        AttributedOp attributedOp = op.mAttributions.valueAt(attributionNum);
+
+                        while (attributedOp.isRunning()) {
+                            attributedOp.finished(attributedOp.mInProgressEvents.keyAt(0));
+                        }
+                        while (attributedOp.isPaused()) {
+                            attributedOp.finished(attributedOp.mPausedInProgressEvents.keyAt(0));
+                        }
+                    }
+                }
+            }
+        }
+
+        mHandler.post(PooledLambda.obtainRunnable(HistoricalRegistry::clearHistory,
+                    mHistoricalRegistry, uid, packageName));
     }
 
-    /**
-     * Notify when a uid is removed.
-     */
     public void uidRemoved(int uid) {
-        mAppOpsService.uidRemoved(uid);
+        synchronized (this) {
+            if (mUidStates.indexOfKey(uid) >= 0) {
+                mUidStates.get(uid).clear();
+                mUidStates.remove(uid);
+                scheduleFastWriteLocked();
+            }
+        }
+    }
+
+    // The callback method from ForegroundPolicyInterface
+    private void onUidStateChanged(int uid, int state, boolean foregroundModeMayChange) {
+        synchronized (this) {
+            UidState uidState = getUidStateLocked(uid, true);
+
+            if (uidState != null && foregroundModeMayChange && uidState.hasForegroundWatchers) {
+                for (int fgi = uidState.foregroundOps.size() - 1; fgi >= 0; fgi--) {
+                    if (!uidState.foregroundOps.valueAt(fgi)) {
+                        continue;
+                    }
+                    final int code = uidState.foregroundOps.keyAt(fgi);
+
+                    if (uidState.getUidMode(code) != AppOpsManager.opToDefaultMode(code)
+                            && uidState.getUidMode(code) == AppOpsManager.MODE_FOREGROUND) {
+                        mHandler.sendMessage(PooledLambda.obtainMessage(
+                                AppOpsService::notifyOpChangedForAllPkgsInUid,
+                                this, code, uidState.uid, true, null));
+                    } else if (uidState.pkgOps != null) {
+                        final ArraySet<OnOpModeChangedListener> listenerSet =
+                                mAppOpsCheckingService.getOpModeChangedListeners(code);
+                        if (listenerSet != null) {
+                            for (int cbi = listenerSet.size() - 1; cbi >= 0; cbi--) {
+                                final OnOpModeChangedListener listener = listenerSet.valueAt(cbi);
+                                if ((listener.getFlags()
+                                        & AppOpsManager.WATCH_FOREGROUND_CHANGES) == 0
+                                        || !listener.isWatchingUid(uidState.uid)) {
+                                    continue;
+                                }
+                                for (int pkgi = uidState.pkgOps.size() - 1; pkgi >= 0; pkgi--) {
+                                    final Op op = uidState.pkgOps.valueAt(pkgi).get(code);
+                                    if (op == null) {
+                                        continue;
+                                    }
+                                    if (op.getMode() == AppOpsManager.MODE_FOREGROUND) {
+                                        mHandler.sendMessage(PooledLambda.obtainMessage(
+                                                AppOpsService::notifyOpChanged,
+                                                this, listenerSet.valueAt(cbi), code, uidState.uid,
+                                                uidState.pkgOps.keyAt(pkgi)));
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+
+            if (uidState != null && uidState.pkgOps != null) {
+                int numPkgs = uidState.pkgOps.size();
+                for (int pkgNum = 0; pkgNum < numPkgs; pkgNum++) {
+                    Ops ops = uidState.pkgOps.valueAt(pkgNum);
+
+                    int numOps = ops.size();
+                    for (int opNum = 0; opNum < numOps; opNum++) {
+                        Op op = ops.valueAt(opNum);
+
+                        int numAttributions = op.mAttributions.size();
+                        for (int attributionNum = 0; attributionNum < numAttributions;
+                                attributionNum++) {
+                            AttributedOp attributedOp = op.mAttributions.valueAt(
+                                    attributionNum);
+
+                            attributedOp.onUidStateChanged(state);
+                        }
+                    }
+                }
+            }
+        }
     }
 
     /**
@@ -341,60 +1343,542 @@
      */
     public void updateUidProcState(int uid, int procState,
             @ActivityManager.ProcessCapability int capability) {
-        mAppOpsService.updateUidProcState(uid, procState, capability);
+        synchronized (this) {
+            getUidStateTracker().updateUidProcState(uid, procState, capability);
+            if (!mUidStates.contains(uid)) {
+                UidState uidState = new UidState(uid);
+                mUidStates.put(uid, uidState);
+                onUidStateChanged(uid,
+                        AppOpsUidStateTracker.processStateToUidState(procState), false);
+            }
+        }
     }
 
-    /**
-     * Initiates shutdown.
-     */
     public void shutdown() {
-        mAppOpsService.shutdown();
-
+        Slog.w(TAG, "Writing app ops before shutdown...");
+        boolean doWrite = false;
+        synchronized (this) {
+            if (mWriteScheduled) {
+                mWriteScheduled = false;
+                mFastWriteScheduled = false;
+                mHandler.removeCallbacks(mWriteRunner);
+                doWrite = true;
+            }
+        }
+        if (doWrite) {
+            writeState();
+        }
         if (AppOpsManager.NOTE_OP_COLLECTION_ENABLED && mWriteNoteOpsScheduled) {
             writeNoteOps();
         }
+
+        mHistoricalRegistry.shutdown();
+    }
+
+    private ArrayList<AppOpsManager.OpEntry> collectOps(Ops pkgOps, int[] ops) {
+        ArrayList<AppOpsManager.OpEntry> resOps = null;
+        if (ops == null) {
+            resOps = new ArrayList<>();
+            for (int j=0; j<pkgOps.size(); j++) {
+                Op curOp = pkgOps.valueAt(j);
+                resOps.add(getOpEntryForResult(curOp));
+            }
+        } else {
+            for (int j=0; j<ops.length; j++) {
+                Op curOp = pkgOps.get(ops[j]);
+                if (curOp != null) {
+                    if (resOps == null) {
+                        resOps = new ArrayList<>();
+                    }
+                    resOps.add(getOpEntryForResult(curOp));
+                }
+            }
+        }
+        return resOps;
+    }
+
+    @Nullable
+    private ArrayList<AppOpsManager.OpEntry> collectUidOps(@NonNull UidState uidState,
+            @Nullable int[] ops) {
+        final SparseIntArray opModes = uidState.getNonDefaultUidModes();
+        if (opModes == null) {
+            return null;
+        }
+
+        int opModeCount = opModes.size();
+        if (opModeCount == 0) {
+            return null;
+        }
+        ArrayList<AppOpsManager.OpEntry> resOps = null;
+        if (ops == null) {
+            resOps = new ArrayList<>();
+            for (int i = 0; i < opModeCount; i++) {
+                int code = opModes.keyAt(i);
+                resOps.add(new OpEntry(code, opModes.get(code), Collections.emptyMap()));
+            }
+        } else {
+            for (int j=0; j<ops.length; j++) {
+                int code = ops[j];
+                if (opModes.indexOfKey(code) >= 0) {
+                    if (resOps == null) {
+                        resOps = new ArrayList<>();
+                    }
+                    resOps.add(new OpEntry(code, opModes.get(code), Collections.emptyMap()));
+                }
+            }
+        }
+        return resOps;
+    }
+
+    private static @NonNull OpEntry getOpEntryForResult(@NonNull Op op) {
+        return op.createEntryLocked();
     }
 
     @Override
     public List<AppOpsManager.PackageOps> getPackagesForOps(int[] ops) {
-        return mAppOpsService.getPackagesForOps(ops);
+        final int callingUid = Binder.getCallingUid();
+        final boolean hasAllPackageAccess = mContext.checkPermission(
+                Manifest.permission.GET_APP_OPS_STATS, Binder.getCallingPid(),
+                Binder.getCallingUid(), null) == PackageManager.PERMISSION_GRANTED;
+        ArrayList<AppOpsManager.PackageOps> res = null;
+        synchronized (this) {
+            final int uidStateCount = mUidStates.size();
+            for (int i = 0; i < uidStateCount; i++) {
+                UidState uidState = mUidStates.valueAt(i);
+                if (uidState.pkgOps == null || uidState.pkgOps.isEmpty()) {
+                    continue;
+                }
+                ArrayMap<String, Ops> packages = uidState.pkgOps;
+                final int packageCount = packages.size();
+                for (int j = 0; j < packageCount; j++) {
+                    Ops pkgOps = packages.valueAt(j);
+                    ArrayList<AppOpsManager.OpEntry> resOps = collectOps(pkgOps, ops);
+                    if (resOps != null) {
+                        if (res == null) {
+                            res = new ArrayList<>();
+                        }
+                        AppOpsManager.PackageOps resPackage = new AppOpsManager.PackageOps(
+                                pkgOps.packageName, pkgOps.uidState.uid, resOps);
+                        // Caller can always see their packages and with a permission all.
+                        if (hasAllPackageAccess || callingUid == pkgOps.uidState.uid) {
+                            res.add(resPackage);
+                        }
+                    }
+                }
+            }
+        }
+        return res;
     }
 
     @Override
     public List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName,
             int[] ops) {
-        return mAppOpsService.getOpsForPackage(uid, packageName, ops);
+        enforceGetAppOpsStatsPermissionIfNeeded(uid,packageName);
+        String resolvedPackageName = AppOpsManager.resolvePackageName(uid, packageName);
+        if (resolvedPackageName == null) {
+            return Collections.emptyList();
+        }
+        synchronized (this) {
+            Ops pkgOps = getOpsLocked(uid, resolvedPackageName, null, false, null,
+                    /* edit */ false);
+            if (pkgOps == null) {
+                return null;
+            }
+            ArrayList<AppOpsManager.OpEntry> resOps = collectOps(pkgOps, ops);
+            if (resOps == null) {
+                return null;
+            }
+            ArrayList<AppOpsManager.PackageOps> res = new ArrayList<AppOpsManager.PackageOps>();
+            AppOpsManager.PackageOps resPackage = new AppOpsManager.PackageOps(
+                    pkgOps.packageName, pkgOps.uidState.uid, resOps);
+            res.add(resPackage);
+            return res;
+        }
+    }
+
+    private void enforceGetAppOpsStatsPermissionIfNeeded(int uid, String packageName) {
+        final int callingUid = Binder.getCallingUid();
+        // We get to access everything
+        if (callingUid == Process.myPid()) {
+            return;
+        }
+        // Apps can access their own data
+        if (uid == callingUid && packageName != null
+                && checkPackage(uid, packageName) == MODE_ALLOWED) {
+            return;
+        }
+        // Otherwise, you need a permission...
+        mContext.enforcePermission(android.Manifest.permission.GET_APP_OPS_STATS,
+                Binder.getCallingPid(), callingUid, null);
+    }
+
+    /**
+     * Verify that historical appop request arguments are valid.
+     */
+    private void ensureHistoricalOpRequestIsValid(int uid, String packageName,
+            String attributionTag, List<String> opNames, int filter, long beginTimeMillis,
+            long endTimeMillis, int flags) {
+        if ((filter & FILTER_BY_UID) != 0) {
+            Preconditions.checkArgument(uid != Process.INVALID_UID);
+        } else {
+            Preconditions.checkArgument(uid == Process.INVALID_UID);
+        }
+
+        if ((filter & FILTER_BY_PACKAGE_NAME) != 0) {
+            Objects.requireNonNull(packageName);
+        } else {
+            Preconditions.checkArgument(packageName == null);
+        }
+
+        if ((filter & FILTER_BY_ATTRIBUTION_TAG) == 0) {
+            Preconditions.checkArgument(attributionTag == null);
+        }
+
+        if ((filter & FILTER_BY_OP_NAMES) != 0) {
+            Objects.requireNonNull(opNames);
+        } else {
+            Preconditions.checkArgument(opNames == null);
+        }
+
+        Preconditions.checkFlagsArgument(filter,
+                FILTER_BY_UID | FILTER_BY_PACKAGE_NAME | FILTER_BY_ATTRIBUTION_TAG
+                        | FILTER_BY_OP_NAMES);
+        Preconditions.checkArgumentNonnegative(beginTimeMillis);
+        Preconditions.checkArgument(endTimeMillis > beginTimeMillis);
+        Preconditions.checkFlagsArgument(flags, OP_FLAGS_ALL);
     }
 
     @Override
     public void getHistoricalOps(int uid, String packageName, String attributionTag,
             List<String> opNames, int dataType, int filter, long beginTimeMillis,
             long endTimeMillis, int flags, RemoteCallback callback) {
-        mAppOpsService.getHistoricalOps(uid, packageName, attributionTag, opNames,
-                dataType, filter, beginTimeMillis, endTimeMillis, flags, callback);
+        PackageManager pm = mContext.getPackageManager();
+
+        ensureHistoricalOpRequestIsValid(uid, packageName, attributionTag, opNames, filter,
+                beginTimeMillis, endTimeMillis, flags);
+        Objects.requireNonNull(callback, "callback cannot be null");
+        ActivityManagerInternal ami = LocalServices.getService(ActivityManagerInternal.class);
+        boolean isSelfRequest = (filter & FILTER_BY_UID) != 0 && uid == Binder.getCallingUid();
+        if (!isSelfRequest) {
+            boolean isCallerInstrumented =
+                    ami.getInstrumentationSourceUid(Binder.getCallingUid()) != Process.INVALID_UID;
+            boolean isCallerSystem = Binder.getCallingPid() == Process.myPid();
+            boolean isCallerPermissionController;
+            try {
+                isCallerPermissionController = pm.getPackageUidAsUser(
+                        mContext.getPackageManager().getPermissionControllerPackageName(), 0,
+                        UserHandle.getUserId(Binder.getCallingUid()))
+                        == Binder.getCallingUid();
+            } catch (PackageManager.NameNotFoundException doesNotHappen) {
+                return;
+            }
+
+            boolean doesCallerHavePermission = mContext.checkPermission(
+                    android.Manifest.permission.GET_HISTORICAL_APP_OPS_STATS,
+                    Binder.getCallingPid(), Binder.getCallingUid())
+                    == PackageManager.PERMISSION_GRANTED;
+
+            if (!isCallerSystem && !isCallerInstrumented && !isCallerPermissionController
+                    && !doesCallerHavePermission) {
+                mHandler.post(() -> callback.sendResult(new Bundle()));
+                return;
+            }
+
+            mContext.enforcePermission(android.Manifest.permission.GET_APP_OPS_STATS,
+                    Binder.getCallingPid(), Binder.getCallingUid(), "getHistoricalOps");
+        }
+
+        final String[] opNamesArray = (opNames != null)
+                ? opNames.toArray(new String[opNames.size()]) : null;
+
+        Set<String> attributionChainExemptPackages = null;
+        if ((dataType & HISTORY_FLAG_GET_ATTRIBUTION_CHAINS) != 0) {
+            attributionChainExemptPackages =
+                    PermissionManager.getIndicatorExemptedPackages(mContext);
+        }
+
+        final String[] chainExemptPkgArray = attributionChainExemptPackages != null
+                ? attributionChainExemptPackages.toArray(
+                        new String[attributionChainExemptPackages.size()]) : null;
+
+        // Must not hold the appops lock
+        mHandler.post(PooledLambda.obtainRunnable(HistoricalRegistry::getHistoricalOps,
+                mHistoricalRegistry, uid, packageName, attributionTag, opNamesArray, dataType,
+                filter, beginTimeMillis, endTimeMillis, flags, chainExemptPkgArray,
+                callback).recycleOnUse());
     }
 
     @Override
     public void getHistoricalOpsFromDiskRaw(int uid, String packageName, String attributionTag,
             List<String> opNames, int dataType, int filter, long beginTimeMillis,
             long endTimeMillis, int flags, RemoteCallback callback) {
-        mAppOpsService.getHistoricalOpsFromDiskRaw(uid, packageName, attributionTag,
-                opNames, dataType, filter, beginTimeMillis, endTimeMillis, flags, callback);
+        ensureHistoricalOpRequestIsValid(uid, packageName, attributionTag, opNames, filter,
+                beginTimeMillis, endTimeMillis, flags);
+        Objects.requireNonNull(callback, "callback cannot be null");
+
+        mContext.enforcePermission(Manifest.permission.MANAGE_APPOPS,
+                Binder.getCallingPid(), Binder.getCallingUid(), "getHistoricalOps");
+
+        final String[] opNamesArray = (opNames != null)
+                ? opNames.toArray(new String[opNames.size()]) : null;
+
+        Set<String> attributionChainExemptPackages = null;
+        if ((dataType & HISTORY_FLAG_GET_ATTRIBUTION_CHAINS) != 0) {
+            attributionChainExemptPackages =
+                    PermissionManager.getIndicatorExemptedPackages(mContext);
+        }
+
+        final String[] chainExemptPkgArray = attributionChainExemptPackages != null
+                ? attributionChainExemptPackages.toArray(
+                new String[attributionChainExemptPackages.size()]) : null;
+
+        // Must not hold the appops lock
+        mHandler.post(PooledLambda.obtainRunnable(HistoricalRegistry::getHistoricalOpsFromDiskRaw,
+                mHistoricalRegistry, uid, packageName, attributionTag, opNamesArray, dataType,
+                filter, beginTimeMillis, endTimeMillis, flags, chainExemptPkgArray,
+                callback).recycleOnUse());
     }
 
     @Override
     public void reloadNonHistoricalState() {
-        mAppOpsService.reloadNonHistoricalState();
+        mContext.enforcePermission(Manifest.permission.MANAGE_APPOPS,
+                Binder.getCallingPid(), Binder.getCallingUid(), "reloadNonHistoricalState");
+        writeState();
+        readState();
     }
 
     @Override
     public List<AppOpsManager.PackageOps> getUidOps(int uid, int[] ops) {
-        return mAppOpsService.getUidOps(uid, ops);
+        mContext.enforcePermission(android.Manifest.permission.GET_APP_OPS_STATS,
+                Binder.getCallingPid(), Binder.getCallingUid(), null);
+        synchronized (this) {
+            UidState uidState = getUidStateLocked(uid, false);
+            if (uidState == null) {
+                return null;
+            }
+            ArrayList<AppOpsManager.OpEntry> resOps = collectUidOps(uidState, ops);
+            if (resOps == null) {
+                return null;
+            }
+            ArrayList<AppOpsManager.PackageOps> res = new ArrayList<AppOpsManager.PackageOps>();
+            AppOpsManager.PackageOps resPackage = new AppOpsManager.PackageOps(
+                    null, uidState.uid, resOps);
+            res.add(resPackage);
+            return res;
+        }
+    }
+
+    private void pruneOpLocked(Op op, int uid, String packageName) {
+        op.removeAttributionsWithNoTime();
+
+        if (op.mAttributions.isEmpty()) {
+            Ops ops = getOpsLocked(uid, packageName, null, false, null, /* edit */ false);
+            if (ops != null) {
+                ops.remove(op.op);
+                op.setMode(AppOpsManager.opToDefaultMode(op.op));
+                if (ops.size() <= 0) {
+                    UidState uidState = ops.uidState;
+                    ArrayMap<String, Ops> pkgOps = uidState.pkgOps;
+                    if (pkgOps != null) {
+                        pkgOps.remove(ops.packageName);
+                        mAppOpsCheckingService.removePackage(ops.packageName,
+                                UserHandle.getUserId(uidState.uid));
+                        if (pkgOps.isEmpty()) {
+                            uidState.pkgOps = null;
+                        }
+                        if (uidState.isDefault()) {
+                            uidState.clear();
+                            mUidStates.remove(uid);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    private void enforceManageAppOpsModes(int callingPid, int callingUid, int targetUid) {
+        if (callingPid == Process.myPid()) {
+            return;
+        }
+        final int callingUser = UserHandle.getUserId(callingUid);
+        synchronized (this) {
+            if (mProfileOwners != null && mProfileOwners.get(callingUser, -1) == callingUid) {
+                if (targetUid >= 0 && callingUser == UserHandle.getUserId(targetUid)) {
+                    // Profile owners are allowed to change modes but only for apps
+                    // within their user.
+                    return;
+                }
+            }
+        }
+        mContext.enforcePermission(android.Manifest.permission.MANAGE_APP_OPS_MODES,
+                Binder.getCallingPid(), Binder.getCallingUid(), null);
     }
 
     @Override
     public void setUidMode(int code, int uid, int mode) {
-        mAppOpsService.setUidMode(code, uid, mode, null);
+        setUidMode(code, uid, mode, null);
+    }
+
+    private void setUidMode(int code, int uid, int mode,
+            @Nullable IAppOpsCallback permissionPolicyCallback) {
+        if (DEBUG) {
+            Slog.i(TAG, "uid " + uid + " OP_" + opToName(code) + " := " + modeToName(mode)
+                    + " by uid " + Binder.getCallingUid());
+        }
+
+        enforceManageAppOpsModes(Binder.getCallingPid(), Binder.getCallingUid(), uid);
+        verifyIncomingOp(code);
+        code = AppOpsManager.opToSwitch(code);
+
+        if (permissionPolicyCallback == null) {
+            updatePermissionRevokedCompat(uid, code, mode);
+        }
+
+        int previousMode;
+        synchronized (this) {
+            final int defaultMode = AppOpsManager.opToDefaultMode(code);
+
+            UidState uidState = getUidStateLocked(uid, false);
+            if (uidState == null) {
+                if (mode == defaultMode) {
+                    return;
+                }
+                uidState = new UidState(uid);
+                mUidStates.put(uid, uidState);
+            }
+            if (uidState.getUidMode(code) != AppOpsManager.opToDefaultMode(code)) {
+                previousMode = uidState.getUidMode(code);
+            } else {
+                // doesn't look right but is legacy behavior.
+                previousMode = MODE_DEFAULT;
+            }
+
+            if (!uidState.setUidMode(code, mode)) {
+                return;
+            }
+            uidState.evalForegroundOps();
+            if (mode != MODE_ERRORED && mode != previousMode) {
+                updateStartedOpModeForUidLocked(code, mode == MODE_IGNORED, uid);
+            }
+        }
+
+        notifyOpChangedForAllPkgsInUid(code, uid, false, permissionPolicyCallback);
+        notifyOpChangedSync(code, uid, null, mode, previousMode);
+    }
+
+    /**
+     * Notify that an op changed for all packages in an uid.
+     *
+     * @param code The op that changed
+     * @param uid The uid the op was changed for
+     * @param onlyForeground Only notify watchers that watch for foreground changes
+     */
+    private void notifyOpChangedForAllPkgsInUid(int code, int uid, boolean onlyForeground,
+            @Nullable IAppOpsCallback callbackToIgnore) {
+        ModeCallback listenerToIgnore = callbackToIgnore != null
+                ? mModeWatchers.get(callbackToIgnore.asBinder()) : null;
+        mAppOpsCheckingService.notifyOpChangedForAllPkgsInUid(code, uid, onlyForeground,
+                listenerToIgnore);
+    }
+
+    private void updatePermissionRevokedCompat(int uid, int switchCode, int mode) {
+        PackageManager packageManager = mContext.getPackageManager();
+        if (packageManager == null) {
+            // This can only happen during early boot. At this time the permission state and appop
+            // state are in sync
+            return;
+        }
+
+        String[] packageNames = packageManager.getPackagesForUid(uid);
+        if (ArrayUtils.isEmpty(packageNames)) {
+            return;
+        }
+        String packageName = packageNames[0];
+
+        int[] ops = mSwitchedOps.get(switchCode);
+        for (int code : ops) {
+            String permissionName = AppOpsManager.opToPermission(code);
+            if (permissionName == null) {
+                continue;
+            }
+
+            if (packageManager.checkPermission(permissionName, packageName)
+                    != PackageManager.PERMISSION_GRANTED) {
+                continue;
+            }
+
+            PermissionInfo permissionInfo;
+            try {
+                permissionInfo = packageManager.getPermissionInfo(permissionName, 0);
+            } catch (PackageManager.NameNotFoundException e) {
+                e.printStackTrace();
+                continue;
+            }
+
+            if (!permissionInfo.isRuntime()) {
+                continue;
+            }
+
+            boolean supportsRuntimePermissions = getPackageManagerInternal()
+                    .getUidTargetSdkVersion(uid) >= Build.VERSION_CODES.M;
+
+            UserHandle user = UserHandle.getUserHandleForUid(uid);
+            boolean isRevokedCompat;
+            if (permissionInfo.backgroundPermission != null) {
+                if (packageManager.checkPermission(permissionInfo.backgroundPermission, packageName)
+                        == PackageManager.PERMISSION_GRANTED) {
+                    boolean isBackgroundRevokedCompat = mode != AppOpsManager.MODE_ALLOWED;
+
+                    if (isBackgroundRevokedCompat && supportsRuntimePermissions) {
+                        Slog.w(TAG, "setUidMode() called with a mode inconsistent with runtime"
+                                + " permission state, this is discouraged and you should revoke the"
+                                + " runtime permission instead: uid=" + uid + ", switchCode="
+                                + switchCode + ", mode=" + mode + ", permission="
+                                + permissionInfo.backgroundPermission);
+                    }
+
+                    final long identity = Binder.clearCallingIdentity();
+                    try {
+                        packageManager.updatePermissionFlags(permissionInfo.backgroundPermission,
+                                packageName, PackageManager.FLAG_PERMISSION_REVOKED_COMPAT,
+                                isBackgroundRevokedCompat
+                                        ? PackageManager.FLAG_PERMISSION_REVOKED_COMPAT : 0, user);
+                    } finally {
+                        Binder.restoreCallingIdentity(identity);
+                    }
+                }
+
+                isRevokedCompat = mode != AppOpsManager.MODE_ALLOWED
+                        && mode != AppOpsManager.MODE_FOREGROUND;
+            } else {
+                isRevokedCompat = mode != AppOpsManager.MODE_ALLOWED;
+            }
+
+            if (isRevokedCompat && supportsRuntimePermissions) {
+                Slog.w(TAG, "setUidMode() called with a mode inconsistent with runtime"
+                        + " permission state, this is discouraged and you should revoke the"
+                        + " runtime permission instead: uid=" + uid + ", switchCode="
+                        + switchCode + ", mode=" + mode + ", permission=" + permissionName);
+            }
+
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                packageManager.updatePermissionFlags(permissionName, packageName,
+                        PackageManager.FLAG_PERMISSION_REVOKED_COMPAT, isRevokedCompat
+                                ? PackageManager.FLAG_PERMISSION_REVOKED_COMPAT : 0, user);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+    }
+
+    private void notifyOpChangedSync(int code, int uid, @NonNull String packageName, int mode,
+            int previousMode) {
+        final StorageManagerInternal storageManagerInternal =
+                LocalServices.getService(StorageManagerInternal.class);
+        if (storageManagerInternal != null) {
+            storageManagerInternal.onAppOpsChanged(code, uid, packageName, mode, previousMode);
+        }
     }
 
     /**
@@ -407,12 +1891,309 @@
      */
     @Override
     public void setMode(int code, int uid, @NonNull String packageName, int mode) {
-        mAppOpsService.setMode(code, uid, packageName, mode, null);
+        setMode(code, uid, packageName, mode, null);
+    }
+
+    void setMode(int code, int uid, @NonNull String packageName, int mode,
+            @Nullable IAppOpsCallback permissionPolicyCallback) {
+        enforceManageAppOpsModes(Binder.getCallingPid(), Binder.getCallingUid(), uid);
+        verifyIncomingOp(code);
+        if (!isIncomingPackageValid(packageName, UserHandle.getUserId(uid))) {
+            return;
+        }
+
+        ArraySet<OnOpModeChangedListener> repCbs = null;
+        code = AppOpsManager.opToSwitch(code);
+
+        PackageVerificationResult pvr;
+        try {
+            pvr = verifyAndGetBypass(uid, packageName, null);
+        } catch (SecurityException e) {
+            Slog.e(TAG, "Cannot setMode", e);
+            return;
+        }
+
+        int previousMode = MODE_DEFAULT;
+        synchronized (this) {
+            UidState uidState = getUidStateLocked(uid, false);
+            Op op = getOpLocked(code, uid, packageName, null, false, pvr.bypass, /* edit */ true);
+            if (op != null) {
+                if (op.getMode() != mode) {
+                    previousMode = op.getMode();
+                    op.setMode(mode);
+
+                    if (uidState != null) {
+                        uidState.evalForegroundOps();
+                    }
+                    ArraySet<OnOpModeChangedListener> cbs =
+                            mAppOpsCheckingService.getOpModeChangedListeners(code);
+                    if (cbs != null) {
+                        if (repCbs == null) {
+                            repCbs = new ArraySet<>();
+                        }
+                        repCbs.addAll(cbs);
+                    }
+                    cbs = mAppOpsCheckingService.getPackageModeChangedListeners(packageName);
+                    if (cbs != null) {
+                        if (repCbs == null) {
+                            repCbs = new ArraySet<>();
+                        }
+                        repCbs.addAll(cbs);
+                    }
+                    if (repCbs != null && permissionPolicyCallback != null) {
+                        repCbs.remove(mModeWatchers.get(permissionPolicyCallback.asBinder()));
+                    }
+                    if (mode == AppOpsManager.opToDefaultMode(op.op)) {
+                        // If going into the default mode, prune this op
+                        // if there is nothing else interesting in it.
+                        pruneOpLocked(op, uid, packageName);
+                    }
+                    scheduleFastWriteLocked();
+                    if (mode != MODE_ERRORED) {
+                        updateStartedOpModeForUidLocked(code, mode == MODE_IGNORED, uid);
+                    }
+                }
+            }
+        }
+        if (repCbs != null) {
+            mHandler.sendMessage(PooledLambda.obtainMessage(
+                    AppOpsService::notifyOpChanged,
+                    this, repCbs, code, uid, packageName));
+        }
+
+        notifyOpChangedSync(code, uid, packageName, mode, previousMode);
+    }
+
+    private void notifyOpChanged(ArraySet<OnOpModeChangedListener> callbacks, int code,
+            int uid, String packageName) {
+        for (int i = 0; i < callbacks.size(); i++) {
+            final OnOpModeChangedListener callback = callbacks.valueAt(i);
+            notifyOpChanged(callback, code, uid, packageName);
+        }
+    }
+
+    private void notifyOpChanged(OnOpModeChangedListener callback, int code,
+            int uid, String packageName) {
+        mAppOpsCheckingService.notifyOpChanged(callback, code, uid, packageName);
+    }
+
+    private static ArrayList<ChangeRec> addChange(ArrayList<ChangeRec> reports,
+            int op, int uid, String packageName, int previousMode) {
+        boolean duplicate = false;
+        if (reports == null) {
+            reports = new ArrayList<>();
+        } else {
+            final int reportCount = reports.size();
+            for (int j = 0; j < reportCount; j++) {
+                ChangeRec report = reports.get(j);
+                if (report.op == op && report.pkg.equals(packageName)) {
+                    duplicate = true;
+                    break;
+                }
+            }
+        }
+        if (!duplicate) {
+            reports.add(new ChangeRec(op, uid, packageName, previousMode));
+        }
+
+        return reports;
+    }
+
+    private static HashMap<OnOpModeChangedListener, ArrayList<ChangeRec>> addCallbacks(
+            HashMap<OnOpModeChangedListener, ArrayList<ChangeRec>> callbacks,
+            int op, int uid, String packageName, int previousMode,
+            ArraySet<OnOpModeChangedListener> cbs) {
+        if (cbs == null) {
+            return callbacks;
+        }
+        if (callbacks == null) {
+            callbacks = new HashMap<>();
+        }
+        final int N = cbs.size();
+        for (int i=0; i<N; i++) {
+            OnOpModeChangedListener cb = cbs.valueAt(i);
+            ArrayList<ChangeRec> reports = callbacks.get(cb);
+            ArrayList<ChangeRec> changed = addChange(reports, op, uid, packageName, previousMode);
+            if (changed != reports) {
+                callbacks.put(cb, changed);
+            }
+        }
+        return callbacks;
+    }
+
+    static final class ChangeRec {
+        final int op;
+        final int uid;
+        final String pkg;
+        final int previous_mode;
+
+        ChangeRec(int _op, int _uid, String _pkg, int _previous_mode) {
+            op = _op;
+            uid = _uid;
+            pkg = _pkg;
+            previous_mode = _previous_mode;
+        }
     }
 
     @Override
     public void resetAllModes(int reqUserId, String reqPackageName) {
-        mAppOpsService.resetAllModes(reqUserId, reqPackageName);
+        final int callingPid = Binder.getCallingPid();
+        final int callingUid = Binder.getCallingUid();
+        reqUserId = ActivityManager.handleIncomingUser(callingPid, callingUid, reqUserId,
+                true, true, "resetAllModes", null);
+
+        int reqUid = -1;
+        if (reqPackageName != null) {
+            try {
+                reqUid = AppGlobals.getPackageManager().getPackageUid(
+                        reqPackageName, PackageManager.MATCH_UNINSTALLED_PACKAGES, reqUserId);
+            } catch (RemoteException e) {
+                /* ignore - local call */
+            }
+        }
+
+        enforceManageAppOpsModes(callingPid, callingUid, reqUid);
+
+        HashMap<OnOpModeChangedListener, ArrayList<ChangeRec>> callbacks = null;
+        ArrayList<ChangeRec> allChanges = new ArrayList<>();
+        synchronized (this) {
+            boolean changed = false;
+            for (int i = mUidStates.size() - 1; i >= 0; i--) {
+                UidState uidState = mUidStates.valueAt(i);
+
+                SparseIntArray opModes = uidState.getNonDefaultUidModes();
+                if (opModes != null && (uidState.uid == reqUid || reqUid == -1)) {
+                    final int uidOpCount = opModes.size();
+                    for (int j = uidOpCount - 1; j >= 0; j--) {
+                        final int code = opModes.keyAt(j);
+                        if (AppOpsManager.opAllowsReset(code)) {
+                            int previousMode = opModes.valueAt(j);
+                            uidState.setUidMode(code, AppOpsManager.opToDefaultMode(code));
+                            for (String packageName : getPackagesForUid(uidState.uid)) {
+                                callbacks = addCallbacks(callbacks, code, uidState.uid, packageName,
+                                        previousMode,
+                                        mAppOpsCheckingService.getOpModeChangedListeners(code));
+                                callbacks = addCallbacks(callbacks, code, uidState.uid, packageName,
+                                        previousMode, mAppOpsCheckingService
+                                                .getPackageModeChangedListeners(packageName));
+
+                                allChanges = addChange(allChanges, code, uidState.uid,
+                                        packageName, previousMode);
+                            }
+                        }
+                    }
+                }
+
+                if (uidState.pkgOps == null) {
+                    continue;
+                }
+
+                if (reqUserId != UserHandle.USER_ALL
+                        && reqUserId != UserHandle.getUserId(uidState.uid)) {
+                    // Skip any ops for a different user
+                    continue;
+                }
+
+                Map<String, Ops> packages = uidState.pkgOps;
+                Iterator<Map.Entry<String, Ops>> it = packages.entrySet().iterator();
+                boolean uidChanged = false;
+                while (it.hasNext()) {
+                    Map.Entry<String, Ops> ent = it.next();
+                    String packageName = ent.getKey();
+                    if (reqPackageName != null && !reqPackageName.equals(packageName)) {
+                        // Skip any ops for a different package
+                        continue;
+                    }
+                    Ops pkgOps = ent.getValue();
+                    for (int j=pkgOps.size()-1; j>=0; j--) {
+                        Op curOp = pkgOps.valueAt(j);
+                        if (shouldDeferResetOpToDpm(curOp.op)) {
+                            deferResetOpToDpm(curOp.op, reqPackageName, reqUserId);
+                            continue;
+                        }
+                        if (AppOpsManager.opAllowsReset(curOp.op)
+                                && curOp.getMode() != AppOpsManager.opToDefaultMode(curOp.op)) {
+                            int previousMode = curOp.getMode();
+                            curOp.setMode(AppOpsManager.opToDefaultMode(curOp.op));
+                            changed = true;
+                            uidChanged = true;
+                            final int uid = curOp.uidState.uid;
+                            callbacks = addCallbacks(callbacks, curOp.op, uid, packageName,
+                                    previousMode,
+                                    mAppOpsCheckingService.getOpModeChangedListeners(curOp.op));
+                            callbacks = addCallbacks(callbacks, curOp.op, uid, packageName,
+                                    previousMode, mAppOpsCheckingService
+                                            .getPackageModeChangedListeners(packageName));
+
+                            allChanges = addChange(allChanges, curOp.op, uid, packageName,
+                                    previousMode);
+                            curOp.removeAttributionsWithNoTime();
+                            if (curOp.mAttributions.isEmpty()) {
+                                pkgOps.removeAt(j);
+                            }
+                        }
+                    }
+                    if (pkgOps.size() == 0) {
+                        it.remove();
+                        mAppOpsCheckingService.removePackage(packageName,
+                                UserHandle.getUserId(uidState.uid));
+                    }
+                }
+                if (uidState.isDefault()) {
+                    uidState.clear();
+                    mUidStates.remove(uidState.uid);
+                }
+                if (uidChanged) {
+                    uidState.evalForegroundOps();
+                }
+            }
+
+            if (changed) {
+                scheduleFastWriteLocked();
+            }
+        }
+        if (callbacks != null) {
+            for (Map.Entry<OnOpModeChangedListener, ArrayList<ChangeRec>> ent
+                    : callbacks.entrySet()) {
+                OnOpModeChangedListener cb = ent.getKey();
+                ArrayList<ChangeRec> reports = ent.getValue();
+                for (int i=0; i<reports.size(); i++) {
+                    ChangeRec rep = reports.get(i);
+                    mHandler.sendMessage(PooledLambda.obtainMessage(
+                            AppOpsService::notifyOpChanged,
+                            this, cb, rep.op, rep.uid, rep.pkg));
+                }
+            }
+        }
+
+        int numChanges = allChanges.size();
+        for (int i = 0; i < numChanges; i++) {
+            ChangeRec change = allChanges.get(i);
+            notifyOpChangedSync(change.op, change.uid, change.pkg,
+                    AppOpsManager.opToDefaultMode(change.op), change.previous_mode);
+        }
+    }
+
+    private boolean shouldDeferResetOpToDpm(int op) {
+        // TODO(b/174582385): avoid special-casing app-op resets by migrating app-op permission
+        //  pre-grants to a role-based mechanism or another general-purpose mechanism.
+        return dpmi != null && dpmi.supportsResetOp(op);
+    }
+
+    /** Assumes {@link #shouldDeferResetOpToDpm(int)} is true. */
+    private void deferResetOpToDpm(int op, String packageName, @UserIdInt int userId) {
+        // TODO(b/174582385): avoid special-casing app-op resets by migrating app-op permission
+        //  pre-grants to a role-based mechanism or another general-purpose mechanism.
+        dpmi.resetOp(op, packageName, userId);
+    }
+
+    private void evalAllForegroundOpsLocked() {
+        for (int uidi = mUidStates.size() - 1; uidi >= 0; uidi--) {
+            final UidState uidState = mUidStates.valueAt(uidi);
+            if (uidState.foregroundOps != null) {
+                uidState.evalForegroundOps();
+            }
+        }
     }
 
     @Override
@@ -423,17 +2204,66 @@
     @Override
     public void startWatchingModeWithFlags(int op, String packageName, int flags,
             IAppOpsCallback callback) {
-        mAppOpsService.startWatchingModeWithFlags(op, packageName, flags, callback);
+        int watchedUid = -1;
+        final int callingUid = Binder.getCallingUid();
+        final int callingPid = Binder.getCallingPid();
+        // TODO: should have a privileged permission to protect this.
+        // Also, if the caller has requested WATCH_FOREGROUND_CHANGES, should we require
+        // the USAGE_STATS permission since this can provide information about when an
+        // app is in the foreground?
+        Preconditions.checkArgumentInRange(op, AppOpsManager.OP_NONE,
+                AppOpsManager._NUM_OP - 1, "Invalid op code: " + op);
+        if (callback == null) {
+            return;
+        }
+        final boolean mayWatchPackageName = packageName != null
+                && !filterAppAccessUnlocked(packageName, UserHandle.getUserId(callingUid));
+        synchronized (this) {
+            int switchOp = (op != AppOpsManager.OP_NONE) ? AppOpsManager.opToSwitch(op) : op;
+
+            int notifiedOps;
+            if ((flags & CALL_BACK_ON_SWITCHED_OP) == 0) {
+                if (op == OP_NONE) {
+                    notifiedOps = ALL_OPS;
+                } else {
+                    notifiedOps = op;
+                }
+            } else {
+                notifiedOps = switchOp;
+            }
+
+            ModeCallback cb = mModeWatchers.get(callback.asBinder());
+            if (cb == null) {
+                cb = new ModeCallback(callback, watchedUid, flags, notifiedOps, callingUid,
+                        callingPid);
+                mModeWatchers.put(callback.asBinder(), cb);
+            }
+            if (switchOp != AppOpsManager.OP_NONE) {
+                mAppOpsCheckingService.startWatchingOpModeChanged(cb, switchOp);
+            }
+            if (mayWatchPackageName) {
+                mAppOpsCheckingService.startWatchingPackageModeChanged(cb, packageName);
+            }
+            evalAllForegroundOpsLocked();
+        }
     }
 
     @Override
     public void stopWatchingMode(IAppOpsCallback callback) {
-        mAppOpsService.stopWatchingMode(callback);
+        if (callback == null) {
+            return;
+        }
+        synchronized (this) {
+            ModeCallback cb = mModeWatchers.remove(callback.asBinder());
+            if (cb != null) {
+                cb.unlinkToDeath();
+                mAppOpsCheckingService.removeListener(cb);
+            }
+
+            evalAllForegroundOpsLocked();
+        }
     }
 
-    /**
-     * @return the current {@link CheckOpsDelegate}.
-     */
     public CheckOpsDelegate getAppOpsServiceDelegate() {
         synchronized (AppOpsService.this) {
             final CheckOpsDelegateDispatcher dispatcher = mCheckOpsDelegateDispatcher;
@@ -441,9 +2271,6 @@
         }
     }
 
-    /**
-     * Sets the appops {@link CheckOpsDelegate}
-     */
     public void setAppOpsServiceDelegate(CheckOpsDelegate delegate) {
         synchronized (AppOpsService.this) {
             final CheckOpsDelegateDispatcher oldDispatcher = mCheckOpsDelegateDispatcher;
@@ -467,7 +2294,58 @@
 
     private int checkOperationImpl(int code, int uid, String packageName,
             @Nullable String attributionTag, boolean raw) {
-        return mAppOpsService.checkOperation(code, uid, packageName, attributionTag, raw);
+        verifyIncomingOp(code);
+        if (!isIncomingPackageValid(packageName, UserHandle.getUserId(uid))) {
+            return AppOpsManager.opToDefaultMode(code);
+        }
+
+        String resolvedPackageName = AppOpsManager.resolvePackageName(uid, packageName);
+        if (resolvedPackageName == null) {
+            return AppOpsManager.MODE_IGNORED;
+        }
+        return checkOperationUnchecked(code, uid, resolvedPackageName, attributionTag, raw);
+    }
+
+    /**
+     * Get the mode of an app-op.
+     *
+     * @param code The code of the op
+     * @param uid The uid of the package the op belongs to
+     * @param packageName The package the op belongs to
+     * @param raw If the raw state of eval-ed state should be checked.
+     *
+     * @return The mode of the op
+     */
+    private @Mode int checkOperationUnchecked(int code, int uid, @NonNull String packageName,
+            @Nullable String attributionTag, boolean raw) {
+        PackageVerificationResult pvr;
+        try {
+            pvr = verifyAndGetBypass(uid, packageName, null);
+        } catch (SecurityException e) {
+            Slog.e(TAG, "checkOperation", e);
+            return AppOpsManager.opToDefaultMode(code);
+        }
+
+        if (isOpRestrictedDueToSuspend(code, packageName, uid)) {
+            return AppOpsManager.MODE_IGNORED;
+        }
+        synchronized (this) {
+            if (isOpRestrictedLocked(uid, code, packageName, attributionTag, pvr.bypass, true)) {
+                return AppOpsManager.MODE_IGNORED;
+            }
+            code = AppOpsManager.opToSwitch(code);
+            UidState uidState = getUidStateLocked(uid, false);
+            if (uidState != null
+                    && uidState.getUidMode(code) != AppOpsManager.opToDefaultMode(code)) {
+                final int rawMode = uidState.getUidMode(code);
+                return raw ? rawMode : uidState.evalMode(code, rawMode);
+            }
+            Op op = getOpLocked(code, uid, packageName, null, false, pvr.bypass, /* edit */ false);
+            if (op == null) {
+                return AppOpsManager.opToDefaultMode(code);
+            }
+            return raw ? op.getMode() : op.uidState.evalMode(op.op, op.getMode());
+        }
     }
 
     @Override
@@ -487,8 +2365,7 @@
     @Override
     public void setAudioRestriction(int code, int usage, int uid, int mode,
             String[] exceptionPackages) {
-        mAppOpsService.enforceManageAppOpsModes(Binder.getCallingPid(),
-                Binder.getCallingUid(), uid);
+        enforceManageAppOpsModes(Binder.getCallingPid(), Binder.getCallingUid(), uid);
         verifyIncomingUid(uid);
         verifyIncomingOp(code);
 
@@ -496,35 +2373,58 @@
                 code, usage, uid, mode, exceptionPackages);
 
         mHandler.sendMessage(PooledLambda.obtainMessage(
-                AppOpsServiceInterface::notifyWatchersOfChange, mAppOpsService, code,
-                UID_ANY));
+                AppOpsService::notifyWatchersOfChange, this, code, UID_ANY));
     }
 
 
     @Override
     public void setCameraAudioRestriction(@CAMERA_AUDIO_RESTRICTION int mode) {
-        mAppOpsService.enforceManageAppOpsModes(Binder.getCallingPid(),
-                Binder.getCallingUid(), -1);
+        enforceManageAppOpsModes(Binder.getCallingPid(), Binder.getCallingUid(), -1);
 
         mAudioRestrictionManager.setCameraAudioRestriction(mode);
 
         mHandler.sendMessage(PooledLambda.obtainMessage(
-                AppOpsServiceInterface::notifyWatchersOfChange, mAppOpsService,
+                AppOpsService::notifyWatchersOfChange, this,
                 AppOpsManager.OP_PLAY_AUDIO, UID_ANY));
         mHandler.sendMessage(PooledLambda.obtainMessage(
-                AppOpsServiceInterface::notifyWatchersOfChange, mAppOpsService,
+                AppOpsService::notifyWatchersOfChange, this,
                 AppOpsManager.OP_VIBRATE, UID_ANY));
     }
 
     @Override
     public int checkPackage(int uid, String packageName) {
-        return mAppOpsService.checkPackage(uid, packageName);
+        Objects.requireNonNull(packageName);
+        try {
+            verifyAndGetBypass(uid, packageName, null);
+            // When the caller is the system, it's possible that the packageName is the special
+            // one (e.g., "root") which isn't actually existed.
+            if (resolveUid(packageName) == uid
+                    || (isPackageExisted(packageName)
+                            && !filterAppAccessUnlocked(packageName, UserHandle.getUserId(uid)))) {
+                return AppOpsManager.MODE_ALLOWED;
+            }
+            return AppOpsManager.MODE_ERRORED;
+        } catch (SecurityException ignored) {
+            return AppOpsManager.MODE_ERRORED;
+        }
     }
 
     private boolean isPackageExisted(String packageName) {
         return getPackageManagerInternal().getPackageStateInternal(packageName) != null;
     }
 
+    /**
+     * This method will check with PackageManager to determine if the package provided should
+     * be visible to the {@link Binder#getCallingUid()}.
+     *
+     * NOTE: This must not be called while synchronized on {@code this} to avoid dead locks
+     */
+    private boolean filterAppAccessUnlocked(String packageName, int userId) {
+        final int callingUid = Binder.getCallingUid();
+        return LocalServices.getService(PackageManagerInternal.class)
+                .filterAppAccess(packageName, callingUid, userId);
+    }
+
     @Override
     public SyncNotedAppOp noteProxyOperation(int code, AttributionSource attributionSource,
             boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
@@ -570,20 +2470,13 @@
             final int proxyFlags = isProxyTrusted ? AppOpsManager.OP_FLAG_TRUSTED_PROXY
                     : AppOpsManager.OP_FLAG_UNTRUSTED_PROXY;
 
-            final int proxyReturn = mAppOpsService.noteOperationUnchecked(code, proxyUid,
+            final SyncNotedAppOp proxyReturn = noteOperationUnchecked(code, proxyUid,
                     resolveProxyPackageName, proxyAttributionTag, Process.INVALID_UID, null, null,
-                    proxyFlags);
-            if (proxyReturn != AppOpsManager.MODE_ALLOWED) {
-                return new SyncNotedAppOp(proxyReturn, code, proxiedAttributionTag,
+                    proxyFlags, !isProxyTrusted, "proxy " + message, shouldCollectMessage);
+            if (proxyReturn.getOpMode() != AppOpsManager.MODE_ALLOWED) {
+                return new SyncNotedAppOp(proxyReturn.getOpMode(), code, proxiedAttributionTag,
                         proxiedPackageName);
             }
-            if (shouldCollectAsyncNotedOp) {
-                boolean isProxyAttributionTagValid = mAppOpsService.isAttributionTagValid(proxyUid,
-                        resolveProxyPackageName, proxyAttributionTag, null);
-                collectAsyncNotedOp(proxyUid, resolveProxyPackageName, code,
-                        isProxyAttributionTagValid ? proxyAttributionTag : null, proxyFlags,
-                        message, shouldCollectMessage);
-            }
         }
 
         String resolveProxiedPackageName = AppOpsManager.resolvePackageName(proxiedUid,
@@ -595,32 +2488,9 @@
 
         final int proxiedFlags = isProxyTrusted ? AppOpsManager.OP_FLAG_TRUSTED_PROXIED
                 : AppOpsManager.OP_FLAG_UNTRUSTED_PROXIED;
-        final int result = mAppOpsService.noteOperationUnchecked(code, proxiedUid,
-                resolveProxiedPackageName, proxiedAttributionTag, proxyUid, resolveProxyPackageName,
-                proxyAttributionTag, proxiedFlags);
-
-        boolean isProxiedAttributionTagValid = mAppOpsService.isAttributionTagValid(proxiedUid,
-                resolveProxiedPackageName, proxiedAttributionTag, resolveProxyPackageName);
-        if (shouldCollectAsyncNotedOp && result == AppOpsManager.MODE_ALLOWED) {
-            collectAsyncNotedOp(proxiedUid, resolveProxiedPackageName, code,
-                    isProxiedAttributionTagValid ? proxiedAttributionTag : null, proxiedFlags,
-                    message, shouldCollectMessage);
-        }
-
-
-        return new SyncNotedAppOp(result, code,
-                isProxiedAttributionTagValid ? proxiedAttributionTag : null,
-                resolveProxiedPackageName);
-    }
-
-    private boolean isCallerAndAttributionTrusted(@NonNull AttributionSource attributionSource) {
-        if (attributionSource.getUid() != Binder.getCallingUid()
-                && attributionSource.isTrusted(mContext)) {
-            return true;
-        }
-        return mContext.checkPermission(android.Manifest.permission.UPDATE_APP_OPS_STATS,
-                Binder.getCallingPid(), Binder.getCallingUid(), null)
-                == PackageManager.PERMISSION_GRANTED;
+        return noteOperationUnchecked(code, proxiedUid, resolveProxiedPackageName,
+                proxiedAttributionTag, proxyUid, resolveProxyPackageName, proxyAttributionTag,
+                proxiedFlags, shouldCollectAsyncNotedOp, message, shouldCollectMessage);
     }
 
     @Override
@@ -634,58 +2504,258 @@
     private SyncNotedAppOp noteOperationImpl(int code, int uid, @Nullable String packageName,
             @Nullable String attributionTag, boolean shouldCollectAsyncNotedOp,
             @Nullable String message, boolean shouldCollectMessage) {
+        verifyIncomingUid(uid);
+        verifyIncomingOp(code);
         if (!isIncomingPackageValid(packageName, UserHandle.getUserId(uid))) {
             return new SyncNotedAppOp(AppOpsManager.MODE_ERRORED, code, attributionTag,
                     packageName);
         }
 
-        int result = mAppOpsService.noteOperation(code, uid, packageName,
-                attributionTag, message);
-
         String resolvedPackageName = AppOpsManager.resolvePackageName(uid, packageName);
+        if (resolvedPackageName == null) {
+            return new SyncNotedAppOp(AppOpsManager.MODE_IGNORED, code, attributionTag,
+                    packageName);
+        }
+        return noteOperationUnchecked(code, uid, resolvedPackageName, attributionTag,
+                Process.INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF,
+                shouldCollectAsyncNotedOp, message, shouldCollectMessage);
+    }
 
-        boolean isAttributionTagValid = mAppOpsService.isAttributionTagValid(uid,
-                    resolvedPackageName, attributionTag, null);
-
-        if (shouldCollectAsyncNotedOp && result == MODE_ALLOWED) {
-            collectAsyncNotedOp(uid, resolvedPackageName, code,
-                    isAttributionTagValid ? attributionTag : null, AppOpsManager.OP_FLAG_SELF,
-                    message, shouldCollectMessage);
+    private SyncNotedAppOp noteOperationUnchecked(int code, int uid, @NonNull String packageName,
+            @Nullable String attributionTag, int proxyUid, String proxyPackageName,
+            @Nullable String proxyAttributionTag, @OpFlags int flags,
+            boolean shouldCollectAsyncNotedOp, @Nullable String message,
+            boolean shouldCollectMessage) {
+        PackageVerificationResult pvr;
+        try {
+            pvr = verifyAndGetBypass(uid, packageName, attributionTag, proxyPackageName);
+            boolean wasNull = attributionTag == null;
+            if (!pvr.isAttributionTagValid) {
+                attributionTag = null;
+            }
+        } catch (SecurityException e) {
+            Slog.e(TAG, "noteOperation", e);
+            return new SyncNotedAppOp(AppOpsManager.MODE_ERRORED, code, attributionTag,
+                    packageName);
         }
 
-        return new SyncNotedAppOp(result, code, isAttributionTagValid ? attributionTag : null,
-                resolvedPackageName);
+        synchronized (this) {
+            final Ops ops = getOpsLocked(uid, packageName, attributionTag,
+                    pvr.isAttributionTagValid, pvr.bypass, /* edit */ true);
+            if (ops == null) {
+                scheduleOpNotedIfNeededLocked(code, uid, packageName, attributionTag, flags,
+                        AppOpsManager.MODE_IGNORED);
+                if (DEBUG) Slog.d(TAG, "noteOperation: no op for code " + code + " uid " + uid
+                        + " package " + packageName + "flags: " +
+                        AppOpsManager.flagsToString(flags));
+                return new SyncNotedAppOp(AppOpsManager.MODE_ERRORED, code, attributionTag,
+                        packageName);
+            }
+            final Op op = getOpLocked(ops, code, uid, true);
+            final AttributedOp attributedOp = op.getOrCreateAttribution(op, attributionTag);
+            if (attributedOp.isRunning()) {
+                Slog.w(TAG, "Noting op not finished: uid " + uid + " pkg " + packageName + " code "
+                        + code + " startTime of in progress event="
+                        + attributedOp.mInProgressEvents.valueAt(0).getStartTime());
+            }
+
+            final int switchCode = AppOpsManager.opToSwitch(code);
+            final UidState uidState = ops.uidState;
+            if (isOpRestrictedLocked(uid, code, packageName, attributionTag, pvr.bypass, false)) {
+                attributedOp.rejected(uidState.getState(), flags);
+                scheduleOpNotedIfNeededLocked(code, uid, packageName, attributionTag, flags,
+                        AppOpsManager.MODE_IGNORED);
+                return new SyncNotedAppOp(AppOpsManager.MODE_IGNORED, code, attributionTag,
+                        packageName);
+            }
+            // If there is a non-default per UID policy (we set UID op mode only if
+            // non-default) it takes over, otherwise use the per package policy.
+            if (uidState.getUidMode(switchCode) != AppOpsManager.opToDefaultMode(switchCode)) {
+                final int uidMode = uidState.evalMode(code, uidState.getUidMode(switchCode));
+                if (uidMode != AppOpsManager.MODE_ALLOWED) {
+                    if (DEBUG) Slog.d(TAG, "noteOperation: uid reject #" + uidMode + " for code "
+                            + switchCode + " (" + code + ") uid " + uid + " package "
+                            + packageName + " flags: " + AppOpsManager.flagsToString(flags));
+                    attributedOp.rejected(uidState.getState(), flags);
+                    scheduleOpNotedIfNeededLocked(code, uid, packageName, attributionTag, flags,
+                            uidMode);
+                    return new SyncNotedAppOp(uidMode, code, attributionTag, packageName);
+                }
+            } else {
+                final Op switchOp = switchCode != code ? getOpLocked(ops, switchCode, uid, true)
+                        : op;
+                final int mode = switchOp.uidState.evalMode(switchOp.op, switchOp.getMode());
+                if (mode != AppOpsManager.MODE_ALLOWED) {
+                    if (DEBUG) Slog.d(TAG, "noteOperation: reject #" + mode + " for code "
+                            + switchCode + " (" + code + ") uid " + uid + " package "
+                            + packageName + " flags: " + AppOpsManager.flagsToString(flags));
+                    attributedOp.rejected(uidState.getState(), flags);
+                    scheduleOpNotedIfNeededLocked(code, uid, packageName, attributionTag, flags,
+                            mode);
+                    return new SyncNotedAppOp(mode, code, attributionTag, packageName);
+                }
+            }
+            if (DEBUG) {
+                Slog.d(TAG,
+                        "noteOperation: allowing code " + code + " uid " + uid + " package "
+                                + packageName + (attributionTag == null ? ""
+                                : "." + attributionTag) + " flags: "
+                                + AppOpsManager.flagsToString(flags));
+            }
+            scheduleOpNotedIfNeededLocked(code, uid, packageName, attributionTag, flags,
+                    AppOpsManager.MODE_ALLOWED);
+            attributedOp.accessed(proxyUid, proxyPackageName, proxyAttributionTag,
+                    uidState.getState(),
+                    flags);
+
+            if (shouldCollectAsyncNotedOp) {
+                collectAsyncNotedOp(uid, packageName, code, attributionTag, flags, message,
+                        shouldCollectMessage);
+            }
+
+            return new SyncNotedAppOp(AppOpsManager.MODE_ALLOWED, code, attributionTag,
+                    packageName);
+        }
     }
 
     // TODO moltmann: Allow watching for attribution ops
     @Override
     public void startWatchingActive(int[] ops, IAppOpsActiveCallback callback) {
-        mAppOpsService.startWatchingActive(ops, callback);
+        int watchedUid = Process.INVALID_UID;
+        final int callingUid = Binder.getCallingUid();
+        final int callingPid = Binder.getCallingPid();
+        if (mContext.checkCallingOrSelfPermission(Manifest.permission.WATCH_APPOPS)
+                != PackageManager.PERMISSION_GRANTED) {
+            watchedUid = callingUid;
+        }
+        if (ops != null) {
+            Preconditions.checkArrayElementsInRange(ops, 0,
+                    AppOpsManager._NUM_OP - 1, "Invalid op code in: " + Arrays.toString(ops));
+        }
+        if (callback == null) {
+            return;
+        }
+        synchronized (this) {
+            SparseArray<ActiveCallback> callbacks = mActiveWatchers.get(callback.asBinder());
+            if (callbacks == null) {
+                callbacks = new SparseArray<>();
+                mActiveWatchers.put(callback.asBinder(), callbacks);
+            }
+            final ActiveCallback activeCallback = new ActiveCallback(callback, watchedUid,
+                    callingUid, callingPid);
+            for (int op : ops) {
+                callbacks.put(op, activeCallback);
+            }
+        }
     }
 
     @Override
     public void stopWatchingActive(IAppOpsActiveCallback callback) {
-        mAppOpsService.stopWatchingActive(callback);
+        if (callback == null) {
+            return;
+        }
+        synchronized (this) {
+            final SparseArray<ActiveCallback> activeCallbacks =
+                    mActiveWatchers.remove(callback.asBinder());
+            if (activeCallbacks == null) {
+                return;
+            }
+            final int callbackCount = activeCallbacks.size();
+            for (int i = 0; i < callbackCount; i++) {
+                activeCallbacks.valueAt(i).destroy();
+            }
+        }
     }
 
     @Override
     public void startWatchingStarted(int[] ops, @NonNull IAppOpsStartedCallback callback) {
-        mAppOpsService.startWatchingStarted(ops, callback);
+        int watchedUid = Process.INVALID_UID;
+        final int callingUid = Binder.getCallingUid();
+        final int callingPid = Binder.getCallingPid();
+        if (mContext.checkCallingOrSelfPermission(Manifest.permission.WATCH_APPOPS)
+                != PackageManager.PERMISSION_GRANTED) {
+            watchedUid = callingUid;
+        }
+
+        Preconditions.checkArgument(!ArrayUtils.isEmpty(ops), "Ops cannot be null or empty");
+        Preconditions.checkArrayElementsInRange(ops, 0, AppOpsManager._NUM_OP - 1,
+                "Invalid op code in: " + Arrays.toString(ops));
+        Objects.requireNonNull(callback, "Callback cannot be null");
+
+        synchronized (this) {
+            SparseArray<StartedCallback> callbacks = mStartedWatchers.get(callback.asBinder());
+            if (callbacks == null) {
+                callbacks = new SparseArray<>();
+                mStartedWatchers.put(callback.asBinder(), callbacks);
+            }
+
+            final StartedCallback startedCallback = new StartedCallback(callback, watchedUid,
+                    callingUid, callingPid);
+            for (int op : ops) {
+                callbacks.put(op, startedCallback);
+            }
+        }
     }
 
     @Override
     public void stopWatchingStarted(IAppOpsStartedCallback callback) {
-        mAppOpsService.stopWatchingStarted(callback);
+        Objects.requireNonNull(callback, "Callback cannot be null");
+
+        synchronized (this) {
+            final SparseArray<StartedCallback> startedCallbacks =
+                    mStartedWatchers.remove(callback.asBinder());
+            if (startedCallbacks == null) {
+                return;
+            }
+
+            final int callbackCount = startedCallbacks.size();
+            for (int i = 0; i < callbackCount; i++) {
+                startedCallbacks.valueAt(i).destroy();
+            }
+        }
     }
 
     @Override
     public void startWatchingNoted(@NonNull int[] ops, @NonNull IAppOpsNotedCallback callback) {
-        mAppOpsService.startWatchingNoted(ops, callback);
+        int watchedUid = Process.INVALID_UID;
+        final int callingUid = Binder.getCallingUid();
+        final int callingPid = Binder.getCallingPid();
+        if (mContext.checkCallingOrSelfPermission(Manifest.permission.WATCH_APPOPS)
+                != PackageManager.PERMISSION_GRANTED) {
+            watchedUid = callingUid;
+        }
+        Preconditions.checkArgument(!ArrayUtils.isEmpty(ops), "Ops cannot be null or empty");
+        Preconditions.checkArrayElementsInRange(ops, 0, AppOpsManager._NUM_OP - 1,
+                "Invalid op code in: " + Arrays.toString(ops));
+        Objects.requireNonNull(callback, "Callback cannot be null");
+        synchronized (this) {
+            SparseArray<NotedCallback> callbacks = mNotedWatchers.get(callback.asBinder());
+            if (callbacks == null) {
+                callbacks = new SparseArray<>();
+                mNotedWatchers.put(callback.asBinder(), callbacks);
+            }
+            final NotedCallback notedCallback = new NotedCallback(callback, watchedUid,
+                    callingUid, callingPid);
+            for (int op : ops) {
+                callbacks.put(op, notedCallback);
+            }
+        }
     }
 
     @Override
     public void stopWatchingNoted(IAppOpsNotedCallback callback) {
-        mAppOpsService.stopWatchingNoted(callback);
+        Objects.requireNonNull(callback, "Callback cannot be null");
+        synchronized (this) {
+            final SparseArray<NotedCallback> notedCallbacks =
+                    mNotedWatchers.remove(callback.asBinder());
+            if (notedCallbacks == null) {
+                return;
+            }
+            final int callbackCount = notedCallbacks.size();
+            for (int i = 0; i < callbackCount; i++) {
+                notedCallbacks.valueAt(i).destroy();
+            }
+        }
     }
 
     /**
@@ -772,7 +2842,7 @@
         int uid = Binder.getCallingUid();
         Pair<String, Integer> key = getAsyncNotedOpsKey(packageName, uid);
 
-        mAppOpsService.verifyPackage(uid, packageName);
+        verifyAndGetBypass(uid, packageName, null);
 
         synchronized (this) {
             RemoteCallbackList<IAppOpsAsyncNotedCallback> callbacks = mAsyncOpWatchers.get(key);
@@ -802,7 +2872,7 @@
         int uid = Binder.getCallingUid();
         Pair<String, Integer> key = getAsyncNotedOpsKey(packageName, uid);
 
-        mAppOpsService.verifyPackage(uid, packageName);
+        verifyAndGetBypass(uid, packageName, null);
 
         synchronized (this) {
             RemoteCallbackList<IAppOpsAsyncNotedCallback> callbacks = mAsyncOpWatchers.get(key);
@@ -821,7 +2891,7 @@
 
         int uid = Binder.getCallingUid();
 
-        mAppOpsService.verifyPackage(uid, packageName);
+        verifyAndGetBypass(uid, packageName, null);
 
         synchronized (this) {
             return mUnforwardedAsyncNotedOps.remove(getAsyncNotedOpsKey(packageName, uid));
@@ -844,49 +2914,54 @@
             boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp, @NonNull String message,
             boolean shouldCollectMessage, @AttributionFlags int attributionFlags,
             int attributionChainId) {
+        verifyIncomingUid(uid);
+        verifyIncomingOp(code);
         if (!isIncomingPackageValid(packageName, UserHandle.getUserId(uid))) {
             return new SyncNotedAppOp(AppOpsManager.MODE_ERRORED, code, attributionTag,
                     packageName);
         }
 
-        int result = mAppOpsService.startOperation(clientId, code, uid, packageName,
-                attributionTag, startIfModeDefault, message,
-                attributionFlags, attributionChainId);
-
         String resolvedPackageName = AppOpsManager.resolvePackageName(uid, packageName);
-
-        boolean isAttributionTagValid = mAppOpsService.isAttributionTagValid(uid,
-                resolvedPackageName, attributionTag, null);
-
-        if (shouldCollectAsyncNotedOp && result == MODE_ALLOWED) {
-            collectAsyncNotedOp(uid, resolvedPackageName, code,
-                    isAttributionTagValid ? attributionTag : null, AppOpsManager.OP_FLAG_SELF,
-                    message, shouldCollectMessage);
+        if (resolvedPackageName == null) {
+            return new SyncNotedAppOp(AppOpsManager.MODE_IGNORED, code, attributionTag,
+                    packageName);
         }
 
-        return new SyncNotedAppOp(result, code, isAttributionTagValid ? attributionTag : null,
-                resolvedPackageName);
+        // As a special case for OP_RECORD_AUDIO_HOTWORD, which we use only for attribution
+        // purposes and not as a check, also make sure that the caller is allowed to access
+        // the data gated by OP_RECORD_AUDIO.
+        //
+        // TODO: Revert this change before Android 12.
+        if (code == OP_RECORD_AUDIO_HOTWORD || code == OP_RECEIVE_AMBIENT_TRIGGER_AUDIO) {
+            int result = checkOperation(OP_RECORD_AUDIO, uid, packageName);
+            if (result != AppOpsManager.MODE_ALLOWED) {
+                return new SyncNotedAppOp(result, code, attributionTag, packageName);
+            }
+        }
+        return startOperationUnchecked(clientId, code, uid, packageName, attributionTag,
+                Process.INVALID_UID, null, null, OP_FLAG_SELF, startIfModeDefault,
+                shouldCollectAsyncNotedOp, message, shouldCollectMessage, attributionFlags,
+                attributionChainId, /*dryRun*/ false);
     }
 
     @Override
-    public SyncNotedAppOp startProxyOperation(IBinder clientId, int code,
+    public SyncNotedAppOp startProxyOperation(@NonNull IBinder clientId, int code,
             @NonNull AttributionSource attributionSource, boolean startIfModeDefault,
             boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
             boolean skipProxyOperation, @AttributionFlags int proxyAttributionFlags,
             @AttributionFlags int proxiedAttributionFlags, int attributionChainId) {
-        return mCheckOpsDelegateDispatcher.startProxyOperation(clientId, code,
-                attributionSource, startIfModeDefault, shouldCollectAsyncNotedOp, message,
-                shouldCollectMessage, skipProxyOperation, proxyAttributionFlags,
-                proxiedAttributionFlags, attributionChainId);
+        return mCheckOpsDelegateDispatcher.startProxyOperation(clientId, code, attributionSource,
+                startIfModeDefault, shouldCollectAsyncNotedOp, message, shouldCollectMessage,
+                skipProxyOperation, proxyAttributionFlags, proxiedAttributionFlags,
+                attributionChainId);
     }
 
-    private SyncNotedAppOp startProxyOperationImpl(IBinder clientId, int code,
+    private SyncNotedAppOp startProxyOperationImpl(@NonNull IBinder clientId, int code,
             @NonNull AttributionSource attributionSource,
             boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp, String message,
             boolean shouldCollectMessage, boolean skipProxyOperation, @AttributionFlags
             int proxyAttributionFlags, @AttributionFlags int proxiedAttributionFlags,
             int attributionChainId) {
-
         final int proxyUid = attributionSource.getUid();
         final String proxyPackageName = attributionSource.getPackageName();
         final String proxyAttributionTag = attributionSource.getAttributionTag();
@@ -934,68 +3009,147 @@
 
         if (!skipProxyOperation) {
             // Test if the proxied operation will succeed before starting the proxy operation
-            final int testProxiedOp = mAppOpsService.startOperationUnchecked(clientId, code,
+            final SyncNotedAppOp testProxiedOp = startOperationUnchecked(clientId, code,
                     proxiedUid, resolvedProxiedPackageName, proxiedAttributionTag, proxyUid,
                     resolvedProxyPackageName, proxyAttributionTag, proxiedFlags, startIfModeDefault,
+                    shouldCollectAsyncNotedOp, message, shouldCollectMessage,
                     proxiedAttributionFlags, attributionChainId, /*dryRun*/ true);
-
-            boolean isTestProxiedAttributionTagValid =
-                    mAppOpsService.isAttributionTagValid(proxiedUid, resolvedProxiedPackageName,
-                            proxiedAttributionTag, resolvedProxyPackageName);
-
-            if (!shouldStartForMode(testProxiedOp, startIfModeDefault)) {
-                return new SyncNotedAppOp(testProxiedOp, code,
-                        isTestProxiedAttributionTagValid ? proxiedAttributionTag : null,
-                        resolvedProxiedPackageName);
+            if (!shouldStartForMode(testProxiedOp.getOpMode(), startIfModeDefault)) {
+                return testProxiedOp;
             }
 
             final int proxyFlags = isProxyTrusted ? AppOpsManager.OP_FLAG_TRUSTED_PROXY
                     : AppOpsManager.OP_FLAG_UNTRUSTED_PROXY;
 
-            final int proxyAppOp = mAppOpsService.startOperationUnchecked(clientId, code, proxyUid,
+            final SyncNotedAppOp proxyAppOp = startOperationUnchecked(clientId, code, proxyUid,
                     resolvedProxyPackageName, proxyAttributionTag, Process.INVALID_UID, null, null,
-                    proxyFlags, startIfModeDefault, proxyAttributionFlags, attributionChainId,
+                    proxyFlags, startIfModeDefault, !isProxyTrusted, "proxy " + message,
+                    shouldCollectMessage, proxyAttributionFlags, attributionChainId,
                     /*dryRun*/ false);
-
-            boolean isProxyAttributionTagValid = mAppOpsService.isAttributionTagValid(proxyUid,
-                    resolvedProxyPackageName, proxyAttributionTag, null);
-
-            if (!shouldStartForMode(proxyAppOp, startIfModeDefault)) {
-                return new SyncNotedAppOp(proxyAppOp, code,
-                        isProxyAttributionTagValid ? proxyAttributionTag : null,
-                        resolvedProxyPackageName);
-            }
-
-            if (shouldCollectAsyncNotedOp) {
-                collectAsyncNotedOp(proxyUid, resolvedProxyPackageName, code,
-                        isProxyAttributionTagValid ? proxyAttributionTag : null, proxyFlags,
-                        message, shouldCollectMessage);
+            if (!shouldStartForMode(proxyAppOp.getOpMode(), startIfModeDefault)) {
+                return proxyAppOp;
             }
         }
 
-        final int proxiedAppOp = mAppOpsService.startOperationUnchecked(clientId, code, proxiedUid,
-                resolvedProxiedPackageName, proxiedAttributionTag, proxyUid,
-                resolvedProxyPackageName, proxyAttributionTag, proxiedFlags, startIfModeDefault,
-                proxiedAttributionFlags, attributionChainId,/*dryRun*/ false);
-
-        boolean isProxiedAttributionTagValid = mAppOpsService.isAttributionTagValid(proxiedUid,
-                resolvedProxiedPackageName, proxiedAttributionTag, resolvedProxyPackageName);
-
-        if (shouldCollectAsyncNotedOp && proxiedAppOp == MODE_ALLOWED) {
-            collectAsyncNotedOp(proxyUid, resolvedProxiedPackageName, code,
-                    isProxiedAttributionTagValid ? proxiedAttributionTag : null,
-                    proxiedAttributionFlags, message, shouldCollectMessage);
-        }
-
-        return new SyncNotedAppOp(proxiedAppOp, code,
-                isProxiedAttributionTagValid ? proxiedAttributionTag : null,
-                resolvedProxiedPackageName);
+        return startOperationUnchecked(clientId, code, proxiedUid, resolvedProxiedPackageName,
+                proxiedAttributionTag, proxyUid, resolvedProxyPackageName, proxyAttributionTag,
+                proxiedFlags, startIfModeDefault, shouldCollectAsyncNotedOp, message,
+                shouldCollectMessage, proxiedAttributionFlags, attributionChainId,
+                /*dryRun*/ false);
     }
 
     private boolean shouldStartForMode(int mode, boolean startIfModeDefault) {
         return (mode == MODE_ALLOWED || (mode == MODE_DEFAULT && startIfModeDefault));
     }
 
+    private SyncNotedAppOp startOperationUnchecked(IBinder clientId, int code, int uid,
+            @NonNull String packageName, @Nullable String attributionTag, int proxyUid,
+            String proxyPackageName, @Nullable String proxyAttributionTag, @OpFlags int flags,
+            boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp, @Nullable String message,
+            boolean shouldCollectMessage, @AttributionFlags int attributionFlags,
+            int attributionChainId, boolean dryRun) {
+        PackageVerificationResult pvr;
+        try {
+            pvr = verifyAndGetBypass(uid, packageName, attributionTag, proxyPackageName);
+            if (!pvr.isAttributionTagValid) {
+                attributionTag = null;
+            }
+        } catch (SecurityException e) {
+            Slog.e(TAG, "startOperation", e);
+            return new SyncNotedAppOp(AppOpsManager.MODE_ERRORED, code, attributionTag,
+                    packageName);
+        }
+
+        boolean isRestricted = false;
+        int startType = START_TYPE_FAILED;
+        synchronized (this) {
+            final Ops ops = getOpsLocked(uid, packageName, attributionTag,
+                    pvr.isAttributionTagValid, pvr.bypass, /* edit */ true);
+            if (ops == null) {
+                if (!dryRun) {
+                    scheduleOpStartedIfNeededLocked(code, uid, packageName, attributionTag,
+                            flags, AppOpsManager.MODE_IGNORED, startType, attributionFlags,
+                            attributionChainId);
+                }
+                if (DEBUG) Slog.d(TAG, "startOperation: no op for code " + code + " uid " + uid
+                        + " package " + packageName + " flags: "
+                        + AppOpsManager.flagsToString(flags));
+                return new SyncNotedAppOp(AppOpsManager.MODE_ERRORED, code, attributionTag,
+                        packageName);
+            }
+            final Op op = getOpLocked(ops, code, uid, true);
+            final AttributedOp attributedOp = op.getOrCreateAttribution(op, attributionTag);
+            final UidState uidState = ops.uidState;
+            isRestricted = isOpRestrictedLocked(uid, code, packageName, attributionTag, pvr.bypass,
+                    false);
+            final int switchCode = AppOpsManager.opToSwitch(code);
+            // If there is a non-default per UID policy (we set UID op mode only if
+            // non-default) it takes over, otherwise use the per package policy.
+            if (uidState.getUidMode(switchCode) != AppOpsManager.opToDefaultMode(switchCode)) {
+                final int uidMode = uidState.evalMode(code, uidState.getUidMode(switchCode));
+                if (!shouldStartForMode(uidMode, startIfModeDefault)) {
+                    if (DEBUG) {
+                        Slog.d(TAG, "startOperation: uid reject #" + uidMode + " for code "
+                                + switchCode + " (" + code + ") uid " + uid + " package "
+                                + packageName + " flags: " + AppOpsManager.flagsToString(flags));
+                    }
+                    if (!dryRun) {
+                        attributedOp.rejected(uidState.getState(), flags);
+                        scheduleOpStartedIfNeededLocked(code, uid, packageName, attributionTag,
+                                flags, uidMode, startType, attributionFlags, attributionChainId);
+                    }
+                    return new SyncNotedAppOp(uidMode, code, attributionTag, packageName);
+                }
+            } else {
+                final Op switchOp = switchCode != code ? getOpLocked(ops, switchCode, uid, true)
+                        : op;
+                final int mode = switchOp.uidState.evalMode(switchOp.op, switchOp.getMode());
+                if (mode != AppOpsManager.MODE_ALLOWED
+                        && (!startIfModeDefault || mode != MODE_DEFAULT)) {
+                    if (DEBUG) Slog.d(TAG, "startOperation: reject #" + mode + " for code "
+                            + switchCode + " (" + code + ") uid " + uid + " package "
+                            + packageName + " flags: " + AppOpsManager.flagsToString(flags));
+                    if (!dryRun) {
+                        attributedOp.rejected(uidState.getState(), flags);
+                        scheduleOpStartedIfNeededLocked(code, uid, packageName, attributionTag,
+                                flags, mode, startType, attributionFlags, attributionChainId);
+                    }
+                    return new SyncNotedAppOp(mode, code, attributionTag, packageName);
+                }
+            }
+            if (DEBUG) Slog.d(TAG, "startOperation: allowing code " + code + " uid " + uid
+                    + " package " + packageName + " restricted: " + isRestricted
+                    + " flags: " + AppOpsManager.flagsToString(flags));
+            if (!dryRun) {
+                try {
+                    if (isRestricted) {
+                        attributedOp.createPaused(clientId, proxyUid, proxyPackageName,
+                                proxyAttributionTag, uidState.getState(), flags,
+                                attributionFlags, attributionChainId);
+                    } else {
+                        attributedOp.started(clientId, proxyUid, proxyPackageName,
+                                proxyAttributionTag, uidState.getState(), flags,
+                                attributionFlags, attributionChainId);
+                        startType = START_TYPE_STARTED;
+                    }
+                } catch (RemoteException e) {
+                    throw new RuntimeException(e);
+                }
+                scheduleOpStartedIfNeededLocked(code, uid, packageName, attributionTag, flags,
+                        isRestricted ? MODE_IGNORED : MODE_ALLOWED, startType, attributionFlags,
+                        attributionChainId);
+            }
+        }
+
+        if (shouldCollectAsyncNotedOp && !dryRun && !isRestricted) {
+            collectAsyncNotedOp(uid, packageName, code, attributionTag, AppOpsManager.OP_FLAG_SELF,
+                    message, shouldCollectMessage);
+        }
+
+        return new SyncNotedAppOp(isRestricted ? MODE_IGNORED : MODE_ALLOWED, code, attributionTag,
+                packageName);
+    }
+
     @Override
     public void finishOperation(IBinder clientId, int code, int uid, String packageName,
             String attributionTag) {
@@ -1005,11 +3159,22 @@
 
     private void finishOperationImpl(IBinder clientId, int code, int uid, String packageName,
             String attributionTag) {
-        mAppOpsService.finishOperation(clientId, code, uid, packageName, attributionTag);
+        verifyIncomingUid(uid);
+        verifyIncomingOp(code);
+        if (!isIncomingPackageValid(packageName, UserHandle.getUserId(uid))) {
+            return;
+        }
+
+        String resolvedPackageName = AppOpsManager.resolvePackageName(uid, packageName);
+        if (resolvedPackageName == null) {
+            return;
+        }
+
+        finishOperationUnchecked(clientId, code, uid, resolvedPackageName, attributionTag);
     }
 
     @Override
-    public void finishProxyOperation(IBinder clientId, int code,
+    public void finishProxyOperation(@NonNull IBinder clientId, int code,
             @NonNull AttributionSource attributionSource, boolean skipProxyOperation) {
         mCheckOpsDelegateDispatcher.finishProxyOperation(clientId, code, attributionSource,
                 skipProxyOperation);
@@ -1041,8 +3206,8 @@
         }
 
         if (!skipProxyOperation) {
-            mAppOpsService.finishOperationUnchecked(clientId, code, proxyUid,
-                    resolvedProxyPackageName, proxyAttributionTag);
+            finishOperationUnchecked(clientId, code, proxyUid, resolvedProxyPackageName,
+                    proxyAttributionTag);
         }
 
         String resolvedProxiedPackageName = AppOpsManager.resolvePackageName(proxiedUid,
@@ -1051,12 +3216,209 @@
             return null;
         }
 
-        mAppOpsService.finishOperationUnchecked(clientId, code, proxiedUid,
-                resolvedProxiedPackageName, proxiedAttributionTag);
+        finishOperationUnchecked(clientId, code, proxiedUid, resolvedProxiedPackageName,
+                proxiedAttributionTag);
 
         return null;
     }
 
+    private void finishOperationUnchecked(IBinder clientId, int code, int uid, String packageName,
+            String attributionTag) {
+        PackageVerificationResult pvr;
+        try {
+            pvr = verifyAndGetBypass(uid, packageName, attributionTag);
+            if (!pvr.isAttributionTagValid) {
+                attributionTag = null;
+            }
+        } catch (SecurityException e) {
+            Slog.e(TAG, "Cannot finishOperation", e);
+            return;
+        }
+
+        synchronized (this) {
+            Op op = getOpLocked(code, uid, packageName, attributionTag, pvr.isAttributionTagValid,
+                    pvr.bypass, /* edit */ true);
+            if (op == null) {
+                Slog.e(TAG, "Operation not found: uid=" + uid + " pkg=" + packageName + "("
+                        + attributionTag + ") op=" + AppOpsManager.opToName(code));
+                return;
+            }
+            final AttributedOp attributedOp = op.mAttributions.get(attributionTag);
+            if (attributedOp == null) {
+                Slog.e(TAG, "Attribution not found: uid=" + uid + " pkg=" + packageName + "("
+                        + attributionTag + ") op=" + AppOpsManager.opToName(code));
+                return;
+            }
+
+            if (attributedOp.isRunning() || attributedOp.isPaused()) {
+                attributedOp.finished(clientId);
+            } else {
+                Slog.e(TAG, "Operation not started: uid=" + uid + " pkg=" + packageName + "("
+                        + attributionTag + ") op=" + AppOpsManager.opToName(code));
+            }
+        }
+    }
+
+    void scheduleOpActiveChangedIfNeededLocked(int code, int uid, @NonNull
+            String packageName, @Nullable String attributionTag, boolean active, @AttributionFlags
+            int attributionFlags, int attributionChainId) {
+        ArraySet<ActiveCallback> dispatchedCallbacks = null;
+        final int callbackListCount = mActiveWatchers.size();
+        for (int i = 0; i < callbackListCount; i++) {
+            final SparseArray<ActiveCallback> callbacks = mActiveWatchers.valueAt(i);
+            ActiveCallback callback = callbacks.get(code);
+            if (callback != null) {
+                if (callback.mWatchingUid >= 0 && callback.mWatchingUid != uid) {
+                    continue;
+                }
+                if (dispatchedCallbacks == null) {
+                    dispatchedCallbacks = new ArraySet<>();
+                }
+                dispatchedCallbacks.add(callback);
+            }
+        }
+        if (dispatchedCallbacks == null) {
+            return;
+        }
+        mHandler.sendMessage(PooledLambda.obtainMessage(
+                AppOpsService::notifyOpActiveChanged,
+                this, dispatchedCallbacks, code, uid, packageName, attributionTag, active,
+                attributionFlags, attributionChainId));
+    }
+
+    private void notifyOpActiveChanged(ArraySet<ActiveCallback> callbacks,
+            int code, int uid, @NonNull String packageName, @Nullable String attributionTag,
+            boolean active, @AttributionFlags int attributionFlags, int attributionChainId) {
+        // There are features watching for mode changes such as window manager
+        // and location manager which are in our process. The callbacks in these
+        // features may require permissions our remote caller does not have.
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final int callbackCount = callbacks.size();
+            for (int i = 0; i < callbackCount; i++) {
+                final ActiveCallback callback = callbacks.valueAt(i);
+                try {
+                    if (shouldIgnoreCallback(code, callback.mCallingPid, callback.mCallingUid)) {
+                        continue;
+                    }
+                    callback.mCallback.opActiveChanged(code, uid, packageName, attributionTag,
+                            active, attributionFlags, attributionChainId);
+                } catch (RemoteException e) {
+                    /* do nothing */
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
+    void scheduleOpStartedIfNeededLocked(int code, int uid, String pkgName,
+            String attributionTag, @OpFlags int flags, @Mode int result,
+            @AppOpsManager.OnOpStartedListener.StartedType int startedType,
+            @AttributionFlags int attributionFlags, int attributionChainId) {
+        ArraySet<StartedCallback> dispatchedCallbacks = null;
+        final int callbackListCount = mStartedWatchers.size();
+        for (int i = 0; i < callbackListCount; i++) {
+            final SparseArray<StartedCallback> callbacks = mStartedWatchers.valueAt(i);
+
+            StartedCallback callback = callbacks.get(code);
+            if (callback != null) {
+                if (callback.mWatchingUid >= 0 && callback.mWatchingUid != uid) {
+                    continue;
+                }
+
+                if (dispatchedCallbacks == null) {
+                    dispatchedCallbacks = new ArraySet<>();
+                }
+                dispatchedCallbacks.add(callback);
+            }
+        }
+
+        if (dispatchedCallbacks == null) {
+            return;
+        }
+
+        mHandler.sendMessage(PooledLambda.obtainMessage(
+                AppOpsService::notifyOpStarted,
+                this, dispatchedCallbacks, code, uid, pkgName, attributionTag, flags,
+                result, startedType, attributionFlags, attributionChainId));
+    }
+
+    private void notifyOpStarted(ArraySet<StartedCallback> callbacks,
+            int code, int uid, String packageName, String attributionTag, @OpFlags int flags,
+            @Mode int result, @AppOpsManager.OnOpStartedListener.StartedType int startedType,
+            @AttributionFlags int attributionFlags, int attributionChainId) {
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final int callbackCount = callbacks.size();
+            for (int i = 0; i < callbackCount; i++) {
+                final StartedCallback callback = callbacks.valueAt(i);
+                try {
+                    if (shouldIgnoreCallback(code, callback.mCallingPid, callback.mCallingUid)) {
+                        continue;
+                    }
+                    callback.mCallback.opStarted(code, uid, packageName, attributionTag, flags,
+                            result, startedType, attributionFlags, attributionChainId);
+                } catch (RemoteException e) {
+                    /* do nothing */
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
+    private void scheduleOpNotedIfNeededLocked(int code, int uid, String packageName,
+            String attributionTag, @OpFlags int flags, @Mode int result) {
+        ArraySet<NotedCallback> dispatchedCallbacks = null;
+        final int callbackListCount = mNotedWatchers.size();
+        for (int i = 0; i < callbackListCount; i++) {
+            final SparseArray<NotedCallback> callbacks = mNotedWatchers.valueAt(i);
+            final NotedCallback callback = callbacks.get(code);
+            if (callback != null) {
+                if (callback.mWatchingUid >= 0 && callback.mWatchingUid != uid) {
+                    continue;
+                }
+                if (dispatchedCallbacks == null) {
+                    dispatchedCallbacks = new ArraySet<>();
+                }
+                dispatchedCallbacks.add(callback);
+            }
+        }
+        if (dispatchedCallbacks == null) {
+            return;
+        }
+        mHandler.sendMessage(PooledLambda.obtainMessage(
+                AppOpsService::notifyOpChecked,
+                this, dispatchedCallbacks, code, uid, packageName, attributionTag, flags,
+                result));
+    }
+
+    private void notifyOpChecked(ArraySet<NotedCallback> callbacks,
+            int code, int uid, String packageName, String attributionTag, @OpFlags int flags,
+            @Mode int result) {
+        // There are features watching for checks in our process. The callbacks in
+        // these features may require permissions our remote caller does not have.
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final int callbackCount = callbacks.size();
+            for (int i = 0; i < callbackCount; i++) {
+                final NotedCallback callback = callbacks.valueAt(i);
+                try {
+                    if (shouldIgnoreCallback(code, callback.mCallingPid, callback.mCallingUid)) {
+                        continue;
+                    }
+                    callback.mCallback.opNoted(code, uid, packageName, attributionTag, flags,
+                            result);
+                } catch (RemoteException e) {
+                    /* do nothing */
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
     @Override
     public int permissionToOpCode(String permission) {
         if (permission == null) {
@@ -1114,6 +3476,13 @@
                 Binder.getCallingPid(), Binder.getCallingUid(), null);
     }
 
+    private boolean shouldIgnoreCallback(int op, int watcherPid, int watcherUid) {
+        // If it's a restricted read op, ignore it if watcher doesn't have manage ops permission,
+        // as watcher should not use this to signal if the value is changed.
+        return opRestrictsRead(op) && mContext.checkPermission(Manifest.permission.MANAGE_APPOPS,
+                watcherPid, watcherUid) != PackageManager.PERMISSION_GRANTED;
+    }
+
     private void verifyIncomingOp(int op) {
         if (op >= 0 && op < AppOpsManager._NUM_OP) {
             // Enforce manage appops permission if it's a restricted read op.
@@ -1154,6 +3523,35 @@
                 || resolveUid(resolvedPackage) != Process.INVALID_UID;
     }
 
+    private boolean isCallerAndAttributionTrusted(@NonNull AttributionSource attributionSource) {
+        if (attributionSource.getUid() != Binder.getCallingUid()
+                && attributionSource.isTrusted(mContext)) {
+            return true;
+        }
+        return mContext.checkPermission(android.Manifest.permission.UPDATE_APP_OPS_STATS,
+                Binder.getCallingPid(), Binder.getCallingUid(), null)
+                == PackageManager.PERMISSION_GRANTED;
+    }
+
+    private @Nullable UidState getUidStateLocked(int uid, boolean edit) {
+        UidState uidState = mUidStates.get(uid);
+        if (uidState == null) {
+            if (!edit) {
+                return null;
+            }
+            uidState = new UidState(uid);
+            mUidStates.put(uid, uidState);
+        }
+
+        return uidState;
+    }
+
+    private void updateAppWidgetVisibility(SparseArray<String> uidPackageNames, boolean visible) {
+        synchronized (this) {
+            getUidStateTracker().updateAppWidgetVisibility(uidPackageNames, visible);
+        }
+    }
+
     /**
      * @return {@link PackageManagerInternal}
      */
@@ -1165,6 +3563,801 @@
         return mPackageManagerInternal;
     }
 
+    /**
+     * Create a restriction description matching the properties of the package.
+     *
+     * @param pkg The package to create the restriction description for
+     *
+     * @return The restriction matching the package
+     */
+    private RestrictionBypass getBypassforPackage(@NonNull AndroidPackage pkg) {
+        return new RestrictionBypass(pkg.getUid() == Process.SYSTEM_UID, pkg.isPrivileged(),
+                mContext.checkPermission(android.Manifest.permission
+                        .EXEMPT_FROM_AUDIO_RECORD_RESTRICTIONS, -1, pkg.getUid())
+                == PackageManager.PERMISSION_GRANTED);
+    }
+
+    /**
+     * @see #verifyAndGetBypass(int, String, String, String)
+     */
+    private @NonNull PackageVerificationResult verifyAndGetBypass(int uid, String packageName,
+            @Nullable String attributionTag) {
+        return verifyAndGetBypass(uid, packageName, attributionTag, null);
+    }
+
+    /**
+     * Verify that package belongs to uid and return the {@link RestrictionBypass bypass
+     * description} for the package, along with a boolean indicating whether the attribution tag is
+     * valid.
+     *
+     * @param uid The uid the package belongs to
+     * @param packageName The package the might belong to the uid
+     * @param attributionTag attribution tag or {@code null} if no need to verify
+     * @param proxyPackageName The proxy package, from which the attribution tag is to be pulled
+     *
+     * @return PackageVerificationResult containing {@link RestrictionBypass} and whether the
+     *         attribution tag is valid
+     */
+    private @NonNull PackageVerificationResult verifyAndGetBypass(int uid, String packageName,
+            @Nullable String attributionTag, @Nullable String proxyPackageName) {
+        if (uid == Process.ROOT_UID) {
+            // For backwards compatibility, don't check package name for root UID.
+            return new PackageVerificationResult(null,
+                    /* isAttributionTagValid */ true);
+        }
+        if (Process.isSdkSandboxUid(uid)) {
+            // SDK sandbox processes run in their own UID range, but their associated
+            // UID for checks should always be the UID of the package implementing SDK sandbox
+            // service.
+            // TODO: We will need to modify the callers of this function instead, so
+            // modifications and checks against the app ops state are done with the
+            // correct UID.
+            try {
+                final PackageManager pm = mContext.getPackageManager();
+                final String supplementalPackageName = pm.getSdkSandboxPackageName();
+                if (Objects.equals(packageName, supplementalPackageName)) {
+                    uid = pm.getPackageUidAsUser(supplementalPackageName,
+                            PackageManager.PackageInfoFlags.of(0), UserHandle.getUserId(uid));
+                }
+            } catch (PackageManager.NameNotFoundException e) {
+                // Shouldn't happen for the supplemental package
+                e.printStackTrace();
+            }
+        }
+
+
+        // Do not check if uid/packageName/attributionTag is already known.
+        synchronized (this) {
+            UidState uidState = mUidStates.get(uid);
+            if (uidState != null && uidState.pkgOps != null) {
+                Ops ops = uidState.pkgOps.get(packageName);
+
+                if (ops != null && (attributionTag == null || ops.knownAttributionTags.contains(
+                        attributionTag)) && ops.bypass != null) {
+                    return new PackageVerificationResult(ops.bypass,
+                            ops.validAttributionTags.contains(attributionTag));
+                }
+            }
+        }
+
+        int callingUid = Binder.getCallingUid();
+
+        // Allow any attribution tag for resolvable uids
+        int pkgUid;
+        if (Objects.equals(packageName, "com.android.shell")) {
+            // Special case for the shell which is a package but should be able
+            // to bypass app attribution tag restrictions.
+            pkgUid = Process.SHELL_UID;
+        } else {
+            pkgUid = resolveUid(packageName);
+        }
+        if (pkgUid != Process.INVALID_UID) {
+            if (pkgUid != UserHandle.getAppId(uid)) {
+                Slog.e(TAG, "Bad call made by uid " + callingUid + ". "
+                        + "Package \"" + packageName + "\" does not belong to uid " + uid + ".");
+                String otherUidMessage = DEBUG ? " but it is really " + pkgUid : " but it is not";
+                throw new SecurityException("Specified package \"" + packageName + "\" under uid "
+                        +  UserHandle.getAppId(uid) + otherUidMessage);
+            }
+            return new PackageVerificationResult(RestrictionBypass.UNRESTRICTED,
+                    /* isAttributionTagValid */ true);
+        }
+
+        int userId = UserHandle.getUserId(uid);
+        RestrictionBypass bypass = null;
+        boolean isAttributionTagValid = false;
+
+        final long ident = Binder.clearCallingIdentity();
+        try {
+            PackageManagerInternal pmInt = LocalServices.getService(PackageManagerInternal.class);
+            AndroidPackage pkg = pmInt.getPackage(packageName);
+            if (pkg != null) {
+                isAttributionTagValid = isAttributionInPackage(pkg, attributionTag);
+                pkgUid = UserHandle.getUid(userId, UserHandle.getAppId(pkg.getUid()));
+                bypass = getBypassforPackage(pkg);
+            }
+            if (!isAttributionTagValid) {
+                AndroidPackage proxyPkg = proxyPackageName != null
+                        ? pmInt.getPackage(proxyPackageName) : null;
+                // Re-check in proxy.
+                isAttributionTagValid = isAttributionInPackage(proxyPkg, attributionTag);
+                String msg;
+                if (pkg != null && isAttributionTagValid) {
+                    msg = "attributionTag " + attributionTag + " declared in manifest of the proxy"
+                            + " package " + proxyPackageName + ", this is not advised";
+                } else if (pkg != null) {
+                    msg = "attributionTag " + attributionTag + " not declared in manifest of "
+                            + packageName;
+                } else {
+                    msg = "package " + packageName + " not found, can't check for "
+                            + "attributionTag " + attributionTag;
+                }
+
+                try {
+                    if (!mPlatformCompat.isChangeEnabledByPackageName(
+                            SECURITY_EXCEPTION_ON_INVALID_ATTRIBUTION_TAG_CHANGE, packageName,
+                            userId) || !mPlatformCompat.isChangeEnabledByUid(
+                                    SECURITY_EXCEPTION_ON_INVALID_ATTRIBUTION_TAG_CHANGE,
+                            callingUid)) {
+                        // Do not override tags if overriding is not enabled for this package
+                        isAttributionTagValid = true;
+                    }
+                    Slog.e(TAG, msg);
+                } catch (RemoteException neverHappens) {
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+
+        if (pkgUid != uid) {
+            Slog.e(TAG, "Bad call made by uid " + callingUid + ". "
+                    + "Package \"" + packageName + "\" does not belong to uid " + uid + ".");
+            String otherUidMessage = DEBUG ? " but it is really " + pkgUid : " but it is not";
+            throw new SecurityException("Specified package \"" + packageName + "\" under uid " + uid
+                    + otherUidMessage);
+        }
+
+        return new PackageVerificationResult(bypass, isAttributionTagValid);
+    }
+
+    private boolean isAttributionInPackage(@Nullable AndroidPackage pkg,
+            @Nullable String attributionTag) {
+        if (pkg == null) {
+            return false;
+        } else if (attributionTag == null) {
+            return true;
+        }
+        if (pkg.getAttributions() != null) {
+            int numAttributions = pkg.getAttributions().size();
+            for (int i = 0; i < numAttributions; i++) {
+                if (pkg.getAttributions().get(i).getTag().equals(attributionTag)) {
+                    return true;
+                }
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * Get (and potentially create) ops.
+     *
+     * @param uid The uid the package belongs to
+     * @param packageName The name of the package
+     * @param attributionTag attribution tag
+     * @param isAttributionTagValid whether the given attribution tag is valid
+     * @param bypass When to bypass certain op restrictions (can be null if edit == false)
+     * @param edit If an ops does not exist, create the ops?
+
+     * @return The ops
+     */
+    private Ops getOpsLocked(int uid, String packageName, @Nullable String attributionTag,
+            boolean isAttributionTagValid, @Nullable RestrictionBypass bypass, boolean edit) {
+        UidState uidState = getUidStateLocked(uid, edit);
+        if (uidState == null) {
+            return null;
+        }
+
+        if (uidState.pkgOps == null) {
+            if (!edit) {
+                return null;
+            }
+            uidState.pkgOps = new ArrayMap<>();
+        }
+
+        Ops ops = uidState.pkgOps.get(packageName);
+        if (ops == null) {
+            if (!edit) {
+                return null;
+            }
+            ops = new Ops(packageName, uidState);
+            uidState.pkgOps.put(packageName, ops);
+        }
+
+        if (edit) {
+            if (bypass != null) {
+                ops.bypass = bypass;
+            }
+
+            if (attributionTag != null) {
+                ops.knownAttributionTags.add(attributionTag);
+                if (isAttributionTagValid) {
+                    ops.validAttributionTags.add(attributionTag);
+                } else {
+                    ops.validAttributionTags.remove(attributionTag);
+                }
+            }
+        }
+
+        return ops;
+    }
+
+    @Override
+    public void scheduleWriteLocked() {
+        if (!mWriteScheduled) {
+            mWriteScheduled = true;
+            mHandler.postDelayed(mWriteRunner, WRITE_DELAY);
+        }
+    }
+
+    @Override
+    public void scheduleFastWriteLocked() {
+        if (!mFastWriteScheduled) {
+            mWriteScheduled = true;
+            mFastWriteScheduled = true;
+            mHandler.removeCallbacks(mWriteRunner);
+            mHandler.postDelayed(mWriteRunner, 10*1000);
+        }
+    }
+
+    /**
+     * Get the state of an op for a uid.
+     *
+     * @param code The code of the op
+     * @param uid The uid the of the package
+     * @param packageName The package name for which to get the state for
+     * @param attributionTag The attribution tag
+     * @param isAttributionTagValid Whether the given attribution tag is valid
+     * @param bypass When to bypass certain op restrictions (can be null if edit == false)
+     * @param edit Iff {@code true} create the {@link Op} object if not yet created
+     *
+     * @return The {@link Op state} of the op
+     */
+    private @Nullable Op getOpLocked(int code, int uid, @NonNull String packageName,
+            @Nullable String attributionTag, boolean isAttributionTagValid,
+            @Nullable RestrictionBypass bypass, boolean edit) {
+        Ops ops = getOpsLocked(uid, packageName, attributionTag, isAttributionTagValid, bypass,
+                edit);
+        if (ops == null) {
+            return null;
+        }
+        return getOpLocked(ops, code, uid, edit);
+    }
+
+    private Op getOpLocked(Ops ops, int code, int uid, boolean edit) {
+        Op op = ops.get(code);
+        if (op == null) {
+            if (!edit) {
+                return null;
+            }
+            op = new Op(ops.uidState, ops.packageName, code, uid);
+            ops.put(code, op);
+        }
+        if (edit) {
+            scheduleWriteLocked();
+        }
+        return op;
+    }
+
+    private boolean isOpRestrictedDueToSuspend(int code, String packageName, int uid) {
+        if (!ArrayUtils.contains(OPS_RESTRICTED_ON_SUSPEND, code)) {
+            return false;
+        }
+        final PackageManagerInternal pmi = LocalServices.getService(PackageManagerInternal.class);
+        return pmi.isPackageSuspended(packageName, UserHandle.getUserId(uid));
+    }
+
+    private boolean isOpRestrictedLocked(int uid, int code, String packageName,
+            String attributionTag, @Nullable RestrictionBypass appBypass, boolean isCheckOp) {
+        int restrictionSetCount = mOpGlobalRestrictions.size();
+
+        for (int i = 0; i < restrictionSetCount; i++) {
+            ClientGlobalRestrictionState restrictionState = mOpGlobalRestrictions.valueAt(i);
+            if (restrictionState.hasRestriction(code)) {
+                return true;
+            }
+        }
+
+        int userHandle = UserHandle.getUserId(uid);
+        restrictionSetCount = mOpUserRestrictions.size();
+
+        for (int i = 0; i < restrictionSetCount; i++) {
+            // For each client, check that the given op is not restricted, or that the given
+            // package is exempt from the restriction.
+            ClientUserRestrictionState restrictionState = mOpUserRestrictions.valueAt(i);
+            if (restrictionState.hasRestriction(code, packageName, attributionTag, userHandle,
+                    isCheckOp)) {
+                RestrictionBypass opBypass = opAllowSystemBypassRestriction(code);
+                if (opBypass != null) {
+                    // If we are the system, bypass user restrictions for certain codes
+                    synchronized (this) {
+                        if (opBypass.isSystemUid && appBypass != null && appBypass.isSystemUid) {
+                            return false;
+                        }
+                        if (opBypass.isPrivileged && appBypass != null && appBypass.isPrivileged) {
+                            return false;
+                        }
+                        if (opBypass.isRecordAudioRestrictionExcept && appBypass != null
+                                && appBypass.isRecordAudioRestrictionExcept) {
+                            return false;
+                        }
+                    }
+                }
+                return true;
+            }
+        }
+        return false;
+    }
+
+    void readState() {
+        synchronized (mFile) {
+            synchronized (this) {
+                FileInputStream stream;
+                try {
+                    stream = mFile.openRead();
+                } catch (FileNotFoundException e) {
+                    Slog.i(TAG, "No existing app ops " + mFile.getBaseFile() + "; starting empty");
+                    return;
+                }
+                boolean success = false;
+                mUidStates.clear();
+                mAppOpsCheckingService.clearAllModes();
+                try {
+                    TypedXmlPullParser parser = Xml.resolvePullParser(stream);
+                    int type;
+                    while ((type = parser.next()) != XmlPullParser.START_TAG
+                            && type != XmlPullParser.END_DOCUMENT) {
+                        ;
+                    }
+
+                    if (type != XmlPullParser.START_TAG) {
+                        throw new IllegalStateException("no start tag found");
+                    }
+
+                    mVersionAtBoot = parser.getAttributeInt(null, "v", NO_VERSION);
+
+                    int outerDepth = parser.getDepth();
+                    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                            && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+                        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                            continue;
+                        }
+
+                        String tagName = parser.getName();
+                        if (tagName.equals("pkg")) {
+                            readPackage(parser);
+                        } else if (tagName.equals("uid")) {
+                            readUidOps(parser);
+                        } else {
+                            Slog.w(TAG, "Unknown element under <app-ops>: "
+                                    + parser.getName());
+                            XmlUtils.skipCurrentTag(parser);
+                        }
+                    }
+                    success = true;
+                } catch (IllegalStateException e) {
+                    Slog.w(TAG, "Failed parsing " + e);
+                } catch (NullPointerException e) {
+                    Slog.w(TAG, "Failed parsing " + e);
+                } catch (NumberFormatException e) {
+                    Slog.w(TAG, "Failed parsing " + e);
+                } catch (XmlPullParserException e) {
+                    Slog.w(TAG, "Failed parsing " + e);
+                } catch (IOException e) {
+                    Slog.w(TAG, "Failed parsing " + e);
+                } catch (IndexOutOfBoundsException e) {
+                    Slog.w(TAG, "Failed parsing " + e);
+                } finally {
+                    if (!success) {
+                        mUidStates.clear();
+                        mAppOpsCheckingService.clearAllModes();
+                    }
+                    try {
+                        stream.close();
+                    } catch (IOException e) {
+                    }
+                }
+            }
+        }
+    }
+
+    @VisibleForTesting
+    @GuardedBy("this")
+    void upgradeRunAnyInBackgroundLocked() {
+        for (int i = 0; i < mUidStates.size(); i++) {
+            final UidState uidState = mUidStates.valueAt(i);
+            if (uidState == null) {
+                continue;
+            }
+            SparseIntArray opModes = uidState.getNonDefaultUidModes();
+            if (opModes != null) {
+                final int idx = opModes.indexOfKey(AppOpsManager.OP_RUN_IN_BACKGROUND);
+                if (idx >= 0) {
+                    uidState.setUidMode(AppOpsManager.OP_RUN_ANY_IN_BACKGROUND,
+                            opModes.valueAt(idx));
+                }
+            }
+            if (uidState.pkgOps == null) {
+                continue;
+            }
+            boolean changed = false;
+            for (int j = 0; j < uidState.pkgOps.size(); j++) {
+                Ops ops = uidState.pkgOps.valueAt(j);
+                if (ops != null) {
+                    final Op op = ops.get(AppOpsManager.OP_RUN_IN_BACKGROUND);
+                    if (op != null && op.getMode() != AppOpsManager.opToDefaultMode(op.op)) {
+                        final Op copy = new Op(op.uidState, op.packageName,
+                                AppOpsManager.OP_RUN_ANY_IN_BACKGROUND, uidState.uid);
+                        copy.setMode(op.getMode());
+                        ops.put(AppOpsManager.OP_RUN_ANY_IN_BACKGROUND, copy);
+                        changed = true;
+                    }
+                }
+            }
+            if (changed) {
+                uidState.evalForegroundOps();
+            }
+        }
+    }
+
+    /**
+     * The interpretation of the default mode - MODE_DEFAULT - for OP_SCHEDULE_EXACT_ALARM is
+     * changing. Simultaneously, we want to change this op's mode from MODE_DEFAULT to MODE_ALLOWED
+     * for already installed apps. For newer apps, it will stay as MODE_DEFAULT.
+     */
+    @VisibleForTesting
+    @GuardedBy("this")
+    void upgradeScheduleExactAlarmLocked() {
+        final PermissionManagerServiceInternal pmsi = LocalServices.getService(
+                PermissionManagerServiceInternal.class);
+        final UserManagerInternal umi = LocalServices.getService(UserManagerInternal.class);
+        final PackageManagerInternal pmi = getPackageManagerInternal();
+
+        final String[] packagesDeclaringPermission = pmsi.getAppOpPermissionPackages(
+                AppOpsManager.opToPermission(OP_SCHEDULE_EXACT_ALARM));
+        final int[] userIds = umi.getUserIds();
+
+        for (final String pkg : packagesDeclaringPermission) {
+            for (int userId : userIds) {
+                final int uid = pmi.getPackageUid(pkg, 0, userId);
+
+                UidState uidState = mUidStates.get(uid);
+                if (uidState == null) {
+                    uidState = new UidState(uid);
+                    mUidStates.put(uid, uidState);
+                }
+                final int oldMode = uidState.getUidMode(OP_SCHEDULE_EXACT_ALARM);
+                if (oldMode == AppOpsManager.opToDefaultMode(OP_SCHEDULE_EXACT_ALARM)) {
+                    uidState.setUidMode(OP_SCHEDULE_EXACT_ALARM, MODE_ALLOWED);
+                }
+            }
+            // This appop is meant to be controlled at a uid level. So we leave package modes as
+            // they are.
+        }
+    }
+
+    private void upgradeLocked(int oldVersion) {
+        if (oldVersion >= CURRENT_VERSION) {
+            return;
+        }
+        Slog.d(TAG, "Upgrading app-ops xml from version " + oldVersion + " to " + CURRENT_VERSION);
+        switch (oldVersion) {
+            case NO_VERSION:
+                upgradeRunAnyInBackgroundLocked();
+                // fall through
+            case 1:
+                upgradeScheduleExactAlarmLocked();
+                // fall through
+            case 2:
+                // for future upgrades
+        }
+        scheduleFastWriteLocked();
+    }
+
+    private void readUidOps(TypedXmlPullParser parser) throws NumberFormatException,
+            XmlPullParserException, IOException {
+        final int uid = parser.getAttributeInt(null, "n");
+        int outerDepth = parser.getDepth();
+        int type;
+        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                continue;
+            }
+
+            String tagName = parser.getName();
+            if (tagName.equals("op")) {
+                final int code = parser.getAttributeInt(null, "n");
+                final int mode = parser.getAttributeInt(null, "m");
+                setUidMode(code, uid, mode);
+            } else {
+                Slog.w(TAG, "Unknown element under <uid-ops>: "
+                        + parser.getName());
+                XmlUtils.skipCurrentTag(parser);
+            }
+        }
+    }
+
+    private void readPackage(TypedXmlPullParser parser)
+            throws NumberFormatException, XmlPullParserException, IOException {
+        String pkgName = parser.getAttributeValue(null, "n");
+        int outerDepth = parser.getDepth();
+        int type;
+        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                continue;
+            }
+
+            String tagName = parser.getName();
+            if (tagName.equals("uid")) {
+                readUid(parser, pkgName);
+            } else {
+                Slog.w(TAG, "Unknown element under <pkg>: "
+                        + parser.getName());
+                XmlUtils.skipCurrentTag(parser);
+            }
+        }
+    }
+
+    private void readUid(TypedXmlPullParser parser, String pkgName)
+            throws NumberFormatException, XmlPullParserException, IOException {
+        int uid = parser.getAttributeInt(null, "n");
+        final UidState uidState = getUidStateLocked(uid, true);
+        int outerDepth = parser.getDepth();
+        int type;
+        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                continue;
+            }
+            String tagName = parser.getName();
+            if (tagName.equals("op")) {
+                readOp(parser, uidState, pkgName);
+            } else {
+                Slog.w(TAG, "Unknown element under <pkg>: "
+                        + parser.getName());
+                XmlUtils.skipCurrentTag(parser);
+            }
+        }
+        uidState.evalForegroundOps();
+    }
+
+    private void readAttributionOp(TypedXmlPullParser parser, @NonNull Op parent,
+            @Nullable String attribution)
+            throws NumberFormatException, IOException, XmlPullParserException {
+        final AttributedOp attributedOp = parent.getOrCreateAttribution(parent, attribution);
+
+        final long key = parser.getAttributeLong(null, "n");
+        final int uidState = extractUidStateFromKey(key);
+        final int opFlags = extractFlagsFromKey(key);
+
+        final long accessTime = parser.getAttributeLong(null, "t", 0);
+        final long rejectTime = parser.getAttributeLong(null, "r", 0);
+        final long accessDuration = parser.getAttributeLong(null, "d", -1);
+        final String proxyPkg = XmlUtils.readStringAttribute(parser, "pp");
+        final int proxyUid = parser.getAttributeInt(null, "pu", Process.INVALID_UID);
+        final String proxyAttributionTag = XmlUtils.readStringAttribute(parser, "pc");
+
+        if (accessTime > 0) {
+            attributedOp.accessed(accessTime, accessDuration, proxyUid, proxyPkg,
+                    proxyAttributionTag, uidState, opFlags);
+        }
+        if (rejectTime > 0) {
+            attributedOp.rejected(rejectTime, uidState, opFlags);
+        }
+    }
+
+    private void readOp(TypedXmlPullParser parser,
+            @NonNull UidState uidState, @NonNull String pkgName)
+            throws NumberFormatException, XmlPullParserException, IOException {
+        int opCode = parser.getAttributeInt(null, "n");
+        Op op = new Op(uidState, pkgName, opCode, uidState.uid);
+
+        final int mode = parser.getAttributeInt(null, "m", AppOpsManager.opToDefaultMode(op.op));
+        op.setMode(mode);
+
+        int outerDepth = parser.getDepth();
+        int type;
+        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                continue;
+            }
+            String tagName = parser.getName();
+            if (tagName.equals("st")) {
+                readAttributionOp(parser, op, XmlUtils.readStringAttribute(parser, "id"));
+            } else {
+                Slog.w(TAG, "Unknown element under <op>: "
+                        + parser.getName());
+                XmlUtils.skipCurrentTag(parser);
+            }
+        }
+
+        if (uidState.pkgOps == null) {
+            uidState.pkgOps = new ArrayMap<>();
+        }
+        Ops ops = uidState.pkgOps.get(pkgName);
+        if (ops == null) {
+            ops = new Ops(pkgName, uidState);
+            uidState.pkgOps.put(pkgName, ops);
+        }
+        ops.put(op.op, op);
+    }
+
+    void writeState() {
+        synchronized (mFile) {
+            FileOutputStream stream;
+            try {
+                stream = mFile.startWrite();
+            } catch (IOException e) {
+                Slog.w(TAG, "Failed to write state: " + e);
+                return;
+            }
+
+            List<AppOpsManager.PackageOps> allOps = getPackagesForOps(null);
+
+            try {
+                TypedXmlSerializer out = Xml.resolveSerializer(stream);
+                out.startDocument(null, true);
+                out.startTag(null, "app-ops");
+                out.attributeInt(null, "v", CURRENT_VERSION);
+
+                SparseArray<SparseIntArray> uidStatesClone;
+                synchronized (this) {
+                    uidStatesClone = new SparseArray<>(mUidStates.size());
+
+                    final int uidStateCount = mUidStates.size();
+                    for (int uidStateNum = 0; uidStateNum < uidStateCount; uidStateNum++) {
+                        UidState uidState = mUidStates.valueAt(uidStateNum);
+                        int uid = mUidStates.keyAt(uidStateNum);
+
+                        SparseIntArray opModes = uidState.getNonDefaultUidModes();
+                        if (opModes != null && opModes.size() > 0) {
+                            uidStatesClone.put(uid, opModes);
+                        }
+                    }
+                }
+
+                final int uidStateCount = uidStatesClone.size();
+                for (int uidStateNum = 0; uidStateNum < uidStateCount; uidStateNum++) {
+                    SparseIntArray opModes = uidStatesClone.valueAt(uidStateNum);
+                    if (opModes != null && opModes.size() > 0) {
+                        out.startTag(null, "uid");
+                        out.attributeInt(null, "n", uidStatesClone.keyAt(uidStateNum));
+                        final int opCount = opModes.size();
+                        for (int opCountNum = 0; opCountNum < opCount; opCountNum++) {
+                            final int op = opModes.keyAt(opCountNum);
+                            final int mode = opModes.valueAt(opCountNum);
+                            out.startTag(null, "op");
+                            out.attributeInt(null, "n", op);
+                            out.attributeInt(null, "m", mode);
+                            out.endTag(null, "op");
+                        }
+                        out.endTag(null, "uid");
+                    }
+                }
+
+                if (allOps != null) {
+                    String lastPkg = null;
+                    for (int i=0; i<allOps.size(); i++) {
+                        AppOpsManager.PackageOps pkg = allOps.get(i);
+                        if (!Objects.equals(pkg.getPackageName(), lastPkg)) {
+                            if (lastPkg != null) {
+                                out.endTag(null, "pkg");
+                            }
+                            lastPkg = pkg.getPackageName();
+                            if (lastPkg != null) {
+                                out.startTag(null, "pkg");
+                                out.attribute(null, "n", lastPkg);
+                            }
+                        }
+                        out.startTag(null, "uid");
+                        out.attributeInt(null, "n", pkg.getUid());
+                        List<AppOpsManager.OpEntry> ops = pkg.getOps();
+                        for (int j=0; j<ops.size(); j++) {
+                            AppOpsManager.OpEntry op = ops.get(j);
+                            out.startTag(null, "op");
+                            out.attributeInt(null, "n", op.getOp());
+                            if (op.getMode() != AppOpsManager.opToDefaultMode(op.getOp())) {
+                                out.attributeInt(null, "m", op.getMode());
+                            }
+
+                            for (String attributionTag : op.getAttributedOpEntries().keySet()) {
+                                final AttributedOpEntry attribution =
+                                        op.getAttributedOpEntries().get(attributionTag);
+
+                                final ArraySet<Long> keys = attribution.collectKeys();
+
+                                final int keyCount = keys.size();
+                                for (int k = 0; k < keyCount; k++) {
+                                    final long key = keys.valueAt(k);
+
+                                    final int uidState = AppOpsManager.extractUidStateFromKey(key);
+                                    final int flags = AppOpsManager.extractFlagsFromKey(key);
+
+                                    final long accessTime = attribution.getLastAccessTime(uidState,
+                                            uidState, flags);
+                                    final long rejectTime = attribution.getLastRejectTime(uidState,
+                                            uidState, flags);
+                                    final long accessDuration = attribution.getLastDuration(
+                                            uidState, uidState, flags);
+                                    // Proxy information for rejections is not backed up
+                                    final OpEventProxyInfo proxy = attribution.getLastProxyInfo(
+                                            uidState, uidState, flags);
+
+                                    if (accessTime <= 0 && rejectTime <= 0 && accessDuration <= 0
+                                            && proxy == null) {
+                                        continue;
+                                    }
+
+                                    String proxyPkg = null;
+                                    String proxyAttributionTag = null;
+                                    int proxyUid = Process.INVALID_UID;
+                                    if (proxy != null) {
+                                        proxyPkg = proxy.getPackageName();
+                                        proxyAttributionTag = proxy.getAttributionTag();
+                                        proxyUid = proxy.getUid();
+                                    }
+
+                                    out.startTag(null, "st");
+                                    if (attributionTag != null) {
+                                        out.attribute(null, "id", attributionTag);
+                                    }
+                                    out.attributeLong(null, "n", key);
+                                    if (accessTime > 0) {
+                                        out.attributeLong(null, "t", accessTime);
+                                    }
+                                    if (rejectTime > 0) {
+                                        out.attributeLong(null, "r", rejectTime);
+                                    }
+                                    if (accessDuration > 0) {
+                                        out.attributeLong(null, "d", accessDuration);
+                                    }
+                                    if (proxyPkg != null) {
+                                        out.attribute(null, "pp", proxyPkg);
+                                    }
+                                    if (proxyAttributionTag != null) {
+                                        out.attribute(null, "pc", proxyAttributionTag);
+                                    }
+                                    if (proxyUid >= 0) {
+                                        out.attributeInt(null, "pu", proxyUid);
+                                    }
+                                    out.endTag(null, "st");
+                                }
+                            }
+
+                            out.endTag(null, "op");
+                        }
+                        out.endTag(null, "uid");
+                    }
+                    if (lastPkg != null) {
+                        out.endTag(null, "pkg");
+                    }
+                }
+
+                out.endTag(null, "app-ops");
+                out.endDocument();
+                mFile.finishWrite(stream);
+            } catch (IOException e) {
+                Slog.w(TAG, "Failed to write state, restoring backup.", e);
+                mFile.failWrite(stream);
+            }
+        }
+        mHistoricalRegistry.writeAndClearDiscreteHistory();
+    }
+
     static class Shell extends ShellCommand {
         final IAppOpsService mInterface;
         final AppOpsService mInternal;
@@ -1178,6 +4371,7 @@
         int mode;
         int packageUid;
         int nonpackageUid;
+        final static Binder sBinder = new Binder();
         IBinder mToken;
         boolean targetsUid;
 
@@ -1198,7 +4392,7 @@
             dumpCommandHelp(pw);
         }
 
-        static int strOpToOp(String op, PrintWriter err) {
+        static private int strOpToOp(String op, PrintWriter err) {
             try {
                 return AppOpsManager.strOpToOp(op);
             } catch (IllegalArgumentException e) {
@@ -1395,24 +4589,6 @@
         pw.println("              not specified, the current user is assumed.");
     }
 
-    @Override
-    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        mAppOpsService.dump(fd, pw, args);
-
-        pw.println();
-        if (mCheckOpsDelegateDispatcher.mPolicy != null
-                && mCheckOpsDelegateDispatcher.mPolicy instanceof AppOpsPolicy) {
-            AppOpsPolicy policy = (AppOpsPolicy) mCheckOpsDelegateDispatcher.mPolicy;
-            policy.dumpTags(pw);
-        } else {
-            pw.println("  AppOps policy not set.");
-        }
-
-        if (mAudioRestrictionManager.hasActiveRestrictions()) {
-            pw.println();
-            mAudioRestrictionManager.dump(pw);
-        }
-    }
     static int onShellCommand(Shell shell, String cmd) {
         if (cmd == null) {
             return shell.handleDefaultCommands(cmd);
@@ -1616,12 +4792,14 @@
                     return 0;
                 }
                 case "write-settings": {
-                    shell.mInternal.mAppOpsService
-                            .enforceManageAppOpsModes(Binder.getCallingPid(),
+                    shell.mInternal.enforceManageAppOpsModes(Binder.getCallingPid(),
                             Binder.getCallingUid(), -1);
                     final long token = Binder.clearCallingIdentity();
                     try {
-                        shell.mInternal.mAppOpsService.writeState();
+                        synchronized (shell.mInternal) {
+                            shell.mInternal.mHandler.removeCallbacks(shell.mInternal.mWriteRunner);
+                        }
+                        shell.mInternal.writeState();
                         pw.println("Current settings written.");
                     } finally {
                         Binder.restoreCallingIdentity(token);
@@ -1629,12 +4807,11 @@
                     return 0;
                 }
                 case "read-settings": {
-                    shell.mInternal.mAppOpsService
-                            .enforceManageAppOpsModes(Binder.getCallingPid(),
-                                    Binder.getCallingUid(), -1);
+                    shell.mInternal.enforceManageAppOpsModes(Binder.getCallingPid(),
+                            Binder.getCallingUid(), -1);
                     final long token = Binder.clearCallingIdentity();
                     try {
-                        shell.mInternal.mAppOpsService.readState();
+                        shell.mInternal.readState();
                         pw.println("Last settings read.");
                     } finally {
                         Binder.restoreCallingIdentity(token);
@@ -1680,70 +4857,877 @@
         return -1;
     }
 
+    private void dumpHelp(PrintWriter pw) {
+        pw.println("AppOps service (appops) dump options:");
+        pw.println("  -h");
+        pw.println("    Print this help text.");
+        pw.println("  --op [OP]");
+        pw.println("    Limit output to data associated with the given app op code.");
+        pw.println("  --mode [MODE]");
+        pw.println("    Limit output to data associated with the given app op mode.");
+        pw.println("  --package [PACKAGE]");
+        pw.println("    Limit output to data associated with the given package name.");
+        pw.println("  --attributionTag [attributionTag]");
+        pw.println("    Limit output to data associated with the given attribution tag.");
+        pw.println("  --include-discrete [n]");
+        pw.println("    Include discrete ops limited to n per dimension. Use zero for no limit.");
+        pw.println("  --watchers");
+        pw.println("    Only output the watcher sections.");
+        pw.println("  --history");
+        pw.println("    Only output history.");
+        pw.println("  --uid-state-changes");
+        pw.println("    Include logs about uid state changes.");
+    }
+
+    private void dumpStatesLocked(@NonNull PrintWriter pw, @Nullable String filterAttributionTag,
+            @HistoricalOpsRequestFilter int filter, long nowElapsed, @NonNull Op op, long now,
+            @NonNull SimpleDateFormat sdf, @NonNull Date date, @NonNull String prefix) {
+        final int numAttributions = op.mAttributions.size();
+        for (int i = 0; i < numAttributions; i++) {
+            if ((filter & FILTER_BY_ATTRIBUTION_TAG) != 0 && !Objects.equals(
+                    op.mAttributions.keyAt(i), filterAttributionTag)) {
+                continue;
+            }
+
+            pw.print(prefix + op.mAttributions.keyAt(i) + "=[\n");
+            dumpStatesLocked(pw, nowElapsed, op, op.mAttributions.keyAt(i), now, sdf, date,
+                    prefix + "  ");
+            pw.print(prefix + "]\n");
+        }
+    }
+
+    private void dumpStatesLocked(@NonNull PrintWriter pw, long nowElapsed, @NonNull Op op,
+            @Nullable String attributionTag, long now, @NonNull SimpleDateFormat sdf,
+            @NonNull Date date, @NonNull String prefix) {
+
+        final AttributedOpEntry entry = op.createSingleAttributionEntryLocked(
+                attributionTag).getAttributedOpEntries().get(attributionTag);
+
+        final ArraySet<Long> keys = entry.collectKeys();
+
+        final int keyCount = keys.size();
+        for (int k = 0; k < keyCount; k++) {
+            final long key = keys.valueAt(k);
+
+            final int uidState = AppOpsManager.extractUidStateFromKey(key);
+            final int flags = AppOpsManager.extractFlagsFromKey(key);
+
+            final long accessTime = entry.getLastAccessTime(uidState, uidState, flags);
+            final long rejectTime = entry.getLastRejectTime(uidState, uidState, flags);
+            final long accessDuration = entry.getLastDuration(uidState, uidState, flags);
+            final OpEventProxyInfo proxy = entry.getLastProxyInfo(uidState, uidState, flags);
+
+            String proxyPkg = null;
+            String proxyAttributionTag = null;
+            int proxyUid = Process.INVALID_UID;
+            if (proxy != null) {
+                proxyPkg = proxy.getPackageName();
+                proxyAttributionTag = proxy.getAttributionTag();
+                proxyUid = proxy.getUid();
+            }
+
+            if (accessTime > 0) {
+                pw.print(prefix);
+                pw.print("Access: ");
+                pw.print(AppOpsManager.keyToString(key));
+                pw.print(" ");
+                date.setTime(accessTime);
+                pw.print(sdf.format(date));
+                pw.print(" (");
+                TimeUtils.formatDuration(accessTime - now, pw);
+                pw.print(")");
+                if (accessDuration > 0) {
+                    pw.print(" duration=");
+                    TimeUtils.formatDuration(accessDuration, pw);
+                }
+                if (proxyUid >= 0) {
+                    pw.print(" proxy[");
+                    pw.print("uid=");
+                    pw.print(proxyUid);
+                    pw.print(", pkg=");
+                    pw.print(proxyPkg);
+                    pw.print(", attributionTag=");
+                    pw.print(proxyAttributionTag);
+                    pw.print("]");
+                }
+                pw.println();
+            }
+
+            if (rejectTime > 0) {
+                pw.print(prefix);
+                pw.print("Reject: ");
+                pw.print(AppOpsManager.keyToString(key));
+                date.setTime(rejectTime);
+                pw.print(sdf.format(date));
+                pw.print(" (");
+                TimeUtils.formatDuration(rejectTime - now, pw);
+                pw.print(")");
+                if (proxyUid >= 0) {
+                    pw.print(" proxy[");
+                    pw.print("uid=");
+                    pw.print(proxyUid);
+                    pw.print(", pkg=");
+                    pw.print(proxyPkg);
+                    pw.print(", attributionTag=");
+                    pw.print(proxyAttributionTag);
+                    pw.print("]");
+                }
+                pw.println();
+            }
+        }
+
+        final AttributedOp attributedOp = op.mAttributions.get(attributionTag);
+        if (attributedOp.isRunning()) {
+            long earliestElapsedTime = Long.MAX_VALUE;
+            long maxNumStarts = 0;
+            int numInProgressEvents = attributedOp.mInProgressEvents.size();
+            for (int i = 0; i < numInProgressEvents; i++) {
+                AttributedOp.InProgressStartOpEvent event =
+                        attributedOp.mInProgressEvents.valueAt(i);
+
+                earliestElapsedTime = Math.min(earliestElapsedTime, event.getStartElapsedTime());
+                maxNumStarts = Math.max(maxNumStarts, event.mNumUnfinishedStarts);
+            }
+
+            pw.print(prefix + "Running start at: ");
+            TimeUtils.formatDuration(nowElapsed - earliestElapsedTime, pw);
+            pw.println();
+
+            if (maxNumStarts > 1) {
+                pw.print(prefix + "startNesting=");
+                pw.println(maxNumStarts);
+            }
+        }
+    }
+
+    @NeverCompile // Avoid size overhead of debugging code.
+    @Override
+    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+        if (!DumpUtils.checkDumpAndUsageStatsPermission(mContext, TAG, pw)) return;
+
+        int dumpOp = OP_NONE;
+        String dumpPackage = null;
+        String dumpAttributionTag = null;
+        int dumpUid = Process.INVALID_UID;
+        int dumpMode = -1;
+        boolean dumpWatchers = false;
+        // TODO ntmyren: Remove the dumpHistory and dumpFilter
+        boolean dumpHistory = false;
+        boolean includeDiscreteOps = false;
+        boolean dumpUidStateChangeLogs = false;
+        int nDiscreteOps = 10;
+        @HistoricalOpsRequestFilter int dumpFilter = 0;
+        boolean dumpAll = false;
+
+        if (args != null) {
+            for (int i = 0; i < args.length; i++) {
+                String arg = args[i];
+                if ("-h".equals(arg)) {
+                    dumpHelp(pw);
+                    return;
+                } else if ("-a".equals(arg)) {
+                    // dump all data
+                    dumpAll = true;
+                } else if ("--op".equals(arg)) {
+                    i++;
+                    if (i >= args.length) {
+                        pw.println("No argument for --op option");
+                        return;
+                    }
+                    dumpOp = Shell.strOpToOp(args[i], pw);
+                    dumpFilter |= FILTER_BY_OP_NAMES;
+                    if (dumpOp < 0) {
+                        return;
+                    }
+                } else if ("--package".equals(arg)) {
+                    i++;
+                    if (i >= args.length) {
+                        pw.println("No argument for --package option");
+                        return;
+                    }
+                    dumpPackage = args[i];
+                    dumpFilter |= FILTER_BY_PACKAGE_NAME;
+                    try {
+                        dumpUid = AppGlobals.getPackageManager().getPackageUid(dumpPackage,
+                                PackageManager.MATCH_KNOWN_PACKAGES | PackageManager.MATCH_INSTANT,
+                                0);
+                    } catch (RemoteException e) {
+                    }
+                    if (dumpUid < 0) {
+                        pw.println("Unknown package: " + dumpPackage);
+                        return;
+                    }
+                    dumpUid = UserHandle.getAppId(dumpUid);
+                    dumpFilter |= FILTER_BY_UID;
+                } else if ("--attributionTag".equals(arg)) {
+                    i++;
+                    if (i >= args.length) {
+                        pw.println("No argument for --attributionTag option");
+                        return;
+                    }
+                    dumpAttributionTag = args[i];
+                    dumpFilter |= FILTER_BY_ATTRIBUTION_TAG;
+                } else if ("--mode".equals(arg)) {
+                    i++;
+                    if (i >= args.length) {
+                        pw.println("No argument for --mode option");
+                        return;
+                    }
+                    dumpMode = Shell.strModeToMode(args[i], pw);
+                    if (dumpMode < 0) {
+                        return;
+                    }
+                } else if ("--watchers".equals(arg)) {
+                    dumpWatchers = true;
+                } else if ("--include-discrete".equals(arg)) {
+                    i++;
+                    if (i >= args.length) {
+                        pw.println("No argument for --include-discrete option");
+                        return;
+                    }
+                    try {
+                        nDiscreteOps = Integer.valueOf(args[i]);
+                    } catch (NumberFormatException e) {
+                        pw.println("Wrong parameter: " + args[i]);
+                        return;
+                    }
+                    includeDiscreteOps = true;
+                } else if ("--history".equals(arg)) {
+                    dumpHistory = true;
+                } else if (arg.length() > 0 && arg.charAt(0) == '-') {
+                    pw.println("Unknown option: " + arg);
+                    return;
+                } else if ("--uid-state-changes".equals(arg)) {
+                    dumpUidStateChangeLogs = true;
+                } else {
+                    pw.println("Unknown command: " + arg);
+                    return;
+                }
+            }
+        }
+
+        final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+        final Date date = new Date();
+        synchronized (this) {
+            pw.println("Current AppOps Service state:");
+            if (!dumpHistory && !dumpWatchers) {
+                mConstants.dump(pw);
+            }
+            pw.println();
+            final long now = System.currentTimeMillis();
+            final long nowElapsed = SystemClock.elapsedRealtime();
+            final long nowUptime = SystemClock.uptimeMillis();
+            boolean needSep = false;
+            if (dumpFilter == 0 && dumpMode < 0 && mProfileOwners != null && !dumpWatchers
+                    && !dumpHistory) {
+                pw.println("  Profile owners:");
+                for (int poi = 0; poi < mProfileOwners.size(); poi++) {
+                    pw.print("    User #");
+                    pw.print(mProfileOwners.keyAt(poi));
+                    pw.print(": ");
+                    UserHandle.formatUid(pw, mProfileOwners.valueAt(poi));
+                    pw.println();
+                }
+                pw.println();
+            }
+
+            if (!dumpHistory) {
+                needSep |= mAppOpsCheckingService.dumpListeners(dumpOp, dumpUid, dumpPackage, pw);
+            }
+
+            if (mModeWatchers.size() > 0 && dumpOp < 0 && !dumpHistory) {
+                boolean printedHeader = false;
+                for (int i = 0; i < mModeWatchers.size(); i++) {
+                    final ModeCallback cb = mModeWatchers.valueAt(i);
+                    if (dumpPackage != null
+                            && dumpUid != UserHandle.getAppId(cb.getWatchingUid())) {
+                        continue;
+                    }
+                    needSep = true;
+                    if (!printedHeader) {
+                        pw.println("  All op mode watchers:");
+                        printedHeader = true;
+                    }
+                    pw.print("    ");
+                    pw.print(Integer.toHexString(System.identityHashCode(mModeWatchers.keyAt(i))));
+                    pw.print(": "); pw.println(cb);
+                }
+            }
+            if (mActiveWatchers.size() > 0 && dumpMode < 0) {
+                needSep = true;
+                boolean printedHeader = false;
+                for (int watcherNum = 0; watcherNum < mActiveWatchers.size(); watcherNum++) {
+                    final SparseArray<ActiveCallback> activeWatchers =
+                            mActiveWatchers.valueAt(watcherNum);
+                    if (activeWatchers.size() <= 0) {
+                        continue;
+                    }
+                    final ActiveCallback cb = activeWatchers.valueAt(0);
+                    if (dumpOp >= 0 && activeWatchers.indexOfKey(dumpOp) < 0) {
+                        continue;
+                    }
+                    if (dumpPackage != null
+                            && dumpUid != UserHandle.getAppId(cb.mWatchingUid)) {
+                        continue;
+                    }
+                    if (!printedHeader) {
+                        pw.println("  All op active watchers:");
+                        printedHeader = true;
+                    }
+                    pw.print("    ");
+                    pw.print(Integer.toHexString(System.identityHashCode(
+                            mActiveWatchers.keyAt(watcherNum))));
+                    pw.println(" ->");
+                    pw.print("        [");
+                    final int opCount = activeWatchers.size();
+                    for (int opNum = 0; opNum < opCount; opNum++) {
+                        if (opNum > 0) {
+                            pw.print(' ');
+                        }
+                        pw.print(AppOpsManager.opToName(activeWatchers.keyAt(opNum)));
+                        if (opNum < opCount - 1) {
+                            pw.print(',');
+                        }
+                    }
+                    pw.println("]");
+                    pw.print("        ");
+                    pw.println(cb);
+                }
+            }
+            if (mStartedWatchers.size() > 0 && dumpMode < 0) {
+                needSep = true;
+                boolean printedHeader = false;
+
+                final int watchersSize = mStartedWatchers.size();
+                for (int watcherNum = 0; watcherNum < watchersSize; watcherNum++) {
+                    final SparseArray<StartedCallback> startedWatchers =
+                            mStartedWatchers.valueAt(watcherNum);
+                    if (startedWatchers.size() <= 0) {
+                        continue;
+                    }
+
+                    final StartedCallback cb = startedWatchers.valueAt(0);
+                    if (dumpOp >= 0 && startedWatchers.indexOfKey(dumpOp) < 0) {
+                        continue;
+                    }
+
+                    if (dumpPackage != null
+                            && dumpUid != UserHandle.getAppId(cb.mWatchingUid)) {
+                        continue;
+                    }
+
+                    if (!printedHeader) {
+                        pw.println("  All op started watchers:");
+                        printedHeader = true;
+                    }
+
+                    pw.print("    ");
+                    pw.print(Integer.toHexString(System.identityHashCode(
+                            mStartedWatchers.keyAt(watcherNum))));
+                    pw.println(" ->");
+
+                    pw.print("        [");
+                    final int opCount = startedWatchers.size();
+                    for (int opNum = 0; opNum < opCount; opNum++) {
+                        if (opNum > 0) {
+                            pw.print(' ');
+                        }
+
+                        pw.print(AppOpsManager.opToName(startedWatchers.keyAt(opNum)));
+                        if (opNum < opCount - 1) {
+                            pw.print(',');
+                        }
+                    }
+                    pw.println("]");
+
+                    pw.print("        ");
+                    pw.println(cb);
+                }
+            }
+            if (mNotedWatchers.size() > 0 && dumpMode < 0) {
+                needSep = true;
+                boolean printedHeader = false;
+                for (int watcherNum = 0; watcherNum < mNotedWatchers.size(); watcherNum++) {
+                    final SparseArray<NotedCallback> notedWatchers =
+                            mNotedWatchers.valueAt(watcherNum);
+                    if (notedWatchers.size() <= 0) {
+                        continue;
+                    }
+                    final NotedCallback cb = notedWatchers.valueAt(0);
+                    if (dumpOp >= 0 && notedWatchers.indexOfKey(dumpOp) < 0) {
+                        continue;
+                    }
+                    if (dumpPackage != null
+                            && dumpUid != UserHandle.getAppId(cb.mWatchingUid)) {
+                        continue;
+                    }
+                    if (!printedHeader) {
+                        pw.println("  All op noted watchers:");
+                        printedHeader = true;
+                    }
+                    pw.print("    ");
+                    pw.print(Integer.toHexString(System.identityHashCode(
+                            mNotedWatchers.keyAt(watcherNum))));
+                    pw.println(" ->");
+                    pw.print("        [");
+                    final int opCount = notedWatchers.size();
+                    for (int opNum = 0; opNum < opCount; opNum++) {
+                        if (opNum > 0) {
+                            pw.print(' ');
+                        }
+                        pw.print(AppOpsManager.opToName(notedWatchers.keyAt(opNum)));
+                        if (opNum < opCount - 1) {
+                            pw.print(',');
+                        }
+                    }
+                    pw.println("]");
+                    pw.print("        ");
+                    pw.println(cb);
+                }
+            }
+            if (mAudioRestrictionManager.hasActiveRestrictions() && dumpOp < 0
+                    && dumpPackage != null && dumpMode < 0 && !dumpWatchers) {
+                needSep = mAudioRestrictionManager.dump(pw) || needSep;
+            }
+            if (needSep) {
+                pw.println();
+            }
+            for (int i=0; i<mUidStates.size(); i++) {
+                UidState uidState = mUidStates.valueAt(i);
+                final SparseIntArray opModes = uidState.getNonDefaultUidModes();
+                final ArrayMap<String, Ops> pkgOps = uidState.pkgOps;
+
+                if (dumpWatchers || dumpHistory) {
+                    continue;
+                }
+                if (dumpOp >= 0 || dumpPackage != null || dumpMode >= 0) {
+                    boolean hasOp = dumpOp < 0 || (opModes != null
+                            && opModes.indexOfKey(dumpOp) >= 0);
+                    boolean hasPackage = dumpPackage == null || dumpUid == mUidStates.keyAt(i);
+                    boolean hasMode = dumpMode < 0;
+                    if (!hasMode && opModes != null) {
+                        for (int opi = 0; !hasMode && opi < opModes.size(); opi++) {
+                            if (opModes.valueAt(opi) == dumpMode) {
+                                hasMode = true;
+                            }
+                        }
+                    }
+                    if (pkgOps != null) {
+                        for (int pkgi = 0;
+                                 (!hasOp || !hasPackage || !hasMode) && pkgi < pkgOps.size();
+                                 pkgi++) {
+                            Ops ops = pkgOps.valueAt(pkgi);
+                            if (!hasOp && ops != null && ops.indexOfKey(dumpOp) >= 0) {
+                                hasOp = true;
+                            }
+                            if (!hasMode) {
+                                for (int opi = 0; !hasMode && opi < ops.size(); opi++) {
+                                    if (ops.valueAt(opi).getMode() == dumpMode) {
+                                        hasMode = true;
+                                    }
+                                }
+                            }
+                            if (!hasPackage && dumpPackage.equals(ops.packageName)) {
+                                hasPackage = true;
+                            }
+                        }
+                    }
+                    if (uidState.foregroundOps != null && !hasOp) {
+                        if (uidState.foregroundOps.indexOfKey(dumpOp) > 0) {
+                            hasOp = true;
+                        }
+                    }
+                    if (!hasOp || !hasPackage || !hasMode) {
+                        continue;
+                    }
+                }
+
+                pw.print("  Uid "); UserHandle.formatUid(pw, uidState.uid); pw.println(":");
+                uidState.dump(pw, nowElapsed);
+                if (uidState.foregroundOps != null && (dumpMode < 0
+                        || dumpMode == AppOpsManager.MODE_FOREGROUND)) {
+                    pw.println("    foregroundOps:");
+                    for (int j = 0; j < uidState.foregroundOps.size(); j++) {
+                        if (dumpOp >= 0 && dumpOp != uidState.foregroundOps.keyAt(j)) {
+                            continue;
+                        }
+                        pw.print("      ");
+                        pw.print(AppOpsManager.opToName(uidState.foregroundOps.keyAt(j)));
+                        pw.print(": ");
+                        pw.println(uidState.foregroundOps.valueAt(j) ? "WATCHER" : "SILENT");
+                    }
+                    pw.print("    hasForegroundWatchers=");
+                    pw.println(uidState.hasForegroundWatchers);
+                }
+                needSep = true;
+
+                if (opModes != null) {
+                    final int opModeCount = opModes.size();
+                    for (int j = 0; j < opModeCount; j++) {
+                        final int code = opModes.keyAt(j);
+                        final int mode = opModes.valueAt(j);
+                        if (dumpOp >= 0 && dumpOp != code) {
+                            continue;
+                        }
+                        if (dumpMode >= 0 && dumpMode != mode) {
+                            continue;
+                        }
+                        pw.print("      "); pw.print(AppOpsManager.opToName(code));
+                        pw.print(": mode="); pw.println(AppOpsManager.modeToName(mode));
+                    }
+                }
+
+                if (pkgOps == null) {
+                    continue;
+                }
+
+                for (int pkgi = 0; pkgi < pkgOps.size(); pkgi++) {
+                    final Ops ops = pkgOps.valueAt(pkgi);
+                    if (dumpPackage != null && !dumpPackage.equals(ops.packageName)) {
+                        continue;
+                    }
+                    boolean printedPackage = false;
+                    for (int j=0; j<ops.size(); j++) {
+                        final Op op = ops.valueAt(j);
+                        final int opCode = op.op;
+                        if (dumpOp >= 0 && dumpOp != opCode) {
+                            continue;
+                        }
+                        if (dumpMode >= 0 && dumpMode != op.getMode()) {
+                            continue;
+                        }
+                        if (!printedPackage) {
+                            pw.print("    Package "); pw.print(ops.packageName); pw.println(":");
+                            printedPackage = true;
+                        }
+                        pw.print("      "); pw.print(AppOpsManager.opToName(opCode));
+                        pw.print(" ("); pw.print(AppOpsManager.modeToName(op.getMode()));
+                        final int switchOp = AppOpsManager.opToSwitch(opCode);
+                        if (switchOp != opCode) {
+                            pw.print(" / switch ");
+                            pw.print(AppOpsManager.opToName(switchOp));
+                            final Op switchObj = ops.get(switchOp);
+                            int mode = switchObj == null
+                                    ? AppOpsManager.opToDefaultMode(switchOp) : switchObj.getMode();
+                            pw.print("="); pw.print(AppOpsManager.modeToName(mode));
+                        }
+                        pw.println("): ");
+                        dumpStatesLocked(pw, dumpAttributionTag, dumpFilter, nowElapsed, op, now,
+                                sdf, date, "        ");
+                    }
+                }
+            }
+            if (needSep) {
+                pw.println();
+            }
+
+            boolean showUserRestrictions = !(dumpMode < 0 && !dumpWatchers && !dumpHistory);
+            mAppOpsRestrictions.dumpRestrictions(pw, dumpOp, dumpPackage, showUserRestrictions);
+
+            if (!dumpHistory && !dumpWatchers) {
+                pw.println();
+                if (mCheckOpsDelegateDispatcher.mPolicy != null
+                        && mCheckOpsDelegateDispatcher.mPolicy instanceof AppOpsPolicy) {
+                    AppOpsPolicy policy = (AppOpsPolicy) mCheckOpsDelegateDispatcher.mPolicy;
+                    policy.dumpTags(pw);
+                } else {
+                    pw.println("  AppOps policy not set.");
+                }
+            }
+
+            if (dumpAll || dumpUidStateChangeLogs) {
+                pw.println();
+                pw.println("Uid State Changes Event Log:");
+                getUidStateTracker().dumpEvents(pw);
+            }
+        }
+
+        // Must not hold the appops lock
+        if (dumpHistory && !dumpWatchers) {
+            mHistoricalRegistry.dump("  ", pw, dumpUid, dumpPackage, dumpAttributionTag, dumpOp,
+                    dumpFilter);
+        }
+        if (includeDiscreteOps) {
+            pw.println("Discrete accesses: ");
+            mHistoricalRegistry.dumpDiscreteData(pw, dumpUid, dumpPackage, dumpAttributionTag,
+                    dumpFilter, dumpOp, sdf, date, "  ", nDiscreteOps);
+        }
+    }
+
     @Override
     public void setUserRestrictions(Bundle restrictions, IBinder token, int userHandle) {
-        mAppOpsService.setUserRestrictions(restrictions, token, userHandle);
+        checkSystemUid("setUserRestrictions");
+        Objects.requireNonNull(restrictions);
+        Objects.requireNonNull(token);
+        for (int i = 0; i < AppOpsManager._NUM_OP; i++) {
+            String restriction = AppOpsManager.opToRestriction(i);
+            if (restriction != null) {
+                setUserRestrictionNoCheck(i, restrictions.getBoolean(restriction, false), token,
+                        userHandle, null);
+            }
+        }
     }
 
     @Override
     public void setUserRestriction(int code, boolean restricted, IBinder token, int userHandle,
             PackageTagsList excludedPackageTags) {
-        mAppOpsService.setUserRestriction(code, restricted, token, userHandle,
-                excludedPackageTags);
+        if (Binder.getCallingPid() != Process.myPid()) {
+            mContext.enforcePermission(Manifest.permission.MANAGE_APP_OPS_RESTRICTIONS,
+                    Binder.getCallingPid(), Binder.getCallingUid(), null);
+        }
+        if (userHandle != UserHandle.getCallingUserId()) {
+            if (mContext.checkCallingOrSelfPermission(Manifest.permission
+                    .INTERACT_ACROSS_USERS_FULL) != PackageManager.PERMISSION_GRANTED
+                && mContext.checkCallingOrSelfPermission(Manifest.permission
+                    .INTERACT_ACROSS_USERS) != PackageManager.PERMISSION_GRANTED) {
+                throw new SecurityException("Need INTERACT_ACROSS_USERS_FULL or"
+                        + " INTERACT_ACROSS_USERS to interact cross user ");
+            }
+        }
+        verifyIncomingOp(code);
+        Objects.requireNonNull(token);
+        setUserRestrictionNoCheck(code, restricted, token, userHandle, excludedPackageTags);
+    }
+
+    private void setUserRestrictionNoCheck(int code, boolean restricted, IBinder token,
+            int userHandle, PackageTagsList excludedPackageTags) {
+        synchronized (AppOpsService.this) {
+            ClientUserRestrictionState restrictionState = mOpUserRestrictions.get(token);
+
+            if (restrictionState == null) {
+                try {
+                    restrictionState = new ClientUserRestrictionState(token);
+                } catch (RemoteException e) {
+                    return;
+                }
+                mOpUserRestrictions.put(token, restrictionState);
+            }
+
+            if (restrictionState.setRestriction(code, restricted, excludedPackageTags,
+                    userHandle)) {
+                mHandler.sendMessage(PooledLambda.obtainMessage(
+                        AppOpsService::notifyWatchersOfChange, this, code, UID_ANY));
+                mHandler.sendMessage(PooledLambda.obtainMessage(
+                        AppOpsService::updateStartedOpModeForUser, this, code, restricted,
+                        userHandle));
+            }
+
+            if (restrictionState.isDefault()) {
+                mOpUserRestrictions.remove(token);
+                restrictionState.destroy();
+            }
+        }
+    }
+
+    private void updateStartedOpModeForUser(int code, boolean restricted, int userId) {
+        synchronized (AppOpsService.this) {
+            int numUids = mUidStates.size();
+            for (int uidNum = 0; uidNum < numUids; uidNum++) {
+                int uid = mUidStates.keyAt(uidNum);
+                if (userId != UserHandle.USER_ALL && UserHandle.getUserId(uid) != userId) {
+                    continue;
+                }
+                updateStartedOpModeForUidLocked(code, restricted, uid);
+            }
+        }
+    }
+
+    private void updateStartedOpModeForUidLocked(int code, boolean restricted, int uid) {
+        UidState uidState = mUidStates.get(uid);
+        if (uidState == null || uidState.pkgOps == null) {
+            return;
+        }
+
+        int numPkgOps = uidState.pkgOps.size();
+        for (int pkgNum = 0; pkgNum < numPkgOps; pkgNum++) {
+            Ops ops = uidState.pkgOps.valueAt(pkgNum);
+            Op op = ops != null ? ops.get(code) : null;
+            if (op == null || (op.getMode() != MODE_ALLOWED && op.getMode() != MODE_FOREGROUND)) {
+                continue;
+            }
+            int numAttrTags = op.mAttributions.size();
+            for (int attrNum = 0; attrNum < numAttrTags; attrNum++) {
+                AttributedOp attrOp = op.mAttributions.valueAt(attrNum);
+                if (restricted && attrOp.isRunning()) {
+                    attrOp.pause();
+                } else if (attrOp.isPaused()) {
+                    attrOp.resume();
+                }
+            }
+        }
+    }
+
+    private void notifyWatchersOfChange(int code, int uid) {
+        final ArraySet<OnOpModeChangedListener> modeChangedListenerSet;
+        synchronized (this) {
+            modeChangedListenerSet = mAppOpsCheckingService.getOpModeChangedListeners(code);
+            if (modeChangedListenerSet == null) {
+                return;
+            }
+        }
+
+        notifyOpChanged(modeChangedListenerSet,  code, uid, null);
     }
 
     @Override
     public void removeUser(int userHandle) throws RemoteException {
-        mAppOpsService.removeUser(userHandle);
+        checkSystemUid("removeUser");
+        synchronized (AppOpsService.this) {
+            final int tokenCount = mOpUserRestrictions.size();
+            for (int i = tokenCount - 1; i >= 0; i--) {
+                ClientUserRestrictionState opRestrictions = mOpUserRestrictions.valueAt(i);
+                opRestrictions.removeUser(userHandle);
+            }
+            removeUidsForUserLocked(userHandle);
+        }
     }
 
     @Override
     public boolean isOperationActive(int code, int uid, String packageName) {
-        return mAppOpsService.isOperationActive(code, uid, packageName);
+        if (Binder.getCallingUid() != uid) {
+            if (mContext.checkCallingOrSelfPermission(Manifest.permission.WATCH_APPOPS)
+                    != PackageManager.PERMISSION_GRANTED) {
+                return false;
+            }
+        }
+        verifyIncomingOp(code);
+        if (!isIncomingPackageValid(packageName, UserHandle.getUserId(uid))) {
+            return false;
+        }
+
+        final String resolvedPackageName = AppOpsManager.resolvePackageName(uid, packageName);
+        if (resolvedPackageName == null) {
+            return false;
+        }
+        // TODO moltmann: Allow to check for attribution op activeness
+        synchronized (AppOpsService.this) {
+            Ops pkgOps = getOpsLocked(uid, resolvedPackageName, null, false, null, false);
+            if (pkgOps == null) {
+                return false;
+            }
+
+            Op op = pkgOps.get(code);
+            if (op == null) {
+                return false;
+            }
+
+            return op.isRunning();
+        }
     }
 
     @Override
     public boolean isProxying(int op, @NonNull String proxyPackageName,
             @NonNull String proxyAttributionTag, int proxiedUid,
             @NonNull String proxiedPackageName) {
-        return mAppOpsService.isProxying(op, proxyPackageName, proxyAttributionTag,
-                proxiedUid, proxiedPackageName);
+        Objects.requireNonNull(proxyPackageName);
+        Objects.requireNonNull(proxiedPackageName);
+        final long callingUid = Binder.getCallingUid();
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final List<AppOpsManager.PackageOps> packageOps = getOpsForPackage(proxiedUid,
+                    proxiedPackageName, new int[] {op});
+            if (packageOps == null || packageOps.isEmpty()) {
+                return false;
+            }
+            final List<OpEntry> opEntries = packageOps.get(0).getOps();
+            if (opEntries.isEmpty()) {
+                return false;
+            }
+            final OpEntry opEntry = opEntries.get(0);
+            if (!opEntry.isRunning()) {
+                return false;
+            }
+            final OpEventProxyInfo proxyInfo = opEntry.getLastProxyInfo(
+                    OP_FLAG_TRUSTED_PROXIED | AppOpsManager.OP_FLAG_UNTRUSTED_PROXIED);
+            return proxyInfo != null && callingUid == proxyInfo.getUid()
+                    && proxyPackageName.equals(proxyInfo.getPackageName())
+                    && Objects.equals(proxyAttributionTag, proxyInfo.getAttributionTag());
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
     public void resetPackageOpsNoHistory(@NonNull String packageName) {
-        mAppOpsService.resetPackageOpsNoHistory(packageName);
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_APPOPS,
+                "resetPackageOpsNoHistory");
+        synchronized (AppOpsService.this) {
+            final int uid = mPackageManagerInternal.getPackageUid(packageName, 0,
+                    UserHandle.getCallingUserId());
+            if (uid == Process.INVALID_UID) {
+                return;
+            }
+            UidState uidState = mUidStates.get(uid);
+            if (uidState == null || uidState.pkgOps == null) {
+                return;
+            }
+            Ops removedOps = uidState.pkgOps.remove(packageName);
+            mAppOpsCheckingService.removePackage(packageName, UserHandle.getUserId(uid));
+            if (removedOps != null) {
+                scheduleFastWriteLocked();
+            }
+        }
     }
 
     @Override
     public void setHistoryParameters(@AppOpsManager.HistoricalMode int mode,
             long baseSnapshotInterval, int compressionStep) {
-        mAppOpsService.setHistoryParameters(mode, baseSnapshotInterval, compressionStep);
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_APPOPS,
+                "setHistoryParameters");
+        // Must not hold the appops lock
+        mHistoricalRegistry.setHistoryParameters(mode, baseSnapshotInterval, compressionStep);
     }
 
     @Override
     public void offsetHistory(long offsetMillis) {
-        mAppOpsService.offsetHistory(offsetMillis);
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_APPOPS,
+                "offsetHistory");
+        // Must not hold the appops lock
+        mHistoricalRegistry.offsetHistory(offsetMillis);
+        mHistoricalRegistry.offsetDiscreteHistory(offsetMillis);
     }
 
     @Override
     public void addHistoricalOps(HistoricalOps ops) {
-        mAppOpsService.addHistoricalOps(ops);
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_APPOPS,
+                "addHistoricalOps");
+        // Must not hold the appops lock
+        mHistoricalRegistry.addHistoricalOps(ops);
     }
 
     @Override
     public void resetHistoryParameters() {
-        mAppOpsService.resetHistoryParameters();
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_APPOPS,
+                "resetHistoryParameters");
+        // Must not hold the appops lock
+        mHistoricalRegistry.resetHistoryParameters();
     }
 
     @Override
     public void clearHistory() {
-        mAppOpsService.clearHistory();
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_APPOPS,
+                "clearHistory");
+        // Must not hold the appops lock
+        mHistoricalRegistry.clearAllHistory();
     }
 
     @Override
     public void rebootHistory(long offlineDurationMillis) {
-        mAppOpsService.rebootHistory(offlineDurationMillis);
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_APPOPS,
+                "rebootHistory");
+
+        Preconditions.checkArgument(offlineDurationMillis >= 0);
+
+        // Must not hold the appops lock
+        mHistoricalRegistry.shutdown();
+
+        if (offlineDurationMillis > 0) {
+            SystemClock.sleep(offlineDurationMillis);
+        }
+
+        mHistoricalRegistry = new HistoricalRegistry(mHistoricalRegistry);
+        mHistoricalRegistry.systemReady(mContext.getContentResolver());
+        mHistoricalRegistry.persistPendingHistory();
     }
 
     /**
@@ -1998,6 +5982,24 @@
         return false;
     }
 
+    @GuardedBy("this")
+    private void removeUidsForUserLocked(int userHandle) {
+        for (int i = mUidStates.size() - 1; i >= 0; --i) {
+            final int uid = mUidStates.keyAt(i);
+            if (UserHandle.getUserId(uid) == userHandle) {
+                mUidStates.valueAt(i).clear();
+                mUidStates.removeAt(i);
+            }
+        }
+    }
+
+    private void checkSystemUid(String function) {
+        int uid = Binder.getCallingUid();
+        if (uid != Process.SYSTEM_UID) {
+            throw new SecurityException(function + " must by called by the system");
+        }
+    }
+
     private static int resolveUid(String packageName)  {
         if (packageName == null) {
             return Process.INVALID_UID;
@@ -2018,43 +6020,184 @@
         return Process.INVALID_UID;
     }
 
+    private static String[] getPackagesForUid(int uid) {
+        String[] packageNames = null;
+
+        // Very early during boot the package manager is not yet or not yet fully started. At this
+        // time there are no packages yet.
+        if (AppGlobals.getPackageManager() != null) {
+            try {
+                packageNames = AppGlobals.getPackageManager().getPackagesForUid(uid);
+            } catch (RemoteException e) {
+                /* ignore - local call */
+            }
+        }
+        if (packageNames == null) {
+            return EmptyArray.STRING;
+        }
+        return packageNames;
+    }
+
+    private final class ClientUserRestrictionState implements DeathRecipient {
+        private final IBinder token;
+
+        ClientUserRestrictionState(IBinder token)
+                throws RemoteException {
+            token.linkToDeath(this, 0);
+            this.token = token;
+        }
+
+        public boolean setRestriction(int code, boolean restricted,
+                PackageTagsList excludedPackageTags, int userId) {
+            return mAppOpsRestrictions.setUserRestriction(token, userId, code,
+                    restricted, excludedPackageTags);
+        }
+
+        public boolean hasRestriction(int code, String packageName, String attributionTag,
+                int userId, boolean isCheckOp) {
+            return mAppOpsRestrictions.getUserRestriction(token, userId, code, packageName,
+                    attributionTag, isCheckOp);
+        }
+
+        public void removeUser(int userId) {
+            mAppOpsRestrictions.clearUserRestrictions(token, userId);
+        }
+
+        public boolean isDefault() {
+            return !mAppOpsRestrictions.hasUserRestrictions(token);
+        }
+
+        @Override
+        public void binderDied() {
+            synchronized (AppOpsService.this) {
+                mAppOpsRestrictions.clearUserRestrictions(token);
+                mOpUserRestrictions.remove(token);
+                destroy();
+            }
+        }
+
+        public void destroy() {
+            token.unlinkToDeath(this, 0);
+        }
+    }
+
+    private final class ClientGlobalRestrictionState implements DeathRecipient {
+        final IBinder mToken;
+
+        ClientGlobalRestrictionState(IBinder token)
+                throws RemoteException {
+            token.linkToDeath(this, 0);
+            this.mToken = token;
+        }
+
+        boolean setRestriction(int code, boolean restricted) {
+            return mAppOpsRestrictions.setGlobalRestriction(mToken, code, restricted);
+        }
+
+        boolean hasRestriction(int code) {
+            return mAppOpsRestrictions.getGlobalRestriction(mToken, code);
+        }
+
+        boolean isDefault() {
+            return !mAppOpsRestrictions.hasGlobalRestrictions(mToken);
+        }
+
+        @Override
+        public void binderDied() {
+            mAppOpsRestrictions.clearGlobalRestrictions(mToken);
+            mOpGlobalRestrictions.remove(mToken);
+            destroy();
+        }
+
+        void destroy() {
+            mToken.unlinkToDeath(this, 0);
+        }
+    }
+
     private final class AppOpsManagerInternalImpl extends AppOpsManagerInternal {
         @Override public void setDeviceAndProfileOwners(SparseIntArray owners) {
-            AppOpsService.this.mAppOpsService.setDeviceAndProfileOwners(owners);
+            synchronized (AppOpsService.this) {
+                mProfileOwners = owners;
+            }
         }
 
         @Override
         public void updateAppWidgetVisibility(SparseArray<String> uidPackageNames,
                 boolean visible) {
-            AppOpsService.this.mAppOpsService
-                    .updateAppWidgetVisibility(uidPackageNames, visible);
+            AppOpsService.this.updateAppWidgetVisibility(uidPackageNames, visible);
         }
 
         @Override
         public void setUidModeFromPermissionPolicy(int code, int uid, int mode,
                 @Nullable IAppOpsCallback callback) {
-            AppOpsService.this.mAppOpsService.setUidMode(code, uid, mode, callback);
+            setUidMode(code, uid, mode, callback);
         }
 
         @Override
         public void setModeFromPermissionPolicy(int code, int uid, @NonNull String packageName,
                 int mode, @Nullable IAppOpsCallback callback) {
-            AppOpsService.this.mAppOpsService
-                    .setMode(code, uid, packageName, mode, callback);
+            setMode(code, uid, packageName, mode, callback);
         }
 
 
         @Override
         public void setGlobalRestriction(int code, boolean restricted, IBinder token) {
-            AppOpsService.this.mAppOpsService
-                    .setGlobalRestriction(code, restricted, token);
+            if (Binder.getCallingPid() != Process.myPid()) {
+                // TODO instead of this enforcement put in AppOpsManagerInternal
+                throw new SecurityException("Only the system can set global restrictions");
+            }
+
+            synchronized (AppOpsService.this) {
+                ClientGlobalRestrictionState restrictionState = mOpGlobalRestrictions.get(token);
+
+                if (restrictionState == null) {
+                    try {
+                        restrictionState = new ClientGlobalRestrictionState(token);
+                    } catch (RemoteException  e) {
+                        return;
+                    }
+                    mOpGlobalRestrictions.put(token, restrictionState);
+                }
+
+                if (restrictionState.setRestriction(code, restricted)) {
+                    mHandler.sendMessage(PooledLambda.obtainMessage(
+                            AppOpsService::notifyWatchersOfChange, AppOpsService.this, code,
+                            UID_ANY));
+                    mHandler.sendMessage(PooledLambda.obtainMessage(
+                            AppOpsService::updateStartedOpModeForUser, AppOpsService.this,
+                            code, restricted, UserHandle.USER_ALL));
+                }
+
+                if (restrictionState.isDefault()) {
+                    mOpGlobalRestrictions.remove(token);
+                    restrictionState.destroy();
+                }
+            }
         }
 
         @Override
         public int getOpRestrictionCount(int code, UserHandle user, String pkg,
                 String attributionTag) {
-            return AppOpsService.this.mAppOpsService
-                    .getOpRestrictionCount(code, user, pkg, attributionTag);
+            int number = 0;
+            synchronized (AppOpsService.this) {
+                int numRestrictions = mOpUserRestrictions.size();
+                for (int i = 0; i < numRestrictions; i++) {
+                    if (mOpUserRestrictions.valueAt(i)
+                            .hasRestriction(code, pkg, attributionTag, user.getIdentifier(),
+                                    false)) {
+                        number++;
+                    }
+                }
+
+                numRestrictions = mOpGlobalRestrictions.size();
+                for (int i = 0; i < numRestrictions; i++) {
+                    if (mOpGlobalRestrictions.valueAt(i).hasRestriction(code)) {
+                        number++;
+                    }
+                }
+            }
+
+            return number;
         }
     }
 
@@ -2350,7 +6493,7 @@
                     attributionFlags, attributionChainId, AppOpsService.this::startOperationImpl);
         }
 
-        public SyncNotedAppOp startProxyOperation(IBinder clientId, int code,
+        public SyncNotedAppOp startProxyOperation(@NonNull IBinder clientId, int code,
                 @NonNull AttributionSource attributionSource, boolean startIfModeDefault,
                 boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
                 boolean skipProxyOperation, @AttributionFlags int proxyAttributionFlags,
@@ -2380,7 +6523,7 @@
                     proxyAttributionFlags, proxiedAttributionFlags, attributionChainId);
         }
 
-        private SyncNotedAppOp startDelegateProxyOperationImpl(IBinder clientId, int code,
+        private SyncNotedAppOp startDelegateProxyOperationImpl(@NonNull IBinder clientId, int code,
                 @NonNull AttributionSource attributionSource, boolean startIfModeDefault,
                 boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
                 boolean skipProxyOperation, @AttributionFlags int proxyAttributionFlags,
@@ -2414,7 +6557,7 @@
                     AppOpsService.this::finishOperationImpl);
         }
 
-        public void finishProxyOperation(IBinder clientId, int code,
+        public void finishProxyOperation(@NonNull IBinder clientId, int code,
                 @NonNull AttributionSource attributionSource, boolean skipProxyOperation) {
             if (mPolicy != null) {
                 if (mCheckOpsDelegate != null) {
@@ -2432,7 +6575,7 @@
             }
         }
 
-        private Void finishDelegateProxyOperationImpl(IBinder clientId, int code,
+        private Void finishDelegateProxyOperationImpl(@NonNull IBinder clientId, int code,
                 @NonNull AttributionSource attributionSource, boolean skipProxyOperation) {
             mCheckOpsDelegate.finishProxyOperation(clientId, code, attributionSource,
                     skipProxyOperation, AppOpsService.this::finishProxyOperationImpl);
diff --git a/services/core/java/com/android/server/appop/AppOpsServiceImpl.java b/services/core/java/com/android/server/appop/AppOpsServiceImpl.java
deleted file mode 100644
index 70f3bcc..0000000
--- a/services/core/java/com/android/server/appop/AppOpsServiceImpl.java
+++ /dev/null
@@ -1,4679 +0,0 @@
-/*
- * Copyright (C) 2012 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.server.appop;
-
-import static android.app.AppOpsManager.AttributedOpEntry;
-import static android.app.AppOpsManager.AttributionFlags;
-import static android.app.AppOpsManager.CALL_BACK_ON_SWITCHED_OP;
-import static android.app.AppOpsManager.FILTER_BY_ATTRIBUTION_TAG;
-import static android.app.AppOpsManager.FILTER_BY_OP_NAMES;
-import static android.app.AppOpsManager.FILTER_BY_PACKAGE_NAME;
-import static android.app.AppOpsManager.FILTER_BY_UID;
-import static android.app.AppOpsManager.HISTORY_FLAG_GET_ATTRIBUTION_CHAINS;
-import static android.app.AppOpsManager.HistoricalOps;
-import static android.app.AppOpsManager.HistoricalOpsRequestFilter;
-import static android.app.AppOpsManager.KEY_BG_STATE_SETTLE_TIME;
-import static android.app.AppOpsManager.KEY_FG_SERVICE_STATE_SETTLE_TIME;
-import static android.app.AppOpsManager.KEY_TOP_STATE_SETTLE_TIME;
-import static android.app.AppOpsManager.MODE_ALLOWED;
-import static android.app.AppOpsManager.MODE_DEFAULT;
-import static android.app.AppOpsManager.MODE_ERRORED;
-import static android.app.AppOpsManager.MODE_FOREGROUND;
-import static android.app.AppOpsManager.MODE_IGNORED;
-import static android.app.AppOpsManager.Mode;
-import static android.app.AppOpsManager.OP_CAMERA;
-import static android.app.AppOpsManager.OP_FLAGS_ALL;
-import static android.app.AppOpsManager.OP_FLAG_SELF;
-import static android.app.AppOpsManager.OP_FLAG_TRUSTED_PROXIED;
-import static android.app.AppOpsManager.OP_NONE;
-import static android.app.AppOpsManager.OP_PLAY_AUDIO;
-import static android.app.AppOpsManager.OP_RECEIVE_AMBIENT_TRIGGER_AUDIO;
-import static android.app.AppOpsManager.OP_RECORD_AUDIO;
-import static android.app.AppOpsManager.OP_RECORD_AUDIO_HOTWORD;
-import static android.app.AppOpsManager.OP_VIBRATE;
-import static android.app.AppOpsManager.OnOpStartedListener.START_TYPE_FAILED;
-import static android.app.AppOpsManager.OnOpStartedListener.START_TYPE_STARTED;
-import static android.app.AppOpsManager.OpEntry;
-import static android.app.AppOpsManager.OpEventProxyInfo;
-import static android.app.AppOpsManager.OpFlags;
-import static android.app.AppOpsManager.RestrictionBypass;
-import static android.app.AppOpsManager.SECURITY_EXCEPTION_ON_INVALID_ATTRIBUTION_TAG_CHANGE;
-import static android.app.AppOpsManager._NUM_OP;
-import static android.app.AppOpsManager.extractFlagsFromKey;
-import static android.app.AppOpsManager.extractUidStateFromKey;
-import static android.app.AppOpsManager.modeToName;
-import static android.app.AppOpsManager.opAllowSystemBypassRestriction;
-import static android.app.AppOpsManager.opRestrictsRead;
-import static android.app.AppOpsManager.opToName;
-import static android.content.Intent.ACTION_PACKAGE_REMOVED;
-import static android.content.Intent.EXTRA_REPLACING;
-
-import static com.android.server.appop.AppOpsServiceImpl.ModeCallback.ALL_OPS;
-
-import android.Manifest;
-import android.annotation.NonNull;
-import android.annotation.Nullable;
-import android.annotation.UserIdInt;
-import android.app.ActivityManager;
-import android.app.ActivityManagerInternal;
-import android.app.AppGlobals;
-import android.app.AppOpsManager;
-import android.app.admin.DevicePolicyManagerInternal;
-import android.content.BroadcastReceiver;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManagerInternal;
-import android.content.pm.PermissionInfo;
-import android.database.ContentObserver;
-import android.net.Uri;
-import android.os.AsyncTask;
-import android.os.Binder;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.HandlerExecutor;
-import android.os.IBinder;
-import android.os.IBinder.DeathRecipient;
-import android.os.PackageTagsList;
-import android.os.Process;
-import android.os.RemoteCallback;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.SystemClock;
-import android.os.UserHandle;
-import android.os.storage.StorageManagerInternal;
-import android.permission.PermissionManager;
-import android.provider.Settings;
-import android.util.ArrayMap;
-import android.util.ArraySet;
-import android.util.AtomicFile;
-import android.util.KeyValueListParser;
-import android.util.Slog;
-import android.util.SparseArray;
-import android.util.SparseBooleanArray;
-import android.util.SparseIntArray;
-import android.util.TimeUtils;
-import android.util.Xml;
-
-import com.android.internal.annotations.GuardedBy;
-import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.app.IAppOpsActiveCallback;
-import com.android.internal.app.IAppOpsCallback;
-import com.android.internal.app.IAppOpsNotedCallback;
-import com.android.internal.app.IAppOpsStartedCallback;
-import com.android.internal.compat.IPlatformCompat;
-import com.android.internal.os.Clock;
-import com.android.internal.util.ArrayUtils;
-import com.android.internal.util.DumpUtils;
-import com.android.internal.util.Preconditions;
-import com.android.internal.util.XmlUtils;
-import com.android.internal.util.function.pooled.PooledLambda;
-import com.android.modules.utils.TypedXmlPullParser;
-import com.android.modules.utils.TypedXmlSerializer;
-import com.android.server.LocalServices;
-import com.android.server.LockGuard;
-import com.android.server.SystemServerInitThreadPool;
-import com.android.server.pm.pkg.AndroidPackage;
-import com.android.server.pm.pkg.component.ParsedAttribution;
-
-import dalvik.annotation.optimization.NeverCompile;
-
-import libcore.util.EmptyArray;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-
-class AppOpsServiceImpl implements AppOpsServiceInterface {
-    static final String TAG = "AppOps";
-    static final boolean DEBUG = false;
-
-    private static final int NO_VERSION = -1;
-    /**
-     * Increment by one every time and add the corresponding upgrade logic in
-     * {@link #upgradeLocked(int)} below. The first version was 1
-     */
-    private static final int CURRENT_VERSION = 1;
-
-    // Write at most every 30 minutes.
-    static final long WRITE_DELAY = DEBUG ? 1000 : 30 * 60 * 1000;
-
-    // Constant meaning that any UID should be matched when dispatching callbacks
-    private static final int UID_ANY = -2;
-
-    private static final int[] OPS_RESTRICTED_ON_SUSPEND = {
-            OP_PLAY_AUDIO,
-            OP_RECORD_AUDIO,
-            OP_CAMERA,
-            OP_VIBRATE,
-    };
-    private static final int MAX_UNUSED_POOLED_OBJECTS = 3;
-
-    final Context mContext;
-    final AtomicFile mFile;
-    final Handler mHandler;
-
-    /**
-     * Pool for {@link AttributedOp.OpEventProxyInfoPool} to avoid to constantly reallocate new
-     * objects
-     */
-    @GuardedBy("this")
-    final AttributedOp.OpEventProxyInfoPool mOpEventProxyInfoPool =
-            new AttributedOp.OpEventProxyInfoPool(MAX_UNUSED_POOLED_OBJECTS);
-
-    /**
-     * Pool for {@link AttributedOp.InProgressStartOpEventPool} to avoid to constantly reallocate
-     * new objects
-     */
-    @GuardedBy("this")
-    final AttributedOp.InProgressStartOpEventPool mInProgressStartOpEventPool =
-            new AttributedOp.InProgressStartOpEventPool(mOpEventProxyInfoPool,
-                    MAX_UNUSED_POOLED_OBJECTS);
-    @Nullable
-    private final DevicePolicyManagerInternal dpmi =
-            LocalServices.getService(DevicePolicyManagerInternal.class);
-
-    private final IPlatformCompat mPlatformCompat = IPlatformCompat.Stub.asInterface(
-            ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE));
-
-    boolean mWriteScheduled;
-    boolean mFastWriteScheduled;
-    final Runnable mWriteRunner = new Runnable() {
-        public void run() {
-            synchronized (AppOpsServiceImpl.this) {
-                mWriteScheduled = false;
-                mFastWriteScheduled = false;
-                AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
-                    @Override
-                    protected Void doInBackground(Void... params) {
-                        writeState();
-                        return null;
-                    }
-                };
-                task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
-            }
-        }
-    };
-
-    @GuardedBy("this")
-    @VisibleForTesting
-    final SparseArray<UidState> mUidStates = new SparseArray<>();
-
-    volatile @NonNull HistoricalRegistry mHistoricalRegistry = new HistoricalRegistry(this);
-
-    /*
-     * These are app op restrictions imposed per user from various parties.
-     */
-    private final ArrayMap<IBinder, ClientUserRestrictionState> mOpUserRestrictions =
-            new ArrayMap<>();
-
-    /*
-     * These are app op restrictions imposed globally from various parties within the system.
-     */
-    private final ArrayMap<IBinder, ClientGlobalRestrictionState> mOpGlobalRestrictions =
-            new ArrayMap<>();
-
-    SparseIntArray mProfileOwners;
-
-    /**
-     * Reverse lookup for {@link AppOpsManager#opToSwitch(int)}. Initialized once and never
-     * changed
-     */
-    private final SparseArray<int[]> mSwitchedOps = new SparseArray<>();
-
-    /**
-     * Package Manager internal. Access via {@link #getPackageManagerInternal()}
-     */
-    private @Nullable PackageManagerInternal mPackageManagerInternal;
-
-    /**
-     * Interface for app-op modes.
-     */
-    @VisibleForTesting
-    AppOpsCheckingServiceInterface mAppOpsServiceInterface;
-
-    /**
-     * Interface for app-op restrictions.
-     */
-    @VisibleForTesting
-    AppOpsRestrictions mAppOpsRestrictions;
-
-    private AppOpsUidStateTracker mUidStateTracker;
-
-    /**
-     * Hands the definition of foreground and uid states
-     */
-    @GuardedBy("this")
-    public AppOpsUidStateTracker getUidStateTracker() {
-        if (mUidStateTracker == null) {
-            mUidStateTracker = new AppOpsUidStateTrackerImpl(
-                    LocalServices.getService(ActivityManagerInternal.class),
-                    mHandler,
-                    r -> {
-                        synchronized (AppOpsServiceImpl.this) {
-                            r.run();
-                        }
-                    },
-                    Clock.SYSTEM_CLOCK, mConstants);
-
-            mUidStateTracker.addUidStateChangedCallback(new HandlerExecutor(mHandler),
-                    this::onUidStateChanged);
-        }
-        return mUidStateTracker;
-    }
-
-    /**
-     * All times are in milliseconds. These constants are kept synchronized with the system
-     * global Settings. Any access to this class or its fields should be done while
-     * holding the AppOpsService lock.
-     */
-    final class Constants extends ContentObserver {
-
-        /**
-         * How long we want for a drop in uid state from top to settle before applying it.
-         *
-         * @see Settings.Global#APP_OPS_CONSTANTS
-         * @see AppOpsManager#KEY_TOP_STATE_SETTLE_TIME
-         */
-        public long TOP_STATE_SETTLE_TIME;
-
-        /**
-         * How long we want for a drop in uid state from foreground to settle before applying it.
-         *
-         * @see Settings.Global#APP_OPS_CONSTANTS
-         * @see AppOpsManager#KEY_FG_SERVICE_STATE_SETTLE_TIME
-         */
-        public long FG_SERVICE_STATE_SETTLE_TIME;
-
-        /**
-         * How long we want for a drop in uid state from background to settle before applying it.
-         *
-         * @see Settings.Global#APP_OPS_CONSTANTS
-         * @see AppOpsManager#KEY_BG_STATE_SETTLE_TIME
-         */
-        public long BG_STATE_SETTLE_TIME;
-
-        private final KeyValueListParser mParser = new KeyValueListParser(',');
-        private ContentResolver mResolver;
-
-        Constants(Handler handler) {
-            super(handler);
-            updateConstants();
-        }
-
-        public void startMonitoring(ContentResolver resolver) {
-            mResolver = resolver;
-            mResolver.registerContentObserver(
-                    Settings.Global.getUriFor(Settings.Global.APP_OPS_CONSTANTS),
-                    false, this);
-            updateConstants();
-        }
-
-        @Override
-        public void onChange(boolean selfChange, Uri uri) {
-            updateConstants();
-        }
-
-        private void updateConstants() {
-            String value = mResolver != null ? Settings.Global.getString(mResolver,
-                    Settings.Global.APP_OPS_CONSTANTS) : "";
-
-            synchronized (AppOpsServiceImpl.this) {
-                try {
-                    mParser.setString(value);
-                } catch (IllegalArgumentException e) {
-                    // Failed to parse the settings string, log this and move on
-                    // with defaults.
-                    Slog.e(TAG, "Bad app ops settings", e);
-                }
-                TOP_STATE_SETTLE_TIME = mParser.getDurationMillis(
-                        KEY_TOP_STATE_SETTLE_TIME, 5 * 1000L);
-                FG_SERVICE_STATE_SETTLE_TIME = mParser.getDurationMillis(
-                        KEY_FG_SERVICE_STATE_SETTLE_TIME, 5 * 1000L);
-                BG_STATE_SETTLE_TIME = mParser.getDurationMillis(
-                        KEY_BG_STATE_SETTLE_TIME, 1 * 1000L);
-            }
-        }
-
-        void dump(PrintWriter pw) {
-            pw.println("  Settings:");
-
-            pw.print("    ");
-            pw.print(KEY_TOP_STATE_SETTLE_TIME);
-            pw.print("=");
-            TimeUtils.formatDuration(TOP_STATE_SETTLE_TIME, pw);
-            pw.println();
-            pw.print("    ");
-            pw.print(KEY_FG_SERVICE_STATE_SETTLE_TIME);
-            pw.print("=");
-            TimeUtils.formatDuration(FG_SERVICE_STATE_SETTLE_TIME, pw);
-            pw.println();
-            pw.print("    ");
-            pw.print(KEY_BG_STATE_SETTLE_TIME);
-            pw.print("=");
-            TimeUtils.formatDuration(BG_STATE_SETTLE_TIME, pw);
-            pw.println();
-        }
-    }
-
-    @VisibleForTesting
-    final Constants mConstants;
-
-    @VisibleForTesting
-    final class UidState {
-        public final int uid;
-
-        public ArrayMap<String, Ops> pkgOps;
-
-        // true indicates there is an interested observer, false there isn't but it has such an op
-        //TODO: Move foregroundOps and hasForegroundWatchers into the AppOpsServiceInterface.
-        public SparseBooleanArray foregroundOps;
-        public boolean hasForegroundWatchers;
-
-        public UidState(int uid) {
-            this.uid = uid;
-        }
-
-        public void clear() {
-            mAppOpsServiceInterface.removeUid(uid);
-            if (pkgOps != null) {
-                for (String packageName : pkgOps.keySet()) {
-                    mAppOpsServiceInterface.removePackage(packageName, UserHandle.getUserId(uid));
-                }
-            }
-            pkgOps = null;
-        }
-
-        public boolean isDefault() {
-            boolean areAllPackageModesDefault = true;
-            if (pkgOps != null) {
-                for (String packageName : pkgOps.keySet()) {
-                    if (!mAppOpsServiceInterface.arePackageModesDefault(packageName,
-                            UserHandle.getUserId(uid))) {
-                        areAllPackageModesDefault = false;
-                        break;
-                    }
-                }
-            }
-            return (pkgOps == null || pkgOps.isEmpty())
-                    && mAppOpsServiceInterface.areUidModesDefault(uid)
-                    && areAllPackageModesDefault;
-        }
-
-        // Functions for uid mode access and manipulation.
-        public SparseIntArray getNonDefaultUidModes() {
-            return mAppOpsServiceInterface.getNonDefaultUidModes(uid);
-        }
-
-        public int getUidMode(int op) {
-            return mAppOpsServiceInterface.getUidMode(uid, op);
-        }
-
-        public boolean setUidMode(int op, int mode) {
-            return mAppOpsServiceInterface.setUidMode(uid, op, mode);
-        }
-
-        @SuppressWarnings("GuardedBy")
-        int evalMode(int op, int mode) {
-            return getUidStateTracker().evalMode(uid, op, mode);
-        }
-
-        public void evalForegroundOps() {
-            foregroundOps = null;
-            foregroundOps = mAppOpsServiceInterface.evalForegroundUidOps(uid, foregroundOps);
-            if (pkgOps != null) {
-                for (int i = pkgOps.size() - 1; i >= 0; i--) {
-                    foregroundOps = mAppOpsServiceInterface
-                            .evalForegroundPackageOps(pkgOps.valueAt(i).packageName,
-                                    foregroundOps,
-                                    UserHandle.getUserId(uid));
-                }
-            }
-            hasForegroundWatchers = false;
-            if (foregroundOps != null) {
-                for (int i = 0; i < foregroundOps.size(); i++) {
-                    if (foregroundOps.valueAt(i)) {
-                        hasForegroundWatchers = true;
-                        break;
-                    }
-                }
-            }
-        }
-
-        @SuppressWarnings("GuardedBy")
-        public int getState() {
-            return getUidStateTracker().getUidState(uid);
-        }
-
-        @SuppressWarnings("GuardedBy")
-        public void dump(PrintWriter pw, long nowElapsed) {
-            getUidStateTracker().dumpUidState(pw, uid, nowElapsed);
-        }
-    }
-
-    static final class Ops extends SparseArray<Op> {
-        final String packageName;
-        final UidState uidState;
-
-        /**
-         * The restriction properties of the package. If {@code null} it could not have been read
-         * yet and has to be refreshed.
-         */
-        @Nullable RestrictionBypass bypass;
-
-        /** Lazily populated cache of attributionTags of this package */
-        final @NonNull ArraySet<String> knownAttributionTags = new ArraySet<>();
-
-        /**
-         * Lazily populated cache of <b>valid</b> attributionTags of this package, a set smaller
-         * than or equal to {@link #knownAttributionTags}.
-         */
-        final @NonNull ArraySet<String> validAttributionTags = new ArraySet<>();
-
-        Ops(String _packageName, UidState _uidState) {
-            packageName = _packageName;
-            uidState = _uidState;
-        }
-    }
-
-    /** Returned from {@link #verifyAndGetBypass(int, String, String, String)}. */
-    private static final class PackageVerificationResult {
-
-        final RestrictionBypass bypass;
-        final boolean isAttributionTagValid;
-
-        PackageVerificationResult(RestrictionBypass bypass, boolean isAttributionTagValid) {
-            this.bypass = bypass;
-            this.isAttributionTagValid = isAttributionTagValid;
-        }
-    }
-
-    final class Op {
-        int op;
-        int uid;
-        final UidState uidState;
-        final @NonNull String packageName;
-
-        /** attributionTag -> AttributedOp */
-        final ArrayMap<String, AttributedOp> mAttributions = new ArrayMap<>(1);
-
-        Op(UidState uidState, String packageName, int op, int uid) {
-            this.op = op;
-            this.uid = uid;
-            this.uidState = uidState;
-            this.packageName = packageName;
-        }
-
-        @Mode int getMode() {
-            return mAppOpsServiceInterface.getPackageMode(packageName, this.op,
-                    UserHandle.getUserId(this.uid));
-        }
-
-        void setMode(@Mode int mode) {
-            mAppOpsServiceInterface.setPackageMode(packageName, this.op, mode,
-                    UserHandle.getUserId(this.uid));
-        }
-
-        void removeAttributionsWithNoTime() {
-            for (int i = mAttributions.size() - 1; i >= 0; i--) {
-                if (!mAttributions.valueAt(i).hasAnyTime()) {
-                    mAttributions.removeAt(i);
-                }
-            }
-        }
-
-        private @NonNull AttributedOp getOrCreateAttribution(@NonNull Op parent,
-                @Nullable String attributionTag) {
-            AttributedOp attributedOp;
-
-            attributedOp = mAttributions.get(attributionTag);
-            if (attributedOp == null) {
-                attributedOp = new AttributedOp(AppOpsServiceImpl.this, attributionTag,
-                        parent);
-                mAttributions.put(attributionTag, attributedOp);
-            }
-
-            return attributedOp;
-        }
-
-        @NonNull
-        OpEntry createEntryLocked() {
-            final int numAttributions = mAttributions.size();
-
-            final ArrayMap<String, AppOpsManager.AttributedOpEntry> attributionEntries =
-                    new ArrayMap<>(numAttributions);
-            for (int i = 0; i < numAttributions; i++) {
-                attributionEntries.put(mAttributions.keyAt(i),
-                        mAttributions.valueAt(i).createAttributedOpEntryLocked());
-            }
-
-            return new OpEntry(op, getMode(), attributionEntries);
-        }
-
-        @NonNull
-        OpEntry createSingleAttributionEntryLocked(@Nullable String attributionTag) {
-            final int numAttributions = mAttributions.size();
-
-            final ArrayMap<String, AttributedOpEntry> attributionEntries = new ArrayMap<>(1);
-            for (int i = 0; i < numAttributions; i++) {
-                if (Objects.equals(mAttributions.keyAt(i), attributionTag)) {
-                    attributionEntries.put(mAttributions.keyAt(i),
-                            mAttributions.valueAt(i).createAttributedOpEntryLocked());
-                    break;
-                }
-            }
-
-            return new OpEntry(op, getMode(), attributionEntries);
-        }
-
-        boolean isRunning() {
-            final int numAttributions = mAttributions.size();
-            for (int i = 0; i < numAttributions; i++) {
-                if (mAttributions.valueAt(i).isRunning()) {
-                    return true;
-                }
-            }
-
-            return false;
-        }
-    }
-
-    final ArrayMap<IBinder, ModeCallback> mModeWatchers = new ArrayMap<>();
-    final ArrayMap<IBinder, SparseArray<ActiveCallback>> mActiveWatchers = new ArrayMap<>();
-    final ArrayMap<IBinder, SparseArray<StartedCallback>> mStartedWatchers = new ArrayMap<>();
-    final ArrayMap<IBinder, SparseArray<NotedCallback>> mNotedWatchers = new ArrayMap<>();
-
-    final class ModeCallback extends OnOpModeChangedListener implements DeathRecipient  {
-        /** If mWatchedOpCode==ALL_OPS notify for ops affected by the switch-op */
-        public static final int ALL_OPS = -2;
-
-        // Need to keep this only because stopWatchingMode needs an IAppOpsCallback.
-        // Otherwise we can just use the IBinder object.
-        private final IAppOpsCallback mCallback;
-
-        ModeCallback(IAppOpsCallback callback, int watchingUid, int flags, int watchedOpCode,
-                int callingUid, int callingPid) {
-            super(watchingUid, flags, watchedOpCode, callingUid, callingPid);
-            this.mCallback = callback;
-            try {
-                mCallback.asBinder().linkToDeath(this, 0);
-            } catch (RemoteException e) {
-                /*ignored*/
-            }
-        }
-
-        @Override
-        public String toString() {
-            StringBuilder sb = new StringBuilder(128);
-            sb.append("ModeCallback{");
-            sb.append(Integer.toHexString(System.identityHashCode(this)));
-            sb.append(" watchinguid=");
-            UserHandle.formatUid(sb, getWatchingUid());
-            sb.append(" flags=0x");
-            sb.append(Integer.toHexString(getFlags()));
-            switch (getWatchedOpCode()) {
-                case OP_NONE:
-                    break;
-                case ALL_OPS:
-                    sb.append(" op=(all)");
-                    break;
-                default:
-                    sb.append(" op=");
-                    sb.append(opToName(getWatchedOpCode()));
-                    break;
-            }
-            sb.append(" from uid=");
-            UserHandle.formatUid(sb, getCallingUid());
-            sb.append(" pid=");
-            sb.append(getCallingPid());
-            sb.append('}');
-            return sb.toString();
-        }
-
-        void unlinkToDeath() {
-            mCallback.asBinder().unlinkToDeath(this, 0);
-        }
-
-        @Override
-        public void binderDied() {
-            stopWatchingMode(mCallback);
-        }
-
-        @Override
-        public void onOpModeChanged(int op, int uid, String packageName) throws RemoteException {
-            mCallback.opChanged(op, uid, packageName);
-        }
-    }
-
-    final class ActiveCallback implements DeathRecipient {
-        final IAppOpsActiveCallback mCallback;
-        final int mWatchingUid;
-        final int mCallingUid;
-        final int mCallingPid;
-
-        ActiveCallback(IAppOpsActiveCallback callback, int watchingUid, int callingUid,
-                int callingPid) {
-            mCallback = callback;
-            mWatchingUid = watchingUid;
-            mCallingUid = callingUid;
-            mCallingPid = callingPid;
-            try {
-                mCallback.asBinder().linkToDeath(this, 0);
-            } catch (RemoteException e) {
-                /*ignored*/
-            }
-        }
-
-        @Override
-        public String toString() {
-            StringBuilder sb = new StringBuilder(128);
-            sb.append("ActiveCallback{");
-            sb.append(Integer.toHexString(System.identityHashCode(this)));
-            sb.append(" watchinguid=");
-            UserHandle.formatUid(sb, mWatchingUid);
-            sb.append(" from uid=");
-            UserHandle.formatUid(sb, mCallingUid);
-            sb.append(" pid=");
-            sb.append(mCallingPid);
-            sb.append('}');
-            return sb.toString();
-        }
-
-        void destroy() {
-            mCallback.asBinder().unlinkToDeath(this, 0);
-        }
-
-        @Override
-        public void binderDied() {
-            stopWatchingActive(mCallback);
-        }
-    }
-
-    final class StartedCallback implements DeathRecipient {
-        final IAppOpsStartedCallback mCallback;
-        final int mWatchingUid;
-        final int mCallingUid;
-        final int mCallingPid;
-
-        StartedCallback(IAppOpsStartedCallback callback, int watchingUid, int callingUid,
-                int callingPid) {
-            mCallback = callback;
-            mWatchingUid = watchingUid;
-            mCallingUid = callingUid;
-            mCallingPid = callingPid;
-            try {
-                mCallback.asBinder().linkToDeath(this, 0);
-            } catch (RemoteException e) {
-                /*ignored*/
-            }
-        }
-
-        @Override
-        public String toString() {
-            StringBuilder sb = new StringBuilder(128);
-            sb.append("StartedCallback{");
-            sb.append(Integer.toHexString(System.identityHashCode(this)));
-            sb.append(" watchinguid=");
-            UserHandle.formatUid(sb, mWatchingUid);
-            sb.append(" from uid=");
-            UserHandle.formatUid(sb, mCallingUid);
-            sb.append(" pid=");
-            sb.append(mCallingPid);
-            sb.append('}');
-            return sb.toString();
-        }
-
-        void destroy() {
-            mCallback.asBinder().unlinkToDeath(this, 0);
-        }
-
-        @Override
-        public void binderDied() {
-            stopWatchingStarted(mCallback);
-        }
-    }
-
-    final class NotedCallback implements DeathRecipient {
-        final IAppOpsNotedCallback mCallback;
-        final int mWatchingUid;
-        final int mCallingUid;
-        final int mCallingPid;
-
-        NotedCallback(IAppOpsNotedCallback callback, int watchingUid, int callingUid,
-                int callingPid) {
-            mCallback = callback;
-            mWatchingUid = watchingUid;
-            mCallingUid = callingUid;
-            mCallingPid = callingPid;
-            try {
-                mCallback.asBinder().linkToDeath(this, 0);
-            } catch (RemoteException e) {
-                /*ignored*/
-            }
-        }
-
-        @Override
-        public String toString() {
-            StringBuilder sb = new StringBuilder(128);
-            sb.append("NotedCallback{");
-            sb.append(Integer.toHexString(System.identityHashCode(this)));
-            sb.append(" watchinguid=");
-            UserHandle.formatUid(sb, mWatchingUid);
-            sb.append(" from uid=");
-            UserHandle.formatUid(sb, mCallingUid);
-            sb.append(" pid=");
-            sb.append(mCallingPid);
-            sb.append('}');
-            return sb.toString();
-        }
-
-        void destroy() {
-            mCallback.asBinder().unlinkToDeath(this, 0);
-        }
-
-        @Override
-        public void binderDied() {
-            stopWatchingNoted(mCallback);
-        }
-    }
-
-    /**
-     * Call {@link AttributedOp#onClientDeath attributedOp.onClientDeath(clientId)}.
-     */
-    static void onClientDeath(@NonNull AttributedOp attributedOp,
-            @NonNull IBinder clientId) {
-        attributedOp.onClientDeath(clientId);
-    }
-
-    AppOpsServiceImpl(File storagePath, Handler handler, Context context) {
-        mContext = context;
-
-        for (int switchedCode = 0; switchedCode < _NUM_OP; switchedCode++) {
-            int switchCode = AppOpsManager.opToSwitch(switchedCode);
-            mSwitchedOps.put(switchCode,
-                    ArrayUtils.appendInt(mSwitchedOps.get(switchCode), switchedCode));
-        }
-        mAppOpsServiceInterface =
-                new AppOpsCheckingServiceImpl(this, this, handler, context, mSwitchedOps);
-        mAppOpsRestrictions = new AppOpsRestrictionsImpl(context, handler,
-                mAppOpsServiceInterface);
-
-        LockGuard.installLock(this, LockGuard.INDEX_APP_OPS);
-        mFile = new AtomicFile(storagePath, "appops");
-
-        mHandler = handler;
-        mConstants = new Constants(mHandler);
-        readState();
-    }
-
-    /**
-     * Handler for work when packages are removed or updated
-     */
-    private BroadcastReceiver mOnPackageUpdatedReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            String action = intent.getAction();
-            String pkgName = intent.getData().getEncodedSchemeSpecificPart();
-            int uid = intent.getIntExtra(Intent.EXTRA_UID, Process.INVALID_UID);
-
-            if (action.equals(ACTION_PACKAGE_REMOVED) && !intent.hasExtra(EXTRA_REPLACING)) {
-                synchronized (AppOpsServiceImpl.this) {
-                    UidState uidState = mUidStates.get(uid);
-                    if (uidState == null || uidState.pkgOps == null) {
-                        return;
-                    }
-                    mAppOpsServiceInterface.removePackage(pkgName, UserHandle.getUserId(uid));
-                    Ops removedOps = uidState.pkgOps.remove(pkgName);
-                    if (removedOps != null) {
-                        scheduleFastWriteLocked();
-                    }
-                }
-            } else if (action.equals(Intent.ACTION_PACKAGE_REPLACED)) {
-                AndroidPackage pkg = getPackageManagerInternal().getPackage(pkgName);
-                if (pkg == null) {
-                    return;
-                }
-
-                ArrayMap<String, String> dstAttributionTags = new ArrayMap<>();
-                ArraySet<String> attributionTags = new ArraySet<>();
-                attributionTags.add(null);
-                if (pkg.getAttributions() != null) {
-                    int numAttributions = pkg.getAttributions().size();
-                    for (int attributionNum = 0; attributionNum < numAttributions;
-                            attributionNum++) {
-                        ParsedAttribution attribution = pkg.getAttributions().get(attributionNum);
-                        attributionTags.add(attribution.getTag());
-
-                        int numInheritFrom = attribution.getInheritFrom().size();
-                        for (int inheritFromNum = 0; inheritFromNum < numInheritFrom;
-                                inheritFromNum++) {
-                            dstAttributionTags.put(attribution.getInheritFrom().get(inheritFromNum),
-                                    attribution.getTag());
-                        }
-                    }
-                }
-
-                synchronized (AppOpsServiceImpl.this) {
-                    UidState uidState = mUidStates.get(uid);
-                    if (uidState == null || uidState.pkgOps == null) {
-                        return;
-                    }
-
-                    Ops ops = uidState.pkgOps.get(pkgName);
-                    if (ops == null) {
-                        return;
-                    }
-
-                    // Reset cached package properties to re-initialize when needed
-                    ops.bypass = null;
-                    ops.knownAttributionTags.clear();
-
-                    // Merge data collected for removed attributions into their successor
-                    // attributions
-                    int numOps = ops.size();
-                    for (int opNum = 0; opNum < numOps; opNum++) {
-                        Op op = ops.valueAt(opNum);
-
-                        int numAttributions = op.mAttributions.size();
-                        for (int attributionNum = numAttributions - 1; attributionNum >= 0;
-                                attributionNum--) {
-                            String attributionTag = op.mAttributions.keyAt(attributionNum);
-
-                            if (attributionTags.contains(attributionTag)) {
-                                // attribution still exist after upgrade
-                                continue;
-                            }
-
-                            String newAttributionTag = dstAttributionTags.get(attributionTag);
-
-                            AttributedOp newAttributedOp = op.getOrCreateAttribution(op,
-                                    newAttributionTag);
-                            newAttributedOp.add(op.mAttributions.valueAt(attributionNum));
-                            op.mAttributions.removeAt(attributionNum);
-
-                            scheduleFastWriteLocked();
-                        }
-                    }
-                }
-            }
-        }
-    };
-
-    @Override
-    public void systemReady() {
-        mConstants.startMonitoring(mContext.getContentResolver());
-        mHistoricalRegistry.systemReady(mContext.getContentResolver());
-
-        IntentFilter packageUpdateFilter = new IntentFilter();
-        packageUpdateFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
-        packageUpdateFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
-        packageUpdateFilter.addDataScheme("package");
-
-        mContext.registerReceiverAsUser(mOnPackageUpdatedReceiver, UserHandle.ALL,
-                packageUpdateFilter, null, null);
-
-        synchronized (this) {
-            for (int uidNum = mUidStates.size() - 1; uidNum >= 0; uidNum--) {
-                int uid = mUidStates.keyAt(uidNum);
-                UidState uidState = mUidStates.valueAt(uidNum);
-
-                String[] pkgsInUid = getPackagesForUid(uidState.uid);
-                if (ArrayUtils.isEmpty(pkgsInUid)) {
-                    uidState.clear();
-                    mUidStates.removeAt(uidNum);
-                    scheduleFastWriteLocked();
-                    continue;
-                }
-
-                ArrayMap<String, Ops> pkgs = uidState.pkgOps;
-                if (pkgs == null) {
-                    continue;
-                }
-
-                int numPkgs = pkgs.size();
-                for (int pkgNum = 0; pkgNum < numPkgs; pkgNum++) {
-                    String pkg = pkgs.keyAt(pkgNum);
-
-                    String action;
-                    if (!ArrayUtils.contains(pkgsInUid, pkg)) {
-                        action = Intent.ACTION_PACKAGE_REMOVED;
-                    } else {
-                        action = Intent.ACTION_PACKAGE_REPLACED;
-                    }
-
-                    SystemServerInitThreadPool.submit(
-                            () -> mOnPackageUpdatedReceiver.onReceive(mContext, new Intent(action)
-                                    .setData(Uri.fromParts("package", pkg, null))
-                                    .putExtra(Intent.EXTRA_UID, uid)),
-                            "Update app-ops uidState in case package " + pkg + " changed");
-                }
-            }
-        }
-
-        final IntentFilter packageSuspendFilter = new IntentFilter();
-        packageSuspendFilter.addAction(Intent.ACTION_PACKAGES_UNSUSPENDED);
-        packageSuspendFilter.addAction(Intent.ACTION_PACKAGES_SUSPENDED);
-        mContext.registerReceiverAsUser(new BroadcastReceiver() {
-            @Override
-            public void onReceive(Context context, Intent intent) {
-                final int[] changedUids = intent.getIntArrayExtra(Intent.EXTRA_CHANGED_UID_LIST);
-                final String[] changedPkgs = intent.getStringArrayExtra(
-                        Intent.EXTRA_CHANGED_PACKAGE_LIST);
-                for (int code : OPS_RESTRICTED_ON_SUSPEND) {
-                    ArraySet<OnOpModeChangedListener> onModeChangedListeners;
-                    synchronized (AppOpsServiceImpl.this) {
-                        onModeChangedListeners =
-                                mAppOpsServiceInterface.getOpModeChangedListeners(code);
-                        if (onModeChangedListeners == null) {
-                            continue;
-                        }
-                    }
-                    for (int i = 0; i < changedUids.length; i++) {
-                        final int changedUid = changedUids[i];
-                        final String changedPkg = changedPkgs[i];
-                        // We trust packagemanager to insert matching uid and packageNames in the
-                        // extras
-                        notifyOpChanged(onModeChangedListeners, code, changedUid, changedPkg);
-                    }
-                }
-            }
-        }, UserHandle.ALL, packageSuspendFilter, null, null);
-    }
-
-    @Override
-    public void packageRemoved(int uid, String packageName) {
-        synchronized (this) {
-            UidState uidState = mUidStates.get(uid);
-            if (uidState == null) {
-                return;
-            }
-
-            Ops removedOps = null;
-
-            // Remove any package state if such.
-            if (uidState.pkgOps != null) {
-                removedOps = uidState.pkgOps.remove(packageName);
-                mAppOpsServiceInterface.removePackage(packageName, UserHandle.getUserId(uid));
-            }
-
-            // If we just nuked the last package state check if the UID is valid.
-            if (removedOps != null && uidState.pkgOps.isEmpty()
-                    && getPackagesForUid(uid).length <= 0) {
-                uidState.clear();
-                mUidStates.remove(uid);
-            }
-
-            if (removedOps != null) {
-                scheduleFastWriteLocked();
-
-                final int numOps = removedOps.size();
-                for (int opNum = 0; opNum < numOps; opNum++) {
-                    final Op op = removedOps.valueAt(opNum);
-
-                    final int numAttributions = op.mAttributions.size();
-                    for (int attributionNum = 0; attributionNum < numAttributions;
-                            attributionNum++) {
-                        AttributedOp attributedOp = op.mAttributions.valueAt(attributionNum);
-
-                        while (attributedOp.isRunning()) {
-                            attributedOp.finished(attributedOp.mInProgressEvents.keyAt(0));
-                        }
-                        while (attributedOp.isPaused()) {
-                            attributedOp.finished(attributedOp.mPausedInProgressEvents.keyAt(0));
-                        }
-                    }
-                }
-            }
-        }
-
-        mHandler.post(PooledLambda.obtainRunnable(HistoricalRegistry::clearHistory,
-                mHistoricalRegistry, uid, packageName));
-    }
-
-    @Override
-    public void uidRemoved(int uid) {
-        synchronized (this) {
-            if (mUidStates.indexOfKey(uid) >= 0) {
-                mUidStates.get(uid).clear();
-                mUidStates.remove(uid);
-                scheduleFastWriteLocked();
-            }
-        }
-    }
-
-    // The callback method from ForegroundPolicyInterface
-    private void onUidStateChanged(int uid, int state, boolean foregroundModeMayChange) {
-        synchronized (this) {
-            UidState uidState = getUidStateLocked(uid, true);
-
-            if (uidState != null && foregroundModeMayChange && uidState.hasForegroundWatchers) {
-                for (int fgi = uidState.foregroundOps.size() - 1; fgi >= 0; fgi--) {
-                    if (!uidState.foregroundOps.valueAt(fgi)) {
-                        continue;
-                    }
-                    final int code = uidState.foregroundOps.keyAt(fgi);
-
-                    if (uidState.getUidMode(code) != AppOpsManager.opToDefaultMode(code)
-                            && uidState.getUidMode(code) == AppOpsManager.MODE_FOREGROUND) {
-                        mHandler.sendMessage(PooledLambda.obtainMessage(
-                                AppOpsServiceImpl::notifyOpChangedForAllPkgsInUid,
-                                this, code, uidState.uid, true, null));
-                    } else if (uidState.pkgOps != null) {
-                        final ArraySet<OnOpModeChangedListener> listenerSet =
-                                mAppOpsServiceInterface.getOpModeChangedListeners(code);
-                        if (listenerSet != null) {
-                            for (int cbi = listenerSet.size() - 1; cbi >= 0; cbi--) {
-                                final OnOpModeChangedListener listener = listenerSet.valueAt(cbi);
-                                if ((listener.getFlags()
-                                        & AppOpsManager.WATCH_FOREGROUND_CHANGES) == 0
-                                        || !listener.isWatchingUid(uidState.uid)) {
-                                    continue;
-                                }
-                                for (int pkgi = uidState.pkgOps.size() - 1; pkgi >= 0; pkgi--) {
-                                    final Op op = uidState.pkgOps.valueAt(pkgi).get(code);
-                                    if (op == null) {
-                                        continue;
-                                    }
-                                    if (op.getMode() == AppOpsManager.MODE_FOREGROUND) {
-                                        mHandler.sendMessage(PooledLambda.obtainMessage(
-                                                AppOpsServiceImpl::notifyOpChanged,
-                                                this, listenerSet.valueAt(cbi), code, uidState.uid,
-                                                uidState.pkgOps.keyAt(pkgi)));
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-
-            if (uidState != null && uidState.pkgOps != null) {
-                int numPkgs = uidState.pkgOps.size();
-                for (int pkgNum = 0; pkgNum < numPkgs; pkgNum++) {
-                    Ops ops = uidState.pkgOps.valueAt(pkgNum);
-
-                    int numOps = ops.size();
-                    for (int opNum = 0; opNum < numOps; opNum++) {
-                        Op op = ops.valueAt(opNum);
-
-                        int numAttributions = op.mAttributions.size();
-                        for (int attributionNum = 0; attributionNum < numAttributions;
-                                attributionNum++) {
-                            AttributedOp attributedOp = op.mAttributions.valueAt(
-                                    attributionNum);
-
-                            attributedOp.onUidStateChanged(state);
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    /**
-     * Notify the proc state or capability has changed for a certain UID.
-     */
-    @Override
-    public void updateUidProcState(int uid, int procState,
-            @ActivityManager.ProcessCapability int capability) {
-        synchronized (this) {
-            getUidStateTracker().updateUidProcState(uid, procState, capability);
-            if (!mUidStates.contains(uid)) {
-                UidState uidState = new UidState(uid);
-                mUidStates.put(uid, uidState);
-                onUidStateChanged(uid,
-                        AppOpsUidStateTracker.processStateToUidState(procState), false);
-            }
-        }
-    }
-
-    @Override
-    public void shutdown() {
-        Slog.w(TAG, "Writing app ops before shutdown...");
-        boolean doWrite = false;
-        synchronized (this) {
-            if (mWriteScheduled) {
-                mWriteScheduled = false;
-                mFastWriteScheduled = false;
-                mHandler.removeCallbacks(mWriteRunner);
-                doWrite = true;
-            }
-        }
-        if (doWrite) {
-            writeState();
-        }
-
-        mHistoricalRegistry.shutdown();
-    }
-
-    private ArrayList<AppOpsManager.OpEntry> collectOps(Ops pkgOps, int[] ops) {
-        ArrayList<AppOpsManager.OpEntry> resOps = null;
-        if (ops == null) {
-            resOps = new ArrayList<>();
-            for (int j = 0; j < pkgOps.size(); j++) {
-                Op curOp = pkgOps.valueAt(j);
-                resOps.add(getOpEntryForResult(curOp));
-            }
-        } else {
-            for (int j = 0; j < ops.length; j++) {
-                Op curOp = pkgOps.get(ops[j]);
-                if (curOp != null) {
-                    if (resOps == null) {
-                        resOps = new ArrayList<>();
-                    }
-                    resOps.add(getOpEntryForResult(curOp));
-                }
-            }
-        }
-        return resOps;
-    }
-
-    @Nullable
-    private ArrayList<AppOpsManager.OpEntry> collectUidOps(@NonNull UidState uidState,
-            @Nullable int[] ops) {
-        final SparseIntArray opModes = uidState.getNonDefaultUidModes();
-        if (opModes == null) {
-            return null;
-        }
-
-        int opModeCount = opModes.size();
-        if (opModeCount == 0) {
-            return null;
-        }
-        ArrayList<AppOpsManager.OpEntry> resOps = null;
-        if (ops == null) {
-            resOps = new ArrayList<>();
-            for (int i = 0; i < opModeCount; i++) {
-                int code = opModes.keyAt(i);
-                resOps.add(new OpEntry(code, opModes.get(code), Collections.emptyMap()));
-            }
-        } else {
-            for (int j = 0; j < ops.length; j++) {
-                int code = ops[j];
-                if (opModes.indexOfKey(code) >= 0) {
-                    if (resOps == null) {
-                        resOps = new ArrayList<>();
-                    }
-                    resOps.add(new OpEntry(code, opModes.get(code), Collections.emptyMap()));
-                }
-            }
-        }
-        return resOps;
-    }
-
-    private static @NonNull OpEntry getOpEntryForResult(@NonNull Op op) {
-        return op.createEntryLocked();
-    }
-
-    @Override
-    public List<AppOpsManager.PackageOps> getPackagesForOps(int[] ops) {
-        final int callingUid = Binder.getCallingUid();
-        final boolean hasAllPackageAccess = mContext.checkPermission(
-                Manifest.permission.GET_APP_OPS_STATS, Binder.getCallingPid(),
-                Binder.getCallingUid(), null) == PackageManager.PERMISSION_GRANTED;
-        ArrayList<AppOpsManager.PackageOps> res = null;
-        synchronized (this) {
-            final int uidStateCount = mUidStates.size();
-            for (int i = 0; i < uidStateCount; i++) {
-                UidState uidState = mUidStates.valueAt(i);
-                if (uidState.pkgOps == null || uidState.pkgOps.isEmpty()) {
-                    continue;
-                }
-                ArrayMap<String, Ops> packages = uidState.pkgOps;
-                final int packageCount = packages.size();
-                for (int j = 0; j < packageCount; j++) {
-                    Ops pkgOps = packages.valueAt(j);
-                    ArrayList<AppOpsManager.OpEntry> resOps = collectOps(pkgOps, ops);
-                    if (resOps != null) {
-                        if (res == null) {
-                            res = new ArrayList<>();
-                        }
-                        AppOpsManager.PackageOps resPackage = new AppOpsManager.PackageOps(
-                                pkgOps.packageName, pkgOps.uidState.uid, resOps);
-                        // Caller can always see their packages and with a permission all.
-                        if (hasAllPackageAccess || callingUid == pkgOps.uidState.uid) {
-                            res.add(resPackage);
-                        }
-                    }
-                }
-            }
-        }
-        return res;
-    }
-
-    @Override
-    public List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName,
-            int[] ops) {
-        enforceGetAppOpsStatsPermissionIfNeeded(uid, packageName);
-        String resolvedPackageName = AppOpsManager.resolvePackageName(uid, packageName);
-        if (resolvedPackageName == null) {
-            return Collections.emptyList();
-        }
-        synchronized (this) {
-            Ops pkgOps = getOpsLocked(uid, resolvedPackageName, null, false, null,
-                    /* edit */ false);
-            if (pkgOps == null) {
-                return null;
-            }
-            ArrayList<AppOpsManager.OpEntry> resOps = collectOps(pkgOps, ops);
-            if (resOps == null) {
-                return null;
-            }
-            ArrayList<AppOpsManager.PackageOps> res = new ArrayList<>();
-            AppOpsManager.PackageOps resPackage = new AppOpsManager.PackageOps(
-                    pkgOps.packageName, pkgOps.uidState.uid, resOps);
-            res.add(resPackage);
-            return res;
-        }
-    }
-
-    private void enforceGetAppOpsStatsPermissionIfNeeded(int uid, String packageName) {
-        final int callingUid = Binder.getCallingUid();
-        // We get to access everything
-        if (callingUid == Process.myPid()) {
-            return;
-        }
-        // Apps can access their own data
-        if (uid == callingUid && packageName != null
-                && checkPackage(uid, packageName) == MODE_ALLOWED) {
-            return;
-        }
-        // Otherwise, you need a permission...
-        mContext.enforcePermission(android.Manifest.permission.GET_APP_OPS_STATS,
-                Binder.getCallingPid(), callingUid, null);
-    }
-
-    /**
-     * Verify that historical appop request arguments are valid.
-     */
-    private void ensureHistoricalOpRequestIsValid(int uid, String packageName,
-            String attributionTag, List<String> opNames, int filter, long beginTimeMillis,
-            long endTimeMillis, int flags) {
-        if ((filter & FILTER_BY_UID) != 0) {
-            Preconditions.checkArgument(uid != Process.INVALID_UID);
-        } else {
-            Preconditions.checkArgument(uid == Process.INVALID_UID);
-        }
-
-        if ((filter & FILTER_BY_PACKAGE_NAME) != 0) {
-            Objects.requireNonNull(packageName);
-        } else {
-            Preconditions.checkArgument(packageName == null);
-        }
-
-        if ((filter & FILTER_BY_ATTRIBUTION_TAG) == 0) {
-            Preconditions.checkArgument(attributionTag == null);
-        }
-
-        if ((filter & FILTER_BY_OP_NAMES) != 0) {
-            Objects.requireNonNull(opNames);
-        } else {
-            Preconditions.checkArgument(opNames == null);
-        }
-
-        Preconditions.checkFlagsArgument(filter,
-                FILTER_BY_UID | FILTER_BY_PACKAGE_NAME | FILTER_BY_ATTRIBUTION_TAG
-                        | FILTER_BY_OP_NAMES);
-        Preconditions.checkArgumentNonnegative(beginTimeMillis);
-        Preconditions.checkArgument(endTimeMillis > beginTimeMillis);
-        Preconditions.checkFlagsArgument(flags, OP_FLAGS_ALL);
-    }
-
-    @Override
-    public void getHistoricalOps(int uid, String packageName, String attributionTag,
-            List<String> opNames, int dataType, int filter, long beginTimeMillis,
-            long endTimeMillis, int flags, RemoteCallback callback) {
-        PackageManager pm = mContext.getPackageManager();
-
-        ensureHistoricalOpRequestIsValid(uid, packageName, attributionTag, opNames, filter,
-                beginTimeMillis, endTimeMillis, flags);
-        Objects.requireNonNull(callback, "callback cannot be null");
-        ActivityManagerInternal ami = LocalServices.getService(ActivityManagerInternal.class);
-        boolean isSelfRequest = (filter & FILTER_BY_UID) != 0 && uid == Binder.getCallingUid();
-        if (!isSelfRequest) {
-            boolean isCallerInstrumented =
-                    ami.getInstrumentationSourceUid(Binder.getCallingUid()) != Process.INVALID_UID;
-            boolean isCallerSystem = Binder.getCallingPid() == Process.myPid();
-            boolean isCallerPermissionController;
-            try {
-                isCallerPermissionController = pm.getPackageUidAsUser(
-                        mContext.getPackageManager().getPermissionControllerPackageName(), 0,
-                        UserHandle.getUserId(Binder.getCallingUid()))
-                        == Binder.getCallingUid();
-            } catch (PackageManager.NameNotFoundException doesNotHappen) {
-                return;
-            }
-
-            boolean doesCallerHavePermission = mContext.checkPermission(
-                    android.Manifest.permission.GET_HISTORICAL_APP_OPS_STATS,
-                    Binder.getCallingPid(), Binder.getCallingUid())
-                    == PackageManager.PERMISSION_GRANTED;
-
-            if (!isCallerSystem && !isCallerInstrumented && !isCallerPermissionController
-                    && !doesCallerHavePermission) {
-                mHandler.post(() -> callback.sendResult(new Bundle()));
-                return;
-            }
-
-            mContext.enforcePermission(android.Manifest.permission.GET_APP_OPS_STATS,
-                    Binder.getCallingPid(), Binder.getCallingUid(), "getHistoricalOps");
-        }
-
-        final String[] opNamesArray = (opNames != null)
-                ? opNames.toArray(new String[opNames.size()]) : null;
-
-        Set<String> attributionChainExemptPackages = null;
-        if ((dataType & HISTORY_FLAG_GET_ATTRIBUTION_CHAINS) != 0) {
-            attributionChainExemptPackages =
-                    PermissionManager.getIndicatorExemptedPackages(mContext);
-        }
-
-        final String[] chainExemptPkgArray = attributionChainExemptPackages != null
-                ? attributionChainExemptPackages.toArray(
-                new String[attributionChainExemptPackages.size()]) : null;
-
-        // Must not hold the appops lock
-        mHandler.post(PooledLambda.obtainRunnable(HistoricalRegistry::getHistoricalOps,
-                mHistoricalRegistry, uid, packageName, attributionTag, opNamesArray, dataType,
-                filter, beginTimeMillis, endTimeMillis, flags, chainExemptPkgArray,
-                callback).recycleOnUse());
-    }
-
-    @Override
-    public void getHistoricalOpsFromDiskRaw(int uid, String packageName, String attributionTag,
-            List<String> opNames, int dataType, int filter, long beginTimeMillis,
-            long endTimeMillis, int flags, RemoteCallback callback) {
-        ensureHistoricalOpRequestIsValid(uid, packageName, attributionTag, opNames, filter,
-                beginTimeMillis, endTimeMillis, flags);
-        Objects.requireNonNull(callback, "callback cannot be null");
-
-        mContext.enforcePermission(Manifest.permission.MANAGE_APPOPS,
-                Binder.getCallingPid(), Binder.getCallingUid(), "getHistoricalOps");
-
-        final String[] opNamesArray = (opNames != null)
-                ? opNames.toArray(new String[opNames.size()]) : null;
-
-        Set<String> attributionChainExemptPackages = null;
-        if ((dataType & HISTORY_FLAG_GET_ATTRIBUTION_CHAINS) != 0) {
-            attributionChainExemptPackages =
-                    PermissionManager.getIndicatorExemptedPackages(mContext);
-        }
-
-        final String[] chainExemptPkgArray = attributionChainExemptPackages != null
-                ? attributionChainExemptPackages.toArray(
-                new String[attributionChainExemptPackages.size()]) : null;
-
-        // Must not hold the appops lock
-        mHandler.post(PooledLambda.obtainRunnable(HistoricalRegistry::getHistoricalOpsFromDiskRaw,
-                mHistoricalRegistry, uid, packageName, attributionTag, opNamesArray, dataType,
-                filter, beginTimeMillis, endTimeMillis, flags, chainExemptPkgArray,
-                callback).recycleOnUse());
-    }
-
-    @Override
-    public void reloadNonHistoricalState() {
-        mContext.enforcePermission(Manifest.permission.MANAGE_APPOPS,
-                Binder.getCallingPid(), Binder.getCallingUid(), "reloadNonHistoricalState");
-        writeState();
-        readState();
-    }
-
-    @Override
-    public List<AppOpsManager.PackageOps> getUidOps(int uid, int[] ops) {
-        mContext.enforcePermission(android.Manifest.permission.GET_APP_OPS_STATS,
-                Binder.getCallingPid(), Binder.getCallingUid(), null);
-        synchronized (this) {
-            UidState uidState = getUidStateLocked(uid, false);
-            if (uidState == null) {
-                return null;
-            }
-            ArrayList<AppOpsManager.OpEntry> resOps = collectUidOps(uidState, ops);
-            if (resOps == null) {
-                return null;
-            }
-            ArrayList<AppOpsManager.PackageOps> res = new ArrayList<AppOpsManager.PackageOps>();
-            AppOpsManager.PackageOps resPackage = new AppOpsManager.PackageOps(
-                    null, uidState.uid, resOps);
-            res.add(resPackage);
-            return res;
-        }
-    }
-
-    private void pruneOpLocked(Op op, int uid, String packageName) {
-        op.removeAttributionsWithNoTime();
-
-        if (op.mAttributions.isEmpty()) {
-            Ops ops = getOpsLocked(uid, packageName, null, false, null, /* edit */ false);
-            if (ops != null) {
-                ops.remove(op.op);
-                op.setMode(AppOpsManager.opToDefaultMode(op.op));
-                if (ops.size() <= 0) {
-                    UidState uidState = ops.uidState;
-                    ArrayMap<String, Ops> pkgOps = uidState.pkgOps;
-                    if (pkgOps != null) {
-                        pkgOps.remove(ops.packageName);
-                        mAppOpsServiceInterface.removePackage(ops.packageName,
-                                UserHandle.getUserId(uidState.uid));
-                        if (pkgOps.isEmpty()) {
-                            uidState.pkgOps = null;
-                        }
-                        if (uidState.isDefault()) {
-                            uidState.clear();
-                            mUidStates.remove(uid);
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    @Override
-    public void enforceManageAppOpsModes(int callingPid, int callingUid, int targetUid) {
-        if (callingPid == Process.myPid()) {
-            return;
-        }
-        final int callingUser = UserHandle.getUserId(callingUid);
-        synchronized (this) {
-            if (mProfileOwners != null && mProfileOwners.get(callingUser, -1) == callingUid) {
-                if (targetUid >= 0 && callingUser == UserHandle.getUserId(targetUid)) {
-                    // Profile owners are allowed to change modes but only for apps
-                    // within their user.
-                    return;
-                }
-            }
-        }
-        mContext.enforcePermission(android.Manifest.permission.MANAGE_APP_OPS_MODES,
-                Binder.getCallingPid(), Binder.getCallingUid(), null);
-    }
-
-    @Override
-    public void setUidMode(int code, int uid, int mode,
-            @Nullable IAppOpsCallback permissionPolicyCallback) {
-        if (DEBUG) {
-            Slog.i(TAG, "uid " + uid + " OP_" + opToName(code) + " := " + modeToName(mode)
-                    + " by uid " + Binder.getCallingUid());
-        }
-
-        enforceManageAppOpsModes(Binder.getCallingPid(), Binder.getCallingUid(), uid);
-        verifyIncomingOp(code);
-        code = AppOpsManager.opToSwitch(code);
-
-        if (permissionPolicyCallback == null) {
-            updatePermissionRevokedCompat(uid, code, mode);
-        }
-
-        int previousMode;
-        synchronized (this) {
-            final int defaultMode = AppOpsManager.opToDefaultMode(code);
-
-            UidState uidState = getUidStateLocked(uid, false);
-            if (uidState == null) {
-                if (mode == defaultMode) {
-                    return;
-                }
-                uidState = new UidState(uid);
-                mUidStates.put(uid, uidState);
-            }
-            if (uidState.getUidMode(code) != AppOpsManager.opToDefaultMode(code)) {
-                previousMode = uidState.getUidMode(code);
-            } else {
-                // doesn't look right but is legacy behavior.
-                previousMode = MODE_DEFAULT;
-            }
-
-            if (!uidState.setUidMode(code, mode)) {
-                return;
-            }
-            uidState.evalForegroundOps();
-            if (mode != MODE_ERRORED && mode != previousMode) {
-                updateStartedOpModeForUidLocked(code, mode == MODE_IGNORED, uid);
-            }
-        }
-
-        notifyOpChangedForAllPkgsInUid(code, uid, false, permissionPolicyCallback);
-        notifyOpChangedSync(code, uid, null, mode, previousMode);
-    }
-
-    /**
-     * Notify that an op changed for all packages in an uid.
-     *
-     * @param code           The op that changed
-     * @param uid            The uid the op was changed for
-     * @param onlyForeground Only notify watchers that watch for foreground changes
-     */
-    private void notifyOpChangedForAllPkgsInUid(int code, int uid, boolean onlyForeground,
-            @Nullable IAppOpsCallback callbackToIgnore) {
-        ModeCallback listenerToIgnore = callbackToIgnore != null
-                ? mModeWatchers.get(callbackToIgnore.asBinder()) : null;
-        mAppOpsServiceInterface.notifyOpChangedForAllPkgsInUid(code, uid, onlyForeground,
-                listenerToIgnore);
-    }
-
-    private void updatePermissionRevokedCompat(int uid, int switchCode, int mode) {
-        PackageManager packageManager = mContext.getPackageManager();
-        if (packageManager == null) {
-            // This can only happen during early boot. At this time the permission state and appop
-            // state are in sync
-            return;
-        }
-
-        String[] packageNames = packageManager.getPackagesForUid(uid);
-        if (ArrayUtils.isEmpty(packageNames)) {
-            return;
-        }
-        String packageName = packageNames[0];
-
-        int[] ops = mSwitchedOps.get(switchCode);
-        for (int code : ops) {
-            String permissionName = AppOpsManager.opToPermission(code);
-            if (permissionName == null) {
-                continue;
-            }
-
-            if (packageManager.checkPermission(permissionName, packageName)
-                    != PackageManager.PERMISSION_GRANTED) {
-                continue;
-            }
-
-            PermissionInfo permissionInfo;
-            try {
-                permissionInfo = packageManager.getPermissionInfo(permissionName, 0);
-            } catch (PackageManager.NameNotFoundException e) {
-                e.printStackTrace();
-                continue;
-            }
-
-            if (!permissionInfo.isRuntime()) {
-                continue;
-            }
-
-            boolean supportsRuntimePermissions = getPackageManagerInternal()
-                    .getUidTargetSdkVersion(uid) >= Build.VERSION_CODES.M;
-
-            UserHandle user = UserHandle.getUserHandleForUid(uid);
-            boolean isRevokedCompat;
-            if (permissionInfo.backgroundPermission != null) {
-                if (packageManager.checkPermission(permissionInfo.backgroundPermission, packageName)
-                        == PackageManager.PERMISSION_GRANTED) {
-                    boolean isBackgroundRevokedCompat = mode != AppOpsManager.MODE_ALLOWED;
-
-                    if (isBackgroundRevokedCompat && supportsRuntimePermissions) {
-                        Slog.w(TAG, "setUidMode() called with a mode inconsistent with runtime"
-                                + " permission state, this is discouraged and you should revoke the"
-                                + " runtime permission instead: uid=" + uid + ", switchCode="
-                                + switchCode + ", mode=" + mode + ", permission="
-                                + permissionInfo.backgroundPermission);
-                    }
-
-                    final long identity = Binder.clearCallingIdentity();
-                    try {
-                        packageManager.updatePermissionFlags(permissionInfo.backgroundPermission,
-                                packageName, PackageManager.FLAG_PERMISSION_REVOKED_COMPAT,
-                                isBackgroundRevokedCompat
-                                        ? PackageManager.FLAG_PERMISSION_REVOKED_COMPAT : 0, user);
-                    } finally {
-                        Binder.restoreCallingIdentity(identity);
-                    }
-                }
-
-                isRevokedCompat = mode != AppOpsManager.MODE_ALLOWED
-                        && mode != AppOpsManager.MODE_FOREGROUND;
-            } else {
-                isRevokedCompat = mode != AppOpsManager.MODE_ALLOWED;
-            }
-
-            if (isRevokedCompat && supportsRuntimePermissions) {
-                Slog.w(TAG, "setUidMode() called with a mode inconsistent with runtime"
-                        + " permission state, this is discouraged and you should revoke the"
-                        + " runtime permission instead: uid=" + uid + ", switchCode="
-                        + switchCode + ", mode=" + mode + ", permission=" + permissionName);
-            }
-
-            final long identity = Binder.clearCallingIdentity();
-            try {
-                packageManager.updatePermissionFlags(permissionName, packageName,
-                        PackageManager.FLAG_PERMISSION_REVOKED_COMPAT, isRevokedCompat
-                                ? PackageManager.FLAG_PERMISSION_REVOKED_COMPAT : 0, user);
-            } finally {
-                Binder.restoreCallingIdentity(identity);
-            }
-        }
-    }
-
-    private void notifyOpChangedSync(int code, int uid, @NonNull String packageName, int mode,
-            int previousMode) {
-        final StorageManagerInternal storageManagerInternal =
-                LocalServices.getService(StorageManagerInternal.class);
-        if (storageManagerInternal != null) {
-            storageManagerInternal.onAppOpsChanged(code, uid, packageName, mode, previousMode);
-        }
-    }
-
-    @Override
-    public void setMode(int code, int uid, @NonNull String packageName, int mode,
-            @Nullable IAppOpsCallback permissionPolicyCallback) {
-        enforceManageAppOpsModes(Binder.getCallingPid(), Binder.getCallingUid(), uid);
-        verifyIncomingOp(code);
-        if (!isIncomingPackageValid(packageName, UserHandle.getUserId(uid))) {
-            return;
-        }
-
-        ArraySet<OnOpModeChangedListener> repCbs = null;
-        code = AppOpsManager.opToSwitch(code);
-
-        PackageVerificationResult pvr;
-        try {
-            pvr = verifyAndGetBypass(uid, packageName, null);
-        } catch (SecurityException e) {
-            Slog.e(TAG, "Cannot setMode", e);
-            return;
-        }
-
-        int previousMode = MODE_DEFAULT;
-        synchronized (this) {
-            UidState uidState = getUidStateLocked(uid, false);
-            Op op = getOpLocked(code, uid, packageName, null, false, pvr.bypass, /* edit */ true);
-            if (op != null) {
-                if (op.getMode() != mode) {
-                    previousMode = op.getMode();
-                    op.setMode(mode);
-
-                    if (uidState != null) {
-                        uidState.evalForegroundOps();
-                    }
-                    ArraySet<OnOpModeChangedListener> cbs =
-                            mAppOpsServiceInterface.getOpModeChangedListeners(code);
-                    if (cbs != null) {
-                        if (repCbs == null) {
-                            repCbs = new ArraySet<>();
-                        }
-                        repCbs.addAll(cbs);
-                    }
-                    cbs = mAppOpsServiceInterface.getPackageModeChangedListeners(packageName);
-                    if (cbs != null) {
-                        if (repCbs == null) {
-                            repCbs = new ArraySet<>();
-                        }
-                        repCbs.addAll(cbs);
-                    }
-                    if (repCbs != null && permissionPolicyCallback != null) {
-                        repCbs.remove(mModeWatchers.get(permissionPolicyCallback.asBinder()));
-                    }
-                    if (mode == AppOpsManager.opToDefaultMode(op.op)) {
-                        // If going into the default mode, prune this op
-                        // if there is nothing else interesting in it.
-                        pruneOpLocked(op, uid, packageName);
-                    }
-                    scheduleFastWriteLocked();
-                    if (mode != MODE_ERRORED) {
-                        updateStartedOpModeForUidLocked(code, mode == MODE_IGNORED, uid);
-                    }
-                }
-            }
-        }
-        if (repCbs != null) {
-            mHandler.sendMessage(PooledLambda.obtainMessage(
-                    AppOpsServiceImpl::notifyOpChanged,
-                    this, repCbs, code, uid, packageName));
-        }
-
-        notifyOpChangedSync(code, uid, packageName, mode, previousMode);
-    }
-
-    private void notifyOpChanged(ArraySet<OnOpModeChangedListener> callbacks, int code,
-            int uid, String packageName) {
-        for (int i = 0; i < callbacks.size(); i++) {
-            final OnOpModeChangedListener callback = callbacks.valueAt(i);
-            notifyOpChanged(callback, code, uid, packageName);
-        }
-    }
-
-    private void notifyOpChanged(OnOpModeChangedListener callback, int code,
-            int uid, String packageName) {
-        mAppOpsServiceInterface.notifyOpChanged(callback, code, uid, packageName);
-    }
-
-    private static ArrayList<ChangeRec> addChange(ArrayList<ChangeRec> reports,
-            int op, int uid, String packageName, int previousMode) {
-        boolean duplicate = false;
-        if (reports == null) {
-            reports = new ArrayList<>();
-        } else {
-            final int reportCount = reports.size();
-            for (int j = 0; j < reportCount; j++) {
-                ChangeRec report = reports.get(j);
-                if (report.op == op && report.pkg.equals(packageName)) {
-                    duplicate = true;
-                    break;
-                }
-            }
-        }
-        if (!duplicate) {
-            reports.add(new ChangeRec(op, uid, packageName, previousMode));
-        }
-
-        return reports;
-    }
-
-    private static HashMap<OnOpModeChangedListener, ArrayList<ChangeRec>> addCallbacks(
-            HashMap<OnOpModeChangedListener, ArrayList<ChangeRec>> callbacks,
-            int op, int uid, String packageName, int previousMode,
-            ArraySet<OnOpModeChangedListener> cbs) {
-        if (cbs == null) {
-            return callbacks;
-        }
-        if (callbacks == null) {
-            callbacks = new HashMap<>();
-        }
-        final int N = cbs.size();
-        for (int i=0; i<N; i++) {
-            OnOpModeChangedListener cb = cbs.valueAt(i);
-            ArrayList<ChangeRec> reports = callbacks.get(cb);
-            ArrayList<ChangeRec> changed = addChange(reports, op, uid, packageName, previousMode);
-            if (changed != reports) {
-                callbacks.put(cb, changed);
-            }
-        }
-        return callbacks;
-    }
-
-    static final class ChangeRec {
-        final int op;
-        final int uid;
-        final String pkg;
-        final int previous_mode;
-
-        ChangeRec(int _op, int _uid, String _pkg, int _previous_mode) {
-            op = _op;
-            uid = _uid;
-            pkg = _pkg;
-            previous_mode = _previous_mode;
-        }
-    }
-
-    @Override
-    public void resetAllModes(int reqUserId, String reqPackageName) {
-        final int callingPid = Binder.getCallingPid();
-        final int callingUid = Binder.getCallingUid();
-        reqUserId = ActivityManager.handleIncomingUser(callingPid, callingUid, reqUserId,
-                true, true, "resetAllModes", null);
-
-        int reqUid = -1;
-        if (reqPackageName != null) {
-            try {
-                reqUid = AppGlobals.getPackageManager().getPackageUid(
-                        reqPackageName, PackageManager.MATCH_UNINSTALLED_PACKAGES, reqUserId);
-            } catch (RemoteException e) {
-                /* ignore - local call */
-            }
-        }
-
-        enforceManageAppOpsModes(callingPid, callingUid, reqUid);
-
-        HashMap<OnOpModeChangedListener, ArrayList<ChangeRec>> callbacks = null;
-        ArrayList<ChangeRec> allChanges = new ArrayList<>();
-        synchronized (this) {
-            boolean changed = false;
-            for (int i = mUidStates.size() - 1; i >= 0; i--) {
-                UidState uidState = mUidStates.valueAt(i);
-
-                SparseIntArray opModes = uidState.getNonDefaultUidModes();
-                if (opModes != null && (uidState.uid == reqUid || reqUid == -1)) {
-                    final int uidOpCount = opModes.size();
-                    for (int j = uidOpCount - 1; j >= 0; j--) {
-                        final int code = opModes.keyAt(j);
-                        if (AppOpsManager.opAllowsReset(code)) {
-                            int previousMode = opModes.valueAt(j);
-                            uidState.setUidMode(code, AppOpsManager.opToDefaultMode(code));
-                            for (String packageName : getPackagesForUid(uidState.uid)) {
-                                callbacks = addCallbacks(callbacks, code, uidState.uid,
-                                        packageName, previousMode,
-                                        mAppOpsServiceInterface.getOpModeChangedListeners(code));
-                                callbacks = addCallbacks(callbacks, code, uidState.uid,
-                                        packageName, previousMode, mAppOpsServiceInterface
-                                                .getPackageModeChangedListeners(packageName));
-
-                                allChanges = addChange(allChanges, code, uidState.uid,
-                                        packageName, previousMode);
-                            }
-                        }
-                    }
-                }
-
-                if (uidState.pkgOps == null) {
-                    continue;
-                }
-
-                if (reqUserId != UserHandle.USER_ALL
-                        && reqUserId != UserHandle.getUserId(uidState.uid)) {
-                    // Skip any ops for a different user
-                    continue;
-                }
-
-                Map<String, Ops> packages = uidState.pkgOps;
-                Iterator<Map.Entry<String, Ops>> it = packages.entrySet().iterator();
-                boolean uidChanged = false;
-                while (it.hasNext()) {
-                    Map.Entry<String, Ops> ent = it.next();
-                    String packageName = ent.getKey();
-                    if (reqPackageName != null && !reqPackageName.equals(packageName)) {
-                        // Skip any ops for a different package
-                        continue;
-                    }
-                    Ops pkgOps = ent.getValue();
-                    for (int j=pkgOps.size()-1; j>=0; j--) {
-                        Op curOp = pkgOps.valueAt(j);
-                        if (shouldDeferResetOpToDpm(curOp.op)) {
-                            deferResetOpToDpm(curOp.op, reqPackageName, reqUserId);
-                            continue;
-                        }
-                        if (AppOpsManager.opAllowsReset(curOp.op)
-                                && curOp.getMode() != AppOpsManager.opToDefaultMode(curOp.op)) {
-                            int previousMode = curOp.getMode();
-                            curOp.setMode(AppOpsManager.opToDefaultMode(curOp.op));
-                            changed = true;
-                            uidChanged = true;
-                            final int uid = curOp.uidState.uid;
-                            callbacks = addCallbacks(callbacks, curOp.op, uid, packageName,
-                                    previousMode,
-                                    mAppOpsServiceInterface.getOpModeChangedListeners(curOp.op));
-                            callbacks = addCallbacks(callbacks, curOp.op, uid, packageName,
-                                    previousMode, mAppOpsServiceInterface
-                                            .getPackageModeChangedListeners(packageName));
-
-                            allChanges = addChange(allChanges, curOp.op, uid, packageName,
-                                    previousMode);
-                            curOp.removeAttributionsWithNoTime();
-                            if (curOp.mAttributions.isEmpty()) {
-                                pkgOps.removeAt(j);
-                            }
-                        }
-                    }
-                    if (pkgOps.size() == 0) {
-                        it.remove();
-                        mAppOpsServiceInterface.removePackage(packageName,
-                                UserHandle.getUserId(uidState.uid));
-                    }
-                }
-                if (uidState.isDefault()) {
-                    uidState.clear();
-                    mUidStates.remove(uidState.uid);
-                }
-                if (uidChanged) {
-                    uidState.evalForegroundOps();
-                }
-            }
-
-            if (changed) {
-                scheduleFastWriteLocked();
-            }
-        }
-        if (callbacks != null) {
-            for (Map.Entry<OnOpModeChangedListener, ArrayList<ChangeRec>> ent
-                    : callbacks.entrySet()) {
-                OnOpModeChangedListener cb = ent.getKey();
-                ArrayList<ChangeRec> reports = ent.getValue();
-                for (int i=0; i<reports.size(); i++) {
-                    ChangeRec rep = reports.get(i);
-                    mHandler.sendMessage(PooledLambda.obtainMessage(
-                            AppOpsServiceImpl::notifyOpChanged,
-                            this, cb, rep.op, rep.uid, rep.pkg));
-                }
-            }
-        }
-
-        int numChanges = allChanges.size();
-        for (int i = 0; i < numChanges; i++) {
-            ChangeRec change = allChanges.get(i);
-            notifyOpChangedSync(change.op, change.uid, change.pkg,
-                    AppOpsManager.opToDefaultMode(change.op), change.previous_mode);
-        }
-    }
-
-    private boolean shouldDeferResetOpToDpm(int op) {
-        // TODO(b/174582385): avoid special-casing app-op resets by migrating app-op permission
-        //  pre-grants to a role-based mechanism or another general-purpose mechanism.
-        return dpmi != null && dpmi.supportsResetOp(op);
-    }
-
-    /** Assumes {@link #shouldDeferResetOpToDpm(int)} is true. */
-    private void deferResetOpToDpm(int op, String packageName, @UserIdInt int userId) {
-        // TODO(b/174582385): avoid special-casing app-op resets by migrating app-op permission
-        //  pre-grants to a role-based mechanism or another general-purpose mechanism.
-        dpmi.resetOp(op, packageName, userId);
-    }
-
-    private void evalAllForegroundOpsLocked() {
-        for (int uidi = mUidStates.size() - 1; uidi >= 0; uidi--) {
-            final UidState uidState = mUidStates.valueAt(uidi);
-            if (uidState.foregroundOps != null) {
-                uidState.evalForegroundOps();
-            }
-        }
-    }
-
-    @Override
-    public void startWatchingModeWithFlags(int op, String packageName, int flags,
-            IAppOpsCallback callback) {
-        int watchedUid = -1;
-        final int callingUid = Binder.getCallingUid();
-        final int callingPid = Binder.getCallingPid();
-        // TODO: should have a privileged permission to protect this.
-        // Also, if the caller has requested WATCH_FOREGROUND_CHANGES, should we require
-        // the USAGE_STATS permission since this can provide information about when an
-        // app is in the foreground?
-        Preconditions.checkArgumentInRange(op, AppOpsManager.OP_NONE,
-                AppOpsManager._NUM_OP - 1, "Invalid op code: " + op);
-        if (callback == null) {
-            return;
-        }
-        final boolean mayWatchPackageName = packageName != null
-                && !filterAppAccessUnlocked(packageName, UserHandle.getUserId(callingUid));
-        synchronized (this) {
-            int switchOp = (op != AppOpsManager.OP_NONE) ? AppOpsManager.opToSwitch(op) : op;
-
-            int notifiedOps;
-            if ((flags & CALL_BACK_ON_SWITCHED_OP) == 0) {
-                if (op == OP_NONE) {
-                    notifiedOps = ALL_OPS;
-                } else {
-                    notifiedOps = op;
-                }
-            } else {
-                notifiedOps = switchOp;
-            }
-
-            ModeCallback cb = mModeWatchers.get(callback.asBinder());
-            if (cb == null) {
-                cb = new ModeCallback(callback, watchedUid, flags, notifiedOps, callingUid,
-                        callingPid);
-                mModeWatchers.put(callback.asBinder(), cb);
-            }
-            if (switchOp != AppOpsManager.OP_NONE) {
-                mAppOpsServiceInterface.startWatchingOpModeChanged(cb, switchOp);
-            }
-            if (mayWatchPackageName) {
-                mAppOpsServiceInterface.startWatchingPackageModeChanged(cb, packageName);
-            }
-            evalAllForegroundOpsLocked();
-        }
-    }
-
-    @Override
-    public void stopWatchingMode(IAppOpsCallback callback) {
-        if (callback == null) {
-            return;
-        }
-        synchronized (this) {
-            ModeCallback cb = mModeWatchers.remove(callback.asBinder());
-            if (cb != null) {
-                cb.unlinkToDeath();
-                mAppOpsServiceInterface.removeListener(cb);
-            }
-
-            evalAllForegroundOpsLocked();
-        }
-    }
-
-    @Override
-    public int checkOperation(int code, int uid, String packageName,
-            @Nullable String attributionTag, boolean raw) {
-        verifyIncomingOp(code);
-        if (!isIncomingPackageValid(packageName, UserHandle.getUserId(uid))) {
-            return AppOpsManager.opToDefaultMode(code);
-        }
-
-        String resolvedPackageName = AppOpsManager.resolvePackageName(uid, packageName);
-        if (resolvedPackageName == null) {
-            return AppOpsManager.MODE_IGNORED;
-        }
-        return checkOperationUnchecked(code, uid, resolvedPackageName, attributionTag, raw);
-    }
-
-    /**
-     * Get the mode of an app-op.
-     *
-     * @param code        The code of the op
-     * @param uid         The uid of the package the op belongs to
-     * @param packageName The package the op belongs to
-     * @param raw         If the raw state of eval-ed state should be checked.
-     * @return The mode of the op
-     */
-    private @Mode int checkOperationUnchecked(int code, int uid, @NonNull String packageName,
-            @Nullable String attributionTag, boolean raw) {
-        PackageVerificationResult pvr;
-        try {
-            pvr = verifyAndGetBypass(uid, packageName, null);
-        } catch (SecurityException e) {
-            Slog.e(TAG, "checkOperation", e);
-            return AppOpsManager.opToDefaultMode(code);
-        }
-
-        if (isOpRestrictedDueToSuspend(code, packageName, uid)) {
-            return AppOpsManager.MODE_IGNORED;
-        }
-        synchronized (this) {
-            if (isOpRestrictedLocked(uid, code, packageName, attributionTag, pvr.bypass, true)) {
-                return AppOpsManager.MODE_IGNORED;
-            }
-            code = AppOpsManager.opToSwitch(code);
-            UidState uidState = getUidStateLocked(uid, false);
-            if (uidState != null
-                    && uidState.getUidMode(code) != AppOpsManager.opToDefaultMode(code)) {
-                final int rawMode = uidState.getUidMode(code);
-                return raw ? rawMode : uidState.evalMode(code, rawMode);
-            }
-            Op op = getOpLocked(code, uid, packageName, null, false, pvr.bypass, /* edit */ false);
-            if (op == null) {
-                return AppOpsManager.opToDefaultMode(code);
-            }
-            return raw ? op.getMode() : op.uidState.evalMode(op.op, op.getMode());
-        }
-    }
-
-    @Override
-    public int checkPackage(int uid, String packageName) {
-        Objects.requireNonNull(packageName);
-        try {
-            verifyAndGetBypass(uid, packageName, null);
-            // When the caller is the system, it's possible that the packageName is the special
-            // one (e.g., "root") which isn't actually existed.
-            if (resolveUid(packageName) == uid
-                    || (isPackageExisted(packageName)
-                            && !filterAppAccessUnlocked(packageName, UserHandle.getUserId(uid)))) {
-                return AppOpsManager.MODE_ALLOWED;
-            }
-            return AppOpsManager.MODE_ERRORED;
-        } catch (SecurityException ignored) {
-            return AppOpsManager.MODE_ERRORED;
-        }
-    }
-
-    private boolean isPackageExisted(String packageName) {
-        return getPackageManagerInternal().getPackageStateInternal(packageName) != null;
-    }
-
-    /**
-     * This method will check with PackageManager to determine if the package provided should
-     * be visible to the {@link Binder#getCallingUid()}.
-     *
-     * NOTE: This must not be called while synchronized on {@code this} to avoid dead locks
-     */
-    private boolean filterAppAccessUnlocked(String packageName, int userId) {
-        final int callingUid = Binder.getCallingUid();
-        return LocalServices.getService(PackageManagerInternal.class)
-                .filterAppAccess(packageName, callingUid, userId);
-    }
-
-    @Override
-    public int noteOperation(int code, int uid, @Nullable String packageName,
-            @Nullable String attributionTag, @Nullable String message) {
-        verifyIncomingUid(uid);
-        verifyIncomingOp(code);
-        if (!isIncomingPackageValid(packageName, UserHandle.getUserId(uid))) {
-            return AppOpsManager.MODE_ERRORED;
-        }
-
-        String resolvedPackageName = AppOpsManager.resolvePackageName(uid, packageName);
-        if (resolvedPackageName == null) {
-            return AppOpsManager.MODE_IGNORED;
-        }
-        return noteOperationUnchecked(code, uid, resolvedPackageName, attributionTag,
-                Process.INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF);
-    }
-
-    @Override
-    public int noteOperationUnchecked(int code, int uid, @NonNull String packageName,
-            @Nullable String attributionTag, int proxyUid, String proxyPackageName,
-            @Nullable String proxyAttributionTag, @OpFlags int flags) {
-        PackageVerificationResult pvr;
-        try {
-            pvr = verifyAndGetBypass(uid, packageName, attributionTag, proxyPackageName);
-            if (!pvr.isAttributionTagValid) {
-                attributionTag = null;
-            }
-        } catch (SecurityException e) {
-            Slog.e(TAG, "noteOperation", e);
-            return AppOpsManager.MODE_ERRORED;
-        }
-
-        synchronized (this) {
-            final Ops ops = getOpsLocked(uid, packageName, attributionTag,
-                    pvr.isAttributionTagValid, pvr.bypass, /* edit */ true);
-            if (ops == null) {
-                scheduleOpNotedIfNeededLocked(code, uid, packageName, attributionTag, flags,
-                        AppOpsManager.MODE_IGNORED);
-                if (DEBUG) {
-                    Slog.d(TAG, "noteOperation: no op for code " + code + " uid " + uid
-                            + " package " + packageName + "flags: "
-                            + AppOpsManager.flagsToString(flags));
-                }
-                return AppOpsManager.MODE_ERRORED;
-            }
-            final Op op = getOpLocked(ops, code, uid, true);
-            final AttributedOp attributedOp = op.getOrCreateAttribution(op, attributionTag);
-            if (attributedOp.isRunning()) {
-                Slog.w(TAG, "Noting op not finished: uid " + uid + " pkg " + packageName + " code "
-                        + code + " startTime of in progress event="
-                        + attributedOp.mInProgressEvents.valueAt(0).getStartTime());
-            }
-
-            final int switchCode = AppOpsManager.opToSwitch(code);
-            final UidState uidState = ops.uidState;
-            if (isOpRestrictedLocked(uid, code, packageName, attributionTag, pvr.bypass, false)) {
-                attributedOp.rejected(uidState.getState(), flags);
-                scheduleOpNotedIfNeededLocked(code, uid, packageName, attributionTag, flags,
-                        AppOpsManager.MODE_IGNORED);
-                return AppOpsManager.MODE_IGNORED;
-            }
-            // If there is a non-default per UID policy (we set UID op mode only if
-            // non-default) it takes over, otherwise use the per package policy.
-            if (uidState.getUidMode(switchCode) != AppOpsManager.opToDefaultMode(switchCode)) {
-                final int uidMode = uidState.evalMode(code, uidState.getUidMode(switchCode));
-                if (uidMode != AppOpsManager.MODE_ALLOWED) {
-                    if (DEBUG) {
-                        Slog.d(TAG, "noteOperation: uid reject #" + uidMode + " for code "
-                                + switchCode + " (" + code + ") uid " + uid + " package "
-                                + packageName + " flags: " + AppOpsManager.flagsToString(flags));
-                    }
-                    attributedOp.rejected(uidState.getState(), flags);
-                    scheduleOpNotedIfNeededLocked(code, uid, packageName, attributionTag, flags,
-                            uidMode);
-                    return uidMode;
-                }
-            } else {
-                final Op switchOp = switchCode != code ? getOpLocked(ops, switchCode, uid, true)
-                        : op;
-                final int mode = switchOp.uidState.evalMode(switchOp.op, switchOp.getMode());
-                if (mode != AppOpsManager.MODE_ALLOWED) {
-                    if (DEBUG) {
-                        Slog.d(TAG, "noteOperation: reject #" + mode + " for code "
-                                + switchCode + " (" + code + ") uid " + uid + " package "
-                                + packageName + " flags: " + AppOpsManager.flagsToString(flags));
-                    }
-                    attributedOp.rejected(uidState.getState(), flags);
-                    scheduleOpNotedIfNeededLocked(code, uid, packageName, attributionTag, flags,
-                            mode);
-                    return mode;
-                }
-            }
-            if (DEBUG) {
-                Slog.d(TAG,
-                        "noteOperation: allowing code " + code + " uid " + uid + " package "
-                                + packageName + (attributionTag == null ? ""
-                                : "." + attributionTag) + " flags: "
-                                + AppOpsManager.flagsToString(flags));
-            }
-            scheduleOpNotedIfNeededLocked(code, uid, packageName, attributionTag, flags,
-                    AppOpsManager.MODE_ALLOWED);
-            attributedOp.accessed(proxyUid, proxyPackageName, proxyAttributionTag,
-                    uidState.getState(),
-                    flags);
-
-            return AppOpsManager.MODE_ALLOWED;
-        }
-    }
-
-    @Override
-    public boolean isAttributionTagValid(int uid, @NonNull String packageName,
-            @Nullable String attributionTag,
-            @Nullable String proxyPackageName) {
-        try {
-            return verifyAndGetBypass(uid, packageName, attributionTag, proxyPackageName)
-                    .isAttributionTagValid;
-        } catch (SecurityException ignored) {
-            // We don't want to throw, this exception will be handled in the (c/n/s)Operation calls
-            // when they need the bypass object.
-            return false;
-        }
-    }
-
-    // TODO moltmann: Allow watching for attribution ops
-    @Override
-    public void startWatchingActive(int[] ops, IAppOpsActiveCallback callback) {
-        int watchedUid = Process.INVALID_UID;
-        final int callingUid = Binder.getCallingUid();
-        final int callingPid = Binder.getCallingPid();
-        if (mContext.checkCallingOrSelfPermission(Manifest.permission.WATCH_APPOPS)
-                != PackageManager.PERMISSION_GRANTED) {
-            watchedUid = callingUid;
-        }
-        if (ops != null) {
-            Preconditions.checkArrayElementsInRange(ops, 0,
-                    AppOpsManager._NUM_OP - 1, "Invalid op code in: " + Arrays.toString(ops));
-        }
-        if (callback == null) {
-            return;
-        }
-        synchronized (this) {
-            SparseArray<ActiveCallback> callbacks = mActiveWatchers.get(callback.asBinder());
-            if (callbacks == null) {
-                callbacks = new SparseArray<>();
-                mActiveWatchers.put(callback.asBinder(), callbacks);
-            }
-            final ActiveCallback activeCallback = new ActiveCallback(callback, watchedUid,
-                    callingUid, callingPid);
-            for (int op : ops) {
-                callbacks.put(op, activeCallback);
-            }
-        }
-    }
-
-    @Override
-    public void stopWatchingActive(IAppOpsActiveCallback callback) {
-        if (callback == null) {
-            return;
-        }
-        synchronized (this) {
-            final SparseArray<ActiveCallback> activeCallbacks =
-                    mActiveWatchers.remove(callback.asBinder());
-            if (activeCallbacks == null) {
-                return;
-            }
-            final int callbackCount = activeCallbacks.size();
-            for (int i = 0; i < callbackCount; i++) {
-                activeCallbacks.valueAt(i).destroy();
-            }
-        }
-    }
-
-    @Override
-    public void startWatchingStarted(int[] ops, @NonNull IAppOpsStartedCallback callback) {
-        int watchedUid = Process.INVALID_UID;
-        final int callingUid = Binder.getCallingUid();
-        final int callingPid = Binder.getCallingPid();
-        if (mContext.checkCallingOrSelfPermission(Manifest.permission.WATCH_APPOPS)
-                != PackageManager.PERMISSION_GRANTED) {
-            watchedUid = callingUid;
-        }
-
-        Preconditions.checkArgument(!ArrayUtils.isEmpty(ops), "Ops cannot be null or empty");
-        Preconditions.checkArrayElementsInRange(ops, 0, AppOpsManager._NUM_OP - 1,
-                "Invalid op code in: " + Arrays.toString(ops));
-        Objects.requireNonNull(callback, "Callback cannot be null");
-
-        synchronized (this) {
-            SparseArray<StartedCallback> callbacks = mStartedWatchers.get(callback.asBinder());
-            if (callbacks == null) {
-                callbacks = new SparseArray<>();
-                mStartedWatchers.put(callback.asBinder(), callbacks);
-            }
-
-            final StartedCallback startedCallback = new StartedCallback(callback, watchedUid,
-                    callingUid, callingPid);
-            for (int op : ops) {
-                callbacks.put(op, startedCallback);
-            }
-        }
-    }
-
-    @Override
-    public void stopWatchingStarted(IAppOpsStartedCallback callback) {
-        Objects.requireNonNull(callback, "Callback cannot be null");
-
-        synchronized (this) {
-            final SparseArray<StartedCallback> startedCallbacks =
-                    mStartedWatchers.remove(callback.asBinder());
-            if (startedCallbacks == null) {
-                return;
-            }
-
-            final int callbackCount = startedCallbacks.size();
-            for (int i = 0; i < callbackCount; i++) {
-                startedCallbacks.valueAt(i).destroy();
-            }
-        }
-    }
-
-    @Override
-    public void startWatchingNoted(@NonNull int[] ops, @NonNull IAppOpsNotedCallback callback) {
-        int watchedUid = Process.INVALID_UID;
-        final int callingUid = Binder.getCallingUid();
-        final int callingPid = Binder.getCallingPid();
-        if (mContext.checkCallingOrSelfPermission(Manifest.permission.WATCH_APPOPS)
-                != PackageManager.PERMISSION_GRANTED) {
-            watchedUid = callingUid;
-        }
-        Preconditions.checkArgument(!ArrayUtils.isEmpty(ops), "Ops cannot be null or empty");
-        Preconditions.checkArrayElementsInRange(ops, 0, AppOpsManager._NUM_OP - 1,
-                "Invalid op code in: " + Arrays.toString(ops));
-        Objects.requireNonNull(callback, "Callback cannot be null");
-        synchronized (this) {
-            SparseArray<NotedCallback> callbacks = mNotedWatchers.get(callback.asBinder());
-            if (callbacks == null) {
-                callbacks = new SparseArray<>();
-                mNotedWatchers.put(callback.asBinder(), callbacks);
-            }
-            final NotedCallback notedCallback = new NotedCallback(callback, watchedUid,
-                    callingUid, callingPid);
-            for (int op : ops) {
-                callbacks.put(op, notedCallback);
-            }
-        }
-    }
-
-    @Override
-    public void stopWatchingNoted(IAppOpsNotedCallback callback) {
-        Objects.requireNonNull(callback, "Callback cannot be null");
-        synchronized (this) {
-            final SparseArray<NotedCallback> notedCallbacks =
-                    mNotedWatchers.remove(callback.asBinder());
-            if (notedCallbacks == null) {
-                return;
-            }
-            final int callbackCount = notedCallbacks.size();
-            for (int i = 0; i < callbackCount; i++) {
-                notedCallbacks.valueAt(i).destroy();
-            }
-        }
-    }
-
-    @Override
-    public int startOperation(@NonNull IBinder clientId, int code, int uid,
-            @Nullable String packageName, @Nullable String attributionTag,
-            boolean startIfModeDefault, @NonNull String message,
-            @AttributionFlags int attributionFlags, int attributionChainId) {
-        verifyIncomingUid(uid);
-        verifyIncomingOp(code);
-        if (!isIncomingPackageValid(packageName, UserHandle.getUserId(uid))) {
-            return AppOpsManager.MODE_ERRORED;
-        }
-
-        String resolvedPackageName = AppOpsManager.resolvePackageName(uid, packageName);
-        if (resolvedPackageName == null) {
-            return AppOpsManager.MODE_IGNORED;
-        }
-
-        // As a special case for OP_RECORD_AUDIO_HOTWORD, which we use only for attribution
-        // purposes and not as a check, also make sure that the caller is allowed to access
-        // the data gated by OP_RECORD_AUDIO.
-        //
-        // TODO: Revert this change before Android 12.
-        if (code == OP_RECORD_AUDIO_HOTWORD || code == OP_RECEIVE_AMBIENT_TRIGGER_AUDIO) {
-            int result = checkOperation(OP_RECORD_AUDIO, uid, packageName, null, false);
-            if (result != AppOpsManager.MODE_ALLOWED) {
-                return result;
-            }
-        }
-        return startOperationUnchecked(clientId, code, uid, packageName, attributionTag,
-                Process.INVALID_UID, null, null, OP_FLAG_SELF, startIfModeDefault,
-                attributionFlags, attributionChainId, /*dryRun*/ false);
-    }
-
-    private boolean shouldStartForMode(int mode, boolean startIfModeDefault) {
-        return (mode == MODE_ALLOWED || (mode == MODE_DEFAULT && startIfModeDefault));
-    }
-
-    @Override
-    public int startOperationUnchecked(IBinder clientId, int code, int uid,
-            @NonNull String packageName, @Nullable String attributionTag, int proxyUid,
-            String proxyPackageName, @Nullable String proxyAttributionTag, @OpFlags int flags,
-            boolean startIfModeDefault, @AttributionFlags int attributionFlags,
-            int attributionChainId, boolean dryRun) {
-        PackageVerificationResult pvr;
-        try {
-            pvr = verifyAndGetBypass(uid, packageName, attributionTag, proxyPackageName);
-            if (!pvr.isAttributionTagValid) {
-                attributionTag = null;
-            }
-        } catch (SecurityException e) {
-            Slog.e(TAG, "startOperation", e);
-            return AppOpsManager.MODE_ERRORED;
-        }
-
-        boolean isRestricted;
-        int startType = START_TYPE_FAILED;
-        synchronized (this) {
-            final Ops ops = getOpsLocked(uid, packageName, attributionTag,
-                    pvr.isAttributionTagValid, pvr.bypass, /* edit */ true);
-            if (ops == null) {
-                if (!dryRun) {
-                    scheduleOpStartedIfNeededLocked(code, uid, packageName, attributionTag,
-                            flags, AppOpsManager.MODE_IGNORED, startType, attributionFlags,
-                            attributionChainId);
-                }
-                if (DEBUG) {
-                    Slog.d(TAG, "startOperation: no op for code " + code + " uid " + uid
-                            + " package " + packageName + " flags: "
-                            + AppOpsManager.flagsToString(flags));
-                }
-                return AppOpsManager.MODE_ERRORED;
-            }
-            final Op op = getOpLocked(ops, code, uid, true);
-            final AttributedOp attributedOp = op.getOrCreateAttribution(op, attributionTag);
-            final UidState uidState = ops.uidState;
-            isRestricted = isOpRestrictedLocked(uid, code, packageName, attributionTag, pvr.bypass,
-                    false);
-            final int switchCode = AppOpsManager.opToSwitch(code);
-            // If there is a non-default per UID policy (we set UID op mode only if
-            // non-default) it takes over, otherwise use the per package policy.
-            if (uidState.getUidMode(switchCode) != AppOpsManager.opToDefaultMode(switchCode)) {
-                final int uidMode = uidState.evalMode(code, uidState.getUidMode(switchCode));
-                if (!shouldStartForMode(uidMode, startIfModeDefault)) {
-                    if (DEBUG) {
-                        Slog.d(TAG, "startOperation: uid reject #" + uidMode + " for code "
-                                + switchCode + " (" + code + ") uid " + uid + " package "
-                                + packageName + " flags: " + AppOpsManager.flagsToString(flags));
-                    }
-                    if (!dryRun) {
-                        attributedOp.rejected(uidState.getState(), flags);
-                        scheduleOpStartedIfNeededLocked(code, uid, packageName, attributionTag,
-                                flags, uidMode, startType, attributionFlags, attributionChainId);
-                    }
-                    return uidMode;
-                }
-            } else {
-                final Op switchOp = switchCode != code ? getOpLocked(ops, switchCode, uid, true)
-                        : op;
-                final int mode = switchOp.uidState.evalMode(switchOp.op, switchOp.getMode());
-                if (!shouldStartForMode(mode, startIfModeDefault)) {
-                    if (DEBUG) {
-                        Slog.d(TAG, "startOperation: reject #" + mode + " for code "
-                                + switchCode + " (" + code + ") uid " + uid + " package "
-                                + packageName + " flags: " + AppOpsManager.flagsToString(flags));
-                    }
-                    if (!dryRun) {
-                        attributedOp.rejected(uidState.getState(), flags);
-                        scheduleOpStartedIfNeededLocked(code, uid, packageName, attributionTag,
-                                flags, mode, startType, attributionFlags, attributionChainId);
-                    }
-                    return mode;
-                }
-            }
-            if (DEBUG) {
-                Slog.d(TAG, "startOperation: allowing code " + code + " uid " + uid
-                        + " package " + packageName + " restricted: " + isRestricted
-                        + " flags: " + AppOpsManager.flagsToString(flags));
-            }
-            if (!dryRun) {
-                try {
-                    if (isRestricted) {
-                        attributedOp.createPaused(clientId, proxyUid, proxyPackageName,
-                                proxyAttributionTag, uidState.getState(), flags,
-                                attributionFlags, attributionChainId);
-                    } else {
-                        attributedOp.started(clientId, proxyUid, proxyPackageName,
-                                proxyAttributionTag, uidState.getState(), flags,
-                                attributionFlags, attributionChainId);
-                        startType = START_TYPE_STARTED;
-                    }
-                } catch (RemoteException e) {
-                    throw new RuntimeException(e);
-                }
-                scheduleOpStartedIfNeededLocked(code, uid, packageName, attributionTag, flags,
-                        isRestricted ? MODE_IGNORED : MODE_ALLOWED, startType, attributionFlags,
-                        attributionChainId);
-            }
-        }
-
-        // Possible bug? The raw mode could have been MODE_DEFAULT to reach here.
-        return isRestricted ? MODE_IGNORED : MODE_ALLOWED;
-    }
-
-    @Override
-    public void finishOperation(IBinder clientId, int code, int uid, String packageName,
-            String attributionTag) {
-        verifyIncomingUid(uid);
-        verifyIncomingOp(code);
-        if (!isIncomingPackageValid(packageName, UserHandle.getUserId(uid))) {
-            return;
-        }
-
-        String resolvedPackageName = AppOpsManager.resolvePackageName(uid, packageName);
-        if (resolvedPackageName == null) {
-            return;
-        }
-
-        finishOperationUnchecked(clientId, code, uid, resolvedPackageName, attributionTag);
-    }
-
-    @Override
-    public void finishOperationUnchecked(IBinder clientId, int code, int uid, String packageName,
-            String attributionTag) {
-        PackageVerificationResult pvr;
-        try {
-            pvr = verifyAndGetBypass(uid, packageName, attributionTag);
-            if (!pvr.isAttributionTagValid) {
-                attributionTag = null;
-            }
-        } catch (SecurityException e) {
-            Slog.e(TAG, "Cannot finishOperation", e);
-            return;
-        }
-
-        synchronized (this) {
-            Op op = getOpLocked(code, uid, packageName, attributionTag, pvr.isAttributionTagValid,
-                    pvr.bypass, /* edit */ true);
-            if (op == null) {
-                Slog.e(TAG, "Operation not found: uid=" + uid + " pkg=" + packageName + "("
-                        + attributionTag + ") op=" + AppOpsManager.opToName(code));
-                return;
-            }
-            final AttributedOp attributedOp = op.mAttributions.get(attributionTag);
-            if (attributedOp == null) {
-                Slog.e(TAG, "Attribution not found: uid=" + uid + " pkg=" + packageName + "("
-                        + attributionTag + ") op=" + AppOpsManager.opToName(code));
-                return;
-            }
-
-            if (attributedOp.isRunning() || attributedOp.isPaused()) {
-                attributedOp.finished(clientId);
-            } else {
-                Slog.e(TAG, "Operation not started: uid=" + uid + " pkg=" + packageName + "("
-                        + attributionTag + ") op=" + AppOpsManager.opToName(code));
-            }
-        }
-    }
-
-    void scheduleOpActiveChangedIfNeededLocked(int code, int uid, @NonNull String packageName,
-            @Nullable String attributionTag, boolean active,
-            @AttributionFlags int attributionFlags, int attributionChainId) {
-        ArraySet<ActiveCallback> dispatchedCallbacks = null;
-        final int callbackListCount = mActiveWatchers.size();
-        for (int i = 0; i < callbackListCount; i++) {
-            final SparseArray<ActiveCallback> callbacks = mActiveWatchers.valueAt(i);
-            ActiveCallback callback = callbacks.get(code);
-            if (callback != null) {
-                if (callback.mWatchingUid >= 0 && callback.mWatchingUid != uid) {
-                    continue;
-                }
-                if (dispatchedCallbacks == null) {
-                    dispatchedCallbacks = new ArraySet<>();
-                }
-                dispatchedCallbacks.add(callback);
-            }
-        }
-        if (dispatchedCallbacks == null) {
-            return;
-        }
-        mHandler.sendMessage(PooledLambda.obtainMessage(
-                AppOpsServiceImpl::notifyOpActiveChanged,
-                this, dispatchedCallbacks, code, uid, packageName, attributionTag, active,
-                attributionFlags, attributionChainId));
-    }
-
-    private void notifyOpActiveChanged(ArraySet<ActiveCallback> callbacks,
-            int code, int uid, @NonNull String packageName, @Nullable String attributionTag,
-            boolean active, @AttributionFlags int attributionFlags, int attributionChainId) {
-        // There are features watching for mode changes such as window manager
-        // and location manager which are in our process. The callbacks in these
-        // features may require permissions our remote caller does not have.
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            final int callbackCount = callbacks.size();
-            for (int i = 0; i < callbackCount; i++) {
-                final ActiveCallback callback = callbacks.valueAt(i);
-                try {
-                    if (shouldIgnoreCallback(code, callback.mCallingPid, callback.mCallingUid)) {
-                        continue;
-                    }
-                    callback.mCallback.opActiveChanged(code, uid, packageName, attributionTag,
-                            active, attributionFlags, attributionChainId);
-                } catch (RemoteException e) {
-                    /* do nothing */
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    void scheduleOpStartedIfNeededLocked(int code, int uid, String pkgName,
-            String attributionTag, @OpFlags int flags, @Mode int result,
-            @AppOpsManager.OnOpStartedListener.StartedType int startedType,
-            @AttributionFlags int attributionFlags, int attributionChainId) {
-        ArraySet<StartedCallback> dispatchedCallbacks = null;
-        final int callbackListCount = mStartedWatchers.size();
-        for (int i = 0; i < callbackListCount; i++) {
-            final SparseArray<StartedCallback> callbacks = mStartedWatchers.valueAt(i);
-
-            StartedCallback callback = callbacks.get(code);
-            if (callback != null) {
-                if (callback.mWatchingUid >= 0 && callback.mWatchingUid != uid) {
-                    continue;
-                }
-
-                if (dispatchedCallbacks == null) {
-                    dispatchedCallbacks = new ArraySet<>();
-                }
-                dispatchedCallbacks.add(callback);
-            }
-        }
-
-        if (dispatchedCallbacks == null) {
-            return;
-        }
-
-        mHandler.sendMessage(PooledLambda.obtainMessage(
-                AppOpsServiceImpl::notifyOpStarted,
-                this, dispatchedCallbacks, code, uid, pkgName, attributionTag, flags,
-                result, startedType, attributionFlags, attributionChainId));
-    }
-
-    private void notifyOpStarted(ArraySet<StartedCallback> callbacks,
-            int code, int uid, String packageName, String attributionTag, @OpFlags int flags,
-            @Mode int result, @AppOpsManager.OnOpStartedListener.StartedType int startedType,
-            @AttributionFlags int attributionFlags, int attributionChainId) {
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            final int callbackCount = callbacks.size();
-            for (int i = 0; i < callbackCount; i++) {
-                final StartedCallback callback = callbacks.valueAt(i);
-                try {
-                    if (shouldIgnoreCallback(code, callback.mCallingPid, callback.mCallingUid)) {
-                        continue;
-                    }
-                    callback.mCallback.opStarted(code, uid, packageName, attributionTag, flags,
-                            result, startedType, attributionFlags, attributionChainId);
-                } catch (RemoteException e) {
-                    /* do nothing */
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    private void scheduleOpNotedIfNeededLocked(int code, int uid, String packageName,
-            String attributionTag, @OpFlags int flags, @Mode int result) {
-        ArraySet<NotedCallback> dispatchedCallbacks = null;
-        final int callbackListCount = mNotedWatchers.size();
-        for (int i = 0; i < callbackListCount; i++) {
-            final SparseArray<NotedCallback> callbacks = mNotedWatchers.valueAt(i);
-            final NotedCallback callback = callbacks.get(code);
-            if (callback != null) {
-                if (callback.mWatchingUid >= 0 && callback.mWatchingUid != uid) {
-                    continue;
-                }
-                if (dispatchedCallbacks == null) {
-                    dispatchedCallbacks = new ArraySet<>();
-                }
-                dispatchedCallbacks.add(callback);
-            }
-        }
-        if (dispatchedCallbacks == null) {
-            return;
-        }
-        mHandler.sendMessage(PooledLambda.obtainMessage(
-                AppOpsServiceImpl::notifyOpChecked,
-                this, dispatchedCallbacks, code, uid, packageName, attributionTag, flags,
-                result));
-    }
-
-    private void notifyOpChecked(ArraySet<NotedCallback> callbacks,
-            int code, int uid, String packageName, String attributionTag, @OpFlags int flags,
-            @Mode int result) {
-        // There are features watching for checks in our process. The callbacks in
-        // these features may require permissions our remote caller does not have.
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            final int callbackCount = callbacks.size();
-            for (int i = 0; i < callbackCount; i++) {
-                final NotedCallback callback = callbacks.valueAt(i);
-                try {
-                    if (shouldIgnoreCallback(code, callback.mCallingPid, callback.mCallingUid)) {
-                        continue;
-                    }
-                    callback.mCallback.opNoted(code, uid, packageName, attributionTag, flags,
-                            result);
-                } catch (RemoteException e) {
-                    /* do nothing */
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    private void verifyIncomingUid(int uid) {
-        if (uid == Binder.getCallingUid()) {
-            return;
-        }
-        if (Binder.getCallingPid() == Process.myPid()) {
-            return;
-        }
-        mContext.enforcePermission(android.Manifest.permission.UPDATE_APP_OPS_STATS,
-                Binder.getCallingPid(), Binder.getCallingUid(), null);
-    }
-
-    private boolean shouldIgnoreCallback(int op, int watcherPid, int watcherUid) {
-        // If it's a restricted read op, ignore it if watcher doesn't have manage ops permission,
-        // as watcher should not use this to signal if the value is changed.
-        return opRestrictsRead(op) && mContext.checkPermission(Manifest.permission.MANAGE_APPOPS,
-                watcherPid, watcherUid) != PackageManager.PERMISSION_GRANTED;
-    }
-
-    private void verifyIncomingOp(int op) {
-        if (op >= 0 && op < AppOpsManager._NUM_OP) {
-            // Enforce manage appops permission if it's a restricted read op.
-            if (opRestrictsRead(op)) {
-                mContext.enforcePermission(Manifest.permission.MANAGE_APPOPS,
-                        Binder.getCallingPid(), Binder.getCallingUid(), "verifyIncomingOp");
-            }
-            return;
-        }
-        throw new IllegalArgumentException("Bad operation #" + op);
-    }
-
-    private boolean isIncomingPackageValid(@Nullable String packageName, @UserIdInt int userId) {
-        final int callingUid = Binder.getCallingUid();
-        // Handle the special UIDs that don't have actual packages (audioserver, cameraserver, etc).
-        if (packageName == null || isSpecialPackage(callingUid, packageName)) {
-            return true;
-        }
-
-        // If the package doesn't exist, #verifyAndGetBypass would throw a SecurityException in
-        // the end. Although that exception would be caught and return, we could make it return
-        // early.
-        if (!isPackageExisted(packageName)) {
-            return false;
-        }
-
-        if (getPackageManagerInternal().filterAppAccess(packageName, callingUid, userId)) {
-            Slog.w(TAG, packageName + " not found from " + callingUid);
-            return false;
-        }
-
-        return true;
-    }
-
-    private boolean isSpecialPackage(int callingUid, @Nullable String packageName) {
-        final String resolvedPackage = AppOpsManager.resolvePackageName(callingUid, packageName);
-        return callingUid == Process.SYSTEM_UID
-                || resolveUid(resolvedPackage) != Process.INVALID_UID;
-    }
-
-    private @Nullable UidState getUidStateLocked(int uid, boolean edit) {
-        UidState uidState = mUidStates.get(uid);
-        if (uidState == null) {
-            if (!edit) {
-                return null;
-            }
-            uidState = new UidState(uid);
-            mUidStates.put(uid, uidState);
-        }
-
-        return uidState;
-    }
-
-    @Override
-    public void updateAppWidgetVisibility(SparseArray<String> uidPackageNames, boolean visible) {
-        synchronized (this) {
-            getUidStateTracker().updateAppWidgetVisibility(uidPackageNames, visible);
-        }
-    }
-
-    /**
-     * @return {@link PackageManagerInternal}
-     */
-    private @NonNull PackageManagerInternal getPackageManagerInternal() {
-        if (mPackageManagerInternal == null) {
-            mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class);
-        }
-
-        return mPackageManagerInternal;
-    }
-
-    @Override
-    public void verifyPackage(int uid, String packageName) {
-        verifyAndGetBypass(uid, packageName, null);
-    }
-
-    /**
-     * Create a restriction description matching the properties of the package.
-     *
-     * @param pkg The package to create the restriction description for
-     * @return The restriction matching the package
-     */
-    private RestrictionBypass getBypassforPackage(@NonNull AndroidPackage pkg) {
-        return new RestrictionBypass(pkg.getUid() == Process.SYSTEM_UID, pkg.isPrivileged(),
-                mContext.checkPermission(android.Manifest.permission
-                        .EXEMPT_FROM_AUDIO_RECORD_RESTRICTIONS, -1, pkg.getUid())
-                        == PackageManager.PERMISSION_GRANTED);
-    }
-
-    /**
-     * @see #verifyAndGetBypass(int, String, String, String)
-     */
-    private @NonNull PackageVerificationResult verifyAndGetBypass(int uid, String packageName,
-            @Nullable String attributionTag) {
-        return verifyAndGetBypass(uid, packageName, attributionTag, null);
-    }
-
-    /**
-     * Verify that package belongs to uid and return the {@link RestrictionBypass bypass
-     * description} for the package, along with a boolean indicating whether the attribution tag is
-     * valid.
-     *
-     * @param uid              The uid the package belongs to
-     * @param packageName      The package the might belong to the uid
-     * @param attributionTag   attribution tag or {@code null} if no need to verify
-     * @param proxyPackageName The proxy package, from which the attribution tag is to be pulled
-     * @return PackageVerificationResult containing {@link RestrictionBypass} and whether the
-     * attribution tag is valid
-     */
-    private @NonNull PackageVerificationResult verifyAndGetBypass(int uid, String packageName,
-            @Nullable String attributionTag, @Nullable String proxyPackageName) {
-        if (uid == Process.ROOT_UID) {
-            // For backwards compatibility, don't check package name for root UID.
-            return new PackageVerificationResult(null,
-                    /* isAttributionTagValid */ true);
-        }
-        if (Process.isSdkSandboxUid(uid)) {
-            // SDK sandbox processes run in their own UID range, but their associated
-            // UID for checks should always be the UID of the package implementing SDK sandbox
-            // service.
-            // TODO: We will need to modify the callers of this function instead, so
-            // modifications and checks against the app ops state are done with the
-            // correct UID.
-            try {
-                final PackageManager pm = mContext.getPackageManager();
-                final String supplementalPackageName = pm.getSdkSandboxPackageName();
-                if (Objects.equals(packageName, supplementalPackageName)) {
-                    uid = pm.getPackageUidAsUser(supplementalPackageName,
-                            PackageManager.PackageInfoFlags.of(0), UserHandle.getUserId(uid));
-                }
-            } catch (PackageManager.NameNotFoundException e) {
-                // Shouldn't happen for the supplemental package
-                e.printStackTrace();
-            }
-        }
-
-
-        // Do not check if uid/packageName/attributionTag is already known.
-        synchronized (this) {
-            UidState uidState = mUidStates.get(uid);
-            if (uidState != null && uidState.pkgOps != null) {
-                Ops ops = uidState.pkgOps.get(packageName);
-
-                if (ops != null && (attributionTag == null || ops.knownAttributionTags.contains(
-                        attributionTag)) && ops.bypass != null) {
-                    return new PackageVerificationResult(ops.bypass,
-                            ops.validAttributionTags.contains(attributionTag));
-                }
-            }
-        }
-
-        int callingUid = Binder.getCallingUid();
-
-        // Allow any attribution tag for resolvable uids
-        int pkgUid;
-        if (Objects.equals(packageName, "com.android.shell")) {
-            // Special case for the shell which is a package but should be able
-            // to bypass app attribution tag restrictions.
-            pkgUid = Process.SHELL_UID;
-        } else {
-            pkgUid = resolveUid(packageName);
-        }
-        if (pkgUid != Process.INVALID_UID) {
-            if (pkgUid != UserHandle.getAppId(uid)) {
-                Slog.e(TAG, "Bad call made by uid " + callingUid + ". "
-                        + "Package \"" + packageName + "\" does not belong to uid " + uid + ".");
-                String otherUidMessage = DEBUG ? " but it is really " + pkgUid : " but it is not";
-                throw new SecurityException("Specified package \"" + packageName + "\" under uid "
-                        + UserHandle.getAppId(uid) + otherUidMessage);
-            }
-            return new PackageVerificationResult(RestrictionBypass.UNRESTRICTED,
-                    /* isAttributionTagValid */ true);
-        }
-
-        int userId = UserHandle.getUserId(uid);
-        RestrictionBypass bypass = null;
-        boolean isAttributionTagValid = false;
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            PackageManagerInternal pmInt = LocalServices.getService(PackageManagerInternal.class);
-            AndroidPackage pkg = pmInt.getPackage(packageName);
-            if (pkg != null) {
-                isAttributionTagValid = isAttributionInPackage(pkg, attributionTag);
-                pkgUid = UserHandle.getUid(userId, UserHandle.getAppId(pkg.getUid()));
-                bypass = getBypassforPackage(pkg);
-            }
-            if (!isAttributionTagValid) {
-                AndroidPackage proxyPkg = proxyPackageName != null
-                        ? pmInt.getPackage(proxyPackageName) : null;
-                // Re-check in proxy.
-                isAttributionTagValid = isAttributionInPackage(proxyPkg, attributionTag);
-                String msg;
-                if (pkg != null && isAttributionTagValid) {
-                    msg = "attributionTag " + attributionTag + " declared in manifest of the proxy"
-                            + " package " + proxyPackageName + ", this is not advised";
-                } else if (pkg != null) {
-                    msg = "attributionTag " + attributionTag + " not declared in manifest of "
-                            + packageName;
-                } else {
-                    msg = "package " + packageName + " not found, can't check for "
-                            + "attributionTag " + attributionTag;
-                }
-
-                try {
-                    if (!mPlatformCompat.isChangeEnabledByPackageName(
-                            SECURITY_EXCEPTION_ON_INVALID_ATTRIBUTION_TAG_CHANGE, packageName,
-                            userId) || !mPlatformCompat.isChangeEnabledByUid(
-                            SECURITY_EXCEPTION_ON_INVALID_ATTRIBUTION_TAG_CHANGE,
-                            callingUid)) {
-                        // Do not override tags if overriding is not enabled for this package
-                        isAttributionTagValid = true;
-                    }
-                    Slog.e(TAG, msg);
-                } catch (RemoteException neverHappens) {
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-
-        if (pkgUid != uid) {
-            Slog.e(TAG, "Bad call made by uid " + callingUid + ". "
-                    + "Package \"" + packageName + "\" does not belong to uid " + uid + ".");
-            String otherUidMessage = DEBUG ? " but it is really " + pkgUid : " but it is not";
-            throw new SecurityException("Specified package \"" + packageName + "\" under uid " + uid
-                    + otherUidMessage);
-        }
-
-        return new PackageVerificationResult(bypass, isAttributionTagValid);
-    }
-
-    private boolean isAttributionInPackage(@Nullable AndroidPackage pkg,
-            @Nullable String attributionTag) {
-        if (pkg == null) {
-            return false;
-        } else if (attributionTag == null) {
-            return true;
-        }
-        if (pkg.getAttributions() != null) {
-            int numAttributions = pkg.getAttributions().size();
-            for (int i = 0; i < numAttributions; i++) {
-                if (pkg.getAttributions().get(i).getTag().equals(attributionTag)) {
-                    return true;
-                }
-            }
-        }
-
-        return false;
-    }
-
-    /**
-     * Get (and potentially create) ops.
-     *
-     * @param uid                   The uid the package belongs to
-     * @param packageName           The name of the package
-     * @param attributionTag        attribution tag
-     * @param isAttributionTagValid whether the given attribution tag is valid
-     * @param bypass                When to bypass certain op restrictions (can be null if edit
-        *                              == false)
-     * @param edit                  If an ops does not exist, create the ops?
-     * @return The ops
-     */
-    private Ops getOpsLocked(int uid, String packageName, @Nullable String attributionTag,
-            boolean isAttributionTagValid, @Nullable RestrictionBypass bypass, boolean edit) {
-        UidState uidState = getUidStateLocked(uid, edit);
-        if (uidState == null) {
-            return null;
-        }
-
-        if (uidState.pkgOps == null) {
-            if (!edit) {
-                return null;
-            }
-            uidState.pkgOps = new ArrayMap<>();
-        }
-
-        Ops ops = uidState.pkgOps.get(packageName);
-        if (ops == null) {
-            if (!edit) {
-                return null;
-            }
-            ops = new Ops(packageName, uidState);
-            uidState.pkgOps.put(packageName, ops);
-        }
-
-        if (edit) {
-            if (bypass != null) {
-                ops.bypass = bypass;
-            }
-
-            if (attributionTag != null) {
-                ops.knownAttributionTags.add(attributionTag);
-                if (isAttributionTagValid) {
-                    ops.validAttributionTags.add(attributionTag);
-                } else {
-                    ops.validAttributionTags.remove(attributionTag);
-                }
-            }
-        }
-
-        return ops;
-    }
-
-    @Override
-    public void scheduleWriteLocked() {
-        if (!mWriteScheduled) {
-            mWriteScheduled = true;
-            mHandler.postDelayed(mWriteRunner, WRITE_DELAY);
-        }
-    }
-
-    @Override
-    public void scheduleFastWriteLocked() {
-        if (!mFastWriteScheduled) {
-            mWriteScheduled = true;
-            mFastWriteScheduled = true;
-            mHandler.removeCallbacks(mWriteRunner);
-            mHandler.postDelayed(mWriteRunner, 10 * 1000);
-        }
-    }
-
-    /**
-     * Get the state of an op for a uid.
-     *
-     * @param code                  The code of the op
-     * @param uid                   The uid the of the package
-     * @param packageName           The package name for which to get the state for
-     * @param attributionTag        The attribution tag
-     * @param isAttributionTagValid Whether the given attribution tag is valid
-     * @param bypass                When to bypass certain op restrictions (can be null if edit
-     *                              == false)
-     * @param edit                  Iff {@code true} create the {@link Op} object if not yet created
-     * @return The {@link Op state} of the op
-     */
-    private @Nullable Op getOpLocked(int code, int uid, @NonNull String packageName,
-            @Nullable String attributionTag, boolean isAttributionTagValid,
-            @Nullable RestrictionBypass bypass, boolean edit) {
-        Ops ops = getOpsLocked(uid, packageName, attributionTag, isAttributionTagValid, bypass,
-                edit);
-        if (ops == null) {
-            return null;
-        }
-        return getOpLocked(ops, code, uid, edit);
-    }
-
-    private Op getOpLocked(Ops ops, int code, int uid, boolean edit) {
-        Op op = ops.get(code);
-        if (op == null) {
-            if (!edit) {
-                return null;
-            }
-            op = new Op(ops.uidState, ops.packageName, code, uid);
-            ops.put(code, op);
-        }
-        if (edit) {
-            scheduleWriteLocked();
-        }
-        return op;
-    }
-
-    private boolean isOpRestrictedDueToSuspend(int code, String packageName, int uid) {
-        if (!ArrayUtils.contains(OPS_RESTRICTED_ON_SUSPEND, code)) {
-            return false;
-        }
-        final PackageManagerInternal pmi = LocalServices.getService(PackageManagerInternal.class);
-        return pmi.isPackageSuspended(packageName, UserHandle.getUserId(uid));
-    }
-
-    private boolean isOpRestrictedLocked(int uid, int code, String packageName,
-            String attributionTag, @Nullable RestrictionBypass appBypass, boolean isCheckOp) {
-        int restrictionSetCount = mOpGlobalRestrictions.size();
-
-        for (int i = 0; i < restrictionSetCount; i++) {
-            ClientGlobalRestrictionState restrictionState = mOpGlobalRestrictions.valueAt(i);
-            if (restrictionState.hasRestriction(code)) {
-                return true;
-            }
-        }
-
-        int userHandle = UserHandle.getUserId(uid);
-        restrictionSetCount = mOpUserRestrictions.size();
-
-        for (int i = 0; i < restrictionSetCount; i++) {
-            // For each client, check that the given op is not restricted, or that the given
-            // package is exempt from the restriction.
-            ClientUserRestrictionState restrictionState = mOpUserRestrictions.valueAt(i);
-            if (restrictionState.hasRestriction(code, packageName, attributionTag, userHandle,
-                    isCheckOp)) {
-                RestrictionBypass opBypass = opAllowSystemBypassRestriction(code);
-                if (opBypass != null) {
-                    // If we are the system, bypass user restrictions for certain codes
-                    synchronized (this) {
-                        if (opBypass.isSystemUid && appBypass != null && appBypass.isSystemUid) {
-                            return false;
-                        }
-                        if (opBypass.isPrivileged && appBypass != null && appBypass.isPrivileged) {
-                            return false;
-                        }
-                        if (opBypass.isRecordAudioRestrictionExcept && appBypass != null
-                                && appBypass.isRecordAudioRestrictionExcept) {
-                            return false;
-                        }
-                    }
-                }
-                return true;
-            }
-        }
-        return false;
-    }
-
-    @Override
-    public void readState() {
-        int oldVersion = NO_VERSION;
-        synchronized (mFile) {
-            synchronized (this) {
-                FileInputStream stream;
-                try {
-                    stream = mFile.openRead();
-                } catch (FileNotFoundException e) {
-                    Slog.i(TAG, "No existing app ops " + mFile.getBaseFile() + "; starting empty");
-                    return;
-                }
-                boolean success = false;
-                mUidStates.clear();
-                mAppOpsServiceInterface.clearAllModes();
-                try {
-                    TypedXmlPullParser parser = Xml.resolvePullParser(stream);
-                    int type;
-                    while ((type = parser.next()) != XmlPullParser.START_TAG
-                            && type != XmlPullParser.END_DOCUMENT) {
-                        // Parse next until we reach the start or end
-                    }
-
-                    if (type != XmlPullParser.START_TAG) {
-                        throw new IllegalStateException("no start tag found");
-                    }
-
-                    oldVersion = parser.getAttributeInt(null, "v", NO_VERSION);
-
-                    int outerDepth = parser.getDepth();
-                    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                            && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-                        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                            continue;
-                        }
-
-                        String tagName = parser.getName();
-                        if (tagName.equals("pkg")) {
-                            readPackage(parser);
-                        } else if (tagName.equals("uid")) {
-                            readUidOps(parser);
-                        } else {
-                            Slog.w(TAG, "Unknown element under <app-ops>: "
-                                    + parser.getName());
-                            XmlUtils.skipCurrentTag(parser);
-                        }
-                    }
-                    success = true;
-                } catch (IllegalStateException e) {
-                    Slog.w(TAG, "Failed parsing " + e);
-                } catch (NullPointerException e) {
-                    Slog.w(TAG, "Failed parsing " + e);
-                } catch (NumberFormatException e) {
-                    Slog.w(TAG, "Failed parsing " + e);
-                } catch (XmlPullParserException e) {
-                    Slog.w(TAG, "Failed parsing " + e);
-                } catch (IOException e) {
-                    Slog.w(TAG, "Failed parsing " + e);
-                } catch (IndexOutOfBoundsException e) {
-                    Slog.w(TAG, "Failed parsing " + e);
-                } finally {
-                    if (!success) {
-                        mUidStates.clear();
-                        mAppOpsServiceInterface.clearAllModes();
-                    }
-                    try {
-                        stream.close();
-                    } catch (IOException e) {
-                    }
-                }
-            }
-        }
-        synchronized (this) {
-            upgradeLocked(oldVersion);
-        }
-    }
-
-    private void upgradeRunAnyInBackgroundLocked() {
-        for (int i = 0; i < mUidStates.size(); i++) {
-            final UidState uidState = mUidStates.valueAt(i);
-            if (uidState == null) {
-                continue;
-            }
-            SparseIntArray opModes = uidState.getNonDefaultUidModes();
-            if (opModes != null) {
-                final int idx = opModes.indexOfKey(AppOpsManager.OP_RUN_IN_BACKGROUND);
-                if (idx >= 0) {
-                    uidState.setUidMode(AppOpsManager.OP_RUN_ANY_IN_BACKGROUND,
-                            opModes.valueAt(idx));
-                }
-            }
-            if (uidState.pkgOps == null) {
-                continue;
-            }
-            boolean changed = false;
-            for (int j = 0; j < uidState.pkgOps.size(); j++) {
-                Ops ops = uidState.pkgOps.valueAt(j);
-                if (ops != null) {
-                    final Op op = ops.get(AppOpsManager.OP_RUN_IN_BACKGROUND);
-                    if (op != null && op.getMode() != AppOpsManager.opToDefaultMode(op.op)) {
-                        final Op copy = new Op(op.uidState, op.packageName,
-                                AppOpsManager.OP_RUN_ANY_IN_BACKGROUND, uidState.uid);
-                        copy.setMode(op.getMode());
-                        ops.put(AppOpsManager.OP_RUN_ANY_IN_BACKGROUND, copy);
-                        changed = true;
-                    }
-                }
-            }
-            if (changed) {
-                uidState.evalForegroundOps();
-            }
-        }
-    }
-
-    private void upgradeLocked(int oldVersion) {
-        if (oldVersion >= CURRENT_VERSION) {
-            return;
-        }
-        Slog.d(TAG, "Upgrading app-ops xml from version " + oldVersion + " to " + CURRENT_VERSION);
-        switch (oldVersion) {
-            case NO_VERSION:
-                upgradeRunAnyInBackgroundLocked();
-                // fall through
-            case 1:
-                // for future upgrades
-        }
-        scheduleFastWriteLocked();
-    }
-
-    private void readUidOps(TypedXmlPullParser parser) throws NumberFormatException,
-            XmlPullParserException, IOException {
-        final int uid = parser.getAttributeInt(null, "n");
-        int outerDepth = parser.getDepth();
-        int type;
-        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                continue;
-            }
-
-            String tagName = parser.getName();
-            if (tagName.equals("op")) {
-                final int code = parser.getAttributeInt(null, "n");
-                final int mode = parser.getAttributeInt(null, "m");
-                setUidMode(code, uid, mode, null);
-            } else {
-                Slog.w(TAG, "Unknown element under <uid-ops>: "
-                        + parser.getName());
-                XmlUtils.skipCurrentTag(parser);
-            }
-        }
-    }
-
-    private void readPackage(TypedXmlPullParser parser)
-            throws NumberFormatException, XmlPullParserException, IOException {
-        String pkgName = parser.getAttributeValue(null, "n");
-        int outerDepth = parser.getDepth();
-        int type;
-        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                continue;
-            }
-
-            String tagName = parser.getName();
-            if (tagName.equals("uid")) {
-                readUid(parser, pkgName);
-            } else {
-                Slog.w(TAG, "Unknown element under <pkg>: "
-                        + parser.getName());
-                XmlUtils.skipCurrentTag(parser);
-            }
-        }
-    }
-
-    private void readUid(TypedXmlPullParser parser, String pkgName)
-            throws NumberFormatException, XmlPullParserException, IOException {
-        int uid = parser.getAttributeInt(null, "n");
-        final UidState uidState = getUidStateLocked(uid, true);
-        int outerDepth = parser.getDepth();
-        int type;
-        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                continue;
-            }
-            String tagName = parser.getName();
-            if (tagName.equals("op")) {
-                readOp(parser, uidState, pkgName);
-            } else {
-                Slog.w(TAG, "Unknown element under <pkg>: "
-                        + parser.getName());
-                XmlUtils.skipCurrentTag(parser);
-            }
-        }
-        uidState.evalForegroundOps();
-    }
-
-    private void readAttributionOp(TypedXmlPullParser parser, @NonNull Op parent,
-            @Nullable String attribution)
-            throws NumberFormatException, IOException, XmlPullParserException {
-        final AttributedOp attributedOp = parent.getOrCreateAttribution(parent, attribution);
-
-        final long key = parser.getAttributeLong(null, "n");
-        final int uidState = extractUidStateFromKey(key);
-        final int opFlags = extractFlagsFromKey(key);
-
-        final long accessTime = parser.getAttributeLong(null, "t", 0);
-        final long rejectTime = parser.getAttributeLong(null, "r", 0);
-        final long accessDuration = parser.getAttributeLong(null, "d", -1);
-        final String proxyPkg = XmlUtils.readStringAttribute(parser, "pp");
-        final int proxyUid = parser.getAttributeInt(null, "pu", Process.INVALID_UID);
-        final String proxyAttributionTag = XmlUtils.readStringAttribute(parser, "pc");
-
-        if (accessTime > 0) {
-            attributedOp.accessed(accessTime, accessDuration, proxyUid, proxyPkg,
-                    proxyAttributionTag, uidState, opFlags);
-        }
-        if (rejectTime > 0) {
-            attributedOp.rejected(rejectTime, uidState, opFlags);
-        }
-    }
-
-    private void readOp(TypedXmlPullParser parser,
-            @NonNull UidState uidState, @NonNull String pkgName)
-            throws NumberFormatException, XmlPullParserException, IOException {
-        int opCode = parser.getAttributeInt(null, "n");
-        Op op = new Op(uidState, pkgName, opCode, uidState.uid);
-
-        final int mode = parser.getAttributeInt(null, "m", AppOpsManager.opToDefaultMode(op.op));
-        op.setMode(mode);
-
-        int outerDepth = parser.getDepth();
-        int type;
-        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                continue;
-            }
-            String tagName = parser.getName();
-            if (tagName.equals("st")) {
-                readAttributionOp(parser, op, XmlUtils.readStringAttribute(parser, "id"));
-            } else {
-                Slog.w(TAG, "Unknown element under <op>: "
-                        + parser.getName());
-                XmlUtils.skipCurrentTag(parser);
-            }
-        }
-
-        if (uidState.pkgOps == null) {
-            uidState.pkgOps = new ArrayMap<>();
-        }
-        Ops ops = uidState.pkgOps.get(pkgName);
-        if (ops == null) {
-            ops = new Ops(pkgName, uidState);
-            uidState.pkgOps.put(pkgName, ops);
-        }
-        ops.put(op.op, op);
-    }
-
-    @Override
-    public void writeState() {
-        synchronized (mFile) {
-            FileOutputStream stream;
-            try {
-                stream = mFile.startWrite();
-            } catch (IOException e) {
-                Slog.w(TAG, "Failed to write state: " + e);
-                return;
-            }
-
-            List<AppOpsManager.PackageOps> allOps = getPackagesForOps(null);
-
-            try {
-                TypedXmlSerializer out = Xml.resolveSerializer(stream);
-                out.startDocument(null, true);
-                out.startTag(null, "app-ops");
-                out.attributeInt(null, "v", CURRENT_VERSION);
-
-                SparseArray<SparseIntArray> uidStatesClone;
-                synchronized (this) {
-                    uidStatesClone = new SparseArray<>(mUidStates.size());
-
-                    final int uidStateCount = mUidStates.size();
-                    for (int uidStateNum = 0; uidStateNum < uidStateCount; uidStateNum++) {
-                        UidState uidState = mUidStates.valueAt(uidStateNum);
-                        int uid = mUidStates.keyAt(uidStateNum);
-
-                        SparseIntArray opModes = uidState.getNonDefaultUidModes();
-                        if (opModes != null && opModes.size() > 0) {
-                            uidStatesClone.put(uid, opModes);
-                        }
-                    }
-                }
-
-                final int uidStateCount = uidStatesClone.size();
-                for (int uidStateNum = 0; uidStateNum < uidStateCount; uidStateNum++) {
-                    SparseIntArray opModes = uidStatesClone.valueAt(uidStateNum);
-                    if (opModes != null && opModes.size() > 0) {
-                        out.startTag(null, "uid");
-                        out.attributeInt(null, "n", uidStatesClone.keyAt(uidStateNum));
-                        final int opCount = opModes.size();
-                        for (int opCountNum = 0; opCountNum < opCount; opCountNum++) {
-                            final int op = opModes.keyAt(opCountNum);
-                            final int mode = opModes.valueAt(opCountNum);
-                            out.startTag(null, "op");
-                            out.attributeInt(null, "n", op);
-                            out.attributeInt(null, "m", mode);
-                            out.endTag(null, "op");
-                        }
-                        out.endTag(null, "uid");
-                    }
-                }
-
-                if (allOps != null) {
-                    String lastPkg = null;
-                    for (int i = 0; i < allOps.size(); i++) {
-                        AppOpsManager.PackageOps pkg = allOps.get(i);
-                        if (!Objects.equals(pkg.getPackageName(), lastPkg)) {
-                            if (lastPkg != null) {
-                                out.endTag(null, "pkg");
-                            }
-                            lastPkg = pkg.getPackageName();
-                            if (lastPkg != null) {
-                                out.startTag(null, "pkg");
-                                out.attribute(null, "n", lastPkg);
-                            }
-                        }
-                        out.startTag(null, "uid");
-                        out.attributeInt(null, "n", pkg.getUid());
-                        List<AppOpsManager.OpEntry> ops = pkg.getOps();
-                        for (int j = 0; j < ops.size(); j++) {
-                            AppOpsManager.OpEntry op = ops.get(j);
-                            out.startTag(null, "op");
-                            out.attributeInt(null, "n", op.getOp());
-                            if (op.getMode() != AppOpsManager.opToDefaultMode(op.getOp())) {
-                                out.attributeInt(null, "m", op.getMode());
-                            }
-
-                            for (String attributionTag : op.getAttributedOpEntries().keySet()) {
-                                final AttributedOpEntry attribution =
-                                        op.getAttributedOpEntries().get(attributionTag);
-
-                                final ArraySet<Long> keys = attribution.collectKeys();
-
-                                final int keyCount = keys.size();
-                                for (int k = 0; k < keyCount; k++) {
-                                    final long key = keys.valueAt(k);
-
-                                    final int uidState = AppOpsManager.extractUidStateFromKey(key);
-                                    final int flags = AppOpsManager.extractFlagsFromKey(key);
-
-                                    final long accessTime = attribution.getLastAccessTime(uidState,
-                                            uidState, flags);
-                                    final long rejectTime = attribution.getLastRejectTime(uidState,
-                                            uidState, flags);
-                                    final long accessDuration = attribution.getLastDuration(
-                                            uidState, uidState, flags);
-                                    // Proxy information for rejections is not backed up
-                                    final OpEventProxyInfo proxy = attribution.getLastProxyInfo(
-                                            uidState, uidState, flags);
-
-                                    if (accessTime <= 0 && rejectTime <= 0 && accessDuration <= 0
-                                            && proxy == null) {
-                                        continue;
-                                    }
-
-                                    String proxyPkg = null;
-                                    String proxyAttributionTag = null;
-                                    int proxyUid = Process.INVALID_UID;
-                                    if (proxy != null) {
-                                        proxyPkg = proxy.getPackageName();
-                                        proxyAttributionTag = proxy.getAttributionTag();
-                                        proxyUid = proxy.getUid();
-                                    }
-
-                                    out.startTag(null, "st");
-                                    if (attributionTag != null) {
-                                        out.attribute(null, "id", attributionTag);
-                                    }
-                                    out.attributeLong(null, "n", key);
-                                    if (accessTime > 0) {
-                                        out.attributeLong(null, "t", accessTime);
-                                    }
-                                    if (rejectTime > 0) {
-                                        out.attributeLong(null, "r", rejectTime);
-                                    }
-                                    if (accessDuration > 0) {
-                                        out.attributeLong(null, "d", accessDuration);
-                                    }
-                                    if (proxyPkg != null) {
-                                        out.attribute(null, "pp", proxyPkg);
-                                    }
-                                    if (proxyAttributionTag != null) {
-                                        out.attribute(null, "pc", proxyAttributionTag);
-                                    }
-                                    if (proxyUid >= 0) {
-                                        out.attributeInt(null, "pu", proxyUid);
-                                    }
-                                    out.endTag(null, "st");
-                                }
-                            }
-
-                            out.endTag(null, "op");
-                        }
-                        out.endTag(null, "uid");
-                    }
-                    if (lastPkg != null) {
-                        out.endTag(null, "pkg");
-                    }
-                }
-
-                out.endTag(null, "app-ops");
-                out.endDocument();
-                mFile.finishWrite(stream);
-            } catch (IOException e) {
-                Slog.w(TAG, "Failed to write state, restoring backup.", e);
-                mFile.failWrite(stream);
-            }
-        }
-        mHistoricalRegistry.writeAndClearDiscreteHistory();
-    }
-
-    private void dumpHelp(PrintWriter pw) {
-        pw.println("AppOps service (appops) dump options:");
-        pw.println("  -h");
-        pw.println("    Print this help text.");
-        pw.println("  --op [OP]");
-        pw.println("    Limit output to data associated with the given app op code.");
-        pw.println("  --mode [MODE]");
-        pw.println("    Limit output to data associated with the given app op mode.");
-        pw.println("  --package [PACKAGE]");
-        pw.println("    Limit output to data associated with the given package name.");
-        pw.println("  --attributionTag [attributionTag]");
-        pw.println("    Limit output to data associated with the given attribution tag.");
-        pw.println("  --include-discrete [n]");
-        pw.println("    Include discrete ops limited to n per dimension. Use zero for no limit.");
-        pw.println("  --watchers");
-        pw.println("    Only output the watcher sections.");
-        pw.println("  --history");
-        pw.println("    Only output history.");
-        pw.println("  --uid-state-changes");
-        pw.println("    Include logs about uid state changes.");
-    }
-
-    private void dumpStatesLocked(@NonNull PrintWriter pw, @Nullable String filterAttributionTag,
-            @HistoricalOpsRequestFilter int filter, long nowElapsed, @NonNull Op op, long now,
-            @NonNull SimpleDateFormat sdf, @NonNull Date date, @NonNull String prefix) {
-        final int numAttributions = op.mAttributions.size();
-        for (int i = 0; i < numAttributions; i++) {
-            if ((filter & FILTER_BY_ATTRIBUTION_TAG) != 0 && !Objects.equals(
-                    op.mAttributions.keyAt(i), filterAttributionTag)) {
-                continue;
-            }
-
-            pw.print(prefix + op.mAttributions.keyAt(i) + "=[\n");
-            dumpStatesLocked(pw, nowElapsed, op, op.mAttributions.keyAt(i), now, sdf, date,
-                    prefix + "  ");
-            pw.print(prefix + "]\n");
-        }
-    }
-
-    private void dumpStatesLocked(@NonNull PrintWriter pw, long nowElapsed, @NonNull Op op,
-            @Nullable String attributionTag, long now, @NonNull SimpleDateFormat sdf,
-            @NonNull Date date, @NonNull String prefix) {
-
-        final AttributedOpEntry entry = op.createSingleAttributionEntryLocked(
-                attributionTag).getAttributedOpEntries().get(attributionTag);
-
-        final ArraySet<Long> keys = entry.collectKeys();
-
-        final int keyCount = keys.size();
-        for (int k = 0; k < keyCount; k++) {
-            final long key = keys.valueAt(k);
-
-            final int uidState = AppOpsManager.extractUidStateFromKey(key);
-            final int flags = AppOpsManager.extractFlagsFromKey(key);
-
-            final long accessTime = entry.getLastAccessTime(uidState, uidState, flags);
-            final long rejectTime = entry.getLastRejectTime(uidState, uidState, flags);
-            final long accessDuration = entry.getLastDuration(uidState, uidState, flags);
-            final OpEventProxyInfo proxy = entry.getLastProxyInfo(uidState, uidState, flags);
-
-            String proxyPkg = null;
-            String proxyAttributionTag = null;
-            int proxyUid = Process.INVALID_UID;
-            if (proxy != null) {
-                proxyPkg = proxy.getPackageName();
-                proxyAttributionTag = proxy.getAttributionTag();
-                proxyUid = proxy.getUid();
-            }
-
-            if (accessTime > 0) {
-                pw.print(prefix);
-                pw.print("Access: ");
-                pw.print(AppOpsManager.keyToString(key));
-                pw.print(" ");
-                date.setTime(accessTime);
-                pw.print(sdf.format(date));
-                pw.print(" (");
-                TimeUtils.formatDuration(accessTime - now, pw);
-                pw.print(")");
-                if (accessDuration > 0) {
-                    pw.print(" duration=");
-                    TimeUtils.formatDuration(accessDuration, pw);
-                }
-                if (proxyUid >= 0) {
-                    pw.print(" proxy[");
-                    pw.print("uid=");
-                    pw.print(proxyUid);
-                    pw.print(", pkg=");
-                    pw.print(proxyPkg);
-                    pw.print(", attributionTag=");
-                    pw.print(proxyAttributionTag);
-                    pw.print("]");
-                }
-                pw.println();
-            }
-
-            if (rejectTime > 0) {
-                pw.print(prefix);
-                pw.print("Reject: ");
-                pw.print(AppOpsManager.keyToString(key));
-                date.setTime(rejectTime);
-                pw.print(sdf.format(date));
-                pw.print(" (");
-                TimeUtils.formatDuration(rejectTime - now, pw);
-                pw.print(")");
-                if (proxyUid >= 0) {
-                    pw.print(" proxy[");
-                    pw.print("uid=");
-                    pw.print(proxyUid);
-                    pw.print(", pkg=");
-                    pw.print(proxyPkg);
-                    pw.print(", attributionTag=");
-                    pw.print(proxyAttributionTag);
-                    pw.print("]");
-                }
-                pw.println();
-            }
-        }
-
-        final AttributedOp attributedOp = op.mAttributions.get(attributionTag);
-        if (attributedOp.isRunning()) {
-            long earliestElapsedTime = Long.MAX_VALUE;
-            long maxNumStarts = 0;
-            int numInProgressEvents = attributedOp.mInProgressEvents.size();
-            for (int i = 0; i < numInProgressEvents; i++) {
-                AttributedOp.InProgressStartOpEvent event =
-                        attributedOp.mInProgressEvents.valueAt(i);
-
-                earliestElapsedTime = Math.min(earliestElapsedTime, event.getStartElapsedTime());
-                maxNumStarts = Math.max(maxNumStarts, event.mNumUnfinishedStarts);
-            }
-
-            pw.print(prefix + "Running start at: ");
-            TimeUtils.formatDuration(nowElapsed - earliestElapsedTime, pw);
-            pw.println();
-
-            if (maxNumStarts > 1) {
-                pw.print(prefix + "startNesting=");
-                pw.println(maxNumStarts);
-            }
-        }
-    }
-
-    @NeverCompile // Avoid size overhead of debugging code.
-    @Override
-    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (!DumpUtils.checkDumpAndUsageStatsPermission(mContext, TAG, pw)) return;
-
-        int dumpOp = OP_NONE;
-        String dumpPackage = null;
-        String dumpAttributionTag = null;
-        int dumpUid = Process.INVALID_UID;
-        int dumpMode = -1;
-        boolean dumpWatchers = false;
-        // TODO ntmyren: Remove the dumpHistory and dumpFilter
-        boolean dumpHistory = false;
-        boolean includeDiscreteOps = false;
-        boolean dumpUidStateChangeLogs = false;
-        int nDiscreteOps = 10;
-        @HistoricalOpsRequestFilter int dumpFilter = 0;
-        boolean dumpAll = false;
-
-        if (args != null) {
-            for (int i = 0; i < args.length; i++) {
-                String arg = args[i];
-                if ("-h".equals(arg)) {
-                    dumpHelp(pw);
-                    return;
-                } else if ("-a".equals(arg)) {
-                    // dump all data
-                    dumpAll = true;
-                } else if ("--op".equals(arg)) {
-                    i++;
-                    if (i >= args.length) {
-                        pw.println("No argument for --op option");
-                        return;
-                    }
-                    dumpOp = AppOpsService.Shell.strOpToOp(args[i], pw);
-                    dumpFilter |= FILTER_BY_OP_NAMES;
-                    if (dumpOp < 0) {
-                        return;
-                    }
-                } else if ("--package".equals(arg)) {
-                    i++;
-                    if (i >= args.length) {
-                        pw.println("No argument for --package option");
-                        return;
-                    }
-                    dumpPackage = args[i];
-                    dumpFilter |= FILTER_BY_PACKAGE_NAME;
-                    try {
-                        dumpUid = AppGlobals.getPackageManager().getPackageUid(dumpPackage,
-                                PackageManager.MATCH_KNOWN_PACKAGES | PackageManager.MATCH_INSTANT,
-                                0);
-                    } catch (RemoteException e) {
-                    }
-                    if (dumpUid < 0) {
-                        pw.println("Unknown package: " + dumpPackage);
-                        return;
-                    }
-                    dumpUid = UserHandle.getAppId(dumpUid);
-                    dumpFilter |= FILTER_BY_UID;
-                } else if ("--attributionTag".equals(arg)) {
-                    i++;
-                    if (i >= args.length) {
-                        pw.println("No argument for --attributionTag option");
-                        return;
-                    }
-                    dumpAttributionTag = args[i];
-                    dumpFilter |= FILTER_BY_ATTRIBUTION_TAG;
-                } else if ("--mode".equals(arg)) {
-                    i++;
-                    if (i >= args.length) {
-                        pw.println("No argument for --mode option");
-                        return;
-                    }
-                    dumpMode = AppOpsService.Shell.strModeToMode(args[i], pw);
-                    if (dumpMode < 0) {
-                        return;
-                    }
-                } else if ("--watchers".equals(arg)) {
-                    dumpWatchers = true;
-                } else if ("--include-discrete".equals(arg)) {
-                    i++;
-                    if (i >= args.length) {
-                        pw.println("No argument for --include-discrete option");
-                        return;
-                    }
-                    try {
-                        nDiscreteOps = Integer.valueOf(args[i]);
-                    } catch (NumberFormatException e) {
-                        pw.println("Wrong parameter: " + args[i]);
-                        return;
-                    }
-                    includeDiscreteOps = true;
-                } else if ("--history".equals(arg)) {
-                    dumpHistory = true;
-                } else if (arg.length() > 0 && arg.charAt(0) == '-') {
-                    pw.println("Unknown option: " + arg);
-                    return;
-                } else if ("--uid-state-changes".equals(arg)) {
-                    dumpUidStateChangeLogs = true;
-                } else {
-                    pw.println("Unknown command: " + arg);
-                    return;
-                }
-            }
-        }
-
-        final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
-        final Date date = new Date();
-        synchronized (this) {
-            pw.println("Current AppOps Service state:");
-            if (!dumpHistory && !dumpWatchers) {
-                mConstants.dump(pw);
-            }
-            pw.println();
-            final long now = System.currentTimeMillis();
-            final long nowElapsed = SystemClock.elapsedRealtime();
-            boolean needSep = false;
-            if (dumpFilter == 0 && dumpMode < 0 && mProfileOwners != null && !dumpWatchers
-                    && !dumpHistory) {
-                pw.println("  Profile owners:");
-                for (int poi = 0; poi < mProfileOwners.size(); poi++) {
-                    pw.print("    User #");
-                    pw.print(mProfileOwners.keyAt(poi));
-                    pw.print(": ");
-                    UserHandle.formatUid(pw, mProfileOwners.valueAt(poi));
-                    pw.println();
-                }
-                pw.println();
-            }
-
-            if (!dumpHistory) {
-                needSep |= mAppOpsServiceInterface.dumpListeners(dumpOp, dumpUid, dumpPackage, pw);
-            }
-
-            if (mModeWatchers.size() > 0 && dumpOp < 0 && !dumpHistory) {
-                boolean printedHeader = false;
-                for (int i = 0; i < mModeWatchers.size(); i++) {
-                    final ModeCallback cb = mModeWatchers.valueAt(i);
-                    if (dumpPackage != null
-                            && dumpUid != UserHandle.getAppId(cb.getWatchingUid())) {
-                        continue;
-                    }
-                    needSep = true;
-                    if (!printedHeader) {
-                        pw.println("  All op mode watchers:");
-                        printedHeader = true;
-                    }
-                    pw.print("    ");
-                    pw.print(Integer.toHexString(System.identityHashCode(mModeWatchers.keyAt(i))));
-                    pw.print(": ");
-                    pw.println(cb);
-                }
-            }
-            if (mActiveWatchers.size() > 0 && dumpMode < 0) {
-                needSep = true;
-                boolean printedHeader = false;
-                for (int watcherNum = 0; watcherNum < mActiveWatchers.size(); watcherNum++) {
-                    final SparseArray<ActiveCallback> activeWatchers =
-                            mActiveWatchers.valueAt(watcherNum);
-                    if (activeWatchers.size() <= 0) {
-                        continue;
-                    }
-                    final ActiveCallback cb = activeWatchers.valueAt(0);
-                    if (dumpOp >= 0 && activeWatchers.indexOfKey(dumpOp) < 0) {
-                        continue;
-                    }
-                    if (dumpPackage != null
-                            && dumpUid != UserHandle.getAppId(cb.mWatchingUid)) {
-                        continue;
-                    }
-                    if (!printedHeader) {
-                        pw.println("  All op active watchers:");
-                        printedHeader = true;
-                    }
-                    pw.print("    ");
-                    pw.print(Integer.toHexString(System.identityHashCode(
-                            mActiveWatchers.keyAt(watcherNum))));
-                    pw.println(" ->");
-                    pw.print("        [");
-                    final int opCount = activeWatchers.size();
-                    for (int opNum = 0; opNum < opCount; opNum++) {
-                        if (opNum > 0) {
-                            pw.print(' ');
-                        }
-                        pw.print(AppOpsManager.opToName(activeWatchers.keyAt(opNum)));
-                        if (opNum < opCount - 1) {
-                            pw.print(',');
-                        }
-                    }
-                    pw.println("]");
-                    pw.print("        ");
-                    pw.println(cb);
-                }
-            }
-            if (mStartedWatchers.size() > 0 && dumpMode < 0) {
-                needSep = true;
-                boolean printedHeader = false;
-
-                final int watchersSize = mStartedWatchers.size();
-                for (int watcherNum = 0; watcherNum < watchersSize; watcherNum++) {
-                    final SparseArray<StartedCallback> startedWatchers =
-                            mStartedWatchers.valueAt(watcherNum);
-                    if (startedWatchers.size() <= 0) {
-                        continue;
-                    }
-
-                    final StartedCallback cb = startedWatchers.valueAt(0);
-                    if (dumpOp >= 0 && startedWatchers.indexOfKey(dumpOp) < 0) {
-                        continue;
-                    }
-
-                    if (dumpPackage != null
-                            && dumpUid != UserHandle.getAppId(cb.mWatchingUid)) {
-                        continue;
-                    }
-
-                    if (!printedHeader) {
-                        pw.println("  All op started watchers:");
-                        printedHeader = true;
-                    }
-
-                    pw.print("    ");
-                    pw.print(Integer.toHexString(System.identityHashCode(
-                            mStartedWatchers.keyAt(watcherNum))));
-                    pw.println(" ->");
-
-                    pw.print("        [");
-                    final int opCount = startedWatchers.size();
-                    for (int opNum = 0; opNum < opCount; opNum++) {
-                        if (opNum > 0) {
-                            pw.print(' ');
-                        }
-
-                        pw.print(AppOpsManager.opToName(startedWatchers.keyAt(opNum)));
-                        if (opNum < opCount - 1) {
-                            pw.print(',');
-                        }
-                    }
-                    pw.println("]");
-
-                    pw.print("        ");
-                    pw.println(cb);
-                }
-            }
-            if (mNotedWatchers.size() > 0 && dumpMode < 0) {
-                needSep = true;
-                boolean printedHeader = false;
-                for (int watcherNum = 0; watcherNum < mNotedWatchers.size(); watcherNum++) {
-                    final SparseArray<NotedCallback> notedWatchers =
-                            mNotedWatchers.valueAt(watcherNum);
-                    if (notedWatchers.size() <= 0) {
-                        continue;
-                    }
-                    final NotedCallback cb = notedWatchers.valueAt(0);
-                    if (dumpOp >= 0 && notedWatchers.indexOfKey(dumpOp) < 0) {
-                        continue;
-                    }
-                    if (dumpPackage != null
-                            && dumpUid != UserHandle.getAppId(cb.mWatchingUid)) {
-                        continue;
-                    }
-                    if (!printedHeader) {
-                        pw.println("  All op noted watchers:");
-                        printedHeader = true;
-                    }
-                    pw.print("    ");
-                    pw.print(Integer.toHexString(System.identityHashCode(
-                            mNotedWatchers.keyAt(watcherNum))));
-                    pw.println(" ->");
-                    pw.print("        [");
-                    final int opCount = notedWatchers.size();
-                    for (int opNum = 0; opNum < opCount; opNum++) {
-                        if (opNum > 0) {
-                            pw.print(' ');
-                        }
-                        pw.print(AppOpsManager.opToName(notedWatchers.keyAt(opNum)));
-                        if (opNum < opCount - 1) {
-                            pw.print(',');
-                        }
-                    }
-                    pw.println("]");
-                    pw.print("        ");
-                    pw.println(cb);
-                }
-            }
-            if (needSep) {
-                pw.println();
-            }
-            for (int i = 0; i < mUidStates.size(); i++) {
-                UidState uidState = mUidStates.valueAt(i);
-                final SparseIntArray opModes = uidState.getNonDefaultUidModes();
-                final ArrayMap<String, Ops> pkgOps = uidState.pkgOps;
-
-                if (dumpWatchers || dumpHistory) {
-                    continue;
-                }
-                if (dumpOp >= 0 || dumpPackage != null || dumpMode >= 0) {
-                    boolean hasOp = dumpOp < 0 || (opModes != null
-                            && opModes.indexOfKey(dumpOp) >= 0);
-                    boolean hasPackage = dumpPackage == null || dumpUid == mUidStates.keyAt(i);
-                    boolean hasMode = dumpMode < 0;
-                    if (!hasMode && opModes != null) {
-                        for (int opi = 0; !hasMode && opi < opModes.size(); opi++) {
-                            if (opModes.valueAt(opi) == dumpMode) {
-                                hasMode = true;
-                            }
-                        }
-                    }
-                    if (pkgOps != null) {
-                        for (int pkgi = 0;
-                                (!hasOp || !hasPackage || !hasMode) && pkgi < pkgOps.size();
-                                pkgi++) {
-                            Ops ops = pkgOps.valueAt(pkgi);
-                            if (!hasOp && ops != null && ops.indexOfKey(dumpOp) >= 0) {
-                                hasOp = true;
-                            }
-                            if (!hasMode) {
-                                for (int opi = 0; !hasMode && opi < ops.size(); opi++) {
-                                    if (ops.valueAt(opi).getMode() == dumpMode) {
-                                        hasMode = true;
-                                    }
-                                }
-                            }
-                            if (!hasPackage && dumpPackage.equals(ops.packageName)) {
-                                hasPackage = true;
-                            }
-                        }
-                    }
-                    if (uidState.foregroundOps != null && !hasOp) {
-                        if (uidState.foregroundOps.indexOfKey(dumpOp) > 0) {
-                            hasOp = true;
-                        }
-                    }
-                    if (!hasOp || !hasPackage || !hasMode) {
-                        continue;
-                    }
-                }
-
-                pw.print("  Uid ");
-                UserHandle.formatUid(pw, uidState.uid);
-                pw.println(":");
-                uidState.dump(pw, nowElapsed);
-                if (uidState.foregroundOps != null && (dumpMode < 0
-                        || dumpMode == AppOpsManager.MODE_FOREGROUND)) {
-                    pw.println("    foregroundOps:");
-                    for (int j = 0; j < uidState.foregroundOps.size(); j++) {
-                        if (dumpOp >= 0 && dumpOp != uidState.foregroundOps.keyAt(j)) {
-                            continue;
-                        }
-                        pw.print("      ");
-                        pw.print(AppOpsManager.opToName(uidState.foregroundOps.keyAt(j)));
-                        pw.print(": ");
-                        pw.println(uidState.foregroundOps.valueAt(j) ? "WATCHER" : "SILENT");
-                    }
-                    pw.print("    hasForegroundWatchers=");
-                    pw.println(uidState.hasForegroundWatchers);
-                }
-                needSep = true;
-
-                if (opModes != null) {
-                    final int opModeCount = opModes.size();
-                    for (int j = 0; j < opModeCount; j++) {
-                        final int code = opModes.keyAt(j);
-                        final int mode = opModes.valueAt(j);
-                        if (dumpOp >= 0 && dumpOp != code) {
-                            continue;
-                        }
-                        if (dumpMode >= 0 && dumpMode != mode) {
-                            continue;
-                        }
-                        pw.print("      ");
-                        pw.print(AppOpsManager.opToName(code));
-                        pw.print(": mode=");
-                        pw.println(AppOpsManager.modeToName(mode));
-                    }
-                }
-
-                if (pkgOps == null) {
-                    continue;
-                }
-
-                for (int pkgi = 0; pkgi < pkgOps.size(); pkgi++) {
-                    final Ops ops = pkgOps.valueAt(pkgi);
-                    if (dumpPackage != null && !dumpPackage.equals(ops.packageName)) {
-                        continue;
-                    }
-                    boolean printedPackage = false;
-                    for (int j = 0; j < ops.size(); j++) {
-                        final Op op = ops.valueAt(j);
-                        final int opCode = op.op;
-                        if (dumpOp >= 0 && dumpOp != opCode) {
-                            continue;
-                        }
-                        if (dumpMode >= 0 && dumpMode != op.getMode()) {
-                            continue;
-                        }
-                        if (!printedPackage) {
-                            pw.print("    Package ");
-                            pw.print(ops.packageName);
-                            pw.println(":");
-                            printedPackage = true;
-                        }
-                        pw.print("      ");
-                        pw.print(AppOpsManager.opToName(opCode));
-                        pw.print(" (");
-                        pw.print(AppOpsManager.modeToName(op.getMode()));
-                        final int switchOp = AppOpsManager.opToSwitch(opCode);
-                        if (switchOp != opCode) {
-                            pw.print(" / switch ");
-                            pw.print(AppOpsManager.opToName(switchOp));
-                            final Op switchObj = ops.get(switchOp);
-                            int mode = switchObj == null
-                                    ? AppOpsManager.opToDefaultMode(switchOp) : switchObj.getMode();
-                            pw.print("=");
-                            pw.print(AppOpsManager.modeToName(mode));
-                        }
-                        pw.println("): ");
-                        dumpStatesLocked(pw, dumpAttributionTag, dumpFilter, nowElapsed, op, now,
-                                sdf, date, "        ");
-                    }
-                }
-            }
-            if (needSep) {
-                pw.println();
-            }
-
-            boolean showUserRestrictions = !(dumpMode < 0 && !dumpWatchers && !dumpHistory);
-            mAppOpsRestrictions.dumpRestrictions(pw, dumpOp, dumpPackage, showUserRestrictions);
-
-            if (dumpAll || dumpUidStateChangeLogs) {
-                pw.println();
-                pw.println("Uid State Changes Event Log:");
-                getUidStateTracker().dumpEvents(pw);
-            }
-        }
-
-        // Must not hold the appops lock
-        if (dumpHistory && !dumpWatchers) {
-            mHistoricalRegistry.dump("  ", pw, dumpUid, dumpPackage, dumpAttributionTag, dumpOp,
-                    dumpFilter);
-        }
-        if (includeDiscreteOps) {
-            pw.println("Discrete accesses: ");
-            mHistoricalRegistry.dumpDiscreteData(pw, dumpUid, dumpPackage, dumpAttributionTag,
-                    dumpFilter, dumpOp, sdf, date, "  ", nDiscreteOps);
-        }
-    }
-
-    @Override
-    public void setUserRestrictions(Bundle restrictions, IBinder token, int userHandle) {
-        checkSystemUid("setUserRestrictions");
-        Objects.requireNonNull(restrictions);
-        Objects.requireNonNull(token);
-        for (int i = 0; i < AppOpsManager._NUM_OP; i++) {
-            String restriction = AppOpsManager.opToRestriction(i);
-            if (restriction != null) {
-                setUserRestrictionNoCheck(i, restrictions.getBoolean(restriction, false), token,
-                        userHandle, null);
-            }
-        }
-    }
-
-    @Override
-    public void setUserRestriction(int code, boolean restricted, IBinder token, int userHandle,
-            PackageTagsList excludedPackageTags) {
-        if (Binder.getCallingPid() != Process.myPid()) {
-            mContext.enforcePermission(Manifest.permission.MANAGE_APP_OPS_RESTRICTIONS,
-                    Binder.getCallingPid(), Binder.getCallingUid(), null);
-        }
-        if (userHandle != UserHandle.getCallingUserId()) {
-            if (mContext.checkCallingOrSelfPermission(Manifest.permission
-                    .INTERACT_ACROSS_USERS_FULL) != PackageManager.PERMISSION_GRANTED
-                    && mContext.checkCallingOrSelfPermission(Manifest.permission
-                    .INTERACT_ACROSS_USERS) != PackageManager.PERMISSION_GRANTED) {
-                throw new SecurityException("Need INTERACT_ACROSS_USERS_FULL or"
-                        + " INTERACT_ACROSS_USERS to interact cross user ");
-            }
-        }
-        verifyIncomingOp(code);
-        Objects.requireNonNull(token);
-        setUserRestrictionNoCheck(code, restricted, token, userHandle, excludedPackageTags);
-    }
-
-    private void setUserRestrictionNoCheck(int code, boolean restricted, IBinder token,
-            int userHandle, PackageTagsList excludedPackageTags) {
-        synchronized (AppOpsServiceImpl.this) {
-            ClientUserRestrictionState restrictionState = mOpUserRestrictions.get(token);
-
-            if (restrictionState == null) {
-                try {
-                    restrictionState = new ClientUserRestrictionState(token);
-                } catch (RemoteException e) {
-                    return;
-                }
-                mOpUserRestrictions.put(token, restrictionState);
-            }
-
-            if (restrictionState.setRestriction(code, restricted, excludedPackageTags,
-                    userHandle)) {
-                mHandler.sendMessage(PooledLambda.obtainMessage(
-                        AppOpsServiceImpl::notifyWatchersOfChange, this, code, UID_ANY));
-                mHandler.sendMessage(PooledLambda.obtainMessage(
-                        AppOpsServiceImpl::updateStartedOpModeForUser, this, code,
-                        restricted, userHandle));
-            }
-
-            if (restrictionState.isDefault()) {
-                mOpUserRestrictions.remove(token);
-                restrictionState.destroy();
-            }
-        }
-    }
-
-    @Override
-    public void setGlobalRestriction(int code, boolean restricted, IBinder token) {
-        if (Binder.getCallingPid() != Process.myPid()) {
-            throw new SecurityException("Only the system can set global restrictions");
-        }
-
-        synchronized (this) {
-            ClientGlobalRestrictionState restrictionState = mOpGlobalRestrictions.get(token);
-
-            if (restrictionState == null) {
-                try {
-                    restrictionState = new ClientGlobalRestrictionState(token);
-                } catch (RemoteException e) {
-                    return;
-                }
-                mOpGlobalRestrictions.put(token, restrictionState);
-            }
-
-            if (restrictionState.setRestriction(code, restricted)) {
-                mHandler.sendMessage(PooledLambda.obtainMessage(
-                        AppOpsServiceImpl::notifyWatchersOfChange, this, code, UID_ANY));
-                mHandler.sendMessage(PooledLambda.obtainMessage(
-                        AppOpsServiceImpl::updateStartedOpModeForUser, this, code,
-                        restricted, UserHandle.USER_ALL));
-            }
-
-            if (restrictionState.isDefault()) {
-                mOpGlobalRestrictions.remove(token);
-                restrictionState.destroy();
-            }
-        }
-    }
-
-    @Override
-    public int getOpRestrictionCount(int code, UserHandle user, String pkg,
-            String attributionTag) {
-        int number = 0;
-        synchronized (this) {
-            int numRestrictions = mOpUserRestrictions.size();
-            for (int i = 0; i < numRestrictions; i++) {
-                if (mOpUserRestrictions.valueAt(i)
-                        .hasRestriction(code, pkg, attributionTag, user.getIdentifier(),
-                                false)) {
-                    number++;
-                }
-            }
-
-            numRestrictions = mOpGlobalRestrictions.size();
-            for (int i = 0; i < numRestrictions; i++) {
-                if (mOpGlobalRestrictions.valueAt(i).hasRestriction(code)) {
-                    number++;
-                }
-            }
-        }
-
-        return number;
-    }
-
-    private void updateStartedOpModeForUser(int code, boolean restricted, int userId) {
-        synchronized (AppOpsServiceImpl.this) {
-            int numUids = mUidStates.size();
-            for (int uidNum = 0; uidNum < numUids; uidNum++) {
-                int uid = mUidStates.keyAt(uidNum);
-                if (userId != UserHandle.USER_ALL && UserHandle.getUserId(uid) != userId) {
-                    continue;
-                }
-                updateStartedOpModeForUidLocked(code, restricted, uid);
-            }
-        }
-    }
-
-    private void updateStartedOpModeForUidLocked(int code, boolean restricted, int uid) {
-        UidState uidState = mUidStates.get(uid);
-        if (uidState == null || uidState.pkgOps == null) {
-            return;
-        }
-
-        int numPkgOps = uidState.pkgOps.size();
-        for (int pkgNum = 0; pkgNum < numPkgOps; pkgNum++) {
-            Ops ops = uidState.pkgOps.valueAt(pkgNum);
-            Op op = ops != null ? ops.get(code) : null;
-            if (op == null || (op.getMode() != MODE_ALLOWED && op.getMode() != MODE_FOREGROUND)) {
-                continue;
-            }
-            int numAttrTags = op.mAttributions.size();
-            for (int attrNum = 0; attrNum < numAttrTags; attrNum++) {
-                AttributedOp attrOp = op.mAttributions.valueAt(attrNum);
-                if (restricted && attrOp.isRunning()) {
-                    attrOp.pause();
-                } else if (attrOp.isPaused()) {
-                    attrOp.resume();
-                }
-            }
-        }
-    }
-
-    @Override
-    public void notifyWatchersOfChange(int code, int uid) {
-        final ArraySet<OnOpModeChangedListener> modeChangedListenerSet;
-        synchronized (this) {
-            modeChangedListenerSet = mAppOpsServiceInterface.getOpModeChangedListeners(code);
-            if (modeChangedListenerSet == null) {
-                return;
-            }
-        }
-
-        notifyOpChanged(modeChangedListenerSet, code, uid, null);
-    }
-
-    @Override
-    public void removeUser(int userHandle) throws RemoteException {
-        checkSystemUid("removeUser");
-        synchronized (AppOpsServiceImpl.this) {
-            final int tokenCount = mOpUserRestrictions.size();
-            for (int i = tokenCount - 1; i >= 0; i--) {
-                ClientUserRestrictionState opRestrictions = mOpUserRestrictions.valueAt(i);
-                opRestrictions.removeUser(userHandle);
-            }
-            removeUidsForUserLocked(userHandle);
-        }
-    }
-
-    @Override
-    public boolean isOperationActive(int code, int uid, String packageName) {
-        if (Binder.getCallingUid() != uid) {
-            if (mContext.checkCallingOrSelfPermission(Manifest.permission.WATCH_APPOPS)
-                    != PackageManager.PERMISSION_GRANTED) {
-                return false;
-            }
-        }
-        verifyIncomingOp(code);
-        if (!isIncomingPackageValid(packageName, UserHandle.getUserId(uid))) {
-            return false;
-        }
-
-        final String resolvedPackageName = AppOpsManager.resolvePackageName(uid, packageName);
-        if (resolvedPackageName == null) {
-            return false;
-        }
-        // TODO moltmann: Allow to check for attribution op activeness
-        synchronized (AppOpsServiceImpl.this) {
-            Ops pkgOps = getOpsLocked(uid, resolvedPackageName, null, false, null, false);
-            if (pkgOps == null) {
-                return false;
-            }
-
-            Op op = pkgOps.get(code);
-            if (op == null) {
-                return false;
-            }
-
-            return op.isRunning();
-        }
-    }
-
-    @Override
-    public boolean isProxying(int op, @NonNull String proxyPackageName,
-            @NonNull String proxyAttributionTag, int proxiedUid,
-            @NonNull String proxiedPackageName) {
-        Objects.requireNonNull(proxyPackageName);
-        Objects.requireNonNull(proxiedPackageName);
-        final long callingUid = Binder.getCallingUid();
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            final List<AppOpsManager.PackageOps> packageOps = getOpsForPackage(proxiedUid,
-                    proxiedPackageName, new int[]{op});
-            if (packageOps == null || packageOps.isEmpty()) {
-                return false;
-            }
-            final List<OpEntry> opEntries = packageOps.get(0).getOps();
-            if (opEntries.isEmpty()) {
-                return false;
-            }
-            final OpEntry opEntry = opEntries.get(0);
-            if (!opEntry.isRunning()) {
-                return false;
-            }
-            final OpEventProxyInfo proxyInfo = opEntry.getLastProxyInfo(
-                    OP_FLAG_TRUSTED_PROXIED | AppOpsManager.OP_FLAG_UNTRUSTED_PROXIED);
-            return proxyInfo != null && callingUid == proxyInfo.getUid()
-                    && proxyPackageName.equals(proxyInfo.getPackageName())
-                    && Objects.equals(proxyAttributionTag, proxyInfo.getAttributionTag());
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    @Override
-    public void resetPackageOpsNoHistory(@NonNull String packageName) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_APPOPS,
-                "resetPackageOpsNoHistory");
-        synchronized (AppOpsServiceImpl.this) {
-            final int uid = mPackageManagerInternal.getPackageUid(packageName, 0,
-                    UserHandle.getCallingUserId());
-            if (uid == Process.INVALID_UID) {
-                return;
-            }
-            UidState uidState = mUidStates.get(uid);
-            if (uidState == null || uidState.pkgOps == null) {
-                return;
-            }
-            Ops removedOps = uidState.pkgOps.remove(packageName);
-            mAppOpsServiceInterface.removePackage(packageName, UserHandle.getUserId(uid));
-            if (removedOps != null) {
-                scheduleFastWriteLocked();
-            }
-        }
-    }
-
-    @Override
-    public void setHistoryParameters(@AppOpsManager.HistoricalMode int mode,
-            long baseSnapshotInterval, int compressionStep) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_APPOPS,
-                "setHistoryParameters");
-        // Must not hold the appops lock
-        mHistoricalRegistry.setHistoryParameters(mode, baseSnapshotInterval, compressionStep);
-    }
-
-    @Override
-    public void offsetHistory(long offsetMillis) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_APPOPS,
-                "offsetHistory");
-        // Must not hold the appops lock
-        mHistoricalRegistry.offsetHistory(offsetMillis);
-        mHistoricalRegistry.offsetDiscreteHistory(offsetMillis);
-    }
-
-    @Override
-    public void addHistoricalOps(HistoricalOps ops) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_APPOPS,
-                "addHistoricalOps");
-        // Must not hold the appops lock
-        mHistoricalRegistry.addHistoricalOps(ops);
-    }
-
-    @Override
-    public void resetHistoryParameters() {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_APPOPS,
-                "resetHistoryParameters");
-        // Must not hold the appops lock
-        mHistoricalRegistry.resetHistoryParameters();
-    }
-
-    @Override
-    public void clearHistory() {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_APPOPS,
-                "clearHistory");
-        // Must not hold the appops lock
-        mHistoricalRegistry.clearAllHistory();
-    }
-
-    @Override
-    public void rebootHistory(long offlineDurationMillis) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_APPOPS,
-                "rebootHistory");
-
-        Preconditions.checkArgument(offlineDurationMillis >= 0);
-
-        // Must not hold the appops lock
-        mHistoricalRegistry.shutdown();
-
-        if (offlineDurationMillis > 0) {
-            SystemClock.sleep(offlineDurationMillis);
-        }
-
-        mHistoricalRegistry = new HistoricalRegistry(mHistoricalRegistry);
-        mHistoricalRegistry.systemReady(mContext.getContentResolver());
-        mHistoricalRegistry.persistPendingHistory();
-    }
-
-    @GuardedBy("this")
-    private void removeUidsForUserLocked(int userHandle) {
-        for (int i = mUidStates.size() - 1; i >= 0; --i) {
-            final int uid = mUidStates.keyAt(i);
-            if (UserHandle.getUserId(uid) == userHandle) {
-                mUidStates.valueAt(i).clear();
-                mUidStates.removeAt(i);
-            }
-        }
-    }
-
-    private void checkSystemUid(String function) {
-        int uid = Binder.getCallingUid();
-        if (uid != Process.SYSTEM_UID) {
-            throw new SecurityException(function + " must by called by the system");
-        }
-    }
-
-    private static int resolveUid(String packageName) {
-        if (packageName == null) {
-            return Process.INVALID_UID;
-        }
-        switch (packageName) {
-            case "root":
-                return Process.ROOT_UID;
-            case "shell":
-            case "dumpstate":
-                return Process.SHELL_UID;
-            case "media":
-                return Process.MEDIA_UID;
-            case "audioserver":
-                return Process.AUDIOSERVER_UID;
-            case "cameraserver":
-                return Process.CAMERASERVER_UID;
-        }
-        return Process.INVALID_UID;
-    }
-
-    private static String[] getPackagesForUid(int uid) {
-        String[] packageNames = null;
-
-        // Very early during boot the package manager is not yet or not yet fully started. At this
-        // time there are no packages yet.
-        if (AppGlobals.getPackageManager() != null) {
-            try {
-                packageNames = AppGlobals.getPackageManager().getPackagesForUid(uid);
-            } catch (RemoteException e) {
-                /* ignore - local call */
-            }
-        }
-        if (packageNames == null) {
-            return EmptyArray.STRING;
-        }
-        return packageNames;
-    }
-
-    private final class ClientUserRestrictionState implements DeathRecipient {
-        private final IBinder mToken;
-
-        ClientUserRestrictionState(IBinder token)
-                throws RemoteException {
-            token.linkToDeath(this, 0);
-            this.mToken = token;
-        }
-
-        public boolean setRestriction(int code, boolean restricted,
-                PackageTagsList excludedPackageTags, int userId) {
-            return mAppOpsRestrictions.setUserRestriction(mToken, userId, code,
-                    restricted, excludedPackageTags);
-        }
-
-        public boolean hasRestriction(int code, String packageName, String attributionTag,
-                int userId, boolean isCheckOp) {
-            return mAppOpsRestrictions.getUserRestriction(mToken, userId, code, packageName,
-                    attributionTag, isCheckOp);
-        }
-
-        public void removeUser(int userId) {
-            mAppOpsRestrictions.clearUserRestrictions(mToken, userId);
-        }
-
-        public boolean isDefault() {
-            return !mAppOpsRestrictions.hasUserRestrictions(mToken);
-        }
-
-        @Override
-        public void binderDied() {
-            synchronized (AppOpsServiceImpl.this) {
-                mAppOpsRestrictions.clearUserRestrictions(mToken);
-                mOpUserRestrictions.remove(mToken);
-                destroy();
-            }
-        }
-
-        public void destroy() {
-            mToken.unlinkToDeath(this, 0);
-        }
-    }
-
-    private final class ClientGlobalRestrictionState implements DeathRecipient {
-        final IBinder mToken;
-
-        ClientGlobalRestrictionState(IBinder token)
-                throws RemoteException {
-            token.linkToDeath(this, 0);
-            this.mToken = token;
-        }
-
-        boolean setRestriction(int code, boolean restricted) {
-            return mAppOpsRestrictions.setGlobalRestriction(mToken, code, restricted);
-        }
-
-        boolean hasRestriction(int code) {
-            return mAppOpsRestrictions.getGlobalRestriction(mToken, code);
-        }
-
-        boolean isDefault() {
-            return !mAppOpsRestrictions.hasGlobalRestrictions(mToken);
-        }
-
-        @Override
-        public void binderDied() {
-            mAppOpsRestrictions.clearGlobalRestrictions(mToken);
-            mOpGlobalRestrictions.remove(mToken);
-            destroy();
-        }
-
-        void destroy() {
-            mToken.unlinkToDeath(this, 0);
-        }
-    }
-
-    @Override
-    public void setDeviceAndProfileOwners(SparseIntArray owners) {
-        synchronized (this) {
-            mProfileOwners = owners;
-        }
-    }
-}
diff --git a/services/core/java/com/android/server/appop/AppOpsServiceInterface.java b/services/core/java/com/android/server/appop/AppOpsServiceInterface.java
deleted file mode 100644
index 8420fcb..0000000
--- a/services/core/java/com/android/server/appop/AppOpsServiceInterface.java
+++ /dev/null
@@ -1,494 +0,0 @@
-/*
- * 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.server.appop;
-
-import android.annotation.NonNull;
-import android.annotation.Nullable;
-import android.app.ActivityManager;
-import android.app.AppOpsManager;
-import android.content.AttributionSource;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.os.PackageTagsList;
-import android.os.RemoteCallback;
-import android.os.RemoteException;
-import android.os.UserHandle;
-import android.util.SparseArray;
-import android.util.SparseIntArray;
-
-import com.android.internal.app.IAppOpsActiveCallback;
-import com.android.internal.app.IAppOpsCallback;
-import com.android.internal.app.IAppOpsNotedCallback;
-import com.android.internal.app.IAppOpsStartedCallback;
-
-import dalvik.annotation.optimization.NeverCompile;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-import java.util.List;
-
-/**
- *
- */
-public interface AppOpsServiceInterface extends PersistenceScheduler {
-
-    /**
-     *
-     */
-    void systemReady();
-
-    /**
-     *
-     */
-    void shutdown();
-
-    /**
-     *
-     * @param uid
-     * @param packageName
-     */
-    void verifyPackage(int uid, String packageName);
-
-    /**
-     *
-     * @param op
-     * @param packageName
-     * @param flags
-     * @param callback
-     */
-    void startWatchingModeWithFlags(int op, String packageName, int flags,
-            IAppOpsCallback callback);
-
-    /**
-     *
-     * @param callback
-     */
-    void stopWatchingMode(IAppOpsCallback callback);
-
-    /**
-     *
-     * @param ops
-     * @param callback
-     */
-    void startWatchingActive(int[] ops, IAppOpsActiveCallback callback);
-
-    /**
-     *
-     * @param callback
-     */
-    void stopWatchingActive(IAppOpsActiveCallback callback);
-
-    /**
-     *
-     * @param ops
-     * @param callback
-     */
-    void startWatchingStarted(int[] ops, @NonNull IAppOpsStartedCallback callback);
-
-    /**
-     *
-     * @param callback
-     */
-    void stopWatchingStarted(IAppOpsStartedCallback callback);
-
-    /**
-     *
-     * @param ops
-     * @param callback
-     */
-    void startWatchingNoted(@NonNull int[] ops, @NonNull IAppOpsNotedCallback callback);
-
-    /**
-     *
-     * @param callback
-     */
-    void stopWatchingNoted(IAppOpsNotedCallback callback);
-
-    /**
-     * @param clientId
-     * @param code
-     * @param uid
-     * @param packageName
-     * @param attributionTag
-     * @param startIfModeDefault
-     * @param message
-     * @param attributionFlags
-     * @param attributionChainId
-     * @return
-     */
-    int startOperation(@NonNull IBinder clientId, int code, int uid,
-            @Nullable String packageName, @Nullable String attributionTag,
-            boolean startIfModeDefault, @NonNull String message,
-            @AppOpsManager.AttributionFlags int attributionFlags,
-            int attributionChainId);
-
-
-    int startOperationUnchecked(IBinder clientId, int code, int uid, @NonNull String packageName,
-            @Nullable String attributionTag, int proxyUid, String proxyPackageName,
-            @Nullable String proxyAttributionTag, @AppOpsManager.OpFlags int flags,
-            boolean startIfModeDefault, @AppOpsManager.AttributionFlags int attributionFlags,
-            int attributionChainId, boolean dryRun);
-
-    /**
-     *
-     * @param clientId
-     * @param code
-     * @param uid
-     * @param packageName
-     * @param attributionTag
-     */
-    void finishOperation(IBinder clientId, int code, int uid, String packageName,
-            String attributionTag);
-
-    /**
-     *
-     * @param clientId
-     * @param code
-     * @param uid
-     * @param packageName
-     * @param attributionTag
-     */
-    void finishOperationUnchecked(IBinder clientId, int code, int uid, String packageName,
-            String attributionTag);
-
-    /**
-     *
-     * @param uidPackageNames
-     * @param visible
-     */
-    void updateAppWidgetVisibility(SparseArray<String> uidPackageNames, boolean visible);
-
-    /**
-     *
-     */
-    void readState();
-
-    /**
-     *
-     */
-    void writeState();
-
-    /**
-     *
-     * @param uid
-     * @param packageName
-     */
-    void packageRemoved(int uid, String packageName);
-
-    /**
-     *
-     * @param uid
-     */
-    void uidRemoved(int uid);
-
-    /**
-     *
-     * @param uid
-     * @param procState
-     * @param capability
-     */
-    void updateUidProcState(int uid, int procState,
-            @ActivityManager.ProcessCapability int capability);
-
-    /**
-     *
-     * @param ops
-     * @return
-     */
-    List<AppOpsManager.PackageOps> getPackagesForOps(int[] ops);
-
-    /**
-     *
-     * @param uid
-     * @param packageName
-     * @param ops
-     * @return
-     */
-    List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName,
-            int[] ops);
-
-    /**
-     *
-     * @param uid
-     * @param packageName
-     * @param attributionTag
-     * @param opNames
-     * @param dataType
-     * @param filter
-     * @param beginTimeMillis
-     * @param endTimeMillis
-     * @param flags
-     * @param callback
-     */
-    void getHistoricalOps(int uid, String packageName, String attributionTag,
-            List<String> opNames, int dataType, int filter, long beginTimeMillis,
-            long endTimeMillis, int flags, RemoteCallback callback);
-
-    /**
-     *
-     * @param uid
-     * @param packageName
-     * @param attributionTag
-     * @param opNames
-     * @param dataType
-     * @param filter
-     * @param beginTimeMillis
-     * @param endTimeMillis
-     * @param flags
-     * @param callback
-     */
-    void getHistoricalOpsFromDiskRaw(int uid, String packageName, String attributionTag,
-            List<String> opNames, int dataType, int filter, long beginTimeMillis,
-            long endTimeMillis, int flags, RemoteCallback callback);
-
-    /**
-     *
-     */
-    void reloadNonHistoricalState();
-
-    /**
-     *
-     * @param uid
-     * @param ops
-     * @return
-     */
-    List<AppOpsManager.PackageOps> getUidOps(int uid, int[] ops);
-
-    /**
-     *
-     * @param owners
-     */
-    void setDeviceAndProfileOwners(SparseIntArray owners);
-
-    // used in audio restriction calls, might just copy the logic to avoid having this call.
-    /**
-     *
-     * @param callingPid
-     * @param callingUid
-     * @param targetUid
-     */
-    void enforceManageAppOpsModes(int callingPid, int callingUid, int targetUid);
-
-    /**
-     *
-     * @param code
-     * @param uid
-     * @param mode
-     * @param permissionPolicyCallback
-     */
-    void setUidMode(int code, int uid, int mode,
-            @Nullable IAppOpsCallback permissionPolicyCallback);
-
-    /**
-     *
-     * @param code
-     * @param uid
-     * @param packageName
-     * @param mode
-     * @param permissionPolicyCallback
-     */
-    void setMode(int code, int uid, @NonNull String packageName, int mode,
-            @Nullable IAppOpsCallback permissionPolicyCallback);
-
-    /**
-     *
-     * @param reqUserId
-     * @param reqPackageName
-     */
-    void resetAllModes(int reqUserId, String reqPackageName);
-
-    /**
-     *
-     * @param code
-     * @param uid
-     * @param packageName
-     * @param attributionTag
-     * @param raw
-     * @return
-     */
-    int checkOperation(int code, int uid, String packageName,
-            @Nullable String attributionTag, boolean raw);
-
-    /**
-     *
-     * @param uid
-     * @param packageName
-     * @return
-     */
-    int checkPackage(int uid, String packageName);
-
-    /**
-     *
-     * @param code
-     * @param uid
-     * @param packageName
-     * @param attributionTag
-     * @param message
-     * @return
-     */
-    int noteOperation(int code, int uid, @Nullable String packageName,
-            @Nullable String attributionTag, @Nullable String message);
-
-    /**
-     *
-     * @param code
-     * @param uid
-     * @param packageName
-     * @param attributionTag
-     * @param proxyUid
-     * @param proxyPackageName
-     * @param proxyAttributionTag
-     * @param flags
-     * @return
-     */
-    @AppOpsManager.Mode
-    int noteOperationUnchecked(int code, int uid, @NonNull String packageName,
-            @Nullable String attributionTag, int proxyUid, String proxyPackageName,
-            @Nullable String proxyAttributionTag, @AppOpsManager.OpFlags int flags);
-
-    boolean isAttributionTagValid(int uid, @NonNull String packageName,
-            @Nullable String attributionTag, @Nullable String proxyPackageName);
-
-    /**
-     *
-     * @param fd
-     * @param pw
-     * @param args
-     */
-    @NeverCompile
-        // Avoid size overhead of debugging code.
-    void dump(FileDescriptor fd, PrintWriter pw, String[] args);
-
-    /**
-     *
-     * @param restrictions
-     * @param token
-     * @param userHandle
-     */
-    void setUserRestrictions(Bundle restrictions, IBinder token, int userHandle);
-
-    /**
-     *
-     * @param code
-     * @param restricted
-     * @param token
-     * @param userHandle
-     * @param excludedPackageTags
-     */
-    void setUserRestriction(int code, boolean restricted, IBinder token, int userHandle,
-            PackageTagsList excludedPackageTags);
-
-    /**
-     *
-     * @param code
-     * @param restricted
-     * @param token
-     */
-    void setGlobalRestriction(int code, boolean restricted, IBinder token);
-
-    /**
-     *
-     * @param code
-     * @param user
-     * @param pkg
-     * @param attributionTag
-     * @return
-     */
-    int getOpRestrictionCount(int code, UserHandle user, String pkg,
-            String attributionTag);
-
-    /**
-     *
-     * @param code
-     * @param uid
-     */
-    // added to interface for audio restriction stuff
-    void notifyWatchersOfChange(int code, int uid);
-
-    /**
-     *
-     * @param userHandle
-     * @throws RemoteException
-     */
-    void removeUser(int userHandle) throws RemoteException;
-
-    /**
-     *
-     * @param code
-     * @param uid
-     * @param packageName
-     * @return
-     */
-    boolean isOperationActive(int code, int uid, String packageName);
-
-    /**
-     *
-     * @param op
-     * @param proxyPackageName
-     * @param proxyAttributionTag
-     * @param proxiedUid
-     * @param proxiedPackageName
-     * @return
-     */
-    // TODO this one might not need to be in the interface
-    boolean isProxying(int op, @NonNull String proxyPackageName,
-            @NonNull String proxyAttributionTag, int proxiedUid,
-            @NonNull String proxiedPackageName);
-
-    /**
-     *
-     * @param packageName
-     */
-    void resetPackageOpsNoHistory(@NonNull String packageName);
-
-    /**
-     *
-     * @param mode
-     * @param baseSnapshotInterval
-     * @param compressionStep
-     */
-    void setHistoryParameters(@AppOpsManager.HistoricalMode int mode,
-            long baseSnapshotInterval, int compressionStep);
-
-    /**
-     *
-     * @param offsetMillis
-     */
-    void offsetHistory(long offsetMillis);
-
-    /**
-     *
-     * @param ops
-     */
-    void addHistoricalOps(AppOpsManager.HistoricalOps ops);
-
-    /**
-     *
-     */
-    void resetHistoryParameters();
-
-    /**
-     *
-     */
-    void clearHistory();
-
-    /**
-     *
-     * @param offlineDurationMillis
-     */
-    void rebootHistory(long offlineDurationMillis);
-}
diff --git a/services/core/java/com/android/server/appop/AppOpsUidStateTrackerImpl.java b/services/core/java/com/android/server/appop/AppOpsUidStateTrackerImpl.java
index c1434e4..5114bd5 100644
--- a/services/core/java/com/android/server/appop/AppOpsUidStateTrackerImpl.java
+++ b/services/core/java/com/android/server/appop/AppOpsUidStateTrackerImpl.java
@@ -59,7 +59,7 @@
     private final DelayableExecutor mExecutor;
     private final Clock mClock;
     private ActivityManagerInternal mActivityManagerInternal;
-    private AppOpsServiceImpl.Constants mConstants;
+    private AppOpsService.Constants mConstants;
 
     private SparseIntArray mUidStates = new SparseIntArray();
     private SparseIntArray mPendingUidStates = new SparseIntArray();
@@ -85,7 +85,7 @@
 
     AppOpsUidStateTrackerImpl(ActivityManagerInternal activityManagerInternal,
             Handler handler, Executor lockingExecutor, Clock clock,
-            AppOpsServiceImpl.Constants constants) {
+            AppOpsService.Constants constants) {
 
         this(activityManagerInternal, new DelayableExecutor() {
             @Override
@@ -102,7 +102,7 @@
 
     @VisibleForTesting
     AppOpsUidStateTrackerImpl(ActivityManagerInternal activityManagerInternal,
-            DelayableExecutor executor, Clock clock, AppOpsServiceImpl.Constants constants,
+            DelayableExecutor executor, Clock clock, AppOpsService.Constants constants,
             Thread executorThread) {
         mActivityManagerInternal = activityManagerInternal;
         mExecutor = executor;
diff --git a/services/core/java/com/android/server/appop/AttributedOp.java b/services/core/java/com/android/server/appop/AttributedOp.java
index 7970269..dcc36bc 100644
--- a/services/core/java/com/android/server/appop/AttributedOp.java
+++ b/services/core/java/com/android/server/appop/AttributedOp.java
@@ -40,9 +40,9 @@
 import java.util.NoSuchElementException;
 
 final class AttributedOp {
-    private final @NonNull AppOpsServiceImpl mAppOpsService;
+    private final @NonNull AppOpsService mAppOpsService;
     public final @Nullable String tag;
-    public final @NonNull AppOpsServiceImpl.Op parent;
+    public final @NonNull AppOpsService.Op parent;
 
     /**
      * Last successful accesses (noteOp + finished startOp) for each uidState/opFlag combination
@@ -80,8 +80,8 @@
     // @GuardedBy("mAppOpsService")
     @Nullable ArrayMap<IBinder, InProgressStartOpEvent> mPausedInProgressEvents;
 
-    AttributedOp(@NonNull AppOpsServiceImpl appOpsService, @Nullable String tag,
-                 @NonNull AppOpsServiceImpl.Op parent) {
+    AttributedOp(@NonNull AppOpsService appOpsService, @Nullable String tag,
+            @NonNull AppOpsService.Op parent) {
         mAppOpsService = appOpsService;
         this.tag = tag;
         this.parent = parent;
@@ -131,8 +131,8 @@
 
         AppOpsManager.OpEventProxyInfo proxyInfo = null;
         if (proxyUid != Process.INVALID_UID) {
-            proxyInfo = mAppOpsService.mOpEventProxyInfoPool.acquire(proxyUid,
-                    proxyPackageName, proxyAttributionTag);
+            proxyInfo = mAppOpsService.mOpEventProxyInfoPool.acquire(proxyUid, proxyPackageName,
+                    proxyAttributionTag);
         }
 
         AppOpsManager.NoteOpEvent existingEvent = mAccessEvents.get(key);
@@ -238,7 +238,7 @@
         if (event == null) {
             event = mAppOpsService.mInProgressStartOpEventPool.acquire(startTime,
                     SystemClock.elapsedRealtime(), clientId, tag,
-                    PooledLambda.obtainRunnable(AppOpsServiceImpl::onClientDeath, this, clientId),
+                    PooledLambda.obtainRunnable(AppOpsService::onClientDeath, this, clientId),
                     proxyUid, proxyPackageName, proxyAttributionTag, uidState, flags,
                     attributionFlags, attributionChainId);
             events.put(clientId, event);
@@ -251,9 +251,9 @@
         event.mNumUnfinishedStarts++;
 
         if (isStarted) {
-            mAppOpsService.mHistoricalRegistry.incrementOpAccessedCount(parent.op,
-                    parent.uid, parent.packageName, tag, uidState, flags, startTime,
-                    attributionFlags, attributionChainId);
+            mAppOpsService.mHistoricalRegistry.incrementOpAccessedCount(parent.op, parent.uid,
+                    parent.packageName, tag, uidState, flags, startTime, attributionFlags,
+                    attributionChainId);
         }
     }
 
@@ -309,8 +309,8 @@
             mAccessEvents.put(makeKey(event.getUidState(), event.getFlags()),
                     finishedEvent);
 
-            mAppOpsService.mHistoricalRegistry.increaseOpAccessDuration(parent.op,
-                    parent.uid, parent.packageName, tag, event.getUidState(),
+            mAppOpsService.mHistoricalRegistry.increaseOpAccessDuration(parent.op, parent.uid,
+                    parent.packageName, tag, event.getUidState(),
                     event.getFlags(), finishedEvent.getNoteTime(), finishedEvent.getDuration(),
                     event.getAttributionFlags(), event.getAttributionChainId());
 
@@ -334,13 +334,13 @@
     @SuppressWarnings("GuardedBy") // Lock is held on mAppOpsService
     private void finishPossiblyPaused(@NonNull IBinder clientId, boolean isPausing) {
         if (!isPaused()) {
-            Slog.wtf(AppOpsServiceImpl.TAG, "No ops running or paused");
+            Slog.wtf(AppOpsService.TAG, "No ops running or paused");
             return;
         }
 
         int indexOfToken = mPausedInProgressEvents.indexOfKey(clientId);
         if (indexOfToken < 0) {
-            Slog.wtf(AppOpsServiceImpl.TAG, "No op running or paused for the client");
+            Slog.wtf(AppOpsService.TAG, "No op running or paused for the client");
             return;
         } else if (isPausing) {
             // already paused
@@ -416,9 +416,9 @@
             mInProgressEvents.put(event.getClientId(), event);
             event.setStartElapsedTime(SystemClock.elapsedRealtime());
             event.setStartTime(startTime);
-            mAppOpsService.mHistoricalRegistry.incrementOpAccessedCount(parent.op,
-                    parent.uid, parent.packageName, tag, event.getUidState(), event.getFlags(),
-                    startTime, event.getAttributionFlags(), event.getAttributionChainId());
+            mAppOpsService.mHistoricalRegistry.incrementOpAccessedCount(parent.op, parent.uid,
+                    parent.packageName, tag, event.getUidState(), event.getFlags(), startTime,
+                    event.getAttributionFlags(), event.getAttributionChainId());
             if (shouldSendActive) {
                 mAppOpsService.scheduleOpActiveChangedIfNeededLocked(parent.op, parent.uid,
                         parent.packageName, tag, true, event.getAttributionFlags(),
@@ -503,8 +503,8 @@
                         newEvent.mNumUnfinishedStarts += numPreviousUnfinishedStarts - 1;
                     }
                 } catch (RemoteException e) {
-                    if (AppOpsServiceImpl.DEBUG) {
-                        Slog.e(AppOpsServiceImpl.TAG,
+                    if (AppOpsService.DEBUG) {
+                        Slog.e(AppOpsService.TAG,
                                 "Cannot switch to new uidState " + newState);
                     }
                 }
@@ -555,8 +555,8 @@
             ArrayMap<IBinder, InProgressStartOpEvent> ignoredEvents =
                     opToAdd.isRunning()
                             ? opToAdd.mInProgressEvents : opToAdd.mPausedInProgressEvents;
-            Slog.w(AppOpsServiceImpl.TAG, "Ignoring " + ignoredEvents.size()
-                    + " app-ops, running: " + opToAdd.isRunning());
+            Slog.w(AppOpsService.TAG, "Ignoring " + ignoredEvents.size() + " app-ops, running: "
+                    + opToAdd.isRunning());
 
             int numInProgressEvents = ignoredEvents.size();
             for (int i = 0; i < numInProgressEvents; i++) {
@@ -668,22 +668,16 @@
         /**
          * Create a new {@link InProgressStartOpEvent}.
          *
-         * @param startTime          The time {@link AppOpCheckingServiceInterface#startOperation}
-         *                          was called
-         * @param startElapsedTime   The elapsed time whe
-         *                          {@link AppOpCheckingServiceInterface#startOperation} was called
-         * @param clientId           The client id of the caller of
-         *                          {@link AppOpCheckingServiceInterface#startOperation}
+         * @param startTime          The time {@link #startOperation} was called
+         * @param startElapsedTime   The elapsed time when {@link #startOperation} was called
+         * @param clientId           The client id of the caller of {@link #startOperation}
          * @param attributionTag     The attribution tag for the operation.
          * @param onDeath            The code to execute on client death
-         * @param uidState           The uidstate of the app
-         *                          {@link AppOpCheckingServiceInterface#startOperation} was called
-         *                          for
+         * @param uidState           The uidstate of the app {@link #startOperation} was called for
          * @param attributionFlags   the attribution flags for this operation.
          * @param attributionChainId the unique id of the attribution chain this op is a part of.
-         * @param proxy              The proxy information, if
-         *                          {@link AppOpCheckingServiceInterface#startProxyOperation} was
-         *                          called
+         * @param proxy              The proxy information, if {@link #startProxyOperation} was
+         *                           called
          * @param flags              The trusted/nontrusted/self flags.
          * @throws RemoteException If the client is dying
          */
@@ -724,21 +718,15 @@
         /**
          * Reinit existing object with new state.
          *
-         * @param startTime          The time {@link AppOpCheckingServiceInterface#startOperation}
-         *                          was called
-         * @param startElapsedTime   The elapsed time when
-         *                          {@link AppOpCheckingServiceInterface#startOperation} was called
-         * @param clientId           The client id of the caller of
-         *                          {@link AppOpCheckingServiceInterface#startOperation}
+         * @param startTime          The time {@link #startOperation} was called
+         * @param startElapsedTime   The elapsed time when {@link #startOperation} was called
+         * @param clientId           The client id of the caller of {@link #startOperation}
          * @param attributionTag     The attribution tag for this operation.
          * @param onDeath            The code to execute on client death
-         * @param uidState           The uidstate of the app
-         *                          {@link AppOpCheckingServiceInterface#startOperation} was called
-         *                          for
+         * @param uidState           The uidstate of the app {@link #startOperation} was called for
          * @param flags              The flags relating to the proxy
-         * @param proxy              The proxy information, if
-         *                          {@link AppOpCheckingServiceInterface#startProxyOperation was
-         *                          called
+         * @param proxy              The proxy information, if {@link #startProxyOperation}
+         *                           was called
          * @param attributionFlags   the attribution flags for this operation.
          * @param attributionChainId the unique id of the attribution chain this op is a part of.
          * @param proxyPool          The pool to release
diff --git a/services/core/java/com/android/server/audio/AudioDeviceBroker.java b/services/core/java/com/android/server/audio/AudioDeviceBroker.java
index 2fe06094..418027f 100644
--- a/services/core/java/com/android/server/audio/AudioDeviceBroker.java
+++ b/services/core/java/com/android/server/audio/AudioDeviceBroker.java
@@ -1998,4 +1998,13 @@
             return mDeviceInventory.getDeviceSensorUuid(device);
         }
     }
+
+    void dispatchPreferredMixerAttributesChangedCausedByDeviceRemoved(AudioDeviceInfo info) {
+        // Currently, only media usage will be allowed to set preferred mixer attributes
+        mAudioService.dispatchPreferredMixerAttributesChanged(
+                new AudioAttributes.Builder()
+                        .setUsage(AudioAttributes.USAGE_MEDIA).build(),
+                info.getId(),
+                null /*mixerAttributes*/);
+    }
 }
diff --git a/services/core/java/com/android/server/audio/AudioDeviceInventory.java b/services/core/java/com/android/server/audio/AudioDeviceInventory.java
index c8f282f..34457b0 100644
--- a/services/core/java/com/android/server/audio/AudioDeviceInventory.java
+++ b/services/core/java/com/android/server/audio/AudioDeviceInventory.java
@@ -22,6 +22,7 @@
 import android.bluetooth.BluetoothProfile;
 import android.content.Intent;
 import android.media.AudioDeviceAttributes;
+import android.media.AudioDeviceInfo;
 import android.media.AudioDevicePort;
 import android.media.AudioFormat;
 import android.media.AudioManager;
@@ -532,6 +533,18 @@
                 .set(MediaMetrics.Property.STATE,
                         wdcs.mState == AudioService.CONNECTION_STATE_DISCONNECTED
                                 ? MediaMetrics.Value.DISCONNECTED : MediaMetrics.Value.CONNECTED);
+        AudioDeviceInfo info = null;
+        if (wdcs.mState == AudioService.CONNECTION_STATE_DISCONNECTED
+                && AudioSystem.DEVICE_OUT_ALL_USB_SET.contains(
+                        wdcs.mAttributes.getInternalType())) {
+            for (AudioDeviceInfo deviceInfo : AudioManager.getDevicesStatic(
+                    AudioManager.GET_DEVICES_OUTPUTS)) {
+                if (deviceInfo.getInternalType() == wdcs.mAttributes.getInternalType()) {
+                    info = deviceInfo;
+                    break;
+                }
+            }
+        }
         synchronized (mDevicesLock) {
             if ((wdcs.mState == AudioService.CONNECTION_STATE_DISCONNECTED)
                     && DEVICE_OVERRIDE_A2DP_ROUTE_ON_PLUG_SET.contains(type)) {
@@ -556,6 +569,11 @@
             if (type == AudioSystem.DEVICE_OUT_HDMI) {
                 mDeviceBroker.checkVolumeCecOnHdmiConnection(wdcs.mState, wdcs.mCaller);
             }
+            if (wdcs.mState == AudioService.CONNECTION_STATE_DISCONNECTED
+                    && AudioSystem.DEVICE_OUT_ALL_USB_SET.contains(
+                            wdcs.mAttributes.getInternalType())) {
+                mDeviceBroker.dispatchPreferredMixerAttributesChangedCausedByDeviceRemoved(info);
+            }
             sendDeviceConnectionIntent(type, wdcs.mState,
                     wdcs.mAttributes.getAddress(), wdcs.mAttributes.getName());
             updateAudioRoutes(type, wdcs.mState);
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index aa8ee3d..9b433cf 100644
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -17,6 +17,7 @@
 package com.android.server.audio;
 
 import static android.Manifest.permission.REMOTE_AUDIO_PLAYBACK;
+import static android.app.BroadcastOptions.DELIVERY_GROUP_POLICY_MOST_RECENT;
 import static android.media.AudioManager.RINGER_MODE_NORMAL;
 import static android.media.AudioManager.RINGER_MODE_SILENT;
 import static android.media.AudioManager.RINGER_MODE_VIBRATE;
@@ -27,6 +28,7 @@
 import static android.provider.Settings.Secure.VOLUME_HUSH_OFF;
 import static android.provider.Settings.Secure.VOLUME_HUSH_VIBRATE;
 
+import static com.android.server.audio.SoundDoseHelper.ACTION_CHECK_MUSIC_ACTIVE;
 import static com.android.server.utils.EventLogger.Event.ALOGE;
 import static com.android.server.utils.EventLogger.Event.ALOGI;
 import static com.android.server.utils.EventLogger.Event.ALOGW;
@@ -42,12 +44,11 @@
 import android.app.ActivityManager;
 import android.app.ActivityManagerInternal;
 import android.app.ActivityThread;
-import android.app.AlarmManager;
 import android.app.AppGlobals;
 import android.app.AppOpsManager;
+import android.app.BroadcastOptions;
 import android.app.IUidObserver;
 import android.app.NotificationManager;
-import android.app.PendingIntent;
 import android.app.role.OnRoleHoldersChangedListener;
 import android.app.role.RoleManager;
 import android.bluetooth.BluetoothAdapter;
@@ -89,6 +90,7 @@
 import android.media.AudioHalVersionInfo;
 import android.media.AudioManager;
 import android.media.AudioManagerInternal;
+import android.media.AudioMixerAttributes;
 import android.media.AudioPlaybackConfiguration;
 import android.media.AudioRecordingConfiguration;
 import android.media.AudioRoutesInfo;
@@ -105,6 +107,7 @@
 import android.media.IDeviceVolumeBehaviorDispatcher;
 import android.media.IMuteAwaitConnectionCallback;
 import android.media.IPlaybackConfigDispatcher;
+import android.media.IPreferredMixerAttributesDispatcher;
 import android.media.IRecordingConfigDispatcher;
 import android.media.IRingtonePlayer;
 import android.media.ISpatializerCallback;
@@ -166,7 +169,6 @@
 import android.util.ArraySet;
 import android.util.IntArray;
 import android.util.Log;
-import android.util.MathUtils;
 import android.util.PrintWriterPrinter;
 import android.util.Slog;
 import android.util.SparseArray;
@@ -178,6 +180,7 @@
 import com.android.internal.annotations.GuardedBy;
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
+import com.android.internal.os.SomeArgs;
 import com.android.internal.util.DumpUtils;
 import com.android.internal.util.Preconditions;
 import com.android.server.EventLogTags;
@@ -332,7 +335,7 @@
     private static final int SENDMSG_QUEUE = 2;
 
     // AudioHandler messages
-    private static final int MSG_SET_DEVICE_VOLUME = 0;
+    /*package*/ static final int MSG_SET_DEVICE_VOLUME = 0;
     private static final int MSG_PERSIST_VOLUME = 1;
     private static final int MSG_PERSIST_VOLUME_GROUP = 2;
     private static final int MSG_PERSIST_RINGER_MODE = 3;
@@ -342,13 +345,8 @@
     private static final int MSG_SET_FORCE_USE = 8;
     private static final int MSG_BT_HEADSET_CNCT_FAILED = 9;
     private static final int MSG_SET_ALL_VOLUMES = 10;
-    private static final int MSG_CHECK_MUSIC_ACTIVE = 11;
-    private static final int MSG_CONFIGURE_SAFE_MEDIA_VOLUME = 12;
-    private static final int MSG_CONFIGURE_SAFE_MEDIA_VOLUME_FORCED = 13;
-    private static final int MSG_PERSIST_SAFE_VOLUME_STATE = 14;
     private static final int MSG_UNLOAD_SOUND_EFFECTS = 15;
     private static final int MSG_SYSTEM_READY = 16;
-    private static final int MSG_PERSIST_MUSIC_ACTIVE_MS = 17;
     private static final int MSG_UNMUTE_STREAM = 18;
     private static final int MSG_DYN_POLICY_MIX_STATE_UPDATE = 19;
     private static final int MSG_INDICATE_SYSTEM_READY = 20;
@@ -383,6 +381,10 @@
     private static final int MSG_FOLD_UPDATE = 49;
     private static final int MSG_RESET_SPATIALIZER = 50;
     private static final int MSG_NO_LOG_FOR_PLAYER_I = 51;
+    private static final int MSG_DISPATCH_PREFERRED_MIXER_ATTRIBUTES = 52;
+
+    /** Messages handled by the {@link SoundDoseHelper}. */
+    /*package*/ static final int SAFE_MEDIA_VOLUME_MSG_START = 1000;
 
     // start of messages handled under wakelock
     //   these messages can only be queued, i.e. sent with queueMsgUnderWakeLock(),
@@ -399,6 +401,9 @@
     // List of empty UIDs used to reset the active assistant list
     private static final int[] NO_ACTIVE_ASSISTANT_SERVICE_UIDS = new int[0];
 
+    // check playback or record activity every 6 seconds for UIDs owning mode IN_COMMUNICATION
+    private static final int CHECK_MODE_FOR_UID_PERIOD_MS = 6000;
+
     /** @see AudioSystemThread */
     private AudioSystemThread mAudioSystemThread;
     /** @see AudioHandler */
@@ -410,6 +415,10 @@
         return mStreamStates[stream].getIndex(device);
     }
 
+    /*package*/ VolumeStreamState getVssVolumeForStream(int stream) {
+        return mStreamStates[stream];
+    }
+
     /*package*/ int getMaxVssVolumeForStream(int stream) {
         return mStreamStates[stream].getMaxIndex();
     }
@@ -838,11 +847,6 @@
 
     private int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
 
-    // Used when safe volume warning message display is requested by setStreamVolume(). In this
-    // case, the new requested volume, stream type and device are stored in mPendingVolumeCommand
-    // and used later when/if disableSafeMediaVolume() is called.
-    private StreamVolumeCommand mPendingVolumeCommand;
-
     private PowerManager.WakeLock mAudioEventWakeLock;
 
     private final MediaFocusControl mMediaFocusControl;
@@ -894,6 +898,8 @@
     private boolean mNavigationRepeatSoundEffectsEnabled;
     private boolean mHomeSoundEffectEnabled;
 
+    private final SoundDoseHelper mSoundDoseHelper;
+
     @GuardedBy("mSettingsLock")
     private int mCurrentImeUid;
 
@@ -1184,6 +1190,9 @@
             mAudioHandler = new AudioHandler(looper);
         }
 
+        mSoundDoseHelper = new SoundDoseHelper(this, mContext, mAudioHandler, mSettings,
+                mVolumeController);
+
         AudioSystem.setErrorCallback(mAudioSystemCallback);
 
         updateAudioHalPids();
@@ -1199,16 +1208,6 @@
                 new String("AudioService ctor"),
                 0);
 
-        mSafeMediaVolumeState = mSettings.getGlobalInt(mContentResolver,
-                                            Settings.Global.AUDIO_SAFE_VOLUME_STATE,
-                                            SAFE_MEDIA_VOLUME_NOT_CONFIGURED);
-        // The default safe volume index read here will be replaced by the actual value when
-        // the mcc is read by onConfigureSafeVolume()
-        mSafeMediaVolumeIndex = mContext.getResources().getInteger(
-                com.android.internal.R.integer.config_safe_media_volume_index) * 10;
-
-        mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
-
         mUseFixedVolume = mContext.getResources().getBoolean(
                 com.android.internal.R.bool.config_useFixedVolume);
 
@@ -1285,9 +1284,7 @@
         // persistent data
         initVolumeGroupStates();
 
-        // mSafeUsbMediaVolumeIndex must be initialized after createStreamStates() because it
-        // relies on audio policy having correct ranges for volume indexes.
-        mSafeUsbMediaVolumeIndex = getSafeUsbMediaVolumeIndex();
+        mSoundDoseHelper.initSafeUsbMediaVolumeIndex();
 
         // Call setRingerModeInt() to apply correct mute
         // state on streams affected by ringer mode.
@@ -1442,14 +1439,7 @@
 
         mNm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
 
-        sendMsg(mAudioHandler,
-                MSG_CONFIGURE_SAFE_MEDIA_VOLUME_FORCED,
-                SENDMSG_REPLACE,
-                0,
-                0,
-                TAG,
-                SystemProperties.getBoolean("audio.safemedia.bypass", false) ?
-                        0 : SAFE_VOLUME_CONFIGURE_TIMEOUT_MS);
+        mSoundDoseHelper.configureSafeMediaVolume(/*forced=*/true, TAG);
 
         initA11yMonitoring();
 
@@ -1715,6 +1705,7 @@
         }
 
         mSpatializerHelper.reset(/* featureEnabled */ mHasSpatializerEffect);
+        mSoundDoseHelper.reset();
 
         onIndicateSystemReady();
         // indicate the end of reconfiguration phase to audio HAL
@@ -1987,8 +1978,8 @@
             @AudioService.ConnectionState int state, String caller) {
         if (state == AudioService.CONNECTION_STATE_CONNECTED) {
             // DEVICE_OUT_HDMI is now connected
-            if (mSafeMediaVolumeDevices.contains(AudioSystem.DEVICE_OUT_HDMI)) {
-                scheduleMusicActiveCheck();
+            if (mSoundDoseHelper.safeDevicesContains(AudioSystem.DEVICE_OUT_HDMI)) {
+                mSoundDoseHelper.scheduleMusicActiveCheck();
             }
 
             if (isPlatformTelevision()) {
@@ -3283,10 +3274,7 @@
             return;
         }
 
-        // reset any pending volume command
-        synchronized (mSafeMediaVolumeStateLock) {
-            mPendingVolumeCommand = null;
-        }
+        mSoundDoseHelper.invalidatPendingVolumeCommand();
 
         flags &= ~AudioManager.FLAG_FIXED_VOLUME;
         if (streamTypeAlias == AudioSystem.STREAM_MUSIC && isFixedVolumeDevice(device)) {
@@ -3295,10 +3283,8 @@
             // Always toggle between max safe volume and 0 for fixed volume devices where safe
             // volume is enforced, and max and 0 for the others.
             // This is simulated by stepping by the full allowed volume range
-            if (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE &&
-                    mSafeMediaVolumeDevices.contains(device)) {
-                step = safeMediaVolumeIndex(device);
-            } else {
+            step = mSoundDoseHelper.getSafeMediaVolumeIndex(device);
+            if (step < 0) {
                 step = streamState.getMaxIndex();
             }
             if (aliasIndex != 0) {
@@ -3371,10 +3357,10 @@
                         }
                     }
                 }
-            } else if ((direction == AudioManager.ADJUST_RAISE) &&
-                    !checkSafeMediaVolume(streamTypeAlias, aliasIndex + step, device)) {
+            } else if ((direction == AudioManager.ADJUST_RAISE)
+                    && mSoundDoseHelper.raiseVolumeDisplaySafeMediaVolume(streamTypeAlias,
+                            aliasIndex + step, device, flags)) {
                 Log.e(TAG, "adjustStreamVolume() safe volume index = " + oldIndex);
-                mVolumeController.postDisplaySafeVolumeWarning(flags);
             } else if (!isFullVolumeDevice(device)
                     && (streamState.adjustIndex(direction * step, device, caller,
                             hasModifyAudioSettings)
@@ -3545,29 +3531,6 @@
         Binder.restoreCallingIdentity(identity);
     }
 
-    // StreamVolumeCommand contains the information needed to defer the process of
-    // setStreamVolume() in case the user has to acknowledge the safe volume warning message.
-    static class StreamVolumeCommand {
-        public final int mStreamType;
-        public final int mIndex;
-        public final int mFlags;
-        public final int mDevice;
-
-        StreamVolumeCommand(int streamType, int index, int flags, int device) {
-            mStreamType = streamType;
-            mIndex = index;
-            mFlags = flags;
-            mDevice = device;
-        }
-
-        @Override
-        public String toString() {
-            return new StringBuilder().append("{streamType=").append(mStreamType).append(",index=")
-                    .append(mIndex).append(",flags=").append(mFlags).append(",device=")
-                    .append(mDevice).append('}').toString();
-        }
-    }
-
     private int getNewRingerMode(int stream, int index, int flags) {
         // setRingerMode does nothing if the device is single volume,so the value would be unchanged
         if (mIsSingleVolume) {
@@ -3615,7 +3578,7 @@
         return false;
     }
 
-    private void onSetStreamVolume(int streamType, int index, int flags, int device,
+     /*package*/ void onSetStreamVolume(int streamType, int index, int flags, int device,
             String caller, boolean hasModifyAudioSettings) {
         final int stream = mStreamVolumeAlias[streamType];
         setStreamVolumeInt(stream, index, device, false, caller, hasModifyAudioSettings);
@@ -3959,7 +3922,7 @@
             updateHearingAidVolumeOnVoiceActivityUpdate();
         }
         if (mMediaPlaybackActive.getAndSet(mediaActive) != mediaActive && mediaActive) {
-            scheduleMusicActiveCheck();
+            mSoundDoseHelper.scheduleMusicActiveCheck();
         }
         // Update playback active state for all apps in audio mode stack.
         // When the audio mode owner becomes active, replace any delayed MSG_UPDATE_AUDIO_MODE
@@ -4205,71 +4168,64 @@
             return;
         }
 
-        synchronized (mSafeMediaVolumeStateLock) {
-            // reset any pending volume command
-            mPendingVolumeCommand = null;
+        mSoundDoseHelper.invalidatPendingVolumeCommand();
 
-            oldIndex = streamState.getIndex(device);
+        oldIndex = streamState.getIndex(device);
 
-            index = rescaleIndex(index * 10, streamType, streamTypeAlias);
+        index = rescaleIndex(index * 10, streamType, streamTypeAlias);
 
-            if (streamTypeAlias == AudioSystem.STREAM_MUSIC
-                    && AudioSystem.DEVICE_OUT_ALL_A2DP_SET.contains(device)
-                    && (flags & AudioManager.FLAG_BLUETOOTH_ABS_VOLUME) == 0) {
-                if (DEBUG_VOL) {
-                    Log.d(TAG, "setStreamVolume postSetAvrcpAbsoluteVolumeIndex index=" + index
-                            + "stream=" + streamType);
+        if (streamTypeAlias == AudioSystem.STREAM_MUSIC
+                && AudioSystem.DEVICE_OUT_ALL_A2DP_SET.contains(device)
+                && (flags & AudioManager.FLAG_BLUETOOTH_ABS_VOLUME) == 0) {
+            if (DEBUG_VOL) {
+                Log.d(TAG, "setStreamVolume postSetAvrcpAbsoluteVolumeIndex index=" + index
+                        + "stream=" + streamType);
+            }
+            mDeviceBroker.postSetAvrcpAbsoluteVolumeIndex(index / 10);
+        } else if (isAbsoluteVolumeDevice(device)
+                && ((flags & AudioManager.FLAG_ABSOLUTE_VOLUME) == 0)) {
+            AbsoluteVolumeDeviceInfo info = mAbsoluteVolumeDeviceInfoMap.get(device);
+
+            dispatchAbsoluteVolumeChanged(streamType, info, index);
+        }
+
+        if (AudioSystem.isLeAudioDeviceType(device)
+                && streamType == getBluetoothContextualVolumeStream()
+                && (flags & AudioManager.FLAG_BLUETOOTH_ABS_VOLUME) == 0) {
+            if (DEBUG_VOL) {
+                Log.d(TAG, "adjustSreamVolume postSetLeAudioVolumeIndex index="
+                        + index + " stream=" + streamType);
+            }
+            mDeviceBroker.postSetLeAudioVolumeIndex(index, mStreamStates[streamType].getMaxIndex(),
+                    streamType);
+        }
+
+        if (device == AudioSystem.DEVICE_OUT_HEARING_AID
+                && streamType == getBluetoothContextualVolumeStream()) {
+            Log.i(TAG, "setStreamVolume postSetHearingAidVolumeIndex index=" + index
+                    + " stream=" + streamType);
+            mDeviceBroker.postSetHearingAidVolumeIndex(index, streamType);
+        }
+
+        flags &= ~AudioManager.FLAG_FIXED_VOLUME;
+        if (streamTypeAlias == AudioSystem.STREAM_MUSIC && isFixedVolumeDevice(device)) {
+            flags |= AudioManager.FLAG_FIXED_VOLUME;
+
+            // volume is either 0 or max allowed for fixed volume devices
+            if (index != 0) {
+                index = mSoundDoseHelper.getSafeMediaVolumeIndex(device);
+                if (index < 0) {
+                    index = streamState.getMaxIndex();
                 }
-                mDeviceBroker.postSetAvrcpAbsoluteVolumeIndex(index / 10);
-            } else if (isAbsoluteVolumeDevice(device)
-                    && ((flags & AudioManager.FLAG_ABSOLUTE_VOLUME) == 0)) {
-                AbsoluteVolumeDeviceInfo info = mAbsoluteVolumeDeviceInfoMap.get(device);
-
-                dispatchAbsoluteVolumeChanged(streamType, info, index);
-            }
-
-            if (AudioSystem.isLeAudioDeviceType(device)
-                    && streamType == getBluetoothContextualVolumeStream()
-                    && (flags & AudioManager.FLAG_BLUETOOTH_ABS_VOLUME) == 0) {
-                if (DEBUG_VOL) {
-                    Log.d(TAG, "adjustSreamVolume postSetLeAudioVolumeIndex index="
-                            + index + " stream=" + streamType);
-                }
-                mDeviceBroker.postSetLeAudioVolumeIndex(index,
-                    mStreamStates[streamType].getMaxIndex(), streamType);
-            }
-
-            if (device == AudioSystem.DEVICE_OUT_HEARING_AID
-                    && streamType == getBluetoothContextualVolumeStream()) {
-                Log.i(TAG, "setStreamVolume postSetHearingAidVolumeIndex index=" + index
-                        + " stream=" + streamType);
-                mDeviceBroker.postSetHearingAidVolumeIndex(index, streamType);
-            }
-
-            flags &= ~AudioManager.FLAG_FIXED_VOLUME;
-            if (streamTypeAlias == AudioSystem.STREAM_MUSIC && isFixedVolumeDevice(device)) {
-                flags |= AudioManager.FLAG_FIXED_VOLUME;
-
-                // volume is either 0 or max allowed for fixed volume devices
-                if (index != 0) {
-                    if (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE &&
-                            mSafeMediaVolumeDevices.contains(device)) {
-                        index = safeMediaVolumeIndex(device);
-                    } else {
-                        index = streamState.getMaxIndex();
-                    }
-                }
-            }
-
-            if (!checkSafeMediaVolume(streamTypeAlias, index, device)) {
-                mVolumeController.postDisplaySafeVolumeWarning(flags);
-                mPendingVolumeCommand = new StreamVolumeCommand(
-                                                    streamType, index, flags, device);
-            } else {
-                onSetStreamVolume(streamType, index, flags, device, caller, hasModifyAudioSettings);
-                index = mStreamStates[streamType].getIndex(device);
             }
         }
+
+        if (!mSoundDoseHelper.willDisplayWarningAfterCheckVolume(streamType, index, device,
+                flags)) {
+            onSetStreamVolume(streamType, index, flags, device, caller, hasModifyAudioSettings);
+            index = mStreamStates[streamType].getIndex(device);
+        }
+
         synchronized (mHdmiClientLock) {
             if (streamTypeAlias == AudioSystem.STREAM_MUSIC
                     && (oldIndex != index)) {
@@ -4427,7 +4383,7 @@
         }
     }
 
-    private void sendBroadcastToAll(Intent intent) {
+    private void sendBroadcastToAll(Intent intent, Bundle options) {
         if (!mSystemServer.isPrivileged()) {
             return;
         }
@@ -4435,7 +4391,8 @@
         intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
         final long ident = Binder.clearCallingIdentity();
         try {
-            mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
+            mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
+                    null /* receiverPermission */, options);
         } finally {
             Binder.restoreCallingIdentity(ident);
         }
@@ -5846,14 +5803,8 @@
         checkAllAliasStreamVolumes();
         checkMuteAffectedStreams();
 
-        synchronized (mSafeMediaVolumeStateLock) {
-            mMusicActiveMs = MathUtils.constrain(mSettings.getSecureIntForUser(mContentResolver,
-                    Settings.Secure.UNSAFE_VOLUME_MUSIC_ACTIVE_MS, 0, UserHandle.USER_CURRENT),
-                    0, UNSAFE_VOLUME_MUSIC_ACTIVE_MS_MAX);
-            if (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE) {
-                enforceSafeMediaVolume(TAG);
-            }
-        }
+        mSoundDoseHelper.restoreMusicActiveMs();
+        mSoundDoseHelper.enforceSafeMediaVolumeIfActive(TAG);
 
         readVolumeGroupsSettings();
 
@@ -6189,139 +6140,6 @@
         return mContentResolver;
     }
 
-    private void scheduleMusicActiveCheck() {
-        synchronized (mSafeMediaVolumeStateLock) {
-            cancelMusicActiveCheck();
-            mMusicActiveIntent = PendingIntent.getBroadcast(mContext,
-                REQUEST_CODE_CHECK_MUSIC_ACTIVE,
-                new Intent(ACTION_CHECK_MUSIC_ACTIVE),
-                PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
-            mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
-                    SystemClock.elapsedRealtime()
-                    + MUSIC_ACTIVE_POLL_PERIOD_MS, mMusicActiveIntent);
-        }
-    }
-
-    private void cancelMusicActiveCheck() {
-        synchronized (mSafeMediaVolumeStateLock) {
-            if (mMusicActiveIntent != null) {
-                mAlarmManager.cancel(mMusicActiveIntent);
-                mMusicActiveIntent = null;
-            }
-        }
-    }
-    private void onCheckMusicActive(String caller) {
-        synchronized (mSafeMediaVolumeStateLock) {
-            if (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_INACTIVE) {
-                int device = getDeviceForStream(AudioSystem.STREAM_MUSIC);
-                if (mSafeMediaVolumeDevices.contains(device)
-                        && mAudioSystem.isStreamActive(AudioSystem.STREAM_MUSIC, 0)) {
-                    scheduleMusicActiveCheck();
-                    int index = mStreamStates[AudioSystem.STREAM_MUSIC].getIndex(device);
-                    if (index > safeMediaVolumeIndex(device)) {
-                        // Approximate cumulative active music time
-                        long curTimeMs = SystemClock.elapsedRealtime();
-                        if (mLastMusicActiveTimeMs != 0) {
-                            mMusicActiveMs += (int) (curTimeMs - mLastMusicActiveTimeMs);
-                        }
-                        mLastMusicActiveTimeMs = curTimeMs;
-                        Log.i(TAG, "onCheckMusicActive() mMusicActiveMs: " + mMusicActiveMs);
-                        if (mMusicActiveMs > UNSAFE_VOLUME_MUSIC_ACTIVE_MS_MAX) {
-                            setSafeMediaVolumeEnabled(true, caller);
-                            mMusicActiveMs = 0;
-                        }
-                        saveMusicActiveMs();
-                    }
-                } else {
-                    cancelMusicActiveCheck();
-                    mLastMusicActiveTimeMs = 0;
-                }
-            }
-        }
-    }
-
-    private void saveMusicActiveMs() {
-        mAudioHandler.obtainMessage(MSG_PERSIST_MUSIC_ACTIVE_MS, mMusicActiveMs, 0).sendToTarget();
-    }
-
-    private int getSafeUsbMediaVolumeIndex() {
-        // determine UI volume index corresponding to the wanted safe gain in dBFS
-        int min = MIN_STREAM_VOLUME[AudioSystem.STREAM_MUSIC];
-        int max = MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC];
-
-        mSafeUsbMediaVolumeDbfs = mContext.getResources().getInteger(
-                com.android.internal.R.integer.config_safe_media_volume_usb_mB) / 100.0f;
-
-        while (Math.abs(max - min) > 1) {
-            int index = (max + min) / 2;
-            float gainDB = AudioSystem.getStreamVolumeDB(
-                    AudioSystem.STREAM_MUSIC, index, AudioSystem.DEVICE_OUT_USB_HEADSET);
-            if (Float.isNaN(gainDB)) {
-                //keep last min in case of read error
-                break;
-            } else if (gainDB == mSafeUsbMediaVolumeDbfs) {
-                min = index;
-                break;
-            } else if (gainDB < mSafeUsbMediaVolumeDbfs) {
-                min = index;
-            } else {
-                max = index;
-            }
-        }
-        return min * 10;
-    }
-
-    private void onConfigureSafeVolume(boolean force, String caller) {
-        synchronized (mSafeMediaVolumeStateLock) {
-            int mcc = mContext.getResources().getConfiguration().mcc;
-            if ((mMcc != mcc) || ((mMcc == 0) && force)) {
-                mSafeMediaVolumeIndex = mContext.getResources().getInteger(
-                        com.android.internal.R.integer.config_safe_media_volume_index) * 10;
-
-                mSafeUsbMediaVolumeIndex = getSafeUsbMediaVolumeIndex();
-
-                boolean safeMediaVolumeEnabled =
-                        SystemProperties.getBoolean("audio.safemedia.force", false)
-                        || mContext.getResources().getBoolean(
-                                com.android.internal.R.bool.config_safe_media_volume_enabled);
-
-                boolean safeMediaVolumeBypass =
-                        SystemProperties.getBoolean("audio.safemedia.bypass", false);
-
-                // The persisted state is either "disabled" or "active": this is the state applied
-                // next time we boot and cannot be "inactive"
-                int persistedState;
-                if (safeMediaVolumeEnabled && !safeMediaVolumeBypass) {
-                    persistedState = SAFE_MEDIA_VOLUME_ACTIVE;
-                    // The state can already be "inactive" here if the user has forced it before
-                    // the 30 seconds timeout for forced configuration. In this case we don't reset
-                    // it to "active".
-                    if (mSafeMediaVolumeState != SAFE_MEDIA_VOLUME_INACTIVE) {
-                        if (mMusicActiveMs == 0) {
-                            mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_ACTIVE;
-                            enforceSafeMediaVolume(caller);
-                        } else {
-                            // We have existing playback time recorded, already confirmed.
-                            mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_INACTIVE;
-                            mLastMusicActiveTimeMs = 0;
-                        }
-                    }
-                } else {
-                    persistedState = SAFE_MEDIA_VOLUME_DISABLED;
-                    mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_DISABLED;
-                }
-                mMcc = mcc;
-                sendMsg(mAudioHandler,
-                        MSG_PERSIST_SAFE_VOLUME_STATE,
-                        SENDMSG_QUEUE,
-                        persistedState,
-                        0,
-                        null,
-                        0);
-            }
-        }
-    }
-
     ///////////////////////////////////////////////////////////////////////////
     // Internal methods
     ///////////////////////////////////////////////////////////////////////////
@@ -6725,7 +6543,7 @@
             Intent broadcast = new Intent(AudioManager.VIBRATE_SETTING_CHANGED_ACTION);
             broadcast.putExtra(AudioManager.EXTRA_VIBRATE_TYPE, vibrateType);
             broadcast.putExtra(AudioManager.EXTRA_VIBRATE_SETTING, getVibrateSetting(vibrateType));
-            sendBroadcastToAll(broadcast);
+            sendBroadcastToAll(broadcast, null /* options */);
         }
     }
 
@@ -6756,6 +6574,20 @@
         handler.sendMessageAtTime(handler.obtainMessage(msg, arg1, arg2, obj), time);
     }
 
+    private static void sendBundleMsg(Handler handler, int msg,
+            int existingMsgPolicy, int arg1, int arg2, Object obj, Bundle bundle, int delay) {
+        if (existingMsgPolicy == SENDMSG_REPLACE) {
+            handler.removeMessages(msg);
+        } else if (existingMsgPolicy == SENDMSG_NOOP && handler.hasMessages(msg)) {
+            return;
+        }
+
+        final long time = SystemClock.uptimeMillis() + delay;
+        Message message = handler.obtainMessage(msg, arg1, arg2, obj);
+        message.setData(bundle);
+        handler.sendMessageAtTime(message, time);
+    }
+
     boolean checkAudioSettingsPermission(String method) {
         if (callingOrSelfHasAudioSettingsPermission()) {
             return true;
@@ -7711,7 +7543,7 @@
     //  2   mSetModeLock
     //  3     mSettingsLock
     //  4       VolumeStreamState.class
-    private class VolumeStreamState {
+    /*package*/ class VolumeStreamState {
         private final int mStreamType;
         private int mIndexMin;
         // min index when user doesn't have permission to change audio settings
@@ -7750,7 +7582,9 @@
             }
         };
         private final Intent mVolumeChanged;
+        private final Bundle mVolumeChangedOptions;
         private final Intent mStreamDevicesChanged;
+        private final Bundle mStreamDevicesChangedOptions;
 
         private VolumeStreamState(String settingName, int streamType) {
             mVolumeIndexSettingName = settingName;
@@ -7772,8 +7606,21 @@
             readSettings();
             mVolumeChanged = new Intent(AudioManager.VOLUME_CHANGED_ACTION);
             mVolumeChanged.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, mStreamType);
+            final BroadcastOptions volumeChangedOptions = BroadcastOptions.makeBasic();
+            // This allows us to discard older broadcasts still waiting to be delivered
+            // which have the same namespace (VOLUME_CHANGED_ACTION) and key (mStreamType).
+            volumeChangedOptions.setDeliveryGroupPolicy(DELIVERY_GROUP_POLICY_MOST_RECENT);
+            volumeChangedOptions.setDeliveryGroupMatchingKey(
+                    AudioManager.VOLUME_CHANGED_ACTION, String.valueOf(mStreamType));
+            mVolumeChangedOptions = volumeChangedOptions.toBundle();
+
             mStreamDevicesChanged = new Intent(AudioManager.STREAM_DEVICES_CHANGED_ACTION);
             mStreamDevicesChanged.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, mStreamType);
+            final BroadcastOptions streamDevicesChangedOptions = BroadcastOptions.makeBasic();
+            streamDevicesChangedOptions.setDeliveryGroupPolicy(DELIVERY_GROUP_POLICY_MOST_RECENT);
+            streamDevicesChangedOptions.setDeliveryGroupMatchingKey(
+                    AudioManager.STREAM_DEVICES_CHANGED_ACTION, String.valueOf(mStreamType));
+            mStreamDevicesChangedOptions = streamDevicesChangedOptions.toBundle();
         }
 
         /**
@@ -7822,11 +7669,14 @@
             }
             // send STREAM_DEVICES_CHANGED_ACTION on the message handler so it is scheduled after
             // the postObserveDevicesForStreams is handled
+            final SomeArgs args = SomeArgs.obtain();
+            args.arg1 = mStreamDevicesChanged;
+            args.arg2 = mStreamDevicesChangedOptions;
             sendMsg(mAudioHandler,
                     MSG_STREAM_DEVICES_CHANGED,
                     SENDMSG_QUEUE, prevDevices /*arg1*/, devices /*arg2*/,
                     // ok to send reference to this object, it is final
-                    mStreamDevicesChanged /*obj*/, 0 /*delay*/);
+                    args /*obj*/, 0 /*delay*/);
             return mObservedDeviceSet;
         }
 
@@ -8051,7 +7901,7 @@
                     mVolumeChanged.putExtra(AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, oldIndex);
                     mVolumeChanged.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE_ALIAS,
                             mStreamVolumeAlias[mStreamType]);
-                    sendBroadcastToAll(mVolumeChanged);
+                    sendBroadcastToAll(mVolumeChanged, mVolumeChangedOptions);
                 }
             }
             return changed;
@@ -8179,7 +8029,7 @@
                 Intent intent = new Intent(AudioManager.STREAM_MUTE_CHANGED_ACTION);
                 intent.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, mStreamType);
                 intent.putExtra(AudioManager.EXTRA_STREAM_VOLUME_MUTED, state);
-                sendBroadcastToAll(intent);
+                sendBroadcastToAll(intent, null /* options */);
             }
             return changed;
         }
@@ -8364,8 +8214,8 @@
         final VolumeStreamState streamState = mStreamStates[update.mStreamType];
         if (update.hasVolumeIndex()) {
             int index = update.getVolumeIndex();
-            if (!checkSafeMediaVolume(update.mStreamType, index, update.mDevice)) {
-                index = safeMediaVolumeIndex(update.mDevice);
+            if (!mSoundDoseHelper.checkSafeMediaVolume(update.mStreamType, index, update.mDevice)) {
+                index = mSoundDoseHelper.safeMediaVolumeIndex(update.mDevice);
             }
             streamState.setIndex(index, update.mDevice, update.mCaller,
                     // trusted as index is always validated before message is posted
@@ -8415,7 +8265,7 @@
     }
 
     /** Handles internal volume messages in separate volume thread. */
-    private class AudioHandler extends Handler {
+    /*package*/ class AudioHandler extends Handler {
 
         AudioHandler() {
             super();
@@ -8462,12 +8312,6 @@
             mSettings.putGlobalInt(mContentResolver, Settings.Global.MODE_RINGER, ringerMode);
         }
 
-        private void onPersistSafeVolumeState(int state) {
-            mSettings.putGlobalInt(mContentResolver,
-                    Settings.Global.AUDIO_SAFE_VOLUME_STATE,
-                    state);
-        }
-
         private void onNotifyVolumeEvent(@NonNull IAudioPolicyCallback apc,
                 @AudioManager.VolumeAdjustment int direction) {
             try {
@@ -8585,19 +8429,6 @@
                     mSpatializerHelper.reset(/* featureEnabled */ mHasSpatializerEffect);
                     break;
 
-                case MSG_CHECK_MUSIC_ACTIVE:
-                    onCheckMusicActive((String) msg.obj);
-                    break;
-
-                case MSG_CONFIGURE_SAFE_MEDIA_VOLUME_FORCED:
-                case MSG_CONFIGURE_SAFE_MEDIA_VOLUME:
-                    onConfigureSafeVolume((msg.what == MSG_CONFIGURE_SAFE_MEDIA_VOLUME_FORCED),
-                            (String) msg.obj);
-                    break;
-                case MSG_PERSIST_SAFE_VOLUME_STATE:
-                    onPersistSafeVolumeState(msg.arg1);
-                    break;
-
                 case MSG_SYSTEM_READY:
                     onSystemReady();
                     break;
@@ -8610,13 +8441,6 @@
                     onAccessoryPlugMediaUnmute(msg.arg1);
                     break;
 
-                case MSG_PERSIST_MUSIC_ACTIVE_MS:
-                    final int musicActiveMs = msg.arg1;
-                    mSettings.putSecureIntForUser(mContentResolver,
-                            Settings.Secure.UNSAFE_VOLUME_MUSIC_ACTIVE_MS, musicActiveMs,
-                            UserHandle.USER_CURRENT);
-                    break;
-
                 case MSG_UNMUTE_STREAM:
                     onUnmuteStream(msg.arg1, msg.arg2);
                     break;
@@ -8682,9 +8506,14 @@
                     break;
 
                 case MSG_STREAM_DEVICES_CHANGED:
-                    sendBroadcastToAll(((Intent) msg.obj)
+                    final SomeArgs args = (SomeArgs) msg.obj;
+                    final Intent intent = (Intent) args.arg1;
+                    final Bundle options = (Bundle) args.arg2;
+                    args.recycle();
+                    sendBroadcastToAll(intent
                             .putExtra(AudioManager.EXTRA_PREV_VOLUME_STREAM_DEVICES, msg.arg1)
-                            .putExtra(AudioManager.EXTRA_VOLUME_STREAM_DEVICES, msg.arg2));
+                            .putExtra(AudioManager.EXTRA_VOLUME_STREAM_DEVICES, msg.arg2),
+                            options);
                     break;
 
                 case MSG_UPDATE_VOLUME_STATES_FOR_DEVICE:
@@ -8746,6 +8575,16 @@
                 case MSG_NO_LOG_FOR_PLAYER_I:
                     mPlaybackMonitor.ignorePlayerIId(msg.arg1);
                     break;
+
+                case MSG_DISPATCH_PREFERRED_MIXER_ATTRIBUTES:
+                    onDispatchPreferredMixerAttributesChanged(msg.getData(), msg.arg1);
+                    break;
+
+                default:
+                    if (msg.what >= SAFE_MEDIA_VOLUME_MSG_START) {
+                        // msg could be for the SoundDoseHelper
+                        mSoundDoseHelper.handleMessage(msg);
+                    }
             }
         }
     }
@@ -8862,8 +8701,8 @@
     /** only public for mocking/spying, do not call outside of AudioService */
     @VisibleForTesting
     public void checkMusicActive(int deviceType, String caller) {
-        if (mSafeMediaVolumeDevices.contains(deviceType)) {
-            scheduleMusicActiveCheck();
+        if (mSoundDoseHelper.safeDevicesContains(deviceType)) {
+            mSoundDoseHelper.scheduleMusicActiveCheck();
         }
     }
 
@@ -8997,7 +8836,8 @@
                     }
                 }
             } else if (action.equals(ACTION_CHECK_MUSIC_ACTIVE)) {
-                onCheckMusicActive(ACTION_CHECK_MUSIC_ACTIVE);
+                mSoundDoseHelper.onCheckMusicActive(ACTION_CHECK_MUSIC_ACTIVE,
+                        mAudioSystem.isStreamActive(AudioSystem.STREAM_MUSIC, 0));
             }
         }
     } // end class AudioServiceBroadcastReceiver
@@ -9883,13 +9723,7 @@
             // reading new configuration "safely" (i.e. under try catch) in case anything
             // goes wrong.
             Configuration config = context.getResources().getConfiguration();
-            sendMsg(mAudioHandler,
-                    MSG_CONFIGURE_SAFE_MEDIA_VOLUME,
-                    SENDMSG_REPLACE,
-                    0,
-                    0,
-                    TAG,
-                    0);
+            mSoundDoseHelper.configureSafeMediaVolume(/*forced*/false, TAG);
 
             boolean cameraSoundForced = readCameraSoundForced();
             synchronized (mSettingsLock) {
@@ -9947,143 +9781,10 @@
         return mDeviceBroker.startWatchingRoutes(observer);
     }
 
-
-    //==========================================================================================
-    // Safe media volume management.
-    // MUSIC stream volume level is limited when headphones are connected according to safety
-    // regulation. When the user attempts to raise the volume above the limit, a warning is
-    // displayed and the user has to acknowlegde before the volume is actually changed.
-    // The volume index corresponding to the limit is stored in config_safe_media_volume_index
-    // property. Platforms with a different limit must set this property accordingly in their
-    // overlay.
-    //==========================================================================================
-
-    // mSafeMediaVolumeState indicates whether the media volume is limited over headphones.
-    // It is SAFE_MEDIA_VOLUME_NOT_CONFIGURED at boot time until a network service is connected
-    // or the configure time is elapsed. It is then set to SAFE_MEDIA_VOLUME_ACTIVE or
-    // SAFE_MEDIA_VOLUME_DISABLED according to country option. If not SAFE_MEDIA_VOLUME_DISABLED, it
-    // can be set to SAFE_MEDIA_VOLUME_INACTIVE by calling AudioService.disableSafeMediaVolume()
-    // (when user opts out).
-    private static final int SAFE_MEDIA_VOLUME_NOT_CONFIGURED = 0;
-    private static final int SAFE_MEDIA_VOLUME_DISABLED = 1;
-    private static final int SAFE_MEDIA_VOLUME_INACTIVE = 2;  // confirmed
-    private static final int SAFE_MEDIA_VOLUME_ACTIVE = 3;  // unconfirmed
-    private int mSafeMediaVolumeState;
-    private final Object mSafeMediaVolumeStateLock = new Object();
-
-    private int mMcc = 0;
-    // mSafeMediaVolumeIndex is the cached value of config_safe_media_volume_index property
-    private int mSafeMediaVolumeIndex;
-    // mSafeUsbMediaVolumeDbfs is the cached value of the config_safe_media_volume_usb_mB
-    // property, divided by 100.0.
-    private float mSafeUsbMediaVolumeDbfs;
-    // mSafeUsbMediaVolumeIndex is used for USB Headsets and is the music volume UI index
-    // corresponding to a gain of mSafeUsbMediaVolumeDbfs (defaulting to -37dB) in audio
-    // flinger mixer.
-    // We remove -22 dBs from the theoretical -15dB to account for the EQ + bass boost
-    // amplification when both effects are on with all band gains at maximum.
-    // This level corresponds to a loudness of 85 dB SPL for the warning to be displayed when
-    // the headset is compliant to EN 60950 with a max loudness of 100dB SPL.
-    private int mSafeUsbMediaVolumeIndex;
-    // mSafeMediaVolumeDevices lists the devices for which safe media volume is enforced,
-    /*package*/ final Set<Integer> mSafeMediaVolumeDevices = new HashSet<>(
-            Arrays.asList(AudioSystem.DEVICE_OUT_WIRED_HEADSET,
-                    AudioSystem.DEVICE_OUT_WIRED_HEADPHONE, AudioSystem.DEVICE_OUT_USB_HEADSET));
-    // mMusicActiveMs is the cumulative time of music activity since safe volume was disabled.
-    // When this time reaches UNSAFE_VOLUME_MUSIC_ACTIVE_MS_MAX, the safe media volume is re-enabled
-    // automatically. mMusicActiveMs is rounded to a multiple of MUSIC_ACTIVE_POLL_PERIOD_MS.
-    private int mMusicActiveMs;
-    private long mLastMusicActiveTimeMs = 0;
-    private PendingIntent mMusicActiveIntent = null;
-    private AlarmManager mAlarmManager;
-
-    private static final int UNSAFE_VOLUME_MUSIC_ACTIVE_MS_MAX = (20 * 3600 * 1000); // 20 hours
-    private static final int MUSIC_ACTIVE_POLL_PERIOD_MS = 60000;  // 1 minute polling interval
-    private static final int SAFE_VOLUME_CONFIGURE_TIMEOUT_MS = 30000;  // 30s after boot completed
-    // check playback or record activity every 6 seconds for UIDs owning mode IN_COMMUNICATION
-    private static final int CHECK_MODE_FOR_UID_PERIOD_MS = 6000;
-
-    private static final String ACTION_CHECK_MUSIC_ACTIVE =
-            AudioService.class.getSimpleName() + ".CHECK_MUSIC_ACTIVE";
-    private static final int REQUEST_CODE_CHECK_MUSIC_ACTIVE = 1;
-
-    private int safeMediaVolumeIndex(int device) {
-        if (!mSafeMediaVolumeDevices.contains(device)) {
-            return MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC];
-        }
-        if (device == AudioSystem.DEVICE_OUT_USB_HEADSET) {
-            return mSafeUsbMediaVolumeIndex;
-        } else {
-            return mSafeMediaVolumeIndex;
-        }
-    }
-
-    private void setSafeMediaVolumeEnabled(boolean on, String caller) {
-        synchronized (mSafeMediaVolumeStateLock) {
-            if ((mSafeMediaVolumeState != SAFE_MEDIA_VOLUME_NOT_CONFIGURED) &&
-                    (mSafeMediaVolumeState != SAFE_MEDIA_VOLUME_DISABLED)) {
-                if (on && (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_INACTIVE)) {
-                    mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_ACTIVE;
-                    enforceSafeMediaVolume(caller);
-                } else if (!on && (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE)) {
-                    mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_INACTIVE;
-                    mMusicActiveMs = 1;  // nonzero = confirmed
-                    mLastMusicActiveTimeMs = 0;
-                    saveMusicActiveMs();
-                    scheduleMusicActiveCheck();
-                }
-            }
-        }
-    }
-
-    private void enforceSafeMediaVolume(String caller) {
-        VolumeStreamState streamState = mStreamStates[AudioSystem.STREAM_MUSIC];
-        Set<Integer> devices = mSafeMediaVolumeDevices;
-
-        for (int device : devices) {
-            int index = streamState.getIndex(device);
-            if (index > safeMediaVolumeIndex(device)) {
-                streamState.setIndex(safeMediaVolumeIndex(device), device, caller,
-                            true /*hasModifyAudioSettings*/);
-                sendMsg(mAudioHandler,
-                        MSG_SET_DEVICE_VOLUME,
-                        SENDMSG_QUEUE,
-                        device,
-                        0,
-                        streamState,
-                        0);
-            }
-        }
-    }
-
-    private boolean checkSafeMediaVolume(int streamType, int index, int device) {
-        synchronized (mSafeMediaVolumeStateLock) {
-            if ((mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE)
-                    && (mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC)
-                    && (mSafeMediaVolumeDevices.contains(device))
-                    && (index > safeMediaVolumeIndex(device))) {
-                return false;
-            }
-            return true;
-        }
-    }
-
     @Override
     public void disableSafeMediaVolume(String callingPackage) {
         enforceVolumeController("disable the safe media volume");
-        synchronized (mSafeMediaVolumeStateLock) {
-            final long identity = Binder.clearCallingIdentity();
-            setSafeMediaVolumeEnabled(false, callingPackage);
-            Binder.restoreCallingIdentity(identity);
-            if (mPendingVolumeCommand != null) {
-                onSetStreamVolume(mPendingVolumeCommand.mStreamType,
-                                  mPendingVolumeCommand.mIndex,
-                                  mPendingVolumeCommand.mFlags,
-                                  mPendingVolumeCommand.mDevice,
-                                  callingPackage, true /*hasModifyAudioSettings*/);
-                mPendingVolumeCommand = null;
-            }
-        }
+        mSoundDoseHelper.disableSafeMediaVolume(callingPackage);
     }
 
     //==========================================================================================
@@ -10302,6 +10003,7 @@
     static final int LOG_NB_EVENTS_VOLUME = 40;
     static final int LOG_NB_EVENTS_DYN_POLICY = 10;
     static final int LOG_NB_EVENTS_SPATIAL = 30;
+    static final int LOG_NB_EVENTS_SOUND_DOSE = 30;
 
     static final EventLogger
             sLifecycleLogger = new EventLogger(LOG_NB_EVENTS_LIFECYCLE,
@@ -10411,15 +10113,8 @@
 
         pw.println("\nOther state:");
         pw.print("  mVolumeController="); pw.println(mVolumeController);
-        pw.print("  mSafeMediaVolumeState=");
-        pw.println(safeMediaVolumeStateToString(mSafeMediaVolumeState));
-        pw.print("  mSafeMediaVolumeIndex="); pw.println(mSafeMediaVolumeIndex);
-        pw.print("  mSafeUsbMediaVolumeIndex="); pw.println(mSafeUsbMediaVolumeIndex);
-        pw.print("  mSafeUsbMediaVolumeDbfs="); pw.println(mSafeUsbMediaVolumeDbfs);
+        mSoundDoseHelper.dump(pw);
         pw.print("  sIndependentA11yVolume="); pw.println(sIndependentA11yVolume);
-        pw.print("  mPendingVolumeCommand="); pw.println(mPendingVolumeCommand);
-        pw.print("  mMusicActiveMs="); pw.println(mMusicActiveMs);
-        pw.print("  mMcc="); pw.println(mMcc);
         pw.print("  mCameraSoundForced="); pw.println(isCameraSoundForced());
         pw.print("  mHasVibrator="); pw.println(mHasVibrator);
         pw.print("  mVolumePolicy="); pw.println(mVolumePolicy);
@@ -10520,16 +10215,6 @@
     private static final String mMetricsId = MediaMetrics.Name.AUDIO_SERVICE
             + MediaMetrics.SEPARATOR;
 
-    private static String safeMediaVolumeStateToString(int state) {
-        switch(state) {
-            case SAFE_MEDIA_VOLUME_NOT_CONFIGURED: return "SAFE_MEDIA_VOLUME_NOT_CONFIGURED";
-            case SAFE_MEDIA_VOLUME_DISABLED: return "SAFE_MEDIA_VOLUME_DISABLED";
-            case SAFE_MEDIA_VOLUME_INACTIVE: return "SAFE_MEDIA_VOLUME_INACTIVE";
-            case SAFE_MEDIA_VOLUME_ACTIVE: return "SAFE_MEDIA_VOLUME_ACTIVE";
-        }
-        return null;
-    }
-
     // Inform AudioFlinger of our device's low RAM attribute
     private static void readAndSetLowRamDevice()
     {
@@ -10609,7 +10294,14 @@
         }
     }
 
-    public class VolumeController {
+    /** Interface used for enforcing the safe hearing standard. */
+    public interface ISafeHearingVolumeController {
+        /** Displays an instructional safeguard as required by the safe hearing standard. */
+        void postDisplaySafeVolumeWarning(int flags);
+    }
+
+    /** Wrapper which encapsulates the {@link IVolumeController} functionality. */
+    public class VolumeController implements ISafeHearingVolumeController {
         private static final String TAG = "VolumeController";
 
         private IVolumeController mController;
@@ -10696,6 +10388,7 @@
             return "VolumeController(" + asBinder() + ",mVisible=" + mVisible + ")";
         }
 
+        @Override
         public void postDisplaySafeVolumeWarning(int flags) {
             if (mController == null)
                 return;
@@ -11352,6 +11045,125 @@
         }
     }
 
+    /**
+     * @see AudioManager#setPreferredMixerAttributes(
+     *      AudioAttributes, AudioDeviceInfo, AudioMixerAttributes)
+     */
+    public int setPreferredMixerAttributes(AudioAttributes attributes,
+            int portId, AudioMixerAttributes mixerAttributes) {
+        Objects.requireNonNull(attributes);
+        Objects.requireNonNull(mixerAttributes);
+        if (!checkAudioSettingsPermission("setPreferredMixerAttributes()")) {
+            return AudioSystem.PERMISSION_DENIED;
+        }
+        final int uid = Binder.getCallingUid();
+        final int pid = Binder.getCallingPid();
+        int status = AudioSystem.SUCCESS;
+        final long token = Binder.clearCallingIdentity();
+        try {
+            final String logString = TextUtils.formatSimple(
+                    "setPreferredMixerAttributes u/pid:%d/%d attr:%s mixerAttributes:%s portId:%d",
+                    uid, pid, attributes.toString(), mixerAttributes.toString(), portId);
+            sDeviceLogger.enqueue(new EventLogger.StringEvent(logString).printLog(TAG));
+
+            status = mAudioSystem.setPreferredMixerAttributes(
+                    attributes, portId, uid, mixerAttributes);
+            if (status == AudioSystem.SUCCESS) {
+                dispatchPreferredMixerAttributesChanged(attributes, portId, mixerAttributes);
+            } else {
+                Log.e(TAG, TextUtils.formatSimple("Error %d in %s)", status, logString));
+            }
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+        return status;
+    }
+
+    /**
+     * @see AudioManager#clearPreferredMixerAttributes(AudioAttributes, AudioDeviceInfo)
+     */
+    public int clearPreferredMixerAttributes(AudioAttributes attributes, int portId) {
+        Objects.requireNonNull(attributes);
+        if (!checkAudioSettingsPermission("clearPreferredMixerAttributes()")) {
+            return AudioSystem.PERMISSION_DENIED;
+        }
+        final int uid = Binder.getCallingUid();
+        final int pid = Binder.getCallingPid();
+        int status = AudioSystem.SUCCESS;
+        final long token = Binder.clearCallingIdentity();
+        try {
+            final String logString = TextUtils.formatSimple(
+                    "clearPreferredMixerAttributes u/pid:%d/%d attr:%s",
+                    uid, pid, attributes.toString());
+            sDeviceLogger.enqueue(new EventLogger.StringEvent(logString).printLog(TAG));
+
+            status = mAudioSystem.clearPreferredMixerAttributes(attributes, portId, uid);
+            if (status == AudioSystem.SUCCESS) {
+                dispatchPreferredMixerAttributesChanged(attributes, portId, null /*mixerAttr*/);
+            } else {
+                Log.e(TAG, TextUtils.formatSimple("Error %d in %s)", status, logString));
+            }
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+        return status;
+    }
+
+    void dispatchPreferredMixerAttributesChanged(
+            AudioAttributes attr, int deviceId, AudioMixerAttributes mixerAttr) {
+        Bundle bundle = new Bundle();
+        bundle.putParcelable(KEY_AUDIO_ATTRIBUTES, attr);
+        bundle.putParcelable(KEY_AUDIO_MIXER_ATTRIBUTES, mixerAttr);
+        sendBundleMsg(mAudioHandler, MSG_DISPATCH_PREFERRED_MIXER_ATTRIBUTES, SENDMSG_QUEUE,
+                deviceId, 0, null, bundle, 0);
+    }
+
+    final RemoteCallbackList<IPreferredMixerAttributesDispatcher> mPrefMixerAttrDispatcher =
+            new RemoteCallbackList<IPreferredMixerAttributesDispatcher>();
+    private static final String KEY_AUDIO_ATTRIBUTES = "audio_attributes";
+    private static final String KEY_AUDIO_MIXER_ATTRIBUTES = "audio_mixer_attributes";
+
+    /** @see AudioManager#addOnPreferredMixerAttributesChangedListener(
+     *       Executor, AudioManager.OnPreferredMixerAttributesChangedListener)
+     */
+    public void registerPreferredMixerAttributesDispatcher(
+            @Nullable IPreferredMixerAttributesDispatcher dispatcher) {
+        if (dispatcher == null) {
+            return;
+        }
+        mPrefMixerAttrDispatcher.register(dispatcher);
+    }
+
+    /** @see AudioManager#removeOnPreferredMixerAttributesChangedListener(
+     *       AudioManager.OnPreferredMixerAttributesChangedListener)
+     */
+    public void unregisterPreferredMixerAttributesDispatcher(
+            @Nullable IPreferredMixerAttributesDispatcher dispatcher) {
+        if (dispatcher == null) {
+            return;
+        }
+        mPrefMixerAttrDispatcher.unregister(dispatcher);
+    }
+
+    protected void onDispatchPreferredMixerAttributesChanged(Bundle data, int deviceId) {
+        final int nbDispathers = mPrefMixerAttrDispatcher.beginBroadcast();
+        final AudioAttributes attr = data.getParcelable(
+                KEY_AUDIO_ATTRIBUTES, AudioAttributes.class);
+        final AudioMixerAttributes mixerAttr = data.getParcelable(
+                KEY_AUDIO_MIXER_ATTRIBUTES, AudioMixerAttributes.class);
+        for (int i = 0; i < nbDispathers; i++) {
+            try {
+                mPrefMixerAttrDispatcher.getBroadcastItem(i)
+                        .dispatchPrefMixerAttributesChanged(attr, deviceId, mixerAttr);
+            } catch (RemoteException e) {
+                Log.e(TAG, "Can't call dispatchPrefMixerAttributesChanged() "
+                        + "IPreferredMixerAttributesDispatcher "
+                        + mPrefMixerAttrDispatcher.getBroadcastItem(i).asBinder(), e);
+            }
+        }
+        mPrefMixerAttrDispatcher.finishBroadcast();
+    }
+
     private final Object mExtVolumeControllerLock = new Object();
     private IAudioPolicyCallback mExtVolumeController;
     private void setExtVolumeController(IAudioPolicyCallback apc) {
@@ -11427,8 +11239,8 @@
     }
 
     public List<AudioRecordingConfiguration> getActiveRecordingConfigurations() {
-        final boolean isPrivileged =
-                (PackageManager.PERMISSION_GRANTED == mContext.checkCallingPermission(
+        final boolean isPrivileged = Binder.getCallingUid() == Process.SYSTEM_UID
+                || (PackageManager.PERMISSION_GRANTED == mContext.checkCallingPermission(
                         android.Manifest.permission.MODIFY_AUDIO_ROUTING));
         return mRecordMonitor.getActiveRecordingConfigurations(isPrivileged);
     }
@@ -11608,6 +11420,11 @@
             public void onStop() {
                 unregisterAudioPolicyAsync(mPolicyCallback);
             }
+
+            @Override
+            public void onCapturedContentResize(int width, int height) {
+                // Ignore resize of the captured content.
+            }
         };
         UnregisterOnStopCallback mProjectionCallback;
 
diff --git a/services/core/java/com/android/server/audio/AudioServiceEvents.java b/services/core/java/com/android/server/audio/AudioServiceEvents.java
index b920517..d30bec7 100644
--- a/services/core/java/com/android/server/audio/AudioServiceEvents.java
+++ b/services/core/java/com/android/server/audio/AudioServiceEvents.java
@@ -476,4 +476,53 @@
             }
         }
     }
+
+    static final class SoundDoseEvent extends EventLogger.Event {
+        static final int MOMENTARY_EXPOSURE = 0;
+        static final int DOSE_UPDATE = 1;
+        static final int DOSE_REPEAT_5X = 2;
+        static final int DOSE_ACCUMULATION_START = 3;
+        final int mEventType;
+        final float mFloatValue;
+        final long mLongValue;
+
+        private SoundDoseEvent(int event, float f, long l) {
+            mEventType = event;
+            mFloatValue = f;
+            mLongValue = l;
+        }
+
+        static SoundDoseEvent getMomentaryExposureEvent(float mel) {
+            return new SoundDoseEvent(MOMENTARY_EXPOSURE, mel, 0 /*ignored*/);
+        }
+
+        static SoundDoseEvent getDoseUpdateEvent(float csd, long totalDuration) {
+            return new SoundDoseEvent(DOSE_UPDATE, csd, totalDuration);
+        }
+
+        static SoundDoseEvent getDoseRepeat5xEvent() {
+            return new SoundDoseEvent(DOSE_REPEAT_5X, 0 /*ignored*/, 0 /*ignored*/);
+        }
+
+        static SoundDoseEvent getDoseAccumulationStartEvent() {
+            return new SoundDoseEvent(DOSE_ACCUMULATION_START, 0 /*ignored*/, 0 /*ignored*/);
+        }
+
+        @Override
+        public String eventToString() {
+            switch (mEventType) {
+                case MOMENTARY_EXPOSURE:
+                    return String.format("momentary exposure MEL=%.2f", mFloatValue);
+                case DOSE_UPDATE:
+                    return String.format(java.util.Locale.US,
+                            "dose update CSD=%.1f%% total duration=%d",
+                            mFloatValue * 100.0f, mLongValue);
+                case DOSE_REPEAT_5X:
+                    return "CSD reached 500%";
+                case DOSE_ACCUMULATION_START:
+                    return "CSD accumulating: RS2 entered";
+            }
+            return new StringBuilder("FIXME invalid event type:").append(mEventType).toString();
+        }
+    }
 }
diff --git a/services/core/java/com/android/server/audio/AudioSystemAdapter.java b/services/core/java/com/android/server/audio/AudioSystemAdapter.java
index c3754eb..c176f29 100644
--- a/services/core/java/com/android/server/audio/AudioSystemAdapter.java
+++ b/services/core/java/com/android/server/audio/AudioSystemAdapter.java
@@ -20,7 +20,10 @@
 import android.annotation.Nullable;
 import android.media.AudioAttributes;
 import android.media.AudioDeviceAttributes;
+import android.media.AudioMixerAttributes;
 import android.media.AudioSystem;
+import android.media.ISoundDose;
+import android.media.ISoundDoseCallback;
 import android.media.audiopolicy.AudioMix;
 import android.os.SystemClock;
 import android.util.Log;
@@ -189,15 +192,7 @@
             synchronized (mDevicesForAttrCache) {
                 res = mDevicesForAttrCache.get(key);
                 if (res == null) {
-                    // result from AudioSystem guaranteed non-null, but could be invalid
-                    // if there is a failure to talk to APM
                     res = AudioSystem.getDevicesForAttributes(attributes, forVolume);
-                    if (res.size() > 1 && res.get(0) != null
-                            && res.get(0).getInternalType() == AudioSystem.DEVICE_NONE) {
-                        Log.e(TAG, "unable to get devices for " + attributes);
-                        // return now, do not put invalid value in cache
-                        return res;
-                    }
                     mDevicesForAttrCache.put(key, res);
                     if (DEBUG_CACHE) {
                         Log.d(TAG, mMethodNames[METHOD_GETDEVICESFORATTRIBUTES]
@@ -495,6 +490,45 @@
     }
 
     /**
+     * Same as {@link AudioSystem#getSoundDoseInterface(ISoundDoseCallback)}
+     * @param callback
+     * @return
+     */
+    public ISoundDose getSoundDoseInterface(ISoundDoseCallback callback) {
+        return AudioSystem.getSoundDoseInterface(callback);
+    }
+
+    /**
+     * Same as
+     * {@link AudioSystem#setPreferredMixerAttributes(
+     *        AudioAttributes, int, int, AudioMixerAttributes)}
+     * @param attributes
+     * @param mixerAttributes
+     * @param uid
+     * @param portId
+     * @return
+     */
+    public int setPreferredMixerAttributes(
+            @NonNull AudioAttributes attributes,
+            int portId,
+            int uid,
+            @NonNull AudioMixerAttributes mixerAttributes) {
+        return AudioSystem.setPreferredMixerAttributes(attributes, portId, uid, mixerAttributes);
+    }
+
+    /**
+     * Same as {@link AudioSystem#clearPreferredMixerAttributes(AudioAttributes, int, int)}
+     * @param attributes
+     * @param uid
+     * @param portId
+     * @return
+     */
+    public int clearPreferredMixerAttributes(
+            @NonNull AudioAttributes attributes, int portId, int uid) {
+        return AudioSystem.clearPreferredMixerAttributes(attributes, portId, uid);
+    }
+
+    /**
      * Part of AudioService dump
      * @param pw
      */
diff --git a/services/core/java/com/android/server/audio/SoundDoseHelper.java b/services/core/java/com/android/server/audio/SoundDoseHelper.java
new file mode 100644
index 0000000..5fe9ada
--- /dev/null
+++ b/services/core/java/com/android/server/audio/SoundDoseHelper.java
@@ -0,0 +1,589 @@
+/*
+ * 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.server.audio;
+
+import static com.android.server.audio.AudioService.MAX_STREAM_VOLUME;
+import static com.android.server.audio.AudioService.MIN_STREAM_VOLUME;
+import static com.android.server.audio.AudioService.MSG_SET_DEVICE_VOLUME;
+import static com.android.server.audio.AudioService.SAFE_MEDIA_VOLUME_MSG_START;
+
+import android.annotation.NonNull;
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.media.AudioSystem;
+import android.media.ISoundDose;
+import android.media.ISoundDoseCallback;
+import android.media.SoundDoseRecord;
+import android.os.Binder;
+import android.os.Message;
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.os.SystemProperties;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.util.Log;
+import android.util.MathUtils;
+
+import com.android.internal.annotations.GuardedBy;
+import com.android.server.audio.AudioService.AudioHandler;
+import com.android.server.audio.AudioService.ISafeHearingVolumeController;
+import com.android.server.audio.AudioServiceEvents.SoundDoseEvent;
+import com.android.server.utils.EventLogger;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Safe media volume management.
+ * MUSIC stream volume level is limited when headphones are connected according to safety
+ * regulation. When the user attempts to raise the volume above the limit, a warning is
+ * displayed and the user has to acknowledge before the volume is actually changed.
+ * The volume index corresponding to the limit is stored in config_safe_media_volume_index
+ * property. Platforms with a different limit must set this property accordingly in their
+ * overlay.
+ */
+public class SoundDoseHelper {
+    private static final String TAG = "AS.SoundDoseHelper";
+
+    /*package*/ static final String ACTION_CHECK_MUSIC_ACTIVE =
+            AudioService.class.getSimpleName() + ".CHECK_MUSIC_ACTIVE";
+
+    /** Flag to enable/disable the sound dose computation. */
+    private static final boolean USE_CSD_FOR_SAFE_HEARING = false;
+
+    // mSafeMediaVolumeState indicates whether the media volume is limited over headphones.
+    // It is SAFE_MEDIA_VOLUME_NOT_CONFIGURED at boot time until a network service is connected
+    // or the configure time is elapsed. It is then set to SAFE_MEDIA_VOLUME_ACTIVE or
+    // SAFE_MEDIA_VOLUME_DISABLED according to country option. If not SAFE_MEDIA_VOLUME_DISABLED, it
+    // can be set to SAFE_MEDIA_VOLUME_INACTIVE by calling AudioService.disableSafeMediaVolume()
+    // (when user opts out).
+    private static final int SAFE_MEDIA_VOLUME_NOT_CONFIGURED = 0;
+    private static final int SAFE_MEDIA_VOLUME_DISABLED = 1;
+    private static final int SAFE_MEDIA_VOLUME_INACTIVE = 2;  // confirmed
+    private static final int SAFE_MEDIA_VOLUME_ACTIVE = 3;  // unconfirmed
+
+    private static final int MSG_CONFIGURE_SAFE_MEDIA_VOLUME = SAFE_MEDIA_VOLUME_MSG_START + 1;
+    private static final int MSG_PERSIST_SAFE_VOLUME_STATE = SAFE_MEDIA_VOLUME_MSG_START + 2;
+    private static final int MSG_PERSIST_MUSIC_ACTIVE_MS = SAFE_MEDIA_VOLUME_MSG_START + 3;
+
+    private static final int UNSAFE_VOLUME_MUSIC_ACTIVE_MS_MAX = (20 * 3600 * 1000); // 20 hours
+
+    // 30s after boot completed
+    private static final int SAFE_VOLUME_CONFIGURE_TIMEOUT_MS = 30000;
+
+    private static final int MUSIC_ACTIVE_POLL_PERIOD_MS = 60000;  // 1 minute polling interval
+    private static final int REQUEST_CODE_CHECK_MUSIC_ACTIVE = 1;
+
+    private static final float CUSTOM_RS2_VALUE = 90;
+
+    private final EventLogger mLogger = new EventLogger(AudioService.LOG_NB_EVENTS_SOUND_DOSE,
+            "CSD updates");
+
+    private int mMcc = 0;
+
+    final Object mSafeMediaVolumeStateLock = new Object();
+    private int mSafeMediaVolumeState;
+
+    // Used when safe volume warning message display is requested by setStreamVolume(). In this
+    // case, the new requested volume, stream type and device are stored in mPendingVolumeCommand
+    // and used later when/if disableSafeMediaVolume() is called.
+    private StreamVolumeCommand mPendingVolumeCommand;
+
+    // mSafeMediaVolumeIndex is the cached value of config_safe_media_volume_index property
+    private int mSafeMediaVolumeIndex;
+    // mSafeUsbMediaVolumeDbfs is the cached value of the config_safe_media_volume_usb_mB
+    // property, divided by 100.0.
+    private float mSafeUsbMediaVolumeDbfs;
+
+    // mSafeUsbMediaVolumeIndex is used for USB Headsets and is the music volume UI index
+    // corresponding to a gain of mSafeUsbMediaVolumeDbfs (defaulting to -37dB) in audio
+    // flinger mixer.
+    // We remove -22 dBs from the theoretical -15dB to account for the EQ + bass boost
+    // amplification when both effects are on with all band gains at maximum.
+    // This level corresponds to a loudness of 85 dB SPL for the warning to be displayed when
+    // the headset is compliant to EN 60950 with a max loudness of 100dB SPL.
+    private int mSafeUsbMediaVolumeIndex;
+    // mSafeMediaVolumeDevices lists the devices for which safe media volume is enforced,
+    private final Set<Integer> mSafeMediaVolumeDevices = new HashSet<>(
+            Arrays.asList(AudioSystem.DEVICE_OUT_WIRED_HEADSET,
+                    AudioSystem.DEVICE_OUT_WIRED_HEADPHONE, AudioSystem.DEVICE_OUT_USB_HEADSET));
+
+
+    // mMusicActiveMs is the cumulative time of music activity since safe volume was disabled.
+    // When this time reaches UNSAFE_VOLUME_MUSIC_ACTIVE_MS_MAX, the safe media volume is re-enabled
+    // automatically. mMusicActiveMs is rounded to a multiple of MUSIC_ACTIVE_POLL_PERIOD_MS.
+    private int mMusicActiveMs;
+    private long mLastMusicActiveTimeMs = 0;
+    private PendingIntent mMusicActiveIntent = null;
+    private final AlarmManager mAlarmManager;
+
+    @NonNull private final AudioService mAudioService;
+    @NonNull private final SettingsAdapter mSettings;
+    @NonNull private final AudioHandler mAudioHandler;
+    @NonNull private final ISafeHearingVolumeController mVolumeController;
+
+    private ISoundDose mSoundDose;
+    private float mCurrentCsd = 0.f;
+    private final List<SoundDoseRecord> mDoseRecords = new ArrayList<>();
+
+    private final Context mContext;
+
+    private final ISoundDoseCallback.Stub mSoundDoseCallback = new ISoundDoseCallback.Stub() {
+        public void onMomentaryExposure(float currentMel, int deviceId) {
+            Log.w(TAG, "DeviceId " + deviceId + " triggered momentary exposure with value: "
+                    + currentMel);
+            mLogger.enqueue(SoundDoseEvent.getMomentaryExposureEvent(currentMel));
+        }
+
+        public void onNewCsdValue(float currentCsd, SoundDoseRecord[] records) {
+            Log.i(TAG, "onNewCsdValue: " + currentCsd);
+            mCurrentCsd = currentCsd;
+            mDoseRecords.addAll(Arrays.asList(records));
+            long totalDuration = 0;
+            for (SoundDoseRecord record : records) {
+                Log.i(TAG, "  new record: csd=" + record.value
+                        + " averageMel=" + record.averageMel + " timestamp=" + record.timestamp
+                        + " duration=" + record.duration);
+                totalDuration += record.duration;
+            }
+            mLogger.enqueue(SoundDoseEvent.getDoseUpdateEvent(currentCsd, totalDuration));
+        }
+    };
+
+    SoundDoseHelper(@NonNull AudioService audioService, Context context,
+            @NonNull AudioHandler audioHandler,
+            @NonNull SettingsAdapter settings,
+            @NonNull ISafeHearingVolumeController volumeController) {
+        mAudioService = audioService;
+        mAudioHandler = audioHandler;
+        mSettings = settings;
+        mVolumeController = volumeController;
+
+        mContext = context;
+
+        mSafeMediaVolumeState = mSettings.getGlobalInt(audioService.getContentResolver(),
+                Settings.Global.AUDIO_SAFE_VOLUME_STATE, 0);
+
+        // The default safe volume index read here will be replaced by the actual value when
+        // the mcc is read by onConfigureSafeVolume()
+        mSafeMediaVolumeIndex = mContext.getResources().getInteger(
+                com.android.internal.R.integer.config_safe_media_volume_index) * 10;
+
+        mAlarmManager = (AlarmManager) mContext.getSystemService(
+                Context.ALARM_SERVICE);
+
+        initCsd();
+    }
+
+    /*package*/ int safeMediaVolumeIndex(int device) {
+        if (!mSafeMediaVolumeDevices.contains(device)) {
+            return MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC];
+        }
+        if (device == AudioSystem.DEVICE_OUT_USB_HEADSET) {
+            return mSafeUsbMediaVolumeIndex;
+        } else {
+            return mSafeMediaVolumeIndex;
+        }
+    }
+
+    /*package*/ void restoreMusicActiveMs() {
+        synchronized (mSafeMediaVolumeStateLock) {
+            mMusicActiveMs = MathUtils.constrain(
+                    mSettings.getSecureIntForUser(mAudioService.getContentResolver(),
+                            Settings.Secure.UNSAFE_VOLUME_MUSIC_ACTIVE_MS, 0,
+                            UserHandle.USER_CURRENT),
+                    0, UNSAFE_VOLUME_MUSIC_ACTIVE_MS_MAX);
+        }
+    }
+
+    /*package*/ void enforceSafeMediaVolumeIfActive(String caller) {
+        synchronized (mSafeMediaVolumeStateLock) {
+            if (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE) {
+                enforceSafeMediaVolume(caller);
+            }
+        }
+    }
+
+    /*package*/ void enforceSafeMediaVolume(String caller) {
+        AudioService.VolumeStreamState streamState = mAudioService.getVssVolumeForStream(
+                AudioSystem.STREAM_MUSIC);
+        Set<Integer> devices = mSafeMediaVolumeDevices;
+
+        for (int device : devices) {
+            int index = streamState.getIndex(device);
+            int safeIndex = safeMediaVolumeIndex(device);
+            if (index > safeIndex) {
+                streamState.setIndex(safeIndex, device, caller, true /*hasModifyAudioSettings*/);
+                mAudioHandler.sendMessageAtTime(
+                        mAudioHandler.obtainMessage(MSG_SET_DEVICE_VOLUME, device, /*arg2=*/0,
+                                streamState), /*delay=*/0);
+            }
+        }
+    }
+
+    /*package*/ boolean checkSafeMediaVolume(int streamType, int index, int device) {
+        boolean result;
+        synchronized (mSafeMediaVolumeStateLock) {
+            result = checkSafeMediaVolume_l(streamType, index, device);
+        }
+        return result;
+    }
+
+    @GuardedBy("mSafeMediaVolumeStateLock")
+    private boolean checkSafeMediaVolume_l(int streamType, int index, int device) {
+        return (mSafeMediaVolumeState != SAFE_MEDIA_VOLUME_ACTIVE)
+                    || (AudioService.mStreamVolumeAlias[streamType] != AudioSystem.STREAM_MUSIC)
+                    || (!mSafeMediaVolumeDevices.contains(device))
+                    || (index <= safeMediaVolumeIndex(device))
+                    || USE_CSD_FOR_SAFE_HEARING;
+    }
+
+    /*package*/ boolean willDisplayWarningAfterCheckVolume(int streamType, int index, int device,
+            int flags) {
+        synchronized (mSafeMediaVolumeStateLock) {
+            if (!checkSafeMediaVolume_l(streamType, index, device)) {
+                mVolumeController.postDisplaySafeVolumeWarning(flags);
+                mPendingVolumeCommand = new StreamVolumeCommand(
+                        streamType, index, flags, device);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /*package*/ void disableSafeMediaVolume(String callingPackage) {
+        synchronized (mSafeMediaVolumeStateLock) {
+            final long identity = Binder.clearCallingIdentity();
+            setSafeMediaVolumeEnabled(false, callingPackage);
+            Binder.restoreCallingIdentity(identity);
+
+            if (mPendingVolumeCommand != null) {
+                mAudioService.onSetStreamVolume(mPendingVolumeCommand.mStreamType,
+                        mPendingVolumeCommand.mIndex,
+                        mPendingVolumeCommand.mFlags,
+                        mPendingVolumeCommand.mDevice,
+                        callingPackage, true /*hasModifyAudioSettings*/);
+                mPendingVolumeCommand = null;
+            }
+        }
+    }
+
+    /*package*/ void scheduleMusicActiveCheck() {
+        synchronized (mSafeMediaVolumeStateLock) {
+            cancelMusicActiveCheck();
+            if (!USE_CSD_FOR_SAFE_HEARING) {
+                mMusicActiveIntent = PendingIntent.getBroadcast(mContext,
+                        REQUEST_CODE_CHECK_MUSIC_ACTIVE,
+                        new Intent(ACTION_CHECK_MUSIC_ACTIVE),
+                        PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
+                mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
+                        SystemClock.elapsedRealtime()
+                                + MUSIC_ACTIVE_POLL_PERIOD_MS, mMusicActiveIntent);
+            }
+        }
+    }
+
+    /*package*/ void onCheckMusicActive(String caller, boolean isStreamActive) {
+        synchronized (mSafeMediaVolumeStateLock) {
+            if (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_INACTIVE) {
+                int device = mAudioService.getDeviceForStream(AudioSystem.STREAM_MUSIC);
+                if (mSafeMediaVolumeDevices.contains(device) && isStreamActive) {
+                    scheduleMusicActiveCheck();
+                    int index = mAudioService.getVssVolumeForDevice(AudioSystem.STREAM_MUSIC,
+                            device);
+                    if (index > safeMediaVolumeIndex(device)) {
+                        // Approximate cumulative active music time
+                        long curTimeMs = SystemClock.elapsedRealtime();
+                        if (mLastMusicActiveTimeMs != 0) {
+                            mMusicActiveMs += (int) (curTimeMs - mLastMusicActiveTimeMs);
+                        }
+                        mLastMusicActiveTimeMs = curTimeMs;
+                        Log.i(TAG, "onCheckMusicActive() mMusicActiveMs: " + mMusicActiveMs);
+                        if (mMusicActiveMs > UNSAFE_VOLUME_MUSIC_ACTIVE_MS_MAX) {
+                            setSafeMediaVolumeEnabled(true, caller);
+                            mMusicActiveMs = 0;
+                        }
+                        saveMusicActiveMs();
+                    }
+                } else {
+                    cancelMusicActiveCheck();
+                    mLastMusicActiveTimeMs = 0;
+                }
+            }
+        }
+    }
+
+    /*package*/ void configureSafeMediaVolume(boolean forced, String caller) {
+        int msg = MSG_CONFIGURE_SAFE_MEDIA_VOLUME;
+        mAudioHandler.removeMessages(msg);
+
+        long time = 0;
+        if (forced) {
+            time = (SystemClock.uptimeMillis() + (SystemProperties.getBoolean(
+                    "audio.safemedia.bypass", false) ? 0 : SAFE_VOLUME_CONFIGURE_TIMEOUT_MS));
+        }
+        mAudioHandler.sendMessageAtTime(
+                mAudioHandler.obtainMessage(msg, /*arg1=*/forced ? 1 : 0, /*arg2=*/0, caller),
+                time);
+    }
+
+    /*package*/ void initSafeUsbMediaVolumeIndex() {
+        // mSafeUsbMediaVolumeIndex must be initialized after createStreamStates() because it
+        // relies on audio policy having correct ranges for volume indexes.
+        mSafeUsbMediaVolumeIndex = getSafeUsbMediaVolumeIndex();
+    }
+
+    /*package*/ int getSafeMediaVolumeIndex(int device) {
+        if (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE && mSafeMediaVolumeDevices.contains(
+                device)) {
+            return safeMediaVolumeIndex(device);
+        } else {
+            return -1;
+        }
+    }
+
+    /*package*/ boolean raiseVolumeDisplaySafeMediaVolume(int streamType, int index, int device,
+            int flags) {
+        if (checkSafeMediaVolume(streamType, index, device)) {
+            return false;
+        }
+
+        mVolumeController.postDisplaySafeVolumeWarning(flags);
+        return true;
+    }
+
+    /*package*/ boolean safeDevicesContains(int device) {
+        return mSafeMediaVolumeDevices.contains(device);
+    }
+
+    /*package*/ void invalidatPendingVolumeCommand() {
+        synchronized (mSafeMediaVolumeStateLock) {
+            mPendingVolumeCommand = null;
+        }
+    }
+
+    /*package*/ void handleMessage(Message msg) {
+        switch (msg.what) {
+            case MSG_CONFIGURE_SAFE_MEDIA_VOLUME:
+                onConfigureSafeVolume((msg.arg1 == 1), (String) msg.obj);
+                break;
+            case MSG_PERSIST_SAFE_VOLUME_STATE:
+                onPersistSafeVolumeState(msg.arg1);
+                break;
+            case MSG_PERSIST_MUSIC_ACTIVE_MS:
+                final int musicActiveMs = msg.arg1;
+                mSettings.putSecureIntForUser(mAudioService.getContentResolver(),
+                        Settings.Secure.UNSAFE_VOLUME_MUSIC_ACTIVE_MS, musicActiveMs,
+                        UserHandle.USER_CURRENT);
+                break;
+        }
+
+    }
+
+    /*package*/ void dump(PrintWriter pw) {
+        pw.print("  mSafeMediaVolumeState=");
+        pw.println(safeMediaVolumeStateToString(mSafeMediaVolumeState));
+        pw.print("  mSafeMediaVolumeIndex="); pw.println(mSafeMediaVolumeIndex);
+        pw.print("  mSafeUsbMediaVolumeIndex="); pw.println(mSafeUsbMediaVolumeIndex);
+        pw.print("  mSafeUsbMediaVolumeDbfs="); pw.println(mSafeUsbMediaVolumeDbfs);
+        pw.print("  mMusicActiveMs="); pw.println(mMusicActiveMs);
+        pw.print("  mMcc="); pw.println(mMcc);
+        pw.print("  mPendingVolumeCommand="); pw.println(mPendingVolumeCommand);
+        pw.println();
+        mLogger.dump(pw);
+        pw.println();
+    }
+
+    /*package*/void reset() {
+        Log.d(TAG, "Reset the sound dose helper");
+        initCsd();
+    }
+
+    private void initCsd() {
+        synchronized (mSafeMediaVolumeStateLock) {
+            if (USE_CSD_FOR_SAFE_HEARING) {
+                Log.v(TAG, "Initializing sound dose");
+
+                mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_DISABLED;
+                mSoundDose = AudioSystem.getSoundDoseInterface(mSoundDoseCallback);
+                try {
+                    if (mSoundDose != null && mSoundDose.asBinder().isBinderAlive()) {
+                        mSoundDose.setOutputRs2(CUSTOM_RS2_VALUE);
+                        if (mCurrentCsd != 0.f) {
+                            Log.d(TAG, "Resetting the saved sound dose value " + mCurrentCsd);
+                            SoundDoseRecord[] records = mDoseRecords.toArray(
+                                    new SoundDoseRecord[0]);
+                            mSoundDose.resetCsd(mCurrentCsd, records);
+                        }
+                    }
+                } catch (RemoteException e) {
+                    // noop
+                }
+            }
+        }
+    }
+
+    private void onConfigureSafeVolume(boolean force, String caller) {
+        synchronized (mSafeMediaVolumeStateLock) {
+            int mcc = mContext.getResources().getConfiguration().mcc;
+            if ((mMcc != mcc) || ((mMcc == 0) && force)) {
+                mSafeMediaVolumeIndex = mContext.getResources().getInteger(
+                        com.android.internal.R.integer.config_safe_media_volume_index) * 10;
+
+                mSafeUsbMediaVolumeIndex = getSafeUsbMediaVolumeIndex();
+
+                boolean safeMediaVolumeEnabled =
+                        SystemProperties.getBoolean("audio.safemedia.force", false)
+                                || mContext.getResources().getBoolean(
+                                com.android.internal.R.bool.config_safe_media_volume_enabled);
+
+                boolean safeMediaVolumeBypass =
+                        SystemProperties.getBoolean("audio.safemedia.bypass", false);
+
+                // The persisted state is either "disabled" or "active": this is the state applied
+                // next time we boot and cannot be "inactive"
+                int persistedState;
+                if (safeMediaVolumeEnabled && !safeMediaVolumeBypass && !USE_CSD_FOR_SAFE_HEARING) {
+                    persistedState = SAFE_MEDIA_VOLUME_ACTIVE;
+                    // The state can already be "inactive" here if the user has forced it before
+                    // the 30 seconds timeout for forced configuration. In this case we don't reset
+                    // it to "active".
+                    if (mSafeMediaVolumeState != SAFE_MEDIA_VOLUME_INACTIVE) {
+                        if (mMusicActiveMs == 0) {
+                            mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_ACTIVE;
+                            enforceSafeMediaVolume(caller);
+                        } else {
+                            // We have existing playback time recorded, already confirmed.
+                            mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_INACTIVE;
+                            mLastMusicActiveTimeMs = 0;
+                        }
+                    }
+                } else {
+                    persistedState = SAFE_MEDIA_VOLUME_DISABLED;
+                    mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_DISABLED;
+                }
+                mMcc = mcc;
+                mAudioHandler.sendMessageAtTime(
+                        mAudioHandler.obtainMessage(MSG_PERSIST_SAFE_VOLUME_STATE,
+                                persistedState, /*arg2=*/0,
+                                /*obj=*/null), /*delay=*/0);
+            }
+        }
+    }
+
+    @GuardedBy("mSafeMediaVolumeStateLock")
+    private void setSafeMediaVolumeEnabled(boolean on, String caller) {
+        if ((mSafeMediaVolumeState != SAFE_MEDIA_VOLUME_NOT_CONFIGURED) && (mSafeMediaVolumeState
+                != SAFE_MEDIA_VOLUME_DISABLED)) {
+            if (on && (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_INACTIVE)) {
+                mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_ACTIVE;
+                enforceSafeMediaVolume(caller);
+            } else if (!on && (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE)) {
+                mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_INACTIVE;
+                mMusicActiveMs = 1;  // nonzero = confirmed
+                mLastMusicActiveTimeMs = 0;
+                saveMusicActiveMs();
+                scheduleMusicActiveCheck();
+            }
+        }
+    }
+
+    @GuardedBy("mSafeMediaVolumeStateLock")
+    private void cancelMusicActiveCheck() {
+        if (mMusicActiveIntent != null) {
+            mAlarmManager.cancel(mMusicActiveIntent);
+            mMusicActiveIntent = null;
+        }
+    }
+
+    @GuardedBy("mSafeMediaVolumeStateLock")
+    private void saveMusicActiveMs() {
+        mAudioHandler.obtainMessage(MSG_PERSIST_MUSIC_ACTIVE_MS, mMusicActiveMs, 0).sendToTarget();
+    }
+
+    private int getSafeUsbMediaVolumeIndex() {
+        // determine UI volume index corresponding to the wanted safe gain in dBFS
+        int min = MIN_STREAM_VOLUME[AudioSystem.STREAM_MUSIC];
+        int max = MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC];
+
+        mSafeUsbMediaVolumeDbfs = mContext.getResources().getInteger(
+                com.android.internal.R.integer.config_safe_media_volume_usb_mB) / 100.0f;
+
+        while (Math.abs(max - min) > 1) {
+            int index = (max + min) / 2;
+            float gainDB = AudioSystem.getStreamVolumeDB(
+                    AudioSystem.STREAM_MUSIC, index, AudioSystem.DEVICE_OUT_USB_HEADSET);
+            if (Float.isNaN(gainDB)) {
+                //keep last min in case of read error
+                break;
+            } else if (gainDB == mSafeUsbMediaVolumeDbfs) {
+                min = index;
+                break;
+            } else if (gainDB < mSafeUsbMediaVolumeDbfs) {
+                min = index;
+            } else {
+                max = index;
+            }
+        }
+        return min * 10;
+    }
+
+    private void onPersistSafeVolumeState(int state) {
+        mSettings.putGlobalInt(mAudioService.getContentResolver(),
+                Settings.Global.AUDIO_SAFE_VOLUME_STATE,
+                state);
+    }
+
+    private static String safeMediaVolumeStateToString(int state) {
+        switch(state) {
+            case SAFE_MEDIA_VOLUME_NOT_CONFIGURED: return "SAFE_MEDIA_VOLUME_NOT_CONFIGURED";
+            case SAFE_MEDIA_VOLUME_DISABLED: return "SAFE_MEDIA_VOLUME_DISABLED";
+            case SAFE_MEDIA_VOLUME_INACTIVE: return "SAFE_MEDIA_VOLUME_INACTIVE";
+            case SAFE_MEDIA_VOLUME_ACTIVE: return "SAFE_MEDIA_VOLUME_ACTIVE";
+        }
+        return null;
+    }
+
+    // StreamVolumeCommand contains the information needed to defer the process of
+    // setStreamVolume() in case the user has to acknowledge the safe volume warning message.
+    private static class StreamVolumeCommand {
+        public final int mStreamType;
+        public final int mIndex;
+        public final int mFlags;
+        public final int mDevice;
+
+        StreamVolumeCommand(int streamType, int index, int flags, int device) {
+            mStreamType = streamType;
+            mIndex = index;
+            mFlags = flags;
+            mDevice = device;
+        }
+
+        @Override
+        public String toString() {
+            return new StringBuilder().append("{streamType=").append(mStreamType).append(",index=")
+                    .append(mIndex).append(",flags=").append(mFlags).append(",device=")
+                    .append(mDevice).append('}').toString();
+        }
+    }
+}
diff --git a/services/core/java/com/android/server/audio/TEST_MAPPING b/services/core/java/com/android/server/audio/TEST_MAPPING
index f3a73f0..d6c2fb2 100644
--- a/services/core/java/com/android/server/audio/TEST_MAPPING
+++ b/services/core/java/com/android/server/audio/TEST_MAPPING
@@ -13,6 +13,17 @@
                     "include-filter": "android.media.audio.cts.SpatializerTest"
                 }
             ]
+        },
+        {
+            "name": "audiopolicytest",
+            "options": [
+                {
+                    "include-filter": "com.android.audiopolicytest.AudioPolicyDeathTest"
+                },
+                {
+                    "include-annotation": "android.platform.test.annotations.Presubmit"
+                }
+            ]
         }
     ]
 }
diff --git a/services/core/java/com/android/server/broadcastradio/IRadioServiceAidlImpl.java b/services/core/java/com/android/server/broadcastradio/IRadioServiceAidlImpl.java
index 6a01042..b66120d 100644
--- a/services/core/java/com/android/server/broadcastradio/IRadioServiceAidlImpl.java
+++ b/services/core/java/com/android/server/broadcastradio/IRadioServiceAidlImpl.java
@@ -86,7 +86,8 @@
 
     @Override
     public ITuner openTuner(int moduleId, RadioManager.BandConfig bandConfig,
-            boolean withAudio, ITunerCallback callback) throws RemoteException {
+            boolean withAudio, ITunerCallback callback, int targetSdkVersion)
+            throws RemoteException {
         if (isDebugEnabled()) {
             Slogf.d(TAG, "Opening module %d", moduleId);
         }
@@ -94,7 +95,7 @@
         if (callback == null) {
             throw new IllegalArgumentException("Callback must not be null");
         }
-        return mHalAidl.openSession(moduleId, bandConfig, withAudio, callback);
+        return mHalAidl.openSession(moduleId, bandConfig, withAudio, callback, targetSdkVersion);
     }
 
     @Override
diff --git a/services/core/java/com/android/server/broadcastradio/IRadioServiceHidlImpl.java b/services/core/java/com/android/server/broadcastradio/IRadioServiceHidlImpl.java
index 408fba1..8a1ba19 100644
--- a/services/core/java/com/android/server/broadcastradio/IRadioServiceHidlImpl.java
+++ b/services/core/java/com/android/server/broadcastradio/IRadioServiceHidlImpl.java
@@ -92,7 +92,8 @@
 
     @Override
     public ITuner openTuner(int moduleId, RadioManager.BandConfig bandConfig,
-            boolean withAudio, ITunerCallback callback) throws RemoteException {
+            boolean withAudio, ITunerCallback callback, int targetSdkVersion)
+            throws RemoteException {
         if (isDebugEnabled()) {
             Slog.d(TAG, "Opening module " + moduleId);
         }
diff --git a/services/core/java/com/android/server/broadcastradio/aidl/BroadcastRadioServiceImpl.java b/services/core/java/com/android/server/broadcastradio/aidl/BroadcastRadioServiceImpl.java
index 03acf72..772cd41 100644
--- a/services/core/java/com/android/server/broadcastradio/aidl/BroadcastRadioServiceImpl.java
+++ b/services/core/java/com/android/server/broadcastradio/aidl/BroadcastRadioServiceImpl.java
@@ -199,7 +199,8 @@
      */
     @Nullable
     public ITuner openSession(int moduleId, @Nullable RadioManager.BandConfig legacyConfig,
-            boolean withAudio, ITunerCallback callback) throws RemoteException {
+            boolean withAudio, ITunerCallback callback, int targetSdkVersion)
+            throws RemoteException {
         if (DEBUG) {
             Slogf.d(TAG, "Open AIDL radio session");
         }
@@ -222,7 +223,7 @@
             }
         }
 
-        TunerSession tunerSession = radioModule.openSession(callback);
+        TunerSession tunerSession = radioModule.openSession(callback, targetSdkVersion);
         if (legacyConfig != null) {
             tunerSession.setConfiguration(legacyConfig);
         }
diff --git a/services/core/java/com/android/server/broadcastradio/aidl/ConversionUtils.java b/services/core/java/com/android/server/broadcastradio/aidl/ConversionUtils.java
index d90f9c4..3c0fda8 100644
--- a/services/core/java/com/android/server/broadcastradio/aidl/ConversionUtils.java
+++ b/services/core/java/com/android/server/broadcastradio/aidl/ConversionUtils.java
@@ -33,6 +33,8 @@
 import android.hardware.radio.ProgramSelector;
 import android.hardware.radio.RadioManager;
 import android.hardware.radio.RadioMetadata;
+import android.hardware.radio.RadioTuner;
+import android.os.Build;
 import android.os.ParcelableException;
 import android.os.ServiceSpecificException;
 import android.util.ArrayMap;
@@ -62,6 +64,11 @@
         throw new UnsupportedOperationException("ConversionUtils class is noninstantiable");
     }
 
+    static boolean isAtLeastU(int targetSdkVersion) {
+        // TODO(b/261770108): Use version code for U.
+        return targetSdkVersion >= Build.VERSION_CODES.CUR_DEVELOPMENT;
+    }
+
     static RuntimeException throwOnError(RuntimeException halException, String action) {
         if (!(halException instanceof ServiceSpecificException)) {
             return new ParcelableException(new RuntimeException(
@@ -89,6 +96,27 @@
         }
     }
 
+    @RadioTuner.TunerResultType
+    static int halResultToTunerResult(int result) {
+        switch (result) {
+            case Result.OK:
+                return RadioTuner.TUNER_RESULT_OK;
+            case Result.INTERNAL_ERROR:
+                return RadioTuner.TUNER_RESULT_INTERNAL_ERROR;
+            case Result.INVALID_ARGUMENTS:
+                return RadioTuner.TUNER_RESULT_INVALID_ARGUMENTS;
+            case Result.INVALID_STATE:
+                return RadioTuner.TUNER_RESULT_INVALID_STATE;
+            case Result.NOT_SUPPORTED:
+                return RadioTuner.TUNER_RESULT_NOT_SUPPORTED;
+            case Result.TIMEOUT:
+                return RadioTuner.TUNER_RESULT_TIMEOUT;
+            case Result.UNKNOWN_ERROR:
+            default:
+                return RadioTuner.TUNER_RESULT_UNKNOWN_ERROR;
+        }
+    }
+
     static VendorKeyValue[] vendorInfoToHalVendorKeyValues(@Nullable Map<String, String> info) {
         if (info == null) {
             return new VendorKeyValue[]{};
@@ -143,6 +171,7 @@
             case ProgramSelector.IDENTIFIER_TYPE_DAB_ENSEMBLE:
             case ProgramSelector.IDENTIFIER_TYPE_DAB_SCID:
             case ProgramSelector.IDENTIFIER_TYPE_DAB_FREQUENCY:
+            case ProgramSelector.IDENTIFIER_TYPE_DAB_DMB_SID_EXT:
                 return ProgramSelector.PROGRAM_TYPE_DAB;
             case ProgramSelector.IDENTIFIER_TYPE_DRMO_SERVICE_ID:
             case ProgramSelector.IDENTIFIER_TYPE_DRMO_FREQUENCY:
@@ -471,6 +500,60 @@
         return new ProgramList.Chunk(chunk.purge, chunk.complete, modified, removed);
     }
 
+    private static boolean isNewIdentifierInU(ProgramSelector.Identifier id) {
+        return id.getType() == ProgramSelector.IDENTIFIER_TYPE_DAB_DMB_SID_EXT;
+    }
+
+    static boolean programSelectorMeetsSdkVersionRequirement(ProgramSelector sel,
+            int targetSdkVersion) {
+        if (isAtLeastU(targetSdkVersion)) {
+            return true;
+        }
+        if (sel.getPrimaryId().getType() == ProgramSelector.IDENTIFIER_TYPE_DAB_DMB_SID_EXT) {
+            return false;
+        }
+        ProgramSelector.Identifier[] secondaryIds = sel.getSecondaryIds();
+        for (int i = 0; i < secondaryIds.length; i++) {
+            if (isNewIdentifierInU(secondaryIds[i])) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    static boolean programInfoMeetsSdkVersionRequirement(RadioManager.ProgramInfo info,
+            int targetSdkVersion) {
+        if (isAtLeastU(targetSdkVersion)) {
+            return true;
+        }
+        if (!programSelectorMeetsSdkVersionRequirement(info.getSelector(), targetSdkVersion)) {
+            return false;
+        }
+        if (isNewIdentifierInU(info.getLogicallyTunedTo())
+                || isNewIdentifierInU(info.getPhysicallyTunedTo())) {
+            return false;
+        }
+        Iterator<ProgramSelector.Identifier> relatedContentIt = info.getRelatedContent().iterator();
+        while (relatedContentIt.hasNext()) {
+            if (isNewIdentifierInU(relatedContentIt.next())) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    static ProgramList.Chunk convertChunkToTargetSdkVersion(ProgramList.Chunk chunk,
+            int targetSdkVersion) {
+        if (isAtLeastU(targetSdkVersion)) {
+            return chunk;
+        }
+        Set<RadioManager.ProgramInfo> modified = chunk.getModified();
+        modified.removeIf(info -> !programInfoMeetsSdkVersionRequirement(info, targetSdkVersion));
+        Set<ProgramSelector.Identifier> removed = chunk.getRemoved();
+        removed.removeIf(id -> isNewIdentifierInU(id));
+        return new ProgramList.Chunk(chunk.isPurge(), chunk.isComplete(), modified, removed);
+    }
+
     public static android.hardware.radio.Announcement announcementFromHalAnnouncement(
             Announcement hwAnnouncement) {
         return new android.hardware.radio.Announcement(
diff --git a/services/core/java/com/android/server/broadcastradio/aidl/RadioModule.java b/services/core/java/com/android/server/broadcastradio/aidl/RadioModule.java
index e956a9c..6193f23 100644
--- a/services/core/java/com/android/server/broadcastradio/aidl/RadioModule.java
+++ b/services/core/java/com/android/server/broadcastradio/aidl/RadioModule.java
@@ -100,7 +100,16 @@
                 synchronized (mLock) {
                     android.hardware.radio.ProgramSelector csel =
                             ConversionUtils.programSelectorFromHalProgramSelector(programSelector);
-                    fanoutAidlCallbackLocked(cb -> cb.onTuneFailed(result, csel));
+                    int tunerResult = ConversionUtils.halResultToTunerResult(result);
+                    fanoutAidlCallbackLocked((cb, sdkVersion) -> {
+                        if (csel != null && !ConversionUtils
+                                .programSelectorMeetsSdkVersionRequirement(csel, sdkVersion)) {
+                            Slogf.e(TAG, "onTuneFailed: cannot send program selector "
+                                    + "requiring higher target SDK version");
+                            return;
+                        }
+                        cb.onTuneFailed(tunerResult, csel);
+                    });
                 }
             });
         }
@@ -112,7 +121,13 @@
                     mCurrentProgramInfo =
                             ConversionUtils.programInfoFromHalProgramInfo(halProgramInfo);
                     RadioManager.ProgramInfo currentProgramInfo = mCurrentProgramInfo;
-                    fanoutAidlCallbackLocked(cb -> {
+                    fanoutAidlCallbackLocked((cb, sdkVersion) -> {
+                        if (!ConversionUtils.programInfoMeetsSdkVersionRequirement(
+                                currentProgramInfo, sdkVersion)) {
+                            Slogf.e(TAG, "onCurrentProgramInfoChanged: cannot send "
+                                    + "program info requiring higher target SDK version");
+                            return;
+                        }
                         cb.onCurrentProgramInfoChanged(currentProgramInfo);
                     });
                 }
@@ -139,7 +154,7 @@
             fireLater(() -> {
                 synchronized (mLock) {
                     mAntennaConnected = connected;
-                    fanoutAidlCallbackLocked(cb -> cb.onAntennaState(connected));
+                    fanoutAidlCallbackLocked((cb, sdkVersion) -> cb.onAntennaState(connected));
                 }
             });
         }
@@ -147,8 +162,11 @@
         @Override
         public void onConfigFlagUpdated(int flag, boolean value) {
             fireLater(() -> {
-                // TODO(b/243853343): implement config flag update method in
-                //  android.hardware.radio.ITunerCallback
+                synchronized (mLock) {
+                    fanoutAidlCallbackLocked((cb, sdkVersion) -> {
+                        cb.onConfigFlagUpdated(flag, value);
+                    });
+                }
             });
         }
 
@@ -158,7 +176,9 @@
                 synchronized (mLock) {
                     Map<String, String> cparam =
                             ConversionUtils.vendorInfoFromHalVendorKeyValues(parameters);
-                    fanoutAidlCallbackLocked(cb -> cb.onParametersUpdated(cparam));
+                    fanoutAidlCallbackLocked((cb, sdkVersion) -> {
+                        cb.onParametersUpdated(cparam);
+                    });
                 }
             });
         }
@@ -222,14 +242,14 @@
         mService.setTunerCallback(mHalTunerCallback);
     }
 
-    TunerSession openSession(android.hardware.radio.ITunerCallback userCb)
+    TunerSession openSession(android.hardware.radio.ITunerCallback userCb, int targetSdkVersion)
             throws RemoteException {
         mLogger.logRadioEvent("Open TunerSession");
         TunerSession tunerSession;
         Boolean antennaConnected;
         RadioManager.ProgramInfo currentProgramInfo;
         synchronized (mLock) {
-            tunerSession = new TunerSession(this, mService, userCb);
+            tunerSession = new TunerSession(this, mService, userCb, targetSdkVersion);
             mAidlTunerSessions.add(tunerSession);
             antennaConnected = mAntennaConnected;
             currentProgramInfo = mCurrentProgramInfo;
@@ -382,7 +402,8 @@
     }
 
     interface AidlCallbackRunnable {
-        void run(android.hardware.radio.ITunerCallback callback) throws RemoteException;
+        void run(android.hardware.radio.ITunerCallback callback, int targetSdkVersion)
+                throws RemoteException;
     }
 
     // Invokes runnable with each TunerSession currently open.
@@ -399,7 +420,8 @@
         List<TunerSession> deadSessions = null;
         for (int i = 0; i < mAidlTunerSessions.size(); i++) {
             try {
-                runnable.run(mAidlTunerSessions.valueAt(i).mCallback);
+                runnable.run(mAidlTunerSessions.valueAt(i).mCallback,
+                        mAidlTunerSessions.valueAt(i).getTargetSdkVersion());
             } catch (DeadObjectException ex) {
                 // The other side died without calling close(), so just purge it from our records.
                 Slogf.e(TAG, "Removing dead TunerSession");
diff --git a/services/core/java/com/android/server/broadcastradio/aidl/TunerSession.java b/services/core/java/com/android/server/broadcastradio/aidl/TunerSession.java
index 1ce4044..d700ed0 100644
--- a/services/core/java/com/android/server/broadcastradio/aidl/TunerSession.java
+++ b/services/core/java/com/android/server/broadcastradio/aidl/TunerSession.java
@@ -21,7 +21,6 @@
 import android.hardware.broadcastradio.ConfigFlag;
 import android.hardware.broadcastradio.IBroadcastRadio;
 import android.hardware.radio.ITuner;
-import android.hardware.radio.ITunerCallback;
 import android.hardware.radio.ProgramList;
 import android.hardware.radio.ProgramSelector;
 import android.hardware.radio.RadioManager;
@@ -47,6 +46,7 @@
     private final RadioLogger mLogger;
     private final RadioModule mModule;
     final android.hardware.radio.ITunerCallback mCallback;
+    private final int mTargetSdkVersion;
     private final IBroadcastRadio mService;
 
     @GuardedBy("mLock")
@@ -61,10 +61,11 @@
     private RadioManager.BandConfig mPlaceHolderConfig;
 
     TunerSession(RadioModule radioModule, IBroadcastRadio service,
-            android.hardware.radio.ITunerCallback callback) {
+            android.hardware.radio.ITunerCallback callback, int targetSdkVersion) {
         mModule = Objects.requireNonNull(radioModule, "radioModule cannot be null");
         mService = Objects.requireNonNull(service, "service cannot be null");
         mCallback = Objects.requireNonNull(callback, "callback cannot be null");
+        mTargetSdkVersion = targetSdkVersion;
         mLogger = new RadioLogger(TAG, TUNER_EVENT_LOGGER_QUEUE_SIZE);
     }
 
@@ -129,7 +130,7 @@
             mPlaceHolderConfig = Objects.requireNonNull(config, "config cannot be null");
         }
         Slogf.i(TAG, "Ignoring setConfiguration - not applicable for broadcastradio HAL AIDL");
-        mModule.fanoutAidlCallback(cb -> cb.onConfigurationChanged(config));
+        mModule.fanoutAidlCallback((cb, sdkVersion) -> cb.onConfigurationChanged(config));
     }
 
     @Override
@@ -178,8 +179,8 @@
     }
 
     @Override
-    public void scan(boolean directionDown, boolean skipSubChannel) throws RemoteException {
-        mLogger.logRadioEvent("Scan with direction %s, skipSubChannel? %s",
+    public void seek(boolean directionDown, boolean skipSubChannel) throws RemoteException {
+        mLogger.logRadioEvent("Seek with direction %s, skipSubChannel? %s",
                 directionDown ? "down" : "up", skipSubChannel ? "yes" : "no");
         if (!RadioServiceUserController.isCurrentOrSystemUser()) {
             Slogf.w(TAG, "Cannot scan on AIDL HAL client from non-current user");
@@ -232,8 +233,7 @@
 
     @Override
     public void cancelAnnouncement() {
-        // TODO(b/244485175): deperacte cancelAnnouncement
-        Slogf.i(TAG, "Announcements control doesn't involve cancelling at the HAL level in AIDL");
+        Slogf.w(TAG, "Announcements control doesn't involve cancelling at the HAL level in AIDL");
     }
 
     @Override
@@ -244,12 +244,14 @@
 
     @Override
     public boolean startBackgroundScan() {
-        Slogf.i(TAG, "Explicit background scan trigger is not supported with HAL AIDL");
+        Slogf.w(TAG, "Explicit background scan trigger is not supported with HAL AIDL");
         if (!RadioServiceUserController.isCurrentOrSystemUser()) {
             Slogf.w(TAG, "Cannot start background scan on AIDL HAL client from non-current user");
             return false;
         }
-        mModule.fanoutAidlCallback(ITunerCallback::onBackgroundScanComplete);
+        mModule.fanoutAidlCallback((cb, sdkVersion) -> {
+            cb.onBackgroundScanComplete();
+        });
         return true;
     }
 
@@ -277,6 +279,10 @@
         mModule.onTunerSessionProgramListFilterChanged(this);
     }
 
+    int getTargetSdkVersion() {
+        return mTargetSdkVersion;
+    }
+
     ProgramList.Filter getProgramListFilter() {
         synchronized (mLock) {
             return mProgramInfoCache == null ? null : mProgramInfoCache.getFilter();
@@ -312,7 +318,14 @@
         }
         for (int i = 0; i < chunks.size(); i++) {
             try {
-                mCallback.onProgramListUpdated(chunks.get(i));
+                if (!ConversionUtils.isAtLeastU(getTargetSdkVersion())) {
+                    ProgramList.Chunk downgradedChunk =
+                            ConversionUtils.convertChunkToTargetSdkVersion(chunks.get(i),
+                                    getTargetSdkVersion());
+                    mCallback.onProgramListUpdated(downgradedChunk);
+                } else {
+                    mCallback.onProgramListUpdated(chunks.get(i));
+                }
             } catch (RemoteException ex) {
                 Slogf.w(TAG, ex, "mCallback.onProgramListUpdated() failed");
             }
diff --git a/services/core/java/com/android/server/broadcastradio/hal1/Tuner.java b/services/core/java/com/android/server/broadcastradio/hal1/Tuner.java
index ed8a37a..8e5f6b5 100644
--- a/services/core/java/com/android/server/broadcastradio/hal1/Tuner.java
+++ b/services/core/java/com/android/server/broadcastradio/hal1/Tuner.java
@@ -189,9 +189,9 @@
     }
 
     @Override
-    public void scan(boolean directionDown, boolean skipSubChannel) {
+    public void seek(boolean directionDown, boolean skipSubChannel) {
         if (!RadioServiceUserController.isCurrentOrSystemUser()) {
-            Slogf.w(TAG, "Cannot scan on HAL 1.x client from non-current user");
+            Slogf.w(TAG, "Cannot seek on HAL 1.x client from non-current user");
             return;
         }
         synchronized (mLock) {
diff --git a/services/core/java/com/android/server/broadcastradio/hal1/TunerCallback.java b/services/core/java/com/android/server/broadcastradio/hal1/TunerCallback.java
index 0cc3833..aa43b75 100644
--- a/services/core/java/com/android/server/broadcastradio/hal1/TunerCallback.java
+++ b/services/core/java/com/android/server/broadcastradio/hal1/TunerCallback.java
@@ -174,8 +174,13 @@
     }
 
     @Override
+    public void onConfigFlagUpdated(int flag, boolean value) {
+        Slog.w(TAG, "Not applicable for HAL 1.x");
+    }
+
+    @Override
     public void onParametersUpdated(Map<String, String> parameters) {
-        Slog.e(TAG, "Not applicable for HAL 1.x");
+        Slog.w(TAG, "Not applicable for HAL 1.x");
     }
 
     @Override
diff --git a/services/core/java/com/android/server/broadcastradio/hal2/BroadcastRadioService.java b/services/core/java/com/android/server/broadcastradio/hal2/BroadcastRadioService.java
index 984bf51..1e31f20 100644
--- a/services/core/java/com/android/server/broadcastradio/hal2/BroadcastRadioService.java
+++ b/services/core/java/com/android/server/broadcastradio/hal2/BroadcastRadioService.java
@@ -169,7 +169,7 @@
     }
 
     public ITuner openSession(int moduleId, @Nullable RadioManager.BandConfig legacyConfig,
-        boolean withAudio, @NonNull ITunerCallback callback) throws RemoteException {
+            boolean withAudio, @NonNull ITunerCallback callback) throws RemoteException {
         Slog.v(TAG, "Open HIDL 2.0 session with module id " + moduleId);
         if (!RadioServiceUserController.isCurrentOrSystemUser()) {
             Slogf.e(TAG, "Cannot open tuner on HAL 2.0 client for non-current user");
diff --git a/services/core/java/com/android/server/broadcastradio/hal2/Convert.java b/services/core/java/com/android/server/broadcastradio/hal2/Convert.java
index 3daf1db..98a450f 100644
--- a/services/core/java/com/android/server/broadcastradio/hal2/Convert.java
+++ b/services/core/java/com/android/server/broadcastradio/hal2/Convert.java
@@ -36,6 +36,7 @@
 import android.hardware.radio.ProgramSelector;
 import android.hardware.radio.RadioManager;
 import android.hardware.radio.RadioMetadata;
+import android.hardware.radio.RadioTuner;
 import android.os.ParcelableException;
 import android.util.Slog;
 
@@ -81,6 +82,27 @@
         }
     }
 
+    @RadioTuner.TunerResultType
+    static int halResultToTunerResult(int result) {
+        switch (result) {
+            case Result.OK:
+                return RadioTuner.TUNER_RESULT_OK;
+            case Result.INTERNAL_ERROR:
+                return RadioTuner.TUNER_RESULT_INTERNAL_ERROR;
+            case Result.INVALID_ARGUMENTS:
+                return RadioTuner.TUNER_RESULT_INVALID_ARGUMENTS;
+            case Result.INVALID_STATE:
+                return RadioTuner.TUNER_RESULT_INVALID_STATE;
+            case Result.NOT_SUPPORTED:
+                return RadioTuner.TUNER_RESULT_NOT_SUPPORTED;
+            case Result.TIMEOUT:
+                return RadioTuner.TUNER_RESULT_TIMEOUT;
+            case Result.UNKNOWN_ERROR:
+            default:
+                return RadioTuner.TUNER_RESULT_UNKNOWN_ERROR;
+        }
+    }
+
     static @NonNull ArrayList<VendorKeyValue>
     vendorInfoToHal(@Nullable Map<String, String> info) {
         if (info == null) return new ArrayList<>();
@@ -130,6 +152,7 @@
             case ProgramSelector.IDENTIFIER_TYPE_DAB_ENSEMBLE:
             case ProgramSelector.IDENTIFIER_TYPE_DAB_SCID:
             case ProgramSelector.IDENTIFIER_TYPE_DAB_FREQUENCY:
+            case ProgramSelector.IDENTIFIER_TYPE_DAB_DMB_SID_EXT:
                 return ProgramSelector.PROGRAM_TYPE_DAB;
             case ProgramSelector.IDENTIFIER_TYPE_DRMO_SERVICE_ID:
             case ProgramSelector.IDENTIFIER_TYPE_DRMO_FREQUENCY:
diff --git a/services/core/java/com/android/server/broadcastradio/hal2/RadioModule.java b/services/core/java/com/android/server/broadcastradio/hal2/RadioModule.java
index 0ea5f0f..59a8154 100644
--- a/services/core/java/com/android/server/broadcastradio/hal2/RadioModule.java
+++ b/services/core/java/com/android/server/broadcastradio/hal2/RadioModule.java
@@ -87,8 +87,9 @@
             fireLater(() -> {
                 android.hardware.radio.ProgramSelector csel =
                         Convert.programSelectorFromHal(programSelector);
+                int tunerResult = Convert.halResultToTunerResult(result);
                 synchronized (mLock) {
-                    fanoutAidlCallbackLocked(cb -> cb.onTuneFailed(result, csel));
+                    fanoutAidlCallbackLocked(cb -> cb.onTuneFailed(tunerResult, csel));
                 }
             });
         }
diff --git a/services/core/java/com/android/server/broadcastradio/hal2/TunerSession.java b/services/core/java/com/android/server/broadcastradio/hal2/TunerSession.java
index 7afee27..204b964 100644
--- a/services/core/java/com/android/server/broadcastradio/hal2/TunerSession.java
+++ b/services/core/java/com/android/server/broadcastradio/hal2/TunerSession.java
@@ -171,8 +171,8 @@
     }
 
     @Override
-    public void scan(boolean directionDown, boolean skipSubChannel) throws RemoteException {
-        mEventLogger.logRadioEvent("Scan with direction %s, skipSubChannel? %s",
+    public void seek(boolean directionDown, boolean skipSubChannel) throws RemoteException {
+        mEventLogger.logRadioEvent("Seek with direction %s, skipSubChannel? %s",
                 directionDown ? "down" : "up", skipSubChannel ? "yes" : "no");
         if (!RadioServiceUserController.isCurrentOrSystemUser()) {
             Slogf.w(TAG, "Cannot scan on HAL 2.0 client from non-current user");
@@ -214,7 +214,7 @@
 
     @Override
     public void cancelAnnouncement() {
-        Slog.i(TAG, "Announcements control doesn't involve cancelling at the HAL level in HAL 2.0");
+        Slog.w(TAG, "Announcements control doesn't involve cancelling at the HAL level in HAL 2.0");
     }
 
     @Override
@@ -225,7 +225,7 @@
 
     @Override
     public boolean startBackgroundScan() {
-        Slog.i(TAG, "Explicit background scan trigger is not supported with HAL 2.0");
+        Slog.w(TAG, "Explicit background scan trigger is not supported with HAL 2.0");
         if (!RadioServiceUserController.isCurrentOrSystemUser()) {
             Slogf.w(TAG,
                     "Cannot start background scan on HAL 2.0 client from non-current user");
diff --git a/services/core/java/com/android/server/clipboard/EmulatorClipboardMonitor.java b/services/core/java/com/android/server/clipboard/EmulatorClipboardMonitor.java
index ab3b250..dce1c96 100644
--- a/services/core/java/com/android/server/clipboard/EmulatorClipboardMonitor.java
+++ b/services/core/java/com/android/server/clipboard/EmulatorClipboardMonitor.java
@@ -29,6 +29,7 @@
 import java.io.EOFException;
 import java.io.FileDescriptor;
 import java.io.InterruptedIOException;
+import java.net.ProtocolException;
 import java.net.SocketException;
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
@@ -39,12 +40,16 @@
 // write contents of the host system's clipboard.
 class EmulatorClipboardMonitor implements Consumer<ClipData> {
     private static final String TAG = "EmulatorClipboardMonitor";
+
     private static final String PIPE_NAME = "pipe:clipboard";
     private static final int HOST_PORT = 5000;
-    private final Thread mHostMonitorThread;
+
     private static final boolean LOG_CLIBOARD_ACCESS =
             SystemProperties.getBoolean("ro.boot.qemu.log_clipboard_access", false);
+    private static final int MAX_CLIPBOARD_BYTES = 128 << 20;
+
     private FileDescriptor mPipe = null;
+    private final Thread mHostMonitorThread;
 
     private static byte[] createOpenHandshake() {
         // String.getBytes doesn't include the null terminator,
@@ -97,8 +102,8 @@
         return fd;
     }
 
-    private static byte[] receiveMessage(final FileDescriptor fd) throws ErrnoException,
-            InterruptedIOException, EOFException {
+    private byte[] receiveMessage(final FileDescriptor fd) throws ErrnoException,
+            InterruptedIOException, EOFException, ProtocolException {
         final byte[] lengthBits = new byte[4];
         readFully(fd, lengthBits, 0, lengthBits.length);
 
@@ -106,6 +111,10 @@
         bb.order(ByteOrder.LITTLE_ENDIAN);
         final int msgLen = bb.getInt();
 
+        if (msgLen <= 0 || msgLen > MAX_CLIPBOARD_BYTES) {
+            throw new ProtocolException("Clipboard message length: " + msgLen + " out of bounds.");
+        }
+
         final byte[] msg = new byte[msgLen];
         readFully(fd, msg, 0, msg.length);
 
@@ -150,7 +159,8 @@
                     }
                     setAndroidClipboard.accept(clip);
                 } catch (ErrnoException | EOFException | InterruptedIOException
-                         | InterruptedException e) {
+                         | InterruptedException | ProtocolException | OutOfMemoryError e) {
+                    Slog.w(TAG, "Failure to read from host clipboard", e);
                     setPipeFD(null);
 
                     try {
diff --git a/services/core/java/com/android/server/companion/virtual/OWNERS b/services/core/java/com/android/server/companion/virtual/OWNERS
new file mode 100644
index 0000000..2e475a9
--- /dev/null
+++ b/services/core/java/com/android/server/companion/virtual/OWNERS
@@ -0,0 +1 @@
+include /services/companion/java/com/android/server/companion/virtual/OWNERS
\ No newline at end of file
diff --git a/services/core/java/com/android/server/companion/virtual/VirtualDeviceManagerInternal.java b/services/core/java/com/android/server/companion/virtual/VirtualDeviceManagerInternal.java
index d2e572f..09bec5e 100644
--- a/services/core/java/com/android/server/companion/virtual/VirtualDeviceManagerInternal.java
+++ b/services/core/java/com/android/server/companion/virtual/VirtualDeviceManagerInternal.java
@@ -18,7 +18,6 @@
 
 import android.annotation.NonNull;
 import android.companion.virtual.IVirtualDevice;
-import android.companion.virtual.VirtualDeviceParams;
 
 import java.util.Set;
 
@@ -37,7 +36,6 @@
         void onVirtualDisplayRemoved(int displayId);
     }
 
-
     /** Interface to listen to the changes on the list of app UIDs running on any virtual device. */
     public interface AppsOnVirtualDeviceListener {
         /** Notifies that running apps on any virtual device has changed */
@@ -73,6 +71,25 @@
     public abstract boolean isValidVirtualDevice(IVirtualDevice virtualDevice);
 
     /**
+     * Gets the owner uid for a deviceId.
+     *
+     * @param deviceId which device we're asking about
+     * @return the uid of the app which created and owns the VirtualDevice with the given deviceId,
+     * or {@link android.os.Process#INVALID_UID} if no such device exists.
+     */
+    public abstract int getDeviceOwnerUid(int deviceId);
+
+    /**
+     * Finds VirtualDevices where an app is running.
+     *
+     * @param uid - the app's uid
+     * @return a set of id's of VirtualDevices where the app with the given uid is running.
+     * *Note* this only checks VirtualDevices, and does not include information about whether
+     * the app is running on the default device or not.
+     */
+    public abstract @NonNull Set<Integer> getDeviceIdsForUid(int uid);
+
+    /**
      * Notifies that a virtual display is created.
      *
      * @param displayId The display id of the created virtual display.
@@ -94,12 +111,6 @@
     public abstract int getBaseVirtualDisplayFlags(IVirtualDevice virtualDevice);
 
     /**
-     * Returns true if the given {@code uid} is the owner of any virtual devices that are
-     * currently active.
-     */
-    public abstract boolean isAppOwnerOfAnyVirtualDevice(int uid);
-
-    /**
      * Returns true if the given {@code uid} is currently running on any virtual devices. This is
      * determined by whether the app has any activities in the task stack on a virtual-device-owned
      * display.
@@ -110,14 +121,4 @@
      * Returns true if the {@code displayId} is owned by any virtual device
      */
     public abstract boolean isDisplayOwnedByAnyVirtualDevice(int displayId);
-
-    /**
-     * Returns the device policy for the given virtual device and policy type.
-     *
-     * <p>In case the virtual device identifier is not valid, or there's no explicitly specified
-     * policy for that device and policy type, then
-     * {@link VirtualDeviceParams#DEVICE_POLICY_DEFAULT} is returned.
-     */
-    public abstract @VirtualDeviceParams.DevicePolicy int getDevicePolicy(
-            int deviceId, @VirtualDeviceParams.PolicyType int policyType);
 }
diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java
index bc9bc03..19dbee7 100644
--- a/services/core/java/com/android/server/connectivity/Vpn.java
+++ b/services/core/java/com/android/server/connectivity/Vpn.java
@@ -646,7 +646,10 @@
                 .removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)
                 .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED)
                 .setTransportInfo(new VpnTransportInfo(
-                        VpnManager.TYPE_VPN_NONE, null /* sessionId */, false /* bypassable */))
+                        VpnManager.TYPE_VPN_NONE,
+                        null /* sessionId */,
+                        false /* bypassable */,
+                        false /* longLivedTcpConnectionsExpensive */))
                 .build();
 
         loadAlwaysOnPackage();
@@ -711,7 +714,10 @@
         mNetworkCapabilities = new NetworkCapabilities.Builder(mNetworkCapabilities)
                 .setUids(null)
                 .setTransportInfo(new VpnTransportInfo(
-                        VpnManager.TYPE_VPN_NONE, null /* sessionId */, false /* bypassable */))
+                        VpnManager.TYPE_VPN_NONE,
+                        null /* sessionId */,
+                        false /* bypassable */,
+                        false /* longLivedTcpConnectionsExpensive */))
                 .build();
     }
 
@@ -1570,7 +1576,8 @@
                 mConfig.allowedApplications, mConfig.disallowedApplications));
 
         capsBuilder.setTransportInfo(
-                new VpnTransportInfo(getActiveVpnType(), mConfig.session, mConfig.allowBypass));
+                new VpnTransportInfo(getActiveVpnType(), mConfig.session, mConfig.allowBypass,
+                        false /* longLivedTcpConnectionsExpensive */));
 
         // Only apps targeting Q and above can explicitly declare themselves as metered.
         // These VPNs are assumed metered unless they state otherwise.
@@ -3475,6 +3482,8 @@
                 return;
             } else {
                 mActiveNetwork = null;
+                mUnderlyingNetworkCapabilities = null;
+                mUnderlyingLinkProperties = null;
             }
 
             if (mScheduledHandleNetworkLostFuture != null) {
@@ -3664,9 +3673,6 @@
                 scheduleRetryNewIkeSession();
             }
 
-            mUnderlyingNetworkCapabilities = null;
-            mUnderlyingLinkProperties = null;
-
             // Close all obsolete state, but keep VPN alive incase a usable network comes up.
             // (Mirrors VpnService behavior)
             Log.d(TAG, "Resetting state for token: " + mCurrentToken);
diff --git a/services/core/java/com/android/server/display/DisplayDeviceConfig.java b/services/core/java/com/android/server/display/DisplayDeviceConfig.java
index c1e9526..98a0af7 100644
--- a/services/core/java/com/android/server/display/DisplayDeviceConfig.java
+++ b/services/core/java/com/android/server/display/DisplayDeviceConfig.java
@@ -36,16 +36,19 @@
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.display.BrightnessSynchronizer;
 import com.android.server.display.config.AutoBrightness;
+import com.android.server.display.config.BlockingZoneConfig;
 import com.android.server.display.config.BrightnessThresholds;
 import com.android.server.display.config.BrightnessThrottlingMap;
 import com.android.server.display.config.BrightnessThrottlingPoint;
 import com.android.server.display.config.Density;
+import com.android.server.display.config.DisplayBrightnessPoint;
 import com.android.server.display.config.DisplayConfiguration;
 import com.android.server.display.config.DisplayQuirks;
 import com.android.server.display.config.HbmTiming;
 import com.android.server.display.config.HighBrightnessMode;
 import com.android.server.display.config.NitsMap;
 import com.android.server.display.config.Point;
+import com.android.server.display.config.RefreshRateConfigs;
 import com.android.server.display.config.RefreshRateRange;
 import com.android.server.display.config.SdrHdrRatioMap;
 import com.android.server.display.config.SdrHdrRatioPoint;
@@ -130,6 +133,35 @@
  *        </brightnessThrottlingMap>
  *      </thermalThrottling>
  *
+ *      <refreshRate>
+ *        <lowerBlockingZoneConfigs>
+ *          <defaultRefreshRate>75</defaultRefreshRate>
+ *          <blockingZoneThreshold>
+ *            <displayBrightnessPoint>
+ *              <lux>50</lux>
+ *              <nits>45.3</nits>
+ *            </displayBrightnessPoint>
+ *            <displayBrightnessPoint>
+ *              <lux>60</lux>
+ *              <nits>55.2</nits>
+ *            </displayBrightnessPoint>
+ *          </blockingZoneThreshold>
+ *        </lowerBlockingZoneConfigs>
+ *        <higherBlockingZoneConfigs>
+ *          <defaultRefreshRate>90</defaultRefreshRate>
+ *          <blockingZoneThreshold>
+ *            <displayBrightnessPoint>
+ *              <lux>500</lux>
+ *              <nits>245.3</nits>
+ *            </displayBrightnessPoint>
+ *            <displayBrightnessPoint>
+ *              <lux>600</lux>
+ *              <nits>232.3</nits>
+ *            </displayBrightnessPoint>
+ *          </blockingZoneThreshold>
+ *        </higherBlockingZoneConfigs>
+ *      </refreshRate>
+ *
  *      <highBrightnessMode enabled="true">
  *        <transitionPoint>0.62</transitionPoint>
  *        <minimumLux>10000</minimumLux>
@@ -358,6 +390,9 @@
     private static final String STABLE_ID_SUFFIX_FORMAT = "id_%d";
     private static final String NO_SUFFIX_FORMAT = "%d";
     private static final long STABLE_FLAG = 1L << 62;
+    private static final int DEFAULT_LOW_REFRESH_RATE = 60;
+    private static final int DEFAULT_HIGH_REFRESH_RATE = 0;
+    private static final int[] DEFAULT_BRIGHTNESS_THRESHOLDS = new int[]{};
 
     private static final float[] DEFAULT_AMBIENT_THRESHOLD_LEVELS = new float[]{0f};
     private static final float[] DEFAULT_AMBIENT_BRIGHTENING_THRESHOLDS = new float[]{100f};
@@ -512,6 +547,49 @@
     // This stores the raw value loaded from the config file - true if not written.
     private boolean mDdcAutoBrightnessAvailable = true;
 
+    /**
+     * The default peak refresh rate for a given device. This value prevents the framework from
+     * using higher refresh rates, even if display modes with higher refresh rates are available
+     * from hardware composer. Only has an effect if the value is non-zero.
+     */
+    private int mDefaultHighRefreshRate = DEFAULT_HIGH_REFRESH_RATE;
+
+    /**
+     * The default refresh rate for a given device. This value sets the higher default
+     * refresh rate. If the hardware composer on the device supports display modes with
+     * a higher refresh rate than the default value specified here, the framework may use those
+     * higher refresh rate modes if an app chooses one by setting preferredDisplayModeId or calling
+     * setFrameRate(). We have historically allowed fallback to mDefaultHighRefreshRate if
+     * mDefaultLowRefreshRate is set to 0, but this is not supported anymore.
+     */
+    private int mDefaultLowRefreshRate = DEFAULT_LOW_REFRESH_RATE;
+
+    /**
+     * The display uses different gamma curves for different refresh rates. It's hard for panel
+     * vendors to tune the curves to have exact same brightness for different refresh rate. So
+     * brightness flickers could be observed at switch time. The issue is worse at the gamma lower
+     * end. In addition, human eyes are more sensitive to the flicker at darker environment. To
+     * prevent flicker, we only support higher refresh rates if the display brightness is above a
+     * threshold. For example, no higher refresh rate if display brightness <= disp0 && ambient
+     * brightness <= amb0 || display brightness <= disp1 && ambient brightness <= amb1
+     */
+    private int[] mLowDisplayBrightnessThresholds = DEFAULT_BRIGHTNESS_THRESHOLDS;
+    private int[] mLowAmbientBrightnessThresholds = DEFAULT_BRIGHTNESS_THRESHOLDS;
+
+    /**
+     * The display uses different gamma curves for different refresh rates. It's hard for panel
+     * vendors to tune the curves to have exact same brightness for different refresh rate. So
+     * brightness flickers could be observed at switch time. The issue can be observed on the screen
+     * with even full white content at the high brightness. To prevent flickering, we support fixed
+     * refresh rates if the display and ambient brightness are equal to or above the provided
+     * thresholds. You can define multiple threshold levels as higher brightness environments may
+     * have lower display brightness requirements for the flickering is visible. For example, fixed
+     * refresh rate if display brightness >= disp0 && ambient brightness >= amb0 || display
+     * brightness >= disp1 && ambient brightness >= amb1
+     */
+    private int[] mHighDisplayBrightnessThresholds = DEFAULT_BRIGHTNESS_THRESHOLDS;
+    private int[] mHighAmbientBrightnessThresholds = DEFAULT_BRIGHTNESS_THRESHOLDS;
+
     // Brightness Throttling data may be updated via the DeviceConfig. Here we store the original
     // data, which comes from the ddc, and the current one, which may be the DeviceConfig
     // overwritten value.
@@ -1195,15 +1273,15 @@
     /**
      * @return Default peak refresh rate of the associated display
      */
-    public int getDefaultPeakRefreshRate() {
-        return mContext.getResources().getInteger(R.integer.config_defaultPeakRefreshRate);
+    public int getDefaultHighRefreshRate() {
+        return mDefaultHighRefreshRate;
     }
 
     /**
      * @return Default refresh rate of the associated display
      */
-    public int getDefaultRefreshRate() {
-        return mContext.getResources().getInteger(R.integer.config_defaultRefreshRate);
+    public int getDefaultLowRefreshRate() {
+        return mDefaultLowRefreshRate;
     }
 
     /**
@@ -1212,8 +1290,7 @@
      * allowed
      */
     public int[] getLowDisplayBrightnessThresholds() {
-        return mContext.getResources().getIntArray(
-                R.array.config_brightnessThresholdsOfPeakRefreshRate);
+        return mLowDisplayBrightnessThresholds;
     }
 
     /**
@@ -1222,8 +1299,7 @@
      * allowed
      */
     public int[] getLowAmbientBrightnessThresholds() {
-        return mContext.getResources().getIntArray(
-                R.array.config_ambientThresholdsOfPeakRefreshRate);
+        return mLowAmbientBrightnessThresholds;
     }
 
     /**
@@ -1232,8 +1308,7 @@
      * allowed
      */
     public int[] getHighDisplayBrightnessThresholds() {
-        return mContext.getResources().getIntArray(
-                R.array.config_highDisplayBrightnessThresholdsOfFixedRefreshRate);
+        return mHighDisplayBrightnessThresholds;
     }
 
     /**
@@ -1242,8 +1317,7 @@
      * allowed
      */
     public int[] getHighAmbientBrightnessThresholds() {
-        return mContext.getResources().getIntArray(
-                R.array.config_highAmbientBrightnessThresholdsOfFixedRefreshRate);
+        return mHighAmbientBrightnessThresholds;
     }
 
     @Override
@@ -1335,6 +1409,17 @@
                 + ", mBrightnessLevelsNits= " + Arrays.toString(mBrightnessLevelsNits)
                 + ", mDdcAutoBrightnessAvailable= " + mDdcAutoBrightnessAvailable
                 + ", mAutoBrightnessAvailable= " + mAutoBrightnessAvailable
+                + "\n"
+                + ", mDefaultRefreshRate= " + mDefaultLowRefreshRate
+                + ", mDefaultPeakRefreshRate= " + mDefaultHighRefreshRate
+                + ", mLowDisplayBrightnessThresholds= "
+                + Arrays.toString(mLowDisplayBrightnessThresholds)
+                + ", mLowAmbientBrightnessThresholds= "
+                + Arrays.toString(mLowAmbientBrightnessThresholds)
+                + ", mHighDisplayBrightnessThresholds= "
+                + Arrays.toString(mHighDisplayBrightnessThresholds)
+                + ", mHighAmbientBrightnessThresholds= "
+                + Arrays.toString(mHighAmbientBrightnessThresholds)
                 + "}";
     }
 
@@ -1392,6 +1477,7 @@
                 loadAmbientHorizonFromDdc(config);
                 loadBrightnessChangeThresholds(config);
                 loadAutoBrightnessConfigValues(config);
+                loadRefreshRateSetting(config);
             } else {
                 Slog.w(TAG, "DisplayDeviceConfig file is null");
             }
@@ -1414,6 +1500,7 @@
         setProxSensorUnspecified();
         loadAutoBrightnessConfigsFromConfigXml();
         loadAutoBrightnessAvailableFromConfigXml();
+        loadRefreshRateSetting(null);
         mLoadedFrom = "<config.xml>";
     }
 
@@ -1624,6 +1711,143 @@
         }
     }
 
+    private void loadRefreshRateSetting(DisplayConfiguration config) {
+        final RefreshRateConfigs refreshRateConfigs =
+                (config == null) ? null : config.getRefreshRate();
+        BlockingZoneConfig lowerBlockingZoneConfig =
+                (refreshRateConfigs == null) ? null
+                        : refreshRateConfigs.getLowerBlockingZoneConfigs();
+        BlockingZoneConfig higherBlockingZoneConfig =
+                (refreshRateConfigs == null) ? null
+                        : refreshRateConfigs.getHigherBlockingZoneConfigs();
+        loadLowerRefreshRateBlockingZones(lowerBlockingZoneConfig);
+        loadHigherRefreshRateBlockingZones(higherBlockingZoneConfig);
+    }
+
+
+    /**
+     * Loads the refresh rate configurations pertaining to the upper blocking zones.
+     */
+    private void loadLowerRefreshRateBlockingZones(BlockingZoneConfig lowerBlockingZoneConfig) {
+        loadLowerBlockingZoneDefaultRefreshRate(lowerBlockingZoneConfig);
+        loadLowerBrightnessThresholds(lowerBlockingZoneConfig);
+    }
+
+    /**
+     * Loads the refresh rate configurations pertaining to the upper blocking zones.
+     */
+    private void loadHigherRefreshRateBlockingZones(BlockingZoneConfig upperBlockingZoneConfig) {
+        loadHigherBlockingZoneDefaultRefreshRate(upperBlockingZoneConfig);
+        loadHigherBrightnessThresholds(upperBlockingZoneConfig);
+    }
+
+    /**
+     * Loads the default peak refresh rate. Internally, this takes care of loading
+     * the value from the display config, and if not present, falls back to config.xml.
+     */
+    private void loadHigherBlockingZoneDefaultRefreshRate(
+                BlockingZoneConfig upperBlockingZoneConfig) {
+        if (upperBlockingZoneConfig == null) {
+            mDefaultHighRefreshRate = mContext.getResources().getInteger(
+                com.android.internal.R.integer.config_defaultPeakRefreshRate);
+        } else {
+            mDefaultHighRefreshRate =
+                upperBlockingZoneConfig.getDefaultRefreshRate().intValue();
+        }
+    }
+
+    /**
+     * Loads the default refresh rate. Internally, this takes care of loading
+     * the value from the display config, and if not present, falls back to config.xml.
+     */
+    private void loadLowerBlockingZoneDefaultRefreshRate(
+                BlockingZoneConfig lowerBlockingZoneConfig) {
+        if (lowerBlockingZoneConfig == null) {
+            mDefaultLowRefreshRate = mContext.getResources().getInteger(
+                com.android.internal.R.integer.config_defaultRefreshRate);
+        } else {
+            mDefaultLowRefreshRate =
+                lowerBlockingZoneConfig.getDefaultRefreshRate().intValue();
+        }
+    }
+
+    /**
+     * Loads the lower brightness thresholds for refresh rate switching. Internally, this takes care
+     * of loading the value from the display config, and if not present, falls back to config.xml.
+     */
+    private void loadLowerBrightnessThresholds(BlockingZoneConfig lowerBlockingZoneConfig) {
+        if (lowerBlockingZoneConfig == null) {
+            mLowDisplayBrightnessThresholds = mContext.getResources().getIntArray(
+                R.array.config_brightnessThresholdsOfPeakRefreshRate);
+            mLowAmbientBrightnessThresholds = mContext.getResources().getIntArray(
+                R.array.config_ambientThresholdsOfPeakRefreshRate);
+            if (mLowDisplayBrightnessThresholds == null || mLowAmbientBrightnessThresholds == null
+                    || mLowDisplayBrightnessThresholds.length
+                    != mLowAmbientBrightnessThresholds.length) {
+                throw new RuntimeException("display low brightness threshold array and ambient "
+                    + "brightness threshold array have different length: "
+                    + "mLowDisplayBrightnessThresholds="
+                    + Arrays.toString(mLowDisplayBrightnessThresholds)
+                    + ", mLowAmbientBrightnessThresholds="
+                    + Arrays.toString(mLowAmbientBrightnessThresholds));
+            }
+        } else {
+            List<DisplayBrightnessPoint> lowerThresholdDisplayBrightnessPoints =
+                    lowerBlockingZoneConfig.getBlockingZoneThreshold().getDisplayBrightnessPoint();
+            int size = lowerThresholdDisplayBrightnessPoints.size();
+            mLowDisplayBrightnessThresholds = new int[size];
+            mLowAmbientBrightnessThresholds = new int[size];
+            for (int i = 0; i < size; i++) {
+                // We are explicitly casting this value to an integer to be able to reuse the
+                // existing DisplayBrightnessPoint type. It is fine to do this because the round off
+                // will have the negligible and unnoticeable impact on the loaded thresholds.
+                mLowDisplayBrightnessThresholds[i] = (int) lowerThresholdDisplayBrightnessPoints
+                    .get(i).getNits().floatValue();
+                mLowAmbientBrightnessThresholds[i] = lowerThresholdDisplayBrightnessPoints
+                    .get(i).getLux().intValue();
+            }
+        }
+    }
+
+    /**
+     * Loads the higher brightness thresholds for refresh rate switching. Internally, this takes
+     * care of loading the value from the display config, and if not present, falls back to
+     * config.xml.
+     */
+    private void loadHigherBrightnessThresholds(BlockingZoneConfig blockingZoneConfig) {
+        if (blockingZoneConfig == null) {
+            mHighDisplayBrightnessThresholds = mContext.getResources().getIntArray(
+                R.array.config_highDisplayBrightnessThresholdsOfFixedRefreshRate);
+            mHighAmbientBrightnessThresholds = mContext.getResources().getIntArray(
+                R.array.config_highAmbientBrightnessThresholdsOfFixedRefreshRate);
+            if (mHighAmbientBrightnessThresholds == null || mHighDisplayBrightnessThresholds == null
+                    || mHighAmbientBrightnessThresholds.length
+                    != mHighDisplayBrightnessThresholds.length) {
+                throw new RuntimeException("display high brightness threshold array and ambient "
+                    + "brightness threshold array have different length: "
+                    + "mHighDisplayBrightnessThresholds="
+                    + Arrays.toString(mHighDisplayBrightnessThresholds)
+                    + ", mHighAmbientBrightnessThresholds="
+                    + Arrays.toString(mHighAmbientBrightnessThresholds));
+            }
+        } else {
+            List<DisplayBrightnessPoint> higherThresholdDisplayBrightnessPoints =
+                    blockingZoneConfig.getBlockingZoneThreshold().getDisplayBrightnessPoint();
+            int size = higherThresholdDisplayBrightnessPoints.size();
+            mHighDisplayBrightnessThresholds = new int[size];
+            mHighAmbientBrightnessThresholds = new int[size];
+            for (int i = 0; i < size; i++) {
+                // We are explicitly casting this value to an integer to be able to reuse the
+                // existing DisplayBrightnessPoint type. It is fine to do this because the round off
+                // will have the negligible and unnoticeable impact on the loaded thresholds.
+                mHighDisplayBrightnessThresholds[i] = (int) higherThresholdDisplayBrightnessPoints
+                    .get(i).getNits().floatValue();
+                mHighAmbientBrightnessThresholds[i] = higherThresholdDisplayBrightnessPoints
+                    .get(i).getLux().intValue();
+            }
+        }
+    }
+
     private void loadAutoBrightnessConfigValues(DisplayConfiguration config) {
         final AutoBrightness autoBrightness = config.getAutoBrightness();
         loadAutoBrightnessBrighteningLightDebounce(autoBrightness);
diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java
index ae84e96..329e3ca 100644
--- a/services/core/java/com/android/server/display/DisplayManagerService.java
+++ b/services/core/java/com/android/server/display/DisplayManagerService.java
@@ -1414,12 +1414,20 @@
         // LogicalDisplayMapper aware of the link between the new display and its associated virtual
         // device before triggering DISPLAY_DEVICE_EVENT_ADDED.
         if ((flags & VIRTUAL_DISPLAY_FLAG_DEVICE_DISPLAY_GROUP) != 0) {
-            try {
-                final int virtualDeviceId = virtualDevice.getDeviceId();
-                mLogicalDisplayMapper.associateDisplayDeviceWithVirtualDevice(
-                        device, virtualDeviceId);
-            } catch (RemoteException e) {
-                e.rethrowFromSystemServer();
+            if (virtualDevice != null) {
+                try {
+                    final int virtualDeviceId = virtualDevice.getDeviceId();
+                    mLogicalDisplayMapper.associateDisplayDeviceWithVirtualDevice(
+                            device, virtualDeviceId);
+                } catch (RemoteException e) {
+                    e.rethrowFromSystemServer();
+                }
+            } else {
+                Slog.i(
+                        TAG,
+                        "Display created with VIRTUAL_DISPLAY_FLAG_DEVICE_DISPLAY_GROUP set, but no"
+                            + " virtual device. The display will not be added to a device display"
+                            + " group.");
             }
         }
 
@@ -1844,15 +1852,7 @@
         Settings.Global.putInt(mContext.getContentResolver(),
                 Settings.Global.USER_PREFERRED_RESOLUTION_WIDTH, resolutionWidth);
         mDisplayDeviceRepo.forEachLocked((DisplayDevice device) -> {
-            // If there is a display specific mode, don't override that
-            final Point deviceUserPreferredResolution =
-                    mPersistentDataStore.getUserPreferredResolution(device);
-            final float deviceRefreshRate =
-                    mPersistentDataStore.getUserPreferredRefreshRate(device);
-            if (!isValidResolution(deviceUserPreferredResolution)
-                    && !isValidRefreshRate(deviceRefreshRate)) {
-                device.setUserPreferredDisplayModeLocked(mode);
-            }
+            device.setUserPreferredDisplayModeLocked(mode);
         });
     }
 
@@ -3715,44 +3715,21 @@
         @Override
         public Set<DisplayInfo> getPossibleDisplayInfo(int displayId) {
             synchronized (mSyncRoot) {
-                // Retrieve the group associated with this display id.
-                final int displayGroupId =
-                        mLogicalDisplayMapper.getDisplayGroupIdFromDisplayIdLocked(displayId);
-                if (displayGroupId == Display.INVALID_DISPLAY_GROUP) {
-                    Slog.w(TAG,
-                            "Can't get possible display info since display group for " + displayId
-                                    + " does not exist");
-                    return new ArraySet<>();
-                }
-
-                // Assume any display in this group can be swapped out for the given display id.
                 Set<DisplayInfo> possibleInfo = new ArraySet<>();
-                final DisplayGroup group = mLogicalDisplayMapper.getDisplayGroupLocked(
-                        displayGroupId);
-                for (int i = 0; i < group.getSizeLocked(); i++) {
-                    final int id = group.getIdLocked(i);
-                    final LogicalDisplay logical = mLogicalDisplayMapper.getDisplayLocked(id);
-                    if (logical == null) {
-                        Slog.w(TAG,
-                                "Can't get possible display info since logical display for "
-                                        + "display id " + id + " does not exist, as part of group "
-                                        + displayGroupId);
-                    } else {
-                        possibleInfo.add(logical.getDisplayInfoLocked());
-                    }
-                }
-
-                // For the supported device states, retrieve the DisplayInfos for the logical
-                // display layout.
+                // For each of supported device states, retrieve the display layout of that state,
+                // and return all of the DisplayInfos (one per state) for the given display id.
                 if (mDeviceStateManager == null) {
                     Slog.w(TAG, "Can't get supported states since DeviceStateManager not ready");
-                } else {
-                    final int[] supportedStates =
-                            mDeviceStateManager.getSupportedStateIdentifiers();
-                    for (int state : supportedStates) {
-                        possibleInfo.addAll(
-                                mLogicalDisplayMapper.getDisplayInfoForStateLocked(state, displayId,
-                                        displayGroupId));
+                    return possibleInfo;
+                }
+                final int[] supportedStates =
+                        mDeviceStateManager.getSupportedStateIdentifiers();
+                DisplayInfo displayInfo;
+                for (int state : supportedStates) {
+                    displayInfo = mLogicalDisplayMapper.getDisplayInfoForStateLocked(state,
+                            displayId);
+                    if (displayInfo != null) {
+                        possibleInfo.add(displayInfo);
                     }
                 }
                 return possibleInfo;
diff --git a/services/core/java/com/android/server/display/DisplayModeDirector.java b/services/core/java/com/android/server/display/DisplayModeDirector.java
index 405a2b9..5dba015 100644
--- a/services/core/java/com/android/server/display/DisplayModeDirector.java
+++ b/services/core/java/com/android/server/display/DisplayModeDirector.java
@@ -1358,7 +1358,7 @@
             mDefaultRefreshRate =
                     (displayDeviceConfig == null) ? (float) mContext.getResources().getInteger(
                         R.integer.config_defaultRefreshRate)
-                        : (float) displayDeviceConfig.getDefaultRefreshRate();
+                        : (float) displayDeviceConfig.getDefaultLowRefreshRate();
         }
 
         public void observe() {
@@ -1445,7 +1445,7 @@
                 defaultPeakRefreshRate =
                         (displayDeviceConfig == null) ? (float) mContext.getResources().getInteger(
                                 R.integer.config_defaultPeakRefreshRate)
-                                : (float) displayDeviceConfig.getDefaultPeakRefreshRate();
+                                : (float) displayDeviceConfig.getDefaultHighRefreshRate();
             }
             mDefaultPeakRefreshRate = defaultPeakRefreshRate;
         }
diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java
index 9d47892..75415cd 100644
--- a/services/core/java/com/android/server/display/DisplayPowerController.java
+++ b/services/core/java/com/android/server/display/DisplayPowerController.java
@@ -453,6 +453,8 @@
     // PowerManager.BRIGHTNESS_INVALID_FLOAT when there's no temporary adjustment set.
     private float mTemporaryAutoBrightnessAdjustment;
 
+    private boolean mUseAutoBrightness;
+
     private boolean mIsRbcActive;
 
     // Whether there's a callback to tell listeners the display has changed scheduled to run. When
@@ -683,6 +685,7 @@
     @Override
     public void onSwitchUser(@UserIdInt int newUserId) {
         handleSettingsChange(true /* userSwitch */);
+        handleBrightnessModeChange();
         if (mBrightnessTracker != null) {
             mBrightnessTracker.onSwitchUser(newUserId);
         }
@@ -930,6 +933,10 @@
         mContext.getContentResolver().registerContentObserver(
                 Settings.System.getUriFor(Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ),
                 false /*notifyForDescendants*/, mSettingsObserver, UserHandle.USER_ALL);
+        mContext.getContentResolver().registerContentObserver(
+                Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS_MODE),
+                false /*notifyForDescendants*/, mSettingsObserver, UserHandle.USER_ALL);
+        handleBrightnessModeChange();
     }
 
     private void setUpAutoBrightness(Resources resources, Handler handler) {
@@ -1335,11 +1342,11 @@
 
         final boolean autoBrightnessEnabledInDoze =
                 mAllowAutoBrightnessWhileDozingConfig && Display.isDozeState(state);
-        final boolean autoBrightnessEnabled = mPowerRequest.useAutoBrightness
+        final boolean autoBrightnessEnabled = mUseAutoBrightness
                 && (state == Display.STATE_ON || autoBrightnessEnabledInDoze)
                 && Float.isNaN(brightnessState)
                 && mAutomaticBrightnessController != null;
-        final boolean autoBrightnessDisabledDueToDisplayOff = mPowerRequest.useAutoBrightness
+        final boolean autoBrightnessDisabledDueToDisplayOff = mUseAutoBrightness
                 && !(state == Display.STATE_ON || autoBrightnessEnabledInDoze);
         final int autoBrightnessState = autoBrightnessEnabled
                 ? AutomaticBrightnessController.AUTO_BRIGHTNESS_ENABLED
@@ -1691,7 +1698,7 @@
                 || brightnessAdjustmentFlags != 0) {
             float lastBrightness = mLastBrightnessEvent.getBrightness();
             mTempBrightnessEvent.setInitialBrightness(lastBrightness);
-            mTempBrightnessEvent.setAutomaticBrightnessEnabled(mPowerRequest.useAutoBrightness);
+            mTempBrightnessEvent.setAutomaticBrightnessEnabled(mUseAutoBrightness);
             mLastBrightnessEvent.copyFrom(mTempBrightnessEvent);
             BrightnessEvent newEvent = new BrightnessEvent(mTempBrightnessEvent);
             // Adjustment flags (and user-set flag) only get added after the equality checks since
@@ -2341,6 +2348,18 @@
         sendUpdatePowerState();
     }
 
+    private void handleBrightnessModeChange() {
+        final int screenBrightnessModeSetting = Settings.System.getIntForUser(
+                mContext.getContentResolver(),
+                Settings.System.SCREEN_BRIGHTNESS_MODE,
+                Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, UserHandle.USER_CURRENT);
+        mHandler.post(() -> {
+            mUseAutoBrightness = screenBrightnessModeSetting
+                    == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
+            updatePowerState();
+        });
+    }
+
     private float getAutoBrightnessAdjustmentSetting() {
         final float adj = Settings.System.getFloatForUser(mContext.getContentResolver(),
                 Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, 0.0f, UserHandle.USER_CURRENT);
@@ -2425,7 +2444,7 @@
     private void notifyBrightnessTrackerChanged(float brightness, boolean userInitiated,
             boolean hadUserDataPoint) {
         final float brightnessInNits = convertToNits(brightness);
-        if (mPowerRequest.useAutoBrightness && brightnessInNits >= 0.0f
+        if (mUseAutoBrightness && brightnessInNits >= 0.0f
                 && mAutomaticBrightnessController != null && mBrightnessTracker != null) {
             // We only want to track changes on devices that can actually map the display backlight
             // values into a physical brightness unit since the value provided by the API is in
@@ -2897,7 +2916,11 @@
 
         @Override
         public void onChange(boolean selfChange, Uri uri) {
-            handleSettingsChange(false /* userSwitch */);
+            if (uri.equals(Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS_MODE))) {
+                handleBrightnessModeChange();
+            } else {
+                handleSettingsChange(false /* userSwitch */);
+            }
         }
     }
 
diff --git a/services/core/java/com/android/server/display/DisplayPowerController2.java b/services/core/java/com/android/server/display/DisplayPowerController2.java
index 346b340..84b6da8 100644
--- a/services/core/java/com/android/server/display/DisplayPowerController2.java
+++ b/services/core/java/com/android/server/display/DisplayPowerController2.java
@@ -396,6 +396,8 @@
     // PowerManager.BRIGHTNESS_INVALID_FLOAT when there's no temporary adjustment set.
     private float mTemporaryAutoBrightnessAdjustment;
 
+    private boolean mUseAutoBrightness;
+
     private boolean mIsRbcActive;
 
     // Animators.
@@ -600,6 +602,7 @@
     @Override
     public void onSwitchUser(@UserIdInt int newUserId) {
         handleSettingsChange(true /* userSwitch */);
+        handleBrightnessModeChange();
         if (mBrightnessTracker != null) {
             mBrightnessTracker.onSwitchUser(newUserId);
         }
@@ -842,6 +845,10 @@
         mContext.getContentResolver().registerContentObserver(
                 Settings.System.getUriFor(Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ),
                 false /*notifyForDescendants*/, mSettingsObserver, UserHandle.USER_ALL);
+        mContext.getContentResolver().registerContentObserver(
+                Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS_MODE),
+                false /*notifyForDescendants*/, mSettingsObserver, UserHandle.USER_ALL);
+        handleBrightnessModeChange();
     }
 
     private void setUpAutoBrightness(Resources resources, Handler handler) {
@@ -1174,11 +1181,11 @@
         final boolean autoBrightnessEnabledInDoze =
                 mDisplayBrightnessController.isAllowAutoBrightnessWhileDozingConfig()
                         && Display.isDozeState(state);
-        final boolean autoBrightnessEnabled = mPowerRequest.useAutoBrightness
+        final boolean autoBrightnessEnabled = mUseAutoBrightness
                 && (state == Display.STATE_ON || autoBrightnessEnabledInDoze)
                 && Float.isNaN(brightnessState)
                 && mAutomaticBrightnessController != null;
-        final boolean autoBrightnessDisabledDueToDisplayOff = mPowerRequest.useAutoBrightness
+        final boolean autoBrightnessDisabledDueToDisplayOff = mUseAutoBrightness
                 && !(state == Display.STATE_ON || autoBrightnessEnabledInDoze);
         final int autoBrightnessState = autoBrightnessEnabled
                 ? AutomaticBrightnessController.AUTO_BRIGHTNESS_ENABLED
@@ -1510,7 +1517,7 @@
                 || brightnessAdjustmentFlags != 0) {
             float lastBrightness = mLastBrightnessEvent.getBrightness();
             mTempBrightnessEvent.setInitialBrightness(lastBrightness);
-            mTempBrightnessEvent.setAutomaticBrightnessEnabled(mPowerRequest.useAutoBrightness);
+            mTempBrightnessEvent.setAutomaticBrightnessEnabled(mUseAutoBrightness);
             mLastBrightnessEvent.copyFrom(mTempBrightnessEvent);
             BrightnessEvent newEvent = new BrightnessEvent(mTempBrightnessEvent);
             // Adjustment flags (and user-set flag) only get added after the equality checks since
@@ -2045,6 +2052,18 @@
         sendUpdatePowerState();
     }
 
+    private void handleBrightnessModeChange() {
+        final int screenBrightnessModeSetting = Settings.System.getIntForUser(
+                mContext.getContentResolver(),
+                Settings.System.SCREEN_BRIGHTNESS_MODE,
+                Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, UserHandle.USER_CURRENT);
+        mHandler.post(() -> {
+            mUseAutoBrightness = screenBrightnessModeSetting
+                    == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
+            updatePowerState();
+        });
+    }
+
     private float getAutoBrightnessAdjustmentSetting() {
         final float adj = Settings.System.getFloatForUser(mContext.getContentResolver(),
                 Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, 0.0f, UserHandle.USER_CURRENT);
@@ -2131,7 +2150,7 @@
     private void notifyBrightnessTrackerChanged(float brightness, boolean userInitiated,
             boolean hadUserDataPoint) {
         final float brightnessInNits = convertToNits(brightness);
-        if (mPowerRequest.useAutoBrightness && brightnessInNits >= 0.0f
+        if (mUseAutoBrightness && brightnessInNits >= 0.0f
                 && mAutomaticBrightnessController != null && mBrightnessTracker != null) {
             // We only want to track changes on devices that can actually map the display backlight
             // values into a physical brightness unit since the value provided by the API is in
@@ -2499,7 +2518,11 @@
 
         @Override
         public void onChange(boolean selfChange, Uri uri) {
-            handleSettingsChange(false /* userSwitch */);
+            if (uri.equals(Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS_MODE))) {
+                handleBrightnessModeChange();
+            } else {
+                handleSettingsChange(false /* userSwitch */);
+            }
         }
     }
 
diff --git a/services/core/java/com/android/server/display/LocalDisplayAdapter.java b/services/core/java/com/android/server/display/LocalDisplayAdapter.java
index ee53b60..be5980b 100644
--- a/services/core/java/com/android/server/display/LocalDisplayAdapter.java
+++ b/services/core/java/com/android/server/display/LocalDisplayAdapter.java
@@ -112,13 +112,13 @@
                 mSurfaceControlProxy.getPhysicalDisplayToken(physicalDisplayId);
         if (displayToken != null) {
             SurfaceControl.StaticDisplayInfo staticInfo =
-                    mSurfaceControlProxy.getStaticDisplayInfo(displayToken);
+                    mSurfaceControlProxy.getStaticDisplayInfo(physicalDisplayId);
             if (staticInfo == null) {
                 Slog.w(TAG, "No valid static info found for display device " + physicalDisplayId);
                 return;
             }
             SurfaceControl.DynamicDisplayInfo dynamicInfo =
-                    mSurfaceControlProxy.getDynamicDisplayInfo(displayToken);
+                    mSurfaceControlProxy.getDynamicDisplayInfo(physicalDisplayId);
             if (dynamicInfo == null) {
                 Slog.w(TAG, "No valid dynamic info found for display device " + physicalDisplayId);
                 return;
@@ -1402,8 +1402,8 @@
 
     @VisibleForTesting
     public static class SurfaceControlProxy {
-        public SurfaceControl.DynamicDisplayInfo getDynamicDisplayInfo(IBinder token) {
-            return SurfaceControl.getDynamicDisplayInfo(token);
+        public SurfaceControl.DynamicDisplayInfo getDynamicDisplayInfo(long displayId) {
+            return SurfaceControl.getDynamicDisplayInfo(displayId);
         }
 
         public long[] getPhysicalDisplayIds() {
@@ -1414,8 +1414,8 @@
             return DisplayControl.getPhysicalDisplayToken(physicalDisplayId);
         }
 
-        public SurfaceControl.StaticDisplayInfo getStaticDisplayInfo(IBinder displayToken) {
-            return SurfaceControl.getStaticDisplayInfo(displayToken);
+        public SurfaceControl.StaticDisplayInfo getStaticDisplayInfo(long displayId) {
+            return SurfaceControl.getStaticDisplayInfo(displayId);
         }
 
         public SurfaceControl.DesiredDisplayModeSpecs getDesiredDisplayModeSpecs(
diff --git a/services/core/java/com/android/server/display/LogicalDisplayMapper.java b/services/core/java/com/android/server/display/LogicalDisplayMapper.java
index 80f47a1..d7983ae 100644
--- a/services/core/java/com/android/server/display/LogicalDisplayMapper.java
+++ b/services/core/java/com/android/server/display/LogicalDisplayMapper.java
@@ -19,6 +19,7 @@
 import static android.view.Display.DEFAULT_DISPLAY;
 
 import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.content.Context;
 import android.hardware.devicestate.DeviceStateManager;
 import android.os.Handler;
@@ -29,7 +30,6 @@
 import android.os.SystemProperties;
 import android.text.TextUtils;
 import android.util.ArrayMap;
-import android.util.ArraySet;
 import android.util.IndentingPrintWriter;
 import android.util.Slog;
 import android.util.SparseArray;
@@ -45,7 +45,6 @@
 
 import java.io.PrintWriter;
 import java.util.Arrays;
-import java.util.Set;
 import java.util.function.Consumer;
 
 /**
@@ -324,58 +323,44 @@
     }
 
     /**
-     * Returns the set of {@link DisplayInfo} for this device state, only fetching the info that is
-     * part of the same display group as the provided display id. The DisplayInfo represent the
-     * logical display layouts possible for the given device state.
+     * Returns the {@link DisplayInfo} for this device state, indicated by the given display id. The
+     * DisplayInfo represents the attributes of the indicated display in the layout associated with
+     * this state. This is used to get display information for various displays in various states;
+     * e.g. to help apps preload resources for the possible display states.
      *
      * @param deviceState the state to query possible layouts for
-     * @param displayId   the display id to apply to all displays within the group
-     * @param groupId     the display group to filter display info for. Must be the same group as
-     *                    the display with the provided display id.
+     * @param displayId   the display id to retrieve
+     * @return {@code null} if no corresponding {@link DisplayInfo} could be found, or the
+     * {@link DisplayInfo} with a matching display id.
      */
-    public Set<DisplayInfo> getDisplayInfoForStateLocked(int deviceState, int displayId,
-            int groupId) {
-        Set<DisplayInfo> displayInfos = new ArraySet<>();
+    @Nullable
+    public DisplayInfo getDisplayInfoForStateLocked(int deviceState, int displayId) {
+        // Retrieve the layout for this particular state.
         final Layout layout = mDeviceStateToLayoutMap.get(deviceState);
-        final int layoutSize = layout.size();
-        for (int i = 0; i < layoutSize; i++) {
-            Layout.Display displayLayout = layout.getAt(i);
-            if (displayLayout == null) {
-                continue;
-            }
-
-            // If the underlying display-device we want to use for this display
-            // doesn't exist, then skip it. This can happen at startup as display-devices
-            // trickle in one at a time. When the new display finally shows up, the layout is
-            // recalculated so that the display is properly added to the current layout.
-            final DisplayAddress address = displayLayout.getAddress();
-            final DisplayDevice device = mDisplayDeviceRepo.getByAddressLocked(address);
-            if (device == null) {
-                Slog.w(TAG, "The display device (" + address + "), is not available"
-                        + " for the display state " + deviceState);
-                continue;
-            }
-
-            // Find or create the LogicalDisplay to map the DisplayDevice to.
-            final int logicalDisplayId = displayLayout.getLogicalDisplayId();
-            final LogicalDisplay logicalDisplay = getDisplayLocked(logicalDisplayId);
-            if (logicalDisplay == null) {
-                Slog.w(TAG, "The logical display (" + address + "), is not available"
-                        + " for the display state " + deviceState);
-                continue;
-            }
-            final DisplayInfo temp = logicalDisplay.getDisplayInfoLocked();
-            DisplayInfo displayInfo = new DisplayInfo(temp);
-            if (displayInfo.displayGroupId != groupId) {
-                // Ignore any displays not in the provided group.
-                continue;
-            }
-            // A display in the same group can be swapped out at any point, so set the display id
-            // for all results to the provided display id.
-            displayInfo.displayId = displayId;
-            displayInfos.add(displayInfo);
+        if (layout == null) {
+            return null;
         }
-        return displayInfos;
+        // Retrieve the details of the given display within this layout.
+        Layout.Display display = layout.getById(displayId);
+        if (display == null) {
+            return null;
+        }
+        // Retrieve the display info for the display that matches the display id.
+        final DisplayDevice device = mDisplayDeviceRepo.getByAddressLocked(display.getAddress());
+        if (device == null) {
+            Slog.w(TAG, "The display device (" + display.getAddress() + "), is not available"
+                    + " for the display state " + mDeviceState);
+            return null;
+        }
+        LogicalDisplay logicalDisplay = getDisplayLocked(device, /* includeDisabled= */ true);
+        if (logicalDisplay == null) {
+            Slog.w(TAG, "The logical display associated with address (" + display.getAddress()
+                    + "), is not available for the display state " + mDeviceState);
+            return null;
+        }
+        DisplayInfo displayInfo = new DisplayInfo(logicalDisplay.getDisplayInfoLocked());
+        displayInfo.displayId = displayId;
+        return displayInfo;
     }
 
     public void dumpLocked(PrintWriter pw) {
diff --git a/services/core/java/com/android/server/display/VirtualDisplayAdapter.java b/services/core/java/com/android/server/display/VirtualDisplayAdapter.java
index a118b2f..7c647cf 100644
--- a/services/core/java/com/android/server/display/VirtualDisplayAdapter.java
+++ b/services/core/java/com/android/server/display/VirtualDisplayAdapter.java
@@ -599,6 +599,15 @@
                 handleMediaProjectionStoppedLocked(mAppToken);
             }
         }
+
+        @Override
+        public void onCapturedContentResize(int width, int height) {
+            // Do nothing when we tell the client that the content is resized - it is up to them
+            // to decide to update the VirtualDisplay and Surface.
+            // We could only update the VirtualDisplay size, anyway (which the client wouldn't
+            // expect), and there will still be letterboxing on the output content since the
+            // Surface and VirtualDisplay would then have different aspect ratios.
+        }
     }
 
     @VisibleForTesting
diff --git a/services/core/java/com/android/server/dreams/DreamManagerService.java b/services/core/java/com/android/server/dreams/DreamManagerService.java
index ea09629..b822541 100644
--- a/services/core/java/com/android/server/dreams/DreamManagerService.java
+++ b/services/core/java/com/android/server/dreams/DreamManagerService.java
@@ -378,6 +378,10 @@
                 return false;
             }
 
+            if (!dreamsEnabledForUser(ActivityManager.getCurrentUser())) {
+                return false;
+            }
+
             if ((mWhenToDream & DREAM_ON_CHARGE) == DREAM_ON_CHARGE) {
                 return mIsCharging;
             }
diff --git a/services/core/java/com/android/server/graphics/fonts/FontManagerService.java b/services/core/java/com/android/server/graphics/fonts/FontManagerService.java
index 28dc318..3c5b067 100644
--- a/services/core/java/com/android/server/graphics/fonts/FontManagerService.java
+++ b/services/core/java/com/android/server/graphics/fonts/FontManagerService.java
@@ -187,8 +187,8 @@
         }
 
         @Override
-        public void setUpFsverity(String filePath, byte[] pkcs7Signature) throws IOException {
-            VerityUtils.setUpFsverity(filePath, pkcs7Signature);
+        public void setUpFsverity(String filePath) throws IOException {
+            VerityUtils.setUpFsverity(filePath, /* signature */ (byte[]) null);
         }
 
         @Override
diff --git a/services/core/java/com/android/server/graphics/fonts/UpdatableFontDir.java b/services/core/java/com/android/server/graphics/fonts/UpdatableFontDir.java
index 457d5b7..6f93608 100644
--- a/services/core/java/com/android/server/graphics/fonts/UpdatableFontDir.java
+++ b/services/core/java/com/android/server/graphics/fonts/UpdatableFontDir.java
@@ -78,7 +78,7 @@
     interface FsverityUtil {
         boolean isFromTrustedProvider(String path, byte[] pkcs7Signature);
 
-        void setUpFsverity(String path, byte[] pkcs7Signature) throws IOException;
+        void setUpFsverity(String path) throws IOException;
 
         boolean rename(File src, File dest);
     }
@@ -354,8 +354,7 @@
             try {
                 // Do not parse font file before setting up fs-verity.
                 // setUpFsverity throws IOException if failed.
-                mFsverityUtil.setUpFsverity(tempNewFontFile.getAbsolutePath(),
-                        pkcs7Signature);
+                mFsverityUtil.setUpFsverity(tempNewFontFile.getAbsolutePath());
             } catch (IOException e) {
                 throw new SystemFontException(
                         FontManager.RESULT_ERROR_VERIFICATION_FAILURE,
diff --git a/services/core/java/com/android/server/input/InputManagerInternal.java b/services/core/java/com/android/server/input/InputManagerInternal.java
index 298098a..01a564d 100644
--- a/services/core/java/com/android/server/input/InputManagerInternal.java
+++ b/services/core/java/com/android/server/input/InputManagerInternal.java
@@ -171,4 +171,19 @@
      * {@see Light.LIGHT_TYPE_KEYBOARD_BACKLIGHT}
      */
     public abstract void decrementKeyboardBacklight(int deviceId);
+
+    /**
+     * Add a runtime association between the input port and device type. Input ports are expected to
+     * be unique.
+     * @param inputPort The port of the input device.
+     * @param type The type of the device. E.g. "touchNavigation".
+     */
+    public abstract void setTypeAssociation(@NonNull String inputPort, @NonNull String type);
+
+    /**
+     * Removes a runtime association between the input device and type.
+     *
+     * @param inputPort The port of the input device.
+     */
+    public abstract void unsetTypeAssociation(@NonNull String inputPort);
 }
diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java
index 81d782e..1809b18 100644
--- a/services/core/java/com/android/server/input/InputManagerService.java
+++ b/services/core/java/com/android/server/input/InputManagerService.java
@@ -248,6 +248,13 @@
     @GuardedBy("mAssociationsLock")
     private final Map<String, String> mUniqueIdAssociations = new ArrayMap<>();
 
+    // Stores input ports associated with device types. For example, adding an association
+    // {"123", "touchNavigation"} here would mean that a touch device appearing at port "123" would
+    // enumerate as a "touch navigation" device rather than the default "touchpad as a mouse
+    // pointer" device.
+    @GuardedBy("mAssociationsLock")
+    private final Map<String, String> mDeviceTypeAssociations = new ArrayMap<>();
+
     // Guards per-display input properties and properties relating to the mouse pointer.
     // Threads can wait on this lock to be notified the next time the display on which the mouse
     // pointer is shown has changed.
@@ -294,6 +301,9 @@
     // Manages Keyboard backlight
     private final KeyboardBacklightController mKeyboardBacklightController;
 
+    // Manages Keyboard modifier keys remapping
+    private final KeyRemapper mKeyRemapper;
+
     // Maximum number of milliseconds to wait for input event injection.
     private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
 
@@ -408,6 +418,7 @@
         mBatteryController = new BatteryController(mContext, mNative, injector.getLooper());
         mKeyboardBacklightController = new KeyboardBacklightController(mContext, mNative,
                 mDataStore, injector.getLooper());
+        mKeyRemapper = new KeyRemapper(mContext, mNative, mDataStore, injector.getLooper());
 
         mUseDevInputEventForAudioJack =
                 mContext.getResources().getBoolean(R.bool.config_useDevInputEventForAudioJack);
@@ -536,6 +547,7 @@
         mKeyboardLayoutManager.systemRunning();
         mBatteryController.systemRunning();
         mKeyboardBacklightController.systemRunning();
+        mKeyRemapper.systemRunning();
     }
 
     private void reloadDeviceAliases() {
@@ -1188,7 +1200,7 @@
     @Override // Binder call
     public String getKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
             @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
-            @NonNull InputMethodSubtype imeSubtype) {
+            @Nullable InputMethodSubtype imeSubtype) {
         return mKeyboardLayoutManager.getKeyboardLayoutForInputDevice(identifier, userId,
                 imeInfo, imeSubtype);
     }
@@ -1197,16 +1209,16 @@
     @Override // Binder call
     public void setKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
             @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
-            @NonNull InputMethodSubtype imeSubtype, String keyboardLayoutDescriptor) {
+            @Nullable InputMethodSubtype imeSubtype, String keyboardLayoutDescriptor) {
         super.setKeyboardLayoutForInputDevice_enforcePermission();
         mKeyboardLayoutManager.setKeyboardLayoutForInputDevice(identifier, userId, imeInfo,
                 imeSubtype, keyboardLayoutDescriptor);
     }
 
     @Override // Binder call
-    public String[] getKeyboardLayoutListForInputDevice(InputDeviceIdentifier identifier,
+    public KeyboardLayout[] getKeyboardLayoutListForInputDevice(InputDeviceIdentifier identifier,
             @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
-            @NonNull InputMethodSubtype imeSubtype) {
+            @Nullable InputMethodSubtype imeSubtype) {
         return mKeyboardLayoutManager.getKeyboardLayoutListForInputDevice(identifier, userId,
                 imeInfo, imeSubtype);
     }
@@ -1900,6 +1912,23 @@
         mNative.changeUniqueIdAssociation();
     }
 
+    void setTypeAssociationInternal(@NonNull String inputPort, @NonNull String type) {
+        Objects.requireNonNull(inputPort);
+        Objects.requireNonNull(type);
+        synchronized (mAssociationsLock) {
+            mDeviceTypeAssociations.put(inputPort, type);
+        }
+        mNative.changeTypeAssociation();
+    }
+
+    void unsetTypeAssociationInternal(@NonNull String inputPort) {
+        Objects.requireNonNull(inputPort);
+        synchronized (mAssociationsLock) {
+            mDeviceTypeAssociations.remove(inputPort);
+        }
+        mNative.changeTypeAssociation();
+    }
+
     @Override // Binder call
     public InputSensorInfo[] getSensorList(int deviceId) {
         return mNative.getSensorList(deviceId);
@@ -2216,6 +2245,13 @@
                     pw.println("  uniqueId: " + v);
                 });
             }
+            if (!mDeviceTypeAssociations.isEmpty()) {
+                pw.println("Type Associations:");
+                mDeviceTypeAssociations.forEach((k, v) -> {
+                    pw.print("  port: " + k);
+                    pw.println("  type: " + v);
+                });
+            }
         }
     }
 
@@ -2625,6 +2661,18 @@
         return flatten(associations);
     }
 
+    // Native callback
+    @SuppressWarnings("unused")
+    @VisibleForTesting
+    String[] getDeviceTypeAssociations() {
+        final Map<String, String> associations;
+        synchronized (mAssociationsLock) {
+            associations = new HashMap<>(mDeviceTypeAssociations);
+        }
+
+        return flatten(associations);
+    }
+
     /**
      * Gets if an input device could dispatch to the given display".
      * @param deviceId The input device id.
@@ -2738,6 +2786,27 @@
         return mKeyboardLayoutManager.getKeyboardLayoutOverlay(identifier);
     }
 
+    @EnforcePermission(Manifest.permission.REMAP_MODIFIER_KEYS)
+    @Override // Binder call
+    public void remapModifierKey(int fromKey, int toKey) {
+        super.remapModifierKey_enforcePermission();
+        mKeyRemapper.remapKey(fromKey, toKey);
+    }
+
+    @EnforcePermission(Manifest.permission.REMAP_MODIFIER_KEYS)
+    @Override // Binder call
+    public void clearAllModifierKeyRemappings() {
+        super.clearAllModifierKeyRemappings_enforcePermission();
+        mKeyRemapper.clearAllKeyRemappings();
+    }
+
+    @EnforcePermission(Manifest.permission.REMAP_MODIFIER_KEYS)
+    @Override // Binder call
+    public Map<Integer, Integer> getModifierKeyRemapping() {
+        super.getModifierKeyRemapping_enforcePermission();
+        return mKeyRemapper.getKeyRemapping();
+    }
+
     // Native callback.
     @SuppressWarnings("unused")
     private String getDeviceAlias(String uniqueId) {
@@ -3237,6 +3306,16 @@
         public void decrementKeyboardBacklight(int deviceId) {
             mKeyboardBacklightController.decrementKeyboardBacklight(deviceId);
         }
+
+        @Override
+        public void setTypeAssociation(@NonNull String inputPort, @NonNull String type) {
+            setTypeAssociationInternal(inputPort, type);
+        }
+
+        @Override
+        public void unsetTypeAssociation(@NonNull String inputPort) {
+            unsetTypeAssociationInternal(inputPort);
+        }
     }
 
     @Override
diff --git a/services/core/java/com/android/server/input/KeyRemapper.java b/services/core/java/com/android/server/input/KeyRemapper.java
new file mode 100644
index 0000000..950e094
--- /dev/null
+++ b/services/core/java/com/android/server/input/KeyRemapper.java
@@ -0,0 +1,161 @@
+/*
+ * 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.server.input;
+
+import android.content.Context;
+import android.hardware.input.InputManager;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.view.InputDevice;
+
+import com.android.internal.annotations.GuardedBy;
+
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * A component of {@link InputManagerService} responsible for managing key remappings.
+ *
+ * @hide
+ */
+final class KeyRemapper implements InputManager.InputDeviceListener {
+
+    private static final int MSG_UPDATE_EXISTING_DEVICES = 1;
+    private static final int MSG_REMAP_KEY = 2;
+    private static final int MSG_CLEAR_ALL_REMAPPING = 3;
+
+    private final Context mContext;
+    private final NativeInputManagerService mNative;
+    // The PersistentDataStore should be locked before use.
+    @GuardedBy("mDataStore")
+    private final PersistentDataStore mDataStore;
+    private final Handler mHandler;
+
+    KeyRemapper(Context context, NativeInputManagerService nativeService,
+            PersistentDataStore dataStore, Looper looper) {
+        mContext = context;
+        mNative = nativeService;
+        mDataStore = dataStore;
+        mHandler = new Handler(looper, this::handleMessage);
+    }
+
+    public void systemRunning() {
+        InputManager inputManager = Objects.requireNonNull(
+                mContext.getSystemService(InputManager.class));
+        inputManager.registerInputDeviceListener(this, mHandler);
+
+        Message msg = Message.obtain(mHandler, MSG_UPDATE_EXISTING_DEVICES,
+                inputManager.getInputDeviceIds());
+        mHandler.sendMessage(msg);
+    }
+
+    public void remapKey(int fromKey, int toKey) {
+        Message msg = Message.obtain(mHandler, MSG_REMAP_KEY, fromKey, toKey);
+        mHandler.sendMessage(msg);
+    }
+
+    public void clearAllKeyRemappings() {
+        Message msg = Message.obtain(mHandler, MSG_CLEAR_ALL_REMAPPING);
+        mHandler.sendMessage(msg);
+    }
+
+    public Map<Integer, Integer> getKeyRemapping() {
+        synchronized (mDataStore) {
+            return mDataStore.getKeyRemapping();
+        }
+    }
+
+    private void addKeyRemapping(int fromKey, int toKey) {
+        InputManager inputManager = Objects.requireNonNull(
+                mContext.getSystemService(InputManager.class));
+        for (int deviceId : inputManager.getInputDeviceIds()) {
+            InputDevice inputDevice = inputManager.getInputDevice(deviceId);
+            if (inputDevice != null && !inputDevice.isVirtual() && inputDevice.isFullKeyboard()) {
+                mNative.addKeyRemapping(deviceId, fromKey, toKey);
+            }
+        }
+    }
+
+    private void remapKeyInternal(int fromKey, int toKey) {
+        addKeyRemapping(fromKey, toKey);
+        synchronized (mDataStore) {
+            try {
+                if (fromKey == toKey) {
+                    mDataStore.clearMappedKey(fromKey);
+                } else {
+                    mDataStore.remapKey(fromKey, toKey);
+                }
+            } finally {
+                mDataStore.saveIfNeeded();
+            }
+        }
+    }
+
+    private void clearAllRemappingsInternal() {
+        synchronized (mDataStore) {
+            try {
+                Map<Integer, Integer> keyRemapping = mDataStore.getKeyRemapping();
+                for (int fromKey : keyRemapping.keySet()) {
+                    mDataStore.clearMappedKey(fromKey);
+
+                    // Remapping to itself will clear the remapping on native side
+                    addKeyRemapping(fromKey, fromKey);
+                }
+            } finally {
+                mDataStore.saveIfNeeded();
+            }
+        }
+    }
+
+    @Override
+    public void onInputDeviceAdded(int deviceId) {
+        InputManager inputManager = Objects.requireNonNull(
+                mContext.getSystemService(InputManager.class));
+        InputDevice inputDevice = inputManager.getInputDevice(deviceId);
+        if (inputDevice != null && !inputDevice.isVirtual() && inputDevice.isFullKeyboard()) {
+            Map<Integer, Integer> remapping = getKeyRemapping();
+            remapping.forEach(
+                    (fromKey, toKey) -> mNative.addKeyRemapping(deviceId, fromKey, toKey));
+        }
+    }
+
+    @Override
+    public void onInputDeviceRemoved(int deviceId) {
+    }
+
+    @Override
+    public void onInputDeviceChanged(int deviceId) {
+    }
+
+    private boolean handleMessage(Message msg) {
+        switch (msg.what) {
+            case MSG_UPDATE_EXISTING_DEVICES:
+                for (int deviceId : (int[]) msg.obj) {
+                    onInputDeviceAdded(deviceId);
+                }
+                return true;
+            case MSG_REMAP_KEY:
+                remapKeyInternal(msg.arg1, msg.arg2);
+                return true;
+            case MSG_CLEAR_ALL_REMAPPING:
+                clearAllRemappingsInternal();
+                return true;
+        }
+        return false;
+    }
+}
diff --git a/services/core/java/com/android/server/input/KeyboardLayoutManager.java b/services/core/java/com/android/server/input/KeyboardLayoutManager.java
index 1bb14aa..d76da83 100644
--- a/services/core/java/com/android/server/input/KeyboardLayoutManager.java
+++ b/services/core/java/com/android/server/input/KeyboardLayoutManager.java
@@ -17,6 +17,7 @@
 package com.android.server.input;
 
 import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.annotation.UserIdInt;
 import android.app.Notification;
 import android.app.NotificationManager;
@@ -550,7 +551,7 @@
 
     public String getKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
             @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
-            @NonNull InputMethodSubtype imeSubtype) {
+            @Nullable InputMethodSubtype imeSubtype) {
         // TODO(b/259530132): Implement the new keyboard layout API: Returning non-IME specific
         //  layout for now.
         return getCurrentKeyboardLayoutForInputDevice(identifier);
@@ -558,23 +559,18 @@
 
     public void setKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
             @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
-            @NonNull InputMethodSubtype imeSubtype, String keyboardLayoutDescriptor) {
+            @Nullable InputMethodSubtype imeSubtype, String keyboardLayoutDescriptor) {
         // TODO(b/259530132): Implement the new keyboard layout API: setting non-IME specific
         //  layout for now.
         setCurrentKeyboardLayoutForInputDevice(identifier, keyboardLayoutDescriptor);
     }
 
-    public String[] getKeyboardLayoutListForInputDevice(InputDeviceIdentifier identifier,
+    public KeyboardLayout[] getKeyboardLayoutListForInputDevice(InputDeviceIdentifier identifier,
             @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
-            @NonNull InputMethodSubtype imeSubtype) {
+            @Nullable InputMethodSubtype imeSubtype) {
         // TODO(b/259530132): Implement the new keyboard layout API: Returning list of all
         //  layouts for now.
-        KeyboardLayout[] allLayouts = getKeyboardLayouts();
-        String[] allLayoutDesc = new String[allLayouts.length];
-        for (int i = 0; i < allLayouts.length; i++) {
-            allLayoutDesc[i] = allLayouts[i].getDescriptor();
-        }
-        return allLayoutDesc;
+        return getKeyboardLayouts();
     }
 
     public void switchKeyboardLayout(int deviceId, int direction) {
diff --git a/services/core/java/com/android/server/input/NativeInputManagerService.java b/services/core/java/com/android/server/input/NativeInputManagerService.java
index cfa7fb1..184bc0e 100644
--- a/services/core/java/com/android/server/input/NativeInputManagerService.java
+++ b/services/core/java/com/android/server/input/NativeInputManagerService.java
@@ -47,6 +47,8 @@
 
     int getSwitchState(int deviceId, int sourceMask, int sw);
 
+    void addKeyRemapping(int deviceId, int fromKeyCode, int toKeyCode);
+
     boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists);
 
     int getKeyCodeForKeyLocation(int deviceId, int locationKeyCode);
@@ -184,6 +186,8 @@
 
     void changeUniqueIdAssociation();
 
+    void changeTypeAssociation();
+
     void notifyPointerDisplayIdChanged();
 
     void setDisplayEligibilityForPointerCapture(int displayId, boolean enabled);
@@ -235,6 +239,9 @@
         public native int getSwitchState(int deviceId, int sourceMask, int sw);
 
         @Override
+        public native void addKeyRemapping(int deviceId, int fromKeyCode, int toKeyCode);
+
+        @Override
         public native boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes,
                 boolean[] keyExists);
 
@@ -395,6 +402,9 @@
         public native void changeUniqueIdAssociation();
 
         @Override
+        public native void changeTypeAssociation();
+
+        @Override
         public native void notifyPointerDisplayIdChanged();
 
         @Override
diff --git a/services/core/java/com/android/server/input/PersistentDataStore.java b/services/core/java/com/android/server/input/PersistentDataStore.java
index 1bb10c7..375377a7 100644
--- a/services/core/java/com/android/server/input/PersistentDataStore.java
+++ b/services/core/java/com/android/server/input/PersistentDataStore.java
@@ -27,14 +27,13 @@
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.util.ArrayUtils;
 import com.android.internal.util.XmlUtils;
+import com.android.modules.utils.TypedXmlPullParser;
+import com.android.modules.utils.TypedXmlSerializer;
 
 import libcore.io.IoUtils;
 
 import org.xmlpull.v1.XmlPullParserException;
 
-import com.android.modules.utils.TypedXmlPullParser;
-import com.android.modules.utils.TypedXmlSerializer;
-
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
@@ -64,6 +63,8 @@
 final class PersistentDataStore {
     static final String TAG = "InputManager";
 
+    private static final int INVALID_VALUE = -1;
+
     // Input device state by descriptor.
     private final HashMap<String, InputDeviceState> mInputDevices =
             new HashMap<String, InputDeviceState>();
@@ -77,6 +78,9 @@
     // True if there are changes to be saved.
     private boolean mDirty;
 
+    // Storing key remapping
+    private Map<Integer, Integer> mKeyRemapping = new HashMap<>();
+
     public PersistentDataStore() {
         this(new Injector());
     }
@@ -187,6 +191,30 @@
         return state.getKeyboardBacklightBrightness(lightId);
     }
 
+    public boolean remapKey(int fromKey, int toKey) {
+        loadIfNeeded();
+        if (mKeyRemapping.getOrDefault(fromKey, INVALID_VALUE) == toKey) {
+            return false;
+        }
+        mKeyRemapping.put(fromKey, toKey);
+        setDirty();
+        return true;
+    }
+
+    public boolean clearMappedKey(int key) {
+        loadIfNeeded();
+        if (mKeyRemapping.containsKey(key)) {
+            mKeyRemapping.remove(key);
+            setDirty();
+        }
+        return true;
+    }
+
+    public Map<Integer, Integer> getKeyRemapping() {
+        loadIfNeeded();
+        return new HashMap<>(mKeyRemapping);
+    }
+
     public boolean removeUninstalledKeyboardLayouts(Set<String> availableKeyboardLayouts) {
         boolean changed = false;
         for (InputDeviceState state : mInputDevices.values()) {
@@ -229,6 +257,7 @@
     }
 
     private void clearState() {
+        mKeyRemapping.clear();
         mInputDevices.clear();
     }
 
@@ -280,7 +309,9 @@
         XmlUtils.beginDocument(parser, "input-manager-state");
         final int outerDepth = parser.getDepth();
         while (XmlUtils.nextElementWithin(parser, outerDepth)) {
-            if (parser.getName().equals("input-devices")) {
+            if (parser.getName().equals("key-remapping")) {
+                loadKeyRemappingFromXml(parser);
+            } else if (parser.getName().equals("input-devices")) {
                 loadInputDevicesFromXml(parser);
             }
         }
@@ -307,10 +338,31 @@
         }
     }
 
+    private void loadKeyRemappingFromXml(TypedXmlPullParser parser)
+            throws IOException, XmlPullParserException {
+        final int outerDepth = parser.getDepth();
+        while (XmlUtils.nextElementWithin(parser, outerDepth)) {
+            if (parser.getName().equals("remap")) {
+                int fromKey = parser.getAttributeInt(null, "from-key");
+                int toKey = parser.getAttributeInt(null, "to-key");
+                mKeyRemapping.put(fromKey, toKey);
+            }
+        }
+    }
+
     private void saveToXml(TypedXmlSerializer serializer) throws IOException {
         serializer.startDocument(null, true);
         serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
         serializer.startTag(null, "input-manager-state");
+        serializer.startTag(null, "key-remapping");
+        for (int fromKey : mKeyRemapping.keySet()) {
+            int toKey = mKeyRemapping.get(fromKey);
+            serializer.startTag(null, "remap");
+            serializer.attributeInt(null, "from-key", fromKey);
+            serializer.attributeInt(null, "to-key", toKey);
+            serializer.endTag(null, "remap");
+        }
+        serializer.endTag(null, "key-remapping");
         serializer.startTag(null, "input-devices");
         for (Map.Entry<String, InputDeviceState> entry : mInputDevices.entrySet()) {
             final String descriptor = entry.getKey();
@@ -329,7 +381,6 @@
         private static final String[] CALIBRATION_NAME = { "x_scale",
                 "x_ymix", "x_offset", "y_xmix", "y_scale", "y_offset" };
 
-        private static final int INVALID_VALUE = -1;
         private final TouchCalibration[] mTouchCalibration = new TouchCalibration[4];
         @Nullable
         private String mCurrentKeyboardLayout;
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodUtils.java b/services/core/java/com/android/server/inputmethod/InputMethodUtils.java
index ebf9237d..be99bfb 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodUtils.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodUtils.java
@@ -199,9 +199,14 @@
     }
 
     /**
-     * Utility class for putting and getting settings for InputMethod
+     * Utility class for putting and getting settings for InputMethod.
+     *
+     * This is used in two ways:
+     * - Singleton instance in {@link InputMethodManagerService}, which is updated on user-switch to
+     * follow the current user.
+     * - On-demand instances when we need settings for non-current users.
+     *
      * TODO: Move all putters and getters of settings to this class.
-     * TODO(b/235661780): Make the setting supports multi-users.
      */
     @UserHandleAware
     public static class InputMethodSettings {
@@ -212,9 +217,9 @@
                 new TextUtils.SimpleStringSplitter(INPUT_METHOD_SUBTYPE_SEPARATOR);
 
         @NonNull
-        private final Context mUserAwareContext;
-        private final Resources mRes;
-        private final ContentResolver mResolver;
+        private Context mUserAwareContext;
+        private Resources mRes;
+        private ContentResolver mResolver;
         private final ArrayMap<String, InputMethodInfo> mMethodMap;
 
         /**
@@ -272,15 +277,19 @@
             return imsList;
         }
 
-        InputMethodSettings(@NonNull Context context,
-                ArrayMap<String, InputMethodInfo> methodMap, @UserIdInt int userId,
-                boolean copyOnWrite) {
+        private void initContentWithUserContext(@NonNull Context context, @UserIdInt int userId) {
             mUserAwareContext = context.getUserId() == userId
                     ? context
                     : context.createContextAsUser(UserHandle.of(userId), 0 /* flags */);
             mRes = mUserAwareContext.getResources();
             mResolver = mUserAwareContext.getContentResolver();
+        }
+
+        InputMethodSettings(@NonNull Context context,
+                ArrayMap<String, InputMethodInfo> methodMap, @UserIdInt int userId,
+                boolean copyOnWrite) {
             mMethodMap = methodMap;
+            initContentWithUserContext(context, userId);
             switchCurrentUser(userId, copyOnWrite);
         }
 
@@ -301,6 +310,9 @@
                 mEnabledInputMethodsStrCache = "";
                 // TODO: mCurrentProfileIds should be cleared here.
             }
+            if (mUserAwareContext.getUserId() != userId) {
+                initContentWithUserContext(mUserAwareContext, userId);
+            }
             mCurrentUserId = userId;
             mCopyOnWrite = copyOnWrite;
             // TODO: mCurrentProfileIds should be updated here.
diff --git a/services/core/java/com/android/server/location/LocationManagerService.java b/services/core/java/com/android/server/location/LocationManagerService.java
index 3ce51c3..b4c9596 100644
--- a/services/core/java/com/android/server/location/LocationManagerService.java
+++ b/services/core/java/com/android/server/location/LocationManagerService.java
@@ -24,6 +24,7 @@
 import static android.content.pm.PackageManager.PERMISSION_GRANTED;
 import static android.location.LocationManager.BLOCK_PENDING_INTENT_SYSTEM_API_USAGE;
 import static android.location.LocationManager.FUSED_PROVIDER;
+import static android.location.LocationManager.GPS_HARDWARE_PROVIDER;
 import static android.location.LocationManager.GPS_PROVIDER;
 import static android.location.LocationManager.NETWORK_PROVIDER;
 import static android.location.LocationRequest.LOW_POWER_EXCEPTIONS;
@@ -95,6 +96,7 @@
 import android.util.Log;
 
 import com.android.internal.annotations.GuardedBy;
+import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.util.DumpUtils;
 import com.android.internal.util.Preconditions;
 import com.android.server.FgThread;
@@ -319,6 +321,9 @@
 
         for (LocationProviderManager manager : mProviderManagers) {
             if (providerName.equals(manager.getName())) {
+                if (!manager.isVisibleToCaller()) {
+                    return null;
+                }
                 return manager;
             }
         }
@@ -341,8 +346,9 @@
         }
     }
 
-    private void addLocationProviderManager(LocationProviderManager manager,
-            @Nullable AbstractLocationProvider realProvider) {
+    @VisibleForTesting
+    void addLocationProviderManager(
+            LocationProviderManager manager, @Nullable AbstractLocationProvider realProvider) {
         synchronized (mProviderManagers) {
             Preconditions.checkState(getLocationProviderManager(manager.getName()) == null);
 
@@ -453,6 +459,20 @@
             }
             if (gnssProvider == null) {
                 gnssProvider = mGnssManagerService.getGnssLocationProvider();
+            } else {
+                // If we have a GNSS provider override, add the hardware provider as a standalone
+                // option for use by apps with the correct permission. Note the GNSS HAL can only
+                // support a single client, so mGnssManagerService.getGnssLocationProvider() can
+                // only be installed with a single provider.
+                LocationProviderManager gnssHardwareManager =
+                        new LocationProviderManager(
+                                mContext,
+                                mInjector,
+                                GPS_HARDWARE_PROVIDER,
+                                mPassiveManager,
+                                Collections.singletonList(Manifest.permission.LOCATION_HARDWARE));
+                addLocationProviderManager(
+                        gnssHardwareManager, mGnssManagerService.getGnssLocationProvider());
             }
 
             LocationProviderManager gnssManager = new LocationProviderManager(mContext, mInjector,
@@ -629,7 +649,9 @@
     public List<String> getAllProviders() {
         ArrayList<String> providers = new ArrayList<>(mProviderManagers.size());
         for (LocationProviderManager manager : mProviderManagers) {
-            providers.add(manager.getName());
+            if (manager.isVisibleToCaller()) {
+                providers.add(manager.getName());
+            }
         }
         return providers;
     }
@@ -644,15 +666,18 @@
         synchronized (mLock) {
             ArrayList<String> providers = new ArrayList<>(mProviderManagers.size());
             for (LocationProviderManager manager : mProviderManagers) {
-                String name = manager.getName();
-                if (enabledOnly && !manager.isEnabled(UserHandle.getCallingUserId())) {
-                    continue;
+                if (manager.isVisibleToCaller()) {
+                    String name = manager.getName();
+                    if (enabledOnly && !manager.isEnabled(UserHandle.getCallingUserId())) {
+                        continue;
+                    }
+                    if (criteria != null
+                            && !LocationProvider.propertiesMeetCriteria(
+                                    name, manager.getProperties(), criteria)) {
+                        continue;
+                    }
+                    providers.add(name);
                 }
-                if (criteria != null && !LocationProvider.propertiesMeetCriteria(name,
-                        manager.getProperties(), criteria)) {
-                    continue;
-                }
-                providers.add(name);
             }
             return providers;
         }
@@ -1059,7 +1084,9 @@
     public void addProviderRequestListener(IProviderRequestListener listener) {
         mContext.enforceCallingOrSelfPermission(INTERACT_ACROSS_USERS, null);
         for (LocationProviderManager manager : mProviderManagers) {
-            manager.addProviderRequestListener(listener);
+            if (manager.isVisibleToCaller()) {
+                manager.addProviderRequestListener(listener);
+            }
         }
     }
 
@@ -1649,7 +1676,7 @@
                 if (provider != null && !provider.equals(manager.getName())) {
                     continue;
                 }
-                if (identity.equals(manager.getProviderIdentity())) {
+                if (identity.equals(manager.getProviderIdentity()) && manager.isVisibleToCaller()) {
                     return true;
                 }
             }
diff --git a/services/core/java/com/android/server/location/provider/LocationProviderManager.java b/services/core/java/com/android/server/location/provider/LocationProviderManager.java
index 7063cb8..ffdb531 100644
--- a/services/core/java/com/android/server/location/provider/LocationProviderManager.java
+++ b/services/core/java/com/android/server/location/provider/LocationProviderManager.java
@@ -19,6 +19,7 @@
 import static android.app.AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION;
 import static android.app.AppOpsManager.OP_MONITOR_LOCATION;
 import static android.app.compat.CompatChanges.isChangeEnabled;
+import static android.content.pm.PackageManager.PERMISSION_GRANTED;
 import static android.location.LocationManager.DELIVER_HISTORICAL_LOCATIONS;
 import static android.location.LocationManager.GPS_PROVIDER;
 import static android.location.LocationManager.KEY_FLUSH_COMPLETE;
@@ -48,6 +49,7 @@
 
 import android.annotation.IntDef;
 import android.annotation.Nullable;
+import android.annotation.SuppressLint;
 import android.app.AlarmManager.OnAlarmListener;
 import android.app.BroadcastOptions;
 import android.app.PendingIntent;
@@ -124,6 +126,7 @@
 import java.lang.annotation.RetentionPolicy;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.NoSuchElementException;
 import java.util.Objects;
 import java.util.concurrent.CopyOnWriteArrayList;
@@ -1362,6 +1365,10 @@
     @GuardedBy("mMultiplexerLock")
     private final ArrayList<ProviderEnabledListener> mEnabledListeners;
 
+    // Extra permissions required to use this provider (on top of the usual location permissions).
+    // Not guarded because it's read only.
+    private final Collection<String> mRequiredPermissions;
+
     private final CopyOnWriteArrayList<IProviderRequestListener> mProviderRequestListeners;
 
     protected final LocationManagerInternal mLocationManagerInternal;
@@ -1435,12 +1442,34 @@
 
     public LocationProviderManager(Context context, Injector injector,
             String name, @Nullable PassiveLocationProviderManager passiveManager) {
+        this(context, injector, name, passiveManager, Collections.emptyList());
+    }
+
+    /**
+     * Creates a manager for a location provider (the two have a 1:1 correspondence).
+     *
+     * @param context Context in which the manager is running.
+     * @param injector Injector to retrieve system components (useful to override in testing)
+     * @param name Name of this provider (used in LocationManager APIs by client apps).
+     * @param passiveManager The "passive" manager (special case provider that returns locations
+     *     from all other providers).
+     * @param requiredPermissions Required permissions for accessing this provider. All of the given
+     *     permissions are required to access the provider. If a caller doesn't hold the correct
+     *     permission, the provider will be invisible to it.
+     */
+    public LocationProviderManager(
+            Context context,
+            Injector injector,
+            String name,
+            @Nullable PassiveLocationProviderManager passiveManager,
+            Collection<String> requiredPermissions) {
         mContext = context;
         mName = Objects.requireNonNull(name);
         mPassiveManager = passiveManager;
         mState = STATE_STOPPED;
         mEnabled = new SparseBooleanArray(2);
         mLastLocations = new SparseArray<>(2);
+        mRequiredPermissions = requiredPermissions;
 
         mEnabledListeners = new ArrayList<>();
         mProviderRequestListeners = new CopyOnWriteArrayList<>();
@@ -1559,6 +1588,24 @@
         }
     }
 
+    /**
+     * Returns true if this provider is visible to the current caller (whether called from a binder
+     * thread or not). If a provider isn't visible, then all APIs return the same data they would if
+     * the provider didn't exist (i.e. the caller can't see or use the provider).
+     *
+     * <p>This method doesn't require any permissions, but uses permissions to determine which
+     * subset of providers are visible.
+     */
+    @SuppressLint("AndroidFrameworkRequiresPermission")
+    public boolean isVisibleToCaller() {
+        for (String permission : mRequiredPermissions) {
+            if (mContext.checkCallingOrSelfPermission(permission) != PERMISSION_GRANTED) {
+                return false;
+            }
+        }
+        return true;
+    }
+
     public void addEnabledListener(ProviderEnabledListener listener) {
         synchronized (mMultiplexerLock) {
             Preconditions.checkState(mState != STATE_STOPPED);
diff --git a/services/core/java/com/android/server/locksettings/LockSettingsService.java b/services/core/java/com/android/server/locksettings/LockSettingsService.java
index 0ae3a02..5f39a52 100644
--- a/services/core/java/com/android/server/locksettings/LockSettingsService.java
+++ b/services/core/java/com/android/server/locksettings/LockSettingsService.java
@@ -21,6 +21,8 @@
 import static android.Manifest.permission.READ_CONTACTS;
 import static android.Manifest.permission.SET_AND_VERIFY_LOCKSCREEN_CREDENTIALS;
 import static android.Manifest.permission.SET_INITIAL_LOCK;
+import static android.app.admin.DevicePolicyManager.DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_DEFAULT;
+import static android.app.admin.DevicePolicyManager.DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_FLAG;
 import static android.app.admin.DevicePolicyResources.Strings.Core.PROFILE_ENCRYPTED_DETAIL;
 import static android.app.admin.DevicePolicyResources.Strings.Core.PROFILE_ENCRYPTED_MESSAGE;
 import static android.app.admin.DevicePolicyResources.Strings.Core.PROFILE_ENCRYPTED_TITLE;
@@ -69,7 +71,7 @@
 import android.content.pm.UserInfo;
 import android.database.ContentObserver;
 import android.database.sqlite.SQLiteDatabase;
-import android.hardware.authsecret.V1_0.IAuthSecret;
+import android.hardware.authsecret.IAuthSecret;
 import android.hardware.biometrics.BiometricManager;
 import android.hardware.face.Face;
 import android.hardware.face.FaceManager;
@@ -91,6 +93,7 @@
 import android.os.UserManager;
 import android.os.storage.IStorageManager;
 import android.os.storage.StorageManager;
+import android.provider.DeviceConfig;
 import android.provider.Settings;
 import android.provider.Settings.Secure;
 import android.security.AndroidKeyStoreMaintenance;
@@ -237,8 +240,7 @@
     protected final UserManager mUserManager;
     private final IStorageManager mStorageManager;
     private final IActivityManager mActivityManager;
-    @VisibleForTesting
-    protected final SyntheticPasswordManager mSpManager;
+    private final SyntheticPasswordManager mSpManager;
 
     private final java.security.KeyStore mJavaKeyStore;
     private final RecoverableKeyStoreManager mRecoverableKeyStoreManager;
@@ -265,7 +267,8 @@
     protected boolean mHasSecureLockScreen;
 
     protected IGateKeeperService mGateKeeperService;
-    protected IAuthSecret mAuthSecretService;
+    protected IAuthSecret mAuthSecretServiceAidl;
+    protected android.hardware.authsecret.V1_0.IAuthSecret mAuthSecretServiceHidl;
 
     private static final String GSI_RUNNING_PROP = "ro.gsid.image_running";
 
@@ -833,12 +836,19 @@
     }
 
     private void getAuthSecretHal() {
-        try {
-            mAuthSecretService = IAuthSecret.getService(/* retry */ true);
-        } catch (NoSuchElementException e) {
-            Slog.i(TAG, "Device doesn't implement AuthSecret HAL");
-        } catch (RemoteException e) {
-            Slog.w(TAG, "Failed to get AuthSecret HAL", e);
+        mAuthSecretServiceAidl = IAuthSecret.Stub.asInterface(ServiceManager.
+                                 waitForDeclaredService(IAuthSecret.DESCRIPTOR + "/default"));
+        if (mAuthSecretServiceAidl == null) {
+            Slog.i(TAG, "Device doesn't implement AuthSecret HAL(aidl), try to get hidl version");
+
+            try {
+                mAuthSecretServiceHidl =
+                    android.hardware.authsecret.V1_0.IAuthSecret.getService(/* retry */ true);
+            } catch (NoSuchElementException e) {
+                Slog.i(TAG, "Device doesn't implement AuthSecret HAL(hidl)");
+            } catch (RemoteException e) {
+                Slog.w(TAG, "Failed to get AuthSecret HAL(hidl)", e);
+            }
         }
     }
 
@@ -935,7 +945,7 @@
                     if (!isSyntheticPasswordBasedCredentialLocked(userId)) {
                         Slogf.i(TAG, "Creating locksettings state for user %d now that boot "
                                 + "is complete", userId);
-                        initializeSyntheticPasswordLocked(userId);
+                        initializeSyntheticPassword(userId);
                     }
                 }
             }
@@ -974,7 +984,7 @@
         long protectorId = getCurrentLskfBasedProtectorId(userId);
         if (protectorId == SyntheticPasswordManager.NULL_PROTECTOR_ID) {
             Slogf.i(TAG, "Migrating unsecured user %d to SP-based credential", userId);
-            initializeSyntheticPasswordLocked(userId);
+            initializeSyntheticPassword(userId);
         } else {
             Slogf.i(TAG, "Existing unsecured user %d has a synthetic password; re-encrypting CE " +
                     "key with it", userId);
@@ -1016,11 +1026,18 @@
     }
 
     private void enforceFrpResolved() {
+        final int mainUserId = mInjector.getUserManagerInternal().getMainUserId();
+        if (mainUserId < 0) {
+            Slog.i(TAG, "No Main user on device; skip enforceFrpResolved");
+            return;
+        }
         final ContentResolver cr = mContext.getContentResolver();
+
         final boolean inSetupWizard = Settings.Secure.getIntForUser(cr,
-                Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_SYSTEM) == 0;
-        final boolean secureFrp = Settings.Secure.getIntForUser(cr,
-                Settings.Secure.SECURE_FRP_MODE, 0, UserHandle.USER_SYSTEM) == 1;
+                Settings.Secure.USER_SETUP_COMPLETE, 0, mainUserId) == 0;
+        final boolean secureFrp = Settings.Global.getInt(cr,
+                Settings.Global.SECURE_FRP_MODE, 0) == 1;
+
         if (inSetupWizard && secureFrp) {
             throw new SecurityException("Cannot change credential in SUW while factory reset"
                     + " protection is not resolved yet");
@@ -1634,13 +1651,7 @@
         Objects.requireNonNull(savedCredential);
         if (DEBUG) Slog.d(TAG, "setLockCredentialInternal: user=" + userId);
         synchronized (mSpManager) {
-            if (!isSyntheticPasswordBasedCredentialLocked(userId)) {
-                if (!savedCredential.isNone()) {
-                    throw new IllegalStateException("Saved credential given, but user has no SP");
-                }
-                // TODO(b/232452368): this case is only needed by unit tests now; remove it.
-                initializeSyntheticPasswordLocked(userId);
-            } else if (savedCredential.isNone() && isProfileWithUnifiedLock(userId)) {
+            if (savedCredential.isNone() && isProfileWithUnifiedLock(userId)) {
                 // get credential from keystore when profile has unified lock
                 try {
                     //TODO: remove as part of b/80170828
@@ -2304,9 +2315,7 @@
                 return;
             }
             removeStateForReusedUserIdIfNecessary(userId, userSerialNumber);
-            synchronized (mSpManager) {
-                initializeSyntheticPasswordLocked(userId);
-            }
+            initializeSyntheticPassword(userId);
         }
     }
 
@@ -2601,17 +2610,25 @@
         // If the given user is the primary user, pass the auth secret to the HAL.  Only the system
         // user can be primary.  Check for the system user ID before calling getUserInfo(), as other
         // users may still be under construction.
-        if (mAuthSecretService != null && userId == UserHandle.USER_SYSTEM &&
+        if (userId == UserHandle.USER_SYSTEM &&
                 mUserManager.getUserInfo(userId).isPrimary()) {
-            try {
-                final byte[] rawSecret = sp.deriveVendorAuthSecret();
-                final ArrayList<Byte> secret = new ArrayList<>(rawSecret.length);
-                for (int i = 0; i < rawSecret.length; ++i) {
-                    secret.add(rawSecret[i]);
+            final byte[] rawSecret = sp.deriveVendorAuthSecret();
+            if (mAuthSecretServiceAidl != null) {
+                try {
+                    mAuthSecretServiceAidl.setPrimaryUserCredential(rawSecret);
+                } catch (RemoteException e) {
+                    Slog.w(TAG, "Failed to pass primary user secret to AuthSecret HAL(aidl)", e);
                 }
-                mAuthSecretService.primaryUserCredential(secret);
-            } catch (RemoteException e) {
-                Slog.w(TAG, "Failed to pass primary user secret to AuthSecret HAL", e);
+            } else if (mAuthSecretServiceHidl != null) {
+                try {
+                    final ArrayList<Byte> secret = new ArrayList<>(rawSecret.length);
+                    for (int i = 0; i < rawSecret.length; ++i) {
+                        secret.add(rawSecret[i]);
+                    }
+                    mAuthSecretServiceHidl.primaryUserCredential(secret);
+                } catch (RemoteException e) {
+                    Slog.w(TAG, "Failed to pass primary user secret to AuthSecret HAL(hidl)", e);
+                }
             }
         }
     }
@@ -2624,21 +2641,22 @@
      * until the time when Weaver is guaranteed to be available), or when upgrading from Android 13
      * or earlier where users with no LSKF didn't necessarily have an SP.
      */
-    @GuardedBy("mSpManager")
     @VisibleForTesting
-    SyntheticPassword initializeSyntheticPasswordLocked(int userId) {
-        Slog.i(TAG, "Initialize SyntheticPassword for user: " + userId);
-        Preconditions.checkState(getCurrentLskfBasedProtectorId(userId) ==
-                SyntheticPasswordManager.NULL_PROTECTOR_ID,
-                "Cannot reinitialize SP");
+    SyntheticPassword initializeSyntheticPassword(int userId) {
+        synchronized (mSpManager) {
+            Slog.i(TAG, "Initialize SyntheticPassword for user: " + userId);
+            Preconditions.checkState(getCurrentLskfBasedProtectorId(userId) ==
+                    SyntheticPasswordManager.NULL_PROTECTOR_ID,
+                    "Cannot reinitialize SP");
 
-        final SyntheticPassword sp = mSpManager.newSyntheticPassword(userId);
-        final long protectorId = mSpManager.createLskfBasedProtector(getGateKeeperService(),
-                LockscreenCredential.createNone(), sp, userId);
-        setCurrentLskfBasedProtectorId(protectorId, userId);
-        setUserKeyProtection(userId, sp.deriveFileBasedEncryptionKey());
-        onSyntheticPasswordKnown(userId, sp);
-        return sp;
+            final SyntheticPassword sp = mSpManager.newSyntheticPassword(userId);
+            final long protectorId = mSpManager.createLskfBasedProtector(getGateKeeperService(),
+                    LockscreenCredential.createNone(), sp, userId);
+            setCurrentLskfBasedProtectorId(protectorId, userId);
+            setUserKeyProtection(userId, sp.deriveFileBasedEncryptionKey());
+            onSyntheticPasswordKnown(userId, sp);
+            return sp;
+        }
     }
 
     @VisibleForTesting
@@ -2654,13 +2672,6 @@
         setLong(LSKF_LAST_CHANGED_TIME_KEY, System.currentTimeMillis(), userId);
     }
 
-    @VisibleForTesting
-    boolean isSyntheticPasswordBasedCredential(int userId) {
-        synchronized (mSpManager) {
-            return isSyntheticPasswordBasedCredentialLocked(userId);
-        }
-    }
-
     private boolean isSyntheticPasswordBasedCredentialLocked(int userId) {
         if (userId == USER_FRP) {
             final int type = mStorage.readPersistentDataBlock().type;
@@ -2899,19 +2910,14 @@
             @NonNull EscrowTokenStateChangeCallback callback) {
         if (DEBUG) Slog.d(TAG, "addEscrowToken: user=" + userId + ", type=" + type);
         synchronized (mSpManager) {
-            // If the user has no LSKF, then the token can be activated immediately, after creating
-            // the user's SP if it doesn't already exist.  Otherwise, the token can't be activated
-            // until the SP is unlocked by another protector (normally the LSKF-based one).
+            // If the user has no LSKF, then the token can be activated immediately.  Otherwise, the
+            // token can't be activated until the SP is unlocked by another protector (normally the
+            // LSKF-based one).
             SyntheticPassword sp = null;
             if (!isUserSecure(userId)) {
                 long protectorId = getCurrentLskfBasedProtectorId(userId);
-                if (protectorId == SyntheticPasswordManager.NULL_PROTECTOR_ID) {
-                    // TODO(b/232452368): this case is only needed by unit tests now; remove it.
-                    sp = initializeSyntheticPasswordLocked(userId);
-                } else {
-                    sp = mSpManager.unlockLskfBasedProtector(getGateKeeperService(), protectorId,
-                            LockscreenCredential.createNone(), userId, null).syntheticPassword;
-                }
+                sp = mSpManager.unlockLskfBasedProtector(getGateKeeperService(), protectorId,
+                        LockscreenCredential.createNone(), userId, null).syntheticPassword;
             }
             disableEscrowTokenOnNonManagedDevicesIfNeeded(userId);
             if (!mSpManager.hasEscrowData(userId)) {
@@ -3167,18 +3173,34 @@
      * if we are running an automotive build.
      */
     private void disableEscrowTokenOnNonManagedDevicesIfNeeded(int userId) {
-        final UserManagerInternal userManagerInternal = mInjector.getUserManagerInternal();
+        // TODO(b/258213147): Remove
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER,
+                    DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_FLAG,
+                    DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_DEFAULT)) {
 
-        // Managed profile should have escrow enabled
-        if (userManagerInternal.isUserManaged(userId)) {
-            Slog.i(TAG, "Managed profile can have escrow token");
-            return;
-        }
+                if (mInjector.getDeviceStateCache().isUserOrganizationManaged(userId)) {
+                    Slog.i(TAG, "Organization managed users can have escrow token");
+                    return;
+                }
+            } else {
+                final UserManagerInternal userManagerInternal = mInjector.getUserManagerInternal();
 
-        // Devices with Device Owner should have escrow enabled on all users.
-        if (userManagerInternal.isDeviceManaged()) {
-            Slog.i(TAG, "Corp-owned device can have escrow token");
-            return;
+                // Managed profile should have escrow enabled
+                if (userManagerInternal.isUserManaged(userId)) {
+                    Slog.i(TAG, "Managed profile can have escrow token");
+                    return;
+                }
+
+                // Devices with Device Owner should have escrow enabled on all users.
+                if (userManagerInternal.isDeviceManaged()) {
+                    Slog.i(TAG, "Corp-owned device can have escrow token");
+                    return;
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
 
         // If the device is yet to be provisioned (still in SUW), there is still
diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java
index d08150c..e51ed1b 100644
--- a/services/core/java/com/android/server/media/MediaSessionService.java
+++ b/services/core/java/com/android/server/media/MediaSessionService.java
@@ -2046,6 +2046,11 @@
                 int controllerUid) {
             final int uid = Binder.getCallingUid();
             final int userId = UserHandle.getUserHandleForUid(uid).getIdentifier();
+            if (LocalServices.getService(PackageManagerInternal.class)
+                    .filterAppAccess(controllerPackageName, uid, userId)) {
+                // The controllerPackageName is not visible to the caller.
+                return false;
+            }
             final long token = Binder.clearCallingIdentity();
             try {
                 // Don't perform check between controllerPackageName and controllerUid.
diff --git a/services/core/java/com/android/server/media/projection/MediaProjectionManagerService.java b/services/core/java/com/android/server/media/projection/MediaProjectionManagerService.java
index ed8d852..50e1fca 100644
--- a/services/core/java/com/android/server/media/projection/MediaProjectionManagerService.java
+++ b/services/core/java/com/android/server/media/projection/MediaProjectionManagerService.java
@@ -315,7 +315,7 @@
         @Override // Binder call
         public boolean isValidMediaProjection(IMediaProjection projection) {
             return MediaProjectionManagerService.this.isValidMediaProjection(
-                    projection.asBinder());
+                    projection == null ? null : projection.asBinder());
         }
 
         @Override // Binder call
@@ -348,7 +348,26 @@
             } finally {
                 Binder.restoreCallingIdentity(token);
             }
+        }
 
+        @Override // Binder call
+        public void notifyActiveProjectionCapturedContentResized(int width, int height) {
+            if (mContext.checkCallingOrSelfPermission(Manifest.permission.MANAGE_MEDIA_PROJECTION)
+                    != PackageManager.PERMISSION_GRANTED) {
+                throw new SecurityException("Requires MANAGE_MEDIA_PROJECTION in order to notify "
+                        + "on captured content resize");
+            }
+            if (!isValidMediaProjection(mProjectionGrant)) {
+                return;
+            }
+            final long token = Binder.clearCallingIdentity();
+            try {
+                if (mProjectionGrant != null && mCallbackDelegate != null) {
+                    mCallbackDelegate.dispatchResize(mProjectionGrant, width, height);
+                }
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
         }
 
         @Override //Binder call
@@ -659,9 +678,11 @@
 
     private static class CallbackDelegate {
         private Map<IBinder, IMediaProjectionCallback> mClientCallbacks;
+        // Map from the IBinder token representing the callback, to the callback instance.
+        // Represents the callbacks registered on the client's MediaProjectionManager.
         private Map<IBinder, IMediaProjectionWatcherCallback> mWatcherCallbacks;
         private Handler mHandler;
-        private Object mLock = new Object();
+        private final Object mLock = new Object();
 
         public CallbackDelegate() {
             mHandler = new Handler(Looper.getMainLooper(), null, true /*async*/);
@@ -715,6 +736,8 @@
             }
             synchronized (mLock) {
                 for (IMediaProjectionCallback callback : mClientCallbacks.values()) {
+                    // Notify every callback the client has registered for a particular
+                    // MediaProjection instance.
                     mHandler.post(new ClientStopCallback(callback));
                 }
 
@@ -724,6 +747,33 @@
                 }
             }
         }
+
+        public void dispatchResize(MediaProjection projection, int width, int height) {
+            if (projection == null) {
+                Slog.e(TAG, "Tried to dispatch stop notification for a null media projection."
+                        + " Ignoring!");
+                return;
+            }
+            synchronized (mLock) {
+                // TODO(b/249827847) Currently the service assumes there is only one projection
+                //  at once - need to find the callback for the given projection, when there are
+                //  multiple sessions.
+                for (IMediaProjectionCallback callback : mClientCallbacks.values()) {
+                    mHandler.post(() -> {
+                        try {
+                            // Notify every callback the client has registered for a particular
+                            // MediaProjection instance.
+                            callback.onCapturedContentResize(width, height);
+                        } catch (RemoteException e) {
+                            Slog.w(TAG, "Failed to notify media projection has resized to " + width
+                                    + " x " + height, e);
+                        }
+                    });
+                }
+                // Do not need to notify watcher callback about resize, since watcher callback
+                // is for passing along if recording is still ongoing or not.
+            }
+        }
     }
 
     private static final class WatcherStartCallback implements Runnable {
diff --git a/services/core/java/com/android/server/media/projection/OWNERS b/services/core/java/com/android/server/media/projection/OWNERS
index 9ca3910..832bcd9 100644
--- a/services/core/java/com/android/server/media/projection/OWNERS
+++ b/services/core/java/com/android/server/media/projection/OWNERS
@@ -1,2 +1 @@
-michaelwr@google.com
-santoscordon@google.com
+include /media/java/android/media/projection/OWNERS
diff --git a/services/core/java/com/android/server/notification/NotificationRecordLogger.java b/services/core/java/com/android/server/notification/NotificationRecordLogger.java
index ef1e11c..4031c83 100644
--- a/services/core/java/com/android/server/notification/NotificationRecordLogger.java
+++ b/services/core/java/com/android/server/notification/NotificationRecordLogger.java
@@ -18,8 +18,8 @@
 
 import static android.service.notification.NotificationListenerService.REASON_ASSISTANT_CANCEL;
 import static android.service.notification.NotificationListenerService.REASON_CANCEL;
+import static android.service.notification.NotificationListenerService.REASON_CLEAR_DATA;
 import static android.service.notification.NotificationListenerService.REASON_CLICK;
-import static android.service.notification.NotificationListenerService.REASON_TIMEOUT;
 
 import android.annotation.NonNull;
 import android.annotation.Nullable;
@@ -172,7 +172,12 @@
         NOTIFICATION_CANCEL_SNOOZED(181),
         @UiEvent(doc = "Notification was canceled due to timeout")
         NOTIFICATION_CANCEL_TIMEOUT(182),
-        // Values 183-189 reserved for future system dismissal reasons
+        @UiEvent(doc = "Notification was canceled due to the backing channel being deleted")
+        NOTIFICATION_CANCEL_CHANNEL_REMOVED(1261),
+        @UiEvent(doc = "Notification was canceled due to the app's storage being cleared")
+        NOTIFICATION_CANCEL_CLEAR_DATA(1262),
+        // Values above this line must remain in the same order as the corresponding
+        // NotificationCancelReason enum values.
         @UiEvent(doc = "Notification was canceled due to user dismissal of a peeking notification.")
         NOTIFICATION_CANCEL_USER_PEEK(190),
         @UiEvent(doc = "Notification was canceled due to user dismissal from the always-on display")
@@ -208,7 +213,7 @@
             // Most cancel reasons do not have a meaningful surface. Reason codes map directly
             // to NotificationCancelledEvent codes.
             if (surface == NotificationStats.DISMISSAL_OTHER) {
-                if ((REASON_CLICK <= reason) && (reason <= REASON_TIMEOUT)) {
+                if ((REASON_CLICK <= reason) && (reason <= REASON_CLEAR_DATA)) {
                     return NotificationCancelledEvent.values()[reason];
                 }
                 if (reason == REASON_ASSISTANT_CANCEL) {
diff --git a/services/core/java/com/android/server/pm/AppStateHelper.java b/services/core/java/com/android/server/pm/AppStateHelper.java
index 9ea350f..e6e8212a 100644
--- a/services/core/java/com/android/server/pm/AppStateHelper.java
+++ b/services/core/java/com/android/server/pm/AppStateHelper.java
@@ -16,15 +16,22 @@
 
 package com.android.server.pm;
 
+import static android.media.AudioAttributes.USAGE_VOICE_COMMUNICATION;
+import static android.media.AudioAttributes.USAGE_VOICE_COMMUNICATION_SIGNALLING;
+
 import android.app.ActivityManager;
 import android.app.ActivityManager.RunningAppProcessInfo;
+import android.app.ActivityManagerInternal;
 import android.content.Context;
+import android.media.AudioManager;
 import android.media.IAudioService;
 import android.os.ServiceManager;
+import android.telecom.TelecomManager;
 import android.text.TextUtils;
 import android.util.ArraySet;
 
 import com.android.internal.util.ArrayUtils;
+import com.android.server.LocalServices;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -72,6 +79,43 @@
     }
 
     /**
+     * True if any app is using voice communication.
+     */
+    private boolean hasVoiceCall() {
+        var am = mContext.getSystemService(AudioManager.class);
+        try {
+            for (var apc : am.getActivePlaybackConfigurations()) {
+                if (!apc.isActive()) {
+                    continue;
+                }
+                var usage = apc.getAudioAttributes().getUsage();
+                if (usage == USAGE_VOICE_COMMUNICATION
+                        || usage == USAGE_VOICE_COMMUNICATION_SIGNALLING) {
+                    return true;
+                }
+            }
+        } catch (Exception ignore) {
+        }
+        return false;
+    }
+
+    /**
+     * True if the app is recording audio.
+     */
+    private boolean isRecordingAudio(String packageName) {
+        var am = mContext.getSystemService(AudioManager.class);
+        try {
+            for (var arc : am.getActiveRecordingConfigurations()) {
+                if (TextUtils.equals(arc.getClientPackageName(), packageName)) {
+                    return true;
+                }
+            }
+        } catch (Exception ignore) {
+        }
+        return false;
+    }
+
+    /**
      * True if the app is in the foreground.
      */
     private boolean isAppForeground(String packageName) {
@@ -89,8 +133,7 @@
      * True if the app is playing/recording audio.
      */
     private boolean hasActiveAudio(String packageName) {
-        // TODO(b/235306967): also check recording
-        return hasAudioFocus(packageName);
+        return hasAudioFocus(packageName) || isRecordingAudio(packageName);
     }
 
     /**
@@ -143,16 +186,16 @@
      * True if there is an ongoing phone call.
      */
     public boolean isInCall() {
-        // To be implemented
-        return false;
+        // TelecomManager doesn't handle the case where some apps don't implement ConnectionService.
+        // We check apps using voice communication to detect if the device is in call.
+        var tm = mContext.getSystemService(TelecomManager.class);
+        return tm.isInCall() || hasVoiceCall();
     }
 
     /**
      * Returns a list of packages which depend on {@code packageNames}. These are the packages
      * that will be affected when updating {@code packageNames} and should participate in
      * the evaluation of install constraints.
-     *
-     * TODO(b/235306967): Also include bounded services as dependency.
      */
     public List<String> getDependencyPackages(List<String> packageNames) {
         var results = new ArraySet<String>();
@@ -167,6 +210,10 @@
                 }
             }
         }
+        var amInternal = LocalServices.getService(ActivityManagerInternal.class);
+        for (var packageName : packageNames) {
+            results.addAll(amInternal.getClientPackages(packageName));
+        }
         return new ArrayList<>(results);
     }
 }
diff --git a/services/core/java/com/android/server/pm/BackgroundInstallControlService.java b/services/core/java/com/android/server/pm/BackgroundInstallControlService.java
index df95f86..d4c4c69 100644
--- a/services/core/java/com/android/server/pm/BackgroundInstallControlService.java
+++ b/services/core/java/com/android/server/pm/BackgroundInstallControlService.java
@@ -17,19 +17,46 @@
 package com.android.server.pm;
 
 import android.annotation.NonNull;
+import android.app.usage.UsageEvents;
+import android.app.usage.UsageStatsManagerInternal;
 import android.content.Context;
+import android.content.pm.ApplicationInfo;
 import android.content.pm.IBackgroundInstallControlService;
 import android.content.pm.IPackageManager;
+import android.content.pm.InstallSourceInfo;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
+import android.content.pm.PackageManagerInternal;
 import android.content.pm.ParceledListSlice;
-import android.os.IBinder;
+import android.os.Environment;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
 import android.os.RemoteException;
 import android.os.ServiceManager;
+import android.os.SystemClock;
+import android.os.UserHandle;
+import android.util.ArraySet;
+import android.util.AtomicFile;
+import android.util.Slog;
 import android.util.SparseArrayMap;
+import android.util.SparseSetArray;
+import android.util.proto.ProtoInputStream;
+import android.util.proto.ProtoOutputStream;
 
 import com.android.internal.annotations.VisibleForTesting;
+import com.android.server.LocalServices;
+import com.android.server.ServiceThread;
 import com.android.server.SystemService;
+import com.android.server.pm.permission.PermissionManagerServiceInternal;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ListIterator;
+import java.util.Set;
+import java.util.TreeSet;
 
 /**
  * @hide
@@ -37,14 +64,30 @@
 public class BackgroundInstallControlService extends SystemService {
     private static final String TAG = "BackgroundInstallControlService";
 
+    private static final String DISK_FILE_NAME = "states";
+    private static final String DISK_DIR_NAME = "bic";
+
+    private static final int MAX_FOREGROUND_TIME_FRAMES_SIZE = 10;
+
+    private static final int MSG_USAGE_EVENT_RECEIVED = 0;
+    private static final int MSG_PACKAGE_ADDED = 1;
+    private static final int MSG_PACKAGE_REMOVED = 2;
+
     private final Context mContext;
     private final BinderService mBinderService;
     private final IPackageManager mIPackageManager;
+    private final PackageManagerInternal mPackageManagerInternal;
+    private final UsageStatsManagerInternal mUsageStatsManagerInternal;
+    private final PermissionManagerServiceInternal mPermissionManager;
+    private final Handler mHandler;
+    private final File mDiskFile;
 
-    // User ID -> package name -> time diff
-    // The time diff between the last foreground activity installer and
-    // the "onPackageAdded" function call.
-    private final SparseArrayMap<String, Long> mBackgroundInstalledPackages =
+
+    private SparseSetArray<String> mBackgroundInstalledPackages = null;
+
+    // User ID -> package name -> set of foreground time frame
+    private final SparseArrayMap<String,
+            TreeSet<ForegroundTimeFrame>> mInstallerForegroundTimeFrames =
             new SparseArrayMap<>();
 
     public BackgroundInstallControlService(@NonNull Context context) {
@@ -56,49 +99,385 @@
         super(injector.getContext());
         mContext = injector.getContext();
         mIPackageManager = injector.getIPackageManager();
+        mPackageManagerInternal = injector.getPackageManagerInternal();
+        mPermissionManager = injector.getPermissionManager();
+        mHandler = new EventHandler(injector.getLooper(), this);
+        mDiskFile = injector.getDiskFile();
+        mUsageStatsManagerInternal = injector.getUsageStatsManagerInternal();
+        mUsageStatsManagerInternal.registerListener(
+                (userId, event) ->
+                        mHandler.obtainMessage(MSG_USAGE_EVENT_RECEIVED,
+                                userId,
+                                0,
+                                event).sendToTarget()
+        );
         mBinderService = new BinderService(this);
     }
 
     private static final class BinderService extends IBackgroundInstallControlService.Stub {
         final BackgroundInstallControlService mService;
 
-        BinderService(BackgroundInstallControlService service)  {
+        BinderService(BackgroundInstallControlService service) {
             mService = service;
         }
 
         @Override
         public ParceledListSlice<PackageInfo> getBackgroundInstalledPackages(
                 @PackageManager.PackageInfoFlagsBits long flags, int userId) {
-            ParceledListSlice<PackageInfo> packages;
-            try {
-                packages = mService.mIPackageManager.getInstalledPackages(flags, userId);
-            } catch (RemoteException e) {
-                throw new IllegalStateException("Package manager not available", e);
-            }
-
-            // TODO(b/244216300): to enable the test the usage by BinaryTransparencyService,
-            // we currently comment out the actual implementation.
-            // The fake implementation is just to filter out the first app of the list.
-            // for (int i = 0, size = packages.getList().size(); i < size; i++) {
-            //     String packageName = packages.getList().get(i).packageName;
-            //     if (!mBackgroundInstalledPackages.contains(userId, packageName) {
-            //         packages.getList().remove(i);
-            //     }
-            // }
-            if (packages.getList().size() > 0) {
-                packages.getList().remove(0);
-            }
-            return packages;
+            return mService.getBackgroundInstalledPackages(flags, userId);
         }
     }
 
-    /**
-     * Called when the system service should publish a binder service using
-     * {@link #publishBinderService(String, IBinder).}
-     */
+    @VisibleForTesting
+    ParceledListSlice<PackageInfo> getBackgroundInstalledPackages(
+            @PackageManager.PackageInfoFlagsBits long flags, int userId) {
+        ParceledListSlice<PackageInfo> packages;
+        try {
+            packages = mIPackageManager.getInstalledPackages(flags, userId);
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+
+        initBackgroundInstalledPackages();
+
+        ListIterator<PackageInfo> iter = packages.getList().listIterator();
+        while (iter.hasNext()) {
+            String packageName = iter.next().packageName;
+            if (!mBackgroundInstalledPackages.contains(userId, packageName)) {
+                iter.remove();
+            }
+        }
+
+        return packages;
+    }
+
+    private static class EventHandler extends Handler {
+        private final BackgroundInstallControlService mService;
+
+        EventHandler(Looper looper, BackgroundInstallControlService service) {
+            super(looper);
+            mService = service;
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case MSG_USAGE_EVENT_RECEIVED: {
+                    mService.handleUsageEvent((UsageEvents.Event) msg.obj, msg.arg1 /* userId */);
+                    break;
+                }
+                case MSG_PACKAGE_ADDED: {
+                    mService.handlePackageAdd((String) msg.obj, msg.arg1 /* userId */);
+                    break;
+                }
+                case MSG_PACKAGE_REMOVED: {
+                    mService.handlePackageRemove((String) msg.obj, msg.arg1 /* userId */);
+                    break;
+                }
+                default:
+                    Slog.w(TAG, "Unknown message: " + msg.what);
+            }
+        }
+    }
+
+    void handlePackageAdd(String packageName, int userId) {
+        InstallSourceInfo installSourceInfo = null;
+        try {
+            installSourceInfo = mIPackageManager.getInstallSourceInfo(packageName);
+        } catch (RemoteException e) {
+            // Failed to talk to PackageManagerService Should never happen!
+            throw e.rethrowFromSystemServer();
+        }
+        String installerPackageName =
+                installSourceInfo == null ? null : installSourceInfo.getInstallingPackageName();
+        if (installerPackageName == null) {
+            Slog.w(TAG, "fails to get installerPackageName for " + packageName);
+            return;
+        }
+
+        ApplicationInfo appInfo = null;
+        try {
+            appInfo = mIPackageManager.getApplicationInfo(packageName,
+                    0, userId);
+        } catch (RemoteException e) {
+            // Failed to talk to PackageManagerService Should never happen!
+            throw e.rethrowFromSystemServer();
+        }
+
+        if (appInfo == null) {
+            Slog.w(TAG, "fails to get appInfo for " + packageName);
+            return;
+        }
+
+        // convert up-time to current time.
+        final long installTimestamp = System.currentTimeMillis()
+                - (SystemClock.uptimeMillis() - appInfo.createTimestamp);
+
+        if (wasForegroundInstallation(installerPackageName, userId, installTimestamp)) {
+            return;
+        }
+
+        initBackgroundInstalledPackages();
+        mBackgroundInstalledPackages.add(userId, packageName);
+        writeBackgroundInstalledPackagesToDisk();
+    }
+
+    private boolean wasForegroundInstallation(String installerPackageName,
+            int userId, long installTimestamp) {
+        TreeSet<BackgroundInstallControlService.ForegroundTimeFrame> foregroundTimeFrames =
+                mInstallerForegroundTimeFrames.get(userId, installerPackageName);
+
+        // The installer never run in foreground.
+        if (foregroundTimeFrames == null) {
+            return false;
+        }
+
+        for (var foregroundTimeFrame : foregroundTimeFrames) {
+            // the foreground time frame starts later than the installation.
+            // so the installation is outside the foreground time frame.
+            if (foregroundTimeFrame.startTimeStampMillis > installTimestamp) {
+                continue;
+            }
+
+            // the foreground time frame is not over yet.
+            // the installation is inside the foreground time frame.
+            if (!foregroundTimeFrame.isDone()) {
+                return true;
+            }
+
+            // the foreground time frame ends later than the installation.
+            // the installation is inside the foreground time frame.
+            if (installTimestamp <= foregroundTimeFrame.endTimeStampMillis) {
+                return true;
+            }
+        }
+
+        // the installation is not inside any of foreground time frames.
+        // so it is not a foreground installation.
+        return false;
+    }
+
+    void handlePackageRemove(String packageName, int userId) {
+        initBackgroundInstalledPackages();
+        mBackgroundInstalledPackages.remove(userId, packageName);
+        writeBackgroundInstalledPackagesToDisk();
+    }
+
+    void handleUsageEvent(UsageEvents.Event event, int userId) {
+        if (event.mEventType != UsageEvents.Event.ACTIVITY_RESUMED
+                && event.mEventType != UsageEvents.Event.ACTIVITY_PAUSED
+                && event.mEventType != UsageEvents.Event.ACTIVITY_STOPPED) {
+            return;
+        }
+
+        if (!isInstaller(event.mPackage, userId)) {
+            return;
+        }
+
+        if (!mInstallerForegroundTimeFrames.contains(userId, event.mPackage)) {
+            mInstallerForegroundTimeFrames.add(userId, event.mPackage, new TreeSet<>());
+        }
+
+        TreeSet<BackgroundInstallControlService.ForegroundTimeFrame> foregroundTimeFrames =
+                mInstallerForegroundTimeFrames.get(userId, event.mPackage);
+
+        if ((foregroundTimeFrames.size() == 0) || foregroundTimeFrames.last().isDone()) {
+            // ignore the other events if there is no open ForegroundTimeFrame.
+            if (event.mEventType != UsageEvents.Event.ACTIVITY_RESUMED) {
+                return;
+            }
+            foregroundTimeFrames.add(new ForegroundTimeFrame(event.mTimeStamp));
+        }
+
+        foregroundTimeFrames.last().addEvent(event);
+
+        if (foregroundTimeFrames.size() > MAX_FOREGROUND_TIME_FRAMES_SIZE) {
+            foregroundTimeFrames.pollFirst();
+        }
+    }
+
+    @VisibleForTesting
+    void writeBackgroundInstalledPackagesToDisk() {
+        AtomicFile atomicFile = new AtomicFile(mDiskFile);
+        FileOutputStream fileOutputStream;
+        try {
+            fileOutputStream = atomicFile.startWrite();
+        } catch (IOException e) {
+            Slog.e(TAG, "Failed to start write to states protobuf.", e);
+            return;
+        }
+
+        try {
+            ProtoOutputStream protoOutputStream = new ProtoOutputStream(fileOutputStream);
+            for (int i = 0; i < mBackgroundInstalledPackages.size(); i++) {
+                int userId = mBackgroundInstalledPackages.keyAt(i);
+                for (String packageName : mBackgroundInstalledPackages.get(userId)) {
+                    long token = protoOutputStream.start(
+                            BackgroundInstalledPackagesProto.BG_INSTALLED_PKG);
+                    protoOutputStream.write(
+                            BackgroundInstalledPackageProto.PACKAGE_NAME, packageName);
+                    protoOutputStream.write(
+                            BackgroundInstalledPackageProto.USER_ID, userId + 1);
+                    protoOutputStream.end(token);
+                }
+            }
+            protoOutputStream.flush();
+            atomicFile.finishWrite(fileOutputStream);
+        } catch (Exception e) {
+            Slog.e(TAG, "Failed to finish write to states protobuf.", e);
+            atomicFile.failWrite(fileOutputStream);
+        }
+    }
+
+    @VisibleForTesting
+    void initBackgroundInstalledPackages() {
+        if (mBackgroundInstalledPackages != null) {
+            return;
+        }
+
+        mBackgroundInstalledPackages = new SparseSetArray<>();
+
+        if (!mDiskFile.exists()) {
+            return;
+        }
+
+        AtomicFile atomicFile = new AtomicFile(mDiskFile);
+        try (FileInputStream fileInputStream = atomicFile.openRead()) {
+            ProtoInputStream protoInputStream = new ProtoInputStream(fileInputStream);
+
+            while (protoInputStream.nextField() != ProtoInputStream.NO_MORE_FIELDS) {
+                if (protoInputStream.getFieldNumber()
+                        != (int) BackgroundInstalledPackagesProto.BG_INSTALLED_PKG) {
+                    continue;
+                }
+                long token = protoInputStream.start(
+                        BackgroundInstalledPackagesProto.BG_INSTALLED_PKG);
+                String packageName = null;
+                int userId = UserHandle.USER_NULL;
+                while (protoInputStream.nextField() != ProtoInputStream.NO_MORE_FIELDS) {
+                    switch (protoInputStream.getFieldNumber()) {
+                        case (int) BackgroundInstalledPackageProto.PACKAGE_NAME:
+                            packageName = protoInputStream.readString(
+                                    BackgroundInstalledPackageProto.PACKAGE_NAME);
+                            break;
+                        case (int) BackgroundInstalledPackageProto.USER_ID:
+                            userId = protoInputStream.readInt(
+                                    BackgroundInstalledPackageProto.USER_ID) - 1;
+                            break;
+                        default:
+                            Slog.w(TAG, "Undefined field in proto: "
+                                    + protoInputStream.getFieldNumber());
+                    }
+                }
+                protoInputStream.end(token);
+                if (packageName != null && userId != UserHandle.USER_NULL) {
+                    mBackgroundInstalledPackages.add(userId, packageName);
+                } else {
+                    Slog.w(TAG, "Fails to get packageName or UserId from proto file");
+                }
+            }
+        } catch (IOException e) {
+            Slog.w(TAG, "Error reading state from the disk", e);
+        }
+    }
+
+    @VisibleForTesting
+    SparseSetArray<String> getBackgroundInstalledPackages() {
+        return mBackgroundInstalledPackages;
+    }
+
+    @VisibleForTesting
+    SparseArrayMap<String, TreeSet<ForegroundTimeFrame>> getInstallerForegroundTimeFrames() {
+        return mInstallerForegroundTimeFrames;
+    }
+
+    private boolean isInstaller(String pkgName, int userId) {
+        if (mInstallerForegroundTimeFrames.contains(userId, pkgName)) {
+            return true;
+        }
+        return mPermissionManager.checkPermission(pkgName,
+                android.Manifest.permission.INSTALL_PACKAGES,
+                userId) == PackageManager.PERMISSION_GRANTED;
+    }
+
     @Override
     public void onStart() {
-        publishBinderService(Context.BACKGROUND_INSTALL_CONTROL_SERVICE, mBinderService);
+        onStart(/* isForTesting= */ false);
+    }
+
+    @VisibleForTesting
+    void onStart(boolean isForTesting) {
+        if (!isForTesting) {
+            publishBinderService(Context.BACKGROUND_INSTALL_CONTROL_SERVICE, mBinderService);
+        }
+
+        mPackageManagerInternal.getPackageList(new PackageManagerInternal.PackageListObserver() {
+            @Override
+            public void onPackageAdded(String packageName, int uid) {
+                final int userId = UserHandle.getUserId(uid);
+                mHandler.obtainMessage(MSG_PACKAGE_ADDED,
+                        userId, 0, packageName).sendToTarget();
+            }
+
+            @Override
+            public void onPackageRemoved(String packageName, int uid) {
+                final int userId = UserHandle.getUserId(uid);
+                mHandler.obtainMessage(MSG_PACKAGE_REMOVED,
+                        userId, 0, packageName).sendToTarget();
+            }
+        });
+    }
+
+    // The foreground time frame (ForegroundTimeFrame) represents the period
+    // when a package's activities continuously occupy the foreground.
+    // Each ForegroundTimeFrame starts with an ACTIVITY_RESUMED event,
+    // and then ends with an ACTIVITY_PAUSED or ACTIVITY_STOPPED event.
+    // The startTimeStampMillis stores the timestamp of the ACTIVITY_RESUMED event.
+    // The endTimeStampMillis stores the timestamp of the ACTIVITY_PAUSED or ACTIVITY_STOPPED event
+    // that wraps up the ForegroundTimeFrame.
+    // The activities are designed to handle the edge case in which a package's one activity
+    // seamlessly replace another activity of the same package. Thus, we count these activities
+    // together as a ForegroundTimeFrame. For this scenario, only when all the activities terminate
+    // shall consider the completion of the ForegroundTimeFrame.
+    static final class ForegroundTimeFrame implements Comparable<ForegroundTimeFrame> {
+        public final long startTimeStampMillis;
+        public long endTimeStampMillis;
+        public final Set<Integer> activities;
+
+        public int compareTo(ForegroundTimeFrame o) {
+            int comp = Long.compare(startTimeStampMillis, o.startTimeStampMillis);
+            if (comp != 0) return comp;
+
+            return Integer.compare(hashCode(), o.hashCode());
+        }
+
+        ForegroundTimeFrame(long startTimeStampMillis) {
+            this.startTimeStampMillis = startTimeStampMillis;
+            endTimeStampMillis = 0;
+            activities = new ArraySet<>();
+        }
+
+        public boolean isDone() {
+            return endTimeStampMillis != 0;
+        }
+
+        public void addEvent(UsageEvents.Event event) {
+            switch (event.mEventType) {
+                case UsageEvents.Event.ACTIVITY_RESUMED:
+                    activities.add(event.mInstanceId);
+                    break;
+                case UsageEvents.Event.ACTIVITY_PAUSED:
+                case UsageEvents.Event.ACTIVITY_STOPPED:
+                    if (activities.contains(event.mInstanceId)) {
+                        activities.remove(event.mInstanceId);
+                        if (activities.size() == 0) {
+                            endTimeStampMillis = event.mTimeStamp;
+                        }
+                    }
+                    break;
+                default:
+            }
+        }
     }
 
     /**
@@ -108,6 +487,16 @@
         Context getContext();
 
         IPackageManager getIPackageManager();
+
+        PackageManagerInternal getPackageManagerInternal();
+
+        UsageStatsManagerInternal getUsageStatsManagerInternal();
+
+        PermissionManagerServiceInternal getPermissionManager();
+
+        Looper getLooper();
+
+        File getDiskFile();
     }
 
     private static final class InjectorImpl implements Injector {
@@ -126,5 +515,36 @@
         public IPackageManager getIPackageManager() {
             return IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
         }
+
+        @Override
+        public PackageManagerInternal getPackageManagerInternal() {
+            return LocalServices.getService(PackageManagerInternal.class);
+        }
+
+        @Override
+        public UsageStatsManagerInternal getUsageStatsManagerInternal() {
+            return LocalServices.getService(UsageStatsManagerInternal.class);
+        }
+
+        @Override
+        public PermissionManagerServiceInternal getPermissionManager() {
+            return LocalServices.getService(PermissionManagerServiceInternal.class);
+        }
+
+        @Override
+        public Looper getLooper() {
+            ServiceThread serviceThread = new ServiceThread(TAG,
+                    android.os.Process.THREAD_PRIORITY_FOREGROUND, true /* allowIo */);
+            serviceThread.start();
+            return serviceThread.getLooper();
+
+        }
+
+        @Override
+        public File getDiskFile() {
+            File dir = new File(Environment.getDataSystemDirectory(), DISK_DIR_NAME);
+            File file = new File(dir, DISK_FILE_NAME);
+            return file;
+        }
     }
 }
diff --git a/services/core/java/com/android/server/pm/CloneProfileResolver.java b/services/core/java/com/android/server/pm/CloneProfileResolver.java
index d3113e1..73036f1 100644
--- a/services/core/java/com/android/server/pm/CloneProfileResolver.java
+++ b/services/core/java/com/android/server/pm/CloneProfileResolver.java
@@ -18,6 +18,8 @@
 
 import android.content.Intent;
 import android.content.pm.ResolveInfo;
+import android.os.Binder;
+import android.provider.DeviceConfig;
 
 import com.android.server.pm.pkg.PackageStateInternal;
 import com.android.server.pm.resolution.ComponentResolverApi;
@@ -32,6 +34,30 @@
  */
 public class CloneProfileResolver extends CrossProfileResolver {
 
+    /**
+     * Feature flag to allow/restrict intent redirection from/to clone profile.
+     * Default value is false,this is to ensure that framework is not impacted by intent redirection
+     * till we are ready to launch.
+     * From Android U onwards, this would be set to true and eventually removed.
+     * @hide
+     */
+    private static final String FLAG_ALLOW_INTENT_REDIRECTION_FOR_CLONE_PROFILE =
+            "allow_intent_redirection_for_clone_profile";
+
+    /**
+     * Returns true if intent redirection for clone profile feature flag is set
+     * @return value of flag allow_intent_redirection_for_clone_profile
+     */
+    public static boolean isIntentRedirectionForCloneProfileAllowed() {
+        final long token = Binder.clearCallingIdentity();
+        try {
+            return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_APP_CLONING,
+                    FLAG_ALLOW_INTENT_REDIRECTION_FOR_CLONE_PROFILE, false /* defaultValue */);
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
     public CloneProfileResolver(ComponentResolverApi componentResolver,
             UserManagerService userManagerService) {
         super(componentResolver, userManagerService);
diff --git a/services/core/java/com/android/server/pm/Computer.java b/services/core/java/com/android/server/pm/Computer.java
index 5b8ee2b..60621a0 100644
--- a/services/core/java/com/android/server/pm/Computer.java
+++ b/services/core/java/com/android/server/pm/Computer.java
@@ -338,6 +338,9 @@
     @NonNull
     ArrayMap<String, ? extends PackageStateInternal> getPackageStates();
 
+    @NonNull
+    ArrayMap<String, ? extends PackageStateInternal> getDisabledSystemPackageStates();
+
     @Nullable
     String getRenamedPackage(@NonNull String packageName);
 
diff --git a/services/core/java/com/android/server/pm/ComputerEngine.java b/services/core/java/com/android/server/pm/ComputerEngine.java
index 45b633f..b8fba51 100644
--- a/services/core/java/com/android/server/pm/ComputerEngine.java
+++ b/services/core/java/com/android/server/pm/ComputerEngine.java
@@ -185,6 +185,10 @@
             return mSettings.getPackagesLocked().untrackedStorage();
         }
 
+        public ArrayMap<String, ? extends PackageStateInternal> getDisabledSystemPackages() {
+            return mSettings.getDisabledSystemPackagesLocked().untrackedStorage();
+        }
+
         public Settings(@NonNull com.android.server.pm.Settings settings) {
             mSettings = settings;
         }
@@ -3459,6 +3463,12 @@
         return mSettings.getPackages();
     }
 
+    @NonNull
+    @Override
+    public ArrayMap<String, ? extends PackageStateInternal> getDisabledSystemPackageStates() {
+        return mSettings.getDisabledSystemPackages();
+    }
+
     @Nullable
     @Override
     public String getRenamedPackage(@NonNull String packageName) {
diff --git a/services/core/java/com/android/server/pm/CrossProfileIntentFilterHelper.java b/services/core/java/com/android/server/pm/CrossProfileIntentFilterHelper.java
new file mode 100644
index 0000000..e682586
--- /dev/null
+++ b/services/core/java/com/android/server/pm/CrossProfileIntentFilterHelper.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.server.pm;
+
+import android.content.Context;
+import android.content.pm.UserInfo;
+import android.content.pm.UserProperties;
+import android.util.ArraySet;
+
+/**
+ * Helper class to manage {@link com.android.server.pm.CrossProfileIntentFilter}s.
+ */
+public class CrossProfileIntentFilterHelper {
+    private Context mContext;
+    private UserManagerInternal mUserManagerInternal;
+    private Settings mSettings;
+    private UserManagerService mUserManagerService;
+    private PackageManagerTracedLock mLock;
+
+    public CrossProfileIntentFilterHelper(Settings settings, UserManagerService userManagerService,
+            PackageManagerTracedLock lock, UserManagerInternal userManagerInternal,
+            Context context) {
+        mSettings = settings;
+        mUserManagerService = userManagerService;
+        mLock = lock;
+        mContext = context;
+        mUserManagerInternal = userManagerInternal;
+    }
+
+    /**
+     * For users that have
+     * {@link android.content.pm.UserProperties#getUpdateCrossProfileIntentFiltersOnOTA} set, this
+     * task will update default {@link com.android.server.pm.CrossProfileIntentFilter} between that
+     * user and its parent. This will only update CrossProfileIntentFilters set by system package.
+     * The new default are configured in {@link UserTypeDetails}.
+     */
+    public void updateDefaultCrossProfileIntentFilter() {
+        for (UserInfo userInfo : mUserManagerInternal.getUsers(false)) {
+
+            UserProperties currentUserProperties = mUserManagerInternal
+                    .getUserProperties(userInfo.id);
+
+            if (currentUserProperties.getUpdateCrossProfileIntentFiltersOnOTA()) {
+                int parentUserId = mUserManagerInternal.getProfileParentId(userInfo.id);
+                if (parentUserId != userInfo.id) {
+                    clearCrossProfileIntentFilters(userInfo.id,
+                            mContext.getOpPackageName(), parentUserId);
+                    clearCrossProfileIntentFilters(parentUserId,
+                            mContext.getOpPackageName(),  userInfo.id);
+
+                    mUserManagerInternal.setDefaultCrossProfileIntentFilters(parentUserId,
+                            userInfo.id);
+                }
+            }
+        }
+    }
+
+    /**
+     * Clear {@link CrossProfileIntentFilter}s configured on source user by ownerPackage
+     * targeting the targetUserId. If targetUserId is null then it will clear
+     * {@link CrossProfileIntentFilter} for any target user.
+     * @param sourceUserId source user for whom CrossProfileIntentFilter would be configured
+     * @param ownerPackage package who would have configured CrossProfileIntentFilter
+     * @param targetUserId user id for which CrossProfileIntentFilter will be removed.
+     *                     This can be null in which case it will clear for any target user.
+     */
+    public void clearCrossProfileIntentFilters(int sourceUserId, String ownerPackage,
+            Integer targetUserId) {
+        synchronized (mLock) {
+            CrossProfileIntentResolver resolver = mSettings
+                    .editCrossProfileIntentResolverLPw(sourceUserId);
+            ArraySet<CrossProfileIntentFilter> set =
+                    new ArraySet<>(resolver.filterSet());
+            for (CrossProfileIntentFilter filter : set) {
+                //Only remove if calling user is allowed based on access control of
+                // {@link CrossProfileIntentFilter}
+                if (filter.getOwnerPackage().equals(ownerPackage)
+                        && (targetUserId == null || filter.mTargetUserId == targetUserId)
+                        && mUserManagerService.isCrossProfileIntentFilterAccessible(sourceUserId,
+                        filter.mTargetUserId, /* addCrossProfileIntentFilter */ false)) {
+                    resolver.removeFilter(filter);
+                }
+            }
+        }
+    }
+}
diff --git a/services/core/java/com/android/server/pm/CrossProfileIntentResolverEngine.java b/services/core/java/com/android/server/pm/CrossProfileIntentResolverEngine.java
index 5d97cb7..1e0822d 100644
--- a/services/core/java/com/android/server/pm/CrossProfileIntentResolverEngine.java
+++ b/services/core/java/com/android/server/pm/CrossProfileIntentResolverEngine.java
@@ -32,7 +32,6 @@
 import android.content.pm.UserInfo;
 import android.os.Process;
 import android.text.TextUtils;
-import android.util.FeatureFlagUtils;
 import android.util.Pair;
 import android.util.Slog;
 import android.util.SparseArray;
@@ -250,8 +249,7 @@
          * SETTINGS_ALLOW_INTENT_REDIRECTION_FOR_CLONE_PROFILE is enabled
          */
         if (sourceUserInfo.isCloneProfile() || targetUserInfo.isCloneProfile()) {
-            if (FeatureFlagUtils.isEnabled(mContext,
-                    FeatureFlagUtils.SETTINGS_ALLOW_INTENT_REDIRECTION_FOR_CLONE_PROFILE)) {
+            if (CloneProfileResolver.isIntentRedirectionForCloneProfileAllowed()) {
                 return new CloneProfileResolver(computer.getComponentResolver(),
                         mUserManager);
             } else {
diff --git a/services/core/java/com/android/server/pm/DeletePackageHelper.java b/services/core/java/com/android/server/pm/DeletePackageHelper.java
index 6998db7..a6def7d 100644
--- a/services/core/java/com/android/server/pm/DeletePackageHelper.java
+++ b/services/core/java/com/android/server/pm/DeletePackageHelper.java
@@ -261,7 +261,7 @@
             final boolean killApp = (deleteFlags & PackageManager.DELETE_DONT_KILL_APP) == 0;
             info.sendPackageRemovedBroadcasts(killApp, removedBySystem);
             info.sendSystemPackageUpdatedBroadcasts();
-            PackageMetrics.onUninstallSucceeded(info, deleteFlags, mUserManagerInternal);
+            PackageMetrics.onUninstallSucceeded(info, deleteFlags, userId);
         }
 
         // Force a gc to clear up things.
@@ -550,6 +550,7 @@
             outInfo.mRemovedUsers = userIds;
             outInfo.mBroadcastUsers = userIds;
             outInfo.mIsExternal = ps.isExternalStorage();
+            outInfo.mRemovedPackageVersionCode = ps.getVersionCode();
         }
     }
 
diff --git a/services/core/java/com/android/server/pm/GentleUpdateHelper.java b/services/core/java/com/android/server/pm/GentleUpdateHelper.java
index 247ac90..7cb096d 100644
--- a/services/core/java/com/android/server/pm/GentleUpdateHelper.java
+++ b/services/core/java/com/android/server/pm/GentleUpdateHelper.java
@@ -16,7 +16,12 @@
 
 package com.android.server.pm;
 
+import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
+import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND_SERVICE;
+
 import android.annotation.WorkerThread;
+import android.app.ActivityManager;
+import android.app.ActivityManager.RunningAppProcessInfo;
 import android.app.ActivityThread;
 import android.app.job.JobInfo;
 import android.app.job.JobParameters;
@@ -28,6 +33,9 @@
 import android.content.pm.PackageInstaller.InstallConstraintsResult;
 import android.os.Handler;
 import android.os.Looper;
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.text.format.DateUtils;
 import android.util.Slog;
 
 import java.util.ArrayDeque;
@@ -73,12 +81,24 @@
         public final List<String> packageNames;
         public final InstallConstraints constraints;
         public final CompletableFuture<InstallConstraintsResult> future;
+        private final long mFinishTime;
+
+        /**
+         * Note {@code timeoutMillis} will be clamped to 0 ~ one week to avoid overflow.
+         */
         PendingInstallConstraintsCheck(List<String> packageNames,
                 InstallConstraints constraints,
-                CompletableFuture<InstallConstraintsResult> future) {
+                CompletableFuture<InstallConstraintsResult> future,
+                long timeoutMillis) {
             this.packageNames = packageNames;
             this.constraints = constraints;
             this.future = future;
+
+            timeoutMillis = Math.max(0, Math.min(DateUtils.WEEK_IN_MILLIS, timeoutMillis));
+            mFinishTime = SystemClock.elapsedRealtime() + timeoutMillis;
+        }
+        public boolean isTimedOut() {
+            return SystemClock.elapsedRealtime() >= mFinishTime;
         }
     }
 
@@ -95,15 +115,31 @@
         mAppStateHelper = appStateHelper;
     }
 
+    void systemReady() {
+        var am = mContext.getSystemService(ActivityManager.class);
+        // Monitor top-visible apps
+        am.addOnUidImportanceListener(this::onUidImportance, IMPORTANCE_FOREGROUND);
+        // Monitor foreground apps
+        am.addOnUidImportanceListener(this::onUidImportance, IMPORTANCE_FOREGROUND_SERVICE);
+    }
+
     /**
      * Checks if install constraints are satisfied for the given packages.
      */
     CompletableFuture<InstallConstraintsResult> checkInstallConstraints(
-            List<String> packageNames, InstallConstraints constraints) {
+            List<String> packageNames, InstallConstraints constraints,
+            long timeoutMillis) {
         var future = new CompletableFuture<InstallConstraintsResult>();
         mHandler.post(() -> {
+            long clampedTimeoutMillis = timeoutMillis;
+            if (constraints.isRequireDeviceIdle()) {
+                // Device-idle-constraint is required. Clamp the timeout to ensure
+                // timeout-check happens after device-idle-check.
+                clampedTimeoutMillis = Math.max(timeoutMillis, PENDING_CHECK_MILLIS);
+            }
+
             var pendingCheck = new PendingInstallConstraintsCheck(
-                    packageNames, constraints, future);
+                    packageNames, constraints, future, clampedTimeoutMillis);
             if (constraints.isRequireDeviceIdle()) {
                 mPendingChecks.add(pendingCheck);
                 // JobScheduler doesn't provide queries about whether the device is idle.
@@ -113,8 +149,17 @@
                 scheduleIdleJob();
                 mHandler.postDelayed(() -> processPendingCheck(pendingCheck, false),
                         PENDING_CHECK_MILLIS);
-            } else {
-                processPendingCheck(pendingCheck, false);
+            } else if (!processPendingCheck(pendingCheck, false)) {
+                // Not resolved. Schedule a job for re-check
+                mPendingChecks.add(pendingCheck);
+                scheduleIdleJob();
+            }
+
+            if (!future.isDone()) {
+                // Ensure the pending check is resolved after timeout, no matter constraints
+                // satisfied or not.
+                mHandler.postDelayed(() -> processPendingCheck(pendingCheck, false),
+                        clampedTimeoutMillis);
             }
         });
         return future;
@@ -143,29 +188,77 @@
     }
 
     @WorkerThread
-    private void processPendingCheck(PendingInstallConstraintsCheck pendingCheck, boolean isIdle) {
+    private boolean areConstraintsSatisfied(List<String> packageNames,
+            InstallConstraints constraints, boolean isIdle) {
+        return (!constraints.isRequireDeviceIdle() || isIdle)
+                && (!constraints.isRequireAppNotForeground()
+                || !mAppStateHelper.hasForegroundApp(packageNames))
+                && (!constraints.isRequireAppNotInteracting()
+                || !mAppStateHelper.hasInteractingApp(packageNames))
+                && (!constraints.isRequireAppNotTopVisible()
+                || !mAppStateHelper.hasTopVisibleApp(packageNames))
+                && (!constraints.isRequireNotInCall()
+                || !mAppStateHelper.isInCall());
+    }
+
+    @WorkerThread
+    private boolean processPendingCheck(
+            PendingInstallConstraintsCheck pendingCheck, boolean isIdle) {
         var future = pendingCheck.future;
         if (future.isDone()) {
-            return;
+            return true;
         }
         var constraints = pendingCheck.constraints;
         var packageNames = mAppStateHelper.getDependencyPackages(pendingCheck.packageNames);
-        var constraintsSatisfied = (!constraints.isRequireDeviceIdle() || isIdle)
-                && (!constraints.isRequireAppNotForeground()
-                        || !mAppStateHelper.hasForegroundApp(packageNames))
-                && (!constraints.isRequireAppNotInteracting()
-                        || !mAppStateHelper.hasInteractingApp(packageNames))
-                && (!constraints.isRequireAppNotTopVisible()
-                        || !mAppStateHelper.hasTopVisibleApp(packageNames))
-                && (!constraints.isRequireNotInCall()
-                        || !mAppStateHelper.isInCall());
-        future.complete(new InstallConstraintsResult((constraintsSatisfied)));
+        var satisfied = areConstraintsSatisfied(packageNames, constraints, isIdle);
+        if (satisfied || pendingCheck.isTimedOut()) {
+            future.complete(new InstallConstraintsResult((satisfied)));
+            return true;
+        }
+        return false;
     }
 
     @WorkerThread
     private void processPendingChecksInIdle() {
-        while (!mPendingChecks.isEmpty()) {
-            processPendingCheck(mPendingChecks.remove(), true);
+        int size = mPendingChecks.size();
+        for (int i = 0; i < size; ++i) {
+            var pendingCheck = mPendingChecks.remove();
+            if (!processPendingCheck(pendingCheck, true)) {
+                // Not resolved. Put it back in the queue.
+                mPendingChecks.add(pendingCheck);
+            }
+        }
+        if (!mPendingChecks.isEmpty()) {
+            // Schedule a job for remaining pending checks
+            scheduleIdleJob();
+        }
+    }
+
+    @WorkerThread
+    private void onUidImportance(String packageName,
+            @RunningAppProcessInfo.Importance int importance) {
+        int size = mPendingChecks.size();
+        for (int i = 0; i < size; ++i) {
+            var pendingCheck = mPendingChecks.remove();
+            var dependencyPackages =
+                    mAppStateHelper.getDependencyPackages(pendingCheck.packageNames);
+            if (!dependencyPackages.contains(packageName)
+                    || !processPendingCheck(pendingCheck, false)) {
+                mPendingChecks.add(pendingCheck);
+            }
+        }
+        if (!mPendingChecks.isEmpty()) {
+            // Schedule a job for remaining pending checks
+            scheduleIdleJob();
+        }
+    }
+
+    private void onUidImportance(int uid, @RunningAppProcessInfo.Importance int importance) {
+        var pm = ActivityThread.getPackageManager();
+        try {
+            var packageName = pm.getNameForUid(uid);
+            mHandler.post(() -> onUidImportance(packageName, importance));
+        } catch (RemoteException ignore) {
         }
     }
 }
diff --git a/services/core/java/com/android/server/pm/InitAppsHelper.java b/services/core/java/com/android/server/pm/InitAppsHelper.java
index 12b5ab8..823bc71 100644
--- a/services/core/java/com/android/server/pm/InitAppsHelper.java
+++ b/services/core/java/com/android/server/pm/InitAppsHelper.java
@@ -39,6 +39,8 @@
 import android.os.Environment;
 import android.os.SystemClock;
 import android.os.Trace;
+import android.system.ErrnoException;
+import android.system.Os;
 import android.util.ArrayMap;
 import android.util.EventLog;
 import android.util.Slog;
@@ -55,6 +57,7 @@
 import com.android.server.utils.WatchedArrayMap;
 
 import java.io.File;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ExecutorService;
@@ -227,6 +230,24 @@
     }
 
     /**
+     * Fix up the previously-installed app directory mode - they can't be readable by non-system
+     * users to prevent them from listing the dir to discover installed package names.
+     */
+    void fixInstalledAppDirMode() {
+        try (var files = Files.newDirectoryStream(mPm.getAppInstallDir().toPath())) {
+            files.forEach(dir -> {
+                try {
+                    Os.chmod(dir.toString(), 0771);
+                } catch (ErrnoException e) {
+                    Slog.w(TAG, "Failed to fix an installed app dir mode", e);
+                }
+            });
+        } catch (Exception e) {
+            Slog.w(TAG, "Failed to walk the app install directory to fix the modes", e);
+        }
+    }
+
+    /**
      * Install apps/updates from data dir and fix system apps that are affected.
      */
     @GuardedBy({"mPm.mInstallLock", "mPm.mLock"})
@@ -234,6 +255,11 @@
             long startTime) {
         EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_DATA_SCAN_START,
                 SystemClock.uptimeMillis());
+
+        if ((mScanFlags & SCAN_FIRST_BOOT_OR_UPGRADE) == SCAN_FIRST_BOOT_OR_UPGRADE) {
+            fixInstalledAppDirMode();
+        }
+
         scanDirTracedLI(mPm.getAppInstallDir(), 0,
                 mScanFlags | SCAN_REQUIRE_KNOWN, packageParser, mExecutorService);
 
diff --git a/services/core/java/com/android/server/pm/InstallPackageHelper.java b/services/core/java/com/android/server/pm/InstallPackageHelper.java
index 7553370..911cfbd 100644
--- a/services/core/java/com/android/server/pm/InstallPackageHelper.java
+++ b/services/core/java/com/android/server/pm/InstallPackageHelper.java
@@ -1608,6 +1608,7 @@
                             ps.getUninstallReason(userId));
                 }
                 removedInfo.mIsExternal = oldPackage.isExternalStorage();
+                removedInfo.mRemovedPackageVersionCode = oldPackage.getLongVersionCode();
                 request.setRemovedInfo(removedInfo);
 
                 sysPkg = oldPackage.isSystem();
@@ -1719,7 +1720,7 @@
         final boolean onIncremental = mPm.mIncrementalManager != null
                 && isIncrementalPath(beforeCodeFile.getAbsolutePath());
         try {
-            makeDirRecursive(afterCodeFile.getParentFile(), 0775);
+            makeDirRecursive(afterCodeFile.getParentFile(), 0771);
             if (onIncremental) {
                 // Just link files here. The stage dir will be removed when the installation
                 // session is completed.
@@ -2241,6 +2242,7 @@
     @GuardedBy("mPm.mInstallLock")
     private void executePostCommitStepsLIF(List<ReconciledPackage> reconciledPackages) {
         final ArraySet<IncrementalStorage> incrementalStorages = new ArraySet<>();
+        final ArrayList<String> apkPaths = new ArrayList<>();
         for (ReconciledPackage reconciledPkg : reconciledPackages) {
             final InstallRequest installRequest = reconciledPkg.mInstallRequest;
             final boolean instantApp = ((installRequest.getScanFlags() & SCAN_AS_INSTANT_APP) != 0);
@@ -2260,25 +2262,11 @@
             }
 
             // Enabling fs-verity is a blocking operation. To reduce the impact to the install time,
-            // run in a background thread.
-            final ArrayList<String> apkPaths = new ArrayList<>();
+            // collect the files to later enable in a background thread.
             apkPaths.add(pkg.getBaseApkPath());
             if (pkg.getSplitCodePaths() != null) {
                 Collections.addAll(apkPaths, pkg.getSplitCodePaths());
             }
-            mInjector.getBackgroundHandler().post(() -> {
-                try {
-                    for (String path : apkPaths) {
-                        if (!VerityUtils.hasFsverity(path)) {
-                            VerityUtils.setUpFsverity(path, (byte[]) null);
-                        }
-                    }
-                } catch (IOException e) {
-                    // There's nothing we can do if the setup failed. Since fs-verity is
-                    // optional, just ignore the error for now.
-                    Slog.e(TAG, "Failed to fully enable fs-verity to " + packageName);
-                }
-            });
 
             // Hardcode previousAppId to 0 to disable any data migration (http://b/221088088)
             mAppDataHelper.prepareAppDataPostCommitLIF(pkg, 0);
@@ -2392,6 +2380,20 @@
         }
         PackageManagerServiceUtils.waitForNativeBinariesExtractionForIncremental(
                 incrementalStorages);
+
+        mInjector.getBackgroundHandler().post(() -> {
+            for (String path : apkPaths) {
+                if (!VerityUtils.hasFsverity(path)) {
+                    try {
+                        VerityUtils.setUpFsverity(path, (byte[]) null);
+                    } catch (IOException e) {
+                        // There's nothing we can do if the setup failed. Since fs-verity is
+                        // optional, just ignore the error for now.
+                        Slog.e(TAG, "Failed to fully enable fs-verity to " + path);
+                    }
+                }
+            }
+        });
     }
 
     Pair<Integer, String> verifyReplacingVersionCode(PackageInfoLite pkgLite,
diff --git a/services/core/java/com/android/server/pm/InstallRequest.java b/services/core/java/com/android/server/pm/InstallRequest.java
index 5974a9c..c6cdc4c 100644
--- a/services/core/java/com/android/server/pm/InstallRequest.java
+++ b/services/core/java/com/android/server/pm/InstallRequest.java
@@ -773,10 +773,10 @@
         }
     }
 
-    public void onInstallCompleted() {
+    public void onInstallCompleted(int userId) {
         if (getReturnCode() == INSTALL_SUCCEEDED) {
             if (mPackageMetrics != null) {
-                mPackageMetrics.onInstallSucceed();
+                mPackageMetrics.onInstallSucceed(userId);
             }
         }
     }
diff --git a/services/core/java/com/android/server/pm/InstallingSession.java b/services/core/java/com/android/server/pm/InstallingSession.java
index 2b6398a..b600aa8 100644
--- a/services/core/java/com/android/server/pm/InstallingSession.java
+++ b/services/core/java/com/android/server/pm/InstallingSession.java
@@ -535,7 +535,7 @@
             mInstallPackageHelper.installPackagesTraced(installRequests);
 
             for (InstallRequest request : installRequests) {
-                request.onInstallCompleted();
+                request.onInstallCompleted(mUser.getIdentifier());
                 doPostInstall(request);
             }
         }
diff --git a/services/core/java/com/android/server/pm/PackageInstallerService.java b/services/core/java/com/android/server/pm/PackageInstallerService.java
index 409d352..9c60795 100644
--- a/services/core/java/com/android/server/pm/PackageInstallerService.java
+++ b/services/core/java/com/android/server/pm/PackageInstallerService.java
@@ -45,6 +45,7 @@
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageInstaller;
 import android.content.pm.PackageInstaller.InstallConstraints;
+import android.content.pm.PackageInstaller.InstallConstraintsResult;
 import android.content.pm.PackageInstaller.SessionInfo;
 import android.content.pm.PackageInstaller.SessionParams;
 import android.content.pm.PackageItemInfo;
@@ -91,7 +92,6 @@
 import com.android.internal.notification.SystemNotificationChannels;
 import com.android.internal.util.ImageUtils;
 import com.android.internal.util.IndentingPrintWriter;
-import com.android.internal.util.Preconditions;
 import com.android.modules.utils.TypedXmlPullParser;
 import com.android.modules.utils.TypedXmlSerializer;
 import com.android.server.IoThread;
@@ -123,6 +123,7 @@
 import java.util.Random;
 import java.util.TreeMap;
 import java.util.TreeSet;
+import java.util.concurrent.CompletableFuture;
 import java.util.function.IntPredicate;
 import java.util.function.Supplier;
 
@@ -153,6 +154,13 @@
     private static final long MAX_HISTORICAL_SESSIONS = 1048576;
     /** Destroy sessions older than this on storage free request */
     private static final long MAX_SESSION_AGE_ON_LOW_STORAGE_MILLIS = 8 * DateUtils.HOUR_IN_MILLIS;
+    /** Maximum time to wait for install constraints to be satisfied */
+    private static final long MAX_INSTALL_CONSTRAINTS_TIMEOUT_MILLIS = DateUtils.WEEK_IN_MILLIS;
+
+    /** Threshold of historical sessions size */
+    private static final int HISTORICAL_SESSIONS_THRESHOLD = 500;
+    /** Size of historical sessions to be cleared when reaching threshold */
+    private static final int HISTORICAL_CLEAR_SIZE = 400;
 
     /**
      * Allow verification-skipping if it's a development app installed through ADB with
@@ -295,6 +303,7 @@
     public void systemReady() {
         mAppOps = mContext.getSystemService(AppOpsManager.class);
         mStagingManager.systemReady();
+        mGentleUpdateHelper.systemReady();
 
         synchronized (mSessions) {
             readSessionsLocked();
@@ -549,6 +558,10 @@
         CharArrayWriter writer = new CharArrayWriter();
         IndentingPrintWriter pw = new IndentingPrintWriter(writer, "    ");
         session.dump(pw);
+        if (mHistoricalSessions.size() > HISTORICAL_SESSIONS_THRESHOLD) {
+            Slog.d(TAG, "Historical sessions size reaches threshold, clear the oldest");
+            mHistoricalSessions.subList(0, HISTORICAL_CLEAR_SIZE).clear();
+        }
         mHistoricalSessions.add(writer.toString());
 
         int installerUid = session.getInstallerUid();
@@ -1239,12 +1252,11 @@
         }
     }
 
-    @Override
-    public void checkInstallConstraints(String installerPackageName, List<String> packageNames,
-            InstallConstraints constraints, RemoteCallback callback) {
-        Preconditions.checkArgument(packageNames != null);
-        Preconditions.checkArgument(constraints != null);
-        Preconditions.checkArgument(callback != null);
+    private CompletableFuture<InstallConstraintsResult> checkInstallConstraintsInternal(
+            String installerPackageName, List<String> packageNames,
+            InstallConstraints constraints, long timeoutMillis) {
+        Objects.requireNonNull(packageNames);
+        Objects.requireNonNull(constraints);
 
         final var snapshot = mPm.snapshotComputer();
         final int callingUid = Binder.getCallingUid();
@@ -1258,7 +1270,16 @@
             }
         }
 
-        var future = mGentleUpdateHelper.checkInstallConstraints(packageNames, constraints);
+        return mGentleUpdateHelper.checkInstallConstraints(
+                packageNames, constraints, timeoutMillis);
+    }
+
+    @Override
+    public void checkInstallConstraints(String installerPackageName, List<String> packageNames,
+            InstallConstraints constraints, RemoteCallback callback) {
+        Objects.requireNonNull(callback);
+        var future = checkInstallConstraintsInternal(
+                installerPackageName, packageNames, constraints, /*timeoutMillis=*/0);
         future.thenAccept(result -> {
             var b = new Bundle();
             b.putParcelable("result", result);
@@ -1267,6 +1288,27 @@
     }
 
     @Override
+    public void waitForInstallConstraints(String installerPackageName, List<String> packageNames,
+            InstallConstraints constraints, IntentSender callback, long timeoutMillis) {
+        Objects.requireNonNull(callback);
+        if (timeoutMillis < 0 || timeoutMillis > MAX_INSTALL_CONSTRAINTS_TIMEOUT_MILLIS) {
+            throw new IllegalArgumentException("Invalid timeoutMillis=" + timeoutMillis);
+        }
+        var future = checkInstallConstraintsInternal(
+                installerPackageName, packageNames, constraints, timeoutMillis);
+        future.thenAccept(result -> {
+            final var intent = new Intent();
+            intent.putExtra(Intent.EXTRA_PACKAGES, packageNames.toArray(new String[0]));
+            intent.putExtra(PackageInstaller.EXTRA_INSTALL_CONSTRAINTS, constraints);
+            intent.putExtra(PackageInstaller.EXTRA_INSTALL_CONSTRAINTS_RESULT, result);
+            try {
+                callback.sendIntent(mContext, 0, intent, null, null);
+            } catch (SendIntentException ignore) {
+            }
+        });
+    }
+
+    @Override
     public void registerCallback(IPackageInstallerCallback callback, int userId) {
         final Computer snapshot = mPm.snapshotComputer();
         snapshot.enforceCrossUserPermission(Binder.getCallingUid(), userId, true, false,
diff --git a/services/core/java/com/android/server/pm/PackageInstallerSession.java b/services/core/java/com/android/server/pm/PackageInstallerSession.java
index 3983acf..9aaf685 100644
--- a/services/core/java/com/android/server/pm/PackageInstallerSession.java
+++ b/services/core/java/com/android/server/pm/PackageInstallerSession.java
@@ -125,7 +125,7 @@
 import android.os.incremental.PerUidReadTimeouts;
 import android.os.incremental.StorageHealthCheckParams;
 import android.os.storage.StorageManager;
-import android.provider.Settings.Secure;
+import android.provider.Settings.Global;
 import android.stats.devicepolicy.DevicePolicyEnums;
 import android.system.ErrnoException;
 import android.system.Int64Ref;
@@ -1842,7 +1842,8 @@
             assertNoWriteFileTransfersOpenLocked();
 
             final boolean isSecureFrpEnabled =
-                    (Secure.getInt(mContext.getContentResolver(), Secure.SECURE_FRP_MODE, 0) == 1);
+                    Global.getInt(mContext.getContentResolver(), Global.SECURE_FRP_MODE, 0) == 1;
+
             if (isSecureFrpEnabled
                     && !isSecureFrpInstallAllowed(mContext, Binder.getCallingUid())) {
                 throw new SecurityException("Can't install packages while in secure FRP");
@@ -2785,6 +2786,7 @@
         // Default to require only if existing base apk has fs-verity signature.
         mVerityFoundForApks = PackageManagerServiceUtils.isApkVerityEnabled()
                 && params.mode == SessionParams.MODE_INHERIT_EXISTING
+                && VerityUtils.hasFsverity(pkgInfo.applicationInfo.getBaseCodePath())
                 && (new File(VerityUtils.getFsveritySignatureFilePath(
                         pkgInfo.applicationInfo.getBaseCodePath()))).exists();
 
diff --git a/services/core/java/com/android/server/pm/PackageManagerLocal.java b/services/core/java/com/android/server/pm/PackageManagerLocal.java
index fad61b8..935c4dd 100644
--- a/services/core/java/com/android/server/pm/PackageManagerLocal.java
+++ b/services/core/java/com/android/server/pm/PackageManagerLocal.java
@@ -30,7 +30,6 @@
 import java.lang.annotation.RetentionPolicy;
 import java.util.List;
 import java.util.Map;
-import java.util.function.Consumer;
 
 /**
  * In-process API for server side PackageManager related infrastructure.
@@ -150,6 +149,16 @@
         @NonNull
         Map<String, PackageState> getPackageStates();
 
+        /**
+         * Returns a map of all disabled system {@link PackageState PackageStates} on the device.
+         *
+         * @return Mapping of package name to disabled system {@link PackageState}.
+         *
+         * @hide Pending API
+         */
+        @NonNull
+        Map<String, PackageState> getDisabledSystemPackageStates();
+
         @Override
         void close();
     }
@@ -177,8 +186,6 @@
         @NonNull
         Map<String, PackageState> getPackageStates();
 
-        void forAllPackageStates(@NonNull Consumer<PackageState> consumer);
-
         @Override
         void close();
     }
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index cf59a1e..f38f000 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -1537,7 +1537,10 @@
                 (i, pm) -> new BackgroundDexOptService(i.getContext(), i.getDexManager(), pm),
                 (i, pm) -> IBackupManager.Stub.asInterface(ServiceManager.getService(
                         Context.BACKUP_SERVICE)),
-                (i, pm) -> new SharedLibrariesImpl(pm, i));
+                (i, pm) -> new SharedLibrariesImpl(pm, i),
+                (i, pm) -> new CrossProfileIntentFilterHelper(i.getSettings(),
+                        i.getUserManagerService(), i.getLock(), i.getUserManagerInternal(),
+                        context));
 
         if (Build.VERSION.SDK_INT <= 0) {
             Slog.w(TAG, "**** ro.build.version.sdk not set!");
@@ -2029,13 +2032,21 @@
             final WatchedArrayMap<String, PackageSetting> packageSettings =
                 mSettings.getPackagesLocked();
 
-            // Save the names of pre-existing packages prior to scanning, so we can determine
-            // which system packages are completely new due to an upgrade.
             if (isDeviceUpgrading()) {
+                // Save the names of pre-existing packages prior to scanning, so we can determine
+                // which system packages are completely new due to an upgrade.
                 mExistingPackages = new ArraySet<>(packageSettings.size());
                 for (PackageSetting ps : packageSettings.values()) {
                     mExistingPackages.add(ps.getPackageName());
                 }
+
+                // Triggering {@link com.android.server.pm.crossprofile.
+                // CrossProfileIntentFilterHelper.updateDefaultCrossProfileIntentFilter} to update
+                // {@link  CrossProfileIntentFilter}s between eligible users and their parent
+                t.traceBegin("cross profile intent filter update");
+                mInjector.getCrossProfileIntentFilterHelper()
+                        .updateDefaultCrossProfileIntentFilter();
+                t.traceEnd();
             }
 
             mCacheDir = PackageManagerServiceUtils.preparePackageParserCache(
@@ -3078,6 +3089,7 @@
         info.mRemovedUsers = new int[] {userId};
         info.mBroadcastUsers = new int[] {userId};
         info.mUid = UserHandle.getUid(userId, packageState.getAppId());
+        info.mRemovedPackageVersionCode = packageState.getVersionCode();
         info.sendPackageRemovedBroadcasts(true /*killApp*/, false /*removedBySystem*/);
     }
 
@@ -3254,6 +3266,7 @@
         return isPackageDeviceAdmin(packageName, UserHandle.USER_ALL);
     }
 
+    // TODO(b/261957226): centralise this logic in DPM
     boolean isPackageDeviceAdmin(String packageName, int userId) {
         final IDevicePolicyManager dpm = getDevicePolicyManager();
         try {
@@ -3280,6 +3293,9 @@
                     if (dpm.packageHasActiveAdmins(packageName, users[i])) {
                         return true;
                     }
+                    if (isDeviceManagementRoleHolder(packageName, users[i])) {
+                        return true;
+                    }
                 }
             }
         } catch (RemoteException e) {
@@ -3287,6 +3303,24 @@
         return false;
     }
 
+    private boolean isDeviceManagementRoleHolder(String packageName, int userId) {
+        return Objects.equals(packageName, getDevicePolicyManagementRoleHolderPackageName(userId));
+    }
+
+    @Nullable
+    private String getDevicePolicyManagementRoleHolderPackageName(int userId) {
+        return Binder.withCleanCallingIdentity(() -> {
+            RoleManager roleManager = mContext.getSystemService(RoleManager.class);
+            List<String> roleHolders =
+                    roleManager.getRoleHoldersAsUser(
+                            RoleManager.ROLE_DEVICE_POLICY_MANAGEMENT, UserHandle.of(userId));
+            if (roleHolders.isEmpty()) {
+                return null;
+            }
+            return roleHolders.get(0);
+        });
+    }
+
     /** Returns the device policy manager interface. */
     private IDevicePolicyManager getDevicePolicyManager() {
         if (mDevicePolicyManager == null) {
@@ -3447,6 +3481,7 @@
         scheduleWritePackageRestrictions(sourceUserId);
     }
 
+
     // Enforcing that callingUid is owning pkg on userId
     private void enforceOwnerRights(@NonNull Computer snapshot, String pkg, int callingUid) {
         // The system owns everything.
@@ -4637,21 +4672,9 @@
             enforceOwnerRights(snapshot, ownerPackage, callingUid);
             PackageManagerServiceUtils.enforceShellRestriction(mInjector.getUserManagerInternal(),
                     UserManager.DISALLOW_DEBUGGING_FEATURES, callingUid, sourceUserId);
-            synchronized (mLock) {
-                CrossProfileIntentResolver resolver =
-                        mSettings.editCrossProfileIntentResolverLPw(sourceUserId);
-                ArraySet<CrossProfileIntentFilter> set =
-                        new ArraySet<>(resolver.filterSet());
-                for (CrossProfileIntentFilter filter : set) {
-                    //Only remove if calling user is allowed based on access control of
-                    // {@link CrossProfileIntentFilter}
-                    if (filter.getOwnerPackage().equals(ownerPackage)
-                            && mUserManager.isCrossProfileIntentFilterAccessible(sourceUserId,
-                            filter.mTargetUserId, /* addCrossProfileIntentFilter */ false)) {
-                        resolver.removeFilter(filter);
-                    }
-                }
-            }
+            PackageManagerService.this.mInjector.getCrossProfileIntentFilterHelper()
+                            .clearCrossProfileIntentFilters(sourceUserId, ownerPackage,
+                                    null);
             scheduleWritePackageRestrictions(sourceUserId);
         }
 
diff --git a/services/core/java/com/android/server/pm/PackageManagerServiceInjector.java b/services/core/java/com/android/server/pm/PackageManagerServiceInjector.java
index 396994b..76e6e45f 100644
--- a/services/core/java/com/android/server/pm/PackageManagerServiceInjector.java
+++ b/services/core/java/com/android/server/pm/PackageManagerServiceInjector.java
@@ -139,6 +139,7 @@
     private final Singleton<BackgroundDexOptService> mBackgroundDexOptService;
     private final Singleton<IBackupManager> mIBackupManager;
     private final Singleton<SharedLibrariesImpl> mSharedLibrariesProducer;
+    private final Singleton<CrossProfileIntentFilterHelper> mCrossProfileIntentFilterHelperProducer;
 
     PackageManagerServiceInjector(Context context, PackageManagerTracedLock lock,
             Installer installer, Object installLock, PackageAbiHelper abiHelper,
@@ -176,7 +177,8 @@
             ServiceProducer getSystemServiceProducer,
             Producer<BackgroundDexOptService> backgroundDexOptService,
             Producer<IBackupManager> iBackupManager,
-            Producer<SharedLibrariesImpl> sharedLibrariesProducer) {
+            Producer<SharedLibrariesImpl> sharedLibrariesProducer,
+            Producer<CrossProfileIntentFilterHelper> crossProfileIntentFilterHelperProducer) {
         mContext = context;
         mLock = lock;
         mInstaller = installer;
@@ -228,6 +230,8 @@
         mBackgroundDexOptService = new Singleton<>(backgroundDexOptService);
         mIBackupManager = new Singleton<>(iBackupManager);
         mSharedLibrariesProducer = new Singleton<>(sharedLibrariesProducer);
+        mCrossProfileIntentFilterHelperProducer = new Singleton<>(
+                crossProfileIntentFilterHelperProducer);
     }
 
     /**
@@ -262,6 +266,14 @@
         return mLock;
     }
 
+    /**
+     * {@link CrossProfileIntentFilterHelper} which manages {@link CrossProfileIntentFilter}
+     * @return CrossProfileIntentFilterHelper
+     */
+    public CrossProfileIntentFilterHelper getCrossProfileIntentFilterHelper() {
+        return mCrossProfileIntentFilterHelperProducer.get(this, mPackageManager);
+    }
+
     public Installer getInstaller() {
         return mInstaller;
     }
diff --git a/services/core/java/com/android/server/pm/PackageManagerShellCommand.java b/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
index e1efc61..2138c20 100644
--- a/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
+++ b/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
@@ -99,7 +99,6 @@
 import android.text.TextUtils;
 import android.text.format.DateUtils;
 import android.util.ArrayMap;
-import android.util.ArraySet;
 import android.util.IntArray;
 import android.util.PrintWriterPrinter;
 import android.util.Slog;
@@ -116,6 +115,7 @@
 import com.android.server.art.ArtManagerLocal;
 import com.android.server.pm.PackageManagerShellCommandDataLoader.Metadata;
 import com.android.server.pm.permission.LegacyPermissionManagerInternal;
+import com.android.server.pm.permission.PermissionAllowlist;
 import com.android.server.pm.verify.domain.DomainVerificationShell;
 
 import dalvik.system.DexFile;
@@ -2684,26 +2684,7 @@
             getErrPrintWriter().println("Error: no package specified.");
             return 1;
         }
-
-        ArraySet<String> privAppPermissions = null;
-        if (isVendorApp(pkg)) {
-            privAppPermissions = SystemConfig.getInstance().getVendorPrivAppPermissions(pkg);
-        } else if (isProductApp(pkg)) {
-            privAppPermissions = SystemConfig.getInstance().getProductPrivAppPermissions(pkg);
-        } else if (isSystemExtApp(pkg)) {
-            privAppPermissions = SystemConfig.getInstance()
-                    .getSystemExtPrivAppPermissions(pkg);
-        } else if (isApexApp(pkg)) {
-            final String apexName = ApexManager.getInstance().getApexModuleNameForPackageName(
-                    getApexPackageNameContainingPackage(pkg));
-            privAppPermissions = SystemConfig.getInstance()
-                    .getApexPrivAppPermissions(apexName, pkg);
-        } else {
-            privAppPermissions = SystemConfig.getInstance().getPrivAppPermissions(pkg);
-        }
-
-        getOutPrintWriter().println(privAppPermissions == null
-                ? "{}" : privAppPermissions.toString());
+        getOutPrintWriter().println(getPrivAppPermissionsString(pkg, true));
         return 0;
     }
 
@@ -2713,29 +2694,54 @@
             getErrPrintWriter().println("Error: no package specified.");
             return 1;
         }
-
-        ArraySet<String> privAppPermissions = null;
-        if (isVendorApp(pkg)) {
-            privAppPermissions = SystemConfig.getInstance().getVendorPrivAppDenyPermissions(pkg);
-        } else if (isProductApp(pkg)) {
-            privAppPermissions = SystemConfig.getInstance().getProductPrivAppDenyPermissions(pkg);
-        } else if (isSystemExtApp(pkg)) {
-            privAppPermissions = SystemConfig.getInstance()
-                    .getSystemExtPrivAppDenyPermissions(pkg);
-        } else if (isApexApp(pkg)) {
-            final String apexName = ApexManager.getInstance().getApexModuleNameForPackageName(
-                    getApexPackageNameContainingPackage(pkg));
-            privAppPermissions = SystemConfig.getInstance()
-                    .getApexPrivAppDenyPermissions(apexName, pkg);
-        } else {
-            privAppPermissions = SystemConfig.getInstance().getPrivAppDenyPermissions(pkg);
-        }
-
-        getOutPrintWriter().println(privAppPermissions == null
-                ? "{}" : privAppPermissions.toString());
+        getOutPrintWriter().println(getPrivAppPermissionsString(pkg, false));
         return 0;
     }
 
+    @NonNull
+    private String getPrivAppPermissionsString(@NonNull String packageName, boolean allowed) {
+        final PermissionAllowlist permissionAllowlist =
+                SystemConfig.getInstance().getPermissionAllowlist();
+        final ArrayMap<String, ArrayMap<String, Boolean>> privAppPermissions;
+        if (isVendorApp(packageName)) {
+            privAppPermissions = permissionAllowlist.getVendorPrivilegedAppAllowlist();
+        } else if (isProductApp(packageName)) {
+            privAppPermissions = permissionAllowlist.getProductPrivilegedAppAllowlist();
+        } else if (isSystemExtApp(packageName)) {
+            privAppPermissions = permissionAllowlist.getSystemExtPrivilegedAppAllowlist();
+        } else if (isApexApp(packageName)) {
+            final String moduleName = ApexManager.getInstance().getApexModuleNameForPackageName(
+                    getApexPackageNameContainingPackage(packageName));
+            privAppPermissions = permissionAllowlist.getApexPrivilegedAppAllowlists()
+                    .get(moduleName);
+        } else {
+            privAppPermissions = permissionAllowlist.getPrivilegedAppAllowlist();
+        }
+        final ArrayMap<String, Boolean> permissions = privAppPermissions != null
+                ? privAppPermissions.get(packageName) : null;
+        if (permissions == null) {
+            return "{}";
+        }
+        final StringBuilder result = new StringBuilder("{");
+        boolean isFirstPermission = true;
+        final int permissionsSize = permissions.size();
+        for (int i = 0; i < permissionsSize; i++) {
+            boolean permissionAllowed = permissions.valueAt(i);
+            if (permissionAllowed != allowed) {
+                continue;
+            }
+            if (isFirstPermission) {
+                isFirstPermission = false;
+            } else {
+                result.append(", ");
+            }
+            String permissionName = permissions.keyAt(i);
+            result.append(permissionName);
+        }
+        result.append("}");
+        return result.toString();
+    }
+
     private int runGetOemPermissions() {
         final String pkg = getNextArg();
         if (pkg == null) {
@@ -2743,7 +2749,7 @@
             return 1;
         }
         final Map<String, Boolean> oemPermissions = SystemConfig.getInstance()
-                .getOemPermissions(pkg);
+                .getPermissionAllowlist().getOemAppAllowlist().get(pkg);
         if (oemPermissions == null || oemPermissions.isEmpty()) {
             getOutPrintWriter().println("{}");
         } else {
diff --git a/services/core/java/com/android/server/pm/PackageMetrics.java b/services/core/java/com/android/server/pm/PackageMetrics.java
index 81f1a98..8252a9fa 100644
--- a/services/core/java/com/android/server/pm/PackageMetrics.java
+++ b/services/core/java/com/android/server/pm/PackageMetrics.java
@@ -19,6 +19,7 @@
 import static android.os.Process.INVALID_UID;
 
 import android.annotation.IntDef;
+import android.app.admin.SecurityLog;
 import android.content.pm.PackageManager;
 import android.content.pm.parsing.ApkLiteParseUtils;
 import android.util.Pair;
@@ -67,8 +68,8 @@
         mInstallRequest = installRequest;
     }
 
-    public void onInstallSucceed() {
-        // TODO(b/239722919): report to SecurityLog if on work profile or managed device
+    public void onInstallSucceed(int userId) {
+        reportInstallationToSecurityLog(userId);
         reportInstallationStats(true /* success */);
     }
 
@@ -77,8 +78,13 @@
     }
 
     private void reportInstallationStats(boolean success) {
-        UserManagerInternal userManagerInternal =
+        final UserManagerInternal userManagerInternal =
                 LocalServices.getService(UserManagerInternal.class);
+        if (userManagerInternal == null) {
+            // UserManagerService is not available. Skip metrics reporting.
+            return;
+        }
+
         final long installDurationMillis =
                 System.currentTimeMillis() - mInstallStartTimestampMillis;
         // write to stats
@@ -196,12 +202,17 @@
         }
     }
 
-    public static void onUninstallSucceeded(PackageRemovedInfo info, int deleteFlags,
-            UserManagerInternal userManagerInternal) {
+    public static void onUninstallSucceeded(PackageRemovedInfo info, int deleteFlags, int userId) {
         if (info.mIsUpdate) {
             // Not logging uninstalls caused by app updates
             return;
         }
+        final UserManagerInternal userManagerInternal =
+                LocalServices.getService(UserManagerInternal.class);
+        if (userManagerInternal == null) {
+            // UserManagerService is not available. Skip metrics reporting.
+            return;
+        }
         final int[] removedUsers = info.mRemovedUsers;
         final int[] removedUserTypes = userManagerInternal.getUserTypesForStatsd(removedUsers);
         final int[] originalUsers = info.mOrigUsers;
@@ -210,6 +221,9 @@
                 info.mUid, removedUsers, removedUserTypes, originalUsers, originalUserTypes,
                 deleteFlags, PackageManager.DELETE_SUCCEEDED, info.mIsRemovedPackageSystemUpdate,
                 !info.mRemovedForAllUsers);
+        final String packageName = info.mRemovedPackage;
+        final long versionCode = info.mRemovedPackageVersionCode;
+        reportUninstallationToSecurityLog(packageName, versionCode, userId);
     }
 
     public static void onVerificationFailed(VerifyingSession verifyingSession) {
@@ -242,4 +256,32 @@
                 verifyingSession.isStaged() /* is_staged */
         );
     }
+
+    private void reportInstallationToSecurityLog(int userId) {
+        if (!SecurityLog.isLoggingEnabled()) {
+            return;
+        }
+        final PackageSetting ps = mInstallRequest.getScannedPackageSetting();
+        if (ps == null) {
+            return;
+        }
+        final String packageName = ps.getPackageName();
+        final long versionCode = ps.getVersionCode();
+        if (!mInstallRequest.isInstallReplace()) {
+            SecurityLog.writeEvent(SecurityLog.TAG_PACKAGE_INSTALLED, packageName, versionCode,
+                    userId);
+        } else {
+            SecurityLog.writeEvent(SecurityLog.TAG_PACKAGE_UPDATED, packageName, versionCode,
+                    userId);
+        }
+    }
+
+    private static void reportUninstallationToSecurityLog(String packageName, long versionCode,
+            int userId) {
+        if (!SecurityLog.isLoggingEnabled()) {
+            return;
+        }
+        SecurityLog.writeEvent(SecurityLog.TAG_PACKAGE_UNINSTALLED, packageName, versionCode,
+                userId);
+    }
 }
diff --git a/services/core/java/com/android/server/pm/PackageRemovedInfo.java b/services/core/java/com/android/server/pm/PackageRemovedInfo.java
index dd580a5..c762fd3 100644
--- a/services/core/java/com/android/server/pm/PackageRemovedInfo.java
+++ b/services/core/java/com/android/server/pm/PackageRemovedInfo.java
@@ -51,6 +51,7 @@
     boolean mRemovedForAllUsers;
     boolean mIsStaticSharedLib;
     boolean mIsExternal;
+    long mRemovedPackageVersionCode;
     // a two dimensional array mapping userId to the set of appIds that can receive notice
     // of package changes
     SparseArray<int[]> mBroadcastAllowList;
diff --git a/services/core/java/com/android/server/pm/RemovePackageHelper.java b/services/core/java/com/android/server/pm/RemovePackageHelper.java
index 8c58397..41985e3 100644
--- a/services/core/java/com/android/server/pm/RemovePackageHelper.java
+++ b/services/core/java/com/android/server/pm/RemovePackageHelper.java
@@ -275,6 +275,7 @@
             outInfo.populateUsers(deletedPs.queryInstalledUsers(
                     mUserManagerInternal.getUserIds(), true), deletedPs);
             outInfo.mIsExternal = deletedPs.isExternalStorage();
+            outInfo.mRemovedPackageVersionCode = deletedPs.getVersionCode();
         }
 
         removePackageLI(deletedPs.getPackageName(), (flags & PackageManager.DELETE_CHATTY) != 0);
diff --git a/services/core/java/com/android/server/pm/ResolveIntentHelper.java b/services/core/java/com/android/server/pm/ResolveIntentHelper.java
index fada577..622c6ee 100644
--- a/services/core/java/com/android/server/pm/ResolveIntentHelper.java
+++ b/services/core/java/com/android/server/pm/ResolveIntentHelper.java
@@ -52,6 +52,7 @@
 
 import com.android.internal.app.ResolverActivity;
 import com.android.internal.util.ArrayUtils;
+import com.android.internal.util.FrameworkStatsLog;
 import com.android.server.am.ActivityManagerService;
 import com.android.server.compat.PlatformCompat;
 import com.android.server.pm.pkg.AndroidPackage;
@@ -102,7 +103,8 @@
     }
 
     private static void filterNonExportedComponents(Intent intent, int filterCallingUid,
-            List<ResolveInfo> query, PlatformCompat platformCompat, Computer computer) {
+            List<ResolveInfo> query, PlatformCompat platformCompat, String resolvedType,
+            Computer computer) {
         if (query == null
                 || intent.getPackage() != null
                 || intent.getComponent() != null
@@ -113,21 +115,24 @@
         String callerPackage = caller == null ? "Not specified" : caller.getPackageName();
         for (int i = query.size() - 1; i >= 0; i--) {
             if (!query.get(i).getComponentInfo().exported) {
-                if (!platformCompat.isChangeEnabledByUid(
+                boolean hasToBeExportedToMatch = platformCompat.isChangeEnabledByUid(
                         ActivityManagerService.IMPLICIT_INTENTS_ONLY_MATCH_EXPORTED_COMPONENTS,
-                        filterCallingUid)) {
-                    Slog.w(TAG, "Non-exported component not filtered out "
-                            + "(will be filtered out once the app targets U+)- intent: "
-                            + intent.getAction() + ", component: "
-                            + query.get(i).getComponentInfo()
-                            .getComponentName().flattenToShortString()
-                            + ", starter: " + callerPackage);
+                        filterCallingUid);
+                String[] categories = intent.getCategories() == null ? new String[0]
+                        : intent.getCategories().toArray(String[]::new);
+                FrameworkStatsLog.write(FrameworkStatsLog.UNSAFE_INTENT_EVENT_REPORTED,
+                        FrameworkStatsLog.UNSAFE_INTENT_EVENT_REPORTED__EVENT_TYPE__INTERNAL_NON_EXPORTED_COMPONENT_MATCH,
+                        filterCallingUid,
+                        query.get(i).getComponentInfo().getComponentName().flattenToShortString(),
+                        callerPackage,
+                        intent.getAction(),
+                        categories,
+                        resolvedType,
+                        intent.getScheme(),
+                        hasToBeExportedToMatch);
+                if (!hasToBeExportedToMatch) {
                     return;
                 }
-                Slog.w(TAG, "Non-exported component filtered out - intent: "
-                        + intent.getAction() + ", component: "
-                        + query.get(i).getComponentInfo().getComponentName().flattenToShortString()
-                        + ", starter: " + callerPackage);
                 query.remove(i);
             }
         }
@@ -173,7 +178,7 @@
                     resolveForStart, true /*allowDynamicSplits*/);
             if (exportedComponentsOnly) {
                 filterNonExportedComponents(intent, filterCallingUid, query,
-                        mPlatformCompat, computer);
+                        mPlatformCompat, resolvedType, computer);
             }
             Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
 
diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java
index bc9f7b2..7fec0eb00f 100644
--- a/services/core/java/com/android/server/pm/Settings.java
+++ b/services/core/java/com/android/server/pm/Settings.java
@@ -814,6 +814,10 @@
         return mPackages;
     }
 
+    WatchedArrayMap<String, PackageSetting> getDisabledSystemPackagesLocked() {
+        return mDisabledSysPackages;
+    }
+
     KeySetManagerService getKeySetManagerService() {
         return mKeySetManagerService;
     }
@@ -2465,7 +2469,7 @@
                 mReadMessages.append("Reading from backup stopped packages file\n");
                 PackageManagerService.reportSettingsProblem(Log.INFO,
                         "Need to read from backup stopped packages file");
-                if (mSettingsFilename.exists()) {
+                if (mStoppedPackagesFilename.exists()) {
                     // If both the backup and normal file exist, we
                     // ignore the normal one since it might have been
                     // corrupted.
diff --git a/services/core/java/com/android/server/pm/ShortcutPackage.java b/services/core/java/com/android/server/pm/ShortcutPackage.java
index 0362ddd..4fddc9c 100644
--- a/services/core/java/com/android/server/pm/ShortcutPackage.java
+++ b/services/core/java/com/android/server/pm/ShortcutPackage.java
@@ -1470,9 +1470,15 @@
         }
 
         // Then make sure none of the activities have more than the max number of shortcuts.
+        int total = 0;
         for (int i = counts.size() - 1; i >= 0; i--) {
-            service.enforceMaxActivityShortcuts(counts.valueAt(i));
+            int count = counts.valueAt(i);
+            service.enforceMaxActivityShortcuts(count);
+            total += count;
         }
+
+        // Finally make sure that the app doesn't have more than the max number of shortcuts.
+        service.enforceMaxAppShortcuts(total);
     }
 
     /**
diff --git a/services/core/java/com/android/server/pm/ShortcutService.java b/services/core/java/com/android/server/pm/ShortcutService.java
index 83720f1..12a33ee 100644
--- a/services/core/java/com/android/server/pm/ShortcutService.java
+++ b/services/core/java/com/android/server/pm/ShortcutService.java
@@ -181,6 +181,9 @@
     static final int DEFAULT_MAX_SHORTCUTS_PER_ACTIVITY = 15;
 
     @VisibleForTesting
+    static final int DEFAULT_MAX_SHORTCUTS_PER_APP = 60;
+
+    @VisibleForTesting
     static final int DEFAULT_MAX_ICON_DIMENSION_DP = 96;
 
     @VisibleForTesting
@@ -257,6 +260,11 @@
         String KEY_MAX_SHORTCUTS = "max_shortcuts";
 
         /**
+         * Key name for the max dynamic shortcuts per app. (int)
+         */
+        String KEY_MAX_SHORTCUTS_PER_APP = "max_shortcuts_per_app";
+
+        /**
          * Key name for icon compression quality, 0-100.
          */
         String KEY_ICON_QUALITY = "icon_quality";
@@ -329,9 +337,14 @@
             new SparseArray<>();
 
     /**
+     * Max number of dynamic + manifest shortcuts that each activity can have at a time.
+     */
+    private int mMaxShortcutsPerActivity;
+
+    /**
      * Max number of dynamic + manifest shortcuts that each application can have at a time.
      */
-    private int mMaxShortcuts;
+    private int mMaxShortcutsPerApp;
 
     /**
      * Max number of updating API calls that each application can make during the interval.
@@ -804,9 +817,12 @@
         mMaxUpdatesPerInterval = Math.max(0, (int) parser.getLong(
                 ConfigConstants.KEY_MAX_UPDATES_PER_INTERVAL, DEFAULT_MAX_UPDATES_PER_INTERVAL));
 
-        mMaxShortcuts = Math.max(0, (int) parser.getLong(
+        mMaxShortcutsPerActivity = Math.max(0, (int) parser.getLong(
                 ConfigConstants.KEY_MAX_SHORTCUTS, DEFAULT_MAX_SHORTCUTS_PER_ACTIVITY));
 
+        mMaxShortcutsPerApp = Math.max(0, (int) parser.getLong(
+                ConfigConstants.KEY_MAX_SHORTCUTS_PER_APP, DEFAULT_MAX_SHORTCUTS_PER_APP));
+
         final int iconDimensionDp = Math.max(1, injectIsLowRamDevice()
                 ? (int) parser.getLong(
                 ConfigConstants.KEY_MAX_ICON_DIMENSION_DP_LOWRAM,
@@ -1746,16 +1762,33 @@
      *                                  {@link #getMaxActivityShortcuts()}.
      */
     void enforceMaxActivityShortcuts(int numShortcuts) {
-        if (numShortcuts > mMaxShortcuts) {
+        if (numShortcuts > mMaxShortcutsPerActivity) {
             throw new IllegalArgumentException("Max number of dynamic shortcuts exceeded");
         }
     }
 
     /**
+     * @throws IllegalArgumentException if {@code numShortcuts} is bigger than
+     *                                  {@link #getMaxAppShortcuts()}.
+     */
+    void enforceMaxAppShortcuts(int numShortcuts) {
+        if (numShortcuts > mMaxShortcutsPerApp) {
+            throw new IllegalArgumentException("Max number of dynamic shortcuts per app exceeded");
+        }
+    }
+
+    /**
      * Return the max number of dynamic + manifest shortcuts for each launcher icon.
      */
     int getMaxActivityShortcuts() {
-        return mMaxShortcuts;
+        return mMaxShortcutsPerActivity;
+    }
+
+    /**
+     * Return the max number of dynamic + manifest shortcuts for each launcher icon.
+     */
+    int getMaxAppShortcuts() {
+        return mMaxShortcutsPerApp;
     }
 
     /**
@@ -2188,6 +2221,8 @@
             ps.ensureNotImmutable(shortcut.getId(), /*ignoreInvisible=*/ true);
             fillInDefaultActivity(Arrays.asList(shortcut));
 
+            enforceMaxAppShortcuts(ps.getShortcutCount());
+
             if (!shortcut.hasRank()) {
                 shortcut.setRank(0);
             }
@@ -2575,7 +2610,7 @@
             throws RemoteException {
         verifyCaller(packageName, userId);
 
-        return mMaxShortcuts;
+        return mMaxShortcutsPerActivity;
     }
 
     @Override
@@ -4724,7 +4759,7 @@
                 pw.print("    maxUpdatesPerInterval: ");
                 pw.println(mMaxUpdatesPerInterval);
                 pw.print("    maxShortcutsPerActivity: ");
-                pw.println(mMaxShortcuts);
+                pw.println(mMaxShortcutsPerActivity);
                 pw.println();
 
                 mStatLogger.dump(pw, "  ");
@@ -5211,7 +5246,7 @@
 
     @VisibleForTesting
     int getMaxShortcutsForTest() {
-        return mMaxShortcuts;
+        return mMaxShortcutsPerActivity;
     }
 
     @VisibleForTesting
diff --git a/services/core/java/com/android/server/pm/UserManagerInternal.java b/services/core/java/com/android/server/pm/UserManagerInternal.java
index 0f920c6..2ae8b52 100644
--- a/services/core/java/com/android/server/pm/UserManagerInternal.java
+++ b/services/core/java/com/android/server/pm/UserManagerInternal.java
@@ -59,6 +59,18 @@
     })
     public @interface UserAssignmentResult {}
 
+    public static final int USER_START_MODE_FOREGROUND = 1;
+    public static final int USER_START_MODE_BACKGROUND = 2;
+    public static final int USER_START_MODE_BACKGROUND_VISIBLE = 3;
+
+    private static final String PREFIX_USER_START_MODE = "USER_START_MODE_";
+    @IntDef(flag = false, prefix = {PREFIX_USER_START_MODE}, value = {
+            USER_START_MODE_FOREGROUND,
+            USER_START_MODE_BACKGROUND,
+            USER_START_MODE_BACKGROUND_VISIBLE
+    })
+    public @interface UserStartMode {}
+
     public interface UserRestrictionsListener {
         /**
          * Called when a user restriction changes.
@@ -141,23 +153,39 @@
     /**
      * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to update
      * whether the device is managed by device owner.
+     *
+     * @deprecated Use methods in {@link android.app.admin.DevicePolicyManagerInternal}.
      */
+    @Deprecated
+    // TODO(b/258213147): Remove
     public abstract void setDeviceManaged(boolean isManaged);
 
     /**
      * Returns whether the device is managed by device owner.
+     *
+     * @deprecated Use methods in {@link android.app.admin.DevicePolicyManagerInternal}.
      */
+    @Deprecated
+    // TODO(b/258213147): Remove
     public abstract boolean isDeviceManaged();
 
     /**
      * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to update
      * whether the user is managed by profile owner.
+     *
+     * @deprecated Use methods in {@link android.app.admin.DevicePolicyManagerInternal}.
      */
+    // TODO(b/258213147): Remove
+    @Deprecated
     public abstract void setUserManaged(int userId, boolean isManaged);
 
     /**
-     * whether a profile owner manages this user.
+     * Whether a profile owner manages this user.
+     *
+     * @deprecated Use methods in {@link android.app.admin.DevicePolicyManagerInternal}.
      */
+    // TODO(b/258213147): Remove
+    @Deprecated
     public abstract boolean isUserManaged(int userId);
 
     /**
@@ -367,8 +395,7 @@
      * pass a valid display id.
      */
     public abstract @UserAssignmentResult int assignUserToDisplayOnStart(@UserIdInt int userId,
-            @UserIdInt int profileGroupId,
-            boolean foreground, int displayId);
+            @UserIdInt int profileGroupId, @UserStartMode int userStartMode, int displayId);
 
     /**
      * Unassigns a user from its current display when it's stopping.
@@ -429,6 +456,13 @@
                 result);
     }
 
+    /**
+     * Gets the user-friendly representation of a user start {@code mode}.
+     */
+    public static String userStartModeToString(@UserStartMode int mode) {
+        return DebugUtils.constantToString(UserManagerInternal.class, PREFIX_USER_START_MODE, mode);
+    }
+
     /** Adds a {@link UserVisibilityListener}. */
     public abstract void addUserVisibilityListener(UserVisibilityListener listener);
 
diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java
index 3234e87..251da84 100644
--- a/services/core/java/com/android/server/pm/UserManagerService.java
+++ b/services/core/java/com/android/server/pm/UserManagerService.java
@@ -93,6 +93,7 @@
 import android.provider.Settings;
 import android.service.voice.VoiceInteractionManagerInternal;
 import android.stats.devicepolicy.DevicePolicyEnums;
+import android.telecom.TelecomManager;
 import android.text.TextUtils;
 import android.util.ArrayMap;
 import android.util.ArraySet;
@@ -126,8 +127,10 @@
 import com.android.server.LockGuard;
 import com.android.server.SystemService;
 import com.android.server.am.UserState;
+import com.android.server.pm.UserManagerInternal.UserAssignmentResult;
 import com.android.server.pm.UserManagerInternal.UserLifecycleListener;
 import com.android.server.pm.UserManagerInternal.UserRestrictionsListener;
+import com.android.server.pm.UserManagerInternal.UserStartMode;
 import com.android.server.pm.UserManagerInternal.UserVisibilityListener;
 import com.android.server.storage.DeviceStorageMonitorInternal;
 import com.android.server.utils.Slogf;
@@ -1970,6 +1973,63 @@
         }
     }
 
+    /**
+     * Returns whether switching users is currently allowed for the provided user.
+     * <p>
+     * Switching users is not allowed in the following cases:
+     * <li>the user is in a phone call</li>
+     * <li>{@link UserManager#DISALLOW_USER_SWITCH} is set</li>
+     * <li>system user hasn't been unlocked yet</li>
+     *
+     * @return A {@link UserManager.UserSwitchabilityResult} flag indicating if the user is
+     * switchable.
+     */
+    public @UserManager.UserSwitchabilityResult int getUserSwitchability(int userId) {
+        checkManageOrInteractPermissionIfCallerInOtherProfileGroup(userId, "getUserSwitchability");
+
+        final TimingsTraceAndSlog t = new TimingsTraceAndSlog();
+        t.traceBegin("getUserSwitchability-" + userId);
+
+        int flags = UserManager.SWITCHABILITY_STATUS_OK;
+
+        t.traceBegin("TM.isInCall");
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final TelecomManager telecomManager = mContext.getSystemService(TelecomManager.class);
+            if (telecomManager != null && telecomManager.isInCall()) {
+                flags |= UserManager.SWITCHABILITY_STATUS_USER_IN_CALL;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+        t.traceEnd();
+
+        t.traceBegin("hasUserRestriction-DISALLOW_USER_SWITCH");
+        if (mLocalService.hasUserRestriction(DISALLOW_USER_SWITCH, userId)) {
+            flags |= UserManager.SWITCHABILITY_STATUS_USER_SWITCH_DISALLOWED;
+        }
+        t.traceEnd();
+
+        // System User is always unlocked in Headless System User Mode, so ignore this flag
+        if (!isHeadlessSystemUserMode()) {
+            t.traceBegin("getInt-ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED");
+            final boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt(
+                    mContext.getContentResolver(),
+                    Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0;
+            t.traceEnd();
+            t.traceBegin("isUserUnlocked-USER_SYSTEM");
+            final boolean systemUserUnlocked = mLocalService.isUserUnlocked(UserHandle.USER_SYSTEM);
+            t.traceEnd();
+
+            if (!allowUserSwitchingWhenSystemUserLocked && !systemUserUnlocked) {
+                flags |= UserManager.SWITCHABILITY_STATUS_SYSTEM_USER_LOCKED;
+            }
+        }
+        t.traceEnd();
+
+        return flags;
+    }
+
     @VisibleForTesting
     boolean isUserSwitcherEnabled(@UserIdInt int mUserId) {
         boolean multiUserSettingOn = Settings.Global.getInt(mContext.getContentResolver(),
@@ -6602,6 +6662,7 @@
             }
         }
 
+        // TODO(b/258213147): Remove
         @Override
         public void setDeviceManaged(boolean isManaged) {
             synchronized (mUsersLock) {
@@ -6609,6 +6670,7 @@
             }
         }
 
+        // TODO(b/258213147): Remove
         @Override
         public boolean isDeviceManaged() {
             synchronized (mUsersLock) {
@@ -6616,6 +6678,7 @@
             }
         }
 
+        // TODO(b/258213147): Remove
         @Override
         public void setUserManaged(@UserIdInt int userId, boolean isManaged) {
             synchronized (mUsersLock) {
@@ -6623,6 +6686,7 @@
             }
         }
 
+        // TODO(b/258213147): Remove
         @Override
         public boolean isUserManaged(@UserIdInt int userId) {
             synchronized (mUsersLock) {
@@ -6919,10 +6983,11 @@
         }
 
         @Override
-        public int assignUserToDisplayOnStart(@UserIdInt int userId, @UserIdInt int profileGroupId,
-                boolean foreground, int displayId) {
+        @UserAssignmentResult
+        public int assignUserToDisplayOnStart(@UserIdInt int userId,
+                @UserIdInt int profileGroupId, @UserStartMode int userStartMode, int displayId) {
             return mUserVisibilityMediator.assignUserToDisplayOnStart(userId, profileGroupId,
-                    foreground, displayId);
+                    userStartMode, displayId);
         }
 
         @Override
diff --git a/services/core/java/com/android/server/pm/UserTypeFactory.java b/services/core/java/com/android/server/pm/UserTypeFactory.java
index 8fb5773..2bb72b8 100644
--- a/services/core/java/com/android/server/pm/UserTypeFactory.java
+++ b/services/core/java/com/android/server/pm/UserTypeFactory.java
@@ -132,7 +132,8 @@
                         .setShowInLauncher(UserProperties.SHOW_IN_LAUNCHER_WITH_PARENT)
                         .setShowInSettings(UserProperties.SHOW_IN_SETTINGS_WITH_PARENT)
                         .setInheritDevicePolicy(UserProperties.INHERIT_DEVICE_POLICY_FROM_PARENT)
-                        .setUseParentsContacts(true));
+                        .setUseParentsContacts(true)
+                        .setUpdateCrossProfileIntentFiltersOnOTA(true));
     }
 
     /**
diff --git a/services/core/java/com/android/server/pm/UserVisibilityMediator.java b/services/core/java/com/android/server/pm/UserVisibilityMediator.java
index 9b9ca10..40d87bc 100644
--- a/services/core/java/com/android/server/pm/UserVisibilityMediator.java
+++ b/services/core/java/com/android/server/pm/UserVisibilityMediator.java
@@ -23,7 +23,11 @@
 import static com.android.server.pm.UserManagerInternal.USER_ASSIGNMENT_RESULT_FAILURE;
 import static com.android.server.pm.UserManagerInternal.USER_ASSIGNMENT_RESULT_SUCCESS_INVISIBLE;
 import static com.android.server.pm.UserManagerInternal.USER_ASSIGNMENT_RESULT_SUCCESS_VISIBLE;
+import static com.android.server.pm.UserManagerInternal.USER_START_MODE_BACKGROUND;
+import static com.android.server.pm.UserManagerInternal.USER_START_MODE_BACKGROUND_VISIBLE;
+import static com.android.server.pm.UserManagerInternal.USER_START_MODE_FOREGROUND;
 import static com.android.server.pm.UserManagerInternal.userAssignmentResultToString;
+import static com.android.server.pm.UserManagerInternal.userStartModeToString;
 
 import android.annotation.IntDef;
 import android.annotation.Nullable;
@@ -43,6 +47,7 @@
 import com.android.internal.util.Preconditions;
 import com.android.server.am.EventLogTags;
 import com.android.server.pm.UserManagerInternal.UserAssignmentResult;
+import com.android.server.pm.UserManagerInternal.UserStartMode;
 import com.android.server.pm.UserManagerInternal.UserVisibilityListener;
 import com.android.server.utils.Slogf;
 
@@ -139,10 +144,11 @@
     }
 
     /**
-     * See {@link UserManagerInternal#assignUserToDisplayOnStart(int, int, boolean, int)}.
+     * See {@link UserManagerInternal#assignUserToDisplayOnStart(int, int, int, int)}.
      */
     public @UserAssignmentResult int assignUserToDisplayOnStart(@UserIdInt int userId,
-            @UserIdInt int unResolvedProfileGroupId, boolean foreground, int displayId) {
+            @UserIdInt int unResolvedProfileGroupId, @UserStartMode int userStartMode,
+            int displayId) {
         Preconditions.checkArgument(!isSpecialUserId(userId), "user id cannot be generic: %d",
                 userId);
         // This method needs to perform 4 actions:
@@ -161,14 +167,16 @@
                 ? userId
                 : unResolvedProfileGroupId;
         if (DBG) {
-            Slogf.d(TAG, "assignUserToDisplayOnStart(%d, %d, %b, %d): actualProfileGroupId=%d",
-                    userId, unResolvedProfileGroupId, foreground, displayId, profileGroupId);
+            Slogf.d(TAG, "assignUserToDisplayOnStart(%d, %d, %s, %d): actualProfileGroupId=%d",
+                    userId, unResolvedProfileGroupId, userStartModeToString(userStartMode),
+                    displayId, profileGroupId);
         }
 
         int result;
         IntArray visibleUsersBefore, visibleUsersAfter;
         synchronized (mLock) {
-            result = getUserVisibilityOnStartLocked(userId, profileGroupId, foreground, displayId);
+            result = getUserVisibilityOnStartLocked(userId, profileGroupId, userStartMode,
+                    displayId);
             if (DBG) {
                 Slogf.d(TAG, "result of getUserVisibilityOnStartLocked(%s)",
                         userAssignmentResultToString(result));
@@ -185,7 +193,7 @@
             visibleUsersBefore = getVisibleUsers();
 
             // Set current user / profiles state
-            if (foreground) {
+            if (userStartMode == USER_START_MODE_FOREGROUND) {
                 mCurrentUserId = userId;
             }
             if (DBG) {
@@ -228,8 +236,23 @@
 
     @GuardedBy("mLock")
     @UserAssignmentResult
-    private int getUserVisibilityOnStartLocked(@UserIdInt int userId,
-            @UserIdInt int profileGroupId, boolean foreground, int displayId) {
+    private int getUserVisibilityOnStartLocked(@UserIdInt int userId, @UserIdInt int profileGroupId,
+            @UserStartMode int userStartMode, int displayId) {
+
+        // Check for invalid combinations first
+        if (userStartMode == USER_START_MODE_BACKGROUND && displayId != DEFAULT_DISPLAY) {
+            Slogf.wtf(TAG, "cannot start user (%d) as BACKGROUND_USER on secondary display (%d) "
+                    + "(it should be BACKGROUND_USER_VISIBLE", userId, displayId);
+            return USER_ASSIGNMENT_RESULT_FAILURE;
+        }
+        if (userStartMode == USER_START_MODE_BACKGROUND_VISIBLE
+                && displayId == DEFAULT_DISPLAY && !isProfile(userId, profileGroupId)) {
+            Slogf.wtf(TAG, "cannot start full user (%d) visible on default display", userId);
+            return USER_ASSIGNMENT_RESULT_FAILURE;
+        }
+
+        boolean foreground = userStartMode == USER_START_MODE_FOREGROUND;
+
         if (displayId != DEFAULT_DISPLAY) {
             if (foreground) {
                 Slogf.w(TAG, "getUserVisibilityOnStartLocked(%d, %d, %b, %d) failed: cannot start "
diff --git a/services/core/java/com/android/server/pm/dex/ArtStatsLogUtils.java b/services/core/java/com/android/server/pm/dex/ArtStatsLogUtils.java
index 9f21097..f0bf1ea8 100644
--- a/services/core/java/com/android/server/pm/dex/ArtStatsLogUtils.java
+++ b/services/core/java/com/android/server/pm/dex/ArtStatsLogUtils.java
@@ -299,7 +299,8 @@
                     apkType,
                     ISA_MAP.getOrDefault(isa,
                             ArtStatsLog.ART_DATUM_REPORTED__ISA__ART_ISA_UNKNOWN),
-                    ArtStatsLog.ART_DATUM_REPORTED__GC__ART_GC_COLLECTOR_TYPE_UNKNOWN);
+                    ArtStatsLog.ART_DATUM_REPORTED__GC__ART_GC_COLLECTOR_TYPE_UNKNOWN,
+                    ArtStatsLog.ART_DATUM_REPORTED__UFFD_SUPPORT__ART_UFFD_SUPPORT_UNKNOWN);
         }
     }
 
diff --git a/services/core/java/com/android/server/pm/local/PackageManagerLocalImpl.java b/services/core/java/com/android/server/pm/local/PackageManagerLocalImpl.java
index 024b63e..4e0a11d 100644
--- a/services/core/java/com/android/server/pm/local/PackageManagerLocalImpl.java
+++ b/services/core/java/com/android/server/pm/local/PackageManagerLocalImpl.java
@@ -34,7 +34,6 @@
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
-import java.util.function.Consumer;
 
 /** @hide */
 public class PackageManagerLocalImpl implements PackageManagerLocal {
@@ -105,6 +104,9 @@
         @Nullable
         private Map<String, PackageState> mCachedUnmodifiablePackageStates;
 
+        @Nullable
+        private Map<String, PackageState> mCachedUnmodifiableDisabledSystemPackageStates;
+
         private UnfilteredSnapshotImpl(@NonNull PackageDataSnapshot snapshot) {
             super(snapshot);
         }
@@ -127,10 +129,24 @@
             return mCachedUnmodifiablePackageStates;
         }
 
+        @SuppressWarnings("RedundantSuppression")
+        @NonNull
+        @Override
+        public Map<String, PackageState> getDisabledSystemPackageStates() {
+            checkClosed();
+
+            if (mCachedUnmodifiableDisabledSystemPackageStates == null) {
+                mCachedUnmodifiableDisabledSystemPackageStates =
+                        Collections.unmodifiableMap(mSnapshot.getDisabledSystemPackageStates());
+            }
+            return mCachedUnmodifiableDisabledSystemPackageStates;
+        }
+
         @Override
         public void close() {
             super.close();
             mCachedUnmodifiablePackageStates = null;
+            mCachedUnmodifiableDisabledSystemPackageStates = null;
         }
     }
 
@@ -198,18 +214,5 @@
 
             return mFilteredPackageStates;
         }
-
-        @Override
-        public void forAllPackageStates(@NonNull Consumer<PackageState> consumer) {
-            checkClosed();
-
-            var packageStates = mSnapshot.getPackageStates();
-            for (int index = 0, size = packageStates.size(); index < size; index++) {
-                var packageState = packageStates.valueAt(index);
-                if (!mSnapshot.shouldFilterApplication(packageState, mCallingUid, mUserId)) {
-                    consumer.accept(packageState);
-                }
-            }
-        }
     }
 }
diff --git a/services/core/java/com/android/server/pm/permission/Permission.java b/services/core/java/com/android/server/pm/permission/Permission.java
index 69e7bf1..165c52d 100644
--- a/services/core/java/com/android/server/pm/permission/Permission.java
+++ b/services/core/java/com/android/server/pm/permission/Permission.java
@@ -322,6 +322,10 @@
         return (mPermissionInfo.protectionLevel & PermissionInfo.PROTECTION_FLAG_COMPANION) != 0;
     }
 
+    public boolean isModule() {
+        return (mPermissionInfo.protectionLevel & PermissionInfo.PROTECTION_FLAG_MODULE) != 0;
+    }
+
     public boolean isRetailDemo() {
         return (mPermissionInfo.protectionLevel & PermissionInfo.PROTECTION_FLAG_RETAIL_DEMO) != 0;
     }
diff --git a/services/core/java/com/android/server/pm/permission/PermissionAllowlist.java b/services/core/java/com/android/server/pm/permission/PermissionAllowlist.java
new file mode 100644
index 0000000..3efac81
--- /dev/null
+++ b/services/core/java/com/android/server/pm/permission/PermissionAllowlist.java
@@ -0,0 +1,140 @@
+/*
+ * 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.server.pm.permission;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.util.ArrayMap;
+
+/**
+ * Data class for OEM and privileged app permission allowlist state.
+ */
+public final class PermissionAllowlist {
+    @NonNull
+    private final ArrayMap<String, ArrayMap<String, Boolean>> mOemAppAllowlist = new ArrayMap<>();
+    @NonNull
+    private final ArrayMap<String, ArrayMap<String, Boolean>> mPrivilegedAppAllowlist =
+            new ArrayMap<>();
+    @NonNull
+    private final ArrayMap<String, ArrayMap<String, Boolean>> mVendorPrivilegedAppAllowlist =
+            new ArrayMap<>();
+    @NonNull
+    private final ArrayMap<String, ArrayMap<String, Boolean>> mProductPrivilegedAppAllowlist =
+            new ArrayMap<>();
+    @NonNull
+    private final ArrayMap<String, ArrayMap<String, Boolean>> mSystemExtPrivilegedAppAllowlist =
+            new ArrayMap<>();
+    @NonNull
+    private final ArrayMap<String, ArrayMap<String, ArrayMap<String, Boolean>>>
+            mApexPrivilegedAppAllowlists = new ArrayMap<>();
+
+    @NonNull
+    public ArrayMap<String, ArrayMap<String, Boolean>> getOemAppAllowlist() {
+        return mOemAppAllowlist;
+    }
+
+    @NonNull
+    public ArrayMap<String, ArrayMap<String, Boolean>> getPrivilegedAppAllowlist() {
+        return mPrivilegedAppAllowlist;
+    }
+
+    @NonNull
+    public ArrayMap<String, ArrayMap<String, Boolean>> getVendorPrivilegedAppAllowlist() {
+        return mVendorPrivilegedAppAllowlist;
+    }
+
+    @NonNull
+    public ArrayMap<String, ArrayMap<String, Boolean>> getProductPrivilegedAppAllowlist() {
+        return mProductPrivilegedAppAllowlist;
+    }
+
+    @NonNull
+    public ArrayMap<String, ArrayMap<String, Boolean>> getSystemExtPrivilegedAppAllowlist() {
+        return mSystemExtPrivilegedAppAllowlist;
+    }
+
+    @NonNull
+    public ArrayMap<String, ArrayMap<String, ArrayMap<String, Boolean>>>
+            getApexPrivilegedAppAllowlists() {
+        return mApexPrivilegedAppAllowlists;
+    }
+
+    @Nullable
+    public Boolean getOemAppAllowlistState(@NonNull String packageName,
+            @NonNull String permissionName) {
+        ArrayMap<String, Boolean> permissions = mOemAppAllowlist.get(packageName);
+        if (permissions == null) {
+            return null;
+        }
+        return permissions.get(permissionName);
+    }
+
+    @Nullable
+    public Boolean getPrivilegedAppAllowlistState(@NonNull String packageName,
+            @NonNull String permissionName) {
+        ArrayMap<String, Boolean> permissions = mPrivilegedAppAllowlist.get(packageName);
+        if (permissions == null) {
+            return null;
+        }
+        return permissions.get(permissionName);
+    }
+
+    @Nullable
+    public Boolean getVendorPrivilegedAppAllowlistState(@NonNull String packageName,
+            @NonNull String permissionName) {
+        ArrayMap<String, Boolean> permissions = mVendorPrivilegedAppAllowlist.get(packageName);
+        if (permissions == null) {
+            return null;
+        }
+        return permissions.get(permissionName);
+    }
+
+    @Nullable
+    public Boolean getProductPrivilegedAppAllowlistState(@NonNull String packageName,
+            @NonNull String permissionName) {
+        ArrayMap<String, Boolean> permissions = mProductPrivilegedAppAllowlist.get(packageName);
+        if (permissions == null) {
+            return null;
+        }
+        return permissions.get(permissionName);
+    }
+
+    @Nullable
+    public Boolean getSystemExtPrivilegedAppAllowlistState(@NonNull String packageName,
+            @NonNull String permissionName) {
+        ArrayMap<String, Boolean> permissions = mSystemExtPrivilegedAppAllowlist.get(packageName);
+        if (permissions == null) {
+            return null;
+        }
+        return permissions.get(permissionName);
+    }
+
+    @Nullable
+    public Boolean getApexPrivilegedAppAllowlistState(@NonNull String moduleName,
+            @NonNull String packageName, @NonNull String permissionName) {
+        ArrayMap<String, ArrayMap<String, Boolean>> allowlist =
+                mApexPrivilegedAppAllowlists.get(moduleName);
+        if (allowlist == null) {
+            return null;
+        }
+        ArrayMap<String, Boolean> permissions = allowlist.get(packageName);
+        if (permissions == null) {
+            return null;
+        }
+        return permissions.get(permissionName);
+    }
+}
diff --git a/services/core/java/com/android/server/pm/permission/PermissionManagerServiceImpl.java b/services/core/java/com/android/server/pm/permission/PermissionManagerServiceImpl.java
index e56edeb..f9c0deb 100644
--- a/services/core/java/com/android/server/pm/permission/PermissionManagerServiceImpl.java
+++ b/services/core/java/com/android/server/pm/permission/PermissionManagerServiceImpl.java
@@ -238,6 +238,8 @@
         NOTIFICATION_PERMISSIONS.add(Manifest.permission.POST_NOTIFICATIONS);
     }
 
+    @NonNull private final ApexManager mApexManager;
+
     /** Set of source package names for Privileged Permission Allowlist */
     private final ArraySet<String> mPrivilegedPermissionAllowlistSourcePackageNames =
             new ArraySet<>();
@@ -421,6 +423,7 @@
         mPackageManagerInt = LocalServices.getService(PackageManagerInternal.class);
         mUserManagerInt = LocalServices.getService(UserManagerInternal.class);
         mIsLeanback = availableFeatures.containsKey(PackageManager.FEATURE_LEANBACK);
+        mApexManager = ApexManager.getInstance();
 
         mPrivilegedPermissionAllowlistSourcePackageNames.add(PLATFORM_PACKAGE_NAME);
         // PackageManager.hasSystemFeature() is not used here because PackageManagerService
@@ -3309,16 +3312,12 @@
             return true;
         }
         final String permissionName = permission.getName();
-        final ApexManager apexManager = ApexManager.getInstance();
         final String containingApexPackageName =
-                apexManager.getActiveApexPackageNameContainingPackage(packageName);
-        if (isInSystemConfigPrivAppPermissions(pkg, permissionName,
-                containingApexPackageName)) {
-            return true;
-        }
-        if (isInSystemConfigPrivAppDenyPermissions(pkg, permissionName,
-                containingApexPackageName)) {
-            return false;
+                mApexManager.getActiveApexPackageNameContainingPackage(packageName);
+        final Boolean allowlistState = getPrivilegedPermissionAllowlistState(pkg, permissionName,
+                containingApexPackageName);
+        if (allowlistState != null) {
+            return allowlistState;
         }
         // Updated system apps do not need to be allowlisted
         if (packageSetting.getTransientState().isUpdatedSystemApp()) {
@@ -3354,62 +3353,43 @@
         return !RoSystemProperties.CONTROL_PRIVAPP_PERMISSIONS_ENFORCE;
     }
 
-    private boolean isInSystemConfigPrivAppPermissions(@NonNull AndroidPackage pkg,
-            @NonNull String permission, String containingApexPackageName) {
-        final SystemConfig systemConfig = SystemConfig.getInstance();
-        final Set<String> permissions;
+    @Nullable
+    private Boolean getPrivilegedPermissionAllowlistState(@NonNull AndroidPackage pkg,
+            @NonNull String permissionName, String containingApexPackageName) {
+        final PermissionAllowlist permissionAllowlist =
+                SystemConfig.getInstance().getPermissionAllowlist();
+        final String packageName = pkg.getPackageName();
         if (pkg.isVendor()) {
-            permissions = systemConfig.getVendorPrivAppPermissions(pkg.getPackageName());
+            return permissionAllowlist.getVendorPrivilegedAppAllowlistState(packageName,
+                    permissionName);
         } else if (pkg.isProduct()) {
-            permissions = systemConfig.getProductPrivAppPermissions(pkg.getPackageName());
+            return permissionAllowlist.getProductPrivilegedAppAllowlistState(packageName,
+                    permissionName);
         } else if (pkg.isSystemExt()) {
-            permissions = systemConfig.getSystemExtPrivAppPermissions(pkg.getPackageName());
+            return permissionAllowlist.getSystemExtPrivilegedAppAllowlistState(packageName,
+                    permissionName);
         } else if (containingApexPackageName != null) {
-            final ApexManager apexManager = ApexManager.getInstance();
-            final String apexName = apexManager.getApexModuleNameForPackageName(
-                    containingApexPackageName);
-            final Set<String> privAppPermissions = systemConfig.getPrivAppPermissions(
-                    pkg.getPackageName());
-            final Set<String> apexPermissions = systemConfig.getApexPrivAppPermissions(
-                    apexName, pkg.getPackageName());
-            if (privAppPermissions != null) {
+            final Boolean nonApexAllowlistState =
+                    permissionAllowlist.getPrivilegedAppAllowlistState(packageName, permissionName);
+            if (nonApexAllowlistState != null) {
                 // TODO(andreionea): Remove check as soon as all apk-in-apex
                 // permission allowlists are migrated.
                 Slog.w(TAG, "Package " + pkg.getPackageName() + " is an APK in APEX,"
                         + " but has permission allowlist on the system image. Please bundle the"
                         + " allowlist in the " + containingApexPackageName + " APEX instead.");
-                if (apexPermissions != null) {
-                    permissions = new ArraySet<>(privAppPermissions);
-                    permissions.addAll(apexPermissions);
-                } else {
-                    permissions = privAppPermissions;
-                }
-            } else {
-                permissions = apexPermissions;
             }
+            final String moduleName = mApexManager.getApexModuleNameForPackageName(
+                    containingApexPackageName);
+            final Boolean apexAllowlistState =
+                    permissionAllowlist.getApexPrivilegedAppAllowlistState(moduleName, packageName,
+                            permissionName);
+            if (apexAllowlistState != null) {
+                return apexAllowlistState;
+            }
+            return nonApexAllowlistState;
         } else {
-            permissions = systemConfig.getPrivAppPermissions(pkg.getPackageName());
+            return permissionAllowlist.getPrivilegedAppAllowlistState(packageName, permissionName);
         }
-        return CollectionUtils.contains(permissions, permission);
-    }
-
-    private boolean isInSystemConfigPrivAppDenyPermissions(@NonNull AndroidPackage pkg,
-            @NonNull String permission, String containingApexPackageName) {
-        final SystemConfig systemConfig = SystemConfig.getInstance();
-        final Set<String> permissions;
-        if (pkg.isVendor()) {
-            permissions = systemConfig.getVendorPrivAppDenyPermissions(pkg.getPackageName());
-        } else if (pkg.isProduct()) {
-            permissions = systemConfig.getProductPrivAppDenyPermissions(pkg.getPackageName());
-        } else if (pkg.isSystemExt()) {
-            permissions = systemConfig.getSystemExtPrivAppDenyPermissions(pkg.getPackageName());
-        } else if (containingApexPackageName != null) {
-            permissions = systemConfig.getApexPrivAppDenyPermissions(containingApexPackageName,
-                    pkg.getPackageName());
-        } else {
-            permissions = systemConfig.getPrivAppDenyPermissions(pkg.getPackageName());
-        }
-        return CollectionUtils.contains(permissions, permission);
     }
 
     private boolean shouldGrantPermissionBySignature(@NonNull AndroidPackage pkg,
@@ -3582,6 +3562,11 @@
             // Special permission for the recents app.
             allowed = true;
         }
+        if (!allowed && bp.isModule() && mApexManager.getActiveApexPackageNameContainingPackage(
+                pkg.getPackageName()) != null) {
+            // Special permission granted for APKs inside APEX modules.
+            allowed = true;
+        }
         return allowed;
     }
 
@@ -3606,8 +3591,8 @@
             return false;
         }
         // all oem permissions must explicitly be granted or denied
-        final Boolean granted =
-                SystemConfig.getInstance().getOemPermissions(pkg.getPackageName()).get(permission);
+        final Boolean granted = SystemConfig.getInstance().getPermissionAllowlist()
+                .getOemAppAllowlistState(pkg.getPackageName(), permission);
         if (granted == null) {
             throw new IllegalStateException("OEM permission " + permission
                     + " requested by package " + pkg.getPackageName()
diff --git a/services/core/java/com/android/server/pm/snapshot/PackageDataSnapshot.java b/services/core/java/com/android/server/pm/snapshot/PackageDataSnapshot.java
index b2080b2..90a0c7c 100644
--- a/services/core/java/com/android/server/pm/snapshot/PackageDataSnapshot.java
+++ b/services/core/java/com/android/server/pm/snapshot/PackageDataSnapshot.java
@@ -16,7 +16,6 @@
 
 package com.android.server.pm.snapshot;
 
-import android.annotation.SystemApi;
 import android.content.pm.PackageManagerInternal;
 
 import com.android.server.pm.Computer;
@@ -32,6 +31,5 @@
  *
  * @hide
  */
-@SystemApi(client = SystemApi.Client.SYSTEM_SERVER)
 public interface PackageDataSnapshot {
 }
diff --git a/services/core/java/com/android/server/policy/LegacyGlobalActions.java b/services/core/java/com/android/server/policy/LegacyGlobalActions.java
index 54ece73..983b7f4 100644
--- a/services/core/java/com/android/server/policy/LegacyGlobalActions.java
+++ b/services/core/java/com/android/server/policy/LegacyGlobalActions.java
@@ -283,7 +283,7 @@
                 mItems.add(mAirplaneModeOn);
             } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
                 if (Settings.Global.getInt(mContext.getContentResolver(),
-                        Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) {
+                        Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserAdmin()) {
                     mItems.add(new BugReportAction());
                 }
             } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) {
@@ -535,9 +535,9 @@
         }
     }
 
-    private boolean isCurrentUserOwner() {
+    private boolean isCurrentUserAdmin() {
         UserInfo currentUser = getCurrentUser();
-        return currentUser == null || currentUser.isPrimary();
+        return currentUser == null || currentUser.isAdmin();
     }
 
     private void addUsersToMenu(ArrayList<Action> items) {
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
index 2f0f88a..b5d4afe 100644
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -1054,6 +1054,19 @@
             return;
         }
 
+        // Make sure the device locks. Unfortunately, this has the side-effect of briefly revealing
+        // the lock screen before the dream appears. Note that this locking behavior needs to
+        // happen regardless of whether we end up dreaming (below) or not.
+        // TODO(b/261662912): Find a better way to lock the device that doesn't result in jank.
+        lockNow(null);
+
+        // Don't dream if the user isn't user zero.
+        // TODO(b/261907079): Move this check to DreamManagerService#canStartDreamingInternal().
+        if (ActivityManager.getCurrentUser() != UserHandle.USER_SYSTEM) {
+            noDreamAction.run();
+            return;
+        }
+
         final DreamManagerInternal dreamManagerInternal = getDreamManagerInternal();
         if (dreamManagerInternal == null || !dreamManagerInternal.canStartDreaming(isScreenOn)) {
             noDreamAction.run();
@@ -1714,6 +1727,11 @@
         }
     }
 
+    private void showSystemSettings() {
+        startActivityAsUser(new Intent(android.provider.Settings.ACTION_SETTINGS),
+                UserHandle.CURRENT_OR_SELF);
+    }
+
     private void showPictureInPictureMenu(KeyEvent event) {
         if (DEBUG_INPUT) Log.d(TAG, "showPictureInPictureMenu event=" + event);
         mHandler.removeMessages(MSG_SHOW_PICTURE_IN_PICTURE_MENU);
@@ -2868,16 +2886,7 @@
 
         switch(keyCode) {
             case KeyEvent.KEYCODE_HOME:
-                // First we always handle the home key here, so applications
-                // can never break it, although if keyguard is on, we do let
-                // it handle it, because that gives us the correct 5 second
-                // timeout.
-                DisplayHomeButtonHandler handler = mDisplayHomeButtonHandlers.get(displayId);
-                if (handler == null) {
-                    handler = new DisplayHomeButtonHandler(displayId);
-                    mDisplayHomeButtonHandlers.put(displayId, handler);
-                }
-                return handler.handleHomeButton(focusedToken, event);
+                return handleHomeShortcuts(displayId, focusedToken, event);
             case KeyEvent.KEYCODE_MENU:
                 // Hijack modified menu keys for debugging features
                 final int chordBug = KeyEvent.META_SHIFT_ON;
@@ -2891,6 +2900,11 @@
                     }
                 }
                 break;
+            case KeyEvent.KEYCODE_RECENT_APPS:
+                if (down && repeatCount == 0) {
+                    showRecentApps(false /* triggeredFromAltTab */);
+                }
+                return key_consumed;
             case KeyEvent.KEYCODE_APP_SWITCH:
                 if (!keyguardOn) {
                     if (down && repeatCount == 0) {
@@ -2900,6 +2914,25 @@
                     }
                 }
                 return key_consumed;
+            case KeyEvent.KEYCODE_A:
+                if (down && event.isMetaPressed()) {
+                    launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD,
+                            event.getDeviceId(),
+                            event.getEventTime(), AssistUtils.INVOCATION_TYPE_UNKNOWN);
+                    return key_consumed;
+                }
+                break;
+            case KeyEvent.KEYCODE_H:
+                if (down && event.isMetaPressed()) {
+                    return handleHomeShortcuts(displayId, focusedToken, event);
+                }
+                break;
+            case KeyEvent.KEYCODE_I:
+                if (down && event.isMetaPressed()) {
+                    showSystemSettings();
+                    return key_consumed;
+                }
+                break;
             case KeyEvent.KEYCODE_N:
                 if (down && event.isMetaPressed()) {
                     IStatusBarService service = getStatusBarService();
@@ -2933,6 +2966,11 @@
                 if (down && event.isMetaPressed() && event.isCtrlPressed() && repeatCount == 0) {
                     enterStageSplitFromRunningApp(true /* leftOrTop */);
                     return key_consumed;
+                } else if (!down && event.isMetaPressed()) {
+                    boolean backKeyHandled = backKeyPress();
+                    if (backKeyHandled) {
+                        return key_consumed;
+                    }
                 }
                 break;
             case KeyEvent.KEYCODE_DPAD_RIGHT:
@@ -2941,6 +2979,14 @@
                     return key_consumed;
                 }
                 break;
+            case KeyEvent.KEYCODE_GRAVE:
+                if (!down && event.isMetaPressed()) {
+                    boolean backKeyHandled = backKeyPress();
+                    if (backKeyHandled) {
+                        return key_consumed;
+                    }
+                }
+                break;
             case KeyEvent.KEYCODE_SLASH:
                 if (down && repeatCount == 0 && event.isMetaPressed() && !keyguardOn) {
                     toggleKeyboardShortcutsMenu(event.getDeviceId());
@@ -3040,12 +3086,13 @@
                 }
                 break;
             case KeyEvent.KEYCODE_TAB:
-                if (event.isMetaPressed()) {
-                    // Pass through keyboard navigation keys.
-                    return key_not_consumed;
-                }
-                // Display task switcher for ALT-TAB.
-                if (down && repeatCount == 0) {
+                if (down && event.isMetaPressed()) {
+                    if (!keyguardOn && isUserSetupComplete()) {
+                        showRecentApps(false);
+                        return key_consumed;
+                    }
+                } else if (down && repeatCount == 0) {
+                    // Display task switcher for ALT-TAB.
                     if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
                         final int shiftlessModifiers =
                                 event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
@@ -3100,9 +3147,7 @@
                         mPendingCapsLockToggle = false;
                     } else if (mPendingMetaAction) {
                         if (!canceled) {
-                            launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD,
-                                    event.getDeviceId(),
-                                    event.getEventTime(), AssistUtils.INVOCATION_TYPE_UNKNOWN);
+                            // TODO: launch all apps here.
                         }
                         mPendingMetaAction = false;
                     }
@@ -3157,6 +3202,19 @@
         return key_not_consumed;
     }
 
+    private int handleHomeShortcuts(int displayId, IBinder focusedToken, KeyEvent event) {
+        // First we always handle the home key here, so applications
+        // can never break it, although if keyguard is on, we do let
+        // it handle it, because that gives us the correct 5 second
+        // timeout.
+        DisplayHomeButtonHandler handler = mDisplayHomeButtonHandlers.get(displayId);
+        if (handler == null) {
+            handler = new DisplayHomeButtonHandler(displayId);
+            mDisplayHomeButtonHandlers.put(displayId, handler);
+        }
+        return handler.handleHomeButton(focusedToken, event);
+    }
+
     private void toggleMicrophoneMuteFromKey() {
         if (mSensorPrivacyManager.supportsSensorToggle(
                 SensorPrivacyManager.TOGGLE_TYPE_SOFTWARE,
diff --git a/services/core/java/com/android/server/power/Notifier.java b/services/core/java/com/android/server/power/Notifier.java
index 1fe82f4..09a7b29 100644
--- a/services/core/java/com/android/server/power/Notifier.java
+++ b/services/core/java/com/android/server/power/Notifier.java
@@ -25,7 +25,6 @@
 import android.content.Context;
 import android.content.IIntentReceiver;
 import android.content.Intent;
-import android.content.IntentFilter;
 import android.hardware.display.DisplayManagerInternal;
 import android.media.AudioManager;
 import android.media.Ringtone;
@@ -67,6 +66,7 @@
 import com.android.server.statusbar.StatusBarManagerInternal;
 
 import java.io.PrintWriter;
+import java.util.UUID;
 import java.util.concurrent.Executor;
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -140,9 +140,8 @@
     private final NotifierHandler mHandler;
     private final Executor mBackgroundExecutor;
     private final Intent mScreenOnIntent;
-    private final Bundle mScreenOnOptions;
     private final Intent mScreenOffIntent;
-    private final Bundle mScreenOffOptions;
+    private final Bundle mScreenOnOffOptions;
 
     // True if the device should suspend when the screen is off due to proximity.
     private final boolean mSuspendWhenScreenOffDueToProximityConfig;
@@ -204,14 +203,11 @@
         mScreenOnIntent.addFlags(
                 Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND
                 | Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS);
-        mScreenOnOptions = BroadcastOptions.makeRemovingMatchingFilter(
-                new IntentFilter(Intent.ACTION_SCREEN_OFF)).toBundle();
         mScreenOffIntent = new Intent(Intent.ACTION_SCREEN_OFF);
         mScreenOffIntent.addFlags(
                 Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND
                 | Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS);
-        mScreenOffOptions = BroadcastOptions.makeRemovingMatchingFilter(
-                new IntentFilter(Intent.ACTION_SCREEN_ON)).toBundle();
+        mScreenOnOffOptions = createScreenOnOffBroadcastOptions();
 
         mSuspendWhenScreenOffDueToProximityConfig = context.getResources().getBoolean(
                 com.android.internal.R.bool.config_suspendWhenScreenOffDueToProximity);
@@ -229,6 +225,25 @@
     }
 
     /**
+     * Create the {@link BroadcastOptions} bundle that will be used with sending the
+     * {@link Intent#ACTION_SCREEN_ON} and {@link Intent#ACTION_SCREEN_OFF} broadcasts.
+     */
+    private Bundle createScreenOnOffBroadcastOptions() {
+        final BroadcastOptions options = BroadcastOptions.makeBasic();
+        // This allows the broadcasting system to discard any older broadcasts
+        // waiting to be delivered to a process.
+        options.setDeliveryGroupPolicy(BroadcastOptions.DELIVERY_GROUP_POLICY_MOST_RECENT);
+        // Set namespace and key to identify which older broadcasts can be discarded.
+        // We could use any strings here but namespace needs to be unlikely to be reused with in
+        // the system_server process, as that could result in potentially discarding some
+        // non-screen on/off related broadcast.
+        options.setDeliveryGroupMatchingKey(
+                UUID.randomUUID().toString(),
+                Intent.ACTION_SCREEN_ON);
+        return options.toBundle();
+    }
+
+    /**
      * Called when a wake lock is acquired.
      */
     public void onWakeLockAcquired(int flags, String tag, String packageName,
@@ -798,7 +813,7 @@
         if (mActivityManagerInternal.isSystemReady()) {
             final boolean ordered = !mActivityManagerInternal.isModernQueueEnabled();
             mActivityManagerInternal.broadcastIntent(mScreenOnIntent, mWakeUpBroadcastDone,
-                    null, ordered, UserHandle.USER_ALL, null, null, mScreenOnOptions);
+                    null, ordered, UserHandle.USER_ALL, null, null, mScreenOnOffOptions);
         } else {
             EventLog.writeEvent(EventLogTags.POWER_SCREEN_BROADCAST_STOP, 2, 1);
             sendNextBroadcast();
@@ -823,7 +838,7 @@
         if (mActivityManagerInternal.isSystemReady()) {
             final boolean ordered = !mActivityManagerInternal.isModernQueueEnabled();
             mActivityManagerInternal.broadcastIntent(mScreenOffIntent, mGoToSleepBroadcastDone,
-                    null, ordered, UserHandle.USER_ALL, null, null, mScreenOffOptions);
+                    null, ordered, UserHandle.USER_ALL, null, null, mScreenOnOffOptions);
         } else {
             EventLog.writeEvent(EventLogTags.POWER_SCREEN_BROADCAST_STOP, 3, 1);
             sendNextBroadcast();
diff --git a/services/core/java/com/android/server/power/PowerGroup.java b/services/core/java/com/android/server/power/PowerGroup.java
index 1c4e143..522c6c8 100644
--- a/services/core/java/com/android/server/power/PowerGroup.java
+++ b/services/core/java/com/android/server/power/PowerGroup.java
@@ -407,16 +407,14 @@
         return mDisplayPowerRequest.policy;
     }
 
-    boolean updateLocked(float screenBrightnessOverride, boolean autoBrightness,
-            boolean useProximitySensor, boolean boostScreenBrightness, int dozeScreenState,
-            float dozeScreenBrightness, boolean overrideDrawWakeLock,
-            PowerSaveState powerSaverState, boolean quiescent, boolean dozeAfterScreenOff,
-            boolean bootCompleted, boolean screenBrightnessBoostInProgress,
-            boolean waitForNegativeProximity) {
+    boolean updateLocked(float screenBrightnessOverride, boolean useProximitySensor,
+            boolean boostScreenBrightness, int dozeScreenState, float dozeScreenBrightness,
+            boolean overrideDrawWakeLock, PowerSaveState powerSaverState, boolean quiescent,
+            boolean dozeAfterScreenOff, boolean bootCompleted,
+            boolean screenBrightnessBoostInProgress, boolean waitForNegativeProximity) {
         mDisplayPowerRequest.policy = getDesiredScreenPolicyLocked(quiescent, dozeAfterScreenOff,
                 bootCompleted, screenBrightnessBoostInProgress);
         mDisplayPowerRequest.screenBrightnessOverride = screenBrightnessOverride;
-        mDisplayPowerRequest.useAutoBrightness = autoBrightness;
         mDisplayPowerRequest.useProximitySensor = useProximitySensor;
         mDisplayPowerRequest.boostScreenBrightness = boostScreenBrightness;
 
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java
index 6e3c827..b5ddc06 100644
--- a/services/core/java/com/android/server/power/PowerManagerService.java
+++ b/services/core/java/com/android/server/power/PowerManagerService.java
@@ -581,10 +581,6 @@
     private boolean mIsFaceDown = false;
     private long mLastFlipTime = 0L;
 
-    // The screen brightness mode.
-    // One of the Settings.System.SCREEN_BRIGHTNESS_MODE_* constants.
-    private int mScreenBrightnessModeSetting;
-
     // The screen brightness setting override from the window manager
     // to allow the current foreground activity to override the brightness.
     private float mScreenBrightnessOverrideFromWindowManager =
@@ -1457,10 +1453,6 @@
             mSystemProperties.set(SYSTEM_PROPERTY_RETAIL_DEMO_ENABLED, retailDemoValue);
         }
 
-        mScreenBrightnessModeSetting = Settings.System.getIntForUser(resolver,
-                Settings.System.SCREEN_BRIGHTNESS_MODE,
-                Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, UserHandle.USER_CURRENT);
-
         mDirty |= DIRTY_SETTINGS;
     }
 
@@ -3432,23 +3424,18 @@
                 final PowerGroup powerGroup = mPowerGroups.valueAt(idx);
                 final int groupId = powerGroup.getGroupId();
 
-                // Determine appropriate screen brightness and auto-brightness adjustments.
-                final boolean autoBrightness;
+                // Determine appropriate screen brightness.
                 final float screenBrightnessOverride;
                 if (!mBootCompleted) {
                     // Keep the brightness steady during boot. This requires the
                     // bootloader brightness and the default brightness to be identical.
-                    autoBrightness = false;
                     screenBrightnessOverride = mScreenBrightnessDefault;
                 } else if (isValidBrightness(mScreenBrightnessOverrideFromWindowManager)) {
-                    autoBrightness = false;
                     screenBrightnessOverride = mScreenBrightnessOverrideFromWindowManager;
                 } else {
-                    autoBrightness = (mScreenBrightnessModeSetting
-                            == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
                     screenBrightnessOverride = PowerManager.BRIGHTNESS_INVALID_FLOAT;
                 }
-                boolean ready = powerGroup.updateLocked(screenBrightnessOverride, autoBrightness,
+                boolean ready = powerGroup.updateLocked(screenBrightnessOverride,
                         shouldUseProximitySensorLocked(), shouldBoostScreenBrightness(),
                         mDozeScreenStateOverrideFromDreamManager,
                         mDozeScreenBrightnessOverrideFromDreamManagerFloat,
@@ -3469,7 +3456,6 @@
                             powerGroup.getUserActivitySummaryLocked())
                             + ", mBootCompleted=" + mBootCompleted
                             + ", screenBrightnessOverride=" + screenBrightnessOverride
-                            + ", useAutoBrightness=" + autoBrightness
                             + ", mScreenBrightnessBoostInProgress="
                             + mScreenBrightnessBoostInProgress
                             + ", sQuiescent=" + sQuiescent);
@@ -4488,7 +4474,6 @@
                     + mMaximumScreenOffTimeoutFromDeviceAdmin + " (enforced="
                     + isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked() + ")");
             pw.println("  mStayOnWhilePluggedInSetting=" + mStayOnWhilePluggedInSetting);
-            pw.println("  mScreenBrightnessModeSetting=" + mScreenBrightnessModeSetting);
             pw.println("  mScreenBrightnessOverrideFromWindowManager="
                     + mScreenBrightnessOverrideFromWindowManager);
             pw.println("  mUserActivityTimeoutOverrideFromWindowManager="
@@ -4866,9 +4851,6 @@
             proto.end(stayOnWhilePluggedInToken);
 
             proto.write(
-                    PowerServiceSettingsAndConfigurationDumpProto.SCREEN_BRIGHTNESS_MODE_SETTING,
-                    mScreenBrightnessModeSetting);
-            proto.write(
                     PowerServiceSettingsAndConfigurationDumpProto
                             .SCREEN_BRIGHTNESS_OVERRIDE_FROM_WINDOW_MANAGER,
                     mScreenBrightnessOverrideFromWindowManager);
diff --git a/services/core/java/com/android/server/power/ThermalManagerService.java b/services/core/java/com/android/server/power/ThermalManagerService.java
index f378588..6b2c6e3 100644
--- a/services/core/java/com/android/server/power/ThermalManagerService.java
+++ b/services/core/java/com/android/server/power/ThermalManagerService.java
@@ -19,16 +19,18 @@
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.content.Context;
+import android.hardware.thermal.IThermal;
+import android.hardware.thermal.IThermalChangedCallback;
+import android.hardware.thermal.TemperatureThreshold;
+import android.hardware.thermal.ThrottlingSeverity;
 import android.hardware.thermal.V1_0.ThermalStatus;
 import android.hardware.thermal.V1_0.ThermalStatusCode;
 import android.hardware.thermal.V1_1.IThermalCallback;
-import android.hardware.thermal.V2_0.IThermalChangedCallback;
-import android.hardware.thermal.V2_0.TemperatureThreshold;
-import android.hardware.thermal.V2_0.ThrottlingSeverity;
 import android.os.Binder;
 import android.os.CoolingDevice;
 import android.os.Handler;
 import android.os.HwBinder;
+import android.os.IBinder;
 import android.os.IThermalEventListener;
 import android.os.IThermalService;
 import android.os.IThermalStatusListener;
@@ -37,6 +39,7 @@
 import android.os.RemoteCallbackList;
 import android.os.RemoteException;
 import android.os.ResultReceiver;
+import android.os.ServiceManager;
 import android.os.ShellCallback;
 import android.os.ShellCommand;
 import android.os.SystemClock;
@@ -56,12 +59,14 @@
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
 
 /**
  * This is a system service that listens to HAL thermal events and dispatch those to listeners.
@@ -98,7 +103,7 @@
     @GuardedBy("mLock")
     private int mStatus;
 
-    /** If override status takes effect*/
+    /** If override status takes effect */
     @GuardedBy("mLock")
     private boolean mIsStatusOverride;
 
@@ -144,6 +149,10 @@
             // Connect to HAL and post to listeners.
             boolean halConnected = (mHalWrapper != null);
             if (!halConnected) {
+                mHalWrapper = new ThermalHalAidlWrapper();
+                halConnected = mHalWrapper.connectToHal();
+            }
+            if (!halConnected) {
                 mHalWrapper = new ThermalHal20Wrapper();
                 halConnected = mHalWrapper.connectToHal();
             }
@@ -684,6 +693,162 @@
         }
     }
 
+    @VisibleForTesting
+    static class ThermalHalAidlWrapper extends ThermalHalWrapper implements IBinder.DeathRecipient {
+        /* Proxy object for the Thermal HAL AIDL service. */
+        private IThermal mInstance = null;
+
+        /** Callback for Thermal HAL AIDL. */
+        private final IThermalChangedCallback mThermalChangedCallback =
+                new IThermalChangedCallback.Stub() {
+                    @Override public void notifyThrottling(
+                            android.hardware.thermal.Temperature temperature)
+                            throws RemoteException {
+                        Temperature svcTemperature = new Temperature(temperature.value,
+                                temperature.type, temperature.name, temperature.throttlingStatus);
+                        final long token = Binder.clearCallingIdentity();
+                        try {
+                            mCallback.onValues(svcTemperature);
+                        } finally {
+                            Binder.restoreCallingIdentity(token);
+                        }
+                    }
+
+            @Override public int getInterfaceVersion() throws RemoteException {
+                return this.VERSION;
+            }
+
+            @Override public String getInterfaceHash() throws RemoteException {
+                return this.HASH;
+            }
+        };
+
+        @Override
+        protected List<Temperature> getCurrentTemperatures(boolean shouldFilter,
+                int type) {
+            synchronized (mHalLock) {
+                final List<Temperature> ret = new ArrayList<>();
+                if (mInstance == null) {
+                    return ret;
+                }
+                try {
+                    final android.hardware.thermal.Temperature[] halRet =
+                            shouldFilter ? mInstance.getTemperaturesWithType(type)
+                                    : mInstance.getTemperatures();
+                    for (android.hardware.thermal.Temperature t : halRet) {
+                        if (!Temperature.isValidStatus(t.throttlingStatus)) {
+                            Slog.e(TAG, "Invalid temperature status " + t.throttlingStatus
+                                    + " received from AIDL HAL");
+                            t.throttlingStatus = Temperature.THROTTLING_NONE;
+                        }
+                        if (shouldFilter && t.type != type) {
+                            continue;
+                        }
+                        ret.add(new Temperature(t.value, t.type, t.name, t.throttlingStatus));
+                    }
+                } catch (RemoteException e) {
+                    Slog.e(TAG, "Couldn't getCurrentTemperatures, reconnecting", e);
+                    connectToHal();
+                }
+                return ret;
+            }
+        }
+
+        @Override
+        protected List<CoolingDevice> getCurrentCoolingDevices(boolean shouldFilter,
+                int type) {
+            synchronized (mHalLock) {
+                final List<CoolingDevice> ret = new ArrayList<>();
+                if (mInstance == null) {
+                    return ret;
+                }
+                try {
+                    final android.hardware.thermal.CoolingDevice[] halRet = shouldFilter
+                            ? mInstance.getCoolingDevicesWithType(type)
+                            : mInstance.getCoolingDevices();
+                    for (android.hardware.thermal.CoolingDevice t : halRet) {
+                        if (!CoolingDevice.isValidType(t.type)) {
+                            Slog.e(TAG, "Invalid cooling device type " + t.type + " from AIDL HAL");
+                            continue;
+                        }
+                        if (shouldFilter && t.type != type) {
+                            continue;
+                        }
+                        ret.add(new CoolingDevice(t.value, t.type, t.name));
+                    }
+                } catch (RemoteException e) {
+                    Slog.e(TAG, "Couldn't getCurrentCoolingDevices, reconnecting", e);
+                    connectToHal();
+                }
+                return ret;
+            }
+        }
+
+        @Override
+        @NonNull protected List<TemperatureThreshold> getTemperatureThresholds(
+                boolean shouldFilter, int type) {
+            synchronized (mHalLock) {
+                final List<TemperatureThreshold> ret = new ArrayList<>();
+                if (mInstance == null) {
+                    return ret;
+                }
+                try {
+                    final TemperatureThreshold[] halRet =
+                            shouldFilter ? mInstance.getTemperatureThresholdsWithType(type)
+                                    : mInstance.getTemperatureThresholds();
+
+                    return Arrays.stream(halRet).filter(t -> t.type == type).collect(
+                            Collectors.toList());
+                } catch (RemoteException e) {
+                    Slog.e(TAG, "Couldn't getTemperatureThresholds, reconnecting...", e);
+                    connectToHal();
+                }
+                return ret;
+            }
+        }
+
+        @Override
+        protected boolean connectToHal() {
+            synchronized (mHalLock) {
+                IBinder binder = Binder.allowBlocking(ServiceManager.waitForDeclaredService(
+                        IThermal.DESCRIPTOR + "/default"));
+                initProxyAndRegisterCallback(binder);
+            }
+            return mInstance != null;
+        }
+
+        @VisibleForTesting
+        void initProxyAndRegisterCallback(IBinder binder) {
+            synchronized (mHalLock) {
+                if (binder != null) {
+                    mInstance = IThermal.Stub.asInterface(binder);
+                    try {
+                        binder.linkToDeath(this, 0);
+                        mInstance.registerThermalChangedCallback(mThermalChangedCallback);
+                    } catch (RemoteException e) {
+                        Slog.e(TAG, "Unable to connect IThermal AIDL instance", e);
+                        mInstance = null;
+                    }
+                }
+            }
+        }
+
+        @Override
+        protected void dump(PrintWriter pw, String prefix) {
+            synchronized (mHalLock) {
+                pw.print(prefix);
+                pw.println(
+                        "ThermalHAL AIDL " + IThermal.VERSION + "  connected: " + (mInstance != null
+                                ? "yes" : "no"));
+            }
+        }
+
+        @Override
+        public synchronized void binderDied() {
+            Slog.w(TAG, "IThermal HAL instance died");
+            mInstance = null;
+        }
+    }
 
     static class ThermalHal10Wrapper extends ThermalHalWrapper {
         /** Proxy object for the Thermal HAL 1.0 service. */
@@ -814,8 +979,8 @@
                             android.hardware.thermal.V1_0.Temperature temperature) {
                         Temperature thermalSvcTemp = new Temperature(
                                 temperature.currentValue, temperature.type, temperature.name,
-                                isThrottling ? ThrottlingSeverity.SEVERE
-                                        : ThrottlingSeverity.NONE);
+                                isThrottling ? Temperature.THROTTLING_SEVERE
+                                        : Temperature.THROTTLING_NONE);
                         final long token = Binder.clearCallingIdentity();
                         try {
                             mCallback.onValues(thermalSvcTemp);
@@ -941,8 +1106,9 @@
         private android.hardware.thermal.V2_0.IThermal mThermalHal20 = null;
 
         /** HWbinder callback for Thermal HAL 2.0. */
-        private final IThermalChangedCallback.Stub mThermalCallback20 =
-                new IThermalChangedCallback.Stub() {
+        private final android.hardware.thermal.V2_0.IThermalChangedCallback.Stub
+                mThermalCallback20 =
+                new android.hardware.thermal.V2_0.IThermalChangedCallback.Stub() {
                     @Override
                     public void notifyThrottling(
                             android.hardware.thermal.V2_0.Temperature temperature) {
@@ -976,7 +1142,7 @@
                                                 temperature.throttlingStatus)) {
                                             Slog.e(TAG, "Invalid status data from HAL");
                                             temperature.throttlingStatus =
-                                                Temperature.THROTTLING_NONE;
+                                                    Temperature.THROTTLING_NONE;
                                         }
                                         ret.add(new Temperature(
                                                 temperature.value, temperature.type,
@@ -1043,7 +1209,9 @@
                     mThermalHal20.getTemperatureThresholds(shouldFilter, type,
                             (status, thresholds) -> {
                                 if (ThermalStatusCode.SUCCESS == status.code) {
-                                    ret.addAll(thresholds);
+                                    ret.addAll(thresholds.stream().map(
+                                            this::convertToAidlTemperatureThreshold).collect(
+                                            Collectors.toList()));
                                 } else {
                                     Slog.e(TAG,
                                             "Couldn't get temperature thresholds because of HAL "
@@ -1057,6 +1225,16 @@
             }
         }
 
+        private TemperatureThreshold convertToAidlTemperatureThreshold(
+                android.hardware.thermal.V2_0.TemperatureThreshold threshold) {
+            final TemperatureThreshold ret = new TemperatureThreshold();
+            ret.name = threshold.name;
+            ret.type = threshold.type;
+            ret.coldThrottlingThresholds = threshold.coldThrottlingThresholds;
+            ret.hotThrottlingThresholds = threshold.hotThrottlingThresholds;
+            return ret;
+        }
+
         @Override
         protected boolean connectToHal() {
             synchronized (mHalLock) {
diff --git a/services/core/java/com/android/server/power/stats/BatteryStatsImpl.java b/services/core/java/com/android/server/power/stats/BatteryStatsImpl.java
index af4fa85..855fcaf 100644
--- a/services/core/java/com/android/server/power/stats/BatteryStatsImpl.java
+++ b/services/core/java/com/android/server/power/stats/BatteryStatsImpl.java
@@ -763,8 +763,6 @@
     @NonNull
     private final BatteryStatsHistory mHistory;
 
-    private BatteryStatsHistoryIterator mBatteryStatsHistoryIterator;
-
     int mStartCount;
 
     /**
@@ -4658,10 +4656,10 @@
         final int mappedUid = mapUid(uid);
         if (type == WAKE_TYPE_PARTIAL) {
             mWakeLockNesting--;
+            if (historyName == null) {
+                historyName = name;
+            }
             if (mRecordAllHistory) {
-                if (historyName == null) {
-                    historyName = name;
-                }
                 if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName,
                         mappedUid, 0)) {
                     mHistory.recordEvent(elapsedRealtimeMs, uptimeMs,
@@ -4669,8 +4667,8 @@
                 }
             }
             if (mWakeLockNesting == 0) {
-                mHistory.recordStateStopEvent(elapsedRealtimeMs, uptimeMs,
-                        HistoryItem.STATE_WAKE_LOCK_FLAG);
+                mHistory.recordWakelockStopEvent(elapsedRealtimeMs, uptimeMs, historyName,
+                        mappedUid);
             }
         }
         if (mappedUid >= 0) {
@@ -11242,17 +11240,11 @@
         return mHistory.getHistoryUsedSize();
     }
 
-    @Override
-    public boolean startIteratingHistoryLocked() {
-        mBatteryStatsHistoryIterator = createBatteryStatsHistoryIterator();
-        return true;
-    }
-
     /**
      * Creates an iterator for battery stats history.
      */
-    @VisibleForTesting
-    public BatteryStatsHistoryIterator createBatteryStatsHistoryIterator() {
+    @Override
+    public BatteryStatsHistoryIterator iterateBatteryStatsHistory() {
         return mHistory.iterate();
     }
 
@@ -11277,17 +11269,6 @@
     }
 
     @Override
-    public boolean getNextHistoryLocked(HistoryItem out) {
-        return mBatteryStatsHistoryIterator.next(out);
-    }
-
-    @Override
-    public void finishIteratingHistoryLocked() {
-        mBatteryStatsHistoryIterator.close();
-        mBatteryStatsHistoryIterator = null;
-    }
-
-    @Override
     public int getStartCount() {
         return mStartCount;
     }
diff --git a/services/core/java/com/android/server/power/stats/BatteryUsageStatsProvider.java b/services/core/java/com/android/server/power/stats/BatteryUsageStatsProvider.java
index c36d950..7da9197 100644
--- a/services/core/java/com/android/server/power/stats/BatteryUsageStatsProvider.java
+++ b/services/core/java/com/android/server/power/stats/BatteryUsageStatsProvider.java
@@ -286,16 +286,15 @@
                 BatteryStats.Uid.PROCESS_STATE_FOREGROUND, realtimeUs,
                 BatteryStats.STATS_SINCE_CHARGED);
 
-        totalForegroundDurationUs += uid.getProcessStateTime(
-                BatteryStats.Uid.PROCESS_STATE_FOREGROUND_SERVICE, realtimeUs,
-                BatteryStats.STATS_SINCE_CHARGED);
-
         return totalForegroundDurationUs / 1000;
     }
 
     private long getProcessBackgroundTimeMs(BatteryStats.Uid uid, long realtimeUs) {
-        return uid.getProcessStateTime(BatteryStats.Uid.PROCESS_STATE_BACKGROUND, realtimeUs,
-                BatteryStats.STATS_SINCE_CHARGED) / 1000;
+        return (uid.getProcessStateTime(BatteryStats.Uid.PROCESS_STATE_BACKGROUND,
+                realtimeUs, BatteryStats.STATS_SINCE_CHARGED)
+                + uid.getProcessStateTime(BatteryStats.Uid.PROCESS_STATE_FOREGROUND_SERVICE,
+                realtimeUs, BatteryStats.STATS_SINCE_CHARGED))
+                / 1000;
     }
 
     private BatteryUsageStats getAggregatedBatteryUsageStats(BatteryUsageStatsQuery query) {
diff --git a/services/core/java/com/android/server/security/rkp/OWNERS b/services/core/java/com/android/server/security/rkp/OWNERS
new file mode 100644
index 0000000..348f940
--- /dev/null
+++ b/services/core/java/com/android/server/security/rkp/OWNERS
@@ -0,0 +1 @@
+file:platform/frameworks/base:master:/core/java/android/security/rkp/OWNERS
diff --git a/services/core/java/com/android/server/security/rkp/RemoteProvisioningService.java b/services/core/java/com/android/server/security/rkp/RemoteProvisioningService.java
new file mode 100644
index 0000000..65a4b38
--- /dev/null
+++ b/services/core/java/com/android/server/security/rkp/RemoteProvisioningService.java
@@ -0,0 +1,126 @@
+/*
+ * 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.server.security.rkp;
+
+import android.content.Context;
+import android.os.Binder;
+import android.os.OutcomeReceiver;
+import android.os.RemoteException;
+import android.security.rkp.IGetKeyCallback;
+import android.security.rkp.IGetRegistrationCallback;
+import android.security.rkp.IRegistration;
+import android.security.rkp.IRemoteProvisioning;
+import android.security.rkp.service.RegistrationProxy;
+import android.util.Log;
+
+import com.android.server.SystemService;
+
+import java.time.Duration;
+
+/**
+ * Implements the remote provisioning system service. This service is backed by a mainline
+ * module, allowing the underlying implementation to be updated. The code here is a thin
+ * proxy for the code in android.security.rkp.service.
+ *
+ * @hide
+ */
+public class RemoteProvisioningService extends SystemService {
+    public static final String TAG = "RemoteProvisionSysSvc";
+    private static final Duration CREATE_REGISTRATION_TIMEOUT = Duration.ofSeconds(10);
+    private final RemoteProvisioningImpl mBinderImpl = new RemoteProvisioningImpl();
+
+    /** @hide */
+    public RemoteProvisioningService(Context context) {
+        super(context);
+    }
+
+    @Override
+    public void onStart() {
+        publishBinderService(Context.REMOTE_PROVISIONING_SERVICE, mBinderImpl);
+    }
+
+    private final class RemoteProvisioningImpl extends IRemoteProvisioning.Stub {
+
+        final class RegistrationBinder extends IRegistration.Stub {
+            static final String TAG = RemoteProvisioningService.TAG;
+            private final RegistrationProxy mRegistration;
+
+            RegistrationBinder(RegistrationProxy registration) {
+                mRegistration = registration;
+            }
+
+            @Override
+            public void getKey(int keyId, IGetKeyCallback callback) {
+                Log.e(TAG, "RegistrationBinder.getKey NOT YET IMPLEMENTED");
+            }
+
+            @Override
+            public void cancelGetKey(IGetKeyCallback callback) {
+                Log.e(TAG, "RegistrationBinder.cancelGetKey NOT YET IMPLEMENTED");
+            }
+
+            @Override
+            public void storeUpgradedKey(byte[] oldKeyBlob, byte[] newKeyBlob) {
+                Log.e(TAG, "RegistrationBinder.storeUpgradedKey NOT YET IMPLEMENTED");
+            }
+        }
+
+        @Override
+        public void getRegistration(String irpcName, IGetRegistrationCallback callback)
+                throws RemoteException {
+            final int callerUid = Binder.getCallingUidOrThrow();
+            final long callingIdentity = Binder.clearCallingIdentity();
+            try {
+                Log.i(TAG, "getRegistration(" + irpcName + ")");
+                RegistrationProxy.createAsync(
+                        getContext(),
+                        callerUid,
+                        irpcName,
+                        CREATE_REGISTRATION_TIMEOUT,
+                        getContext().getMainExecutor(),
+                        new OutcomeReceiver<>() {
+                            @Override
+                            public void onResult(RegistrationProxy registration) {
+                                try {
+                                    callback.onSuccess(new RegistrationBinder(registration));
+                                } catch (RemoteException e) {
+                                    Log.e(TAG, "Error calling success callback", e);
+                                }
+                            }
+
+                            @Override
+                            public void onError(Exception error) {
+                                try {
+                                    callback.onError(error.toString());
+                                } catch (RemoteException e) {
+                                    Log.e(TAG, "Error calling error callback", e);
+                                }
+                            }
+                        });
+            } finally {
+                Binder.restoreCallingIdentity(callingIdentity);
+            }
+        }
+
+        @Override
+        public void cancelGetRegistration(IGetRegistrationCallback callback)
+                throws RemoteException {
+            Log.i(TAG, "cancelGetRegistration()");
+            callback.onError("cancelGetRegistration not yet implemented");
+        }
+    }
+}
diff --git a/services/core/java/com/android/server/sensorprivacy/SensorPrivacyService.java b/services/core/java/com/android/server/sensorprivacy/SensorPrivacyService.java
index ab35dc8..6d39177 100644
--- a/services/core/java/com/android/server/sensorprivacy/SensorPrivacyService.java
+++ b/services/core/java/com/android/server/sensorprivacy/SensorPrivacyService.java
@@ -223,7 +223,7 @@
     }
 
     class SensorPrivacyServiceImpl extends ISensorPrivacyManager.Stub implements
-            AppOpsManager.OnOpNotedListener, AppOpsManager.OnOpStartedListener,
+            AppOpsManager.OnOpNotedInternalListener, AppOpsManager.OnOpStartedListener,
             IBinder.DeathRecipient, UserManagerInternal.UserRestrictionsListener {
 
         private final SensorPrivacyHandler mHandler;
diff --git a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java
index c379abc..6c616e0 100644
--- a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java
+++ b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java
@@ -2408,7 +2408,20 @@
                         metrics.gpuTotalUsageKb,
                         metrics.gpuPrivateAllocationsKb,
                         metrics.dmaBufTotalExportedKb,
-                        metrics.shmemKb));
+                        metrics.shmemKb,
+                        metrics.totalKb,
+                        metrics.freeKb,
+                        metrics.availableKb,
+                        metrics.activeKb,
+                        metrics.inactiveKb,
+                        metrics.activeAnonKb,
+                        metrics.inactiveAnonKb,
+                        metrics.activeFileKb,
+                        metrics.inactiveFileKb,
+                        metrics.swapTotalKb,
+                        metrics.swapFreeKb,
+                        metrics.cmaTotalKb,
+                        metrics.cmaFreeKb));
         return StatsManager.PULL_SUCCESS;
     }
 
diff --git a/services/core/java/com/android/server/stats/pull/SystemMemoryUtil.java b/services/core/java/com/android/server/stats/pull/SystemMemoryUtil.java
index 9ebf59e..2ab4fdf 100644
--- a/services/core/java/com/android/server/stats/pull/SystemMemoryUtil.java
+++ b/services/core/java/com/android/server/stats/pull/SystemMemoryUtil.java
@@ -83,6 +83,19 @@
         result.pageTablesKb = (int) mInfos[Debug.MEMINFO_PAGE_TABLES];
         result.kernelStackKb = (int) mInfos[Debug.MEMINFO_KERNEL_STACK];
         result.shmemKb = (int) mInfos[Debug.MEMINFO_SHMEM];
+        result.totalKb = (int) mInfos[Debug.MEMINFO_TOTAL];
+        result.freeKb = (int) mInfos[Debug.MEMINFO_FREE];
+        result.availableKb = (int) mInfos[Debug.MEMINFO_AVAILABLE];
+        result.activeKb = (int) mInfos[Debug.MEMINFO_ACTIVE];
+        result.inactiveKb = (int) mInfos[Debug.MEMINFO_INACTIVE];
+        result.activeAnonKb = (int) mInfos[Debug.MEMINFO_ACTIVE_ANON];
+        result.inactiveAnonKb = (int) mInfos[Debug.MEMINFO_INACTIVE_ANON];
+        result.activeFileKb = (int) mInfos[Debug.MEMINFO_ACTIVE_FILE];
+        result.inactiveFileKb = (int) mInfos[Debug.MEMINFO_INACTIVE_FILE];
+        result.swapTotalKb = (int) mInfos[Debug.MEMINFO_SWAP_TOTAL];
+        result.swapFreeKb = (int) mInfos[Debug.MEMINFO_SWAP_FREE];
+        result.cmaTotalKb = (int) mInfos[Debug.MEMINFO_CMA_TOTAL];
+        result.cmaFreeKb = (int) mInfos[Debug.MEMINFO_CMA_FREE];
         result.totalIonKb = totalIonKb;
         result.gpuTotalUsageKb = gpuTotalUsageKb;
         result.gpuPrivateAllocationsKb = gpuPrivateAllocationsKb;
@@ -97,6 +110,19 @@
         public int pageTablesKb;
         public int kernelStackKb;
         public int shmemKb;
+        public int totalKb;
+        public int freeKb;
+        public int availableKb;
+        public int activeKb;
+        public int inactiveKb;
+        public int activeAnonKb;
+        public int inactiveAnonKb;
+        public int activeFileKb;
+        public int inactiveFileKb;
+        public int swapTotalKb;
+        public int swapFreeKb;
+        public int cmaTotalKb;
+        public int cmaFreeKb;
         public int totalIonKb;
         public int gpuTotalUsageKb;
         public int gpuPrivateAllocationsKb;
diff --git a/services/core/java/com/android/server/vcn/VcnGatewayConnection.java b/services/core/java/com/android/server/vcn/VcnGatewayConnection.java
index 05df22f..3be16a1 100644
--- a/services/core/java/com/android/server/vcn/VcnGatewayConnection.java
+++ b/services/core/java/com/android/server/vcn/VcnGatewayConnection.java
@@ -26,6 +26,7 @@
 import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
 import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
 import static android.net.ipsec.ike.exceptions.IkeProtocolException.ERROR_TYPE_AUTHENTICATION_FAILED;
+import static android.net.vcn.VcnGatewayConnectionConfig.VCN_GATEWAY_OPTION_ENABLE_DATA_STALL_RECOVERY_WITH_MOBILITY;
 import static android.net.vcn.VcnManager.VCN_ERROR_CODE_CONFIG_ERROR;
 import static android.net.vcn.VcnManager.VCN_ERROR_CODE_INTERNAL_ERROR;
 import static android.net.vcn.VcnManager.VCN_ERROR_CODE_NETWORK_ERROR;
@@ -36,6 +37,8 @@
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.content.Context;
+import android.net.ConnectivityDiagnosticsManager;
+import android.net.ConnectivityDiagnosticsManager.ConnectivityDiagnosticsCallback;
 import android.net.ConnectivityManager;
 import android.net.InetAddresses;
 import android.net.IpPrefix;
@@ -50,6 +53,7 @@
 import android.net.NetworkAgentConfig;
 import android.net.NetworkCapabilities;
 import android.net.NetworkProvider;
+import android.net.NetworkRequest;
 import android.net.NetworkScore;
 import android.net.RouteInfo;
 import android.net.TelephonyNetworkSpecifier;
@@ -546,6 +550,39 @@
         }
     }
 
+    /**
+     * Sent when there is a suspected data stall on a network
+     *
+     * <p>Only relevant in the Connected state.
+     *
+     * @param arg1 The "all" token; this signal is always honored.
+     * @param obj @NonNull An EventDataStallSuspectedInfo instance with relevant data.
+     */
+    private static final int EVENT_DATA_STALL_SUSPECTED = 13;
+
+    private static class EventDataStallSuspectedInfo implements EventInfo {
+        @NonNull public final Network network;
+
+        EventDataStallSuspectedInfo(@NonNull Network network) {
+            this.network = network;
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(network);
+        }
+
+        @Override
+        public boolean equals(@Nullable Object other) {
+            if (!(other instanceof EventDataStallSuspectedInfo)) {
+                return false;
+            }
+
+            final EventDataStallSuspectedInfo rhs = (EventDataStallSuspectedInfo) other;
+            return Objects.equals(network, rhs.network);
+        }
+    }
+
     @VisibleForTesting(visibility = Visibility.PRIVATE)
     @NonNull
     final DisconnectedState mDisconnectedState = new DisconnectedState();
@@ -578,10 +615,13 @@
     @NonNull
     private final VcnUnderlyingNetworkControllerCallback mUnderlyingNetworkControllerCallback;
 
+    @NonNull private final VcnConnectivityDiagnosticsCallback mConnectivityDiagnosticsCallback;
+
     private final boolean mIsMobileDataEnabled;
 
     @NonNull private final IpSecManager mIpSecManager;
     @NonNull private final ConnectivityManager mConnectivityManager;
+    @NonNull private final ConnectivityDiagnosticsManager mConnectivityDiagnosticsManager;
 
     @Nullable private IpSecTunnelInterface mTunnelIface = null;
 
@@ -748,6 +788,20 @@
                         mUnderlyingNetworkControllerCallback);
         mIpSecManager = mVcnContext.getContext().getSystemService(IpSecManager.class);
         mConnectivityManager = mVcnContext.getContext().getSystemService(ConnectivityManager.class);
+        mConnectivityDiagnosticsManager =
+                mVcnContext.getContext().getSystemService(ConnectivityDiagnosticsManager.class);
+
+        mConnectivityDiagnosticsCallback = new VcnConnectivityDiagnosticsCallback();
+
+        if (mConnectionConfig.hasGatewayOption(
+                VCN_GATEWAY_OPTION_ENABLE_DATA_STALL_RECOVERY_WITH_MOBILITY)) {
+            final NetworkRequest diagRequest =
+                    new NetworkRequest.Builder().addTransportType(TRANSPORT_CELLULAR).build();
+            mConnectivityDiagnosticsManager.registerConnectivityDiagnosticsCallback(
+                    diagRequest,
+                    new HandlerExecutor(new Handler(vcnContext.getLooper())),
+                    mConnectivityDiagnosticsCallback);
+        }
 
         addState(mDisconnectedState);
         addState(mDisconnectingState);
@@ -810,6 +864,9 @@
         mUnderlyingNetworkController.teardown();
 
         mGatewayStatusCallback.onQuit();
+
+        mConnectivityDiagnosticsManager.unregisterConnectivityDiagnosticsCallback(
+                mConnectivityDiagnosticsCallback);
     }
 
     /**
@@ -828,6 +885,20 @@
         sendMessageAndAcquireWakeLock(EVENT_SUBSCRIPTIONS_CHANGED, TOKEN_ALL);
     }
 
+    private class VcnConnectivityDiagnosticsCallback extends ConnectivityDiagnosticsCallback {
+        @Override
+        public void onDataStallSuspected(ConnectivityDiagnosticsManager.DataStallReport report) {
+            mVcnContext.ensureRunningOnLooperThread();
+
+            final Network network = report.getNetwork();
+            logInfo("Data stall suspected on " + network);
+            sendMessageAndAcquireWakeLock(
+                    EVENT_DATA_STALL_SUSPECTED,
+                    TOKEN_ALL,
+                    new EventDataStallSuspectedInfo(network));
+        }
+    }
+
     private class VcnUnderlyingNetworkControllerCallback
             implements UnderlyingNetworkControllerCallback {
         @Override
@@ -1367,7 +1438,8 @@
                 case EVENT_SUBSCRIPTIONS_CHANGED: // Fallthrough
                 case EVENT_SAFE_MODE_TIMEOUT_EXCEEDED: // Fallthrough
                 case EVENT_MIGRATION_COMPLETED: // Fallthrough
-                case EVENT_IKE_CONNECTION_INFO_CHANGED:
+                case EVENT_IKE_CONNECTION_INFO_CHANGED: // Fallthrough
+                case EVENT_DATA_STALL_SUSPECTED:
                     logUnexpectedEvent(msg.what);
                     break;
                 default:
@@ -1925,6 +1997,11 @@
                     mIkeConnectionInfo =
                             ((EventIkeConnectionInfoChangedInfo) msg.obj).ikeConnectionInfo;
                     break;
+                case EVENT_DATA_STALL_SUSPECTED:
+                    final Network networkWithDataStall =
+                            ((EventDataStallSuspectedInfo) msg.obj).network;
+                    handleDataStallSuspected(networkWithDataStall);
+                    break;
                 default:
                     logUnhandledMessage(msg);
                     break;
@@ -1985,6 +2062,15 @@
             }
         }
 
+        private void handleDataStallSuspected(Network networkWithDataStall) {
+            if (mUnderlying != null
+                    && mNetworkAgent != null
+                    && mNetworkAgent.getNetwork().equals(networkWithDataStall)) {
+                logInfo("Perform Mobility update to recover from suspected data stall");
+                mIkeSession.setNetwork(mUnderlying.network);
+            }
+        }
+
         protected void setupInterfaceAndNetworkAgent(
                 int token,
                 @NonNull IpSecTunnelInterface tunnelIface,
@@ -2424,6 +2510,11 @@
     }
 
     @VisibleForTesting(visibility = Visibility.PRIVATE)
+    ConnectivityDiagnosticsCallback getConnectivityDiagnosticsCallback() {
+        return mConnectivityDiagnosticsCallback;
+    }
+
+    @VisibleForTesting(visibility = Visibility.PRIVATE)
     UnderlyingNetworkRecord getUnderlyingNetwork() {
         return mUnderlying;
     }
diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
index 5d08461..37450ac 100644
--- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
+++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
@@ -34,6 +34,7 @@
 
 import android.annotation.NonNull;
 import android.app.ActivityManager;
+import android.app.ActivityOptions;
 import android.app.AppGlobals;
 import android.app.AppOpsManager;
 import android.app.ILocalWallpaperColorConsumer;
@@ -602,6 +603,13 @@
      * for display.
      */
     void generateCrop(WallpaperData wallpaper) {
+        TimingsTraceAndSlog t = new TimingsTraceAndSlog(TAG);
+        t.traceBegin("WPMS.generateCrop");
+        generateCropInternal(wallpaper);
+        t.traceEnd();
+    }
+
+    private void generateCropInternal(WallpaperData wallpaper) {
         boolean success = false;
 
         // Only generate crop for default display.
@@ -3166,6 +3174,15 @@
                 }
             }
 
+            final ActivityOptions clientOptions = ActivityOptions.makeBasic();
+            clientOptions.setIgnorePendingIntentCreatorForegroundState(true);
+            PendingIntent clientIntent = PendingIntent.getActivityAsUser(
+                    mContext, 0, Intent.createChooser(
+                            new Intent(Intent.ACTION_SET_WALLPAPER),
+                            mContext.getText(com.android.internal.R.string.chooser_wallpaper)),
+                    PendingIntent.FLAG_IMMUTABLE, clientOptions.toBundle(),
+                    UserHandle.of(serviceUserId));
+
             // Bind the service!
             if (DEBUG) Slog.v(TAG, "Binding to:" + componentName);
             final int componentUid = mIPackageManager.getPackageUid(componentName.getPackageName(),
@@ -3174,11 +3191,7 @@
             intent.setComponent(componentName);
             intent.putExtra(Intent.EXTRA_CLIENT_LABEL,
                     com.android.internal.R.string.wallpaper_binding_label);
-            intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivityAsUser(
-                    mContext, 0,
-                    Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER),
-                            mContext.getText(com.android.internal.R.string.chooser_wallpaper)),
-                    PendingIntent.FLAG_IMMUTABLE, null, new UserHandle(serviceUserId)));
+            intent.putExtra(Intent.EXTRA_CLIENT_INTENT, clientIntent);
             if (!mContext.bindServiceAsUser(intent, newConn,
                     Context.BIND_AUTO_CREATE | Context.BIND_SHOWING_UI
                             | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE
diff --git a/services/core/java/com/android/server/wearable/WearableSensingManagerService.java b/services/core/java/com/android/server/wearable/WearableSensingManagerService.java
index 707d0044..e145898 100644
--- a/services/core/java/com/android/server/wearable/WearableSensingManagerService.java
+++ b/services/core/java/com/android/server/wearable/WearableSensingManagerService.java
@@ -38,6 +38,7 @@
 import android.util.Slog;
 
 import com.android.internal.R;
+import com.android.internal.annotations.VisibleForTesting;
 import com.android.server.LocalServices;
 import com.android.server.SystemService;
 import com.android.server.infra.AbstractMasterSystemService;
@@ -161,7 +162,7 @@
         return null;
     }
 
-    // Used in testing.
+    @VisibleForTesting
     void provideDataStream(@UserIdInt int userId, ParcelFileDescriptor parcelFileDescriptor,
             RemoteCallback callback) {
         synchronized (mLock) {
@@ -174,7 +175,7 @@
         }
     }
 
-    // Used in testing.
+    @VisibleForTesting
     void provideData(@UserIdInt int userId, PersistableBundle data, SharedMemory sharedMemory,
             RemoteCallback callback) {
         synchronized (mLock) {
diff --git a/services/core/java/com/android/server/wm/ActivityClientController.java b/services/core/java/com/android/server/wm/ActivityClientController.java
index af430f9..2b49a81 100644
--- a/services/core/java/com/android/server/wm/ActivityClientController.java
+++ b/services/core/java/com/android/server/wm/ActivityClientController.java
@@ -17,7 +17,15 @@
 package com.android.server.wm;
 
 import static android.Manifest.permission.CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS;
+import static android.app.Activity.FULLSCREEN_MODE_REQUEST_ENTER;
 import static android.app.ActivityTaskManager.INVALID_TASK_ID;
+import static android.app.ActivityTaskManager.INVALID_WINDOWING_MODE;
+import static android.app.FullscreenRequestHandler.REMOTE_CALLBACK_RESULT_KEY;
+import static android.app.FullscreenRequestHandler.RESULT_APPROVED;
+import static android.app.FullscreenRequestHandler.RESULT_FAILED_NOT_DEFAULT_FREEFORM;
+import static android.app.FullscreenRequestHandler.RESULT_FAILED_NOT_IN_FREEFORM;
+import static android.app.FullscreenRequestHandler.RESULT_FAILED_NOT_IN_FULLSCREEN_WITH_HISTORY;
+import static android.app.FullscreenRequestHandler.RESULT_FAILED_NOT_TOP_FOCUSED;
 import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
 import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
 import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
@@ -27,6 +35,7 @@
 import static android.service.voice.VoiceInteractionSession.SHOW_SOURCE_APPLICATION;
 import static android.view.Display.DEFAULT_DISPLAY;
 import static android.view.Display.INVALID_DISPLAY;
+import static android.view.WindowManager.TRANSIT_CHANGE;
 import static android.view.WindowManager.TRANSIT_TO_BACK;
 import static android.view.WindowManager.TRANSIT_TO_FRONT;
 
@@ -52,6 +61,7 @@
 import android.app.Activity;
 import android.app.ActivityManager;
 import android.app.ActivityTaskManager;
+import android.app.FullscreenRequestHandler;
 import android.app.IActivityClientController;
 import android.app.ICompatCameraControlCallback;
 import android.app.IRequestFinishCallback;
@@ -71,6 +81,7 @@
 import android.os.Binder;
 import android.os.Bundle;
 import android.os.IBinder;
+import android.os.IRemoteCallback;
 import android.os.Parcel;
 import android.os.PersistableBundle;
 import android.os.RemoteException;
@@ -85,6 +96,7 @@
 
 import com.android.internal.app.AssistUtils;
 import com.android.internal.policy.IKeyguardDismissCallback;
+import com.android.internal.protolog.ProtoLogGroup;
 import com.android.internal.protolog.common.ProtoLog;
 import com.android.internal.util.FrameworkStatsLog;
 import com.android.server.LocalServices;
@@ -675,29 +687,32 @@
 
     @Override
     public int getLaunchedFromUid(IBinder token) {
-        if (!canGetLaunchedFrom()) {
-            return INVALID_UID;
-        }
+        final int uid = Binder.getCallingUid();
+        final boolean isInternalCaller = isInternalCallerGetLaunchedFrom(uid);
         synchronized (mGlobalLock) {
             final ActivityRecord r = ActivityRecord.forTokenLocked(token);
-            return r != null ? r.launchedFromUid : INVALID_UID;
+            if (r != null && (isInternalCaller || r.mShareIdentity || r.launchedFromUid == uid)) {
+                return r.launchedFromUid;
+            }
         }
+        return INVALID_UID;
     }
 
     @Override
     public String getLaunchedFromPackage(IBinder token) {
-        if (!canGetLaunchedFrom()) {
-            return null;
-        }
+        final int uid = Binder.getCallingUid();
+        final boolean isInternalCaller = isInternalCallerGetLaunchedFrom(uid);
         synchronized (mGlobalLock) {
             final ActivityRecord r = ActivityRecord.forTokenLocked(token);
-            return r != null ? r.launchedFromPackage : null;
+            if (r != null && (isInternalCaller || r.mShareIdentity || r.launchedFromUid == uid)) {
+                return r.launchedFromPackage;
+            }
         }
+        return null;
     }
 
-    /** Whether the caller can get the package or uid that launched its activity. */
-    private boolean canGetLaunchedFrom() {
-        final int uid = Binder.getCallingUid();
+    /** Whether the call to one of the getLaunchedFrom APIs is performed by an internal caller. */
+    private boolean isInternalCallerGetLaunchedFrom(int uid) {
         if (UserHandle.getAppId(uid) == SYSTEM_UID) {
             return true;
         }
@@ -1056,6 +1071,133 @@
         }
     }
 
+    private @FullscreenRequestHandler.RequestResult int validateMultiwindowFullscreenRequestLocked(
+            Task topFocusedRootTask, int fullscreenRequest, ActivityRecord requesterActivity) {
+        // If the mode is not by default freeform, the freeform will be a user-driven event.
+        if (topFocusedRootTask.getParent().getWindowingMode() != WINDOWING_MODE_FREEFORM) {
+            return RESULT_FAILED_NOT_DEFAULT_FREEFORM;
+        }
+        // If this is not coming from the currently top-most activity, reject the request.
+        if (requesterActivity != topFocusedRootTask.getTopMostActivity()) {
+            return RESULT_FAILED_NOT_TOP_FOCUSED;
+        }
+        if (fullscreenRequest == FULLSCREEN_MODE_REQUEST_ENTER) {
+            if (topFocusedRootTask.getWindowingMode() != WINDOWING_MODE_FREEFORM) {
+                return RESULT_FAILED_NOT_IN_FREEFORM;
+            }
+        } else {
+            if (topFocusedRootTask.getWindowingMode() != WINDOWING_MODE_FULLSCREEN) {
+                return RESULT_FAILED_NOT_IN_FULLSCREEN_WITH_HISTORY;
+            }
+            if (topFocusedRootTask.mMultiWindowRestoreWindowingMode == INVALID_WINDOWING_MODE) {
+                return RESULT_FAILED_NOT_IN_FULLSCREEN_WITH_HISTORY;
+            }
+        }
+        return RESULT_APPROVED;
+    }
+
+    @Override
+    public void requestMultiwindowFullscreen(IBinder callingActivity, int fullscreenRequest,
+            IRemoteCallback callback) {
+        final long ident = Binder.clearCallingIdentity();
+        try {
+            synchronized (mGlobalLock) {
+                requestMultiwindowFullscreenLocked(callingActivity, fullscreenRequest, callback);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    private void requestMultiwindowFullscreenLocked(IBinder callingActivity, int fullscreenRequest,
+            IRemoteCallback callback) {
+        final ActivityRecord r = ActivityRecord.forTokenLocked(callingActivity);
+        if (r == null) {
+            return;
+        }
+
+        // If the shell transition is not enabled, just execute and done.
+        final TransitionController controller = r.mTransitionController;
+        if (!controller.isShellTransitionsEnabled()) {
+            final @FullscreenRequestHandler.RequestResult int validateResult;
+            final Task topFocusedRootTask;
+            topFocusedRootTask = mService.getTopDisplayFocusedRootTask();
+            validateResult = validateMultiwindowFullscreenRequestLocked(topFocusedRootTask,
+                    fullscreenRequest, r);
+            reportMultiwindowFullscreenRequestValidatingResult(callback, validateResult);
+            if (validateResult == RESULT_APPROVED) {
+                executeMultiWindowFullscreenRequest(fullscreenRequest, topFocusedRootTask);
+            }
+            return;
+        }
+        // Initiate the transition.
+        final Transition transition = new Transition(TRANSIT_CHANGE, 0 /* flags */, controller,
+                mService.mWindowManager.mSyncEngine);
+        if (mService.mWindowManager.mSyncEngine.hasActiveSync()) {
+            ProtoLog.v(ProtoLogGroup.WM_DEBUG_WINDOW_TRANSITIONS,
+                    "Creating Pending Multiwindow Fullscreen Request: %s", transition);
+            mService.mWindowManager.mSyncEngine.queueSyncSet(
+                    () -> r.mTransitionController.moveToCollecting(transition),
+                    () -> {
+                        executeFullscreenRequestTransition(fullscreenRequest, callback, r,
+                                transition, true /* queued */);
+                    });
+        } else {
+            executeFullscreenRequestTransition(fullscreenRequest, callback, r, transition,
+                    false /* queued */);
+        }
+    }
+
+    private void executeFullscreenRequestTransition(int fullscreenRequest, IRemoteCallback callback,
+            ActivityRecord r, Transition transition, boolean queued) {
+        final @FullscreenRequestHandler.RequestResult int validateResult;
+        final Task topFocusedRootTask;
+        topFocusedRootTask = mService.getTopDisplayFocusedRootTask();
+        validateResult = validateMultiwindowFullscreenRequestLocked(topFocusedRootTask,
+                fullscreenRequest, r);
+        reportMultiwindowFullscreenRequestValidatingResult(callback, validateResult);
+        if (validateResult != RESULT_APPROVED) {
+            if (queued) {
+                transition.abort();
+            }
+            return;
+        }
+        r.mTransitionController.requestStartTransition(transition, topFocusedRootTask,
+                null /* remoteTransition */, null /* displayChange */);
+        executeMultiWindowFullscreenRequest(fullscreenRequest, topFocusedRootTask);
+        transition.setReady(topFocusedRootTask, true);
+    }
+
+    private static void reportMultiwindowFullscreenRequestValidatingResult(IRemoteCallback callback,
+            @FullscreenRequestHandler.RequestResult int result) {
+        if (callback == null) {
+            return;
+        }
+        Bundle res = new Bundle();
+        res.putInt(REMOTE_CALLBACK_RESULT_KEY, result);
+        try {
+            callback.sendResult(res);
+        } catch (RemoteException e) {
+            Slog.w(TAG, "client throws an exception back to the server, ignore it");
+        }
+    }
+
+    private static void executeMultiWindowFullscreenRequest(int fullscreenRequest, Task requester) {
+        final int targetWindowingMode;
+        if (fullscreenRequest == FULLSCREEN_MODE_REQUEST_ENTER) {
+            requester.mMultiWindowRestoreWindowingMode =
+                    requester.getRequestedOverrideWindowingMode();
+            targetWindowingMode = WINDOWING_MODE_FULLSCREEN;
+        } else {
+            targetWindowingMode = requester.mMultiWindowRestoreWindowingMode;
+            requester.mMultiWindowRestoreWindowingMode = INVALID_WINDOWING_MODE;
+        }
+        requester.setWindowingMode(targetWindowingMode);
+        if (targetWindowingMode == WINDOWING_MODE_FULLSCREEN) {
+            requester.setBounds(null);
+        }
+    }
+
     @Override
     public void startLockTaskModeByToken(IBinder token) {
         synchronized (mGlobalLock) {
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index aec06f0..efd0ffa 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -513,7 +513,6 @@
                                        // dies. After an activity is launched it follows the value
                                        // of #mIcicle.
     boolean launchFailed;   // set if a launched failed, to abort on 2nd try
-    boolean stopped;        // is activity pause finished?
     boolean delayedResume;  // not yet resumed because of stopped app switches?
     boolean finishing;      // activity in pending finish list?
     boolean deferRelaunchUntilPaused;   // relaunch of activity is being deferred until pause is
@@ -671,7 +670,7 @@
     private boolean mCurrentLaunchCanTurnScreenOn = true;
 
     /** Whether our surface was set to be showing in the last call to {@link #prepareSurfaces} */
-    private boolean mLastSurfaceShowing = true;
+    private boolean mLastSurfaceShowing;
 
     /**
      * The activity is opaque and fills the entire space of this task.
@@ -796,12 +795,6 @@
     // TODO: Make this final
     int mTargetSdk;
 
-    // Is this window's surface needed?  This is almost like visible, except
-    // it will sometimes be true a little earlier: when the activity record has
-    // been shown, but is still waiting for its app transition to execute
-    // before making its windows shown.
-    private boolean mVisibleRequested;
-
     // Last visibility state we reported to the app token.
     boolean reportedVisible;
 
@@ -880,7 +873,9 @@
     boolean mEnteringAnimation;
     boolean mOverrideTaskTransition;
     boolean mDismissKeyguard;
+    boolean mShareIdentity;
 
+    /** True if the activity has reported stopped; False if the activity becomes visible. */
     boolean mAppStopped;
     // A hint to override the window specified rotation animation, or -1 to use the window specified
     // value. We use this so that we can select the right animation in the cases of starting
@@ -1141,7 +1136,6 @@
         pw.print(prefix); pw.print("mHaveState="); pw.print(mHaveState);
                 pw.print(" mIcicle="); pw.println(mIcicle);
         pw.print(prefix); pw.print("state="); pw.print(mState);
-                pw.print(" stopped="); pw.print(stopped);
                 pw.print(" delayedResume="); pw.print(delayedResume);
                 pw.print(" finishing="); pw.println(finishing);
         pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
@@ -1240,8 +1234,8 @@
                 pw.println(prefix + "supportsEnterPipOnTaskSwitch: "
                         + supportsEnterPipOnTaskSwitch);
             }
-            if (info.getMaxAspectRatio() != 0) {
-                pw.println(prefix + "maxAspectRatio=" + info.getMaxAspectRatio());
+            if (getMaxAspectRatio() != 0) {
+                pw.println(prefix + "maxAspectRatio=" + getMaxAspectRatio());
             }
             final float minAspectRatio = getMinAspectRatio();
             if (minAspectRatio != 0) {
@@ -1574,19 +1568,14 @@
 
         if (oldParent != null) {
             oldParent.cleanUpActivityReferences(this);
-            // Update isVisibleRequested value of parent TaskFragment and send the callback to the
-            // client side if needed.
-            oldParent.onActivityVisibleRequestedChanged();
         }
 
         if (newParent != null) {
-            // Update isVisibleRequested value of parent TaskFragment and send the callback to the
-            // client side if needed.
-            newParent.onActivityVisibleRequestedChanged();
             if (isState(RESUMED)) {
                 newParent.setResumedActivity(this, "onParentChanged");
                 mImeInsetsFrozenUntilStartInput = false;
             }
+            mLetterboxUiController.onActivityParentChanged(newParent);
         }
 
         if (rootTask != null && rootTask.topRunningActivity() == this) {
@@ -2010,6 +1999,7 @@
 
             mOverrideTaskTransition = options.getOverrideTaskTransition();
             mDismissKeyguard = options.getDismissKeyguard();
+            mShareIdentity = options.getShareIdentity();
         }
 
         ColorDisplayService.ColorDisplayServiceInternal cds = LocalServices.getService(
@@ -2033,7 +2023,6 @@
         requestCode = _reqCode;
         setState(INITIALIZING, "ActivityRecord ctor");
         launchFailed = false;
-        stopped = false;
         delayedResume = false;
         finishing = false;
         deferRelaunchUntilPaused = false;
@@ -3883,7 +3872,7 @@
             }
             taskFragment.sendTaskFragmentInfoChanged();
         }
-        if (stopped) {
+        if (mAppStopped) {
             abortAndClearOptionsAnimation();
         }
     }
@@ -5086,11 +5075,6 @@
         return mVisible;
     }
 
-    @Override
-    boolean isVisibleRequested() {
-        return mVisibleRequested;
-    }
-
     void setVisible(boolean visible) {
         if (visible != mVisible) {
             mVisible = visible;
@@ -5105,16 +5089,9 @@
      * This is the only place that writes {@link #mVisibleRequested} (except unit test). The caller
      * outside of this class should use {@link #setVisibility}.
      */
-    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
-    void setVisibleRequested(boolean visible) {
-        if (visible == mVisibleRequested) {
-            return;
-        }
-        mVisibleRequested = visible;
-        final TaskFragment taskFragment = getTaskFragment();
-        if (taskFragment != null) {
-            taskFragment.onActivityVisibleRequestedChanged();
-        }
+    @Override
+    boolean setVisibleRequested(boolean visible) {
+        if (!super.setVisibleRequested(visible)) return false;
         setInsetsFrozen(!visible);
         if (app != null) {
             mTaskSupervisor.onProcessActivityStateChanged(app, false /* forceBatch */);
@@ -5123,6 +5100,13 @@
         if (!visible) {
             finishOrAbortReplacingWindow();
         }
+        return true;
+    }
+
+    @Override
+    protected boolean onChildVisibleRequestedChanged(@Nullable WindowContainer child) {
+        // Activity manages visibleRequested directly (it's not determined by children)
+        return false;
     }
 
     /**
@@ -5489,7 +5473,8 @@
         // no animation but there will still be a transition set.
         // We still need to delay hiding the surface such that it
         // can be synchronized with showing the next surface in the transition.
-        if (!isVisible() && !delayed && !displayContent.mAppTransition.isTransitionSet()) {
+        if (!usingShellTransitions && !isVisible() && !delayed
+                && !displayContent.mAppTransition.isTransitionSet()) {
             SurfaceControl.openTransaction();
             try {
                 forAllWindows(win -> {
@@ -5724,11 +5709,12 @@
         }
     }
 
-    void notifyAppResumed(boolean wasStopped) {
+    void notifyAppResumed() {
         if (getParent() == null) {
             Slog.w(TAG_WM, "Attempted to notify resumed of non-existing app token: " + token);
             return;
         }
+        final boolean wasStopped = mAppStopped;
         ProtoLog.v(WM_DEBUG_ADD_REMOVE, "notifyAppResumed: wasStopped=%b %s",
                 wasStopped, this);
         mAppStopped = false;
@@ -5743,32 +5729,6 @@
     }
 
     /**
-     * Notify that the app has stopped, and it is okay to destroy any surfaces which were
-     * keeping alive in case they were still being used.
-     */
-    void notifyAppStopped() {
-        ProtoLog.v(WM_DEBUG_ADD_REMOVE, "notifyAppStopped: %s", this);
-        mAppStopped = true;
-        firstWindowDrawn = false;
-        // This is to fix the edge case that auto-enter-pip is finished in Launcher but app calls
-        // setAutoEnterEnabled(false) and transitions to STOPPED state, see b/191930787.
-        // Clear any surface transactions and content overlay in this case.
-        if (task != null && task.mLastRecentsAnimationTransaction != null) {
-            task.clearLastRecentsAnimationTransaction(true /* forceRemoveOverlay */);
-        }
-        // Reset the last saved PiP snap fraction on app stop.
-        mDisplayContent.mPinnedTaskController.onActivityHidden(mActivityComponent);
-        mDisplayContent.mUnknownAppVisibilityController.appRemovedOrHidden(this);
-        if (isClientVisible()) {
-            // Though this is usually unlikely to happen, still make sure the client is invisible.
-            setClientVisible(false);
-        }
-        destroySurfaces();
-        // Remove any starting window that was added for this app if they are still around.
-        removeStartingWindow();
-    }
-
-    /**
      * Suppress transition until the new activity becomes ready, otherwise the keyguard can appear
      * for a short amount of time before the new process with the new activity had the ability to
      * set its showWhenLocked flags.
@@ -6128,7 +6088,6 @@
             mLastNewIntent = newIntents.get(newIntents.size() - 1);
         }
         newIntents = null;
-        stopped = false;
 
         if (isActivityTypeHome()) {
             mTaskSupervisor.updateHomeProcess(task.getBottomMostActivity().app);
@@ -6250,7 +6209,6 @@
         }
         resumeKeyDispatchingLocked();
         try {
-            stopped = false;
             ProtoLog.v(WM_DEBUG_STATES, "Moving to STOPPING: %s (stop requested)", this);
 
             setState(STOPPING, "stopIfPossible");
@@ -6268,7 +6226,7 @@
             // notification will clean things up.
             Slog.w(TAG, "Exception thrown during pause", e);
             // Just in case, assume it to be stopped.
-            stopped = true;
+            mAppStopped = true;
             ProtoLog.v(WM_DEBUG_STATES, "Stop failed; moving to STOPPED: %s", this);
             setState(STOPPED, "stopIfPossible");
             if (deferRelaunchUntilPaused) {
@@ -6277,12 +6235,16 @@
         }
     }
 
+    /**
+     * Notifies that the activity has stopped, and it is okay to destroy any surfaces which were
+     * keeping alive in case they were still being used.
+     */
     void activityStopped(Bundle newIcicle, PersistableBundle newPersistentState,
             CharSequence description) {
+        removeStopTimeout();
         final boolean isStopping = mState == STOPPING;
         if (!isStopping && mState != RESTARTING_PROCESS) {
             Slog.i(TAG, "Activity reported stop, but no longer stopping: " + this + " " + mState);
-            removeStopTimeout();
             return;
         }
         if (newPersistentState != null) {
@@ -6298,28 +6260,42 @@
             updateTaskDescription(description);
         }
         ProtoLog.i(WM_DEBUG_STATES, "Saving icicle of %s: %s", this, mIcicle);
-        if (!stopped) {
+
+        if (isStopping) {
             ProtoLog.v(WM_DEBUG_STATES, "Moving to STOPPED: %s (stop complete)", this);
-            removeStopTimeout();
-            stopped = true;
-            if (isStopping) {
-                setState(STOPPED, "activityStoppedLocked");
-            }
-
-            notifyAppStopped();
-
-            if (finishing) {
-                abortAndClearOptionsAnimation();
-            } else {
-                if (deferRelaunchUntilPaused) {
-                    destroyImmediately("stop-config");
-                    mRootWindowContainer.resumeFocusedTasksTopActivities();
-                } else {
-                    mAtmService.updatePreviousProcess(this);
-                }
-            }
-            mTaskSupervisor.checkReadyForSleepLocked(true /* allowDelay */);
+            setState(STOPPED, "activityStopped");
         }
+
+        mAppStopped = true;
+        firstWindowDrawn = false;
+        // This is to fix the edge case that auto-enter-pip is finished in Launcher but app calls
+        // setAutoEnterEnabled(false) and transitions to STOPPED state, see b/191930787.
+        // Clear any surface transactions and content overlay in this case.
+        if (task.mLastRecentsAnimationTransaction != null) {
+            task.clearLastRecentsAnimationTransaction(true /* forceRemoveOverlay */);
+        }
+        // Reset the last saved PiP snap fraction on app stop.
+        mDisplayContent.mPinnedTaskController.onActivityHidden(mActivityComponent);
+        mDisplayContent.mUnknownAppVisibilityController.appRemovedOrHidden(this);
+        if (isClientVisible()) {
+            // Though this is usually unlikely to happen, still make sure the client is invisible.
+            setClientVisible(false);
+        }
+        destroySurfaces();
+        // Remove any starting window that was added for this app if they are still around.
+        removeStartingWindow();
+
+        if (finishing) {
+            abortAndClearOptionsAnimation();
+        } else {
+            if (deferRelaunchUntilPaused) {
+                destroyImmediately("stop-config");
+                mRootWindowContainer.resumeFocusedTasksTopActivities();
+            } else {
+                mAtmService.updatePreviousProcess(this);
+            }
+        }
+        mTaskSupervisor.checkReadyForSleepLocked(true /* allowDelay */);
     }
 
     void addToStopping(boolean scheduleIdle, boolean idleDelayed, String reason) {
@@ -6857,7 +6833,7 @@
     private ActivityRecord getWaitingHistoryRecordLocked() {
         // First find the real culprit...  if this activity has stopped, then the key dispatching
         // timeout should not be caused by this.
-        if (stopped) {
+        if (mAppStopped) {
             final Task rootTask = mRootWindowContainer.getTopDisplayFocusedRootTask();
             if (rootTask == null) {
                 return this;
@@ -6938,7 +6914,7 @@
         }
         if (isState(RESUMED) || getRootTask() == null
                 || this == getTaskFragment().getPausingActivity()
-                || !mHaveState || !stopped) {
+                || !mHaveState || !mAppStopped) {
             // We're not ready for this kind of thing.
             return false;
         }
@@ -7428,6 +7404,11 @@
     }
 
     @Override
+    boolean showSurfaceOnCreation() {
+        return false;
+    }
+
+    @Override
     void prepareSurfaces() {
         final boolean show = isVisible() || isAnimating(PARENTS,
                 ANIMATION_TYPE_APP_TRANSITION | ANIMATION_TYPE_RECENTS);
@@ -7666,6 +7647,15 @@
     @Configuration.Orientation
     @Override
     int getRequestedConfigurationOrientation(boolean forDisplay) {
+        if (mLetterboxUiController.hasInheritedOrientation()) {
+            final RootDisplayArea root = getRootDisplayArea();
+            if (forDisplay && root != null && root.isOrientationDifferentFromDisplay()) {
+                return ActivityInfo.reverseOrientation(
+                        mLetterboxUiController.getInheritedOrientation());
+            } else {
+                return mLetterboxUiController.getInheritedOrientation();
+            }
+        }
         if (mOrientation == SCREEN_ORIENTATION_BEHIND && task != null) {
             // We use Task here because we want to be consistent with what happens in
             // multi-window mode where other tasks orientations are ignored.
@@ -7700,6 +7690,10 @@
         // This activity may relaunch or perform configuration change so once it has reported drawn,
         // the screen can be unfrozen.
         ensureActivityConfiguration(0 /* globalChanges */, !PRESERVE_WINDOWS);
+        if (mTransitionController.isCollecting(this)) {
+            // In case the task was changed from PiP but still keeps old transform.
+            task.resetSurfaceControlTransforms();
+        }
     }
 
     void setRequestedOrientation(int requestedOrientation) {
@@ -7789,6 +7783,9 @@
 
     @Nullable
     CompatDisplayInsets getCompatDisplayInsets() {
+        if (mLetterboxUiController.hasInheritedLetterboxBehavior()) {
+            return mLetterboxUiController.getInheritedCompatDisplayInsets();
+        }
         return mCompatDisplayInsets;
     }
 
@@ -7871,6 +7868,10 @@
 
     // TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer.
     private void updateCompatDisplayInsets() {
+        if (mLetterboxUiController.hasInheritedLetterboxBehavior()) {
+            mCompatDisplayInsets =  mLetterboxUiController.getInheritedCompatDisplayInsets();
+            return;
+        }
         if (mCompatDisplayInsets != null || !shouldCreateCompatDisplayInsets()) {
             // The override configuration is set only once in size compatibility mode.
             return;
@@ -7932,6 +7933,9 @@
 
     @Override
     float getCompatScale() {
+        if (mLetterboxUiController.hasInheritedLetterboxBehavior()) {
+            return mLetterboxUiController.getInheritedSizeCompatScale();
+        }
         return hasSizeCompatBounds() ? mSizeCompatScale : super.getCompatScale();
     }
 
@@ -8041,6 +8045,16 @@
     }
 
     /**
+     * @return The orientation to use to understand if reachability is enabled.
+     */
+    @ActivityInfo.ScreenOrientation
+    int getOrientationForReachability() {
+        return mLetterboxUiController.hasInheritedLetterboxBehavior()
+                ? mLetterboxUiController.getInheritedOrientation()
+                : getRequestedConfigurationOrientation();
+    }
+
+    /**
      * Returns whether activity bounds are letterboxed.
      *
      * <p>Note that letterbox UI may not be shown even when this returns {@code true}. See {@link
@@ -8080,6 +8094,10 @@
         if (!ignoreVisibility && !mVisibleRequested) {
             return APP_COMPAT_STATE_CHANGED__STATE__NOT_VISIBLE;
         }
+        // TODO(b/256564921): Investigate if we need new metrics for translucent activities
+        if (mLetterboxUiController.hasInheritedLetterboxBehavior()) {
+            return mLetterboxUiController.getInheritedAppCompatState();
+        }
         if (mInSizeCompatModeForBounds) {
             return APP_COMPAT_STATE_CHANGED__STATE__LETTERBOXED_FOR_SIZE_COMPAT_MODE;
         }
@@ -8550,6 +8568,11 @@
     }
 
     private boolean isInSizeCompatModeForBounds(final Rect appBounds, final Rect containerBounds) {
+        if (mLetterboxUiController.hasInheritedLetterboxBehavior()) {
+            // To avoid wrong app behaviour, we decided to disable SCM when a translucent activity
+            // is letterboxed.
+            return false;
+        }
         final int appWidth = appBounds.width();
         final int appHeight = appBounds.height();
         final int containerAppWidth = containerBounds.width();
@@ -8570,10 +8593,11 @@
 
         // The rest of the condition is that only one side is smaller than the container, but it
         // still needs to exclude the cases where the size is limited by the fixed aspect ratio.
-        if (info.getMaxAspectRatio() > 0) {
+        final float maxAspectRatio = getMaxAspectRatio();
+        if (maxAspectRatio > 0) {
             final float aspectRatio = (0.5f + Math.max(appWidth, appHeight))
                     / Math.min(appWidth, appHeight);
-            if (aspectRatio >= info.getMaxAspectRatio()) {
+            if (aspectRatio >= maxAspectRatio) {
                 // The current size has reached the max aspect ratio.
                 return false;
             }
@@ -8795,7 +8819,7 @@
     // TODO(b/36505427): Consider moving this method and similar ones to ConfigurationContainer.
     private boolean applyAspectRatio(Rect outBounds, Rect containingAppBounds,
             Rect containingBounds, float desiredAspectRatio) {
-        final float maxAspectRatio = info.getMaxAspectRatio();
+        final float maxAspectRatio = getMaxAspectRatio();
         final Task rootTask = getRootTask();
         final float minAspectRatio = getMinAspectRatio();
         final TaskFragment organizedTf = getOrganizedTaskFragment();
@@ -8902,6 +8926,9 @@
      * Returns the min aspect ratio of this activity.
      */
     float getMinAspectRatio() {
+        if (mLetterboxUiController.hasInheritedLetterboxBehavior()) {
+            return mLetterboxUiController.getInheritedMinAspectRatio();
+        }
         if (info.applicationInfo == null) {
             return info.getMinAspectRatio();
         }
@@ -8946,11 +8973,18 @@
                 && parent.getWindowConfiguration().getWindowingMode() == WINDOWING_MODE_FULLSCREEN;
     }
 
+    float getMaxAspectRatio() {
+        if (mLetterboxUiController.hasInheritedLetterboxBehavior()) {
+            return mLetterboxUiController.getInheritedMaxAspectRatio();
+        }
+        return info.getMaxAspectRatio();
+    }
+
     /**
      * Returns true if the activity has maximum or minimum aspect ratio.
      */
     private boolean hasFixedAspectRatio() {
-        return info.getMaxAspectRatio() != 0 || getMinAspectRatio() != 0;
+        return getMaxAspectRatio() != 0 || getMinAspectRatio() != 0;
     }
 
     /**
diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java
index 1e06375..2762c45 100644
--- a/services/core/java/com/android/server/wm/ActivityStarter.java
+++ b/services/core/java/com/android/server/wm/ActivityStarter.java
@@ -1823,7 +1823,7 @@
         if (mPreferredTaskDisplayArea != null) {
             final DisplayContent displayContent = mRootWindowContainer.getDisplayContentOrCreate(
                     mPreferredTaskDisplayArea.getDisplayId());
-            if (displayContent != null && displayContent.mDwpcHelper.hasController()) {
+            if (displayContent != null) {
                 final int targetWindowingMode = (targetTask != null)
                         ? targetTask.getWindowingMode() : displayContent.getWindowingMode();
                 final int launchingFromDisplayId =
@@ -2285,6 +2285,15 @@
             mLaunchFlags |= FLAG_ACTIVITY_NEW_TASK;
         }
 
+        if (r.info.requiredDisplayCategory != null && mSourceRecord != null
+                && !r.info.requiredDisplayCategory.equals(
+                        mSourceRecord.info.requiredDisplayCategory)) {
+            // Adding NEW_TASK flag for activity with display category attribute if the display
+            // category of the source record is different, so that the activity won't be launched
+            // in source record's task.
+            mLaunchFlags |= FLAG_ACTIVITY_NEW_TASK;
+        }
+
         sendNewTaskResultRequestIfNeeded();
 
         if ((mLaunchFlags & FLAG_ACTIVITY_NEW_DOCUMENT) != 0 && r.resultTo == null) {
@@ -2372,6 +2381,12 @@
             Slog.w(TAG, "Starting activity in task not in recents: " + inTask);
             mInTask = null;
         }
+        // Prevent to start activity in Task with different display category
+        if (mInTask != null && !mInTask.isSameRequiredDisplayCategory(r.info)) {
+            Slog.w(TAG, "Starting activity in task with different display category: "
+                    + mInTask);
+            mInTask = null;
+        }
         mInTaskFragment = inTaskFragment;
 
         mStartFlags = startFlags;
diff --git a/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java b/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java
index 8a247cf..33c90a0 100644
--- a/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java
+++ b/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java
@@ -395,7 +395,7 @@
 
         final DisplayContent displayContent =
                 mRootWindowContainer.getDisplayContentOrCreate(displayId);
-        if (displayContent != null && displayContent.mDwpcHelper.hasController()) {
+        if (displayContent != null) {
             final ArrayList<ActivityInfo> activities = new ArrayList<>();
             if (activityInfo != null) {
                 activities.add(activityInfo);
@@ -405,10 +405,8 @@
                     activities.add(r.info);
                 });
             }
-            if (!displayContent.mDwpcHelper.canContainActivities(activities,
-                    displayContent.getWindowingMode())) {
-                return false;
-            }
+            return displayContent.mDwpcHelper.canContainActivities(activities,
+                        displayContent.getWindowingMode());
         }
 
         return true;
diff --git a/services/core/java/com/android/server/wm/BackNavigationController.java b/services/core/java/com/android/server/wm/BackNavigationController.java
index b16602e..14131e6 100644
--- a/services/core/java/com/android/server/wm/BackNavigationController.java
+++ b/services/core/java/com/android/server/wm/BackNavigationController.java
@@ -235,6 +235,7 @@
             // We don't have an application callback, let's find the destination of the back gesture
             // The search logic should align with ActivityClientController#finishActivity
             prevActivity = currentTask.topRunningActivity(currentActivity.token, INVALID_TASK_ID);
+            final boolean isOccluded = isKeyguardOccluded(window);
             // TODO Dialog window does not need to attach on activity, check
             // window.mAttrs.type != TYPE_BASE_APPLICATION
             if ((window.getParent().getChildCount() > 1
@@ -244,16 +245,24 @@
                 backType = BackNavigationInfo.TYPE_DIALOG_CLOSE;
                 removedWindowContainer = window;
             } else if (prevActivity != null) {
-                // We have another Activity in the same currentTask to go to
-                backType = BackNavigationInfo.TYPE_CROSS_ACTIVITY;
-                removedWindowContainer = currentActivity;
-                prevTask = prevActivity.getTask();
+                if (!isOccluded || prevActivity.canShowWhenLocked()) {
+                    // We have another Activity in the same currentTask to go to
+                    backType = BackNavigationInfo.TYPE_CROSS_ACTIVITY;
+                    removedWindowContainer = currentActivity;
+                    prevTask = prevActivity.getTask();
+                } else {
+                    backType = BackNavigationInfo.TYPE_CALLBACK;
+                }
             } else if (currentTask.returnsToHomeRootTask()) {
-                // Our Task should bring back to home
-                removedWindowContainer = currentTask;
-                prevTask = currentTask.getDisplayArea().getRootHomeTask();
-                backType = BackNavigationInfo.TYPE_RETURN_TO_HOME;
-                mShowWallpaper = true;
+                if (isOccluded) {
+                    backType = BackNavigationInfo.TYPE_CALLBACK;
+                } else {
+                    // Our Task should bring back to home
+                    removedWindowContainer = currentTask;
+                    prevTask = currentTask.getDisplayArea().getRootHomeTask();
+                    backType = BackNavigationInfo.TYPE_RETURN_TO_HOME;
+                    mShowWallpaper = true;
+                }
             } else if (currentActivity.isRootOfTask()) {
                 // TODO(208789724): Create single source of truth for this, maybe in
                 //  RootWindowContainer
@@ -267,7 +276,9 @@
                     backType = BackNavigationInfo.TYPE_CALLBACK;
                 } else {
                     prevActivity = prevTask.getTopNonFinishingActivity();
-                    if (prevTask.isActivityTypeHome()) {
+                    if (prevActivity == null || (isOccluded && !prevActivity.canShowWhenLocked())) {
+                        backType = BackNavigationInfo.TYPE_CALLBACK;
+                    } else if (prevTask.isActivityTypeHome()) {
                         backType = BackNavigationInfo.TYPE_RETURN_TO_HOME;
                         mShowWallpaper = true;
                     } else {
@@ -323,6 +334,12 @@
         return mAnimationTargets.mComposed && mAnimationTargets.mWaitTransition;
     }
 
+    boolean isKeyguardOccluded(WindowState focusWindow) {
+        final KeyguardController kc = mWindowManagerService.mAtmService.mKeyguardController;
+        final int displayId = focusWindow.getDisplayId();
+        return kc.isKeyguardLocked(displayId) && kc.isDisplayOccluded(displayId);
+    }
+
     // For legacy transition.
     /**
      *  Once we find the transition targets match back animation targets, remove the target from
diff --git a/services/core/java/com/android/server/wm/ContentRecorder.java b/services/core/java/com/android/server/wm/ContentRecorder.java
index 6e23ed9..8d5d0d5 100644
--- a/services/core/java/com/android/server/wm/ContentRecorder.java
+++ b/services/core/java/com/android/server/wm/ContentRecorder.java
@@ -16,6 +16,7 @@
 
 package com.android.server.wm;
 
+import static android.content.Context.MEDIA_PROJECTION_SERVICE;
 import static android.content.res.Configuration.ORIENTATION_UNDEFINED;
 import static android.view.ContentRecordingSession.RECORD_CONTENT_DISPLAY;
 import static android.view.ContentRecordingSession.RECORD_CONTENT_TASK;
@@ -27,8 +28,10 @@
 import android.content.res.Configuration;
 import android.graphics.Point;
 import android.graphics.Rect;
-import android.media.projection.MediaProjectionManager;
+import android.media.projection.IMediaProjectionManager;
 import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.ServiceManager;
 import android.provider.DeviceConfig;
 import android.view.ContentRecordingSession;
 import android.view.Display;
@@ -83,13 +86,7 @@
     private int mLastOrientation = ORIENTATION_UNDEFINED;
 
     ContentRecorder(@NonNull DisplayContent displayContent) {
-        this(displayContent, () -> {
-            MediaProjectionManager mpm = displayContent.mWmService.mContext.getSystemService(
-                    MediaProjectionManager.class);
-            if (mpm != null) {
-                mpm.stopActiveProjection();
-            }
-        });
+        this(displayContent, new RemoteMediaProjectionManagerWrapper());
     }
 
     @VisibleForTesting
@@ -445,6 +442,9 @@
                 .setPosition(mRecordedSurface, shiftedX /* x */, shiftedY /* y */)
                 .apply();
         mLastRecordedBounds = new Rect(recordedContentBounds);
+        // Request to notify the client about the resize.
+        mMediaProjectionManager.notifyActiveProjectionCapturedContentResized(
+                mLastRecordedBounds.width(), mLastRecordedBounds.height());
     }
 
     /**
@@ -503,6 +503,56 @@
 
     @VisibleForTesting interface MediaProjectionManagerWrapper {
         void stopActiveProjection();
+        void notifyActiveProjectionCapturedContentResized(int width, int height);
+    }
+
+    private static final class RemoteMediaProjectionManagerWrapper implements
+            MediaProjectionManagerWrapper {
+        @Nullable private IMediaProjectionManager mIMediaProjectionManager = null;
+
+        @Override
+        public void stopActiveProjection() {
+            fetchMediaProjectionManager();
+            if (mIMediaProjectionManager == null) {
+                return;
+            }
+            try {
+                mIMediaProjectionManager.stopActiveProjection();
+            } catch (RemoteException e) {
+                ProtoLog.e(WM_DEBUG_CONTENT_RECORDING,
+                        "Unable to tell MediaProjectionManagerService to stop the active "
+                                + "projection: %s",
+                        e);
+            }
+        }
+
+        @Override
+        public void notifyActiveProjectionCapturedContentResized(int width, int height) {
+            fetchMediaProjectionManager();
+            if (mIMediaProjectionManager == null) {
+                return;
+            }
+            try {
+                mIMediaProjectionManager.notifyActiveProjectionCapturedContentResized(width,
+                        height);
+            } catch (RemoteException e) {
+                ProtoLog.e(WM_DEBUG_CONTENT_RECORDING,
+                        "Unable to tell MediaProjectionManagerService about resizing the active "
+                                + "projection: %s",
+                        e);
+            }
+        }
+
+        private void fetchMediaProjectionManager() {
+            if (mIMediaProjectionManager != null) {
+                return;
+            }
+            IBinder b = ServiceManager.getService(MEDIA_PROJECTION_SERVICE);
+            if (b == null) {
+                return;
+            }
+            mIMediaProjectionManager = IMediaProjectionManager.Stub.asInterface(b);
+        }
     }
 
     private boolean isRecordingContentTask() {
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index d5802cf..c6dc24f 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -3392,6 +3392,9 @@
             if (!controller.isCollecting(this)) {
                 controller.collect(this);
                 startAsyncRotationIfNeeded();
+                if (mFixedRotationLaunchingApp != null) {
+                    setSeamlessTransitionForFixedRotation(controller.getCollectingTransition());
+                }
             }
             return;
         }
@@ -3401,12 +3404,8 @@
             mAtmService.startLaunchPowerMode(POWER_MODE_REASON_CHANGE_DISPLAY);
             if (mFixedRotationLaunchingApp != null) {
                 // A fixed-rotation transition is done, then continue to start a seamless display
-                // transition. And be fore the start transaction is applied, the non-app windows
-                // need to keep in previous rotation to avoid showing inconsistent content.
-                t.setSeamlessRotation(this);
-                if (mAsyncRotationController != null) {
-                    mAsyncRotationController.keepAppearanceInPreviousRotation();
-                }
+                // transition.
+                setSeamlessTransitionForFixedRotation(t);
             } else if (isRotationChanging()) {
                 if (displayChange != null) {
                     final boolean seamless = mDisplayRotation.shouldRotateSeamlessly(
@@ -3425,6 +3424,15 @@
         }
     }
 
+    private void setSeamlessTransitionForFixedRotation(Transition t) {
+        t.setSeamlessRotation(this);
+        // Before the start transaction is applied, the non-app windows need to keep in previous
+        // rotation to avoid showing inconsistent content.
+        if (mAsyncRotationController != null) {
+            mAsyncRotationController.keepAppearanceInPreviousRotation();
+        }
+    }
+
     /** If the display is in transition, there should be a screenshot covering it. */
     @Override
     boolean inTransition() {
diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java
index b419f36..300deca 100644
--- a/services/core/java/com/android/server/wm/DisplayPolicy.java
+++ b/services/core/java/com/android/server/wm/DisplayPolicy.java
@@ -2128,15 +2128,10 @@
     }
 
     void updateSystemBarAttributes() {
-        WindowState winCandidate = mFocusedWindow;
-        if (winCandidate == null && mTopFullscreenOpaqueWindowState != null
-                && (mTopFullscreenOpaqueWindowState.mAttrs.flags
-                & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0) {
-            // Only focusable window can take system bar control.
-            winCandidate = mTopFullscreenOpaqueWindowState;
-        }
         // If there is no window focused, there will be nobody to handle the events
         // anyway, so just hang on in whatever state we're in until things settle down.
+        WindowState winCandidate = mFocusedWindow != null ? mFocusedWindow
+                : mTopFullscreenOpaqueWindowState;
         if (winCandidate == null) {
             return;
         }
diff --git a/services/core/java/com/android/server/wm/DisplayWindowPolicyControllerHelper.java b/services/core/java/com/android/server/wm/DisplayWindowPolicyControllerHelper.java
index 69fd00c..72ed108 100644
--- a/services/core/java/com/android/server/wm/DisplayWindowPolicyControllerHelper.java
+++ b/services/core/java/com/android/server/wm/DisplayWindowPolicyControllerHelper.java
@@ -22,12 +22,14 @@
 import android.content.pm.ActivityInfo;
 import android.os.UserHandle;
 import android.util.ArraySet;
+import android.util.Slog;
 import android.window.DisplayWindowPolicyController;
 
 import java.io.PrintWriter;
 import java.util.List;
 
 class DisplayWindowPolicyControllerHelper {
+    private static final String TAG = "DisplayWindowPolicyControllerHelper";
 
     private final DisplayContent mDisplayContent;
 
@@ -69,6 +71,17 @@
     public boolean canContainActivities(@NonNull List<ActivityInfo> activities,
             @WindowConfiguration.WindowingMode int windowingMode) {
         if (mDisplayWindowPolicyController == null) {
+            for (int i = activities.size() - 1; i >= 0; i--) {
+                final ActivityInfo aInfo = activities.get(i);
+                if (aInfo.requiredDisplayCategory != null) {
+                    Slog.e(TAG,
+                            String.format("Activity with requiredDisplayCategory='%s' cannot be"
+                                            + " displayed on display %d because that display does"
+                                            + " not have a matching category",
+                                    aInfo.requiredDisplayCategory, mDisplayContent.mDisplayId));
+                    return false;
+                }
+            }
             return true;
         }
         return mDisplayWindowPolicyController.canContainActivities(activities, windowingMode);
@@ -81,6 +94,14 @@
             @WindowConfiguration.WindowingMode int windowingMode, int launchingFromDisplayId,
             boolean isNewTask) {
         if (mDisplayWindowPolicyController == null) {
+            if (activityInfo.requiredDisplayCategory != null) {
+                Slog.e(TAG,
+                        String.format("Activity with requiredDisplayCategory='%s' cannot be"
+                                + " launched on display %d because that display does"
+                                + " not have a matching category",
+                                activityInfo.requiredDisplayCategory, mDisplayContent.mDisplayId));
+                return false;
+            }
             return true;
         }
         return mDisplayWindowPolicyController.canActivityBeLaunched(activityInfo, windowingMode,
diff --git a/services/core/java/com/android/server/wm/LetterboxConfiguration.java b/services/core/java/com/android/server/wm/LetterboxConfiguration.java
index c19353c..127a7bf 100644
--- a/services/core/java/com/android/server/wm/LetterboxConfiguration.java
+++ b/services/core/java/com/android/server/wm/LetterboxConfiguration.java
@@ -21,6 +21,7 @@
 import android.annotation.Nullable;
 import android.content.Context;
 import android.graphics.Color;
+import android.provider.DeviceConfig;
 
 import com.android.internal.R;
 import com.android.internal.annotations.VisibleForTesting;
@@ -103,6 +104,10 @@
 
     final Context mContext;
 
+    // Responsible for the persistence of letterbox[Horizontal|Vertical]PositionMultiplier
+    @NonNull
+    private final LetterboxConfigurationPersister mLetterboxConfigurationPersister;
+
     // Aspect ratio of letterbox for fixed orientation, values <=
     // MIN_FIXED_ORIENTATION_LETTERBOX_ASPECT_RATIO will be ignored.
     private float mFixedOrientationLetterboxAspectRatio;
@@ -165,9 +170,12 @@
     // Whether using split screen aspect ratio as a default aspect ratio for unresizable apps.
     private boolean mIsSplitScreenAspectRatioForUnresizableAppsEnabled;
 
-    // Responsible for the persistence of letterbox[Horizontal|Vertical]PositionMultiplier
-    @NonNull
-    private final LetterboxConfigurationPersister mLetterboxConfigurationPersister;
+    // Whether letterboxing strategy is enabled for translucent activities. If {@value false}
+    // all the feature is disabled
+    private boolean mTranslucentLetterboxingEnabled;
+
+    // Allows to enable letterboxing strategy for translucent activities ignoring flags.
+    private boolean mTranslucentLetterboxingOverrideEnabled;
 
     LetterboxConfiguration(Context systemUiContext) {
         this(systemUiContext, new LetterboxConfigurationPersister(systemUiContext,
@@ -206,6 +214,8 @@
                 R.dimen.config_letterboxDefaultMinAspectRatioForUnresizableApps));
         mIsSplitScreenAspectRatioForUnresizableAppsEnabled = mContext.getResources().getBoolean(
                 R.bool.config_letterboxIsSplitScreenAspectRatioForUnresizableAppsEnabled);
+        mTranslucentLetterboxingEnabled = mContext.getResources().getBoolean(
+                R.bool.config_letterboxIsEnabledForTranslucentActivities);
         mLetterboxConfigurationPersister = letterboxConfigurationPersister;
         mLetterboxConfigurationPersister.start();
     }
@@ -817,6 +827,32 @@
                 R.bool.config_letterboxIsSplitScreenAspectRatioForUnresizableAppsEnabled);
     }
 
+    boolean isTranslucentLetterboxingEnabled() {
+        return mTranslucentLetterboxingOverrideEnabled || (mTranslucentLetterboxingEnabled
+                && isTranslucentLetterboxingAllowed());
+    }
+
+    void setTranslucentLetterboxingEnabled(boolean translucentLetterboxingEnabled) {
+        mTranslucentLetterboxingEnabled = translucentLetterboxingEnabled;
+    }
+
+    void setTranslucentLetterboxingOverrideEnabled(
+            boolean translucentLetterboxingOverrideEnabled) {
+        mTranslucentLetterboxingOverrideEnabled = translucentLetterboxingOverrideEnabled;
+        setTranslucentLetterboxingEnabled(translucentLetterboxingOverrideEnabled);
+    }
+
+    /**
+     * Resets whether we use the constraints override strategy for letterboxing when dealing
+     * with translucent activities {@link R.bool.config_letterboxIsEnabledForTranslucentActivities}.
+     */
+    void resetTranslucentLetterboxingEnabled() {
+        final boolean newValue = mContext.getResources().getBoolean(
+                R.bool.config_letterboxIsEnabledForTranslucentActivities);
+        setTranslucentLetterboxingEnabled(newValue);
+        setTranslucentLetterboxingOverrideEnabled(false);
+    }
+
     /** Calculates a new letterboxPositionForHorizontalReachability value and updates the store */
     private void updatePositionForHorizontalReachability(
             Function<Integer, Integer> newHorizonalPositionFun) {
@@ -839,4 +875,9 @@
                 nextVerticalPosition);
     }
 
+    // TODO(b/262378106): Cache runtime flag and implement DeviceConfig.OnPropertiesChangedListener
+    static boolean isTranslucentLetterboxingAllowed() {
+        return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_WINDOW_MANAGER,
+                "enable_translucent_activity_letterbox", false);
+    }
 }
diff --git a/services/core/java/com/android/server/wm/LetterboxUiController.java b/services/core/java/com/android/server/wm/LetterboxUiController.java
index bcea6f4..a53a5fc 100644
--- a/services/core/java/com/android/server/wm/LetterboxUiController.java
+++ b/services/core/java/com/android/server/wm/LetterboxUiController.java
@@ -17,6 +17,7 @@
 package com.android.server.wm;
 
 import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
+import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
 import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
 import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
 import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
@@ -27,6 +28,7 @@
 import static com.android.internal.util.FrameworkStatsLog.APP_COMPAT_STATE_CHANGED__LETTERBOX_POSITION__RIGHT;
 import static com.android.internal.util.FrameworkStatsLog.APP_COMPAT_STATE_CHANGED__LETTERBOX_POSITION__TOP;
 import static com.android.internal.util.FrameworkStatsLog.APP_COMPAT_STATE_CHANGED__LETTERBOX_POSITION__UNKNOWN_POSITION;
+import static com.android.internal.util.FrameworkStatsLog.APP_COMPAT_STATE_CHANGED__STATE__UNKNOWN;
 import static com.android.internal.util.FrameworkStatsLog.LETTERBOX_POSITION_CHANGED__POSITION_CHANGE__BOTTOM_TO_CENTER;
 import static com.android.internal.util.FrameworkStatsLog.LETTERBOX_POSITION_CHANGED__POSITION_CHANGE__CENTER_TO_BOTTOM;
 import static com.android.internal.util.FrameworkStatsLog.LETTERBOX_POSITION_CHANGED__POSITION_CHANGE__CENTER_TO_LEFT;
@@ -82,13 +84,44 @@
 
     private static final String TAG = TAG_WITH_CLASS_NAME ? "LetterboxUiController" : TAG_ATM;
 
+    private static final float UNDEFINED_ASPECT_RATIO = 0f;
+
     private final Point mTmpPoint = new Point();
 
     private final LetterboxConfiguration mLetterboxConfiguration;
+
     private final ActivityRecord mActivityRecord;
 
+    /*
+     * WindowContainerListener responsible to make translucent activities inherit
+     * constraints from the first opaque activity beneath them. It's null for not
+     * translucent activities.
+     */
+    @Nullable
+    private WindowContainerListener mLetterboxConfigListener;
+
     private boolean mShowWallpaperForLetterboxBackground;
 
+    // In case of transparent activities we might need to access the aspectRatio of the
+    // first opaque activity beneath.
+    private float mInheritedMinAspectRatio = UNDEFINED_ASPECT_RATIO;
+    private float mInheritedMaxAspectRatio = UNDEFINED_ASPECT_RATIO;
+
+    @Configuration.Orientation
+    private int mInheritedOrientation = Configuration.ORIENTATION_UNDEFINED;
+
+    // The app compat state for the opaque activity if any
+    private int mInheritedAppCompatState = APP_COMPAT_STATE_CHANGED__STATE__UNKNOWN;
+
+    // If true it means that the opaque activity beneath a translucent one is in SizeCompatMode.
+    private boolean mIsInheritedInSizeCompatMode;
+
+    // This is the SizeCompatScale of the opaque activity beneath a translucent one
+    private float mInheritedSizeCompatScale;
+
+    // The CompatDisplayInsets of the opaque activity beneath the translucent one.
+    private ActivityRecord.CompatDisplayInsets mInheritedCompatDisplayInsets;
+
     @Nullable
     private Letterbox mLetterbox;
 
@@ -220,7 +253,9 @@
                     : mActivityRecord.inMultiWindowMode()
                             ? mActivityRecord.getTask().getBounds()
                             : mActivityRecord.getRootTask().getParent().getBounds();
-            mLetterbox.layout(spaceToFill, w.getFrame(), mTmpPoint);
+            final Rect innerFrame = hasInheritedLetterboxBehavior()
+                    ? mActivityRecord.getWindowConfiguration().getBounds() : w.getFrame();
+            mLetterbox.layout(spaceToFill, innerFrame, mTmpPoint);
         } else if (mLetterbox != null) {
             mLetterbox.hide();
         }
@@ -305,7 +340,9 @@
     }
 
     private void handleHorizontalDoubleTap(int x) {
-        if (!isHorizontalReachabilityEnabled() || mActivityRecord.isInTransition()) {
+        // TODO(b/260857308): Investigate if enabling reachability for translucent activity
+        if (hasInheritedLetterboxBehavior() || !isHorizontalReachabilityEnabled()
+                || mActivityRecord.isInTransition()) {
             return;
         }
 
@@ -341,7 +378,9 @@
     }
 
     private void handleVerticalDoubleTap(int y) {
-        if (!isVerticalReachabilityEnabled() || mActivityRecord.isInTransition()) {
+        // TODO(b/260857308): Investigate if enabling reachability for translucent activity
+        if (hasInheritedLetterboxBehavior() || !isVerticalReachabilityEnabled()
+                || mActivityRecord.isInTransition()) {
             return;
         }
 
@@ -390,7 +429,7 @@
                 && parentConfiguration.windowConfiguration.getWindowingMode()
                         == WINDOWING_MODE_FULLSCREEN
                 && (parentConfiguration.orientation == ORIENTATION_LANDSCAPE
-                && mActivityRecord.getRequestedConfigurationOrientation() == ORIENTATION_PORTRAIT);
+                && mActivityRecord.getOrientationForReachability() == ORIENTATION_PORTRAIT);
     }
 
     private boolean isHorizontalReachabilityEnabled() {
@@ -412,7 +451,7 @@
                 && parentConfiguration.windowConfiguration.getWindowingMode()
                         == WINDOWING_MODE_FULLSCREEN
                 && (parentConfiguration.orientation == ORIENTATION_PORTRAIT
-                && mActivityRecord.getRequestedConfigurationOrientation() == ORIENTATION_LANDSCAPE);
+                && mActivityRecord.getOrientationForReachability() == ORIENTATION_LANDSCAPE);
     }
 
     private boolean isVerticalReachabilityEnabled() {
@@ -576,9 +615,7 @@
         // Rounded corners should be displayed above the taskbar.
         bounds.bottom =
                 Math.min(bounds.bottom, getTaskbarInsetsSource(mainWindow).getFrame().top);
-        if (mActivityRecord.inSizeCompatMode() && mActivityRecord.getCompatScale() < 1.0f) {
-            bounds.scale(1.0f / mActivityRecord.getCompatScale());
-        }
+        scaleIfNeeded(bounds);
     }
 
     private int getInsetsStateCornerRadius(
@@ -788,4 +825,144 @@
                 w.mAttrs.insetsFlags.appearance
         );
     }
+
+    /**
+     * Handles translucent activities letterboxing inheriting constraints from the
+     * first opaque activity beneath.
+     * @param parent The parent container.
+     */
+    void onActivityParentChanged(WindowContainer<?> parent) {
+        if (!mLetterboxConfiguration.isTranslucentLetterboxingEnabled()) {
+            return;
+        }
+        if (mLetterboxConfigListener != null) {
+            mLetterboxConfigListener.onRemoved();
+            clearInheritedConfig();
+        }
+        // In case mActivityRecord.getCompatDisplayInsets() is not null we don't apply the
+        // opaque activity constraints because we're expecting the activity is already letterboxed.
+        if (mActivityRecord.getTask() == null || mActivityRecord.getCompatDisplayInsets() != null
+                || mActivityRecord.fillsParent()) {
+            return;
+        }
+        final ActivityRecord firstOpaqueActivityBeneath = mActivityRecord.getTask().getActivity(
+                ActivityRecord::fillsParent, mActivityRecord, false /* includeBoundary */,
+                true /* traverseTopToBottom */);
+        if (firstOpaqueActivityBeneath == null
+                || mActivityRecord.launchedFromUid != firstOpaqueActivityBeneath.getUid()) {
+            // We skip letterboxing if the translucent activity doesn't have any opaque
+            // activities beneath of if it's launched from a different user (e.g. notification)
+            return;
+        }
+        inheritConfiguration(firstOpaqueActivityBeneath);
+        mLetterboxConfigListener = WindowContainer.overrideConfigurationPropagation(
+                mActivityRecord, firstOpaqueActivityBeneath,
+                (opaqueConfig, transparentConfig) -> {
+                    final Configuration mutatedConfiguration = new Configuration();
+                    final Rect parentBounds = parent.getWindowConfiguration().getBounds();
+                    final Rect bounds = mutatedConfiguration.windowConfiguration.getBounds();
+                    final Rect letterboxBounds = opaqueConfig.windowConfiguration.getBounds();
+                    // We cannot use letterboxBounds directly here because the position relies on
+                    // letterboxing. Using letterboxBounds directly, would produce a double offset.
+                    bounds.set(parentBounds.left, parentBounds.top,
+                            parentBounds.left + letterboxBounds.width(),
+                            parentBounds.top + letterboxBounds.height());
+                    // We need to initialize appBounds to avoid NPE. The actual value will
+                    // be set ahead when resolving the Configuration for the activity.
+                    mutatedConfiguration.windowConfiguration.setAppBounds(new Rect());
+                    return mutatedConfiguration;
+                });
+    }
+
+    /**
+     * @return {@code true} if the current activity is translucent with an opaque activity
+     * beneath. In this case it will inherit bounds, orientation and aspect ratios from
+     * the first opaque activity beneath.
+     */
+    boolean hasInheritedLetterboxBehavior() {
+        return mLetterboxConfigListener != null && !mActivityRecord.matchParentBounds();
+    }
+
+    /**
+     * @return {@code true} if the current activity is translucent with an opaque activity
+     * beneath and needs to inherit its orientation.
+     */
+    boolean hasInheritedOrientation() {
+        // To force a different orientation, the transparent one needs to have an explicit one
+        // otherwise the existing one is fine and the actual orientation will depend on the
+        // bounds.
+        // To avoid wrong behaviour, we're not forcing orientation for activities with not
+        // fixed orientation (e.g. permission dialogs).
+        return hasInheritedLetterboxBehavior()
+                && mActivityRecord.mOrientation != SCREEN_ORIENTATION_UNSPECIFIED;
+    }
+
+    float getInheritedMinAspectRatio() {
+        return mInheritedMinAspectRatio;
+    }
+
+    float getInheritedMaxAspectRatio() {
+        return mInheritedMaxAspectRatio;
+    }
+
+    int getInheritedAppCompatState() {
+        return mInheritedAppCompatState;
+    }
+
+    float getInheritedSizeCompatScale() {
+        return mInheritedSizeCompatScale;
+    }
+
+    @Configuration.Orientation
+    int getInheritedOrientation() {
+        return mInheritedOrientation;
+    }
+
+    public ActivityRecord.CompatDisplayInsets getInheritedCompatDisplayInsets() {
+        return mInheritedCompatDisplayInsets;
+    }
+
+    private void inheritConfiguration(ActivityRecord firstOpaque) {
+        // To avoid wrong behaviour, we're not forcing a specific aspet ratio to activities
+        // which are not already providing one (e.g. permission dialogs) and presumably also
+        // not resizable.
+        if (mActivityRecord.getMinAspectRatio() != UNDEFINED_ASPECT_RATIO) {
+            mInheritedMinAspectRatio = firstOpaque.getMinAspectRatio();
+        }
+        if (mActivityRecord.getMaxAspectRatio() != UNDEFINED_ASPECT_RATIO) {
+            mInheritedMaxAspectRatio = firstOpaque.getMaxAspectRatio();
+        }
+        mInheritedOrientation = firstOpaque.getRequestedConfigurationOrientation();
+        mInheritedAppCompatState = firstOpaque.getAppCompatState();
+        mIsInheritedInSizeCompatMode = firstOpaque.inSizeCompatMode();
+        mInheritedSizeCompatScale = firstOpaque.getCompatScale();
+        mInheritedCompatDisplayInsets = firstOpaque.getCompatDisplayInsets();
+    }
+
+    private void clearInheritedConfig() {
+        mLetterboxConfigListener = null;
+        mInheritedMinAspectRatio = UNDEFINED_ASPECT_RATIO;
+        mInheritedMaxAspectRatio = UNDEFINED_ASPECT_RATIO;
+        mInheritedOrientation = Configuration.ORIENTATION_UNDEFINED;
+        mInheritedAppCompatState = APP_COMPAT_STATE_CHANGED__STATE__UNKNOWN;
+        mIsInheritedInSizeCompatMode = false;
+        mInheritedSizeCompatScale = 1f;
+        mInheritedCompatDisplayInsets = null;
+    }
+
+    private void scaleIfNeeded(Rect bounds) {
+        if (boundsNeedToScale()) {
+            bounds.scale(1.0f / mActivityRecord.getCompatScale());
+        }
+    }
+
+    private boolean boundsNeedToScale() {
+        if (hasInheritedLetterboxBehavior()) {
+            return mIsInheritedInSizeCompatMode
+                    && mInheritedSizeCompatScale < 1.0f;
+        } else {
+            return mActivityRecord.inSizeCompatMode()
+                    && mActivityRecord.getCompatScale() < 1.0f;
+        }
+    }
 }
diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java
index 1ee4d6b..749fa1f 100644
--- a/services/core/java/com/android/server/wm/RootWindowContainer.java
+++ b/services/core/java/com/android/server/wm/RootWindowContainer.java
@@ -418,7 +418,8 @@
             } else if (!isDocument && !taskIsDocument
                     && mIdealRecord == null && mCandidateRecord == null
                     && task.rootAffinity != null) {
-                if (task.rootAffinity.equals(mTaskAffinity)) {
+                if (task.rootAffinity.equals(mTaskAffinity)
+                        && task.isSameRequiredDisplayCategory(mInfo)) {
                     ProtoLog.d(WM_DEBUG_TASKS, "Found matching affinity candidate!");
                     // It is possible for multiple tasks to have the same root affinity especially
                     // if they are in separate root tasks. We save off this candidate, but keep
@@ -2099,6 +2100,7 @@
                     // from the client organizer, so the PIP activity can get the correct config
                     // from the Task, and prevent conflict with the PipTaskOrganizer.
                     tf.updateRequestedOverrideConfiguration(EMPTY);
+                    tf.updateRelativeEmbeddedBounds();
                 }
             });
             rootTask.setWindowingMode(WINDOWING_MODE_PINNED);
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index a74a4b0..07e3b83 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -18,6 +18,7 @@
 
 import static android.app.ActivityManager.isStartResultSuccessful;
 import static android.app.ActivityTaskManager.INVALID_TASK_ID;
+import static android.app.ActivityTaskManager.INVALID_WINDOWING_MODE;
 import static android.app.ActivityTaskManager.RESIZE_MODE_FORCED;
 import static android.app.ActivityTaskManager.RESIZE_MODE_SYSTEM_SCREEN_ROTATION;
 import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SPLIT_SCREEN;
@@ -443,6 +444,8 @@
     @Surface.Rotation
     private int mRotation;
 
+    int mMultiWindowRestoreWindowingMode = INVALID_WINDOWING_MODE;
+
     /**
      * Last requested orientation reported to DisplayContent. This is different from {@link
      * #mOrientation} in the sense that this takes activities' requested orientation into
@@ -491,6 +494,9 @@
     private int mForceHiddenFlags = 0;
     private boolean mForceTranslucent = false;
 
+    // The display category name for this task.
+    String mRequiredDisplayCategory;
+
     // TODO(b/160201781): Revisit double invocation issue in Task#removeChild.
     /**
      * Skip {@link ActivityTaskSupervisor#removeTask(Task, boolean, boolean, String)} execution if
@@ -1011,6 +1017,7 @@
             // affinity -- we don't want it changing after initially set, but the initially
             // set value may be null.
             rootAffinity = affinity;
+            mRequiredDisplayCategory = info.requiredDisplayCategory;
         }
         effectiveUid = info.applicationInfo.uid;
         mIsEffectivelySystemApp = info.applicationInfo.isSystemApp();
@@ -1121,11 +1128,12 @@
         if (inMultiWindowMode() || !hasChild()) return false;
         if (intent != null) {
             final int returnHomeFlags = FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME;
+            if ((intent.getFlags() & returnHomeFlags) != returnHomeFlags) {
+                return false;
+            }
             final Task task = getDisplayArea() != null ? getDisplayArea().getRootHomeTask() : null;
-            final boolean isLockTaskModeViolation = task != null
-                    && mAtmService.getLockTaskController().isLockTaskModeViolation(task);
-            return (intent.getFlags() & returnHomeFlags) == returnHomeFlags
-                    && !isLockTaskModeViolation;
+            return !(task != null
+                    && mAtmService.getLockTaskController().isLockTaskModeViolation(task));
         }
         final Task bottomTask = getBottomMostTask();
         return bottomTask != this && bottomTask.returnsToHomeRootTask();
@@ -1591,15 +1599,22 @@
                 removeChild(r, reason);
             });
         } else {
+            final ArrayList<ActivityRecord> finishingActivities = new ArrayList<>();
+            forAllActivities(r -> {
+                if (r.finishing || (excludingTaskOverlay && r.isTaskOverlay())) {
+                    return;
+                }
+                finishingActivities.add(r);
+            });
+
             // Finish or destroy apps from the bottom to ensure that all the other activity have
             // been finished and the top task in another task gets resumed when a top activity is
             // removed. Otherwise, the next top activity could be started while the top activity
             // is removed, which is not necessary since the next top activity is on the same Task
             // and should also be removed.
-            forAllActivities((r) -> {
-                if (r.finishing || (excludingTaskOverlay && r.isTaskOverlay())) {
-                    return;
-                }
+            for (int i = finishingActivities.size() - 1; i >= 0; i--) {
+                final ActivityRecord r = finishingActivities.get(i);
+
                 // Prevent the transition from being executed too early if the top activity is
                 // resumed but the mVisibleRequested of any other activity is true, the transition
                 // should wait until next activity resumed.
@@ -1609,7 +1624,7 @@
                 } else {
                     r.destroyIfPossible(reason);
                 }
-            }, false /* traverseTopToBottom */);
+            }
         }
     }
 
@@ -1914,7 +1929,6 @@
             mTaskSupervisor.scheduleUpdateMultiWindowMode(this);
         }
 
-        final int newWinMode = getWindowingMode();
         if (shouldStartChangeTransition(prevWinMode, mTmpPrevBounds)) {
             initializeChangeTransition(mTmpPrevBounds);
         }
@@ -1928,16 +1942,15 @@
             }
         }
 
-        if (pipChanging && wasInPictureInPicture) {
+        if (pipChanging && wasInPictureInPicture
+                && !mTransitionController.isShellTransitionsEnabled()) {
             // If the top activity is changing from PiP to fullscreen with fixed rotation,
             // clear the crop and rotation matrix of task because fixed rotation will handle
             // the transformation on activity level. This also avoids flickering caused by the
             // latency of fullscreen task organizer configuring the surface.
             final ActivityRecord r = topRunningActivity();
             if (r != null && mDisplayContent.isFixedRotationLaunchingApp(r)) {
-                getSyncTransaction().setWindowCrop(mSurfaceControl, null)
-                        .setCornerRadius(mSurfaceControl, 0f)
-                        .setMatrix(mSurfaceControl, Matrix.IDENTITY_MATRIX, new float[9]);
+                resetSurfaceControlTransforms();
             }
         }
 
@@ -3529,13 +3542,10 @@
     }
 
     @Override
-    void onActivityVisibleRequestedChanged() {
-        final boolean prevVisibleRequested = mVisibleRequested;
-        // mVisibleRequested is updated in super method.
-        super.onActivityVisibleRequestedChanged();
-        if (prevVisibleRequested != mVisibleRequested) {
-            sendTaskFragmentParentInfoChangedIfNeeded();
-        }
+    protected boolean onChildVisibleRequestedChanged(@Nullable WindowContainer child) {
+        if (!super.onChildVisibleRequestedChanged(child)) return false;
+        sendTaskFragmentParentInfoChangedIfNeeded();
+        return true;
     }
 
     void sendTaskFragmentParentInfoChangedIfNeeded() {
@@ -6076,6 +6086,15 @@
         }
     }
 
+    /**
+     * Return true if the activityInfo has the same requiredDisplayCategory as this task.
+     */
+    boolean isSameRequiredDisplayCategory(@NonNull ActivityInfo info) {
+        return mRequiredDisplayCategory != null && mRequiredDisplayCategory.equals(
+                info.requiredDisplayCategory)
+                || (mRequiredDisplayCategory == null && info.requiredDisplayCategory == null);
+    }
+
     @Override
     public void dumpDebug(ProtoOutputStream proto, long fieldId,
             @WindowTraceLogLevel int logLevel) {
diff --git a/services/core/java/com/android/server/wm/TaskFragment.java b/services/core/java/com/android/server/wm/TaskFragment.java
index 66b868a..9126586 100644
--- a/services/core/java/com/android/server/wm/TaskFragment.java
+++ b/services/core/java/com/android/server/wm/TaskFragment.java
@@ -302,6 +302,14 @@
     private final IBinder mFragmentToken;
 
     /**
+     * The bounds of the embedded TaskFragment relative to the parent Task.
+     * {@code null} if it is not {@link #mIsEmbedded}
+     * TODO(b/261785978) cleanup with legacy app transition
+     */
+    @Nullable
+    private final Rect mRelativeEmbeddedBounds;
+
+    /**
      * Whether to delay the call to {@link #updateOrganizedTaskFragmentSurface()} when there is a
      * configuration change.
      */
@@ -316,9 +324,6 @@
 
     final Point mLastSurfaceSize = new Point();
 
-    /** The latest updated value when there's a child {@link #onActivityVisibleRequestedChanged} */
-    boolean mVisibleRequested;
-
     private final Rect mTmpBounds = new Rect();
     private final Rect mTmpFullBounds = new Rect();
     /** For calculating screenWidthDp and screenWidthDp, i.e. the area without the system bars. */
@@ -383,6 +388,7 @@
         mRootWindowContainer = mAtmService.mRootWindowContainer;
         mCreatedByOrganizer = createdByOrganizer;
         mIsEmbedded = isEmbedded;
+        mRelativeEmbeddedBounds = isEmbedded ? new Rect() : null;
         mTaskFragmentOrganizerController =
                 mAtmService.mWindowOrganizerController.mTaskFragmentOrganizerController;
         mFragmentToken = fragmentToken;
@@ -1355,7 +1361,7 @@
 
         if (next.attachedToProcess()) {
             if (DEBUG_SWITCH) {
-                Slog.v(TAG_SWITCH, "Resume running: " + next + " stopped=" + next.stopped
+                Slog.v(TAG_SWITCH, "Resume running: " + next + " stopped=" + next.mAppStopped
                         + " visibleRequested=" + next.isVisibleRequested());
             }
 
@@ -1370,7 +1376,7 @@
                     || mLastPausedActivity != null && !mLastPausedActivity.occludesParent();
 
             // This activity is now becoming visible.
-            if (!next.isVisibleRequested() || next.stopped || lastActivityTranslucent) {
+            if (!next.isVisibleRequested() || next.mAppStopped || lastActivityTranslucent) {
                 next.app.addToPendingTop();
                 next.setVisibility(true);
             }
@@ -1421,7 +1427,7 @@
                     // Do over!
                     mTaskSupervisor.scheduleResumeTopActivities();
                 }
-                if (!next.isVisibleRequested() || next.stopped) {
+                if (!next.isVisibleRequested() || next.mAppStopped) {
                     next.setVisibility(true);
                 }
                 next.completeResumeLocked();
@@ -1450,7 +1456,7 @@
 
                 // Well the app will no longer be stopped.
                 // Clear app token stopped state in window manager if needed.
-                next.notifyAppResumed(next.stopped);
+                next.notifyAppResumed();
 
                 EventLogTags.writeWmResumeActivity(next.mUserId, System.identityHashCode(next),
                         next.getTask().mTaskId, next.shortComponentName);
@@ -2410,16 +2416,53 @@
         }
     }
 
-    /** Whether we should prepare a transition for this {@link TaskFragment} bounds change. */
-    boolean shouldStartChangeTransition(Rect startBounds) {
+    /**
+     * Gets the relative bounds of this embedded TaskFragment. This should only be called on
+     * embedded TaskFragment.
+     */
+    @NonNull
+    Rect getRelativeEmbeddedBounds() {
+        if (mRelativeEmbeddedBounds == null) {
+            throw new IllegalStateException("The TaskFragment is not embedded");
+        }
+        return mRelativeEmbeddedBounds;
+    }
+
+    /**
+     * Updates the record of the relative bounds of this embedded TaskFragment. This should only be
+     * called when the embedded TaskFragment's override bounds are changed.
+     * Returns {@code true} if the bounds is changed.
+     */
+    void updateRelativeEmbeddedBounds() {
+        // We only record the override bounds, which means it will not be changed when it is filling
+        // Task, and resize with the parent.
+        getRequestedOverrideBounds(mTmpBounds);
+        getRelativePosition(mTmpPoint);
+        mTmpBounds.offsetTo(mTmpPoint.x, mTmpPoint.y);
+        mRelativeEmbeddedBounds.set(mTmpBounds);
+    }
+
+    /**
+     * Updates the record of relative bounds of this embedded TaskFragment, and checks whether we
+     * should prepare a transition for the bounds change.
+     */
+    boolean shouldStartChangeTransition(@NonNull Rect absStartBounds,
+            @NonNull Rect relStartBounds) {
         if (mTaskFragmentOrganizer == null || !canStartChangeTransition()) {
             return false;
         }
 
-        // Only take snapshot if the bounds are resized.
-        final Rect endBounds = getConfiguration().windowConfiguration.getBounds();
-        return endBounds.width() != startBounds.width()
-                || endBounds.height() != startBounds.height();
+        if (mTransitionController.isShellTransitionsEnabled()) {
+            // For Shell transition, the change will be collected anyway, so only take snapshot when
+            // the bounds are resized.
+            final Rect endBounds = getConfiguration().windowConfiguration.getBounds();
+            return endBounds.width() != absStartBounds.width()
+                    || endBounds.height() != absStartBounds.height();
+        } else {
+            // For legacy transition, we need to trigger a change transition as long as the bounds
+            // is changed, even if it is not resized.
+            return !relStartBounds.equals(mRelativeEmbeddedBounds);
+        }
     }
 
     /** Records the starting bounds of the closing organized TaskFragment. */
@@ -2787,22 +2830,6 @@
         return getWindowingMode() == WINDOWING_MODE_FULLSCREEN || matchParentBounds();
     }
 
-    void onActivityVisibleRequestedChanged() {
-        final boolean isVisibleRequested = isVisibleRequested();
-        if (mVisibleRequested == isVisibleRequested) {
-            return;
-        }
-        mVisibleRequested = isVisibleRequested;
-        final WindowContainer<?> parent = getParent();
-        if (parent == null) {
-            return;
-        }
-        final TaskFragment parentTf = parent.asTaskFragment();
-        if (parentTf != null) {
-            parentTf.onActivityVisibleRequestedChanged();
-        }
-    }
-
     @Nullable
     @Override
     TaskFragment getTaskFragment(Predicate<TaskFragment> callback) {
diff --git a/services/core/java/com/android/server/wm/Transition.java b/services/core/java/com/android/server/wm/Transition.java
index 2737456..b7f3cb4 100644
--- a/services/core/java/com/android/server/wm/Transition.java
+++ b/services/core/java/com/android/server/wm/Transition.java
@@ -636,7 +636,7 @@
                 // No need to clip the display in case seeing the clipped content when during the
                 // display rotation. No need to clip activities because they rely on clipping on
                 // task layers.
-                if (target.asDisplayContent() != null || target.asActivityRecord() != null) {
+                if (target.asTaskFragment() == null) {
                     t.setCrop(targetLeash, null /* crop */);
                 } else {
                     // Crop to the resolved override bounds.
diff --git a/services/core/java/com/android/server/wm/WallpaperWindowToken.java b/services/core/java/com/android/server/wm/WallpaperWindowToken.java
index 32cfb70..87f4ad4 100644
--- a/services/core/java/com/android/server/wm/WallpaperWindowToken.java
+++ b/services/core/java/com/android/server/wm/WallpaperWindowToken.java
@@ -41,8 +41,6 @@
 
     private static final String TAG = TAG_WITH_CLASS_NAME ? "WallpaperWindowToken" : TAG_WM;
 
-    private boolean mVisibleRequested = false;
-
     WallpaperWindowToken(WindowManagerService service, IBinder token, boolean explicit,
             DisplayContent dc, boolean ownerCanManageAppTokens) {
         this(service, token, explicit, dc, ownerCanManageAppTokens, null /* options */);
@@ -221,15 +219,17 @@
         return false;
     }
 
-    void setVisibleRequested(boolean visible) {
-        if (mVisibleRequested == visible) return;
-        mVisibleRequested = visible;
+    @Override
+    protected boolean setVisibleRequested(boolean visible) {
+        if (!super.setVisibleRequested(visible)) return false;
         setInsetsFrozen(!visible);
+        return true;
     }
 
     @Override
-    boolean isVisibleRequested() {
-        return mVisibleRequested;
+    protected boolean onChildVisibleRequestedChanged(@Nullable WindowContainer child) {
+        // Wallpaper manages visibleRequested directly (it's not determined by children)
+        return false;
     }
 
     @Override
diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java
index 6e61071..64574a7 100644
--- a/services/core/java/com/android/server/wm/WindowContainer.java
+++ b/services/core/java/com/android/server/wm/WindowContainer.java
@@ -315,6 +315,13 @@
     private boolean mIsFocusable = true;
 
     /**
+     * This indicates whether this window is visible by policy. This can precede physical
+     * visibility ({@link #isVisible} - whether it has a surface showing on the screen) in
+     * cases where an animation is on-going.
+     */
+    protected boolean mVisibleRequested;
+
+    /**
      * Used as a unique, cross-process identifier for this Container. It also serves a minimal
      * interface to other processes.
      */
@@ -635,7 +642,6 @@
         if (showSurfaceOnCreation()) {
             getSyncTransaction().show(mSurfaceControl);
         }
-        onSurfaceShown(getSyncTransaction());
         updateSurfacePositionNonOrganized();
         if (mLastMagnificationSpec != null) {
             applyMagnificationSpec(getSyncTransaction(), mLastMagnificationSpec);
@@ -690,13 +696,6 @@
         scheduleAnimation();
     }
 
-    /**
-     * Called when the surface is shown for the first time.
-     */
-    void onSurfaceShown(Transaction t) {
-        // do nothing
-    }
-
     // Temp. holders for a chain of containers we are currently processing.
     private final LinkedList<WindowContainer> mTmpChain1 = new LinkedList<>();
     private final LinkedList<WindowContainer> mTmpChain2 = new LinkedList<>();
@@ -772,6 +771,7 @@
             parent.mTreeWeight += child.mTreeWeight;
             parent = parent.getParent();
         }
+        onChildVisibleRequestedChanged(child);
         onChildPositionChanged(child);
     }
 
@@ -800,6 +800,7 @@
             parent.mTreeWeight -= child.mTreeWeight;
             parent = parent.getParent();
         }
+        onChildVisibleRequestedChanged(null);
         onChildPositionChanged(child);
     }
 
@@ -1023,10 +1024,11 @@
      * @param dc The display this container is on after changes.
      */
     void onDisplayChanged(DisplayContent dc) {
-        if (mDisplayContent != null) {
+        if (mDisplayContent != null && mDisplayContent != dc) {
+            // Cancel any change transition queued-up for this container on the old display when
+            // this container is moved from the old display.
             mDisplayContent.mClosingChangingContainers.remove(this);
             if (mDisplayContent.mChangingContainers.remove(this)) {
-                // Cancel any change transition queued-up for this container on the old display.
                 mSurfaceFreezer.unfreeze(getSyncTransaction());
             }
         }
@@ -1288,13 +1290,41 @@
      * the transition is finished.
      */
     boolean isVisibleRequested() {
-        for (int i = mChildren.size() - 1; i >= 0; --i) {
-            final WindowContainer child = mChildren.get(i);
-            if (child.isVisibleRequested()) {
-                return true;
+        return mVisibleRequested;
+    }
+
+    /** @return `true` if visibleRequested changed. */
+    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PROTECTED)
+    boolean setVisibleRequested(boolean visible) {
+        if (mVisibleRequested == visible) return false;
+        mVisibleRequested = visible;
+        final WindowContainer parent = getParent();
+        if (parent != null) {
+            parent.onChildVisibleRequestedChanged(this);
+        }
+        return true;
+    }
+
+    /**
+     * @param child The changed or added child. `null` if a child was removed.
+     * @return `true` if visibleRequested changed.
+     */
+    protected boolean onChildVisibleRequestedChanged(@Nullable WindowContainer child) {
+        final boolean childVisReq = child != null && child.isVisibleRequested();
+        boolean newVisReq = mVisibleRequested;
+        if (childVisReq && !mVisibleRequested) {
+            newVisReq = true;
+        } else if (!childVisReq && mVisibleRequested) {
+            newVisReq = false;
+            for (int i = mChildren.size() - 1; i >= 0; --i) {
+                final WindowContainer wc = mChildren.get(i);
+                if (wc != child && wc.isVisibleRequested()) {
+                    newVisReq = true;
+                    break;
+                }
             }
         }
-        return false;
+        return setVisibleRequested(newVisReq);
     }
 
     /**
@@ -3025,13 +3055,16 @@
                     // When there are more than one changing containers, it may leave part of the
                     // screen empty. Show background color to cover that.
                     showBackdrop = getDisplayContent().mChangingContainers.size() > 1;
+                    backdropColor = appTransition.getNextAppTransitionBackgroundColor();
                 } else {
                     // Check whether the app has requested to show backdrop for open/close
                     // transition.
                     final Animation a = appTransition.getNextAppRequestedAnimation(enter);
-                    showBackdrop = a != null && a.getShowBackdrop();
+                    if (a != null) {
+                        showBackdrop = a.getShowBackdrop();
+                        backdropColor = a.getBackdropColor();
+                    }
                 }
-                backdropColor = appTransition.getNextAppTransitionBackgroundColor();
             }
             final Rect localBounds = new Rect(mTmpRect);
             localBounds.offsetTo(mTmpPoint.x, mTmpPoint.y);
@@ -3948,27 +3981,54 @@
         unregisterConfigurationChangeListener(listener);
     }
 
+    static void overrideConfigurationPropagation(WindowContainer<?> receiver,
+            WindowContainer<?> supplier) {
+        overrideConfigurationPropagation(receiver, supplier, null /* configurationMerger */);
+    }
+
     /**
      * Forces the receiver container to always use the configuration of the supplier container as
      * its requested override configuration. It allows to propagate configuration without changing
      * the relationship between child and parent.
+     *
+     * @param receiver            The {@link WindowContainer<?>} which will receive the {@link
+     *                            Configuration} result of the merging operation.
+     * @param supplier            The {@link WindowContainer<?>} which provides the initial {@link
+     *                            Configuration}.
+     * @param configurationMerger A {@link ConfigurationMerger} which combines the {@link
+     *                            Configuration} of the receiver and the supplier.
      */
-    static void overrideConfigurationPropagation(WindowContainer<?> receiver,
-            WindowContainer<?> supplier) {
+    static WindowContainerListener overrideConfigurationPropagation(WindowContainer<?> receiver,
+            WindowContainer<?> supplier, @Nullable ConfigurationMerger configurationMerger) {
         final ConfigurationContainerListener listener = new ConfigurationContainerListener() {
             @Override
             public void onMergedOverrideConfigurationChanged(Configuration mergedOverrideConfig) {
-                receiver.onRequestedOverrideConfigurationChanged(supplier.getConfiguration());
+                final Configuration mergedConfiguration =
+                        configurationMerger != null
+                                ? configurationMerger.merge(mergedOverrideConfig,
+                                receiver.getConfiguration())
+                                : supplier.getConfiguration();
+                receiver.onRequestedOverrideConfigurationChanged(mergedConfiguration);
             }
         };
         supplier.registerConfigurationChangeListener(listener);
-        receiver.registerWindowContainerListener(new WindowContainerListener() {
+        final WindowContainerListener wcListener = new WindowContainerListener() {
             @Override
             public void onRemoved() {
                 receiver.unregisterWindowContainerListener(this);
                 supplier.unregisterConfigurationChangeListener(listener);
             }
-        });
+        };
+        receiver.registerWindowContainerListener(wcListener);
+        return wcListener;
+    }
+
+    /**
+     * Abstraction for functions merging two {@link Configuration} objects into one.
+     */
+    @FunctionalInterface
+    interface ConfigurationMerger {
+        Configuration merge(Configuration first, Configuration second);
     }
 
     /**
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index f6f825f..be1e7e6 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -168,7 +168,6 @@
 import android.app.IAssistDataReceiver;
 import android.app.WindowConfiguration;
 import android.content.BroadcastReceiver;
-import android.content.ComponentName;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
@@ -178,7 +177,6 @@
 import android.content.pm.PackageManagerInternal;
 import android.content.pm.TestUtilityService;
 import android.content.res.Configuration;
-import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.database.ContentObserver;
 import android.graphics.Bitmap;
@@ -3718,19 +3716,9 @@
                 return;
             }
 
-            try {
-                // TODO(b/221898546): remove the following and convert to jni
-                IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlingerAIDL");
-                if (surfaceFlinger != null) {
-                    ProtoLog.i(WM_ERROR, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
-                    Parcel data = Parcel.obtain();
-                    data.writeInterfaceToken("android.gui.ISurfaceComposer");
-                    surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, // BOOT_FINISHED
-                            data, null, 0);
-                    data.recycle();
-                }
-            } catch (RemoteException ex) {
-                ProtoLog.e(WM_ERROR, "Boot completed: SurfaceFlinger is dead!");
+            if (!SurfaceControl.bootFinished()) {
+                ProtoLog.w(WM_ERROR, "performEnableScreen: bootFinished() failed.");
+                return;
             }
 
             EventLogTags.writeWmBootAnimationDone(SystemClock.uptimeMillis());
diff --git a/services/core/java/com/android/server/wm/WindowManagerShellCommand.java b/services/core/java/com/android/server/wm/WindowManagerShellCommand.java
index 46a30fb..060784d 100644
--- a/services/core/java/com/android/server/wm/WindowManagerShellCommand.java
+++ b/services/core/java/com/android/server/wm/WindowManagerShellCommand.java
@@ -978,6 +978,29 @@
         return 0;
     }
 
+    private int runSetTranslucentLetterboxingEnabled(PrintWriter pw) {
+        String arg = getNextArg();
+        final boolean enabled;
+        switch (arg) {
+            case "true":
+            case "1":
+                enabled = true;
+                break;
+            case "false":
+            case "0":
+                enabled = false;
+                break;
+            default:
+                getErrPrintWriter().println("Error: expected true, 1, false, 0, but got " + arg);
+                return -1;
+        }
+
+        synchronized (mInternal.mGlobalLock) {
+            mLetterboxConfiguration.setTranslucentLetterboxingOverrideEnabled(enabled);
+        }
+        return 0;
+    }
+
     private int runSetLetterboxStyle(PrintWriter pw) throws RemoteException {
         if (peekNextArg() == null) {
             getErrPrintWriter().println("Error: No arguments provided.");
@@ -1033,6 +1056,9 @@
                 case "--isSplitScreenAspectRatioForUnresizableAppsEnabled":
                     runSetLetterboxIsSplitScreenAspectRatioForUnresizableAppsEnabled(pw);
                     break;
+                case "--isTranslucentLetterboxingEnabled":
+                    runSetTranslucentLetterboxingEnabled(pw);
+                    break;
                 default:
                     getErrPrintWriter().println(
                             "Error: Unrecognized letterbox style option: " + arg);
@@ -1096,6 +1122,9 @@
                         mLetterboxConfiguration
                                 .getIsSplitScreenAspectRatioForUnresizableAppsEnabled();
                         break;
+                    case "isTranslucentLetterboxingEnabled":
+                        mLetterboxConfiguration.resetTranslucentLetterboxingEnabled();
+                        break;
                     default:
                         getErrPrintWriter().println(
                                 "Error: Unrecognized letterbox style option: " + arg);
@@ -1196,6 +1225,7 @@
             mLetterboxConfiguration.resetDefaultPositionForVerticalReachability();
             mLetterboxConfiguration.resetIsEducationEnabled();
             mLetterboxConfiguration.resetIsSplitScreenAspectRatioForUnresizableAppsEnabled();
+            mLetterboxConfiguration.resetTranslucentLetterboxingEnabled();
         }
     }
 
@@ -1232,7 +1262,6 @@
             pw.println("Is using split screen aspect ratio as aspect ratio for unresizable apps: "
                     + mLetterboxConfiguration
                             .getIsSplitScreenAspectRatioForUnresizableAppsEnabled());
-
             pw.println("Background type: "
                     + LetterboxConfiguration.letterboxBackgroundTypeToString(
                             mLetterboxConfiguration.getLetterboxBackgroundType()));
@@ -1242,6 +1271,12 @@
                     + mLetterboxConfiguration.getLetterboxBackgroundWallpaperBlurRadius());
             pw.println("    Wallpaper dark scrim alpha: "
                     + mLetterboxConfiguration.getLetterboxBackgroundWallpaperDarkScrimAlpha());
+
+            if (mLetterboxConfiguration.isTranslucentLetterboxingEnabled()) {
+                pw.println("Letterboxing for translucent activities: enabled");
+            } else {
+                pw.println("Letterboxing for translucent activities: disabled");
+            }
         }
         return 0;
     }
@@ -1434,12 +1469,16 @@
         pw.println("      --isSplitScreenAspectRatioForUnresizableAppsEnabled [true|1|false|0]");
         pw.println("        Whether using split screen aspect ratio as a default aspect ratio for");
         pw.println("        unresizable apps.");
+        pw.println("      --isTranslucentLetterboxingEnabled [true|1|false|0]");
+        pw.println("        Whether letterboxing for translucent activities is enabled.");
+
         pw.println("  reset-letterbox-style [aspectRatio|cornerRadius|backgroundType");
         pw.println("      |backgroundColor|wallpaperBlurRadius|wallpaperDarkScrimAlpha");
         pw.println("      |horizontalPositionMultiplier|verticalPositionMultiplier");
         pw.println("      |isHorizontalReachabilityEnabled|isVerticalReachabilityEnabled");
-        pw.println("      isEducationEnabled||defaultPositionMultiplierForHorizontalReachability");
-        pw.println("      ||defaultPositionMultiplierForVerticalReachability]");
+        pw.println("      |isEducationEnabled||defaultPositionMultiplierForHorizontalReachability");
+        pw.println("      |isTranslucentLetterboxingEnabled");
+        pw.println("      |defaultPositionMultiplierForVerticalReachability]");
         pw.println("    Resets overrides to default values for specified properties separated");
         pw.println("    by space, e.g. 'reset-letterbox-style aspectRatio cornerRadius'.");
         pw.println("    If no arguments provided, all values will be reset.");
diff --git a/services/core/java/com/android/server/wm/WindowOrganizerController.java b/services/core/java/com/android/server/wm/WindowOrganizerController.java
index 738adc3..7241172 100644
--- a/services/core/java/com/android/server/wm/WindowOrganizerController.java
+++ b/services/core/java/com/android/server/wm/WindowOrganizerController.java
@@ -148,7 +148,8 @@
     @VisibleForTesting
     final ArrayMap<IBinder, TaskFragment> mLaunchTaskFragments = new ArrayMap<>();
 
-    private final Rect mTmpBounds = new Rect();
+    private final Rect mTmpBounds0 = new Rect();
+    private final Rect mTmpBounds1 = new Rect();
 
     WindowOrganizerController(ActivityTaskManagerService atm) {
         mService = atm;
@@ -797,14 +798,15 @@
         // When the TaskFragment is resized, we may want to create a change transition for it, for
         // which we want to defer the surface update until we determine whether or not to start
         // change transition.
-        mTmpBounds.set(taskFragment.getBounds());
+        mTmpBounds0.set(taskFragment.getBounds());
+        mTmpBounds1.set(taskFragment.getRelativeEmbeddedBounds());
         taskFragment.deferOrganizedTaskFragmentSurfaceUpdate();
         final int effects = applyChanges(taskFragment, c, errorCallbackToken);
-        if (taskFragment.shouldStartChangeTransition(mTmpBounds)) {
-            taskFragment.initializeChangeTransition(mTmpBounds);
+        taskFragment.updateRelativeEmbeddedBounds();
+        if (taskFragment.shouldStartChangeTransition(mTmpBounds0, mTmpBounds1)) {
+            taskFragment.initializeChangeTransition(mTmpBounds0);
         }
         taskFragment.continueOrganizedTaskFragmentSurfaceUpdate();
-        mTmpBounds.set(0, 0, 0, 0);
         return effects;
     }
 
@@ -1907,7 +1909,18 @@
         // actions.
         taskFragment.setTaskFragmentOrganizer(creationParams.getOrganizer(),
                 ownerActivity.getUid(), ownerActivity.info.processName);
-        ownerTask.addChild(taskFragment, POSITION_TOP);
+        final int position;
+        if (creationParams.getPairedPrimaryFragmentToken() != null) {
+            // When there is a paired primary TaskFragment, we want to place the new TaskFragment
+            // right above the paired one to make sure there is no other window in between.
+            final TaskFragment pairedPrimaryTaskFragment = getTaskFragment(
+                    creationParams.getPairedPrimaryFragmentToken());
+            final int pairedPosition = ownerTask.mChildren.indexOf(pairedPrimaryTaskFragment);
+            position = pairedPosition != -1 ? pairedPosition + 1 : POSITION_TOP;
+        } else {
+            position = POSITION_TOP;
+        }
+        ownerTask.addChild(taskFragment, position);
         taskFragment.setWindowingMode(creationParams.getWindowingMode());
         taskFragment.setBounds(creationParams.getInitialBounds());
         mLaunchTaskFragments.put(creationParams.getFragmentToken(), taskFragment);
diff --git a/services/core/java/com/android/server/wm/WindowProcessController.java b/services/core/java/com/android/server/wm/WindowProcessController.java
index d2cd8f8..e9b81ec 100644
--- a/services/core/java/com/android/server/wm/WindowProcessController.java
+++ b/services/core/java/com/android/server/wm/WindowProcessController.java
@@ -903,7 +903,7 @@
             if (launchedActivity == activity) {
                 continue;
             }
-            if (!activity.stopped) {
+            if (!activity.mAppStopped) {
                 return true;
             }
         }
@@ -926,7 +926,7 @@
     boolean shouldKillProcessForRemovedTask(Task task) {
         for (int k = 0; k < mActivities.size(); k++) {
             final ActivityRecord activity = mActivities.get(k);
-            if (!activity.stopped) {
+            if (!activity.mAppStopped) {
                 // Don't kill process(es) that has an activity not stopped.
                 return false;
             }
@@ -956,7 +956,7 @@
             }
             // Don't consider any activities that are currently not in a state where they
             // can be destroyed.
-            if (r.isVisibleRequested() || !r.stopped || !r.hasSavedState() || !r.isDestroyable()
+            if (r.isVisibleRequested() || !r.mAppStopped || !r.hasSavedState() || !r.isDestroyable()
                     || r.isState(STARTED, RESUMED, PAUSING, PAUSED, STOPPING)) {
                 if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Not releasing in-use activity: " + r);
                 continue;
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index c6578ef..1b7bd9e 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -2090,7 +2090,10 @@
         } else {
             final Task task = getTask();
             final boolean canFromTask = task != null && task.canAffectSystemUiFlags();
-            return canFromTask && mActivityRecord.isVisible();
+            return canFromTask && mActivityRecord.isVisible()
+            // Do not let snapshot window control the bar
+                    && (mAttrs.type != TYPE_APPLICATION_STARTING
+                    || !(mStartingData instanceof SnapshotStartingData));
         }
     }
 
diff --git a/services/core/java/com/android/server/wm/WindowToken.java b/services/core/java/com/android/server/wm/WindowToken.java
index f2527b6..c6b7898 100644
--- a/services/core/java/com/android/server/wm/WindowToken.java
+++ b/services/core/java/com/android/server/wm/WindowToken.java
@@ -582,9 +582,7 @@
                 .setCallsite("WindowToken.getOrCreateFixedRotationLeash")
                 .build();
         t.setPosition(leash, mLastSurfacePosition.x, mLastSurfacePosition.y);
-        t.show(leash);
         t.reparent(getSurfaceControl(), leash);
-        t.setAlpha(getSurfaceControl(), 1.f);
         mFixedRotationTransformLeash = leash;
         updateSurfaceRotation(t, rotation, mFixedRotationTransformLeash);
         return mFixedRotationTransformLeash;
diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp
index 969056e..c36c571 100644
--- a/services/core/jni/com_android_server_input_InputManagerService.cpp
+++ b/services/core/jni/com_android_server_input_InputManagerService.cpp
@@ -120,6 +120,7 @@
     jmethodID getExcludedDeviceNames;
     jmethodID getInputPortAssociations;
     jmethodID getInputUniqueIdAssociations;
+    jmethodID getDeviceTypeAssociations;
     jmethodID getKeyRepeatTimeout;
     jmethodID getKeyRepeatDelay;
     jmethodID getHoverTapTimeout;
@@ -411,6 +412,8 @@
     void ensureSpriteControllerLocked();
     sp<SurfaceControl> getParentSurfaceForPointers(int displayId);
     static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
+    std::unordered_map<std::string, std::string> readMapFromInterleavedJavaArray(
+            jmethodID method, const char* methodName);
 
     static inline JNIEnv* jniEnv() { return AndroidRuntime::getJNIEnv(); }
 };
@@ -583,21 +586,14 @@
         }
         env->DeleteLocalRef(portAssociations);
     }
-    outConfig->uniqueIdAssociations.clear();
-    jobjectArray uniqueIdAssociations = jobjectArray(
-            env->CallObjectMethod(mServiceObj, gServiceClassInfo.getInputUniqueIdAssociations));
-    if (!checkAndClearExceptionFromCallback(env, "getInputUniqueIdAssociations") &&
-        uniqueIdAssociations) {
-        jsize length = env->GetArrayLength(uniqueIdAssociations);
-        for (jsize i = 0; i < length / 2; i++) {
-            std::string inputDeviceUniqueId =
-                    getStringElementFromJavaArray(env, uniqueIdAssociations, 2 * i);
-            std::string displayUniqueId =
-                    getStringElementFromJavaArray(env, uniqueIdAssociations, 2 * i + 1);
-            outConfig->uniqueIdAssociations.insert({inputDeviceUniqueId, displayUniqueId});
-        }
-        env->DeleteLocalRef(uniqueIdAssociations);
-    }
+
+    outConfig->uniqueIdAssociations =
+            readMapFromInterleavedJavaArray(gServiceClassInfo.getInputUniqueIdAssociations,
+                                            "getInputUniqueIdAssociations");
+
+    outConfig->deviceTypeAssociations =
+            readMapFromInterleavedJavaArray(gServiceClassInfo.getDeviceTypeAssociations,
+                                            "getDeviceTypeAssociations");
 
     jint hoverTapTimeout = env->CallIntMethod(mServiceObj,
             gServiceClassInfo.getHoverTapTimeout);
@@ -647,6 +643,23 @@
     } // release lock
 }
 
+std::unordered_map<std::string, std::string> NativeInputManager::readMapFromInterleavedJavaArray(
+        jmethodID method, const char* methodName) {
+    JNIEnv* env = jniEnv();
+    jobjectArray javaArray = jobjectArray(env->CallObjectMethod(mServiceObj, method));
+    std::unordered_map<std::string, std::string> map;
+    if (!checkAndClearExceptionFromCallback(env, methodName) && javaArray) {
+        jsize length = env->GetArrayLength(javaArray);
+        for (jsize i = 0; i < length / 2; i++) {
+            std::string key = getStringElementFromJavaArray(env, javaArray, 2 * i);
+            std::string value = getStringElementFromJavaArray(env, javaArray, 2 * i + 1);
+            map.insert({key, value});
+        }
+    }
+    env->DeleteLocalRef(javaArray);
+    return map;
+}
+
 std::shared_ptr<PointerControllerInterface> NativeInputManager::obtainPointerController(
         int32_t /* deviceId */) {
     ATRACE_CALL();
@@ -1578,6 +1591,12 @@
     return vec;
 }
 
+static void nativeAddKeyRemapping(JNIEnv* env, jobject nativeImplObj, jint deviceId,
+                                  jint fromKeyCode, jint toKeyCode) {
+    NativeInputManager* im = getNativeInputManager(env, nativeImplObj);
+    im->getInputManager()->getReader().addKeyRemapping(deviceId, fromKeyCode, toKeyCode);
+}
+
 static jboolean nativeHasKeys(JNIEnv* env, jobject nativeImplObj, jint deviceId, jint sourceMask,
                               jintArray keyCodes, jbooleanArray outFlags) {
     NativeInputManager* im = getNativeInputManager(env, nativeImplObj);
@@ -2231,6 +2250,12 @@
             InputReaderConfiguration::CHANGE_DISPLAY_INFO);
 }
 
+static void nativeChangeTypeAssociation(JNIEnv* env, jobject nativeImplObj) {
+    NativeInputManager* im = getNativeInputManager(env, nativeImplObj);
+    im->getInputManager()->getReader().requestRefreshConfiguration(
+            InputReaderConfiguration::CHANGE_DEVICE_TYPE);
+}
+
 static void nativeSetMotionClassifierEnabled(JNIEnv* env, jobject nativeImplObj, jboolean enabled) {
     NativeInputManager* im = getNativeInputManager(env, nativeImplObj);
 
@@ -2360,6 +2385,7 @@
         {"getScanCodeState", "(III)I", (void*)nativeGetScanCodeState},
         {"getKeyCodeState", "(III)I", (void*)nativeGetKeyCodeState},
         {"getSwitchState", "(III)I", (void*)nativeGetSwitchState},
+        {"addKeyRemapping", "(III)V", (void*)nativeAddKeyRemapping},
         {"hasKeys", "(II[I[Z)Z", (void*)nativeHasKeys},
         {"getKeyCodeForKeyLocation", "(II)I", (void*)nativeGetKeyCodeForKeyLocation},
         {"createInputChannel", "(Ljava/lang/String;)Landroid/view/InputChannel;",
@@ -2418,6 +2444,7 @@
         {"canDispatchToDisplay", "(II)Z", (void*)nativeCanDispatchToDisplay},
         {"notifyPortAssociationsChanged", "()V", (void*)nativeNotifyPortAssociationsChanged},
         {"changeUniqueIdAssociation", "()V", (void*)nativeChangeUniqueIdAssociation},
+        {"changeTypeAssociation", "()V", (void*)nativeChangeTypeAssociation},
         {"setDisplayEligibilityForPointerCapture", "(IZ)V",
          (void*)nativeSetDisplayEligibilityForPointerCapture},
         {"setMotionClassifierEnabled", "(Z)V", (void*)nativeSetMotionClassifierEnabled},
@@ -2539,6 +2566,9 @@
     GET_METHOD_ID(gServiceClassInfo.getInputUniqueIdAssociations, clazz,
                   "getInputUniqueIdAssociations", "()[Ljava/lang/String;");
 
+    GET_METHOD_ID(gServiceClassInfo.getDeviceTypeAssociations, clazz, "getDeviceTypeAssociations",
+                  "()[Ljava/lang/String;");
+
     GET_METHOD_ID(gServiceClassInfo.getKeyRepeatTimeout, clazz,
             "getKeyRepeatTimeout", "()I");
 
diff --git a/services/core/jni/stats/SurfaceFlingerPuller.cpp b/services/core/jni/stats/SurfaceFlingerPuller.cpp
index 8873673..b959798 100644
--- a/services/core/jni/stats/SurfaceFlingerPuller.cpp
+++ b/services/core/jni/stats/SurfaceFlingerPuller.cpp
@@ -122,9 +122,12 @@
     for (const auto& atom : atomList.atom()) {
         // The strings must outlive the BytesFields, which only have a pointer to the data.
         std::string present2PresentStr, post2presentStr, acquire2PresentStr, latch2PresentStr,
-                desired2PresentStr, post2AcquireStr, frameRateVoteStr, appDeadlineMissesStr;
+                desired2PresentStr, post2AcquireStr, frameRateVoteStr, appDeadlineMissesStr,
+                present2PresentDeltaStr;
         optional<BytesField> present2Present =
                 getBytes(atom.present_to_present(), present2PresentStr);
+        optional<BytesField> present2PresentDelta =
+                getBytes(atom.present_to_present_delta(), present2PresentDeltaStr);
         optional<BytesField> post2present = getBytes(atom.post_to_present(), post2presentStr);
         optional<BytesField> acquire2Present =
                 getBytes(atom.acquire_to_present(), acquire2PresentStr);
@@ -138,7 +141,8 @@
 
         // Fail if any serialization to bytes failed.
         if (!present2Present || !post2present || !acquire2Present || !latch2Present ||
-            !desired2Present || !post2Acquire || !frameRateVote || !appDeadlineMisses) {
+            !desired2Present || !post2Acquire || !frameRateVote || !appDeadlineMisses ||
+            !present2PresentDelta) {
             return AStatsManager_PULL_SKIP;
         }
 
@@ -159,7 +163,7 @@
                                       atom.total_jank_frames_app_buffer_stuffing(),
                                       atom.display_refresh_rate_bucket(), atom.render_rate_bucket(),
                                       frameRateVote.value(), appDeadlineMisses.value(),
-                                      atom.game_mode());
+                                      atom.game_mode(), present2PresentDelta.value());
     }
     return AStatsManager_PULL_SUCCESS;
 }
diff --git a/services/core/jni/tvinput/JTvInputHal.cpp b/services/core/jni/tvinput/JTvInputHal.cpp
index 0f6ef03..3453cbd 100644
--- a/services/core/jni/tvinput/JTvInputHal.cpp
+++ b/services/core/jni/tvinput/JTvInputHal.cpp
@@ -42,8 +42,11 @@
                                std::shared_ptr<ITvInputWrapper>(new ITvInputWrapper(hidlITvInput)),
                                looper);
     }
-    ::ndk::SpAIBinder binder(AServiceManager_waitForService(TV_INPUT_AIDL_SERVICE_NAME));
-    std::shared_ptr<AidlITvInput> aidlITvInput = AidlITvInput::fromBinder(binder);
+    std::shared_ptr<AidlITvInput> aidlITvInput = nullptr;
+    if (AServiceManager_isDeclared(TV_INPUT_AIDL_SERVICE_NAME)) {
+        ::ndk::SpAIBinder binder(AServiceManager_waitForService(TV_INPUT_AIDL_SERVICE_NAME));
+        aidlITvInput = AidlITvInput::fromBinder(binder);
+    }
     if (aidlITvInput == nullptr) {
         ALOGE("Couldn't get tv.input service.");
         return nullptr;
diff --git a/services/core/xsd/display-device-config/display-device-config.xsd b/services/core/xsd/display-device-config/display-device-config.xsd
index b914051..f96c9293 100644
--- a/services/core/xsd/display-device-config/display-device-config.xsd
+++ b/services/core/xsd/display-device-config/display-device-config.xsd
@@ -44,9 +44,11 @@
                 </xs:element>
                 <xs:element type="highBrightnessMode" name="highBrightnessMode" minOccurs="0"
                             maxOccurs="1"/>
-                <xs:element type="displayQuirks" name="quirks" minOccurs="0" maxOccurs="1" />
+                <xs:element type="displayQuirks" name="quirks" minOccurs="0" maxOccurs="1"/>
                 <xs:element type="autoBrightness" name="autoBrightness" minOccurs="0"
-                            maxOccurs="1" />
+                            maxOccurs="1"/>
+                <xs:element type="refreshRateConfigs" name="refreshRate" minOccurs="0"
+                            maxOccurs="1"/>
                 <xs:element type="nonNegativeDecimal" name="screenBrightnessRampFastDecrease">
                     <xs:annotation name="final"/>
                 </xs:element>
@@ -324,7 +326,7 @@
                 <xs:annotation name="final"/>
             </xs:element>
         </xs:sequence>
-      </xs:complexType>
+    </xs:complexType>
 
     <!-- Thresholds for brightness changes. -->
     <xs:complexType name="thresholds">
@@ -452,4 +454,35 @@
             </xs:element>
         </xs:sequence>
     </xs:complexType>
+
+    <xs:complexType name="refreshRateConfigs">
+        <xs:element name="lowerBlockingZoneConfigs" type="blockingZoneConfig"
+                    minOccurs="0" maxOccurs="1">
+            <xs:annotation name="final"/>
+        </xs:element>
+        <xs:element name="higherBlockingZoneConfigs" type="blockingZoneConfig"
+                    minOccurs="0" maxOccurs="1">
+            <xs:annotation name="final"/>
+        </xs:element>
+    </xs:complexType>
+
+    <xs:complexType name="blockingZoneConfig">
+        <xs:element name="defaultRefreshRate" type="xs:nonNegativeInteger"
+                    minOccurs="1" maxOccurs="1">
+            <xs:annotation name="final"/>
+        </xs:element>
+        <xs:element name="blockingZoneThreshold" type="blockingZoneThreshold"
+                    minOccurs="1" maxOccurs="1">
+            <xs:annotation name="final"/>
+        </xs:element>
+    </xs:complexType>
+
+    <xs:complexType name="blockingZoneThreshold">
+        <xs:sequence>
+            <xs:element name="displayBrightnessPoint" type="displayBrightnessPoint"
+                        minOccurs="1" maxOccurs="unbounded">
+                <xs:annotation name="final"/>
+            </xs:element>
+        </xs:sequence>
+    </xs:complexType>
 </xs:schema>
diff --git a/services/core/xsd/display-device-config/schema/current.txt b/services/core/xsd/display-device-config/schema/current.txt
index d89bd7c..6276eda 100644
--- a/services/core/xsd/display-device-config/schema/current.txt
+++ b/services/core/xsd/display-device-config/schema/current.txt
@@ -13,6 +13,19 @@
     method public void setEnabled(boolean);
   }
 
+  public class BlockingZoneConfig {
+    ctor public BlockingZoneConfig();
+    method public final com.android.server.display.config.BlockingZoneThreshold getBlockingZoneThreshold();
+    method public final java.math.BigInteger getDefaultRefreshRate();
+    method public final void setBlockingZoneThreshold(com.android.server.display.config.BlockingZoneThreshold);
+    method public final void setDefaultRefreshRate(java.math.BigInteger);
+  }
+
+  public class BlockingZoneThreshold {
+    ctor public BlockingZoneThreshold();
+    method public final java.util.List<com.android.server.display.config.DisplayBrightnessPoint> getDisplayBrightnessPoint();
+  }
+
   public class BrightnessThresholds {
     ctor public BrightnessThresholds();
     method public final com.android.server.display.config.ThresholdPoints getBrightnessThresholdPoints();
@@ -76,6 +89,7 @@
     method public final com.android.server.display.config.SensorDetails getLightSensor();
     method public final com.android.server.display.config.SensorDetails getProxSensor();
     method public com.android.server.display.config.DisplayQuirks getQuirks();
+    method public com.android.server.display.config.RefreshRateConfigs getRefreshRate();
     method @NonNull public final java.math.BigDecimal getScreenBrightnessDefault();
     method @NonNull public final com.android.server.display.config.NitsMap getScreenBrightnessMap();
     method public final java.math.BigInteger getScreenBrightnessRampDecreaseMaxMillis();
@@ -97,6 +111,7 @@
     method public final void setLightSensor(com.android.server.display.config.SensorDetails);
     method public final void setProxSensor(com.android.server.display.config.SensorDetails);
     method public void setQuirks(com.android.server.display.config.DisplayQuirks);
+    method public void setRefreshRate(com.android.server.display.config.RefreshRateConfigs);
     method public final void setScreenBrightnessDefault(@NonNull java.math.BigDecimal);
     method public final void setScreenBrightnessMap(@NonNull com.android.server.display.config.NitsMap);
     method public final void setScreenBrightnessRampDecreaseMaxMillis(java.math.BigInteger);
@@ -160,6 +175,14 @@
     method public final void setValue(@NonNull java.math.BigDecimal);
   }
 
+  public class RefreshRateConfigs {
+    ctor public RefreshRateConfigs();
+    method public final com.android.server.display.config.BlockingZoneConfig getHigherBlockingZoneConfigs();
+    method public final com.android.server.display.config.BlockingZoneConfig getLowerBlockingZoneConfigs();
+    method public final void setHigherBlockingZoneConfigs(com.android.server.display.config.BlockingZoneConfig);
+    method public final void setLowerBlockingZoneConfigs(com.android.server.display.config.BlockingZoneConfig);
+  }
+
   public class RefreshRateRange {
     ctor public RefreshRateRange();
     method public final java.math.BigInteger getMaximum();
diff --git a/services/credentials/java/com/android/server/credentials/CredentialManagerService.java b/services/credentials/java/com/android/server/credentials/CredentialManagerService.java
index d3b9e10..a92e4a1 100644
--- a/services/credentials/java/com/android/server/credentials/CredentialManagerService.java
+++ b/services/credentials/java/com/android/server/credentials/CredentialManagerService.java
@@ -20,6 +20,7 @@
 
 import android.annotation.NonNull;
 import android.annotation.UserIdInt;
+import android.app.ActivityManager;
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.credentials.ClearCredentialStateRequest;
@@ -30,13 +31,17 @@
 import android.credentials.ICreateCredentialCallback;
 import android.credentials.ICredentialManager;
 import android.credentials.IGetCredentialCallback;
+import android.credentials.IListEnabledProvidersCallback;
+import android.credentials.ListEnabledProvidersResponse;
+import android.credentials.ISetEnabledProvidersCallback;
 import android.os.Binder;
 import android.os.CancellationSignal;
 import android.os.ICancellationSignal;
+import android.os.RemoteException;
 import android.os.UserHandle;
 import android.provider.Settings;
 import android.service.credentials.BeginCreateCredentialRequest;
-import android.service.credentials.GetCredentialsRequest;
+import android.service.credentials.BeginGetCredentialsRequest;
 import android.text.TextUtils;
 import android.util.Log;
 import android.util.Slog;
@@ -52,20 +57,23 @@
 /**
  * Entry point service for credential management.
  *
- * <p>This service provides the {@link ICredentialManager} implementation and keeps a list of
- * {@link CredentialManagerServiceImpl} per user; the real work is done by
- * {@link CredentialManagerServiceImpl} itself.
+ * <p>This service provides the {@link ICredentialManager} implementation and keeps a list of {@link
+ * CredentialManagerServiceImpl} per user; the real work is done by {@link
+ * CredentialManagerServiceImpl} itself.
  */
-public final class CredentialManagerService extends
-        AbstractMasterSystemService<CredentialManagerService, CredentialManagerServiceImpl> {
+public final class CredentialManagerService
+        extends AbstractMasterSystemService<
+                CredentialManagerService, CredentialManagerServiceImpl> {
 
     private static final String TAG = "CredManSysService";
 
     public CredentialManagerService(@NonNull Context context) {
-        super(context,
-                new SecureSettingsServiceNameResolver(context, Settings.Secure.CREDENTIAL_SERVICE,
-                        /*isMultipleMode=*/true),
-                null, PACKAGE_UPDATE_POLICY_REFRESH_EAGER);
+        super(
+                context,
+                new SecureSettingsServiceNameResolver(
+                        context, Settings.Secure.CREDENTIAL_SERVICE, /* isMultipleMode= */ true),
+                null,
+                PACKAGE_UPDATE_POLICY_REFRESH_EAGER);
     }
 
     @Override
@@ -74,12 +82,14 @@
     }
 
     @Override // from AbstractMasterSystemService
-    protected CredentialManagerServiceImpl newServiceLocked(@UserIdInt int resolvedUserId,
-            boolean disabled) {
+    protected CredentialManagerServiceImpl newServiceLocked(
+            @UserIdInt int resolvedUserId, boolean disabled) {
         // This method should not be called for CredentialManagerService as it is configured to use
         // multiple services.
-        Slog.w(TAG, "Should not be here - CredentialManagerService is configured to use "
-                + "multiple services");
+        Slog.w(
+                TAG,
+                "Should not be here - CredentialManagerService is configured to use "
+                        + "multiple services");
         return null;
     }
 
@@ -89,8 +99,8 @@
     }
 
     @Override // from AbstractMasterSystemService
-    protected List<CredentialManagerServiceImpl> newServiceListLocked(int resolvedUserId,
-            boolean disabled, String[] serviceNames) {
+    protected List<CredentialManagerServiceImpl> newServiceListLocked(
+            int resolvedUserId, boolean disabled, String[] serviceNames) {
         if (serviceNames == null || serviceNames.length == 0) {
             Slog.i(TAG, "serviceNames sent in newServiceListLocked is null, or empty");
             return new ArrayList<>();
@@ -102,8 +112,8 @@
                 continue;
             }
             try {
-                serviceList.add(new CredentialManagerServiceImpl(this, mLock, resolvedUserId,
-                        serviceName));
+                serviceList.add(
+                        new CredentialManagerServiceImpl(this, mLock, resolvedUserId, serviceName));
             } catch (PackageManager.NameNotFoundException | SecurityException e) {
                 Log.i(TAG, "Unable to add serviceInfo : " + e.getMessage());
             }
@@ -127,19 +137,20 @@
         }
     }
 
-    private List<ProviderSession> initiateProviderSessions(RequestSession session,
-            List<String> requestOptions) {
+    private List<ProviderSession> initiateProviderSessions(
+            RequestSession session, List<String> requestOptions) {
         List<ProviderSession> providerSessions = new ArrayList<>();
         // Invoke all services of a user to initiate a provider session
-        runForUser((service) -> {
-            if (service.isServiceCapable(requestOptions)) {
-                ProviderSession providerSession = service
-                        .initiateProviderSessionForRequest(session);
-                if (providerSession != null) {
-                    providerSessions.add(providerSession);
-                }
-            }
-        });
+        runForUser(
+                (service) -> {
+                    if (service.isServiceCapable(requestOptions)) {
+                        ProviderSession providerSession =
+                                service.initiateProviderSessionForRequest(session);
+                        if (providerSession != null) {
+                            providerSessions.add(providerSession);
+                        }
+                    }
+                });
         return providerSessions;
     }
 
@@ -154,25 +165,33 @@
             ICancellationSignal cancelTransport = CancellationSignal.createTransport();
 
             // New request session, scoped for this request only.
-            final GetRequestSession session = new GetRequestSession(getContext(),
-                    UserHandle.getCallingUserId(),
-                    callback,
-                    request,
-                    callingPackage);
+            final GetRequestSession session =
+                    new GetRequestSession(
+                            getContext(),
+                            UserHandle.getCallingUserId(),
+                            callback,
+                            request,
+                            callingPackage);
 
             // Initiate all provider sessions
             List<ProviderSession> providerSessions =
-                    initiateProviderSessions(session, request.getGetCredentialOptions()
-                            .stream().map(GetCredentialOption::getType)
-                            .collect(Collectors.toList()));
+                    initiateProviderSessions(
+                            session,
+                            request.getGetCredentialOptions().stream()
+                                    .map(GetCredentialOption::getType)
+                                    .collect(Collectors.toList()));
             // TODO : Return error when no providers available
 
             // Iterate over all provider sessions and invoke the request
-            providerSessions.forEach(providerGetSession -> {
-                providerGetSession.getRemoteCredentialService().onGetCredentials(
-                        (GetCredentialsRequest) providerGetSession.getProviderRequest(),
-                        /*callback=*/providerGetSession);
-            });
+            providerSessions.forEach(
+                    providerGetSession -> {
+                        providerGetSession
+                                .getRemoteCredentialService()
+                                .onBeginGetCredentials(
+                                        (BeginGetCredentialsRequest)
+                                                providerGetSession.getProviderRequest(),
+                                        /* callback= */ providerGetSession);
+                    });
             return cancelTransport;
         }
 
@@ -186,11 +205,13 @@
             ICancellationSignal cancelTransport = CancellationSignal.createTransport();
 
             // New request session, scoped for this request only.
-            final CreateRequestSession session = new CreateRequestSession(getContext(),
-                    UserHandle.getCallingUserId(),
-                    request,
-                    callback,
-                    callingPackage);
+            final CreateRequestSession session =
+                    new CreateRequestSession(
+                            getContext(),
+                            UserHandle.getCallingUserId(),
+                            request,
+                            callback,
+                            callingPackage);
 
             // Initiate all provider sessions
             List<ProviderSession> providerSessions =
@@ -198,16 +219,83 @@
             // TODO : Return error when no providers available
 
             // Iterate over all provider sessions and invoke the request
-            providerSessions.forEach(providerCreateSession -> {
-                providerCreateSession.getRemoteCredentialService().onCreateCredential(
-                        (BeginCreateCredentialRequest)
-                                providerCreateSession.getProviderRequest(),
-                        /*callback=*/providerCreateSession);
-            });
+            providerSessions.forEach(
+                    providerCreateSession -> {
+                        providerCreateSession
+                                .getRemoteCredentialService()
+                                .onCreateCredential(
+                                        (BeginCreateCredentialRequest)
+                                                providerCreateSession.getProviderRequest(),
+                                        /* callback= */ providerCreateSession);
+                    });
             return cancelTransport;
         }
 
         @Override
+        public ICancellationSignal listEnabledProviders(IListEnabledProvidersCallback callback) {
+            Log.i(TAG, "listEnabledProviders");
+            ICancellationSignal cancelTransport = CancellationSignal.createTransport();
+
+            List<String> enabledProviders = new ArrayList<>();
+            runForUser(
+                    (service) -> {
+                        enabledProviders.add(
+                                service.getServiceInfo().getComponentName().flattenToString());
+                    });
+
+            // Call the callback.
+            try {
+                callback.onResponse(ListEnabledProvidersResponse.create(enabledProviders));
+            } catch (RemoteException e) {
+                Log.i(TAG, "Issue with invoking response: " + e.getMessage());
+                // TODO: Propagate failure
+            }
+
+            return cancelTransport;
+        }
+
+        @Override
+        public void setEnabledProviders(
+                List<String> providers, int userId, ISetEnabledProvidersCallback callback) {
+            Log.i(TAG, "setEnabledProviders");
+
+            userId =
+                    ActivityManager.handleIncomingUser(
+                            Binder.getCallingPid(),
+                            Binder.getCallingUid(),
+                            userId,
+                            false,
+                            false,
+                            "setEnabledProviders",
+                            null);
+
+            String storedValue = String.join(":", providers);
+            if (!Settings.Secure.putStringForUser(
+                    getContext().getContentResolver(),
+                    Settings.Secure.CREDENTIAL_SERVICE,
+                    storedValue,
+                    userId)) {
+                Log.e(TAG, "Failed to store setting containing enabled providers");
+                try {
+                    callback.onError(
+                            "failed_setting_store",
+                            "Failed to store setting containing enabled providers");
+                } catch (RemoteException e) {
+                    Log.i(TAG, "Issue with invoking error response: " + e.getMessage());
+                    // TODO: Propagate failure
+                }
+            }
+
+            // Call the callback.
+            try {
+                callback.onResponse();
+            } catch (RemoteException e) {
+                Log.i(TAG, "Issue with invoking response: " + e.getMessage());
+                // TODO: Propagate failure
+            }
+        }
+
+        @Override
         public ICancellationSignal clearCredentialState(ClearCredentialStateRequest request,
                 IClearCredentialStateCallback callback, String callingPackage) {
             // TODO: implement.
diff --git a/services/credentials/java/com/android/server/credentials/PendingIntentResultHandler.java b/services/credentials/java/com/android/server/credentials/PendingIntentResultHandler.java
index d0bc074..7f9e57a 100644
--- a/services/credentials/java/com/android/server/credentials/PendingIntentResultHandler.java
+++ b/services/credentials/java/com/android/server/credentials/PendingIntentResultHandler.java
@@ -19,7 +19,7 @@
 import android.app.Activity;
 import android.content.Intent;
 import android.credentials.CreateCredentialResponse;
-import android.credentials.Credential;
+import android.credentials.GetCredentialResponse;
 import android.credentials.ui.ProviderPendingIntentResponse;
 import android.service.credentials.CredentialProviderService;
 import android.service.credentials.CredentialsResponseContent;
@@ -43,8 +43,7 @@
             return null;
         }
         return resultData.getParcelableExtra(
-                CredentialProviderService
-                        .EXTRA_GET_CREDENTIALS_CONTENT_RESULT,
+                CredentialProviderService.EXTRA_CREDENTIALS_RESPONSE_CONTENT,
                 CredentialsResponseContent.class);
     }
 
@@ -54,17 +53,17 @@
             return null;
         }
         return resultData.getParcelableExtra(
-                CredentialProviderService.EXTRA_CREATE_CREDENTIAL_RESULT,
+                CredentialProviderService.EXTRA_CREATE_CREDENTIAL_RESPONSE,
                 CreateCredentialResponse.class);
     }
 
-    /** Extracts the {@link Credential} object added to the result data. */
-    public static Credential extractCredential(Intent resultData) {
+    /** Extracts the {@link GetCredentialResponse} object added to the result data. */
+    public static GetCredentialResponse extractGetCredentialResponse(Intent resultData) {
         if (resultData == null) {
             return null;
         }
         return resultData.getParcelableExtra(
-                CredentialProviderService.EXTRA_CREDENTIAL_RESULT,
-                Credential.class);
+                CredentialProviderService.EXTRA_GET_CREDENTIAL_RESPONSE,
+                GetCredentialResponse.class);
     }
 }
diff --git a/services/credentials/java/com/android/server/credentials/ProviderGetSession.java b/services/credentials/java/com/android/server/credentials/ProviderGetSession.java
index 6cd011b..9888cc0 100644
--- a/services/credentials/java/com/android/server/credentials/ProviderGetSession.java
+++ b/services/credentials/java/com/android/server/credentials/ProviderGetSession.java
@@ -19,19 +19,23 @@
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.annotation.UserIdInt;
+import android.app.PendingIntent;
 import android.content.Context;
-import android.credentials.Credential;
+import android.content.Intent;
 import android.credentials.GetCredentialOption;
 import android.credentials.GetCredentialResponse;
 import android.credentials.ui.Entry;
 import android.credentials.ui.GetCredentialProviderData;
 import android.credentials.ui.ProviderPendingIntentResponse;
 import android.service.credentials.Action;
+import android.service.credentials.BeginGetCredentialOption;
+import android.service.credentials.BeginGetCredentialsRequest;
+import android.service.credentials.BeginGetCredentialsResponse;
 import android.service.credentials.CredentialEntry;
 import android.service.credentials.CredentialProviderInfo;
+import android.service.credentials.CredentialProviderService;
 import android.service.credentials.CredentialsResponseContent;
-import android.service.credentials.GetCredentialsRequest;
-import android.service.credentials.GetCredentialsResponse;
+import android.service.credentials.GetCredentialRequest;
 import android.util.Log;
 import android.util.Pair;
 import android.util.Slog;
@@ -41,6 +45,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
+import java.util.stream.Collectors;
 
 /**
  * Central provider session that listens for provider callbacks, and maintains provider state.
@@ -48,10 +53,10 @@
  *
  * @hide
  */
-public final class ProviderGetSession extends ProviderSession<GetCredentialsRequest,
-        GetCredentialsResponse>
+public final class ProviderGetSession extends ProviderSession<BeginGetCredentialsRequest,
+        BeginGetCredentialsResponse>
         implements
-        RemoteCredentialService.ProviderCallbacks<GetCredentialsResponse> {
+        RemoteCredentialService.ProviderCallbacks<BeginGetCredentialsResponse> {
     private static final String TAG = "ProviderGetSession";
 
     // Key to be used as an entry key for a credential entry
@@ -69,6 +74,9 @@
     @Nullable
     private Pair<String, Action> mUiAuthenticationAction = null;
 
+    /** The complete request to be used in the second round. */
+    private final GetCredentialRequest mCompleteRequest;
+
     /** Creates a new provider session to be used by the request session. */
     @Nullable public static ProviderGetSession createNewSession(
             Context context,
@@ -76,20 +84,34 @@
             CredentialProviderInfo providerInfo,
             GetRequestSession getRequestSession,
             RemoteCredentialService remoteCredentialService) {
-        GetCredentialsRequest providerRequest =
+        GetCredentialRequest completeRequest =
                 createProviderRequest(providerInfo.getCapabilities(),
                         getRequestSession.mClientRequest,
                         getRequestSession.mClientCallingPackage);
-        if (providerRequest != null) {
+        if (completeRequest != null) {
+            // TODO: Update to using query data when ready
+            BeginGetCredentialsRequest beginGetCredentialsRequest =
+                    new BeginGetCredentialsRequest.Builder(
+                            completeRequest.getCallingPackage())
+                            .setBeginGetCredentialOptions(
+                                    completeRequest.getGetCredentialOptions().stream().map(
+                                            option -> {
+                                                //TODO : Replace with option.getCandidateQueryData
+                                                // when ready
+                                                return new BeginGetCredentialOption(
+                                                    option.getType(),
+                                                        option.getCandidateQueryData());
+                                            }).collect(Collectors.toList()))
+                            .build();
             return new ProviderGetSession(context, providerInfo, getRequestSession, userId,
-                    remoteCredentialService, providerRequest);
+                    remoteCredentialService, beginGetCredentialsRequest, completeRequest);
         }
         Log.i(TAG, "Unable to create provider session");
         return null;
     }
 
     @Nullable
-    private static GetCredentialsRequest createProviderRequest(List<String> providerCapabilities,
+    private static GetCredentialRequest createProviderRequest(List<String> providerCapabilities,
             android.credentials.GetCredentialRequest clientRequest,
             String clientCallingPackage) {
         List<GetCredentialOption> filteredOptions = new ArrayList<>();
@@ -104,7 +126,7 @@
             }
         }
         if (!filteredOptions.isEmpty()) {
-            return new GetCredentialsRequest.Builder(clientCallingPackage).setGetCredentialOptions(
+            return new GetCredentialRequest.Builder(clientCallingPackage).setGetCredentialOptions(
                     filteredOptions).build();
         }
         Log.i(TAG, "In createProviderRequest - returning null");
@@ -115,8 +137,10 @@
             CredentialProviderInfo info,
             ProviderInternalCallback callbacks,
             int userId, RemoteCredentialService remoteCredentialService,
-            GetCredentialsRequest request) {
-        super(context, info, request, callbacks, userId, remoteCredentialService);
+            BeginGetCredentialsRequest beginGetRequest,
+            GetCredentialRequest completeGetRequest) {
+        super(context, info, beginGetRequest, callbacks, userId, remoteCredentialService);
+        mCompleteRequest = completeGetRequest;
         setStatus(Status.PENDING);
     }
 
@@ -128,7 +152,7 @@
 
     /** Called when the provider response has been updated by an external source. */
     @Override // Callback from the remote provider
-    public void onProviderResponseSuccess(@Nullable GetCredentialsResponse response) {
+    public void onProviderResponseSuccess(@Nullable BeginGetCredentialsResponse response) {
         Log.i(TAG, "in onProviderResponseSuccess");
         onUpdateResponse(response);
     }
@@ -254,19 +278,26 @@
             mUiCredentialEntries.put(entryId, credentialEntry);
             Log.i(TAG, "in prepareUiProviderData creating ui entry with id " + entryId);
             if (credentialEntry.getPendingIntent() != null) {
+                setUpFillInIntent(credentialEntry.getPendingIntent());
                 credentialUiEntries.add(new Entry(CREDENTIAL_ENTRY_KEY, entryId,
                         credentialEntry.getSlice(), credentialEntry.getPendingIntent(),
                         /*fillInIntent=*/null));
-            } else if (credentialEntry.getCredential() != null) {
-                credentialUiEntries.add(new Entry(CREDENTIAL_ENTRY_KEY, entryId,
-                        credentialEntry.getSlice()));
             } else {
-                Log.i(TAG, "No credential or pending intent. Should not happen.");
+                Log.i(TAG, "No pending intent. Should not happen.");
             }
         }
         return credentialUiEntries;
     }
 
+    private Intent setUpFillInIntent(PendingIntent pendingIntent) {
+        Intent intent = pendingIntent.getIntent();
+        intent.putExtra(
+                CredentialProviderService
+                        .EXTRA_GET_CREDENTIAL_REQUEST,
+                mCompleteRequest);
+        return intent;
+    }
+
     private List<Entry> prepareUiActionEntries(@Nullable List<Action> actions) {
         List<Entry> actionEntries = new ArrayList<>();
         for (Action action : actions) {
@@ -292,17 +323,14 @@
 
     private void onCredentialEntrySelected(CredentialEntry credentialEntry,
             ProviderPendingIntentResponse providerPendingIntentResponse) {
-        if (credentialEntry.getCredential() != null) {
-            mCallbacks.onFinalResponseReceived(mComponentName, new GetCredentialResponse(
-                    credentialEntry.getCredential()));
-            return;
-        } else if (providerPendingIntentResponse != null) {
+        if (providerPendingIntentResponse != null) {
             if (PendingIntentResultHandler.isSuccessfulResponse(providerPendingIntentResponse)) {
-                Credential credential = PendingIntentResultHandler.extractCredential(
-                        providerPendingIntentResponse.getResultData());
-                if (credential != null) {
-                    mCallbacks.onFinalResponseReceived(mComponentName,
-                            new GetCredentialResponse(credential));
+                // TODO: Remove credential extraction when flow is fully transitioned
+                GetCredentialResponse getCredentialResponse = PendingIntentResultHandler
+                        .extractGetCredentialResponse(
+                                providerPendingIntentResponse.getResultData());
+                if (getCredentialResponse != null) {
+                    mCallbacks.onFinalResponseReceived(mComponentName, getCredentialResponse);
                     return;
                 }
             }
@@ -320,7 +348,8 @@
                         .extractResponseContent(providerPendingIntentResponse
                                 .getResultData());
                 if (content != null) {
-                    onUpdateResponse(GetCredentialsResponse.createWithResponseContent(content));
+                    onUpdateResponse(
+                            BeginGetCredentialsResponse.createWithResponseContent(content));
                     return;
                 }
             }
@@ -337,7 +366,7 @@
 
 
     /** Updates the response being maintained in state by this provider session. */
-    private void onUpdateResponse(GetCredentialsResponse response) {
+    private void onUpdateResponse(BeginGetCredentialsResponse response) {
         mProviderResponse = response;
         if (response.getAuthenticationAction() != null) {
             Log.i(TAG , "updateResponse with authentication entry");
diff --git a/services/credentials/java/com/android/server/credentials/RemoteCredentialService.java b/services/credentials/java/com/android/server/credentials/RemoteCredentialService.java
index e385bcb..7a883b3 100644
--- a/services/credentials/java/com/android/server/credentials/RemoteCredentialService.java
+++ b/services/credentials/java/com/android/server/credentials/RemoteCredentialService.java
@@ -26,14 +26,14 @@
 import android.os.RemoteException;
 import android.service.credentials.BeginCreateCredentialRequest;
 import android.service.credentials.BeginCreateCredentialResponse;
+import android.service.credentials.BeginGetCredentialsRequest;
+import android.service.credentials.BeginGetCredentialsResponse;
 import android.service.credentials.CredentialProviderException;
 import android.service.credentials.CredentialProviderException.CredentialProviderError;
 import android.service.credentials.CredentialProviderService;
-import android.service.credentials.GetCredentialsRequest;
-import android.service.credentials.GetCredentialsResponse;
 import android.service.credentials.IBeginCreateCredentialCallback;
+import android.service.credentials.IBeginGetCredentialsCallback;
 import android.service.credentials.ICredentialProviderService;
-import android.service.credentials.IGetCredentialsCallback;
 import android.text.format.DateUtils;
 import android.util.Log;
 import android.util.Slog;
@@ -106,19 +106,21 @@
      * @param callback the callback to be used to send back the provider response to the
      *                 {@link ProviderGetSession} class that maintains provider state
      */
-    public void onGetCredentials(@NonNull GetCredentialsRequest request,
-            ProviderCallbacks<GetCredentialsResponse> callback) {
+    public void onBeginGetCredentials(@NonNull BeginGetCredentialsRequest request,
+            ProviderCallbacks<BeginGetCredentialsResponse> callback) {
         Log.i(TAG, "In onGetCredentials in RemoteCredentialService");
         AtomicReference<ICancellationSignal> cancellationSink = new AtomicReference<>();
-        AtomicReference<CompletableFuture<GetCredentialsResponse>> futureRef =
+        AtomicReference<CompletableFuture<BeginGetCredentialsResponse>> futureRef =
                 new AtomicReference<>();
 
-        CompletableFuture<GetCredentialsResponse> connectThenExecute = postAsync(service -> {
-            CompletableFuture<GetCredentialsResponse> getCredentials = new CompletableFuture<>();
+        CompletableFuture<BeginGetCredentialsResponse> connectThenExecute = postAsync(service -> {
+            CompletableFuture<BeginGetCredentialsResponse> getCredentials =
+                    new CompletableFuture<>();
             ICancellationSignal cancellationSignal =
-                    service.onGetCredentials(request, new IGetCredentialsCallback.Stub() {
+                    service.onBeginGetCredentials(request,
+                            new IBeginGetCredentialsCallback.Stub() {
                         @Override
-                        public void onSuccess(GetCredentialsResponse response) {
+                        public void onSuccess(BeginGetCredentialsResponse response) {
                             Log.i(TAG, "In onSuccess in RemoteCredentialService");
                             getCredentials.complete(response);
                         }
@@ -132,7 +134,7 @@
                                     errorCode, errorMsg));
                         }
                     });
-            CompletableFuture<GetCredentialsResponse> future = futureRef.get();
+            CompletableFuture<BeginGetCredentialsResponse> future = futureRef.get();
             if (future != null && future.isCancelled()) {
                 dispatchCancellationSignal(cancellationSignal);
             } else {
@@ -159,7 +161,8 @@
         AtomicReference<CompletableFuture<BeginCreateCredentialResponse>> futureRef =
                 new AtomicReference<>();
 
-        CompletableFuture<BeginCreateCredentialResponse> connectThenExecute = postAsync(service -> {
+        CompletableFuture<BeginCreateCredentialResponse> connectThenExecute =
+                postAsync(service -> {
             CompletableFuture<BeginCreateCredentialResponse> createCredentialFuture =
                     new CompletableFuture<>();
             ICancellationSignal cancellationSignal = service.onBeginCreateCredential(
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/ActiveAdmin.java b/services/devicepolicy/java/com/android/server/devicepolicy/ActiveAdmin.java
index 8047a53..4634ff5 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/ActiveAdmin.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/ActiveAdmin.java
@@ -162,6 +162,8 @@
     private static final String TAG_PREFERENTIAL_NETWORK_SERVICE_CONFIG =
             "preferential_network_service_config";
     private static final String TAG_PROTECTED_PACKAGES = "protected_packages";
+    private static final String TAG_SUSPENDED_PACKAGES = "suspended-packages";
+    private static final String TAG_MTE_POLICY = "mte-policy";
     private static final String ATTR_VALUE = "value";
     private static final String ATTR_LAST_NETWORK_LOGGING_NOTIFICATION = "last-notification";
     private static final String ATTR_NUM_NETWORK_LOGGING_NOTIFICATIONS = "num-notifications";
@@ -221,6 +223,8 @@
     int numNetworkLoggingNotifications = 0;
     long lastNetworkLoggingNotificationTimeMs = 0; // Time in milliseconds since epoch
 
+    @DevicePolicyManager.MtePolicy int mtePolicy = DevicePolicyManager.MTE_NOT_CONTROLLED_BY_POLICY;
+
     ActiveAdmin parentAdmin;
     final boolean isParent;
 
@@ -257,6 +261,8 @@
     // List of packages for which the user cannot invoke "clear data" or "force stop".
     List<String> protectedPackages;
 
+    List<String> suspendedPackages;
+
     // Wi-Fi SSID restriction policy.
     WifiSsidPolicy mWifiSsidPolicy;
 
@@ -508,6 +514,7 @@
         writePackageListToXml(out, TAG_KEEP_UNINSTALLED_PACKAGES, keepUninstalledPackages);
         writePackageListToXml(out, TAG_METERED_DATA_DISABLED_PACKAGES, meteredDisabledPackages);
         writePackageListToXml(out, TAG_PROTECTED_PACKAGES, protectedPackages);
+        writePackageListToXml(out, TAG_SUSPENDED_PACKAGES, suspendedPackages);
         if (hasUserRestrictions()) {
             UserRestrictionsUtils.writeRestrictions(
                     out, userRestrictions, TAG_USER_RESTRICTIONS);
@@ -616,6 +623,9 @@
             }
             out.endTag(null, TAG_PREFERENTIAL_NETWORK_SERVICE_CONFIGS);
         }
+        if (mtePolicy != DevicePolicyManager.MTE_NOT_CONTROLLED_BY_POLICY) {
+            writeAttributeValueToXml(out, TAG_MTE_POLICY, mtePolicy);
+        }
     }
 
     private List<String> ssidsToStrings(Set<WifiSsid> ssids) {
@@ -776,6 +786,8 @@
                 meteredDisabledPackages = readPackageList(parser, tag);
             } else if (TAG_PROTECTED_PACKAGES.equals(tag)) {
                 protectedPackages = readPackageList(parser, tag);
+            } else if (TAG_SUSPENDED_PACKAGES.equals(tag)) {
+                suspendedPackages = readPackageList(parser, tag);
             } else if (TAG_USER_RESTRICTIONS.equals(tag)) {
                 userRestrictions = UserRestrictionsUtils.readRestrictions(parser);
             } else if (TAG_DEFAULT_ENABLED_USER_RESTRICTIONS.equals(tag)) {
@@ -900,6 +912,8 @@
                 if (!configs.isEmpty()) {
                     mPreferentialNetworkServiceConfigs = configs;
                 }
+            } else if (TAG_MTE_POLICY.equals(tag)) {
+                mtePolicy = parser.getAttributeInt(null, ATTR_VALUE);
             } else {
                 Slogf.w(LOG_TAG, "Unknown admin tag: %s", tag);
                 XmlUtils.skipCurrentTag(parser);
@@ -1225,6 +1239,11 @@
             pw.println(protectedPackages);
         }
 
+        if (suspendedPackages != null) {
+            pw.print("suspendedPackages=");
+            pw.println(suspendedPackages);
+        }
+
         pw.print("organizationColor=");
         pw.println(organizationColor);
 
@@ -1327,5 +1346,8 @@
             }
             pw.decreaseIndent();
         }
+
+        pw.print("mtePolicy=");
+        pw.println(mtePolicy);
     }
 }
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 775e3d8..c42ddf8 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -336,7 +336,6 @@
 import android.util.DebugUtils;
 import android.util.IndentingPrintWriter;
 import android.util.IntArray;
-import android.util.Log;
 import android.util.Pair;
 import android.util.Slog;
 import android.util.SparseArray;
@@ -546,7 +545,7 @@
     // to decide whether an existing policy in the {@link #DEVICE_POLICIES_XML} needs to
     // be upgraded. See {@link PolicyVersionUpgrader} on instructions how to add an upgrade
     // step.
-    static final int DPMS_VERSION = 3;
+    static final int DPMS_VERSION = 4;
 
     static {
         SECURE_SETTINGS_ALLOWLIST = new ArraySet<>();
@@ -718,6 +717,16 @@
     private static final String ENABLE_COEXISTENCE_FLAG = "enable_coexistence";
     private static final boolean DEFAULT_ENABLE_COEXISTENCE_FLAG = false;
 
+    // TODO(b/258425381) remove the flag after rollout.
+    private static final String KEEP_PROFILES_RUNNING_FLAG = "enable_keep_profiles_running";
+    private static final boolean DEFAULT_KEEP_PROFILES_RUNNING_FLAG = false;
+
+    /**
+     * This feature flag is checked once after boot and this value us used until the next reboot to
+     * avoid needing to handle the flag changing on the fly.
+     */
+    private final boolean mKeepProfilesRunning = isKeepProfilesRunningFlagEnabled();
+
     /**
      * For apps targeting U+
      * Enable multiple admins to coexist on the same device.
@@ -1210,6 +1219,9 @@
                                 PackageManager.MATCH_DIRECT_BOOT_AWARE
                                         | PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
                                 userHandle) == null) {
+                            Slogf.e(LOG_TAG, String.format(
+                                    "Admin package %s not found for user %d, removing active admin",
+                                    packageName, userHandle));
                             removedAdmin = true;
                             policy.mAdminList.remove(i);
                             policy.mAdminMap.remove(aa.info.getComponent());
@@ -1488,8 +1500,11 @@
         }
 
         PackageManager getPackageManager(int userId) {
-            return mContext
-                    .createContextAsUser(UserHandle.of(userId), 0 /* flags */).getPackageManager();
+            try {
+                return createContextAsUser(UserHandle.of(userId)).getPackageManager();
+            } catch (NameNotFoundException e) {
+                throw new IllegalStateException(e);
+            }
         }
 
         PowerManagerInternal getPowerManagerInternal() {
@@ -1935,10 +1950,11 @@
     }
 
     private Owners makeOwners(Injector injector, PolicyPathProvider pathProvider) {
-        return new Owners(injector.getUserManager(), injector.getUserManagerInternal(),
+        return new Owners(
+                injector.getUserManager(), injector.getUserManagerInternal(),
                 injector.getPackageManagerInternal(),
                 injector.getActivityTaskManagerInternal(),
-                injector.getActivityManagerInternal(), pathProvider);
+                injector.getActivityManagerInternal(), mStateCache, pathProvider);
     }
 
     /**
@@ -3101,6 +3117,20 @@
             List<UserInfo> allUsers = mUserManager.getUsers();
             return allUsers.stream().mapToInt(u -> u.id).toArray();
         }
+
+        @Override
+        public List<String> getPlatformSuspendedPackages(int userId) {
+            PackageManagerInternal pmi = mInjector.getPackageManagerInternal();
+            return mInjector.getPackageManager(userId)
+                    .getInstalledPackages(PackageManager.PackageInfoFlags.of(
+                            MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE))
+                    .stream()
+                    .map(packageInfo -> packageInfo.packageName)
+                    .filter(pkg ->
+                            PLATFORM_PACKAGE_NAME.equals(pmi.getSuspendingPackage(pkg, userId))
+                    )
+                    .collect(Collectors.toList());
+        }
     }
 
     private void performPolicyVersionUpgrade() {
@@ -3151,7 +3181,7 @@
             userId = mOwners.getDeviceOwnerUserId();
         }
         if (VERBOSE_LOG) {
-            Log.v(LOG_TAG, "Starting non-system DO user: " + userId);
+            Slogf.v(LOG_TAG, "Starting non-system DO user: " + userId);
         }
         if (userId != UserHandle.USER_SYSTEM) {
             try {
@@ -5357,7 +5387,8 @@
                         }
                         if (!mInjector.storageManagerIsFileBasedEncryptionEnabled()) {
                             throw new UnsupportedOperationException(
-                                    "FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY only applies to FBE devices");
+                                    "FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY only applies to FBE"
+                                        + " devices");
                         }
                         mUserManager.evictCredentialEncryptionKey(callingUserId);
                     }
@@ -9892,6 +9923,8 @@
                             (size == 1 ? "" : "s"));
                 }
                 pw.println();
+                pw.println("Keep profiles running: " + mKeepProfilesRunning);
+                pw.println();
 
                 mPolicyCache.dump(pw);
                 pw.println();
@@ -11371,6 +11404,30 @@
             Slogf.w(LOG_TAG, "PM failed to suspend packages (%s)", Arrays.toString(packageNames));
             return packageNames;
         }
+
+        ArraySet<String> changed = new ArraySet<>(packageNames);
+        if (suspended) {
+            // Only save those packages that are actually suspended. If a package is exempt or is
+            // unsuspendable, it is skipped.
+            changed.removeAll(List.of(nonSuspendedPackages));
+        } else {
+            // If an admin tries to unsuspend a package that is either exempt or is not
+            // suspendable, drop it from the stored list assuming it must be already unsuspended.
+            changed.addAll(exemptApps);
+        }
+
+        synchronized (getLockObject()) {
+            ActiveAdmin admin = getProfileOwnerOrDeviceOwnerLocked(caller.getUserId());
+            ArraySet<String> current = new ArraySet<>(admin.suspendedPackages);
+            if (suspended) {
+                current.addAll(changed);
+            } else {
+                current.removeAll(changed);
+            }
+            admin.suspendedPackages = current.isEmpty() ? null : new ArrayList<>(current);
+            saveSettingsLocked(caller.getUserId());
+        }
+
         if (exemptApps.isEmpty()) {
             return nonSuspendedPackages;
         }
@@ -13240,7 +13297,7 @@
             CallerIdentity caller = new CallerIdentity(callerUid, null, null);
             if (isUserAffiliatedWithDevice(UserHandle.getUserId(callerUid))
                     && (isActiveProfileOwner(callerUid)
-                        || isDefaultDeviceOwner(caller) || isFinancedDeviceOwner(caller))) {
+                    || isDefaultDeviceOwner(caller) || isFinancedDeviceOwner(caller))) {
                 // device owner or a profile owner affiliated with the device owner
                 return true;
             }
@@ -13533,11 +13590,21 @@
             }
         }
 
+        @Override
+        public boolean isKeepProfilesRunningEnabled() {
+            return mKeepProfilesRunning;
+        }
+
         private @Mode int findInteractAcrossProfilesResetMode(String packageName) {
             return getDefaultCrossProfilePackages().contains(packageName)
                     ? AppOpsManager.MODE_ALLOWED
                     : AppOpsManager.opToDefaultMode(AppOpsManager.OP_INTERACT_ACROSS_PROFILES);
         }
+
+        @Override
+        public boolean isUserOrganizationManaged(@UserIdInt int userHandle) {
+            return getDeviceStateCache().isUserOrganizationManaged(userHandle);
+        }
     }
 
     private Intent createShowAdminSupportIntent(int userId) {
@@ -14387,7 +14454,7 @@
             // Bail out if we are trying to provision a work profile but one already exists.
             if (!mUserManager.canAddMoreManagedProfiles(
                     callingUserId, /* allowedToRemoveOne= */ false)) {
-                Slogf.i(LOG_TAG, "A work profile already exists.");
+                Slogf.i(LOG_TAG, "Cannot add more managed profiles.");
                 return STATUS_CANNOT_ADD_MANAGED_PROFILE;
             }
         } finally {
@@ -19167,4 +19234,62 @@
                 ENABLE_COEXISTENCE_FLAG,
                 DEFAULT_ENABLE_COEXISTENCE_FLAG);
     }
+
+    private static boolean isKeepProfilesRunningFlagEnabled() {
+        return DeviceConfig.getBoolean(
+                NAMESPACE_DEVICE_POLICY_MANAGER,
+                KEEP_PROFILES_RUNNING_FLAG,
+                DEFAULT_KEEP_PROFILES_RUNNING_FLAG);
+    }
+
+    @Override
+    public void setMtePolicy(int flags) {
+        final Set<Integer> allowedModes =
+                Set.of(
+                        DevicePolicyManager.MTE_NOT_CONTROLLED_BY_POLICY,
+                        DevicePolicyManager.MTE_DISABLED,
+                        DevicePolicyManager.MTE_ENABLED);
+        Preconditions.checkArgument(
+                allowedModes.contains(flags), "Provided mode is not one of the allowed values.");
+        final CallerIdentity caller = getCallerIdentity();
+        if (flags == DevicePolicyManager.MTE_DISABLED) {
+            Preconditions.checkCallAuthorization(isDefaultDeviceOwner(caller));
+        } else {
+            Preconditions.checkCallAuthorization(
+                    isDefaultDeviceOwner(caller)
+                            || isProfileOwnerOfOrganizationOwnedDevice(caller));
+        }
+        synchronized (getLockObject()) {
+            ActiveAdmin admin =
+                    getDeviceOwnerOrProfileOwnerOfOrganizationOwnedDeviceLocked(
+                            UserHandle.USER_SYSTEM);
+            if (admin != null) {
+                final String memtagProperty = "arm64.memtag.bootctl";
+                if (flags == DevicePolicyManager.MTE_ENABLED) {
+                    mInjector.systemPropertiesSet(memtagProperty, "memtag");
+                } else if (flags == DevicePolicyManager.MTE_DISABLED) {
+                    mInjector.systemPropertiesSet(memtagProperty, "memtag-off");
+                }
+                admin.mtePolicy = flags;
+                saveSettingsLocked(caller.getUserId());
+            }
+        }
+    }
+
+    @Override
+    public int getMtePolicy() {
+        final CallerIdentity caller = getCallerIdentity();
+        Preconditions.checkCallAuthorization(
+                isDefaultDeviceOwner(caller)
+                        || isProfileOwnerOfOrganizationOwnedDevice(caller)
+                        || isSystemUid(caller));
+        synchronized (getLockObject()) {
+            ActiveAdmin admin =
+                    getDeviceOwnerOrProfileOwnerOfOrganizationOwnedDeviceLocked(
+                            UserHandle.USER_SYSTEM);
+            return admin != null
+                    ? admin.mtePolicy
+                    : DevicePolicyManager.MTE_NOT_CONTROLLED_BY_POLICY;
+        }
+    }
 }
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DeviceStateCacheImpl.java b/services/devicepolicy/java/com/android/server/devicepolicy/DeviceStateCacheImpl.java
index 1215253..011a282 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DeviceStateCacheImpl.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DeviceStateCacheImpl.java
@@ -15,11 +15,17 @@
  */
 package com.android.server.devicepolicy;
 
+import android.annotation.UserIdInt;
+import android.app.admin.DevicePolicyManager;
 import android.app.admin.DeviceStateCache;
 import android.util.IndentingPrintWriter;
 
 import com.android.internal.annotations.GuardedBy;
 
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
 /**
  * Implementation of {@link DeviceStateCache}, to which {@link DevicePolicyManagerService} pushes
  * device state.
@@ -32,6 +38,11 @@
      */
     private final Object mLock = new Object();
 
+    public static final int NO_DEVICE_OWNER = -1;
+
+    private AtomicInteger mDeviceOwnerType = new AtomicInteger(NO_DEVICE_OWNER);
+    private Map<Integer, Boolean> mHasProfileOwner = new ConcurrentHashMap<>();
+
     @GuardedBy("mLock")
     private boolean mIsDeviceProvisioned = false;
 
@@ -47,11 +58,43 @@
         }
     }
 
+    void setDeviceOwnerType(int deviceOwnerType) {
+        mDeviceOwnerType.set(deviceOwnerType);
+    }
+
+    void setHasProfileOwner(int userId, boolean hasProfileOwner) {
+        if (hasProfileOwner) {
+            mHasProfileOwner.put(userId, true);
+        } else {
+            mHasProfileOwner.remove(userId);
+        }
+    }
+
+    @Override
+    public boolean isUserOrganizationManaged(@UserIdInt int userHandle) {
+        if (mHasProfileOwner.getOrDefault(userHandle, false)
+                || hasEnterpriseDeviceOwner()) {
+            return true;
+        }
+
+        // TODO: Support role holder override
+        return false;
+    }
+
+    private boolean hasEnterpriseDeviceOwner() {
+        return mDeviceOwnerType.get() == DevicePolicyManager.DEVICE_OWNER_TYPE_DEFAULT;
+    }
+
     /** Dump content */
     public void dump(IndentingPrintWriter pw) {
         pw.println("Device state cache:");
         pw.increaseIndent();
         pw.println("Device provisioned: " + mIsDeviceProvisioned);
+        pw.println("Device Owner Type: " + mDeviceOwnerType.get());
+        pw.println("Has PO:");
+        for (Integer id : mHasProfileOwner.keySet()) {
+            pw.println("User " + id + ": " + mHasProfileOwner.get(id));
+        }
         pw.decreaseIndent();
     }
 }
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/Owners.java b/services/devicepolicy/java/com/android/server/devicepolicy/Owners.java
index 3b46d52..6f172e4 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/Owners.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/Owners.java
@@ -16,8 +16,12 @@
 
 package com.android.server.devicepolicy;
 
+import static android.app.admin.DevicePolicyManager.DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_DEFAULT;
+import static android.app.admin.DevicePolicyManager.DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_FLAG;
 import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_DEFAULT;
 
+import static com.android.server.devicepolicy.DeviceStateCacheImpl.NO_DEVICE_OWNER;
+
 import android.annotation.Nullable;
 import android.app.ActivityManagerInternal;
 import android.app.AppOpsManagerInternal;
@@ -31,6 +35,7 @@
 import android.os.Process;
 import android.os.UserHandle;
 import android.os.UserManager;
+import android.provider.DeviceConfig;
 import android.util.ArraySet;
 import android.util.IndentingPrintWriter;
 import android.util.Pair;
@@ -69,6 +74,7 @@
     private final PackageManagerInternal mPackageManagerInternal;
     private final ActivityTaskManagerInternal mActivityTaskManagerInternal;
     private final ActivityManagerInternal mActivityManagerInternal;
+    private final DeviceStateCacheImpl mDeviceStateCache;
 
     @GuardedBy("mData")
     private final OwnersData mData;
@@ -81,12 +87,14 @@
             PackageManagerInternal packageManagerInternal,
             ActivityTaskManagerInternal activityTaskManagerInternal,
             ActivityManagerInternal activityManagerInternal,
+            DeviceStateCacheImpl deviceStateCache,
             PolicyPathProvider pathProvider) {
         mUserManager = userManager;
         mUserManagerInternal = userManagerInternal;
         mPackageManagerInternal = packageManagerInternal;
         mActivityTaskManagerInternal = activityTaskManagerInternal;
         mActivityManagerInternal = activityManagerInternal;
+        mDeviceStateCache = deviceStateCache;
         mData = new OwnersData(pathProvider);
     }
 
@@ -99,9 +107,24 @@
                     mUserManager.getAliveUsers().stream().mapToInt(u -> u.id).toArray();
             mData.load(usersIds);
 
-            mUserManagerInternal.setDeviceManaged(hasDeviceOwner());
-            for (int userId : usersIds) {
-                mUserManagerInternal.setUserManaged(userId, hasProfileOwner(userId));
+            // TODO(b/258213147): Remove
+            if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER,
+                    DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_FLAG,
+                    DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_DEFAULT)) {
+                if (hasDeviceOwner()) {
+                    int deviceOwnerType = mData.mDeviceOwnerTypes.getOrDefault(
+                            mData.mDeviceOwner.packageName,
+                            /* defaultValue= */ DEVICE_OWNER_TYPE_DEFAULT);
+                    mDeviceStateCache.setDeviceOwnerType(deviceOwnerType);
+                } else {
+                    mDeviceStateCache.setDeviceOwnerType(NO_DEVICE_OWNER);
+                }
+
+            } else {
+                mUserManagerInternal.setDeviceManaged(hasDeviceOwner());
+                for (int userId : usersIds) {
+                    mUserManagerInternal.setUserManaged(userId, hasProfileOwner(userId));
+                }
             }
 
             notifyChangeLocked();
@@ -224,7 +247,18 @@
                     /* remoteBugreportHash =*/ null, /* isOrganizationOwnedDevice =*/ true);
             mData.mDeviceOwnerUserId = userId;
 
-            mUserManagerInternal.setDeviceManaged(true);
+            // TODO(b/258213147): Remove
+            if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER,
+                    DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_FLAG,
+                    DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_DEFAULT)) {
+                int deviceOwnerType = mData.mDeviceOwnerTypes.getOrDefault(
+                        mData.mDeviceOwner.packageName,
+                        /* defaultValue= */ DEVICE_OWNER_TYPE_DEFAULT);
+                mDeviceStateCache.setDeviceOwnerType(deviceOwnerType);
+            } else {
+                mUserManagerInternal.setDeviceManaged(true);
+            }
+
             notifyChangeLocked();
             pushToActivityTaskManagerLocked();
         }
@@ -236,7 +270,14 @@
             mData.mDeviceOwner = null;
             mData.mDeviceOwnerUserId = UserHandle.USER_NULL;
 
-            mUserManagerInternal.setDeviceManaged(false);
+            // TODO(b/258213147): Remove
+            if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER,
+                    DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_FLAG,
+                    DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_DEFAULT)) {
+                mDeviceStateCache.setDeviceOwnerType(NO_DEVICE_OWNER);
+            } else {
+                mUserManagerInternal.setDeviceManaged(false);
+            }
             notifyChangeLocked();
             pushToActivityTaskManagerLocked();
         }
@@ -248,7 +289,15 @@
             mData.mProfileOwners.put(userId, new OwnerInfo(admin,
                     /* remoteBugreportUri =*/ null, /* remoteBugreportHash =*/ null,
                     /* isOrganizationOwnedDevice =*/ false));
-            mUserManagerInternal.setUserManaged(userId, true);
+
+            // TODO(b/258213147): Remove
+            if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER,
+                    DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_FLAG,
+                    DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_DEFAULT)) {
+                mDeviceStateCache.setHasProfileOwner(userId, true);
+            } else {
+                mUserManagerInternal.setUserManaged(userId, true);
+            }
             notifyChangeLocked();
         }
     }
@@ -256,7 +305,14 @@
     void removeProfileOwner(int userId) {
         synchronized (mData) {
             mData.mProfileOwners.remove(userId);
-            mUserManagerInternal.setUserManaged(userId, false);
+            // TODO(b/258213147): Remove
+            if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER,
+                    DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_FLAG,
+                    DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_DEFAULT)) {
+                mDeviceStateCache.setHasProfileOwner(userId, false);
+            } else {
+                mUserManagerInternal.setUserManaged(userId, false);
+            }
             notifyChangeLocked();
         }
     }
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/PolicyUpgraderDataProvider.java b/services/devicepolicy/java/com/android/server/devicepolicy/PolicyUpgraderDataProvider.java
index 1474749..c0ef0b0 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/PolicyUpgraderDataProvider.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/PolicyUpgraderDataProvider.java
@@ -21,6 +21,7 @@
 
 import com.android.internal.util.JournaledFile;
 
+import java.util.List;
 import java.util.function.Function;
 
 /**
@@ -48,4 +49,9 @@
      * Returns the users to upgrade.
      */
     int[] getUsersForUpgrade();
+
+    /**
+     * Returns packages suspended by platform for a given user.
+     */
+    List<String> getPlatformSuspendedPackages(int userId);
 }
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/PolicyVersionUpgrader.java b/services/devicepolicy/java/com/android/server/devicepolicy/PolicyVersionUpgrader.java
index 8081331..1fe4b57 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/PolicyVersionUpgrader.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/PolicyVersionUpgrader.java
@@ -104,6 +104,12 @@
             currentVersion = 3;
         }
 
+        if (currentVersion == 3) {
+            Slog.i(LOG_TAG, String.format("Upgrading from version %d", currentVersion));
+            upgradePackageSuspension(allUsers, ownersData, allUsersData);
+            currentVersion = 4;
+        }
+
         writePoliciesAndVersion(allUsers, allUsersData, ownersData, currentVersion);
     }
 
@@ -170,6 +176,44 @@
         }
     }
 
+    /**
+     * This upgrade step stores packages suspended via DPM.setPackagesSuspended() into ActiveAdmin
+     * data structure. Prior to this it was only persisted in PackageManager which doesn't have any
+     * way of knowing which admin suspended it.
+     */
+    private void upgradePackageSuspension(
+            int[] allUsers, OwnersData ownersData, SparseArray<DevicePolicyData> allUsersData) {
+        if (ownersData.mDeviceOwner != null) {
+            saveSuspendedPackages(allUsersData, ownersData.mDeviceOwnerUserId,
+                    ownersData.mDeviceOwner.admin);
+        }
+
+        for (int i = 0; i < ownersData.mProfileOwners.size(); i++) {
+            int ownerUserId = ownersData.mProfileOwners.keyAt(i);
+            OwnersData.OwnerInfo ownerInfo = ownersData.mProfileOwners.valueAt(i);
+            saveSuspendedPackages(allUsersData, ownerUserId, ownerInfo.admin);
+        }
+    }
+
+    private void saveSuspendedPackages(SparseArray<DevicePolicyData> allUsersData, int ownerUserId,
+            ComponentName ownerPackage) {
+        DevicePolicyData ownerUserData = allUsersData.get(ownerUserId);
+        if (ownerUserData == null) {
+            Slog.e(LOG_TAG, "No policy data for owner user, cannot migrate suspended packages");
+            return;
+        }
+
+        ActiveAdmin ownerAdmin = ownerUserData.mAdminMap.get(ownerPackage);
+        if (ownerAdmin == null) {
+            Slog.e(LOG_TAG, "No admin for owner, cannot migrate suspended packages");
+            return;
+        }
+
+        ownerAdmin.suspendedPackages = mProvider.getPlatformSuspendedPackages(ownerUserId);
+        Slog.i(LOG_TAG, String.format("Saved %d packages suspended by %s in user %d",
+                ownerAdmin.suspendedPackages.size(), ownerPackage, ownerUserId));
+    }
+
     private OwnersData loadOwners(int[] allUsers) {
         OwnersData ownersData = new OwnersData(mPathProvider);
         ownersData.load(allUsers);
diff --git a/services/java/com/android/server/BootUserInitializer.java b/services/java/com/android/server/BootUserInitializer.java
index c3329795..deebfc7 100644
--- a/services/java/com/android/server/BootUserInitializer.java
+++ b/services/java/com/android/server/BootUserInitializer.java
@@ -102,6 +102,7 @@
         switchToInitialUser(initialUserId);
     }
 
+    /* TODO(b/261791491): STOPSHIP - SUW should be responsible for this. */
     private void provisionHeadlessSystemUser() {
         if (isDeviceProvisioned()) {
             Slogf.d(TAG, "provisionHeadlessSystemUser(): already provisioned");
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index e96eff21..509d75b 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -154,6 +154,7 @@
 import com.android.server.os.NativeTombstoneManagerService;
 import com.android.server.os.SchedulingPolicyService;
 import com.android.server.people.PeopleService;
+import com.android.server.permission.access.AccessCheckingService;
 import com.android.server.pm.ApexManager;
 import com.android.server.pm.ApexSystemServiceInfo;
 import com.android.server.pm.BackgroundInstallControlService;
@@ -187,6 +188,7 @@
 import com.android.server.security.FileIntegrityService;
 import com.android.server.security.KeyAttestationApplicationIdProviderService;
 import com.android.server.security.KeyChainSystemService;
+import com.android.server.security.rkp.RemoteProvisioningService;
 import com.android.server.sensorprivacy.SensorPrivacyService;
 import com.android.server.sensors.SensorService;
 import com.android.server.signedconfig.SignedConfigService;
@@ -1109,6 +1111,11 @@
         startMemtrackProxyService();
         t.traceEnd();
 
+        // Start AccessCheckingService which provides new implementation for permission and app op.
+        t.traceBegin("StartAccessCheckingService");
+        mSystemServiceManager.startService(AccessCheckingService.class);
+        t.traceEnd();
+
         // Activity manager runs the show.
         t.traceBegin("StartActivityManager");
         // TODO: Might need to move after migration to WM.
@@ -1361,11 +1368,16 @@
         mSystemServiceManager.startService(BugreportManagerService.class);
         t.traceEnd();
 
-        // Serivce for GPU and GPU driver.
+        // Service for GPU and GPU driver.
         t.traceBegin("GpuService");
         mSystemServiceManager.startService(GpuService.class);
         t.traceEnd();
 
+        // Handles system process requests for remotely provisioned keys & data.
+        t.traceBegin("StartRemoteProvisioningService");
+        mSystemServiceManager.startService(RemoteProvisioningService.class);
+        t.traceEnd();
+
         t.traceEnd(); // startCoreServices
     }
 
diff --git a/services/midi/java/com/android/server/midi/MidiService.java b/services/midi/java/com/android/server/midi/MidiService.java
index b519a782..4aba30a 100644
--- a/services/midi/java/com/android/server/midi/MidiService.java
+++ b/services/midi/java/com/android/server/midi/MidiService.java
@@ -23,7 +23,6 @@
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
-// import android.content.IntentFilter;
 import android.content.ServiceConnection;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageInfo;
@@ -31,6 +30,7 @@
 import android.content.pm.ResolveInfo;
 import android.content.pm.ServiceInfo;
 import android.content.res.XmlResourceParser;
+import android.media.MediaMetrics;
 import android.media.midi.IBluetoothMidiService;
 import android.media.midi.IMidiDeviceListener;
 import android.media.midi.IMidiDeviceOpenCallback;
@@ -63,12 +63,16 @@
 import java.io.FileDescriptor;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.time.Duration;
+import java.time.Instant;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
 
 // NOTE about locking order:
 // if there is a path that syncs on BOTH mDevicesByInfo AND mDeviceConnections,
@@ -359,6 +363,17 @@
         private final ArrayList<DeviceConnection> mDeviceConnections
                 = new ArrayList<DeviceConnection>();
 
+        // Keep track of number of added and removed collections for logging
+        private AtomicInteger mDeviceConnectionsAdded = new AtomicInteger();
+        private AtomicInteger mDeviceConnectionsRemoved = new AtomicInteger();
+
+        // Keep track of total time with at least one active connection
+        private AtomicLong mTotalTimeConnectedNs = new AtomicLong();
+        private Instant mPreviousCounterInstant = null;
+
+        private AtomicInteger mTotalInputBytes = new AtomicInteger();
+        private AtomicInteger mTotalOutputBytes = new AtomicInteger();
+
         public Device(IMidiDeviceServer server, MidiDeviceInfo deviceInfo,
                 ServiceInfo serviceInfo, int uid) {
             mDeviceInfo = deviceInfo;
@@ -460,6 +475,11 @@
         public void addDeviceConnection(DeviceConnection connection) {
             Log.d(TAG, "addDeviceConnection() [A] connection:" + connection);
             synchronized (mDeviceConnections) {
+                mDeviceConnectionsAdded.incrementAndGet();
+                if (mPreviousCounterInstant == null) {
+                    mPreviousCounterInstant = Instant.now();
+                }
+
                 Log.d(TAG, "  mServer:" + mServer);
                 if (mServer != null) {
                     Log.i(TAG, "++++ A");
@@ -533,6 +553,20 @@
         public void removeDeviceConnection(DeviceConnection connection) {
             synchronized (mDevicesByInfo) {
                 synchronized (mDeviceConnections) {
+                    int numRemovedConnections = mDeviceConnectionsRemoved.incrementAndGet();
+                    if (mPreviousCounterInstant != null) {
+                        mTotalTimeConnectedNs.addAndGet(Duration.between(
+                                mPreviousCounterInstant, Instant.now()).toNanos());
+                    }
+                    // Stop the clock if all devices have been removed.
+                    // Otherwise, start the clock from the current instant.
+                    if (numRemovedConnections >= mDeviceConnectionsAdded.get()) {
+                        mPreviousCounterInstant = null;
+                    } else {
+                        mPreviousCounterInstant = Instant.now();
+                    }
+                    logMetrics(false /* isDeviceDisconnected */);
+
                     mDeviceConnections.remove(connection);
 
                     if (connection.getDevice().getDeviceInfo().getType()
@@ -569,6 +603,16 @@
                     connection.getClient().removeDeviceConnection(connection);
                 }
                 mDeviceConnections.clear();
+
+                // If the timer is still going, some clients have not closed the connection yet.
+                if (mPreviousCounterInstant != null) {
+                    Instant currentInstant = Instant.now();
+                    mTotalTimeConnectedNs.addAndGet(Duration.between(
+                            mPreviousCounterInstant, currentInstant).toNanos());
+                    mPreviousCounterInstant = currentInstant;
+                }
+
+                logMetrics(true /* isDeviceDisconnected */);
             }
             setDeviceServer(null);
 
@@ -585,6 +629,35 @@
             }
         }
 
+        private void logMetrics(boolean isDeviceDisconnected) {
+            // Only log metrics if the device was used in a connection
+            int numDeviceConnectionAdded = mDeviceConnectionsAdded.get();
+            if (mDeviceInfo != null && numDeviceConnectionAdded > 0) {
+                new MediaMetrics.Item(MediaMetrics.Name.AUDIO_MIDI)
+                    .setUid(mUid)
+                    .set(MediaMetrics.Property.DEVICE_ID, mDeviceInfo.getId())
+                    .set(MediaMetrics.Property.INPUT_PORT_COUNT, mDeviceInfo.getInputPortCount())
+                    .set(MediaMetrics.Property.OUTPUT_PORT_COUNT,
+                            mDeviceInfo.getOutputPortCount())
+                    .set(MediaMetrics.Property.HARDWARE_TYPE, mDeviceInfo.getType())
+                    .set(MediaMetrics.Property.DURATION_NS, mTotalTimeConnectedNs.get())
+                    .set(MediaMetrics.Property.OPENED_COUNT, numDeviceConnectionAdded)
+                    .set(MediaMetrics.Property.CLOSED_COUNT, mDeviceConnectionsRemoved.get())
+                    .set(MediaMetrics.Property.DEVICE_DISCONNECTED,
+                            isDeviceDisconnected ? "true" : "false")
+                    .set(MediaMetrics.Property.IS_SHARED,
+                            !mDeviceInfo.isPrivate() ? "true" : "false")
+                    .set(MediaMetrics.Property.SUPPORTS_MIDI_UMP, mDeviceInfo.getDefaultProtocol()
+                             != MidiDeviceInfo.PROTOCOL_UNKNOWN ? "true" : "false")
+                    .set(MediaMetrics.Property.USING_ALSA, mDeviceInfo.getProperties().get(
+                            MidiDeviceInfo.PROPERTY_ALSA_CARD) != null ? "true" : "false")
+                    .set(MediaMetrics.Property.EVENT, "deviceClosed")
+                    .set(MediaMetrics.Property.TOTAL_INPUT_BYTES, mTotalInputBytes.get())
+                    .set(MediaMetrics.Property.TOTAL_OUTPUT_BYTES, mTotalOutputBytes.get())
+                    .record();
+            }
+        }
+
         @Override
         public void binderDied() {
             Log.d(TAG, "Device died: " + this);
@@ -593,6 +666,11 @@
             }
         }
 
+        public void updateTotalBytes(int totalInputBytes, int totalOutputBytes) {
+            mTotalInputBytes.set(totalInputBytes);
+            mTotalOutputBytes.set(totalOutputBytes);
+        }
+
         @Override
         public String toString() {
             StringBuilder sb = new StringBuilder("Device Info: ");
@@ -1373,6 +1451,17 @@
     }
 
     @Override
+    public void updateTotalBytes(IMidiDeviceServer server, int totalInputBytes,
+            int totalOutputBytes) {
+        synchronized (mDevicesByInfo) {
+            Device device = mDevicesByServer.get(server.asBinder());
+            if (device != null) {
+                device.updateTotalBytes(totalInputBytes, totalOutputBytes);
+            }
+        }
+    }
+
+    @Override
     public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
         if (!DumpUtils.checkDumpPermission(mContext, TAG, writer)) return;
         final IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ");
diff --git a/services/permission/java/com/android/server/permission/access/AccessCheckingService.kt b/services/permission/java/com/android/server/permission/access/AccessCheckingService.kt
index 7b96d42..f493b89 100644
--- a/services/permission/java/com/android/server/permission/access/AccessCheckingService.kt
+++ b/services/permission/java/com/android/server/permission/access/AccessCheckingService.kt
@@ -16,11 +16,23 @@
 
 package com.android.server.permission.access
 
+import android.content.Context
 import com.android.internal.annotations.Keep
-import com.android.server.permission.access.external.PackageState
+import com.android.server.LocalManagerRegistry
+import com.android.server.LocalServices
+import com.android.server.SystemConfig
+import com.android.server.SystemService
+import com.android.server.appop.AppOpsCheckingServiceInterface
+import com.android.server.permission.access.appop.AppOpService
+import com.android.server.permission.access.collection.IntSet
+import com.android.server.permission.access.permission.PermissionService
+import com.android.server.pm.PackageManagerLocal
+import com.android.server.pm.UserManagerService
+import com.android.server.pm.permission.PermissionManagerServiceInterface
+import com.android.server.pm.pkg.PackageState
 
 @Keep
-class AccessCheckingService {
+class AccessCheckingService(context: Context) : SystemService(context) {
     @Volatile
     private lateinit var state: AccessState
     private val stateLock = Any()
@@ -29,14 +41,40 @@
 
     private val persistence = AccessPersistence(policy)
 
-    fun init() {
+    private lateinit var appOpService: AppOpService
+    private lateinit var permissionService: PermissionService
+
+    private lateinit var packageManagerLocal: PackageManagerLocal
+    private lateinit var userManagerService: UserManagerService
+    private lateinit var systemConfig: SystemConfig
+
+    override fun onStart() {
+        appOpService = AppOpService(this)
+        permissionService = PermissionService(this)
+
+        LocalServices.addService(AppOpsCheckingServiceInterface::class.java, appOpService)
+        LocalServices.addService(PermissionManagerServiceInterface::class.java, permissionService)
+    }
+
+    fun initialize() {
+        packageManagerLocal =
+            LocalManagerRegistry.getManagerOrThrow(PackageManagerLocal::class.java)
+        userManagerService = UserManagerService.getInstance()
+        systemConfig = SystemConfig.getInstance()
+
+        val userIds = IntSet(userManagerService.userIdsIncludingPreCreated)
+        val (packageStates, disabledSystemPackageStates) = packageManagerLocal.allPackageStates
+        val permissionAllowlist = systemConfig.permissionAllowlist
+
         val state = AccessState()
-        state.systemState.userIds.apply {
-            // TODO: Get and add all user IDs.
-            // TODO: Maybe get and add all packages?
-        }
+        policy.initialize(
+            state, userIds, packageStates, disabledSystemPackageStates, permissionAllowlist
+        )
         persistence.read(state)
         this.state = state
+
+        appOpService.initialize()
+        permissionService.initialize()
     }
 
     fun getDecision(subject: AccessUri, `object`: AccessUri): Int =
@@ -50,34 +88,73 @@
         }
     }
 
-    fun onUserAdded(userId: Int) {
+    internal fun onUserAdded(userId: Int) {
         mutateState {
             with(policy) { onUserAdded(userId) }
         }
     }
 
-    fun onUserRemoved(userId: Int) {
+    internal fun onUserRemoved(userId: Int) {
         mutateState {
             with(policy) { onUserRemoved(userId) }
         }
     }
 
-    fun onPackageAdded(packageState: PackageState) {
+    internal fun onStorageVolumeMounted(volumeUuid: String?, isSystemUpdated: Boolean) {
+        val (packageStates, disabledSystemPackageStates) = packageManagerLocal.allPackageStates
         mutateState {
-            with(policy) { onPackageAdded(packageState) }
+            with(policy) {
+                onStorageVolumeMounted(
+                    packageStates, disabledSystemPackageStates, volumeUuid, isSystemUpdated
+                )
+            }
         }
     }
 
-    fun onPackageRemoved(packageState: PackageState) {
+    internal fun onPackageAdded(packageName: String) {
+        val (packageStates, disabledSystemPackageStates) = packageManagerLocal.allPackageStates
         mutateState {
-            with(policy) { onPackageRemoved(packageState) }
+            with(policy) { onPackageAdded(packageStates, disabledSystemPackageStates, packageName) }
         }
     }
 
+    internal fun onPackageRemoved(packageName: String, appId: Int) {
+        val (packageStates, disabledSystemPackageStates) = packageManagerLocal.allPackageStates
+        mutateState {
+            with(policy) {
+                onPackageRemoved(packageStates, disabledSystemPackageStates, packageName, appId)
+            }
+        }
+    }
+
+    internal fun onPackageInstalled(packageName: String, userId: Int) {
+        val (packageStates, disabledSystemPackageStates) = packageManagerLocal.allPackageStates
+        mutateState {
+            with(policy) {
+                onPackageInstalled(packageStates, disabledSystemPackageStates, packageName, userId)
+            }
+        }
+    }
+
+    internal fun onPackageUninstalled(packageName: String, appId: Int, userId: Int) {
+        val (packageStates, disabledSystemPackageStates) = packageManagerLocal.allPackageStates
+        mutateState {
+            with(policy) {
+                onPackageUninstalled(
+                    packageStates, disabledSystemPackageStates, packageName, appId, userId
+                )
+            }
+        }
+    }
+
+    private val PackageManagerLocal.allPackageStates:
+        Pair<Map<String, PackageState>, Map<String, PackageState>>
+        get() = withUnfilteredSnapshot().use { it.packageStates to it.disabledSystemPackageStates }
+
     internal inline fun <T> getState(action: GetStateScope.() -> T): T =
         GetStateScope(state).action()
 
-    internal inline fun mutateState(action: MutateStateScope.() -> Unit) {
+    internal inline fun mutateState(crossinline action: MutateStateScope.() -> Unit) {
         synchronized(stateLock) {
             val oldState = state
             val newState = oldState.copy()
diff --git a/services/permission/java/com/android/server/permission/access/AccessPolicy.kt b/services/permission/java/com/android/server/permission/access/AccessPolicy.kt
index e9741c6..89316c2 100644
--- a/services/permission/java/com/android/server/permission/access/AccessPolicy.kt
+++ b/services/permission/java/com/android/server/permission/access/AccessPolicy.kt
@@ -22,11 +22,12 @@
 import com.android.server.permission.access.appop.PackageAppOpPolicy
 import com.android.server.permission.access.appop.UidAppOpPolicy
 import com.android.server.permission.access.collection.* // ktlint-disable no-wildcard-imports
-import com.android.server.permission.access.external.PackageState
 import com.android.server.permission.access.permission.UidPermissionPolicy
 import com.android.server.permission.access.util.forEachTag
 import com.android.server.permission.access.util.tag
 import com.android.server.permission.access.util.tagName
+import com.android.server.pm.permission.PermissionAllowlist
+import com.android.server.pm.pkg.PackageState
 
 class AccessPolicy private constructor(
     private val schemePolicies: IndexedMap<String, IndexedMap<String, SchemePolicy>>
@@ -53,6 +54,25 @@
         with(getSchemePolicy(subject, `object`)) { setDecision(subject, `object`, decision) }
     }
 
+    fun initialize(
+        state: AccessState,
+        userIds: IntSet,
+        packageStates: Map<String, PackageState>,
+        disabledSystemPackageStates: Map<String, PackageState>,
+        permissionAllowlist: PermissionAllowlist
+    ) {
+        state.systemState.apply {
+            this.userIds += userIds
+            this.packageStates = packageStates
+            this.disabledSystemPackageStates = disabledSystemPackageStates
+            packageStates.forEach { (_, packageState) ->
+                appIds.getOrPut(packageState.appId) { IndexedListSet() }
+                    .add(packageState.packageName)
+            }
+            this.permissionAllowlist = permissionAllowlist
+        }
+    }
+
     fun MutateStateScope.onUserAdded(userId: Int) {
         newState.systemState.userIds += userId
         newState.userStates[userId] = UserState()
@@ -69,18 +89,44 @@
         }
     }
 
-    fun MutateStateScope.onPackageAdded(packageState: PackageState) {
+    fun MutateStateScope.onStorageVolumeMounted(
+        packageStates: Map<String, PackageState>,
+        disabledSystemPackageStates: Map<String, PackageState>,
+        volumeUuid: String?,
+        isSystemUpdated: Boolean
+    ) {
+        newState.systemState.apply {
+            this.packageStates = packageStates
+            this.disabledSystemPackageStates = disabledSystemPackageStates
+        }
+        forEachSchemePolicy {
+            with(it) { onStorageVolumeMounted(volumeUuid, isSystemUpdated) }
+        }
+    }
+
+    fun MutateStateScope.onPackageAdded(
+        packageStates: Map<String, PackageState>,
+        disabledSystemPackageStates: Map<String, PackageState>,
+        packageName: String
+    ) {
+        val packageState = packageStates[packageName]
+        // TODO(zhanghai): STOPSHIP: Remove check before feature enable.
+        checkNotNull(packageState) {
+            "Added package $packageName isn't found in packageStates in onPackageAdded()"
+        }
+        val appId = packageState.appId
         var isAppIdAdded = false
         newState.systemState.apply {
-            packageStates[packageState.packageName] = packageState
-            appIds.getOrPut(packageState.appId) {
+            this.packageStates = packageStates
+            this.disabledSystemPackageStates = disabledSystemPackageStates
+            appIds.getOrPut(appId) {
                 isAppIdAdded = true
                 IndexedListSet()
-            }.add(packageState.packageName)
+            }.add(packageName)
         }
         if (isAppIdAdded) {
             forEachSchemePolicy {
-                with(it) { onAppIdAdded(packageState.appId) }
+                with(it) { onAppIdAdded(appId) }
             }
         }
         forEachSchemePolicy {
@@ -88,30 +134,74 @@
         }
     }
 
-    fun MutateStateScope.onPackageRemoved(packageState: PackageState) {
+    fun MutateStateScope.onPackageRemoved(
+        packageStates: Map<String, PackageState>,
+        disabledSystemPackageStates: Map<String, PackageState>,
+        packageName: String,
+        appId: Int
+    ) {
+        // TODO(zhanghai): STOPSHIP: Remove check before feature enable.
+        check(packageName !in packageStates) {
+            "Removed package $packageName is still in packageStates in onPackageRemoved()"
+        }
         var isAppIdRemoved = false
         newState.systemState.apply {
-            packageStates -= packageState.packageName
-            appIds.apply appIds@{
-                this[packageState.appId]?.apply {
-                    this -= packageState.packageName
-                    if (isEmpty()) {
-                        this@appIds -= packageState.appId
-                        isAppIdRemoved = true
-                    }
+            this.packageStates = packageStates
+            this.disabledSystemPackageStates = disabledSystemPackageStates
+            appIds[appId]?.apply {
+                this -= packageName
+                if (isEmpty()) {
+                    appIds -= appId
+                    isAppIdRemoved = true
                 }
             }
         }
         forEachSchemePolicy {
-            with(it) { onPackageRemoved(packageState) }
+            with(it) { onPackageRemoved(packageName, appId) }
         }
         if (isAppIdRemoved) {
             forEachSchemePolicy {
-                with(it) { onAppIdRemoved(packageState.appId) }
+                with(it) { onAppIdRemoved(appId) }
             }
         }
     }
 
+    fun MutateStateScope.onPackageInstalled(
+        packageStates: Map<String, PackageState>,
+        disabledSystemPackageStates: Map<String, PackageState>,
+        packageName: String,
+        userId: Int
+    ) {
+        newState.systemState.apply {
+            this.packageStates = packageStates
+            this.disabledSystemPackageStates = disabledSystemPackageStates
+        }
+        val packageState = packageStates[packageName]
+        // TODO(zhanghai): STOPSHIP: Remove check before feature enable.
+        checkNotNull(packageState) {
+            "Installed package $packageName isn't found in packageStates in onPackageInstalled()"
+        }
+        forEachSchemePolicy {
+            with(it) { onPackageInstalled(packageState, userId) }
+        }
+    }
+
+    fun MutateStateScope.onPackageUninstalled(
+        packageStates: Map<String, PackageState>,
+        disabledSystemPackageStates: Map<String, PackageState>,
+        packageName: String,
+        appId: Int,
+        userId: Int
+    ) {
+        newState.systemState.apply {
+            this.packageStates = packageStates
+            this.disabledSystemPackageStates = disabledSystemPackageStates
+        }
+        forEachSchemePolicy {
+            with(it) { onPackageUninstalled(packageName, appId, userId) }
+        }
+    }
+
     fun BinaryXmlPullParser.parseSystemState(systemState: SystemState) {
         forEachTag {
             when (tagName) {
@@ -182,10 +272,6 @@
 }
 
 abstract class SchemePolicy {
-    @Volatile
-    private var onDecisionChangedListeners = IndexedListSet<OnDecisionChangedListener>()
-    private val onDecisionChangedListenersLock = Any()
-
     abstract val subjectScheme: String
 
     abstract val objectScheme: String
@@ -198,30 +284,6 @@
         decision: Int
     )
 
-    fun addOnDecisionChangedListener(listener: OnDecisionChangedListener) {
-        synchronized(onDecisionChangedListenersLock) {
-            onDecisionChangedListeners = onDecisionChangedListeners + listener
-        }
-    }
-
-    fun removeOnDecisionChangedListener(listener: OnDecisionChangedListener) {
-        synchronized(onDecisionChangedListenersLock) {
-            onDecisionChangedListeners = onDecisionChangedListeners - listener
-        }
-    }
-
-    protected fun notifyOnDecisionChangedListeners(
-        subject: AccessUri,
-        `object`: AccessUri,
-        oldDecision: Int,
-        newDecision: Int
-    ) {
-        val listeners = onDecisionChangedListeners
-        listeners.forEachIndexed { _, it ->
-            it.onDecisionChanged(subject, `object`, oldDecision, newDecision)
-        }
-    }
-
     open fun MutateStateScope.onUserAdded(userId: Int) {}
 
     open fun MutateStateScope.onUserRemoved(userId: Int) {}
@@ -230,9 +292,18 @@
 
     open fun MutateStateScope.onAppIdRemoved(appId: Int) {}
 
+    open fun MutateStateScope.onStorageVolumeMounted(
+        volumeUuid: String?,
+        isSystemUpdated: Boolean
+    ) {}
+
     open fun MutateStateScope.onPackageAdded(packageState: PackageState) {}
 
-    open fun MutateStateScope.onPackageRemoved(packageState: PackageState) {}
+    open fun MutateStateScope.onPackageRemoved(packageName: String, appId: Int) {}
+
+    open fun MutateStateScope.onPackageInstalled(packageState: PackageState, userId: Int) {}
+
+    open fun MutateStateScope.onPackageUninstalled(packageName: String, appId: Int, userId: Int) {}
 
     open fun BinaryXmlPullParser.parseSystemState(systemState: SystemState) {}
 
@@ -241,13 +312,4 @@
     open fun BinaryXmlPullParser.parseUserState(userId: Int, userState: UserState) {}
 
     open fun BinaryXmlSerializer.serializeUserState(userId: Int, userState: UserState) {}
-
-    fun interface OnDecisionChangedListener {
-        fun onDecisionChanged(
-            subject: AccessUri,
-            `object`: AccessUri,
-            oldDecision: Int,
-            newDecision: Int
-        )
-    }
 }
diff --git a/services/permission/java/com/android/server/permission/access/AccessState.kt b/services/permission/java/com/android/server/permission/access/AccessState.kt
index cf8f383..fae1ec3 100644
--- a/services/permission/java/com/android/server/permission/access/AccessState.kt
+++ b/services/permission/java/com/android/server/permission/access/AccessState.kt
@@ -18,73 +18,66 @@
 
 import android.content.pm.PermissionGroupInfo
 import com.android.server.permission.access.collection.* // ktlint-disable no-wildcard-imports
-import com.android.server.permission.access.data.Permission
-import com.android.server.permission.access.external.PackageState
+import com.android.server.permission.access.permission.Permission
+import com.android.server.pm.permission.PermissionAllowlist
+import com.android.server.pm.pkg.PackageState
 
 class AccessState private constructor(
     val systemState: SystemState,
     val userStates: IntMap<UserState>
 ) {
-    constructor() : this(SystemState(), IntMap())
+    constructor() : this(
+        SystemState(),
+        IntMap()
+    )
 
-    fun copy(): AccessState = AccessState(systemState.copy(), userStates.copy { it.copy() })
+    fun copy(): AccessState = AccessState(
+        systemState.copy(),
+        userStates.copy { it.copy() }
+    )
 }
 
 class SystemState private constructor(
     val userIds: IntSet,
-    val packageStates: IndexedMap<String, PackageState>,
-    val disabledSystemPackageStates: IndexedMap<String, PackageState>,
+    var packageStates: Map<String, PackageState>,
+    var disabledSystemPackageStates: Map<String, PackageState>,
     val appIds: IntMap<IndexedListSet<String>>,
     // A map of KnownPackagesInt to a set of known package names
     val knownPackages: IntMap<IndexedListSet<String>>,
     // A map of userId to packageName
     val deviceAndProfileOwners: IntMap<String>,
-    // A map of packageName to (A map of oem permission name to whether it's granted)
-    val oemPermissions: IndexedMap<String, IndexedMap<String, Boolean>>,
     val privilegedPermissionAllowlistSourcePackageNames: IndexedListSet<String>,
-    // A map of packageName to a set of vendor priv app permission names
-    val vendorPrivAppPermissions: Map<String, Set<String>>,
-    val productPrivAppPermissions: Map<String, Set<String>>,
-    val systemExtPrivAppPermissions: Map<String, Set<String>>,
-    val privAppPermissions: Map<String, Set<String>>,
-    val apexPrivAppPermissions: Map<String, Map<String, Set<String>>>,
-    val vendorPrivAppDenyPermissions: Map<String, Set<String>>,
-    val productPrivAppDenyPermissions: Map<String, Set<String>>,
-    val systemExtPrivAppDenyPermissions: Map<String, Set<String>>,
-    val apexPrivAppDenyPermissions: Map<String, Map<String, Set<String>>>,
-    val privAppDenyPermissions: Map<String, Set<String>>,
+    var permissionAllowlist: PermissionAllowlist,
     val implicitToSourcePermissions: Map<String, Set<String>>,
     val permissionGroups: IndexedMap<String, PermissionGroupInfo>,
     val permissionTrees: IndexedMap<String, Permission>,
     val permissions: IndexedMap<String, Permission>
 ) : WritableState() {
     constructor() : this(
-        IntSet(), IndexedMap(), IndexedMap(), IntMap(), IntMap(), IntMap(), IndexedMap(),
-        IndexedListSet(), IndexedMap(), IndexedMap(), IndexedMap(), IndexedMap(), IndexedMap(),
-        IndexedMap(), IndexedMap(), IndexedMap(), IndexedMap(), IndexedMap(), IndexedMap(),
-        IndexedMap(), IndexedMap(), IndexedMap()
+        IntSet(),
+        emptyMap(),
+        emptyMap(),
+        IntMap(),
+        IntMap(),
+        IntMap(),
+        IndexedListSet(),
+        PermissionAllowlist(),
+        IndexedMap(),
+        IndexedMap(),
+        IndexedMap(),
+        IndexedMap()
     )
 
     fun copy(): SystemState =
         SystemState(
             userIds.copy(),
-            packageStates.copy { it },
-            disabledSystemPackageStates.copy { it },
+            packageStates,
+            disabledSystemPackageStates,
             appIds.copy { it.copy() },
             knownPackages.copy { it.copy() },
             deviceAndProfileOwners.copy { it },
-            oemPermissions.copy { it.copy { it } },
             privilegedPermissionAllowlistSourcePackageNames.copy(),
-            vendorPrivAppPermissions,
-            productPrivAppPermissions,
-            systemExtPrivAppPermissions,
-            privAppPermissions,
-            apexPrivAppPermissions,
-            vendorPrivAppDenyPermissions,
-            productPrivAppDenyPermissions,
-            systemExtPrivAppDenyPermissions,
-            apexPrivAppDenyPermissions,
-            privAppDenyPermissions,
+            permissionAllowlist,
             implicitToSourcePermissions,
             permissionGroups.copy { it },
             permissionTrees.copy { it },
@@ -94,14 +87,21 @@
 
 class UserState private constructor(
     // A map of (appId to a map of (permissionName to permissionFlags))
-    val permissionFlags: IntMap<IndexedMap<String, Int>>,
+    val uidPermissionFlags: IntMap<IndexedMap<String, Int>>,
     val uidAppOpModes: IntMap<IndexedMap<String, Int>>,
     val packageAppOpModes: IndexedMap<String, IndexedMap<String, Int>>
 ) : WritableState() {
-    constructor() : this(IntMap(), IntMap(), IndexedMap())
+    constructor() : this(
+        IntMap(),
+        IntMap(),
+        IndexedMap()
+    )
 
-    fun copy(): UserState = UserState(permissionFlags.copy { it.copy { it } },
-        uidAppOpModes.copy { it.copy { it } }, packageAppOpModes.copy { it.copy { it } })
+    fun copy(): UserState = UserState(
+        uidPermissionFlags.copy { it.copy { it } },
+        uidAppOpModes.copy { it.copy { it } },
+        packageAppOpModes.copy { it.copy { it } }
+    )
 }
 
 object WriteMode {
diff --git a/services/permission/java/com/android/server/permission/access/AccessUri.kt b/services/permission/java/com/android/server/permission/access/AccessUri.kt
index 7e98d2c..d1abc04 100644
--- a/services/permission/java/com/android/server/permission/access/AccessUri.kt
+++ b/services/permission/java/com/android/server/permission/access/AccessUri.kt
@@ -16,8 +16,7 @@
 
 package com.android.server.permission.access
 
-import com.android.server.permission.access.external.UserHandle
-import com.android.server.permission.access.external.UserHandleCompat
+import android.os.UserHandle
 
 sealed class AccessUri(
     val scheme: String
@@ -70,7 +69,7 @@
     val uid: Int
 ) : AccessUri(SCHEME) {
     val userId: Int
-        get() = UserHandleCompat.getUserId(uid)
+        get() = UserHandle.getUserId(uid)
 
     val appId: Int
         get() = UserHandle.getAppId(uid)
diff --git a/services/permission/java/com/android/server/permission/access/appop/AppOpsCheckingServiceCompatImpl.kt b/services/permission/java/com/android/server/permission/access/appop/AppOpService.kt
similarity index 94%
rename from services/permission/java/com/android/server/permission/access/appop/AppOpsCheckingServiceCompatImpl.kt
rename to services/permission/java/com/android/server/permission/access/appop/AppOpService.kt
index a565feb..b8d6aa3 100644
--- a/services/permission/java/com/android/server/permission/access/appop/AppOpsCheckingServiceCompatImpl.kt
+++ b/services/permission/java/com/android/server/permission/access/appop/AppOpService.kt
@@ -24,9 +24,13 @@
 import com.android.server.permission.access.AccessCheckingService
 import java.io.PrintWriter
 
-class AppOpsCheckingServiceCompatImpl(
-    private val accessCheckingService: AccessCheckingService
+class AppOpService(
+    private val service: AccessCheckingService
 ) : AppOpsCheckingServiceInterface {
+    fun initialize() {
+        TODO("Not yet implemented")
+    }
+
     override fun getNonDefaultUidModes(uid: Int): SparseIntArray {
         TODO("Not yet implemented")
     }
@@ -139,6 +143,6 @@
     }
 
     companion object {
-        private val LOG_TAG = AppOpsCheckingServiceCompatImpl::class.java.simpleName
+        private val LOG_TAG = AppOpService::class.java.simpleName
     }
 }
diff --git a/services/permission/java/com/android/server/permission/access/appop/BaseAppOpPolicy.kt b/services/permission/java/com/android/server/permission/access/appop/BaseAppOpPolicy.kt
index a1a5e2d..7f4e0f7 100644
--- a/services/permission/java/com/android/server/permission/access/appop/BaseAppOpPolicy.kt
+++ b/services/permission/java/com/android/server/permission/access/appop/BaseAppOpPolicy.kt
@@ -16,50 +16,17 @@
 
 package com.android.server.permission.access.appop
 
-import android.app.AppOpsManager
 import com.android.modules.utils.BinaryXmlPullParser
 import com.android.modules.utils.BinaryXmlSerializer
-import com.android.server.permission.access.AccessUri
 import com.android.server.permission.access.AppOpUri
-import com.android.server.permission.access.GetStateScope
-import com.android.server.permission.access.MutateStateScope
 import com.android.server.permission.access.SchemePolicy
 import com.android.server.permission.access.UserState
-import com.android.server.permission.access.collection.* // ktlint-disable no-wildcard-imports
 
-abstract class BaseAppOpPolicy(private val persistence: BaseAppOpPersistence) : SchemePolicy() {
-    override fun GetStateScope.getDecision(subject: AccessUri, `object`: AccessUri): Int {
-        `object` as AppOpUri
-        return getModes(subject)
-            .getWithDefault(`object`.appOpName, opToDefaultMode(`object`.appOpName))
-    }
-
-    override fun MutateStateScope.setDecision(
-        subject: AccessUri,
-        `object`: AccessUri,
-        decision: Int
-    ) {
-        `object` as AppOpUri
-        val modes = getOrCreateModes(subject)
-        val oldMode = modes.putWithDefault(`object`.appOpName, decision,
-            opToDefaultMode(`object`.appOpName))
-        if (modes.isEmpty()) {
-            removeModes(subject)
-        }
-        if (oldMode != decision) {
-            notifyOnDecisionChangedListeners(subject, `object`, oldMode, decision)
-        }
-    }
-
-    abstract fun GetStateScope.getModes(subject: AccessUri): IndexedMap<String, Int>?
-
-    abstract fun MutateStateScope.getOrCreateModes(subject: AccessUri): IndexedMap<String, Int>
-
-    abstract fun MutateStateScope.removeModes(subject: AccessUri)
-
-    // TODO need to check that [AppOpsManager.getSystemAlertWindowDefault] works; likely no issue
-    //  since running in system process.
-    private fun opToDefaultMode(appOpName: String) = AppOpsManager.opToDefaultMode(appOpName)
+abstract class BaseAppOpPolicy(
+    private val persistence: BaseAppOpPersistence
+) : SchemePolicy() {
+    override val objectScheme: String
+        get() = AppOpUri.SCHEME
 
     override fun BinaryXmlPullParser.parseUserState(userId: Int, userState: UserState) {
         with(persistence) { this@parseUserState.parseUserState(userId, userState) }
diff --git a/services/permission/java/com/android/server/permission/access/appop/PackageAppOpPolicy.kt b/services/permission/java/com/android/server/permission/access/appop/PackageAppOpPolicy.kt
index 966489f..607e512 100644
--- a/services/permission/java/com/android/server/permission/access/appop/PackageAppOpPolicy.kt
+++ b/services/permission/java/com/android/server/permission/access/appop/PackageAppOpPolicy.kt
@@ -16,41 +16,101 @@
 
 package com.android.server.permission.access.appop
 
+import android.app.AppOpsManager
 import com.android.server.permission.access.AccessUri
 import com.android.server.permission.access.AppOpUri
 import com.android.server.permission.access.GetStateScope
 import com.android.server.permission.access.MutateStateScope
 import com.android.server.permission.access.PackageUri
-import com.android.server.permission.access.UserState
 import com.android.server.permission.access.collection.* // ktlint-disable no-wildcard-imports
-import com.android.server.permission.access.external.PackageState
 
 class PackageAppOpPolicy : BaseAppOpPolicy(PackageAppOpPersistence()) {
+    @Volatile
+    private var onAppOpModeChangedListeners = IndexedListSet<OnAppOpModeChangedListener>()
+    private val onAppOpModeChangedListenersLock = Any()
+
     override val subjectScheme: String
         get() = PackageUri.SCHEME
 
-    override val objectScheme: String
-        get() = AppOpUri.SCHEME
-
-    override fun GetStateScope.getModes(subject: AccessUri): IndexedMap<String, Int>? {
+    override fun GetStateScope.getDecision(subject: AccessUri, `object`: AccessUri): Int {
         subject as PackageUri
-        return state.userStates[subject.userId]?.packageAppOpModes?.get(subject.packageName)
+        `object` as AppOpUri
+        return getAppOpMode(subject.packageName, subject.userId, `object`.appOpName)
     }
 
-    override fun MutateStateScope.getOrCreateModes(subject: AccessUri): IndexedMap<String, Int> {
+    override fun MutateStateScope.setDecision(
+        subject: AccessUri,
+        `object`: AccessUri,
+        decision: Int
+    ) {
         subject as PackageUri
-        return newState.userStates.getOrPut(subject.userId) { UserState() }
-            .packageAppOpModes.getOrPut(subject.packageName) { IndexedMap() }
+        `object` as AppOpUri
+        setAppOpMode(subject.packageName, subject.userId, `object`.appOpName, decision)
     }
 
-    override fun MutateStateScope.removeModes(subject: AccessUri) {
-        subject as PackageUri
-        newState.userStates[subject.userId]?.packageAppOpModes?.remove(subject.packageName)
-    }
-
-    override fun MutateStateScope.onPackageRemoved(packageState: PackageState) {
+    override fun MutateStateScope.onPackageRemoved(packageName: String, appId: Int) {
         newState.userStates.forEachIndexed { _, _, userState ->
-            userState.packageAppOpModes -= packageState.packageName
+            userState.packageAppOpModes -= packageName
+            userState.requestWrite()
+            // Skip notifying the change listeners since the package no longer exists.
         }
     }
+
+    fun MutateStateScope.removeAppOpModes(packageName: String, userId: Int): Boolean =
+        newState.userStates[userId].packageAppOpModes.remove(packageName) != null
+
+    fun GetStateScope.getAppOpMode(packageName: String, userId: Int, appOpName: String): Int =
+        state.userStates[userId].packageAppOpModes[packageName]
+            .getWithDefault(appOpName, AppOpsManager.opToDefaultMode(appOpName))
+
+    fun MutateStateScope.setAppOpMode(
+        packageName: String,
+        userId: Int,
+        appOpName: String,
+        mode: Int
+    ): Boolean {
+        val userState = newState.userStates[userId]
+        val packageAppOpModes = userState.packageAppOpModes
+        var appOpModes = packageAppOpModes[packageName]
+        val defaultMode = AppOpsManager.opToDefaultMode(appOpName)
+        val oldMode = appOpModes.getWithDefault(appOpName, defaultMode)
+        if (oldMode == mode) {
+            return false
+        }
+        if (appOpModes == null) {
+            appOpModes = IndexedMap()
+            packageAppOpModes[packageName] = appOpModes
+        }
+        appOpModes.putWithDefault(appOpName, mode, defaultMode)
+        if (appOpModes.isEmpty()) {
+            packageAppOpModes -= packageName
+        }
+        userState.requestWrite()
+        onAppOpModeChangedListeners.forEachIndexed { _, it ->
+            it.onAppOpModeChanged(packageName, userId, appOpName, oldMode, mode)
+        }
+        return true
+    }
+
+    fun addOnAppOpModeChangedListener(listener: OnAppOpModeChangedListener) {
+        synchronized(onAppOpModeChangedListenersLock) {
+            onAppOpModeChangedListeners = onAppOpModeChangedListeners + listener
+        }
+    }
+
+    fun removeOnAppOpModeChangedListener(listener: OnAppOpModeChangedListener) {
+        synchronized(onAppOpModeChangedListenersLock) {
+            onAppOpModeChangedListeners = onAppOpModeChangedListeners - listener
+        }
+    }
+
+    fun interface OnAppOpModeChangedListener {
+        fun onAppOpModeChanged(
+            packageName: String,
+            userId: Int,
+            appOpName: String,
+            oldMode: Int,
+            newMode: Int
+        )
+    }
 }
diff --git a/services/permission/java/com/android/server/permission/access/appop/UidAppOpPolicy.kt b/services/permission/java/com/android/server/permission/access/appop/UidAppOpPolicy.kt
index 862db8f..0b01038 100644
--- a/services/permission/java/com/android/server/permission/access/appop/UidAppOpPolicy.kt
+++ b/services/permission/java/com/android/server/permission/access/appop/UidAppOpPolicy.kt
@@ -16,40 +16,104 @@
 
 package com.android.server.permission.access.appop
 
+import android.app.AppOpsManager
 import com.android.server.permission.access.AccessUri
 import com.android.server.permission.access.AppOpUri
 import com.android.server.permission.access.GetStateScope
 import com.android.server.permission.access.MutateStateScope
 import com.android.server.permission.access.UidUri
-import com.android.server.permission.access.UserState
 import com.android.server.permission.access.collection.* // ktlint-disable no-wildcard-imports
 
 class UidAppOpPolicy : BaseAppOpPolicy(UidAppOpPersistence()) {
+    @Volatile
+    private var onAppOpModeChangedListeners = IndexedListSet<OnAppOpModeChangedListener>()
+    private val onAppOpModeChangedListenersLock = Any()
+
     override val subjectScheme: String
         get() = UidUri.SCHEME
 
-    override val objectScheme: String
-        get() = AppOpUri.SCHEME
-
-    override fun GetStateScope.getModes(subject: AccessUri): IndexedMap<String, Int>? {
+    override fun GetStateScope.getDecision(subject: AccessUri, `object`: AccessUri): Int {
         subject as UidUri
-        return state.userStates[subject.userId]?.uidAppOpModes?.get(subject.appId)
+        `object` as AppOpUri
+        return getAppOpMode(subject.appId, subject.userId, `object`.appOpName)
     }
 
-    override fun MutateStateScope.getOrCreateModes(subject: AccessUri): IndexedMap<String, Int> {
+    override fun MutateStateScope.setDecision(
+        subject: AccessUri,
+        `object`: AccessUri,
+        decision: Int
+    ) {
         subject as UidUri
-        return newState.userStates.getOrPut(subject.userId) { UserState() }
-            .uidAppOpModes.getOrPut(subject.appId) { IndexedMap() }
-    }
-
-    override fun MutateStateScope.removeModes(subject: AccessUri) {
-        subject as UidUri
-        newState.userStates[subject.userId]?.uidAppOpModes?.remove(subject.appId)
+        `object` as AppOpUri
+        setAppOpMode(subject.appId, subject.userId, `object`.appOpName, decision)
     }
 
     override fun MutateStateScope.onAppIdRemoved(appId: Int) {
         newState.userStates.forEachIndexed { _, _, userState ->
             userState.uidAppOpModes -= appId
+            userState.requestWrite()
+            // Skip notifying the change listeners since the app ID no longer exists.
         }
     }
+
+    fun GetStateScope.getAppOpModes(appId: Int, userId: Int): IndexedMap<String, Int>? =
+        state.userStates[userId].uidAppOpModes[appId]
+
+    fun MutateStateScope.removeAppOpModes(appId: Int, userId: Int): Boolean =
+        newState.userStates[userId].uidAppOpModes.removeReturnOld(appId) != null
+
+    fun GetStateScope.getAppOpMode(appId: Int, userId: Int, appOpName: String): Int =
+        state.userStates[userId].uidAppOpModes[appId]
+            .getWithDefault(appOpName, AppOpsManager.opToDefaultMode(appOpName))
+
+    fun MutateStateScope.setAppOpMode(
+        appId: Int,
+        userId: Int,
+        appOpName: String,
+        mode: Int
+    ): Boolean {
+        val userState = newState.userStates[userId]
+        val uidAppOpModes = userState.uidAppOpModes
+        var appOpModes = uidAppOpModes[appId]
+        val defaultMode = AppOpsManager.opToDefaultMode(appOpName)
+        val oldMode = appOpModes.getWithDefault(appOpName, defaultMode)
+        if (oldMode == mode) {
+            return false
+        }
+        if (appOpModes == null) {
+            appOpModes = IndexedMap()
+            uidAppOpModes[appId] = appOpModes
+        }
+        appOpModes.putWithDefault(appOpName, mode, defaultMode)
+        if (appOpModes.isEmpty()) {
+            uidAppOpModes -= appId
+        }
+        userState.requestWrite()
+        onAppOpModeChangedListeners.forEachIndexed { _, it ->
+            it.onAppOpModeChanged(appId, userId, appOpName, oldMode, mode)
+        }
+        return true
+    }
+
+    fun addOnAppOpModeChangedListener(listener: OnAppOpModeChangedListener) {
+        synchronized(onAppOpModeChangedListenersLock) {
+            onAppOpModeChangedListeners = onAppOpModeChangedListeners + listener
+        }
+    }
+
+    fun removeOnAppOpModeChangedListener(listener: OnAppOpModeChangedListener) {
+        synchronized(onAppOpModeChangedListenersLock) {
+            onAppOpModeChangedListeners = onAppOpModeChangedListeners - listener
+        }
+    }
+
+    fun interface OnAppOpModeChangedListener {
+        fun onAppOpModeChanged(
+            appId: Int,
+            userId: Int,
+            appOpName: String,
+            oldMode: Int,
+            newMode: Int
+        )
+    }
 }
diff --git a/services/permission/java/com/android/server/permission/access/collection/IndexedList.kt b/services/permission/java/com/android/server/permission/access/collection/IndexedList.kt
index 5ba435c..c4d07fe 100644
--- a/services/permission/java/com/android/server/permission/access/collection/IndexedList.kt
+++ b/services/permission/java/com/android/server/permission/access/collection/IndexedList.kt
@@ -19,8 +19,8 @@
 typealias IndexedList<T> = ArrayList<T>
 
 inline fun <T> IndexedList<T>.allIndexed(predicate: (Int, T) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (!predicate(index, this[index])) {
+    forEachIndexed { index, element ->
+        if (!predicate(index, element)) {
             return false
         }
     }
@@ -28,8 +28,8 @@
 }
 
 inline fun <T> IndexedList<T>.anyIndexed(predicate: (Int, T) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (predicate(index, this[index])) {
+    forEachIndexed { index, element ->
+        if (predicate(index, element)) {
             return true
         }
     }
@@ -45,6 +45,12 @@
     }
 }
 
+inline fun <T> IndexedList<T>.forEachReversedIndexed(action: (Int, T) -> Unit) {
+    for (index in lastIndex downTo 0) {
+        action(index, this[index])
+    }
+}
+
 @Suppress("NOTHING_TO_INLINE")
 inline operator fun <T> IndexedList<T>.minus(element: T): IndexedList<T> =
     copy().apply { this -= element }
@@ -55,8 +61,8 @@
 }
 
 inline fun <T> IndexedList<T>.noneIndexed(predicate: (Int, T) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (predicate(index, this[index])) {
+    forEachIndexed { index, element ->
+        if (predicate(index, element)) {
             return false
         }
     }
@@ -72,18 +78,24 @@
     add(element)
 }
 
-inline fun <T> IndexedList<T>.removeAllIndexed(predicate: (Int, T) -> Boolean) {
-    for (index in lastIndex downTo 0) {
-        if (predicate(index, this[index])) {
+inline fun <T> IndexedList<T>.removeAllIndexed(predicate: (Int, T) -> Boolean): Boolean {
+    var isChanged = false
+    forEachReversedIndexed { index, element ->
+        if (predicate(index, element)) {
             removeAt(index)
+            isChanged = true
         }
     }
+    return isChanged
 }
 
-inline fun <T> IndexedList<T>.retainAllIndexed(predicate: (Int, T) -> Boolean) {
-    for (index in lastIndex downTo 0) {
-        if (!predicate(index, this[index])) {
+inline fun <T> IndexedList<T>.retainAllIndexed(predicate: (Int, T) -> Boolean): Boolean {
+    var isChanged = false
+    forEachReversedIndexed { index, element ->
+        if (!predicate(index, element)) {
             removeAt(index)
+            isChanged = true
         }
     }
+    return isChanged
 }
diff --git a/services/permission/java/com/android/server/permission/access/collection/IndexedListSet.kt b/services/permission/java/com/android/server/permission/access/collection/IndexedListSet.kt
index ac552ff..c40f7ee 100644
--- a/services/permission/java/com/android/server/permission/access/collection/IndexedListSet.kt
+++ b/services/permission/java/com/android/server/permission/access/collection/IndexedListSet.kt
@@ -70,8 +70,8 @@
 }
 
 inline fun <T> IndexedListSet<T>.allIndexed(predicate: (Int, T) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (!predicate(index, elementAt(index))) {
+    forEachIndexed { index, element ->
+        if (!predicate(index, element)) {
             return false
         }
     }
@@ -79,8 +79,8 @@
 }
 
 inline fun <T> IndexedListSet<T>.anyIndexed(predicate: (Int, T) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (predicate(index, elementAt(index))) {
+    forEachIndexed { index, element ->
+        if (predicate(index, element)) {
             return true
         }
     }
@@ -93,6 +93,12 @@
     }
 }
 
+inline fun <T> IndexedListSet<T>.forEachReversedIndexed(action: (Int, T) -> Unit) {
+    for (index in lastIndex downTo 0) {
+        action(index, elementAt(index))
+    }
+}
+
 inline val <T> IndexedListSet<T>.lastIndex: Int
     get() = size - 1
 
@@ -106,8 +112,8 @@
 }
 
 inline fun <T> IndexedListSet<T>.noneIndexed(predicate: (Int, T) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (predicate(index, elementAt(index))) {
+    forEachIndexed { index, element ->
+        if (predicate(index, element)) {
             return false
         }
     }
@@ -123,18 +129,24 @@
     add(element)
 }
 
-inline fun <T> IndexedListSet<T>.removeAllIndexed(predicate: (Int, T) -> Boolean) {
-    for (index in lastIndex downTo 0) {
-        if (predicate(index, elementAt(index))) {
+inline fun <T> IndexedListSet<T>.removeAllIndexed(predicate: (Int, T) -> Boolean): Boolean {
+    var isChanged = false
+    forEachReversedIndexed { index, element ->
+        if (predicate(index, element)) {
             removeAt(index)
+            isChanged = true
         }
     }
+    return isChanged
 }
 
-inline fun <T> IndexedListSet<T>.retainAllIndexed(predicate: (Int, T) -> Boolean) {
-    for (index in lastIndex downTo 0) {
-        if (!predicate(index, elementAt(index))) {
+inline fun <T> IndexedListSet<T>.retainAllIndexed(predicate: (Int, T) -> Boolean): Boolean {
+    var isChanged = false
+    forEachReversedIndexed { index, element ->
+        if (!predicate(index, element)) {
             removeAt(index)
+            isChanged = true
         }
     }
+    return isChanged
 }
diff --git a/services/permission/java/com/android/server/permission/access/collection/IndexedMap.kt b/services/permission/java/com/android/server/permission/access/collection/IndexedMap.kt
index 1251666..43f18e2 100644
--- a/services/permission/java/com/android/server/permission/access/collection/IndexedMap.kt
+++ b/services/permission/java/com/android/server/permission/access/collection/IndexedMap.kt
@@ -21,8 +21,8 @@
 typealias IndexedMap<K, V> = ArrayMap<K, V>
 
 inline fun <K, V> IndexedMap<K, V>.allIndexed(predicate: (Int, K, V) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (!predicate(index, keyAt(index), valueAt(index))) {
+    forEachIndexed { index, key, value ->
+        if (!predicate(index, key, value)) {
             return false
         }
     }
@@ -30,8 +30,8 @@
 }
 
 inline fun <K, V> IndexedMap<K, V>.anyIndexed(predicate: (Int, K, V) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (predicate(index, keyAt(index), valueAt(index))) {
+    forEachIndexed { index, key, value ->
+        if (predicate(index, key, value)) {
             return true
         }
     }
@@ -46,8 +46,8 @@
     }
 
 inline fun <K, V, R> IndexedMap<K, V>.firstNotNullOfOrNullIndexed(transform: (Int, K, V) -> R): R? {
-    for (index in 0 until size) {
-        transform(index, keyAt(index), valueAt(index))?.let { return it }
+    forEachIndexed { index, key, value ->
+        transform(index, key, value)?.let { return it }
     }
     return null
 }
@@ -64,6 +64,12 @@
     }
 }
 
+inline fun <K, V> IndexedMap<K, V>.forEachReversedIndexed(action: (Int, K, V) -> Unit) {
+    for (index in lastIndex downTo 0) {
+        action(index, keyAt(index), valueAt(index))
+    }
+}
+
 inline fun <K, V> IndexedMap<K, V>.forEachValueIndexed(action: (Int, V) -> Unit) {
     for (index in 0 until size) {
         action(index, valueAt(index))
@@ -90,6 +96,15 @@
     remove(key)
 }
 
+inline fun <K, V> IndexedMap<K, V>.noneIndexed(predicate: (Int, K, V) -> Boolean): Boolean {
+    forEachIndexed { index, key, value ->
+        if (predicate(index, key, value)) {
+            return false
+        }
+    }
+    return true
+}
+
 @Suppress("NOTHING_TO_INLINE")
 inline fun <K, V> IndexedMap<K, V>.putWithDefault(key: K, value: V, defaultValue: V): V {
     val index = indexOfKey(key)
@@ -111,20 +126,26 @@
     }
 }
 
-inline fun <K, V> IndexedMap<K, V>.removeAllIndexed(predicate: (Int, K, V) -> Boolean) {
-    for (index in lastIndex downTo 0) {
-        if (predicate(index, keyAt(index), valueAt(index))) {
+inline fun <K, V> IndexedMap<K, V>.removeAllIndexed(predicate: (Int, K, V) -> Boolean): Boolean {
+    var isChanged = false
+    forEachReversedIndexed { index, key, value ->
+        if (predicate(index, key, value)) {
             removeAt(index)
+            isChanged = true
         }
     }
+    return isChanged
 }
 
-inline fun <K, V> IndexedMap<K, V>.retainAllIndexed(predicate: (Int, K, V) -> Boolean) {
-    for (index in lastIndex downTo 0) {
-        if (!predicate(index, keyAt(index), valueAt(index))) {
+inline fun <K, V> IndexedMap<K, V>.retainAllIndexed(predicate: (Int, K, V) -> Boolean): Boolean {
+    var isChanged = false
+    forEachReversedIndexed { index, key, value ->
+        if (!predicate(index, key, value)) {
             removeAt(index)
+            isChanged = true
         }
     }
+    return isChanged
 }
 
 @Suppress("NOTHING_TO_INLINE")
diff --git a/services/permission/java/com/android/server/permission/access/collection/IndexedSet.kt b/services/permission/java/com/android/server/permission/access/collection/IndexedSet.kt
index 36d8ff0c..13fa31f 100644
--- a/services/permission/java/com/android/server/permission/access/collection/IndexedSet.kt
+++ b/services/permission/java/com/android/server/permission/access/collection/IndexedSet.kt
@@ -21,8 +21,8 @@
 typealias IndexedSet<T> = ArraySet<T>
 
 inline fun <T> IndexedSet<T>.allIndexed(predicate: (Int, T) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (!predicate(index, elementAt(index))) {
+    forEachIndexed { index, element ->
+        if (!predicate(index, element)) {
             return false
         }
     }
@@ -30,8 +30,8 @@
 }
 
 inline fun <T> IndexedSet<T>.anyIndexed(predicate: (Int, T) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (predicate(index, elementAt(index))) {
+    forEachIndexed { index, element ->
+        if (predicate(index, element)) {
             return true
         }
     }
@@ -50,6 +50,12 @@
     }
 }
 
+inline fun <T> IndexedSet<T>.forEachReversedIndexed(action: (Int, T) -> Unit) {
+    for (index in lastIndex downTo 0) {
+        action(index, elementAt(index))
+    }
+}
+
 inline val <T> IndexedSet<T>.lastIndex: Int
     get() = size - 1
 
@@ -63,8 +69,8 @@
 }
 
 inline fun <T> IndexedSet<T>.noneIndexed(predicate: (Int, T) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (predicate(index, elementAt(index))) {
+    forEachIndexed { index, element ->
+        if (predicate(index, element)) {
             return false
         }
     }
@@ -80,20 +86,26 @@
     add(element)
 }
 
-inline fun <T> IndexedSet<T>.removeAllIndexed(predicate: (Int, T) -> Boolean) {
-    for (index in lastIndex downTo 0) {
-        if (predicate(index, elementAt(index))) {
+inline fun <T> IndexedSet<T>.removeAllIndexed(predicate: (Int, T) -> Boolean): Boolean {
+    var isChanged = false
+    forEachReversedIndexed { index, element ->
+        if (predicate(index, element)) {
             removeAt(index)
+            isChanged = true
         }
     }
+    return isChanged
 }
 
-inline fun <T> IndexedSet<T>.retainAllIndexed(predicate: (Int, T) -> Boolean) {
-    for (index in lastIndex downTo 0) {
-        if (!predicate(index, elementAt(index))) {
+inline fun <T> IndexedSet<T>.retainAllIndexed(predicate: (Int, T) -> Boolean): Boolean {
+    var isChanged = false
+    forEachReversedIndexed { index, element ->
+        if (!predicate(index, element)) {
             removeAt(index)
+            isChanged = true
         }
     }
+    return isChanged
 }
 
 @Suppress("NOTHING_TO_INLINE")
diff --git a/services/permission/java/com/android/server/permission/access/collection/IntMap.kt b/services/permission/java/com/android/server/permission/access/collection/IntMap.kt
index 9051c66..e905567 100644
--- a/services/permission/java/com/android/server/permission/access/collection/IntMap.kt
+++ b/services/permission/java/com/android/server/permission/access/collection/IntMap.kt
@@ -21,8 +21,8 @@
 typealias IntMap<T> = SparseArray<T>
 
 inline fun <T> IntMap<T>.allIndexed(predicate: (Int, Int, T) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (!predicate(index, keyAt(index), valueAt(index))) {
+    forEachIndexed { index, key, value ->
+        if (!predicate(index, key, value)) {
             return false
         }
     }
@@ -30,8 +30,8 @@
 }
 
 inline fun <T> IntMap<T>.anyIndexed(predicate: (Int, Int, T) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (predicate(index, keyAt(index), valueAt(index))) {
+    forEachIndexed { index, key, value ->
+        if (predicate(index, key, value)) {
             return true
         }
     }
@@ -46,8 +46,8 @@
     }
 
 inline fun <T, R> IntMap<T>.firstNotNullOfOrNullIndexed(transform: (Int, Int, T) -> R): R? {
-    for (index in 0 until size) {
-        transform(index, keyAt(index), valueAt(index))?.let { return it }
+    forEachIndexed { index, key, value ->
+        transform(index, key, value)?.let { return it }
     }
     return null
 }
@@ -64,6 +64,12 @@
     }
 }
 
+inline fun <T> IntMap<T>.forEachReversedIndexed(action: (Int, Int, T) -> Unit) {
+    for (index in lastIndex downTo 0) {
+        action(index, keyAt(index), valueAt(index))
+    }
+}
+
 inline fun <T> IntMap<T>.forEachValueIndexed(action: (Int, T) -> Unit) {
     for (index in 0 until size) {
         action(index, valueAt(index))
@@ -91,8 +97,8 @@
 }
 
 inline fun <T> IntMap<T>.noneIndexed(predicate: (Int, Int, T) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (predicate(index, keyAt(index), valueAt(index))) {
+    forEachIndexed { index, key, value ->
+        if (predicate(index, key, value)) {
             return false
         }
     }
@@ -120,20 +126,38 @@
     }
 }
 
-inline fun <T> IntMap<T>.removeAllIndexed(predicate: (Int, Int, T) -> Boolean) {
-    for (index in lastIndex downTo 0) {
-        if (predicate(index, keyAt(index), valueAt(index))) {
-            removeAt(index)
-        }
+// SparseArray.removeReturnOld() is @hide, so a backup once we move to APIs.
+fun <T> IntMap<T>.removeReturnOld(key: Int): T? {
+    val index = indexOfKey(key)
+    return if (index >= 0) {
+        val oldValue = valueAt(index)
+        removeAt(index)
+        oldValue
+    } else {
+        null
     }
 }
 
-inline fun <T> IntMap<T>.retainAllIndexed(predicate: (Int, Int, T) -> Boolean) {
-    for (index in lastIndex downTo 0) {
-        if (!predicate(index, keyAt(index), valueAt(index))) {
+inline fun <T> IntMap<T>.removeAllIndexed(predicate: (Int, Int, T) -> Boolean): Boolean {
+    var isChanged = false
+    forEachReversedIndexed { index, key, value ->
+        if (predicate(index, key, value)) {
             removeAt(index)
+            isChanged = true
         }
     }
+    return isChanged
+}
+
+inline fun <T> IntMap<T>.retainAllIndexed(predicate: (Int, Int, T) -> Boolean): Boolean {
+    var isChanged = false
+    forEachReversedIndexed { index, key, value ->
+        if (!predicate(index, key, value)) {
+            removeAt(index)
+            isChanged = true
+        }
+    }
+    return isChanged
 }
 
 inline val <T> IntMap<T>.size: Int
diff --git a/services/permission/java/com/android/server/permission/access/collection/IntSet.kt b/services/permission/java/com/android/server/permission/access/collection/IntSet.kt
index d6dfe9d..4717251 100644
--- a/services/permission/java/com/android/server/permission/access/collection/IntSet.kt
+++ b/services/permission/java/com/android/server/permission/access/collection/IntSet.kt
@@ -51,9 +51,11 @@
     fun copy(): IntSet = IntSet(array.clone())
 }
 
+fun IntSet(values: IntArray): IntSet = IntSet().apply{ this += values }
+
 inline fun IntSet.allIndexed(predicate: (Int, Int) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (!predicate(index, elementAt(index))) {
+    forEachIndexed { index, element ->
+        if (!predicate(index, element)) {
             return false
         }
     }
@@ -61,8 +63,8 @@
 }
 
 inline fun IntSet.anyIndexed(predicate: (Int, Int) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (predicate(index, elementAt(index))) {
+    forEachIndexed { index, element ->
+        if (predicate(index, element)) {
             return true
         }
     }
@@ -75,6 +77,12 @@
     }
 }
 
+inline fun IntSet.forEachReversedIndexed(action: (Int, Int) -> Unit) {
+    for (index in lastIndex downTo 0) {
+        action(index, elementAt(index))
+    }
+}
+
 inline val IntSet.lastIndex: Int
     get() = size - 1
 
@@ -87,8 +95,8 @@
 }
 
 inline fun IntSet.noneIndexed(predicate: (Int, Int) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (predicate(index, elementAt(index))) {
+    forEachIndexed { index, element ->
+        if (predicate(index, element)) {
             return false
         }
     }
@@ -103,18 +111,32 @@
     add(element)
 }
 
-inline fun IntSet.removeAllIndexed(predicate: (Int, Int) -> Boolean) {
-    for (index in lastIndex downTo 0) {
-        if (predicate(index, elementAt(index))) {
-            removeAt(index)
-        }
-    }
+operator fun IntSet.plusAssign(set: IntSet) {
+    set.forEachIndexed { _, it -> this += it }
 }
 
-inline fun IntSet.retainAllIndexed(predicate: (Int, Int) -> Boolean) {
-    for (index in lastIndex downTo 0) {
-        if (!predicate(index, elementAt(index))) {
+operator fun IntSet.plusAssign(array: IntArray) {
+    array.forEach { this += it }
+}
+
+inline fun IntSet.removeAllIndexed(predicate: (Int, Int) -> Boolean): Boolean {
+    var isChanged = false
+    forEachReversedIndexed { index, element ->
+        if (predicate(index, element)) {
             removeAt(index)
+            isChanged = true
         }
     }
+    return isChanged
+}
+
+inline fun IntSet.retainAllIndexed(predicate: (Int, Int) -> Boolean): Boolean {
+    var isChanged = false
+    forEachReversedIndexed { index, element ->
+        if (!predicate(index, element)) {
+            removeAt(index)
+            isChanged = true
+        }
+    }
+    return isChanged
 }
diff --git a/services/permission/java/com/android/server/permission/access/collection/List.kt b/services/permission/java/com/android/server/permission/access/collection/List.kt
index dc28642..91f15bc 100644
--- a/services/permission/java/com/android/server/permission/access/collection/List.kt
+++ b/services/permission/java/com/android/server/permission/access/collection/List.kt
@@ -17,8 +17,8 @@
 package com.android.server.permission.access.collection
 
 inline fun <T> List<T>.allIndexed(predicate: (Int, T) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (!predicate(index, this[index])) {
+    forEachIndexed { index, element ->
+        if (!predicate(index, element)) {
             return false
         }
     }
@@ -26,8 +26,8 @@
 }
 
 inline fun <T> List<T>.anyIndexed(predicate: (Int, T) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (predicate(index, this[index])) {
+    forEachIndexed { index, element ->
+        if (predicate(index, element)) {
             return true
         }
     }
@@ -40,27 +40,39 @@
     }
 }
 
+inline fun <T> List<T>.forEachReversedIndexed(action: (Int, T) -> Unit) {
+    for (index in lastIndex downTo 0) {
+        action(index, this[index])
+    }
+}
+
 inline fun <T> List<T>.noneIndexed(predicate: (Int, T) -> Boolean): Boolean {
-    for (index in 0 until size) {
-        if (predicate(index, this[index])) {
+    forEachIndexed { index, element ->
+        if (predicate(index, element)) {
             return false
         }
     }
     return true
 }
 
-inline fun <T> MutableList<T>.removeAllIndexed(predicate: (Int, T) -> Boolean) {
-    for (index in lastIndex downTo 0) {
-        if (predicate(index, this[index])) {
+inline fun <T> MutableList<T>.removeAllIndexed(predicate: (Int, T) -> Boolean): Boolean {
+    var isChanged = false
+    forEachReversedIndexed { index, element ->
+        if (predicate(index, element)) {
             removeAt(index)
+            isChanged = true
         }
     }
+    return isChanged
 }
 
-inline fun <T> MutableList<T>.retainAllIndexed(predicate: (Int, T) -> Boolean) {
-    for (index in lastIndex downTo 0) {
-        if (!predicate(index, this[index])) {
+inline fun <T> MutableList<T>.retainAllIndexed(predicate: (Int, T) -> Boolean): Boolean {
+    var isChanged = false
+    forEachReversedIndexed { index, element ->
+        if (!predicate(index, element)) {
             removeAt(index)
+            isChanged = true
         }
     }
+    return isChanged
 }
diff --git a/services/permission/java/com/android/server/permission/access/data/Package.kt b/services/permission/java/com/android/server/permission/access/data/Package.kt
deleted file mode 100644
index d6f98ab..0000000
--- a/services/permission/java/com/android/server/permission/access/data/Package.kt
+++ /dev/null
@@ -1,43 +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.server.permission.access.data
-
-import com.android.server.permission.access.external.AndroidPackage
-
-class Package(
-    private val androidPackage: AndroidPackage
-) {
-    val name: String
-        get() = androidPackage.packageName
-
-    val adoptPermissions: List<String>
-        get() = androidPackage.adoptPermissions
-
-    val appId: Int
-        get() = androidPackage.appId
-
-    val requestedPermissions: List<String>
-        get() = androidPackage.requestedPermissions
-
-    override fun equals(other: Any?): Boolean {
-        throw NotImplementedError()
-    }
-
-    override fun hashCode(): Int {
-        throw NotImplementedError()
-    }
-}
diff --git a/services/permission/java/com/android/server/permission/access/external/CompatibilityPermissionInfo.kt b/services/permission/java/com/android/server/permission/access/external/CompatibilityPermissionInfo.kt
deleted file mode 100644
index aadd8ba..0000000
--- a/services/permission/java/com/android/server/permission/access/external/CompatibilityPermissionInfo.kt
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.server.permission.access.external
-
-class CompatibilityPermissionInfo {
-    companion object {
-        val COMPAT_PERMS = arrayOf(CompatibilityPermissionInfo())
-    }
-
-    val name: String
-        get() = throw NotImplementedError()
-
-    val sdkVersion: Int
-        get() = throw NotImplementedError()
-}
diff --git a/services/permission/java/com/android/server/permission/access/external/KnownPackages.kt b/services/permission/java/com/android/server/permission/access/external/KnownPackages.kt
deleted file mode 100644
index 1239450..0000000
--- a/services/permission/java/com/android/server/permission/access/external/KnownPackages.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.server.permission.access.external
-
-class KnownPackages {
-    companion object {
-        const val PACKAGE_SYSTEM = 0
-        const val PACKAGE_SETUP_WIZARD = 1
-        const val PACKAGE_INSTALLER = 2
-        const val PACKAGE_VERIFIER = 4
-        const val PACKAGE_SYSTEM_TEXT_CLASSIFIER = 6
-        const val PACKAGE_PERMISSION_CONTROLLER = 7
-        const val PACKAGE_CONFIGURATOR = 10
-        const val PACKAGE_INCIDENT_REPORT_APPROVER = 11
-        const val PACKAGE_APP_PREDICTOR = 12
-        const val PACKAGE_COMPANION = 15
-        const val PACKAGE_RETAIL_DEMO = 16
-        const val PACKAGE_RECENTS = 17
-    }
-}
diff --git a/services/permission/java/com/android/server/permission/access/external/PackageInfoUtils.kt b/services/permission/java/com/android/server/permission/access/external/PackageInfoUtils.kt
deleted file mode 100644
index 24b28bd..0000000
--- a/services/permission/java/com/android/server/permission/access/external/PackageInfoUtils.kt
+++ /dev/null
@@ -1,33 +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.server.permission.access.external
-
-import android.content.pm.PermissionGroupInfo
-import android.content.pm.PermissionInfo
-
-object PackageInfoUtils {
-    fun generatePermissionInfo(parsedPermission: ParsedPermission, flags: Long): PermissionInfo {
-        throw NotImplementedError()
-    }
-
-    fun generatePermissionGroupInfo(
-        parsedPermissionGroup: ParsedPermissionGroup,
-        flags: Long
-    ): PermissionGroupInfo {
-        throw NotImplementedError()
-    }
-}
diff --git a/services/permission/java/com/android/server/permission/access/external/PackageState.kt b/services/permission/java/com/android/server/permission/access/external/PackageState.kt
deleted file mode 100644
index b81d794..0000000
--- a/services/permission/java/com/android/server/permission/access/external/PackageState.kt
+++ /dev/null
@@ -1,65 +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.server.permission.access.external
-
-import android.util.SparseArray
-
-interface PackageState {
-    val androidPackage: AndroidPackage?
-    val appId: Int
-    val isSystem: Boolean
-    val isUpdatedSystemApp: Boolean
-    val packageName: String
-    val userStates: SparseArray<PackageUserState>
-    val hasSharedUser: Boolean
-    val sharedUserAppId: Int
-    val signingDetails: SigningDetails
-}
-
-interface AndroidPackage {
-    val packageName: String
-    val apexModuleName: String?
-    val appId: Int
-    val isPrivileged: Boolean
-    val isOem: Boolean
-    val isVendor: Boolean
-    val isProduct: Boolean
-    val isSystemExt: Boolean
-    val targetSdkVersion: Int
-    val adoptPermissions: List<String>
-    val permissions: List<ParsedPermission>
-    val permissionGroups: List<ParsedPermissionGroup>
-    val requestedPermissions: List<String>
-    val implicitPermissions: List<String>
-}
-
-interface ParsedPermission {
-    val name: String
-    val isTree: Boolean
-    val packageName: String
-    val isSignature: Boolean
-    val protectionLevel: Int
-}
-
-interface ParsedPermissionGroup {
-    val name: String
-    val packageName: String
-}
-
-interface PackageUserState {
-    val isInstantApp: Boolean
-}
diff --git a/services/permission/java/com/android/server/permission/access/external/SigningDetails.kt b/services/permission/java/com/android/server/permission/access/external/SigningDetails.kt
deleted file mode 100644
index 25917f9..0000000
--- a/services/permission/java/com/android/server/permission/access/external/SigningDetails.kt
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.server.permission.access.external
-
-object SigningDetails {
-    fun hasCommonSignerWithCapability(otherDetails: SigningDetails, flags: Int): Boolean {
-        throw NotImplementedError()
-    }
-
-    fun hasAncestorOrSelf(oldDetails: SigningDetails): Boolean {
-        throw NotImplementedError()
-    }
-
-    fun checkCapability(oldDetails: SigningDetails, flags: Int): Boolean {
-        throw NotImplementedError()
-    }
-
-    fun hasAncestorOrSelfWithDigest(certDigests: Set<String>): Boolean {
-        throw NotImplementedError()
-    }
-
-    class CertCapabilities {
-        companion object {
-            /** grant SIGNATURE permissions to pkgs with this cert  */
-            var PERMISSION = 4
-        }
-    }
-}
diff --git a/services/permission/java/com/android/server/permission/access/external/UserHandle.kt b/services/permission/java/com/android/server/permission/access/external/UserHandle.kt
deleted file mode 100644
index e1072a7..0000000
--- a/services/permission/java/com/android/server/permission/access/external/UserHandle.kt
+++ /dev/null
@@ -1,31 +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.server.permission.access.external
-
-interface UserHandle {
-    companion object {
-        fun getAppId(uid: Int): Int {
-            throw NotImplementedError()
-        }
-    }
-}
-
-object UserHandleCompat {
-    fun getUserId(uid: Int): Int {
-        throw NotImplementedError()
-    }
-}
diff --git a/services/permission/java/com/android/server/permission/access/data/Permission.kt b/services/permission/java/com/android/server/permission/access/permission/Permission.kt
similarity index 98%
rename from services/permission/java/com/android/server/permission/access/data/Permission.kt
rename to services/permission/java/com/android/server/permission/access/permission/Permission.kt
index 877f23b..efa5bf3 100644
--- a/services/permission/java/com/android/server/permission/access/data/Permission.kt
+++ b/services/permission/java/com/android/server/permission/access/permission/Permission.kt
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.server.permission.access.data
+package com.android.server.permission.access.permission
 
 import android.content.pm.PermissionInfo
 import com.android.server.permission.access.util.hasBits
diff --git a/services/permission/java/com/android/server/permission/access/permission/PermissionFlags.kt b/services/permission/java/com/android/server/permission/access/permission/PermissionFlags.kt
index bb1a86c..6b2b1856 100644
--- a/services/permission/java/com/android/server/permission/access/permission/PermissionFlags.kt
+++ b/services/permission/java/com/android/server/permission/access/permission/PermissionFlags.kt
@@ -16,17 +16,468 @@
 
 package com.android.server.permission.access.permission
 
-object PermissionFlags {
-    const val INSTALL_GRANTED = 1 shl 0
-    const val INSTALL_REVOKED = 1 shl 1
-    const val PROTECTION_GRANTED = 1 shl 2
-    const val ROLE_GRANTED = 1 shl 3
-    // For permissions that are granted in other ways,
-    // ex: via an API or implicit permissions that inherit from granted install permissions
-    const val OTHER_GRANTED = 1 shl 4
-    // For the permissions that are implicit for the package
-    const val IMPLICIT = 1 shl 5
+import android.app.AppOpsManager
+import android.app.admin.DevicePolicyManager
+import android.content.pm.PackageManager
+import android.os.Build
+import android.permission.PermissionManager
+import com.android.server.permission.access.util.andInv
+import com.android.server.permission.access.util.hasAnyBit
+import com.android.server.permission.access.util.hasBits
 
-    const val MASK_GRANTED = INSTALL_GRANTED or PROTECTION_GRANTED or OTHER_GRANTED or ROLE_GRANTED
-    const val MASK_RUNTIME = OTHER_GRANTED or IMPLICIT
+/**
+ * A set of internal permission flags that's better than the set of `FLAG_PERMISSION_*` constants on
+ * [PackageManager].
+ *
+ * The old binary permission state is now tracked by multiple `*_GRANTED` and `*_REVOKED` flags, so
+ * that:
+ *
+ * - With [INSTALL_GRANTED] and [INSTALL_REVOKED], we can now get rid of the old per-package
+ *   `areInstallPermissionsFixed` attribute and correctly track it per-permission, finally fixing
+ *   edge cases during module rollbacks.
+ *
+ * - With [LEGACY_GRANTED] and [IMPLICIT_GRANTED], we can now ensure that legacy permissions and
+ *   implicit permissions split from non-runtime permissions are never revoked, without checking
+ *   split permissions and package state everywhere slowly and in slightly different ways.
+ *
+ * - With [RESTRICTION_REVOKED], we can now get rid of the error-prone logic about revoking and
+ *   potentially re-granting permissions upon restriction state changes.
+ *
+ * Permission grants due to protection level are now tracked by [PROTECTION_GRANTED], and permission
+ * grants due to [PackageManager.grantRuntimePermission] are now tracked by [RUNTIME_GRANTED].
+ *
+ * The [PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED] and
+ * [PackageManager.FLAG_PERMISSION_REVOKE_WHEN_REQUESTED] flags are now unified into [IMPLICIT], and
+ * they can be differentiated by the presence of [LEGACY_GRANTED].
+ *
+ * The rest of the permission flags have a 1:1 mapping to the old `FLAG_PERMISSION_*` constants, and
+ * don't have any effect on the binary permission state.
+ */
+object PermissionFlags {
+    /**
+     * Permission flag for a normal permission that is granted at package installation.
+     */
+    const val INSTALL_GRANTED = 1 shl 0
+
+    /**
+     * Permission flag for a normal permission that is revoked at package installation.
+     *
+     * Normally packages that have already been installed cannot be granted new normal permissions
+     * until its next installation (update), so this flag helps track that the normal permission was
+     * revoked upon its most recent installation.
+     */
+    const val INSTALL_REVOKED = 1 shl 1
+
+    /**
+     * Permission flag for a signature or internal permission that is granted based on the
+     * permission's protection level, including its protection and protection flags.
+     *
+     * For example, this flag may be set when the permission is a signature permission and the
+     * package is having a compatible signing certificate with the package defining the permission,
+     * or when the permission is a privileged permission and the package is a privileged app with
+     * its permission in the
+     * [privileged permission allowlist](https://source.android.com/docs/core/permissions/perms-allowlist).
+     */
+    const val PROTECTION_GRANTED = 1 shl 2
+
+    /**
+     * Permission flag for a role or runtime permission that is or was granted by a role.
+     *
+     * @see PackageManager.FLAG_PERMISSION_GRANTED_BY_ROLE
+     */
+    const val ROLE = 1 shl 3
+
+    /**
+     * Permission flag for a development, role or runtime permission that is granted via
+     * [PackageManager.grantRuntimePermission].
+     */
+    const val RUNTIME_GRANTED = 1 shl 4
+
+    /**
+     * Permission flag for a runtime permission whose state is set by the user.
+     *
+     * For example, this flag may be set when the permission is allowed by the user in the
+     * request permission dialog, or managed in the permission settings.
+     *
+     * @see PackageManager.FLAG_PERMISSION_USER_SET
+     */
+    const val USER_SET = 1 shl 5
+
+    /**
+     * Permission flag for a runtime permission whose state is (revoked and) fixed by the user.
+     *
+     * For example, this flag may be set when the permission is denied twice by the user in the
+     * request permission dialog.
+     *
+     * @see PackageManager.FLAG_PERMISSION_USER_FIXED
+     */
+    const val USER_FIXED = 1 shl 6
+
+    /**
+     * Permission flag for a runtime permission whose state is set and fixed by the device policy
+     * via [DevicePolicyManager.setPermissionGrantState].
+     *
+     * @see PackageManager.FLAG_PERMISSION_POLICY_FIXED
+     */
+    const val POLICY_FIXED = 1 shl 7
+
+    /**
+     * Permission flag for a runtime permission that is (pregranted and) fixed by the system.
+     *
+     * For example, this flag may be set in
+     * [com.android.server.pm.permission.DefaultPermissionGrantPolicy].
+     *
+     * @see PackageManager.FLAG_PERMISSION_SYSTEM_FIXED
+     */
+    const val SYSTEM_FIXED = 1 shl 8
+
+    /**
+     * Permission flag for a runtime permission that is or was pregranted by the system.
+     *
+     * For example, this flag may be set in
+     * [com.android.server.pm.permission.DefaultPermissionGrantPolicy].
+     *
+     * @see PackageManager.FLAG_PERMISSION_SYSTEM_FIXED
+     */
+    const val PREGRANT = 1 shl 9
+
+    /**
+     * Permission flag for a runtime permission that is granted because the package targets a legacy
+     * SDK version before [Build.VERSION_CODES.M] and doesn't support runtime permissions.
+     *
+     * As long as this flag is set, the permission should always be considered granted, although
+     * [APP_OP_REVOKED] may cause the app op for the runtime permission to be revoked. Once the
+     * package targets a higher SDK version so that it started supporting runtime permissions, this
+     * flag should be removed and the remaining flags should take effect.
+     *
+     * @see PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED
+     * @see PackageManager.FLAG_PERMISSION_REVOKED_COMPAT
+     */
+    const val LEGACY_GRANTED = 1 shl 10
+
+    /**
+     * Permission flag for a runtime permission that is granted because the package targets a lower
+     * SDK version and the permission is implicit to it as a
+     * [split permission][PermissionManager.SplitPermissionInfo] from other non-runtime permissions.
+     *
+     * As long as this flag is set, the permission should always be considered granted, although
+     * [APP_OP_REVOKED] may cause the app op for the runtime permission to be revoked. Once the
+     * package targets a higher SDK version so that the permission is no longer implicit to it, this
+     * flag should be removed and the remaining flags should take effect.
+     *
+     * @see PackageManager.FLAG_PERMISSION_REVOKE_WHEN_REQUESTED
+     * @see PackageManager.FLAG_PERMISSION_REVOKED_COMPAT
+     */
+    const val IMPLICIT_GRANTED = 1 shl 11
+
+    /**
+     * Permission flag for a runtime permission that is granted because the package targets a legacy
+     * SDK version before [Build.VERSION_CODES.M] and doesn't support runtime permissions, so that
+     * it needs to be reviewed by the user; or granted because the package targets a lower SDK
+     * version and the permission is implicit to it as a
+     * [split permission][PermissionManager.SplitPermissionInfo] from other non-runtime permissions,
+     * so that it needs to be revoked when it's no longer implicit.
+     *
+     * @see PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED
+     * @see PackageManager.FLAG_PERMISSION_REVOKE_WHEN_REQUESTED
+     */
+    const val IMPLICIT = 1 shl 12
+
+    /**
+     * Permission flag for a runtime permission that is user-sensitive when it's granted.
+     *
+     * This flag is informational and managed by PermissionController.
+     *
+     * @see PackageManager.FLAG_PERMISSION_USER_SENSITIVE_WHEN_GRANTED
+     */
+    const val USER_SENSITIVE_WHEN_GRANTED = 1 shl 13
+
+    /**
+     * Permission flag for a runtime permission that is user-sensitive when it's revoked.
+     *
+     * This flag is informational and managed by PermissionController.
+     *
+     * @see PackageManager.FLAG_PERMISSION_USER_SENSITIVE_WHEN_DENIED
+     */
+    const val USER_SENSITIVE_WHEN_REVOKED = 1 shl 14
+
+    /**
+     * Permission flag for a restricted runtime permission that is exempt by the package's
+     * installer.
+     *
+     * For example, this flag may be set when the installer applied the exemption as part of the
+     * [session parameters](https://developer.android.com/reference/android/content/pm/PackageInstaller.SessionParams#setWhitelistedRestrictedPermissions(java.util.Set%3Cjava.lang.String%3E)).
+     *
+     * The permission will be restricted when none of the exempt flags is set.
+     *
+     * @see PackageManager.FLAG_PERMISSION_RESTRICTION_INSTALLER_EXEMPT
+     */
+    const val INSTALLER_EXEMPT = 1 shl 15
+
+    /**
+     * Permission flag for a restricted runtime permission that is exempt by the system.
+     *
+     * For example, this flag may be set when the package is a system app.
+     *
+     * The permission will be restricted when none of the exempt flags is set.
+     *
+     * @see PackageManager.FLAG_PERMISSION_RESTRICTION_SYSTEM_EXEMPT
+     */
+    const val SYSTEM_EXEMPT = 1 shl 16
+
+    /**
+     * Permission flag for a restricted runtime permission that is exempt due to system upgrade.
+     *
+     * For example, this flag may be set when the package was installed before the system was
+     * upgraded to [Build.VERSION_CODES.Q], when restricted permissions were introduced.
+     *
+     * The permission will be restricted when none of the exempt flags is set.
+     *
+     * @see PackageManager.FLAG_PERMISSION_RESTRICTION_UPGRADE_EXEMPT
+     */
+    const val UPGRADE_EXEMPT = 1 shl 17
+
+    /**
+     * Permission flag for a restricted runtime permission that is revoked due to being hard
+     * restricted.
+     *
+     * @see PackageManager.FLAG_PERMISSION_APPLY_RESTRICTION
+     */
+    const val RESTRICTION_REVOKED = 1 shl 18
+
+    /**
+     * Permission flag for a restricted runtime permission that is soft restricted.
+     *
+     * @see PackageManager.FLAG_PERMISSION_APPLY_RESTRICTION
+     */
+    const val SOFT_RESTRICTED = 1 shl 19
+
+    /**
+     * Permission flag for a runtime permission whose app op is revoked.
+     *
+     * For example, this flag may be set when the runtime permission is legacy or implicit but still
+     * "revoked" by the user in permission settings, or when the app op mode for the runtime
+     * permission is set to revoked via [AppOpsManager.setUidMode].
+     *
+     * @see PackageManager.FLAG_PERMISSION_REVOKED_COMPAT
+     */
+    const val APP_OP_REVOKED = 1 shl 20
+
+    /**
+     * Permission flag for a runtime permission that is granted as one-time.
+     *
+     * For example, this flag may be set when the user selected "Only this time" in the request
+     * permission dialog.
+     *
+     * This flag, along with other user decisions when it is set, should never be persisted, and
+     * should be removed once the permission is revoked.
+     *
+     * @see PackageManager.FLAG_PERMISSION_ONE_TIME
+     */
+    const val ONE_TIME = 1 shl 21
+
+    /**
+     * Permission flag for a runtime permission that was revoked due to app hibernation.
+     *
+     * This flag is informational and added by PermissionController, and should be removed once the
+     * permission is granted again.
+     *
+     * @see PackageManager.FLAG_PERMISSION_AUTO_REVOKED
+     */
+    const val HIBERNATION = 1 shl 22
+
+    /**
+     * Permission flag for a runtime permission that is selected by the user.
+     *
+     * For example, this flag may be set when one of the coarse/fine location accuracies is
+     * selected by the user.
+     *
+     * This flag is informational and managed by PermissionController.
+     *
+     * @see PackageManager.FLAG_PERMISSION_SELECTED_LOCATION_ACCURACY
+     */
+    const val USER_SELECTED = 1 shl 23
+
+    /**
+     * Mask for all permission flags.
+     */
+    const val MASK_ALL = 0.inv()
+
+    /**
+     * Mask for all permission flags that may be applied to a runtime permission.
+     */
+    const val MASK_RUNTIME = ROLE or RUNTIME_GRANTED or USER_SET or USER_FIXED or POLICY_FIXED or
+        SYSTEM_FIXED or PREGRANT or LEGACY_GRANTED or IMPLICIT_GRANTED or IMPLICIT or
+        USER_SENSITIVE_WHEN_GRANTED or USER_SENSITIVE_WHEN_REVOKED or INSTALLER_EXEMPT or
+        SYSTEM_EXEMPT or UPGRADE_EXEMPT or RESTRICTION_REVOKED or SOFT_RESTRICTED or
+        APP_OP_REVOKED or ONE_TIME or HIBERNATION or USER_SELECTED
+
+    /**
+     * Mask for all API permission flags about permission restriction.
+     */
+    private const val API_MASK_RESTRICTION =
+        PackageManager.FLAG_PERMISSION_RESTRICTION_INSTALLER_EXEMPT or
+            PackageManager.FLAG_PERMISSION_RESTRICTION_SYSTEM_EXEMPT or
+            PackageManager.FLAG_PERMISSION_RESTRICTION_UPGRADE_EXEMPT or
+            PackageManager.FLAG_PERMISSION_APPLY_RESTRICTION
+
+    /**
+     * Mask for all permission flags about permission restriction.
+     */
+    private const val MASK_RESTRICTION = INSTALLER_EXEMPT or SYSTEM_EXEMPT or
+        UPGRADE_EXEMPT or RESTRICTION_REVOKED or SOFT_RESTRICTED
+
+    fun isPermissionGranted(policyFlags: Int): Boolean {
+        if (policyFlags.hasBits(INSTALL_GRANTED)) {
+            return true
+        }
+        if (policyFlags.hasBits(INSTALL_REVOKED)) {
+            return false
+        }
+        if (policyFlags.hasBits(PROTECTION_GRANTED)) {
+            return true
+        }
+        if (policyFlags.hasBits(LEGACY_GRANTED) || policyFlags.hasBits(IMPLICIT_GRANTED)) {
+            return true
+        }
+        if (policyFlags.hasBits(RESTRICTION_REVOKED)) {
+            return false
+        }
+        return policyFlags.hasBits(RUNTIME_GRANTED)
+    }
+
+    fun isAppOpGranted(policyFlags: Int): Boolean =
+        isPermissionGranted(policyFlags) && !policyFlags.hasBits(APP_OP_REVOKED)
+
+    fun isReviewRequired(policyFlags: Int): Boolean =
+        policyFlags.hasBits(LEGACY_GRANTED) && policyFlags.hasBits(IMPLICIT)
+
+    fun toApiFlags(policyFlags: Int): Int {
+        var apiFlags = 0
+        if (policyFlags.hasBits(USER_SET)) {
+            apiFlags = apiFlags or PackageManager.FLAG_PERMISSION_USER_SET
+        }
+        if (policyFlags.hasBits(USER_FIXED)) {
+            apiFlags = apiFlags or PackageManager.FLAG_PERMISSION_USER_FIXED
+        }
+        if (policyFlags.hasBits(POLICY_FIXED)) {
+            apiFlags = apiFlags or PackageManager.FLAG_PERMISSION_POLICY_FIXED
+        }
+        if (policyFlags.hasBits(SYSTEM_FIXED)) {
+            apiFlags = apiFlags or PackageManager.FLAG_PERMISSION_SYSTEM_FIXED
+        }
+        if (policyFlags.hasBits(PREGRANT)) {
+            apiFlags = apiFlags or PackageManager.FLAG_PERMISSION_GRANTED_BY_DEFAULT
+        }
+        if (policyFlags.hasBits(IMPLICIT)) {
+            apiFlags = apiFlags or if (policyFlags.hasBits(LEGACY_GRANTED)) {
+                PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED
+            } else {
+                PackageManager.FLAG_PERMISSION_REVOKE_WHEN_REQUESTED
+            }
+        }
+        if (policyFlags.hasBits(USER_SENSITIVE_WHEN_GRANTED)) {
+            apiFlags = apiFlags or PackageManager.FLAG_PERMISSION_USER_SENSITIVE_WHEN_GRANTED
+        }
+        if (policyFlags.hasBits(USER_SENSITIVE_WHEN_REVOKED)) {
+            apiFlags = apiFlags or PackageManager.FLAG_PERMISSION_USER_SENSITIVE_WHEN_DENIED
+        }
+        if (policyFlags.hasBits(INSTALLER_EXEMPT)) {
+            apiFlags = apiFlags or PackageManager.FLAG_PERMISSION_RESTRICTION_INSTALLER_EXEMPT
+        }
+        if (policyFlags.hasBits(SYSTEM_EXEMPT)) {
+            apiFlags = apiFlags or PackageManager.FLAG_PERMISSION_RESTRICTION_SYSTEM_EXEMPT
+        }
+        if (policyFlags.hasBits(UPGRADE_EXEMPT)) {
+            apiFlags = apiFlags or PackageManager.FLAG_PERMISSION_RESTRICTION_UPGRADE_EXEMPT
+        }
+        if (policyFlags.hasBits(RESTRICTION_REVOKED) || policyFlags.hasBits(SOFT_RESTRICTED)) {
+            apiFlags = apiFlags or PackageManager.FLAG_PERMISSION_APPLY_RESTRICTION
+        }
+        if (policyFlags.hasBits(ROLE)) {
+            apiFlags = apiFlags or PackageManager.FLAG_PERMISSION_GRANTED_BY_ROLE
+        }
+        if (policyFlags.hasBits(APP_OP_REVOKED)) {
+            apiFlags = apiFlags or PackageManager.FLAG_PERMISSION_REVOKED_COMPAT
+        }
+        if (policyFlags.hasBits(ONE_TIME)) {
+            apiFlags = apiFlags or PackageManager.FLAG_PERMISSION_ONE_TIME
+        }
+        if (policyFlags.hasBits(HIBERNATION)) {
+            apiFlags = apiFlags or PackageManager.FLAG_PERMISSION_AUTO_REVOKED
+        }
+        if (policyFlags.hasBits(USER_SELECTED)) {
+            apiFlags = apiFlags or PackageManager.FLAG_PERMISSION_SELECTED_LOCATION_ACCURACY
+        }
+        return apiFlags
+    }
+
+    fun setRuntimePermissionGranted(policyFlags: Int, isGranted: Boolean): Int =
+        if (isGranted) policyFlags or RUNTIME_GRANTED else policyFlags andInv RUNTIME_GRANTED
+
+    fun updatePolicyFlags(policyFlags: Int, apiFlagMask: Int, apiFlagValues: Int): Int {
+        check(!apiFlagMask.hasAnyBit(API_MASK_RESTRICTION)) {
+            "Permission flags about permission restriction can only be directly mutated by the" +
+                " policy"
+        }
+        val oldApiFlags = toApiFlags(policyFlags)
+        val newApiFlags = (oldApiFlags andInv apiFlagMask) or (apiFlagValues and apiFlagMask)
+        return toPolicyFlags(policyFlags, newApiFlags)
+    }
+
+    private fun toPolicyFlags(oldPolicyFlags: Int, apiFlags: Int): Int {
+        var policyFlags = 0
+        policyFlags = policyFlags or (oldPolicyFlags and INSTALL_GRANTED)
+        policyFlags = policyFlags or (oldPolicyFlags and INSTALL_REVOKED)
+        policyFlags = policyFlags or (oldPolicyFlags and PROTECTION_GRANTED)
+        if (apiFlags.hasBits(PackageManager.FLAG_PERMISSION_GRANTED_BY_ROLE)) {
+            policyFlags = policyFlags or ROLE
+        }
+        policyFlags = policyFlags or (oldPolicyFlags and RUNTIME_GRANTED)
+        if (apiFlags.hasBits(PackageManager.FLAG_PERMISSION_USER_SET)) {
+            policyFlags = policyFlags or USER_SET
+        }
+        if (apiFlags.hasBits(PackageManager.FLAG_PERMISSION_USER_FIXED)) {
+            policyFlags = policyFlags or USER_FIXED
+        }
+        if (apiFlags.hasBits(PackageManager.FLAG_PERMISSION_POLICY_FIXED)) {
+            policyFlags = policyFlags or POLICY_FIXED
+        }
+        if (apiFlags.hasBits(PackageManager.FLAG_PERMISSION_SYSTEM_FIXED)) {
+            policyFlags = policyFlags or SYSTEM_FIXED
+        }
+        if (apiFlags.hasBits(PackageManager.FLAG_PERMISSION_GRANTED_BY_DEFAULT)) {
+            policyFlags = policyFlags or PREGRANT
+        }
+        policyFlags = policyFlags or (oldPolicyFlags and LEGACY_GRANTED)
+        policyFlags = policyFlags or (oldPolicyFlags and IMPLICIT_GRANTED)
+        if (apiFlags.hasBits(PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED) ||
+            apiFlags.hasBits(PackageManager.FLAG_PERMISSION_REVOKE_WHEN_REQUESTED)) {
+            policyFlags = policyFlags or IMPLICIT
+        }
+        if (apiFlags.hasBits(PackageManager.FLAG_PERMISSION_USER_SENSITIVE_WHEN_GRANTED)) {
+            policyFlags = policyFlags or USER_SENSITIVE_WHEN_GRANTED
+        }
+        if (apiFlags.hasBits(PackageManager.FLAG_PERMISSION_USER_SENSITIVE_WHEN_DENIED)) {
+            policyFlags = policyFlags or USER_SENSITIVE_WHEN_REVOKED
+        }
+        // FLAG_PERMISSION_APPLY_RESTRICTION can be either REVOKED_BY_RESTRICTION when the
+        // permission is hard restricted, or SOFT_RESTRICTED when the permission is soft restricted.
+        // However since we should never allow indirect mutation of restriction state, we can just
+        // get the flags about restriction from the old policy flags.
+        policyFlags = policyFlags or (oldPolicyFlags and MASK_RESTRICTION)
+        if (apiFlags.hasBits(PackageManager.FLAG_PERMISSION_REVOKED_COMPAT)) {
+            policyFlags = policyFlags or APP_OP_REVOKED
+        }
+        if (apiFlags.hasBits(PackageManager.FLAG_PERMISSION_ONE_TIME)) {
+            policyFlags = policyFlags or ONE_TIME
+        }
+        if (apiFlags.hasBits(PackageManager.FLAG_PERMISSION_AUTO_REVOKED)) {
+            policyFlags = policyFlags or HIBERNATION
+        }
+        if (apiFlags.hasBits(PackageManager.FLAG_PERMISSION_SELECTED_LOCATION_ACCURACY)) {
+            policyFlags = policyFlags or USER_SELECTED
+        }
+        return policyFlags
+    }
 }
diff --git a/services/permission/java/com/android/server/permission/access/permission/ModernPermissionManagerServiceImpl.kt b/services/permission/java/com/android/server/permission/access/permission/PermissionService.kt
similarity index 81%
rename from services/permission/java/com/android/server/permission/access/permission/ModernPermissionManagerServiceImpl.kt
rename to services/permission/java/com/android/server/permission/access/permission/PermissionService.kt
index cc51866..8201736 100644
--- a/services/permission/java/com/android/server/permission/access/permission/ModernPermissionManagerServiceImpl.kt
+++ b/services/permission/java/com/android/server/permission/access/permission/PermissionService.kt
@@ -33,8 +33,9 @@
 import com.android.server.permission.access.AccessCheckingService
 import com.android.server.permission.access.PermissionUri
 import com.android.server.permission.access.UidUri
-import com.android.server.permission.access.data.Permission
+import com.android.server.permission.access.collection.* // ktlint-disable no-wildcard-imports
 import com.android.server.permission.access.util.hasBits
+import com.android.server.pm.UserManagerService
 import com.android.server.pm.permission.LegacyPermission
 import com.android.server.pm.permission.LegacyPermissionSettings
 import com.android.server.pm.permission.LegacyPermissionState
@@ -46,17 +47,24 @@
 /**
  * Modern implementation of [PermissionManagerServiceInterface].
  */
-class ModernPermissionManagerServiceImpl(
+class PermissionService(
     private val service: AccessCheckingService
 ) : PermissionManagerServiceInterface {
     private val policy =
         service.getSchemePolicy(UidUri.SCHEME, PermissionUri.SCHEME) as UidPermissionPolicy
 
-    private val packageManagerInternal =
-        LocalServices.getService(PackageManagerInternal::class.java)
+    private lateinit var packageManagerInternal: PackageManagerInternal
+    private lateinit var packageManagerLocal: PackageManagerLocal
+    private lateinit var userManagerService: UserManagerService
 
-    private val packageManagerLocal =
-        LocalManagerRegistry.getManagerOrThrow(PackageManagerLocal::class.java)
+    private val mountedStorageVolumes = IndexedSet<String?>()
+
+    fun initialize() {
+        packageManagerInternal = LocalServices.getService(PackageManagerInternal::class.java)
+        packageManagerLocal =
+            LocalManagerRegistry.getManagerOrThrow(PackageManagerLocal::class.java)
+        userManagerService = UserManagerService.getInstance()
+    }
 
     override fun getAllPermissionGroups(flags: Int): List<PermissionGroupInfo> {
         TODO("Not yet implemented")
@@ -224,7 +232,12 @@
     }
 
     override fun getPermissionFlags(packageName: String, permissionName: String, userId: Int): Int {
-        TODO("Not yet implemented")
+        // TODO: Implement permission checks.
+        val appId = 0
+        val flags = service.getState {
+            with(policy) { getPermissionFlags(appId, userId, permissionName) }
+        }
+        return PermissionFlags.toApiFlags(flags)
     }
 
     override fun isPermissionRevokedByPolicy(
@@ -236,7 +249,12 @@
     }
 
     override fun isPermissionsReviewRequired(packageName: String, userId: Int): Boolean {
-        TODO("Not yet implemented")
+        val packageState = packageManagerLocal.withUnfilteredSnapshot()
+            .use { it.packageStates[packageName] } ?: return false
+        val permissionFlags = service.getState {
+            with(policy) { getUidPermissionFlags(packageState.appId, userId) }
+        } ?: return false
+        return permissionFlags.anyIndexed { _, _, flags -> PermissionFlags.isReviewRequired(flags) }
     }
 
     override fun shouldShowRequestPermissionRationale(
@@ -351,6 +369,8 @@
     }
 
     override fun readLegacyPermissionsTEMP(legacyPermissionSettings: LegacyPermissionSettings) {
+        // Package settings has been read when this method is called.
+        service.initialize()
         TODO("Not yet implemented")
     }
 
@@ -375,15 +395,18 @@
     }
 
     override fun onUserCreated(userId: Int) {
-        TODO("Not yet implemented")
+        service.onUserAdded(userId)
     }
 
     override fun onUserRemoved(userId: Int) {
-        TODO("Not yet implemented")
+        service.onUserRemoved(userId)
     }
 
     override fun onStorageVolumeMounted(volumeUuid: String, fingerprintChanged: Boolean) {
-        TODO("Not yet implemented")
+        service.onStorageVolumeMounted(volumeUuid, fingerprintChanged)
+        synchronized(mountedStorageVolumes) {
+            mountedStorageVolumes += volumeUuid
+        }
     }
 
     override fun onPackageAdded(
@@ -391,7 +414,18 @@
         isInstantApp: Boolean,
         oldPackage: AndroidPackage?
     ) {
-        TODO("Not yet implemented")
+        synchronized(mountedStorageVolumes) {
+            if (androidPackage.volumeUuid !in mountedStorageVolumes) {
+                // Wait for the storage volume to be mounted and batch the state mutation there.
+                return
+            }
+        }
+        service.onPackageAdded(androidPackage.packageName)
+    }
+
+    override fun onPackageRemoved(androidPackage: AndroidPackage) {
+        // This may not be a full removal so ignored - we'll figure out full removal in
+        // onPackageUninstalled().
     }
 
     override fun onPackageInstalled(
@@ -400,21 +434,38 @@
         params: PermissionManagerServiceInternal.PackageInstalledParams,
         userId: Int
     ) {
-        TODO("Not yet implemented")
+        synchronized(mountedStorageVolumes) {
+            if (androidPackage.volumeUuid !in mountedStorageVolumes) {
+                // Wait for the storage volume to be mounted and batch the state mutation there.
+                return
+            }
+        }
+        val userIds = if (userId == UserHandle.USER_ALL) {
+            userManagerService.userIdsIncludingPreCreated
+        } else {
+            intArrayOf(userId)
+        }
+        userIds.forEach { service.onPackageInstalled(androidPackage.packageName, it) }
+        // TODO: Handle params.
     }
 
     override fun onPackageUninstalled(
         packageName: String,
         appId: Int,
         androidPackage: AndroidPackage?,
-        sharedUserPkgs: MutableList<AndroidPackage>,
+        sharedUserPkgs: List<AndroidPackage>,
         userId: Int
     ) {
-        TODO("Not yet implemented")
-    }
-
-    override fun onPackageRemoved(androidPackage: AndroidPackage) {
-        TODO("Not yet implemented")
+        val userIds = if (userId == UserHandle.USER_ALL) {
+            userManagerService.userIdsIncludingPreCreated
+        } else {
+            intArrayOf(userId)
+        }
+        userIds.forEach { service.onPackageUninstalled(packageName, appId, it) }
+        val packageState = packageManagerInternal.packageStates[packageName]
+        if (packageState == null) {
+            service.onPackageRemoved(packageName, appId)
+        }
     }
 
     /**
diff --git a/services/permission/java/com/android/server/permission/access/permission/UidPermissionPersistence.kt b/services/permission/java/com/android/server/permission/access/permission/UidPermissionPersistence.kt
index 3489061..061933a 100644
--- a/services/permission/java/com/android/server/permission/access/permission/UidPermissionPersistence.kt
+++ b/services/permission/java/com/android/server/permission/access/permission/UidPermissionPersistence.kt
@@ -22,7 +22,6 @@
 import com.android.modules.utils.BinaryXmlSerializer
 import com.android.server.permission.access.SystemState
 import com.android.server.permission.access.collection.* // ktlint-disable no-wildcard-imports
-import com.android.server.permission.access.data.Permission
 import com.android.server.permission.access.util.attribute
 import com.android.server.permission.access.util.attributeInt
 import com.android.server.permission.access.util.attributeIntHex
diff --git a/services/permission/java/com/android/server/permission/access/permission/UidPermissionPolicy.kt b/services/permission/java/com/android/server/permission/access/permission/UidPermissionPolicy.kt
index e081924..b2f52cc 100644
--- a/services/permission/java/com/android/server/permission/access/permission/UidPermissionPolicy.kt
+++ b/services/permission/java/com/android/server/permission/access/permission/UidPermissionPolicy.kt
@@ -20,9 +20,11 @@
 import android.content.pm.PackageManager
 import android.content.pm.PermissionGroupInfo
 import android.content.pm.PermissionInfo
+import android.content.pm.SigningDetails
 import android.os.Build
 import android.os.UserHandle
 import android.util.Log
+import com.android.internal.os.RoSystemProperties
 import com.android.modules.utils.BinaryXmlPullParser
 import com.android.modules.utils.BinaryXmlSerializer
 import com.android.server.permission.access.AccessState
@@ -33,22 +35,23 @@
 import com.android.server.permission.access.SchemePolicy
 import com.android.server.permission.access.SystemState
 import com.android.server.permission.access.UidUri
-import com.android.server.permission.access.UserState
 import com.android.server.permission.access.collection.* // ktlint-disable no-wildcard-imports
-import com.android.server.permission.access.data.Permission
-import com.android.server.permission.access.external.AndroidPackage
-import com.android.server.permission.access.external.CompatibilityPermissionInfo
-import com.android.server.permission.access.external.KnownPackages
-import com.android.server.permission.access.external.PackageInfoUtils
-import com.android.server.permission.access.external.PackageState
-import com.android.server.permission.access.external.RoSystemProperties
-import com.android.server.permission.access.external.SigningDetails
-import com.android.server.permission.access.util.hasAnyBit
+import com.android.server.permission.access.util.andInv
 import com.android.server.permission.access.util.hasBits
+import com.android.server.pm.KnownPackages
+import com.android.server.pm.parsing.PackageInfoUtils
+import com.android.server.pm.permission.CompatibilityPermissionInfo
+import com.android.server.pm.pkg.AndroidPackage
+import com.android.server.pm.pkg.PackageState
 
 class UidPermissionPolicy : SchemePolicy() {
     private val persistence = UidPermissionPersistence()
 
+    @Volatile
+    private var onPermissionFlagsChangedListeners =
+        IndexedListSet<OnPermissionFlagsChangedListener>()
+    private val onPermissionFlagsChangedListenersLock = Any()
+
     override val subjectScheme: String
         get() = UidUri.SCHEME
 
@@ -58,8 +61,7 @@
     override fun GetStateScope.getDecision(subject: AccessUri, `object`: AccessUri): Int {
         subject as UidUri
         `object` as PermissionUri
-        return state.userStates[subject.userId]?.permissionFlags?.get(subject.appId)
-            ?.get(`object`.permissionName) ?: 0
+        return getPermissionFlags(subject.appId, subject.userId, `object`.permissionName)
     }
 
     override fun MutateStateScope.setDecision(
@@ -69,26 +71,22 @@
     ) {
         subject as UidUri
         `object` as PermissionUri
-        val uidFlags = newState.userStates.getOrPut(subject.userId) { UserState() }
-            .permissionFlags.getOrPut(subject.appId) { IndexedMap() }
-        uidFlags[`object`.permissionName] = decision
+        setPermissionFlags(subject.appId, subject.userId, `object`.permissionName, decision)
     }
 
     override fun MutateStateScope.onUserAdded(userId: Int) {
-        newState.systemState.packageStates.forEachValueIndexed { _, packageState ->
-            evaluateAllPermissionStatesForPackageAndUser(packageState, null, userId)
+        newState.systemState.packageStates.forEach { (_, packageState) ->
+            evaluateAllPermissionStatesForPackageAndUser(packageState, userId, null)
             grantImplicitPermissions(packageState, userId)
         }
     }
 
-    override fun MutateStateScope.onAppIdAdded(appId: Int) {
-        newState.userStates.forEachIndexed { _, _, userState ->
-            userState.permissionFlags.getOrPut(appId) { IndexedMap() }
-        }
-    }
-
     override fun MutateStateScope.onAppIdRemoved(appId: Int) {
-        newState.userStates.forEachIndexed { _, _, userState -> userState.permissionFlags -= appId }
+        newState.userStates.forEachValueIndexed { _, userState ->
+            userState.uidPermissionFlags -= appId
+            userState.requestWrite()
+            // Skip notifying the change listeners since the app ID no longer exists.
+        }
     }
 
     override fun MutateStateScope.onPackageAdded(packageState: PackageState) {
@@ -97,7 +95,7 @@
         addPermissionGroups(packageState)
         addPermissions(packageState, changedPermissionNames)
         // TODO: revokeStoragePermissionsIfScopeExpandedInternal()
-        trimPermissions(packageState.packageName)
+        trimPermissions(packageState.packageName, changedPermissionNames)
         changedPermissionNames.forEachIndexed { _, permissionName ->
             evaluatePermissionStateForAllPackages(permissionName, packageState)
         }
@@ -121,22 +119,23 @@
             if (!canAdoptPermissions(packageName, originalPackageName)) {
                 return@forEachIndexed
             }
-            newState.systemState.permissions.let { permissions ->
-                permissions.forEachIndexed permissions@ {
-                    permissionIndex, permissionName, oldPermission ->
-                    if (oldPermission.packageName != originalPackageName) {
-                        return@permissions
-                    }
-                    @Suppress("DEPRECATION")
-                    val newPermissionInfo = PermissionInfo().apply {
-                        name = oldPermission.permissionInfo.name
-                        this.packageName = packageName
-                        protectionLevel = oldPermission.permissionInfo.protectionLevel
-                    }
-                    val newPermission = Permission(newPermissionInfo, false, oldPermission.type, 0)
-                    changedPermissionNames += permissionName
-                    permissions.setValueAt(permissionIndex, newPermission)
+            val systemState = newState.systemState
+            val permissions = systemState.permissions
+            permissions.forEachIndexed permissions@ {
+                permissionIndex, permissionName, oldPermission ->
+                if (oldPermission.packageName != originalPackageName) {
+                    return@permissions
                 }
+                @Suppress("DEPRECATION")
+                val newPermissionInfo = PermissionInfo().apply {
+                    name = oldPermission.permissionInfo.name
+                    this.packageName = packageName
+                    protectionLevel = oldPermission.permissionInfo.protectionLevel
+                }
+                val newPermission = Permission(newPermissionInfo, false, oldPermission.type, 0)
+                permissions.setValueAt(permissionIndex, newPermission)
+                systemState.requestWrite()
+                changedPermissionNames += permissionName
             }
         }
     }
@@ -179,7 +178,7 @@
         packageState.androidPackage!!.permissionGroups.forEachIndexed { _, parsedPermissionGroup ->
             val newPermissionGroup = PackageInfoUtils.generatePermissionGroupInfo(
                 parsedPermissionGroup, PackageManager.GET_META_DATA.toLong()
-            )
+            )!!
             // TODO: Clear permission state on group take-over?
             val permissionGroupName = newPermissionGroup.name
             val oldPermissionGroup = newState.systemState.permissionGroups[permissionGroupName]
@@ -211,13 +210,14 @@
             // }
             val newPermissionInfo = PackageInfoUtils.generatePermissionInfo(
                 parsedPermission, PackageManager.GET_META_DATA.toLong()
-            )
+            )!!
             // TODO: newPermissionInfo.flags |= PermissionInfo.FLAG_INSTALLED
+            val systemState = newState.systemState
             val permissionName = newPermissionInfo.name
             val oldPermission = if (parsedPermission.isTree) {
-                newState.systemState.permissionTrees[permissionName]
+                systemState.permissionTrees[permissionName]
             } else {
-                newState.systemState.permissions[permissionName]
+                systemState.permissions[permissionName]
             }
             // Different from the old implementation, which may add an (incomplete) signature
             // permission inside another package's permission tree, we now consistently ignore such
@@ -247,19 +247,18 @@
                 if (oldPermission.type == Permission.TYPE_CONFIG && !oldPermission.isReconciled) {
                     // It's a config permission and has no owner, take ownership now.
                     Permission(newPermissionInfo, true, Permission.TYPE_CONFIG, packageState.appId)
-                } else if (newState.systemState.packageStates[oldPackageName]?.isSystem != true) {
+                } else if (systemState.packageStates[oldPackageName]?.isSystem != true) {
                     Log.w(
                         LOG_TAG, "Overriding permission $permissionName with new declaration in" +
                             " system package $newPackageName: originally declared in another" +
                             " package $oldPackageName"
                     )
                     // Remove permission state on owner change.
-                    newState.userStates.forEachValueIndexed { _, userState ->
-                        userState.permissionFlags.forEachValueIndexed { _, permissionFlags ->
-                            permissionFlags -= newPermissionInfo.name
+                    systemState.userIds.forEachIndexed { _, userId ->
+                        systemState.appIds.forEachKeyIndexed { _, appId ->
+                            setPermissionFlags(appId, userId, permissionName, 0)
                         }
                     }
-                    // TODO: Notify re-evaluation of this permission.
                     Permission(
                         newPermissionInfo, true, Permission.TYPE_MANIFEST, packageState.appId
                     )
@@ -278,23 +277,28 @@
                 Permission(newPermissionInfo, true, Permission.TYPE_MANIFEST, packageState.appId)
             }
 
-            changedPermissionNames += permissionName
             if (parsedPermission.isTree) {
-                newState.systemState.permissionTrees[permissionName] = newPermission
+                systemState.permissionTrees[permissionName] = newPermission
             } else {
-                newState.systemState.permissions[permissionName] = newPermission
+                systemState.permissions[permissionName] = newPermission
             }
+            systemState.requestWrite()
+            changedPermissionNames += permissionName
         }
     }
 
-    private fun MutateStateScope.trimPermissions(packageName: String) {
-        val packageState = newState.systemState.packageStates[packageName]
+    private fun MutateStateScope.trimPermissions(
+        packageName: String,
+        changedPermissionNames: IndexedSet<String>
+    ) {
+        val systemState = newState.systemState
+        val packageState = systemState.packageStates[packageName]
         val androidPackage = packageState?.androidPackage
         if (packageState != null && androidPackage == null) {
             return
         }
 
-        newState.systemState.permissionTrees.removeAllIndexed {
+        val isPermissionTreeRemoved = systemState.permissionTrees.removeAllIndexed {
             _, permissionTreeName, permissionTree ->
             permissionTree.packageName == packageName && (
                 packageState == null || androidPackage!!.permissions.noneIndexed { _, it ->
@@ -302,26 +306,30 @@
                 }
             )
         }
+        if (isPermissionTreeRemoved) {
+            systemState.requestWrite()
+        }
 
-        newState.systemState.permissions.removeAllIndexed { i, permissionName, permission ->
+        systemState.permissions.removeAllIndexed { permissionIndex, permissionName, permission ->
             val updatedPermission = updatePermissionIfDynamic(permission)
-            newState.systemState.permissions.setValueAt(i, updatedPermission)
+            newState.systemState.permissions.setValueAt(permissionIndex, updatedPermission)
             if (updatedPermission.packageName == packageName && (
                 packageState == null || androidPackage!!.permissions.noneIndexed { _, it ->
                     !it.isTree && it.name == permissionName
                 }
             )) {
-                if (!isPermissionDeclaredByDisabledSystemPackage(permission)) {
-                    newState.userStates.forEachIndexed { _, userId, userState ->
-                        userState.permissionFlags.forEachKeyIndexed { _, appId ->
-                            setPermissionFlags(
-                                appId, permissionName, getPermissionFlags(
-                                    appId, permissionName, userId
-                                ) and PermissionFlags.INSTALL_REVOKED, userId
-                            )
-                        }
+                // Different from the old implementation where we keep the permission state if the
+                // permission is declared by a disabled system package (ag/15189282), we now
+                // shouldn't be notified when the updated system package is removed but the disabled
+                // system package isn't re-enabled yet, so we don't need to maintain that brittle
+                // special case either.
+                systemState.userIds.forEachIndexed { _, userId ->
+                    systemState.appIds.forEachKeyIndexed { _, appId ->
+                        setPermissionFlags(appId, userId, permissionName, 0)
                     }
                 }
+                changedPermissionNames += permissionName
+                systemState.requestWrite()
                 true
             } else {
                 false
@@ -329,16 +337,6 @@
         }
     }
 
-    private fun MutateStateScope.isPermissionDeclaredByDisabledSystemPackage(
-        permission: Permission
-    ): Boolean {
-        val disabledSystemPackage = newState.systemState
-            .disabledSystemPackageStates[permission.packageName]?.androidPackage ?: return false
-        return disabledSystemPackage.permissions.anyIndexed { _, it ->
-            it.name == permission.name && it.protectionLevel == permission.protectionLevel
-        }
-    }
-
     private fun MutateStateScope.updatePermissionIfDynamic(permission: Permission): Permission {
         if (!permission.isDynamic) {
             return permission
@@ -368,11 +366,14 @@
         permissionName: String,
         installedPackageState: PackageState?
     ) {
-        newState.systemState.userIds.forEachIndexed { _, userId ->
-            oldState.userStates[userId]?.permissionFlags?.forEachIndexed {
-                _, appId, permissionFlags ->
-                if (permissionName in permissionFlags) {
-                    evaluatePermissionState(appId, permissionName, installedPackageState, userId)
+        val systemState = newState.systemState
+        systemState.userIds.forEachIndexed { _, userId ->
+            systemState.appIds.forEachKeyIndexed { _, appId ->
+                val isPermissionRequested = anyPackageInAppId(appId) { packageState ->
+                    permissionName in packageState.androidPackage!!.requestedPermissions
+                }
+                if (isPermissionRequested) {
+                    evaluatePermissionState(appId, userId, permissionName, installedPackageState)
                 }
             }
         }
@@ -384,28 +385,28 @@
     ) {
         newState.systemState.userIds.forEachIndexed { _, userId ->
             evaluateAllPermissionStatesForPackageAndUser(
-                packageState, installedPackageState, userId
+                packageState, userId, installedPackageState
             )
         }
     }
 
     private fun MutateStateScope.evaluateAllPermissionStatesForPackageAndUser(
         packageState: PackageState,
-        installedPackageState: PackageState?,
-        userId: Int
+        userId: Int,
+        installedPackageState: PackageState?
     ) {
         packageState.androidPackage?.requestedPermissions?.forEachIndexed { _, permissionName ->
             evaluatePermissionState(
-                packageState.appId, permissionName, installedPackageState, userId
+                packageState.appId, userId, permissionName, installedPackageState
             )
         }
     }
 
     private fun MutateStateScope.evaluatePermissionState(
         appId: Int,
+        userId: Int,
         permissionName: String,
-        installedPackageState: PackageState?,
-        userId: Int
+        installedPackageState: PackageState?
     ) {
         val packageNames = newState.systemState.appIds[appId]
         val hasMissingPackage = packageNames.anyIndexed { _, packageName ->
@@ -416,7 +417,7 @@
             return
         }
         val permission = newState.systemState.permissions[permissionName] ?: return
-        val oldFlags = getPermissionFlags(appId, permissionName, userId)
+        val oldFlags = getPermissionFlags(appId, userId, permissionName)
         if (permission.isNormal) {
             val wasGranted = oldFlags.hasBits(PermissionFlags.INSTALL_GRANTED)
             if (!wasGranted) {
@@ -438,7 +439,7 @@
                 } else {
                     PermissionFlags.INSTALL_REVOKED
                 }
-                setPermissionFlags(appId, permissionName, newFlags, userId)
+                setPermissionFlags(appId, userId, permissionName, newFlags)
             }
         } else if (permission.isSignature || permission.isInternal) {
             val wasProtectionGranted = oldFlags.hasBits(PermissionFlags.PROTECTION_GRANTED)
@@ -472,12 +473,12 @@
             // should only affect the other static flags, but not dynamic flags like development or
             // role. This may be useful in the case of an updated system app.
             if (permission.isDevelopment) {
-                newFlags = newFlags or (oldFlags and PermissionFlags.OTHER_GRANTED)
+                newFlags = newFlags or (oldFlags and PermissionFlags.RUNTIME_GRANTED)
             }
             if (permission.isRole) {
-                newFlags = newFlags or (oldFlags and PermissionFlags.ROLE_GRANTED)
+                newFlags = newFlags or (oldFlags and PermissionFlags.ROLE)
             }
-            setPermissionFlags(appId, permissionName, newFlags, userId)
+            setPermissionFlags(appId, userId, permissionName, newFlags)
         } else if (permission.isRuntime) {
             // TODO: add runtime permissions
         } else {
@@ -503,7 +504,7 @@
             }
             // Explicitly check against the old state to determine if this permission is new.
             val isNewPermission = getPermissionFlags(
-                appId, implicitPermissionName, userId, oldState
+                appId, userId, implicitPermissionName, oldState
             ) == 0
             if (!isNewPermission) {
                 return@implicitPermissions
@@ -516,9 +517,9 @@
                 checkNotNull(sourcePermission) {
                     "Unknown source permission $sourcePermissionName in split permissions"
                 }
-                val sourceFlags = getPermissionFlags(appId, sourcePermissionName, userId)
-                val isSourceGranted = sourceFlags.hasAnyBit(PermissionFlags.MASK_GRANTED)
-                val isNewGranted = newFlags.hasAnyBit(PermissionFlags.MASK_GRANTED)
+                val sourceFlags = getPermissionFlags(appId, userId, sourcePermissionName)
+                val isSourceGranted = PermissionFlags.isPermissionGranted(sourceFlags)
+                val isNewGranted = PermissionFlags.isPermissionGranted(newFlags)
                 val isGrantingNewFromRevoke = isSourceGranted && !isNewGranted
                 if (isSourceGranted == isNewGranted || isGrantingNewFromRevoke) {
                     if (isGrantingNewFromRevoke) {
@@ -526,32 +527,15 @@
                     }
                     newFlags = newFlags or (sourceFlags and PermissionFlags.MASK_RUNTIME)
                     if (!sourcePermission.isRuntime && isSourceGranted) {
-                        newFlags = newFlags or PermissionFlags.OTHER_GRANTED
+                        newFlags = newFlags or PermissionFlags.IMPLICIT_GRANTED
                     }
                 }
             }
             newFlags = newFlags or PermissionFlags.IMPLICIT
-            setPermissionFlags(appId, implicitPermissionName, newFlags, userId)
+            setPermissionFlags(appId, userId, implicitPermissionName, newFlags)
         }
     }
 
-    private fun MutateStateScope.getPermissionFlags(
-        appId: Int,
-        permissionName: String,
-        userId: Int,
-        state: AccessState = newState
-    ): Int = state.userStates[userId].permissionFlags[appId].getWithDefault(permissionName, 0)
-
-    private fun MutateStateScope.setPermissionFlags(
-        appId: Int,
-        permissionName: String,
-        flags: Int,
-        userId: Int
-    ) {
-        newState.userStates[userId].permissionFlags[appId]!!
-            .putWithDefault(permissionName, flags, 0)
-    }
-
     private fun isCompatibilityPermissionForPackage(
         androidPackage: AndroidPackage,
         permissionName: String
@@ -573,23 +557,24 @@
         packageState: PackageState,
         permission: Permission
     ): Boolean {
-        // check if the package is allow to use this signature permission.  A package is allowed to
-        // use a signature permission if:
-        //     - it has the same set of signing certificates as the source package
-        //     - or its signing certificate was rotated from the source package's certificate
-        //     - or its signing certificate is a previous signing certificate of the defining
-        //       package, and the defining package still trusts the old certificate for permissions
-        //     - or it shares a common signing certificate in its lineage with the defining package,
-        //       and the defining package still trusts the old certificate for permissions
-        //     - or it shares the above relationships with the system package
+        // Check if the package is allowed to use this signature permission.  A package is allowed
+        // to use a signature permission if:
+        // - it has the same set of signing certificates as the source package
+        // - or its signing certificate was rotated from the source package's certificate
+        // - or its signing certificate is a previous signing certificate of the defining
+        //     package, and the defining package still trusts the old certificate for permissions
+        // - or it shares a common signing certificate in its lineage with the defining package,
+        //     and the defining package still trusts the old certificate for permissions
+        // - or it shares the above relationships with the system package
+        val packageSigningDetails = packageState.androidPackage!!.signingDetails
         val sourceSigningDetails = newState.systemState
-            .packageStates[permission.packageName]?.signingDetails
+            .packageStates[permission.packageName]?.androidPackage?.signingDetails
         val platformSigningDetails = newState.systemState
-            .packageStates[PLATFORM_PACKAGE_NAME]!!.signingDetails
-        return sourceSigningDetails?.hasCommonSignerWithCapability(packageState.signingDetails,
+            .packageStates[PLATFORM_PACKAGE_NAME]!!.androidPackage!!.signingDetails
+        return sourceSigningDetails?.hasCommonSignerWithCapability(packageSigningDetails,
             SigningDetails.CertCapabilities.PERMISSION) == true ||
-            packageState.signingDetails.hasAncestorOrSelf(platformSigningDetails) ||
-            platformSigningDetails.checkCapability(packageState.signingDetails,
+            packageSigningDetails.hasAncestorOrSelf(platformSigningDetails) ||
+            platformSigningDetails.checkCapability(packageSigningDetails,
                     SigningDetails.CertCapabilities.PERMISSION)
     }
 
@@ -611,11 +596,9 @@
             newState.systemState.privilegedPermissionAllowlistSourcePackageNames) {
             return true
         }
-        if (isInSystemConfigPrivAppPermissions(androidPackage, permission.name)) {
-            return true
-        }
-        if (isInSystemConfigPrivAppDenyPermissions(androidPackage, permission.name)) {
-            return false
+        val allowlistState = getPrivilegedPermissionAllowlistState(androidPackage, permission.name)
+        if (allowlistState != null) {
+            return allowlistState
         }
         // Updated system apps do not need to be allowlisted
         if (packageState.isUpdatedSystemApp) {
@@ -625,60 +608,51 @@
         return !RoSystemProperties.CONTROL_PRIVAPP_PERMISSIONS_ENFORCE
     }
 
-    private fun MutateStateScope.isInSystemConfigPrivAppPermissions(
+    /**
+     * Get the whether a privileged permission is explicitly allowed or denied for a package in the
+     * allowlist, or `null` if it's not in the allowlist.
+     */
+    private fun MutateStateScope.getPrivilegedPermissionAllowlistState(
         androidPackage: AndroidPackage,
         permissionName: String
-    ): Boolean {
-        val apexModuleName = androidPackage.apexModuleName
-        val systemState = newState.systemState
+    ): Boolean? {
+        val permissionAllowlist = newState.systemState.permissionAllowlist
+        // TODO(b/261913353): STOPSHIP: Add AndroidPackage.apexModuleName. The below is only for
+        //  passing compilation but won't actually work.
+        //val apexModuleName = androidPackage.apexModuleName
+        val apexModuleName = androidPackage.packageName
         val packageName = androidPackage.packageName
-        val permissionNames = when {
-            androidPackage.isVendor -> systemState.vendorPrivAppPermissions[packageName]
-            androidPackage.isProduct -> systemState.productPrivAppPermissions[packageName]
-            androidPackage.isSystemExt -> systemState.systemExtPrivAppPermissions[packageName]
+        return when {
+            androidPackage.isVendor -> permissionAllowlist.getVendorPrivilegedAppAllowlistState(
+                packageName, permissionName
+            )
+            androidPackage.isProduct -> permissionAllowlist.getProductPrivilegedAppAllowlistState(
+                packageName, permissionName
+            )
+            androidPackage.isSystemExt ->
+                permissionAllowlist.getSystemExtPrivilegedAppAllowlistState(
+                    packageName, permissionName
+                )
             apexModuleName != null -> {
-                val apexPrivAppPermissions = systemState.apexPrivAppPermissions[apexModuleName]
-                    ?.get(packageName)
-                val privAppPermissions = systemState.privAppPermissions[packageName]
-                when {
-                    apexPrivAppPermissions == null -> privAppPermissions
-                    privAppPermissions == null -> apexPrivAppPermissions
-                    else -> apexPrivAppPermissions + privAppPermissions
+                val nonApexAllowlistState = permissionAllowlist.getPrivilegedAppAllowlistState(
+                    packageName, permissionName
+                )
+                if (nonApexAllowlistState != null) {
+                    // TODO(andreionea): Remove check as soon as all apk-in-apex
+                    // permission allowlists are migrated.
+                    Log.w(
+                        LOG_TAG, "Package $packageName is an APK in APEX but has permission" +
+                            " allowlist on the system image, please bundle the allowlist in the" +
+                            " $apexModuleName APEX instead"
+                    )
                 }
+                val apexAllowlistState = permissionAllowlist.getApexPrivilegedAppAllowlistState(
+                    apexModuleName, packageName, permissionName
+                )
+                apexAllowlistState ?: nonApexAllowlistState
             }
-            else -> systemState.privAppPermissions[packageName]
+            else -> permissionAllowlist.getPrivilegedAppAllowlistState(packageName, permissionName)
         }
-        return permissionNames?.contains(permissionName) == true
-    }
-
-    private fun MutateStateScope.isInSystemConfigPrivAppDenyPermissions(
-        androidPackage: AndroidPackage,
-        permissionName: String
-    ): Boolean {
-        // Different from the previous implementation, which may incorrectly use the APEX package
-        // name, we now use the APEX module name to be consistent with the allowlist.
-        val apexModuleName = androidPackage.apexModuleName
-        val systemState = newState.systemState
-        val packageName = androidPackage.packageName
-        val permissionNames = when {
-            androidPackage.isVendor -> systemState.vendorPrivAppDenyPermissions[packageName]
-            androidPackage.isProduct -> systemState.productPrivAppDenyPermissions[packageName]
-            androidPackage.isSystemExt -> systemState.systemExtPrivAppDenyPermissions[packageName]
-            // Different from the previous implementation, which ignores the regular priv app
-            // denylist in this case, we now respect it as well to be consistent with the allowlist.
-            apexModuleName != null -> {
-                val apexPrivAppDenyPermissions = systemState
-                    .apexPrivAppDenyPermissions[apexModuleName]?.get(packageName)
-                val privAppDenyPermissions = systemState.privAppDenyPermissions[packageName]
-                when {
-                    apexPrivAppDenyPermissions == null -> privAppDenyPermissions
-                    privAppDenyPermissions == null -> apexPrivAppDenyPermissions
-                    else -> apexPrivAppDenyPermissions + privAppDenyPermissions
-                }
-            }
-            else -> systemState.privAppDenyPermissions[packageName]
-        }
-        return permissionNames?.contains(permissionName) == true
     }
 
     private fun MutateStateScope.anyPackageInAppId(
@@ -741,7 +715,7 @@
             return true
         }
         if (permission.isKnownSigner &&
-            packageState.signingDetails.hasAncestorOrSelfWithDigest(permission.knownCerts)) {
+            androidPackage.signingDetails.hasAncestorOrSelfWithDigest(permission.knownCerts)) {
             // If the permission is to be granted to a known signer then check if any of this
             // app's signing certificates are in the trusted certificate digest Set.
             return true
@@ -819,13 +793,13 @@
             }
             permission.isOem -> {
                 if (androidPackage.isOem) {
-                    val isOemAllowlisted = newState.systemState
-                        .oemPermissions[packageName]?.get(permissionName)
-                    checkNotNull(isOemAllowlisted) {
+                    val allowlistState = newState.systemState.permissionAllowlist
+                        .getOemAppAllowlistState(packageName, permissionName)
+                    checkNotNull(allowlistState) {
                         "OEM permission $permissionName requested by package" +
                             " $packageName must be explicitly declared granted or not"
                     }
-                    return isOemAllowlisted
+                    return allowlistState
                 }
             }
         }
@@ -840,8 +814,11 @@
         return uid == ownerUid
     }
 
-    override fun MutateStateScope.onPackageRemoved(packageState: PackageState) {
-        // TODO
+    override fun MutateStateScope.onPackageRemoved(packageName: String, appId: Int) {
+        // TODO: STOPSHIP: Remove this check or at least turn into logging.
+        check(packageName !in newState.systemState.disabledSystemPackageStates) {
+            "Package $packageName reported as removed before disabled system package is enabled"
+        }
     }
 
     override fun BinaryXmlPullParser.parseSystemState(systemState: SystemState) {
@@ -858,6 +835,80 @@
     fun GetStateScope.getPermission(permissionName: String): Permission? =
         state.systemState.permissions[permissionName]
 
+    fun GetStateScope.getUidPermissionFlags(appId: Int, userId: Int): IndexedMap<String, Int>? =
+        state.userStates[userId]?.uidPermissionFlags?.get(appId)
+
+    fun GetStateScope.getPermissionFlags(
+        appId: Int,
+        userId: Int,
+        permissionName: String
+    ): Int = getPermissionFlags(state, appId, userId, permissionName)
+
+    private fun MutateStateScope.getPermissionFlags(
+        appId: Int,
+        userId: Int,
+        permissionName: String,
+        state: AccessState = newState
+    ): Int = getPermissionFlags(state, appId, userId, permissionName)
+
+    private fun getPermissionFlags(
+        state: AccessState,
+        appId: Int,
+        userId: Int,
+        permissionName: String
+    ): Int =
+        state.userStates[userId]?.uidPermissionFlags?.get(appId).getWithDefault(permissionName, 0)
+
+    fun MutateStateScope.setPermissionFlags(
+        appId: Int,
+        userId: Int,
+        permissionName: String,
+        flags: Int
+    ): Boolean =
+        updatePermissionFlags(appId, userId, permissionName, PermissionFlags.MASK_ALL, flags)
+
+    fun MutateStateScope.updatePermissionFlags(
+        appId: Int,
+        userId: Int,
+        permissionName: String,
+        flagMask: Int,
+        flagValues: Int
+    ): Boolean {
+        val userState = newState.userStates[userId]
+        val uidPermissionFlags = userState.uidPermissionFlags
+        var permissionFlags = uidPermissionFlags[appId]
+        val oldFlags = permissionFlags.getWithDefault(permissionName, 0)
+        val newFlags = (oldFlags andInv flagMask) or (flagValues and flagMask)
+        if (oldFlags == newFlags) {
+            return false
+        }
+        if (permissionFlags == null) {
+            permissionFlags = IndexedMap()
+            uidPermissionFlags[appId] = permissionFlags
+        }
+        permissionFlags.putWithDefault(permissionName, newFlags, 0)
+        if (permissionFlags.isEmpty()) {
+            uidPermissionFlags -= appId
+        }
+        userState.requestWrite()
+        onPermissionFlagsChangedListeners.forEachIndexed { _, it ->
+            it.onPermissionFlagsChanged(appId, userId, permissionName, oldFlags, newFlags)
+        }
+        return true
+    }
+
+    fun addOnPermissionFlagsChangedListener(listener: OnPermissionFlagsChangedListener) {
+        synchronized(onPermissionFlagsChangedListenersLock) {
+            onPermissionFlagsChangedListeners = onPermissionFlagsChangedListeners + listener
+        }
+    }
+
+    fun removeOnPermissionFlagsChangedListener(listener: OnPermissionFlagsChangedListener) {
+        synchronized(onPermissionFlagsChangedListenersLock) {
+            onPermissionFlagsChangedListeners = onPermissionFlagsChangedListeners - listener
+        }
+    }
+
     companion object {
         private val LOG_TAG = UidPermissionPolicy::class.java.simpleName
 
@@ -872,4 +923,14 @@
             Manifest.permission.READ_MEDIA_VIDEO,
         )
     }
+
+    fun interface OnPermissionFlagsChangedListener {
+        fun onPermissionFlagsChanged(
+            appId: Int,
+            userId: Int,
+            permissionName: String,
+            oldFlags: Int,
+            newFlags: Int
+        )
+    }
 }
diff --git a/services/tests/InputMethodSystemServerTests/Android.bp b/services/tests/InputMethodSystemServerTests/Android.bp
index 939fb6a..70a5c3f 100644
--- a/services/tests/InputMethodSystemServerTests/Android.bp
+++ b/services/tests/InputMethodSystemServerTests/Android.bp
@@ -28,7 +28,7 @@
     ],
 
     srcs: [
-        "src/**/*.java",
+        "src/server/**/*.java",
     ],
 
     static_libs: [
@@ -60,3 +60,52 @@
         enabled: false,
     },
 }
+
+android_test {
+    name: "FrameworksImeTests",
+    defaults: [
+        "modules-utils-testable-device-config-defaults",
+    ],
+
+    srcs: [
+        "src/com/android/inputmethodservice/**/*.java",
+    ],
+
+    manifest: "src/com/android/inputmethodservice/AndroidManifest.xml",
+    test_config: "src/com/android/inputmethodservice/AndroidTest.xml",
+
+    static_libs: [
+        "androidx.test.core",
+        "androidx.test.runner",
+        "androidx.test.espresso.core",
+        "androidx.test.espresso.contrib",
+        "androidx.test.ext.truth",
+        "frameworks-base-testutils",
+        "mockito-target-extended-minus-junit4",
+        "platform-test-annotations",
+        "services.core",
+        "servicestests-core-utils",
+        "servicestests-utils-mockito-extended",
+        "truth-prebuilt",
+        "SimpleImeTestingLib",
+        "SimpleImeImsLib",
+    ],
+
+    libs: [
+        "android.test.mock",
+        "android.test.base",
+        "android.test.runner",
+    ],
+
+    data: [
+        ":SimpleTestIme",
+    ],
+
+    certificate: "platform",
+    platform_apis: true,
+    test_suites: ["device-tests"],
+
+    optimize: {
+        enabled: false,
+    },
+}
diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/AndroidManifest.xml b/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/AndroidManifest.xml
new file mode 100644
index 0000000..0104f71
--- /dev/null
+++ b/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/AndroidManifest.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ 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.
+  -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+          package="com.android.inputmethod.imetests">
+
+    <uses-sdk android:targetSdkVersion="31" />
+
+    <!-- Permissions required for granting and logging -->
+    <uses-permission android:name="android.permission.LOG_COMPAT_CHANGE"/>
+    <uses-permission android:name="android.permission.READ_COMPAT_CHANGE_CONFIG"/>
+    <uses-permission android:name="android.permission.OVERRIDE_COMPAT_CHANGE_CONFIG"/>
+    <uses-permission android:name="android.permission.OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD"/>
+
+    <!-- Permissions for reading system info -->
+    <uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
+    <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
+
+    <application android:debuggable="true">
+        <uses-library android:name="android.test.runner" />
+    </application>
+
+    <!-- The "targetPackage" reference the instruments APK package, which is the FakeImeApk, while
+    the test package is "com.android.inputmethod.imetests" (FrameworksImeTests.apk).-->
+    <instrumentation
+        android:name="androidx.test.runner.AndroidJUnitRunner"
+        android:targetPackage="com.android.apps.inputmethod.simpleime"
+        android:label="Frameworks IME Tests" />
+</manifest>
diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/AndroidTest.xml b/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/AndroidTest.xml
new file mode 100644
index 0000000..6c24d6d
--- /dev/null
+++ b/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/AndroidTest.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ 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.
+  -->
+<configuration description="Runs Frameworks IME Tests.">
+    <option name="test-suite-tag" value="apct" />
+    <option name="test-suite-tag" value="apct-instrumentation" />
+
+    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+        <option name="cleanup-apks" value="true" />
+        <option name="install-arg" value="-t" />
+        <option name="test-file-name" value="FrameworksImeTests.apk" />
+        <option name="test-file-name" value="SimpleTestIme.apk" />
+    </target_preparer>
+
+    <option name="test-tag" value="FrameworksImeTests" />
+
+    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
+        <option name="package" value="com.android.inputmethod.imetests" />
+        <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
+        <option name="hidden-api-checks" value="false"/>
+    </test>
+
+    <!-- Collect the files in the dump directory for debugging -->
+    <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector">
+        <option name="directory-keys" value="/sdcard/FrameworksImeTests/" />
+        <option name="collect-on-run-ended-only" value="true" />
+    </metrics_collector>
+</configuration>
diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java b/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java
new file mode 100644
index 0000000..16a9845
--- /dev/null
+++ b/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java
@@ -0,0 +1,276 @@
+/*
+ * 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.inputmethodservice;
+
+import static com.android.compatibility.common.util.SystemUtil.eventually;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.app.Instrumentation;
+import android.content.Context;
+import android.content.res.Configuration;
+import android.os.RemoteException;
+import android.support.test.uiautomator.By;
+import android.support.test.uiautomator.UiDevice;
+import android.support.test.uiautomator.UiObject2;
+import android.support.test.uiautomator.Until;
+import android.util.Log;
+import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.MediumTest;
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import com.android.apps.inputmethod.simpleime.ims.InputMethodServiceWrapper;
+import com.android.apps.inputmethod.simpleime.testing.TestActivity;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+@RunWith(AndroidJUnit4.class)
+@MediumTest
+public class InputMethodServiceTest {
+    private static final String TAG = "SimpleIMSTest";
+    private static final String INPUT_METHOD_SERVICE_NAME = ".SimpleInputMethodService";
+    private static final String EDIT_TEXT_DESC = "Input box";
+    private static final long TIMEOUT_IN_SECONDS = 3;
+
+    public Instrumentation mInstrumentation;
+    public UiDevice mUiDevice;
+    public Context mContext;
+    public String mTargetPackageName;
+    public TestActivity mActivity;
+    public EditText mEditText;
+    public InputMethodServiceWrapper mInputMethodService;
+    public String mInputMethodId;
+
+    @Before
+    public void setUp() throws Exception {
+        mInstrumentation = InstrumentationRegistry.getInstrumentation();
+        mUiDevice = UiDevice.getInstance(mInstrumentation);
+        mContext = mInstrumentation.getContext();
+        mTargetPackageName = mInstrumentation.getTargetContext().getPackageName();
+        mInputMethodId = getInputMethodId();
+        prepareIme();
+        prepareEditor();
+
+        // Waits for input binding ready.
+        eventually(
+                () -> {
+                    mInputMethodService =
+                            InputMethodServiceWrapper.getInputMethodServiceWrapperForTesting();
+                    assertThat(mInputMethodService).isNotNull();
+
+                    // The editor won't bring up keyboard by default.
+                    assertThat(mInputMethodService.getCurrentInputStarted()).isTrue();
+                    assertThat(mInputMethodService.getCurrentInputViewStarted()).isFalse();
+                });
+    }
+
+    @Test
+    public void testShowHideKeyboard_byUserAction() throws InterruptedException {
+        // Performs click on editor box to bring up the soft keyboard.
+        Log.i(TAG, "Click on EditText.");
+        verifyInputViewStatus(() -> clickOnEditorText(), true /* inputViewStarted */);
+
+        // Press back key to hide soft keyboard.
+        Log.i(TAG, "Press back");
+        verifyInputViewStatus(
+                () -> assertThat(mUiDevice.pressHome()).isTrue(), false /* inputViewStarted */);
+    }
+
+    @Test
+    public void testShowHideKeyboard_byApi() throws InterruptedException {
+        // Triggers to show IME via public API.
+        verifyInputViewStatus(
+                () -> assertThat(mActivity.showImeWithWindowInsetsController()).isTrue(),
+                true /* inputViewStarted */);
+
+        // Triggers to hide IME via public API.
+        // TODO(b/242838873): investigate why WIC#hide(ime()) does not work, likely related to
+        //  triggered from IME process.
+        verifyInputViewStatusOnMainSync(
+                () -> assertThat(mActivity.hideImeWithInputMethodManager(0 /* flags */)).isTrue(),
+                false /* inputViewStarted */);
+    }
+
+    @Test
+    public void testShowHideSelf() throws InterruptedException {
+        // IME requests to show itself without any flags: expect shown.
+        Log.i(TAG, "Call IMS#requestShowSelf(0)");
+        verifyInputViewStatusOnMainSync(
+                () -> mInputMethodService.requestShowSelf(0), true /* inputViewStarted */);
+
+        // IME requests to hide itself with flag: HIDE_IMPLICIT_ONLY, expect not hide (shown).
+        Log.i(TAG, "Call IMS#requestHideSelf(InputMethodManager.HIDE_IMPLICIT_ONLY)");
+        verifyInputViewStatusOnMainSync(
+                () -> mInputMethodService.requestHideSelf(InputMethodManager.HIDE_IMPLICIT_ONLY),
+                true /* inputViewStarted */);
+
+        // IME request to hide itself without any flags: expect hidden.
+        Log.i(TAG, "Call IMS#requestHideSelf(0)");
+        verifyInputViewStatusOnMainSync(
+                () -> mInputMethodService.requestHideSelf(0), false /* inputViewStarted */);
+
+        // IME request to show itself with flag SHOW_IMPLICIT: expect shown.
+        Log.i(TAG, "Call IMS#requestShowSelf(InputMethodManager.SHOW_IMPLICIT)");
+        verifyInputViewStatusOnMainSync(
+                () -> mInputMethodService.requestShowSelf(InputMethodManager.SHOW_IMPLICIT),
+                true /* inputViewStarted */);
+
+        // IME request to hide itself with flag: HIDE_IMPLICIT_ONLY, expect hidden.
+        Log.i(TAG, "Call IMS#requestHideSelf(InputMethodManager.HIDE_IMPLICIT_ONLY)");
+        verifyInputViewStatusOnMainSync(
+                () -> mInputMethodService.requestHideSelf(InputMethodManager.HIDE_IMPLICIT_ONLY),
+                false /* inputViewStarted */);
+    }
+
+    private void verifyInputViewStatus(Runnable runnable, boolean inputViewStarted)
+            throws InterruptedException {
+        verifyInputViewStatusInternal(runnable, inputViewStarted, false /*runOnMainSync*/);
+    }
+
+    private void verifyInputViewStatusOnMainSync(Runnable runnable, boolean inputViewStarted)
+            throws InterruptedException {
+        verifyInputViewStatusInternal(runnable, inputViewStarted, true /*runOnMainSync*/);
+    }
+
+    private void verifyInputViewStatusInternal(
+            Runnable runnable, boolean inputViewStarted, boolean runOnMainSync)
+            throws InterruptedException {
+        CountDownLatch signal = new CountDownLatch(1);
+        mInputMethodService.setCountDownLatchForTesting(signal);
+        // Runnable to trigger onStartInputView()/ onFinishInputView()
+        if (runOnMainSync) {
+            mInstrumentation.runOnMainSync(runnable);
+        } else {
+            runnable.run();
+        }
+        // Waits for onStartInputView() to finish.
+        mInstrumentation.waitForIdleSync();
+        signal.await(TIMEOUT_IN_SECONDS, TimeUnit.SECONDS);
+        // Input is not finished.
+        assertThat(mInputMethodService.getCurrentInputStarted()).isTrue();
+        assertThat(mInputMethodService.getCurrentInputViewStarted()).isEqualTo(inputViewStarted);
+    }
+
+    @Test
+    public void testFullScreenMode() throws Exception {
+        Log.i(TAG, "Set orientation natural");
+        verifyFullscreenMode(() -> setOrientation(0), true /* orientationPortrait */);
+
+        Log.i(TAG, "Set orientation left");
+        verifyFullscreenMode(() -> setOrientation(1), false /* orientationPortrait */);
+
+        Log.i(TAG, "Set orientation right");
+        verifyFullscreenMode(() -> setOrientation(2), false /* orientationPortrait */);
+
+        mUiDevice.unfreezeRotation();
+    }
+
+    private void setOrientation(int orientation) {
+        // Simple wrapper for catching RemoteException.
+        try {
+            switch (orientation) {
+                case 1:
+                    mUiDevice.setOrientationLeft();
+                    break;
+                case 2:
+                    mUiDevice.setOrientationRight();
+                    break;
+                default:
+                    mUiDevice.setOrientationNatural();
+            }
+        } catch (RemoteException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private void verifyFullscreenMode(Runnable runnable, boolean orientationPortrait)
+            throws InterruptedException {
+        CountDownLatch signal = new CountDownLatch(1);
+        mInputMethodService.setCountDownLatchForTesting(signal);
+
+        // Runnable to trigger onConfigurationChanged()
+        try {
+            runnable.run();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        // Waits for onConfigurationChanged() to finish.
+        mInstrumentation.waitForIdleSync();
+        signal.await(TIMEOUT_IN_SECONDS, TimeUnit.SECONDS);
+
+        clickOnEditorText();
+        eventually(() -> assertThat(mInputMethodService.isInputViewShown()).isTrue());
+
+        assertThat(mInputMethodService.getResources().getConfiguration().orientation)
+                .isEqualTo(
+                        orientationPortrait
+                                ? Configuration.ORIENTATION_PORTRAIT
+                                : Configuration.ORIENTATION_LANDSCAPE);
+        EditorInfo editorInfo = mInputMethodService.getCurrentInputEditorInfo();
+        assertThat(editorInfo.imeOptions & EditorInfo.IME_FLAG_NO_FULLSCREEN).isEqualTo(0);
+        assertThat(editorInfo.internalImeOptions & EditorInfo.IME_INTERNAL_FLAG_APP_WINDOW_PORTRAIT)
+                .isEqualTo(
+                        orientationPortrait ? EditorInfo.IME_INTERNAL_FLAG_APP_WINDOW_PORTRAIT : 0);
+        assertThat(mInputMethodService.onEvaluateFullscreenMode()).isEqualTo(!orientationPortrait);
+        assertThat(mInputMethodService.isFullscreenMode()).isEqualTo(!orientationPortrait);
+
+        mUiDevice.pressBack();
+    }
+
+    private void prepareIme() throws Exception {
+        executeShellCommand("ime enable " + mInputMethodId);
+        executeShellCommand("ime set " + mInputMethodId);
+        mInstrumentation.waitForIdleSync();
+        Log.i(TAG, "Finish preparing IME");
+    }
+
+    private void prepareEditor() {
+        mActivity = TestActivity.start(mInstrumentation);
+        mEditText = mActivity.mEditText;
+        Log.i(TAG, "Finish preparing activity with editor.");
+    }
+
+    private String getInputMethodId() {
+        return mTargetPackageName + "/" + INPUT_METHOD_SERVICE_NAME;
+    }
+
+    private String executeShellCommand(String cmd) throws Exception {
+        Log.i(TAG, "Run command: " + cmd);
+        return UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
+                .executeShellCommand(cmd);
+    }
+
+    private void clickOnEditorText() {
+        // Find the editText and click it.
+        UiObject2 editTextUiObject =
+                mUiDevice.wait(
+                        Until.findObject(By.desc(EDIT_TEXT_DESC)),
+                        TimeUnit.SECONDS.toMillis(TIMEOUT_IN_SECONDS));
+        assertThat(editTextUiObject).isNotNull();
+        editTextUiObject.click();
+        mInstrumentation.waitForIdleSync();
+    }
+}
diff --git a/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/Android.bp b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/Android.bp
new file mode 100644
index 0000000..ef50476
--- /dev/null
+++ b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/Android.bp
@@ -0,0 +1,62 @@
+// 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 {
+    // See: http://go/android-license-faq
+    // A large-scale-change added 'default_applicable_licenses' to import
+    // all of the 'license_kinds' from "frameworks_base_license"
+    // to get the below license kinds:
+    //   SPDX-license-identifier-Apache-2.0
+    default_applicable_licenses: ["frameworks_base_license"],
+}
+
+android_test_helper_app {
+    name: "SimpleTestIme",
+
+    srcs: [
+        "src/com/android/apps/inputmethod/simpleime/*.java",
+    ],
+
+    static_libs: [
+        "SimpleImeImsLib",
+        "SimpleImeTestingLib",
+    ],
+    resource_dirs: ["res"],
+    manifest: "AndroidManifest.xml",
+
+    dex_preopt: {
+        enabled: false,
+    },
+    optimize: {
+        enabled: false,
+    },
+    export_package_resources: true,
+    sdk_version: "current",
+}
+
+android_library {
+    name: "SimpleImeImsLib",
+    srcs: [
+        "src/com/android/apps/inputmethod/simpleime/ims/*.java",
+    ],
+    sdk_version: "current",
+}
+
+android_library {
+    name: "SimpleImeTestingLib",
+    srcs: [
+        "src/com/android/apps/inputmethod/simpleime/testing/*.java",
+    ],
+    sdk_version: "current",
+}
diff --git a/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/AndroidManifest.xml b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/AndroidManifest.xml
new file mode 100644
index 0000000..802caf1
--- /dev/null
+++ b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/AndroidManifest.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ 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.
+  -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+          package="com.android.apps.inputmethod.simpleime">
+
+    <uses-sdk android:targetSdkVersion="31" />
+
+    <application android:debuggable="true"
+                 android:label="@string/app_name">
+        <service
+            android:name="com.android.apps.inputmethod.simpleime.SimpleInputMethodService"
+            android:label="@string/app_name"
+            android:directBootAware="true"
+            android:permission="android.permission.BIND_INPUT_METHOD"
+            android:exported="true">
+
+            <meta-data
+                android:name="android.view.im"
+                android:resource="@xml/method"/>
+
+            <intent-filter>
+                <action android:name="android.view.InputMethod"/>
+            </intent-filter>
+        </service>
+
+        <!-- This is for test only. -->
+        <activity android:name="com.android.apps.inputmethod.simpleime.testing.TestActivity"
+                  android:exported="false"
+                  android:label="TestActivity"
+                  android:launchMode="singleInstance"
+                  android:excludeFromRecents="true"
+                  android:noHistory="true"
+                  android:taskAffinity="">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+            </intent-filter>
+        </activity>
+    </application>
+</manifest>
\ No newline at end of file
diff --git a/packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/drawable/key_border.xml
similarity index 70%
copy from packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml
copy to services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/drawable/key_border.xml
index 1992c77..dbfcc30 100644
--- a/packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml
+++ b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/drawable/key_border.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!--
   ~ Copyright (C) 2022 The Android Open Source Project
   ~
@@ -14,7 +15,16 @@
   ~ limitations under the License.
   -->
 
-<shape xmlns:android="http://schemas.android.com/apk/res/android">
-    <solid android:color="@color/dream_overlay_aqi_unknown" />
-    <corners android:radius="@dimen/dream_aqi_badge_corner_radius" />
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+       android:shape="rectangle" >
+    <solid
+        android:color="#FAFAFA" >
+    </solid>
+    <stroke
+        android:width="1dp"
+        android:color="#0F000000" >
+    </stroke>
+    <corners
+        android:radius="2dp"   >
+    </corners>
 </shape>
\ No newline at end of file
diff --git a/packages/SystemUI/res/layout/dream_overlay_complication_weather.xml b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/layout/input_view.xml
similarity index 80%
rename from packages/SystemUI/res/layout/dream_overlay_complication_weather.xml
rename to services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/layout/input_view.xml
index f05922f..f229270 100644
--- a/packages/SystemUI/res/layout/dream_overlay_complication_weather.xml
+++ b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/layout/input_view.xml
@@ -13,10 +13,10 @@
   ~ 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.
--->
-<TextView
+  -->
+
+<FrameLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/weather_view"
-    style="@style/clock_subtitle"
-    android:layout_width="wrap_content"
-    android:layout_height="wrap_content" />
+    android:id="@+id/input"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"/>
\ No newline at end of file
diff --git a/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/layout/qwerty_10_9_9.xml b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/layout/qwerty_10_9_9.xml
new file mode 100644
index 0000000..ee94ea9
--- /dev/null
+++ b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/layout/qwerty_10_9_9.xml
@@ -0,0 +1,200 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ 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.
+  -->
+
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    style="@style/KeyboardArea">
+
+    <View style="@style/KeyboardRow.Header"/>
+
+    <LinearLayout style="@style/KeyboardRow">
+        <TextView
+            android:id="@+id/key_pos_0_0"
+            android:text="q"
+            android:tag="KEYCODE_Q"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_0_1"
+            android:text="w"
+            android:tag="KEYCODE_W"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_0_2"
+            android:text="e"
+            android:tag="KEYCODE_E"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_0_3"
+            android:text="r"
+            android:tag="KEYCODE_R"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_0_4"
+            android:text="t"
+            android:tag="KEYCODE_T"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_0_5"
+            android:text="y"
+            android:tag="KEYCODE_Y"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_0_6"
+            android:text="u"
+            android:tag="KEYCODE_U"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_0_7"
+            android:text="i"
+            android:tag="KEYCODE_I"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_0_8"
+            android:text="o"
+            android:tag="KEYCODE_O"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_0_9"
+            android:text="p"
+            android:tag="KEYCODE_P"
+            style="@style/SoftKey"/>
+    </LinearLayout>
+
+    <LinearLayout style="@style/KeyboardRow">
+        <TextView
+            android:id="@+id/key_pos_1_0"
+            android:text="a"
+            android:tag="KEYCODE_A"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_1_1"
+            android:text="s"
+            android:tag="KEYCODE_S"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_1_2"
+            android:text="d"
+            android:tag="KEYCODE_D"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_1_3"
+            android:text="f"
+            android:tag="KEYCODE_F"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_1_4"
+            android:text="g"
+            android:tag="KEYCODE_G"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_1_5"
+            android:text="h"
+            android:tag="KEYCODE_H"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_1_6"
+            android:text="j"
+            android:tag="KEYCODE_J"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_1_7"
+            android:text="k"
+            android:tag="KEYCODE_K"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_1_8"
+            android:text="l"
+            android:tag="KEYCODE_L"
+            style="@style/SoftKey"/>
+    </LinearLayout>
+
+    <LinearLayout style="@style/KeyboardRow">
+        <TextView
+            android:id="@+id/key_pos_shift"
+            android:text="SHI"
+            android:tag="KEYCODE_SHIFT"
+            style="@style/SoftKey.Function"/>
+        <TextView
+            android:id="@+id/key_pos_2_0"
+            android:text="z"
+            android:tag="KEYCODE_Z"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_2_1"
+            android:text="x"
+            android:tag="KEYCODE_X"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_2_2"
+            style="@style/SoftKey"
+            android:text="c"
+            android:tag="KEYCODE_C"/>
+        <TextView
+            android:id="@+id/key_pos_2_3"
+            android:text="v"
+            android:tag="KEYCODE_V"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_2_4"
+            android:text="b"
+            android:tag="KEYCODE_B"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_2_5"
+            android:text="n"
+            android:tag="KEYCODE_N"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_2_6"
+            android:text="m"
+            android:tag="KEYCODE_M"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_del"
+            android:text="DEL"
+            android:tag="KEYCODE_DEL"
+            style="@style/SoftKey.Function"/>
+    </LinearLayout>
+
+    <LinearLayout style="@style/KeyboardRow">
+        <TextView
+            android:id="@+id/key_pos_symbol"
+            android:text="TAB"
+            android:tag="KEYCODE_TAB"
+            style="@style/SoftKey.Function"/>
+        <TextView
+            android:id="@+id/key_pos_comma"
+            android:text=","
+            android:tag="KEYCODE_COMMA"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_space"
+            android:text="SPACE"
+            android:tag="KEYCODE_SPACE"
+            style="@style/SoftKey.Space"/>
+        <TextView
+            android:id="@+id/key_pos_period"
+            android:text="."
+            android:tag="KEYCODE_PERIOD"
+            style="@style/SoftKey"/>
+        <TextView
+            android:id="@+id/key_pos_enter"
+            android:text="ENT"
+            android:tag="KEYCODE_ENTER"
+            style="@style/SoftKey.Function.Bottom"/>
+    </LinearLayout>
+</LinearLayout>
diff --git a/packages/SystemUI/res/layout/dream_overlay_complication_weather.xml b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/values/dimens.xml
similarity index 73%
copy from packages/SystemUI/res/layout/dream_overlay_complication_weather.xml
copy to services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/values/dimens.xml
index f05922f..1a4959e 100644
--- a/packages/SystemUI/res/layout/dream_overlay_complication_weather.xml
+++ b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/values/dimens.xml
@@ -13,10 +13,12 @@
   ~ 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.
--->
-<TextView
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/weather_view"
-    style="@style/clock_subtitle"
-    android:layout_width="wrap_content"
-    android:layout_height="wrap_content" />
+  -->
+
+<resources>
+    <dimen name="text_size_normal">24dp</dimen>
+    <dimen name="text_size_symbol">14dp</dimen>
+
+    <dimen name="keyboard_header_height">40dp</dimen>
+    <dimen name="keyboard_row_height">50dp</dimen>
+</resources>
\ No newline at end of file
diff --git a/packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/values/strings.xml
similarity index 74%
copy from packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml
copy to services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/values/strings.xml
index 1992c77..11377fa 100644
--- a/packages/SystemUI/res/drawable/dream_aqi_badge_bg.xml
+++ b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/values/strings.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!--
   ~ Copyright (C) 2022 The Android Open Source Project
   ~
@@ -14,7 +15,6 @@
   ~ limitations under the License.
   -->
 
-<shape xmlns:android="http://schemas.android.com/apk/res/android">
-    <solid android:color="@color/dream_overlay_aqi_unknown" />
-    <corners android:radius="@dimen/dream_aqi_badge_corner_radius" />
-</shape>
\ No newline at end of file
+<resources>
+    <string name="app_name">Fake IME</string>
+</resources>
\ No newline at end of file
diff --git a/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/values/styles.xml b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/values/styles.xml
new file mode 100644
index 0000000..83f7bc3
--- /dev/null
+++ b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/values/styles.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ 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.
+  -->
+
+<resources>
+    <style name="KeyboardArea">
+        <item name="android:layout_width">match_parent</item>
+        <item name="android:layout_height">wrap_content</item>
+        <item name="android:layout_gravity">bottom</item>
+        <item name="android:orientation">vertical</item>
+        <item name="android:background">#FFFFFFFF</item>
+    </style>
+
+    <style name="KeyboardRow">
+        <item name="android:layout_width">match_parent</item>
+        <item name="android:layout_height">@dimen/keyboard_row_height</item>
+        <item name="android:orientation">horizontal</item>
+    </style>
+
+    <style name="KeyboardRow.Header">
+        <item name="android:layout_height">@dimen/keyboard_header_height</item>
+        <item name="android:background">#FFEEEEEE</item>
+    </style>
+
+    <style name="SoftKey">
+        <item name="android:layout_width">0dp</item>
+        <item name="android:layout_height">match_parent</item>
+        <item name="android:layout_weight">2</item>
+        <item name="android:gravity">center</item>
+        <item name="android:textColor">#FF000000</item>
+        <item name="android:textSize">@dimen/text_size_normal</item>
+        <item name="android:fontFamily">roboto-regular</item>
+        <item name="android:background">@drawable/key_border</item>
+    </style>
+
+    <style name="SoftKey.Function">
+        <item name="android:layout_weight">3</item>
+        <item name="android:textColor">#FF333333</item>
+        <item name="android:textSize">@dimen/text_size_symbol</item>
+    </style>
+
+    <style name="SoftKey.Function.Bottom">
+        <item name="android:layout_weight">3</item>
+        <item name="android:textColor">#FF333333</item>
+        <item name="android:textSize">@dimen/text_size_symbol</item>
+    </style>
+
+    <style name="SoftKey.Space">
+        <item name="android:layout_weight">10</item>
+        <item name="android:textColor">#FF333333</item>
+        <item name="android:textSize">@dimen/text_size_symbol</item>
+    </style>
+</resources>
\ No newline at end of file
diff --git a/packages/SystemUI/res/layout/dream_overlay_complication_weather.xml b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/xml/method.xml
similarity index 73%
copy from packages/SystemUI/res/layout/dream_overlay_complication_weather.xml
copy to services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/xml/method.xml
index f05922f..872b068 100644
--- a/packages/SystemUI/res/layout/dream_overlay_complication_weather.xml
+++ b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/res/xml/method.xml
@@ -13,10 +13,11 @@
   ~ 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.
--->
-<TextView
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/weather_view"
-    style="@style/clock_subtitle"
-    android:layout_width="wrap_content"
-    android:layout_height="wrap_content" />
+  -->
+
+<input-method xmlns:android="http://schemas.android.com/apk/res/android">
+    <subtype
+        android:label="FakeIme"
+        android:imeSubtypeLocale="en_US"
+        android:imeSubtypeMode="keyboard"/>
+</input-method>
\ No newline at end of file
diff --git a/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/KeyCodeConstants.java b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/KeyCodeConstants.java
new file mode 100644
index 0000000..990fa24
--- /dev/null
+++ b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/KeyCodeConstants.java
@@ -0,0 +1,68 @@
+/*
+ * 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.apps.inputmethod.simpleime;
+
+import android.view.KeyEvent;
+
+import java.util.HashMap;
+
+/** Holder of key codes and their name. */
+public final class KeyCodeConstants {
+    private KeyCodeConstants() {}
+
+    static final HashMap<String, Integer> KEY_NAME_TO_CODE_MAP = new HashMap<>();
+
+    static {
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_A", KeyEvent.KEYCODE_A);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_B", KeyEvent.KEYCODE_B);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_C", KeyEvent.KEYCODE_C);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_D", KeyEvent.KEYCODE_D);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_E", KeyEvent.KEYCODE_E);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_F", KeyEvent.KEYCODE_F);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_G", KeyEvent.KEYCODE_G);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_H", KeyEvent.KEYCODE_H);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_I", KeyEvent.KEYCODE_I);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_J", KeyEvent.KEYCODE_J);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_K", KeyEvent.KEYCODE_K);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_L", KeyEvent.KEYCODE_L);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_M", KeyEvent.KEYCODE_M);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_N", KeyEvent.KEYCODE_N);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_O", KeyEvent.KEYCODE_O);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_P", KeyEvent.KEYCODE_P);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_Q", KeyEvent.KEYCODE_Q);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_R", KeyEvent.KEYCODE_R);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_S", KeyEvent.KEYCODE_S);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_T", KeyEvent.KEYCODE_T);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_U", KeyEvent.KEYCODE_U);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_V", KeyEvent.KEYCODE_V);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_W", KeyEvent.KEYCODE_W);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_X", KeyEvent.KEYCODE_X);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_Y", KeyEvent.KEYCODE_Y);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_Z", KeyEvent.KEYCODE_Z);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_SHIFT", KeyEvent.KEYCODE_SHIFT_LEFT);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_DEL", KeyEvent.KEYCODE_DEL);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_SPACE", KeyEvent.KEYCODE_SPACE);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_ENTER", KeyEvent.KEYCODE_ENTER);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_COMMA", KeyEvent.KEYCODE_COMMA);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_PERIOD", KeyEvent.KEYCODE_PERIOD);
+        KEY_NAME_TO_CODE_MAP.put("KEYCODE_TAB", KeyEvent.KEYCODE_TAB);
+    }
+
+    public static boolean isAlphaKeyCode(int keyCode) {
+        return keyCode >= KeyEvent.KEYCODE_A && keyCode <= KeyEvent.KEYCODE_Z;
+    }
+}
diff --git a/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/SimpleInputMethodService.java b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/SimpleInputMethodService.java
new file mode 100644
index 0000000..48942a3
--- /dev/null
+++ b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/SimpleInputMethodService.java
@@ -0,0 +1,67 @@
+/*
+ * 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.apps.inputmethod.simpleime;
+
+import android.inputmethodservice.InputMethodService;
+import android.os.SystemClock;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.InputConnection;
+import android.widget.FrameLayout;
+
+import com.android.apps.inputmethod.simpleime.ims.InputMethodServiceWrapper;
+
+/** The {@link InputMethodService} implementation for SimpeTestIme app. */
+public class SimpleInputMethodService extends InputMethodServiceWrapper {
+    private static final String TAG = "SimpleIMS";
+
+    private FrameLayout mInputView;
+
+    @Override
+    public View onCreateInputView() {
+        Log.i(TAG, "onCreateInputView()");
+        mInputView = (FrameLayout) LayoutInflater.from(this).inflate(R.layout.input_view, null);
+        return mInputView;
+    }
+
+    @Override
+    public void onStartInputView(EditorInfo info, boolean restarting) {
+        super.onStartInputView(info, restarting);
+        mInputView.removeAllViews();
+        SimpleKeyboard keyboard = new SimpleKeyboard(this, R.layout.qwerty_10_9_9);
+        mInputView.addView(keyboard.inflateKeyboardView(LayoutInflater.from(this), mInputView));
+    }
+
+    void handle(String data, int keyboardState) {
+        InputConnection inputConnection = getCurrentInputConnection();
+        Integer keyCode = KeyCodeConstants.KEY_NAME_TO_CODE_MAP.get(data);
+        Log.v(TAG, "keyCode: " + keyCode);
+        if (keyCode != null) {
+            inputConnection.sendKeyEvent(
+                    new KeyEvent(
+                            SystemClock.uptimeMillis(),
+                            SystemClock.uptimeMillis(),
+                            KeyEvent.ACTION_DOWN,
+                            keyCode,
+                            0,
+                            KeyCodeConstants.isAlphaKeyCode(keyCode) ? keyboardState : 0));
+        }
+    }
+}
diff --git a/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/SimpleKeyboard.java b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/SimpleKeyboard.java
new file mode 100644
index 0000000..b16ec9eb
--- /dev/null
+++ b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/SimpleKeyboard.java
@@ -0,0 +1,126 @@
+/*
+ * 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.apps.inputmethod.simpleime;
+
+import android.text.TextUtils;
+import android.util.Log;
+import android.util.SparseArray;
+import android.view.KeyEvent;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+/** Controls the visible virtual keyboard view. */
+final class SimpleKeyboard {
+    private static final String TAG = "SimpleKeyboard";
+
+    private static final int[] SOFT_KEY_IDS =
+            new int[] {
+                R.id.key_pos_0_0,
+                R.id.key_pos_0_1,
+                R.id.key_pos_0_2,
+                R.id.key_pos_0_3,
+                R.id.key_pos_0_4,
+                R.id.key_pos_0_5,
+                R.id.key_pos_0_6,
+                R.id.key_pos_0_7,
+                R.id.key_pos_0_8,
+                R.id.key_pos_0_9,
+                R.id.key_pos_1_0,
+                R.id.key_pos_1_1,
+                R.id.key_pos_1_2,
+                R.id.key_pos_1_3,
+                R.id.key_pos_1_4,
+                R.id.key_pos_1_5,
+                R.id.key_pos_1_6,
+                R.id.key_pos_1_7,
+                R.id.key_pos_1_8,
+                R.id.key_pos_2_0,
+                R.id.key_pos_2_1,
+                R.id.key_pos_2_2,
+                R.id.key_pos_2_3,
+                R.id.key_pos_2_4,
+                R.id.key_pos_2_5,
+                R.id.key_pos_2_6,
+                R.id.key_pos_shift,
+                R.id.key_pos_del,
+                R.id.key_pos_symbol,
+                R.id.key_pos_comma,
+                R.id.key_pos_space,
+                R.id.key_pos_period,
+                R.id.key_pos_enter,
+            };
+
+    private final SimpleInputMethodService mSimpleInputMethodService;
+    private final int mViewResId;
+    private final SparseArray<TextView> mSoftKeyViews = new SparseArray<>();
+    private View mKeyboardView;
+    private int mKeyboardState;
+
+    SimpleKeyboard(SimpleInputMethodService simpleInputMethodService, int viewResId) {
+        this.mSimpleInputMethodService = simpleInputMethodService;
+        this.mViewResId = viewResId;
+        this.mKeyboardState = 0;
+    }
+
+    View inflateKeyboardView(LayoutInflater inflater, ViewGroup inputView) {
+        mKeyboardView = inflater.inflate(mViewResId, inputView, false);
+        mapSoftKeys();
+        return mKeyboardView;
+    }
+
+    private void mapSoftKeys() {
+        for (int id : SOFT_KEY_IDS) {
+            TextView softKeyView = mKeyboardView.findViewById(id);
+            mSoftKeyViews.put(id, softKeyView);
+            String tagData = softKeyView.getTag() != null ? softKeyView.getTag().toString() : null;
+            softKeyView.setOnClickListener(v -> handle(tagData));
+        }
+    }
+
+    private void handle(String data) {
+        Log.i(TAG, "handle(): " + data);
+        if (TextUtils.isEmpty(data)) {
+            return;
+        }
+        if ("KEYCODE_SHIFT".equals(data)) {
+            handleShift();
+            return;
+        }
+
+        mSimpleInputMethodService.handle(data, mKeyboardState);
+    }
+
+    private void handleShift() {
+        mKeyboardState = toggleShiftState(mKeyboardState);
+        Log.v(TAG, "currentKeyboardState: " + mKeyboardState);
+        boolean isShiftOn = isShiftOn(mKeyboardState);
+        for (int i = 0; i < mSoftKeyViews.size(); i++) {
+            TextView softKeyView = mSoftKeyViews.valueAt(i);
+            softKeyView.setAllCaps(isShiftOn);
+        }
+    }
+
+    private static boolean isShiftOn(int state) {
+        return (state & KeyEvent.META_SHIFT_ON) == KeyEvent.META_SHIFT_ON;
+    }
+
+    private static int toggleShiftState(int state) {
+        return state ^ KeyEvent.META_SHIFT_ON;
+    }
+}
diff --git a/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/ims/InputMethodServiceWrapper.java b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/ims/InputMethodServiceWrapper.java
new file mode 100644
index 0000000..b706a65
--- /dev/null
+++ b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/ims/InputMethodServiceWrapper.java
@@ -0,0 +1,102 @@
+/*
+ * 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.apps.inputmethod.simpleime.ims;
+
+import android.content.res.Configuration;
+import android.inputmethodservice.InputMethodService;
+import android.util.Log;
+import android.view.inputmethod.EditorInfo;
+
+import java.util.concurrent.CountDownLatch;
+
+/** Wrapper of {@link InputMethodService} to expose interfaces for testing purpose. */
+public class InputMethodServiceWrapper extends InputMethodService {
+    private static final String TAG = "InputMethodServiceWrapper";
+
+    private static InputMethodServiceWrapper sInputMethodServiceWrapper;
+
+    public static InputMethodServiceWrapper getInputMethodServiceWrapperForTesting() {
+        return sInputMethodServiceWrapper;
+    }
+
+    private boolean mInputViewStarted;
+    private CountDownLatch mCountDownLatchForTesting;
+
+    public boolean getCurrentInputViewStarted() {
+        return mInputViewStarted;
+    }
+
+    public void setCountDownLatchForTesting(CountDownLatch countDownLatchForTesting) {
+        mCountDownLatchForTesting = countDownLatchForTesting;
+    }
+
+    @Override
+    public void onCreate() {
+        Log.i(TAG, "onCreate()");
+        super.onCreate();
+        sInputMethodServiceWrapper = this;
+    }
+
+    @Override
+    public void onStartInput(EditorInfo info, boolean restarting) {
+        Log.i(TAG, "onStartInput() editor=" + info + ", restarting=" + restarting);
+        super.onStartInput(info, restarting);
+    }
+
+    @Override
+    public void onStartInputView(EditorInfo info, boolean restarting) {
+        Log.i(TAG, "onStartInputView() editor=" + info + ", restarting=" + restarting);
+        super.onStartInputView(info, restarting);
+        mInputViewStarted = true;
+        if (mCountDownLatchForTesting != null) {
+            mCountDownLatchForTesting.countDown();
+        }
+    }
+
+    @Override
+    public void onFinishInput() {
+        Log.i(TAG, "onFinishInput()");
+        super.onFinishInput();
+    }
+
+    @Override
+    public void onFinishInputView(boolean finishingInput) {
+        Log.i(TAG, "onFinishInputView()");
+        super.onFinishInputView(finishingInput);
+        mInputViewStarted = false;
+
+        if (mCountDownLatchForTesting != null) {
+            mCountDownLatchForTesting.countDown();
+        }
+    }
+
+    @Override
+    public void requestHideSelf(int flags) {
+        Log.i(TAG, "requestHideSelf() " + flags);
+        super.requestHideSelf(flags);
+    }
+
+    @Override
+    public void onConfigurationChanged(Configuration newConfig) {
+        Log.i(TAG, "onConfigurationChanged() " + newConfig);
+        super.onConfigurationChanged(newConfig);
+
+        if (mCountDownLatchForTesting != null) {
+            mCountDownLatchForTesting.countDown();
+        }
+    }
+}
diff --git a/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/testing/TestActivity.java b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/testing/TestActivity.java
new file mode 100644
index 0000000..0eec7e6
--- /dev/null
+++ b/services/tests/InputMethodSystemServerTests/test-apps/SimpleTestIme/src/com/android/apps/inputmethod/simpleime/testing/TestActivity.java
@@ -0,0 +1,105 @@
+/*
+ * 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.apps.inputmethod.simpleime.testing;
+
+import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
+import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
+
+import android.app.Activity;
+import android.app.Instrumentation;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.WindowInsets;
+import android.view.WindowInsetsController;
+import android.view.WindowManager;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+
+/**
+ * A special activity for testing purpose.
+ *
+ * <p>This is used when the instruments package is SimpleTestIme, as the Intent needs to be started
+ * in the instruments package. More details see {@link
+ * Instrumentation#startActivitySync(Intent)}.</>
+ */
+public class TestActivity extends Activity {
+    private static final String TAG = "TestActivity";
+
+    /**
+     * Start a new test activity with an editor and wait for it to begin running before returning.
+     *
+     * @param instrumentation application instrumentation
+     * @return the newly started activity
+     */
+    public static TestActivity start(Instrumentation instrumentation) {
+        Intent intent =
+                new Intent()
+                        .setAction(Intent.ACTION_MAIN)
+                        .setClass(instrumentation.getTargetContext(), TestActivity.class)
+                        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+        return (TestActivity) instrumentation.startActivitySync(intent);
+    }
+
+    public EditText mEditText;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
+        LinearLayout rootView = new LinearLayout(this);
+        mEditText = new EditText(this);
+        mEditText.setContentDescription("Input box");
+        rootView.addView(mEditText, new LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT));
+        setContentView(rootView);
+        mEditText.requestFocus();
+        super.onCreate(savedInstanceState);
+    }
+
+    /** Shows soft keyboard via InputMethodManager. */
+    public boolean showImeWithInputMethodManager(int flags) {
+        InputMethodManager imm = getSystemService(InputMethodManager.class);
+        boolean result = imm.showSoftInput(mEditText, flags);
+        Log.i(TAG, "hideIme() via InputMethodManager, result=" + result);
+        return result;
+    }
+
+    /** Shows soft keyboard via WindowInsetsController. */
+    public boolean showImeWithWindowInsetsController() {
+        WindowInsetsController windowInsetsController = mEditText.getWindowInsetsController();
+        windowInsetsController.show(WindowInsets.Type.ime());
+        Log.i(TAG, "showIme() via WindowInsetsController");
+        return true;
+    }
+
+    /** Hides soft keyboard via InputMethodManager. */
+    public boolean hideImeWithInputMethodManager(int flags) {
+        InputMethodManager imm = getSystemService(InputMethodManager.class);
+        boolean result = imm.hideSoftInputFromWindow(mEditText.getWindowToken(), flags);
+        Log.i(TAG, "hideIme() via InputMethodManager, result=" + result);
+        return result;
+    }
+
+    /** Hides soft keyboard via WindowInsetsController. */
+    public boolean hideImeWithWindowInsetsController() {
+        WindowInsetsController windowInsetsController = mEditText.getWindowInsetsController();
+        windowInsetsController.hide(WindowInsets.Type.ime());
+        Log.i(TAG, "hideIme() via WindowInsetsController");
+        return true;
+    }
+}
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/AppsFilterImplTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/AppsFilterImplTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/AppsFilterImplTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/AppsFilterImplTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/BundleUtilsTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/BundleUtilsTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/BundleUtilsTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/BundleUtilsTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/CompatibilityModeTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/CompatibilityModeTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/CompatibilityModeTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/CompatibilityModeTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/CrossProfileAppsServiceImplTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/CrossProfileAppsServiceImplTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/CrossProfileAppsServiceImplTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/CrossProfileAppsServiceImplTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/InstallerTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/InstallerTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/InstallerTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/InstallerTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/KeySetManagerServiceTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/KeySetManagerServiceTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/KeySetManagerServiceTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/KeySetManagerServiceTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/KeySetStrings.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/KeySetStrings.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/KeySetStrings.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/KeySetStrings.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/KeySetUtils.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/KeySetUtils.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/KeySetUtils.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/KeySetUtils.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/ModuleInfoProviderTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/ModuleInfoProviderTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/ModuleInfoProviderTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/ModuleInfoProviderTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/PackageInstallerSessionTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/PackageInstallerSessionTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/PackageInstallerSessionTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/PackageInstallerSessionTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/PackageManagerServiceTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/PackageManagerServiceTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/PackageManagerServiceTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/PackageManagerServiceTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/PackageManagerSettingsTests.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/PackageManagerSettingsTests.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/PackageManagerSettingsTests.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/PackageManagerSettingsTests.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/PackageManagerTests.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/PackageManagerTests.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/PackageManagerTests.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/PackageManagerTests.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/PackageParserTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/PackageParserTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/PackageParserTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/PackageParserTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/PackageSignaturesTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/PackageSignaturesTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/PackageSignaturesTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/PackageSignaturesTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/PackageUserStateTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/PackageUserStateTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/PackageUserStateTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/PackageUserStateTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/PackageVerificationStateTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/PackageVerificationStateTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/PackageVerificationStateTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/PackageVerificationStateTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/ParallelPackageParserTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/ParallelPackageParserTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/ParallelPackageParserTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/ParallelPackageParserTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/PreferredComponentTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/PreferredComponentTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/PreferredComponentTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/PreferredComponentTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/RestrictionsSetTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/RestrictionsSetTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/RestrictionsSetTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/RestrictionsSetTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/ScanRequestBuilder.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/ScanRequestBuilder.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/ScanRequestBuilder.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/ScanRequestBuilder.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/ScanTests.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/ScanTests.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/ScanTests.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/ScanTests.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/UserDataPreparerTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/UserDataPreparerTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/UserDataPreparerTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/UserDataPreparerTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/WatchedIntentHandlingTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/WatchedIntentHandlingTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/WatchedIntentHandlingTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/WatchedIntentHandlingTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/PackageParserLegacyCoreTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/PackageParserLegacyCoreTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/PackageParserLegacyCoreTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/PackageParserLegacyCoreTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/PackageParsingDeferErrorTest.kt b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/PackageParsingDeferErrorTest.kt
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/PackageParsingDeferErrorTest.kt
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/PackageParsingDeferErrorTest.kt
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/SystemPartitionParseTest.kt b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/SystemPartitionParseTest.kt
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/SystemPartitionParseTest.kt
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/SystemPartitionParseTest.kt
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/AndroidHidlUpdaterTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/AndroidHidlUpdaterTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/AndroidHidlUpdaterTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/AndroidHidlUpdaterTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/AndroidNetIpSecIkeUpdaterTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/AndroidNetIpSecIkeUpdaterTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/AndroidNetIpSecIkeUpdaterTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/AndroidNetIpSecIkeUpdaterTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/AndroidTestBaseUpdaterTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/AndroidTestBaseUpdaterTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/AndroidTestBaseUpdaterTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/AndroidTestBaseUpdaterTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/AndroidTestRunnerSplitUpdaterTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/AndroidTestRunnerSplitUpdaterTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/AndroidTestRunnerSplitUpdaterTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/AndroidTestRunnerSplitUpdaterTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/ApexSharedLibraryUpdaterTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/ApexSharedLibraryUpdaterTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/ApexSharedLibraryUpdaterTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/ApexSharedLibraryUpdaterTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/ComGoogleAndroidMapsUpdaterTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/ComGoogleAndroidMapsUpdaterTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/ComGoogleAndroidMapsUpdaterTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/ComGoogleAndroidMapsUpdaterTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/OptionalClassRunner.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/OptionalClassRunner.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/OptionalClassRunner.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/OptionalClassRunner.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/OrgApacheHttpLegacyUpdaterTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/OrgApacheHttpLegacyUpdaterTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/OrgApacheHttpLegacyUpdaterTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/OrgApacheHttpLegacyUpdaterTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/PackageBackwardCompatibilityTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/PackageBackwardCompatibilityTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/PackageBackwardCompatibilityTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/PackageBackwardCompatibilityTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/PackageSharedLibraryUpdaterTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/PackageSharedLibraryUpdaterTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/PackageSharedLibraryUpdaterTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/PackageSharedLibraryUpdaterTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/RemoveUnnecessaryAndroidTestBaseLibraryTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/RemoveUnnecessaryAndroidTestBaseLibraryTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/RemoveUnnecessaryAndroidTestBaseLibraryTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/RemoveUnnecessaryAndroidTestBaseLibraryTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/RemoveUnnecessaryOrgApacheHttpLegacyLibraryTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/RemoveUnnecessaryOrgApacheHttpLegacyLibraryTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/parsing/library/RemoveUnnecessaryOrgApacheHttpLegacyLibraryTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/parsing/library/RemoveUnnecessaryOrgApacheHttpLegacyLibraryTest.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/utils/OWNERS b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/utils/OWNERS
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/utils/OWNERS
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/utils/OWNERS
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/utils/WatchableTester.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/utils/WatchableTester.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/utils/WatchableTester.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/utils/WatchableTester.java
diff --git a/services/tests/PackageManagerServiceTests/server/src/com/android/server/utils/WatcherTest.java b/services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/utils/WatcherTest.java
similarity index 100%
rename from services/tests/PackageManagerServiceTests/server/src/com/android/server/utils/WatcherTest.java
rename to services/tests/PackageManagerServiceTests/server/src/com/android/server/pm/utils/WatcherTest.java
diff --git a/services/tests/mockingservicestests/assets/AppOpsUpgradeTest/appops-version-1.xml b/services/tests/mockingservicestests/assets/AppOpsUpgradeTest/appops-version-1.xml
new file mode 100644
index 0000000..1dde7dc
--- /dev/null
+++ b/services/tests/mockingservicestests/assets/AppOpsUpgradeTest/appops-version-1.xml
@@ -0,0 +1,781 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>

+<app-ops v="1">

+  <uid n="1001">

+    <op n="0" m="4" />

+    <op n="1" m="4" />

+    <op n="15" m="0" />

+    <op n="27" m="4" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="1002">

+    <op n="0" m="4" />

+    <op n="1" m="4" />

+    <op n="15" m="0" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10077">

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10079">

+    <op n="116" m="1" />

+  </uid>

+  <uid n="10080">

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10081">

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10086">

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10087">

+    <op n="59" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10090">

+    <op n="0" m="4" />

+    <op n="1" m="4" />

+  </uid>

+  <uid n="10096">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+  </uid>

+  <uid n="10112">

+    <op n="11" m="1" />

+    <op n="51" m="1" />

+    <op n="59" m="1" />

+    <op n="62" m="1" />

+    <op n="81" m="1" />

+    <op n="83" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10113">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+    <op n="51" m="1" />

+    <op n="62" m="1" />

+  </uid>

+  <uid n="10114">

+    <op n="4" m="1" />

+  </uid>

+  <uid n="10115">

+    <op n="0" m="1" />

+  </uid>

+  <uid n="10116">

+    <op n="0" m="1" />

+  </uid>

+  <uid n="10117">

+    <op n="0" m="4" />

+    <op n="1" m="4" />

+    <op n="13" m="1" />

+    <op n="14" m="1" />

+    <op n="16" m="1" />

+    <op n="26" m="4" />

+    <op n="27" m="4" />

+  </uid>

+  <uid n="10118">

+    <op n="51" m="1" />

+  </uid>

+  <uid n="10119">

+    <op n="11" m="1" />

+    <op n="77" m="1" />

+    <op n="111" m="1" />

+  </uid>

+  <uid n="10120">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+    <op n="4" m="1" />

+    <op n="6" m="1" />

+    <op n="7" m="1" />

+    <op n="11" m="1" />

+    <op n="13" m="1" />

+    <op n="26" m="1" />

+    <op n="27" m="1" />

+    <op n="54" m="1" />

+    <op n="59" m="1" />

+    <op n="81" m="1" />

+    <op n="83" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10121">

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10122">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+    <op n="51" m="1" />

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="81" m="1" />

+    <op n="83" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10123">

+    <op n="0" m="4" />

+    <op n="1" m="4" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10124">

+    <op n="11" m="1" />

+    <op n="26" m="1" />

+  </uid>

+  <uid n="10125">

+    <op n="11" m="1" />

+  </uid>

+  <uid n="10127">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+    <op n="26" m="4" />

+    <op n="27" m="4" />

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="65" m="1" />

+    <op n="81" m="1" />

+    <op n="83" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+    <op n="111" m="1" />

+  </uid>

+  <uid n="10129">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+  </uid>

+  <uid n="10130">

+    <op n="51" m="1" />

+  </uid>

+  <uid n="10131">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="81" m="1" />

+    <op n="83" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10132">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+    <op n="26" m="1" />

+    <op n="27" m="1" />

+    <op n="69" m="1" />

+    <op n="79" m="1" />

+  </uid>

+  <uid n="10133">

+    <op n="11" m="1" />

+  </uid>

+  <uid n="10136">

+    <op n="0" m="1" />

+    <op n="4" m="1" />

+    <op n="77" m="1" />

+    <op n="87" m="1" />

+    <op n="111" m="1" />

+    <op n="114" m="1" />

+  </uid>

+  <uid n="10137">

+    <op n="62" m="1" />

+  </uid>

+  <uid n="10138">

+    <op n="26" m="4" />

+  </uid>

+  <uid n="10140">

+    <op n="26" m="4" />

+    <op n="27" m="4" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10141">

+    <op n="11" m="1" />

+    <op n="27" m="1" />

+    <op n="111" m="1" />

+  </uid>

+  <uid n="10142">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+    <op n="11" m="1" />

+  </uid>

+  <uid n="10144">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+    <op n="4" m="1" />

+    <op n="11" m="1" />

+    <op n="27" m="4" />

+    <op n="111" m="1" />

+  </uid>

+  <uid n="10145">

+    <op n="11" m="1" />

+  </uid>

+  <uid n="10149">

+    <op n="11" m="1" />

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="81" m="1" />

+    <op n="83" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10150">

+    <op n="51" m="1" />

+  </uid>

+  <uid n="10151">

+    <op n="11" m="1" />

+  </uid>

+  <uid n="10152">

+    <op n="11" m="1" />

+  </uid>

+  <uid n="10154">

+    <op n="0" m="4" />

+    <op n="1" m="4" />

+    <op n="27" m="4" />

+  </uid>

+  <uid n="10155">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+  </uid>

+  <uid n="10157">

+    <op n="13" m="1" />

+  </uid>

+  <uid n="10158">

+    <op n="11" m="1" />

+  </uid>

+  <uid n="10160">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+    <op n="11" m="1" />

+    <op n="26" m="4" />

+    <op n="27" m="4" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10161">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+    <op n="11" m="1" />

+    <op n="51" m="1" />

+    <op n="77" m="1" />

+    <op n="87" m="1" />

+    <op n="111" m="1" />

+    <op n="114" m="1" />

+  </uid>

+  <uid n="10162">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+    <op n="15" m="0" />

+    <op n="26" m="4" />

+    <op n="27" m="4" />

+    <op n="87" m="1" />

+    <op n="89" m="0" />

+  </uid>

+  <uid n="10163">

+    <op n="26" m="4" />

+    <op n="27" m="4" />

+    <op n="56" m="4" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10164">

+    <op n="26" m="1" />

+    <op n="27" m="4" />

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="69" m="1" />

+    <op n="79" m="1" />

+    <op n="81" m="1" />

+    <op n="83" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10169">

+    <op n="11" m="1" />

+  </uid>

+  <uid n="10170">

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10171">

+    <op n="26" m="1" />

+    <op n="51" m="1" />

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="81" m="1" />

+    <op n="83" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10172">

+    <op n="11" m="1" />

+  </uid>

+  <uid n="10173">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+    <op n="23" m="0" />

+    <op n="26" m="1" />

+    <op n="51" m="1" />

+    <op n="62" m="1" />

+    <op n="65" m="1" />

+  </uid>

+  <uid n="10175">

+    <op n="0" m="1" />

+    <op n="11" m="1" />

+    <op n="26" m="1" />

+    <op n="27" m="1" />

+  </uid>

+  <uid n="10178">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+    <op n="11" m="1" />

+    <op n="27" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10179">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+    <op n="4" m="1" />

+    <op n="11" m="1" />

+    <op n="26" m="1" />

+    <op n="27" m="1" />

+    <op n="51" m="1" />

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="62" m="1" />

+    <op n="81" m="1" />

+    <op n="83" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10180">

+    <op n="11" m="1" />

+  </uid>

+  <uid n="10181">

+    <op n="4" m="1" />

+    <op n="11" m="1" />

+    <op n="26" m="1" />

+    <op n="27" m="1" />

+    <op n="59" m="1" />

+    <op n="62" m="1" />

+    <op n="81" m="1" />

+    <op n="83" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="1110181">

+    <op n="4" m="1" />

+    <op n="11" m="1" />

+    <op n="26" m="1" />

+    <op n="27" m="1" />

+    <op n="81" m="1" />

+    <op n="83" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+    <op n="107" m="2" />

+  </uid>

+  <uid n="10182">

+    <op n="27" m="4" />

+  </uid>

+  <uid n="10183">

+    <op n="11" m="1" />

+    <op n="26" m="4" />

+  </uid>

+  <uid n="10184">

+    <op n="4" m="1" />

+    <op n="11" m="1" />

+    <op n="13" m="1" />

+    <op n="26" m="1" />

+    <op n="27" m="4" />

+  </uid>

+  <uid n="10185">

+    <op n="8" m="1" />

+    <op n="59" m="1" />

+    <op n="81" m="1" />

+    <op n="83" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10187">

+    <op n="11" m="1" />

+  </uid>

+  <uid n="10189">

+    <op n="11" m="1" />

+    <op n="26" m="1" />

+    <op n="27" m="1" />

+    <op n="51" m="1" />

+  </uid>

+  <uid n="10190">

+    <op n="0" m="1" />

+    <op n="13" m="1" />

+  </uid>

+  <uid n="10191">

+    <op n="11" m="1" />

+  </uid>

+  <uid n="10192">

+    <op n="11" m="1" />

+    <op n="13" m="1" />

+    <op n="26" m="1" />

+    <op n="27" m="1" />

+    <op n="51" m="1" />

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="81" m="1" />

+    <op n="83" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10193">

+    <op n="11" m="1" />

+  </uid>

+  <uid n="10197">

+    <op n="11" m="1" />

+  </uid>

+  <uid n="10198">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+    <op n="4" m="1" />

+    <op n="11" m="1" />

+    <op n="26" m="1" />

+    <op n="27" m="1" />

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="77" m="1" />

+    <op n="81" m="1" />

+    <op n="83" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+    <op n="90" m="1" />

+    <op n="107" m="0" />

+    <op n="111" m="1" />

+  </uid>

+  <uid n="10199">

+    <op n="4" m="1" />

+    <op n="11" m="1" />

+    <op n="26" m="1" />

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="62" m="1" />

+    <op n="81" m="1" />

+    <op n="83" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10200">

+    <op n="11" m="1" />

+    <op n="65" m="1" />

+    <op n="107" m="1" />

+  </uid>

+  <uid n="1110200">

+    <op n="11" m="1" />

+    <op n="65" m="1" />

+    <op n="107" m="2" />

+  </uid>

+  <uid n="10201">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+    <op n="4" m="1" />

+    <op n="11" m="1" />

+    <op n="51" m="1" />

+    <op n="62" m="1" />

+    <op n="84" m="0" />

+    <op n="86" m="0" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10206">

+    <op n="0" m="4" />

+    <op n="1" m="4" />

+    <op n="26" m="4" />

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10209">

+    <op n="11" m="1" />

+    <op n="51" m="1" />

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="81" m="1" />

+    <op n="83" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10210">

+    <op n="51" m="1" />

+  </uid>

+  <uid n="10212">

+    <op n="11" m="1" />

+    <op n="62" m="1" />

+  </uid>

+  <uid n="10214">

+    <op n="26" m="4" />

+  </uid>

+  <uid n="10216">

+    <op n="51" m="1" />

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10225">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+    <op n="51" m="1" />

+    <op n="59" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10229">

+    <op n="11" m="1" />

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="62" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10231">

+    <op n="51" m="1" />

+  </uid>

+  <uid n="10232">

+    <op n="51" m="1" />

+  </uid>

+  <uid n="10234">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+    <op n="11" m="1" />

+    <op n="13" m="1" />

+    <op n="20" m="1" />

+    <op n="26" m="1" />

+    <op n="27" m="1" />

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="81" m="1" />

+    <op n="83" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10235">

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10237">

+    <op n="0" m="4" />

+    <op n="1" m="4" />

+  </uid>

+  <uid n="10238">

+    <op n="26" m="4" />

+    <op n="27" m="4" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10240">

+    <op n="112" m="1" />

+  </uid>

+  <uid n="10241">

+    <op n="59" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10245">

+    <op n="13" m="1" />

+    <op n="51" m="1" />

+  </uid>

+  <uid n="10247">

+    <op n="0" m="1" />

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="81" m="1" />

+    <op n="83" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="0" />

+    <op n="90" m="1" />

+  </uid>

+  <uid n="10254">

+    <op n="11" m="1" />

+  </uid>

+  <uid n="10255">

+    <op n="11" m="1" />

+  </uid>

+  <uid n="10256">

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10258">

+    <op n="11" m="1" />

+  </uid>

+  <uid n="10260">

+    <op n="51" m="1" />

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <uid n="10262">

+    <op n="15" m="0" />

+  </uid>

+  <uid n="10266">

+    <op n="0" m="4" />

+  </uid>

+  <uid n="10267">

+    <op n="0" m="1" />

+    <op n="1" m="1" />

+    <op n="4" m="1" />

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="62" m="1" />

+    <op n="77" m="1" />

+    <op n="81" m="1" />

+    <op n="83" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+    <op n="107" m="2" />

+    <op n="111" m="1" />

+  </uid>

+  <uid n="10268">

+    <op n="4" m="1" />

+    <op n="11" m="1" />

+    <op n="62" m="1" />

+  </uid>

+  <uid n="10269">

+    <op n="11" m="1" />

+    <op n="26" m="1" />

+    <op n="27" m="1" />

+    <op n="59" m="1" />

+    <op n="60" m="1" />

+    <op n="85" m="1" />

+    <op n="87" m="1" />

+  </uid>

+  <pkg n="com.google.android.iwlan">

+    <uid n="0">

+      <op n="1" />

+      <op n="75" m="0" />

+    </uid>

+  </pkg>

+  <pkg n="com.android.phone">

+    <uid n="0">

+      <op n="1" />

+      <op n="75" m="0" />

+    </uid>

+  </pkg>

+  <pkg n="android">

+    <uid n="1000">

+      <op n="0">

+        <st n="214748364801" t="1670287941040" />

+      </op>

+      <op n="4">

+        <st n="214748364801" t="1670289665522" />

+      </op>

+      <op n="6">

+        <st n="214748364801" t="1670287946650" />

+      </op>

+      <op n="8">

+        <st n="214748364801" t="1670289624396" />

+      </op>

+      <op n="14">

+        <st n="214748364801" t="1670287951031" />

+      </op>

+      <op n="40">

+        <st n="214748364801" t="1670291786337" d="156" />

+      </op>

+      <op n="41">

+        <st id="SensorNotificationService" n="214748364801" t="1670287585567" d="4251183" />

+        <st id="CountryDetector" n="214748364801" t="1670287583306" d="6700" />

+      </op>

+      <op n="43">

+        <st n="214748364801" r="1670291755062" />

+      </op>

+      <op n="61">

+        <st n="214748364801" r="1670291754997" />

+      </op>

+      <op n="105">

+        <st n="214748364801" r="1670291473903" />

+        <st id="GnssService" n="214748364801" r="1670288044920" />

+      </op>

+      <op n="111">

+        <st n="214748364801" t="1670291441554" />

+      </op>

+    </uid>

+  </pkg>

+  <pkg n="com.android.server.telecom">

+    <uid n="1000">

+      <op n="6">

+        <st n="214748364801" t="1670287609092" />

+      </op>

+      <op n="111">

+        <st n="214748364801" t="1670287583728" />

+      </op>

+    </uid>

+  </pkg>

+  <pkg n="com.android.settings">

+    <uid n="1000">

+      <op n="43">

+        <st n="214748364801" r="1670291447349" />

+      </op>

+      <op n="105">

+        <st n="214748364801" r="1670291399231" />

+      </op>

+      <op n="111">

+        <st n="214748364801" t="1670291756910" />

+      </op>

+    </uid>

+  </pkg>

+  <pkg n="com.android.phone">

+    <uid n="1001">

+      <op n="15">

+        <st n="214748364801" t="1670287951022" />

+      </op>

+      <op n="40">

+        <st n="214748364801" t="1670291786177" />

+      </op>

+      <op n="105">

+        <st n="214748364801" r="1670291756403" />

+      </op>

+    </uid>

+  </pkg>

+  <pkg n="com.android.bluetooth">

+    <uid n="1002">

+      <op n="4">

+        <st n="214748364801" t="1670289671076" />

+      </op>

+      <op n="40">

+        <st n="214748364801" t="1670287585676" d="8" />

+      </op>

+      <op n="43">

+        <st n="214748364801" r="1670287585818" />

+      </op>

+      <op n="77">

+        <st n="214748364801" t="1670288037629" />

+      </op>

+      <op n="111">

+        <st n="214748364801" t="1670287592081" />

+      </op>

+    </uid>

+  </pkg>

+  <pkg n="com.android.vending">

+    <uid n="10136">

+      <op n="40">

+        <st n="429496729601" t="1670289621210" d="114" />

+        <st n="858993459201" t="1670289879730" d="349" />

+        <st n="1288490188801" t="1670287942622" d="937" />

+      </op>

+      <op n="43">

+        <st n="429496729601" r="1670289755305" />

+        <st n="858993459201" r="1670288019246" />

+        <st n="1073741824001" r="1670289571783" />

+        <st n="1288490188801" r="1670289373336" />

+      </op>

+      <op n="76">

+        <st n="429496729601" t="1670289748735" d="15991" />

+        <st n="858993459201" t="1670291395180" d="79201" />

+        <st n="1073741824001" t="1670291395168" d="12" />

+        <st n="1288490188801" t="1670291526029" d="3" />

+        <st n="1503238553601" t="1670291526032" d="310718" />

+      </op>

+      <op n="105">

+        <st n="429496729601" r="1670289538910" />

+        <st n="858993459201" r="1670288054519" />

+        <st n="1073741824001" r="1670287599379" />

+        <st n="1288490188801" r="1670289526854" />

+        <st n="1503238553601" r="1670289528242" />

+      </op>

+    </uid>

+  </pkg>

+  <pkg n="com.android.nfc">

+    <uid n="1027">

+      <op n="40">

+        <st n="214748364801" t="1670291786330" d="22" />

+      </op>

+    </uid>

+  </pkg>

+</app-ops>
\ No newline at end of file
diff --git a/services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueModernImplTest.java b/services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueModernImplTest.java
index de09b19..8d78cd6 100644
--- a/services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueModernImplTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueModernImplTest.java
@@ -195,6 +195,12 @@
                 false, null, false, null);
     }
 
+    private void enqueueOrReplaceBroadcast(BroadcastProcessQueue queue,
+            BroadcastRecord record, int recordIndex, long enqueueTime) {
+        queue.enqueueOrReplaceBroadcast(record, recordIndex);
+        record.enqueueTime = enqueueTime;
+    }
+
     @Test
     public void testRunnableList_Simple() {
         assertRunnableList(List.of(), mHead);
@@ -549,29 +555,32 @@
         mConstants.MAX_CONSECUTIVE_URGENT_DISPATCHES = 2;
         BroadcastProcessQueue queue = new BroadcastProcessQueue(mConstants,
                 PACKAGE_GREEN, getUidForPackage(PACKAGE_GREEN));
+        long timeCounter = 100;
 
         // mix of broadcasts, with more than 2 fg/urgent
-        queue.enqueueOrReplaceBroadcast(
-                makeBroadcastRecord(new Intent(Intent.ACTION_TIMEZONE_CHANGED)), 0);
-        queue.enqueueOrReplaceBroadcast(
-                makeBroadcastRecord(new Intent(Intent.ACTION_ALARM_CHANGED)), 0);
-        queue.enqueueOrReplaceBroadcast(
-                makeBroadcastRecord(new Intent(Intent.ACTION_TIME_TICK)), 0);
-        queue.enqueueOrReplaceBroadcast(
+        enqueueOrReplaceBroadcast(queue,
+                makeBroadcastRecord(new Intent(Intent.ACTION_TIMEZONE_CHANGED)),
+                        0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
+                makeBroadcastRecord(new Intent(Intent.ACTION_ALARM_CHANGED)),
+                        0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
+                makeBroadcastRecord(new Intent(Intent.ACTION_TIME_TICK)), 0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
                 makeBroadcastRecord(new Intent(Intent.ACTION_LOCALE_CHANGED)
-                        .addFlags(Intent.FLAG_RECEIVER_FOREGROUND)), 0);
-        queue.enqueueOrReplaceBroadcast(
+                        .addFlags(Intent.FLAG_RECEIVER_FOREGROUND)), 0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
                 makeBroadcastRecord(new Intent(Intent.ACTION_APPLICATION_PREFERENCES),
-                        optInteractive), 0);
-        queue.enqueueOrReplaceBroadcast(
+                        optInteractive), 0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
                 makeBroadcastRecord(new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE),
-                        optInteractive), 0);
-        queue.enqueueOrReplaceBroadcast(
+                        optInteractive), 0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
                 makeBroadcastRecord(new Intent(Intent.ACTION_INPUT_METHOD_CHANGED)
-                        .addFlags(Intent.FLAG_RECEIVER_FOREGROUND)), 0);
-        queue.enqueueOrReplaceBroadcast(
+                        .addFlags(Intent.FLAG_RECEIVER_FOREGROUND)), 0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
                 makeBroadcastRecord(new Intent(Intent.ACTION_NEW_OUTGOING_CALL),
-                        optInteractive), 0);
+                        optInteractive), 0, timeCounter++);
 
         queue.makeActiveNextPending();
         assertEquals(Intent.ACTION_LOCALE_CHANGED, queue.getActive().intent.getAction());
@@ -604,35 +613,38 @@
         mConstants.MAX_CONSECUTIVE_NORMAL_DISPATCHES = 2;
         final BroadcastProcessQueue queue = new BroadcastProcessQueue(mConstants,
                 PACKAGE_GREEN, getUidForPackage(PACKAGE_GREEN));
+        long timeCounter = 100;
 
         // mix of broadcasts, with more than 2 normal
-        queue.enqueueOrReplaceBroadcast(
+        enqueueOrReplaceBroadcast(queue,
                 makeBroadcastRecord(new Intent(Intent.ACTION_BOOT_COMPLETED)
-                        .addFlags(Intent.FLAG_RECEIVER_OFFLOAD)), 0);
-        queue.enqueueOrReplaceBroadcast(
-                makeBroadcastRecord(new Intent(Intent.ACTION_TIMEZONE_CHANGED)), 0);
-        queue.enqueueOrReplaceBroadcast(
+                        .addFlags(Intent.FLAG_RECEIVER_OFFLOAD)), 0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
+                makeBroadcastRecord(new Intent(Intent.ACTION_TIMEZONE_CHANGED)),
+                        0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
                 makeBroadcastRecord(new Intent(Intent.ACTION_PACKAGE_CHANGED)
-                        .addFlags(Intent.FLAG_RECEIVER_OFFLOAD)), 0);
-        queue.enqueueOrReplaceBroadcast(
-                makeBroadcastRecord(new Intent(Intent.ACTION_ALARM_CHANGED)), 0);
-        queue.enqueueOrReplaceBroadcast(
-                makeBroadcastRecord(new Intent(Intent.ACTION_TIME_TICK)), 0);
-        queue.enqueueOrReplaceBroadcast(
+                        .addFlags(Intent.FLAG_RECEIVER_OFFLOAD)), 0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
+                makeBroadcastRecord(new Intent(Intent.ACTION_ALARM_CHANGED)),
+                0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
+                makeBroadcastRecord(new Intent(Intent.ACTION_TIME_TICK)), 0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
                 makeBroadcastRecord(new Intent(Intent.ACTION_LOCALE_CHANGED)
-                        .addFlags(Intent.FLAG_RECEIVER_FOREGROUND)), 0);
-        queue.enqueueOrReplaceBroadcast(
+                        .addFlags(Intent.FLAG_RECEIVER_FOREGROUND)), 0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
                 makeBroadcastRecord(new Intent(Intent.ACTION_APPLICATION_PREFERENCES),
-                        optInteractive), 0);
-        queue.enqueueOrReplaceBroadcast(
+                        optInteractive), 0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
                 makeBroadcastRecord(new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE),
-                        optInteractive), 0);
-        queue.enqueueOrReplaceBroadcast(
+                        optInteractive), 0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
                 makeBroadcastRecord(new Intent(Intent.ACTION_INPUT_METHOD_CHANGED)
-                        .addFlags(Intent.FLAG_RECEIVER_FOREGROUND)), 0);
-        queue.enqueueOrReplaceBroadcast(
+                        .addFlags(Intent.FLAG_RECEIVER_FOREGROUND)), 0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
                 makeBroadcastRecord(new Intent(Intent.ACTION_NEW_OUTGOING_CALL),
-                        optInteractive), 0);
+                        optInteractive), 0, timeCounter++);
 
         queue.makeActiveNextPending();
         assertEquals(Intent.ACTION_LOCALE_CHANGED, queue.getActive().intent.getAction());
@@ -659,6 +671,63 @@
     }
 
     /**
+     * Verify that BroadcastProcessQueue#setPrioritizeEarliest() works as expected.
+     */
+    @Test
+    public void testPrioritizeEarliest() {
+        final BroadcastOptions optInteractive = BroadcastOptions.makeBasic();
+        optInteractive.setInteractive(true);
+
+        BroadcastProcessQueue queue = new BroadcastProcessQueue(mConstants,
+                PACKAGE_GREEN, getUidForPackage(PACKAGE_GREEN));
+        queue.setPrioritizeEarliest(true);
+        long timeCounter = 100;
+
+        enqueueOrReplaceBroadcast(queue,
+                makeBroadcastRecord(new Intent(Intent.ACTION_BOOT_COMPLETED)
+                        .addFlags(Intent.FLAG_RECEIVER_OFFLOAD)), 0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
+                makeBroadcastRecord(new Intent(Intent.ACTION_TIMEZONE_CHANGED)),
+                        0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
+                makeBroadcastRecord(new Intent(Intent.ACTION_PACKAGE_CHANGED)
+                        .addFlags(Intent.FLAG_RECEIVER_OFFLOAD)), 0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
+                makeBroadcastRecord(new Intent(Intent.ACTION_ALARM_CHANGED)),
+                        0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
+                makeBroadcastRecord(new Intent(Intent.ACTION_TIME_TICK)),
+                        0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
+                makeBroadcastRecord(new Intent(Intent.ACTION_LOCALE_CHANGED)
+                        .addFlags(Intent.FLAG_RECEIVER_FOREGROUND)), 0, timeCounter++);
+        enqueueOrReplaceBroadcast(queue,
+                makeBroadcastRecord(new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE),
+                        optInteractive), 0, timeCounter++);
+
+        // When we mark BroadcastProcessQueue to prioritize earliest, we should
+        // expect to dispatch broadcasts in the order they were enqueued
+        queue.makeActiveNextPending();
+        assertEquals(Intent.ACTION_BOOT_COMPLETED, queue.getActive().intent.getAction());
+        queue.makeActiveNextPending();
+        assertEquals(Intent.ACTION_TIMEZONE_CHANGED, queue.getActive().intent.getAction());
+        // after MAX_CONSECUTIVE_URGENT_DISPATCHES expect an ordinary one next
+        queue.makeActiveNextPending();
+        assertEquals(Intent.ACTION_PACKAGE_CHANGED, queue.getActive().intent.getAction());
+        // and then back to prioritizing urgent ones
+        queue.makeActiveNextPending();
+        assertEquals(Intent.ACTION_ALARM_CHANGED, queue.getActive().intent.getAction());
+        queue.makeActiveNextPending();
+        assertEquals(Intent.ACTION_TIME_TICK, queue.getActive().intent.getAction());
+        queue.makeActiveNextPending();
+        assertEquals(Intent.ACTION_LOCALE_CHANGED, queue.getActive().intent.getAction());
+        // verify the reset-count-then-resume worked too
+        queue.makeActiveNextPending();
+        assertEquals(AppWidgetManager.ACTION_APPWIDGET_UPDATE,
+                queue.getActive().intent.getAction());
+    }
+
+    /**
      * Verify that sending a broadcast that removes any matching pending
      * broadcasts is applied as expected.
      */
diff --git a/services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueTest.java b/services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueTest.java
index b9615f6..d79c4d8 100644
--- a/services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/am/BroadcastQueueTest.java
@@ -50,6 +50,7 @@
 import android.app.AppOpsManager;
 import android.app.BroadcastOptions;
 import android.app.IApplicationThread;
+import android.app.ReceiverInfo;
 import android.app.usage.UsageEvents.Event;
 import android.app.usage.UsageStatsManagerInternal;
 import android.content.ComponentName;
@@ -62,6 +63,7 @@
 import android.content.pm.PackageManager;
 import android.content.pm.PackageManagerInternal;
 import android.content.pm.ResolveInfo;
+import android.content.res.CompatibilityInfo;
 import android.os.Binder;
 import android.os.Bundle;
 import android.os.DeadObjectException;
@@ -262,6 +264,7 @@
             return res;
         }).when(mAms).startProcessLocked(any(), any(), anyBoolean(), anyInt(),
                 any(), anyInt(), anyBoolean(), anyBoolean());
+
         doAnswer((invocation) -> {
             final String processName = invocation.getArgument(0);
             final int uid = invocation.getArgument(1);
@@ -295,12 +298,16 @@
         };
 
         if (mImpl == Impl.DEFAULT) {
-            mQueue = new BroadcastQueueImpl(mAms, mHandlerThread.getThreadHandler(), TAG,
+            var q = new BroadcastQueueImpl(mAms, mHandlerThread.getThreadHandler(), TAG,
                     constants, emptySkipPolicy, emptyHistory, false,
                     ProcessList.SCHED_GROUP_DEFAULT);
+            q.mReceiverBatch.mDeepReceiverCopy = true;
+            mQueue = q;
         } else if (mImpl == Impl.MODERN) {
-            mQueue = new BroadcastQueueModernImpl(mAms, mHandlerThread.getThreadHandler(),
+            var q = new BroadcastQueueModernImpl(mAms, mHandlerThread.getThreadHandler(),
                     constants, constants, emptySkipPolicy, emptyHistory);
+            q.mReceiverBatch.mDeepReceiverCopy = true;
+            mQueue = q;
         } else {
             throw new UnsupportedOperationException();
         }
@@ -398,6 +405,43 @@
                 UnaryOperator.identity());
     }
 
+    private void doRegisteredReceiver(ProcessRecord r, boolean wedge, boolean abort,
+            UnaryOperator<Bundle> extrasOperator, ReceiverInfo info) {
+        final Intent intent = info.intent;
+        final Bundle extras = info.extras;
+        final boolean ordered = info.ordered;
+        mScheduledBroadcasts.add(makeScheduledBroadcast(r, intent));
+        if (!wedge && ordered) {
+            assertTrue(r.mReceivers.numberOfCurReceivers() > 0);
+            assertNotEquals(ProcessList.SCHED_GROUP_UNDEFINED,
+                    mQueue.getPreferredSchedulingGroupLocked(r));
+            mHandlerThread.getThreadHandler().post(() -> {
+                synchronized (mAms) {
+                    mQueue.finishReceiverLocked(r, Activity.RESULT_OK,
+                            null, extrasOperator.apply(extras), abort, false);
+                }
+            });
+        }
+    }
+
+    private void doManifestReceiver(ProcessRecord r, boolean wedge, boolean abort,
+            UnaryOperator<Bundle> extrasOperator, ReceiverInfo info) {
+        final Intent intent = info.intent;
+        final Bundle extras = info.extras;
+        mScheduledBroadcasts.add(makeScheduledBroadcast(r, intent));
+        if (!wedge) {
+            assertTrue(r.mReceivers.numberOfCurReceivers() > 0);
+            assertNotEquals(ProcessList.SCHED_GROUP_UNDEFINED,
+                    mQueue.getPreferredSchedulingGroupLocked(r));
+            mHandlerThread.getThreadHandler().post(() -> {
+                synchronized (mAms) {
+                    mQueue.finishReceiverLocked(r, Activity.RESULT_OK, null,
+                            extrasOperator.apply(extras), abort, false);
+                }
+            });
+        }
+    }
+
     private ProcessRecord makeActiveProcessRecord(ApplicationInfo ai, String processName,
             ProcessBehavior behavior, UnaryOperator<Bundle> extrasOperator) throws Exception {
         final boolean wedge = (behavior == ProcessBehavior.WEDGE);
@@ -441,47 +485,22 @@
         if (dead) return r;
 
         doAnswer((invocation) -> {
-            Log.v(TAG, "Intercepting scheduleReceiver() for "
+            Log.v(TAG, "Intercepting scheduleReceiverList() for "
                     + Arrays.toString(invocation.getArguments()));
-            final Intent intent = invocation.getArgument(0);
-            final Bundle extras = invocation.getArgument(5);
-            mScheduledBroadcasts.add(makeScheduledBroadcast(r, intent));
-            if (!wedge) {
-                assertTrue(r.mReceivers.numberOfCurReceivers() > 0);
-                assertNotEquals(ProcessList.SCHED_GROUP_UNDEFINED,
-                        mQueue.getPreferredSchedulingGroupLocked(r));
-                mHandlerThread.getThreadHandler().post(() -> {
-                    synchronized (mAms) {
-                        mQueue.finishReceiverLocked(r, Activity.RESULT_OK, null,
-                                extrasOperator.apply(extras), abort, false);
-                    }
-                });
+            final List<ReceiverInfo> data = invocation.getArgument(0);
+            for (int i = 0; i < data.size(); i++) {
+                ReceiverInfo info = data.get(i);
+                // The logic here mimics the logic in ActivityThread: elements of the list are
+                // forwarded to a handler for manifest receivers or to a handler for registered
+                // receivers.
+                if (info.registered) {
+                    doRegisteredReceiver(r, wedge, abort, extrasOperator, info);
+                } else {
+                    doManifestReceiver(r, wedge, abort, extrasOperator, info);
+                }
             }
             return null;
-        }).when(thread).scheduleReceiver(any(), any(), any(), anyInt(), any(), any(), anyBoolean(),
-                anyInt(), anyInt());
-
-        doAnswer((invocation) -> {
-            Log.v(TAG, "Intercepting scheduleRegisteredReceiver() for "
-                    + Arrays.toString(invocation.getArguments()));
-            final Intent intent = invocation.getArgument(1);
-            final Bundle extras = invocation.getArgument(4);
-            final boolean ordered = invocation.getArgument(5);
-            mScheduledBroadcasts.add(makeScheduledBroadcast(r, intent));
-            if (!wedge && ordered) {
-                assertTrue(r.mReceivers.numberOfCurReceivers() > 0);
-                assertNotEquals(ProcessList.SCHED_GROUP_UNDEFINED,
-                        mQueue.getPreferredSchedulingGroupLocked(r));
-                mHandlerThread.getThreadHandler().post(() -> {
-                    synchronized (mAms) {
-                        mQueue.finishReceiverLocked(r, Activity.RESULT_OK,
-                                null, extrasOperator.apply(extras), abort, false);
-                    }
-                });
-            }
-            return null;
-        }).when(thread).scheduleRegisteredReceiver(any(), any(), anyInt(), any(), any(),
-                anyBoolean(), anyBoolean(), anyInt(), anyInt());
+        }).when(thread).scheduleReceiverList(any());
 
         return r;
     }
@@ -623,6 +642,123 @@
         };
     }
 
+    private static <T> boolean matchElement(T a, T b) {
+        return a == null || a.equals(b);
+    }
+    private static <T> boolean matchObject(ArgumentMatcher<T> m, T b) {
+        return m == null || m.matches(b);
+    }
+
+    /**
+     * Create an ArgumentMatcher for a manifest receiver.  The parameters are in the order of
+     * {@link IApplicationThread#scheduleReceiver} but the names correspond to the field names in
+     * {@link ReceiverInfo}.  For every parameter, a null means "don't care".
+     */
+    private ArgumentMatcher<ReceiverInfo> manifestReceiverMatcher(
+            ArgumentMatcher<Intent> intent,
+            ArgumentMatcher<ActivityInfo> activityInfo,
+            ArgumentMatcher<CompatibilityInfo> compatInfo,
+            Integer resultCode,
+            ArgumentMatcher<String> data,
+            ArgumentMatcher<Bundle> extras,
+            Boolean sync,
+            Integer sendingUser,
+            Integer processState) {
+        return (test) -> {
+            return test.registered == false
+                    && matchObject(intent, test.intent)
+                    && matchObject(activityInfo, test.activityInfo)
+                    && matchObject(compatInfo, test.compatInfo)
+                    && matchElement(resultCode, test.resultCode)
+                    && matchObject(data, test.data)
+                    && matchObject(extras, test.extras)
+                    && matchElement(sync, test.sync)
+                    && matchElement(sendingUser, test.sendingUser)
+                    && matchElement(processState, test.processState);
+        };
+    }
+
+
+    /**
+     * Create an argument suitable for the verify() mock methods, when the goal is to find a call
+     * containing a manifest receiver.
+     */
+    private List<ReceiverInfo> manifestReceiver(
+            ArgumentMatcher<Intent> intent,
+            ArgumentMatcher<ActivityInfo> activityInfo,
+            ArgumentMatcher<CompatibilityInfo> compatInfo,
+            Integer resultCode,
+            ArgumentMatcher<String> data,
+            ArgumentMatcher<Bundle> extras,
+            Boolean sync,
+            Integer sendingUser,
+            Integer processState) {
+        return argThat(receiverList(manifestReceiverMatcher(intent, activityInfo, compatInfo,
+                                resultCode, data, extras, sync, sendingUser, processState)));
+    }
+
+    /**
+     * Create an ArgumentMatcher for a registered receiver.  The parameters are in the order of
+     * {@link IApplicationThread#scheduleRegisteredReceiver} but the names correspond to the field
+     * names in {@link ReceiverInfo}.  For every parameter, a null means "don't care".
+     */
+    private ArgumentMatcher<ReceiverInfo> registeredReceiverMatcher(
+            ArgumentMatcher<IIntentReceiver> receiver,
+            ArgumentMatcher<Intent> intent,
+            Integer resultCode,
+            ArgumentMatcher<String> data,
+            ArgumentMatcher<Bundle> extras,
+            Boolean ordered,
+            Boolean sticky,
+            Integer sendingUser,
+            Integer processState) {
+        return (test) -> {
+            return test.registered == true
+                    && matchObject(receiver, test.receiver)
+                    && matchObject(intent, test.intent)
+                    && matchElement(resultCode, test.resultCode)
+                    && matchObject(data, test.data)
+                    && matchObject(extras, test.extras)
+                    && matchElement(ordered, test.ordered)
+                    && matchElement(sticky, test.sticky)
+                    && matchElement(sendingUser, test.sendingUser)
+                    && matchElement(processState, test.processState);
+        };
+    }
+
+    /**
+     * Create an argument suitable for the verify() mock methods, when the goal is to find a call
+     * containing a registered receiver.
+     */
+    private List<ReceiverInfo> registeredReceiver(
+            ArgumentMatcher<IIntentReceiver> receiver,
+            ArgumentMatcher<Intent> intent,
+            Integer resultCode,
+            ArgumentMatcher<String> data,
+            ArgumentMatcher<Bundle> extras,
+            Boolean ordered,
+            Boolean sticky,
+            Integer sendingUser,
+            Integer processState) {
+        return argThat(receiverList(registeredReceiverMatcher(receiver, intent, resultCode,
+                                data, extras, ordered, sticky, sendingUser, processState)));
+    }
+
+    /**
+     * Apply a matcher to every element in a ReceiverInfo list.
+     */
+    private ArgumentMatcher<List<ReceiverInfo>> receiverList(ArgumentMatcher<ReceiverInfo> a) {
+        return (test) -> {
+            for (int i = 0; i < test.size(); i++) {
+                ReceiverInfo r = test.get(i);
+                if (a.matches(r)) {
+                    return true;
+                }
+            }
+            return false;
+        };
+    }
+
     private ArgumentMatcher<Bundle> bundleEquals(Bundle bundle) {
         return (test) -> {
             // TODO: check values in addition to keys
@@ -654,26 +790,27 @@
     }
 
     private void verifyScheduleReceiver(VerificationMode mode, ProcessRecord app, Intent intent,
-            int userId) throws Exception {
-        verify(app.getThread(), mode).scheduleReceiver(
-                argThat(filterEqualsIgnoringComponent(intent)), any(), any(), anyInt(), any(),
-                any(), eq(false), eq(userId), anyInt());
-    }
-
-    private void verifyScheduleReceiver(VerificationMode mode, ProcessRecord app, Intent intent,
             ComponentName component) throws Exception {
         final Intent targetedIntent = new Intent(intent);
         targetedIntent.setComponent(component);
-        verify(app.getThread(), mode).scheduleReceiver(
-                argThat(filterEquals(targetedIntent)), any(), any(), anyInt(), any(),
-                any(), eq(false), eq(UserHandle.USER_SYSTEM), anyInt());
+        verify(app.getThread(), mode).scheduleReceiverList(
+            manifestReceiver(filterEquals(targetedIntent),
+                    null, null, null, null, null, null, UserHandle.USER_SYSTEM, null));
     }
 
-    private void verifyScheduleRegisteredReceiver(ProcessRecord app, Intent intent)
+    private void verifyScheduleReceiver(VerificationMode mode, ProcessRecord app,
+            Intent intent, int userId) throws Exception {
+        verify(app.getThread(), mode).scheduleReceiverList(
+            manifestReceiver(filterEqualsIgnoringComponent(intent),
+                    null, null, null, null, null, null, userId, null));
+    }
+
+    private void verifyScheduleRegisteredReceiver(ProcessRecord app,
+            Intent intent)
             throws Exception {
-        verify(app.getThread()).scheduleRegisteredReceiver(any(),
-                argThat(filterEqualsIgnoringComponent(intent)), anyInt(), any(), any(),
-                anyBoolean(), anyBoolean(), eq(UserHandle.USER_SYSTEM), anyInt());
+        verify(app.getThread()).scheduleReceiverList(
+            registeredReceiver(null, filterEqualsIgnoringComponent(intent),
+                    null, null, null, null, null, UserHandle.USER_SYSTEM, null));
     }
 
     static final int USER_GUEST = 11;
@@ -1237,23 +1374,24 @@
         final InOrder inOrder = inOrder(greenThread, blueThread, yellowThread, redThread);
         final Bundle expectedExtras = new Bundle();
         expectedExtras.putBoolean(PACKAGE_RED, true);
-        inOrder.verify(greenThread).scheduleReceiver(
-                argThat(filterEqualsIgnoringComponent(airplane)), any(), any(),
-                eq(Activity.RESULT_OK), any(), argThat(bundleEquals(expectedExtras)), eq(true),
-                eq(UserHandle.USER_SYSTEM), anyInt());
-        inOrder.verify(blueThread).scheduleReceiver(
-                argThat(filterEqualsIgnoringComponent(airplane)), any(), any(),
-                eq(Activity.RESULT_OK), any(), argThat(bundleEquals(expectedExtras)), eq(true),
-                eq(UserHandle.USER_SYSTEM), anyInt());
+        inOrder.verify(greenThread).scheduleReceiverList(manifestReceiver(
+                filterEqualsIgnoringComponent(airplane), null, null,
+                Activity.RESULT_OK, null, bundleEquals(expectedExtras), true,
+                UserHandle.USER_SYSTEM, null));
+        inOrder.verify(blueThread).scheduleReceiverList(manifestReceiver(
+                filterEqualsIgnoringComponent(airplane), null, null,
+                Activity.RESULT_OK, null, bundleEquals(expectedExtras), true,
+                UserHandle.USER_SYSTEM, null));
         expectedExtras.putBoolean(PACKAGE_BLUE, true);
-        inOrder.verify(yellowThread).scheduleReceiver(
-                argThat(filterEqualsIgnoringComponent(airplane)), any(), any(),
-                eq(Activity.RESULT_OK), any(), argThat(bundleEquals(expectedExtras)), eq(true),
-                eq(UserHandle.USER_SYSTEM), anyInt());
+        inOrder.verify(yellowThread).scheduleReceiverList(manifestReceiver(
+                filterEqualsIgnoringComponent(airplane), null, null,
+                Activity.RESULT_OK, null, bundleEquals(expectedExtras), true,
+                UserHandle.USER_SYSTEM, null));
         expectedExtras.putBoolean(PACKAGE_YELLOW, true);
-        inOrder.verify(redThread).scheduleRegisteredReceiver(any(), argThat(filterEquals(airplane)),
-                eq(Activity.RESULT_OK), any(), argThat(bundleEquals(expectedExtras)), eq(false),
-                anyBoolean(), eq(UserHandle.USER_SYSTEM), anyInt());
+        inOrder.verify(redThread).scheduleReceiverList(registeredReceiver(
+                null, filterEquals(airplane),
+                Activity.RESULT_OK, null, bundleEquals(expectedExtras), false,
+                null, UserHandle.USER_SYSTEM, null));
 
         // Finally, verify that we thawed the final receiver
         verify(mAms.mOomAdjuster.mCachedAppOptimizer).unfreezeTemporarily(eq(callerApp),
@@ -1316,22 +1454,24 @@
         // have invoked or skipped the second receiver depending on the intent
         // flag policy; we always deliver to final receiver regardless of abort
         final InOrder inOrder = inOrder(greenThread, blueThread, redThread);
-        inOrder.verify(greenThread).scheduleReceiver(
-                argThat(filterEqualsIgnoringComponent(intent)), any(), any(),
-                eq(Activity.RESULT_OK), any(), any(), eq(true), eq(UserHandle.USER_SYSTEM),
-                anyInt());
+        inOrder.verify(greenThread).scheduleReceiverList(manifestReceiver(
+                filterEqualsIgnoringComponent(intent), null, null,
+                Activity.RESULT_OK, null, null, true, UserHandle.USER_SYSTEM,
+                null));
         if ((intent.getFlags() & Intent.FLAG_RECEIVER_NO_ABORT) != 0) {
-            inOrder.verify(blueThread).scheduleReceiver(
-                    argThat(filterEqualsIgnoringComponent(intent)), any(), any(),
-                    eq(Activity.RESULT_OK), any(), any(), eq(true), eq(UserHandle.USER_SYSTEM),
-                    anyInt());
+            inOrder.verify(blueThread).scheduleReceiverList(manifestReceiver(
+                    filterEqualsIgnoringComponent(intent), null, null,
+                    Activity.RESULT_OK, null, null, true, UserHandle.USER_SYSTEM,
+                    null));
         } else {
-            inOrder.verify(blueThread, never()).scheduleReceiver(any(), any(), any(), anyInt(),
-                    any(), any(), anyBoolean(), anyInt(), anyInt());
+            inOrder.verify(blueThread, never()).scheduleReceiverList(manifestReceiver(
+                    null, null, null, null,
+                    null, null, null, null, null));
         }
-        inOrder.verify(redThread).scheduleRegisteredReceiver(any(), argThat(filterEquals(intent)),
-                eq(Activity.RESULT_OK), any(), argThat(bundleEquals(expectedExtras)),
-                eq(false), anyBoolean(), eq(UserHandle.USER_SYSTEM), anyInt());
+        inOrder.verify(redThread).scheduleReceiverList(registeredReceiver(
+                null, filterEquals(intent),
+                Activity.RESULT_OK, null, bundleEquals(expectedExtras),
+                false, null, UserHandle.USER_SYSTEM, null));
     }
 
     /**
@@ -1351,9 +1491,10 @@
                 orderedResultTo, orderedExtras));
 
         waitForIdle();
-        verify(callerThread).scheduleRegisteredReceiver(any(), argThat(filterEquals(airplane)),
-                eq(Activity.RESULT_OK), any(), argThat(bundleEquals(orderedExtras)), eq(false),
-                anyBoolean(), eq(UserHandle.USER_SYSTEM), anyInt());
+        verify(callerThread).scheduleReceiverList(registeredReceiver(
+                null, filterEquals(airplane),
+                Activity.RESULT_OK, null, bundleEquals(orderedExtras), false,
+                null, UserHandle.USER_SYSTEM, null));
     }
 
     /**
@@ -1371,9 +1512,10 @@
                         makeManifestReceiver(PACKAGE_BLUE, CLASS_BLUE)), resultTo));
 
         waitForIdle();
-        verify(callerThread).scheduleRegisteredReceiver(any(), argThat(filterEquals(airplane)),
-                eq(Activity.RESULT_OK), any(), any(), eq(false),
-                anyBoolean(), eq(UserHandle.USER_SYSTEM), anyInt());
+        verify(callerThread).scheduleReceiverList(registeredReceiver(
+                null, filterEquals(airplane),
+                Activity.RESULT_OK, null, null, false,
+                null, UserHandle.USER_SYSTEM, null));
     }
 
     /**
@@ -1536,28 +1678,28 @@
         final InOrder inOrder = inOrder(callerThread, blueThread);
 
         // First broadcast is canceled
-        inOrder.verify(callerThread).scheduleRegisteredReceiver(any(),
-                argThat(filterAndExtrasEquals(timezoneFirst)), eq(Activity.RESULT_CANCELED), any(),
-                any(), eq(false), anyBoolean(), eq(UserHandle.USER_SYSTEM), anyInt());
+        inOrder.verify(callerThread).scheduleReceiverList(registeredReceiver(null,
+                filterAndExtrasEquals(timezoneFirst), Activity.RESULT_CANCELED, null,
+                null, false, null, UserHandle.USER_SYSTEM, null));
 
         // We deliver second broadcast to app
         timezoneSecond.setClassName(PACKAGE_BLUE, CLASS_GREEN);
-        inOrder.verify(blueThread).scheduleReceiver(
-                argThat(filterAndExtrasEquals(timezoneSecond)),
-                any(), any(), anyInt(), any(), any(), eq(true), anyInt(), anyInt());
+        inOrder.verify(blueThread).scheduleReceiverList(manifestReceiver(
+                filterAndExtrasEquals(timezoneSecond),
+                null, null, null, null, null, true, null, null));
 
         // Second broadcast is finished
         timezoneSecond.setComponent(null);
-        inOrder.verify(callerThread).scheduleRegisteredReceiver(any(),
-                argThat(filterAndExtrasEquals(timezoneSecond)), eq(Activity.RESULT_OK), any(),
-                any(), eq(false), anyBoolean(), eq(UserHandle.USER_SYSTEM), anyInt());
+        inOrder.verify(callerThread).scheduleReceiverList(registeredReceiver(null,
+                filterAndExtrasEquals(timezoneSecond), Activity.RESULT_OK, null,
+                null, false, null, UserHandle.USER_SYSTEM, null));
 
         // Since we "replaced" the first broadcast in its original position,
         // only now do we see the airplane broadcast
         airplane.setClassName(PACKAGE_BLUE, CLASS_RED);
-        inOrder.verify(blueThread).scheduleReceiver(
-                argThat(filterEquals(airplane)),
-                any(), any(), anyInt(), any(), any(), eq(false), anyInt(), anyInt());
+        inOrder.verify(blueThread).scheduleReceiverList(manifestReceiver(
+                filterEquals(airplane),
+                null, null, null, null, null, false, null, null));
     }
 
     @Test
diff --git a/services/tests/mockingservicestests/src/com/android/server/app/GameManagerServiceTests.java b/services/tests/mockingservicestests/src/com/android/server/app/GameManagerServiceTests.java
index a8d8945..d3fa92c 100644
--- a/services/tests/mockingservicestests/src/com/android/server/app/GameManagerServiceTests.java
+++ b/services/tests/mockingservicestests/src/com/android/server/app/GameManagerServiceTests.java
@@ -647,15 +647,15 @@
         }
     }
 
-    private void checkReportedOptedInGameModes(GameManagerService gameManagerService,
-            int... requiredOptedInModes) {
-        Arrays.sort(requiredOptedInModes);
-        // check GetModeInfo.getOptedInGameModes
+    private void checkReportedOverriddenGameModes(GameManagerService gameManagerService,
+            int... requiredOverriddenModes) {
+        Arrays.sort(requiredOverriddenModes);
+        // check GetModeInfo.getOverriddenGameModes
         GameModeInfo info = gameManagerService.getGameModeInfo(mPackageName, USER_ID_1);
         assertNotNull(info);
-        int[] optedInModes = info.getOptedInGameModes();
-        Arrays.sort(optedInModes);
-        assertArrayEquals(requiredOptedInModes, optedInModes);
+        int[] overriddenModes = info.getOverriddenGameModes();
+        Arrays.sort(overriddenModes);
+        assertArrayEquals(requiredOverriddenModes, overriddenModes);
     }
 
     private void checkDownscaling(GameManagerService gameManagerService,
@@ -697,7 +697,7 @@
         assertEquals(fps, config.getGameModeConfiguration(gameMode).getFps());
     }
 
-    private boolean checkOptedIn(GameManagerService gameManagerService, int gameMode) {
+    private boolean checkOverridden(GameManagerService gameManagerService, int gameMode) {
         GameManagerService.GamePackageConfiguration config =
                 gameManagerService.getConfig(mPackageName, USER_ID_1);
         return config.willGamePerformOptimizations(gameMode);
@@ -870,8 +870,8 @@
                 mTestLooper.getLooper());
         startUser(gameManagerService, USER_ID_1);
 
-        assertFalse(checkOptedIn(gameManagerService, GameManager.GAME_MODE_PERFORMANCE));
-        assertFalse(checkOptedIn(gameManagerService, GameManager.GAME_MODE_BATTERY));
+        assertFalse(checkOverridden(gameManagerService, GameManager.GAME_MODE_PERFORMANCE));
+        assertFalse(checkOverridden(gameManagerService, GameManager.GAME_MODE_BATTERY));
         checkFps(gameManagerService, GameManager.GAME_MODE_PERFORMANCE, 0);
 
         gameManagerService.setGameModeConfigOverride(mPackageName, USER_ID_1, 3, "40",
@@ -884,9 +884,9 @@
         mockInterventionsDisabledAllOptInFromXml();
         gameManagerService.updateConfigsForUser(USER_ID_1, false, mPackageName);
 
-        assertTrue(checkOptedIn(gameManagerService, GameManager.GAME_MODE_PERFORMANCE));
+        assertTrue(checkOverridden(gameManagerService, GameManager.GAME_MODE_PERFORMANCE));
         // opt-in is still false for battery mode as override exists
-        assertFalse(checkOptedIn(gameManagerService, GameManager.GAME_MODE_BATTERY));
+        assertFalse(checkOverridden(gameManagerService, GameManager.GAME_MODE_BATTERY));
     }
 
     /**
@@ -1310,7 +1310,7 @@
         checkReportedAvailableGameModes(gameManagerService, GameManager.GAME_MODE_PERFORMANCE,
                 GameManager.GAME_MODE_BATTERY, GameManager.GAME_MODE_STANDARD,
                 GameManager.GAME_MODE_CUSTOM);
-        checkReportedOptedInGameModes(gameManagerService);
+        checkReportedOverriddenGameModes(gameManagerService);
 
         assertEquals(new GameModeConfiguration.Builder()
                 .setFpsOverride(30)
@@ -1337,7 +1337,7 @@
         checkReportedAvailableGameModes(gameManagerService,
                 GameManager.GAME_MODE_BATTERY, GameManager.GAME_MODE_STANDARD,
                 GameManager.GAME_MODE_CUSTOM);
-        checkReportedOptedInGameModes(gameManagerService);
+        checkReportedOverriddenGameModes(gameManagerService);
 
         assertNotNull(gameModeInfo.getGameModeConfiguration(GameManager.GAME_MODE_BATTERY));
         assertNull(gameModeInfo.getGameModeConfiguration(GameManager.GAME_MODE_PERFORMANCE));
@@ -1357,7 +1357,7 @@
         checkReportedAvailableGameModes(gameManagerService,
                 GameManager.GAME_MODE_PERFORMANCE, GameManager.GAME_MODE_STANDARD,
                 GameManager.GAME_MODE_CUSTOM);
-        checkReportedOptedInGameModes(gameManagerService);
+        checkReportedOverriddenGameModes(gameManagerService);
 
         assertNotNull(gameModeInfo.getGameModeConfiguration(GameManager.GAME_MODE_PERFORMANCE));
         assertNull(gameModeInfo.getGameModeConfiguration(GameManager.GAME_MODE_BATTERY));
@@ -1382,7 +1382,7 @@
     }
 
     @Test
-    public void testGetGameModeInfoWithAllGameModesOptedIn_noDeviceConfig()
+    public void testGetGameModeInfoWithAllGameModesOverridden_noDeviceConfig()
             throws Exception {
         mockModifyGameModeGranted();
         mockInterventionsEnabledAllOptInFromXml();
@@ -1390,14 +1390,14 @@
         GameManagerService gameManagerService = createServiceAndStartUser(USER_ID_1);
         GameModeInfo gameModeInfo = gameManagerService.getGameModeInfo(mPackageName, USER_ID_1);
         assertEquals(GameManager.GAME_MODE_STANDARD, gameModeInfo.getActiveGameMode());
-        verifyAllModesOptedInAndInterventionsAvailable(gameManagerService, gameModeInfo);
+        verifyAllModesOverriddenAndInterventionsAvailable(gameManagerService, gameModeInfo);
 
         assertNull(gameModeInfo.getGameModeConfiguration(GameManager.GAME_MODE_BATTERY));
         assertNull(gameModeInfo.getGameModeConfiguration(GameManager.GAME_MODE_PERFORMANCE));
     }
 
     @Test
-    public void testGetGameModeInfoWithAllGameModesOptedIn_allDeviceConfig()
+    public void testGetGameModeInfoWithAllGameModesOverridden_allDeviceConfig()
             throws Exception {
         mockModifyGameModeGranted();
         mockInterventionsEnabledAllOptInFromXml();
@@ -1405,26 +1405,26 @@
         GameManagerService gameManagerService = createServiceAndStartUser(USER_ID_1);
         GameModeInfo gameModeInfo = gameManagerService.getGameModeInfo(mPackageName, USER_ID_1);
         assertEquals(GameManager.GAME_MODE_STANDARD, gameModeInfo.getActiveGameMode());
-        verifyAllModesOptedInAndInterventionsAvailable(gameManagerService, gameModeInfo);
+        verifyAllModesOverriddenAndInterventionsAvailable(gameManagerService, gameModeInfo);
 
         assertNull(gameModeInfo.getGameModeConfiguration(GameManager.GAME_MODE_BATTERY));
         assertNull(gameModeInfo.getGameModeConfiguration(GameManager.GAME_MODE_PERFORMANCE));
     }
 
-    private void verifyAllModesOptedInAndInterventionsAvailable(
+    private void verifyAllModesOverriddenAndInterventionsAvailable(
             GameManagerService gameManagerService,
             GameModeInfo gameModeInfo) {
         checkReportedAvailableGameModes(gameManagerService,
                 GameManager.GAME_MODE_PERFORMANCE, GameManager.GAME_MODE_BATTERY,
                 GameManager.GAME_MODE_STANDARD, GameManager.GAME_MODE_CUSTOM);
-        checkReportedOptedInGameModes(gameManagerService,
+        checkReportedOverriddenGameModes(gameManagerService,
                 GameManager.GAME_MODE_PERFORMANCE, GameManager.GAME_MODE_BATTERY);
         assertTrue(gameModeInfo.isFpsOverrideAllowed());
         assertTrue(gameModeInfo.isDownscalingAllowed());
     }
 
     @Test
-    public void testGetGameModeInfoWithBatteryModeOptedIn_withBatteryDeviceConfig()
+    public void testGetGameModeInfoWithBatteryModeOverridden_withBatteryDeviceConfig()
             throws Exception {
         mockModifyGameModeGranted();
         mockInterventionsEnabledBatteryOptInFromXml();
@@ -1435,14 +1435,14 @@
 
         checkReportedAvailableGameModes(gameManagerService, GameManager.GAME_MODE_BATTERY,
                 GameManager.GAME_MODE_STANDARD, GameManager.GAME_MODE_CUSTOM);
-        checkReportedOptedInGameModes(gameManagerService, GameManager.GAME_MODE_BATTERY);
+        checkReportedOverriddenGameModes(gameManagerService, GameManager.GAME_MODE_BATTERY);
 
         assertNull(gameModeInfo.getGameModeConfiguration(GameManager.GAME_MODE_BATTERY));
         assertNull(gameModeInfo.getGameModeConfiguration(GameManager.GAME_MODE_PERFORMANCE));
     }
 
     @Test
-    public void testGetGameModeInfoWithPerformanceModeOptedIn_withAllDeviceConfig()
+    public void testGetGameModeInfoWithPerformanceModeOverridden_withAllDeviceConfig()
             throws Exception {
         mockModifyGameModeGranted();
         mockInterventionsEnabledPerformanceOptInFromXml();
@@ -1454,7 +1454,7 @@
         checkReportedAvailableGameModes(gameManagerService, GameManager.GAME_MODE_PERFORMANCE,
                 GameManager.GAME_MODE_BATTERY, GameManager.GAME_MODE_STANDARD,
                 GameManager.GAME_MODE_CUSTOM);
-        checkReportedOptedInGameModes(gameManagerService, GameManager.GAME_MODE_PERFORMANCE);
+        checkReportedOverriddenGameModes(gameManagerService, GameManager.GAME_MODE_PERFORMANCE);
 
         assertNotNull(gameModeInfo.getGameModeConfiguration(GameManager.GAME_MODE_BATTERY));
         assertNull(gameModeInfo.getGameModeConfiguration(GameManager.GAME_MODE_PERFORMANCE));
@@ -1993,7 +1993,7 @@
     }
 
     @Test
-    public void testResetInterventions_onGameModeOptedIn() throws Exception {
+    public void testResetInterventions_onGameModeOverridden() throws Exception {
         mockModifyGameModeGranted();
         String configStringBefore =
                 "mode=2,downscaleFactor=1.0,fps=90";
diff --git a/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsLegacyRestrictionsTest.java b/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsLegacyRestrictionsTest.java
index be13bad..021d01c 100644
--- a/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsLegacyRestrictionsTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsLegacyRestrictionsTest.java
@@ -48,7 +48,7 @@
     StaticMockitoSession mSession;
 
     @Mock
-    AppOpsServiceImpl.Constants mConstants;
+    AppOpsService.Constants mConstants;
 
     @Mock
     Context mContext;
diff --git a/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java b/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java
index 7d4bc6f..c0688d1 100644
--- a/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java
@@ -22,8 +22,6 @@
 import static android.app.AppOpsManager.OP_READ_SMS;
 import static android.app.AppOpsManager.OP_WIFI_SCAN;
 import static android.app.AppOpsManager.OP_WRITE_SMS;
-import static android.app.AppOpsManager.resolvePackageName;
-import static android.os.Process.INVALID_UID;
 
 import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
 import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
@@ -41,7 +39,6 @@
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.ArgumentMatchers.nullable;
 
-import android.app.AppOpsManager;
 import android.app.AppOpsManager.OpEntry;
 import android.app.AppOpsManager.PackageOps;
 import android.content.ContentResolver;
@@ -89,13 +86,13 @@
 
     private File mAppOpsFile;
     private Handler mHandler;
-    private AppOpsServiceImpl mAppOpsService;
+    private AppOpsService mAppOpsService;
     private int mMyUid;
     private long mTestStartMillis;
     private StaticMockitoSession mMockingSession;
 
     private void setupAppOpsService() {
-        mAppOpsService = new AppOpsServiceImpl(mAppOpsFile, mHandler, spy(sContext));
+        mAppOpsService = new AppOpsService(mAppOpsFile, mHandler, spy(sContext));
         mAppOpsService.mHistoricalRegistry.systemReady(sContext.getContentResolver());
 
         // Always approve all permission checks
@@ -164,20 +161,17 @@
 
     @Test
     public void testNoteOperationAndGetOpsForPackage() {
-        mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED, null);
-        mAppOpsService.setMode(OP_WRITE_SMS, mMyUid, sMyPackageName, MODE_ERRORED, null);
+        mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
+        mAppOpsService.setMode(OP_WRITE_SMS, mMyUid, sMyPackageName, MODE_ERRORED);
 
         // Note an op that's allowed.
-        mAppOpsService.noteOperationUnchecked(OP_READ_SMS, mMyUid,
-                resolvePackageName(mMyUid, sMyPackageName), null,
-                INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF);
+        mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
         List<PackageOps> loggedOps = getLoggedOps();
         assertContainsOp(loggedOps, OP_READ_SMS, mTestStartMillis, -1, MODE_ALLOWED);
 
         // Note another op that's not allowed.
-        mAppOpsService.noteOperationUnchecked(OP_WRITE_SMS, mMyUid,
-                resolvePackageName(mMyUid, sMyPackageName), null,
-                INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF);
+        mAppOpsService.noteOperation(OP_WRITE_SMS, mMyUid, sMyPackageName, null, false, null,
+                false);
         loggedOps = getLoggedOps();
         assertContainsOp(loggedOps, OP_READ_SMS, mTestStartMillis, -1, MODE_ALLOWED);
         assertContainsOp(loggedOps, OP_WRITE_SMS, -1, mTestStartMillis, MODE_ERRORED);
@@ -191,20 +185,18 @@
     @Test
     public void testNoteOperationAndGetOpsForPackage_controlledByDifferentOp() {
         // This op controls WIFI_SCAN
-        mAppOpsService.setMode(OP_COARSE_LOCATION, mMyUid, sMyPackageName, MODE_ALLOWED, null);
+        mAppOpsService.setMode(OP_COARSE_LOCATION, mMyUid, sMyPackageName, MODE_ALLOWED);
 
-        assertThat(mAppOpsService.noteOperationUnchecked(OP_WIFI_SCAN, mMyUid,
-                resolvePackageName(mMyUid, sMyPackageName), null,
-                INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF)).isEqualTo(MODE_ALLOWED);
+        assertThat(mAppOpsService.noteOperation(OP_WIFI_SCAN, mMyUid, sMyPackageName, null, false,
+                null, false).getOpMode()).isEqualTo(MODE_ALLOWED);
 
         assertContainsOp(getLoggedOps(), OP_WIFI_SCAN, mTestStartMillis, -1,
                 MODE_ALLOWED /* default for WIFI_SCAN; this is not changed or used in this test */);
 
         // Now set COARSE_LOCATION to ERRORED -> this will make WIFI_SCAN disabled as well.
-        mAppOpsService.setMode(OP_COARSE_LOCATION, mMyUid, sMyPackageName, MODE_ERRORED, null);
-        assertThat(mAppOpsService.noteOperationUnchecked(OP_WIFI_SCAN, mMyUid,
-                resolvePackageName(mMyUid, sMyPackageName), null,
-                INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF)).isEqualTo(MODE_ERRORED);
+        mAppOpsService.setMode(OP_COARSE_LOCATION, mMyUid, sMyPackageName, MODE_ERRORED);
+        assertThat(mAppOpsService.noteOperation(OP_WIFI_SCAN, mMyUid, sMyPackageName, null, false,
+                null, false).getOpMode()).isEqualTo(MODE_ERRORED);
 
         assertContainsOp(getLoggedOps(), OP_WIFI_SCAN, mTestStartMillis, mTestStartMillis,
                 MODE_ALLOWED /* default for WIFI_SCAN; this is not changed or used in this test */);
@@ -213,14 +205,11 @@
     // Tests the dumping and restoring of the in-memory state to/from XML.
     @Test
     public void testStatePersistence() {
-        mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED, null);
-        mAppOpsService.setMode(OP_WRITE_SMS, mMyUid, sMyPackageName, MODE_ERRORED, null);
-        mAppOpsService.noteOperationUnchecked(OP_READ_SMS, mMyUid,
-                resolvePackageName(mMyUid, sMyPackageName), null,
-                INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF);
-        mAppOpsService.noteOperationUnchecked(OP_WRITE_SMS, mMyUid,
-                resolvePackageName(mMyUid, sMyPackageName), null,
-                INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF);
+        mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
+        mAppOpsService.setMode(OP_WRITE_SMS, mMyUid, sMyPackageName, MODE_ERRORED);
+        mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
+        mAppOpsService.noteOperation(OP_WRITE_SMS, mMyUid, sMyPackageName, null, false, null,
+                false);
         mAppOpsService.writeState();
 
         // Create a new app ops service which will initialize its state from XML.
@@ -235,10 +224,8 @@
     // Tests that ops are persisted during shutdown.
     @Test
     public void testShutdown() {
-        mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED, null);
-        mAppOpsService.noteOperationUnchecked(OP_READ_SMS, mMyUid,
-                resolvePackageName(mMyUid, sMyPackageName), null,
-                INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF);
+        mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
+        mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
         mAppOpsService.shutdown();
 
         // Create a new app ops service which will initialize its state from XML.
@@ -251,10 +238,8 @@
 
     @Test
     public void testGetOpsForPackage() {
-        mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED, null);
-        mAppOpsService.noteOperationUnchecked(OP_READ_SMS, mMyUid,
-                resolvePackageName(mMyUid, sMyPackageName), null,
-                INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF);
+        mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
+        mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
 
         // Query all ops
         List<PackageOps> loggedOps = mAppOpsService.getOpsForPackage(
@@ -282,10 +267,8 @@
 
     @Test
     public void testPackageRemoved() {
-        mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED, null);
-        mAppOpsService.noteOperationUnchecked(OP_READ_SMS, mMyUid,
-                resolvePackageName(mMyUid, sMyPackageName), null,
-                INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF);
+        mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
+        mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
 
         List<PackageOps> loggedOps = getLoggedOps();
         assertContainsOp(loggedOps, OP_READ_SMS, mTestStartMillis, -1, MODE_ALLOWED);
@@ -339,10 +322,8 @@
 
     @Test
     public void testUidRemoved() {
-        mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED, null);
-        mAppOpsService.noteOperationUnchecked(OP_READ_SMS, mMyUid,
-                resolvePackageName(mMyUid, sMyPackageName), null,
-                INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF);
+        mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
+        mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
 
         List<PackageOps> loggedOps = getLoggedOps();
         assertContainsOp(loggedOps, OP_READ_SMS, mTestStartMillis, -1, MODE_ALLOWED);
diff --git a/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsUidStateTrackerTest.java b/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsUidStateTrackerTest.java
index 3efd5e7..98e895a 100644
--- a/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsUidStateTrackerTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsUidStateTrackerTest.java
@@ -76,7 +76,7 @@
     ActivityManagerInternal mAmi;
 
     @Mock
-    AppOpsServiceImpl.Constants mConstants;
+    AppOpsService.Constants mConstants;
 
     AppOpsUidStateTrackerTestExecutor mExecutor = new AppOpsUidStateTrackerTestExecutor();
 
diff --git a/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsUpgradeTest.java b/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsUpgradeTest.java
index 298dbf4..9eed6ad 100644
--- a/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsUpgradeTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsUpgradeTest.java
@@ -16,23 +16,32 @@
 
 package com.android.server.appop;
 
+import static android.app.AppOpsManager.OP_SCHEDULE_EXACT_ALARM;
+
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
+
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyLong;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.ArgumentMatchers.nullable;
 import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
 
 import android.app.AppOpsManager;
 import android.content.Context;
 import android.content.pm.PackageManager;
+import android.content.pm.PackageManagerInternal;
 import android.content.res.AssetManager;
 import android.os.Handler;
-import android.os.HandlerThread;
+import android.os.UserHandle;
 import android.util.Log;
 import android.util.SparseArray;
 import android.util.SparseIntArray;
@@ -42,11 +51,20 @@
 import androidx.test.filters.SmallTest;
 import androidx.test.runner.AndroidJUnit4;
 
+import com.android.internal.util.ArrayUtils;
 import com.android.modules.utils.TypedXmlPullParser;
+import com.android.server.LocalServices;
+import com.android.server.SystemServerInitThreadPool;
+import com.android.server.pm.UserManagerInternal;
+import com.android.server.pm.permission.PermissionManagerServiceInternal;
 
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoSession;
+import org.mockito.quality.Strictness;
 import org.xmlpull.v1.XmlPullParser;
 
 import java.io.File;
@@ -64,42 +82,52 @@
     private static final String TAG = AppOpsUpgradeTest.class.getSimpleName();
     private static final String APP_OPS_UNVERSIONED_ASSET_PATH =
             "AppOpsUpgradeTest/appops-unversioned.xml";
+    private static final String APP_OPS_VERSION_1_ASSET_PATH =
+            "AppOpsUpgradeTest/appops-version-1.xml";
     private static final String APP_OPS_FILENAME = "appops-test.xml";
     private static final int NON_DEFAULT_OPS_IN_FILE = 4;
-    private static final int CURRENT_VERSION = 1;
 
-    private File mAppOpsFile;
-    private Context mContext;
+    private static final Context sContext = InstrumentationRegistry.getTargetContext();
+    private static final File sAppOpsFile = new File(sContext.getFilesDir(), APP_OPS_FILENAME);
+
+    private Context mTestContext;
+    private MockitoSession mMockitoSession;
+
+    @Mock
+    private PackageManagerInternal mPackageManagerInternal;
+    @Mock
+    private PackageManager mPackageManager;
+    @Mock
+    private UserManagerInternal mUserManagerInternal;
+    @Mock
+    private PermissionManagerServiceInternal mPermissionManagerInternal;
+    @Mock
     private Handler mHandler;
 
-    private void extractAppOpsFile() {
-        mAppOpsFile.getParentFile().mkdirs();
-        if (mAppOpsFile.exists()) {
-            mAppOpsFile.delete();
-        }
-        try (FileOutputStream out = new FileOutputStream(mAppOpsFile);
-             InputStream in = mContext.getAssets().open(APP_OPS_UNVERSIONED_ASSET_PATH,
-                     AssetManager.ACCESS_BUFFER)) {
+    private static void extractAppOpsFile(String assetPath) {
+        sAppOpsFile.getParentFile().mkdirs();
+        try (FileOutputStream out = new FileOutputStream(sAppOpsFile);
+             InputStream in = sContext.getAssets().open(assetPath, AssetManager.ACCESS_BUFFER)) {
             byte[] buffer = new byte[4096];
             int bytesRead;
             while ((bytesRead = in.read(buffer)) >= 0) {
                 out.write(buffer, 0, bytesRead);
             }
             out.flush();
-            Log.d(TAG, "Successfully copied xml to " + mAppOpsFile.getAbsolutePath());
+            Log.d(TAG, "Successfully copied xml to " + sAppOpsFile.getAbsolutePath());
         } catch (IOException exc) {
             Log.e(TAG, "Exception while copying appops xml", exc);
             fail();
         }
     }
 
-    private void assertSameModes(SparseArray<AppOpsServiceImpl.UidState> uidStates,
+    private void assertSameModes(SparseArray<AppOpsService.UidState> uidStates,
             int op1, int op2) {
         int numberOfNonDefaultOps = 0;
         final int defaultModeOp1 = AppOpsManager.opToDefaultMode(op1);
         final int defaultModeOp2 = AppOpsManager.opToDefaultMode(op2);
-        for(int i = 0; i < uidStates.size(); i++) {
-            final AppOpsServiceImpl.UidState uidState = uidStates.valueAt(i);
+        for (int i = 0; i < uidStates.size(); i++) {
+            final AppOpsService.UidState uidState = uidStates.valueAt(i);
             SparseIntArray opModes = uidState.getNonDefaultUidModes();
             if (opModes != null) {
                 final int uidMode1 = opModes.get(op1, defaultModeOp1);
@@ -113,12 +141,12 @@
                 continue;
             }
             for (int j = 0; j < uidState.pkgOps.size(); j++) {
-                final AppOpsServiceImpl.Ops ops = uidState.pkgOps.valueAt(j);
+                final AppOpsService.Ops ops = uidState.pkgOps.valueAt(j);
                 if (ops == null) {
                     continue;
                 }
-                final AppOpsServiceImpl.Op _op1 = ops.get(op1);
-                final AppOpsServiceImpl.Op _op2 = ops.get(op2);
+                final AppOpsService.Op _op1 = ops.get(op1);
+                final AppOpsService.Op _op2 = ops.get(op2);
                 final int mode1 = (_op1 == null) ? defaultModeOp1 : _op1.getMode();
                 final int mode2 = (_op2 == null) ? defaultModeOp2 : _op2.getMode();
                 assertEquals(mode1, mode2);
@@ -132,41 +160,191 @@
 
     @Before
     public void setUp() {
-        mContext = InstrumentationRegistry.getTargetContext();
-        mAppOpsFile = new File(mContext.getFilesDir(), APP_OPS_FILENAME);
-        extractAppOpsFile();
-        HandlerThread handlerThread = new HandlerThread(TAG);
-        handlerThread.start();
-        mHandler = new Handler(handlerThread.getLooper());
+        if (sAppOpsFile.exists()) {
+            sAppOpsFile.delete();
+        }
+
+        mMockitoSession = mockitoSession()
+                .initMocks(this)
+                .spyStatic(LocalServices.class)
+                .mockStatic(SystemServerInitThreadPool.class)
+                .strictness(Strictness.LENIENT)
+                .startMocking();
+
+        doReturn(mPermissionManagerInternal).when(
+                () -> LocalServices.getService(PermissionManagerServiceInternal.class));
+        doReturn(mUserManagerInternal).when(
+                () -> LocalServices.getService(UserManagerInternal.class));
+        doReturn(mPackageManagerInternal).when(
+                () -> LocalServices.getService(PackageManagerInternal.class));
+
+        mTestContext = spy(sContext);
+
+        // Pretend everybody has all permissions
+        doNothing().when(mTestContext).enforcePermission(anyString(), anyInt(), anyInt(),
+                nullable(String.class));
+
+        doReturn(mPackageManager).when(mTestContext).getPackageManager();
+
+        // Stub out package calls to disable AppOpsService#updatePermissionRevokedCompat
+        doReturn(null).when(mPackageManager).getPackagesForUid(anyInt());
+    }
+
+    @After
+    public void tearDown() {
+        mMockitoSession.finishMocking();
     }
 
     @Test
-    public void testUpgradeFromNoVersion() throws Exception {
-        AppOpsDataParser parser = new AppOpsDataParser(mAppOpsFile);
+    public void upgradeRunAnyInBackground() {
+        extractAppOpsFile(APP_OPS_UNVERSIONED_ASSET_PATH);
+
+        AppOpsService testService = new AppOpsService(sAppOpsFile, mHandler, mTestContext);
+
+        testService.upgradeRunAnyInBackgroundLocked();
+        assertSameModes(testService.mUidStates, AppOpsManager.OP_RUN_IN_BACKGROUND,
+                AppOpsManager.OP_RUN_ANY_IN_BACKGROUND);
+    }
+
+    private static int getModeInFile(int uid) {
+        switch (uid) {
+            case 10198:
+                return 0;
+            case 10200:
+                return 1;
+            case 1110200:
+            case 10267:
+            case 1110181:
+                return 2;
+            default:
+                return AppOpsManager.opToDefaultMode(OP_SCHEDULE_EXACT_ALARM);
+        }
+    }
+
+    @Test
+    public void upgradeScheduleExactAlarm() {
+        extractAppOpsFile(APP_OPS_VERSION_1_ASSET_PATH);
+
+        String[] packageNames = {"p1", "package2", "pkg3", "package.4", "pkg-5", "pkg.6"};
+        int[] appIds = {10267, 10181, 10198, 10199, 10200, 4213};
+        int[] userIds = {0, 10, 11};
+
+        doReturn(userIds).when(mUserManagerInternal).getUserIds();
+
+        doReturn(packageNames).when(mPermissionManagerInternal).getAppOpPermissionPackages(
+                AppOpsManager.opToPermission(OP_SCHEDULE_EXACT_ALARM));
+
+        doAnswer(invocation -> {
+            String pkg = invocation.getArgument(0);
+            int index = ArrayUtils.indexOf(packageNames, pkg);
+            if (index < 0) {
+                return index;
+            }
+            int userId = invocation.getArgument(2);
+            return UserHandle.getUid(userId, appIds[index]);
+        }).when(mPackageManagerInternal).getPackageUid(anyString(), anyLong(), anyInt());
+
+        AppOpsService testService = new AppOpsService(sAppOpsFile, mHandler, mTestContext);
+
+        testService.upgradeScheduleExactAlarmLocked();
+
+        for (int userId : userIds) {
+            for (int appId : appIds) {
+                final int uid = UserHandle.getUid(userId, appId);
+                final int previousMode = getModeInFile(uid);
+
+                final int expectedMode;
+                if (previousMode == AppOpsManager.opToDefaultMode(OP_SCHEDULE_EXACT_ALARM)) {
+                    expectedMode = AppOpsManager.MODE_ALLOWED;
+                } else {
+                    expectedMode = previousMode;
+                }
+                final AppOpsService.UidState uidState = testService.mUidStates.get(uid);
+                assertEquals(expectedMode, uidState.getUidMode(OP_SCHEDULE_EXACT_ALARM));
+            }
+        }
+
+        // These uids don't even declare the permission. So should stay as default / empty.
+        int[] unrelatedUidsInFile = {10225, 10178};
+
+        for (int uid : unrelatedUidsInFile) {
+            final AppOpsService.UidState uidState = testService.mUidStates.get(uid);
+            assertEquals(AppOpsManager.opToDefaultMode(OP_SCHEDULE_EXACT_ALARM),
+                    uidState.getUidMode(OP_SCHEDULE_EXACT_ALARM));
+        }
+    }
+
+    @Test
+    public void upgradeFromNoFile() {
+        assertFalse(sAppOpsFile.exists());
+
+        AppOpsService testService = spy(
+                new AppOpsService(sAppOpsFile, mHandler, mTestContext));
+
+        doNothing().when(testService).upgradeRunAnyInBackgroundLocked();
+        doNothing().when(testService).upgradeScheduleExactAlarmLocked();
+
+        // trigger upgrade
+        testService.systemReady();
+
+        verify(testService, never()).upgradeRunAnyInBackgroundLocked();
+        verify(testService, never()).upgradeScheduleExactAlarmLocked();
+
+        testService.writeState();
+
+        assertTrue(sAppOpsFile.exists());
+
+        AppOpsDataParser parser = new AppOpsDataParser(sAppOpsFile);
+        assertTrue(parser.parse());
+        assertEquals(AppOpsService.CURRENT_VERSION, parser.mVersion);
+    }
+
+    @Test
+    public void upgradeFromNoVersion() {
+        extractAppOpsFile(APP_OPS_UNVERSIONED_ASSET_PATH);
+        AppOpsDataParser parser = new AppOpsDataParser(sAppOpsFile);
         assertTrue(parser.parse());
         assertEquals(AppOpsDataParser.NO_VERSION, parser.mVersion);
 
-        // Use mock context and package manager to fake permision package manager calls.
-        Context testContext = spy(mContext);
+        AppOpsService testService = spy(
+                new AppOpsService(sAppOpsFile, mHandler, mTestContext));
 
-        // Pretent everybody has all permissions
-        doNothing().when(testContext).enforcePermission(anyString(), anyInt(), anyInt(),
-                nullable(String.class));
+        doNothing().when(testService).upgradeRunAnyInBackgroundLocked();
+        doNothing().when(testService).upgradeScheduleExactAlarmLocked();
 
-        PackageManager testPM = mock(PackageManager.class);
-        when(testContext.getPackageManager()).thenReturn(testPM);
+        // trigger upgrade
+        testService.systemReady();
 
-        // Stub out package calls to disable AppOpsService#updatePermissionRevokedCompat
-        when(testPM.getPackagesForUid(anyInt())).thenReturn(null);
+        verify(testService).upgradeRunAnyInBackgroundLocked();
+        verify(testService).upgradeScheduleExactAlarmLocked();
 
-        AppOpsServiceImpl testService = spy(
-                new AppOpsServiceImpl(mAppOpsFile, mHandler, testContext)); // trigger upgrade
-        assertSameModes(testService.mUidStates, AppOpsManager.OP_RUN_IN_BACKGROUND,
-                AppOpsManager.OP_RUN_ANY_IN_BACKGROUND);
-        mHandler.removeCallbacks(testService.mWriteRunner);
         testService.writeState();
         assertTrue(parser.parse());
-        assertEquals(CURRENT_VERSION, parser.mVersion);
+        assertEquals(AppOpsService.CURRENT_VERSION, parser.mVersion);
+    }
+
+    @Test
+    public void upgradeFromVersion1() {
+        extractAppOpsFile(APP_OPS_VERSION_1_ASSET_PATH);
+        AppOpsDataParser parser = new AppOpsDataParser(sAppOpsFile);
+        assertTrue(parser.parse());
+        assertEquals(1, parser.mVersion);
+
+        AppOpsService testService = spy(
+                new AppOpsService(sAppOpsFile, mHandler, mTestContext));
+
+        doNothing().when(testService).upgradeRunAnyInBackgroundLocked();
+        doNothing().when(testService).upgradeScheduleExactAlarmLocked();
+
+        // trigger upgrade
+        testService.systemReady();
+
+        verify(testService, never()).upgradeRunAnyInBackgroundLocked();
+        verify(testService).upgradeScheduleExactAlarmLocked();
+
+        testService.writeState();
+        assertTrue(parser.parse());
+        assertEquals(AppOpsService.CURRENT_VERSION, parser.mVersion);
     }
 
     /**
@@ -174,7 +352,7 @@
      * Other fields may be added as and when required for testing.
      */
     private static final class AppOpsDataParser {
-        static final int NO_VERSION = -1;
+        static final int NO_VERSION = -123;
         int mVersion;
         private File mFile;
 
diff --git a/services/tests/mockingservicestests/src/com/android/server/display/LocalDisplayAdapterTest.java b/services/tests/mockingservicestests/src/com/android/server/display/LocalDisplayAdapterTest.java
index f105971..4524759 100644
--- a/services/tests/mockingservicestests/src/com/android/server/display/LocalDisplayAdapterTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/display/LocalDisplayAdapterTest.java
@@ -169,6 +169,18 @@
                 .thenReturn(mockArray);
         when(mMockedResources.obtainTypedArray(R.array.config_builtInDisplayIsRoundArray))
                 .thenReturn(mockArray);
+        when(mMockedResources.getIntArray(
+            com.android.internal.R.array.config_brightnessThresholdsOfPeakRefreshRate))
+            .thenReturn(new int[]{});
+        when(mMockedResources.getIntArray(
+            com.android.internal.R.array.config_ambientThresholdsOfPeakRefreshRate))
+            .thenReturn(new int[]{});
+        when(mMockedResources.getIntArray(
+            com.android.internal.R.array.config_highDisplayBrightnessThresholdsOfFixedRefreshRate))
+            .thenReturn(new int[]{});
+        when(mMockedResources.getIntArray(
+            com.android.internal.R.array.config_highAmbientBrightnessThresholdsOfFixedRefreshRate))
+            .thenReturn(new int[]{});
     }
 
     @After
@@ -1046,9 +1058,9 @@
         mAddresses.add(display.address);
         when(mSurfaceControlProxy.getPhysicalDisplayToken(display.address.getPhysicalDisplayId()))
                 .thenReturn(display.token);
-        when(mSurfaceControlProxy.getStaticDisplayInfo(display.token))
+        when(mSurfaceControlProxy.getStaticDisplayInfo(display.address.getPhysicalDisplayId()))
                 .thenReturn(display.info);
-        when(mSurfaceControlProxy.getDynamicDisplayInfo(display.token))
+        when(mSurfaceControlProxy.getDynamicDisplayInfo(display.address.getPhysicalDisplayId()))
                 .thenReturn(display.dynamicInfo);
         when(mSurfaceControlProxy.getDesiredDisplayModeSpecs(display.token))
                 .thenReturn(display.desiredDisplayModeSpecs);
diff --git a/services/tests/mockingservicestests/src/com/android/server/job/JobConcurrencyManagerTest.java b/services/tests/mockingservicestests/src/com/android/server/job/JobConcurrencyManagerTest.java
index 6e4d214..480a4f3 100644
--- a/services/tests/mockingservicestests/src/com/android/server/job/JobConcurrencyManagerTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/job/JobConcurrencyManagerTest.java
@@ -113,7 +113,8 @@
 
         @Override
         JobServiceContext createJobServiceContext(JobSchedulerService service,
-                JobConcurrencyManager concurrencyManager, IBatteryStats batteryStats,
+                JobConcurrencyManager concurrencyManager,
+                JobNotificationCoordinator notificationCoordinator, IBatteryStats batteryStats,
                 JobPackageTracker tracker, Looper looper) {
             final JobServiceContext context = mock(JobServiceContext.class);
             doAnswer((Answer<Boolean>) invocationOnMock -> {
@@ -216,7 +217,7 @@
         assertEquals(0, preferredUidOnly.size());
         assertEquals(0, stoppable.size());
         assertEquals(0, assignmentInfo.minPreferredUidOnlyWaitingTimeMs);
-        assertEquals(0, assignmentInfo.numRunningTopEj);
+        assertEquals(0, assignmentInfo.numRunningImmediacyPrivileged);
     }
 
     @Test
@@ -238,7 +239,7 @@
         assertEquals(0, preferredUidOnly.size());
         assertEquals(0, stoppable.size());
         assertEquals(0, assignmentInfo.minPreferredUidOnlyWaitingTimeMs);
-        assertEquals(0, assignmentInfo.numRunningTopEj);
+        assertEquals(0, assignmentInfo.numRunningImmediacyPrivileged);
     }
 
     @Test
@@ -264,15 +265,14 @@
         assertEquals(JobConcurrencyManager.STANDARD_CONCURRENCY_LIMIT, preferredUidOnly.size());
         assertEquals(0, stoppable.size());
         assertEquals(0, assignmentInfo.minPreferredUidOnlyWaitingTimeMs);
-        assertEquals(0, assignmentInfo.numRunningTopEj);
+        assertEquals(0, assignmentInfo.numRunningImmediacyPrivileged);
     }
 
     @Test
-    public void testPrepareForAssignmentDetermination_onlyRunningTopEjs() {
+    public void testPrepareForAssignmentDetermination_onlyStartedWithImmediacyPrivilege() {
         for (int i = 0; i < JobConcurrencyManager.STANDARD_CONCURRENCY_LIMIT; ++i) {
             JobStatus job = createJob(mDefaultUserId * UserHandle.PER_USER_RANGE + i);
-            job.startedAsExpeditedJob = true;
-            job.lastEvaluatedBias = JobInfo.BIAS_TOP_APP;
+            job.startedWithImmediacyPrivilege = true;
             mJobConcurrencyManager.addRunningJobForTesting(job);
         }
 
@@ -293,7 +293,7 @@
         assertEquals(JobConcurrencyManager.STANDARD_CONCURRENCY_LIMIT / 2, stoppable.size());
         assertEquals(0, assignmentInfo.minPreferredUidOnlyWaitingTimeMs);
         assertEquals(JobConcurrencyManager.STANDARD_CONCURRENCY_LIMIT,
-                assignmentInfo.numRunningTopEj);
+                assignmentInfo.numRunningImmediacyPrivileged);
     }
 
     @Test
@@ -499,6 +499,38 @@
     }
 
     @Test
+    public void testHasImmediacyPrivilege() {
+        JobStatus job = createJob(mDefaultUserId * UserHandle.PER_USER_RANGE, 0);
+        spyOn(job);
+        assertFalse(mJobConcurrencyManager.hasImmediacyPrivilegeLocked(job));
+
+        doReturn(false).when(job).shouldTreatAsExpeditedJob();
+        doReturn(false).when(job).shouldTreatAsUserInitiated();
+        job.lastEvaluatedBias = JobInfo.BIAS_TOP_APP;
+        assertFalse(mJobConcurrencyManager.hasImmediacyPrivilegeLocked(job));
+
+        doReturn(true).when(job).shouldTreatAsExpeditedJob();
+        doReturn(false).when(job).shouldTreatAsUserInitiated();
+        job.lastEvaluatedBias = JobInfo.BIAS_DEFAULT;
+        assertFalse(mJobConcurrencyManager.hasImmediacyPrivilegeLocked(job));
+
+        doReturn(false).when(job).shouldTreatAsExpeditedJob();
+        doReturn(true).when(job).shouldTreatAsUserInitiated();
+        job.lastEvaluatedBias = JobInfo.BIAS_DEFAULT;
+        assertFalse(mJobConcurrencyManager.hasImmediacyPrivilegeLocked(job));
+
+        doReturn(false).when(job).shouldTreatAsExpeditedJob();
+        doReturn(true).when(job).shouldTreatAsUserInitiated();
+        job.lastEvaluatedBias = JobInfo.BIAS_TOP_APP;
+        assertTrue(mJobConcurrencyManager.hasImmediacyPrivilegeLocked(job));
+
+        doReturn(true).when(job).shouldTreatAsExpeditedJob();
+        doReturn(false).when(job).shouldTreatAsUserInitiated();
+        job.lastEvaluatedBias = JobInfo.BIAS_TOP_APP;
+        assertTrue(mJobConcurrencyManager.hasImmediacyPrivilegeLocked(job));
+    }
+
+    @Test
     public void testIsPkgConcurrencyLimited_top() {
         final JobStatus topJob = createJob(mDefaultUserId * UserHandle.PER_USER_RANGE, 0);
         topJob.lastEvaluatedBias = JobInfo.BIAS_TOP_APP;
diff --git a/services/tests/mockingservicestests/src/com/android/server/job/JobNotificationCoordinatorTest.java b/services/tests/mockingservicestests/src/com/android/server/job/JobNotificationCoordinatorTest.java
new file mode 100644
index 0000000..b4104db
--- /dev/null
+++ b/services/tests/mockingservicestests/src/com/android/server/job/JobNotificationCoordinatorTest.java
@@ -0,0 +1,440 @@
+/*
+ * 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.server.job;
+
+
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.inOrder;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
+
+import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.job.JobService;
+import android.graphics.drawable.Icon;
+import android.os.UserHandle;
+
+import com.android.server.LocalServices;
+import com.android.server.notification.NotificationManagerInternal;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.MockitoSession;
+import org.mockito.quality.Strictness;
+
+public class JobNotificationCoordinatorTest {
+    private static final String TEST_PACKAGE = "com.android.test";
+    private static final String NOTIFICATION_CHANNEL_ID = "validNotificationChannelId";
+
+    private MockitoSession mMockingSession;
+
+    @Mock
+    private NotificationManagerInternal mNotificationManagerInternal;
+
+    @Before
+    public void setUp() {
+        mMockingSession = mockitoSession()
+                .initMocks(this)
+                .mockStatic(LocalServices.class)
+                .strictness(Strictness.LENIENT)
+                .startMocking();
+        doReturn(mNotificationManagerInternal)
+                .when(() -> LocalServices.getService(NotificationManagerInternal.class));
+        doNothing().when(mNotificationManagerInternal)
+                .enqueueNotification(anyString(), anyString(), anyInt(), anyInt(), any(),
+                        anyInt(), any(), anyInt());
+        doNothing().when(mNotificationManagerInternal)
+                .enqueueNotification(anyString(), anyString(), anyInt(), anyInt(), any(),
+                        anyInt(), any(), anyInt());
+        doReturn(mock(NotificationChannel.class)).when(mNotificationManagerInternal)
+                .getNotificationChannel(anyString(), anyInt(), eq(NOTIFICATION_CHANNEL_ID));
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        if (mMockingSession != null) {
+            mMockingSession.finishMocking();
+        }
+    }
+
+    @Test
+    public void testParameterValidation() {
+        final JobNotificationCoordinator coordinator = new JobNotificationCoordinator();
+        final JobServiceContext jsc = mock(JobServiceContext.class);
+        final int uid = 10123;
+        final int pid = 42;
+        final int notificationId = 23;
+
+        try {
+            coordinator.enqueueNotification(jsc, TEST_PACKAGE, pid, uid, notificationId, null,
+                    JobService.JOB_END_NOTIFICATION_POLICY_DETACH);
+            fail("Successfully enqueued a null notification");
+        } catch (NullPointerException e) {
+            // Success
+        }
+
+        Notification notification = createValidNotification();
+        doReturn(null).when(notification).getSmallIcon();
+        try {
+            coordinator.enqueueNotification(jsc, TEST_PACKAGE, pid, uid, notificationId,
+                    notification, JobService.JOB_END_NOTIFICATION_POLICY_DETACH);
+            fail("Successfully enqueued a notification with no small icon");
+        } catch (IllegalArgumentException e) {
+            // Success
+        }
+
+        notification = createValidNotification();
+        doReturn(null).when(notification).getChannelId();
+        try {
+            coordinator.enqueueNotification(jsc, TEST_PACKAGE, pid, uid, notificationId,
+                    notification, JobService.JOB_END_NOTIFICATION_POLICY_DETACH);
+            fail("Successfully enqueued a notification with no valid channel");
+        } catch (IllegalArgumentException e) {
+            // Success
+        }
+
+        notification = createValidNotification();
+        try {
+            coordinator.enqueueNotification(jsc, TEST_PACKAGE, pid, uid, notificationId,
+                    notification, Integer.MAX_VALUE);
+            fail("Successfully enqueued a notification with an invalid job end notification "
+                    + "policy");
+        } catch (IllegalArgumentException e) {
+            // Success
+        }
+    }
+
+    @Test
+    public void testSingleJob_DetachOnStop() {
+        final JobNotificationCoordinator coordinator = new JobNotificationCoordinator();
+        final JobServiceContext jsc = mock(JobServiceContext.class);
+        final Notification notification = createValidNotification();
+        final int uid = 10123;
+        final int pid = 42;
+        final int notificationId = 23;
+
+        coordinator.enqueueNotification(jsc, TEST_PACKAGE, pid, uid, notificationId, notification,
+                JobService.JOB_END_NOTIFICATION_POLICY_DETACH);
+        verify(mNotificationManagerInternal)
+                .enqueueNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid), eq(pid), any(),
+                        eq(notificationId), eq(notification), eq(UserHandle.getUserId(uid)));
+
+        coordinator.removeNotificationAssociation(jsc);
+        verify(mNotificationManagerInternal, never())
+                .cancelNotification(anyString(), anyString(), anyInt(), anyInt(), any(),
+                        anyInt(), anyInt());
+    }
+
+    @Test
+    public void testSingleJob_RemoveOnStop() {
+        final JobNotificationCoordinator coordinator = new JobNotificationCoordinator();
+        final JobServiceContext jsc = mock(JobServiceContext.class);
+        final Notification notification = createValidNotification();
+        final int uid = 10123;
+        final int pid = 42;
+        final int notificationId = 23;
+
+        coordinator.enqueueNotification(jsc, TEST_PACKAGE, pid, uid, notificationId, notification,
+                JobService.JOB_END_NOTIFICATION_POLICY_REMOVE);
+        verify(mNotificationManagerInternal)
+                .enqueueNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid), eq(pid), any(),
+                        eq(notificationId), eq(notification), eq(UserHandle.getUserId(uid)));
+
+        coordinator.removeNotificationAssociation(jsc);
+        verify(mNotificationManagerInternal)
+                .cancelNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid), eq(pid), any(),
+                        eq(notificationId), eq(UserHandle.getUserId(uid)));
+    }
+
+    @Test
+    public void testSingleJob_EnqueueDifferentNotificationId_DetachOnStop() {
+        final JobNotificationCoordinator coordinator = new JobNotificationCoordinator();
+        final JobServiceContext jsc = mock(JobServiceContext.class);
+        final Notification notification1 = createValidNotification();
+        final Notification notification2 = createValidNotification();
+        final int uid = 10123;
+        final int pid = 42;
+        final int notificationId1 = 23;
+        final int notificationId2 = 46;
+
+        InOrder inOrder = inOrder(mNotificationManagerInternal);
+
+        coordinator.enqueueNotification(jsc, TEST_PACKAGE, pid, uid, notificationId1, notification1,
+                JobService.JOB_END_NOTIFICATION_POLICY_DETACH);
+        inOrder.verify(mNotificationManagerInternal)
+                .enqueueNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid), eq(pid), any(),
+                        eq(notificationId1), eq(notification1), eq(UserHandle.getUserId(uid)));
+
+        coordinator.enqueueNotification(jsc, TEST_PACKAGE, pid, uid, notificationId2, notification2,
+                JobService.JOB_END_NOTIFICATION_POLICY_DETACH);
+        inOrder.verify(mNotificationManagerInternal, never())
+                .cancelNotification(anyString(), anyString(), anyInt(), anyInt(), any(),
+                        anyInt(), anyInt());
+        inOrder.verify(mNotificationManagerInternal)
+                .enqueueNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid), eq(pid), any(),
+                        eq(notificationId2), eq(notification2), eq(UserHandle.getUserId(uid)));
+    }
+
+    @Test
+    public void testSingleJob_EnqueueDifferentNotificationId_RemoveOnStop() {
+        final JobNotificationCoordinator coordinator = new JobNotificationCoordinator();
+        final JobServiceContext jsc = mock(JobServiceContext.class);
+        final Notification notification1 = createValidNotification();
+        final Notification notification2 = createValidNotification();
+        final int uid = 10123;
+        final int pid = 42;
+        final int notificationId1 = 23;
+        final int notificationId2 = 46;
+
+        InOrder inOrder = inOrder(mNotificationManagerInternal);
+
+        coordinator.enqueueNotification(jsc, TEST_PACKAGE, pid, uid, notificationId1, notification1,
+                JobService.JOB_END_NOTIFICATION_POLICY_REMOVE);
+        inOrder.verify(mNotificationManagerInternal)
+                .enqueueNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid), eq(pid), any(),
+                        eq(notificationId1), eq(notification1), eq(UserHandle.getUserId(uid)));
+
+        coordinator.enqueueNotification(jsc, TEST_PACKAGE, pid, uid, notificationId2, notification2,
+                JobService.JOB_END_NOTIFICATION_POLICY_REMOVE);
+        inOrder.verify(mNotificationManagerInternal)
+                .cancelNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid), eq(pid), any(),
+                        eq(notificationId1), eq(UserHandle.getUserId(uid)));
+        inOrder.verify(mNotificationManagerInternal)
+                .enqueueNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid), eq(pid), any(),
+                        eq(notificationId2), eq(notification2), eq(UserHandle.getUserId(uid)));
+    }
+
+    @Test
+    public void testSingleJob_EnqueueSameNotificationId() {
+        final JobNotificationCoordinator coordinator = new JobNotificationCoordinator();
+        final JobServiceContext jsc = mock(JobServiceContext.class);
+        final Notification notification1 = createValidNotification();
+        final Notification notification2 = createValidNotification();
+        final int uid = 10123;
+        final int pid = 42;
+        final int notificationId = 23;
+
+        InOrder inOrder = inOrder(mNotificationManagerInternal);
+
+        coordinator.enqueueNotification(jsc, TEST_PACKAGE, pid, uid, notificationId, notification1,
+                JobService.JOB_END_NOTIFICATION_POLICY_DETACH);
+        inOrder.verify(mNotificationManagerInternal)
+                .enqueueNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid), eq(pid), any(),
+                        eq(notificationId), eq(notification1), eq(UserHandle.getUserId(uid)));
+
+        coordinator.enqueueNotification(jsc, TEST_PACKAGE, pid, uid, notificationId, notification2,
+                JobService.JOB_END_NOTIFICATION_POLICY_DETACH);
+        inOrder.verify(mNotificationManagerInternal, never())
+                .cancelNotification(anyString(), anyString(), anyInt(), anyInt(), any(),
+                        anyInt(), anyInt());
+        inOrder.verify(mNotificationManagerInternal)
+                .enqueueNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid), eq(pid), any(),
+                        eq(notificationId), eq(notification2), eq(UserHandle.getUserId(uid)));
+    }
+
+    @Test
+    public void testMultipleJobs_sameApp_EnqueueDifferentNotificationId() {
+        final JobNotificationCoordinator coordinator = new JobNotificationCoordinator();
+        final JobServiceContext jsc1 = mock(JobServiceContext.class);
+        final JobServiceContext jsc2 = mock(JobServiceContext.class);
+        final Notification notification1 = createValidNotification();
+        final Notification notification2 = createValidNotification();
+        final int uid = 10123;
+        final int pid = 42;
+        final int notificationId1 = 23;
+        final int notificationId2 = 46;
+
+        InOrder inOrder = inOrder(mNotificationManagerInternal);
+
+        coordinator.enqueueNotification(jsc1, TEST_PACKAGE, pid, uid, notificationId1,
+                notification1, JobService.JOB_END_NOTIFICATION_POLICY_REMOVE);
+        inOrder.verify(mNotificationManagerInternal)
+                .enqueueNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid), eq(pid), any(),
+                        eq(notificationId1), eq(notification1), eq(UserHandle.getUserId(uid)));
+
+        coordinator.enqueueNotification(jsc2, TEST_PACKAGE, pid, uid, notificationId2,
+                notification2, JobService.JOB_END_NOTIFICATION_POLICY_REMOVE);
+        inOrder.verify(mNotificationManagerInternal, never())
+                .cancelNotification(anyString(), anyString(), anyInt(), anyInt(), any(),
+                        anyInt(), anyInt());
+        inOrder.verify(mNotificationManagerInternal)
+                .enqueueNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid), eq(pid), any(),
+                        eq(notificationId2), eq(notification2), eq(UserHandle.getUserId(uid)));
+
+        // Remove the first job. Only the first notification should be removed.
+        coordinator.removeNotificationAssociation(jsc1);
+        inOrder.verify(mNotificationManagerInternal)
+                .cancelNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid), eq(pid), any(),
+                        eq(notificationId1), eq(UserHandle.getUserId(uid)));
+        inOrder.verify(mNotificationManagerInternal, never())
+                .cancelNotification(anyString(), anyString(), anyInt(), anyInt(), any(),
+                        eq(notificationId2), anyInt());
+
+        coordinator.removeNotificationAssociation(jsc2);
+        inOrder.verify(mNotificationManagerInternal)
+                .cancelNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid), eq(pid), any(),
+                        eq(notificationId2), eq(UserHandle.getUserId(uid)));
+    }
+
+    @Test
+    public void testMultipleJobs_sameApp_EnqueueSameNotificationId() {
+        final JobNotificationCoordinator coordinator = new JobNotificationCoordinator();
+        final JobServiceContext jsc1 = mock(JobServiceContext.class);
+        final JobServiceContext jsc2 = mock(JobServiceContext.class);
+        final Notification notification1 = createValidNotification();
+        final Notification notification2 = createValidNotification();
+        final int uid = 10123;
+        final int pid = 42;
+        final int notificationId = 23;
+
+        InOrder inOrder = inOrder(mNotificationManagerInternal);
+
+        coordinator.enqueueNotification(jsc1, TEST_PACKAGE, pid, uid, notificationId, notification1,
+                JobService.JOB_END_NOTIFICATION_POLICY_DETACH);
+        inOrder.verify(mNotificationManagerInternal)
+                .enqueueNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid), eq(pid), any(),
+                        eq(notificationId), eq(notification1), eq(UserHandle.getUserId(uid)));
+
+        coordinator.enqueueNotification(jsc2, TEST_PACKAGE, pid, uid, notificationId, notification2,
+                JobService.JOB_END_NOTIFICATION_POLICY_REMOVE);
+        inOrder.verify(mNotificationManagerInternal, never())
+                .cancelNotification(anyString(), anyString(), anyInt(), anyInt(), any(),
+                        anyInt(), anyInt());
+        inOrder.verify(mNotificationManagerInternal)
+                .enqueueNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid), eq(pid), any(),
+                        eq(notificationId), eq(notification2), eq(UserHandle.getUserId(uid)));
+
+        // Remove the first job. The notification shouldn't be touched because of the 2nd job.
+        coordinator.removeNotificationAssociation(jsc1);
+        inOrder.verify(mNotificationManagerInternal, never())
+                .cancelNotification(anyString(), anyString(), anyInt(), anyInt(), any(),
+                        anyInt(), anyInt());
+
+        coordinator.removeNotificationAssociation(jsc2);
+        inOrder.verify(mNotificationManagerInternal)
+                .cancelNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid), eq(pid), any(),
+                        eq(notificationId), eq(UserHandle.getUserId(uid)));
+    }
+
+    @Test
+    public void testMultipleJobs_sameApp_DifferentUsers() {
+        final JobNotificationCoordinator coordinator = new JobNotificationCoordinator();
+        final JobServiceContext jsc1 = mock(JobServiceContext.class);
+        final JobServiceContext jsc2 = mock(JobServiceContext.class);
+        final Notification notification1 = createValidNotification();
+        final Notification notification2 = createValidNotification();
+        final int uid1 = 10123;
+        final int uid2 = 1010123;
+        final int pid = 42;
+        final int notificationId = 23;
+
+        InOrder inOrder = inOrder(mNotificationManagerInternal);
+
+        coordinator.enqueueNotification(jsc1, TEST_PACKAGE, pid, uid1, notificationId,
+                notification1, JobService.JOB_END_NOTIFICATION_POLICY_REMOVE);
+        inOrder.verify(mNotificationManagerInternal)
+                .enqueueNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid1), eq(pid), any(),
+                        eq(notificationId), eq(notification1), eq(UserHandle.getUserId(uid1)));
+
+        coordinator.enqueueNotification(jsc2, TEST_PACKAGE, pid, uid2, notificationId,
+                notification2, JobService.JOB_END_NOTIFICATION_POLICY_REMOVE);
+        inOrder.verify(mNotificationManagerInternal, never())
+                .cancelNotification(anyString(), anyString(), anyInt(), anyInt(), any(),
+                        anyInt(), anyInt());
+        inOrder.verify(mNotificationManagerInternal)
+                .enqueueNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid2), eq(pid), any(),
+                        eq(notificationId), eq(notification2), eq(UserHandle.getUserId(uid2)));
+
+        // Remove the first job. Only the first notification should be removed.
+        coordinator.removeNotificationAssociation(jsc1);
+        inOrder.verify(mNotificationManagerInternal)
+                .cancelNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid1), eq(pid), any(),
+                        eq(notificationId), eq(UserHandle.getUserId(uid1)));
+        inOrder.verify(mNotificationManagerInternal, never())
+                .cancelNotification(anyString(), anyString(), eq(uid2), anyInt(), any(),
+                        anyInt(), anyInt());
+
+        coordinator.removeNotificationAssociation(jsc2);
+        inOrder.verify(mNotificationManagerInternal)
+                .cancelNotification(eq(TEST_PACKAGE), eq(TEST_PACKAGE), eq(uid2), eq(pid), any(),
+                        eq(notificationId), eq(UserHandle.getUserId(uid2)));
+    }
+
+    @Test
+    public void testMultipleJobs_differentApps() {
+        final JobNotificationCoordinator coordinator = new JobNotificationCoordinator();
+        final String pkg1 = "pkg1";
+        final String pkg2 = "pkg2";
+        final JobServiceContext jsc1 = mock(JobServiceContext.class);
+        final JobServiceContext jsc2 = mock(JobServiceContext.class);
+        final Notification notification1 = createValidNotification();
+        final Notification notification2 = createValidNotification();
+        final int uid = 10123;
+        final int pid = 42;
+        final int notificationId = 23;
+
+        InOrder inOrder = inOrder(mNotificationManagerInternal);
+
+        coordinator.enqueueNotification(jsc1, pkg1, pid, uid, notificationId, notification1,
+                JobService.JOB_END_NOTIFICATION_POLICY_REMOVE);
+        inOrder.verify(mNotificationManagerInternal)
+                .enqueueNotification(eq(pkg1), eq(pkg1), eq(uid), eq(pid), any(),
+                        eq(notificationId), eq(notification1), eq(UserHandle.getUserId(uid)));
+
+        coordinator.enqueueNotification(jsc2, pkg2, pid, uid, notificationId, notification2,
+                JobService.JOB_END_NOTIFICATION_POLICY_REMOVE);
+        inOrder.verify(mNotificationManagerInternal, never())
+                .cancelNotification(anyString(), anyString(), anyInt(), anyInt(), any(),
+                        anyInt(), anyInt());
+        inOrder.verify(mNotificationManagerInternal)
+                .enqueueNotification(eq(pkg2), eq(pkg2), eq(uid), eq(pid), any(),
+                        eq(notificationId), eq(notification2), eq(UserHandle.getUserId(uid)));
+
+        // Remove the first job. Only the first notification should be removed.
+        coordinator.removeNotificationAssociation(jsc1);
+        inOrder.verify(mNotificationManagerInternal)
+                .cancelNotification(eq(pkg1), eq(pkg1), eq(uid), eq(pid), any(),
+                        eq(notificationId), eq(UserHandle.getUserId(uid)));
+        inOrder.verify(mNotificationManagerInternal, never())
+                .cancelNotification(anyString(), anyString(), eq(uid), anyInt(), any(),
+                        anyInt(), anyInt());
+
+        coordinator.removeNotificationAssociation(jsc2);
+        inOrder.verify(mNotificationManagerInternal)
+                .cancelNotification(eq(pkg2), eq(pkg2), eq(uid), eq(pid), any(),
+                        eq(notificationId), eq(UserHandle.getUserId(uid)));
+    }
+
+    private Notification createValidNotification() {
+        final Notification notification = mock(Notification.class);
+        doReturn(mock(Icon.class)).when(notification).getSmallIcon();
+        doReturn(NOTIFICATION_CHANNEL_ID).when(notification).getChannelId();
+        return notification;
+    }
+}
diff --git a/services/tests/mockingservicestests/src/com/android/server/job/JobSchedulerServiceTest.java b/services/tests/mockingservicestests/src/com/android/server/job/JobSchedulerServiceTest.java
index fc737d0..0eeebca 100644
--- a/services/tests/mockingservicestests/src/com/android/server/job/JobSchedulerServiceTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/job/JobSchedulerServiceTest.java
@@ -34,6 +34,8 @@
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyBoolean;
 import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.when;
 
 import android.app.ActivityManager;
@@ -46,6 +48,7 @@
 import android.app.usage.UsageStatsManagerInternal;
 import android.content.ComponentName;
 import android.content.Context;
+import android.content.PermissionChecker;
 import android.content.pm.PackageManager;
 import android.content.pm.PackageManagerInternal;
 import android.content.res.Resources;
@@ -63,7 +66,10 @@
 import com.android.server.LocalServices;
 import com.android.server.PowerAllowlistInternal;
 import com.android.server.SystemServiceManager;
+import com.android.server.job.controllers.ConnectivityController;
 import com.android.server.job.controllers.JobStatus;
+import com.android.server.job.controllers.QuotaController;
+import com.android.server.job.controllers.TareController;
 import com.android.server.pm.UserManagerInternal;
 import com.android.server.usage.AppStandbyInternal;
 
@@ -102,6 +108,7 @@
                 .initMocks(this)
                 .strictness(Strictness.LENIENT)
                 .mockStatic(LocalServices.class)
+                .mockStatic(PermissionChecker.class)
                 .mockStatic(ServiceManager.class)
                 .startMocking();
 
@@ -193,6 +200,15 @@
                 jobInfoBuilder.build(), callingUid, "com.android.test", 0, testTag);
     }
 
+    private void grantRunLongJobsPermission(boolean grant) {
+        final int permissionStatus = grant
+                ? PermissionChecker.PERMISSION_GRANTED : PermissionChecker.PERMISSION_HARD_DENIED;
+        doReturn(permissionStatus)
+                .when(() -> PermissionChecker.checkPermissionForPreflight(
+                        any(), eq(android.Manifest.permission.RUN_LONG_JOBS),
+                        anyInt(), anyInt(), anyString()));
+    }
+
     @Test
     public void testGetMinJobExecutionGuaranteeMs() {
         JobStatus ejMax = createJobStatus("testGetMinJobExecutionGuaranteeMs",
@@ -207,6 +223,15 @@
                 createJobInfo(5).setPriority(JobInfo.PRIORITY_HIGH));
         JobStatus jobDef = createJobStatus("testGetMinJobExecutionGuaranteeMs",
                 createJobInfo(6));
+        JobStatus jobDT = createJobStatus("testGetMinJobExecutionGuaranteeMs",
+                createJobInfo(7)
+                        .setDataTransfer(true).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY));
+        JobStatus jobUI = createJobStatus("testGetMinJobExecutionGuaranteeMs",
+                createJobInfo(8)); // TODO(255371817): add setUserInitiated(true)
+        JobStatus jobUIDT = createJobStatus("testGetMinJobExecutionGuaranteeMs",
+                // TODO(255371817): add setUserInitiated(true)
+                createJobInfo(9)
+                        .setDataTransfer(true).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY));
 
         spyOn(ejMax);
         spyOn(ejHigh);
@@ -214,6 +239,9 @@
         spyOn(ejHighDowngraded);
         spyOn(jobHigh);
         spyOn(jobDef);
+        spyOn(jobDT);
+        spyOn(jobUI);
+        spyOn(jobUIDT);
 
         when(ejMax.shouldTreatAsExpeditedJob()).thenReturn(true);
         when(ejHigh.shouldTreatAsExpeditedJob()).thenReturn(true);
@@ -221,6 +249,16 @@
         when(ejHighDowngraded.shouldTreatAsExpeditedJob()).thenReturn(false);
         when(jobHigh.shouldTreatAsExpeditedJob()).thenReturn(false);
         when(jobDef.shouldTreatAsExpeditedJob()).thenReturn(false);
+        when(jobUI.shouldTreatAsUserInitiated()).thenReturn(true);
+        when(jobUIDT.shouldTreatAsUserInitiated()).thenReturn(true);
+
+        ConnectivityController connectivityController = mService.getConnectivityController();
+        spyOn(connectivityController);
+        mService.mConstants.RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS = 10 * MINUTE_IN_MILLIS;
+        mService.mConstants.RUNTIME_DATA_TRANSFER_LIMIT_MS = 60 * MINUTE_IN_MILLIS;
+        mService.mConstants.RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_BUFFER_FACTOR = 1.5f;
+        mService.mConstants.RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS = HOUR_IN_MILLIS;
+        mService.mConstants.RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS = 6 * HOUR_IN_MILLIS;
 
         assertEquals(mService.mConstants.RUNTIME_MIN_EJ_GUARANTEE_MS,
                 mService.getMinJobExecutionGuaranteeMs(ejMax));
@@ -234,8 +272,96 @@
                 mService.getMinJobExecutionGuaranteeMs(jobHigh));
         assertEquals(mService.mConstants.RUNTIME_MIN_GUARANTEE_MS,
                 mService.getMinJobExecutionGuaranteeMs(jobDef));
+        grantRunLongJobsPermission(false); // Without permission
+        assertEquals(mService.mConstants.RUNTIME_MIN_GUARANTEE_MS,
+                mService.getMinJobExecutionGuaranteeMs(jobDT));
+        grantRunLongJobsPermission(true); // With permission
+        doReturn(ConnectivityController.UNKNOWN_TIME)
+                .when(connectivityController).getEstimatedTransferTimeMs(any());
+        assertEquals(mService.mConstants.RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS,
+                mService.getMinJobExecutionGuaranteeMs(jobDT));
+        doReturn(mService.mConstants.RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS / 2)
+                .when(connectivityController).getEstimatedTransferTimeMs(any());
+        assertEquals(mService.mConstants.RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS,
+                mService.getMinJobExecutionGuaranteeMs(jobDT));
+        doReturn(mService.mConstants.RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS * 2)
+                .when(connectivityController).getEstimatedTransferTimeMs(any());
+        assertEquals(mService.mConstants.RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS,
+                mService.getMinJobExecutionGuaranteeMs(jobDT));
+        doReturn(mService.mConstants.RUNTIME_DATA_TRANSFER_LIMIT_MS * 2)
+                .when(connectivityController).getEstimatedTransferTimeMs(any());
+        assertEquals(mService.mConstants.RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS,
+                mService.getMinJobExecutionGuaranteeMs(jobDT));
+        // UserInitiated
+        assertEquals(mService.mConstants.RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS,
+                mService.getMinJobExecutionGuaranteeMs(jobUI));
+        grantRunLongJobsPermission(false);
+        assertEquals(mService.mConstants.RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS,
+                mService.getMinJobExecutionGuaranteeMs(jobUIDT));
+        grantRunLongJobsPermission(true); // With permission
+        doReturn(ConnectivityController.UNKNOWN_TIME)
+                .when(connectivityController).getEstimatedTransferTimeMs(any());
+        assertEquals(mService.mConstants.RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS,
+                mService.getMinJobExecutionGuaranteeMs(jobUIDT));
+        doReturn(mService.mConstants.RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS / 2)
+                .when(connectivityController).getEstimatedTransferTimeMs(any());
+        assertEquals(mService.mConstants.RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS,
+                mService.getMinJobExecutionGuaranteeMs(jobUIDT));
+        doReturn(mService.mConstants.RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS * 2)
+                .when(connectivityController).getEstimatedTransferTimeMs(any());
+        assertEquals(
+                (long) (mService.mConstants.RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS
+                        * 2 * 1.5),
+                mService.getMinJobExecutionGuaranteeMs(jobUIDT));
+        doReturn(mService.mConstants.RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS * 2)
+                .when(connectivityController).getEstimatedTransferTimeMs(any());
+        assertEquals(mService.mConstants.RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS,
+                mService.getMinJobExecutionGuaranteeMs(jobUIDT));
     }
 
+    @Test
+    public void testGetMaxJobExecutionTimeMs() {
+        JobStatus jobDT = createJobStatus("testGetMaxJobExecutionTimeMs",
+                createJobInfo(7)
+                        .setDataTransfer(true).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY));
+        JobStatus jobUI = createJobStatus("testGetMaxJobExecutionTimeMs",
+                createJobInfo(9)); // TODO(255371817): add setUserInitiated(true)
+        JobStatus jobUIDT = createJobStatus("testGetMaxJobExecutionTimeMs",
+                // TODO(255371817): add setUserInitiated(true)
+                createJobInfo(10)
+                        .setDataTransfer(true).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY));
+
+        spyOn(jobDT);
+        spyOn(jobUI);
+        spyOn(jobUIDT);
+
+        when(jobUI.shouldTreatAsUserInitiated()).thenReturn(true);
+        when(jobUIDT.shouldTreatAsUserInitiated()).thenReturn(true);
+
+        QuotaController quotaController = mService.getQuotaController();
+        spyOn(quotaController);
+        TareController tareController = mService.getTareController();
+        spyOn(tareController);
+        doReturn(mService.mConstants.RUNTIME_FREE_QUOTA_MAX_LIMIT_MS)
+                .when(quotaController).getMaxJobExecutionTimeMsLocked(any());
+        doReturn(mService.mConstants.RUNTIME_FREE_QUOTA_MAX_LIMIT_MS)
+                .when(quotaController).getMaxJobExecutionTimeMsLocked(any());
+
+        grantRunLongJobsPermission(true);
+        assertEquals(mService.mConstants.RUNTIME_DATA_TRANSFER_LIMIT_MS,
+                mService.getMaxJobExecutionTimeMs(jobDT));
+        assertEquals(mService.mConstants.RUNTIME_USER_INITIATED_LIMIT_MS,
+                mService.getMaxJobExecutionTimeMs(jobUI));
+        assertEquals(mService.mConstants.RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS,
+                mService.getMaxJobExecutionTimeMs(jobUIDT));
+        grantRunLongJobsPermission(false);
+        assertEquals(mService.mConstants.RUNTIME_DATA_TRANSFER_LIMIT_MS,
+                mService.getMaxJobExecutionTimeMs(jobDT));
+        assertEquals(mService.mConstants.RUNTIME_FREE_QUOTA_MAX_LIMIT_MS,
+                mService.getMaxJobExecutionTimeMs(jobUI));
+        assertEquals(mService.mConstants.RUNTIME_FREE_QUOTA_MAX_LIMIT_MS,
+                mService.getMaxJobExecutionTimeMs(jobUIDT));
+    }
 
     /**
      * Confirm that {@link JobSchedulerService#getRescheduleJobForFailureLocked(JobStatus, int)}
diff --git a/services/tests/mockingservicestests/src/com/android/server/job/controllers/ConnectivityControllerTest.java b/services/tests/mockingservicestests/src/com/android/server/job/controllers/ConnectivityControllerTest.java
index 1f85f2c..42e22f3 100644
--- a/services/tests/mockingservicestests/src/com/android/server/job/controllers/ConnectivityControllerTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/job/controllers/ConnectivityControllerTest.java
@@ -24,6 +24,7 @@
 import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
 import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
 import static android.net.NetworkCapabilities.TRANSPORT_VPN;
+import static android.text.format.DateUtils.SECOND_IN_MILLIS;
 
 import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
 import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
@@ -35,6 +36,7 @@
 import static com.android.server.job.JobSchedulerService.RARE_INDEX;
 import static com.android.server.job.JobSchedulerService.RESTRICTED_INDEX;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
@@ -240,20 +242,20 @@
                         .setLinkDownstreamBandwidthKbps(1).build(), mConstants));
         // Slow downstream
         assertFalse(controller.isSatisfied(createJobStatus(job), net,
-                createCapabilitiesBuilder().setLinkUpstreamBandwidthKbps(137)
+                createCapabilitiesBuilder().setLinkUpstreamBandwidthKbps(140)
                         .setLinkDownstreamBandwidthKbps(1).build(), mConstants));
         // Slow upstream
         assertFalse(controller.isSatisfied(createJobStatus(job), net,
                 createCapabilitiesBuilder().setLinkUpstreamBandwidthKbps(1)
-                        .setLinkDownstreamBandwidthKbps(137).build(), mConstants));
+                        .setLinkDownstreamBandwidthKbps(140).build(), mConstants));
         // Network good enough
         assertTrue(controller.isSatisfied(createJobStatus(job), net,
-                createCapabilitiesBuilder().setLinkUpstreamBandwidthKbps(137)
-                        .setLinkDownstreamBandwidthKbps(137).build(), mConstants));
+                createCapabilitiesBuilder().setLinkUpstreamBandwidthKbps(140)
+                        .setLinkDownstreamBandwidthKbps(140).build(), mConstants));
         // Network slightly too slow given reduced time
         assertFalse(controller.isSatisfied(createJobStatus(job), net,
-                createCapabilitiesBuilder().setLinkUpstreamBandwidthKbps(130)
-                        .setLinkDownstreamBandwidthKbps(130).build(), mConstants));
+                createCapabilitiesBuilder().setLinkUpstreamBandwidthKbps(139)
+                        .setLinkDownstreamBandwidthKbps(139).build(), mConstants));
         // Slow network is too slow, but device is charging and network is unmetered.
         when(mService.isBatteryCharging()).thenReturn(true);
         controller.onBatteryStateChangedLocked();
@@ -1188,6 +1190,78 @@
         assertFalse(unnetworked.isConstraintSatisfied(JobStatus.CONSTRAINT_CONNECTIVITY));
     }
 
+    @Test
+    public void testCalculateTransferTimeMs() {
+        assertEquals(ConnectivityController.UNKNOWN_TIME,
+                ConnectivityController.calculateTransferTimeMs(1, 0));
+        assertEquals(ConnectivityController.UNKNOWN_TIME,
+                ConnectivityController.calculateTransferTimeMs(JobInfo.NETWORK_BYTES_UNKNOWN, 512));
+        assertEquals(1, ConnectivityController.calculateTransferTimeMs(1, 8));
+        assertEquals(1000, ConnectivityController.calculateTransferTimeMs(1000, 8));
+        assertEquals(8, ConnectivityController.calculateTransferTimeMs(1024, 1024));
+    }
+
+    @Test
+    public void testGetEstimatedTransferTimeMs() {
+        final ArgumentCaptor<NetworkCallback> callbackCaptor =
+                ArgumentCaptor.forClass(NetworkCallback.class);
+        doNothing().when(mConnManager).registerNetworkCallback(any(), callbackCaptor.capture());
+
+        final JobStatus job = createJobStatus(createJob()
+                .setEstimatedNetworkBytes(DataUnit.MEBIBYTES.toBytes(10_000),
+                        DataUnit.MEBIBYTES.toBytes(1_000))
+                .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY));
+
+        final ConnectivityController controller = new ConnectivityController(mService,
+                mFlexibilityController);
+
+        final JobStatus jobNoEstimates = createJobStatus(createJob());
+        assertEquals(ConnectivityController.UNKNOWN_TIME,
+                controller.getEstimatedTransferTimeMs(jobNoEstimates));
+
+        // No network
+        job.network = null;
+        assertEquals(ConnectivityController.UNKNOWN_TIME,
+                controller.getEstimatedTransferTimeMs(job));
+
+        final NetworkCallback generalCallback = callbackCaptor.getValue();
+
+        // No capabilities
+        final Network network = mock(Network.class);
+        answerNetwork(generalCallback, null, null, network, null);
+        job.network = network;
+        assertEquals(ConnectivityController.UNKNOWN_TIME,
+                controller.getEstimatedTransferTimeMs(job));
+
+        // Capabilities don't have bandwidth values
+        NetworkCapabilities caps = createCapabilitiesBuilder().build();
+        answerNetwork(generalCallback, null, null, network, caps);
+        assertEquals(ConnectivityController.UNKNOWN_TIME,
+                controller.getEstimatedTransferTimeMs(job));
+
+        // Capabilities only has downstream bandwidth
+        caps = createCapabilitiesBuilder()
+                .setLinkDownstreamBandwidthKbps(1024)
+                .build();
+        answerNetwork(generalCallback, null, null, network, caps);
+        assertEquals(81920 * SECOND_IN_MILLIS, controller.getEstimatedTransferTimeMs(job));
+
+        // Capabilities only has upstream bandwidth
+        caps = createCapabilitiesBuilder()
+                .setLinkUpstreamBandwidthKbps(2 * 1024)
+                .build();
+        answerNetwork(generalCallback, null, null, network, caps);
+        assertEquals(4096 * SECOND_IN_MILLIS, controller.getEstimatedTransferTimeMs(job));
+
+        // Capabilities only both stream bandwidths
+        caps = createCapabilitiesBuilder()
+                .setLinkDownstreamBandwidthKbps(1024)
+                .setLinkUpstreamBandwidthKbps(2 * 1024)
+                .build();
+        answerNetwork(generalCallback, null, null, network, caps);
+        assertEquals((81920 + 4096) * SECOND_IN_MILLIS, controller.getEstimatedTransferTimeMs(job));
+    }
+
     private void answerNetwork(@NonNull NetworkCallback generalCallback,
             @Nullable NetworkCallback uidCallback, @Nullable Network lastNetwork,
             @Nullable Network net, @Nullable NetworkCapabilities caps) {
@@ -1198,11 +1272,15 @@
             }
         } else {
             generalCallback.onAvailable(net);
-            generalCallback.onCapabilitiesChanged(net, caps);
+            if (caps != null) {
+                generalCallback.onCapabilitiesChanged(net, caps);
+            }
             if (uidCallback != null) {
                 uidCallback.onAvailable(net);
                 uidCallback.onBlockedStatusChanged(net, ConnectivityManager.BLOCKED_REASON_NONE);
-                uidCallback.onCapabilitiesChanged(net, caps);
+                if (caps != null) {
+                    uidCallback.onCapabilitiesChanged(net, caps);
+                }
             }
         }
     }
diff --git a/services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java b/services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java
index 17822c6..d72ccf8 100644
--- a/services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java
@@ -2163,6 +2163,31 @@
     }
 
     @Test
+    public void testIsWithinQuotaLocked_UserInitiated() {
+        // Put app in a state where regular jobs are out of quota.
+        setDischarging();
+        final long now = JobSchedulerService.sElapsedRealtimeClock.millis();
+        final int jobCount = mQcConstants.MAX_JOB_COUNT_PER_RATE_LIMITING_WINDOW;
+        mQuotaController.saveTimingSession(SOURCE_USER_ID, SOURCE_PACKAGE,
+                createTimingSession(now - (HOUR_IN_MILLIS), 15 * MINUTE_IN_MILLIS, 25), false);
+        mQuotaController.saveTimingSession(SOURCE_USER_ID, SOURCE_PACKAGE,
+                createTimingSession(now - (5 * MINUTE_IN_MILLIS), 3 * MINUTE_IN_MILLIS, jobCount),
+                false);
+        JobStatus job = createJobStatus("testIsWithinQuotaLocked_UserInitiated", 1);
+        spyOn(job);
+        synchronized (mQuotaController.mLock) {
+            mQuotaController.incrementJobCountLocked(SOURCE_USER_ID, SOURCE_PACKAGE, jobCount);
+            assertFalse(mQuotaController
+                    .isWithinQuotaLocked(SOURCE_USER_ID, SOURCE_PACKAGE, WORKING_INDEX));
+            doReturn(false).when(job).shouldTreatAsUserInitiated();
+            assertFalse(mQuotaController.isWithinQuotaLocked(job));
+            // User-initiated job should still be allowed.
+            doReturn(true).when(job).shouldTreatAsUserInitiated();
+            assertTrue(mQuotaController.isWithinQuotaLocked(job));
+        }
+    }
+
+    @Test
     public void testIsWithinQuotaLocked_WithQuotaBump_Duration() {
         setDischarging();
         int standbyBucket = WORKING_INDEX;
diff --git a/services/tests/mockingservicestests/src/com/android/server/job/restrictions/ThermalStatusRestrictionTest.java b/services/tests/mockingservicestests/src/com/android/server/job/restrictions/ThermalStatusRestrictionTest.java
index f88e18b..4942690 100644
--- a/services/tests/mockingservicestests/src/com/android/server/job/restrictions/ThermalStatusRestrictionTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/job/restrictions/ThermalStatusRestrictionTest.java
@@ -180,14 +180,47 @@
                 createJobBuilder(7).setExpedited(true).build());
         final JobStatus ej = spy(createJobStatus("testIsJobRestricted",
                 createJobBuilder(8).setExpedited(true).build()));
+        final JobStatus ejRetried = spy(createJobStatus("testIsJobRestricted",
+                createJobBuilder(11).setExpedited(true).build()));
+        final JobStatus ejRunning = spy(createJobStatus("testIsJobRestricted",
+                createJobBuilder(12).setExpedited(true).build()));
+        final JobStatus ejRunningLong = spy(createJobStatus("testIsJobRestricted",
+                createJobBuilder(13).setExpedited(true).build()));
+        final JobStatus ui = spy(createJobStatus("testIsJobRestricted",
+                createJobBuilder(14).build()));
+        final JobStatus uiRetried = spy(createJobStatus("testIsJobRestricted",
+                createJobBuilder(15).build()));
+        final JobStatus uiRunning = spy(createJobStatus("testIsJobRestricted",
+                createJobBuilder(16).build()));
+        final JobStatus uiRunningLong = spy(createJobStatus("testIsJobRestricted",
+                createJobBuilder(17).build()));
         when(ej.shouldTreatAsExpeditedJob()).thenReturn(true);
+        when(ejRetried.shouldTreatAsExpeditedJob()).thenReturn(true);
+        when(ejRunning.shouldTreatAsExpeditedJob()).thenReturn(true);
+        when(ejRunningLong.shouldTreatAsExpeditedJob()).thenReturn(true);
+        when(ui.shouldTreatAsUserInitiated()).thenReturn(true);
+        when(uiRetried.shouldTreatAsUserInitiated()).thenReturn(true);
+        when(uiRunning.shouldTreatAsUserInitiated()).thenReturn(true);
+        when(uiRunningLong.shouldTreatAsUserInitiated()).thenReturn(true);
+        when(ejRetried.getNumPreviousAttempts()).thenReturn(1);
+        when(uiRetried.getNumPreviousAttempts()).thenReturn(2);
         when(mJobSchedulerService.isCurrentlyRunningLocked(jobLowPriorityRunning)).thenReturn(true);
         when(mJobSchedulerService.isCurrentlyRunningLocked(jobHighPriorityRunning))
                 .thenReturn(true);
+        when(mJobSchedulerService.isCurrentlyRunningLocked(jobLowPriorityRunningLong))
+                .thenReturn(true);
+        when(mJobSchedulerService.isCurrentlyRunningLocked(jobHighPriorityRunningLong))
+                .thenReturn(true);
+        when(mJobSchedulerService.isCurrentlyRunningLocked(ejRunning)).thenReturn(true);
+        when(mJobSchedulerService.isCurrentlyRunningLocked(ejRunningLong)).thenReturn(true);
+        when(mJobSchedulerService.isCurrentlyRunningLocked(uiRunning)).thenReturn(true);
+        when(mJobSchedulerService.isCurrentlyRunningLocked(uiRunningLong)).thenReturn(true);
         when(mJobSchedulerService.isJobInOvertimeLocked(jobLowPriorityRunningLong))
                 .thenReturn(true);
         when(mJobSchedulerService.isJobInOvertimeLocked(jobHighPriorityRunningLong))
                 .thenReturn(true);
+        when(mJobSchedulerService.isJobInOvertimeLocked(ejRunningLong)).thenReturn(true);
+        when(mJobSchedulerService.isJobInOvertimeLocked(uiRunningLong)).thenReturn(true);
 
         assertFalse(mThermalStatusRestriction.isJobRestricted(jobMinPriority));
         assertFalse(mThermalStatusRestriction.isJobRestricted(jobLowPriority));
@@ -199,6 +232,13 @@
         assertFalse(mThermalStatusRestriction.isJobRestricted(jobHighPriorityRunningLong));
         assertFalse(mThermalStatusRestriction.isJobRestricted(ej));
         assertFalse(mThermalStatusRestriction.isJobRestricted(ejDowngraded));
+        assertFalse(mThermalStatusRestriction.isJobRestricted(ejRetried));
+        assertFalse(mThermalStatusRestriction.isJobRestricted(ejRunning));
+        assertFalse(mThermalStatusRestriction.isJobRestricted(ejRunningLong));
+        assertFalse(mThermalStatusRestriction.isJobRestricted(ui));
+        assertFalse(mThermalStatusRestriction.isJobRestricted(uiRetried));
+        assertFalse(mThermalStatusRestriction.isJobRestricted(uiRunning));
+        assertFalse(mThermalStatusRestriction.isJobRestricted(uiRunningLong));
 
         mStatusChangedListener.onThermalStatusChanged(THERMAL_STATUS_LIGHT);
 
@@ -212,6 +252,13 @@
         assertFalse(mThermalStatusRestriction.isJobRestricted(jobHighPriorityRunningLong));
         assertFalse(mThermalStatusRestriction.isJobRestricted(ejDowngraded));
         assertFalse(mThermalStatusRestriction.isJobRestricted(ej));
+        assertFalse(mThermalStatusRestriction.isJobRestricted(ejRetried));
+        assertFalse(mThermalStatusRestriction.isJobRestricted(ejRunning));
+        assertFalse(mThermalStatusRestriction.isJobRestricted(ejRunningLong));
+        assertFalse(mThermalStatusRestriction.isJobRestricted(ui));
+        assertFalse(mThermalStatusRestriction.isJobRestricted(uiRetried));
+        assertFalse(mThermalStatusRestriction.isJobRestricted(uiRunning));
+        assertFalse(mThermalStatusRestriction.isJobRestricted(uiRunningLong));
 
         mStatusChangedListener.onThermalStatusChanged(THERMAL_STATUS_MODERATE);
 
@@ -225,6 +272,13 @@
         assertTrue(mThermalStatusRestriction.isJobRestricted(jobHighPriorityRunningLong));
         assertTrue(mThermalStatusRestriction.isJobRestricted(ejDowngraded));
         assertFalse(mThermalStatusRestriction.isJobRestricted(ej));
+        assertTrue(mThermalStatusRestriction.isJobRestricted(ejRetried));
+        assertFalse(mThermalStatusRestriction.isJobRestricted(ejRunning));
+        assertTrue(mThermalStatusRestriction.isJobRestricted(ejRunningLong));
+        assertFalse(mThermalStatusRestriction.isJobRestricted(ui));
+        assertTrue(mThermalStatusRestriction.isJobRestricted(uiRetried));
+        assertFalse(mThermalStatusRestriction.isJobRestricted(uiRunning));
+        assertTrue(mThermalStatusRestriction.isJobRestricted(uiRunningLong));
 
         mStatusChangedListener.onThermalStatusChanged(THERMAL_STATUS_SEVERE);
 
@@ -238,6 +292,13 @@
         assertTrue(mThermalStatusRestriction.isJobRestricted(jobHighPriorityRunningLong));
         assertTrue(mThermalStatusRestriction.isJobRestricted(ejDowngraded));
         assertTrue(mThermalStatusRestriction.isJobRestricted(ej));
+        assertTrue(mThermalStatusRestriction.isJobRestricted(ejRetried));
+        assertTrue(mThermalStatusRestriction.isJobRestricted(ejRunning));
+        assertTrue(mThermalStatusRestriction.isJobRestricted(ejRunningLong));
+        assertTrue(mThermalStatusRestriction.isJobRestricted(ui));
+        assertTrue(mThermalStatusRestriction.isJobRestricted(uiRetried));
+        assertTrue(mThermalStatusRestriction.isJobRestricted(uiRunning));
+        assertTrue(mThermalStatusRestriction.isJobRestricted(uiRunningLong));
 
         mStatusChangedListener.onThermalStatusChanged(THERMAL_STATUS_CRITICAL);
 
@@ -251,6 +312,13 @@
         assertTrue(mThermalStatusRestriction.isJobRestricted(jobHighPriorityRunningLong));
         assertTrue(mThermalStatusRestriction.isJobRestricted(ejDowngraded));
         assertTrue(mThermalStatusRestriction.isJobRestricted(ej));
+        assertTrue(mThermalStatusRestriction.isJobRestricted(ejRetried));
+        assertTrue(mThermalStatusRestriction.isJobRestricted(ejRunning));
+        assertTrue(mThermalStatusRestriction.isJobRestricted(ejRunningLong));
+        assertTrue(mThermalStatusRestriction.isJobRestricted(ui));
+        assertTrue(mThermalStatusRestriction.isJobRestricted(uiRetried));
+        assertTrue(mThermalStatusRestriction.isJobRestricted(uiRunning));
+        assertTrue(mThermalStatusRestriction.isJobRestricted(uiRunningLong));
     }
 
     private JobInfo.Builder createJobBuilder(int jobId) {
diff --git a/services/tests/mockingservicestests/src/com/android/server/location/LocationManagerServiceTest.java b/services/tests/mockingservicestests/src/com/android/server/location/LocationManagerServiceTest.java
new file mode 100644
index 0000000..4d11296
--- /dev/null
+++ b/services/tests/mockingservicestests/src/com/android/server/location/LocationManagerServiceTest.java
@@ -0,0 +1,201 @@
+/*
+ * 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.server.location;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.junit.Assert.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import android.app.AppOpsManager;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.location.ILocationListener;
+import android.location.LocationManagerInternal;
+import android.location.LocationRequest;
+import android.location.provider.ProviderRequest;
+import android.os.IBinder;
+import android.os.PowerManager;
+import android.platform.test.annotations.Presubmit;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.SmallTest;
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import com.android.server.LocalServices;
+import com.android.server.location.injector.FakeUserInfoHelper;
+import com.android.server.location.injector.TestInjector;
+import com.android.server.location.provider.AbstractLocationProvider;
+import com.android.server.location.provider.LocationProviderManager;
+import com.android.server.pm.permission.LegacyPermissionManagerInternal;
+
+import com.google.common.util.concurrent.MoreExecutors;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Spy;
+
+import java.util.Collections;
+
+@Presubmit
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class LocationManagerServiceTest {
+    private static final String PROVIDER_WITH_PERMISSION = "provider_with_permission";
+    private static final String PROVIDER_WITHOUT_PERMISSION = "provider_without_permission";
+    private static final int CURRENT_USER = FakeUserInfoHelper.DEFAULT_USERID;
+    private static final String CALLER_PACKAGE = "caller_package";
+    private static final String MISSING_PERMISSION = "missing_permission";
+
+    private TestInjector mInjector;
+    private LocationManagerService mLocationManagerService;
+
+    @Spy private FakeAbstractLocationProvider mProviderWithPermission;
+    @Spy private FakeAbstractLocationProvider mProviderWithoutPermission;
+    @Mock private ILocationListener mLocationListener;
+    @Mock private IBinder mBinder;
+    @Mock private Context mContext;
+    @Mock private Resources mResources;
+    @Mock private PackageManager mPackageManager;
+    @Mock private AppOpsManager mAppOpsManager;
+    @Mock private PowerManager mPowerManager;
+    @Mock private PowerManager.WakeLock mWakeLock;
+    @Mock private LegacyPermissionManagerInternal mPermissionManagerInternal;
+
+    @Before
+    public void setUp() {
+        initMocks(this);
+
+        doReturn(mContext).when(mContext).createAttributionContext(any());
+        doReturn("android").when(mContext).getPackageName();
+        doReturn(mResources).when(mContext).getResources();
+        doReturn(mPackageManager).when(mContext).getPackageManager();
+        doReturn(mPowerManager).when(mContext).getSystemService(PowerManager.class);
+        doReturn(mWakeLock).when(mPowerManager).newWakeLock(anyInt(), anyString());
+        doReturn(mAppOpsManager).when(mContext).getSystemService(AppOpsManager.class);
+        String[] packages = {CALLER_PACKAGE};
+        doReturn(InstrumentationRegistry.getInstrumentation().getContext().getContentResolver())
+                .when(mContext)
+                .getContentResolver();
+        doReturn(packages).when(mPackageManager).getPackagesForUid(anyInt());
+        doReturn(mBinder).when(mLocationListener).asBinder();
+        doReturn(PackageManager.PERMISSION_DENIED)
+                .when(mContext)
+                .checkCallingOrSelfPermission(MISSING_PERMISSION);
+
+        mInjector = new TestInjector(mContext);
+        mInjector.getUserInfoHelper().setUserVisible(CURRENT_USER, true);
+
+        LocalServices.addService(LegacyPermissionManagerInternal.class, mPermissionManagerInternal);
+
+        mLocationManagerService = new LocationManagerService(mContext, mInjector);
+
+        LocationProviderManager managerWithPermission =
+                new LocationProviderManager(
+                        mContext, mInjector, PROVIDER_WITH_PERMISSION, /* passiveManager= */ null);
+        mLocationManagerService.addLocationProviderManager(
+                managerWithPermission, mProviderWithPermission);
+        LocationProviderManager managerWithoutPermission =
+                new LocationProviderManager(
+                        mContext,
+                        mInjector,
+                        PROVIDER_WITHOUT_PERMISSION,
+                        /* passiveManager= */ null,
+                        Collections.singletonList(MISSING_PERMISSION));
+        mLocationManagerService.addLocationProviderManager(
+                managerWithoutPermission, mProviderWithoutPermission);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        LocalServices.removeServiceForTest(LegacyPermissionManagerInternal.class);
+        LocalServices.removeServiceForTest(LocationManagerInternal.class);
+    }
+
+    @Test
+    public void testRequestLocationUpdates() {
+        LocationRequest request = new LocationRequest.Builder(0).build();
+        mLocationManagerService.registerLocationListener(
+                PROVIDER_WITH_PERMISSION,
+                request,
+                mLocationListener,
+                CALLER_PACKAGE,
+                /* attributionTag= */ null,
+                "any_listener_id");
+        verify(mProviderWithPermission).onSetRequestPublic(any());
+    }
+
+    @Test
+    public void testRequestLocationUpdates_noPermission() {
+        LocationRequest request = new LocationRequest.Builder(0).build();
+        assertThrows(
+                IllegalArgumentException.class,
+                () ->
+                        mLocationManagerService.registerLocationListener(
+                                PROVIDER_WITHOUT_PERMISSION,
+                                request,
+                                mLocationListener,
+                                CALLER_PACKAGE,
+                                /* attributionTag= */ null,
+                                "any_listener_id"));
+    }
+
+    @Test
+    public void testHasProvider() {
+        assertThat(mLocationManagerService.hasProvider(PROVIDER_WITH_PERMISSION)).isTrue();
+    }
+
+    @Test
+    public void testHasProvider_noPermission() {
+        assertThat(mLocationManagerService.hasProvider(PROVIDER_WITHOUT_PERMISSION)).isFalse();
+    }
+
+    @Test
+    public void testGetAllProviders() {
+        assertThat(mLocationManagerService.getAllProviders()).contains(PROVIDER_WITH_PERMISSION);
+        assertThat(mLocationManagerService.getAllProviders())
+                .doesNotContain(PROVIDER_WITHOUT_PERMISSION);
+    }
+
+    abstract static class FakeAbstractLocationProvider extends AbstractLocationProvider {
+        FakeAbstractLocationProvider() {
+            super(
+                    MoreExecutors.directExecutor(),
+                    /* identity= */ null,
+                    /* properties= */ null,
+                    /* extraAttributionTags= */ Collections.emptySet());
+            setAllowed(true);
+        }
+
+        @Override
+        protected void onSetRequest(ProviderRequest request) {
+            // Call a public version of this method so mockito can verify.
+            onSetRequestPublic(request);
+        }
+
+        public abstract void onSetRequestPublic(ProviderRequest request);
+    }
+}
diff --git a/services/tests/mockingservicestests/src/com/android/server/location/provider/LocationProviderManagerTest.java b/services/tests/mockingservicestests/src/com/android/server/location/provider/LocationProviderManagerTest.java
index aa28ad4..7dc1935 100644
--- a/services/tests/mockingservicestests/src/com/android/server/location/provider/LocationProviderManagerTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/location/provider/LocationProviderManagerTest.java
@@ -102,6 +102,7 @@
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Random;
@@ -133,6 +134,7 @@
     private static final CallerIdentity IDENTITY = CallerIdentity.forTest(CURRENT_USER, 1,
             "mypackage", "attribution", "listener");
     private static final WorkSource WORK_SOURCE = new WorkSource(IDENTITY.getUid());
+    private static final String MISSING_PERMISSION = "missing_permission";
 
     private Random mRandom;
 
@@ -173,6 +175,9 @@
         doReturn(mPackageManager).when(mContext).getPackageManager();
         doReturn(mPowerManager).when(mContext).getSystemService(PowerManager.class);
         doReturn(mWakeLock).when(mPowerManager).newWakeLock(anyInt(), anyString());
+        doReturn(PackageManager.PERMISSION_DENIED)
+                .when(mContext)
+                .checkCallingOrSelfPermission(MISSING_PERMISSION);
 
         mInjector = new TestInjector(mContext);
         mInjector.getUserInfoHelper().setUserVisible(CURRENT_USER, true);
@@ -187,12 +192,18 @@
     }
 
     private void createManager(String name) {
+        createManager(name, Collections.emptyList());
+    }
+
+    private void createManager(String name, Collection<String> requiredPermissions) {
         mStateChangedListener = mock(LocationProviderManager.StateChangedListener.class);
 
         mProvider = new TestProvider(PROPERTIES, PROVIDER_IDENTITY);
         mProvider.setProviderAllowed(true);
 
-        mManager = new LocationProviderManager(mContext, mInjector, name, mPassive);
+        mManager =
+                new LocationProviderManager(
+                        mContext, mInjector, name, mPassive, requiredPermissions);
         mManager.startManager(mStateChangedListener);
         mManager.setRealProvider(mProvider);
     }
@@ -1317,6 +1328,17 @@
         assertThat(mInjector.getPackageResetHelper().isResetableForPackage("mypackage")).isFalse();
     }
 
+    @Test
+    public void testIsVisibleToCaller() {
+        assertThat(mManager.isVisibleToCaller()).isTrue();
+    }
+
+    @Test
+    public void testIsVisibleToCaller_noPermissions() {
+        createManager("any_name", Collections.singletonList(MISSING_PERMISSION));
+        assertThat(mManager.isVisibleToCaller()).isFalse();
+    }
+
     private ILocationListener createMockLocationListener() {
         return spy(new ILocationListener.Stub() {
             @Override
diff --git a/services/tests/mockingservicestests/src/com/android/server/pm/MockSystem.kt b/services/tests/mockingservicestests/src/com/android/server/pm/MockSystem.kt
index 27d0662..4f56271 100644
--- a/services/tests/mockingservicestests/src/com/android/server/pm/MockSystem.kt
+++ b/services/tests/mockingservicestests/src/com/android/server/pm/MockSystem.kt
@@ -193,6 +193,7 @@
         val incrementalManager: IncrementalManager = mock()
         val platformCompat: PlatformCompat = mock()
         val settings: Settings = mock()
+        val crossProfileIntentFilterHelper: CrossProfileIntentFilterHelper = mock()
         val resources: Resources = mock()
         val systemConfig: SystemConfig = mock()
         val apexManager: ApexManager = mock()
@@ -279,6 +280,8 @@
         whenever(mocks.injector.incrementalManager).thenReturn(mocks.incrementalManager)
         whenever(mocks.injector.compatibility).thenReturn(mocks.platformCompat)
         whenever(mocks.injector.settings).thenReturn(mocks.settings)
+        whenever(mocks.injector.crossProfileIntentFilterHelper)
+                .thenReturn(mocks.crossProfileIntentFilterHelper)
         whenever(mocks.injector.dexManager).thenReturn(mocks.dexManager)
         whenever(mocks.injector.systemConfig).thenReturn(mocks.systemConfig)
         whenever(mocks.injector.apexManager).thenReturn(mocks.apexManager)
diff --git a/services/tests/mockingservicestests/src/com/android/server/pm/UserVisibilityMediatorMUMDTest.java b/services/tests/mockingservicestests/src/com/android/server/pm/UserVisibilityMediatorMUMDTest.java
index 6d8910e..58cff94 100644
--- a/services/tests/mockingservicestests/src/com/android/server/pm/UserVisibilityMediatorMUMDTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/pm/UserVisibilityMediatorMUMDTest.java
@@ -107,8 +107,8 @@
                 onVisible(PROFILE_USER_ID));
         startForegroundUser(PARENT_USER_ID);
 
-        int result = mMediator.assignUserToDisplayOnStart(PROFILE_USER_ID, PARENT_USER_ID, BG,
-                DEFAULT_DISPLAY);
+        int result = mMediator.assignUserToDisplayOnStart(PROFILE_USER_ID, PARENT_USER_ID,
+                BG_VISIBLE, DEFAULT_DISPLAY);
         assertStartUserResult(result, USER_ASSIGNMENT_RESULT_SUCCESS_VISIBLE);
 
         expectUserIsVisible(PROFILE_USER_ID);
@@ -138,7 +138,8 @@
     public void testStartBgUser_onInvalidDisplay() throws Exception {
         AsyncUserVisibilityListener listener = addListenerForNoEvents();
 
-        int result = mMediator.assignUserToDisplayOnStart(USER_ID, USER_ID, BG, INVALID_DISPLAY);
+        int result = mMediator.assignUserToDisplayOnStart(USER_ID, USER_ID, BG_VISIBLE,
+                INVALID_DISPLAY);
 
         assertStartUserResult(result, USER_ASSIGNMENT_RESULT_FAILURE);
 
@@ -151,7 +152,7 @@
     public void testStartBgUser_onSecondaryDisplay_displayAvailable() throws Exception {
         AsyncUserVisibilityListener listener = addListenerForEvents(onVisible(USER_ID));
 
-        int result = mMediator.assignUserToDisplayOnStart(USER_ID, USER_ID, BG,
+        int result = mMediator.assignUserToDisplayOnStart(USER_ID, USER_ID, BG_VISIBLE,
                 SECONDARY_DISPLAY_ID);
         assertStartUserResult(result, USER_ASSIGNMENT_RESULT_SUCCESS_VISIBLE);
 
@@ -176,7 +177,7 @@
         expectUserIsNotVisibleOnDisplay("before", PARENT_USER_ID, SECONDARY_DISPLAY_ID);
         expectUserIsNotVisibleOnDisplay("before", PROFILE_USER_ID, SECONDARY_DISPLAY_ID);
 
-        int result = mMediator.assignUserToDisplayOnStart(USER_ID, USER_ID, BG,
+        int result = mMediator.assignUserToDisplayOnStart(USER_ID, USER_ID, BG_VISIBLE,
                 SECONDARY_DISPLAY_ID);
         assertStartUserResult(result, USER_ASSIGNMENT_RESULT_SUCCESS_VISIBLE);
 
@@ -189,7 +190,7 @@
         AsyncUserVisibilityListener listener = addListenerForEvents(onVisible(OTHER_USER_ID));
         startUserInSecondaryDisplay(OTHER_USER_ID, SECONDARY_DISPLAY_ID);
 
-        int result = mMediator.assignUserToDisplayOnStart(USER_ID, USER_ID, BG,
+        int result = mMediator.assignUserToDisplayOnStart(USER_ID, USER_ID, BG_VISIBLE,
                 SECONDARY_DISPLAY_ID);
         assertStartUserResult(result, USER_ASSIGNMENT_RESULT_FAILURE);
 
@@ -205,7 +206,7 @@
         AsyncUserVisibilityListener listener = addListenerForEvents(onVisible(USER_ID));
         startUserInSecondaryDisplay(USER_ID, OTHER_SECONDARY_DISPLAY_ID);
 
-        int result = mMediator.assignUserToDisplayOnStart(USER_ID, USER_ID, BG,
+        int result = mMediator.assignUserToDisplayOnStart(USER_ID, USER_ID, BG_VISIBLE,
                 SECONDARY_DISPLAY_ID);
         assertStartUserResult(result, USER_ASSIGNMENT_RESULT_FAILURE);
 
@@ -228,8 +229,8 @@
         AsyncUserVisibilityListener listener = addListenerForEvents(onVisible(PARENT_USER_ID));
         startUserInSecondaryDisplay(PARENT_USER_ID, OTHER_SECONDARY_DISPLAY_ID);
 
-        int result = mMediator.assignUserToDisplayOnStart(PROFILE_USER_ID, PARENT_USER_ID, BG,
-                DEFAULT_DISPLAY);
+        int result = mMediator.assignUserToDisplayOnStart(PROFILE_USER_ID, PARENT_USER_ID,
+                BG_VISIBLE, DEFAULT_DISPLAY);
         assertStartUserResult(result, USER_ASSIGNMENT_RESULT_SUCCESS_INVISIBLE);
 
         expectUserIsNotVisibleAtAll(PROFILE_USER_ID);
diff --git a/services/tests/mockingservicestests/src/com/android/server/pm/UserVisibilityMediatorSUSDTest.java b/services/tests/mockingservicestests/src/com/android/server/pm/UserVisibilityMediatorSUSDTest.java
index 1065392..3d64c29 100644
--- a/services/tests/mockingservicestests/src/com/android/server/pm/UserVisibilityMediatorSUSDTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/pm/UserVisibilityMediatorSUSDTest.java
@@ -106,8 +106,8 @@
                 onVisible(PROFILE_USER_ID));
         startForegroundUser(PARENT_USER_ID);
 
-        int result = mMediator.assignUserToDisplayOnStart(PROFILE_USER_ID, PARENT_USER_ID, BG,
-                DEFAULT_DISPLAY);
+        int result = mMediator.assignUserToDisplayOnStart(PROFILE_USER_ID, PARENT_USER_ID,
+                BG_VISIBLE, DEFAULT_DISPLAY);
         assertStartUserResult(result, USER_ASSIGNMENT_RESULT_SUCCESS_VISIBLE);
 
         expectUserIsVisible(PROFILE_USER_ID);
@@ -126,7 +126,7 @@
     public void testStartBgUser_onSecondaryDisplay() throws Exception {
         AsyncUserVisibilityListener listener = addListenerForNoEvents();
 
-        int result = mMediator.assignUserToDisplayOnStart(USER_ID, USER_ID, BG,
+        int result = mMediator.assignUserToDisplayOnStart(USER_ID, USER_ID, BG_VISIBLE,
                 SECONDARY_DISPLAY_ID);
         assertStartUserResult(result, USER_ASSIGNMENT_RESULT_FAILURE);
 
diff --git a/services/tests/mockingservicestests/src/com/android/server/pm/UserVisibilityMediatorTestCase.java b/services/tests/mockingservicestests/src/com/android/server/pm/UserVisibilityMediatorTestCase.java
index 4487d13..74fd9ff 100644
--- a/services/tests/mockingservicestests/src/com/android/server/pm/UserVisibilityMediatorTestCase.java
+++ b/services/tests/mockingservicestests/src/com/android/server/pm/UserVisibilityMediatorTestCase.java
@@ -26,6 +26,9 @@
 import static com.android.server.pm.UserManagerInternal.USER_ASSIGNMENT_RESULT_FAILURE;
 import static com.android.server.pm.UserManagerInternal.USER_ASSIGNMENT_RESULT_SUCCESS_INVISIBLE;
 import static com.android.server.pm.UserManagerInternal.USER_ASSIGNMENT_RESULT_SUCCESS_VISIBLE;
+import static com.android.server.pm.UserManagerInternal.USER_START_MODE_BACKGROUND;
+import static com.android.server.pm.UserManagerInternal.USER_START_MODE_BACKGROUND_VISIBLE;
+import static com.android.server.pm.UserManagerInternal.USER_START_MODE_FOREGROUND;
 import static com.android.server.pm.UserManagerInternal.userAssignmentResultToString;
 import static com.android.server.pm.UserVisibilityChangedEvent.onInvisible;
 import static com.android.server.pm.UserVisibilityChangedEvent.onVisible;
@@ -99,8 +102,9 @@
      */
     protected static final int OTHER_SECONDARY_DISPLAY_ID = 108;
 
-    protected static final boolean FG = true;
-    protected static final boolean BG = false;
+    protected static final int FG = USER_START_MODE_FOREGROUND;
+    protected static final int BG = USER_START_MODE_BACKGROUND;
+    protected static final int BG_VISIBLE = USER_START_MODE_BACKGROUND_VISIBLE;
 
     private Handler mHandler;
     protected AsyncUserVisibilityListener.Factory mListenerFactory;
@@ -154,8 +158,7 @@
     public final void testStartBgUser_onDefaultDisplay() throws Exception {
         AsyncUserVisibilityListener listener = addListenerForNoEvents();
 
-        int result = mMediator.assignUserToDisplayOnStart(USER_ID, USER_ID, BG,
-                DEFAULT_DISPLAY);
+        int result = mMediator.assignUserToDisplayOnStart(USER_ID, USER_ID, BG, DEFAULT_DISPLAY);
         assertStartUserResult(result, USER_ASSIGNMENT_RESULT_SUCCESS_INVISIBLE);
 
         expectUserIsNotVisibleAtAll(USER_ID);
@@ -166,6 +169,34 @@
     }
 
     @Test
+    public final void testStartBgUser_onDefaultDisplay_visible() throws Exception {
+        AsyncUserVisibilityListener listener = addListenerForNoEvents();
+
+        int result = mMediator.assignUserToDisplayOnStart(USER_ID, USER_ID, BG_VISIBLE,
+                DEFAULT_DISPLAY);
+        assertStartUserResult(result, USER_ASSIGNMENT_RESULT_FAILURE);
+
+        expectUserIsNotVisibleAtAll(PROFILE_USER_ID);
+        expectNoDisplayAssignedToUser(PROFILE_USER_ID);
+
+        listener.verify();
+    }
+
+    @Test
+    public final void testStartBgUser_onSecondaryDisplay_invisible() throws Exception {
+        AsyncUserVisibilityListener listener = addListenerForNoEvents();
+
+        int result = mMediator.assignUserToDisplayOnStart(USER_ID, USER_ID, BG,
+                SECONDARY_DISPLAY_ID);
+        assertStartUserResult(result, USER_ASSIGNMENT_RESULT_FAILURE);
+
+        expectUserIsNotVisibleAtAll(PROFILE_USER_ID);
+        expectNoDisplayAssignedToUser(PROFILE_USER_ID);
+
+        listener.verify();
+    }
+
+    @Test
     public final void testStartBgSystemUser_onSecondaryDisplay() throws Exception {
         AsyncUserVisibilityListener listener = addListenerForEvents(
                 onInvisible(INITIAL_CURRENT_USER_ID),
@@ -228,8 +259,8 @@
             throws Exception {
         AsyncUserVisibilityListener listener = addListenerForNoEvents();
 
-        int result = mMediator.assignUserToDisplayOnStart(PROFILE_USER_ID, PARENT_USER_ID, BG,
-                DEFAULT_DISPLAY);
+        int result = mMediator.assignUserToDisplayOnStart(PROFILE_USER_ID, PARENT_USER_ID,
+                BG_VISIBLE, DEFAULT_DISPLAY);
         assertStartUserResult(result, USER_ASSIGNMENT_RESULT_SUCCESS_INVISIBLE);
 
         expectUserIsNotVisibleAtAll(PROFILE_USER_ID);
@@ -244,8 +275,8 @@
         AsyncUserVisibilityListener listener = addListenerForNoEvents();
         startBackgroundUser(PARENT_USER_ID);
 
-        int result = mMediator.assignUserToDisplayOnStart(PROFILE_USER_ID, PARENT_USER_ID, BG,
-                DEFAULT_DISPLAY);
+        int result = mMediator.assignUserToDisplayOnStart(PROFILE_USER_ID, PARENT_USER_ID,
+                BG_VISIBLE, DEFAULT_DISPLAY);
         assertStartUserResult(result, USER_ASSIGNMENT_RESULT_SUCCESS_INVISIBLE);
 
         expectUserIsNotVisibleAtAll(PROFILE_USER_ID);
@@ -261,6 +292,21 @@
     public final void testStartBgProfile_onSecondaryDisplay() throws Exception {
         AsyncUserVisibilityListener listener = addListenerForNoEvents();
 
+        int result = mMediator.assignUserToDisplayOnStart(PROFILE_USER_ID, PARENT_USER_ID,
+                BG_VISIBLE, SECONDARY_DISPLAY_ID);
+        assertStartUserResult(result, USER_ASSIGNMENT_RESULT_FAILURE);
+
+        expectUserIsNotVisibleAtAll(PROFILE_USER_ID);
+        expectNoDisplayAssignedToUser(PROFILE_USER_ID);
+        expectNoUserAssignedToDisplay(SECONDARY_DISPLAY_ID);
+
+        listener.verify();
+    }
+
+    @Test
+    public final void testStartBgProfile_onSecondaryDisplay_invisible() throws Exception {
+        AsyncUserVisibilityListener listener = addListenerForNoEvents();
+
         int result = mMediator.assignUserToDisplayOnStart(PROFILE_USER_ID, PARENT_USER_ID, BG,
                 SECONDARY_DISPLAY_ID);
         assertStartUserResult(result, USER_ASSIGNMENT_RESULT_FAILURE);
@@ -384,8 +430,8 @@
         Log.d(TAG, "starting default profile (" + PROFILE_USER_ID + ") in background after starting"
                 + " its parent (" + PARENT_USER_ID + ") on foreground");
 
-        int result = mMediator.assignUserToDisplayOnStart(PROFILE_USER_ID, PARENT_USER_ID, BG,
-                DEFAULT_DISPLAY);
+        int result = mMediator.assignUserToDisplayOnStart(PROFILE_USER_ID, PARENT_USER_ID,
+                BG_VISIBLE, DEFAULT_DISPLAY);
         if (result != USER_ASSIGNMENT_RESULT_SUCCESS_VISIBLE) {
             throw new IllegalStateException("Failed to start profile user " + PROFILE_USER_ID
                     + ": mediator returned " + userAssignmentResultToString(result));
@@ -403,7 +449,7 @@
         Preconditions.checkArgument(displayId != INVALID_DISPLAY && displayId != DEFAULT_DISPLAY,
                 "must pass a secondary display, not %d", displayId);
         Log.d(TAG, "startUserInSecondaryDisplay(" + userId + ", " + displayId + ")");
-        int result = mMediator.assignUserToDisplayOnStart(userId, userId, BG, displayId);
+        int result = mMediator.assignUserToDisplayOnStart(userId, userId, BG_VISIBLE, displayId);
         if (result != USER_ASSIGNMENT_RESULT_SUCCESS_VISIBLE) {
             throw new IllegalStateException("Failed to startuser " + userId
                     + " on background: mediator returned " + userAssignmentResultToString(result));
diff --git a/services/tests/mockingservicestests/src/com/android/server/power/ThermalManagerServiceMockingTest.java b/services/tests/mockingservicestests/src/com/android/server/power/ThermalManagerServiceMockingTest.java
new file mode 100644
index 0000000..34b17c7
--- /dev/null
+++ b/services/tests/mockingservicestests/src/com/android/server/power/ThermalManagerServiceMockingTest.java
@@ -0,0 +1,218 @@
+/*
+ * 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.server.power;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import android.hardware.thermal.CoolingType;
+import android.hardware.thermal.IThermal;
+import android.hardware.thermal.IThermalChangedCallback;
+import android.hardware.thermal.TemperatureThreshold;
+import android.hardware.thermal.TemperatureType;
+import android.hardware.thermal.ThrottlingSeverity;
+import android.os.Binder;
+import android.os.CoolingDevice;
+import android.os.RemoteException;
+import android.os.Temperature;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+
+
+public class ThermalManagerServiceMockingTest {
+    @Mock private IThermal mAidlHalMock;
+    private Binder mAidlBinder = new Binder();
+    private CompletableFuture<Temperature> mTemperatureFuture;
+    private ThermalManagerService.ThermalHalWrapper.TemperatureChangedCallback mTemperatureCallback;
+    private ThermalManagerService.ThermalHalAidlWrapper mAidlWrapper;
+    @Captor
+    ArgumentCaptor<IThermalChangedCallback> mAidlCallbackCaptor;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        Mockito.when(mAidlHalMock.asBinder()).thenReturn(mAidlBinder);
+        mAidlBinder.attachInterface(mAidlHalMock, IThermal.class.getName());
+        mTemperatureFuture = new CompletableFuture<>();
+        mTemperatureCallback = temperature -> mTemperatureFuture.complete(temperature);
+        mAidlWrapper = new ThermalManagerService.ThermalHalAidlWrapper();
+        mAidlWrapper.setCallback(mTemperatureCallback);
+        mAidlWrapper.initProxyAndRegisterCallback(mAidlBinder);
+    }
+
+    @Test
+    public void setCallback_aidl() throws Exception {
+        Mockito.verify(mAidlHalMock, Mockito.times(1)).registerThermalChangedCallback(
+                mAidlCallbackCaptor.capture());
+        android.hardware.thermal.Temperature halT =
+                new android.hardware.thermal.Temperature();
+        halT.type = TemperatureType.SOC;
+        halT.name = "test";
+        halT.throttlingStatus = ThrottlingSeverity.SHUTDOWN;
+        halT.value = 99.0f;
+        mAidlCallbackCaptor.getValue().notifyThrottling(halT);
+        Temperature temperature = mTemperatureFuture.get(100, TimeUnit.MILLISECONDS);
+        assertEquals(halT.name, temperature.getName());
+        assertEquals(halT.type, temperature.getType());
+        assertEquals(halT.value, temperature.getValue(), 0.1f);
+        assertEquals(halT.throttlingStatus, temperature.getStatus());
+    }
+
+    @Test
+    public void getCurrentTemperatures_withFilter_aidl() throws RemoteException {
+        android.hardware.thermal.Temperature halT1 = new android.hardware.thermal.Temperature();
+        halT1.type = TemperatureType.MODEM;
+        halT1.name = "test1";
+        halT1.throttlingStatus = ThrottlingSeverity.EMERGENCY;
+        halT1.value = 99.0f;
+        android.hardware.thermal.Temperature halT2 = new android.hardware.thermal.Temperature();
+        halT2.name = "test2";
+        halT2.type = TemperatureType.MODEM;
+        halT2.throttlingStatus = ThrottlingSeverity.NONE;
+
+        android.hardware.thermal.Temperature halT3WithDiffType =
+                new android.hardware.thermal.Temperature();
+        halT3WithDiffType.type = TemperatureType.BCL_CURRENT;
+        halT3WithDiffType.throttlingStatus = ThrottlingSeverity.CRITICAL;
+
+        Mockito.when(mAidlHalMock.getTemperaturesWithType(Mockito.anyInt())).thenReturn(
+                new android.hardware.thermal.Temperature[]{
+                        halT2, halT1, halT3WithDiffType,
+                });
+        List<Temperature> ret = mAidlWrapper.getCurrentTemperatures(true, TemperatureType.MODEM);
+        Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperaturesWithType(
+                TemperatureType.MODEM);
+
+        Temperature expectedT1 = new Temperature(halT1.value, halT1.type, halT1.name,
+                halT1.throttlingStatus);
+        Temperature expectedT2 = new Temperature(halT2.value, halT2.type, halT2.name,
+                halT2.throttlingStatus);
+        List<Temperature> expectedRet = List.of(expectedT1, expectedT2);
+        assertTrue("Got temperature list as " + ret + " with different values compared to "
+                + expectedRet, expectedRet.containsAll(ret));
+    }
+
+    @Test
+    public void getCurrentTemperatures_invalidStatus_aidl() throws RemoteException {
+        android.hardware.thermal.Temperature halTInvalid =
+                new android.hardware.thermal.Temperature();
+        halTInvalid.name = "test";
+        halTInvalid.type = TemperatureType.MODEM;
+        halTInvalid.throttlingStatus = 99;
+
+        Mockito.when(mAidlHalMock.getTemperatures()).thenReturn(
+                new android.hardware.thermal.Temperature[]{
+                        halTInvalid
+                });
+        List<Temperature> ret = mAidlWrapper.getCurrentTemperatures(false, 0);
+        Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperatures();
+
+        List<Temperature> expectedRet = List.of(
+                new Temperature(halTInvalid.value, halTInvalid.type, halTInvalid.name,
+                        ThrottlingSeverity.NONE));
+        assertEquals(expectedRet, ret);
+    }
+
+    @Test
+    public void getCurrentCoolingDevices_withFilter_aidl() throws RemoteException {
+        android.hardware.thermal.CoolingDevice halC1 = new android.hardware.thermal.CoolingDevice();
+        halC1.type = CoolingType.SPEAKER;
+        halC1.name = "test1";
+        halC1.value = 10;
+        android.hardware.thermal.CoolingDevice halC2 = new android.hardware.thermal.CoolingDevice();
+        halC2.type = CoolingType.MODEM;
+        halC2.name = "test2";
+        halC2.value = 110;
+
+        Mockito.when(mAidlHalMock.getCoolingDevicesWithType(Mockito.anyInt())).thenReturn(
+                new android.hardware.thermal.CoolingDevice[]{
+                        halC1, halC2
+                }
+        );
+        List<CoolingDevice> ret = mAidlWrapper.getCurrentCoolingDevices(true, CoolingType.SPEAKER);
+        Mockito.verify(mAidlHalMock, Mockito.times(1)).getCoolingDevicesWithType(
+                CoolingType.SPEAKER);
+
+        CoolingDevice expectedC1 = new CoolingDevice(halC1.value, halC1.type, halC1.name);
+        List<CoolingDevice> expectedRet = List.of(expectedC1);
+        assertTrue("Got cooling device list as " + ret + " with different values compared to "
+                + expectedRet, expectedRet.containsAll(ret));
+    }
+
+    @Test
+    public void getCurrentCoolingDevices_invalidType_aidl() throws RemoteException {
+        android.hardware.thermal.CoolingDevice halC1 = new android.hardware.thermal.CoolingDevice();
+        halC1.type = 99;
+        halC1.name = "test1";
+        halC1.value = 10;
+        android.hardware.thermal.CoolingDevice halC2 = new android.hardware.thermal.CoolingDevice();
+        halC2.type = -1;
+        halC2.name = "test2";
+        halC2.value = 110;
+
+        Mockito.when(mAidlHalMock.getCoolingDevices()).thenReturn(
+                new android.hardware.thermal.CoolingDevice[]{
+                        halC1, halC2
+                }
+        );
+        List<CoolingDevice> ret = mAidlWrapper.getCurrentCoolingDevices(false, 0);
+        Mockito.verify(mAidlHalMock, Mockito.times(1)).getCoolingDevices();
+
+        assertTrue("Got cooling device list as " + ret + ", expecting empty list", ret.isEmpty());
+    }
+
+    @Test
+    public void getTemperatureThresholds_withFilter_aidl() throws RemoteException {
+        TemperatureThreshold halT1 = new TemperatureThreshold();
+        halT1.name = "test1";
+        halT1.type = Temperature.TYPE_SKIN;
+        halT1.hotThrottlingThresholds = new float[]{1, 2, 3};
+        halT1.coldThrottlingThresholds = new float[]{};
+
+        TemperatureThreshold halT2 = new TemperatureThreshold();
+        halT1.name = "test2";
+        halT1.type = Temperature.TYPE_SOC;
+        halT1.hotThrottlingThresholds = new float[]{};
+        halT1.coldThrottlingThresholds = new float[]{3, 2, 1};
+
+        Mockito.when(mAidlHalMock.getTemperatureThresholdsWithType(Mockito.anyInt())).thenReturn(
+                new TemperatureThreshold[]{halT1, halT2}
+        );
+        List<TemperatureThreshold> ret = mAidlWrapper.getTemperatureThresholds(true,
+                Temperature.TYPE_SOC);
+        Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperatureThresholdsWithType(
+                Temperature.TYPE_SOC);
+
+        assertEquals("Got unexpected temperature thresholds size", 1, ret.size());
+        TemperatureThreshold threshold = ret.get(0);
+        assertEquals(halT1.name, threshold.name);
+        assertEquals(halT1.type, threshold.type);
+        assertArrayEquals(halT1.hotThrottlingThresholds, threshold.hotThrottlingThresholds, 0.1f);
+        assertArrayEquals(halT1.coldThrottlingThresholds, threshold.coldThrottlingThresholds, 0.1f);
+    }
+}
diff --git a/services/tests/servicestests/AndroidManifest.xml b/services/tests/servicestests/AndroidManifest.xml
index 9eb3b92..7149265 100644
--- a/services/tests/servicestests/AndroidManifest.xml
+++ b/services/tests/servicestests/AndroidManifest.xml
@@ -98,6 +98,7 @@
     <uses-permission android:name="android.permission.MAINLINE_NETWORK_STACK"/>
     <uses-permission
         android:name="android.permission.OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD"/>
+    <uses-permission android:name="android.permission.OVERRIDE_COMPAT_CHANGE_CONFIG"/>
     <uses-permission android:name="android.permission.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY" />
     <uses-permission android:name="android.permission.READ_NEARBY_STREAMING_POLICY" />
     <uses-permission android:name="android.permission.MODIFY_AUDIO_ROUTING" />
diff --git a/services/tests/servicestests/src/com/android/server/CountryDetectorServiceTest.java b/services/tests/servicestests/src/com/android/server/CountryDetectorServiceTest.java
index 83a597d..b0ad31d 100644
--- a/services/tests/servicestests/src/com/android/server/CountryDetectorServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/CountryDetectorServiceTest.java
@@ -179,8 +179,9 @@
         mCountryDetectorService.systemRunning();
         mCountryDetectorService.addCountryListener(countryListenerA);
         mCountryDetectorService.addCountryListener(countryListenerB);
-        expect.that(countryListenerA.isNotified()).isFalse();
-        expect.that(countryListenerB.isNotified()).isFalse();
+        //Immediate Callback Info support at ag/20470367
+        expect.that(countryListenerA.isNotified()).isTrue();
+        expect.that(countryListenerB.isNotified()).isTrue();
         mCountryDetectorService.notifyReceivers(country);
 
         expect.that(countryListenerA.isNotified()).isTrue();
diff --git a/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java
index cbe6d26..17a5876 100644
--- a/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java
@@ -37,6 +37,7 @@
 import static org.mockito.Mockito.verifyNoMoreInteractions;
 
 import android.annotation.NonNull;
+import android.content.AttributionSource;
 import android.content.Context;
 import android.net.ConnectivityManager;
 import android.net.INetd;
@@ -46,8 +47,10 @@
 import android.os.BatteryStats;
 import android.os.Binder;
 import android.os.IBinder;
+import android.os.PermissionEnforcer;
 import android.os.Process;
 import android.os.RemoteException;
+import android.permission.PermissionCheckerManager;
 import android.test.suitebuilder.annotation.SmallTest;
 import android.util.ArrayMap;
 
@@ -87,6 +90,7 @@
     private ArgumentCaptor<INetdUnsolicitedEventListener> mUnsolListenerCaptor;
 
     private final MockDependencies mDeps = new MockDependencies();
+    private final MockPermissionEnforcer mPermissionEnforcer = new MockPermissionEnforcer();
 
     private final class MockDependencies extends Dependencies {
         @Override
@@ -114,6 +118,24 @@
         }
     }
 
+    private static final class MockPermissionEnforcer extends PermissionEnforcer {
+        @Override
+        protected int checkPermission(@NonNull String permission,
+                @NonNull AttributionSource source) {
+            String[] granted = new String [] {
+                android.Manifest.permission.NETWORK_SETTINGS,
+                android.Manifest.permission.OBSERVE_NETWORK_POLICY,
+                android.Manifest.permission.SHUTDOWN
+            };
+            for (String p : granted) {
+                if (p.equals(permission)) {
+                    return PermissionCheckerManager.PERMISSION_GRANTED;
+                }
+            }
+            return PermissionCheckerManager.PERMISSION_HARD_DENIED;
+        }
+    }
+
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
@@ -122,6 +144,13 @@
         doReturn(Context.CONNECTIVITY_SERVICE).when(mContext).getSystemServiceName(
                 eq(ConnectivityManager.class));
         doReturn(mCm).when(mContext).getSystemService(eq(Context.CONNECTIVITY_SERVICE));
+        // The AIDL stub will use PermissionEnforcer to check permission from the caller.
+        // Mock the service. See MockPermissionEnforcer above.
+        doReturn(Context.PERMISSION_ENFORCER_SERVICE).when(mContext).getSystemServiceName(
+                eq(PermissionEnforcer.class));
+        doReturn(mPermissionEnforcer).when(mContext).getSystemService(
+                eq(Context.PERMISSION_ENFORCER_SERVICE));
+
         // Start the service and wait until it connects to our socket.
         mNMService = NetworkManagementService.create(mContext, mDeps);
     }
diff --git a/services/tests/servicestests/src/com/android/server/am/UserControllerTest.java b/services/tests/servicestests/src/com/android/server/am/UserControllerTest.java
index d47f063..0dfe664 100644
--- a/services/tests/servicestests/src/com/android/server/am/UserControllerTest.java
+++ b/services/tests/servicestests/src/com/android/server/am/UserControllerTest.java
@@ -38,6 +38,8 @@
 import static com.android.server.am.UserController.USER_CURRENT_MSG;
 import static com.android.server.am.UserController.USER_START_MSG;
 import static com.android.server.am.UserController.USER_SWITCH_TIMEOUT_MSG;
+import static com.android.server.pm.UserManagerInternal.USER_START_MODE_BACKGROUND;
+import static com.android.server.pm.UserManagerInternal.USER_START_MODE_FOREGROUND;
 
 import static com.google.android.collect.Lists.newArrayList;
 import static com.google.android.collect.Sets.newHashSet;
@@ -190,7 +192,7 @@
             // that's not the case, the test should call mockAssignUserToMainDisplay()
             doReturn(UserManagerInternal.USER_ASSIGNMENT_RESULT_SUCCESS_VISIBLE)
                     .when(mInjector.mUserManagerInternalMock)
-                    .assignUserToDisplayOnStart(anyInt(), anyInt(), anyBoolean(), anyInt());
+                    .assignUserToDisplayOnStart(anyInt(), anyInt(), anyInt(), anyInt());
 
             mUserController = new UserController(mInjector);
             mUserController.setAllowUserUnlocking(true);
@@ -207,7 +209,7 @@
 
     @Test
     public void testStartUser_foreground() {
-        mUserController.startUser(TEST_USER_ID, true /* foreground */);
+        mUserController.startUser(TEST_USER_ID, USER_START_MODE_FOREGROUND);
         verify(mInjector.getWindowManager()).startFreezingScreen(anyInt(), anyInt());
         verify(mInjector.getWindowManager(), never()).stopFreezingScreen();
         verify(mInjector.getWindowManager(), times(1)).setSwitchingUser(anyBoolean());
@@ -219,7 +221,7 @@
 
     @Test
     public void testStartUser_background() {
-        boolean started = mUserController.startUser(TEST_USER_ID, /* foreground= */ false);
+        boolean started = mUserController.startUser(TEST_USER_ID, USER_START_MODE_BACKGROUND);
         assertWithMessage("startUser(%s, foreground=false)", TEST_USER_ID).that(started).isTrue();
         verify(mInjector.getWindowManager(), never()).startFreezingScreen(anyInt(), anyInt());
         verify(mInjector.getWindowManager(), never()).setSwitchingUser(anyBoolean());
@@ -232,22 +234,15 @@
     public void testStartUser_displayAssignmentFailed() {
         doReturn(UserManagerInternal.USER_ASSIGNMENT_RESULT_FAILURE)
                 .when(mInjector.mUserManagerInternalMock)
-                .assignUserToDisplayOnStart(eq(TEST_USER_ID), anyInt(), eq(true), anyInt());
+                .assignUserToDisplayOnStart(eq(TEST_USER_ID), anyInt(),
+                        eq(USER_START_MODE_FOREGROUND), anyInt());
 
-        boolean started = mUserController.startUser(TEST_USER_ID, /* foreground= */ true);
+        boolean started = mUserController.startUser(TEST_USER_ID, USER_START_MODE_FOREGROUND);
 
         assertWithMessage("startUser(%s, foreground=true)", TEST_USER_ID).that(started).isFalse();
     }
 
     @Test
-    public void testStartUserOnSecondaryDisplay_defaultDisplay() {
-        assertThrows(IllegalArgumentException.class, () -> mUserController
-                .startUserOnSecondaryDisplay(TEST_USER_ID, Display.DEFAULT_DISPLAY));
-
-        verifyUserNeverAssignedToDisplay();
-    }
-
-    @Test
     public void testStartUserOnSecondaryDisplay() {
         boolean started = mUserController.startUserOnSecondaryDisplay(TEST_USER_ID, 42);
 
@@ -266,7 +261,7 @@
         mUserController.setInitialConfig(/* userSwitchUiEnabled= */ false,
                 /* maxRunningUsers= */ 3, /* delayUserDataLocking= */ false);
 
-        mUserController.startUser(TEST_USER_ID, /* foreground= */ true);
+        mUserController.startUser(TEST_USER_ID, USER_START_MODE_FOREGROUND);
         verify(mInjector.getWindowManager(), never()).startFreezingScreen(anyInt(), anyInt());
         verify(mInjector.getWindowManager(), never()).stopFreezingScreen();
         verify(mInjector.getWindowManager(), never()).setSwitchingUser(anyBoolean());
@@ -275,7 +270,8 @@
 
     @Test
     public void testStartPreCreatedUser_foreground() {
-        assertFalse(mUserController.startUser(TEST_PRE_CREATED_USER_ID, /* foreground= */ true));
+        assertFalse(
+                mUserController.startUser(TEST_PRE_CREATED_USER_ID, USER_START_MODE_FOREGROUND));
         // Make sure no intents have been fired for pre-created users.
         assertTrue(mInjector.mSentIntents.isEmpty());
 
@@ -284,7 +280,7 @@
 
     @Test
     public void testStartPreCreatedUser_background() throws Exception {
-        assertTrue(mUserController.startUser(TEST_PRE_CREATED_USER_ID, /* foreground= */ false));
+        assertTrue(mUserController.startUser(TEST_PRE_CREATED_USER_ID, USER_START_MODE_BACKGROUND));
         // Make sure no intents have been fired for pre-created users.
         assertTrue(mInjector.mSentIntents.isEmpty());
 
@@ -352,7 +348,7 @@
         }).when(observer).onUserSwitching(anyInt(), any());
         mUserController.registerUserSwitchObserver(observer, "mock");
         // Start user -- this will update state of mUserController
-        mUserController.startUser(TEST_USER_ID, true);
+        mUserController.startUser(TEST_USER_ID, USER_START_MODE_FOREGROUND);
         Message reportMsg = mInjector.mHandler.getMessageForCode(REPORT_USER_SWITCH_MSG);
         assertNotNull(reportMsg);
         UserState userState = (UserState) reportMsg.obj;
@@ -382,7 +378,7 @@
         when(observer.asBinder()).thenReturn(new Binder());
         mUserController.registerUserSwitchObserver(observer, "mock");
         // Start user -- this will update state of mUserController
-        mUserController.startUser(TEST_USER_ID, true);
+        mUserController.startUser(TEST_USER_ID, USER_START_MODE_FOREGROUND);
         Message reportMsg = mInjector.mHandler.getMessageForCode(REPORT_USER_SWITCH_MSG);
         assertNotNull(reportMsg);
         UserState userState = (UserState) reportMsg.obj;
@@ -408,7 +404,7 @@
         mUserController.setInitialConfig(/* userSwitchUiEnabled= */ true,
                 /* maxRunningUsers= */ 3, /* delayUserDataLocking= */ false);
         // Start user -- this will update state of mUserController
-        mUserController.startUser(TEST_USER_ID, true);
+        mUserController.startUser(TEST_USER_ID, USER_START_MODE_FOREGROUND);
         Message reportMsg = mInjector.mHandler.getMessageForCode(REPORT_USER_SWITCH_MSG);
         assertNotNull(reportMsg);
         UserState userState = (UserState) reportMsg.obj;
@@ -429,7 +425,7 @@
         mUserController.setInitialConfig(/* userSwitchUiEnabled= */ true,
                 /* maxRunningUsers= */ 3, /* delayUserDataLocking= */ false);
         // Start user -- this will update state of mUserController
-        mUserController.startUser(TEST_USER_ID, /* foreground=*/ true);
+        mUserController.startUser(TEST_USER_ID, USER_START_MODE_FOREGROUND);
         Message reportMsg = mInjector.mHandler.getMessageForCode(REPORT_USER_SWITCH_MSG);
         assertNotNull(reportMsg);
         UserState userState = (UserState) reportMsg.obj;
@@ -450,7 +446,7 @@
                 /* maxRunningUsers= */ 3, /* delayUserDataLocking= */ false);
 
         // Start user -- this will update state of mUserController
-        mUserController.startUser(TEST_USER_ID, /* foreground=*/ true);
+        mUserController.startUser(TEST_USER_ID, USER_START_MODE_FOREGROUND);
         Message reportMsg = mInjector.mHandler.getMessageForCode(REPORT_USER_SWITCH_MSG);
         assertNotNull(reportMsg);
         UserState userState = (UserState) reportMsg.obj;
@@ -487,7 +483,7 @@
         when(observer.asBinder()).thenReturn(new Binder());
         mUserController.registerUserSwitchObserver(observer, "mock");
         // Start user -- this will update state of mUserController
-        mUserController.startUser(TEST_USER_ID, true);
+        mUserController.startUser(TEST_USER_ID, USER_START_MODE_FOREGROUND);
         Message reportMsg = mInjector.mHandler.getMessageForCode(REPORT_USER_SWITCH_MSG);
         assertNotNull(reportMsg);
         int oldUserId = reportMsg.arg1;
@@ -511,7 +507,8 @@
     public void testExplicitSystemUserStartInBackground() {
         setUpUser(UserHandle.USER_SYSTEM, 0);
         assertFalse(mUserController.isSystemUserStarted());
-        assertTrue(mUserController.startUser(UserHandle.USER_SYSTEM, false, null));
+        assertTrue(mUserController.startUser(UserHandle.USER_SYSTEM, USER_START_MODE_BACKGROUND,
+                null));
         assertTrue(mUserController.isSystemUserStarted());
     }
 
@@ -662,7 +659,7 @@
     @Test
     public void testStopUser_currentUser() {
         setUpUser(TEST_USER_ID1, /* flags= */ 0);
-        mUserController.startUser(TEST_USER_ID1, /* foreground= */ true);
+        mUserController.startUser(TEST_USER_ID1, USER_START_MODE_FOREGROUND);
 
         int r = mUserController.stopUser(TEST_USER_ID1, /* force= */ true,
                 /* allowDelayedLocking= */ true, /* stopUserCallback= */ null,
@@ -701,7 +698,7 @@
     public void testUserNotUnlockedBeforeAllowed() throws Exception {
         mUserController.setAllowUserUnlocking(false);
 
-        mUserController.startUser(TEST_USER_ID, /* foreground= */ false);
+        mUserController.startUser(TEST_USER_ID, USER_START_MODE_BACKGROUND);
 
         verify(mInjector.mStorageManagerMock, never())
                 .unlockUserKey(eq(TEST_USER_ID), anyInt(), any());
@@ -862,10 +859,10 @@
         setUpUser(user1, 0);
         setUpUser(user2, 0);
 
-        mUserController.startUser(user1, /* foreground= */ true);
+        mUserController.startUser(user1, USER_START_MODE_FOREGROUND);
         mUserController.getStartedUserState(user1).setState(UserState.STATE_RUNNING_UNLOCKED);
 
-        mUserController.startUser(user2, /* foreground= */ false);
+        mUserController.startUser(user2, USER_START_MODE_BACKGROUND);
         mUserController.getStartedUserState(user2).setState(UserState.STATE_RUNNING_LOCKED);
 
         final int event1a = SystemService.UserCompletedEventType.EVENT_TYPE_USER_STARTING;
@@ -902,7 +899,7 @@
 
     private void setUpAndStartUserInBackground(int userId) throws Exception {
         setUpUser(userId, 0);
-        mUserController.startUser(userId, /* foreground= */ false);
+        mUserController.startUser(userId, USER_START_MODE_BACKGROUND);
         verify(mInjector.mLockPatternUtilsMock, times(1)).unlockUserKeyIfUnsecured(userId);
         mUserStates.put(userId, mUserController.getStartedUserState(userId));
     }
@@ -946,7 +943,7 @@
     private void addForegroundUserAndContinueUserSwitch(int newUserId, int expectedOldUserId,
             int expectedNumberOfCalls, boolean expectOldUserStopping) {
         // Start user -- this will update state of mUserController
-        mUserController.startUser(newUserId, true);
+        mUserController.startUser(newUserId, USER_START_MODE_FOREGROUND);
         Message reportMsg = mInjector.mHandler.getMessageForCode(REPORT_USER_SWITCH_MSG);
         assertNotNull(reportMsg);
         UserState userState = (UserState) reportMsg.obj;
@@ -1005,12 +1002,12 @@
 
     private void verifyUserAssignedToDisplay(@UserIdInt int userId, int displayId) {
         verify(mInjector.getUserManagerInternal()).assignUserToDisplayOnStart(eq(userId), anyInt(),
-                anyBoolean(), eq(displayId));
+                anyInt(), eq(displayId));
     }
 
     private void verifyUserNeverAssignedToDisplay() {
         verify(mInjector.getUserManagerInternal(), never()).assignUserToDisplayOnStart(anyInt(),
-                anyInt(), anyBoolean(), anyInt());
+                anyInt(), anyInt(), anyInt());
     }
 
     private void verifyUserUnassignedFromDisplay(@UserIdInt int userId) {
diff --git a/services/tests/servicestests/src/com/android/server/appop/AppOpsNotedWatcherTest.java b/services/tests/servicestests/src/com/android/server/appop/AppOpsNotedWatcherTest.java
index 6630178..47fdcb6 100644
--- a/services/tests/servicestests/src/com/android/server/appop/AppOpsNotedWatcherTest.java
+++ b/services/tests/servicestests/src/com/android/server/appop/AppOpsNotedWatcherTest.java
@@ -64,12 +64,12 @@
         // Verify that we got called for the ops being noted
         final InOrder inOrder = inOrder(listener);
         inOrder.verify(listener, timeout(NOTIFICATION_TIMEOUT_MILLIS)
-                .times(1)).onOpNoted(eq(AppOpsManager.OP_FINE_LOCATION),
+                .times(1)).onOpNoted(eq(AppOpsManager.OPSTR_FINE_LOCATION),
                 eq(Process.myUid()), eq(getContext().getPackageName()),
                 eq(getContext().getAttributionTag()), eq(AppOpsManager.OP_FLAG_SELF),
                 eq(AppOpsManager.MODE_ALLOWED));
         inOrder.verify(listener, timeout(NOTIFICATION_TIMEOUT_MILLIS)
-                .times(1)).onOpNoted(eq(AppOpsManager.OP_CAMERA),
+                .times(1)).onOpNoted(eq(AppOpsManager.OPSTR_CAMERA),
                 eq(Process.myUid()), eq(getContext().getPackageName()),
                 eq(getContext().getAttributionTag()), eq(AppOpsManager.OP_FLAG_SELF),
                 eq(AppOpsManager.MODE_ALLOWED));
@@ -94,7 +94,7 @@
 
         // Verify it's watched again
         verify(listener, timeout(NOTIFICATION_TIMEOUT_MILLIS)
-                .times(2)).onOpNoted(eq(AppOpsManager.OP_FINE_LOCATION),
+                .times(2)).onOpNoted(eq(AppOpsManager.OPSTR_FINE_LOCATION),
                 eq(Process.myUid()), eq(getContext().getPackageName()),
                 eq(getContext().getAttributionTag()), eq(AppOpsManager.OP_FLAG_SELF),
                 eq(AppOpsManager.MODE_ALLOWED));
diff --git a/services/tests/servicestests/src/com/android/server/companion/virtual/InputControllerTest.java b/services/tests/servicestests/src/com/android/server/companion/virtual/InputControllerTest.java
index d2f2af1..9c7c574 100644
--- a/services/tests/servicestests/src/com/android/server/companion/virtual/InputControllerTest.java
+++ b/services/tests/servicestests/src/com/android/server/companion/virtual/InputControllerTest.java
@@ -21,6 +21,7 @@
 import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.startsWith;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
@@ -143,4 +144,38 @@
         verify(mInputManagerInternalMock).setVirtualMousePointerDisplayId(eq(1));
     }
 
+    @Test
+    public void createNavigationTouchpad_hasDeviceId() {
+        final IBinder deviceToken = new Binder();
+        mInputController.createNavigationTouchpad("name", /*vendorId= */ 1, /*productId= */ 1,
+                deviceToken, /* displayId= */ 1, /* touchpadHeight= */ 50, /* touchpadWidth= */ 50);
+
+        int deviceId = mInputController.getInputDeviceId(deviceToken);
+        int[] deviceIds = InputManager.getInstance().getInputDeviceIds();
+
+        assertWithMessage("InputManager's deviceIds list should contain id of the device").that(
+            deviceIds).asList().contains(deviceId);
+    }
+
+    @Test
+    public void createNavigationTouchpad_setsTypeAssociation() {
+        final IBinder deviceToken = new Binder();
+        mInputController.createNavigationTouchpad("name", /*vendorId= */ 1, /*productId= */ 1,
+                deviceToken, /* displayId= */ 1, /* touchpadHeight= */ 50, /* touchpadWidth= */ 50);
+
+        verify(mInputManagerInternalMock).setTypeAssociation(
+                startsWith("virtualNavigationTouchpad:"), eq("touchNavigation"));
+    }
+
+    @Test
+    public void createAndUnregisterNavigationTouchpad_unsetsTypeAssociation() {
+        final IBinder deviceToken = new Binder();
+        mInputController.createNavigationTouchpad("name", /*vendorId= */ 1, /*productId= */ 1,
+                deviceToken, /* displayId= */ 1, /* touchpadHeight= */ 50, /* touchpadWidth= */ 50);
+
+        mInputController.unregisterInputDevice(deviceToken);
+
+        verify(mInputManagerInternalMock).unsetTypeAssociation(
+                startsWith("virtualNavigationTouchpad:"));
+    }
 }
diff --git a/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceManagerServiceTest.java
index 9de6190..31e53d5 100644
--- a/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceManagerServiceTest.java
@@ -16,6 +16,8 @@
 
 package com.android.server.companion.virtual;
 
+import static android.companion.virtual.VirtualDeviceManager.DEVICE_ID_DEFAULT;
+import static android.companion.virtual.VirtualDeviceManager.DEVICE_ID_INVALID;
 import static android.companion.virtual.VirtualDeviceParams.DEVICE_POLICY_CUSTOM;
 import static android.companion.virtual.VirtualDeviceParams.DEVICE_POLICY_DEFAULT;
 import static android.companion.virtual.VirtualDeviceParams.POLICY_TYPE_SENSORS;
@@ -47,7 +49,6 @@
 import android.app.admin.DevicePolicyManager;
 import android.companion.AssociationInfo;
 import android.companion.virtual.IVirtualDeviceActivityListener;
-import android.companion.virtual.VirtualDeviceManager;
 import android.companion.virtual.VirtualDeviceParams;
 import android.companion.virtual.audio.IAudioConfigChangedCallback;
 import android.companion.virtual.audio.IAudioRoutingCallback;
@@ -68,6 +69,7 @@
 import android.hardware.input.VirtualMouseConfig;
 import android.hardware.input.VirtualMouseRelativeEvent;
 import android.hardware.input.VirtualMouseScrollEvent;
+import android.hardware.input.VirtualNavigationTouchpadConfig;
 import android.hardware.input.VirtualTouchEvent;
 import android.hardware.input.VirtualTouchscreenConfig;
 import android.net.MacAddress;
@@ -84,6 +86,7 @@
 import android.testing.AndroidTestingRunner;
 import android.testing.TestableLooper;
 import android.util.ArraySet;
+import android.view.Display;
 import android.view.DisplayInfo;
 import android.view.KeyEvent;
 import android.view.WindowManager;
@@ -95,6 +98,8 @@
 import com.android.server.input.InputManagerInternal;
 import com.android.server.sensors.SensorManagerInternal;
 
+import com.google.android.collect.Sets;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -106,6 +111,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Set;
 import java.util.function.Consumer;
 
 @Presubmit
@@ -122,12 +128,13 @@
     private static final String GOOGLE_MAPS_PACKAGE_NAME = "com.google.android.apps.maps";
     private static final String DEVICE_NAME = "device name";
     private static final int DISPLAY_ID = 2;
+    private static final int DISPLAY_ID_2 = 3;
+    private static final int DEVICE_OWNER_UID_1 = 50;
+    private static final int DEVICE_OWNER_UID_2 = 51;
     private static final int UID_1 = 0;
     private static final int UID_2 = 10;
     private static final int UID_3 = 10000;
     private static final int UID_4 = 10001;
-    private static final int ASSOCIATION_ID_1 = 1;
-    private static final int ASSOCIATION_ID_2 = 2;
     private static final int PRODUCT_ID = 10;
     private static final int VENDOR_ID = 5;
     private static final String UNIQUE_ID = "uniqueid";
@@ -169,6 +176,14 @@
                     .setWidthInPixels(WIDTH)
                     .setHeightInPixels(HEIGHT)
                     .build();
+    private static final VirtualNavigationTouchpadConfig NAVIGATION_TOUCHPAD_CONFIG =
+            new VirtualNavigationTouchpadConfig.Builder(
+                    /* touchpadHeight= */ HEIGHT, /* touchpadWidth= */ WIDTH)
+                    .setVendorId(VENDOR_ID)
+                    .setProductId(PRODUCT_ID)
+                    .setInputDeviceName(DEVICE_NAME)
+                    .setAssociatedDisplayId(DISPLAY_ID)
+                    .build();
 
     private Context mContext;
     private InputManagerMockHelper mInputManagerMockHelper;
@@ -178,6 +193,7 @@
     private AssociationInfo mAssociationInfo;
     private VirtualDeviceManagerService mVdms;
     private VirtualDeviceManagerInternal mLocalService;
+    private VirtualDeviceManagerService.VirtualDeviceManagerImpl mVdm;
     @Mock
     private InputController.NativeWrapper mNativeWrapperMock;
     @Mock
@@ -298,50 +314,64 @@
                 mContext.getSystemService(WindowManager.class), threadVerifier);
         mSensorController = new SensorController(new Object(), VIRTUAL_DEVICE_ID);
 
-        mAssociationInfo = new AssociationInfo(1, 0, null,
+        mAssociationInfo = new AssociationInfo(/* associationId= */ 1, 0, null,
                 MacAddress.BROADCAST_ADDRESS, "", null, null, true, false, false, 0, 0);
 
         mVdms = new VirtualDeviceManagerService(mContext);
         mLocalService = mVdms.getLocalServiceInstance();
+        mVdm = mVdms.new VirtualDeviceManagerImpl();
+        mDeviceImpl = createVirtualDevice(VIRTUAL_DEVICE_ID, DEVICE_OWNER_UID_1);
+    }
 
-        VirtualDeviceParams params = new VirtualDeviceParams
-                .Builder()
-                .setBlockedActivities(getBlockedActivities())
-                .build();
-        mDeviceImpl = new VirtualDeviceImpl(mContext,
-                mAssociationInfo, new Binder(), /* ownerUid */ 0, VIRTUAL_DEVICE_ID,
-                mInputController, mSensorController, (int associationId) -> {},
-                mPendingTrampolineCallback, mActivityListener, mRunningAppsChangedCallback, params);
-        mVdms.addVirtualDevice(mDeviceImpl);
+    @Test
+    public void getDeviceIdForDisplayId_invalidDisplayId_returnsDefault() {
+        assertThat(mVdm.getDeviceIdForDisplayId(Display.INVALID_DISPLAY))
+                .isEqualTo(DEVICE_ID_DEFAULT);
+    }
+
+    @Test
+    public void getDeviceIdForDisplayId_defaultDisplayId_returnsDefault() {
+        assertThat(mVdm.getDeviceIdForDisplayId(Display.DEFAULT_DISPLAY))
+                .isEqualTo(DEVICE_ID_DEFAULT);
+    }
+
+    @Test
+    public void getDeviceIdForDisplayId_nonExistentDisplayId_returnsDefault() {
+        mDeviceImpl.mVirtualDisplayIds.remove(DISPLAY_ID);
+
+        assertThat(mVdm.getDeviceIdForDisplayId(DISPLAY_ID))
+                .isEqualTo(DEVICE_ID_DEFAULT);
+    }
+
+    @Test
+    public void getDeviceIdForDisplayId_withValidVirtualDisplayId_returnsDeviceId() {
+        mDeviceImpl.mVirtualDisplayIds.add(DISPLAY_ID);
+
+        assertThat(mVdm.getDeviceIdForDisplayId(DISPLAY_ID))
+                .isEqualTo(mDeviceImpl.getDeviceId());
     }
 
     @Test
     public void getDevicePolicy_invalidDeviceId_returnsDefault() {
-        assertThat(
-                mLocalService.getDevicePolicy(
-                        VirtualDeviceManager.INVALID_DEVICE_ID, POLICY_TYPE_SENSORS))
+        assertThat(mVdm.getDevicePolicy(DEVICE_ID_INVALID, POLICY_TYPE_SENSORS))
                 .isEqualTo(DEVICE_POLICY_DEFAULT);
     }
 
     @Test
     public void getDevicePolicy_defaultDeviceId_returnsDefault() {
-        assertThat(
-                mLocalService.getDevicePolicy(
-                        VirtualDeviceManager.DEFAULT_DEVICE_ID, POLICY_TYPE_SENSORS))
+        assertThat(mVdm.getDevicePolicy(DEVICE_ID_DEFAULT, POLICY_TYPE_SENSORS))
                 .isEqualTo(DEVICE_POLICY_DEFAULT);
     }
 
     @Test
     public void getDevicePolicy_nonExistentDeviceId_returnsDefault() {
-        assertThat(
-                mLocalService.getDevicePolicy(mDeviceImpl.getDeviceId() + 1, POLICY_TYPE_SENSORS))
+        assertThat(mVdm.getDevicePolicy(mDeviceImpl.getDeviceId() + 1, POLICY_TYPE_SENSORS))
                 .isEqualTo(DEVICE_POLICY_DEFAULT);
     }
 
     @Test
     public void getDevicePolicy_unspecifiedPolicy_returnsDefault() {
-        assertThat(
-                mLocalService.getDevicePolicy(mDeviceImpl.getDeviceId(), POLICY_TYPE_SENSORS))
+        assertThat(mVdm.getDevicePolicy(mDeviceImpl.getDeviceId(), POLICY_TYPE_SENSORS))
                 .isEqualTo(DEVICE_POLICY_DEFAULT);
     }
 
@@ -354,16 +384,116 @@
                 .build();
         mDeviceImpl = new VirtualDeviceImpl(mContext,
                 mAssociationInfo, new Binder(), /* ownerUid */ 0, VIRTUAL_DEVICE_ID,
-                mInputController, mSensorController, (int associationId) -> {},
+                mInputController, mSensorController,
+                /* onDeviceCloseListener= */ (int deviceId) -> {},
                 mPendingTrampolineCallback, mActivityListener, mRunningAppsChangedCallback, params);
         mVdms.addVirtualDevice(mDeviceImpl);
 
-        assertThat(
-                mLocalService.getDevicePolicy(mDeviceImpl.getDeviceId(), POLICY_TYPE_SENSORS))
+        assertThat(mVdm.getDevicePolicy(mDeviceImpl.getDeviceId(), POLICY_TYPE_SENSORS))
                 .isEqualTo(DEVICE_POLICY_CUSTOM);
     }
 
     @Test
+    public void getDeviceOwnerUid_oneDevice_returnsCorrectId() {
+        int ownerUid = mLocalService.getDeviceOwnerUid(mDeviceImpl.getDeviceId());
+        assertThat(ownerUid).isEqualTo(mDeviceImpl.getOwnerUid());
+    }
+
+    @Test
+    public void getDeviceOwnerUid_twoDevices_returnsCorrectId() {
+        int firstDeviceId = mDeviceImpl.getDeviceId();
+        int secondDeviceId = VIRTUAL_DEVICE_ID + 1;
+
+        createVirtualDevice(secondDeviceId, DEVICE_OWNER_UID_2);
+
+        int secondDeviceOwner = mLocalService.getDeviceOwnerUid(secondDeviceId);
+        assertThat(secondDeviceOwner).isEqualTo(DEVICE_OWNER_UID_2);
+
+        int firstDeviceOwner = mLocalService.getDeviceOwnerUid(firstDeviceId);
+        assertThat(firstDeviceOwner).isEqualTo(DEVICE_OWNER_UID_1);
+    }
+
+    @Test
+    public void getDeviceOwnerUid_nonExistentDevice_returnsInvalidUid() {
+        int nonExistentDeviceId = DEVICE_ID_DEFAULT;
+        int ownerUid = mLocalService.getDeviceOwnerUid(nonExistentDeviceId);
+        assertThat(ownerUid).isEqualTo(Process.INVALID_UID);
+    }
+
+    @Test
+    public void getDeviceIdsForUid_noRunningApps_returnsNull() {
+        Set<Integer> deviceIds = mLocalService.getDeviceIdsForUid(UID_1);
+        assertThat(deviceIds).isEmpty();
+    }
+
+    @Test
+    public void getDeviceIdsForUid_differentUidOnDevice_returnsNull() {
+        GenericWindowPolicyController gwpc =
+                mDeviceImpl.createWindowPolicyController(new ArrayList<>());
+        mDeviceImpl.onVirtualDisplayCreatedLocked(gwpc, DISPLAY_ID);
+        gwpc.onRunningAppsChanged(Sets.newArraySet(UID_2));
+
+        Set<Integer> deviceIds = mLocalService.getDeviceIdsForUid(UID_1);
+        assertThat(deviceIds).isEmpty();
+    }
+
+    @Test
+    public void getDeviceIdsForUid_oneUidOnDevice_returnsCorrectId() {
+        GenericWindowPolicyController gwpc =
+                mDeviceImpl.createWindowPolicyController(new ArrayList<>());
+        mDeviceImpl.onVirtualDisplayCreatedLocked(gwpc, DISPLAY_ID);
+        gwpc.onRunningAppsChanged(Sets.newArraySet(UID_1));
+
+        Set<Integer> deviceIds = mLocalService.getDeviceIdsForUid(UID_1);
+        assertThat(deviceIds).containsExactly(mDeviceImpl.getDeviceId());
+    }
+
+    @Test
+    public void getDeviceIdsForUid_twoUidsOnDevice_returnsCorrectId() {
+        GenericWindowPolicyController gwpc =
+                mDeviceImpl.createWindowPolicyController(new ArrayList<>());
+        mDeviceImpl.onVirtualDisplayCreatedLocked(gwpc, DISPLAY_ID);
+        gwpc.onRunningAppsChanged(Sets.newArraySet(UID_1, UID_2));
+
+        Set<Integer> deviceIds = mLocalService.getDeviceIdsForUid(UID_1);
+        assertThat(deviceIds).containsExactly(mDeviceImpl.getDeviceId());
+    }
+
+    @Test
+    public void getDeviceIdsForUid_twoDevicesUidOnOne_returnsCorrectId() {
+        int secondDeviceId = VIRTUAL_DEVICE_ID + 1;
+
+        VirtualDeviceImpl secondDevice = createVirtualDevice(secondDeviceId, DEVICE_OWNER_UID_2);
+
+        GenericWindowPolicyController gwpc =
+                secondDevice.createWindowPolicyController(new ArrayList<>());
+        secondDevice.onVirtualDisplayCreatedLocked(gwpc, DISPLAY_ID_2);
+        gwpc.onRunningAppsChanged(Sets.newArraySet(UID_1));
+
+        Set<Integer> deviceIds = mLocalService.getDeviceIdsForUid(UID_1);
+        assertThat(deviceIds).containsExactly(secondDevice.getDeviceId());
+    }
+
+    @Test
+    public void getDeviceIdsForUid_twoDevicesUidOnBoth_returnsCorrectId() {
+        int secondDeviceId = VIRTUAL_DEVICE_ID + 1;
+
+        VirtualDeviceImpl secondDevice = createVirtualDevice(secondDeviceId, DEVICE_OWNER_UID_2);
+        GenericWindowPolicyController gwpc1 =
+                mDeviceImpl.createWindowPolicyController(new ArrayList<>());
+        GenericWindowPolicyController gwpc2 =
+                mDeviceImpl.createWindowPolicyController(new ArrayList<>());
+        mDeviceImpl.onVirtualDisplayCreatedLocked(gwpc1, DISPLAY_ID);
+        secondDevice.onVirtualDisplayCreatedLocked(gwpc2, DISPLAY_ID_2);
+        gwpc1.onRunningAppsChanged(Sets.newArraySet(UID_1));
+        gwpc2.onRunningAppsChanged(Sets.newArraySet(UID_1, UID_2));
+
+        Set<Integer> deviceIds = mLocalService.getDeviceIdsForUid(UID_1);
+        assertThat(deviceIds).containsExactly(
+                mDeviceImpl.getDeviceId(), secondDevice.getDeviceId());
+    }
+
+    @Test
     public void onVirtualDisplayRemovedLocked_doesNotThrowException() {
         mDeviceImpl.onVirtualDisplayCreatedLocked(
                 mDeviceImpl.createWindowPolicyController(new ArrayList<>()), DISPLAY_ID);
@@ -398,7 +528,7 @@
         ArraySet<Integer> uids = new ArraySet<>(Arrays.asList(UID_1, UID_2));
         mLocalService.registerAppsOnVirtualDeviceListener(mAppsOnVirtualDeviceListener);
 
-        mVdms.notifyRunningAppsChanged(ASSOCIATION_ID_1, uids);
+        mVdms.notifyRunningAppsChanged(mDeviceImpl.getDeviceId(), uids);
         TestableLooper.get(this).processAllMessages();
 
         verify(mAppsOnVirtualDeviceListener).onAppsOnAnyVirtualDeviceChanged(uids);
@@ -411,13 +541,13 @@
         mLocalService.registerAppsOnVirtualDeviceListener(mAppsOnVirtualDeviceListener);
 
         // Notifies that the running apps on the first virtual device has changed.
-        mVdms.notifyRunningAppsChanged(ASSOCIATION_ID_1, uidsOnDevice1);
+        mVdms.notifyRunningAppsChanged(mDeviceImpl.getDeviceId(), uidsOnDevice1);
         TestableLooper.get(this).processAllMessages();
         verify(mAppsOnVirtualDeviceListener).onAppsOnAnyVirtualDeviceChanged(
                 new ArraySet<>(Arrays.asList(UID_1, UID_2)));
 
         // Notifies that the running apps on the second virtual device has changed.
-        mVdms.notifyRunningAppsChanged(ASSOCIATION_ID_2, uidsOnDevice2);
+        mVdms.notifyRunningAppsChanged(mDeviceImpl.getDeviceId() + 1, uidsOnDevice2);
         TestableLooper.get(this).processAllMessages();
         // The union of the apps running on both virtual devices are sent to the listeners.
         verify(mAppsOnVirtualDeviceListener).onAppsOnAnyVirtualDeviceChanged(
@@ -425,7 +555,7 @@
 
         // Notifies that the running apps on the first virtual device has changed again.
         uidsOnDevice1.remove(UID_2);
-        mVdms.notifyRunningAppsChanged(ASSOCIATION_ID_1, uidsOnDevice1);
+        mVdms.notifyRunningAppsChanged(mDeviceImpl.getDeviceId(), uidsOnDevice1);
         mLocalService.onAppsOnVirtualDeviceChanged();
         TestableLooper.get(this).processAllMessages();
         // The union of the apps running on both virtual devices are sent to the listeners.
@@ -434,7 +564,7 @@
 
         // Notifies that the running apps on the first virtual device has changed but with the same
         // set of UIDs.
-        mVdms.notifyRunningAppsChanged(ASSOCIATION_ID_1, uidsOnDevice1);
+        mVdms.notifyRunningAppsChanged(mDeviceImpl.getDeviceId(), uidsOnDevice1);
         mLocalService.onAppsOnVirtualDeviceChanged();
         TestableLooper.get(this).processAllMessages();
         // Listeners should not be notified.
@@ -579,8 +709,67 @@
                         .build();
         mDeviceImpl.createVirtualTouchscreen(positiveConfig, BINDER);
         assertWithMessage(
-                "Virtual touchscreen should create input device descriptor on successful creation"
-                        + ".").that(mInputController.getInputDeviceDescriptors()).isNotEmpty();
+            "Virtual touchscreen should create input device descriptor on successful creation"
+                + ".").that(mInputController.getInputDeviceDescriptors()).isNotEmpty();
+    }
+
+    @Test
+    public void createVirtualNavigationTouchpad_noDisplay_failsSecurityException() {
+        assertThrows(SecurityException.class,
+                () -> mDeviceImpl.createVirtualNavigationTouchpad(NAVIGATION_TOUCHPAD_CONFIG,
+                        BINDER));
+    }
+
+    @Test
+    public void createVirtualNavigationTouchpad_zeroDisplayDimension_failsWithException() {
+        mDeviceImpl.mVirtualDisplayIds.add(DISPLAY_ID);
+        assertThrows(IllegalArgumentException.class,
+                () -> {
+                final VirtualNavigationTouchpadConfig zeroConfig =
+                        new VirtualNavigationTouchpadConfig.Builder(
+                                /* touchpadHeight= */ 0, /* touchpadWidth= */ 0)
+                                .setVendorId(VENDOR_ID)
+                                .setProductId(PRODUCT_ID)
+                                .setInputDeviceName(DEVICE_NAME)
+                                .setAssociatedDisplayId(DISPLAY_ID)
+                                .build();
+                mDeviceImpl.createVirtualNavigationTouchpad(zeroConfig, BINDER);
+            });
+    }
+
+    @Test
+    public void createVirtualNavigationTouchpad_negativeDisplayDimension_failsWithException() {
+        mDeviceImpl.mVirtualDisplayIds.add(DISPLAY_ID);
+        assertThrows(IllegalArgumentException.class,
+                () -> {
+                    final VirtualNavigationTouchpadConfig zeroConfig =
+                            new VirtualNavigationTouchpadConfig.Builder(
+                                    /* touchpadHeight= */ -50, /* touchpadWidth= */ 50)
+                                    .setVendorId(VENDOR_ID)
+                                    .setProductId(PRODUCT_ID)
+                                    .setInputDeviceName(DEVICE_NAME)
+                                    .setAssociatedDisplayId(DISPLAY_ID)
+                                    .build();
+                mDeviceImpl.createVirtualNavigationTouchpad(zeroConfig, BINDER);
+            });
+    }
+
+    @Test
+    public void createVirtualNavigationTouchpad_positiveDisplayDimension_successful() {
+        mDeviceImpl.mVirtualDisplayIds.add(DISPLAY_ID);
+        VirtualNavigationTouchpadConfig positiveConfig =
+                new VirtualNavigationTouchpadConfig.Builder(
+                            /* touchpadHeight= */ 50, /* touchpadWidth= */ 50)
+                        .setVendorId(VENDOR_ID)
+                        .setProductId(PRODUCT_ID)
+                        .setInputDeviceName(DEVICE_NAME)
+                        .setAssociatedDisplayId(DISPLAY_ID)
+                        .build();
+        mDeviceImpl.createVirtualNavigationTouchpad(positiveConfig, BINDER);
+        assertWithMessage(
+            "Virtual navigation touchpad should create input device descriptor on successful "
+            + "creation"
+                + ".").that(mInputController.getInputDeviceDescriptors()).isNotEmpty();
     }
 
     @Test
@@ -627,6 +816,16 @@
     }
 
     @Test
+    public void createVirtualNavigationTouchpad_noPermission_failsSecurityException() {
+        mDeviceImpl.mVirtualDisplayIds.add(DISPLAY_ID);
+        doCallRealMethod().when(mContext).enforceCallingOrSelfPermission(
+                eq(Manifest.permission.CREATE_VIRTUAL_DEVICE), anyString());
+        assertThrows(SecurityException.class,
+                () -> mDeviceImpl.createVirtualNavigationTouchpad(NAVIGATION_TOUCHPAD_CONFIG,
+                        BINDER));
+    }
+
+    @Test
     public void createVirtualSensor_noPermission_failsSecurityException() {
         doCallRealMethod().when(mContext).enforceCallingOrSelfPermission(
                 eq(Manifest.permission.CREATE_VIRTUAL_DEVICE), anyString());
@@ -690,7 +889,18 @@
         mDeviceImpl.mVirtualDisplayIds.add(DISPLAY_ID);
         mDeviceImpl.createVirtualTouchscreen(TOUCHSCREEN_CONFIG, BINDER);
         assertWithMessage("Virtual touchscreen should register fd when the display matches").that(
-                mInputController.getInputDeviceDescriptors()).isNotEmpty();
+            mInputController.getInputDeviceDescriptors()).isNotEmpty();
+        verify(mNativeWrapperMock).openUinputTouchscreen(eq(DEVICE_NAME), eq(VENDOR_ID),
+                eq(PRODUCT_ID), anyString(), eq(HEIGHT), eq(WIDTH));
+    }
+
+    @Test
+    public void createVirtualNavigationTouchpad_hasDisplay_obtainFileDescriptor() {
+        mDeviceImpl.mVirtualDisplayIds.add(DISPLAY_ID);
+        mDeviceImpl.createVirtualNavigationTouchpad(NAVIGATION_TOUCHPAD_CONFIG, BINDER);
+        assertWithMessage("Virtual navigation touchpad should register fd when the display matches")
+            .that(
+            mInputController.getInputDeviceDescriptors()).isNotEmpty();
         verify(mNativeWrapperMock).openUinputTouchscreen(eq(DEVICE_NAME), eq(VENDOR_ID),
                 eq(PRODUCT_ID), anyString(), eq(HEIGHT), eq(WIDTH));
     }
@@ -1135,7 +1345,6 @@
                 /* targetDisplayCategory= */ null);
         verify(mContext).startActivityAsUser(argThat(intent ->
                 intent.filterEquals(blockedAppIntent)), any(), any());
-
     }
 
     @Test
@@ -1161,4 +1370,17 @@
                 intent.filterEquals(blockedAppIntent)), any(), any());
     }
 
+    private VirtualDeviceImpl createVirtualDevice(int virtualDeviceId, int ownerUid) {
+        VirtualDeviceParams params = new VirtualDeviceParams
+                .Builder()
+                .setBlockedActivities(getBlockedActivities())
+                .build();
+        VirtualDeviceImpl virtualDeviceImpl = new VirtualDeviceImpl(mContext,
+                mAssociationInfo, new Binder(), ownerUid, virtualDeviceId,
+                mInputController, mSensorController,
+                /* onDeviceCloseListener= */ (int deviceId) -> {},
+                mPendingTrampolineCallback, mActivityListener, mRunningAppsChangedCallback, params);
+        mVdms.addVirtualDevice(virtualDeviceImpl);
+        return virtualDeviceImpl;
+    }
 }
diff --git a/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceTest.java b/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceTest.java
index f6f1339..f473086 100644
--- a/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceTest.java
+++ b/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceTest.java
@@ -16,8 +16,8 @@
 
 package com.android.server.companion.virtual;
 
-import static android.companion.virtual.VirtualDeviceManager.DEFAULT_DEVICE_ID;
-import static android.companion.virtual.VirtualDeviceManager.INVALID_DEVICE_ID;
+import static android.companion.virtual.VirtualDeviceManager.DEVICE_ID_DEFAULT;
+import static android.companion.virtual.VirtualDeviceManager.DEVICE_ID_INVALID;
 
 import static com.google.common.truth.Truth.assertThat;
 
@@ -41,14 +41,14 @@
     public void build_invalidId_shouldThrowIllegalArgumentException() {
         assertThrows(
                 IllegalArgumentException.class,
-                () -> new VirtualDevice(INVALID_DEVICE_ID, VIRTUAL_DEVICE_NAME));
+                () -> new VirtualDevice(DEVICE_ID_INVALID, VIRTUAL_DEVICE_NAME));
     }
 
     @Test
     public void build_defaultId_shouldThrowIllegalArgumentException() {
         assertThrows(
                 IllegalArgumentException.class,
-                () -> new VirtualDevice(DEFAULT_DEVICE_ID, VIRTUAL_DEVICE_NAME));
+                () -> new VirtualDevice(DEVICE_ID_DEFAULT, VIRTUAL_DEVICE_NAME));
     }
 
     @Test
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
index a02b0f1..a55b196 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
@@ -4310,7 +4310,7 @@
         mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
         setupDeviceOwner();
         assertExpectException(SecurityException.class, null, () ->
-                dpm.setSystemSetting(admin1, Settings.System.SCREEN_BRIGHTNESS_FOR_VR, "0"));
+                dpm.setSystemSetting(admin1, Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, "0"));
     }
 
     @Test
@@ -7730,9 +7730,9 @@
 
         dpm.setDeviceOwnerType(admin1, DEVICE_OWNER_TYPE_FINANCED);
 
-        assertThat(dpm.getDeviceOwnerType(admin1)).isEqualTo(DEVICE_OWNER_TYPE_FINANCED);
+        assertThat(dpm.isFinancedDevice()).isTrue();
         initializeDpms();
-        assertThat(dpm.getDeviceOwnerType(admin1)).isEqualTo(DEVICE_OWNER_TYPE_FINANCED);
+        assertThat(dpm.isFinancedDevice()).isTrue();
     }
 
     @Test
@@ -7743,19 +7743,12 @@
 
         dpm.setDeviceOwnerType(admin1, DEVICE_OWNER_TYPE_FINANCED);
 
-        assertThat(dpm.getDeviceOwnerType(admin1)).isEqualTo(DEVICE_OWNER_TYPE_FINANCED);
+        assertThat(dpm.isFinancedDevice()).isTrue();
     }
 
     @Test
-    public void testGetDeviceOwnerType_throwsExceptionWhenThereIsNoDeviceOwner() {
-        assertThrows(IllegalStateException.class, () -> dpm.getDeviceOwnerType(admin1));
-    }
-
-    @Test
-    public void testGetDeviceOwnerType_throwsExceptionWhenNotAsDeviceOwnerAdmin() throws Exception {
-        setDeviceOwner();
-
-        assertThrows(IllegalStateException.class, () -> dpm.getDeviceOwnerType(admin2));
+    public void testIsFinancedDevice_throwsExceptionWhenThereIsNoDeviceOwner() {
+        assertThrows(SecurityException.class, () -> dpm.isFinancedDevice());
     }
 
     @Test
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/OwnersTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/OwnersTest.java
index f535fda..85a2446 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/OwnersTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/OwnersTest.java
@@ -44,6 +44,7 @@
 public class OwnersTest extends DpmTestBase {
 
     private static final String TESTDPC_PACKAGE = "com.afwsamples.testdpc";
+    private final DeviceStateCacheImpl mDeviceStateCache = new DeviceStateCacheImpl();
 
     @Before
     public void setUp() throws Exception {
@@ -120,6 +121,6 @@
         final MockSystemServices services = getServices();
         return new Owners(services.userManager, services.userManagerInternal,
                 services.packageManagerInternal, services.activityTaskManagerInternal,
-                services.activityManagerInternal, services.pathProvider);
+                services.activityManagerInternal, mDeviceStateCache, services.pathProvider);
     }
 }
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/PolicyVersionUpgraderTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/PolicyVersionUpgraderTest.java
index d540734..1779b16 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/PolicyVersionUpgraderTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/PolicyVersionUpgraderTest.java
@@ -33,6 +33,7 @@
 import android.os.IpcDataCache;
 import android.os.Parcel;
 import android.os.UserHandle;
+import android.util.ArraySet;
 import android.util.Xml;
 
 import androidx.test.InstrumentationRegistry;
@@ -47,29 +48,42 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.function.Function;
 
+import javax.xml.parsers.DocumentBuilderFactory;
+
 @RunWith(JUnit4.class)
 public class PolicyVersionUpgraderTest extends DpmTestBase {
     // NOTE: Only change this value if the corresponding CL also adds a test to test the upgrade
     // to the new version.
-    private static final int LATEST_TESTED_VERSION = 3;
+    private static final int LATEST_TESTED_VERSION = 4;
     public static final String PERMISSIONS_TAG = "admin-can-grant-sensors-permissions";
     public static final String DEVICE_OWNER_XML = "device_owner_2.xml";
     private ComponentName mFakeAdmin;
 
     private class FakePolicyUpgraderDataProvider implements PolicyUpgraderDataProvider {
         Map<ComponentName, DeviceAdminInfo> mComponentToDeviceAdminInfo = new HashMap<>();
+        ArrayList<String> mPlatformSuspendedPackages = new ArrayList<>();
         int[] mUsers;
 
         private JournaledFile makeJournaledFile(int userId, String fileName) {
@@ -98,6 +112,11 @@
         public int[] getUsersForUpgrade() {
             return mUsers;
         }
+
+        @Override
+        public List<String> getPlatformSuspendedPackages(int userId) {
+            return mPlatformSuspendedPackages;
+        }
     }
 
     private final Context mRealTestContext = InstrumentationRegistry.getTargetContext();
@@ -257,10 +276,71 @@
     }
 
     @Test
+    public void testAdminPackageSuspensionSaved() throws Exception {
+        final int ownerUser = 0;
+        mProvider.mUsers = new int[]{ownerUser};
+        getServices().addUser(ownerUser, FLAG_PRIMARY, USER_TYPE_FULL_SYSTEM);
+        setUpPackageManagerForAdmin(admin1, UserHandle.getUid(ownerUser, 123 /* admin app ID */));
+        writeVersionToXml(3);
+        preparePoliciesFile(ownerUser, "device_policies.xml");
+        prepareDeviceOwnerFile(ownerUser, "device_owner_2.xml");
+
+        // Pretend package manager thinks these packages are suspended by the platform.
+        Set<String> suspendedPkgs = Set.of("com.some.app", "foo.bar.baz");
+        mProvider.mPlatformSuspendedPackages.addAll(suspendedPkgs);
+
+        mUpgrader.upgradePolicy(4);
+
+        assertThat(readVersionFromXml()).isAtLeast(4);
+
+        assertAdminSuspendedPackages(ownerUser, suspendedPkgs);
+    }
+
+    private void assertAdminSuspendedPackages(int ownerUser, Set<String> suspendedPkgs)
+            throws Exception {
+        Document policies = readPolicies(ownerUser);
+        Element adminElem =
+                (Element) policies.getDocumentElement().getElementsByTagName("admin").item(0);
+        Element suspendedElem =
+                (Element) adminElem.getElementsByTagName("suspended-packages").item(0);
+        NodeList pkgsNodes = suspendedElem.getElementsByTagName("item");
+        Set<String> storedSuspendedPkgs = new ArraySet<>();
+        for (int i = 0; i < pkgsNodes.getLength(); i++) {
+            Element item = (Element) pkgsNodes.item(i);
+            storedSuspendedPkgs.add(item.getAttribute("value"));
+        }
+        assertThat(storedSuspendedPkgs).isEqualTo(suspendedPkgs);
+    }
+
+    @Test
     public void isLatestVersionTested() {
         assertThat(DevicePolicyManagerService.DPMS_VERSION).isEqualTo(LATEST_TESTED_VERSION);
     }
 
+    /**
+     * Reads ABX binary XML, converts it to text, and returns as an input stream.
+     */
+    private InputStream abxToXmlStream(File file) throws Exception {
+        FileInputStream fileIn = new FileInputStream(file);
+        XmlPullParser in = Xml.newBinaryPullParser();
+        in.setInput(fileIn, StandardCharsets.UTF_8.name());
+
+        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+        XmlSerializer out = Xml.newSerializer();
+        out.setOutput(byteOut, StandardCharsets.UTF_8.name());
+
+        Xml.copy(in, out);
+        out.flush();
+
+        return new ByteArrayInputStream(byteOut.toByteArray());
+    }
+
+    private Document readPolicies(int userId) throws Exception {
+        File policiesFile = mProvider.makeDevicePoliciesJournaledFile(userId).chooseForRead();
+        InputStream is = abxToXmlStream(policiesFile);
+        return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
+    }
+
     private void writeVersionToXml(int dpmsVersion) throws IOException {
         JournaledFile versionFile = mProvider.makePoliciesVersionJournaledFile(0);
         Files.asCharSink(versionFile.chooseForWrite(), Charset.defaultCharset()).write(
diff --git a/services/tests/servicestests/src/com/android/server/display/DisplayDeviceConfigTest.java b/services/tests/servicestests/src/com/android/server/display/DisplayDeviceConfigTest.java
index fdb78b8..c1eafd9 100644
--- a/services/tests/servicestests/src/com/android/server/display/DisplayDeviceConfigTest.java
+++ b/services/tests/servicestests/src/com/android/server/display/DisplayDeviceConfigTest.java
@@ -145,6 +145,16 @@
         assertArrayEquals(new float[]{23, 24, 25},
                 mDisplayDeviceConfig.getAmbientDarkeningPercentagesIdle(), ZERO_DELTA);
 
+        assertEquals(75, mDisplayDeviceConfig.getDefaultLowRefreshRate());
+        assertEquals(90, mDisplayDeviceConfig.getDefaultHighRefreshRate());
+        assertArrayEquals(new int[]{45, 55},
+                mDisplayDeviceConfig.getLowDisplayBrightnessThresholds());
+        assertArrayEquals(new int[]{50, 60},
+                mDisplayDeviceConfig.getLowAmbientBrightnessThresholds());
+        assertArrayEquals(new int[]{65, 75},
+                mDisplayDeviceConfig.getHighDisplayBrightnessThresholds());
+        assertArrayEquals(new int[]{70, 80},
+                mDisplayDeviceConfig.getHighAmbientBrightnessThresholds());
 
         // Todo(brup): Add asserts for BrightnessThrottlingData, DensityMapping,
         // HighBrightnessModeData AmbientLightSensor, RefreshRateLimitations and ProximitySensor.
@@ -207,8 +217,8 @@
                 mDisplayDeviceConfig.getAmbientDarkeningLevelsIdle(), ZERO_DELTA);
         assertArrayEquals(new float[]{29, 30, 31},
                 mDisplayDeviceConfig.getAmbientDarkeningPercentagesIdle(), ZERO_DELTA);
-        assertEquals(mDisplayDeviceConfig.getDefaultRefreshRate(), DEFAULT_REFRESH_RATE);
-        assertEquals(mDisplayDeviceConfig.getDefaultPeakRefreshRate(), DEFAULT_PEAK_REFRESH_RATE);
+        assertEquals(mDisplayDeviceConfig.getDefaultLowRefreshRate(), DEFAULT_REFRESH_RATE);
+        assertEquals(mDisplayDeviceConfig.getDefaultHighRefreshRate(), DEFAULT_PEAK_REFRESH_RATE);
         assertArrayEquals(mDisplayDeviceConfig.getLowDisplayBrightnessThresholds(),
                 LOW_BRIGHTNESS_THRESHOLD_OF_PEAK_REFRESH_RATE);
         assertArrayEquals(mDisplayDeviceConfig.getLowAmbientBrightnessThresholds(),
@@ -416,6 +426,38 @@
                 +           "</brightnessThrottlingPoint>\n"
                 +       "</brightnessThrottlingMap>\n"
                 +   "</thermalThrottling>\n"
+                +   "<refreshRate>\n"
+                +       "<lowerBlockingZoneConfigs>\n"
+                +           "<defaultRefreshRate>75</defaultRefreshRate>\n"
+                +           "<blockingZoneThreshold>\n"
+                +               "<displayBrightnessPoint>\n"
+                +                   "<lux>50</lux>\n"
+                // This number will be rounded to integer when read by the system
+                +                   "<nits>45.3</nits>\n"
+                +               "</displayBrightnessPoint>\n"
+                +               "<displayBrightnessPoint>\n"
+                +                   "<lux>60</lux>\n"
+                // This number will be rounded to integer when read by the system
+                +                   "<nits>55.2</nits>\n"
+                +               "</displayBrightnessPoint>\n"
+                +           "</blockingZoneThreshold>\n"
+                +       "</lowerBlockingZoneConfigs>\n"
+                +       "<higherBlockingZoneConfigs>\n"
+                +           "<defaultRefreshRate>90</defaultRefreshRate>\n"
+                +           "<blockingZoneThreshold>\n"
+                +               "<displayBrightnessPoint>\n"
+                +                   "<lux>70</lux>\n"
+                // This number will be rounded to integer when read by the system
+                +                   "<nits>65.6</nits>\n"
+                +               "</displayBrightnessPoint>\n"
+                +               "<displayBrightnessPoint>\n"
+                +                   "<lux>80</lux>\n"
+                // This number will be rounded to integer when read by the system
+                +                   "<nits>75</nits>\n"
+                +               "</displayBrightnessPoint>\n"
+                +           "</blockingZoneThreshold>\n"
+                +       "</higherBlockingZoneConfigs>\n"
+                +   "</refreshRate>\n"
                 + "</displayConfiguration>\n";
     }
 
diff --git a/services/tests/servicestests/src/com/android/server/display/DisplayManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/display/DisplayManagerServiceTest.java
index ca8e45a..f676a3f 100644
--- a/services/tests/servicestests/src/com/android/server/display/DisplayManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/display/DisplayManagerServiceTest.java
@@ -214,7 +214,7 @@
                 .thenReturn(mMockDisplayToken);
         SurfaceControl.StaticDisplayInfo staticDisplayInfo = new SurfaceControl.StaticDisplayInfo();
         staticDisplayInfo.isInternal = true;
-        when(mSurfaceControlProxy.getStaticDisplayInfo(mMockDisplayToken))
+        when(mSurfaceControlProxy.getStaticDisplayInfo(anyLong()))
                 .thenReturn(staticDisplayInfo);
         SurfaceControl.DynamicDisplayInfo dynamicDisplayMode =
                 new SurfaceControl.DynamicDisplayInfo();
@@ -223,7 +223,7 @@
         displayMode.height = 200;
         displayMode.supportedHdrTypes = new int[]{1, 2};
         dynamicDisplayMode.supportedDisplayModes = new SurfaceControl.DisplayMode[] {displayMode};
-        when(mSurfaceControlProxy.getDynamicDisplayInfo(mMockDisplayToken))
+        when(mSurfaceControlProxy.getDynamicDisplayInfo(anyLong()))
                 .thenReturn(dynamicDisplayMode);
         when(mSurfaceControlProxy.getDesiredDisplayModeSpecs(mMockDisplayToken))
                 .thenReturn(new SurfaceControl.DesiredDisplayModeSpecs());
diff --git a/services/tests/servicestests/src/com/android/server/display/DisplayModeDirectorTest.java b/services/tests/servicestests/src/com/android/server/display/DisplayModeDirectorTest.java
index 865bc98..bd4058a 100644
--- a/services/tests/servicestests/src/com/android/server/display/DisplayModeDirectorTest.java
+++ b/services/tests/servicestests/src/com/android/server/display/DisplayModeDirectorTest.java
@@ -2250,8 +2250,8 @@
 
         // Notify that the default display is updated, such that DisplayDeviceConfig has new values
         DisplayDeviceConfig displayDeviceConfig = mock(DisplayDeviceConfig.class);
-        when(displayDeviceConfig.getDefaultRefreshRate()).thenReturn(50);
-        when(displayDeviceConfig.getDefaultPeakRefreshRate()).thenReturn(55);
+        when(displayDeviceConfig.getDefaultLowRefreshRate()).thenReturn(50);
+        when(displayDeviceConfig.getDefaultHighRefreshRate()).thenReturn(55);
         when(displayDeviceConfig.getLowDisplayBrightnessThresholds()).thenReturn(new int[]{25});
         when(displayDeviceConfig.getLowAmbientBrightnessThresholds()).thenReturn(new int[]{30});
         when(displayDeviceConfig.getHighDisplayBrightnessThresholds()).thenReturn(new int[]{210});
diff --git a/services/tests/servicestests/src/com/android/server/display/LogicalDisplayMapperTest.java b/services/tests/servicestests/src/com/android/server/display/LogicalDisplayMapperTest.java
index c7caa43..c6a0b0f 100644
--- a/services/tests/servicestests/src/com/android/server/display/LogicalDisplayMapperTest.java
+++ b/services/tests/servicestests/src/com/android/server/display/LogicalDisplayMapperTest.java
@@ -18,10 +18,14 @@
 
 import static android.view.Display.DEFAULT_DISPLAY;
 import static android.view.Display.DEFAULT_DISPLAY_GROUP;
+import static android.view.Display.TYPE_INTERNAL;
+import static android.view.Display.TYPE_VIRTUAL;
 
+import static com.android.server.display.DeviceStateToLayoutMap.STATE_DEFAULT;
 import static com.android.server.display.DisplayAdapter.DISPLAY_DEVICE_EVENT_ADDED;
 import static com.android.server.display.DisplayAdapter.DISPLAY_DEVICE_EVENT_CHANGED;
 import static com.android.server.display.DisplayAdapter.DISPLAY_DEVICE_EVENT_REMOVED;
+import static com.android.server.display.DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY;
 import static com.android.server.display.LogicalDisplayMapper.LOGICAL_DISPLAY_EVENT_ADDED;
 import static com.android.server.display.LogicalDisplayMapper.LOGICAL_DISPLAY_EVENT_REMOVED;
 
@@ -69,7 +73,6 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Arrays;
-import java.util.Set;
 
 @SmallTest
 @RunWith(AndroidJUnit4.class)
@@ -155,8 +158,8 @@
 
     @Test
     public void testDisplayDeviceAddAndRemove_Internal() {
-        DisplayDevice device = createDisplayDevice(Display.TYPE_INTERNAL, 600, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
+        DisplayDevice device = createDisplayDevice(TYPE_INTERNAL, 600, 800,
+                FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
 
         // add
         LogicalDisplay displayAdded = add(device);
@@ -177,7 +180,7 @@
         testDisplayDeviceAddAndRemove_NonInternal(Display.TYPE_EXTERNAL);
         testDisplayDeviceAddAndRemove_NonInternal(Display.TYPE_WIFI);
         testDisplayDeviceAddAndRemove_NonInternal(Display.TYPE_OVERLAY);
-        testDisplayDeviceAddAndRemove_NonInternal(Display.TYPE_VIRTUAL);
+        testDisplayDeviceAddAndRemove_NonInternal(TYPE_VIRTUAL);
         testDisplayDeviceAddAndRemove_NonInternal(Display.TYPE_UNKNOWN);
 
         // Call the internal test again, just to verify that adding non-internal displays
@@ -187,9 +190,9 @@
 
     @Test
     public void testDisplayDeviceAdd_TwoInternalOneDefault() {
-        DisplayDevice device1 = createDisplayDevice(Display.TYPE_INTERNAL, 600, 800, 0);
-        DisplayDevice device2 = createDisplayDevice(Display.TYPE_INTERNAL, 600, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
+        DisplayDevice device1 = createDisplayDevice(TYPE_INTERNAL, 600, 800, 0);
+        DisplayDevice device2 = createDisplayDevice(TYPE_INTERNAL, 600, 800,
+                FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
 
         LogicalDisplay display1 = add(device1);
         assertEquals(info(display1).address, info(device1).address);
@@ -202,10 +205,10 @@
 
     @Test
     public void testDisplayDeviceAdd_TwoInternalBothDefault() {
-        DisplayDevice device1 = createDisplayDevice(Display.TYPE_INTERNAL, 600, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
-        DisplayDevice device2 = createDisplayDevice(Display.TYPE_INTERNAL, 600, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
+        DisplayDevice device1 = createDisplayDevice(TYPE_INTERNAL, 600, 800,
+                FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
+        DisplayDevice device2 = createDisplayDevice(TYPE_INTERNAL, 600, 800,
+                FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
 
         LogicalDisplay display1 = add(device1);
         assertEquals(info(display1).address, info(device1).address);
@@ -220,7 +223,7 @@
     @Test
     public void testDisplayDeviceAddAndRemove_OneExternalDefault() {
         DisplayDevice device = createDisplayDevice(Display.TYPE_EXTERNAL, 600, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
+                FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
 
         // add
         LogicalDisplay displayAdded = add(device);
@@ -238,10 +241,10 @@
 
     @Test
     public void testDisplayDeviceAddAndRemove_SwitchDefault() {
-        DisplayDevice device1 = createDisplayDevice(Display.TYPE_INTERNAL, 600, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
-        DisplayDevice device2 = createDisplayDevice(Display.TYPE_INTERNAL, 600, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
+        DisplayDevice device1 = createDisplayDevice(TYPE_INTERNAL, 600, 800,
+                FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
+        DisplayDevice device2 = createDisplayDevice(TYPE_INTERNAL, 600, 800,
+                FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
 
         LogicalDisplay display1 = add(device1);
         assertEquals(info(display1).address, info(device1).address);
@@ -267,10 +270,10 @@
 
     @Test
     public void testGetDisplayIdsLocked() {
-        add(createDisplayDevice(Display.TYPE_INTERNAL, 600, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY));
+        add(createDisplayDevice(TYPE_INTERNAL, 600, 800,
+                FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY));
         add(createDisplayDevice(Display.TYPE_EXTERNAL, 600, 800, 0));
-        add(createDisplayDevice(Display.TYPE_VIRTUAL, 600, 800, 0));
+        add(createDisplayDevice(TYPE_VIRTUAL, 600, 800, 0));
 
         int [] ids = mLogicalDisplayMapper.getDisplayIdsLocked(Process.SYSTEM_UID,
                 /* includeDisabled= */ true);
@@ -280,71 +283,98 @@
     }
 
     @Test
-    public void testGetDisplayInfoForStateLocked_oneDisplayGroup_internalType() {
-        add(createDisplayDevice(Display.TYPE_INTERNAL, 600, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY));
-        add(createDisplayDevice(Display.TYPE_INTERNAL, 200, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY));
-        add(createDisplayDevice(Display.TYPE_INTERNAL, 700, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY));
+    public void testGetDisplayInfoForStateLocked_defaultLayout() {
+        final DisplayDevice device1 = createDisplayDevice(TYPE_INTERNAL, 600, 800,
+                FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
+        final DisplayDevice device2 = createDisplayDevice(TYPE_INTERNAL, 200, 800,
+                FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
 
-        Set<DisplayInfo> displayInfos = mLogicalDisplayMapper.getDisplayInfoForStateLocked(
-                DeviceStateToLayoutMap.STATE_DEFAULT, DEFAULT_DISPLAY, DEFAULT_DISPLAY_GROUP);
-        assertThat(displayInfos.size()).isEqualTo(1);
-        for (DisplayInfo displayInfo : displayInfos) {
-            assertThat(displayInfo.displayId).isEqualTo(DEFAULT_DISPLAY);
-            assertThat(displayInfo.displayGroupId).isEqualTo(DEFAULT_DISPLAY_GROUP);
-            assertThat(displayInfo.logicalWidth).isEqualTo(600);
-            assertThat(displayInfo.logicalHeight).isEqualTo(800);
-        }
+        add(device1);
+        add(device2);
+
+        Layout layout1 = new Layout();
+        layout1.createDisplayLocked(info(device1).address, /* isDefault= */ true,
+                /* isEnabled= */ true, mIdProducer);
+        layout1.createDisplayLocked(info(device2).address, /* isDefault= */ false,
+                /* isEnabled= */ true, mIdProducer);
+        when(mDeviceStateToLayoutMapSpy.get(STATE_DEFAULT)).thenReturn(layout1);
+        assertThat(layout1.size()).isEqualTo(2);
+        final int logicalId2 = layout1.getByAddress(info(device2).address).getLogicalDisplayId();
+
+        final DisplayInfo displayInfoDefault = mLogicalDisplayMapper.getDisplayInfoForStateLocked(
+                STATE_DEFAULT, DEFAULT_DISPLAY);
+        assertThat(displayInfoDefault.displayId).isEqualTo(DEFAULT_DISPLAY);
+        assertThat(displayInfoDefault.logicalWidth).isEqualTo(width(device1));
+        assertThat(displayInfoDefault.logicalHeight).isEqualTo(height(device1));
+
+        final DisplayInfo displayInfoOther = mLogicalDisplayMapper.getDisplayInfoForStateLocked(
+                STATE_DEFAULT, logicalId2);
+        assertThat(displayInfoOther).isNotNull();
+        assertThat(displayInfoOther.displayId).isEqualTo(logicalId2);
+        assertThat(displayInfoOther.logicalWidth).isEqualTo(width(device2));
+        assertThat(displayInfoOther.logicalHeight).isEqualTo(height(device2));
     }
 
     @Test
-    public void testGetDisplayInfoForStateLocked_oneDisplayGroup_differentTypes() {
-        add(createDisplayDevice(Display.TYPE_INTERNAL, 600, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY));
-        add(createDisplayDevice(Display.TYPE_INTERNAL, 200, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY));
-        add(createDisplayDevice(Display.TYPE_EXTERNAL, 700, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY));
+    public void testGetDisplayInfoForStateLocked_multipleLayouts() {
+        final DisplayDevice device1 = createDisplayDevice(TYPE_INTERNAL, 600, 800,
+                FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
+        final DisplayDevice device2 = createDisplayDevice(TYPE_INTERNAL, 200, 800,
+                FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
+        final DisplayDevice device3 = createDisplayDevice(TYPE_VIRTUAL, 700, 800,
+                DisplayDeviceInfo.FLAG_OWN_DISPLAY_GROUP);
 
-        Set<DisplayInfo> displayInfos = mLogicalDisplayMapper.getDisplayInfoForStateLocked(
-                DeviceStateToLayoutMap.STATE_DEFAULT, DEFAULT_DISPLAY, DEFAULT_DISPLAY_GROUP);
-        assertThat(displayInfos.size()).isEqualTo(1);
-        for (DisplayInfo displayInfo : displayInfos) {
-            assertThat(displayInfo.displayId).isEqualTo(DEFAULT_DISPLAY);
-            assertThat(displayInfo.displayGroupId).isEqualTo(DEFAULT_DISPLAY_GROUP);
-            assertThat(displayInfo.logicalWidth).isEqualTo(600);
-            assertThat(displayInfo.logicalHeight).isEqualTo(800);
-        }
-    }
+        add(device1);
+        add(device2);
+        add(device3);
 
-    @Test
-    public void testGetDisplayInfoForStateLocked_multipleDisplayGroups_defaultGroup() {
-        add(createDisplayDevice(Display.TYPE_INTERNAL, 600, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY));
-        add(createDisplayDevice(Display.TYPE_INTERNAL, 200, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY));
-        add(createDisplayDevice(Display.TYPE_VIRTUAL, 700, 800,
-                DisplayDeviceInfo.FLAG_OWN_DISPLAY_GROUP));
+        Layout layout1 = new Layout();
+        layout1.createDisplayLocked(info(device1).address,
+                /* isDefault= */ true, /* isEnabled= */ true, mIdProducer);
+        when(mDeviceStateToLayoutMapSpy.get(STATE_DEFAULT)).thenReturn(layout1);
 
-        Set<DisplayInfo> displayInfos = mLogicalDisplayMapper.getDisplayInfoForStateLocked(
-                DeviceStateToLayoutMap.STATE_DEFAULT, DEFAULT_DISPLAY, DEFAULT_DISPLAY_GROUP);
-        assertThat(displayInfos.size()).isEqualTo(1);
-        for (DisplayInfo displayInfo : displayInfos) {
-            assertThat(displayInfo.displayId).isEqualTo(DEFAULT_DISPLAY);
-            assertThat(displayInfo.displayGroupId).isEqualTo(DEFAULT_DISPLAY_GROUP);
-            assertThat(displayInfo.logicalWidth).isEqualTo(600);
-            assertThat(displayInfo.logicalHeight).isEqualTo(800);
-        }
+        final int layoutState2 = 2;
+        Layout layout2 = new Layout();
+        layout2.createDisplayLocked(info(device2).address,
+                /* isDefault= */ false, /* isEnabled= */ true, mIdProducer);
+        // Device3 is the default display.
+        layout2.createDisplayLocked(info(device3).address,
+                /* isDefault= */ true, /* isEnabled= */ true, mIdProducer);
+        when(mDeviceStateToLayoutMapSpy.get(layoutState2)).thenReturn(layout2);
+        assertThat(layout2.size()).isEqualTo(2);
+        final int logicalId2 = layout2.getByAddress(info(device2).address).getLogicalDisplayId();
+
+        // Default layout.
+        final DisplayInfo displayInfoLayout1Default =
+                mLogicalDisplayMapper.getDisplayInfoForStateLocked(
+                        STATE_DEFAULT, DEFAULT_DISPLAY);
+        assertThat(displayInfoLayout1Default.displayId).isEqualTo(DEFAULT_DISPLAY);
+        assertThat(displayInfoLayout1Default.logicalWidth).isEqualTo(width(device1));
+        assertThat(displayInfoLayout1Default.logicalHeight).isEqualTo(height(device1));
+
+        // Second layout, where device3 is the default display.
+        final DisplayInfo displayInfoLayout2Default =
+                mLogicalDisplayMapper.getDisplayInfoForStateLocked(
+                        layoutState2, DEFAULT_DISPLAY);
+        assertThat(displayInfoLayout2Default.displayId).isEqualTo(DEFAULT_DISPLAY);
+        assertThat(displayInfoLayout2Default.logicalWidth).isEqualTo(width(device3));
+        assertThat(displayInfoLayout2Default.logicalHeight).isEqualTo(height(device3));
+
+        final DisplayInfo displayInfoLayout2Other =
+                mLogicalDisplayMapper.getDisplayInfoForStateLocked(
+                        layoutState2, logicalId2);
+        assertThat(displayInfoLayout2Other).isNotNull();
+        assertThat(displayInfoLayout2Other.displayId).isEqualTo(logicalId2);
+        assertThat(displayInfoLayout2Other.logicalWidth).isEqualTo(width(device2));
+        assertThat(displayInfoLayout2Other.logicalHeight).isEqualTo(height(device2));
     }
 
     @Test
     public void testSingleDisplayGroup() {
-        LogicalDisplay display1 = add(createDisplayDevice(Display.TYPE_INTERNAL, 600, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY));
-        LogicalDisplay display2 = add(createDisplayDevice(Display.TYPE_INTERNAL, 600, 800, 0));
-        LogicalDisplay display3 = add(createDisplayDevice(Display.TYPE_VIRTUAL, 600, 800, 0));
+        LogicalDisplay display1 = add(createDisplayDevice(TYPE_INTERNAL, 600, 800,
+                FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY));
+        LogicalDisplay display2 = add(createDisplayDevice(TYPE_INTERNAL, 600, 800, 0));
+        LogicalDisplay display3 = add(createDisplayDevice(TYPE_VIRTUAL, 600, 800, 0));
 
         assertEquals(DEFAULT_DISPLAY_GROUP,
                 mLogicalDisplayMapper.getDisplayGroupIdFromDisplayIdLocked(id(display1)));
@@ -356,12 +386,12 @@
 
     @Test
     public void testMultipleDisplayGroups() {
-        LogicalDisplay display1 = add(createDisplayDevice(Display.TYPE_INTERNAL, 600, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY));
-        LogicalDisplay display2 = add(createDisplayDevice(Display.TYPE_INTERNAL, 600, 800, 0));
+        LogicalDisplay display1 = add(createDisplayDevice(TYPE_INTERNAL, 600, 800,
+                FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY));
+        LogicalDisplay display2 = add(createDisplayDevice(TYPE_INTERNAL, 600, 800, 0));
 
 
-        TestDisplayDevice device3 = createDisplayDevice(Display.TYPE_VIRTUAL, 600, 800,
+        TestDisplayDevice device3 = createDisplayDevice(TYPE_VIRTUAL, 600, 800,
                 DisplayDeviceInfo.FLAG_OWN_DISPLAY_GROUP);
         LogicalDisplay display3 = add(device3);
 
@@ -519,10 +549,10 @@
 
     @Test
     public void testDeviceStateLocked() {
-        DisplayDevice device1 = createDisplayDevice(Display.TYPE_INTERNAL, 600, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
-        DisplayDevice device2 = createDisplayDevice(Display.TYPE_INTERNAL, 600, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
+        DisplayDevice device1 = createDisplayDevice(TYPE_INTERNAL, 600, 800,
+                FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
+        DisplayDevice device2 = createDisplayDevice(TYPE_INTERNAL, 600, 800,
+                FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
 
         Layout layout = new Layout();
         layout.createDisplayLocked(device1.getDisplayDeviceInfoLocked().address,
@@ -577,14 +607,11 @@
         DisplayAddress displayAddressThree = new TestUtils.TestDisplayAddress();
 
         TestDisplayDevice device1 = createDisplayDevice(displayAddressOne, "one",
-                Display.TYPE_INTERNAL, 600, 800,
-                DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
+                TYPE_INTERNAL, 600, 800, DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY);
         TestDisplayDevice device2 = createDisplayDevice(displayAddressTwo, "two",
-                Display.TYPE_INTERNAL, 200, 800,
-                DisplayDeviceInfo.FLAG_OWN_DISPLAY_GROUP);
+                TYPE_INTERNAL, 200, 800, DisplayDeviceInfo.FLAG_OWN_DISPLAY_GROUP);
         TestDisplayDevice device3 = createDisplayDevice(displayAddressThree, "three",
-                Display.TYPE_INTERNAL, 600, 900,
-                DisplayDeviceInfo.FLAG_OWN_DISPLAY_GROUP);
+                TYPE_INTERNAL, 600, 900, DisplayDeviceInfo.FLAG_OWN_DISPLAY_GROUP);
 
         Layout threeDevicesEnabledLayout = new Layout();
         threeDevicesEnabledLayout.createDisplayLocked(
@@ -603,7 +630,7 @@
                 /* isEnabled= */ true,
                 mIdProducer);
 
-        when(mDeviceStateToLayoutMapSpy.get(DeviceStateToLayoutMap.STATE_DEFAULT))
+        when(mDeviceStateToLayoutMapSpy.get(STATE_DEFAULT))
                 .thenReturn(threeDevicesEnabledLayout);
 
         LogicalDisplay display1 = add(device1);
@@ -735,6 +762,14 @@
         return device.getDisplayDeviceInfoLocked();
     }
 
+    private int width(DisplayDevice device) {
+        return info(device).width;
+    }
+
+    private int height(DisplayDevice device) {
+        return info(device).height;
+    }
+
     private DisplayInfo info(LogicalDisplay display) {
         return display.getDisplayInfoLocked();
     }
diff --git a/services/tests/servicestests/src/com/android/server/graphics/fonts/UpdatableFontDirTest.java b/services/tests/servicestests/src/com/android/server/graphics/fonts/UpdatableFontDirTest.java
index 9672085..68e5ebf 100644
--- a/services/tests/servicestests/src/com/android/server/graphics/fonts/UpdatableFontDirTest.java
+++ b/services/tests/servicestests/src/com/android/server/graphics/fonts/UpdatableFontDirTest.java
@@ -109,17 +109,16 @@
 
         @Override
         public boolean isFromTrustedProvider(String path, byte[] signature) {
-            return mHasFsverityPaths.contains(path);
+            if (!mHasFsverityPaths.contains(path)) {
+                return false;
+            }
+            String fakeSignature = new String(signature, StandardCharsets.UTF_8);
+            return GOOD_SIGNATURE.equals(fakeSignature);
         }
 
         @Override
-        public void setUpFsverity(String path, byte[] pkcs7Signature) throws IOException {
-            String fakeSignature = new String(pkcs7Signature, StandardCharsets.UTF_8);
-            if (GOOD_SIGNATURE.equals(fakeSignature)) {
-                mHasFsverityPaths.add(path);
-            } else {
-                throw new IOException("Failed to set up fake fs-verity");
-            }
+        public void setUpFsverity(String path) throws IOException {
+            mHasFsverityPaths.add(path);
         }
 
         @Override
@@ -813,8 +812,8 @@
             }
 
             @Override
-            public void setUpFsverity(String path, byte[] pkcs7Signature) throws IOException {
-                mFakeFsverityUtil.setUpFsverity(path, pkcs7Signature);
+            public void setUpFsverity(String path) throws IOException {
+                mFakeFsverityUtil.setUpFsverity(path);
             }
 
             @Override
diff --git a/services/tests/servicestests/src/com/android/server/input/InputManagerServiceTests.kt b/services/tests/servicestests/src/com/android/server/input/InputManagerServiceTests.kt
index e390bcc..3326f80f 100644
--- a/services/tests/servicestests/src/com/android/server/input/InputManagerServiceTests.kt
+++ b/services/tests/servicestests/src/com/android/server/input/InputManagerServiceTests.kt
@@ -16,6 +16,7 @@
 
 package com.android.server.input
 
+
 import android.content.Context
 import android.content.ContextWrapper
 import android.hardware.display.DisplayViewport
@@ -25,6 +26,7 @@
 import android.view.Display
 import android.view.PointerIcon
 import androidx.test.InstrumentationRegistry
+import com.google.common.truth.Truth.assertThat
 import java.util.concurrent.CountDownLatch
 import java.util.concurrent.TimeUnit
 import org.junit.Assert.assertFalse
@@ -287,6 +289,28 @@
         verify(native).setPointerAcceleration(eq(5f))
     }
 
+    @Test
+    fun setDeviceTypeAssociation_setsDeviceTypeAssociation() {
+        val inputPort = "inputPort"
+        val type = "type"
+
+        localService.setTypeAssociation(inputPort, type)
+
+        assertThat(service.getDeviceTypeAssociations()).asList().containsExactly(inputPort, type)
+            .inOrder()
+    }
+
+    @Test
+    fun setAndUnsetDeviceTypeAssociation_deviceTypeAssociationIsMissing() {
+        val inputPort = "inputPort"
+        val type = "type"
+
+        localService.setTypeAssociation(inputPort, type)
+        localService.unsetTypeAssociation(inputPort)
+
+        assertTrue(service.getDeviceTypeAssociations().isEmpty())
+    }
+
     private fun setVirtualMousePointerDisplayIdAndVerify(overrideDisplayId: Int) {
         val thread = Thread { localService.setVirtualMousePointerDisplayId(overrideDisplayId) }
         thread.start()
diff --git a/services/tests/servicestests/src/com/android/server/input/KeyRemapperTests.kt b/services/tests/servicestests/src/com/android/server/input/KeyRemapperTests.kt
new file mode 100644
index 0000000..c22782c
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/input/KeyRemapperTests.kt
@@ -0,0 +1,150 @@
+/*
+ * 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.server.input
+
+import android.content.Context
+import android.content.ContextWrapper
+import android.hardware.input.IInputManager
+import android.hardware.input.InputManager
+import android.os.test.TestLooper
+import android.platform.test.annotations.Presubmit
+import android.view.InputDevice
+import android.view.KeyEvent
+import androidx.test.core.app.ApplicationProvider
+import org.junit.After
+import org.junit.Assert.assertEquals
+import org.junit.Before
+import org.junit.Rule
+import org.junit.Test
+import org.mockito.Mock
+import org.mockito.Mockito
+import org.mockito.junit.MockitoJUnit
+import java.io.FileNotFoundException
+import java.io.FileOutputStream
+import java.io.IOException
+import java.io.InputStream
+
+private fun createKeyboard(deviceId: Int): InputDevice =
+    InputDevice.Builder()
+        .setId(deviceId)
+        .setName("Device $deviceId")
+        .setDescriptor("descriptor $deviceId")
+        .setSources(InputDevice.SOURCE_KEYBOARD)
+        .setKeyboardType(InputDevice.KEYBOARD_TYPE_ALPHABETIC)
+        .setExternal(true)
+        .build()
+
+/**
+ * Tests for {@link KeyRemapper}.
+ *
+ * Build/Install/Run:
+ * atest FrameworksServicesTests:KeyRemapperTests
+ */
+@Presubmit
+class KeyRemapperTests {
+
+    companion object {
+        const val DEVICE_ID = 1
+        val REMAPPABLE_KEYS = intArrayOf(
+            KeyEvent.KEYCODE_CTRL_LEFT, KeyEvent.KEYCODE_CTRL_RIGHT,
+            KeyEvent.KEYCODE_META_LEFT, KeyEvent.KEYCODE_META_RIGHT,
+            KeyEvent.KEYCODE_ALT_LEFT, KeyEvent.KEYCODE_ALT_RIGHT,
+            KeyEvent.KEYCODE_SHIFT_LEFT, KeyEvent.KEYCODE_SHIFT_RIGHT,
+            KeyEvent.KEYCODE_CAPS_LOCK
+        )
+    }
+
+    @get:Rule
+    val rule = MockitoJUnit.rule()!!
+
+    @Mock
+    private lateinit var iInputManager: IInputManager
+    @Mock
+    private lateinit var native: NativeInputManagerService
+    private lateinit var mKeyRemapper: KeyRemapper
+    private lateinit var context: Context
+    private lateinit var dataStore: PersistentDataStore
+    private lateinit var testLooper: TestLooper
+
+    @Before
+    fun setup() {
+        context = Mockito.spy(ContextWrapper(ApplicationProvider.getApplicationContext()))
+        dataStore = PersistentDataStore(object : PersistentDataStore.Injector() {
+            override fun openRead(): InputStream? {
+                throw FileNotFoundException()
+            }
+
+            override fun startWrite(): FileOutputStream? {
+                throw IOException()
+            }
+
+            override fun finishWrite(fos: FileOutputStream?, success: Boolean) {}
+        })
+        testLooper = TestLooper()
+        mKeyRemapper = KeyRemapper(
+            context,
+            native,
+            dataStore,
+            testLooper.looper
+        )
+        val inputManager = InputManager.resetInstance(iInputManager)
+        Mockito.`when`(context.getSystemService(Mockito.eq(Context.INPUT_SERVICE)))
+            .thenReturn(inputManager)
+        Mockito.`when`(iInputManager.inputDeviceIds).thenReturn(intArrayOf(DEVICE_ID))
+    }
+
+    @After
+    fun tearDown() {
+        InputManager.clearInstance()
+    }
+
+    @Test
+    fun testKeyRemapping() {
+        val keyboard = createKeyboard(DEVICE_ID)
+        Mockito.`when`(iInputManager.getInputDevice(DEVICE_ID)).thenReturn(keyboard)
+
+        for (i in REMAPPABLE_KEYS.indices) {
+            val fromKeyCode = REMAPPABLE_KEYS[i]
+            val toKeyCode = REMAPPABLE_KEYS[(i + 1) % REMAPPABLE_KEYS.size]
+            mKeyRemapper.remapKey(fromKeyCode, toKeyCode)
+            testLooper.dispatchNext()
+        }
+
+        val remapping = mKeyRemapper.keyRemapping
+        val expectedSize = REMAPPABLE_KEYS.size
+        assertEquals("Remapping size should be $expectedSize", expectedSize, remapping.size)
+
+        for (i in REMAPPABLE_KEYS.indices) {
+            val fromKeyCode = REMAPPABLE_KEYS[i]
+            val toKeyCode = REMAPPABLE_KEYS[(i + 1) % REMAPPABLE_KEYS.size]
+            assertEquals(
+                "Remapping should include mapping from $fromKeyCode to $toKeyCode",
+                toKeyCode,
+                remapping.getOrDefault(fromKeyCode, -1)
+            )
+        }
+
+        mKeyRemapper.clearAllKeyRemappings()
+        testLooper.dispatchNext()
+
+        assertEquals(
+            "Remapping size should be 0 after clearAllModifierKeyRemappings",
+            0,
+            mKeyRemapper.keyRemapping.size
+        )
+    }
+}
\ No newline at end of file
diff --git a/services/tests/servicestests/src/com/android/server/inputmethod/InputMethodUtilsTest.java b/services/tests/servicestests/src/com/android/server/inputmethod/InputMethodUtilsTest.java
index 426b943..4b318de 100644
--- a/services/tests/servicestests/src/com/android/server/inputmethod/InputMethodUtilsTest.java
+++ b/services/tests/servicestests/src/com/android/server/inputmethod/InputMethodUtilsTest.java
@@ -25,8 +25,16 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
+import android.content.ContentResolver;
 import android.content.Context;
+import android.content.ContextWrapper;
+import android.content.IContentProvider;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.ResolveInfo;
 import android.content.pm.ServiceInfo;
@@ -35,6 +43,9 @@
 import android.os.Build;
 import android.os.LocaleList;
 import android.os.Parcel;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.test.mock.MockContentResolver;
 import android.text.TextUtils;
 import android.util.ArrayMap;
 import android.util.IntArray;
@@ -1214,6 +1225,42 @@
                 StartInputFlags.VIEW_HAS_FOCUS | StartInputFlags.IS_TEXT_EDITOR));
     }
 
+    @Test
+    public void testInputMethodSettings_SwitchCurrentUser() {
+        TestContext ownerUserContext = createMockContext(0 /* userId */);
+        final InputMethodInfo systemIme = createFakeInputMethodInfo(
+                "SystemIme", "fake.latin", true /* isSystem */);
+        final InputMethodInfo nonSystemIme = createFakeInputMethodInfo("NonSystemIme",
+                "fake.voice0", false /* isSystem */);
+        final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>();
+        methodMap.put(systemIme.getId(), systemIme);
+
+        // Init InputMethodSettings for the owner user (userId=0), verify calls can get the
+        // corresponding user's context, contentResolver and the resources configuration.
+        InputMethodUtils.InputMethodSettings settings = new InputMethodUtils.InputMethodSettings(
+                ownerUserContext, methodMap, 0 /* userId */, true);
+        assertEquals(0, settings.getCurrentUserId());
+
+        settings.isShowImeWithHardKeyboardEnabled();
+        verify(ownerUserContext.getContentResolver(), atLeastOnce()).getAttributionSource();
+
+        settings.getEnabledInputMethodSubtypeListLocked(nonSystemIme, true);
+        verify(ownerUserContext.getResources(), atLeastOnce()).getConfiguration();
+
+        // Calling switchCurrentUser to the secondary user (userId=10), verify calls can get the
+        // corresponding user's context, contentResolver and the resources configuration.
+        settings.switchCurrentUser(10 /* userId */, true);
+        assertEquals(10, settings.getCurrentUserId());
+
+        settings.isShowImeWithHardKeyboardEnabled();
+        verify(TestContext.getSecondaryUserContext().getContentResolver(),
+                atLeastOnce()).getAttributionSource();
+
+        settings.getEnabledInputMethodSubtypeListLocked(nonSystemIme, true);
+        verify(TestContext.getSecondaryUserContext().getResources(),
+                atLeastOnce()).getConfiguration();
+    }
+
     private static IntArray createSubtypeHashCodeArrayFromStr(String subtypeHashCodesStr) {
         final IntArray subtypes = new IntArray();
         final TextUtils.SimpleStringSplitter imeSubtypeSplitter =
@@ -1236,6 +1283,63 @@
                         imeId, createSubtypeHashCodeArrayFromStr(enabledSubtypeHashCodesStr)));
     }
 
+    private static TestContext createMockContext(int userId) {
+        return new TestContext(InstrumentationRegistry.getInstrumentation()
+                .getTargetContext(), userId);
+    }
+
+    private static class TestContext extends ContextWrapper {
+        private int mUserId;
+        private ContentResolver mResolver;
+        private Resources mResources;
+
+        private static TestContext sSecondaryUserContext;
+
+        TestContext(@NonNull Context context, int userId) {
+            super(context);
+            mUserId = userId;
+            mResolver = mock(MockContentResolver.class);
+            when(mResolver.acquireProvider(Settings.Secure.CONTENT_URI)).thenReturn(
+                    mock(IContentProvider.class));
+            mResources = mock(Resources.class);
+
+            final Configuration configuration = new Configuration();
+            if (userId == 0) {
+                configuration.setLocale(LOCALE_EN_US);
+            } else {
+                configuration.setLocale(LOCALE_FR_CA);
+            }
+            doReturn(configuration).when(mResources).getConfiguration();
+        }
+
+        @Override
+        public Context createContextAsUser(UserHandle user, int flags) {
+            if (user.getIdentifier() != UserHandle.USER_SYSTEM) {
+                return sSecondaryUserContext = new TestContext(this, user.getIdentifier());
+            }
+            return this;
+        }
+
+        @Override
+        public int getUserId() {
+            return mUserId;
+        }
+
+        @Override
+        public ContentResolver getContentResolver() {
+            return mResolver;
+        }
+
+        @Override
+        public Resources getResources() {
+            return mResources;
+        }
+
+        static Context getSecondaryUserContext() {
+            return sSecondaryUserContext;
+        }
+    }
+
     @Test
     public void updateEnabledImeStringTest() {
         // No change cases
diff --git a/services/tests/servicestests/src/com/android/server/locksettings/BaseLockSettingsServiceTests.java b/services/tests/servicestests/src/com/android/server/locksettings/BaseLockSettingsServiceTests.java
index 55ab4a0..5ca695b 100644
--- a/services/tests/servicestests/src/com/android/server/locksettings/BaseLockSettingsServiceTests.java
+++ b/services/tests/servicestests/src/com/android/server/locksettings/BaseLockSettingsServiceTests.java
@@ -16,6 +16,9 @@
 
 package com.android.server.locksettings;
 
+import static android.app.admin.DevicePolicyManager.DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_FLAG;
+import static android.provider.DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER;
+
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
@@ -36,7 +39,7 @@
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.content.pm.UserInfo;
-import android.hardware.authsecret.V1_0.IAuthSecret;
+import android.hardware.authsecret.IAuthSecret;
 import android.hardware.face.FaceManager;
 import android.hardware.fingerprint.FingerprintManager;
 import android.os.FileUtils;
@@ -47,6 +50,7 @@
 import android.os.storage.IStorageManager;
 import android.os.storage.StorageManager;
 import android.provider.Settings;
+import android.provider.DeviceConfig;
 import android.security.KeyStore;
 
 import androidx.test.InstrumentationRegistry;
@@ -81,7 +85,8 @@
     protected static final int SECONDARY_USER_ID = 20;
 
     private static final UserInfo PRIMARY_USER_INFO = new UserInfo(PRIMARY_USER_ID, null, null,
-            UserInfo.FLAG_INITIALIZED | UserInfo.FLAG_ADMIN | UserInfo.FLAG_PRIMARY);
+            UserInfo.FLAG_INITIALIZED | UserInfo.FLAG_ADMIN | UserInfo.FLAG_PRIMARY
+                    | UserInfo.FLAG_MAIN);
     private static final UserInfo SECONDARY_USER_INFO = new UserInfo(SECONDARY_USER_ID, null, null,
             UserInfo.FLAG_INITIALIZED);
 
@@ -188,7 +193,11 @@
         // Adding a fake Device Owner app which will enable escrow token support in LSS.
         when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(
                 new ComponentName("com.dummy.package", ".FakeDeviceOwner"));
+        // TODO(b/258213147): Remove
+        DeviceConfig.setProperty(NAMESPACE_DEVICE_POLICY_MANAGER,
+                DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_FLAG, "true", /* makeDefault= */ false);
         when(mUserManagerInternal.isDeviceManaged()).thenReturn(true);
+        when(mDeviceStateCache.isUserOrganizationManaged(anyInt())).thenReturn(true);
         when(mDeviceStateCache.isDeviceProvisioned()).thenReturn(true);
         mockBiometricsHardwareFingerprintsAndTemplates(PRIMARY_USER_ID);
         mockBiometricsHardwareFingerprintsAndTemplates(MANAGED_PROFILE_USER_ID);
@@ -221,7 +230,10 @@
         when(mUserManager.getProfileParent(eq(profileId))).thenReturn(PRIMARY_USER_INFO);
         when(mUserManager.isUserRunning(eq(profileId))).thenReturn(true);
         when(mUserManager.isUserUnlocked(eq(profileId))).thenReturn(true);
+        // TODO(b/258213147): Remove
         when(mUserManagerInternal.isUserManaged(eq(profileId))).thenReturn(true);
+        when(mDeviceStateCache.isUserOrganizationManaged(eq(profileId)))
+                .thenReturn(true);
         return userInfo;
     }
 
diff --git a/services/tests/servicestests/src/com/android/server/locksettings/LockSettingsServiceTestable.java b/services/tests/servicestests/src/com/android/server/locksettings/LockSettingsServiceTestable.java
index eccfa06..d3b647d 100644
--- a/services/tests/servicestests/src/com/android/server/locksettings/LockSettingsServiceTestable.java
+++ b/services/tests/servicestests/src/com/android/server/locksettings/LockSettingsServiceTestable.java
@@ -22,7 +22,7 @@
 import android.app.admin.DeviceStateCache;
 import android.content.Context;
 import android.content.pm.UserInfo;
-import android.hardware.authsecret.V1_0.IAuthSecret;
+import android.hardware.authsecret.IAuthSecret;
 import android.os.Handler;
 import android.os.Parcel;
 import android.os.Process;
@@ -154,7 +154,7 @@
                 storageManager, spManager, gsiService, recoverableKeyStoreManager,
                 userManagerInternal, deviceStateCache));
         mGateKeeperService = gatekeeper;
-        mAuthSecretService = authSecretService;
+        mAuthSecretServiceAidl = authSecretService;
     }
 
     @Override
@@ -199,4 +199,4 @@
         UserInfo userInfo = mUserManager.getUserInfo(userId);
         return userInfo.isCloneProfile() || userInfo.isManagedProfile();
     }
-}
\ No newline at end of file
+}
diff --git a/services/tests/servicestests/src/com/android/server/locksettings/LockSettingsServiceTests.java b/services/tests/servicestests/src/com/android/server/locksettings/LockSettingsServiceTests.java
index 196226a..41e3a08 100644
--- a/services/tests/servicestests/src/com/android/server/locksettings/LockSettingsServiceTests.java
+++ b/services/tests/servicestests/src/com/android/server/locksettings/LockSettingsServiceTests.java
@@ -59,65 +59,65 @@
 @Presubmit
 @RunWith(AndroidJUnit4.class)
 public class LockSettingsServiceTests extends BaseLockSettingsServiceTests {
+
     @Before
-    public void disableProcessCaches() {
+    public void setUp() {
         PropertyInvalidatedCache.disableForTestMode();
+        mService.initializeSyntheticPassword(PRIMARY_USER_ID);
+        mService.initializeSyntheticPassword(MANAGED_PROFILE_USER_ID);
     }
 
     @Test
-    public void testCreatePasswordPrimaryUser() throws RemoteException {
-        testCreateCredential(PRIMARY_USER_ID, newPassword("password"));
+    public void testSetPasswordPrimaryUser() throws RemoteException {
+        setAndVerifyCredential(PRIMARY_USER_ID, newPassword("password"));
     }
 
     @Test
-    public void testCreatePasswordFailsWithoutLockScreen() throws RemoteException {
-        testCreateCredentialFailsWithoutLockScreen(PRIMARY_USER_ID, newPassword("password"));
+    public void testSetPasswordFailsWithoutLockScreen() throws RemoteException {
+        testSetCredentialFailsWithoutLockScreen(PRIMARY_USER_ID, newPassword("password"));
     }
 
     @Test
-    public void testCreatePatternPrimaryUser() throws RemoteException {
-        testCreateCredential(PRIMARY_USER_ID, newPattern("123456789"));
+    public void testSetPatternPrimaryUser() throws RemoteException {
+        setAndVerifyCredential(PRIMARY_USER_ID, newPattern("123456789"));
     }
 
     @Test
-    public void testCreatePatternFailsWithoutLockScreen() throws RemoteException {
-        testCreateCredentialFailsWithoutLockScreen(PRIMARY_USER_ID, newPattern("123456789"));
+    public void testSetPatternFailsWithoutLockScreen() throws RemoteException {
+        testSetCredentialFailsWithoutLockScreen(PRIMARY_USER_ID, newPattern("123456789"));
     }
 
     @Test
     public void testChangePasswordPrimaryUser() throws RemoteException {
-        testChangeCredentials(PRIMARY_USER_ID, newPattern("78963214"), newPassword("asdfghjk"));
+        testChangeCredential(PRIMARY_USER_ID, newPattern("78963214"), newPassword("asdfghjk"));
     }
 
     @Test
     public void testChangePatternPrimaryUser() throws RemoteException {
-        testChangeCredentials(PRIMARY_USER_ID, newPassword("!£$%^&*(())"), newPattern("1596321"));
+        testChangeCredential(PRIMARY_USER_ID, newPassword("!£$%^&*(())"), newPattern("1596321"));
     }
 
     @Test
     public void testChangePasswordFailPrimaryUser() throws RemoteException {
-        initializeStorageWithCredential(PRIMARY_USER_ID, newPassword("password"));
-
+        setCredential(PRIMARY_USER_ID, newPassword("password"));
         assertFalse(mService.setLockCredential(newPassword("newpwd"), newPassword("badpwd"),
                     PRIMARY_USER_ID));
-        assertVerifyCredentials(PRIMARY_USER_ID, newPassword("password"));
+        assertVerifyCredential(PRIMARY_USER_ID, newPassword("password"));
     }
 
     @Test
     public void testClearPasswordPrimaryUser() throws RemoteException {
-        initializeStorageWithCredential(PRIMARY_USER_ID, newPassword("password"));
-        assertTrue(mService.setLockCredential(nonePassword(), newPassword("password"),
-                PRIMARY_USER_ID));
-        assertEquals(CREDENTIAL_TYPE_NONE, mService.getCredentialType(PRIMARY_USER_ID));
-        assertEquals(0, mGateKeeperService.getSecureUserId(PRIMARY_USER_ID));
+        setCredential(PRIMARY_USER_ID, newPassword("password"));
+        clearCredential(PRIMARY_USER_ID, newPassword("password"));
     }
 
     @Test
     public void testManagedProfileUnifiedChallenge() throws RemoteException {
+        mService.initializeSyntheticPassword(TURNED_OFF_PROFILE_USER_ID);
+
         final LockscreenCredential firstUnifiedPassword = newPassword("pwd-1");
         final LockscreenCredential secondUnifiedPassword = newPassword("pwd-2");
-        assertTrue(mService.setLockCredential(firstUnifiedPassword,
-                nonePassword(), PRIMARY_USER_ID));
+        setCredential(PRIMARY_USER_ID, firstUnifiedPassword);
         mService.setSeparateProfileChallengeEnabled(MANAGED_PROFILE_USER_ID, false, null);
         final long primarySid = mGateKeeperService.getSecureUserId(PRIMARY_USER_ID);
         final long profileSid = mGateKeeperService.getSecureUserId(MANAGED_PROFILE_USER_ID);
@@ -146,14 +146,12 @@
         assertNull(mGateKeeperService.getAuthToken(TURNED_OFF_PROFILE_USER_ID));
 
         // Change primary password and verify that profile SID remains
-        assertTrue(mService.setLockCredential(
-                secondUnifiedPassword, firstUnifiedPassword, PRIMARY_USER_ID));
+        setCredential(PRIMARY_USER_ID, secondUnifiedPassword, firstUnifiedPassword);
         assertEquals(profileSid, mGateKeeperService.getSecureUserId(MANAGED_PROFILE_USER_ID));
         assertNull(mGateKeeperService.getAuthToken(TURNED_OFF_PROFILE_USER_ID));
 
         // Clear unified challenge
-        assertTrue(mService.setLockCredential(nonePassword(),
-                secondUnifiedPassword, PRIMARY_USER_ID));
+        clearCredential(PRIMARY_USER_ID, secondUnifiedPassword);
         assertEquals(0, mGateKeeperService.getSecureUserId(PRIMARY_USER_ID));
         assertEquals(0, mGateKeeperService.getSecureUserId(MANAGED_PROFILE_USER_ID));
         assertEquals(0, mGateKeeperService.getSecureUserId(TURNED_OFF_PROFILE_USER_ID));
@@ -163,12 +161,8 @@
     public void testManagedProfileSeparateChallenge() throws RemoteException {
         final LockscreenCredential primaryPassword = newPassword("primary");
         final LockscreenCredential profilePassword = newPassword("profile");
-        assertTrue(mService.setLockCredential(primaryPassword,
-                nonePassword(),
-                PRIMARY_USER_ID));
-        assertTrue(mService.setLockCredential(profilePassword,
-                nonePassword(),
-                MANAGED_PROFILE_USER_ID));
+        setCredential(PRIMARY_USER_ID, primaryPassword);
+        setCredential(MANAGED_PROFILE_USER_ID, profilePassword);
 
         final long primarySid = mGateKeeperService.getSecureUserId(PRIMARY_USER_ID);
         final long profileSid = mGateKeeperService.getSecureUserId(MANAGED_PROFILE_USER_ID);
@@ -191,8 +185,7 @@
         assertNotNull(mGateKeeperService.getAuthToken(MANAGED_PROFILE_USER_ID));
         assertEquals(profileSid, mGateKeeperService.getSecureUserId(MANAGED_PROFILE_USER_ID));
 
-        assertTrue(mService.setLockCredential(
-                newPassword("pwd"), primaryPassword, PRIMARY_USER_ID));
+        setCredential(PRIMARY_USER_ID, newPassword("pwd"), primaryPassword);
         assertEquals(VerifyCredentialResponse.RESPONSE_OK, mService.verifyCredential(
                 profilePassword, MANAGED_PROFILE_USER_ID, 0 /* flags */)
                 .getResponseCode());
@@ -207,8 +200,7 @@
         assertEquals(CREDENTIAL_TYPE_NONE, mService.getCredentialType(MANAGED_PROFILE_USER_ID));
 
         // Set a separate challenge on the profile
-        assertTrue(mService.setLockCredential(
-                newPassword("12345678"), nonePassword(), MANAGED_PROFILE_USER_ID));
+        setCredential(MANAGED_PROFILE_USER_ID, newPassword("12345678"));
         assertNotEquals(0, mGateKeeperService.getSecureUserId(MANAGED_PROFILE_USER_ID));
         assertEquals(CREDENTIAL_TYPE_PASSWORD, mService.getCredentialType(MANAGED_PROFILE_USER_ID));
 
@@ -221,11 +213,7 @@
 
     @Test
     public void testSetLockCredential_forPrimaryUser_sendsCredentials() throws Exception {
-        assertTrue(mService.setLockCredential(
-                newPassword("password"),
-                nonePassword(),
-                PRIMARY_USER_ID));
-
+        setCredential(PRIMARY_USER_ID, newPassword("password"));
         verify(mRecoverableKeyStoreManager)
                 .lockScreenSecretChanged(CREDENTIAL_TYPE_PASSWORD, "password".getBytes(),
                         PRIMARY_USER_ID);
@@ -234,11 +222,7 @@
     @Test
     public void testSetLockCredential_forProfileWithSeparateChallenge_sendsCredentials()
             throws Exception {
-        assertTrue(mService.setLockCredential(
-                newPattern("12345"),
-                nonePassword(),
-                MANAGED_PROFILE_USER_ID));
-
+        setCredential(MANAGED_PROFILE_USER_ID, newPattern("12345"));
         verify(mRecoverableKeyStoreManager)
                 .lockScreenSecretChanged(CREDENTIAL_TYPE_PATTERN, "12345".getBytes(),
                         MANAGED_PROFILE_USER_ID);
@@ -248,13 +232,8 @@
     public void testSetLockCredential_forProfileWithSeparateChallenge_updatesCredentials()
             throws Exception {
         mService.setSeparateProfileChallengeEnabled(MANAGED_PROFILE_USER_ID, true, null);
-        initializeStorageWithCredential(MANAGED_PROFILE_USER_ID, newPattern("12345"));
-
-        assertTrue(mService.setLockCredential(
-                newPassword("newPassword"),
-                newPattern("12345"),
-                MANAGED_PROFILE_USER_ID));
-
+        setCredential(MANAGED_PROFILE_USER_ID, newPattern("12345"));
+        setCredential(MANAGED_PROFILE_USER_ID, newPassword("newPassword"), newPattern("12345"));
         verify(mRecoverableKeyStoreManager)
                 .lockScreenSecretChanged(CREDENTIAL_TYPE_PASSWORD, "newPassword".getBytes(),
                         MANAGED_PROFILE_USER_ID);
@@ -264,12 +243,7 @@
     public void testSetLockCredential_forProfileWithUnifiedChallenge_doesNotSendRandomCredential()
             throws Exception {
         mService.setSeparateProfileChallengeEnabled(MANAGED_PROFILE_USER_ID, false, null);
-
-        assertTrue(mService.setLockCredential(
-                newPattern("12345"),
-                nonePassword(),
-                PRIMARY_USER_ID));
-
+        setCredential(PRIMARY_USER_ID, newPattern("12345"));
         verify(mRecoverableKeyStoreManager, never())
                 .lockScreenSecretChanged(
                         eq(CREDENTIAL_TYPE_PASSWORD), any(), eq(MANAGED_PROFILE_USER_ID));
@@ -281,13 +255,9 @@
                     throws Exception {
         final LockscreenCredential oldCredential = newPassword("oldPassword");
         final LockscreenCredential newCredential = newPassword("newPassword");
-        initializeStorageWithCredential(PRIMARY_USER_ID, oldCredential);
+        setCredential(PRIMARY_USER_ID, oldCredential);
         mService.setSeparateProfileChallengeEnabled(MANAGED_PROFILE_USER_ID, false, null);
-
-        assertTrue(mService.setLockCredential(
-                newCredential,
-                oldCredential,
-                PRIMARY_USER_ID));
+        setCredential(PRIMARY_USER_ID, newCredential, oldCredential);
 
         verify(mRecoverableKeyStoreManager)
                 .lockScreenSecretChanged(CREDENTIAL_TYPE_PASSWORD, newCredential.getCredential(),
@@ -301,13 +271,9 @@
     public void
             testSetLockCredential_forPrimaryUserWithUnifiedChallengeProfile_removesBothCredentials()
                     throws Exception {
-        initializeStorageWithCredential(PRIMARY_USER_ID, newPassword("oldPassword"));
+        setCredential(PRIMARY_USER_ID, newPassword("oldPassword"));
         mService.setSeparateProfileChallengeEnabled(MANAGED_PROFILE_USER_ID, false, null);
-
-        assertTrue(mService.setLockCredential(
-                nonePassword(),
-                newPassword("oldPassword"),
-                PRIMARY_USER_ID));
+        clearCredential(PRIMARY_USER_ID, newPassword("oldPassword"));
 
         verify(mRecoverableKeyStoreManager)
                 .lockScreenSecretChanged(CREDENTIAL_TYPE_NONE, null, PRIMARY_USER_ID);
@@ -316,11 +282,10 @@
     }
 
     @Test
-    public void testSetLockCredential_nullCredential_removeBiometrics() throws RemoteException {
-        initializeStorageWithCredential(PRIMARY_USER_ID, newPattern("123654"));
+    public void testClearLockCredential_removesBiometrics() throws RemoteException {
+        setCredential(PRIMARY_USER_ID, newPattern("123654"));
         mService.setSeparateProfileChallengeEnabled(MANAGED_PROFILE_USER_ID, false, null);
-
-        mService.setLockCredential(nonePassword(), newPattern("123654"), PRIMARY_USER_ID);
+        clearCredential(PRIMARY_USER_ID, newPattern("123654"));
 
         // Verify fingerprint is removed
         verify(mFingerprintManager).removeAll(eq(PRIMARY_USER_ID), any());
@@ -335,14 +300,9 @@
             throws Exception {
         final LockscreenCredential parentPassword = newPassword("parentPassword");
         final LockscreenCredential profilePassword = newPassword("profilePassword");
-        initializeStorageWithCredential(PRIMARY_USER_ID, parentPassword);
+        setCredential(PRIMARY_USER_ID, parentPassword);
         mService.setSeparateProfileChallengeEnabled(MANAGED_PROFILE_USER_ID, false, null);
-
-        assertTrue(mService.setLockCredential(
-                profilePassword,
-                nonePassword(),
-                MANAGED_PROFILE_USER_ID));
-
+        setCredential(MANAGED_PROFILE_USER_ID, profilePassword);
         verify(mRecoverableKeyStoreManager)
                 .lockScreenSecretChanged(CREDENTIAL_TYPE_PASSWORD, profilePassword.getCredential(),
                         MANAGED_PROFILE_USER_ID);
@@ -356,9 +316,8 @@
         final LockscreenCredential profilePassword = newPattern("12345");
         mService.setSeparateProfileChallengeEnabled(
                 MANAGED_PROFILE_USER_ID, true, profilePassword);
-        initializeStorageWithCredential(PRIMARY_USER_ID, parentPassword);
-        // Create and verify separate profile credentials.
-        testCreateCredential(MANAGED_PROFILE_USER_ID, profilePassword);
+        setCredential(PRIMARY_USER_ID, parentPassword);
+        setAndVerifyCredential(MANAGED_PROFILE_USER_ID, profilePassword);
 
         mService.setSeparateProfileChallengeEnabled(
                 MANAGED_PROFILE_USER_ID, false, profilePassword);
@@ -372,7 +331,7 @@
     @Test
     public void testVerifyCredential_forPrimaryUser_sendsCredentials() throws Exception {
         final LockscreenCredential password = newPassword("password");
-        initializeStorageWithCredential(PRIMARY_USER_ID, password);
+        setCredential(PRIMARY_USER_ID, password);
         reset(mRecoverableKeyStoreManager);
 
         mService.verifyCredential(password, PRIMARY_USER_ID, 0 /* flags */);
@@ -386,10 +345,7 @@
     public void testVerifyCredential_forProfileWithSeparateChallenge_sendsCredentials()
             throws Exception {
         final LockscreenCredential pattern = newPattern("12345");
-        assertTrue(mService.setLockCredential(
-                pattern,
-                nonePassword(),
-                MANAGED_PROFILE_USER_ID));
+        setCredential(MANAGED_PROFILE_USER_ID, pattern);
         reset(mRecoverableKeyStoreManager);
 
         mService.verifyCredential(pattern, MANAGED_PROFILE_USER_ID, 0 /* flags */);
@@ -403,7 +359,7 @@
     public void verifyCredential_forPrimaryUserWithUnifiedChallengeProfile_sendsCredentialsForBoth()
                     throws Exception {
         final LockscreenCredential pattern = newPattern("12345");
-        initializeStorageWithCredential(PRIMARY_USER_ID, pattern);
+        setCredential(PRIMARY_USER_ID, pattern);
         mService.setSeparateProfileChallengeEnabled(MANAGED_PROFILE_USER_ID, false, null);
         reset(mRecoverableKeyStoreManager);
 
@@ -423,7 +379,7 @@
     }
 
     @Test
-    public void testCredentialChangeNotPossibleInSecureFrpModeDuringSuw() {
+    public void testSetCredentialNotPossibleInSecureFrpModeDuringSuw() {
         setUserSetupComplete(false);
         setSecureFrpMode(true);
         try {
@@ -433,21 +389,17 @@
     }
 
     @Test
-    public void testCredentialChangePossibleInSecureFrpModeAfterSuw() {
+    public void testSetCredentialPossibleInSecureFrpModeAfterSuw() throws RemoteException {
         setUserSetupComplete(true);
         setSecureFrpMode(true);
-        assertTrue(mService.setLockCredential(newPassword("1234"), nonePassword(),
-                PRIMARY_USER_ID));
+        setCredential(PRIMARY_USER_ID, newPassword("1234"));
     }
 
     @Test
     public void testPasswordHistoryDisabledByDefault() throws Exception {
         final int userId = PRIMARY_USER_ID;
         checkPasswordHistoryLength(userId, 0);
-        initializeStorageWithCredential(userId, nonePassword());
-        checkPasswordHistoryLength(userId, 0);
-
-        assertTrue(mService.setLockCredential(newPassword("1234"), nonePassword(), userId));
+        setCredential(userId, newPassword("1234"));
         checkPasswordHistoryLength(userId, 0);
     }
 
@@ -456,20 +408,18 @@
         final int userId = PRIMARY_USER_ID;
         when(mDevicePolicyManager.getPasswordHistoryLength(any(), eq(userId))).thenReturn(3);
         checkPasswordHistoryLength(userId, 0);
-        initializeStorageWithCredential(userId, nonePassword());
-        checkPasswordHistoryLength(userId, 0);
 
-        assertTrue(mService.setLockCredential(newPassword("pass1"), nonePassword(), userId));
+        setCredential(userId, newPassword("pass1"));
         checkPasswordHistoryLength(userId, 1);
 
-        assertTrue(mService.setLockCredential(newPassword("pass2"), newPassword("pass1"), userId));
+        setCredential(userId, newPassword("pass2"), newPassword("pass1"));
         checkPasswordHistoryLength(userId, 2);
 
-        assertTrue(mService.setLockCredential(newPassword("pass3"), newPassword("pass2"), userId));
+        setCredential(userId, newPassword("pass3"), newPassword("pass2"));
         checkPasswordHistoryLength(userId, 3);
 
         // maximum length should have been reached
-        assertTrue(mService.setLockCredential(newPassword("pass4"), newPassword("pass3"), userId));
+        setCredential(userId, newPassword("pass4"), newPassword("pass3"));
         checkPasswordHistoryLength(userId, 3);
     }
 
@@ -479,18 +429,11 @@
         assertEquals(expectedLen, hashes.length);
     }
 
-    private void testCreateCredential(int userId, LockscreenCredential credential)
-            throws RemoteException {
-        assertTrue(mService.setLockCredential(credential, nonePassword(), userId));
-        assertVerifyCredentials(userId, credential);
-    }
-
-    private void testCreateCredentialFailsWithoutLockScreen(
+    private void testSetCredentialFailsWithoutLockScreen(
             int userId, LockscreenCredential credential) throws RemoteException {
         mService.mHasSecureLockScreen = false;
-
         try {
-            mService.setLockCredential(credential, null, userId);
+            mService.setLockCredential(credential, nonePassword(), userId);
             fail("An exception should have been thrown.");
         } catch (UnsupportedOperationException e) {
             // Success - the exception was expected.
@@ -499,14 +442,14 @@
         assertEquals(CREDENTIAL_TYPE_NONE, mService.getCredentialType(userId));
     }
 
-    private void testChangeCredentials(int userId, LockscreenCredential newCredential,
+    private void testChangeCredential(int userId, LockscreenCredential newCredential,
             LockscreenCredential oldCredential) throws RemoteException {
-        initializeStorageWithCredential(userId, oldCredential);
-        assertTrue(mService.setLockCredential(newCredential, oldCredential, userId));
-        assertVerifyCredentials(userId, newCredential);
+        setCredential(userId, oldCredential);
+        setCredential(userId, newCredential, oldCredential);
+        assertVerifyCredential(userId, newCredential);
     }
 
-    private void assertVerifyCredentials(int userId, LockscreenCredential credential)
+    private void assertVerifyCredential(int userId, LockscreenCredential credential)
             throws RemoteException{
         VerifyCredentialResponse response = mService.verifyCredential(credential, userId,
                 0 /* flags */);
@@ -533,16 +476,29 @@
                 badCredential, userId, 0 /* flags */).getResponseCode());
     }
 
-    private void initializeStorageWithCredential(int userId, LockscreenCredential credential)
+    private void setAndVerifyCredential(int userId, LockscreenCredential newCredential)
             throws RemoteException {
-        assertEquals(0, mGateKeeperService.getSecureUserId(userId));
-        synchronized (mService.mSpManager) {
-            mService.initializeSyntheticPasswordLocked(userId);
-        }
-        if (credential.isNone()) {
+        setCredential(userId, newCredential);
+        assertVerifyCredential(userId, newCredential);
+    }
+
+    private void setCredential(int userId, LockscreenCredential newCredential)
+            throws RemoteException {
+        setCredential(userId, newCredential, nonePassword());
+    }
+
+    private void clearCredential(int userId, LockscreenCredential oldCredential)
+            throws RemoteException {
+        setCredential(userId, nonePassword(), oldCredential);
+    }
+
+    private void setCredential(int userId, LockscreenCredential newCredential,
+            LockscreenCredential oldCredential) throws RemoteException {
+        assertTrue(mService.setLockCredential(newCredential, oldCredential, userId));
+        assertEquals(newCredential.getType(), mService.getCredentialType(userId));
+        if (newCredential.isNone()) {
             assertEquals(0, mGateKeeperService.getSecureUserId(userId));
         } else {
-            assertTrue(mService.setLockCredential(credential, nonePassword(), userId));
             assertNotEquals(0, mGateKeeperService.getSecureUserId(userId));
         }
     }
diff --git a/services/tests/servicestests/src/com/android/server/locksettings/LockscreenFrpTest.java b/services/tests/servicestests/src/com/android/server/locksettings/LockscreenFrpTest.java
index fc0ca7e..10869da 100644
--- a/services/tests/servicestests/src/com/android/server/locksettings/LockscreenFrpTest.java
+++ b/services/tests/servicestests/src/com/android/server/locksettings/LockscreenFrpTest.java
@@ -42,14 +42,13 @@
 public class LockscreenFrpTest extends BaseLockSettingsServiceTests {
 
     @Before
-    public void setDeviceNotProvisioned() throws Exception {
+    public void setUp() throws Exception {
+        PropertyInvalidatedCache.disableForTestMode();
+
         // FRP credential can only be verified prior to provisioning
         setDeviceProvisioned(false);
-    }
 
-    @Before
-    public void disableProcessCaches() {
-        PropertyInvalidatedCache.disableForTestMode();
+        mService.initializeSyntheticPassword(PRIMARY_USER_ID);
     }
 
     @Test
diff --git a/services/tests/servicestests/src/com/android/server/locksettings/SyntheticPasswordTests.java b/services/tests/servicestests/src/com/android/server/locksettings/SyntheticPasswordTests.java
index b9cafa4..57593cf 100644
--- a/services/tests/servicestests/src/com/android/server/locksettings/SyntheticPasswordTests.java
+++ b/services/tests/servicestests/src/com/android/server/locksettings/SyntheticPasswordTests.java
@@ -19,7 +19,6 @@
 import static com.android.internal.widget.LockPatternUtils.CREDENTIAL_TYPE_NONE;
 import static com.android.internal.widget.LockPatternUtils.CREDENTIAL_TYPE_PASSWORD;
 import static com.android.internal.widget.LockPatternUtils.CREDENTIAL_TYPE_PASSWORD_OR_PIN;
-import static com.android.internal.widget.LockPatternUtils.CURRENT_LSKF_BASED_PROTECTOR_ID_KEY;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -28,6 +27,7 @@
 import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.atLeastOnce;
@@ -36,8 +36,8 @@
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import android.app.admin.PasswordMetrics;
 import android.app.PropertyInvalidatedCache;
+import android.app.admin.PasswordMetrics;
 import android.os.RemoteException;
 import android.platform.test.annotations.Presubmit;
 
@@ -58,8 +58,6 @@
 import org.mockito.ArgumentCaptor;
 
 import java.io.File;
-import java.util.ArrayList;
-
 
 /**
  * atest FrameworksServicesTests:SyntheticPasswordTests
@@ -125,21 +123,11 @@
         return mGateKeeperService.getSecureUserId(SyntheticPasswordManager.fakeUserId(userId)) != 0;
     }
 
-    private boolean hasSyntheticPassword(int userId) throws RemoteException {
-        return mService.getLong(CURRENT_LSKF_BASED_PROTECTOR_ID_KEY, 0, userId) != 0;
-    }
-
-    private void initializeCredential(LockscreenCredential password, int userId)
+    private void initSpAndSetCredential(int userId, LockscreenCredential credential)
             throws RemoteException {
-        assertTrue(mService.setLockCredential(password, nonePassword(), userId));
-        assertEquals(CREDENTIAL_TYPE_PASSWORD, mService.getCredentialType(userId));
-        assertTrue(mService.isSyntheticPasswordBasedCredential(userId));
-    }
-
-    protected void initializeSyntheticPassword(int userId) {
-        synchronized (mService.mSpManager) {
-            mService.initializeSyntheticPasswordLocked(userId);
-        }
+        mService.initializeSyntheticPassword(userId);
+        assertTrue(mService.setLockCredential(credential, nonePassword(), userId));
+        assertEquals(credential.getType(), mService.getCredentialType(userId));
     }
 
     // Tests that the FRP credential is updated when an LSKF-based protector is created for the user
@@ -147,7 +135,7 @@
     @Test
     public void testFrpCredentialSyncedIfDeviceProvisioned() throws RemoteException {
         setDeviceProvisioned(true);
-        initializeSyntheticPassword(PRIMARY_USER_ID);
+        mService.initializeSyntheticPassword(PRIMARY_USER_ID);
         verify(mStorage.mPersistentDataBlockManager).setFrpCredentialHandle(any());
     }
 
@@ -157,7 +145,7 @@
     @Test
     public void testEmptyFrpCredentialNotSyncedIfDeviceNotProvisioned() throws RemoteException {
         setDeviceProvisioned(false);
-        initializeSyntheticPassword(PRIMARY_USER_ID);
+        mService.initializeSyntheticPassword(PRIMARY_USER_ID);
         verify(mStorage.mPersistentDataBlockManager, never()).setFrpCredentialHandle(any());
     }
 
@@ -167,7 +155,7 @@
     @Test
     public void testNonEmptyFrpCredentialSyncedIfDeviceNotProvisioned() throws RemoteException {
         setDeviceProvisioned(false);
-        initializeSyntheticPassword(PRIMARY_USER_ID);
+        mService.initializeSyntheticPassword(PRIMARY_USER_ID);
         verify(mStorage.mPersistentDataBlockManager, never()).setFrpCredentialHandle(any());
         mService.setLockCredential(newPassword("password"), nonePassword(), PRIMARY_USER_ID);
         verify(mStorage.mPersistentDataBlockManager).setFrpCredentialHandle(any());
@@ -178,7 +166,7 @@
         final LockscreenCredential password = newPassword("password");
         final LockscreenCredential newPassword = newPassword("newpassword");
 
-        initializeCredential(password, PRIMARY_USER_ID);
+        initSpAndSetCredential(PRIMARY_USER_ID, password);
         long sid = mGateKeeperService.getSecureUserId(PRIMARY_USER_ID);
         mService.setLockCredential(newPassword, password, PRIMARY_USER_ID);
         assertEquals(VerifyCredentialResponse.RESPONSE_OK, mService.verifyCredential(
@@ -191,7 +179,7 @@
         LockscreenCredential password = newPassword("password");
         LockscreenCredential badPassword = newPassword("badpassword");
 
-        initializeCredential(password, PRIMARY_USER_ID);
+        initSpAndSetCredential(PRIMARY_USER_ID, password);
         assertEquals(VerifyCredentialResponse.RESPONSE_OK, mService.verifyCredential(
                 password, PRIMARY_USER_ID, 0 /* flags */).getResponseCode());
         verify(mActivityManager).unlockUser2(eq(PRIMARY_USER_ID), any());
@@ -205,7 +193,7 @@
         LockscreenCredential password = newPassword("password");
         LockscreenCredential badPassword = newPassword("newpassword");
 
-        initializeCredential(password, PRIMARY_USER_ID);
+        initSpAndSetCredential(PRIMARY_USER_ID, password);
         long sid = mGateKeeperService.getSecureUserId(PRIMARY_USER_ID);
         // clear password
         mService.setLockCredential(nonePassword(), password, PRIMARY_USER_ID);
@@ -223,47 +211,49 @@
         LockscreenCredential password = newPassword("password");
         LockscreenCredential badPassword = newPassword("new");
 
-        initializeCredential(password, PRIMARY_USER_ID);
+        initSpAndSetCredential(PRIMARY_USER_ID, password);
         mService.setLockCredential(badPassword, password, PRIMARY_USER_ID);
         assertEquals(VerifyCredentialResponse.RESPONSE_OK, mService.verifyCredential(
                 badPassword, PRIMARY_USER_ID, 0 /* flags */).getResponseCode());
 
         // Check the same secret was passed each time
-        ArgumentCaptor<ArrayList<Byte>> secret = ArgumentCaptor.forClass(ArrayList.class);
-        verify(mAuthSecretService, atLeastOnce()).primaryUserCredential(secret.capture());
-        assertEquals(1, secret.getAllValues().stream().distinct().count());
+        ArgumentCaptor<byte[]> secret = ArgumentCaptor.forClass(byte[].class);
+        verify(mAuthSecretService, atLeastOnce()).setPrimaryUserCredential(secret.capture());
+        for (byte[] val : secret.getAllValues()) {
+          assertArrayEquals(val, secret.getAllValues().get(0));
+        }
     }
 
     @Test
     public void testVerifyPassesPrimaryUserAuthSecret() throws RemoteException {
         LockscreenCredential password = newPassword("password");
 
-        initializeCredential(password, PRIMARY_USER_ID);
+        initSpAndSetCredential(PRIMARY_USER_ID, password);
         reset(mAuthSecretService);
         assertEquals(VerifyCredentialResponse.RESPONSE_OK, mService.verifyCredential(
                 password, PRIMARY_USER_ID, 0 /* flags */).getResponseCode());
-        verify(mAuthSecretService).primaryUserCredential(any(ArrayList.class));
+        verify(mAuthSecretService).setPrimaryUserCredential(any(byte[].class));
     }
 
     @Test
     public void testSecondaryUserDoesNotPassAuthSecret() throws RemoteException {
         LockscreenCredential password = newPassword("password");
 
-        initializeCredential(password, SECONDARY_USER_ID);
+        initSpAndSetCredential(SECONDARY_USER_ID, password);
         assertEquals(VerifyCredentialResponse.RESPONSE_OK, mService.verifyCredential(
                 password, SECONDARY_USER_ID, 0 /* flags */).getResponseCode());
-        verify(mAuthSecretService, never()).primaryUserCredential(any(ArrayList.class));
+        verify(mAuthSecretService, never()).setPrimaryUserCredential(any(byte[].class));
     }
 
     @Test
     public void testUnlockUserKeyIfUnsecuredPassesPrimaryUserAuthSecret() throws RemoteException {
         LockscreenCredential password = newPassword("password");
-        initializeCredential(password, PRIMARY_USER_ID);
+        initSpAndSetCredential(PRIMARY_USER_ID, password);
         mService.setLockCredential(nonePassword(), password, PRIMARY_USER_ID);
 
         reset(mAuthSecretService);
         mLocalService.unlockUserKeyIfUnsecured(PRIMARY_USER_ID);
-        verify(mAuthSecretService).primaryUserCredential(any(ArrayList.class));
+        verify(mAuthSecretService).setPrimaryUserCredential(any(byte[].class));
     }
 
     @Test
@@ -271,7 +261,7 @@
         LockscreenCredential password = newPassword("password");
         LockscreenCredential pattern = newPattern("123654");
         byte[] token = "some-high-entropy-secure-token".getBytes();
-        initializeCredential(password, PRIMARY_USER_ID);
+        initSpAndSetCredential(PRIMARY_USER_ID, password);
         // Disregard any reportPasswordChanged() invocations as part of credential setup.
         flushHandlerTasks();
         reset(mDevicePolicyManager);
@@ -306,7 +296,7 @@
         LockscreenCredential password = newPassword("password");
         LockscreenCredential pattern = newPattern("123654");
         byte[] token = "some-high-entropy-secure-token".getBytes();
-        initializeCredential(password, PRIMARY_USER_ID);
+        initSpAndSetCredential(PRIMARY_USER_ID, password);
         byte[] storageKey = mStorageManager.getUserUnlockToken(PRIMARY_USER_ID);
 
         long handle = mLocalService.addEscrowToken(token, PRIMARY_USER_ID, null);
@@ -332,7 +322,7 @@
         LockscreenCredential pattern = newPattern("123654");
         LockscreenCredential newPassword = newPassword("password");
         byte[] token = "some-high-entropy-secure-token".getBytes();
-        initializeCredential(password, PRIMARY_USER_ID);
+        initSpAndSetCredential(PRIMARY_USER_ID, password);
         byte[] storageKey = mStorageManager.getUserUnlockToken(PRIMARY_USER_ID);
 
         long handle = mLocalService.addEscrowToken(token, PRIMARY_USER_ID, null);
@@ -352,38 +342,20 @@
     }
 
     @Test
-    public void testEscrowTokenActivatedImmediatelyIfNoUserPasswordNeedsMigration()
-            throws RemoteException {
+    public void testEscrowTokenActivatedImmediatelyIfNoUserPassword() throws RemoteException {
         final byte[] token = "some-high-entropy-secure-token".getBytes();
+        mService.initializeSyntheticPassword(PRIMARY_USER_ID);
         long handle = mLocalService.addEscrowToken(token, PRIMARY_USER_ID, null);
         assertTrue(mLocalService.isEscrowTokenActive(handle, PRIMARY_USER_ID));
         assertEquals(0, mGateKeeperService.getSecureUserId(PRIMARY_USER_ID));
-        assertTrue(hasSyntheticPassword(PRIMARY_USER_ID));
-    }
-
-    @Test
-    public void testEscrowTokenActivatedImmediatelyIfNoUserPasswordNoMigration()
-            throws RemoteException {
-        final byte[] token = "some-high-entropy-secure-token".getBytes();
-        // By first setting a password and then clearing it, we enter the state where SP is
-        // initialized but the user currently has no password
-        initializeCredential(newPassword("password"), PRIMARY_USER_ID);
-        assertTrue(mService.setLockCredential(nonePassword(), newPassword("password"),
-                PRIMARY_USER_ID));
-        assertTrue(mService.isSyntheticPasswordBasedCredential(PRIMARY_USER_ID));
-
-        long handle = mLocalService.addEscrowToken(token, PRIMARY_USER_ID, null);
-        assertTrue(mLocalService.isEscrowTokenActive(handle, PRIMARY_USER_ID));
-        assertEquals(0, mGateKeeperService.getSecureUserId(PRIMARY_USER_ID));
-        assertTrue(hasSyntheticPassword(PRIMARY_USER_ID));
     }
 
     @Test
     public void testEscrowTokenActivatedLaterWithUserPassword() throws RemoteException {
         byte[] token = "some-high-entropy-secure-token".getBytes();
         LockscreenCredential password = newPassword("password");
-        mService.setLockCredential(password, nonePassword(), PRIMARY_USER_ID);
 
+        initSpAndSetCredential(PRIMARY_USER_ID, password);
         long handle = mLocalService.addEscrowToken(token, PRIMARY_USER_ID, null);
         // Token not activated immediately since user password exists
         assertFalse(mLocalService.isEscrowTokenActive(handle, PRIMARY_USER_ID));
@@ -397,10 +369,13 @@
     @Test
     public void testEscrowTokenCannotBeActivatedOnUnmanagedUser() {
         byte[] token = "some-high-entropy-secure-token".getBytes();
+        when(mDeviceStateCache.isUserOrganizationManaged(anyInt())).thenReturn(false);
+        // TODO(b/258213147): Remove
         when(mUserManagerInternal.isDeviceManaged()).thenReturn(false);
         when(mUserManagerInternal.isUserManaged(PRIMARY_USER_ID)).thenReturn(false);
         when(mDeviceStateCache.isDeviceProvisioned()).thenReturn(true);
 
+        mService.initializeSyntheticPassword(PRIMARY_USER_ID);
         try {
             mLocalService.addEscrowToken(token, PRIMARY_USER_ID, null);
             fail("Escrow token should not be possible on unmanaged device");
@@ -415,7 +390,7 @@
 
         LockscreenCredential password = newPassword("password");
         LockscreenCredential pattern = newPattern("123654");
-        initializeCredential(password, PRIMARY_USER_ID);
+        initSpAndSetCredential(PRIMARY_USER_ID, password);
 
         long handle0 = mLocalService.addEscrowToken(token0, PRIMARY_USER_ID, null);
         long handle1 = mLocalService.addEscrowToken(token1, PRIMARY_USER_ID, null);
@@ -444,6 +419,7 @@
         byte[] token = "some-high-entropy-secure-token".getBytes();
 
         mService.mHasSecureLockScreen = false;
+        mService.initializeSyntheticPassword(PRIMARY_USER_ID);
         long handle = mLocalService.addEscrowToken(token, PRIMARY_USER_ID, null);
         assertTrue(mLocalService.isEscrowTokenActive(handle, PRIMARY_USER_ID));
 
@@ -467,7 +443,7 @@
     @Test
     public void testGetHashFactorPrimaryUser() throws RemoteException {
         LockscreenCredential password = newPassword("password");
-        mService.setLockCredential(password, nonePassword(), PRIMARY_USER_ID);
+        initSpAndSetCredential(PRIMARY_USER_ID, password);
         byte[] hashFactor = mService.getHashFactor(password, PRIMARY_USER_ID);
         assertNotNull(hashFactor);
 
@@ -480,6 +456,9 @@
 
     @Test
     public void testGetHashFactorManagedProfileUnifiedChallenge() throws RemoteException {
+        mService.initializeSyntheticPassword(PRIMARY_USER_ID);
+        mService.initializeSyntheticPassword(MANAGED_PROFILE_USER_ID);
+
         LockscreenCredential pattern = newPattern("1236");
         mService.setLockCredential(pattern, nonePassword(), PRIMARY_USER_ID);
         mService.setSeparateProfileChallengeEnabled(MANAGED_PROFILE_USER_ID, false, null);
@@ -488,6 +467,9 @@
 
     @Test
     public void testGetHashFactorManagedProfileSeparateChallenge() throws RemoteException {
+        mService.initializeSyntheticPassword(PRIMARY_USER_ID);
+        mService.initializeSyntheticPassword(MANAGED_PROFILE_USER_ID);
+
         LockscreenCredential primaryPassword = newPassword("primary");
         LockscreenCredential profilePassword = newPassword("profile");
         mService.setLockCredential(primaryPassword, nonePassword(), PRIMARY_USER_ID);
@@ -588,17 +570,17 @@
 
         LockscreenCredential password = newPassword("testGsiDisablesAuthSecret-password");
 
-        initializeCredential(password, PRIMARY_USER_ID);
+        initSpAndSetCredential(PRIMARY_USER_ID, password);
         assertEquals(VerifyCredentialResponse.RESPONSE_OK, mService.verifyCredential(
                 password, PRIMARY_USER_ID, 0 /* flags */).getResponseCode());
-        verify(mAuthSecretService, never()).primaryUserCredential(any(ArrayList.class));
+        verify(mAuthSecretService, never()).setPrimaryUserCredential(any(byte[].class));
     }
 
     @Test
     public void testUnlockUserWithToken() throws Exception {
         LockscreenCredential password = newPassword("password");
         byte[] token = "some-high-entropy-secure-token".getBytes();
-        initializeCredential(password, PRIMARY_USER_ID);
+        initSpAndSetCredential(PRIMARY_USER_ID, password);
         // Disregard any reportPasswordChanged() invocations as part of credential setup.
         flushHandlerTasks();
         reset(mDevicePolicyManager);
@@ -619,7 +601,7 @@
     @Test
     public void testPasswordChange_NoOrphanedFilesLeft() throws Exception {
         LockscreenCredential password = newPassword("password");
-        initializeCredential(password, PRIMARY_USER_ID);
+        initSpAndSetCredential(PRIMARY_USER_ID, password);
         assertTrue(mService.setLockCredential(password, password, PRIMARY_USER_ID));
         assertNoOrphanedFilesLeft(PRIMARY_USER_ID);
     }
@@ -627,6 +609,7 @@
     @Test
     public void testAddingEscrowToken_NoOrphanedFilesLeft() throws Exception {
         final byte[] token = "some-high-entropy-secure-token".getBytes();
+        mService.initializeSyntheticPassword(PRIMARY_USER_ID);
         for (int i = 0; i < 16; i++) {
             long handle = mLocalService.addEscrowToken(token, PRIMARY_USER_ID, null);
             assertTrue(mLocalService.isEscrowTokenActive(handle, PRIMARY_USER_ID));
diff --git a/services/tests/servicestests/src/com/android/server/locksettings/WeakEscrowTokenTests.java b/services/tests/servicestests/src/com/android/server/locksettings/WeakEscrowTokenTests.java
index 51ddcef..2c9ba34 100644
--- a/services/tests/servicestests/src/com/android/server/locksettings/WeakEscrowTokenTests.java
+++ b/services/tests/servicestests/src/com/android/server/locksettings/WeakEscrowTokenTests.java
@@ -40,6 +40,7 @@
 import com.android.internal.widget.LockscreenCredential;
 import com.android.internal.widget.VerifyCredentialResponse;
 
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -49,6 +50,11 @@
 @RunWith(AndroidJUnit4.class)
 public class WeakEscrowTokenTests extends BaseLockSettingsServiceTests{
 
+    @Before
+    public void setUp() {
+        mService.initializeSyntheticPassword(PRIMARY_USER_ID);
+    }
+
     @Test
     public void testWeakTokenActivatedImmediatelyIfNoUserPassword()
             throws RemoteException {
diff --git a/services/tests/servicestests/src/com/android/server/locksettings/WeaverBasedSyntheticPasswordTests.java b/services/tests/servicestests/src/com/android/server/locksettings/WeaverBasedSyntheticPasswordTests.java
index 6c13a6f..966c047 100644
--- a/services/tests/servicestests/src/com/android/server/locksettings/WeaverBasedSyntheticPasswordTests.java
+++ b/services/tests/servicestests/src/com/android/server/locksettings/WeaverBasedSyntheticPasswordTests.java
@@ -36,7 +36,7 @@
         assertEquals(Sets.newHashSet(), mPasswordSlotManager.getUsedSlots());
         mStorage.writePersistentDataBlock(PersistentData.TYPE_SP_WEAVER, frpWeaverSlot, 0,
                 new byte[1]);
-        initializeSyntheticPassword(userId); // This should allocate a Weaver slot.
+        mService.initializeSyntheticPassword(userId); // This should allocate a Weaver slot.
         assertEquals(Sets.newHashSet(1), mPasswordSlotManager.getUsedSlots());
     }
 
@@ -52,7 +52,7 @@
         assertEquals(Sets.newHashSet(), mPasswordSlotManager.getUsedSlots());
         mStorage.writePersistentDataBlock(PersistentData.TYPE_SP_WEAVER, frpWeaverSlot, 0,
                 new byte[1]);
-        initializeSyntheticPassword(userId); // This should allocate a Weaver slot.
+        mService.initializeSyntheticPassword(userId); // This should allocate a Weaver slot.
         assertEquals(Sets.newHashSet(0), mPasswordSlotManager.getUsedSlots());
     }
 }
diff --git a/services/tests/servicestests/src/com/android/server/media/projection/OWNERS b/services/tests/servicestests/src/com/android/server/media/projection/OWNERS
new file mode 100644
index 0000000..832bcd9
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/media/projection/OWNERS
@@ -0,0 +1 @@
+include /media/java/android/media/projection/OWNERS
diff --git a/services/tests/servicestests/src/com/android/server/pm/BackgroundInstallControlServiceTest.java b/services/tests/servicestests/src/com/android/server/pm/BackgroundInstallControlServiceTest.java
new file mode 100644
index 0000000..54fa272
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/pm/BackgroundInstallControlServiceTest.java
@@ -0,0 +1,840 @@
+/*
+ * 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.server.pm;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.usage.UsageEvents;
+import android.app.usage.UsageEvents.Event;
+import android.app.usage.UsageStatsManagerInternal;
+import android.app.usage.UsageStatsManagerInternal.UsageEventListener;
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.IPackageManager;
+import android.content.pm.InstallSourceInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManagerInternal;
+import android.content.pm.ParceledListSlice;
+import android.os.FileUtils;
+import android.os.Looper;
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.os.UserHandle;
+import android.os.test.TestLooper;
+import android.platform.test.annotations.Presubmit;
+import android.util.AtomicFile;
+import android.util.SparseSetArray;
+import android.util.proto.ProtoInputStream;
+import android.util.proto.ProtoOutputStream;
+
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import com.android.server.pm.permission.PermissionManagerServiceInternal;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.internal.util.reflection.FieldSetter;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests for {@link com.android.server.pm.BackgroundInstallControlService}
+ */
+@Presubmit
+public final class BackgroundInstallControlServiceTest {
+    private static final String INSTALLER_NAME_1 = "installer1";
+    private static final String INSTALLER_NAME_2 = "installer2";
+    private static final String PACKAGE_NAME_1 = "package1";
+    private static final String PACKAGE_NAME_2 = "package2";
+    private static final String PACKAGE_NAME_3 = "package3";
+    private static final int USER_ID_1 = 1;
+    private static final int USER_ID_2 = 2;
+    private static final long USAGE_EVENT_TIMESTAMP_1 = 1000;
+    private static final long USAGE_EVENT_TIMESTAMP_2 = 2000;
+    private static final long USAGE_EVENT_TIMESTAMP_3 = 3000;
+    private static final long PACKAGE_ADD_TIMESTAMP_1 = 1500;
+
+    private BackgroundInstallControlService mBackgroundInstallControlService;
+    private PackageManagerInternal.PackageListObserver mPackageListObserver;
+    private UsageEventListener mUsageEventListener;
+    private TestLooper mTestLooper;
+    private Looper mLooper;
+    private File mFile;
+
+
+    @Mock
+    private Context mContext;
+    @Mock
+    private IPackageManager mIPackageManager;
+    @Mock
+    private PackageManagerInternal mPackageManagerInternal;
+    @Mock
+    private UsageStatsManagerInternal mUsageStatsManagerInternal;
+    @Mock
+    private PermissionManagerServiceInternal mPermissionManager;
+    @Captor
+    private ArgumentCaptor<PackageManagerInternal.PackageListObserver> mPackageListObserverCaptor;
+    @Captor
+    private ArgumentCaptor<UsageEventListener> mUsageEventListenerCaptor;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+
+        mTestLooper = new TestLooper();
+        mLooper = mTestLooper.getLooper();
+        mFile = new File(
+                InstrumentationRegistry.getInstrumentation().getContext().getCacheDir(),
+                "test");
+        mBackgroundInstallControlService = new BackgroundInstallControlService(
+                new MockInjector(mContext));
+
+        verify(mUsageStatsManagerInternal).registerListener(mUsageEventListenerCaptor.capture());
+        mUsageEventListener = mUsageEventListenerCaptor.getValue();
+
+        mBackgroundInstallControlService.onStart(true);
+        verify(mPackageManagerInternal).getPackageList(mPackageListObserverCaptor.capture());
+        mPackageListObserver = mPackageListObserverCaptor.getValue();
+    }
+
+    @After
+    public void tearDown() {
+        FileUtils.deleteContentsAndDir(mFile);
+    }
+
+    @Test
+    public void testInitBackgroundInstalledPackages_empty() {
+        assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages());
+        mBackgroundInstallControlService.initBackgroundInstalledPackages();
+        assertNotNull(mBackgroundInstallControlService.getBackgroundInstalledPackages());
+        assertEquals(0,
+                mBackgroundInstallControlService.getBackgroundInstalledPackages().size());
+    }
+
+    @Test
+    public void testInitBackgroundInstalledPackages_one() {
+        AtomicFile atomicFile = new AtomicFile(mFile);
+        FileOutputStream fileOutputStream;
+        try {
+            fileOutputStream = atomicFile.startWrite();
+        } catch (IOException e) {
+            fail("Failed to start write to states protobuf." + e);
+            return;
+        }
+
+        // Write test data to the file on the disk.
+        try {
+            ProtoOutputStream protoOutputStream = new ProtoOutputStream(fileOutputStream);
+            long token = protoOutputStream.start(
+                    BackgroundInstalledPackagesProto.BG_INSTALLED_PKG);
+            protoOutputStream.write(
+                    BackgroundInstalledPackageProto.PACKAGE_NAME, PACKAGE_NAME_1);
+            protoOutputStream.write(
+                    BackgroundInstalledPackageProto.USER_ID, USER_ID_1 + 1);
+            protoOutputStream.end(token);
+            protoOutputStream.flush();
+            atomicFile.finishWrite(fileOutputStream);
+        } catch (Exception e) {
+            fail("Failed to finish write to states protobuf. " + e);
+            atomicFile.failWrite(fileOutputStream);
+        }
+
+        assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages());
+        mBackgroundInstallControlService.initBackgroundInstalledPackages();
+        var packages = mBackgroundInstallControlService.getBackgroundInstalledPackages();
+        assertNotNull(packages);
+        assertEquals(1, packages.size());
+        assertTrue(packages.contains(USER_ID_1, PACKAGE_NAME_1));
+    }
+
+    @Test
+    public void testInitBackgroundInstalledPackages_two() {
+        AtomicFile atomicFile = new AtomicFile(mFile);
+        FileOutputStream fileOutputStream;
+        try {
+            fileOutputStream = atomicFile.startWrite();
+        } catch (IOException e) {
+            fail("Failed to start write to states protobuf." + e);
+            return;
+        }
+
+        // Write test data to the file on the disk.
+        try {
+            ProtoOutputStream protoOutputStream = new ProtoOutputStream(fileOutputStream);
+
+            long token = protoOutputStream.start(
+                    BackgroundInstalledPackagesProto.BG_INSTALLED_PKG);
+            protoOutputStream.write(
+                    BackgroundInstalledPackageProto.PACKAGE_NAME, PACKAGE_NAME_1);
+            protoOutputStream.write(
+                    BackgroundInstalledPackageProto.USER_ID, USER_ID_1 + 1);
+            protoOutputStream.end(token);
+
+            token = protoOutputStream.start(
+                    BackgroundInstalledPackagesProto.BG_INSTALLED_PKG);
+            protoOutputStream.write(
+                    BackgroundInstalledPackageProto.PACKAGE_NAME, PACKAGE_NAME_2);
+            protoOutputStream.write(
+                    BackgroundInstalledPackageProto.USER_ID, USER_ID_2 + 1);
+            protoOutputStream.end(token);
+
+            protoOutputStream.flush();
+            atomicFile.finishWrite(fileOutputStream);
+        } catch (Exception e) {
+            fail("Failed to finish write to states protobuf. " + e);
+            atomicFile.failWrite(fileOutputStream);
+        }
+
+        assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages());
+        mBackgroundInstallControlService.initBackgroundInstalledPackages();
+        var packages = mBackgroundInstallControlService.getBackgroundInstalledPackages();
+        assertNotNull(packages);
+        assertEquals(2, packages.size());
+        assertTrue(packages.contains(USER_ID_1, PACKAGE_NAME_1));
+        assertTrue(packages.contains(USER_ID_2, PACKAGE_NAME_2));
+    }
+
+    @Test
+    public void testWriteBackgroundInstalledPackagesToDisk_empty() {
+        assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages());
+        mBackgroundInstallControlService.initBackgroundInstalledPackages();
+        var packages = mBackgroundInstallControlService.getBackgroundInstalledPackages();
+        assertNotNull(packages);
+        mBackgroundInstallControlService.writeBackgroundInstalledPackagesToDisk();
+
+        // Read the file on the disk to verify
+        var packagesInDisk = new SparseSetArray<>();
+        AtomicFile atomicFile = new AtomicFile(mFile);
+        try (FileInputStream fileInputStream  = atomicFile.openRead()) {
+            ProtoInputStream protoInputStream = new ProtoInputStream(fileInputStream);
+
+            while (protoInputStream.nextField() != ProtoInputStream.NO_MORE_FIELDS) {
+                if (protoInputStream.getFieldNumber()
+                        != (int) BackgroundInstalledPackagesProto.BG_INSTALLED_PKG) {
+                    continue;
+                }
+                long token = protoInputStream.start(
+                        BackgroundInstalledPackagesProto.BG_INSTALLED_PKG);
+                String packageName = null;
+                int userId = UserHandle.USER_NULL;
+                while (protoInputStream.nextField() != ProtoInputStream.NO_MORE_FIELDS) {
+                    switch (protoInputStream.getFieldNumber()) {
+                        case (int) BackgroundInstalledPackageProto.PACKAGE_NAME:
+                            packageName = protoInputStream.readString(
+                                    BackgroundInstalledPackageProto.PACKAGE_NAME);
+                            break;
+                        case (int) BackgroundInstalledPackageProto.USER_ID:
+                            userId = protoInputStream.readInt(
+                                    BackgroundInstalledPackageProto.USER_ID) - 1;
+                            break;
+                        default:
+                            fail("Undefined field in proto: "
+                                    + protoInputStream.getFieldNumber());
+                    }
+                }
+                protoInputStream.end(token);
+                if (packageName != null && userId != UserHandle.USER_NULL) {
+                    packagesInDisk.add(userId, packageName);
+                } else {
+                    fail("Fails to get packageName or UserId from proto file");
+                }
+            }
+        } catch (IOException e) {
+            fail("Error reading state from the disk. " + e);
+        }
+
+        assertEquals(0, packagesInDisk.size());
+        assertEquals(packages.size(), packagesInDisk.size());
+    }
+
+    @Test
+    public void testWriteBackgroundInstalledPackagesToDisk_one() {
+        assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages());
+        mBackgroundInstallControlService.initBackgroundInstalledPackages();
+        var packages = mBackgroundInstallControlService.getBackgroundInstalledPackages();
+        assertNotNull(packages);
+
+        packages.add(USER_ID_1, PACKAGE_NAME_1);
+        mBackgroundInstallControlService.writeBackgroundInstalledPackagesToDisk();
+
+        // Read the file on the disk to verify
+        var packagesInDisk = new SparseSetArray<>();
+        AtomicFile atomicFile = new AtomicFile(mFile);
+        try (FileInputStream fileInputStream  = atomicFile.openRead()) {
+            ProtoInputStream protoInputStream = new ProtoInputStream(fileInputStream);
+
+            while (protoInputStream.nextField() != ProtoInputStream.NO_MORE_FIELDS) {
+                if (protoInputStream.getFieldNumber()
+                        != (int) BackgroundInstalledPackagesProto.BG_INSTALLED_PKG) {
+                    continue;
+                }
+                long token = protoInputStream.start(
+                        BackgroundInstalledPackagesProto.BG_INSTALLED_PKG);
+                String packageName = null;
+                int userId = UserHandle.USER_NULL;
+                while (protoInputStream.nextField() != ProtoInputStream.NO_MORE_FIELDS) {
+                    switch (protoInputStream.getFieldNumber()) {
+                        case (int) BackgroundInstalledPackageProto.PACKAGE_NAME:
+                            packageName = protoInputStream.readString(
+                                    BackgroundInstalledPackageProto.PACKAGE_NAME);
+                            break;
+                        case (int) BackgroundInstalledPackageProto.USER_ID:
+                            userId = protoInputStream.readInt(
+                                    BackgroundInstalledPackageProto.USER_ID) - 1;
+                            break;
+                        default:
+                            fail("Undefined field in proto: "
+                                    + protoInputStream.getFieldNumber());
+                    }
+                }
+                protoInputStream.end(token);
+                if (packageName != null && userId != UserHandle.USER_NULL) {
+                    packagesInDisk.add(userId, packageName);
+                } else {
+                    fail("Fails to get packageName or UserId from proto file");
+                }
+            }
+        } catch (IOException e) {
+            fail("Error reading state from the disk. " + e);
+        }
+
+        assertEquals(1, packagesInDisk.size());
+        assertEquals(packages.size(), packagesInDisk.size());
+        assertTrue(packages.contains(USER_ID_1, PACKAGE_NAME_1));
+    }
+
+    @Test
+    public void testWriteBackgroundInstalledPackagesToDisk_two() {
+        assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages());
+        mBackgroundInstallControlService.initBackgroundInstalledPackages();
+        var packages = mBackgroundInstallControlService.getBackgroundInstalledPackages();
+        assertNotNull(packages);
+
+        packages.add(USER_ID_1, PACKAGE_NAME_1);
+        packages.add(USER_ID_2, PACKAGE_NAME_2);
+        mBackgroundInstallControlService.writeBackgroundInstalledPackagesToDisk();
+
+        // Read the file on the disk to verify
+        var packagesInDisk = new SparseSetArray<>();
+        AtomicFile atomicFile = new AtomicFile(mFile);
+        try (FileInputStream fileInputStream  = atomicFile.openRead()) {
+            ProtoInputStream protoInputStream = new ProtoInputStream(fileInputStream);
+
+            while (protoInputStream.nextField() != ProtoInputStream.NO_MORE_FIELDS) {
+                if (protoInputStream.getFieldNumber()
+                        != (int) BackgroundInstalledPackagesProto.BG_INSTALLED_PKG) {
+                    continue;
+                }
+                long token = protoInputStream.start(
+                        BackgroundInstalledPackagesProto.BG_INSTALLED_PKG);
+                String packageName = null;
+                int userId = UserHandle.USER_NULL;
+                while (protoInputStream.nextField() != ProtoInputStream.NO_MORE_FIELDS) {
+                    switch (protoInputStream.getFieldNumber()) {
+                        case (int) BackgroundInstalledPackageProto.PACKAGE_NAME:
+                            packageName = protoInputStream.readString(
+                                    BackgroundInstalledPackageProto.PACKAGE_NAME);
+                            break;
+                        case (int) BackgroundInstalledPackageProto.USER_ID:
+                            userId = protoInputStream.readInt(
+                                    BackgroundInstalledPackageProto.USER_ID) - 1;
+                            break;
+                        default:
+                            fail("Undefined field in proto: "
+                                    + protoInputStream.getFieldNumber());
+                    }
+                }
+                protoInputStream.end(token);
+                if (packageName != null && userId != UserHandle.USER_NULL) {
+                    packagesInDisk.add(userId, packageName);
+                } else {
+                    fail("Fails to get packageName or UserId from proto file");
+                }
+            }
+        } catch (IOException e) {
+            fail("Error reading state from the disk. " + e);
+        }
+
+        assertEquals(2, packagesInDisk.size());
+        assertEquals(packages.size(), packagesInDisk.size());
+        assertTrue(packages.contains(USER_ID_1, PACKAGE_NAME_1));
+        assertTrue(packages.contains(USER_ID_2, PACKAGE_NAME_2));
+    }
+
+    @Test
+    public void testHandleUsageEvent_permissionDenied() {
+        assertEquals(0,
+                mBackgroundInstallControlService.getInstallerForegroundTimeFrames().numMaps());
+        doReturn(PackageManager.PERMISSION_DENIED).when(mPermissionManager).checkPermission(
+                anyString(), anyString(), anyInt());
+        generateUsageEvent(UsageEvents.Event.ACTIVITY_RESUMED,
+                USER_ID_1, INSTALLER_NAME_1, 0);
+        mTestLooper.dispatchAll();
+        assertEquals(0,
+                mBackgroundInstallControlService.getInstallerForegroundTimeFrames().numMaps());
+    }
+
+    @Test
+    public void testHandleUsageEvent_permissionGranted() {
+        assertEquals(0,
+                mBackgroundInstallControlService.getInstallerForegroundTimeFrames().numMaps());
+        doReturn(PackageManager.PERMISSION_GRANTED).when(mPermissionManager).checkPermission(
+                anyString(), anyString(), anyInt());
+        generateUsageEvent(UsageEvents.Event.ACTIVITY_RESUMED,
+                USER_ID_1, INSTALLER_NAME_1, 0);
+        mTestLooper.dispatchAll();
+        assertEquals(1,
+                mBackgroundInstallControlService.getInstallerForegroundTimeFrames().numMaps());
+    }
+
+    @Test
+    public void testHandleUsageEvent_ignoredEvent() {
+        assertEquals(0,
+                mBackgroundInstallControlService.getInstallerForegroundTimeFrames().numMaps());
+        doReturn(PackageManager.PERMISSION_GRANTED).when(mPermissionManager).checkPermission(
+                anyString(), anyString(), anyInt());
+        generateUsageEvent(UsageEvents.Event.USER_INTERACTION,
+                USER_ID_1, INSTALLER_NAME_1, 0);
+        mTestLooper.dispatchAll();
+        assertEquals(0,
+                mBackgroundInstallControlService.getInstallerForegroundTimeFrames().numMaps());
+    }
+
+    @Test
+    public void testHandleUsageEvent_firstActivityResumedHalfTimeFrame() {
+        assertEquals(0,
+                mBackgroundInstallControlService.getInstallerForegroundTimeFrames().numMaps());
+        doReturn(PackageManager.PERMISSION_GRANTED).when(mPermissionManager).checkPermission(
+                anyString(), anyString(), anyInt());
+        generateUsageEvent(UsageEvents.Event.ACTIVITY_RESUMED,
+                USER_ID_1, INSTALLER_NAME_1, USAGE_EVENT_TIMESTAMP_1);
+        mTestLooper.dispatchAll();
+
+        var installerForegroundTimeFrames =
+                mBackgroundInstallControlService.getInstallerForegroundTimeFrames();
+        assertEquals(1, installerForegroundTimeFrames.numMaps());
+        assertEquals(1, installerForegroundTimeFrames.numElementsForKey(USER_ID_1));
+
+        var foregroundTimeFrames = installerForegroundTimeFrames.get(USER_ID_1, INSTALLER_NAME_1);
+        assertEquals(1, foregroundTimeFrames.size());
+
+        var foregroundTimeFrame = foregroundTimeFrames.first();
+        assertEquals(USAGE_EVENT_TIMESTAMP_1, foregroundTimeFrame.startTimeStampMillis);
+        assertFalse(foregroundTimeFrame.isDone());
+    }
+
+    @Test
+    public void testHandleUsageEvent_firstActivityResumedOneTimeFrame() {
+        assertEquals(0,
+                mBackgroundInstallControlService.getInstallerForegroundTimeFrames().numMaps());
+        doReturn(PackageManager.PERMISSION_GRANTED).when(mPermissionManager).checkPermission(
+                anyString(), anyString(), anyInt());
+        generateUsageEvent(UsageEvents.Event.ACTIVITY_RESUMED,
+                USER_ID_1, INSTALLER_NAME_1, USAGE_EVENT_TIMESTAMP_1);
+        generateUsageEvent(Event.ACTIVITY_STOPPED,
+                USER_ID_1, INSTALLER_NAME_1, USAGE_EVENT_TIMESTAMP_2);
+        mTestLooper.dispatchAll();
+
+        var installerForegroundTimeFrames =
+                mBackgroundInstallControlService.getInstallerForegroundTimeFrames();
+        assertEquals(1, installerForegroundTimeFrames.numMaps());
+        assertEquals(1, installerForegroundTimeFrames.numElementsForKey(USER_ID_1));
+
+        var foregroundTimeFrames = installerForegroundTimeFrames.get(USER_ID_1, INSTALLER_NAME_1);
+        assertEquals(1, foregroundTimeFrames.size());
+
+        var foregroundTimeFrame = foregroundTimeFrames.first();
+        assertEquals(USAGE_EVENT_TIMESTAMP_1, foregroundTimeFrame.startTimeStampMillis);
+        assertTrue(foregroundTimeFrame.isDone());
+    }
+
+    @Test
+    public void testHandleUsageEvent_firstActivityResumedOneAndHalfTimeFrame() {
+        assertEquals(0,
+                mBackgroundInstallControlService.getInstallerForegroundTimeFrames().numMaps());
+        doReturn(PackageManager.PERMISSION_GRANTED).when(mPermissionManager).checkPermission(
+                anyString(), anyString(), anyInt());
+        generateUsageEvent(UsageEvents.Event.ACTIVITY_RESUMED,
+                USER_ID_1, INSTALLER_NAME_1, USAGE_EVENT_TIMESTAMP_1);
+        generateUsageEvent(Event.ACTIVITY_STOPPED,
+                USER_ID_1, INSTALLER_NAME_1, USAGE_EVENT_TIMESTAMP_2);
+        generateUsageEvent(UsageEvents.Event.ACTIVITY_RESUMED,
+                USER_ID_1, INSTALLER_NAME_1, USAGE_EVENT_TIMESTAMP_3);
+        mTestLooper.dispatchAll();
+
+        var installerForegroundTimeFrames =
+                mBackgroundInstallControlService.getInstallerForegroundTimeFrames();
+        assertEquals(1, installerForegroundTimeFrames.numMaps());
+        assertEquals(1, installerForegroundTimeFrames.numElementsForKey(USER_ID_1));
+
+        var foregroundTimeFrames = installerForegroundTimeFrames.get(USER_ID_1, INSTALLER_NAME_1);
+        assertEquals(2, foregroundTimeFrames.size());
+
+        var foregroundTimeFrame1 = foregroundTimeFrames.first();
+        assertEquals(USAGE_EVENT_TIMESTAMP_1, foregroundTimeFrame1.startTimeStampMillis);
+        assertTrue(foregroundTimeFrame1.isDone());
+
+        var foregroundTimeFrame2 = foregroundTimeFrames.last();
+        assertEquals(USAGE_EVENT_TIMESTAMP_3, foregroundTimeFrame2.startTimeStampMillis);
+        assertFalse(foregroundTimeFrame2.isDone());
+    }
+
+    @Test
+    public void testHandleUsageEvent_firstNoneActivityResumed() {
+        assertEquals(0,
+                mBackgroundInstallControlService.getInstallerForegroundTimeFrames().numMaps());
+        doReturn(PackageManager.PERMISSION_GRANTED).when(mPermissionManager).checkPermission(
+                anyString(), anyString(), anyInt());
+        generateUsageEvent(Event.ACTIVITY_STOPPED,
+                USER_ID_1, INSTALLER_NAME_1, USAGE_EVENT_TIMESTAMP_1);
+        mTestLooper.dispatchAll();
+
+        var installerForegroundTimeFrames =
+                mBackgroundInstallControlService.getInstallerForegroundTimeFrames();
+        assertEquals(1, installerForegroundTimeFrames.numMaps());
+        assertEquals(1, installerForegroundTimeFrames.numElementsForKey(USER_ID_1));
+
+        var foregroundTimeFrames = installerForegroundTimeFrames.get(USER_ID_1, INSTALLER_NAME_1);
+        assertEquals(0, foregroundTimeFrames.size());
+    }
+
+    @Test
+    public void testHandleUsageEvent_packageAddedNoUsageEvent() throws
+            RemoteException, NoSuchFieldException {
+        assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages());
+        InstallSourceInfo installSourceInfo = new InstallSourceInfo(
+                /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null,
+                /* originatingPackageName = */ null,
+                /* installingPackageName = */ INSTALLER_NAME_1);
+        assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1);
+        when(mIPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo);
+        ApplicationInfo appInfo = mock(ApplicationInfo.class);
+
+        when(mIPackageManager.getApplicationInfo(
+                eq(PACKAGE_NAME_1),
+                eq(0L),
+                anyInt())
+        ).thenReturn(appInfo);
+
+        long createTimestamp = PACKAGE_ADD_TIMESTAMP_1
+                - (System.currentTimeMillis() - SystemClock.uptimeMillis());
+        FieldSetter.setField(appInfo,
+                ApplicationInfo.class.getDeclaredField("createTimestamp"),
+                createTimestamp);
+
+        int uid = USER_ID_1 * UserHandle.PER_USER_RANGE;
+        assertEquals(USER_ID_1, UserHandle.getUserId(uid));
+
+        mPackageListObserver.onPackageAdded(PACKAGE_NAME_1, uid);
+        mTestLooper.dispatchAll();
+
+        var packages = mBackgroundInstallControlService.getBackgroundInstalledPackages();
+        assertNotNull(packages);
+        assertEquals(1, packages.size());
+        assertTrue(packages.contains(USER_ID_1, PACKAGE_NAME_1));
+    }
+
+    @Test
+    public void testHandleUsageEvent_packageAddedInsideTimeFrame() throws
+            RemoteException, NoSuchFieldException {
+        assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages());
+        InstallSourceInfo installSourceInfo = new InstallSourceInfo(
+                /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null,
+                /* originatingPackageName = */ null,
+                /* installingPackageName = */ INSTALLER_NAME_1);
+        assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1);
+        when(mIPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo);
+        ApplicationInfo appInfo = mock(ApplicationInfo.class);
+
+        when(mIPackageManager.getApplicationInfo(
+                eq(PACKAGE_NAME_1),
+                eq(0L),
+                anyInt())
+        ).thenReturn(appInfo);
+
+        long createTimestamp = PACKAGE_ADD_TIMESTAMP_1
+                - (System.currentTimeMillis() - SystemClock.uptimeMillis());
+        FieldSetter.setField(appInfo,
+                ApplicationInfo.class.getDeclaredField("createTimestamp"),
+                createTimestamp);
+
+        int uid = USER_ID_1 * UserHandle.PER_USER_RANGE;
+        assertEquals(USER_ID_1, UserHandle.getUserId(uid));
+
+        // The following 2 usage events generation is the only difference from the
+        // testHandleUsageEvent_packageAddedNoUsageEvent test.
+        // The 2 usage events make the package adding inside a time frame.
+        // So it's not a background install. Thus, it's null for the return of
+        // mBackgroundInstallControlService.getBackgroundInstalledPackages()
+        doReturn(PackageManager.PERMISSION_GRANTED).when(mPermissionManager).checkPermission(
+                anyString(), anyString(), anyInt());
+        generateUsageEvent(UsageEvents.Event.ACTIVITY_RESUMED,
+                USER_ID_1, INSTALLER_NAME_1, USAGE_EVENT_TIMESTAMP_1);
+        generateUsageEvent(Event.ACTIVITY_STOPPED,
+                USER_ID_1, INSTALLER_NAME_1, USAGE_EVENT_TIMESTAMP_2);
+
+        mPackageListObserver.onPackageAdded(PACKAGE_NAME_1, uid);
+        mTestLooper.dispatchAll();
+        assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages());
+    }
+
+    @Test
+    public void testHandleUsageEvent_packageAddedOutsideTimeFrame1() throws
+            RemoteException, NoSuchFieldException {
+        assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages());
+        InstallSourceInfo installSourceInfo = new InstallSourceInfo(
+                /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null,
+                /* originatingPackageName = */ null,
+                /* installingPackageName = */ INSTALLER_NAME_1);
+        assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1);
+        when(mIPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo);
+        ApplicationInfo appInfo = mock(ApplicationInfo.class);
+
+        when(mIPackageManager.getApplicationInfo(
+                eq(PACKAGE_NAME_1),
+                eq(0L),
+                anyInt())
+        ).thenReturn(appInfo);
+
+        long createTimestamp = PACKAGE_ADD_TIMESTAMP_1
+                - (System.currentTimeMillis() - SystemClock.uptimeMillis());
+        FieldSetter.setField(appInfo,
+                ApplicationInfo.class.getDeclaredField("createTimestamp"),
+                createTimestamp);
+
+        int uid = USER_ID_1 * UserHandle.PER_USER_RANGE;
+        assertEquals(USER_ID_1, UserHandle.getUserId(uid));
+
+        // The following 2 usage events generation is the only difference from the
+        // testHandleUsageEvent_packageAddedNoUsageEvent test.
+        // The 2 usage events make the package adding outside a time frame.
+        // Compared to testHandleUsageEvent_packageAddedInsideTimeFrame,
+        // it's a background install. Thus, it's not null for the return of
+        // mBackgroundInstallControlService.getBackgroundInstalledPackages()
+        doReturn(PackageManager.PERMISSION_GRANTED).when(mPermissionManager).checkPermission(
+                anyString(), anyString(), anyInt());
+        generateUsageEvent(UsageEvents.Event.ACTIVITY_RESUMED,
+                USER_ID_1, INSTALLER_NAME_1, USAGE_EVENT_TIMESTAMP_2);
+        generateUsageEvent(Event.ACTIVITY_STOPPED,
+                USER_ID_1, INSTALLER_NAME_1, USAGE_EVENT_TIMESTAMP_3);
+
+        mPackageListObserver.onPackageAdded(PACKAGE_NAME_1, uid);
+        mTestLooper.dispatchAll();
+
+        var packages = mBackgroundInstallControlService.getBackgroundInstalledPackages();
+        assertNotNull(packages);
+        assertEquals(1, packages.size());
+        assertTrue(packages.contains(USER_ID_1, PACKAGE_NAME_1));
+    }
+    @Test
+    public void testHandleUsageEvent_packageAddedOutsideTimeFrame2() throws
+            RemoteException, NoSuchFieldException {
+        assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages());
+        InstallSourceInfo installSourceInfo = new InstallSourceInfo(
+                /* initiatingPackageName = */ null, /* initiatingPackageSigningInfo = */ null,
+                /* originatingPackageName = */ null,
+                /* installingPackageName = */ INSTALLER_NAME_1);
+        assertEquals(installSourceInfo.getInstallingPackageName(), INSTALLER_NAME_1);
+        when(mIPackageManager.getInstallSourceInfo(anyString())).thenReturn(installSourceInfo);
+        ApplicationInfo appInfo = mock(ApplicationInfo.class);
+
+        when(mIPackageManager.getApplicationInfo(
+                eq(PACKAGE_NAME_1),
+                eq(0L),
+                anyInt())
+        ).thenReturn(appInfo);
+
+        long createTimestamp = PACKAGE_ADD_TIMESTAMP_1
+                - (System.currentTimeMillis() - SystemClock.uptimeMillis());
+        FieldSetter.setField(appInfo,
+                ApplicationInfo.class.getDeclaredField("createTimestamp"),
+                createTimestamp);
+
+        int uid = USER_ID_1 * UserHandle.PER_USER_RANGE;
+        assertEquals(USER_ID_1, UserHandle.getUserId(uid));
+
+        // The following 2 usage events generation is the only difference from the
+        // testHandleUsageEvent_packageAddedNoUsageEvent test.
+        // These 2 usage events are triggered by INSTALLER_NAME_2.
+        // The 2 usage events make the package adding outside a time frame.
+        // Compared to testHandleUsageEvent_packageAddedInsideTimeFrame,
+        // it's a background install. Thus, it's not null for the return of
+        // mBackgroundInstallControlService.getBackgroundInstalledPackages()
+        doReturn(PackageManager.PERMISSION_GRANTED).when(mPermissionManager).checkPermission(
+                anyString(), anyString(), anyInt());
+        generateUsageEvent(UsageEvents.Event.ACTIVITY_RESUMED,
+                USER_ID_2, INSTALLER_NAME_2, USAGE_EVENT_TIMESTAMP_2);
+        generateUsageEvent(Event.ACTIVITY_STOPPED,
+                USER_ID_2, INSTALLER_NAME_2, USAGE_EVENT_TIMESTAMP_3);
+
+        mPackageListObserver.onPackageAdded(PACKAGE_NAME_1, uid);
+        mTestLooper.dispatchAll();
+
+        var packages = mBackgroundInstallControlService.getBackgroundInstalledPackages();
+        assertNotNull(packages);
+        assertEquals(1, packages.size());
+        assertTrue(packages.contains(USER_ID_1, PACKAGE_NAME_1));
+    }
+
+    @Test
+    public void testPackageRemoved() {
+        assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages());
+        mBackgroundInstallControlService.initBackgroundInstalledPackages();
+        var packages = mBackgroundInstallControlService.getBackgroundInstalledPackages();
+        assertNotNull(packages);
+
+        packages.add(USER_ID_1, PACKAGE_NAME_1);
+        packages.add(USER_ID_2, PACKAGE_NAME_2);
+
+        assertEquals(2, packages.size());
+        assertTrue(packages.contains(USER_ID_1, PACKAGE_NAME_1));
+        assertTrue(packages.contains(USER_ID_2, PACKAGE_NAME_2));
+
+        int uid = USER_ID_1 * UserHandle.PER_USER_RANGE;
+        assertEquals(USER_ID_1, UserHandle.getUserId(uid));
+
+        mPackageListObserver.onPackageRemoved(PACKAGE_NAME_1, uid);
+        mTestLooper.dispatchAll();
+
+        assertEquals(1, packages.size());
+        assertFalse(packages.contains(USER_ID_1, PACKAGE_NAME_1));
+        assertTrue(packages.contains(USER_ID_2, PACKAGE_NAME_2));
+    }
+
+    @Test
+    public void testGetBackgroundInstalledPackages() throws RemoteException {
+        assertNull(mBackgroundInstallControlService.getBackgroundInstalledPackages());
+        mBackgroundInstallControlService.initBackgroundInstalledPackages();
+        var bgPackages = mBackgroundInstallControlService.getBackgroundInstalledPackages();
+        assertNotNull(bgPackages);
+
+        bgPackages.add(USER_ID_1, PACKAGE_NAME_1);
+        bgPackages.add(USER_ID_2, PACKAGE_NAME_2);
+
+        assertEquals(2, bgPackages.size());
+        assertTrue(bgPackages.contains(USER_ID_1, PACKAGE_NAME_1));
+        assertTrue(bgPackages.contains(USER_ID_2, PACKAGE_NAME_2));
+
+        List<PackageInfo> packages = new ArrayList<>();
+        var packageInfo1 = makePackageInfo(PACKAGE_NAME_1);
+        packages.add(packageInfo1);
+        var packageInfo2 = makePackageInfo(PACKAGE_NAME_2);
+        packages.add(packageInfo2);
+        var packageInfo3 = makePackageInfo(PACKAGE_NAME_3);
+        packages.add(packageInfo3);
+        doReturn(new ParceledListSlice<>(packages)).when(mIPackageManager).getInstalledPackages(
+                anyLong(), anyInt());
+
+        var resultPackages =
+                mBackgroundInstallControlService.getBackgroundInstalledPackages(0L, USER_ID_1);
+        assertEquals(1, resultPackages.getList().size());
+        assertTrue(resultPackages.getList().contains(packageInfo1));
+        assertFalse(resultPackages.getList().contains(packageInfo2));
+        assertFalse(resultPackages.getList().contains(packageInfo3));
+    }
+
+    /**
+     * Mock a usage event occurring.
+     *
+     * @param usageEventId id of a usage event
+     * @param userId user id of a usage event
+     * @param pkgName package name of a usage event
+     * @param timestamp timestamp of a usage event
+     */
+    private void generateUsageEvent(int usageEventId,
+            int userId,
+            String pkgName,
+            long timestamp) {
+        Event event = new Event(usageEventId, timestamp);
+        event.mPackage = pkgName;
+        mUsageEventListener.onUsageEvent(userId, event);
+    }
+
+    private PackageInfo makePackageInfo(String packageName) {
+        PackageInfo pkg = new PackageInfo();
+        pkg.packageName = packageName;
+        pkg.applicationInfo = new ApplicationInfo();
+        return pkg;
+    }
+
+    private class MockInjector implements BackgroundInstallControlService.Injector {
+        private final Context mContext;
+
+        MockInjector(Context context) {
+            mContext = context;
+        }
+
+        @Override
+        public Context getContext() {
+            return mContext;
+        }
+
+        @Override
+        public IPackageManager getIPackageManager() {
+            return mIPackageManager;
+        }
+
+        @Override
+        public PackageManagerInternal getPackageManagerInternal() {
+            return mPackageManagerInternal;
+        }
+
+        @Override
+        public UsageStatsManagerInternal getUsageStatsManagerInternal() {
+            return mUsageStatsManagerInternal;
+        }
+
+        @Override
+        public PermissionManagerServiceInternal getPermissionManager() {
+            return mPermissionManager;
+        }
+
+        @Override
+        public Looper getLooper() {
+            return mLooper;
+        }
+
+        @Override
+        public File getDiskFile() {
+            return mFile;
+        }
+    }
+}
diff --git a/services/tests/servicestests/src/com/android/server/power/PowerGroupTest.java b/services/tests/servicestests/src/com/android/server/power/PowerGroupTest.java
index b034b0d..fe31b9c 100644
--- a/services/tests/servicestests/src/com/android/server/power/PowerGroupTest.java
+++ b/services/tests/servicestests/src/com/android/server/power/PowerGroupTest.java
@@ -257,7 +257,6 @@
                 .build();
 
         mPowerGroup.updateLocked(/* screenBrightnessOverride= */ BRIGHTNESS,
-                /* autoBrightness = */ false,
                 /* useProximitySensor= */ false,
                 /* boostScreenBrightness= */ false,
                 /* dozeScreenStateOverride= */ Display.STATE_ON,
@@ -273,7 +272,6 @@
                 mPowerGroup.mDisplayPowerRequest;
         assertThat(displayPowerRequest.policy).isEqualTo(POLICY_DIM);
         assertThat(displayPowerRequest.screenBrightnessOverride).isWithin(PRECISION).of(BRIGHTNESS);
-        assertThat(displayPowerRequest.useAutoBrightness).isEqualTo(false);
         assertThat(displayPowerRequest.useProximitySensor).isEqualTo(false);
         assertThat(displayPowerRequest.boostScreenBrightness).isEqualTo(false);
         assertThat(displayPowerRequest.dozeScreenState).isEqualTo(Display.STATE_UNKNOWN);
@@ -297,7 +295,6 @@
         mPowerGroup.setWakeLockSummaryLocked(WAKE_LOCK_DOZE);
 
         mPowerGroup.updateLocked(/* screenBrightnessOverride= */ BRIGHTNESS,
-                /* autoBrightness = */ true,
                 /* useProximitySensor= */ true,
                 /* boostScreenBrightness= */ true,
                 /* dozeScreenStateOverride= */ Display.STATE_ON,
@@ -313,7 +310,6 @@
                 mPowerGroup.mDisplayPowerRequest;
         assertThat(displayPowerRequest.policy).isEqualTo(POLICY_DOZE);
         assertThat(displayPowerRequest.screenBrightnessOverride).isWithin(PRECISION).of(BRIGHTNESS);
-        assertThat(displayPowerRequest.useAutoBrightness).isEqualTo(true);
         assertThat(displayPowerRequest.useProximitySensor).isEqualTo(true);
         assertThat(displayPowerRequest.boostScreenBrightness).isEqualTo(true);
         assertThat(displayPowerRequest.dozeScreenState).isEqualTo(Display.STATE_ON);
@@ -336,7 +332,6 @@
         assertThat(mPowerGroup.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_DOZING);
 
         mPowerGroup.updateLocked(/* screenBrightnessOverride= */ BRIGHTNESS,
-                /* autoBrightness = */ true,
                 /* useProximitySensor= */ true,
                 /* boostScreenBrightness= */ true,
                 /* dozeScreenStateOverride= */ Display.STATE_ON,
@@ -352,7 +347,6 @@
                 mPowerGroup.mDisplayPowerRequest;
         assertThat(displayPowerRequest.policy).isEqualTo(POLICY_OFF);
         assertThat(displayPowerRequest.screenBrightnessOverride).isWithin(PRECISION).of(BRIGHTNESS);
-        assertThat(displayPowerRequest.useAutoBrightness).isEqualTo(true);
         assertThat(displayPowerRequest.useProximitySensor).isEqualTo(true);
         assertThat(displayPowerRequest.boostScreenBrightness).isEqualTo(true);
         assertThat(displayPowerRequest.dozeScreenState).isEqualTo(Display.STATE_UNKNOWN);
@@ -374,7 +368,6 @@
         assertThat(mPowerGroup.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
 
         mPowerGroup.updateLocked(/* screenBrightnessOverride= */ BRIGHTNESS,
-                /* autoBrightness = */ true,
                 /* useProximitySensor= */ true,
                 /* boostScreenBrightness= */ true,
                 /* dozeScreenStateOverride= */ Display.STATE_ON,
@@ -390,7 +383,6 @@
                 mPowerGroup.mDisplayPowerRequest;
         assertThat(displayPowerRequest.policy).isEqualTo(POLICY_OFF);
         assertThat(displayPowerRequest.screenBrightnessOverride).isWithin(PRECISION).of(BRIGHTNESS);
-        assertThat(displayPowerRequest.useAutoBrightness).isEqualTo(true);
         assertThat(displayPowerRequest.useProximitySensor).isEqualTo(true);
         assertThat(displayPowerRequest.boostScreenBrightness).isEqualTo(true);
         assertThat(displayPowerRequest.dozeScreenState).isEqualTo(Display.STATE_UNKNOWN);
@@ -412,7 +404,6 @@
         mPowerGroup.sleepLocked(TIMESTAMP1, UID, GO_TO_SLEEP_REASON_TIMEOUT);
         assertThat(mPowerGroup.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP);
         mPowerGroup.updateLocked(/* screenBrightnessOverride= */ BRIGHTNESS,
-                /* autoBrightness = */ true,
                 /* useProximitySensor= */ true,
                 /* boostScreenBrightness= */ true,
                 /* dozeScreenStateOverride= */ Display.STATE_ON,
@@ -428,7 +419,6 @@
                 mPowerGroup.mDisplayPowerRequest;
         assertThat(displayPowerRequest.policy).isEqualTo(POLICY_OFF);
         assertThat(displayPowerRequest.screenBrightnessOverride).isWithin(PRECISION).of(BRIGHTNESS);
-        assertThat(displayPowerRequest.useAutoBrightness).isEqualTo(true);
         assertThat(displayPowerRequest.useProximitySensor).isEqualTo(true);
         assertThat(displayPowerRequest.boostScreenBrightness).isEqualTo(true);
         assertThat(displayPowerRequest.dozeScreenState).isEqualTo(Display.STATE_UNKNOWN);
@@ -451,7 +441,6 @@
         assertThat(mPowerGroup.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_DREAMING);
         mPowerGroup.setWakeLockSummaryLocked(WAKE_LOCK_SCREEN_BRIGHT);
         mPowerGroup.updateLocked(/* screenBrightnessOverride= */ BRIGHTNESS,
-                /* autoBrightness = */ true,
                 /* useProximitySensor= */ true,
                 /* boostScreenBrightness= */ true,
                 /* dozeScreenStateOverride= */ Display.STATE_ON,
@@ -467,7 +456,6 @@
                 mPowerGroup.mDisplayPowerRequest;
         assertThat(displayPowerRequest.policy).isEqualTo(POLICY_BRIGHT);
         assertThat(displayPowerRequest.screenBrightnessOverride).isWithin(PRECISION).of(BRIGHTNESS);
-        assertThat(displayPowerRequest.useAutoBrightness).isEqualTo(true);
         assertThat(displayPowerRequest.useProximitySensor).isEqualTo(true);
         assertThat(displayPowerRequest.boostScreenBrightness).isEqualTo(true);
         assertThat(displayPowerRequest.dozeScreenState).isEqualTo(Display.STATE_UNKNOWN);
@@ -488,7 +476,6 @@
                 .build();
         assertThat(mPowerGroup.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
         mPowerGroup.updateLocked(/* screenBrightnessOverride= */ BRIGHTNESS,
-                /* autoBrightness = */ true,
                 /* useProximitySensor= */ true,
                 /* boostScreenBrightness= */ true,
                 /* dozeScreenStateOverride= */ Display.STATE_ON,
@@ -504,7 +491,6 @@
                 mPowerGroup.mDisplayPowerRequest;
         assertThat(displayPowerRequest.policy).isEqualTo(POLICY_BRIGHT);
         assertThat(displayPowerRequest.screenBrightnessOverride).isWithin(PRECISION).of(BRIGHTNESS);
-        assertThat(displayPowerRequest.useAutoBrightness).isEqualTo(true);
         assertThat(displayPowerRequest.useProximitySensor).isEqualTo(true);
         assertThat(displayPowerRequest.boostScreenBrightness).isEqualTo(true);
         assertThat(displayPowerRequest.dozeScreenState).isEqualTo(Display.STATE_UNKNOWN);
@@ -526,7 +512,6 @@
         assertThat(mPowerGroup.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
         mPowerGroup.setUserActivitySummaryLocked(USER_ACTIVITY_SCREEN_BRIGHT);
         mPowerGroup.updateLocked(/* screenBrightnessOverride= */ BRIGHTNESS,
-                /* autoBrightness = */ true,
                 /* useProximitySensor= */ true,
                 /* boostScreenBrightness= */ true,
                 /* dozeScreenStateOverride= */ Display.STATE_ON,
@@ -542,7 +527,6 @@
                 mPowerGroup.mDisplayPowerRequest;
         assertThat(displayPowerRequest.policy).isEqualTo(POLICY_BRIGHT);
         assertThat(displayPowerRequest.screenBrightnessOverride).isWithin(PRECISION).of(BRIGHTNESS);
-        assertThat(displayPowerRequest.useAutoBrightness).isEqualTo(true);
         assertThat(displayPowerRequest.useProximitySensor).isEqualTo(true);
         assertThat(displayPowerRequest.boostScreenBrightness).isEqualTo(true);
         assertThat(displayPowerRequest.dozeScreenState).isEqualTo(Display.STATE_UNKNOWN);
@@ -563,7 +547,6 @@
                 .build();
         assertThat(mPowerGroup.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
         mPowerGroup.updateLocked(/* screenBrightnessOverride= */ BRIGHTNESS,
-                /* autoBrightness = */ true,
                 /* useProximitySensor= */ true,
                 /* boostScreenBrightness= */ true,
                 /* dozeScreenStateOverride= */ Display.STATE_ON,
@@ -579,7 +562,6 @@
                 mPowerGroup.mDisplayPowerRequest;
         assertThat(displayPowerRequest.policy).isEqualTo(POLICY_BRIGHT);
         assertThat(displayPowerRequest.screenBrightnessOverride).isWithin(PRECISION).of(BRIGHTNESS);
-        assertThat(displayPowerRequest.useAutoBrightness).isEqualTo(true);
         assertThat(displayPowerRequest.useProximitySensor).isEqualTo(true);
         assertThat(displayPowerRequest.boostScreenBrightness).isEqualTo(true);
         assertThat(displayPowerRequest.dozeScreenState).isEqualTo(Display.STATE_UNKNOWN);
diff --git a/services/tests/servicestests/src/com/android/server/power/ThermalManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/power/ThermalManagerServiceTest.java
index 3848bab..57f9f18 100644
--- a/services/tests/servicestests/src/com/android/server/power/ThermalManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/power/ThermalManagerServiceTest.java
@@ -30,8 +30,8 @@
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
-import android.hardware.thermal.V2_0.TemperatureThreshold;
-import android.hardware.thermal.V2_0.ThrottlingSeverity;
+import android.hardware.thermal.TemperatureThreshold;
+import android.hardware.thermal.ThrottlingSeverity;
 import android.os.CoolingDevice;
 import android.os.IBinder;
 import android.os.IPowerManager;
diff --git a/services/tests/servicestests/src/com/android/server/power/stats/BatteryStatsHistoryIteratorTest.java b/services/tests/servicestests/src/com/android/server/power/stats/BatteryStatsHistoryIteratorTest.java
index 22e44f8..71c8c1d 100644
--- a/services/tests/servicestests/src/com/android/server/power/stats/BatteryStatsHistoryIteratorTest.java
+++ b/services/tests/servicestests/src/com/android/server/power/stats/BatteryStatsHistoryIteratorTest.java
@@ -93,43 +93,44 @@
         }
 
         final BatteryStatsHistoryIterator iterator =
-                mBatteryStats.createBatteryStatsHistoryIterator();
+                mBatteryStats.iterateBatteryStatsHistory();
 
-        BatteryStats.HistoryItem item = new BatteryStats.HistoryItem();
+        BatteryStats.HistoryItem item;
 
-        assertThat(iterator.next(item)).isTrue();
+        assertThat(item = iterator.next()).isNotNull();
         assertHistoryItem(item,
                 BatteryStats.HistoryItem.CMD_RESET, BatteryStats.HistoryItem.EVENT_NONE,
                 null, 0, 3_600_000, 90, 1_000_000);
 
-        assertThat(iterator.next(item)).isTrue();
+        assertThat(item = iterator.next()).isNotNull();
         assertHistoryItem(item,
                 BatteryStats.HistoryItem.CMD_UPDATE, BatteryStats.HistoryItem.EVENT_NONE,
                 null, 0, 3_600_000, 90, 1_000_000);
 
-        assertThat(iterator.next(item)).isTrue();
+        assertThat(item = iterator.next()).isNotNull();
         assertHistoryItem(item,
                 BatteryStats.HistoryItem.CMD_UPDATE, BatteryStats.HistoryItem.EVENT_NONE,
                 null, 0, 2_400_000, 80, 2_000_000);
 
-        assertThat(iterator.next(item)).isTrue();
+        assertThat(item = iterator.next()).isNotNull();
         assertHistoryItem(item,
                 BatteryStats.HistoryItem.CMD_UPDATE, BatteryStats.HistoryItem.EVENT_NONE,
                 null, 0, 2_400_000, 80, 2_000_000);
 
-        assertThat(iterator.next(item)).isTrue();
+        assertThat(item = iterator.next()).isNotNull();
         assertHistoryItem(item,
                 BatteryStats.HistoryItem.CMD_UPDATE,
                 BatteryStats.HistoryItem.EVENT_ALARM | BatteryStats.HistoryItem.EVENT_FLAG_START,
                 "foo", APP_UID, 2_400_000, 80, 3_000_000);
 
-        assertThat(iterator.next(item)).isTrue();
+        assertThat(item = iterator.next()).isNotNull();
         assertHistoryItem(item,
                 BatteryStats.HistoryItem.CMD_UPDATE,
                 BatteryStats.HistoryItem.EVENT_ALARM | BatteryStats.HistoryItem.EVENT_FLAG_FINISH,
                 "foo", APP_UID, 2_400_000, 80, 3_001_000);
 
-        assertThat(iterator.next(item)).isFalse();
+        assertThat(iterator.hasNext()).isFalse();
+        assertThat(iterator.next()).isNull();
     }
 
     // Test history that spans multiple buffers and uses more than 32k different strings.
@@ -163,21 +164,21 @@
         }
 
         final BatteryStatsHistoryIterator iterator =
-                mBatteryStats.createBatteryStatsHistoryIterator();
+                mBatteryStats.iterateBatteryStatsHistory();
 
-        BatteryStats.HistoryItem item = new BatteryStats.HistoryItem();
-        assertThat(iterator.next(item)).isTrue();
+        BatteryStats.HistoryItem item;
+        assertThat(item = iterator.next()).isNotNull();
         assertThat(item.cmd).isEqualTo((int) BatteryStats.HistoryItem.CMD_RESET);
         assertThat(item.eventCode).isEqualTo(BatteryStats.HistoryItem.EVENT_NONE);
         assertThat(item.eventTag).isNull();
 
-        assertThat(iterator.next(item)).isTrue();
+        assertThat(item = iterator.next()).isNotNull();
         assertThat(item.cmd).isEqualTo((int) BatteryStats.HistoryItem.CMD_UPDATE);
         assertThat(item.eventCode).isEqualTo(BatteryStats.HistoryItem.EVENT_NONE);
         assertThat(item.eventTag).isNull();
         assertThat(item.time).isEqualTo(1_000_000);
 
-        assertThat(iterator.next(item)).isTrue();
+        assertThat(item = iterator.next()).isNotNull();
         assertThat(item.cmd).isEqualTo((int) BatteryStats.HistoryItem.CMD_UPDATE);
         assertThat(item.eventCode).isEqualTo(BatteryStats.HistoryItem.EVENT_NONE);
         assertThat(item.eventTag).isNull();
@@ -186,7 +187,7 @@
         for (int i = 0; i < eventCount; i++) {
             String name = "a" + (i % 10);
             do {
-                assertThat(iterator.next(item)).isTrue();
+                assertThat(item = iterator.next()).isNotNull();
                 // Skip a blank event inserted at the start of every buffer
             } while (item.cmd != BatteryStats.HistoryItem.CMD_UPDATE
                     || item.eventCode == BatteryStats.HistoryItem.EVENT_NONE);
@@ -196,7 +197,7 @@
             assertThat(item.eventTag.string).isEqualTo(name);
 
             do {
-                assertThat(iterator.next(item)).isTrue();
+                assertThat(item = iterator.next()).isNotNull();
             } while (item.cmd != BatteryStats.HistoryItem.CMD_UPDATE
                     || item.eventCode == BatteryStats.HistoryItem.EVENT_NONE);
 
@@ -205,7 +206,8 @@
             assertThat(item.eventTag.string).isEqualTo(name);
         }
 
-        assertThat(iterator.next(item)).isFalse();
+        assertThat(iterator.hasNext()).isFalse();
+        assertThat(iterator.next()).isNull();
     }
 
     private void assertHistoryItem(BatteryStats.HistoryItem item, int command, int eventCode,
diff --git a/services/tests/servicestests/src/com/android/server/power/stats/BatteryStatsHistoryTest.java b/services/tests/servicestests/src/com/android/server/power/stats/BatteryStatsHistoryTest.java
index 3f5d331..22a7e8d 100644
--- a/services/tests/servicestests/src/com/android/server/power/stats/BatteryStatsHistoryTest.java
+++ b/services/tests/servicestests/src/com/android/server/power/stats/BatteryStatsHistoryTest.java
@@ -309,10 +309,10 @@
         mHistory.recordMeasuredEnergyDetails(200, 200, details);
 
         BatteryStatsHistoryIterator iterator = mHistory.iterate();
-        BatteryStats.HistoryItem item = new BatteryStats.HistoryItem();
-        assertThat(iterator.next(item)).isTrue(); // First item contains current time only
+        BatteryStats.HistoryItem item;
+        assertThat(item = iterator.next()).isNotNull(); // First item contains current time only
 
-        assertThat(iterator.next(item)).isTrue();
+        assertThat(item = iterator.next()).isNotNull();
 
         String dump = toString(item, /* checkin */ false);
         assertThat(dump).contains("+200ms");
@@ -344,9 +344,9 @@
 
         BatteryStatsHistoryIterator iterator = mHistory.iterate();
         BatteryStats.HistoryItem item = new BatteryStats.HistoryItem();
-        assertThat(iterator.next(item)).isTrue(); // First item contains current time only
+        assertThat(item = iterator.next()).isNotNull(); // First item contains current time only
 
-        assertThat(iterator.next(item)).isTrue();
+        assertThat(item = iterator.next()).isNotNull();
 
         String dump = toString(item, /* checkin */ false);
         assertThat(dump).contains("+200ms");
@@ -361,7 +361,7 @@
         assertThat(checkin).contains("XB,3,2,HIGH");
         assertThat(checkin).contains("XC,10123,100,200,300");
 
-        assertThat(iterator.next(item)).isTrue();
+        assertThat(item = iterator.next()).isNotNull();
 
         dump = toString(item, /* checkin */ false);
         assertThat(dump).contains("+300ms");
diff --git a/services/tests/servicestests/src/com/android/server/power/stats/BatteryStatsNoteTest.java b/services/tests/servicestests/src/com/android/server/power/stats/BatteryStatsNoteTest.java
index e9c5b01..773a2dc 100644
--- a/services/tests/servicestests/src/com/android/server/power/stats/BatteryStatsNoteTest.java
+++ b/services/tests/servicestests/src/com/android/server/power/stats/BatteryStatsNoteTest.java
@@ -83,6 +83,7 @@
  * Run: adb shell am instrument -e class BatteryStatsNoteTest -w \
  *      com.android.frameworks.coretests/androidx.test.runner.AndroidJUnitRunner
  */
+@SuppressWarnings("GuardedBy")
 public class BatteryStatsNoteTest extends TestCase {
     private static final String TAG = BatteryStatsNoteTest.class.getSimpleName();
 
@@ -271,11 +272,11 @@
         clocks.realtime = clocks.uptime = 220;
         bi.noteLongPartialWakelockFinish(name, historyName, ISOLATED_UID);
 
-        final BatteryStatsHistoryIterator iterator =  bi.createBatteryStatsHistoryIterator();
+        final BatteryStatsHistoryIterator iterator =  bi.iterateBatteryStatsHistory();
 
-        BatteryStats.HistoryItem item = new BatteryStats.HistoryItem();
+        BatteryStats.HistoryItem item;
 
-        while (iterator.next(item)) {
+        while ((item = iterator.next()) != null) {
             if (item.eventCode == HistoryItem.EVENT_LONG_WAKE_LOCK_START) break;
         }
         assertThat(item.eventCode).isEqualTo(HistoryItem.EVENT_LONG_WAKE_LOCK_START);
@@ -283,7 +284,7 @@
         assertThat(item.eventTag.string).isEqualTo(historyName);
         assertThat(item.eventTag.uid).isEqualTo(UID);
 
-        while (iterator.next(item)) {
+        while ((item = iterator.next()) != null) {
             if (item.eventCode == HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH) break;
         }
         assertThat(item.eventCode).isEqualTo(HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH);
@@ -327,11 +328,11 @@
         clocks.realtime = clocks.uptime = 220;
         bi.noteLongPartialWakelockFinish(name, historyName, ISOLATED_UID);
 
-        final BatteryStatsHistoryIterator iterator = bi.createBatteryStatsHistoryIterator();
+        final BatteryStatsHistoryIterator iterator = bi.iterateBatteryStatsHistory();
 
-        BatteryStats.HistoryItem item = new BatteryStats.HistoryItem();
+        BatteryStats.HistoryItem item;
 
-        while (iterator.next(item)) {
+        while ((item = iterator.next()) != null) {
             if (item.eventCode == HistoryItem.EVENT_LONG_WAKE_LOCK_START) break;
         }
         assertThat(item.eventCode).isEqualTo(HistoryItem.EVENT_LONG_WAKE_LOCK_START);
@@ -339,7 +340,7 @@
         assertThat(item.eventTag.string).isEqualTo(historyName);
         assertThat(item.eventTag.uid).isEqualTo(UID);
 
-        while (iterator.next(item)) {
+        while ((item = iterator.next()) != null) {
             if (item.eventCode == HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH) break;
         }
         assertThat(item.eventCode).isEqualTo(HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH);
@@ -359,6 +360,7 @@
         // map of ActivityManager process states and how long to simulate run time in each state
         Map<Integer, Integer> stateRuntimeMap = new HashMap<Integer, Integer>();
         stateRuntimeMap.put(ActivityManager.PROCESS_STATE_TOP, 1111);
+        stateRuntimeMap.put(ActivityManager.PROCESS_STATE_BOUND_TOP, 7382);
         stateRuntimeMap.put(ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE, 1234);
         stateRuntimeMap.put(ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE, 2468);
         stateRuntimeMap.put(ActivityManager.PROCESS_STATE_TOP_SLEEPING, 7531);
@@ -395,7 +397,8 @@
 
         actualRunTimeUs = uid.getProcessStateTime(BatteryStats.Uid.PROCESS_STATE_FOREGROUND_SERVICE,
                 elapsedTimeUs, STATS_SINCE_CHARGED);
-        expectedRunTimeMs = stateRuntimeMap.get(ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE);
+        expectedRunTimeMs = stateRuntimeMap.get(ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE)
+                + stateRuntimeMap.get(ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE);
         assertEquals(expectedRunTimeMs * 1000, actualRunTimeUs);
 
         actualRunTimeUs = uid.getProcessStateTime(BatteryStats.Uid.PROCESS_STATE_TOP_SLEEPING,
@@ -405,8 +408,7 @@
 
         actualRunTimeUs = uid.getProcessStateTime(BatteryStats.Uid.PROCESS_STATE_FOREGROUND,
                 elapsedTimeUs, STATS_SINCE_CHARGED);
-        expectedRunTimeMs = stateRuntimeMap.get(ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND)
-                + stateRuntimeMap.get(ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE);
+        expectedRunTimeMs = stateRuntimeMap.get(ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND);
         assertEquals(expectedRunTimeMs * 1000, actualRunTimeUs);
 
         actualRunTimeUs = uid.getProcessStateTime(BatteryStats.Uid.PROCESS_STATE_BACKGROUND,
@@ -414,7 +416,8 @@
         expectedRunTimeMs = stateRuntimeMap.get(ActivityManager.PROCESS_STATE_TRANSIENT_BACKGROUND)
                 + stateRuntimeMap.get(ActivityManager.PROCESS_STATE_BACKUP)
                 + stateRuntimeMap.get(ActivityManager.PROCESS_STATE_SERVICE)
-                + stateRuntimeMap.get(ActivityManager.PROCESS_STATE_RECEIVER);
+                + stateRuntimeMap.get(ActivityManager.PROCESS_STATE_RECEIVER)
+                + stateRuntimeMap.get(ActivityManager.PROCESS_STATE_BOUND_TOP);
         assertEquals(expectedRunTimeMs * 1000, actualRunTimeUs);
 
         actualRunTimeUs = uid.getProcessStateTime(BatteryStats.Uid.PROCESS_STATE_CACHED,
@@ -939,26 +942,27 @@
         clocks.realtime = clocks.uptime = 5000;
         bi.noteAlarmFinishLocked("foo", null, UID);
 
-        HistoryItem item = new HistoryItem();
-        assertTrue(bi.startIteratingHistoryLocked());
+        BatteryStatsHistoryIterator iterator = bi.iterateBatteryStatsHistory();
+        HistoryItem item;
 
-        assertTrue(bi.getNextHistoryLocked(item));
+        assertThat(item = iterator.next()).isNotNull();
         assertEquals(HistoryItem.EVENT_ALARM_START, item.eventCode);
         assertEquals("foo", item.eventTag.string);
         assertEquals(UID, item.eventTag.uid);
 
         // TODO(narayan): Figure out why this event is written to the history buffer. See
         // test below where it is being interspersed between multiple START events too.
-        assertTrue(bi.getNextHistoryLocked(item));
+        assertThat(item = iterator.next()).isNotNull();
         assertEquals(HistoryItem.EVENT_NONE, item.eventCode);
 
-        assertTrue(bi.getNextHistoryLocked(item));
+        assertThat(item = iterator.next()).isNotNull();
         assertEquals(HistoryItem.EVENT_ALARM_FINISH, item.eventCode);
         assertTrue(item.isDeltaData());
         assertEquals("foo", item.eventTag.string);
         assertEquals(UID, item.eventTag.uid);
 
-        assertFalse(bi.getNextHistoryLocked(item));
+        assertThat(iterator.hasNext()).isFalse();
+        assertThat(iterator.next()).isNull();
     }
 
     @SmallTest
@@ -978,28 +982,28 @@
         clocks.realtime = clocks.uptime = 5000;
         bi.noteAlarmFinishLocked("foo", ws, UID);
 
-        HistoryItem item = new HistoryItem();
-        assertTrue(bi.startIteratingHistoryLocked());
+        BatteryStatsHistoryIterator iterator = bi.iterateBatteryStatsHistory();
+        HistoryItem item;
 
-        assertTrue(bi.getNextHistoryLocked(item));
+        assertThat(item = iterator.next()).isNotNull();
         assertEquals(HistoryItem.EVENT_ALARM_START, item.eventCode);
         assertEquals("foo", item.eventTag.string);
         assertEquals(100, item.eventTag.uid);
 
-        assertTrue(bi.getNextHistoryLocked(item));
+        assertThat(item = iterator.next()).isNotNull();
         assertEquals(HistoryItem.EVENT_NONE, item.eventCode);
 
-        assertTrue(bi.getNextHistoryLocked(item));
+        assertThat(item = iterator.next()).isNotNull();
         assertEquals(HistoryItem.EVENT_ALARM_START, item.eventCode);
         assertEquals("foo", item.eventTag.string);
         assertEquals(500, item.eventTag.uid);
 
-        assertTrue(bi.getNextHistoryLocked(item));
+        assertThat(item = iterator.next()).isNotNull();
         assertEquals(HistoryItem.EVENT_ALARM_FINISH, item.eventCode);
         assertEquals("foo", item.eventTag.string);
         assertEquals(100, item.eventTag.uid);
 
-        assertTrue(bi.getNextHistoryLocked(item));
+        assertThat(item = iterator.next()).isNotNull();
         assertEquals(HistoryItem.EVENT_ALARM_FINISH, item.eventCode);
         assertEquals("foo", item.eventTag.string);
         assertEquals(500, item.eventTag.uid);
diff --git a/services/tests/servicestests/src/com/android/server/power/stats/BatteryUsageStatsProviderTest.java b/services/tests/servicestests/src/com/android/server/power/stats/BatteryUsageStatsProviderTest.java
index b313fa4..968609b 100644
--- a/services/tests/servicestests/src/com/android/server/power/stats/BatteryUsageStatsProviderTest.java
+++ b/services/tests/servicestests/src/com/android/server/power/stats/BatteryUsageStatsProviderTest.java
@@ -78,9 +78,9 @@
                 batteryUsageStats.getUidBatteryConsumers();
         final UidBatteryConsumer uidBatteryConsumer = uidBatteryConsumers.get(0);
         assertThat(uidBatteryConsumer.getTimeInStateMs(UidBatteryConsumer.STATE_FOREGROUND))
-                .isEqualTo(60 * MINUTE_IN_MS);
+                .isEqualTo(20 * MINUTE_IN_MS);
         assertThat(uidBatteryConsumer.getTimeInStateMs(UidBatteryConsumer.STATE_BACKGROUND))
-                .isEqualTo(10 * MINUTE_IN_MS);
+                .isEqualTo(40 * MINUTE_IN_MS);
         assertThat(uidBatteryConsumer.getConsumedPower(BatteryConsumer.POWER_COMPONENT_AUDIO))
                 .isWithin(PRECISION).of(2.0);
         assertThat(
@@ -121,40 +121,44 @@
     private BatteryStatsImpl prepareBatteryStats() {
         BatteryStatsImpl batteryStats = mStatsRule.getBatteryStats();
 
+        mStatsRule.setTime(10 * MINUTE_IN_MS, 10 * MINUTE_IN_MS);
         synchronized (batteryStats) {
-            batteryStats.noteActivityResumedLocked(APP_UID,
-                    10 * MINUTE_IN_MS, 10 * MINUTE_IN_MS);
-        }
-        synchronized (batteryStats) {
-            batteryStats.noteUidProcessStateLocked(APP_UID,
-                    ActivityManager.PROCESS_STATE_TOP,
-                    10 * MINUTE_IN_MS, 10 * MINUTE_IN_MS);
-        }
-        synchronized (batteryStats) {
-            batteryStats.noteActivityPausedLocked(APP_UID,
-                    30 * MINUTE_IN_MS, 30 * MINUTE_IN_MS);
-        }
-        synchronized (batteryStats) {
-            batteryStats.noteUidProcessStateLocked(APP_UID,
-                    ActivityManager.PROCESS_STATE_SERVICE,
-                    30 * MINUTE_IN_MS, 30 * MINUTE_IN_MS);
-        }
-        synchronized (batteryStats) {
-            batteryStats.noteUidProcessStateLocked(APP_UID,
-                    ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE,
-                    40 * MINUTE_IN_MS, 40 * MINUTE_IN_MS);
-        }
-        synchronized (batteryStats) {
-            batteryStats.noteUidProcessStateLocked(APP_UID,
-                    ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE,
-                    50 * MINUTE_IN_MS, 50 * MINUTE_IN_MS);
-        }
-        synchronized (batteryStats) {
-            batteryStats.noteUidProcessStateLocked(APP_UID,
-                    ActivityManager.PROCESS_STATE_CACHED_EMPTY,
-                    80 * MINUTE_IN_MS, 80 * MINUTE_IN_MS);
+            batteryStats.noteActivityResumedLocked(APP_UID);
         }
 
+        mStatsRule.setTime(10 * MINUTE_IN_MS, 10 * MINUTE_IN_MS);
+        synchronized (batteryStats) {
+            batteryStats.noteUidProcessStateLocked(APP_UID, ActivityManager.PROCESS_STATE_TOP);
+        }
+        mStatsRule.setTime(30 * MINUTE_IN_MS, 30 * MINUTE_IN_MS);
+        synchronized (batteryStats) {
+            batteryStats.noteActivityPausedLocked(APP_UID);
+        }
+        mStatsRule.setTime(30 * MINUTE_IN_MS, 30 * MINUTE_IN_MS);
+        synchronized (batteryStats) {
+            batteryStats.noteUidProcessStateLocked(APP_UID,
+                    ActivityManager.PROCESS_STATE_SERVICE);
+        }
+        mStatsRule.setTime(40 * MINUTE_IN_MS, 40 * MINUTE_IN_MS);
+        synchronized (batteryStats) {
+            batteryStats.noteUidProcessStateLocked(APP_UID,
+                    ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE);
+        }
+        mStatsRule.setTime(50 * MINUTE_IN_MS, 50 * MINUTE_IN_MS);
+        synchronized (batteryStats) {
+            batteryStats.noteUidProcessStateLocked(APP_UID,
+                    ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE);
+        }
+        mStatsRule.setTime(60 * MINUTE_IN_MS, 60 * MINUTE_IN_MS);
+        synchronized (batteryStats) {
+            batteryStats.noteUidProcessStateLocked(APP_UID,
+                    ActivityManager.PROCESS_STATE_BOUND_TOP);
+        }
+        mStatsRule.setTime(70 * MINUTE_IN_MS, 70 * MINUTE_IN_MS);
+        synchronized (batteryStats) {
+            batteryStats.noteUidProcessStateLocked(APP_UID,
+                    ActivityManager.PROCESS_STATE_CACHED_EMPTY);
+        }
         synchronized (batteryStats) {
             batteryStats.noteFlashlightOnLocked(APP_UID, 1000, 1000);
         }
@@ -215,36 +219,37 @@
 
         final BatteryStatsHistoryIterator iterator =
                 unparceled.iterateBatteryStatsHistory();
-        BatteryStats.HistoryItem item = new BatteryStats.HistoryItem();
+        BatteryStats.HistoryItem item;
 
-        assertThat(iterator.next(item)).isTrue();
+        assertThat(item = iterator.next()).isNotNull();
         assertHistoryItem(item,
                 BatteryStats.HistoryItem.CMD_RESET, BatteryStats.HistoryItem.EVENT_NONE,
                 null, 0, 3_600_000, 90, 1_000_000);
 
-        assertThat(iterator.next(item)).isTrue();
+        assertThat(item = iterator.next()).isNotNull();
         assertHistoryItem(item,
                 BatteryStats.HistoryItem.CMD_UPDATE, BatteryStats.HistoryItem.EVENT_NONE,
                 null, 0, 3_600_000, 90, 1_000_000);
 
-        assertThat(iterator.next(item)).isTrue();
+        assertThat(item = iterator.next()).isNotNull();
         assertHistoryItem(item,
                 BatteryStats.HistoryItem.CMD_UPDATE, BatteryStats.HistoryItem.EVENT_NONE,
                 null, 0, 3_600_000, 90, 2_000_000);
 
-        assertThat(iterator.next(item)).isTrue();
+        assertThat(item = iterator.next()).isNotNull();
         assertHistoryItem(item,
                 BatteryStats.HistoryItem.CMD_UPDATE,
                 BatteryStats.HistoryItem.EVENT_ALARM | BatteryStats.HistoryItem.EVENT_FLAG_START,
                 "foo", APP_UID, 3_600_000, 90, 3_000_000);
 
-        assertThat(iterator.next(item)).isTrue();
+        assertThat(item = iterator.next()).isNotNull();
         assertHistoryItem(item,
                 BatteryStats.HistoryItem.CMD_UPDATE,
                 BatteryStats.HistoryItem.EVENT_ALARM | BatteryStats.HistoryItem.EVENT_FLAG_FINISH,
                 "foo", APP_UID, 3_600_000, 90, 3_001_000);
 
-        assertThat(iterator.next(item)).isFalse();
+        assertThat(iterator.hasNext()).isFalse();
+        assertThat(iterator.next()).isNull();
     }
 
     @Test
@@ -300,16 +305,16 @@
                 BatteryUsageStats.class);
 
         BatteryStatsHistoryIterator iterator = unparceled.iterateBatteryStatsHistory();
-        BatteryStats.HistoryItem item = new BatteryStats.HistoryItem();
+        BatteryStats.HistoryItem item;
 
-        assertThat(iterator.next(item)).isTrue();
+        assertThat(item = iterator.next()).isNotNull();
         assertThat(item.cmd).isEqualTo((int) BatteryStats.HistoryItem.CMD_RESET);
 
         int expectedUid = 1;
-        while (iterator.next(item)) {
+        while ((item = iterator.next()) != null) {
             while (item.cmd != BatteryStats.HistoryItem.CMD_UPDATE
                     || item.eventCode == BatteryStats.HistoryItem.EVENT_NONE) {
-                assertThat(iterator.next(item)).isTrue();
+                assertThat(item = iterator.next()).isNotNull();
             }
             int uid = item.eventTag.uid;
             assertThat(uid).isEqualTo(expectedUid++);
diff --git a/services/tests/servicestests/src/com/android/server/systemconfig/SystemConfigTest.java b/services/tests/servicestests/src/com/android/server/systemconfig/SystemConfigTest.java
index 92c7871..16c213c 100644
--- a/services/tests/servicestests/src/com/android/server/systemconfig/SystemConfigTest.java
+++ b/services/tests/servicestests/src/com/android/server/systemconfig/SystemConfigTest.java
@@ -405,12 +405,11 @@
 
         mSysConfig.readApexPrivAppPermissions(parser, permissionFile, apexDir.toPath());
 
-        assertThat(mSysConfig.getApexPrivAppPermissions("com.android.my_module",
-                "com.android.apk_in_apex"))
-            .containsExactly("android.permission.FOO");
-        assertThat(mSysConfig.getApexPrivAppDenyPermissions("com.android.my_module",
-                "com.android.apk_in_apex"))
-            .containsExactly("android.permission.BAR");
+        ArrayMap<String, Boolean> permissions = mSysConfig.getPermissionAllowlist()
+                .getApexPrivilegedAppAllowlists().get("com.android.my_module")
+                .get("com.android.apk_in_apex");
+        assertThat(permissions)
+            .containsExactly("android.permission.FOO", true, "android.permission.BAR", false);
     }
 
     /**
diff --git a/services/tests/wmtests/AndroidManifest.xml b/services/tests/wmtests/AndroidManifest.xml
index 107bbe1..593ee4a 100644
--- a/services/tests/wmtests/AndroidManifest.xml
+++ b/services/tests/wmtests/AndroidManifest.xml
@@ -45,6 +45,7 @@
     <uses-permission android:name="android.permission.WRITE_DEVICE_CONFIG" />
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+    <uses-permission android:name="android.permission.MANAGE_MEDIA_PROJECTION"/>
 
     <!-- TODO: Remove largeHeap hack when memory leak is fixed (b/123984854) -->
     <application android:debuggable="true"
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java
index ee31748..43627f4 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java
@@ -62,11 +62,13 @@
 import static com.android.server.wm.TaskFragment.EMBEDDING_DISALLOWED_UNTRUSTED_HOST;
 import static com.android.server.wm.WindowContainer.POSITION_BOTTOM;
 import static com.android.server.wm.WindowContainer.POSITION_TOP;
+import static com.android.server.wm.WindowTestsBase.ActivityBuilder.DEFAULT_FAKE_UID;
 
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -1617,6 +1619,130 @@
         assertNull(starter2.mMovedToTopActivity);
     }
 
+    /**
+     * Tests a task with specific display category exist in system and then launching another
+     * activity with the same affinity but without define the display category. Make sure the
+     * lunching activity is placed on the different task.
+     */
+    @Test
+    public void testLaunchActivityWithoutDisplayCategory() {
+        final ActivityInfo info = new ActivityInfo();
+        info.applicationInfo = new ApplicationInfo();
+        info.taskAffinity = ActivityRecord.computeTaskAffinity("test", DEFAULT_FAKE_UID,
+                0 /* launchMode */);
+        info.requiredDisplayCategory = "automotive";
+        final Task task = new TaskBuilder(mSupervisor).setCreateActivity(true).setActivityInfo(info)
+                .build();
+
+        final ActivityRecord target = new ActivityBuilder(mAtm).setAffinity(info.taskAffinity)
+                .build();
+        final ActivityStarter starter = prepareStarter(FLAG_ACTIVITY_NEW_TASK, false);
+        spyOn(starter);
+        doReturn(START_SUCCESS).when(starter).isAllowedToStart(any(), anyBoolean(), any());
+        startActivityInner(starter, target, null /* source */, null /* options */,
+                null /* inTask */, null /* inTaskFragment */);
+
+        assertNotEquals(task, target.getTask());
+    }
+
+    /**
+     * Tests a task with a specific display category exist in the system and then launches another
+     * activity with the different display category. Make sure the launching activity is not placed
+     * on the sourceRecord's task.
+     */
+    @Test
+    public void testLaunchActivityWithDifferentDisplayCategory() {
+        final ActivityInfo info = new ActivityInfo();
+        info.applicationInfo = new ApplicationInfo();
+        info.taskAffinity = ActivityRecord.computeTaskAffinity("test", DEFAULT_FAKE_UID,
+                0 /* launchMode */);
+        info.requiredDisplayCategory = "automotive";
+        final Task task = new TaskBuilder(mSupervisor).setCreateActivity(true).setActivityInfo(info)
+                .build();
+
+        final ActivityRecord target = new ActivityBuilder(mAtm).setRequiredDisplayCategory("auto")
+                .setAffinity(info.taskAffinity).build();
+        final ActivityStarter starter = prepareStarter(0, false);
+        spyOn(starter);
+        doReturn(START_SUCCESS).when(starter).isAllowedToStart(any(), anyBoolean(), any());
+        startActivityInner(starter, target,  task.getBottomMostActivity(), null /* options */,
+                null /* inTask */, null /* inTaskFragment */);
+
+        assertNotEquals(task, target.getTask());
+    }
+
+    /**
+     * Tests a task with specific display category exist in system and then launching another
+     * activity with the same display category. Make sure the launching activity is placed on the
+     * same task.
+     */
+    @Test
+    public void testLaunchActivityWithSameDisplayCategory() {
+        final ActivityInfo info = new ActivityInfo();
+        info.applicationInfo = new ApplicationInfo();
+        info.taskAffinity = ActivityRecord.computeTaskAffinity("test", DEFAULT_FAKE_UID,
+                0 /* launchMode */);
+        info.requiredDisplayCategory = "automotive";
+        final Task task = new TaskBuilder(mSupervisor).setCreateActivity(true).setActivityInfo(info)
+                .build();
+
+        final ActivityRecord target = new ActivityBuilder(mAtm)
+                .setRequiredDisplayCategory(info.requiredDisplayCategory)
+                .setAffinity(info.taskAffinity).build();
+
+        final ActivityStarter starter = prepareStarter(0, false);
+        spyOn(starter);
+        doReturn(START_SUCCESS).when(starter).isAllowedToStart(any(), anyBoolean(), any());
+        startActivityInner(starter, target,  task.getBottomMostActivity(), null /* options */,
+                null /* inTask */, null /* inTaskFragment */);
+
+        assertEquals(task, target.getTask());
+    }
+
+    /**
+     * Tests a task with specific display category exist in system and launching activity into the
+     * specific task within inTask attribute. Make sure the activity is not placed on the task since
+     * the display category is different.
+     */
+    @Test
+    public void testLaunchActivityInTaskWithDisplayCategory() {
+        final ActivityInfo info = new ActivityInfo();
+        info.applicationInfo = new ApplicationInfo();
+        info.requiredDisplayCategory = "automotive";
+        final Task inTask = new TaskBuilder(mSupervisor).setActivityInfo(info).build();
+        inTask.inRecents = true;
+
+        final ActivityStarter starter = prepareStarter(0, false);
+        spyOn(starter);
+        doReturn(START_SUCCESS).when(starter).isAllowedToStart(any(), anyBoolean(), any());
+        final ActivityRecord target = new ActivityBuilder(mAtm).build();
+        startActivityInner(starter, target, null /* source */, null /* options */, inTask,
+                null /* inTaskFragment */);
+
+        assertNotEquals(inTask, target.getTask());
+    }
+
+    /**
+     * Tests a task without a specific display category exist in the system and launches activity
+     * with display category into the task within the inTask attribute. Make sure the activity is
+     * not placed on the task since the display category is different.
+     */
+    @Test
+    public void testLaunchDisplayCategoryActivityInTask() {
+        final Task inTask = new TaskBuilder(mSupervisor).build();
+        inTask.inRecents = true;
+
+        final ActivityStarter starter = prepareStarter(0, false);
+        spyOn(starter);
+        doReturn(START_SUCCESS).when(starter).isAllowedToStart(any(), anyBoolean(), any());
+        final ActivityRecord target = new ActivityBuilder(mAtm).setRequiredDisplayCategory("auto")
+                .build();
+        startActivityInner(starter, target, null /* source */, null /* options */, inTask,
+                null /* inTaskFragment */);
+
+        assertNotEquals(inTask, target.getTask());
+    }
+
     private static void startActivityInner(ActivityStarter starter, ActivityRecord target,
             ActivityRecord source, ActivityOptions options, Task inTask,
             TaskFragment inTaskFragment) {
diff --git a/services/tests/wmtests/src/com/android/server/wm/BackNavigationControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/BackNavigationControllerTests.java
index 3bce860..1b77c95 100644
--- a/services/tests/wmtests/src/com/android/server/wm/BackNavigationControllerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/BackNavigationControllerTests.java
@@ -20,24 +20,23 @@
 import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
 import static android.window.BackNavigationInfo.typeToString;
 
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
+
 import static com.google.common.truth.Truth.assertThat;
 import static com.google.common.truth.Truth.assertWithMessage;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyBoolean;
 import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import android.annotation.NonNull;
 import android.annotation.Nullable;
-import android.hardware.HardwareBuffer;
 import android.os.RemoteException;
 import android.platform.test.annotations.Presubmit;
 import android.view.WindowManager;
@@ -48,7 +47,6 @@
 import android.window.OnBackInvokedCallback;
 import android.window.OnBackInvokedCallbackInfo;
 import android.window.OnBackInvokedDispatcher;
-import android.window.TaskSnapshot;
 import android.window.WindowOnBackInvokedDispatcher;
 
 import com.android.server.LocalServices;
@@ -67,6 +65,7 @@
     private BackNavigationController mBackNavigationController;
     private WindowManagerInternal mWindowManagerInternal;
     private BackAnimationAdapter mBackAnimationAdapter;
+    private Task mRootHomeTask;
 
     @Before
     public void setUp() throws Exception {
@@ -76,6 +75,7 @@
         LocalServices.addService(WindowManagerInternal.class, mWindowManagerInternal);
         mBackNavigationController.setWindowManager(mWm);
         mBackAnimationAdapter = mock(BackAnimationAdapter.class);
+        mRootHomeTask = initHomeActivity();
     }
 
     @Test
@@ -101,7 +101,8 @@
         ActivityRecord recordA = createActivityRecord(taskA);
         Mockito.doNothing().when(recordA).reparentSurfaceControl(any(), any());
 
-        withSystemCallback(createTopTaskWithActivity());
+        final Task topTask = createTopTaskWithActivity();
+        withSystemCallback(topTask);
         BackNavigationInfo backNavigationInfo = startBackNavigation();
         assertWithMessage("BackNavigationInfo").that(backNavigationInfo).isNotNull();
         assertThat(typeToString(backNavigationInfo.getType()))
@@ -111,6 +112,20 @@
         verify(mBackNavigationController).scheduleAnimationLocked(
                 eq(BackNavigationInfo.TYPE_CROSS_TASK), any(), eq(mBackAnimationAdapter),
                 any());
+
+        // reset drawning status
+        topTask.forAllWindows(w -> {
+            makeWindowVisibleAndDrawn(w);
+        }, true);
+        setupKeyguardOccluded();
+        backNavigationInfo = startBackNavigation();
+        assertThat(typeToString(backNavigationInfo.getType()))
+                .isEqualTo(typeToString(BackNavigationInfo.TYPE_CALLBACK));
+
+        doReturn(true).when(recordA).canShowWhenLocked();
+        backNavigationInfo = startBackNavigation();
+        assertThat(typeToString(backNavigationInfo.getType()))
+                .isEqualTo(typeToString(BackNavigationInfo.TYPE_CROSS_TASK));
     }
 
     @Test
@@ -137,6 +152,20 @@
         assertThat(backNavigationInfo.getOnBackInvokedCallback()).isEqualTo(callback);
         assertThat(typeToString(backNavigationInfo.getType()))
                 .isEqualTo(typeToString(BackNavigationInfo.TYPE_CROSS_ACTIVITY));
+
+        // reset drawing status
+        testCase.recordFront.forAllWindows(w -> {
+            makeWindowVisibleAndDrawn(w);
+        }, true);
+        setupKeyguardOccluded();
+        backNavigationInfo = startBackNavigation();
+        assertThat(typeToString(backNavigationInfo.getType()))
+                .isEqualTo(typeToString(BackNavigationInfo.TYPE_CALLBACK));
+
+        doReturn(true).when(testCase.recordBack).canShowWhenLocked();
+        backNavigationInfo = startBackNavigation();
+        assertThat(typeToString(backNavigationInfo.getType()))
+                .isEqualTo(typeToString(BackNavigationInfo.TYPE_CROSS_ACTIVITY));
     }
 
     @Test
@@ -164,12 +193,17 @@
 
     @Test
     public void preparesForBackToHome() {
-        Task task = createTopTaskWithActivity();
-        withSystemCallback(task);
+        final Task topTask = createTopTaskWithActivity();
+        withSystemCallback(topTask);
 
         BackNavigationInfo backNavigationInfo = startBackNavigation();
         assertThat(typeToString(backNavigationInfo.getType()))
                 .isEqualTo(typeToString(BackNavigationInfo.TYPE_RETURN_TO_HOME));
+
+        setupKeyguardOccluded();
+        backNavigationInfo = startBackNavigation();
+        assertThat(typeToString(backNavigationInfo.getType()))
+                .isEqualTo(typeToString(BackNavigationInfo.TYPE_CALLBACK));
     }
 
     @Test
@@ -302,14 +336,22 @@
         };
     }
 
-    @NonNull
-    private TaskSnapshotController createMockTaskSnapshotController() {
-        TaskSnapshotController taskSnapshotController = mock(TaskSnapshotController.class);
-        TaskSnapshot taskSnapshot = mock(TaskSnapshot.class);
-        when(taskSnapshot.getHardwareBuffer()).thenReturn(mock(HardwareBuffer.class));
-        when(taskSnapshotController.getSnapshot(anyInt(), anyInt(), anyBoolean(), anyBoolean()))
-                .thenReturn(taskSnapshot);
-        return taskSnapshotController;
+    private Task initHomeActivity() {
+        final Task task = mDisplayContent.getDefaultTaskDisplayArea().getRootHomeTask();
+        task.forAllLeafTasks((t) -> {
+            if (t.getTopMostActivity() == null) {
+                final ActivityRecord r = createActivityRecord(t);
+                Mockito.doNothing().when(t).reparentSurfaceControl(any(), any());
+                Mockito.doNothing().when(r).reparentSurfaceControl(any(), any());
+            }
+        }, true);
+        return task;
+    }
+
+    private void setupKeyguardOccluded() {
+        final KeyguardController kc = mRootHomeTask.mTaskSupervisor.getKeyguardController();
+        doReturn(true).when(kc).isKeyguardLocked(anyInt());
+        doReturn(true).when(kc).isDisplayOccluded(anyInt());
     }
 
     @NonNull
diff --git a/services/tests/wmtests/src/com/android/server/wm/ContentRecorderTests.java b/services/tests/wmtests/src/com/android/server/wm/ContentRecorderTests.java
index 49fd1ab..92dd047 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ContentRecorderTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ContentRecorderTests.java
@@ -52,6 +52,8 @@
 import androidx.annotation.NonNull;
 import androidx.test.filters.SmallTest;
 
+import com.android.server.wm.ContentRecorder.MediaProjectionManagerWrapper;
+
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -79,7 +81,7 @@
     private ContentRecordingSession mTaskSession;
     private static Point sSurfaceSize;
     private ContentRecorder mContentRecorder;
-    @Mock private ContentRecorder.MediaProjectionManagerWrapper mMediaProjectionManagerWrapper;
+    @Mock private MediaProjectionManagerWrapper mMediaProjectionManagerWrapper;
     private SurfaceControl mRecordedSurface;
     // Handle feature flag.
     private ConfigListener mConfigListener;
@@ -241,7 +243,7 @@
     }
 
     @Test
-    public void testOnTaskConfigurationChanged_resizesSurface() {
+    public void testOnTaskOrientationConfigurationChanged_resizesSurface() {
         mContentRecorder.setContentRecordingSession(mTaskSession);
         mContentRecorder.updateRecording();
 
@@ -256,6 +258,29 @@
     }
 
     @Test
+    public void testOnTaskBoundsConfigurationChanged_notifiesCallback() {
+        final int recordedWidth = 333;
+        final int recordedHeight = 999;
+        // WHEN a recording is ongoing.
+        mContentRecorder.setContentRecordingSession(mTaskSession);
+        mContentRecorder.updateRecording();
+        assertThat(mContentRecorder.isCurrentlyRecording()).isTrue();
+
+        // WHEN a configuration change arrives, and the recorded content is a different size.
+        mTask.setBounds(new Rect(0, 0, recordedWidth, recordedHeight));
+        mContentRecorder.onConfigurationChanged(mDefaultDisplay.getLastOrientation());
+        assertThat(mContentRecorder.isCurrentlyRecording()).isTrue();
+
+        // THEN content in the captured DisplayArea is scaled to fit the surface size.
+        verify(mTransaction, atLeastOnce()).setMatrix(eq(mRecordedSurface), anyFloat(), eq(0f),
+                eq(0f),
+                anyFloat());
+        // THEN the resize callback is notified.
+        verify(mMediaProjectionManagerWrapper).notifyActiveProjectionCapturedContentResized(
+                recordedWidth, recordedHeight);
+    }
+
+    @Test
     public void testPauseRecording_pausesRecording() {
         mContentRecorder.setContentRecordingSession(mDisplaySession);
         mContentRecorder.updateRecording();
@@ -324,6 +349,9 @@
         int scaledWidth = Math.round((float) displayAreaBounds.width() / xScale);
         int xInset = (sSurfaceSize.x - scaledWidth) / 2;
         verify(mTransaction, atLeastOnce()).setPosition(mRecordedSurface, xInset, 0);
+        // THEN the resize callback is notified.
+        verify(mMediaProjectionManagerWrapper).notifyActiveProjectionCapturedContentResized(
+                displayAreaBounds.width(), displayAreaBounds.height());
     }
 
     private static class RecordingTestToken extends Binder {
diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayWindowPolicyControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayWindowPolicyControllerTests.java
index ba68a25..2ce1d60 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayWindowPolicyControllerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayWindowPolicyControllerTests.java
@@ -193,6 +193,30 @@
         assertEquals(result, START_ABORTED);
     }
 
+    @Test
+    public void testCanActivityBeLaunched_requiredDisplayCategory() {
+        ActivityStarter starter = new ActivityStarter(mock(ActivityStartController.class), mAtm,
+                mSupervisor, mock(ActivityStartInterceptor.class));
+        final Task task = new TaskBuilder(mSupervisor).setDisplay(mSecondaryDisplay).build();
+        final ActivityRecord sourceRecord = new ActivityBuilder(mAtm).setTask(task).build();
+        final ActivityRecord disallowedRecord =
+                new ActivityBuilder(mAtm).setRequiredDisplayCategory("auto").build();
+
+        int result = starter.startActivityInner(
+                disallowedRecord,
+                sourceRecord,
+                /* voiceSession= */null,
+                /* voiceInteractor= */ null,
+                /* startFlags= */ 0,
+                /* options= */null,
+                /* inTask= */null,
+                /* inTaskFragment= */ null,
+                /* restrictedBgActivity= */false,
+                /* intentGrants= */null);
+
+        assertEquals(result, START_ABORTED);
+    }
+
     private class TestDisplayWindowPolicyController extends DisplayWindowPolicyController {
 
         public ComponentName DISALLOWED_ACTIVITY =
diff --git a/services/tests/wmtests/src/com/android/server/wm/InsetsPolicyTest.java b/services/tests/wmtests/src/com/android/server/wm/InsetsPolicyTest.java
index fd2a1d1..c7971bc7 100644
--- a/services/tests/wmtests/src/com/android/server/wm/InsetsPolicyTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/InsetsPolicyTest.java
@@ -37,6 +37,8 @@
 import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
 import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;
 
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -46,7 +48,6 @@
 import static org.mockito.ArgumentMatchers.anyBoolean;
 import static org.mockito.Mockito.clearInvocations;
 import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 
 import android.app.StatusBarManager;
@@ -265,7 +266,8 @@
         final WindowState navBar = addNavigationBar();
         navBar.setHasSurface(true);
         navBar.getControllableInsetProvider().setServerVisible(true);
-        final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy());
+        final InsetsPolicy policy = mDisplayContent.getInsetsPolicy();
+        spyOn(policy);
         doNothing().when(policy).startAnimation(anyBoolean(), any());
 
         // Make both system bars invisible.
@@ -302,12 +304,15 @@
         addStatusBar().getControllableInsetProvider().getSource().setVisible(false);
         addNavigationBar().getControllableInsetProvider().setServerVisible(true);
 
-        final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy());
+        final InsetsPolicy policy = mDisplayContent.getInsetsPolicy();
+        spyOn(policy);
         doNothing().when(policy).startAnimation(anyBoolean(), any());
         policy.updateBarControlTarget(mAppWindow);
         policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR},
                 true /* isGestureOnSystemBar */);
         waitUntilWindowAnimatorIdle();
+        assertTrue(policy.isTransient(ITYPE_STATUS_BAR));
+        assertFalse(policy.isTransient(ITYPE_NAVIGATION_BAR));
         final InsetsSourceControl[] controls =
                 mDisplayContent.getInsetsStateController().getControlsForDispatch(mAppWindow);
 
@@ -335,7 +340,8 @@
         navBarSource.setVisible(false);
         mAppWindow.mAboveInsetsState.addSource(navBarSource);
         mAppWindow.mAboveInsetsState.addSource(statusBarSource);
-        final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy());
+        final InsetsPolicy policy = mDisplayContent.getInsetsPolicy();
+        spyOn(policy);
         doNothing().when(policy).startAnimation(anyBoolean(), any());
         policy.updateBarControlTarget(mAppWindow);
         policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR},
@@ -383,7 +389,8 @@
         final WindowState app = addWindow(TYPE_APPLICATION, "app");
         final WindowState app2 = addWindow(TYPE_APPLICATION, "app");
 
-        final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy());
+        final InsetsPolicy policy = mDisplayContent.getInsetsPolicy();
+        spyOn(policy);
         doNothing().when(policy).startAnimation(anyBoolean(), any());
         policy.updateBarControlTarget(app);
         policy.showTransient(new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR},
diff --git a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java
index 13ea99a..6877e4f 100644
--- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java
@@ -166,6 +166,114 @@
     }
 
     @Test
+    public void testApplyStrategyToTranslucentActivities() {
+        mWm.mLetterboxConfiguration.setTranslucentLetterboxingOverrideEnabled(true);
+        setUpDisplaySizeWithApp(2000, 1000);
+        prepareUnresizable(mActivity, 1.5f /* maxAspect */, SCREEN_ORIENTATION_PORTRAIT);
+        mActivity.info.setMinAspectRatio(1.2f);
+        mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
+        // Translucent Activity
+        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm)
+                .setLaunchedFromUid(mActivity.getUid())
+                .setScreenOrientation(SCREEN_ORIENTATION_LANDSCAPE)
+                .setMinAspectRatio(1.1f)
+                .setMaxAspectRatio(3f)
+                .build();
+        doReturn(false).when(translucentActivity).fillsParent();
+        mTask.addChild(translucentActivity);
+        // We check bounds
+        final Rect opaqueBounds = mActivity.getConfiguration().windowConfiguration.getBounds();
+        final Rect translucentRequestedBounds = translucentActivity.getRequestedOverrideBounds();
+        assertEquals(opaqueBounds, translucentRequestedBounds);
+        // We check orientation
+        final int translucentOrientation =
+                translucentActivity.getRequestedConfigurationOrientation();
+        assertEquals(ORIENTATION_PORTRAIT, translucentOrientation);
+        // We check aspect ratios
+        assertEquals(1.2f, translucentActivity.getMinAspectRatio(), 0.00001f);
+        assertEquals(1.5f, translucentActivity.getMaxAspectRatio(), 0.00001f);
+    }
+
+    @Test
+    public void testNotApplyStrategyToTranslucentActivitiesWithDifferentUid() {
+        mWm.mLetterboxConfiguration.setTranslucentLetterboxingOverrideEnabled(true);
+        setUpDisplaySizeWithApp(2000, 1000);
+        prepareUnresizable(mActivity, 1.5f /* maxAspect */, SCREEN_ORIENTATION_PORTRAIT);
+        mActivity.info.setMinAspectRatio(1.2f);
+        mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
+        // Translucent Activity
+        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm)
+                .setScreenOrientation(SCREEN_ORIENTATION_LANDSCAPE)
+                .setMinAspectRatio(1.1f)
+                .setMaxAspectRatio(3f)
+                .build();
+        doReturn(false).when(translucentActivity).fillsParent();
+        mTask.addChild(translucentActivity);
+        // We check bounds
+        final Rect opaqueBounds = mActivity.getConfiguration().windowConfiguration.getBounds();
+        final Rect translucentRequestedBounds = translucentActivity.getRequestedOverrideBounds();
+        assertNotEquals(opaqueBounds, translucentRequestedBounds);
+    }
+
+    @Test
+    public void testApplyStrategyToMultipleTranslucentActivities() {
+        mWm.mLetterboxConfiguration.setTranslucentLetterboxingOverrideEnabled(true);
+        setUpDisplaySizeWithApp(2000, 1000);
+        prepareUnresizable(mActivity, 1.5f /* maxAspect */, SCREEN_ORIENTATION_PORTRAIT);
+        mActivity.info.setMinAspectRatio(1.2f);
+        mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
+        // Translucent Activity
+        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm)
+                .setLaunchedFromUid(mActivity.getUid())
+                .setScreenOrientation(SCREEN_ORIENTATION_LANDSCAPE)
+                .setMinAspectRatio(1.1f)
+                .setMaxAspectRatio(3f)
+                .build();
+        doReturn(false).when(translucentActivity).fillsParent();
+        mTask.addChild(translucentActivity);
+        // We check bounds
+        final Rect opaqueBounds = mActivity.getConfiguration().windowConfiguration.getBounds();
+        final Rect translucentRequestedBounds = translucentActivity.getRequestedOverrideBounds();
+        assertEquals(opaqueBounds, translucentRequestedBounds);
+        // Launch another translucent activity
+        final ActivityRecord translucentActivity2 = new ActivityBuilder(mAtm)
+                .setLaunchedFromUid(mActivity.getUid())
+                .setScreenOrientation(SCREEN_ORIENTATION_LANDSCAPE)
+                .build();
+        doReturn(false).when(translucentActivity2).fillsParent();
+        mTask.addChild(translucentActivity2);
+        // We check bounds
+        final Rect translucent2RequestedBounds = translucentActivity2.getRequestedOverrideBounds();
+        assertEquals(opaqueBounds, translucent2RequestedBounds);
+    }
+
+    @Test
+    public void testTranslucentActivitiesDontGoInSizeCompactMode() {
+        mWm.mLetterboxConfiguration.setTranslucentLetterboxingOverrideEnabled(true);
+        setUpDisplaySizeWithApp(2800, 1400);
+        mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
+        prepareUnresizable(mActivity, -1f /* maxAspect */, SCREEN_ORIENTATION_PORTRAIT);
+        // Rotate to put activity in size compat mode.
+        rotateDisplay(mActivity.mDisplayContent, ROTATION_90);
+        assertTrue(mActivity.inSizeCompatMode());
+        // Rotate back
+        rotateDisplay(mActivity.mDisplayContent, ROTATION_0);
+        assertFalse(mActivity.inSizeCompatMode());
+        // We launch a transparent activity
+        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm)
+                .setLaunchedFromUid(mActivity.getUid())
+                .setScreenOrientation(SCREEN_ORIENTATION_PORTRAIT)
+                .build();
+        doReturn(true).when(translucentActivity).fillsParent();
+        mTask.addChild(translucentActivity);
+        // It should not be in SCM
+        assertFalse(translucentActivity.inSizeCompatMode());
+        // We rotate again
+        rotateDisplay(translucentActivity.mDisplayContent, ROTATION_90);
+        assertFalse(translucentActivity.inSizeCompatMode());
+    }
+
+    @Test
     public void testRestartProcessIfVisible() {
         setUpDisplaySizeWithApp(1000, 2500);
         doNothing().when(mSupervisor).scheduleRestartTimeout(mActivity);
diff --git a/services/tests/wmtests/src/com/android/server/wm/SurfaceSyncGroupTest.java b/services/tests/wmtests/src/com/android/server/wm/SurfaceSyncGroupTest.java
index 5e1fae0..7d9f29c 100644
--- a/services/tests/wmtests/src/com/android/server/wm/SurfaceSyncGroupTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/SurfaceSyncGroupTest.java
@@ -20,6 +20,9 @@
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
 
 import android.platform.test.annotations.Presubmit;
 import android.view.SurfaceControl;
@@ -31,12 +34,15 @@
 import org.junit.Test;
 
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executor;
 import java.util.concurrent.TimeUnit;
 
 @SmallTest
 @Presubmit
 public class SurfaceSyncGroupTest {
 
+    private final Executor mExecutor = Runnable::run;
+
     @Before
     public void setup() {
         SurfaceSyncGroup.setTransactionFactory(StubTransaction::new);
@@ -45,10 +51,11 @@
     @Test
     public void testSyncOne() throws InterruptedException {
         final CountDownLatch finishedLatch = new CountDownLatch(1);
-        SurfaceSyncGroup syncGroup = new SurfaceSyncGroup(transaction -> finishedLatch.countDown());
+        SurfaceSyncGroup syncGroup = new SurfaceSyncGroup();
+        syncGroup.addSyncCompleteCallback(mExecutor, finishedLatch::countDown);
         SyncTarget syncTarget = new SyncTarget();
-        syncGroup.addToSync(syncTarget);
-        syncGroup.markSyncReady();
+        syncGroup.addToSync(syncTarget, false /* parentSyncGroupMerge */);
+        syncGroup.onTransactionReady(null);
 
         syncTarget.onBufferReady();
 
@@ -59,15 +66,16 @@
     @Test
     public void testSyncMultiple() throws InterruptedException {
         final CountDownLatch finishedLatch = new CountDownLatch(1);
-        SurfaceSyncGroup syncGroup = new SurfaceSyncGroup(transaction -> finishedLatch.countDown());
+        SurfaceSyncGroup syncGroup = new SurfaceSyncGroup();
+        syncGroup.addSyncCompleteCallback(mExecutor, finishedLatch::countDown);
         SyncTarget syncTarget1 = new SyncTarget();
         SyncTarget syncTarget2 = new SyncTarget();
         SyncTarget syncTarget3 = new SyncTarget();
 
-        syncGroup.addToSync(syncTarget1);
-        syncGroup.addToSync(syncTarget2);
-        syncGroup.addToSync(syncTarget3);
-        syncGroup.markSyncReady();
+        syncGroup.addToSync(syncTarget1, false /* parentSyncGroupMerge */);
+        syncGroup.addToSync(syncTarget2, false /* parentSyncGroupMerge */);
+        syncGroup.addToSync(syncTarget3, false /* parentSyncGroupMerge */);
+        syncGroup.onTransactionReady(null);
 
         syncTarget1.onBufferReady();
         assertNotEquals(0, finishedLatch.getCount());
@@ -83,35 +91,35 @@
 
     @Test
     public void testAddSyncWhenSyncComplete() {
-        final CountDownLatch finishedLatch = new CountDownLatch(1);
-        SurfaceSyncGroup syncGroup = new SurfaceSyncGroup(transaction -> finishedLatch.countDown());
+        SurfaceSyncGroup syncGroup = new SurfaceSyncGroup();
 
         SyncTarget syncTarget1 = new SyncTarget();
         SyncTarget syncTarget2 = new SyncTarget();
 
-        assertTrue(syncGroup.addToSync(syncTarget1));
-        syncGroup.markSyncReady();
+        assertTrue(syncGroup.addToSync(syncTarget1, false /* parentSyncGroupMerge */));
+        syncGroup.onTransactionReady(null);
         // Adding to a sync that has been completed is also invalid since the sync id has been
         // cleared.
-        assertFalse(syncGroup.addToSync(syncTarget2));
+        assertFalse(syncGroup.addToSync(syncTarget2, false /* parentSyncGroupMerge */));
     }
 
     @Test
-    public void testMultiplesyncGroups() throws InterruptedException {
+    public void testMultipleSyncGroups() throws InterruptedException {
         final CountDownLatch finishedLatch1 = new CountDownLatch(1);
         final CountDownLatch finishedLatch2 = new CountDownLatch(1);
-        SurfaceSyncGroup syncGroup1 = new SurfaceSyncGroup(
-                transaction -> finishedLatch1.countDown());
-        SurfaceSyncGroup syncGroup2 = new SurfaceSyncGroup(
-                transaction -> finishedLatch2.countDown());
+        SurfaceSyncGroup syncGroup1 = new SurfaceSyncGroup();
+        SurfaceSyncGroup syncGroup2 = new SurfaceSyncGroup();
+
+        syncGroup1.addSyncCompleteCallback(mExecutor, finishedLatch1::countDown);
+        syncGroup2.addSyncCompleteCallback(mExecutor, finishedLatch2::countDown);
 
         SyncTarget syncTarget1 = new SyncTarget();
         SyncTarget syncTarget2 = new SyncTarget();
 
-        assertTrue(syncGroup1.addToSync(syncTarget1));
-        assertTrue(syncGroup2.addToSync(syncTarget2));
-        syncGroup1.markSyncReady();
-        syncGroup2.markSyncReady();
+        assertTrue(syncGroup1.addToSync(syncTarget1, false /* parentSyncGroupMerge */));
+        assertTrue(syncGroup2.addToSync(syncTarget2, false /* parentSyncGroupMerge */));
+        syncGroup1.onTransactionReady(null);
+        syncGroup2.onTransactionReady(null);
 
         syncTarget1.onBufferReady();
 
@@ -126,22 +134,23 @@
     }
 
     @Test
-    public void testMergeSync() throws InterruptedException {
+    public void testAddSyncGroup() throws InterruptedException {
         final CountDownLatch finishedLatch1 = new CountDownLatch(1);
         final CountDownLatch finishedLatch2 = new CountDownLatch(1);
-        SurfaceSyncGroup syncGroup1 = new SurfaceSyncGroup(
-                transaction -> finishedLatch1.countDown());
-        SurfaceSyncGroup syncGroup2 = new SurfaceSyncGroup(
-                transaction -> finishedLatch2.countDown());
+        SurfaceSyncGroup syncGroup1 = new SurfaceSyncGroup();
+        SurfaceSyncGroup syncGroup2 = new SurfaceSyncGroup();
+
+        syncGroup1.addSyncCompleteCallback(mExecutor, finishedLatch1::countDown);
+        syncGroup2.addSyncCompleteCallback(mExecutor, finishedLatch2::countDown);
 
         SyncTarget syncTarget1 = new SyncTarget();
         SyncTarget syncTarget2 = new SyncTarget();
 
-        assertTrue(syncGroup1.addToSync(syncTarget1));
-        assertTrue(syncGroup2.addToSync(syncTarget2));
-        syncGroup1.markSyncReady();
-        syncGroup2.merge(syncGroup1);
-        syncGroup2.markSyncReady();
+        assertTrue(syncGroup1.addToSync(syncTarget1, false /* parentSyncGroupMerge */));
+        assertTrue(syncGroup2.addToSync(syncTarget2, false /* parentSyncGroupMerge */));
+        syncGroup1.onTransactionReady(null);
+        syncGroup2.addToSync(syncGroup1, false /* parentSyncGroupMerge */);
+        syncGroup2.onTransactionReady(null);
 
         // Finish syncTarget2 first to test that the syncGroup is not complete until the merged sync
         // is also done.
@@ -161,28 +170,29 @@
     }
 
     @Test
-    public void testMergeSyncAlreadyComplete() throws InterruptedException {
+    public void testAddSyncAlreadyComplete() throws InterruptedException {
         final CountDownLatch finishedLatch1 = new CountDownLatch(1);
         final CountDownLatch finishedLatch2 = new CountDownLatch(1);
-        SurfaceSyncGroup syncGroup1 = new SurfaceSyncGroup(
-                transaction -> finishedLatch1.countDown());
-        SurfaceSyncGroup syncGroup2 = new SurfaceSyncGroup(
-                transaction -> finishedLatch2.countDown());
+        SurfaceSyncGroup syncGroup1 = new SurfaceSyncGroup();
+        SurfaceSyncGroup syncGroup2 = new SurfaceSyncGroup();
+
+        syncGroup1.addSyncCompleteCallback(mExecutor, finishedLatch1::countDown);
+        syncGroup2.addSyncCompleteCallback(mExecutor, finishedLatch2::countDown);
 
         SyncTarget syncTarget1 = new SyncTarget();
         SyncTarget syncTarget2 = new SyncTarget();
 
-        assertTrue(syncGroup1.addToSync(syncTarget1));
-        assertTrue(syncGroup2.addToSync(syncTarget2));
-        syncGroup1.markSyncReady();
+        assertTrue(syncGroup1.addToSync(syncTarget1, false /* parentSyncGroupMerge */));
+        assertTrue(syncGroup2.addToSync(syncTarget2, false /* parentSyncGroupMerge */));
+        syncGroup1.onTransactionReady(null);
         syncTarget1.onBufferReady();
 
         // The first sync will still get a callback when it's sync requirements are done.
         finishedLatch1.await(5, TimeUnit.SECONDS);
         assertEquals(0, finishedLatch1.getCount());
 
-        syncGroup2.merge(syncGroup1);
-        syncGroup2.markSyncReady();
+        syncGroup2.addToSync(syncGroup1, false /* parentSyncGroupMerge */);
+        syncGroup2.onTransactionReady(null);
         syncTarget2.onBufferReady();
 
         // Verify that the second sync will receive complete since the merged sync was already
@@ -191,18 +201,145 @@
         assertEquals(0, finishedLatch2.getCount());
     }
 
-    private static class SyncTarget implements SurfaceSyncGroup.SyncTarget {
-        private SurfaceSyncGroup.TransactionReadyCallback mTransactionReadyCallback;
+    @Test
+    public void testAddSyncAlreadyInASync_NewSyncReadyFirst() throws InterruptedException {
+        final CountDownLatch finishedLatch1 = new CountDownLatch(1);
+        final CountDownLatch finishedLatch2 = new CountDownLatch(1);
+        SurfaceSyncGroup syncGroup1 = new SurfaceSyncGroup();
+        SurfaceSyncGroup syncGroup2 = new SurfaceSyncGroup();
 
-        @Override
-        public void onAddedToSyncGroup(SurfaceSyncGroup parentSyncGroup,
-                SurfaceSyncGroup.TransactionReadyCallback transactionReadyCallback) {
-            mTransactionReadyCallback = transactionReadyCallback;
-        }
+        syncGroup1.addSyncCompleteCallback(mExecutor, finishedLatch1::countDown);
+        syncGroup2.addSyncCompleteCallback(mExecutor, finishedLatch2::countDown);
 
+        SyncTarget syncTarget1 = new SyncTarget();
+        SyncTarget syncTarget2 = new SyncTarget();
+        SyncTarget syncTarget3 = new SyncTarget();
+
+        assertTrue(syncGroup1.addToSync(syncTarget1, false /* parentSyncGroupMerge */));
+        assertTrue(syncGroup1.addToSync(syncTarget2, false /* parentSyncGroupMerge */));
+
+        // Add syncTarget1 to syncGroup2 so it forces syncGroup1 into syncGroup2
+        assertTrue(syncGroup2.addToSync(syncTarget1, false /* parentSyncGroupMerge */));
+        assertTrue(syncGroup2.addToSync(syncTarget3, false /* parentSyncGroupMerge */));
+
+        syncGroup1.onTransactionReady(null);
+        syncGroup2.onTransactionReady(null);
+
+        // Make target1 and target3 ready, but not target2. SyncGroup2 should not be ready since
+        // SyncGroup2 also waits for all of SyncGroup1 to finish, which includes target2
+        syncTarget1.onBufferReady();
+        syncTarget3.onBufferReady();
+
+        // Neither SyncGroup will be ready.
+        finishedLatch1.await(1, TimeUnit.SECONDS);
+        finishedLatch2.await(1, TimeUnit.SECONDS);
+
+        assertEquals(1, finishedLatch1.getCount());
+        assertEquals(1, finishedLatch2.getCount());
+
+        syncTarget2.onBufferReady();
+
+        // Both sync groups should be ready after target2 completed.
+        finishedLatch1.await(5, TimeUnit.SECONDS);
+        finishedLatch2.await(5, TimeUnit.SECONDS);
+        assertEquals(0, finishedLatch1.getCount());
+        assertEquals(0, finishedLatch2.getCount());
+    }
+
+    @Test
+    public void testAddSyncAlreadyInASync_OldSyncFinishesFirst() throws InterruptedException {
+        final CountDownLatch finishedLatch1 = new CountDownLatch(1);
+        final CountDownLatch finishedLatch2 = new CountDownLatch(1);
+        SurfaceSyncGroup syncGroup1 = new SurfaceSyncGroup();
+        SurfaceSyncGroup syncGroup2 = new SurfaceSyncGroup();
+
+        syncGroup1.addSyncCompleteCallback(mExecutor, finishedLatch1::countDown);
+        syncGroup2.addSyncCompleteCallback(mExecutor, finishedLatch2::countDown);
+
+        SyncTarget syncTarget1 = new SyncTarget();
+        SyncTarget syncTarget2 = new SyncTarget();
+        SyncTarget syncTarget3 = new SyncTarget();
+
+        assertTrue(syncGroup1.addToSync(syncTarget1, false /* parentSyncGroupMerge */));
+        assertTrue(syncGroup1.addToSync(syncTarget2, false /* parentSyncGroupMerge */));
+        syncTarget2.onBufferReady();
+
+        // Add syncTarget1 to syncGroup2 so it forces syncGroup1 into syncGroup2
+        assertTrue(syncGroup2.addToSync(syncTarget1, false /* parentSyncGroupMerge */));
+        assertTrue(syncGroup2.addToSync(syncTarget3, false /* parentSyncGroupMerge */));
+
+        syncGroup1.onTransactionReady(null);
+        syncGroup2.onTransactionReady(null);
+
+        syncTarget1.onBufferReady();
+
+        // Only SyncGroup1 will be ready, but SyncGroup2 still needs its own targets to be ready.
+        finishedLatch1.await(1, TimeUnit.SECONDS);
+        finishedLatch2.await(1, TimeUnit.SECONDS);
+
+        assertEquals(0, finishedLatch1.getCount());
+        assertEquals(1, finishedLatch2.getCount());
+
+        syncTarget3.onBufferReady();
+
+        // SyncGroup2 is finished after target3 completed.
+        finishedLatch2.await(1, TimeUnit.SECONDS);
+        assertEquals(0, finishedLatch2.getCount());
+    }
+
+    @Test
+    public void testParentSyncGroupMerge_true() {
+        // Temporarily set a new transaction factory so it will return the stub transaction for
+        // the sync group.
+        SurfaceControl.Transaction parentTransaction = spy(new StubTransaction());
+        SurfaceSyncGroup.setTransactionFactory(() -> parentTransaction);
+
+        final CountDownLatch finishedLatch = new CountDownLatch(1);
+        SurfaceSyncGroup syncGroup = new SurfaceSyncGroup();
+        syncGroup.addSyncCompleteCallback(mExecutor, finishedLatch::countDown);
+
+        SurfaceControl.Transaction targetTransaction = spy(new StubTransaction());
+        SurfaceSyncGroup.setTransactionFactory(() -> targetTransaction);
+
+        SyncTarget syncTarget = new SyncTarget();
+        assertTrue(syncGroup.addToSync(syncTarget, true /* parentSyncGroupMerge */));
+        syncTarget.onTransactionReady(null);
+
+        // When parentSyncGroupMerge is true, the transaction passed in merges the main SyncGroup
+        // transaction first because it knows the previous parentSyncGroup is older so it should
+        // be overwritten by anything newer.
+        verify(targetTransaction).merge(parentTransaction);
+        verify(parentTransaction).merge(targetTransaction);
+    }
+
+    @Test
+    public void testParentSyncGroupMerge_false() {
+        // Temporarily set a new transaction factory so it will return the stub transaction for
+        // the sync group.
+        SurfaceControl.Transaction parentTransaction = spy(new StubTransaction());
+        SurfaceSyncGroup.setTransactionFactory(() -> parentTransaction);
+
+        final CountDownLatch finishedLatch = new CountDownLatch(1);
+        SurfaceSyncGroup syncGroup = new SurfaceSyncGroup();
+        syncGroup.addSyncCompleteCallback(mExecutor, finishedLatch::countDown);
+
+        SurfaceControl.Transaction targetTransaction = spy(new StubTransaction());
+        SurfaceSyncGroup.setTransactionFactory(() -> targetTransaction);
+
+        SyncTarget syncTarget = new SyncTarget();
+        assertTrue(syncGroup.addToSync(syncTarget, false /* parentSyncGroupMerge */));
+        syncTarget.onTransactionReady(null);
+
+        // When parentSyncGroupMerge is false, the transaction passed in should not merge
+        // the main SyncGroup since we don't need to change the transaction order
+        verify(targetTransaction, never()).merge(parentTransaction);
+        verify(parentTransaction).merge(targetTransaction);
+    }
+
+    private static class SyncTarget extends SurfaceSyncGroup {
         void onBufferReady() {
             SurfaceControl.Transaction t = new StubTransaction();
-            mTransactionReadyCallback.onTransactionReady(t);
+            onTransactionReady(t);
         }
     }
 }
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskFragmentOrganizerControllerTest.java b/services/tests/wmtests/src/com/android/server/wm/TaskFragmentOrganizerControllerTest.java
index 834302e..d5c1579 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskFragmentOrganizerControllerTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskFragmentOrganizerControllerTest.java
@@ -19,9 +19,16 @@
 import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
 import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
 import static android.view.Display.DEFAULT_DISPLAY;
+import static android.view.WindowManager.TRANSIT_CHANGE;
+import static android.view.WindowManager.TRANSIT_CLOSE;
+import static android.view.WindowManager.TRANSIT_NONE;
+import static android.view.WindowManager.TRANSIT_OPEN;
 import static android.window.TaskFragmentOrganizer.KEY_ERROR_CALLBACK_OP_TYPE;
 import static android.window.TaskFragmentOrganizer.KEY_ERROR_CALLBACK_THROWABLE;
-import static android.window.TaskFragmentOrganizer.getTransitionType;
+import static android.window.TaskFragmentOrganizer.TASK_FRAGMENT_TRANSIT_CHANGE;
+import static android.window.TaskFragmentOrganizer.TASK_FRAGMENT_TRANSIT_CLOSE;
+import static android.window.TaskFragmentOrganizer.TASK_FRAGMENT_TRANSIT_NONE;
+import static android.window.TaskFragmentOrganizer.TASK_FRAGMENT_TRANSIT_OPEN;
 import static android.window.TaskFragmentTransaction.TYPE_ACTIVITY_REPARENTED_TO_TASK;
 import static android.window.TaskFragmentTransaction.TYPE_TASK_FRAGMENT_APPEARED;
 import static android.window.TaskFragmentTransaction.TYPE_TASK_FRAGMENT_ERROR;
@@ -358,7 +365,6 @@
         assertActivityReparentedToTaskTransaction(task.mTaskId, activity.intent, activity.token);
 
         // Notify organizer if there is any embedded in the Task.
-        clearInvocations(mOrganizer);
         final TaskFragment taskFragment = new TaskFragmentBuilder(mAtm)
                 .setParentTask(task)
                 .setOrganizer(mOrganizer)
@@ -367,11 +373,14 @@
                 DEFAULT_TASK_FRAGMENT_ORGANIZER_PROCESS_NAME);
         activity.reparent(taskFragment, POSITION_TOP);
         activity.mLastTaskFragmentOrganizerBeforePip = null;
+
+        // Clear invocations now because there will be another transaction for the TaskFragment
+        // change above, triggered by the reparent. We only want to test onActivityReparentedToTask
+        // here.
+        clearInvocations(mOrganizer);
         mController.onActivityReparentedToTask(activity);
         mController.dispatchPendingEvents();
 
-        // There will not be TaskFragmentParentInfoChanged because Task visible request is changed
-        // before the organized TaskFragment is added to the Task.
         assertActivityReparentedToTaskTransaction(task.mTaskId, activity.intent, activity.token);
     }
 
@@ -553,10 +562,9 @@
     @Test
     public void testApplyTransaction_enforceHierarchyChange_createTaskFragment() {
         final ActivityRecord ownerActivity = createActivityRecord(mDisplayContent);
-        final IBinder fragmentToken = new Binder();
 
         // Allow organizer to create TaskFragment and start/reparent activity to TaskFragment.
-        createTaskFragmentFromOrganizer(mTransaction, ownerActivity, fragmentToken);
+        createTaskFragmentFromOrganizer(mTransaction, ownerActivity, mFragmentToken);
         mTransaction.startActivityInTaskFragment(
                 mFragmentToken, null /* callerToken */, new Intent(), null /* activityOptions */);
         mTransaction.reparentActivityToTaskFragment(mFragmentToken, mock(IBinder.class));
@@ -565,7 +573,8 @@
         assertApplyTransactionAllowed(mTransaction);
 
         // Successfully created a TaskFragment.
-        final TaskFragment taskFragment = mWindowOrganizerController.getTaskFragment(fragmentToken);
+        final TaskFragment taskFragment = mWindowOrganizerController.getTaskFragment(
+                mFragmentToken);
         assertNotNull(taskFragment);
         assertEquals(ownerActivity.getTask(), taskFragment.getTask());
     }
@@ -581,7 +590,8 @@
         mWindowOrganizerController.mLaunchTaskFragments.put(mFragmentToken, mTaskFragment);
         mTransaction.startActivityInTaskFragment(
                 mFragmentToken, ownerActivity.token, new Intent(), null /* activityOptions */);
-        mOrganizer.applyTransaction(mTransaction);
+        mOrganizer.applyTransaction(mTransaction, TASK_FRAGMENT_TRANSIT_OPEN,
+                false /* shouldApplyIndependently */);
 
         // Not allowed because TaskFragment is not organized by the caller organizer.
         assertApplyTransactionDisallowed(mTransaction);
@@ -602,7 +612,8 @@
                 .build();
         mWindowOrganizerController.mLaunchTaskFragments.put(mFragmentToken, mTaskFragment);
         mTransaction.reparentActivityToTaskFragment(mFragmentToken, activity.token);
-        mOrganizer.applyTransaction(mTransaction);
+        mOrganizer.applyTransaction(mTransaction, TASK_FRAGMENT_TRANSIT_CHANGE,
+                false /* shouldApplyIndependently */);
 
         // Not allowed because TaskFragment is not organized by the caller organizer.
         assertApplyTransactionDisallowed(mTransaction);
@@ -628,7 +639,8 @@
                 .build();
         mWindowOrganizerController.mLaunchTaskFragments.put(fragmentToken2, taskFragment2);
         mTransaction.setAdjacentTaskFragments(mFragmentToken, fragmentToken2, null /* params */);
-        mOrganizer.applyTransaction(mTransaction);
+        mOrganizer.applyTransaction(mTransaction, TASK_FRAGMENT_TRANSIT_CHANGE,
+                false /* shouldApplyIndependently */);
 
         // Not allowed because TaskFragments are not organized by the caller organizer.
         assertApplyTransactionDisallowed(mTransaction);
@@ -661,7 +673,8 @@
                 .build();
         mWindowOrganizerController.mLaunchTaskFragments.put(mFragmentToken, mTaskFragment);
         mTransaction.requestFocusOnTaskFragment(mFragmentToken);
-        mOrganizer.applyTransaction(mTransaction);
+        mOrganizer.applyTransaction(mTransaction, TASK_FRAGMENT_TRANSIT_CHANGE,
+                false /* shouldApplyIndependently */);
 
         // Not allowed because TaskFragment is not organized by the caller organizer.
         assertApplyTransactionDisallowed(mTransaction);
@@ -704,6 +717,40 @@
     }
 
     @Test
+    public void testApplyTransaction_createTaskFragment_withPairedPrimaryFragmentToken() {
+        final Task task = createTask(mDisplayContent);
+        mTaskFragment = new TaskFragmentBuilder(mAtm)
+                .setParentTask(task)
+                .setFragmentToken(mFragmentToken)
+                .createActivityCount(1)
+                .build();
+        mWindowOrganizerController.mLaunchTaskFragments.put(mFragmentToken, mTaskFragment);
+        final ActivityRecord activityOnTop = createActivityRecord(task);
+        final int uid = Binder.getCallingUid();
+        activityOnTop.info.applicationInfo.uid = uid;
+        activityOnTop.getTask().effectiveUid = uid;
+        final IBinder fragmentToken1 = new Binder();
+        final TaskFragmentCreationParams params = new TaskFragmentCreationParams.Builder(
+                mOrganizerToken, fragmentToken1, activityOnTop.token)
+                .setPairedPrimaryFragmentToken(mFragmentToken)
+                .build();
+        mTransaction.setTaskFragmentOrganizer(mIOrganizer);
+        mTransaction.createTaskFragment(params);
+        assertApplyTransactionAllowed(mTransaction);
+
+        // Successfully created a TaskFragment.
+        final TaskFragment taskFragment = mWindowOrganizerController.getTaskFragment(
+                fragmentToken1);
+        assertNotNull(taskFragment);
+        // The new TaskFragment should be positioned right above the paired TaskFragment.
+        assertEquals(task.mChildren.indexOf(mTaskFragment) + 1,
+                task.mChildren.indexOf(taskFragment));
+        // The top activity should remain on top.
+        assertEquals(task.mChildren.indexOf(taskFragment) + 1,
+                task.mChildren.indexOf(activityOnTop));
+    }
+
+    @Test
     public void testApplyTransaction_enforceHierarchyChange_reparentChildren() {
         doReturn(true).when(mTaskFragment).isAttached();
 
@@ -729,7 +776,8 @@
         final ActivityRecord activity = createActivityRecord(task);
         // Skip manipulate the SurfaceControl.
         doNothing().when(activity).setDropInputMode(anyInt());
-        mOrganizer.applyTransaction(mTransaction);
+        mOrganizer.applyTransaction(mTransaction, TASK_FRAGMENT_TRANSIT_CHANGE,
+                false /* shouldApplyIndependently */);
         mTaskFragment = new TaskFragmentBuilder(mAtm)
                 .setParentTask(task)
                 .setFragmentToken(mFragmentToken)
@@ -830,8 +878,8 @@
 
         // Allow organizer to create TaskFragment and start/reparent activity to TaskFragment.
         createTaskFragmentFromOrganizer(mTransaction, ownerActivity, fragmentToken);
-        mController.onTransactionHandled(new Binder(), mTransaction,
-                getTransitionType(mTransaction), false /* shouldApplyIndependently */);
+        mController.onTransactionHandled(new Binder(), mTransaction, TASK_FRAGMENT_TRANSIT_CHANGE,
+                false /* shouldApplyIndependently */);
 
         // Nothing should happen as the organizer is not registered.
         assertNull(mWindowOrganizerController.getTaskFragment(fragmentToken));
@@ -1379,12 +1427,31 @@
         final IBinder transactionToken = tokenCaptor.getValue();
         final WindowContainerTransaction wct = wctCaptor.getValue();
         wct.setTaskFragmentOrganizer(mIOrganizer);
-        mController.onTransactionHandled(transactionToken, wct, getTransitionType(wct),
+        mController.onTransactionHandled(transactionToken, wct, TASK_FRAGMENT_TRANSIT_CHANGE,
                 false /* shouldApplyIndependently */);
 
         verify(mTransitionController).continueTransitionReady();
     }
 
+    @Test
+    public void testWindowOrganizerApplyTransaction_throwException() {
+        // Not allow to use #applyTransaction(WindowContainerTransaction).
+        assertThrows(RuntimeException.class, () -> mOrganizer.applyTransaction(mTransaction));
+
+        // Allow to use the overload method.
+        mOrganizer.applyTransaction(mTransaction, TASK_FRAGMENT_TRANSIT_CHANGE,
+                false /* shouldApplyIndependently */);
+    }
+
+    @Test
+    public void testTaskFragmentTransitionType() {
+        // 1-1 relationship with WindowManager.TransitionType
+        assertEquals(TRANSIT_NONE, TASK_FRAGMENT_TRANSIT_NONE);
+        assertEquals(TRANSIT_OPEN, TASK_FRAGMENT_TRANSIT_OPEN);
+        assertEquals(TRANSIT_CLOSE, TASK_FRAGMENT_TRANSIT_CLOSE);
+        assertEquals(TRANSIT_CHANGE, TASK_FRAGMENT_TRANSIT_CHANGE);
+    }
+
     /**
      * Creates a {@link TaskFragment} with the {@link WindowContainerTransaction}. Calls
      * {@link WindowOrganizerController#applyTransaction(WindowContainerTransaction)} to apply the
@@ -1406,13 +1473,14 @@
     /** Asserts that applying the given transaction will throw a {@link SecurityException}. */
     private void assertApplyTransactionDisallowed(WindowContainerTransaction t) {
         assertThrows(SecurityException.class, () ->
-                mController.applyTransaction(t, getTransitionType(t),
+                mController.applyTransaction(t, TASK_FRAGMENT_TRANSIT_CHANGE,
                         false /* shouldApplyIndependently */));
     }
 
     /** Asserts that applying the given transaction will not throw any exception. */
     private void assertApplyTransactionAllowed(WindowContainerTransaction t) {
-        mController.applyTransaction(t, getTransitionType(t), false /* shouldApplyIndependently */);
+        mController.applyTransaction(t, TASK_FRAGMENT_TRANSIT_CHANGE,
+                false /* shouldApplyIndependently */);
     }
 
     /** Asserts that there will be a transaction for TaskFragment appeared. */
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskFragmentTest.java b/services/tests/wmtests/src/com/android/server/wm/TaskFragmentTest.java
index 8fda191..8ac7ceb 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskFragmentTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskFragmentTest.java
@@ -107,18 +107,49 @@
     }
 
     @Test
+    public void testShouldStartChangeTransition_relativePositionChange() {
+        mockSurfaceFreezerSnapshot(mTaskFragment.mSurfaceFreezer);
+        final Rect startBounds = new Rect(0, 0, 500, 1000);
+        final Rect endBounds = new Rect(500, 0, 1000, 1000);
+        mTaskFragment.setBounds(startBounds);
+        mTaskFragment.updateRelativeEmbeddedBounds();
+        doReturn(true).when(mTaskFragment).isVisible();
+        doReturn(true).when(mTaskFragment).isVisibleRequested();
+
+        // Do not resize, just change the relative position.
+        final Rect relStartBounds = new Rect(mTaskFragment.getRelativeEmbeddedBounds());
+        mTaskFragment.setBounds(endBounds);
+        mTaskFragment.updateRelativeEmbeddedBounds();
+        spyOn(mDisplayContent.mTransitionController);
+
+        // For Shell transition, we don't want to take snapshot when the bounds are not resized
+        doReturn(true).when(mDisplayContent.mTransitionController)
+                .isShellTransitionsEnabled();
+        assertFalse(mTaskFragment.shouldStartChangeTransition(startBounds, relStartBounds));
+
+        // For legacy transition, we want to request a change transition even if it is just relative
+        // bounds change.
+        doReturn(false).when(mDisplayContent.mTransitionController)
+                .isShellTransitionsEnabled();
+        assertTrue(mTaskFragment.shouldStartChangeTransition(startBounds, relStartBounds));
+    }
+
+    @Test
     public void testStartChangeTransition_resetSurface() {
         mockSurfaceFreezerSnapshot(mTaskFragment.mSurfaceFreezer);
         final Rect startBounds = new Rect(0, 0, 1000, 1000);
         final Rect endBounds = new Rect(500, 500, 1000, 1000);
         mTaskFragment.setBounds(startBounds);
+        mTaskFragment.updateRelativeEmbeddedBounds();
         doReturn(true).when(mTaskFragment).isVisible();
         doReturn(true).when(mTaskFragment).isVisibleRequested();
 
         clearInvocations(mTransaction);
+        final Rect relStartBounds = new Rect(mTaskFragment.getRelativeEmbeddedBounds());
         mTaskFragment.deferOrganizedTaskFragmentSurfaceUpdate();
         mTaskFragment.setBounds(endBounds);
-        assertTrue(mTaskFragment.shouldStartChangeTransition(startBounds));
+        mTaskFragment.updateRelativeEmbeddedBounds();
+        assertTrue(mTaskFragment.shouldStartChangeTransition(startBounds, relStartBounds));
         mTaskFragment.initializeChangeTransition(startBounds);
         mTaskFragment.continueOrganizedTaskFragmentSurfaceUpdate();
 
@@ -157,17 +188,20 @@
         final Rect startBounds = new Rect(0, 0, 1000, 1000);
         final Rect endBounds = new Rect(500, 500, 1000, 1000);
         mTaskFragment.setBounds(startBounds);
+        mTaskFragment.updateRelativeEmbeddedBounds();
         doReturn(true).when(mTaskFragment).isVisible();
         doReturn(true).when(mTaskFragment).isVisibleRequested();
 
+        final Rect relStartBounds = new Rect(mTaskFragment.getRelativeEmbeddedBounds());
         final DisplayPolicy displayPolicy = mDisplayContent.getDisplayPolicy();
         displayPolicy.screenTurnedOff();
 
         assertFalse(mTaskFragment.okToAnimate());
 
         mTaskFragment.setBounds(endBounds);
+        mTaskFragment.updateRelativeEmbeddedBounds();
 
-        assertFalse(mTaskFragment.shouldStartChangeTransition(startBounds));
+        assertFalse(mTaskFragment.shouldStartChangeTransition(startBounds, relStartBounds));
     }
 
     /**
@@ -540,8 +574,8 @@
         tf1.setBounds(600, 0, 1200, 1000);
         final ActivityRecord activity0 = tf0.getTopMostActivity();
         final ActivityRecord activity1 = tf1.getTopMostActivity();
-        doReturn(true).when(activity0).isVisibleRequested();
-        doReturn(true).when(activity1).isVisibleRequested();
+        activity0.setVisibleRequested(true);
+        activity1.setVisibleRequested(true);
 
         assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, tf0.getOrientation(SCREEN_ORIENTATION_UNSET));
         assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, tf1.getOrientation(SCREEN_ORIENTATION_UNSET));
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskTests.java
index 74d7884..19e3246 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskTests.java
@@ -1493,7 +1493,6 @@
     public void testReorderActivityToFront() {
         final TaskFragmentOrganizer organizer = new TaskFragmentOrganizer(Runnable::run);
         final Task task =  new TaskBuilder(mSupervisor).setCreateActivity(true).build();
-        doNothing().when(task).onActivityVisibleRequestedChanged();
         final ActivityRecord activity = task.getTopMostActivity();
 
         final TaskFragment fragment = createTaskFragmentWithEmbeddedActivity(task, organizer);
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java
index 50fcafc..98a28cf 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java
@@ -869,6 +869,28 @@
     }
 
     @Test
+    public void testOnDisplayChanged_cleanupChanging() {
+        final Task task = createTask(mDisplayContent);
+        spyOn(task.mSurfaceFreezer);
+        mDisplayContent.mChangingContainers.add(task);
+
+        // Don't remove the changing transition of this window when it is still the old display.
+        // This happens on display info changed.
+        task.onDisplayChanged(mDisplayContent);
+
+        assertTrue(mDisplayContent.mChangingContainers.contains(task));
+        verify(task.mSurfaceFreezer, never()).unfreeze(any());
+
+        // Remove the changing transition of this window when it is moved or reparented from the old
+        // display.
+        final DisplayContent newDc = createNewDisplay();
+        task.onDisplayChanged(newDc);
+
+        assertFalse(mDisplayContent.mChangingContainers.contains(task));
+        verify(task.mSurfaceFreezer).unfreeze(any());
+    }
+
+    @Test
     public void testHandleCompleteDeferredRemoval() {
         final DisplayContent displayContent = createNewDisplay();
         // Do not reparent activity to default display when removing the display.
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java
index 435c39c..69e3244 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java
@@ -413,6 +413,16 @@
     }
 
     @Test
+    public void testCanAffectSystemUiFlags_starting() {
+        final WindowState app = createWindow(null, TYPE_APPLICATION_STARTING, "app");
+        app.mActivityRecord.setVisible(true);
+        app.mStartingData = new SnapshotStartingData(mWm, null, 0);
+        assertFalse(app.canAffectSystemUiFlags());
+        app.mStartingData = new SplashScreenStartingData(mWm, 0, 0);
+        assertTrue(app.canAffectSystemUiFlags());
+    }
+
+    @Test
     public void testCanAffectSystemUiFlags_disallow() {
         final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
         app.mActivityRecord.setVisible(true);
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java b/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java
index 019b14d..4d31414 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java
@@ -1017,6 +1017,7 @@
         private ActivityInfo.WindowLayout mWindowLayout;
         private boolean mVisible = true;
         private ActivityOptions mLaunchIntoPipOpts;
+        private String mRequiredDisplayCategory;
 
         ActivityBuilder(ActivityTaskManagerService service) {
             mService = service;
@@ -1157,6 +1158,11 @@
             return this;
         }
 
+        ActivityBuilder setRequiredDisplayCategory(String requiredDisplayCategory) {
+            mRequiredDisplayCategory = requiredDisplayCategory;
+            return this;
+        }
+
         ActivityRecord build() {
             SystemServicesTestRule.checkHoldsLock(mService.mGlobalLock);
             try {
@@ -1201,6 +1207,9 @@
             aInfo.configChanges |= mConfigChanges;
             aInfo.taskAffinity = mAffinity;
             aInfo.windowLayout = mWindowLayout;
+            if (mRequiredDisplayCategory != null) {
+                aInfo.requiredDisplayCategory = mRequiredDisplayCategory;
+            }
 
             if (mCreateTask) {
                 mTask = new TaskBuilder(mService.mTaskSupervisor)
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/DspTrustedHotwordDetectorSession.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/DspTrustedHotwordDetectorSession.java
new file mode 100644
index 0000000..84bd7160
--- /dev/null
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/DspTrustedHotwordDetectorSession.java
@@ -0,0 +1,263 @@
+/*
+ * 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.server.voiceinteraction;
+
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_ERROR_EXCEPTION;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_PROCESS_RESTARTED_EXCEPTION;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_REJECTED_EXCEPTION;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECTED;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECT_TIMEOUT;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECTED;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECTED_FROM_RESTART;
+
+import android.annotation.NonNull;
+import android.content.Context;
+import android.hardware.soundtrigger.SoundTrigger;
+import android.media.permission.Identity;
+import android.os.IBinder;
+import android.os.PersistableBundle;
+import android.os.RemoteException;
+import android.os.SharedMemory;
+import android.service.voice.AlwaysOnHotwordDetector;
+import android.service.voice.HotwordDetectedResult;
+import android.service.voice.HotwordDetectionService;
+import android.service.voice.HotwordDetector;
+import android.service.voice.HotwordRejectedResult;
+import android.service.voice.IDspHotwordDetectionCallback;
+import android.util.Slog;
+
+import com.android.internal.annotations.GuardedBy;
+import com.android.internal.app.IHotwordRecognitionStatusCallback;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Locale;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * A class that provides Dsp trusted hotword detector to communicate with the {@link
+ * HotwordDetectionService}.
+ *
+ * This class can handle the hotword detection which detector is created by using
+ * {@link android.service.voice.VoiceInteractionService#createAlwaysOnHotwordDetector(String,
+ * Locale, PersistableBundle, SharedMemory, AlwaysOnHotwordDetector.Callback)}.
+ */
+final class DspTrustedHotwordDetectorSession extends HotwordDetectorSession {
+    private static final String TAG = "DspTrustedHotwordDetectorSession";
+
+    // The validation timeout value is 3 seconds for onDetect of DSP trigger event.
+    private static final long VALIDATION_TIMEOUT_MILLIS = 3000;
+    // Write the onDetect timeout metric when it takes more time than MAX_VALIDATION_TIMEOUT_MILLIS.
+    private static final long MAX_VALIDATION_TIMEOUT_MILLIS = 4000;
+
+    @GuardedBy("mLock")
+    private ScheduledFuture<?> mCancellationKeyPhraseDetectionFuture;
+
+    @GuardedBy("mLock")
+    private boolean mValidatingDspTrigger = false;
+
+    DspTrustedHotwordDetectorSession(
+            @NonNull HotwordDetectionConnection.ServiceConnection remoteHotwordDetectionService,
+            @NonNull Object lock, @NonNull Context context, @NonNull IBinder token,
+            @NonNull IHotwordRecognitionStatusCallback callback, int voiceInteractionServiceUid,
+            Identity voiceInteractorIdentity,
+            @NonNull ScheduledExecutorService scheduledExecutorService, boolean logging) {
+        super(remoteHotwordDetectionService, lock, context, token, callback,
+                voiceInteractionServiceUid, voiceInteractorIdentity, scheduledExecutorService,
+                logging);
+    }
+
+    @SuppressWarnings("GuardedBy")
+    void detectFromDspSourceLocked(SoundTrigger.KeyphraseRecognitionEvent recognitionEvent,
+            IHotwordRecognitionStatusCallback externalCallback) {
+        if (DEBUG) {
+            Slog.d(TAG, "detectFromDspSourceLocked");
+        }
+
+        AtomicBoolean timeoutDetected = new AtomicBoolean(false);
+        // TODO: consider making this a non-anonymous class.
+        IDspHotwordDetectionCallback internalCallback = new IDspHotwordDetectionCallback.Stub() {
+            @Override
+            public void onDetected(HotwordDetectedResult result) throws RemoteException {
+                if (DEBUG) {
+                    Slog.d(TAG, "onDetected");
+                }
+                synchronized (mLock) {
+                    if (mCancellationKeyPhraseDetectionFuture != null) {
+                        mCancellationKeyPhraseDetectionFuture.cancel(true);
+                    }
+                    if (timeoutDetected.get()) {
+                        return;
+                    }
+                    HotwordMetricsLogger.writeKeyphraseTriggerEvent(
+                            HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_DSP,
+                            HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECTED,
+                            mVoiceInteractionServiceUid);
+                    if (!mValidatingDspTrigger) {
+                        Slog.i(TAG, "Ignoring #onDetected due to a process restart");
+                        HotwordMetricsLogger.writeKeyphraseTriggerEvent(
+                                HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_DSP,
+                                METRICS_KEYPHRASE_TRIGGERED_DETECT_UNEXPECTED_CALLBACK,
+                                mVoiceInteractionServiceUid);
+                        return;
+                    }
+                    mValidatingDspTrigger = false;
+                    try {
+                        enforcePermissionsForDataDelivery();
+                        enforceExtraKeyphraseIdNotLeaked(result, recognitionEvent);
+                    } catch (SecurityException e) {
+                        Slog.i(TAG, "Ignoring #onDetected due to a SecurityException", e);
+                        HotwordMetricsLogger.writeKeyphraseTriggerEvent(
+                                HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_DSP,
+                                METRICS_KEYPHRASE_TRIGGERED_DETECT_SECURITY_EXCEPTION,
+                                mVoiceInteractionServiceUid);
+                        externalCallback.onError(CALLBACK_ONDETECTED_GOT_SECURITY_EXCEPTION);
+                        return;
+                    }
+                    saveProximityValueToBundle(result);
+                    HotwordDetectedResult newResult;
+                    try {
+                        newResult = mHotwordAudioStreamCopier.startCopyingAudioStreams(result);
+                    } catch (IOException e) {
+                        externalCallback.onError(CALLBACK_ONDETECTED_STREAM_COPY_ERROR);
+                        return;
+                    }
+                    externalCallback.onKeyphraseDetected(recognitionEvent, newResult);
+                    Slog.i(TAG, "Egressed " + HotwordDetectedResult.getUsageSize(newResult)
+                            + " bits from hotword trusted process");
+                    if (mDebugHotwordLogging) {
+                        Slog.i(TAG, "Egressed detected result: " + newResult);
+                    }
+                }
+            }
+
+            @Override
+            public void onRejected(HotwordRejectedResult result) throws RemoteException {
+                if (DEBUG) {
+                    Slog.d(TAG, "onRejected");
+                }
+                synchronized (mLock) {
+                    if (mCancellationKeyPhraseDetectionFuture != null) {
+                        mCancellationKeyPhraseDetectionFuture.cancel(true);
+                    }
+                    if (timeoutDetected.get()) {
+                        return;
+                    }
+                    HotwordMetricsLogger.writeKeyphraseTriggerEvent(
+                            HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_DSP,
+                            HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECTED,
+                            mVoiceInteractionServiceUid);
+                    if (!mValidatingDspTrigger) {
+                        Slog.i(TAG, "Ignoring #onRejected due to a process restart");
+                        HotwordMetricsLogger.writeKeyphraseTriggerEvent(
+                                HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_DSP,
+                                METRICS_KEYPHRASE_TRIGGERED_REJECT_UNEXPECTED_CALLBACK,
+                                mVoiceInteractionServiceUid);
+                        return;
+                    }
+                    mValidatingDspTrigger = false;
+                    externalCallback.onRejected(result);
+                    if (mDebugHotwordLogging && result != null) {
+                        Slog.i(TAG, "Egressed rejected result: " + result);
+                    }
+                }
+            }
+        };
+
+        mValidatingDspTrigger = true;
+        mRemoteHotwordDetectionService.run(service -> {
+            // We use the VALIDATION_TIMEOUT_MILLIS to inform that the client needs to invoke
+            // the callback before timeout value. In order to reduce the latency impact between
+            // server side and client side, we need to use another timeout value
+            // MAX_VALIDATION_TIMEOUT_MILLIS to monitor it.
+            mCancellationKeyPhraseDetectionFuture = mScheduledExecutorService.schedule(
+                    () -> {
+                        // TODO: avoid allocate every time
+                        timeoutDetected.set(true);
+                        Slog.w(TAG, "Timed out on #detectFromDspSource");
+                        HotwordMetricsLogger.writeKeyphraseTriggerEvent(
+                                HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_DSP,
+                                HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECT_TIMEOUT,
+                                mVoiceInteractionServiceUid);
+                        try {
+                            externalCallback.onError(CALLBACK_DETECT_TIMEOUT);
+                        } catch (RemoteException e) {
+                            Slog.w(TAG, "Failed to report onError status: ", e);
+                            HotwordMetricsLogger.writeDetectorEvent(
+                                    HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_DSP,
+                                    HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_ERROR_EXCEPTION,
+                                    mVoiceInteractionServiceUid);
+                        }
+                    },
+                    MAX_VALIDATION_TIMEOUT_MILLIS,
+                    TimeUnit.MILLISECONDS);
+            service.detectFromDspSource(
+                    recognitionEvent,
+                    recognitionEvent.getCaptureFormat(),
+                    VALIDATION_TIMEOUT_MILLIS,
+                    internalCallback);
+        });
+    }
+
+    @Override
+    @SuppressWarnings("GuardedBy")
+    void informRestartProcessLocked() {
+        // TODO(b/244598068): Check HotwordAudioStreamManager first
+        Slog.v(TAG, "informRestartProcessLocked");
+        if (mValidatingDspTrigger) {
+            // We're restarting the process while it's processing a DSP trigger, so report a
+            // rejection. This also allows the Interactor to startRecognition again
+            try {
+                mCallback.onRejected(new HotwordRejectedResult.Builder().build());
+                HotwordMetricsLogger.writeKeyphraseTriggerEvent(
+                        HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_DSP,
+                        HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECTED_FROM_RESTART,
+                        mVoiceInteractionServiceUid);
+            } catch (RemoteException e) {
+                Slog.w(TAG, "Failed to call #rejected");
+                HotwordMetricsLogger.writeDetectorEvent(
+                        HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_DSP,
+                        HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_REJECTED_EXCEPTION,
+                        mVoiceInteractionServiceUid);
+            }
+            mValidatingDspTrigger = false;
+        }
+        mUpdateStateAfterStartFinished.set(false);
+
+        try {
+            mCallback.onProcessRestarted();
+        } catch (RemoteException e) {
+            Slog.w(TAG, "Failed to communicate #onProcessRestarted", e);
+            HotwordMetricsLogger.writeDetectorEvent(
+                    HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_DSP,
+                    HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_PROCESS_RESTARTED_EXCEPTION,
+                    mVoiceInteractionServiceUid);
+        }
+
+        mPerformingExternalSourceHotwordDetection = false;
+        closeExternalAudioStreamLocked("process restarted");
+    }
+
+    @SuppressWarnings("GuardedBy")
+    public void dumpLocked(String prefix, PrintWriter pw) {
+        super.dumpLocked(prefix, pw);
+        pw.print(prefix); pw.print("mValidatingDspTrigger="); pw.println(mValidatingDspTrigger);
+    }
+}
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java
index 2ac25b6..6a7a2f9 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java
@@ -16,67 +16,27 @@
 
 package com.android.server.voiceinteraction;
 
-import static android.Manifest.permission.CAPTURE_AUDIO_HOTWORD;
-import static android.Manifest.permission.RECORD_AUDIO;
-import static android.service.attention.AttentionService.PROXIMITY_UNKNOWN;
-import static android.service.voice.HotwordDetectionService.AUDIO_SOURCE_EXTERNAL;
-import static android.service.voice.HotwordDetectionService.AUDIO_SOURCE_MICROPHONE;
-import static android.service.voice.HotwordDetectionService.ENABLE_PROXIMITY_RESULT;
-import static android.service.voice.HotwordDetectionService.INITIALIZATION_STATUS_SUCCESS;
-import static android.service.voice.HotwordDetectionService.INITIALIZATION_STATUS_UNKNOWN;
-import static android.service.voice.HotwordDetectionService.KEY_INITIALIZATION_STATUS;
-
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_ERROR;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_SUCCESS;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_UNKNOWN_NO_VALUE;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_UNKNOWN_OVER_MAX_CUSTOM_VALUE;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_UNKNOWN_TIMEOUT;
 import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_RESTARTED__REASON__AUDIO_SERVICE_DIED;
 import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_RESTARTED__REASON__SCHEDULE;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__APP_REQUEST_UPDATE_STATE;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_ERROR_EXCEPTION;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_PROCESS_RESTARTED_EXCEPTION;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_REJECTED_EXCEPTION;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_STATUS_REPORTED_EXCEPTION;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_UPDATE_STATE_AFTER_TIMEOUT;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALL_UPDATE_STATE_EXCEPTION;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__EXTERNAL_SOURCE_DETECTED;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__EXTERNAL_SOURCE_DETECT_SECURITY_EXCEPTION;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__EXTERNAL_SOURCE_REJECTED;
 import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__ON_CONNECTED;
 import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__ON_DISCONNECTED;
 import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__REQUEST_BIND_SERVICE;
 import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__REQUEST_BIND_SERVICE_FAIL;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__REQUEST_UPDATE_STATE;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__START_EXTERNAL_SOURCE_DETECTION;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__START_SOFTWARE_DETECTION;
 import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__DETECTOR_TYPE__NORMAL_DETECTOR;
 import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__DETECTOR_TYPE__TRUSTED_DETECTOR_DSP;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECTED;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECT_SECURITY_EXCEPTION;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECT_TIMEOUT;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECT_UNEXPECTED_CALLBACK;
 import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__KEYPHRASE_TRIGGER;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECTED;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECTED_FROM_RESTART;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECT_UNEXPECTED_CALLBACK;
-import static com.android.server.voiceinteraction.SoundTriggerSessionPermissionsDecorator.enforcePermissionForPreflight;
 
 import android.annotation.NonNull;
 import android.annotation.Nullable;
-import android.app.AppOpsManager;
-import android.attention.AttentionManagerInternal;
 import android.content.ComponentName;
 import android.content.ContentCaptureOptions;
 import android.content.Context;
 import android.content.Intent;
-import android.content.PermissionChecker;
 import android.hardware.soundtrigger.IRecognitionStatusCallback;
 import android.hardware.soundtrigger.SoundTrigger;
 import android.media.AudioFormat;
 import android.media.AudioManagerInternal;
 import android.media.permission.Identity;
-import android.media.permission.PermissionUtil;
 import android.os.Binder;
 import android.os.Bundle;
 import android.os.IBinder;
@@ -87,41 +47,29 @@
 import android.os.ServiceManager;
 import android.os.SharedMemory;
 import android.provider.DeviceConfig;
-import android.service.voice.HotwordDetectedResult;
 import android.service.voice.HotwordDetectionService;
 import android.service.voice.HotwordDetector;
-import android.service.voice.HotwordRejectedResult;
-import android.service.voice.IDspHotwordDetectionCallback;
-import android.service.voice.IHotwordDetectionService;
 import android.service.voice.IMicrophoneHotwordDetectionVoiceInteractionCallback;
+import android.service.voice.ISandboxedDetectionService;
 import android.service.voice.VoiceInteractionManagerInternal.HotwordDetectionServiceIdentity;
 import android.speech.IRecognitionServiceManager;
-import android.text.TextUtils;
-import android.util.Pair;
 import android.util.Slog;
+import android.util.SparseArray;
 import android.view.contentcapture.IContentCaptureManager;
 
 import com.android.internal.annotations.GuardedBy;
 import com.android.internal.app.IHotwordRecognitionStatusCallback;
-import com.android.internal.infra.AndroidFuture;
 import com.android.internal.infra.ServiceConnector;
 import com.android.server.LocalServices;
 import com.android.server.pm.permission.PermissionManagerServiceInternal;
 
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
 import java.io.PrintWriter;
-import java.time.Duration;
 import java.time.Instant;
-import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.Consumer;
 import java.util.function.Function;
 
 /**
@@ -132,63 +80,15 @@
     static final boolean DEBUG = false;
 
     private static final String KEY_RESTART_PERIOD_IN_SECONDS = "restart_period_in_seconds";
-    // TODO: These constants need to be refined.
-    // The validation timeout value is 3 seconds for onDetect of DSP trigger event.
-    private static final long VALIDATION_TIMEOUT_MILLIS = 3000;
-    // Write the onDetect timeout metric when it takes more time than MAX_VALIDATION_TIMEOUT_MILLIS.
-    private static final long MAX_VALIDATION_TIMEOUT_MILLIS = 4000;
-    private static final long MAX_UPDATE_TIMEOUT_MILLIS = 30000;
-    private static final long EXTERNAL_HOTWORD_CLEANUP_MILLIS = 2000;
-    private static final Duration MAX_UPDATE_TIMEOUT_DURATION =
-            Duration.ofMillis(MAX_UPDATE_TIMEOUT_MILLIS);
     private static final long RESET_DEBUG_HOTWORD_LOGGING_TIMEOUT_MILLIS = 60 * 60 * 1000; // 1 hour
     private static final int MAX_ISOLATED_PROCESS_NUMBER = 10;
 
-    // The error codes are used for onError callback
-    private static final int HOTWORD_DETECTION_SERVICE_DIED = -1;
-    private static final int CALLBACK_ONDETECTED_GOT_SECURITY_EXCEPTION = -2;
-    private static final int CALLBACK_DETECT_TIMEOUT = -3;
-    private static final int CALLBACK_ONDETECTED_STREAM_COPY_ERROR = -4;
-
-    // Hotword metrics
-    private static final int METRICS_INIT_UNKNOWN_TIMEOUT =
-            HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_UNKNOWN_TIMEOUT;
-    private static final int METRICS_INIT_UNKNOWN_NO_VALUE =
-            HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_UNKNOWN_NO_VALUE;
-    private static final int METRICS_INIT_UNKNOWN_OVER_MAX_CUSTOM_VALUE =
-            HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_UNKNOWN_OVER_MAX_CUSTOM_VALUE;
-    private static final int METRICS_INIT_CALLBACK_STATE_ERROR =
-            HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_ERROR;
-    private static final int METRICS_INIT_CALLBACK_STATE_SUCCESS =
-            HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_SUCCESS;
-
-    private static final int METRICS_KEYPHRASE_TRIGGERED_DETECT_SECURITY_EXCEPTION =
-            HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECT_SECURITY_EXCEPTION;
-    private static final int METRICS_KEYPHRASE_TRIGGERED_DETECT_UNEXPECTED_CALLBACK =
-            HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECT_UNEXPECTED_CALLBACK;
-    private static final int METRICS_KEYPHRASE_TRIGGERED_REJECT_UNEXPECTED_CALLBACK =
-            HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECT_UNEXPECTED_CALLBACK;
-
-    private static final int METRICS_EXTERNAL_SOURCE_DETECTED =
-            HOTWORD_DETECTOR_EVENTS__EVENT__EXTERNAL_SOURCE_DETECTED;
-    private static final int METRICS_EXTERNAL_SOURCE_REJECTED =
-            HOTWORD_DETECTOR_EVENTS__EVENT__EXTERNAL_SOURCE_REJECTED;
-    private static final int METRICS_EXTERNAL_SOURCE_DETECT_SECURITY_EXCEPTION =
-            HOTWORD_DETECTOR_EVENTS__EVENT__EXTERNAL_SOURCE_DETECT_SECURITY_EXCEPTION;
-    private static final int METRICS_CALLBACK_ON_STATUS_REPORTED_EXCEPTION =
-            HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_STATUS_REPORTED_EXCEPTION;
-
-    private final Executor mAudioCopyExecutor = Executors.newCachedThreadPool();
     // TODO: This may need to be a Handler(looper)
     private final ScheduledExecutorService mScheduledExecutorService =
             Executors.newSingleThreadScheduledExecutor();
-    private final AppOpsManager mAppOpsManager;
-    private final HotwordAudioStreamCopier mHotwordAudioStreamCopier;
     @Nullable private final ScheduledFuture<?> mCancellationTaskFuture;
-    private final AtomicBoolean mUpdateStateAfterStartFinished = new AtomicBoolean(false);
     private final IBinder.DeathRecipient mAudioServerDeathRecipient = this::audioServerDied;
-    private final @NonNull ServiceConnectionFactory mServiceConnectionFactory;
-    private final IHotwordRecognitionStatusCallback mCallback;
+    @NonNull private final ServiceConnectionFactory mServiceConnectionFactory;
     private final int mDetectorType;
     /**
      * Time after which each HotwordDetectionService process is stopped and replaced by a new one.
@@ -201,56 +101,38 @@
     final ComponentName mDetectionComponentName;
     final int mUser;
     final Context mContext;
-
-    @Nullable AttentionManagerInternal mAttentionManagerInternal = null;
-
-    final AttentionManagerInternal.ProximityUpdateCallbackInternal mProximityCallbackInternal =
-            this::setProximityValue;
-
-
     volatile HotwordDetectionServiceIdentity mIdentity;
-    private IMicrophoneHotwordDetectionVoiceInteractionCallback mSoftwareCallback;
     private Instant mLastRestartInstant;
 
-    private ScheduledFuture<?> mCancellationKeyPhraseDetectionFuture;
     private ScheduledFuture<?> mDebugHotwordLoggingTimeoutFuture = null;
 
     /** Identity used for attributing app ops when delivering data to the Interactor. */
     @GuardedBy("mLock")
     @Nullable
     private final Identity mVoiceInteractorIdentity;
-    @GuardedBy("mLock")
-    private ParcelFileDescriptor mCurrentAudioSink;
-    @GuardedBy("mLock")
-    private boolean mValidatingDspTrigger = false;
-    @GuardedBy("mLock")
-    private boolean mPerformingSoftwareHotwordDetection;
-    private @NonNull ServiceConnection mRemoteHotwordDetectionService;
+    @NonNull private ServiceConnection mRemoteHotwordDetectionService;
     private IBinder mAudioFlinger;
-    private boolean mDebugHotwordLogging = false;
     @GuardedBy("mLock")
-    private double mProximityMeters = PROXIMITY_UNKNOWN;
+    private boolean mDebugHotwordLogging = false;
+
+    /**
+     * For multiple detectors feature, we only support one AlwaysOnHotwordDetector and one
+     * SoftwareHotwordDetector at the same time. We use SparseArray with detector type as the key
+     * to record the detectors.
+     */
+    @GuardedBy("mLock")
+    private final SparseArray<HotwordDetectorSession> mHotwordDetectorSessions =
+            new SparseArray<>();
 
     HotwordDetectionConnection(Object lock, Context context, int voiceInteractionServiceUid,
             Identity voiceInteractorIdentity, ComponentName serviceName, int userId,
-            boolean bindInstantServiceAllowed, @Nullable PersistableBundle options,
-            @Nullable SharedMemory sharedMemory,
-            @NonNull IHotwordRecognitionStatusCallback callback, int detectorType) {
-        if (callback == null) {
-            Slog.w(TAG, "Callback is null while creating connection");
-            throw new IllegalArgumentException("Callback is null while creating connection");
-        }
+            boolean bindInstantServiceAllowed, int detectorType) {
         mLock = lock;
         mContext = context;
         mVoiceInteractionServiceUid = voiceInteractionServiceUid;
         mVoiceInteractorIdentity = voiceInteractorIdentity;
-        mAppOpsManager = mContext.getSystemService(AppOpsManager.class);
-        mHotwordAudioStreamCopier = new HotwordAudioStreamCopier(mAppOpsManager, detectorType,
-                mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
-                mVoiceInteractorIdentity.attributionTag);
         mDetectionComponentName = serviceName;
         mUser = userId;
-        mCallback = callback;
         mDetectorType = detectorType;
         mReStartPeriodSeconds = DeviceConfig.getInt(DeviceConfig.NAMESPACE_VOICE_INTERACTION,
                 KEY_RESTART_PERIOD_IN_SECONDS, 0);
@@ -259,17 +141,8 @@
         initAudioFlingerLocked();
 
         mServiceConnectionFactory = new ServiceConnectionFactory(intent, bindInstantServiceAllowed);
-
         mRemoteHotwordDetectionService = mServiceConnectionFactory.createLocked();
-        if (ENABLE_PROXIMITY_RESULT) {
-            mAttentionManagerInternal = LocalServices.getService(AttentionManagerInternal.class);
-            if (mAttentionManagerInternal != null) {
-                mAttentionManagerInternal.onStartProximityUpdates(mProximityCallbackInternal);
-            }
-        }
-
         mLastRestartInstant = Instant.now();
-        updateStateAfterProcessStart(options, sharedMemory);
 
         if (mReStartPeriodSeconds <= 0) {
             mCancellationTaskFuture = null;
@@ -281,7 +154,8 @@
                 synchronized (mLock) {
                     restartProcessLocked();
                     HotwordMetricsLogger.writeServiceRestartEvent(mDetectorType,
-                            HOTWORD_DETECTION_SERVICE_RESTARTED__REASON__SCHEDULE);
+                            HOTWORD_DETECTION_SERVICE_RESTARTED__REASON__SCHEDULE,
+                            mVoiceInteractionServiceUid);
                 }
             }, mReStartPeriodSeconds, mReStartPeriodSeconds, TimeUnit.SECONDS);
         }
@@ -316,110 +190,19 @@
             // conditions with audio reading in the service.
             restartProcessLocked();
             HotwordMetricsLogger.writeServiceRestartEvent(mDetectorType,
-                    HOTWORD_DETECTION_SERVICE_RESTARTED__REASON__AUDIO_SERVICE_DIED);
+                    HOTWORD_DETECTION_SERVICE_RESTARTED__REASON__AUDIO_SERVICE_DIED,
+                    mVoiceInteractionServiceUid);
         }
     }
 
-    private void updateStateAfterProcessStart(
-            PersistableBundle options, SharedMemory sharedMemory) {
-        if (DEBUG) {
-            Slog.d(TAG, "updateStateAfterProcessStart");
-        }
-        mRemoteHotwordDetectionService.postAsync(service -> {
-            AndroidFuture<Void> future = new AndroidFuture<>();
-            IRemoteCallback statusCallback = new IRemoteCallback.Stub() {
-                @Override
-                public void sendResult(Bundle bundle) throws RemoteException {
-                    if (DEBUG) {
-                        Slog.d(TAG, "updateState finish");
-                    }
-                    future.complete(null);
-                    if (mUpdateStateAfterStartFinished.getAndSet(true)) {
-                        Slog.w(TAG, "call callback after timeout");
-                        HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                                HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_UPDATE_STATE_AFTER_TIMEOUT,
-                                mVoiceInteractionServiceUid);
-                        return;
-                    }
-                    Pair<Integer, Integer> statusResultPair = getInitStatusAndMetricsResult(bundle);
-                    int status = statusResultPair.first;
-                    int initResultMetricsResult = statusResultPair.second;
-                    try {
-                        mCallback.onStatusReported(status);
-                        HotwordMetricsLogger.writeServiceInitResultEvent(mDetectorType,
-                                initResultMetricsResult);
-                    } catch (RemoteException e) {
-                        Slog.w(TAG, "Failed to report initialization status: " + e);
-                        HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                                METRICS_CALLBACK_ON_STATUS_REPORTED_EXCEPTION,
-                                mVoiceInteractionServiceUid);
-                    }
-                }
-            };
-            try {
-                service.updateState(options, sharedMemory, statusCallback);
-                HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                        HOTWORD_DETECTOR_EVENTS__EVENT__REQUEST_UPDATE_STATE,
-                        mVoiceInteractionServiceUid);
-            } catch (RemoteException e) {
-                // TODO: (b/181842909) Report an error to voice interactor
-                Slog.w(TAG, "Failed to updateState for HotwordDetectionService", e);
-                HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                        HOTWORD_DETECTOR_EVENTS__EVENT__CALL_UPDATE_STATE_EXCEPTION,
-                        mVoiceInteractionServiceUid);
-            }
-            return future.orTimeout(MAX_UPDATE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
-        }).whenComplete((res, err) -> {
-            if (err instanceof TimeoutException) {
-                Slog.w(TAG, "updateState timed out");
-                if (mUpdateStateAfterStartFinished.getAndSet(true)) {
-                    return;
-                }
-                try {
-                    mCallback.onStatusReported(INITIALIZATION_STATUS_UNKNOWN);
-                    HotwordMetricsLogger.writeServiceInitResultEvent(mDetectorType,
-                            METRICS_INIT_UNKNOWN_TIMEOUT);
-                } catch (RemoteException e) {
-                    Slog.w(TAG, "Failed to report initialization status UNKNOWN", e);
-                    HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                            METRICS_CALLBACK_ON_STATUS_REPORTED_EXCEPTION,
-                            mVoiceInteractionServiceUid);
-                }
-            } else if (err != null) {
-                Slog.w(TAG, "Failed to update state: " + err);
-            } else {
-                // NOTE: so far we don't need to take any action.
-            }
-        });
-    }
-
-    private static Pair<Integer, Integer> getInitStatusAndMetricsResult(Bundle bundle) {
-        if (bundle == null) {
-            return new Pair<>(INITIALIZATION_STATUS_UNKNOWN, METRICS_INIT_UNKNOWN_NO_VALUE);
-        }
-        int status = bundle.getInt(KEY_INITIALIZATION_STATUS, INITIALIZATION_STATUS_UNKNOWN);
-        if (status > HotwordDetectionService.getMaxCustomInitializationStatus()) {
-            return new Pair<>(INITIALIZATION_STATUS_UNKNOWN,
-                    status == INITIALIZATION_STATUS_UNKNOWN
-                    ? METRICS_INIT_UNKNOWN_NO_VALUE
-                    : METRICS_INIT_UNKNOWN_OVER_MAX_CUSTOM_VALUE);
-        }
-        // TODO: should guard against negative here
-        int metricsResult = status == INITIALIZATION_STATUS_SUCCESS
-                ? METRICS_INIT_CALLBACK_STATE_SUCCESS
-                : METRICS_INIT_CALLBACK_STATE_ERROR;
-        return new Pair<>(status, metricsResult);
-    }
-
-    private boolean isBound() {
-        synchronized (mLock) {
-            return mRemoteHotwordDetectionService.isBound();
-        }
-    }
-
+    @SuppressWarnings("GuardedBy")
     void cancelLocked() {
         Slog.v(TAG, "cancelLocked");
         clearDebugHotwordLoggingTimeoutLocked();
+        runForEachHotwordDetectorSessionLocked((session) -> {
+            session.destroyLocked();
+        });
+        mHotwordDetectorSessions.clear();
         mDebugHotwordLogging = false;
         mRemoteHotwordDetectionService.unbind();
         LocalServices.getService(PermissionManagerServiceInternal.class)
@@ -429,162 +212,73 @@
         }
         mIdentity = null;
         if (mCancellationTaskFuture != null) {
-            mCancellationTaskFuture.cancel(/* may interrupt */ true);
+            mCancellationTaskFuture.cancel(/* mayInterruptIfRunning= */ true);
         }
         if (mAudioFlinger != null) {
             mAudioFlinger.unlinkToDeath(mAudioServerDeathRecipient, /* flags= */ 0);
         }
-        if (mAttentionManagerInternal != null) {
-            mAttentionManagerInternal.onStopProximityUpdates(mProximityCallbackInternal);
-        }
     }
 
-    void updateStateLocked(PersistableBundle options, SharedMemory sharedMemory) {
-        HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                HOTWORD_DETECTOR_EVENTS__EVENT__APP_REQUEST_UPDATE_STATE,
-                mVoiceInteractionServiceUid);
-
-        // Prevent doing the init late, so restart is handled equally to a clean process start.
-        // TODO(b/191742511): this logic needs a test
-        if (!mUpdateStateAfterStartFinished.get()
-                && Instant.now().minus(MAX_UPDATE_TIMEOUT_DURATION).isBefore(mLastRestartInstant)) {
-            Slog.v(TAG, "call updateStateAfterProcessStart");
-            updateStateAfterProcessStart(options, sharedMemory);
-        } else {
-            mRemoteHotwordDetectionService.run(
-                    service -> service.updateState(options, sharedMemory, null /* callback */));
+    @SuppressWarnings("GuardedBy")
+    void updateStateLocked(PersistableBundle options, SharedMemory sharedMemory,
+            @NonNull IBinder token) {
+        final HotwordDetectorSession session = getDetectorSessionByTokenLocked(token);
+        if (session == null) {
+            Slog.v(TAG, "Not found the detector by token");
+            return;
         }
+        session.updateStateLocked(options, sharedMemory, mLastRestartInstant);
     }
 
-    void startListeningFromMic(
+    /**
+     * This method is only used by SoftwareHotwordDetector.
+     */
+    void startListeningFromMicLocked(
             AudioFormat audioFormat,
             IMicrophoneHotwordDetectionVoiceInteractionCallback callback) {
         if (DEBUG) {
-            Slog.d(TAG, "startListeningFromMic");
+            Slog.d(TAG, "startListeningFromMicLocked");
         }
-        mSoftwareCallback = callback;
-
-        synchronized (mLock) {
-            if (mPerformingSoftwareHotwordDetection) {
-                Slog.i(TAG, "Hotword validation is already in progress, ignoring.");
-                return;
-            }
-            mPerformingSoftwareHotwordDetection = true;
-
-            startListeningFromMicLocked();
+        // We only support one Dsp trusted hotword detector and one software hotword detector at
+        // the same time, so we can reuse original single software trusted hotword mechanism.
+        final SoftwareTrustedHotwordDetectorSession session =
+                getSoftwareTrustedHotwordDetectorSessionLocked();
+        if (session == null) {
+            return;
         }
+        session.startListeningFromMicLocked(audioFormat, callback);
     }
 
-    private void startListeningFromMicLocked() {
-        // TODO: consider making this a non-anonymous class.
-        IDspHotwordDetectionCallback internalCallback = new IDspHotwordDetectionCallback.Stub() {
-            @Override
-            public void onDetected(HotwordDetectedResult result) throws RemoteException {
-                if (DEBUG) {
-                    Slog.d(TAG, "onDetected");
-                }
-                synchronized (mLock) {
-                    HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                            mDetectorType,
-                            HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECTED);
-                    if (!mPerformingSoftwareHotwordDetection) {
-                        Slog.i(TAG, "Hotword detection has already completed");
-                        HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                                mDetectorType,
-                                METRICS_KEYPHRASE_TRIGGERED_DETECT_UNEXPECTED_CALLBACK);
-                        return;
-                    }
-                    mPerformingSoftwareHotwordDetection = false;
-                    try {
-                        enforcePermissionsForDataDelivery();
-                    } catch (SecurityException e) {
-                        HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                                mDetectorType,
-                                METRICS_KEYPHRASE_TRIGGERED_DETECT_SECURITY_EXCEPTION);
-                        mSoftwareCallback.onError();
-                        return;
-                    }
-                    saveProximityValueToBundle(result);
-                    HotwordDetectedResult newResult;
-                    try {
-                        newResult = mHotwordAudioStreamCopier.startCopyingAudioStreams(result);
-                    } catch (IOException e) {
-                        // TODO: Write event
-                        mSoftwareCallback.onError();
-                        return;
-                    }
-                    mSoftwareCallback.onDetected(newResult, null, null);
-                    Slog.i(TAG, "Egressed " + HotwordDetectedResult.getUsageSize(newResult)
-                            + " bits from hotword trusted process");
-                    if (mDebugHotwordLogging) {
-                        Slog.i(TAG, "Egressed detected result: " + newResult);
-                    }
-                }
-            }
-
-            @Override
-            public void onRejected(HotwordRejectedResult result) throws RemoteException {
-                if (DEBUG) {
-                    Slog.wtf(TAG, "onRejected");
-                }
-                HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                        mDetectorType,
-                        HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECTED);
-                // onRejected isn't allowed here, and we are not expecting it.
-            }
-        };
-
-        mRemoteHotwordDetectionService.run(
-                service -> service.detectFromMicrophoneSource(
-                        null,
-                        AUDIO_SOURCE_MICROPHONE,
-                        null,
-                        null,
-                        internalCallback));
-        HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                HOTWORD_DETECTOR_EVENTS__EVENT__START_SOFTWARE_DETECTION,
-                mVoiceInteractionServiceUid);
-    }
-
-    public void startListeningFromExternalSource(
+    public void startListeningFromExternalSourceLocked(
             ParcelFileDescriptor audioStream,
             AudioFormat audioFormat,
             @Nullable PersistableBundle options,
+            @NonNull IBinder token,
             IMicrophoneHotwordDetectionVoiceInteractionCallback callback) {
         if (DEBUG) {
-            Slog.d(TAG, "startListeningFromExternalSource");
+            Slog.d(TAG, "startListeningFromExternalSourceLocked");
         }
-
-        handleExternalSourceHotwordDetection(
-                audioStream,
-                audioFormat,
-                options,
-                callback);
-    }
-
-    void stopListening() {
-        if (DEBUG) {
-            Slog.d(TAG, "stopListening");
-        }
-        synchronized (mLock) {
-            stopListeningLocked();
-        }
-    }
-
-    private void stopListeningLocked() {
-        if (!mPerformingSoftwareHotwordDetection) {
-            Slog.i(TAG, "Hotword detection is not running");
+        final HotwordDetectorSession session = getDetectorSessionByTokenLocked(token);
+        if (session == null) {
+            Slog.v(TAG, "Not found the detector by token");
             return;
         }
-        mPerformingSoftwareHotwordDetection = false;
+        session.startListeningFromExternalSourceLocked(audioStream, audioFormat, options, callback);
+    }
 
-        mRemoteHotwordDetectionService.run(IHotwordDetectionService::stopDetection);
-
-        if (mCurrentAudioSink != null) {
-            Slog.i(TAG, "Closing audio stream to hotword detector: stopping requested");
-            bestEffortClose(mCurrentAudioSink);
+    /**
+     * This method is only used by SoftwareHotwordDetector.
+     */
+    void stopListeningFromMicLocked() {
+        if (DEBUG) {
+            Slog.d(TAG, "stopListeningFromMicLocked");
         }
-        mCurrentAudioSink = null;
+        final SoftwareTrustedHotwordDetectorSession session =
+                getSoftwareTrustedHotwordDetectorSessionLocked();
+        if (session == null) {
+            return;
+        }
+        session.stopListeningFromMicLocked();
     }
 
     void triggerHardwareRecognitionEventForTestLocked(
@@ -596,130 +290,21 @@
         detectFromDspSource(event, callback);
     }
 
-    void detectFromDspSource(SoundTrigger.KeyphraseRecognitionEvent recognitionEvent,
+    private void detectFromDspSource(SoundTrigger.KeyphraseRecognitionEvent recognitionEvent,
             IHotwordRecognitionStatusCallback externalCallback) {
         if (DEBUG) {
             Slog.d(TAG, "detectFromDspSource");
         }
-
-        AtomicBoolean timeoutDetected = new AtomicBoolean(false);
-        // TODO: consider making this a non-anonymous class.
-        IDspHotwordDetectionCallback internalCallback = new IDspHotwordDetectionCallback.Stub() {
-            @Override
-            public void onDetected(HotwordDetectedResult result) throws RemoteException {
-                if (DEBUG) {
-                    Slog.d(TAG, "onDetected");
-                }
-                synchronized (mLock) {
-                    if (mCancellationKeyPhraseDetectionFuture != null) {
-                        mCancellationKeyPhraseDetectionFuture.cancel(true);
-                    }
-                    if (timeoutDetected.get()) {
-                        return;
-                    }
-                    HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                            mDetectorType,
-                            HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECTED);
-                    if (!mValidatingDspTrigger) {
-                        Slog.i(TAG, "Ignoring #onDetected due to a process restart");
-                        HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                                mDetectorType,
-                                METRICS_KEYPHRASE_TRIGGERED_DETECT_UNEXPECTED_CALLBACK);
-                        return;
-                    }
-                    mValidatingDspTrigger = false;
-                    try {
-                        enforcePermissionsForDataDelivery();
-                        enforceExtraKeyphraseIdNotLeaked(result, recognitionEvent);
-                    } catch (SecurityException e) {
-                        Slog.i(TAG, "Ignoring #onDetected due to a SecurityException", e);
-                        HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                                mDetectorType,
-                                METRICS_KEYPHRASE_TRIGGERED_DETECT_SECURITY_EXCEPTION);
-                        externalCallback.onError(CALLBACK_ONDETECTED_GOT_SECURITY_EXCEPTION);
-                        return;
-                    }
-                    saveProximityValueToBundle(result);
-                    HotwordDetectedResult newResult;
-                    try {
-                        newResult = mHotwordAudioStreamCopier.startCopyingAudioStreams(result);
-                    } catch (IOException e) {
-                        // TODO: Write event
-                        externalCallback.onError(CALLBACK_ONDETECTED_STREAM_COPY_ERROR);
-                        return;
-                    }
-                    externalCallback.onKeyphraseDetected(recognitionEvent, newResult);
-                    Slog.i(TAG, "Egressed " + HotwordDetectedResult.getUsageSize(newResult)
-                            + " bits from hotword trusted process");
-                    if (mDebugHotwordLogging) {
-                        Slog.i(TAG, "Egressed detected result: " + newResult);
-                    }
-                }
-            }
-
-            @Override
-            public void onRejected(HotwordRejectedResult result) throws RemoteException {
-                if (DEBUG) {
-                    Slog.d(TAG, "onRejected");
-                }
-                synchronized (mLock) {
-                    if (mCancellationKeyPhraseDetectionFuture != null) {
-                        mCancellationKeyPhraseDetectionFuture.cancel(true);
-                    }
-                    if (timeoutDetected.get()) {
-                        return;
-                    }
-                    HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                            mDetectorType,
-                            HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECTED);
-                    if (!mValidatingDspTrigger) {
-                        Slog.i(TAG, "Ignoring #onRejected due to a process restart");
-                        HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                                mDetectorType,
-                                METRICS_KEYPHRASE_TRIGGERED_REJECT_UNEXPECTED_CALLBACK);
-                        return;
-                    }
-                    mValidatingDspTrigger = false;
-                    externalCallback.onRejected(result);
-                    if (mDebugHotwordLogging && result != null) {
-                        Slog.i(TAG, "Egressed rejected result: " + result);
-                    }
-                }
-            }
-        };
-
+        // We only support one Dsp trusted hotword detector and one software hotword detector at
+        // the same time, so we can reuse original single Dsp trusted hotword mechanism.
         synchronized (mLock) {
-            mValidatingDspTrigger = true;
-            mRemoteHotwordDetectionService.run(service -> {
-                // We use the VALIDATION_TIMEOUT_MILLIS to inform that the client needs to invoke
-                // the callback before timeout value. In order to reduce the latency impact between
-                // server side and client side, we need to use another timeout value
-                // MAX_VALIDATION_TIMEOUT_MILLIS to monitor it.
-                mCancellationKeyPhraseDetectionFuture = mScheduledExecutorService.schedule(
-                        () -> {
-                            // TODO: avoid allocate every time
-                            timeoutDetected.set(true);
-                            Slog.w(TAG, "Timed out on #detectFromDspSource");
-                            HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                                    mDetectorType,
-                                    HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECT_TIMEOUT);
-                            try {
-                                externalCallback.onError(CALLBACK_DETECT_TIMEOUT);
-                            } catch (RemoteException e) {
-                                Slog.w(TAG, "Failed to report onError status: ", e);
-                                HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                                        HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_ERROR_EXCEPTION,
-                                        mVoiceInteractionServiceUid);
-                            }
-                        },
-                        MAX_VALIDATION_TIMEOUT_MILLIS,
-                        TimeUnit.MILLISECONDS);
-                service.detectFromDspSource(
-                        recognitionEvent,
-                        recognitionEvent.getCaptureFormat(),
-                        VALIDATION_TIMEOUT_MILLIS,
-                        internalCallback);
-            });
+            final DspTrustedHotwordDetectorSession session =
+                    getDspTrustedHotwordDetectorSessionLocked();
+            if (session == null || !session.isSameCallback(externalCallback)) {
+                Slog.v(TAG, "Not found the Dsp detector by callback");
+                return;
+            }
+            session.detectFromDspSourceLocked(recognitionEvent, externalCallback);
         }
     }
 
@@ -730,10 +315,14 @@
         }
     }
 
+    @SuppressWarnings("GuardedBy")
     void setDebugHotwordLoggingLocked(boolean logging) {
         Slog.v(TAG, "setDebugHotwordLoggingLocked: " + logging);
         clearDebugHotwordLoggingTimeoutLocked();
         mDebugHotwordLogging = logging;
+        runForEachHotwordDetectorSessionLocked((session) -> {
+            session.setDebugHotwordLoggingLocked(logging);
+        });
 
         if (logging) {
             // Reset mDebugHotwordLogging to false after one hour
@@ -741,6 +330,9 @@
                 Slog.v(TAG, "Timeout to reset mDebugHotwordLogging to false");
                 synchronized (mLock) {
                     mDebugHotwordLogging = false;
+                    runForEachHotwordDetectorSessionLocked((session) -> {
+                        session.setDebugHotwordLoggingLocked(false);
+                    });
                 }
             }, RESET_DEBUG_HOTWORD_LOGGING_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
         }
@@ -748,66 +340,31 @@
 
     private void clearDebugHotwordLoggingTimeoutLocked() {
         if (mDebugHotwordLoggingTimeoutFuture != null) {
-            mDebugHotwordLoggingTimeoutFuture.cancel(/* mayInterruptIfRunning= */true);
+            mDebugHotwordLoggingTimeoutFuture.cancel(/* mayInterruptIfRunning= */ true);
             mDebugHotwordLoggingTimeoutFuture = null;
         }
     }
 
+    @SuppressWarnings("GuardedBy")
     private void restartProcessLocked() {
         // TODO(b/244598068): Check HotwordAudioStreamManager first
         Slog.v(TAG, "Restarting hotword detection process");
         ServiceConnection oldConnection = mRemoteHotwordDetectionService;
         HotwordDetectionServiceIdentity previousIdentity = mIdentity;
 
-        // TODO(volnov): this can be done after connect() has been successful.
-        if (mValidatingDspTrigger) {
-            // We're restarting the process while it's processing a DSP trigger, so report a
-            // rejection. This also allows the Interactor to startReco again
-            try {
-                mCallback.onRejected(new HotwordRejectedResult.Builder().build());
-                HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                        mDetectorType,
-                        HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECTED_FROM_RESTART);
-            } catch (RemoteException e) {
-                Slog.w(TAG, "Failed to call #rejected");
-                HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                        HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_REJECTED_EXCEPTION,
-                        mVoiceInteractionServiceUid);
-            }
-            mValidatingDspTrigger = false;
-        }
-
-        mUpdateStateAfterStartFinished.set(false);
         mLastRestartInstant = Instant.now();
-
         // Recreate connection to reset the cache.
         mRemoteHotwordDetectionService = mServiceConnectionFactory.createLocked();
 
-        Slog.v(TAG, "Started the new process, issuing #onProcessRestarted");
-        try {
-            mCallback.onProcessRestarted();
-        } catch (RemoteException e) {
-            Slog.w(TAG, "Failed to communicate #onProcessRestarted", e);
-            HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                    HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_PROCESS_RESTARTED_EXCEPTION,
-                    mVoiceInteractionServiceUid);
-        }
-
-        // Restart listening from microphone if the hotword process has been restarted.
-        if (mPerformingSoftwareHotwordDetection) {
-            Slog.i(TAG, "Process restarted: calling startRecognition() again");
-            startListeningFromMicLocked();
-        }
-
-        if (mCurrentAudioSink != null) {
-            Slog.i(TAG, "Closing external audio stream to hotword detector: process restarted");
-            bestEffortClose(mCurrentAudioSink);
-            mCurrentAudioSink = null;
-        }
-
+        Slog.v(TAG, "Started the new process, dispatching processRestarted to detector");
+        runForEachHotwordDetectorSessionLocked((session) -> {
+            session.updateRemoteHotwordDetectionServiceLocked(mRemoteHotwordDetectionService);
+            session.informRestartProcessLocked();
+        });
         if (DEBUG) {
-            Slog.i(TAG, "#onProcessRestarted called, unbinding from the old process");
+            Slog.i(TAG, "processRestarted is dispatched done, unbinding from the old process");
         }
+
         oldConnection.ignoreConnectionStatusEvents();
         oldConnection.unbind();
         if (previousIdentity != null) {
@@ -816,14 +373,15 @@
     }
 
     static final class SoundTriggerCallback extends IRecognitionStatusCallback.Stub {
-        private SoundTrigger.KeyphraseRecognitionEvent mRecognitionEvent;
         private final HotwordDetectionConnection mHotwordDetectionConnection;
         private final IHotwordRecognitionStatusCallback mExternalCallback;
+        private final int mVoiceInteractionServiceUid;
 
         SoundTriggerCallback(IHotwordRecognitionStatusCallback callback,
-                HotwordDetectionConnection connection) {
+                HotwordDetectionConnection connection, int uid) {
             mHotwordDetectionConnection = connection;
             mExternalCallback = callback;
+            mVoiceInteractionServiceUid = uid;
         }
 
         @Override
@@ -836,14 +394,15 @@
             if (useHotwordDetectionService) {
                 HotwordMetricsLogger.writeKeyphraseTriggerEvent(
                         HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__DETECTOR_TYPE__TRUSTED_DETECTOR_DSP,
-                        HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__KEYPHRASE_TRIGGER);
-                mRecognitionEvent = recognitionEvent;
+                        HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__KEYPHRASE_TRIGGER,
+                        mVoiceInteractionServiceUid);
                 mHotwordDetectionConnection.detectFromDspSource(
                         recognitionEvent, mExternalCallback);
             } else {
                 HotwordMetricsLogger.writeKeyphraseTriggerEvent(
                         HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__DETECTOR_TYPE__NORMAL_DETECTOR,
-                        HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__KEYPHRASE_TRIGGER);
+                        HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__KEYPHRASE_TRIGGER,
+                        mVoiceInteractionServiceUid);
                 mExternalCallback.onKeyphraseDetected(recognitionEvent, null);
             }
         }
@@ -872,160 +431,20 @@
     }
 
     public void dump(String prefix, PrintWriter pw) {
-        pw.print(prefix); pw.print("mReStartPeriodSeconds="); pw.println(mReStartPeriodSeconds);
-        pw.print(prefix);
-        pw.print("mBound=" + mRemoteHotwordDetectionService.isBound());
-        pw.print(", mValidatingDspTrigger=" + mValidatingDspTrigger);
-        pw.print(", mPerformingSoftwareHotwordDetection=" + mPerformingSoftwareHotwordDetection);
-        pw.print(", mRestartCount=" + mServiceConnectionFactory.mRestartCount);
-        pw.print(", mLastRestartInstant=" + mLastRestartInstant);
-        pw.println(", mDetectorType=" + HotwordDetector.detectorTypeToString(mDetectorType));
-    }
-
-    private void handleExternalSourceHotwordDetection(
-            ParcelFileDescriptor audioStream,
-            AudioFormat audioFormat,
-            @Nullable PersistableBundle options,
-            IMicrophoneHotwordDetectionVoiceInteractionCallback callback) {
-        if (DEBUG) {
-            Slog.d(TAG, "#handleExternalSourceHotwordDetection");
-        }
-        InputStream audioSource = new ParcelFileDescriptor.AutoCloseInputStream(audioStream);
-
-        Pair<ParcelFileDescriptor, ParcelFileDescriptor> clientPipe = createPipe();
-        if (clientPipe == null) {
-            // TODO: Need to propagate as unknown error or something?
-            return;
-        }
-        ParcelFileDescriptor serviceAudioSink = clientPipe.second;
-        ParcelFileDescriptor serviceAudioSource = clientPipe.first;
-
         synchronized (mLock) {
-            mCurrentAudioSink = serviceAudioSink;
+            pw.print(prefix); pw.print("mReStartPeriodSeconds="); pw.println(mReStartPeriodSeconds);
+            pw.print(prefix); pw.print("mBound=");
+            pw.println(mRemoteHotwordDetectionService.isBound());
+            pw.print(prefix); pw.print("mRestartCount=");
+            pw.println(mServiceConnectionFactory.mRestartCount);
+            pw.print(prefix); pw.print("mLastRestartInstant="); pw.println(mLastRestartInstant);
+            pw.print(prefix); pw.print("mDetectorType=");
+            pw.println(HotwordDetector.detectorTypeToString(mDetectorType));
+            pw.print(prefix); pw.println("HotwordDetectorSession(s)");
+            runForEachHotwordDetectorSessionLocked((session) -> {
+                session.dumpLocked(prefix, pw);
+            });
         }
-
-        mAudioCopyExecutor.execute(() -> {
-            try (InputStream source = audioSource;
-                 OutputStream fos =
-                         new ParcelFileDescriptor.AutoCloseOutputStream(serviceAudioSink)) {
-
-                byte[] buffer = new byte[1024];
-                while (true) {
-                    int bytesRead = source.read(buffer, 0, 1024);
-
-                    if (bytesRead < 0) {
-                        Slog.i(TAG, "Reached end of stream for external hotword");
-                        break;
-                    }
-
-                    // TODO: First write to ring buffer to make sure we don't lose data if the next
-                    // statement fails.
-                    // ringBuffer.append(buffer, bytesRead);
-                    fos.write(buffer, 0, bytesRead);
-                }
-            } catch (IOException e) {
-                Slog.w(TAG, "Failed supplying audio data to validator", e);
-
-                try {
-                    callback.onError();
-                } catch (RemoteException ex) {
-                    Slog.w(TAG, "Failed to report onError status: " + ex);
-                    HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                            HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_ERROR_EXCEPTION,
-                            mVoiceInteractionServiceUid);
-                }
-            } finally {
-                synchronized (mLock) {
-                    mCurrentAudioSink = null;
-                }
-            }
-        });
-
-        // TODO: handle cancellations well
-        // TODO: what if we cancelled and started a new one?
-        mRemoteHotwordDetectionService.run(
-                service -> {
-                    service.detectFromMicrophoneSource(
-                            serviceAudioSource,
-                            // TODO: consider making a proxy callback + copy of audio format
-                            AUDIO_SOURCE_EXTERNAL,
-                            audioFormat,
-                            options,
-                            new IDspHotwordDetectionCallback.Stub() {
-                                @Override
-                                public void onRejected(HotwordRejectedResult result)
-                                        throws RemoteException {
-                                    HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                                            METRICS_EXTERNAL_SOURCE_REJECTED,
-                                            mVoiceInteractionServiceUid);
-                                    mScheduledExecutorService.schedule(
-                                            () -> {
-                                                bestEffortClose(serviceAudioSink, audioSource);
-                                            },
-                                            EXTERNAL_HOTWORD_CLEANUP_MILLIS,
-                                            TimeUnit.MILLISECONDS);
-
-                                    callback.onRejected(result);
-
-                                    if (result != null) {
-                                        Slog.i(TAG, "Egressed 'hotword rejected result' "
-                                                + "from hotword trusted process");
-                                        if (mDebugHotwordLogging) {
-                                            Slog.i(TAG, "Egressed detected result: " + result);
-                                        }
-                                    }
-                                }
-
-                                @Override
-                                public void onDetected(HotwordDetectedResult triggerResult)
-                                        throws RemoteException {
-                                    HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                                            METRICS_EXTERNAL_SOURCE_DETECTED,
-                                            mVoiceInteractionServiceUid);
-                                    mScheduledExecutorService.schedule(
-                                            () -> {
-                                                bestEffortClose(serviceAudioSink, audioSource);
-                                            },
-                                            EXTERNAL_HOTWORD_CLEANUP_MILLIS,
-                                            TimeUnit.MILLISECONDS);
-
-                                    try {
-                                        enforcePermissionsForDataDelivery();
-                                    } catch (SecurityException e) {
-                                        HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                                                METRICS_EXTERNAL_SOURCE_DETECT_SECURITY_EXCEPTION,
-                                                mVoiceInteractionServiceUid);
-                                        callback.onError();
-                                        return;
-                                    }
-                                    HotwordDetectedResult newResult;
-                                    try {
-                                        newResult =
-                                                mHotwordAudioStreamCopier.startCopyingAudioStreams(
-                                                        triggerResult);
-                                    } catch (IOException e) {
-                                        // TODO: Write event
-                                        callback.onError();
-                                        return;
-                                    }
-                                    callback.onDetected(newResult, null /* audioFormat */,
-                                            null /* audioStream */);
-                                    Slog.i(TAG, "Egressed "
-                                            + HotwordDetectedResult.getUsageSize(newResult)
-                                            + " bits from hotword trusted process");
-                                    if (mDebugHotwordLogging) {
-                                        Slog.i(TAG,
-                                                "Egressed detected result: " + newResult);
-                                    }
-                                }
-                            });
-
-                    // A copy of this has been created and passed to the hotword validator
-                    bestEffortClose(serviceAudioSource);
-                });
-        HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                HOTWORD_DETECTOR_EVENTS__EVENT__START_EXTERNAL_SOURCE_DETECTION,
-                mVoiceInteractionServiceUid);
     }
 
     private class ServiceConnectionFactory {
@@ -1042,7 +461,7 @@
         ServiceConnection createLocked() {
             ServiceConnection connection =
                     new ServiceConnection(mContext, mIntent, mBindingFlags, mUser,
-                            IHotwordDetectionService.Stub::asInterface,
+                            ISandboxedDetectionService.Stub::asInterface,
                             mRestartCount++ % MAX_ISOLATED_PROCESS_NUMBER);
             connection.connect();
 
@@ -1054,7 +473,7 @@
         }
     }
 
-    private class ServiceConnection extends ServiceConnector.Impl<IHotwordDetectionService> {
+    class ServiceConnection extends ServiceConnector.Impl<ISandboxedDetectionService> {
         private final Object mLock = new Object();
 
         private final Intent mIntent;
@@ -1067,7 +486,7 @@
 
         ServiceConnection(@NonNull Context context,
                 @NonNull Intent intent, int bindingFlags, int userId,
-                @Nullable Function<IBinder, IHotwordDetectionService> binderAsInterface,
+                @Nullable Function<IBinder, ISandboxedDetectionService> binderAsInterface,
                 int instanceNumber) {
             super(context, intent, bindingFlags, userId, binderAsInterface);
             this.mIntent = intent;
@@ -1076,7 +495,7 @@
         }
 
         @Override // from ServiceConnector.Impl
-        protected void onServiceConnectionStatusChanged(IHotwordDetectionService service,
+        protected void onServiceConnectionStatusChanged(ISandboxedDetectionService service,
                 boolean connected) {
             if (DEBUG) {
                 Slog.d(TAG, "onServiceConnectionStatusChanged connected = " + connected);
@@ -1109,21 +528,18 @@
         @Override
         public void binderDied() {
             super.binderDied();
+            Slog.w(TAG, "binderDied");
             synchronized (mLock) {
                 if (!mRespectServiceConnectionStatusChanged) {
                     Slog.v(TAG, "Ignored #binderDied event");
                     return;
                 }
-
-                Slog.w(TAG, "binderDied");
-                try {
-                    mCallback.onError(HOTWORD_DETECTION_SERVICE_DIED);
-                } catch (RemoteException e) {
-                    Slog.w(TAG, "Failed to report onError status: " + e);
-                    HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                            HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_ERROR_EXCEPTION,
-                            mVoiceInteractionServiceUid);
-                }
+            }
+            synchronized (HotwordDetectionConnection.this.mLock) {
+                runForEachHotwordDetectorSessionLocked((session) -> {
+                    session.reportErrorLocked(
+                            HotwordDetectorSession.HOTWORD_DETECTION_SERVICE_DIED);
+                });
             }
         }
 
@@ -1168,16 +584,91 @@
         }
     }
 
-    private static Pair<ParcelFileDescriptor, ParcelFileDescriptor> createPipe() {
-        ParcelFileDescriptor[] fileDescriptors;
-        try {
-            fileDescriptors = ParcelFileDescriptor.createPipe();
-        } catch (IOException e) {
-            Slog.e(TAG, "Failed to create audio stream pipe", e);
+    @SuppressWarnings("GuardedBy")
+    void createDetectorLocked(
+            @Nullable PersistableBundle options,
+            @Nullable SharedMemory sharedMemory,
+            @NonNull IBinder token,
+            @NonNull IHotwordRecognitionStatusCallback callback,
+            int detectorType) {
+        // We only support one Dsp trusted hotword detector and one software hotword detector at
+        // the same time, remove existing one.
+        HotwordDetectorSession removeSession = mHotwordDetectorSessions.get(detectorType);
+        if (removeSession != null) {
+            removeSession.destroyLocked();
+            mHotwordDetectorSessions.remove(detectorType);
+        }
+        final HotwordDetectorSession session;
+        if (detectorType == HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_DSP) {
+            session = new DspTrustedHotwordDetectorSession(mRemoteHotwordDetectionService,
+                    mLock, mContext, token, callback, mVoiceInteractionServiceUid,
+                    mVoiceInteractorIdentity, mScheduledExecutorService, mDebugHotwordLogging);
+        } else {
+            session = new SoftwareTrustedHotwordDetectorSession(
+                    mRemoteHotwordDetectionService, mLock, mContext, token, callback,
+                    mVoiceInteractionServiceUid, mVoiceInteractorIdentity,
+                    mScheduledExecutorService, mDebugHotwordLogging);
+        }
+        mHotwordDetectorSessions.put(detectorType, session);
+        session.initialize(options, sharedMemory);
+    }
+
+    @SuppressWarnings("GuardedBy")
+    void destroyDetectorLocked(@NonNull IBinder token) {
+        final HotwordDetectorSession session = getDetectorSessionByTokenLocked(token);
+        if (session != null) {
+            session.destroyLocked();
+            final int index = mHotwordDetectorSessions.indexOfValue(session);
+            if (index < 0 || index > mHotwordDetectorSessions.size() - 1) {
+                return;
+            }
+            mHotwordDetectorSessions.removeAt(index);
+        }
+    }
+
+    @SuppressWarnings("GuardedBy")
+    private HotwordDetectorSession getDetectorSessionByTokenLocked(IBinder token) {
+        if (token == null) {
             return null;
         }
+        for (int i = 0; i < mHotwordDetectorSessions.size(); i++) {
+            final HotwordDetectorSession session = mHotwordDetectorSessions.valueAt(i);
+            if (!session.isDestroyed() && session.isSameToken(token)) {
+                return session;
+            }
+        }
+        return null;
+    }
 
-        return Pair.create(fileDescriptors[0], fileDescriptors[1]);
+    @SuppressWarnings("GuardedBy")
+    private DspTrustedHotwordDetectorSession getDspTrustedHotwordDetectorSessionLocked() {
+        final HotwordDetectorSession session = mHotwordDetectorSessions.get(
+                HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_DSP);
+        if (session == null || session.isDestroyed()) {
+            Slog.v(TAG, "Not found the Dsp detector");
+            return null;
+        }
+        return (DspTrustedHotwordDetectorSession) session;
+    }
+
+    @SuppressWarnings("GuardedBy")
+    private SoftwareTrustedHotwordDetectorSession getSoftwareTrustedHotwordDetectorSessionLocked() {
+        final HotwordDetectorSession session = mHotwordDetectorSessions.get(
+                HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE);
+        if (session == null || session.isDestroyed()) {
+            Slog.v(TAG, "Not found the software detector");
+            return null;
+        }
+        return (SoftwareTrustedHotwordDetectorSession) session;
+    }
+
+    @SuppressWarnings("GuardedBy")
+    private void runForEachHotwordDetectorSessionLocked(
+            @NonNull Consumer<HotwordDetectorSession> action) {
+        for (int i = 0; i < mHotwordDetectorSessions.size(); i++) {
+            HotwordDetectorSession session = mHotwordDetectorSessions.valueAt(i);
+            action.accept(session);
+        }
     }
 
     private static void updateAudioFlinger(ServiceConnection connection, IBinder audioFlinger) {
@@ -1241,85 +732,4 @@
             }
         });
     }
-
-    private void saveProximityValueToBundle(HotwordDetectedResult result) {
-        synchronized (mLock) {
-            if (result != null && mProximityMeters != PROXIMITY_UNKNOWN) {
-                result.setProximity(mProximityMeters);
-            }
-        }
-    }
-
-    private void setProximityValue(double proximityMeters) {
-        synchronized (mLock) {
-            mProximityMeters = proximityMeters;
-        }
-    }
-
-    private static void bestEffortClose(Closeable... closeables) {
-        for (Closeable closeable : closeables) {
-            bestEffortClose(closeable);
-        }
-    }
-
-    private static void bestEffortClose(Closeable closeable) {
-        try {
-            closeable.close();
-        } catch (IOException e) {
-            if (DEBUG) {
-                Slog.w(TAG, "Failed closing", e);
-            }
-        }
-    }
-
-    // TODO: Share this code with SoundTriggerMiddlewarePermission.
-    private void enforcePermissionsForDataDelivery() {
-        Binder.withCleanCallingIdentity(() -> {
-            enforcePermissionForPreflight(mContext, mVoiceInteractorIdentity, RECORD_AUDIO);
-            int hotwordOp = AppOpsManager.strOpToOp(AppOpsManager.OPSTR_RECORD_AUDIO_HOTWORD);
-            mAppOpsManager.noteOpNoThrow(hotwordOp,
-                    mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
-                    mVoiceInteractorIdentity.attributionTag, OP_MESSAGE);
-            enforcePermissionForDataDelivery(mContext, mVoiceInteractorIdentity,
-                    CAPTURE_AUDIO_HOTWORD, OP_MESSAGE);
-        });
-    }
-
-    /**
-     * Throws a {@link SecurityException} iff the given identity has given permission to receive
-     * data.
-     *
-     * @param context    A {@link Context}, used for permission checks.
-     * @param identity   The identity to check.
-     * @param permission The identifier of the permission we want to check.
-     * @param reason     The reason why we're requesting the permission, for auditing purposes.
-     */
-    private static void enforcePermissionForDataDelivery(@NonNull Context context,
-            @NonNull Identity identity,
-            @NonNull String permission, @NonNull String reason) {
-        final int status = PermissionUtil.checkPermissionForDataDelivery(context, identity,
-                permission, reason);
-        if (status != PermissionChecker.PERMISSION_GRANTED) {
-            throw new SecurityException(
-                    TextUtils.formatSimple("Failed to obtain permission %s for identity %s",
-                            permission,
-                            SoundTriggerSessionPermissionsDecorator.toString(identity)));
-        }
-    }
-
-    private static void enforceExtraKeyphraseIdNotLeaked(HotwordDetectedResult result,
-            SoundTrigger.KeyphraseRecognitionEvent recognitionEvent) {
-        // verify the phrase ID in HotwordDetectedResult is not exposing extra phrases
-        // the DSP did not detect
-        for (SoundTrigger.KeyphraseRecognitionExtra keyphrase : recognitionEvent.keyphraseExtras) {
-            if (keyphrase.getKeyphraseId() == result.getHotwordPhraseId()) {
-                return;
-            }
-        }
-        throw new SecurityException("Ignoring #onDetected due to trusted service "
-                + "sharing a keyphrase ID which the DSP did not detect");
-    }
-
-    private static final String OP_MESSAGE =
-            "Providing hotword detection result to VoiceInteractionService";
 }
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectorSession.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectorSession.java
new file mode 100644
index 0000000..689423a
--- /dev/null
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectorSession.java
@@ -0,0 +1,693 @@
+/*
+ * 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.server.voiceinteraction;
+
+import static android.Manifest.permission.CAPTURE_AUDIO_HOTWORD;
+import static android.Manifest.permission.RECORD_AUDIO;
+import static android.service.attention.AttentionService.PROXIMITY_UNKNOWN;
+import static android.service.voice.HotwordDetectionService.AUDIO_SOURCE_EXTERNAL;
+import static android.service.voice.HotwordDetectionService.ENABLE_PROXIMITY_RESULT;
+import static android.service.voice.HotwordDetectionService.INITIALIZATION_STATUS_SUCCESS;
+import static android.service.voice.HotwordDetectionService.INITIALIZATION_STATUS_UNKNOWN;
+import static android.service.voice.HotwordDetectionService.KEY_INITIALIZATION_STATUS;
+
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_ERROR;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_SUCCESS;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_UNKNOWN_NO_VALUE;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_UNKNOWN_OVER_MAX_CUSTOM_VALUE;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_UNKNOWN_TIMEOUT;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__APP_REQUEST_UPDATE_STATE;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_ERROR_EXCEPTION;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_STATUS_REPORTED_EXCEPTION;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_UPDATE_STATE_AFTER_TIMEOUT;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALL_UPDATE_STATE_EXCEPTION;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__EXTERNAL_SOURCE_DETECTED;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__EXTERNAL_SOURCE_DETECT_SECURITY_EXCEPTION;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__EXTERNAL_SOURCE_REJECTED;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__REQUEST_UPDATE_STATE;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__START_EXTERNAL_SOURCE_DETECTION;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECT_SECURITY_EXCEPTION;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECT_UNEXPECTED_CALLBACK;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECT_UNEXPECTED_CALLBACK;
+import static com.android.server.voiceinteraction.SoundTriggerSessionPermissionsDecorator.enforcePermissionForPreflight;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.app.AppOpsManager;
+import android.attention.AttentionManagerInternal;
+import android.content.Context;
+import android.content.PermissionChecker;
+import android.hardware.soundtrigger.SoundTrigger;
+import android.media.AudioFormat;
+import android.media.permission.Identity;
+import android.media.permission.PermissionUtil;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.os.IRemoteCallback;
+import android.os.ParcelFileDescriptor;
+import android.os.PersistableBundle;
+import android.os.RemoteException;
+import android.os.SharedMemory;
+import android.service.voice.HotwordDetectedResult;
+import android.service.voice.HotwordDetectionService;
+import android.service.voice.HotwordDetector;
+import android.service.voice.HotwordRejectedResult;
+import android.service.voice.IDspHotwordDetectionCallback;
+import android.service.voice.IMicrophoneHotwordDetectionVoiceInteractionCallback;
+import android.text.TextUtils;
+import android.util.Pair;
+import android.util.Slog;
+
+import com.android.internal.annotations.GuardedBy;
+import com.android.internal.app.IHotwordRecognitionStatusCallback;
+import com.android.internal.infra.AndroidFuture;
+import com.android.server.LocalServices;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * A class that provides trusted hotword detector to communicate with the {@link
+ * HotwordDetectionService}.
+ *
+ * This class provides the methods to do initialization with the {@link HotwordDetectionService}
+ * and handle external source detection. It also provides the methods to check if we can egress
+ * the data from the {@link HotwordDetectionService}.
+ *
+ * The subclass should override the {@link #informRestartProcessLocked()} to handle the trusted
+ * process restart.
+ */
+abstract class HotwordDetectorSession {
+    private static final String TAG = "HotwordDetectorSession";
+    static final boolean DEBUG = false;
+
+    private static final String OP_MESSAGE =
+            "Providing hotword detection result to VoiceInteractionService";
+
+    // The error codes are used for onError callback
+    static final int HOTWORD_DETECTION_SERVICE_DIED = -1;
+    static final int CALLBACK_ONDETECTED_GOT_SECURITY_EXCEPTION = -2;
+    static final int CALLBACK_DETECT_TIMEOUT = -3;
+    static final int CALLBACK_ONDETECTED_STREAM_COPY_ERROR = -4;
+
+    // TODO: These constants need to be refined.
+    private static final long MAX_UPDATE_TIMEOUT_MILLIS = 30000;
+    private static final long EXTERNAL_HOTWORD_CLEANUP_MILLIS = 2000;
+    private static final Duration MAX_UPDATE_TIMEOUT_DURATION =
+            Duration.ofMillis(MAX_UPDATE_TIMEOUT_MILLIS);
+
+    // Hotword metrics
+    private static final int METRICS_INIT_UNKNOWN_TIMEOUT =
+            HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_UNKNOWN_TIMEOUT;
+    private static final int METRICS_INIT_UNKNOWN_NO_VALUE =
+            HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_UNKNOWN_NO_VALUE;
+    private static final int METRICS_INIT_UNKNOWN_OVER_MAX_CUSTOM_VALUE =
+            HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_UNKNOWN_OVER_MAX_CUSTOM_VALUE;
+    private static final int METRICS_INIT_CALLBACK_STATE_ERROR =
+            HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_ERROR;
+    private static final int METRICS_INIT_CALLBACK_STATE_SUCCESS =
+            HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_SUCCESS;
+
+    static final int METRICS_KEYPHRASE_TRIGGERED_DETECT_SECURITY_EXCEPTION =
+            HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECT_SECURITY_EXCEPTION;
+    static final int METRICS_KEYPHRASE_TRIGGERED_DETECT_UNEXPECTED_CALLBACK =
+            HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECT_UNEXPECTED_CALLBACK;
+    static final int METRICS_KEYPHRASE_TRIGGERED_REJECT_UNEXPECTED_CALLBACK =
+            HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECT_UNEXPECTED_CALLBACK;
+
+    private static final int METRICS_EXTERNAL_SOURCE_DETECTED =
+            HOTWORD_DETECTOR_EVENTS__EVENT__EXTERNAL_SOURCE_DETECTED;
+    private static final int METRICS_EXTERNAL_SOURCE_REJECTED =
+            HOTWORD_DETECTOR_EVENTS__EVENT__EXTERNAL_SOURCE_REJECTED;
+    private static final int EXTERNAL_SOURCE_DETECT_SECURITY_EXCEPTION =
+            HOTWORD_DETECTOR_EVENTS__EVENT__EXTERNAL_SOURCE_DETECT_SECURITY_EXCEPTION;
+    private static final int METRICS_CALLBACK_ON_STATUS_REPORTED_EXCEPTION =
+            HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_STATUS_REPORTED_EXCEPTION;
+
+    private final Executor mAudioCopyExecutor = Executors.newCachedThreadPool();
+    // TODO: This may need to be a Handler(looper)
+    final ScheduledExecutorService mScheduledExecutorService;
+    private final AppOpsManager mAppOpsManager;
+    final HotwordAudioStreamCopier mHotwordAudioStreamCopier;
+    final AtomicBoolean mUpdateStateAfterStartFinished = new AtomicBoolean(false);
+    final IHotwordRecognitionStatusCallback mCallback;
+
+    final Object mLock;
+    final int mVoiceInteractionServiceUid;
+    final Context mContext;
+
+    @Nullable AttentionManagerInternal mAttentionManagerInternal = null;
+
+    final AttentionManagerInternal.ProximityUpdateCallbackInternal mProximityCallbackInternal =
+            this::setProximityValue;
+
+    /** Identity used for attributing app ops when delivering data to the Interactor. */
+    @Nullable
+    private final Identity mVoiceInteractorIdentity;
+    @GuardedBy("mLock")
+    ParcelFileDescriptor mCurrentAudioSink;
+    @GuardedBy("mLock")
+    @NonNull HotwordDetectionConnection.ServiceConnection mRemoteHotwordDetectionService;
+    boolean mDebugHotwordLogging = false;
+    @GuardedBy("mLock")
+    private double mProximityMeters = PROXIMITY_UNKNOWN;
+    @GuardedBy("mLock")
+    private boolean mInitialized = false;
+    @GuardedBy("mLock")
+    private boolean mDestroyed = false;
+    @GuardedBy("mLock")
+    boolean mPerformingExternalSourceHotwordDetection;
+    @NonNull final IBinder mToken;
+
+    HotwordDetectorSession(
+            @NonNull HotwordDetectionConnection.ServiceConnection remoteHotwordDetectionService,
+            @NonNull Object lock, @NonNull Context context, @NonNull IBinder token,
+            @NonNull IHotwordRecognitionStatusCallback callback, int voiceInteractionServiceUid,
+            Identity voiceInteractorIdentity,
+            @NonNull ScheduledExecutorService scheduledExecutorService, boolean logging) {
+        mRemoteHotwordDetectionService = remoteHotwordDetectionService;
+        mLock = lock;
+        mContext = context;
+        mToken = token;
+        mCallback = callback;
+        mVoiceInteractionServiceUid = voiceInteractionServiceUid;
+        mVoiceInteractorIdentity = voiceInteractorIdentity;
+        mAppOpsManager = mContext.getSystemService(AppOpsManager.class);
+        mHotwordAudioStreamCopier = new HotwordAudioStreamCopier(mAppOpsManager, getDetectorType(),
+                mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
+                mVoiceInteractorIdentity.attributionTag);
+        mScheduledExecutorService = scheduledExecutorService;
+        mDebugHotwordLogging = logging;
+
+        if (ENABLE_PROXIMITY_RESULT) {
+            mAttentionManagerInternal = LocalServices.getService(AttentionManagerInternal.class);
+            if (mAttentionManagerInternal != null) {
+                mAttentionManagerInternal.onStartProximityUpdates(mProximityCallbackInternal);
+            }
+        }
+    }
+
+    @SuppressWarnings("GuardedBy")
+    private void updateStateAfterProcessStartLocked(PersistableBundle options,
+            SharedMemory sharedMemory) {
+        if (DEBUG) {
+            Slog.d(TAG, "updateStateAfterProcessStartLocked");
+        }
+        AndroidFuture<Void> voidFuture = mRemoteHotwordDetectionService.postAsync(service -> {
+            AndroidFuture<Void> future = new AndroidFuture<>();
+            IRemoteCallback statusCallback = new IRemoteCallback.Stub() {
+                @Override
+                public void sendResult(Bundle bundle) throws RemoteException {
+                    if (DEBUG) {
+                        Slog.d(TAG, "updateState finish");
+                    }
+                    future.complete(null);
+                    if (mUpdateStateAfterStartFinished.getAndSet(true)) {
+                        Slog.w(TAG, "call callback after timeout");
+                        HotwordMetricsLogger.writeDetectorEvent(getDetectorType(),
+                                HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_UPDATE_STATE_AFTER_TIMEOUT,
+                                mVoiceInteractionServiceUid);
+                        return;
+                    }
+                    Pair<Integer, Integer> statusResultPair = getInitStatusAndMetricsResult(bundle);
+                    int status = statusResultPair.first;
+                    int initResultMetricsResult = statusResultPair.second;
+                    try {
+                        mCallback.onStatusReported(status);
+                        HotwordMetricsLogger.writeServiceInitResultEvent(getDetectorType(),
+                                initResultMetricsResult, mVoiceInteractionServiceUid);
+                    } catch (RemoteException e) {
+                        Slog.w(TAG, "Failed to report initialization status: " + e);
+                        HotwordMetricsLogger.writeDetectorEvent(getDetectorType(),
+                                METRICS_CALLBACK_ON_STATUS_REPORTED_EXCEPTION,
+                                mVoiceInteractionServiceUid);
+                    }
+                }
+            };
+            try {
+                service.updateState(options, sharedMemory, statusCallback);
+                HotwordMetricsLogger.writeDetectorEvent(getDetectorType(),
+                        HOTWORD_DETECTOR_EVENTS__EVENT__REQUEST_UPDATE_STATE,
+                        mVoiceInteractionServiceUid);
+            } catch (RemoteException e) {
+                // TODO: (b/181842909) Report an error to voice interactor
+                Slog.w(TAG, "Failed to updateState for HotwordDetectionService", e);
+                HotwordMetricsLogger.writeDetectorEvent(getDetectorType(),
+                        HOTWORD_DETECTOR_EVENTS__EVENT__CALL_UPDATE_STATE_EXCEPTION,
+                        mVoiceInteractionServiceUid);
+            }
+            return future.orTimeout(MAX_UPDATE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
+        }).whenComplete((res, err) -> {
+            if (err instanceof TimeoutException) {
+                Slog.w(TAG, "updateState timed out");
+                if (mUpdateStateAfterStartFinished.getAndSet(true)) {
+                    return;
+                }
+                try {
+                    mCallback.onStatusReported(INITIALIZATION_STATUS_UNKNOWN);
+                    HotwordMetricsLogger.writeServiceInitResultEvent(getDetectorType(),
+                            METRICS_INIT_UNKNOWN_TIMEOUT, mVoiceInteractionServiceUid);
+                } catch (RemoteException e) {
+                    Slog.w(TAG, "Failed to report initialization status UNKNOWN", e);
+                    HotwordMetricsLogger.writeDetectorEvent(getDetectorType(),
+                            METRICS_CALLBACK_ON_STATUS_REPORTED_EXCEPTION,
+                            mVoiceInteractionServiceUid);
+                }
+            } else if (err != null) {
+                Slog.w(TAG, "Failed to update state: " + err);
+            }
+        });
+        if (voidFuture == null) {
+            Slog.w(TAG, "Failed to create AndroidFuture");
+        }
+    }
+
+    private static Pair<Integer, Integer> getInitStatusAndMetricsResult(Bundle bundle) {
+        if (bundle == null) {
+            return new Pair<>(INITIALIZATION_STATUS_UNKNOWN, METRICS_INIT_UNKNOWN_NO_VALUE);
+        }
+        int status = bundle.getInt(KEY_INITIALIZATION_STATUS, INITIALIZATION_STATUS_UNKNOWN);
+        if (status > HotwordDetectionService.getMaxCustomInitializationStatus()) {
+            return new Pair<>(INITIALIZATION_STATUS_UNKNOWN,
+                    status == INITIALIZATION_STATUS_UNKNOWN
+                            ? METRICS_INIT_UNKNOWN_NO_VALUE
+                            : METRICS_INIT_UNKNOWN_OVER_MAX_CUSTOM_VALUE);
+        }
+        // TODO: should guard against negative here
+        int metricsResult = status == INITIALIZATION_STATUS_SUCCESS
+                ? METRICS_INIT_CALLBACK_STATE_SUCCESS
+                : METRICS_INIT_CALLBACK_STATE_ERROR;
+        return new Pair<>(status, metricsResult);
+    }
+
+    @SuppressWarnings("GuardedBy")
+    void updateStateLocked(PersistableBundle options, SharedMemory sharedMemory,
+            Instant lastRestartInstant) {
+        HotwordMetricsLogger.writeDetectorEvent(getDetectorType(),
+                HOTWORD_DETECTOR_EVENTS__EVENT__APP_REQUEST_UPDATE_STATE,
+                mVoiceInteractionServiceUid);
+        // Prevent doing the init late, so restart is handled equally to a clean process start.
+        // TODO(b/191742511): this logic needs a test
+        if (!mUpdateStateAfterStartFinished.get() && Instant.now().minus(
+                MAX_UPDATE_TIMEOUT_DURATION).isBefore(lastRestartInstant)) {
+            Slog.v(TAG, "call updateStateAfterProcessStartLocked");
+            updateStateAfterProcessStartLocked(options, sharedMemory);
+        } else {
+            mRemoteHotwordDetectionService.run(
+                    service -> service.updateState(options, sharedMemory, /* callback= */ null));
+        }
+    }
+
+    void startListeningFromExternalSourceLocked(
+            ParcelFileDescriptor audioStream,
+            AudioFormat audioFormat,
+            @Nullable PersistableBundle options,
+            IMicrophoneHotwordDetectionVoiceInteractionCallback callback) {
+        if (DEBUG) {
+            Slog.d(TAG, "startListeningFromExternalSourceLocked");
+        }
+
+        handleExternalSourceHotwordDetectionLocked(
+                audioStream,
+                audioFormat,
+                options,
+                callback);
+    }
+
+    @SuppressWarnings("GuardedBy")
+    private void handleExternalSourceHotwordDetectionLocked(
+            ParcelFileDescriptor audioStream,
+            AudioFormat audioFormat,
+            @Nullable PersistableBundle options,
+            IMicrophoneHotwordDetectionVoiceInteractionCallback callback) {
+        if (DEBUG) {
+            Slog.d(TAG, "#handleExternalSourceHotwordDetectionLocked");
+        }
+        if (mPerformingExternalSourceHotwordDetection) {
+            Slog.i(TAG, "Hotword validation is already in progress for external source.");
+            return;
+        }
+
+        InputStream audioSource = new ParcelFileDescriptor.AutoCloseInputStream(audioStream);
+
+        Pair<ParcelFileDescriptor, ParcelFileDescriptor> clientPipe = createPipe();
+        if (clientPipe == null) {
+            // TODO: Need to propagate as unknown error or something?
+            return;
+        }
+        ParcelFileDescriptor serviceAudioSink = clientPipe.second;
+        ParcelFileDescriptor serviceAudioSource = clientPipe.first;
+
+        mCurrentAudioSink = serviceAudioSink;
+        mPerformingExternalSourceHotwordDetection = true;
+
+        mAudioCopyExecutor.execute(() -> {
+            try (InputStream source = audioSource;
+                 OutputStream fos =
+                         new ParcelFileDescriptor.AutoCloseOutputStream(serviceAudioSink)) {
+
+                byte[] buffer = new byte[1024];
+                while (true) {
+                    int bytesRead = source.read(buffer, 0, 1024);
+
+                    if (bytesRead < 0) {
+                        Slog.i(TAG, "Reached end of stream for external hotword");
+                        break;
+                    }
+
+                    // TODO: First write to ring buffer to make sure we don't lose data if the next
+                    // statement fails.
+                    // ringBuffer.append(buffer, bytesRead);
+                    fos.write(buffer, 0, bytesRead);
+                }
+            } catch (IOException e) {
+                Slog.w(TAG, "Failed supplying audio data to validator", e);
+
+                try {
+                    callback.onError();
+                } catch (RemoteException ex) {
+                    Slog.w(TAG, "Failed to report onError status: " + ex);
+                    HotwordMetricsLogger.writeDetectorEvent(getDetectorType(),
+                            HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_ERROR_EXCEPTION,
+                            mVoiceInteractionServiceUid);
+                }
+            } finally {
+                synchronized (mLock) {
+                    mPerformingExternalSourceHotwordDetection = false;
+                    closeExternalAudioStreamLocked("start external source");
+                }
+            }
+        });
+
+        // TODO: handle cancellations well
+        // TODO: what if we cancelled and started a new one?
+        mRemoteHotwordDetectionService.run(
+                service -> {
+                    service.detectFromMicrophoneSource(
+                            serviceAudioSource,
+                            // TODO: consider making a proxy callback + copy of audio format
+                            AUDIO_SOURCE_EXTERNAL,
+                            audioFormat,
+                            options,
+                            new IDspHotwordDetectionCallback.Stub() {
+                                @Override
+                                public void onRejected(HotwordRejectedResult result)
+                                        throws RemoteException {
+                                    synchronized (mLock) {
+                                        mPerformingExternalSourceHotwordDetection = false;
+                                        HotwordMetricsLogger.writeDetectorEvent(getDetectorType(),
+                                                METRICS_EXTERNAL_SOURCE_REJECTED,
+                                                mVoiceInteractionServiceUid);
+                                        mScheduledExecutorService.schedule(
+                                                () -> {
+                                                    bestEffortClose(serviceAudioSink, audioSource);
+                                                },
+                                                EXTERNAL_HOTWORD_CLEANUP_MILLIS,
+                                                TimeUnit.MILLISECONDS);
+
+                                        callback.onRejected(result);
+
+                                        if (result != null) {
+                                            Slog.i(TAG, "Egressed 'hotword rejected result' "
+                                                    + "from hotword trusted process");
+                                            if (mDebugHotwordLogging) {
+                                                Slog.i(TAG, "Egressed detected result: " + result);
+                                            }
+                                        }
+                                    }
+                                }
+
+                                @Override
+                                public void onDetected(HotwordDetectedResult triggerResult)
+                                        throws RemoteException {
+                                    synchronized (mLock) {
+                                        mPerformingExternalSourceHotwordDetection = false;
+                                        HotwordMetricsLogger.writeDetectorEvent(getDetectorType(),
+                                                METRICS_EXTERNAL_SOURCE_DETECTED,
+                                                mVoiceInteractionServiceUid);
+                                        mScheduledExecutorService.schedule(
+                                                () -> {
+                                                    bestEffortClose(serviceAudioSink, audioSource);
+                                                },
+                                                EXTERNAL_HOTWORD_CLEANUP_MILLIS,
+                                                TimeUnit.MILLISECONDS);
+
+                                        try {
+                                            enforcePermissionsForDataDelivery();
+                                        } catch (SecurityException e) {
+                                            HotwordMetricsLogger.writeDetectorEvent(
+                                                    getDetectorType(),
+                                                    EXTERNAL_SOURCE_DETECT_SECURITY_EXCEPTION,
+                                                    mVoiceInteractionServiceUid);
+                                            callback.onError();
+                                            return;
+                                        }
+                                        HotwordDetectedResult newResult;
+                                        try {
+                                            newResult = mHotwordAudioStreamCopier
+                                                    .startCopyingAudioStreams(triggerResult);
+                                        } catch (IOException e) {
+                                            // TODO: Write event
+                                            callback.onError();
+                                            return;
+                                        }
+                                        callback.onDetected(newResult, /* audioFormat= */ null,
+                                                /* audioStream= */ null);
+                                        Slog.i(TAG, "Egressed "
+                                                + HotwordDetectedResult.getUsageSize(newResult)
+                                                + " bits from hotword trusted process");
+                                        if (mDebugHotwordLogging) {
+                                            Slog.i(TAG,
+                                                    "Egressed detected result: " + newResult);
+                                        }
+                                    }
+                                }
+                            });
+
+                    // A copy of this has been created and passed to the hotword validator
+                    bestEffortClose(serviceAudioSource);
+                });
+        HotwordMetricsLogger.writeDetectorEvent(getDetectorType(),
+                HOTWORD_DETECTOR_EVENTS__EVENT__START_EXTERNAL_SOURCE_DETECTION,
+                mVoiceInteractionServiceUid);
+    }
+
+    void initialize(@Nullable PersistableBundle options, @Nullable SharedMemory sharedMemory) {
+        synchronized (mLock) {
+            if (mInitialized || mDestroyed) {
+                return;
+            }
+            updateStateAfterProcessStartLocked(options, sharedMemory);
+            mInitialized = true;
+        }
+    }
+
+    @SuppressWarnings("GuardedBy")
+    void destroyLocked() {
+        mDestroyed = true;
+        mDebugHotwordLogging = false;
+        mRemoteHotwordDetectionService = null;
+        if (mAttentionManagerInternal != null) {
+            mAttentionManagerInternal.onStopProximityUpdates(mProximityCallbackInternal);
+        }
+    }
+
+    void setDebugHotwordLoggingLocked(boolean logging) {
+        Slog.v(TAG, "setDebugHotwordLoggingLocked: " + logging);
+        mDebugHotwordLogging = logging;
+    }
+
+    @SuppressWarnings("GuardedBy")
+    void updateRemoteHotwordDetectionServiceLocked(
+            @NonNull HotwordDetectionConnection.ServiceConnection remoteHotwordDetectionService) {
+        mRemoteHotwordDetectionService = remoteHotwordDetectionService;
+    }
+
+    void reportErrorLocked(int status) {
+        try {
+            mCallback.onError(status);
+        } catch (RemoteException e) {
+            Slog.w(TAG, "Failed to report onError status: " + e);
+            HotwordMetricsLogger.writeDetectorEvent(getDetectorType(),
+                    HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_ERROR_EXCEPTION,
+                    mVoiceInteractionServiceUid);
+        }
+    }
+
+    /**
+     * Called when the trusted process is restarted.
+     */
+    abstract void informRestartProcessLocked();
+
+    boolean isSameCallback(@Nullable IHotwordRecognitionStatusCallback callback) {
+        synchronized (mLock) {
+            if (callback == null) {
+                return false;
+            }
+            return mCallback.asBinder().equals(callback.asBinder());
+        }
+    }
+
+    boolean isSameToken(@NonNull IBinder token) {
+        synchronized (mLock) {
+            if (token == null) {
+                return false;
+            }
+            return mToken == token;
+        }
+    }
+
+    boolean isDestroyed() {
+        synchronized (mLock) {
+            return mDestroyed;
+        }
+    }
+
+    private static Pair<ParcelFileDescriptor, ParcelFileDescriptor> createPipe() {
+        ParcelFileDescriptor[] fileDescriptors;
+        try {
+            fileDescriptors = ParcelFileDescriptor.createPipe();
+        } catch (IOException e) {
+            Slog.e(TAG, "Failed to create audio stream pipe", e);
+            return null;
+        }
+
+        return Pair.create(fileDescriptors[0], fileDescriptors[1]);
+    }
+
+    void saveProximityValueToBundle(HotwordDetectedResult result) {
+        synchronized (mLock) {
+            if (result != null && mProximityMeters != PROXIMITY_UNKNOWN) {
+                result.setProximity(mProximityMeters);
+            }
+        }
+    }
+
+    private void setProximityValue(double proximityMeters) {
+        synchronized (mLock) {
+            mProximityMeters = proximityMeters;
+        }
+    }
+
+    @SuppressWarnings("GuardedBy")
+    void closeExternalAudioStreamLocked(String reason) {
+        if (mCurrentAudioSink != null) {
+            Slog.i(TAG, "Closing external audio stream to hotword detector: " + reason);
+            bestEffortClose(mCurrentAudioSink);
+            mCurrentAudioSink = null;
+        }
+    }
+
+    private static void bestEffortClose(Closeable... closeables) {
+        for (Closeable closeable : closeables) {
+            bestEffortClose(closeable);
+        }
+    }
+
+    private static void bestEffortClose(Closeable closeable) {
+        try {
+            closeable.close();
+        } catch (IOException e) {
+            if (DEBUG) {
+                Slog.w(TAG, "Failed closing", e);
+            }
+        }
+    }
+
+    // TODO: Share this code with SoundTriggerMiddlewarePermission.
+    void enforcePermissionsForDataDelivery() {
+        Binder.withCleanCallingIdentity(() -> {
+            synchronized (mLock) {
+                enforcePermissionForPreflight(mContext, mVoiceInteractorIdentity, RECORD_AUDIO);
+                int hotwordOp = AppOpsManager.strOpToOp(AppOpsManager.OPSTR_RECORD_AUDIO_HOTWORD);
+                mAppOpsManager.noteOpNoThrow(hotwordOp,
+                        mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
+                        mVoiceInteractorIdentity.attributionTag, OP_MESSAGE);
+                enforcePermissionForDataDelivery(mContext, mVoiceInteractorIdentity,
+                        CAPTURE_AUDIO_HOTWORD, OP_MESSAGE);
+            }
+        });
+    }
+
+    /**
+     * Throws a {@link SecurityException} if the given identity has no permission to receive data.
+     *
+     * @param context    A {@link Context}, used for permission checks.
+     * @param identity   The identity to check.
+     * @param permission The identifier of the permission we want to check.
+     * @param reason     The reason why we're requesting the permission, for auditing purposes.
+     */
+    private static void enforcePermissionForDataDelivery(@NonNull Context context,
+            @NonNull Identity identity, @NonNull String permission, @NonNull String reason) {
+        final int status = PermissionUtil.checkPermissionForDataDelivery(context, identity,
+                permission, reason);
+        if (status != PermissionChecker.PERMISSION_GRANTED) {
+            throw new SecurityException(
+                    TextUtils.formatSimple("Failed to obtain permission %s for identity %s",
+                            permission,
+                            SoundTriggerSessionPermissionsDecorator.toString(identity)));
+        }
+    }
+
+    static void enforceExtraKeyphraseIdNotLeaked(HotwordDetectedResult result,
+            SoundTrigger.KeyphraseRecognitionEvent recognitionEvent) {
+        // verify the phrase ID in HotwordDetectedResult is not exposing extra phrases
+        // the DSP did not detect
+        for (SoundTrigger.KeyphraseRecognitionExtra keyphrase : recognitionEvent.keyphraseExtras) {
+            if (keyphrase.getKeyphraseId() == result.getHotwordPhraseId()) {
+                return;
+            }
+        }
+        throw new SecurityException("Ignoring #onDetected due to trusted service "
+                + "sharing a keyphrase ID which the DSP did not detect");
+    }
+
+    private int getDetectorType() {
+        if (this instanceof DspTrustedHotwordDetectorSession) {
+            return HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_DSP;
+        } else if (this instanceof SoftwareTrustedHotwordDetectorSession) {
+            return HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE;
+        }
+        Slog.v(TAG, "Unexpected detector type");
+        return -1;
+    }
+
+    @SuppressWarnings("GuardedBy")
+    public void dumpLocked(String prefix, PrintWriter pw) {
+        pw.print(prefix); pw.print("mCallback="); pw.println(mCallback);
+        pw.print(prefix); pw.print("mUpdateStateAfterStartFinished=");
+        pw.println(mUpdateStateAfterStartFinished);
+        pw.print(prefix); pw.print("mInitialized="); pw.println(mInitialized);
+        pw.print(prefix); pw.print("mDestroyed="); pw.println(mDestroyed);
+        pw.print(prefix); pw.print("DetectorType=");
+        pw.println(HotwordDetector.detectorTypeToString(getDetectorType()));
+        pw.print(prefix); pw.print("mPerformingExternalSourceHotwordDetection=");
+        pw.println(mPerformingExternalSourceHotwordDetection);
+    }
+}
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordMetricsLogger.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordMetricsLogger.java
index 940aed3..61c18be 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordMetricsLogger.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordMetricsLogger.java
@@ -64,28 +64,28 @@
     /**
      * Logs information related to hotword detection service init result.
      */
-    public static void writeServiceInitResultEvent(int detectorType, int result) {
+    public static void writeServiceInitResultEvent(int detectorType, int result, int uid) {
         int metricsDetectorType = getInitMetricsDetectorType(detectorType);
         FrameworkStatsLog.write(FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED,
-                metricsDetectorType, result);
+                metricsDetectorType, result, uid);
     }
 
     /**
      * Logs information related to hotword detection service restarting.
      */
-    public static void writeServiceRestartEvent(int detectorType, int reason) {
+    public static void writeServiceRestartEvent(int detectorType, int reason, int uid) {
         int metricsDetectorType = getRestartMetricsDetectorType(detectorType);
         FrameworkStatsLog.write(FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_RESTARTED,
-                metricsDetectorType, reason);
+                metricsDetectorType, reason, uid);
     }
 
     /**
      * Logs information related to keyphrase trigger.
      */
-    public static void writeKeyphraseTriggerEvent(int detectorType, int result) {
+    public static void writeKeyphraseTriggerEvent(int detectorType, int result, int uid) {
         int metricsDetectorType = getKeyphraseMetricsDetectorType(detectorType);
         FrameworkStatsLog.write(FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED,
-                metricsDetectorType, result);
+                metricsDetectorType, result, uid);
     }
 
     /**
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/SoftwareTrustedHotwordDetectorSession.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/SoftwareTrustedHotwordDetectorSession.java
new file mode 100644
index 0000000..4eb997a
--- /dev/null
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/SoftwareTrustedHotwordDetectorSession.java
@@ -0,0 +1,220 @@
+/*
+ * 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.server.voiceinteraction;
+
+import static android.service.voice.HotwordDetectionService.AUDIO_SOURCE_MICROPHONE;
+
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_PROCESS_RESTARTED_EXCEPTION;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__START_SOFTWARE_DETECTION;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECTED;
+import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECTED;
+
+import android.annotation.NonNull;
+import android.content.Context;
+import android.media.AudioFormat;
+import android.media.permission.Identity;
+import android.os.IBinder;
+import android.os.PersistableBundle;
+import android.os.RemoteException;
+import android.os.SharedMemory;
+import android.service.voice.HotwordDetectedResult;
+import android.service.voice.HotwordDetectionService;
+import android.service.voice.HotwordDetector;
+import android.service.voice.HotwordRejectedResult;
+import android.service.voice.IDspHotwordDetectionCallback;
+import android.service.voice.IMicrophoneHotwordDetectionVoiceInteractionCallback;
+import android.service.voice.ISandboxedDetectionService;
+import android.util.Slog;
+
+import com.android.internal.annotations.GuardedBy;
+import com.android.internal.app.IHotwordRecognitionStatusCallback;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.concurrent.ScheduledExecutorService;
+
+/**
+ * A class that provides software trusted hotword detector to communicate with the {@link
+ * HotwordDetectionService}.
+ *
+ * This class can handle the hotword detection which detector is created by using
+ * {@link android.service.voice.VoiceInteractionService#createHotwordDetector(PersistableBundle,
+ * SharedMemory, HotwordDetector.Callback)}.
+ */
+final class SoftwareTrustedHotwordDetectorSession extends HotwordDetectorSession {
+    private static final String TAG = "SoftwareTrustedHotwordDetectorSession";
+
+    private IMicrophoneHotwordDetectionVoiceInteractionCallback mSoftwareCallback;
+    @GuardedBy("mLock")
+    private boolean mPerformingSoftwareHotwordDetection;
+
+    SoftwareTrustedHotwordDetectorSession(
+            @NonNull HotwordDetectionConnection.ServiceConnection remoteHotwordDetectionService,
+            @NonNull Object lock, @NonNull Context context, @NonNull IBinder token,
+            @NonNull IHotwordRecognitionStatusCallback callback, int voiceInteractionServiceUid,
+            Identity voiceInteractorIdentity,
+            @NonNull ScheduledExecutorService scheduledExecutorService, boolean logging) {
+        super(remoteHotwordDetectionService, lock, context, token, callback,
+                voiceInteractionServiceUid, voiceInteractorIdentity, scheduledExecutorService,
+                logging);
+    }
+
+    @SuppressWarnings("GuardedBy")
+    void startListeningFromMicLocked(
+            AudioFormat audioFormat,
+            IMicrophoneHotwordDetectionVoiceInteractionCallback callback) {
+        if (DEBUG) {
+            Slog.d(TAG, "startListeningFromMicLocked");
+        }
+        mSoftwareCallback = callback;
+
+        if (mPerformingSoftwareHotwordDetection) {
+            Slog.i(TAG, "Hotword validation is already in progress, ignoring.");
+            return;
+        }
+        mPerformingSoftwareHotwordDetection = true;
+
+        startListeningFromMicLocked();
+    }
+
+    @SuppressWarnings("GuardedBy")
+    private void startListeningFromMicLocked() {
+        // TODO: consider making this a non-anonymous class.
+        IDspHotwordDetectionCallback internalCallback = new IDspHotwordDetectionCallback.Stub() {
+            @Override
+            public void onDetected(HotwordDetectedResult result) throws RemoteException {
+                if (DEBUG) {
+                    Slog.d(TAG, "onDetected");
+                }
+                synchronized (mLock) {
+                    HotwordMetricsLogger.writeKeyphraseTriggerEvent(
+                            HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE,
+                            HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECTED,
+                            mVoiceInteractionServiceUid);
+                    if (!mPerformingSoftwareHotwordDetection) {
+                        Slog.i(TAG, "Hotword detection has already completed");
+                        HotwordMetricsLogger.writeKeyphraseTriggerEvent(
+                                HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE,
+                                METRICS_KEYPHRASE_TRIGGERED_DETECT_UNEXPECTED_CALLBACK,
+                                mVoiceInteractionServiceUid);
+                        return;
+                    }
+                    mPerformingSoftwareHotwordDetection = false;
+                    try {
+                        enforcePermissionsForDataDelivery();
+                    } catch (SecurityException e) {
+                        HotwordMetricsLogger.writeKeyphraseTriggerEvent(
+                                HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE,
+                                METRICS_KEYPHRASE_TRIGGERED_DETECT_SECURITY_EXCEPTION,
+                                mVoiceInteractionServiceUid);
+                        mSoftwareCallback.onError();
+                        return;
+                    }
+                    saveProximityValueToBundle(result);
+                    HotwordDetectedResult newResult;
+                    try {
+                        newResult = mHotwordAudioStreamCopier.startCopyingAudioStreams(result);
+                    } catch (IOException e) {
+                        // TODO: Write event
+                        mSoftwareCallback.onError();
+                        return;
+                    }
+                    mSoftwareCallback.onDetected(newResult, null, null);
+                    Slog.i(TAG, "Egressed " + HotwordDetectedResult.getUsageSize(newResult)
+                            + " bits from hotword trusted process");
+                    if (mDebugHotwordLogging) {
+                        Slog.i(TAG, "Egressed detected result: " + newResult);
+                    }
+                }
+            }
+
+            @Override
+            public void onRejected(HotwordRejectedResult result) throws RemoteException {
+                if (DEBUG) {
+                    Slog.wtf(TAG, "onRejected");
+                }
+                HotwordMetricsLogger.writeKeyphraseTriggerEvent(
+                        HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE,
+                        HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECTED,
+                        mVoiceInteractionServiceUid);
+                // onRejected isn't allowed here, and we are not expecting it.
+            }
+        };
+
+        mRemoteHotwordDetectionService.run(
+                service -> service.detectFromMicrophoneSource(
+                        null,
+                        AUDIO_SOURCE_MICROPHONE,
+                        null,
+                        null,
+                        internalCallback));
+        HotwordMetricsLogger.writeDetectorEvent(
+                HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE,
+                HOTWORD_DETECTOR_EVENTS__EVENT__START_SOFTWARE_DETECTION,
+                mVoiceInteractionServiceUid);
+    }
+
+    @SuppressWarnings("GuardedBy")
+    void stopListeningFromMicLocked() {
+        if (DEBUG) {
+            Slog.d(TAG, "stopListeningFromMicLocked");
+        }
+        if (!mPerformingSoftwareHotwordDetection) {
+            Slog.i(TAG, "Hotword detection is not running");
+            return;
+        }
+        mPerformingSoftwareHotwordDetection = false;
+
+        mRemoteHotwordDetectionService.run(ISandboxedDetectionService::stopDetection);
+
+        closeExternalAudioStreamLocked("stopping requested");
+    }
+
+    @Override
+    @SuppressWarnings("GuardedBy")
+    void informRestartProcessLocked() {
+        // TODO(b/244598068): Check HotwordAudioStreamManager first
+        Slog.v(TAG, "informRestartProcessLocked");
+        mUpdateStateAfterStartFinished.set(false);
+
+        try {
+            mCallback.onProcessRestarted();
+        } catch (RemoteException e) {
+            Slog.w(TAG, "Failed to communicate #onProcessRestarted", e);
+            HotwordMetricsLogger.writeDetectorEvent(
+                    HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE,
+                    HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_PROCESS_RESTARTED_EXCEPTION,
+                    mVoiceInteractionServiceUid);
+        }
+
+        // Restart listening from microphone if the hotword process has been restarted.
+        if (mPerformingSoftwareHotwordDetection) {
+            Slog.i(TAG, "Process restarted: calling startRecognition() again");
+            startListeningFromMicLocked();
+        }
+
+        mPerformingExternalSourceHotwordDetection = false;
+        closeExternalAudioStreamLocked("process restarted");
+    }
+
+    @SuppressWarnings("GuardedBy")
+    public void dumpLocked(String prefix, PrintWriter pw) {
+        super.dumpLocked(prefix, pw);
+        pw.print(prefix); pw.print("mPerformingSoftwareHotwordDetection=");
+        pw.println(mPerformingSoftwareHotwordDetection);
+    }
+}
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/TrustedHotwordDetectorSession.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/TrustedHotwordDetectorSession.java
deleted file mode 100644
index 02f5889..0000000
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/TrustedHotwordDetectorSession.java
+++ /dev/null
@@ -1,1325 +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.server.voiceinteraction;
-
-import static android.Manifest.permission.CAPTURE_AUDIO_HOTWORD;
-import static android.Manifest.permission.RECORD_AUDIO;
-import static android.service.attention.AttentionService.PROXIMITY_UNKNOWN;
-import static android.service.voice.HotwordDetectionService.AUDIO_SOURCE_EXTERNAL;
-import static android.service.voice.HotwordDetectionService.AUDIO_SOURCE_MICROPHONE;
-import static android.service.voice.HotwordDetectionService.ENABLE_PROXIMITY_RESULT;
-import static android.service.voice.HotwordDetectionService.INITIALIZATION_STATUS_SUCCESS;
-import static android.service.voice.HotwordDetectionService.INITIALIZATION_STATUS_UNKNOWN;
-import static android.service.voice.HotwordDetectionService.KEY_INITIALIZATION_STATUS;
-
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_ERROR;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_SUCCESS;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_UNKNOWN_NO_VALUE;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_UNKNOWN_OVER_MAX_CUSTOM_VALUE;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_UNKNOWN_TIMEOUT;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_RESTARTED__REASON__AUDIO_SERVICE_DIED;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_RESTARTED__REASON__SCHEDULE;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__APP_REQUEST_UPDATE_STATE;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_ERROR_EXCEPTION;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_PROCESS_RESTARTED_EXCEPTION;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_REJECTED_EXCEPTION;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_STATUS_REPORTED_EXCEPTION;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_UPDATE_STATE_AFTER_TIMEOUT;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__CALL_UPDATE_STATE_EXCEPTION;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__EXTERNAL_SOURCE_DETECTED;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__EXTERNAL_SOURCE_DETECT_SECURITY_EXCEPTION;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__EXTERNAL_SOURCE_REJECTED;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__ON_CONNECTED;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__ON_DISCONNECTED;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__REQUEST_BIND_SERVICE;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__REQUEST_BIND_SERVICE_FAIL;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__REQUEST_UPDATE_STATE;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__START_EXTERNAL_SOURCE_DETECTION;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS__EVENT__START_SOFTWARE_DETECTION;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__DETECTOR_TYPE__NORMAL_DETECTOR;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__DETECTOR_TYPE__TRUSTED_DETECTOR_DSP;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECTED;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECT_SECURITY_EXCEPTION;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECT_TIMEOUT;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECT_UNEXPECTED_CALLBACK;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__KEYPHRASE_TRIGGER;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECTED;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECTED_FROM_RESTART;
-import static com.android.internal.util.FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECT_UNEXPECTED_CALLBACK;
-import static com.android.server.voiceinteraction.SoundTriggerSessionPermissionsDecorator.enforcePermissionForPreflight;
-
-import android.annotation.NonNull;
-import android.annotation.Nullable;
-import android.app.AppOpsManager;
-import android.attention.AttentionManagerInternal;
-import android.content.ComponentName;
-import android.content.ContentCaptureOptions;
-import android.content.Context;
-import android.content.Intent;
-import android.content.PermissionChecker;
-import android.hardware.soundtrigger.IRecognitionStatusCallback;
-import android.hardware.soundtrigger.SoundTrigger;
-import android.media.AudioFormat;
-import android.media.AudioManagerInternal;
-import android.media.permission.Identity;
-import android.media.permission.PermissionUtil;
-import android.os.Binder;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.os.IRemoteCallback;
-import android.os.ParcelFileDescriptor;
-import android.os.PersistableBundle;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.SharedMemory;
-import android.provider.DeviceConfig;
-import android.service.voice.HotwordDetectedResult;
-import android.service.voice.HotwordDetectionService;
-import android.service.voice.HotwordDetector;
-import android.service.voice.HotwordRejectedResult;
-import android.service.voice.IDspHotwordDetectionCallback;
-import android.service.voice.IHotwordDetectionService;
-import android.service.voice.IMicrophoneHotwordDetectionVoiceInteractionCallback;
-import android.service.voice.VoiceInteractionManagerInternal.HotwordDetectionServiceIdentity;
-import android.speech.IRecognitionServiceManager;
-import android.text.TextUtils;
-import android.util.Pair;
-import android.util.Slog;
-import android.view.contentcapture.IContentCaptureManager;
-
-import com.android.internal.annotations.GuardedBy;
-import com.android.internal.app.IHotwordRecognitionStatusCallback;
-import com.android.internal.infra.AndroidFuture;
-import com.android.internal.infra.ServiceConnector;
-import com.android.server.LocalServices;
-import com.android.server.pm.permission.PermissionManagerServiceInternal;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.time.Duration;
-import java.time.Instant;
-import java.util.concurrent.Executor;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.function.Function;
-
-/**
- * A class that provides the communication with the HotwordDetectionService.
- */
-final class TrustedHotwordDetectorSession {
-    private static final String TAG = "TrustedHotwordDetectorSession";
-    static final boolean DEBUG = false;
-
-    private static final String KEY_RESTART_PERIOD_IN_SECONDS = "restart_period_in_seconds";
-    // TODO: These constants need to be refined.
-    // The validation timeout value is 3 seconds for onDetect of DSP trigger event.
-    private static final long VALIDATION_TIMEOUT_MILLIS = 3000;
-    // Write the onDetect timeout metric when it takes more time than MAX_VALIDATION_TIMEOUT_MILLIS.
-    private static final long MAX_VALIDATION_TIMEOUT_MILLIS = 4000;
-    private static final long MAX_UPDATE_TIMEOUT_MILLIS = 30000;
-    private static final long EXTERNAL_HOTWORD_CLEANUP_MILLIS = 2000;
-    private static final Duration MAX_UPDATE_TIMEOUT_DURATION =
-            Duration.ofMillis(MAX_UPDATE_TIMEOUT_MILLIS);
-    private static final long RESET_DEBUG_HOTWORD_LOGGING_TIMEOUT_MILLIS = 60 * 60 * 1000; // 1 hour
-    private static final int MAX_ISOLATED_PROCESS_NUMBER = 10;
-
-    // The error codes are used for onError callback
-    private static final int HOTWORD_DETECTION_SERVICE_DIED = -1;
-    private static final int CALLBACK_ONDETECTED_GOT_SECURITY_EXCEPTION = -2;
-    private static final int CALLBACK_DETECT_TIMEOUT = -3;
-    private static final int CALLBACK_ONDETECTED_STREAM_COPY_ERROR = -4;
-
-    // Hotword metrics
-    private static final int METRICS_INIT_UNKNOWN_TIMEOUT =
-            HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_UNKNOWN_TIMEOUT;
-    private static final int METRICS_INIT_UNKNOWN_NO_VALUE =
-            HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_UNKNOWN_NO_VALUE;
-    private static final int METRICS_INIT_UNKNOWN_OVER_MAX_CUSTOM_VALUE =
-            HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_UNKNOWN_OVER_MAX_CUSTOM_VALUE;
-    private static final int METRICS_INIT_CALLBACK_STATE_ERROR =
-            HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_ERROR;
-    private static final int METRICS_INIT_CALLBACK_STATE_SUCCESS =
-            HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED__RESULT__CALLBACK_INIT_STATE_SUCCESS;
-
-    private static final int METRICS_KEYPHRASE_TRIGGERED_DETECT_SECURITY_EXCEPTION =
-            HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECT_SECURITY_EXCEPTION;
-    private static final int METRICS_KEYPHRASE_TRIGGERED_DETECT_UNEXPECTED_CALLBACK =
-            HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECT_UNEXPECTED_CALLBACK;
-    private static final int METRICS_KEYPHRASE_TRIGGERED_REJECT_UNEXPECTED_CALLBACK =
-            HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECT_UNEXPECTED_CALLBACK;
-
-    private static final int METRICS_EXTERNAL_SOURCE_DETECTED =
-            HOTWORD_DETECTOR_EVENTS__EVENT__EXTERNAL_SOURCE_DETECTED;
-    private static final int METRICS_EXTERNAL_SOURCE_REJECTED =
-            HOTWORD_DETECTOR_EVENTS__EVENT__EXTERNAL_SOURCE_REJECTED;
-    private static final int METRICS_EXTERNAL_SOURCE_DETECT_SECURITY_EXCEPTION =
-            HOTWORD_DETECTOR_EVENTS__EVENT__EXTERNAL_SOURCE_DETECT_SECURITY_EXCEPTION;
-    private static final int METRICS_CALLBACK_ON_STATUS_REPORTED_EXCEPTION =
-            HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_STATUS_REPORTED_EXCEPTION;
-
-    private final Executor mAudioCopyExecutor = Executors.newCachedThreadPool();
-    // TODO: This may need to be a Handler(looper)
-    private final ScheduledExecutorService mScheduledExecutorService =
-            Executors.newSingleThreadScheduledExecutor();
-    private final AppOpsManager mAppOpsManager;
-    private final HotwordAudioStreamCopier mHotwordAudioStreamCopier;
-    @Nullable private final ScheduledFuture<?> mCancellationTaskFuture;
-    private final AtomicBoolean mUpdateStateAfterStartFinished = new AtomicBoolean(false);
-    private final IBinder.DeathRecipient mAudioServerDeathRecipient = this::audioServerDied;
-    private final @NonNull ServiceConnectionFactory mServiceConnectionFactory;
-    private final IHotwordRecognitionStatusCallback mCallback;
-    private final int mDetectorType;
-    /**
-     * Time after which each HotwordDetectionService process is stopped and replaced by a new one.
-     * 0 indicates no restarts.
-     */
-    private final int mReStartPeriodSeconds;
-
-    final Object mLock;
-    final int mVoiceInteractionServiceUid;
-    final ComponentName mDetectionComponentName;
-    final int mUser;
-    final Context mContext;
-
-    @Nullable AttentionManagerInternal mAttentionManagerInternal = null;
-
-    final AttentionManagerInternal.ProximityUpdateCallbackInternal mProximityCallbackInternal =
-            this::setProximityValue;
-
-
-    volatile HotwordDetectionServiceIdentity mIdentity;
-    private IMicrophoneHotwordDetectionVoiceInteractionCallback mSoftwareCallback;
-    private Instant mLastRestartInstant;
-
-    private ScheduledFuture<?> mCancellationKeyPhraseDetectionFuture;
-    private ScheduledFuture<?> mDebugHotwordLoggingTimeoutFuture = null;
-
-    /** Identity used for attributing app ops when delivering data to the Interactor. */
-    @GuardedBy("mLock")
-    @Nullable
-    private final Identity mVoiceInteractorIdentity;
-    @GuardedBy("mLock")
-    private ParcelFileDescriptor mCurrentAudioSink;
-    @GuardedBy("mLock")
-    private boolean mValidatingDspTrigger = false;
-    @GuardedBy("mLock")
-    private boolean mPerformingSoftwareHotwordDetection;
-    private @NonNull ServiceConnection mRemoteHotwordDetectionService;
-    private IBinder mAudioFlinger;
-    private boolean mDebugHotwordLogging = false;
-    @GuardedBy("mLock")
-    private double mProximityMeters = PROXIMITY_UNKNOWN;
-
-    TrustedHotwordDetectorSession(Object lock, Context context, int voiceInteractionServiceUid,
-            Identity voiceInteractorIdentity, ComponentName serviceName, int userId,
-            boolean bindInstantServiceAllowed, @Nullable PersistableBundle options,
-            @Nullable SharedMemory sharedMemory,
-            @NonNull IHotwordRecognitionStatusCallback callback, int detectorType) {
-        if (callback == null) {
-            Slog.w(TAG, "Callback is null while creating connection");
-            throw new IllegalArgumentException("Callback is null while creating connection");
-        }
-        mLock = lock;
-        mContext = context;
-        mVoiceInteractionServiceUid = voiceInteractionServiceUid;
-        mVoiceInteractorIdentity = voiceInteractorIdentity;
-        mAppOpsManager = mContext.getSystemService(AppOpsManager.class);
-        mHotwordAudioStreamCopier = new HotwordAudioStreamCopier(mAppOpsManager, detectorType,
-                mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
-                mVoiceInteractorIdentity.attributionTag);
-        mDetectionComponentName = serviceName;
-        mUser = userId;
-        mCallback = callback;
-        mDetectorType = detectorType;
-        mReStartPeriodSeconds = DeviceConfig.getInt(DeviceConfig.NAMESPACE_VOICE_INTERACTION,
-                KEY_RESTART_PERIOD_IN_SECONDS, 0);
-        final Intent intent = new Intent(HotwordDetectionService.SERVICE_INTERFACE);
-        intent.setComponent(mDetectionComponentName);
-        initAudioFlingerLocked();
-
-        mServiceConnectionFactory = new ServiceConnectionFactory(intent, bindInstantServiceAllowed);
-
-        mRemoteHotwordDetectionService = mServiceConnectionFactory.createLocked();
-        if (ENABLE_PROXIMITY_RESULT) {
-            mAttentionManagerInternal = LocalServices.getService(AttentionManagerInternal.class);
-            if (mAttentionManagerInternal != null) {
-                mAttentionManagerInternal.onStartProximityUpdates(mProximityCallbackInternal);
-            }
-        }
-
-        mLastRestartInstant = Instant.now();
-        updateStateAfterProcessStart(options, sharedMemory);
-
-        if (mReStartPeriodSeconds <= 0) {
-            mCancellationTaskFuture = null;
-        } else {
-            // TODO: we need to be smarter here, e.g. schedule it a bit more often,
-            //  but wait until the current session is closed.
-            mCancellationTaskFuture = mScheduledExecutorService.scheduleAtFixedRate(() -> {
-                Slog.v(TAG, "Time to restart the process, TTL has passed");
-                synchronized (mLock) {
-                    restartProcessLocked();
-                    HotwordMetricsLogger.writeServiceRestartEvent(mDetectorType,
-                            HOTWORD_DETECTION_SERVICE_RESTARTED__REASON__SCHEDULE);
-                }
-            }, mReStartPeriodSeconds, mReStartPeriodSeconds, TimeUnit.SECONDS);
-        }
-    }
-
-    private void initAudioFlingerLocked() {
-        if (DEBUG) {
-            Slog.d(TAG, "initAudioFlingerLocked");
-        }
-        mAudioFlinger = ServiceManager.waitForService("media.audio_flinger");
-        if (mAudioFlinger == null) {
-            throw new IllegalStateException("Service media.audio_flinger wasn't found.");
-        }
-        if (DEBUG) {
-            Slog.d(TAG, "Obtained audio_flinger binder.");
-        }
-        try {
-            mAudioFlinger.linkToDeath(mAudioServerDeathRecipient, /* flags= */ 0);
-        } catch (RemoteException e) {
-            Slog.w(TAG, "Audio server died before we registered a DeathRecipient; retrying init.",
-                    e);
-            initAudioFlingerLocked();
-        }
-    }
-
-    private void audioServerDied() {
-        Slog.w(TAG, "Audio server died; restarting the HotwordDetectionService.");
-        synchronized (mLock) {
-            // TODO: Check if this needs to be scheduled on a different thread.
-            initAudioFlingerLocked();
-            // We restart the process instead of simply sending over the new binder, to avoid race
-            // conditions with audio reading in the service.
-            restartProcessLocked();
-            HotwordMetricsLogger.writeServiceRestartEvent(mDetectorType,
-                    HOTWORD_DETECTION_SERVICE_RESTARTED__REASON__AUDIO_SERVICE_DIED);
-        }
-    }
-
-    private void updateStateAfterProcessStart(
-            PersistableBundle options, SharedMemory sharedMemory) {
-        if (DEBUG) {
-            Slog.d(TAG, "updateStateAfterProcessStart");
-        }
-        mRemoteHotwordDetectionService.postAsync(service -> {
-            AndroidFuture<Void> future = new AndroidFuture<>();
-            IRemoteCallback statusCallback = new IRemoteCallback.Stub() {
-                @Override
-                public void sendResult(Bundle bundle) throws RemoteException {
-                    if (DEBUG) {
-                        Slog.d(TAG, "updateState finish");
-                    }
-                    future.complete(null);
-                    if (mUpdateStateAfterStartFinished.getAndSet(true)) {
-                        Slog.w(TAG, "call callback after timeout");
-                        HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                                HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_UPDATE_STATE_AFTER_TIMEOUT,
-                                mVoiceInteractionServiceUid);
-                        return;
-                    }
-                    Pair<Integer, Integer> statusResultPair = getInitStatusAndMetricsResult(bundle);
-                    int status = statusResultPair.first;
-                    int initResultMetricsResult = statusResultPair.second;
-                    try {
-                        mCallback.onStatusReported(status);
-                        HotwordMetricsLogger.writeServiceInitResultEvent(mDetectorType,
-                                initResultMetricsResult);
-                    } catch (RemoteException e) {
-                        Slog.w(TAG, "Failed to report initialization status: " + e);
-                        HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                                METRICS_CALLBACK_ON_STATUS_REPORTED_EXCEPTION,
-                                mVoiceInteractionServiceUid);
-                    }
-                }
-            };
-            try {
-                service.updateState(options, sharedMemory, statusCallback);
-                HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                        HOTWORD_DETECTOR_EVENTS__EVENT__REQUEST_UPDATE_STATE,
-                        mVoiceInteractionServiceUid);
-            } catch (RemoteException e) {
-                // TODO: (b/181842909) Report an error to voice interactor
-                Slog.w(TAG, "Failed to updateState for HotwordDetectionService", e);
-                HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                        HOTWORD_DETECTOR_EVENTS__EVENT__CALL_UPDATE_STATE_EXCEPTION,
-                        mVoiceInteractionServiceUid);
-            }
-            return future.orTimeout(MAX_UPDATE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
-        }).whenComplete((res, err) -> {
-            if (err instanceof TimeoutException) {
-                Slog.w(TAG, "updateState timed out");
-                if (mUpdateStateAfterStartFinished.getAndSet(true)) {
-                    return;
-                }
-                try {
-                    mCallback.onStatusReported(INITIALIZATION_STATUS_UNKNOWN);
-                    HotwordMetricsLogger.writeServiceInitResultEvent(mDetectorType,
-                            METRICS_INIT_UNKNOWN_TIMEOUT);
-                } catch (RemoteException e) {
-                    Slog.w(TAG, "Failed to report initialization status UNKNOWN", e);
-                    HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                            METRICS_CALLBACK_ON_STATUS_REPORTED_EXCEPTION,
-                            mVoiceInteractionServiceUid);
-                }
-            } else if (err != null) {
-                Slog.w(TAG, "Failed to update state: " + err);
-            } else {
-                // NOTE: so far we don't need to take any action.
-            }
-        });
-    }
-
-    private static Pair<Integer, Integer> getInitStatusAndMetricsResult(Bundle bundle) {
-        if (bundle == null) {
-            return new Pair<>(INITIALIZATION_STATUS_UNKNOWN, METRICS_INIT_UNKNOWN_NO_VALUE);
-        }
-        int status = bundle.getInt(KEY_INITIALIZATION_STATUS, INITIALIZATION_STATUS_UNKNOWN);
-        if (status > HotwordDetectionService.getMaxCustomInitializationStatus()) {
-            return new Pair<>(INITIALIZATION_STATUS_UNKNOWN,
-                    status == INITIALIZATION_STATUS_UNKNOWN
-                    ? METRICS_INIT_UNKNOWN_NO_VALUE
-                    : METRICS_INIT_UNKNOWN_OVER_MAX_CUSTOM_VALUE);
-        }
-        // TODO: should guard against negative here
-        int metricsResult = status == INITIALIZATION_STATUS_SUCCESS
-                ? METRICS_INIT_CALLBACK_STATE_SUCCESS
-                : METRICS_INIT_CALLBACK_STATE_ERROR;
-        return new Pair<>(status, metricsResult);
-    }
-
-    private boolean isBound() {
-        synchronized (mLock) {
-            return mRemoteHotwordDetectionService.isBound();
-        }
-    }
-
-    void cancelLocked() {
-        Slog.v(TAG, "cancelLocked");
-        clearDebugHotwordLoggingTimeoutLocked();
-        mDebugHotwordLogging = false;
-        mRemoteHotwordDetectionService.unbind();
-        LocalServices.getService(PermissionManagerServiceInternal.class)
-                .setHotwordDetectionServiceProvider(null);
-        if (mIdentity != null) {
-            removeServiceUidForAudioPolicy(mIdentity.getIsolatedUid());
-        }
-        mIdentity = null;
-        if (mCancellationTaskFuture != null) {
-            mCancellationTaskFuture.cancel(/* may interrupt */ true);
-        }
-        if (mAudioFlinger != null) {
-            mAudioFlinger.unlinkToDeath(mAudioServerDeathRecipient, /* flags= */ 0);
-        }
-        if (mAttentionManagerInternal != null) {
-            mAttentionManagerInternal.onStopProximityUpdates(mProximityCallbackInternal);
-        }
-    }
-
-    void updateStateLocked(PersistableBundle options, SharedMemory sharedMemory) {
-        HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                HOTWORD_DETECTOR_EVENTS__EVENT__APP_REQUEST_UPDATE_STATE,
-                mVoiceInteractionServiceUid);
-
-        // Prevent doing the init late, so restart is handled equally to a clean process start.
-        // TODO(b/191742511): this logic needs a test
-        if (!mUpdateStateAfterStartFinished.get()
-                && Instant.now().minus(MAX_UPDATE_TIMEOUT_DURATION).isBefore(mLastRestartInstant)) {
-            Slog.v(TAG, "call updateStateAfterProcessStart");
-            updateStateAfterProcessStart(options, sharedMemory);
-        } else {
-            mRemoteHotwordDetectionService.run(
-                    service -> service.updateState(options, sharedMemory, null /* callback */));
-        }
-    }
-
-    void startListeningFromMic(
-            AudioFormat audioFormat,
-            IMicrophoneHotwordDetectionVoiceInteractionCallback callback) {
-        if (DEBUG) {
-            Slog.d(TAG, "startListeningFromMic");
-        }
-        mSoftwareCallback = callback;
-
-        synchronized (mLock) {
-            if (mPerformingSoftwareHotwordDetection) {
-                Slog.i(TAG, "Hotword validation is already in progress, ignoring.");
-                return;
-            }
-            mPerformingSoftwareHotwordDetection = true;
-
-            startListeningFromMicLocked();
-        }
-    }
-
-    private void startListeningFromMicLocked() {
-        // TODO: consider making this a non-anonymous class.
-        IDspHotwordDetectionCallback internalCallback = new IDspHotwordDetectionCallback.Stub() {
-            @Override
-            public void onDetected(HotwordDetectedResult result) throws RemoteException {
-                if (DEBUG) {
-                    Slog.d(TAG, "onDetected");
-                }
-                synchronized (mLock) {
-                    HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                            mDetectorType,
-                            HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECTED);
-                    if (!mPerformingSoftwareHotwordDetection) {
-                        Slog.i(TAG, "Hotword detection has already completed");
-                        HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                                mDetectorType,
-                                METRICS_KEYPHRASE_TRIGGERED_DETECT_UNEXPECTED_CALLBACK);
-                        return;
-                    }
-                    mPerformingSoftwareHotwordDetection = false;
-                    try {
-                        enforcePermissionsForDataDelivery();
-                    } catch (SecurityException e) {
-                        HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                                mDetectorType,
-                                METRICS_KEYPHRASE_TRIGGERED_DETECT_SECURITY_EXCEPTION);
-                        mSoftwareCallback.onError();
-                        return;
-                    }
-                    saveProximityValueToBundle(result);
-                    HotwordDetectedResult newResult;
-                    try {
-                        newResult = mHotwordAudioStreamCopier.startCopyingAudioStreams(result);
-                    } catch (IOException e) {
-                        // TODO: Write event
-                        mSoftwareCallback.onError();
-                        return;
-                    }
-                    mSoftwareCallback.onDetected(newResult, null, null);
-                    Slog.i(TAG, "Egressed " + HotwordDetectedResult.getUsageSize(newResult)
-                            + " bits from hotword trusted process");
-                    if (mDebugHotwordLogging) {
-                        Slog.i(TAG, "Egressed detected result: " + newResult);
-                    }
-                }
-            }
-
-            @Override
-            public void onRejected(HotwordRejectedResult result) throws RemoteException {
-                if (DEBUG) {
-                    Slog.wtf(TAG, "onRejected");
-                }
-                HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                        mDetectorType,
-                        HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECTED);
-                // onRejected isn't allowed here, and we are not expecting it.
-            }
-        };
-
-        mRemoteHotwordDetectionService.run(
-                service -> service.detectFromMicrophoneSource(
-                        null,
-                        AUDIO_SOURCE_MICROPHONE,
-                        null,
-                        null,
-                        internalCallback));
-        HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                HOTWORD_DETECTOR_EVENTS__EVENT__START_SOFTWARE_DETECTION,
-                mVoiceInteractionServiceUid);
-    }
-
-    public void startListeningFromExternalSource(
-            ParcelFileDescriptor audioStream,
-            AudioFormat audioFormat,
-            @Nullable PersistableBundle options,
-            IMicrophoneHotwordDetectionVoiceInteractionCallback callback) {
-        if (DEBUG) {
-            Slog.d(TAG, "startListeningFromExternalSource");
-        }
-
-        handleExternalSourceHotwordDetection(
-                audioStream,
-                audioFormat,
-                options,
-                callback);
-    }
-
-    void stopListening() {
-        if (DEBUG) {
-            Slog.d(TAG, "stopListening");
-        }
-        synchronized (mLock) {
-            stopListeningLocked();
-        }
-    }
-
-    private void stopListeningLocked() {
-        if (!mPerformingSoftwareHotwordDetection) {
-            Slog.i(TAG, "Hotword detection is not running");
-            return;
-        }
-        mPerformingSoftwareHotwordDetection = false;
-
-        mRemoteHotwordDetectionService.run(IHotwordDetectionService::stopDetection);
-
-        if (mCurrentAudioSink != null) {
-            Slog.i(TAG, "Closing audio stream to hotword detector: stopping requested");
-            bestEffortClose(mCurrentAudioSink);
-        }
-        mCurrentAudioSink = null;
-    }
-
-    void triggerHardwareRecognitionEventForTestLocked(
-            SoundTrigger.KeyphraseRecognitionEvent event,
-            IHotwordRecognitionStatusCallback callback) {
-        if (DEBUG) {
-            Slog.d(TAG, "triggerHardwareRecognitionEventForTestLocked");
-        }
-        detectFromDspSource(event, callback);
-    }
-
-    private void detectFromDspSource(SoundTrigger.KeyphraseRecognitionEvent recognitionEvent,
-            IHotwordRecognitionStatusCallback externalCallback) {
-        if (DEBUG) {
-            Slog.d(TAG, "detectFromDspSource");
-        }
-
-        AtomicBoolean timeoutDetected = new AtomicBoolean(false);
-        // TODO: consider making this a non-anonymous class.
-        IDspHotwordDetectionCallback internalCallback = new IDspHotwordDetectionCallback.Stub() {
-            @Override
-            public void onDetected(HotwordDetectedResult result) throws RemoteException {
-                if (DEBUG) {
-                    Slog.d(TAG, "onDetected");
-                }
-                synchronized (mLock) {
-                    if (mCancellationKeyPhraseDetectionFuture != null) {
-                        mCancellationKeyPhraseDetectionFuture.cancel(true);
-                    }
-                    if (timeoutDetected.get()) {
-                        return;
-                    }
-                    HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                            mDetectorType,
-                            HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECTED);
-                    if (!mValidatingDspTrigger) {
-                        Slog.i(TAG, "Ignoring #onDetected due to a process restart");
-                        HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                                mDetectorType,
-                                METRICS_KEYPHRASE_TRIGGERED_DETECT_UNEXPECTED_CALLBACK);
-                        return;
-                    }
-                    mValidatingDspTrigger = false;
-                    try {
-                        enforcePermissionsForDataDelivery();
-                        enforceExtraKeyphraseIdNotLeaked(result, recognitionEvent);
-                    } catch (SecurityException e) {
-                        Slog.i(TAG, "Ignoring #onDetected due to a SecurityException", e);
-                        HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                                mDetectorType,
-                                METRICS_KEYPHRASE_TRIGGERED_DETECT_SECURITY_EXCEPTION);
-                        externalCallback.onError(CALLBACK_ONDETECTED_GOT_SECURITY_EXCEPTION);
-                        return;
-                    }
-                    saveProximityValueToBundle(result);
-                    HotwordDetectedResult newResult;
-                    try {
-                        newResult = mHotwordAudioStreamCopier.startCopyingAudioStreams(result);
-                    } catch (IOException e) {
-                        // TODO: Write event
-                        externalCallback.onError(CALLBACK_ONDETECTED_STREAM_COPY_ERROR);
-                        return;
-                    }
-                    externalCallback.onKeyphraseDetected(recognitionEvent, newResult);
-                    Slog.i(TAG, "Egressed " + HotwordDetectedResult.getUsageSize(newResult)
-                            + " bits from hotword trusted process");
-                    if (mDebugHotwordLogging) {
-                        Slog.i(TAG, "Egressed detected result: " + newResult);
-                    }
-                }
-            }
-
-            @Override
-            public void onRejected(HotwordRejectedResult result) throws RemoteException {
-                if (DEBUG) {
-                    Slog.d(TAG, "onRejected");
-                }
-                synchronized (mLock) {
-                    if (mCancellationKeyPhraseDetectionFuture != null) {
-                        mCancellationKeyPhraseDetectionFuture.cancel(true);
-                    }
-                    if (timeoutDetected.get()) {
-                        return;
-                    }
-                    HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                            mDetectorType,
-                            HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECTED);
-                    if (!mValidatingDspTrigger) {
-                        Slog.i(TAG, "Ignoring #onRejected due to a process restart");
-                        HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                                mDetectorType,
-                                METRICS_KEYPHRASE_TRIGGERED_REJECT_UNEXPECTED_CALLBACK);
-                        return;
-                    }
-                    mValidatingDspTrigger = false;
-                    externalCallback.onRejected(result);
-                    if (mDebugHotwordLogging && result != null) {
-                        Slog.i(TAG, "Egressed rejected result: " + result);
-                    }
-                }
-            }
-        };
-
-        synchronized (mLock) {
-            mValidatingDspTrigger = true;
-            mRemoteHotwordDetectionService.run(service -> {
-                // We use the VALIDATION_TIMEOUT_MILLIS to inform that the client needs to invoke
-                // the callback before timeout value. In order to reduce the latency impact between
-                // server side and client side, we need to use another timeout value
-                // MAX_VALIDATION_TIMEOUT_MILLIS to monitor it.
-                mCancellationKeyPhraseDetectionFuture = mScheduledExecutorService.schedule(
-                        () -> {
-                            // TODO: avoid allocate every time
-                            timeoutDetected.set(true);
-                            Slog.w(TAG, "Timed out on #detectFromDspSource");
-                            HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                                    mDetectorType,
-                                    HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__DETECT_TIMEOUT);
-                            try {
-                                externalCallback.onError(CALLBACK_DETECT_TIMEOUT);
-                            } catch (RemoteException e) {
-                                Slog.w(TAG, "Failed to report onError status: ", e);
-                                HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                                        HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_ERROR_EXCEPTION,
-                                        mVoiceInteractionServiceUid);
-                            }
-                        },
-                        MAX_VALIDATION_TIMEOUT_MILLIS,
-                        TimeUnit.MILLISECONDS);
-                service.detectFromDspSource(
-                        recognitionEvent,
-                        recognitionEvent.getCaptureFormat(),
-                        VALIDATION_TIMEOUT_MILLIS,
-                        internalCallback);
-            });
-        }
-    }
-
-    void forceRestart() {
-        Slog.v(TAG, "Requested to restart the service internally. Performing the restart");
-        synchronized (mLock) {
-            restartProcessLocked();
-        }
-    }
-
-    void setDebugHotwordLoggingLocked(boolean logging) {
-        Slog.v(TAG, "setDebugHotwordLoggingLocked: " + logging);
-        clearDebugHotwordLoggingTimeoutLocked();
-        mDebugHotwordLogging = logging;
-
-        if (logging) {
-            // Reset mDebugHotwordLogging to false after one hour
-            mDebugHotwordLoggingTimeoutFuture = mScheduledExecutorService.schedule(() -> {
-                Slog.v(TAG, "Timeout to reset mDebugHotwordLogging to false");
-                synchronized (mLock) {
-                    mDebugHotwordLogging = false;
-                }
-            }, RESET_DEBUG_HOTWORD_LOGGING_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
-        }
-    }
-
-    private void clearDebugHotwordLoggingTimeoutLocked() {
-        if (mDebugHotwordLoggingTimeoutFuture != null) {
-            mDebugHotwordLoggingTimeoutFuture.cancel(/* mayInterruptIfRunning= */true);
-            mDebugHotwordLoggingTimeoutFuture = null;
-        }
-    }
-
-    private void restartProcessLocked() {
-        // TODO(b/244598068): Check HotwordAudioStreamManager first
-        Slog.v(TAG, "Restarting hotword detection process");
-        ServiceConnection oldConnection = mRemoteHotwordDetectionService;
-        HotwordDetectionServiceIdentity previousIdentity = mIdentity;
-
-        // TODO(volnov): this can be done after connect() has been successful.
-        if (mValidatingDspTrigger) {
-            // We're restarting the process while it's processing a DSP trigger, so report a
-            // rejection. This also allows the Interactor to startReco again
-            try {
-                mCallback.onRejected(new HotwordRejectedResult.Builder().build());
-                HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                        mDetectorType,
-                        HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__REJECTED_FROM_RESTART);
-            } catch (RemoteException e) {
-                Slog.w(TAG, "Failed to call #rejected");
-                HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                        HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_REJECTED_EXCEPTION,
-                        mVoiceInteractionServiceUid);
-            }
-            mValidatingDspTrigger = false;
-        }
-
-        mUpdateStateAfterStartFinished.set(false);
-        mLastRestartInstant = Instant.now();
-
-        // Recreate connection to reset the cache.
-        mRemoteHotwordDetectionService = mServiceConnectionFactory.createLocked();
-
-        Slog.v(TAG, "Started the new process, issuing #onProcessRestarted");
-        try {
-            mCallback.onProcessRestarted();
-        } catch (RemoteException e) {
-            Slog.w(TAG, "Failed to communicate #onProcessRestarted", e);
-            HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                    HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_PROCESS_RESTARTED_EXCEPTION,
-                    mVoiceInteractionServiceUid);
-        }
-
-        // Restart listening from microphone if the hotword process has been restarted.
-        if (mPerformingSoftwareHotwordDetection) {
-            Slog.i(TAG, "Process restarted: calling startRecognition() again");
-            startListeningFromMicLocked();
-        }
-
-        if (mCurrentAudioSink != null) {
-            Slog.i(TAG, "Closing external audio stream to hotword detector: process restarted");
-            bestEffortClose(mCurrentAudioSink);
-            mCurrentAudioSink = null;
-        }
-
-        if (DEBUG) {
-            Slog.i(TAG, "#onProcessRestarted called, unbinding from the old process");
-        }
-        oldConnection.ignoreConnectionStatusEvents();
-        oldConnection.unbind();
-        if (previousIdentity != null) {
-            removeServiceUidForAudioPolicy(previousIdentity.getIsolatedUid());
-        }
-    }
-
-    static final class SoundTriggerCallback extends IRecognitionStatusCallback.Stub {
-        private SoundTrigger.KeyphraseRecognitionEvent mRecognitionEvent;
-        private final HotwordDetectionConnection mHotwordDetectionConnection;
-        private final IHotwordRecognitionStatusCallback mExternalCallback;
-
-        SoundTriggerCallback(IHotwordRecognitionStatusCallback callback,
-                HotwordDetectionConnection connection) {
-            mHotwordDetectionConnection = connection;
-            mExternalCallback = callback;
-        }
-
-        @Override
-        public void onKeyphraseDetected(SoundTrigger.KeyphraseRecognitionEvent recognitionEvent)
-                throws RemoteException {
-            if (DEBUG) {
-                Slog.d(TAG, "onKeyphraseDetected recognitionEvent : " + recognitionEvent);
-            }
-            final boolean useHotwordDetectionService = mHotwordDetectionConnection != null;
-            if (useHotwordDetectionService) {
-                HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                        HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__DETECTOR_TYPE__TRUSTED_DETECTOR_DSP,
-                        HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__KEYPHRASE_TRIGGER);
-                mRecognitionEvent = recognitionEvent;
-                mHotwordDetectionConnection.detectFromDspSource(
-                        recognitionEvent, mExternalCallback);
-            } else {
-                HotwordMetricsLogger.writeKeyphraseTriggerEvent(
-                        HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__DETECTOR_TYPE__NORMAL_DETECTOR,
-                        HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED__RESULT__KEYPHRASE_TRIGGER);
-                mExternalCallback.onKeyphraseDetected(recognitionEvent, null);
-            }
-        }
-
-        @Override
-        public void onGenericSoundTriggerDetected(
-                SoundTrigger.GenericRecognitionEvent recognitionEvent)
-                throws RemoteException {
-            mExternalCallback.onGenericSoundTriggerDetected(recognitionEvent);
-        }
-
-        @Override
-        public void onError(int status) throws RemoteException {
-            mExternalCallback.onError(status);
-        }
-
-        @Override
-        public void onRecognitionPaused() throws RemoteException {
-            mExternalCallback.onRecognitionPaused();
-        }
-
-        @Override
-        public void onRecognitionResumed() throws RemoteException {
-            mExternalCallback.onRecognitionResumed();
-        }
-    }
-
-    public void dump(String prefix, PrintWriter pw) {
-        pw.print(prefix); pw.print("mReStartPeriodSeconds="); pw.println(mReStartPeriodSeconds);
-        pw.print(prefix);
-        pw.print("mBound=" + mRemoteHotwordDetectionService.isBound());
-        pw.print(", mValidatingDspTrigger=" + mValidatingDspTrigger);
-        pw.print(", mPerformingSoftwareHotwordDetection=" + mPerformingSoftwareHotwordDetection);
-        pw.print(", mRestartCount=" + mServiceConnectionFactory.mRestartCount);
-        pw.print(", mLastRestartInstant=" + mLastRestartInstant);
-        pw.println(", mDetectorType=" + HotwordDetector.detectorTypeToString(mDetectorType));
-    }
-
-    private void handleExternalSourceHotwordDetection(
-            ParcelFileDescriptor audioStream,
-            AudioFormat audioFormat,
-            @Nullable PersistableBundle options,
-            IMicrophoneHotwordDetectionVoiceInteractionCallback callback) {
-        if (DEBUG) {
-            Slog.d(TAG, "#handleExternalSourceHotwordDetection");
-        }
-        InputStream audioSource = new ParcelFileDescriptor.AutoCloseInputStream(audioStream);
-
-        Pair<ParcelFileDescriptor, ParcelFileDescriptor> clientPipe = createPipe();
-        if (clientPipe == null) {
-            // TODO: Need to propagate as unknown error or something?
-            return;
-        }
-        ParcelFileDescriptor serviceAudioSink = clientPipe.second;
-        ParcelFileDescriptor serviceAudioSource = clientPipe.first;
-
-        synchronized (mLock) {
-            mCurrentAudioSink = serviceAudioSink;
-        }
-
-        mAudioCopyExecutor.execute(() -> {
-            try (InputStream source = audioSource;
-                 OutputStream fos =
-                         new ParcelFileDescriptor.AutoCloseOutputStream(serviceAudioSink)) {
-
-                byte[] buffer = new byte[1024];
-                while (true) {
-                    int bytesRead = source.read(buffer, 0, 1024);
-
-                    if (bytesRead < 0) {
-                        Slog.i(TAG, "Reached end of stream for external hotword");
-                        break;
-                    }
-
-                    // TODO: First write to ring buffer to make sure we don't lose data if the next
-                    // statement fails.
-                    // ringBuffer.append(buffer, bytesRead);
-                    fos.write(buffer, 0, bytesRead);
-                }
-            } catch (IOException e) {
-                Slog.w(TAG, "Failed supplying audio data to validator", e);
-
-                try {
-                    callback.onError();
-                } catch (RemoteException ex) {
-                    Slog.w(TAG, "Failed to report onError status: " + ex);
-                    HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                            HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_ERROR_EXCEPTION,
-                            mVoiceInteractionServiceUid);
-                }
-            } finally {
-                synchronized (mLock) {
-                    mCurrentAudioSink = null;
-                }
-            }
-        });
-
-        // TODO: handle cancellations well
-        // TODO: what if we cancelled and started a new one?
-        mRemoteHotwordDetectionService.run(
-                service -> {
-                    service.detectFromMicrophoneSource(
-                            serviceAudioSource,
-                            // TODO: consider making a proxy callback + copy of audio format
-                            AUDIO_SOURCE_EXTERNAL,
-                            audioFormat,
-                            options,
-                            new IDspHotwordDetectionCallback.Stub() {
-                                @Override
-                                public void onRejected(HotwordRejectedResult result)
-                                        throws RemoteException {
-                                    HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                                            METRICS_EXTERNAL_SOURCE_REJECTED,
-                                            mVoiceInteractionServiceUid);
-                                    mScheduledExecutorService.schedule(
-                                            () -> {
-                                                bestEffortClose(serviceAudioSink, audioSource);
-                                            },
-                                            EXTERNAL_HOTWORD_CLEANUP_MILLIS,
-                                            TimeUnit.MILLISECONDS);
-
-                                    callback.onRejected(result);
-
-                                    if (result != null) {
-                                        Slog.i(TAG, "Egressed 'hotword rejected result' "
-                                                + "from hotword trusted process");
-                                        if (mDebugHotwordLogging) {
-                                            Slog.i(TAG, "Egressed detected result: " + result);
-                                        }
-                                    }
-                                }
-
-                                @Override
-                                public void onDetected(HotwordDetectedResult triggerResult)
-                                        throws RemoteException {
-                                    HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                                            METRICS_EXTERNAL_SOURCE_DETECTED,
-                                            mVoiceInteractionServiceUid);
-                                    mScheduledExecutorService.schedule(
-                                            () -> {
-                                                bestEffortClose(serviceAudioSink, audioSource);
-                                            },
-                                            EXTERNAL_HOTWORD_CLEANUP_MILLIS,
-                                            TimeUnit.MILLISECONDS);
-
-                                    try {
-                                        enforcePermissionsForDataDelivery();
-                                    } catch (SecurityException e) {
-                                        HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                                                METRICS_EXTERNAL_SOURCE_DETECT_SECURITY_EXCEPTION,
-                                                mVoiceInteractionServiceUid);
-                                        callback.onError();
-                                        return;
-                                    }
-                                    HotwordDetectedResult newResult;
-                                    try {
-                                        newResult =
-                                                mHotwordAudioStreamCopier.startCopyingAudioStreams(
-                                                        triggerResult);
-                                    } catch (IOException e) {
-                                        // TODO: Write event
-                                        callback.onError();
-                                        return;
-                                    }
-                                    callback.onDetected(newResult, null /* audioFormat */,
-                                            null /* audioStream */);
-                                    Slog.i(TAG, "Egressed "
-                                            + HotwordDetectedResult.getUsageSize(newResult)
-                                            + " bits from hotword trusted process");
-                                    if (mDebugHotwordLogging) {
-                                        Slog.i(TAG,
-                                                "Egressed detected result: " + newResult);
-                                    }
-                                }
-                            });
-
-                    // A copy of this has been created and passed to the hotword validator
-                    bestEffortClose(serviceAudioSource);
-                });
-        HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                HOTWORD_DETECTOR_EVENTS__EVENT__START_EXTERNAL_SOURCE_DETECTION,
-                mVoiceInteractionServiceUid);
-    }
-
-    private class ServiceConnectionFactory {
-        private final Intent mIntent;
-        private final int mBindingFlags;
-
-        private int mRestartCount = 0;
-
-        ServiceConnectionFactory(@NonNull Intent intent, boolean bindInstantServiceAllowed) {
-            mIntent = intent;
-            mBindingFlags = bindInstantServiceAllowed ? Context.BIND_ALLOW_INSTANT : 0;
-        }
-
-        ServiceConnection createLocked() {
-            ServiceConnection connection =
-                    new ServiceConnection(mContext, mIntent, mBindingFlags, mUser,
-                            IHotwordDetectionService.Stub::asInterface,
-                            mRestartCount++ % MAX_ISOLATED_PROCESS_NUMBER);
-            connection.connect();
-
-            updateAudioFlinger(connection, mAudioFlinger);
-            updateContentCaptureManager(connection);
-            updateSpeechService(connection);
-            updateServiceIdentity(connection);
-            return connection;
-        }
-    }
-
-    private class ServiceConnection extends ServiceConnector.Impl<IHotwordDetectionService> {
-        private final Object mLock = new Object();
-
-        private final Intent mIntent;
-        private final int mBindingFlags;
-        private final int mInstanceNumber;
-
-        private boolean mRespectServiceConnectionStatusChanged = true;
-        private boolean mIsBound = false;
-        private boolean mIsLoggedFirstConnect = false;
-
-        ServiceConnection(@NonNull Context context,
-                @NonNull Intent intent, int bindingFlags, int userId,
-                @Nullable Function<IBinder, IHotwordDetectionService> binderAsInterface,
-                int instanceNumber) {
-            super(context, intent, bindingFlags, userId, binderAsInterface);
-            this.mIntent = intent;
-            this.mBindingFlags = bindingFlags;
-            this.mInstanceNumber = instanceNumber;
-        }
-
-        @Override // from ServiceConnector.Impl
-        protected void onServiceConnectionStatusChanged(IHotwordDetectionService service,
-                boolean connected) {
-            if (DEBUG) {
-                Slog.d(TAG, "onServiceConnectionStatusChanged connected = " + connected);
-            }
-            synchronized (mLock) {
-                if (!mRespectServiceConnectionStatusChanged) {
-                    Slog.v(TAG, "Ignored onServiceConnectionStatusChanged event");
-                    return;
-                }
-                mIsBound = connected;
-
-                if (!connected) {
-                    HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                            HOTWORD_DETECTOR_EVENTS__EVENT__ON_DISCONNECTED,
-                            mVoiceInteractionServiceUid);
-                } else if (!mIsLoggedFirstConnect) {
-                    mIsLoggedFirstConnect = true;
-                    HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                            HOTWORD_DETECTOR_EVENTS__EVENT__ON_CONNECTED,
-                            mVoiceInteractionServiceUid);
-                }
-            }
-        }
-
-        @Override
-        protected long getAutoDisconnectTimeoutMs() {
-            return -1;
-        }
-
-        @Override
-        public void binderDied() {
-            super.binderDied();
-            synchronized (mLock) {
-                if (!mRespectServiceConnectionStatusChanged) {
-                    Slog.v(TAG, "Ignored #binderDied event");
-                    return;
-                }
-
-                Slog.w(TAG, "binderDied");
-                try {
-                    mCallback.onError(HOTWORD_DETECTION_SERVICE_DIED);
-                } catch (RemoteException e) {
-                    Slog.w(TAG, "Failed to report onError status: " + e);
-                    HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                            HOTWORD_DETECTOR_EVENTS__EVENT__CALLBACK_ON_ERROR_EXCEPTION,
-                            mVoiceInteractionServiceUid);
-                }
-            }
-        }
-
-        @Override
-        protected boolean bindService(
-                @NonNull android.content.ServiceConnection serviceConnection) {
-            try {
-                HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                        HOTWORD_DETECTOR_EVENTS__EVENT__REQUEST_BIND_SERVICE,
-                        mVoiceInteractionServiceUid);
-                boolean bindResult = mContext.bindIsolatedService(
-                        mIntent,
-                        Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE | mBindingFlags,
-                        "hotword_detector_" + mInstanceNumber,
-                        mExecutor,
-                        serviceConnection);
-                if (!bindResult) {
-                    HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                            HOTWORD_DETECTOR_EVENTS__EVENT__REQUEST_BIND_SERVICE_FAIL,
-                            mVoiceInteractionServiceUid);
-                }
-                return bindResult;
-            } catch (IllegalArgumentException e) {
-                HotwordMetricsLogger.writeDetectorEvent(mDetectorType,
-                        HOTWORD_DETECTOR_EVENTS__EVENT__REQUEST_BIND_SERVICE_FAIL,
-                        mVoiceInteractionServiceUid);
-                Slog.wtf(TAG, "Can't bind to the hotword detection service!", e);
-                return false;
-            }
-        }
-
-        boolean isBound() {
-            synchronized (mLock) {
-                return mIsBound;
-            }
-        }
-
-        void ignoreConnectionStatusEvents() {
-            synchronized (mLock) {
-                mRespectServiceConnectionStatusChanged = false;
-            }
-        }
-    }
-
-    private static Pair<ParcelFileDescriptor, ParcelFileDescriptor> createPipe() {
-        ParcelFileDescriptor[] fileDescriptors;
-        try {
-            fileDescriptors = ParcelFileDescriptor.createPipe();
-        } catch (IOException e) {
-            Slog.e(TAG, "Failed to create audio stream pipe", e);
-            return null;
-        }
-
-        return Pair.create(fileDescriptors[0], fileDescriptors[1]);
-    }
-
-    private static void updateAudioFlinger(ServiceConnection connection, IBinder audioFlinger) {
-        // TODO: Consider using a proxy that limits the exposed API surface.
-        connection.run(service -> service.updateAudioFlinger(audioFlinger));
-    }
-
-    private static void updateContentCaptureManager(ServiceConnection connection) {
-        IBinder b = ServiceManager
-                .getService(Context.CONTENT_CAPTURE_MANAGER_SERVICE);
-        IContentCaptureManager binderService = IContentCaptureManager.Stub.asInterface(b);
-        connection.run(
-                service -> service.updateContentCaptureManager(binderService,
-                        new ContentCaptureOptions(null)));
-    }
-
-    private static void updateSpeechService(ServiceConnection connection) {
-        IBinder b = ServiceManager.getService(Context.SPEECH_RECOGNITION_SERVICE);
-        IRecognitionServiceManager binderService = IRecognitionServiceManager.Stub.asInterface(b);
-        connection.run(service -> {
-            service.updateRecognitionServiceManager(binderService);
-        });
-    }
-
-    private void updateServiceIdentity(ServiceConnection connection) {
-        connection.run(service -> service.ping(new IRemoteCallback.Stub() {
-            @Override
-            public void sendResult(Bundle bundle) throws RemoteException {
-                // TODO: Exit if the service has been unbound already (though there's a very low
-                // chance this happens).
-                if (DEBUG) {
-                    Slog.d(TAG, "updating hotword UID " + Binder.getCallingUid());
-                }
-                // TODO: Have the provider point to the current state stored in
-                // VoiceInteractionManagerServiceImpl.
-                final int uid = Binder.getCallingUid();
-                LocalServices.getService(PermissionManagerServiceInternal.class)
-                        .setHotwordDetectionServiceProvider(() -> uid);
-                mIdentity = new HotwordDetectionServiceIdentity(uid, mVoiceInteractionServiceUid);
-                addServiceUidForAudioPolicy(uid);
-            }
-        }));
-    }
-
-    private void addServiceUidForAudioPolicy(int uid) {
-        mScheduledExecutorService.execute(() -> {
-            AudioManagerInternal audioManager =
-                    LocalServices.getService(AudioManagerInternal.class);
-            if (audioManager != null) {
-                audioManager.addAssistantServiceUid(uid);
-            }
-        });
-    }
-
-    private void removeServiceUidForAudioPolicy(int uid) {
-        mScheduledExecutorService.execute(() -> {
-            AudioManagerInternal audioManager =
-                    LocalServices.getService(AudioManagerInternal.class);
-            if (audioManager != null) {
-                audioManager.removeAssistantServiceUid(uid);
-            }
-        });
-    }
-
-    private void saveProximityValueToBundle(HotwordDetectedResult result) {
-        synchronized (mLock) {
-            if (result != null && mProximityMeters != PROXIMITY_UNKNOWN) {
-                result.setProximity(mProximityMeters);
-            }
-        }
-    }
-
-    private void setProximityValue(double proximityMeters) {
-        synchronized (mLock) {
-            mProximityMeters = proximityMeters;
-        }
-    }
-
-    private static void bestEffortClose(Closeable... closeables) {
-        for (Closeable closeable : closeables) {
-            bestEffortClose(closeable);
-        }
-    }
-
-    private static void bestEffortClose(Closeable closeable) {
-        try {
-            closeable.close();
-        } catch (IOException e) {
-            if (DEBUG) {
-                Slog.w(TAG, "Failed closing", e);
-            }
-        }
-    }
-
-    // TODO: Share this code with SoundTriggerMiddlewarePermission.
-    private void enforcePermissionsForDataDelivery() {
-        Binder.withCleanCallingIdentity(() -> {
-            enforcePermissionForPreflight(mContext, mVoiceInteractorIdentity, RECORD_AUDIO);
-            int hotwordOp = AppOpsManager.strOpToOp(AppOpsManager.OPSTR_RECORD_AUDIO_HOTWORD);
-            mAppOpsManager.noteOpNoThrow(hotwordOp,
-                    mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
-                    mVoiceInteractorIdentity.attributionTag, OP_MESSAGE);
-            enforcePermissionForDataDelivery(mContext, mVoiceInteractorIdentity,
-                    CAPTURE_AUDIO_HOTWORD, OP_MESSAGE);
-        });
-    }
-
-    /**
-     * Throws a {@link SecurityException} iff the given identity has given permission to receive
-     * data.
-     *
-     * @param context    A {@link Context}, used for permission checks.
-     * @param identity   The identity to check.
-     * @param permission The identifier of the permission we want to check.
-     * @param reason     The reason why we're requesting the permission, for auditing purposes.
-     */
-    private static void enforcePermissionForDataDelivery(@NonNull Context context,
-            @NonNull Identity identity,
-            @NonNull String permission, @NonNull String reason) {
-        final int status = PermissionUtil.checkPermissionForDataDelivery(context, identity,
-                permission, reason);
-        if (status != PermissionChecker.PERMISSION_GRANTED) {
-            throw new SecurityException(
-                    TextUtils.formatSimple("Failed to obtain permission %s for identity %s",
-                            permission,
-                            SoundTriggerSessionPermissionsDecorator.toString(identity)));
-        }
-    }
-
-    private static void enforceExtraKeyphraseIdNotLeaked(HotwordDetectedResult result,
-            SoundTrigger.KeyphraseRecognitionEvent recognitionEvent) {
-        // verify the phrase ID in HotwordDetectedResult is not exposing extra phrases
-        // the DSP did not detect
-        for (SoundTrigger.KeyphraseRecognitionExtra keyphrase : recognitionEvent.keyphraseExtras) {
-            if (keyphrase.getKeyphraseId() == result.getHotwordPhraseId()) {
-                return;
-            }
-        }
-        throw new SecurityException("Ignoring #onDetected due to trusted service "
-                + "sharing a keyphrase ID which the DSP did not detect");
-    }
-
-    private static final String OP_MESSAGE =
-            "Providing hotword detection result to VoiceInteractionService";
-}
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
index 7207e373..9a02188 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
@@ -1245,14 +1245,15 @@
         @Override
         public void updateState(
                 @Nullable PersistableBundle options,
-                @Nullable SharedMemory sharedMemory) {
+                @Nullable SharedMemory sharedMemory,
+                @NonNull IBinder token) {
             super.updateState_enforcePermission();
 
             synchronized (this) {
                 enforceIsCurrentVoiceInteractionService();
 
                 Binder.withCleanCallingIdentity(
-                        () -> mImpl.updateStateLocked(options, sharedMemory));
+                        () -> mImpl.updateStateLocked(options, sharedMemory, token));
             }
         }
 
@@ -1262,6 +1263,7 @@
                 @NonNull Identity voiceInteractorIdentity,
                 @Nullable PersistableBundle options,
                 @Nullable SharedMemory sharedMemory,
+                @NonNull IBinder token,
                 IHotwordRecognitionStatusCallback callback,
                 int detectorType) {
             super.initAndVerifyDetector_enforcePermission();
@@ -1274,7 +1276,20 @@
 
                 Binder.withCleanCallingIdentity(
                         () -> mImpl.initAndVerifyDetectorLocked(voiceInteractorIdentity, options,
-                                sharedMemory, callback, detectorType));
+                                sharedMemory, token, callback, detectorType));
+            }
+        }
+
+        @Override
+        public void destroyDetector(@NonNull IBinder token) {
+            synchronized (this) {
+                if (mImpl == null) {
+                    Slog.w(TAG, "destroyDetector without running voice interaction service");
+                    return;
+                }
+
+                Binder.withCleanCallingIdentity(
+                        () -> mImpl.destroyDetectorLocked(token));
             }
         }
 
@@ -1326,6 +1341,7 @@
                 ParcelFileDescriptor audioStream,
                 AudioFormat audioFormat,
                 PersistableBundle options,
+                @NonNull IBinder token,
                 IMicrophoneHotwordDetectionVoiceInteractionCallback callback)
                 throws RemoteException {
             synchronized (this) {
@@ -1338,8 +1354,8 @@
                 }
                 final long caller = Binder.clearCallingIdentity();
                 try {
-                    mImpl.startListeningFromExternalSourceLocked(
-                            audioStream, audioFormat, options, callback);
+                    mImpl.startListeningFromExternalSourceLocked(audioStream, audioFormat, options,
+                            token, callback);
                 } finally {
                     Binder.restoreCallingIdentity(caller);
                 }
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java
index 0a660b0..138362f 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java
@@ -56,7 +56,6 @@
 import android.os.ServiceManager;
 import android.os.SharedMemory;
 import android.os.UserHandle;
-import android.service.voice.HotwordDetector;
 import android.service.voice.IMicrophoneHotwordDetectionVoiceInteractionCallback;
 import android.service.voice.IVoiceInteractionService;
 import android.service.voice.IVoiceInteractionSession;
@@ -113,7 +112,6 @@
 
     VoiceInteractionSessionConnection mActiveSession;
     int mDisabledShowContext;
-    int mDetectorType;
 
     final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
         @Override
@@ -552,7 +550,8 @@
 
     public void updateStateLocked(
             @Nullable PersistableBundle options,
-            @Nullable SharedMemory sharedMemory) {
+            @Nullable SharedMemory sharedMemory,
+            @NonNull IBinder token) {
         Slog.v(TAG, "updateStateLocked");
 
         if (sharedMemory != null && !sharedMemory.setProtect(OsConstants.PROT_READ)) {
@@ -565,7 +564,7 @@
             throw new IllegalStateException("Hotword detection connection not found");
         }
         synchronized (mHotwordDetectionConnection.mLock) {
-            mHotwordDetectionConnection.updateStateLocked(options, sharedMemory);
+            mHotwordDetectionConnection.updateStateLocked(options, sharedMemory, token);
         }
     }
 
@@ -573,6 +572,7 @@
             @NonNull Identity voiceInteractorIdentity,
             @Nullable PersistableBundle options,
             @Nullable SharedMemory sharedMemory,
+            @NonNull IBinder token,
             IHotwordRecognitionStatusCallback callback,
             int detectorType) {
         Slog.v(TAG, "initAndVerifyDetectorLocked");
@@ -624,16 +624,26 @@
             throw new IllegalStateException("Can't set sharedMemory to be read-only");
         }
 
-        mDetectorType = detectorType;
-
         logDetectorCreateEventIfNeeded(callback, detectorType, true,
                 voiceInteractionServiceUid);
         if (mHotwordDetectionConnection == null) {
             mHotwordDetectionConnection = new HotwordDetectionConnection(mServiceStub, mContext,
                     mInfo.getServiceInfo().applicationInfo.uid, voiceInteractorIdentity,
                     mHotwordDetectionComponentName, mUser, /* bindInstantServiceAllowed= */ false,
-                    options, sharedMemory, callback, detectorType);
+                    detectorType);
         }
+        mHotwordDetectionConnection.createDetectorLocked(options, sharedMemory, token, callback,
+                detectorType);
+    }
+
+    public void destroyDetectorLocked(IBinder token) {
+        Slog.v(TAG, "destroyDetectorLocked");
+
+        if (mHotwordDetectionConnection == null) {
+            Slog.w(TAG, "destroy detector callback, but no hotword detection connection");
+            return;
+        }
+        mHotwordDetectionConnection.destroyDetectorLocked(token);
     }
 
     private void logDetectorCreateEventIfNeeded(IHotwordRecognitionStatusCallback callback,
@@ -642,19 +652,16 @@
             HotwordMetricsLogger.writeDetectorCreateEvent(detectorType, isCreated,
                     voiceInteractionServiceUid);
         }
-
     }
 
     public void shutdownHotwordDetectionServiceLocked() {
         if (DEBUG) {
             Slog.d(TAG, "shutdownHotwordDetectionServiceLocked");
         }
-
         if (mHotwordDetectionConnection == null) {
             Slog.w(TAG, "shutdown, but no hotword detection connection");
             return;
         }
-
         mHotwordDetectionConnection.cancelLocked();
         mHotwordDetectionConnection = null;
     }
@@ -663,7 +670,7 @@
             AudioFormat audioFormat,
             IMicrophoneHotwordDetectionVoiceInteractionCallback callback) {
         if (DEBUG) {
-            Slog.d(TAG, "startListeningFromMic");
+            Slog.d(TAG, "startListeningFromMicLocked");
         }
 
         if (mHotwordDetectionConnection == null) {
@@ -671,16 +678,17 @@
             return;
         }
 
-        mHotwordDetectionConnection.startListeningFromMic(audioFormat, callback);
+        mHotwordDetectionConnection.startListeningFromMicLocked(audioFormat, callback);
     }
 
     public void startListeningFromExternalSourceLocked(
             ParcelFileDescriptor audioStream,
             AudioFormat audioFormat,
             @Nullable PersistableBundle options,
+            @NonNull IBinder token,
             IMicrophoneHotwordDetectionVoiceInteractionCallback callback) {
         if (DEBUG) {
-            Slog.d(TAG, "startListeningFromExternalSource");
+            Slog.d(TAG, "startListeningFromExternalSourceLocked");
         }
 
         if (mHotwordDetectionConnection == null) {
@@ -693,21 +701,21 @@
             throw new IllegalStateException("External source is null for hotword detector");
         }
 
-        mHotwordDetectionConnection
-                .startListeningFromExternalSource(audioStream, audioFormat, options, callback);
+        mHotwordDetectionConnection.startListeningFromExternalSourceLocked(audioStream, audioFormat,
+                options, token, callback);
     }
 
     public void stopListeningFromMicLocked() {
         if (DEBUG) {
-            Slog.d(TAG, "stopListeningFromMic");
+            Slog.d(TAG, "stopListeningFromMicLocked");
         }
 
         if (mHotwordDetectionConnection == null) {
-            Slog.w(TAG, "stopListeningFromMic() called but connection isn't established");
+            Slog.w(TAG, "stopListeningFromMicLocked() called but connection isn't established");
             return;
         }
 
-        mHotwordDetectionConnection.stopListening();
+        mHotwordDetectionConnection.stopListeningFromMicLocked();
     }
 
     public void triggerHardwareRecognitionEventForTestLocked(
@@ -730,7 +738,7 @@
             Slog.d(TAG, "createSoundTriggerCallbackLocked");
         }
         return new HotwordDetectionConnection.SoundTriggerCallback(callback,
-                mHotwordDetectionConnection);
+                mHotwordDetectionConnection, mInfo.getServiceInfo().applicationInfo.uid);
     }
 
     private static ServiceInfo getServiceInfoLocked(@NonNull ComponentName componentName,
@@ -809,8 +817,6 @@
             pw.println(Integer.toHexString(mDisabledShowContext));
         }
         pw.print("  mBound="); pw.print(mBound);  pw.print(" mService="); pw.println(mService);
-        pw.print("  mDetectorType=");
-        pw.println(HotwordDetector.detectorTypeToString(mDetectorType));
         if (mHotwordDetectionConnection != null) {
             pw.println("  Hotword detection connection:");
             mHotwordDetectionConnection.dump("    ", pw);
diff --git a/telephony/common/com/android/internal/telephony/TelephonyPermissions.java b/telephony/common/com/android/internal/telephony/TelephonyPermissions.java
index 1ba997f..fdf69430 100644
--- a/telephony/common/com/android/internal/telephony/TelephonyPermissions.java
+++ b/telephony/common/com/android/internal/telephony/TelephonyPermissions.java
@@ -743,11 +743,23 @@
 
     /**
      * Given a list of permissions, check to see if the caller has at least one of them granted. If
-     * not, check to see if the caller has carrier privileges. If the caller does not have any  of
+     * not, check to see if the caller has carrier privileges. If the caller does not have any of
      * these permissions, throw a SecurityException.
      */
     public static void enforceAnyPermissionGrantedOrCarrierPrivileges(Context context, int subId,
             int uid, String message, String... permissions) {
+        enforceAnyPermissionGrantedOrCarrierPrivileges(
+                context, subId, uid, false, message, permissions);
+    }
+
+    /**
+     * Given a list of permissions, check to see if the caller has at least one of them granted. If
+     * not, check to see if the caller has carrier privileges on the specified subscription (or any
+     * subscription if {@code allowCarrierPrivilegeOnAnySub} is {@code true}. If the caller does not
+     * have any of these permissions, throw a {@link SecurityException}.
+     */
+    public static void enforceAnyPermissionGrantedOrCarrierPrivileges(Context context, int subId,
+            int uid, boolean allowCarrierPrivilegeOnAnySub, String message, String... permissions) {
         if (permissions.length == 0) return;
         boolean isGranted = false;
         for (String perm : permissions) {
@@ -758,7 +770,12 @@
         }
 
         if (isGranted) return;
-        if (checkCarrierPrivilegeForSubId(context, subId)) return;
+
+        if (allowCarrierPrivilegeOnAnySub) {
+            if (checkCarrierPrivilegeForAnySubId(context, Binder.getCallingUid())) return;
+        } else {
+            if (checkCarrierPrivilegeForSubId(context, subId)) return;
+        }
 
         StringBuilder b = new StringBuilder(message);
         b.append(": Neither user ");
@@ -769,7 +786,8 @@
             b.append(" or ");
             b.append(permissions[i]);
         }
-        b.append(" or carrier privileges");
+        b.append(" or carrier privileges. subId=" + subId + ", allowCarrierPrivilegeOnAnySub="
+                + allowCarrierPrivilegeOnAnySub);
         throw new SecurityException(b.toString());
     }
 
diff --git a/telephony/java/android/telephony/CarrierConfigManager.java b/telephony/java/android/telephony/CarrierConfigManager.java
index 22cd31a..c4744ef 100644
--- a/telephony/java/android/telephony/CarrierConfigManager.java
+++ b/telephony/java/android/telephony/CarrierConfigManager.java
@@ -17,6 +17,7 @@
 package android.telephony;
 
 import android.Manifest;
+import android.annotation.CallbackExecutor;
 import android.annotation.IntDef;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
@@ -52,6 +53,7 @@
 import com.android.telephony.Rlog;
 
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.Executor;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
@@ -9957,10 +9959,13 @@
      * @param subId the subscription ID, normally obtained from {@link SubscriptionManager}.
      * @return A {@link PersistableBundle} containing the config for the given subId, or default
      *         values for an invalid subId.
+     *
+     * @deprecated Use {@link #getConfigForSubId(int, String...)} instead.
      */
     @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
     @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
     @Nullable
+    @Deprecated
     public PersistableBundle getConfigForSubId(int subId) {
         try {
             ICarrierConfigLoader loader = getICarrierConfigLoader();
@@ -9979,6 +9984,59 @@
     }
 
     /**
+     * Gets the configuration values of the specified keys for a particular subscription.
+     *
+     * <p>If an invalid subId is used, the returned configuration will contain default values for
+     * the specified keys. If the value for the key can't be found, the returned configuration will
+     * filter the key out.
+     *
+     * <p>After using this method to get the configuration bundle,
+     * {@link #isConfigForIdentifiedCarrier(PersistableBundle)} should be called to confirm whether
+     * any carrier specific configuration has been applied.
+     *
+     * <p>Note that on success, the key/value for {@link #KEY_CARRIER_CONFIG_VERSION_STRING} and
+     * {@link #KEY_CARRIER_CONFIG_APPLIED_BOOL} are always in the returned bundle, no matter if they
+     * were explicitly requested.
+     *
+     * <p>Requires Permission:
+     * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}, or the calling app
+     * has carrier privileges on the specified subscription (see
+     * {@link TelephonyManager#hasCarrierPrivileges()}).
+     *
+     * @param subId The subscription ID on which the carrier config should be retrieved.
+     * @param keys  The carrier config keys to retrieve values.
+     * @return A {@link PersistableBundle} with key/value mapping for the specified configuration
+     * on success, or an empty (but never null) bundle on failure (for example, when the calling app
+     * has no permission).
+     */
+    @RequiresPermission(anyOf = {
+            Manifest.permission.READ_PHONE_STATE,
+            "carrier privileges",
+    })
+    @NonNull
+    public PersistableBundle getConfigForSubId(int subId, @NonNull String... keys) {
+        Objects.requireNonNull(keys, "Config keys should be non-null");
+        for (String key : keys) {
+            Objects.requireNonNull(key, "Config key should be non-null");
+        }
+
+        try {
+            ICarrierConfigLoader loader = getICarrierConfigLoader();
+            if (loader == null) {
+                Rlog.w(TAG, "Error getting config for subId " + subId
+                        + " ICarrierConfigLoader is null");
+                throw new IllegalStateException("Carrier config loader is not available.");
+            }
+            return loader.getConfigSubsetForSubIdWithFeature(subId, mContext.getOpPackageName(),
+                    mContext.getAttributionTag(), keys);
+        } catch (RemoteException ex) {
+            Rlog.e(TAG, "Error getting config for subId " + subId + ": " + ex);
+            ex.rethrowAsRuntimeException();
+        }
+        return new PersistableBundle();
+    }
+
+    /**
      * Overrides the carrier config of the provided subscription ID with the provided values.
      *
      * Any further queries to carrier config from any process will return the overridden values
@@ -10052,15 +10110,52 @@
      * has carrier privileges (see {@link TelephonyManager#hasCarrierPrivileges()}).
      *
      * @see #getConfigForSubId
+     * @see #getConfig(String...)
+     * @deprecated use {@link #getConfig(String...)} instead.
      */
     @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
     @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
     @Nullable
+    @Deprecated
     public PersistableBundle getConfig() {
         return getConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
     }
 
     /**
+     * Gets the configuration values of the specified config keys applied for the default
+     * subscription.
+     *
+     * <p>If the value for the key can't be found, the returned bundle will filter the key out.
+     *
+     * <p>After using this method to get the configuration bundle, {@link
+     * #isConfigForIdentifiedCarrier(PersistableBundle)} should be called to confirm whether any
+     * carrier specific configuration has been applied.
+     *
+     * <p>Note that on success, the key/value for {@link #KEY_CARRIER_CONFIG_VERSION_STRING} and
+     * {@link #KEY_CARRIER_CONFIG_APPLIED_BOOL} are always in the returned bundle, no matter if
+     * they were explicitly requested.
+     *
+     * <p>Requires Permission:
+     * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}, or the calling app
+     * has carrier privileges for the default subscription (see
+     * {@link TelephonyManager#hasCarrierPrivileges()}).
+     *
+     * @param keys The config keys to retrieve values
+     * @return A {@link PersistableBundle} with key/value mapping for the specified carrier
+     * configs on success, or an empty (but never null) bundle on failure.
+     * @see #getConfigForSubId(int, String...)
+     * @see SubscriptionManager#getDefaultSubscriptionId()
+     */
+    @RequiresPermission(anyOf = {
+            Manifest.permission.READ_PHONE_STATE,
+            "carrier privileges",
+    })
+    @NonNull
+    public PersistableBundle getConfig(@NonNull String... keys) {
+        return getConfigForSubId(SubscriptionManager.getDefaultSubscriptionId(), keys);
+    }
+
+    /**
      * Determines whether a configuration {@link PersistableBundle} obtained from
      * {@link #getConfig()} or {@link #getConfigForSubId(int)} corresponds to an identified carrier.
      *
@@ -10246,4 +10341,85 @@
             configs.putPersistableBundle(key, (PersistableBundle) value);
         }
     }
+
+    /**
+     * Listener interface to get a notification when the carrier configurations have changed.
+     *
+     * Use this listener to receive timely updates when the carrier configuration changes. System
+     * components should prefer this listener over {@link #ACTION_CARRIER_CONFIG_CHANGED}
+     * whenever possible.
+     *
+     * To register the listener, call
+     * {@link #registerCarrierConfigChangeListener(Executor, CarrierConfigChangeListener)}.
+     * To unregister, call
+     * {@link #unregisterCarrierConfigChangeListener(CarrierConfigChangeListener)}.
+     *
+     * Note that on registration, registrants will NOT receive a notification on last carrier config
+     * change. Only carrier configs change AFTER the registration will be sent to registrants. And
+     * unlike {@link #ACTION_CARRIER_CONFIG_CHANGED}, notification wouldn't send when the device is
+     * unlocked. Registrants only receive the notification when there has been real carrier config
+     * changes.
+     *
+     * @see #registerCarrierConfigChangeListener(Executor, CarrierConfigChangeListener)
+     * @see #unregisterCarrierConfigChangeListener(CarrierConfigChangeListener)
+     * @see #ACTION_CARRIER_CONFIG_CHANGED
+     * @see #getConfig(String...)
+     * @see #getConfigForSubId(int, String...)
+     */
+    public interface CarrierConfigChangeListener {
+        /**
+         * Called when carrier configurations have changed.
+         *
+         * @param logicalSlotIndex  The logical SIM slot index on which to monitor and get
+         *                          notification. It is guaranteed to be valid.
+         * @param subscriptionId    The subscription on the SIM slot. May be
+         *                          {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID}.
+         * @param carrierId         The optional carrier Id, may be
+         *                          {@link TelephonyManager#UNKNOWN_CARRIER_ID}.
+         *                          See {@link TelephonyManager#getSimCarrierId()}.
+         * @param specificCarrierId The optional fine-grained carrierId, may be {@link
+         *                          TelephonyManager#UNKNOWN_CARRIER_ID}. A specific carrierId may
+         *                          be different from the carrierId above in a MVNO scenario. See
+         *                          detail in {@link TelephonyManager#getSimSpecificCarrierId()}.
+         */
+        void onCarrierConfigChanged(int logicalSlotIndex, int subscriptionId, int carrierId,
+                int specificCarrierId);
+    }
+
+    /**
+     * Register a {@link CarrierConfigChangeListener} to get a notification when carrier
+     * configurations have changed.
+     *
+     * @param executor The executor on which the listener will be called.
+     * @param listener The CarrierConfigChangeListener called when carrier configs has changed.
+     */
+    public void registerCarrierConfigChangeListener(@NonNull @CallbackExecutor Executor executor,
+            @NonNull CarrierConfigChangeListener listener) {
+        Objects.requireNonNull(executor, "Executor should be non-null.");
+        Objects.requireNonNull(listener, "Listener should be non-null.");
+
+        TelephonyRegistryManager trm = mContext.getSystemService(TelephonyRegistryManager.class);
+        if (trm == null) {
+            throw new IllegalStateException("Telephony registry service is null");
+        }
+        trm.addCarrierConfigChangedListener(executor, listener);
+    }
+
+    /**
+     * Unregister the {@link CarrierConfigChangeListener} to stop notification on carrier
+     * configurations change.
+     *
+     * @param listener The CarrierConfigChangeListener which was registered with method
+     * {@link #registerCarrierConfigChangeListener(Executor, CarrierConfigChangeListener)}.
+     */
+    public void unregisterCarrierConfigChangeListener(
+            @NonNull CarrierConfigChangeListener listener) {
+        Objects.requireNonNull(listener, "Listener should be non-null.");
+
+        TelephonyRegistryManager trm = mContext.getSystemService(TelephonyRegistryManager.class);
+        if (trm == null) {
+            throw new IllegalStateException("Telephony registry service is null");
+        }
+        trm.removeCarrierConfigChangedListener(listener);
+    }
 }
diff --git a/telephony/java/android/telephony/CellSignalStrengthNr.java b/telephony/java/android/telephony/CellSignalStrengthNr.java
index 297940e..03519a3 100644
--- a/telephony/java/android/telephony/CellSignalStrengthNr.java
+++ b/telephony/java/android/telephony/CellSignalStrengthNr.java
@@ -155,6 +155,16 @@
      */
     private int mParametersUseForLevel;
 
+    /**
+     * Timing advance value for a one way trip from cell to device in microseconds.
+     * Approximate distance is calculated using 300m/us * timingAdvance.
+     *
+     * Reference: 3GPP TS 36.213 section 4.2.3.
+     *
+     * Range: [0, 1282]
+     */
+    private int mTimingAdvance;
+
     /** @hide */
     public CellSignalStrengthNr() {
         setDefaultValues();
@@ -169,10 +179,11 @@
      * @param ssRsrp SS reference signal received power.
      * @param ssRsrq SS reference signal received quality.
      * @param ssSinr SS signal-to-noise and interference ratio.
+     * @param timingAdvance Timing advance.
      * @hide
      */
     public CellSignalStrengthNr(int csiRsrp, int csiRsrq, int csiSinr, int csiCqiTableIndex,
-            List<Byte> csiCqiReport, int ssRsrp, int ssRsrq, int ssSinr) {
+            List<Byte> csiCqiReport, int ssRsrp, int ssRsrq, int ssSinr, int timingAdvance) {
         mCsiRsrp = inRangeOrUnavailable(csiRsrp, -156, -31);
         mCsiRsrq = inRangeOrUnavailable(csiRsrq, -20, -3);
         mCsiSinr = inRangeOrUnavailable(csiSinr, -23, 23);
@@ -183,6 +194,7 @@
         mSsRsrp = inRangeOrUnavailable(ssRsrp, -156, -31);
         mSsRsrq = inRangeOrUnavailable(ssRsrq, -43, 20);
         mSsSinr = inRangeOrUnavailable(ssSinr, -23, 40);
+        mTimingAdvance = inRangeOrUnavailable(timingAdvance, 0, 1282);
         updateLevel(null, null);
     }
 
@@ -198,7 +210,7 @@
     public CellSignalStrengthNr(
             int csiRsrp, int csiRsrq, int csiSinr, int ssRsrp, int ssRsrq, int ssSinr) {
         this(csiRsrp, csiRsrq, csiSinr, CellInfo.UNAVAILABLE, Collections.emptyList(),
-                ssRsrp, ssRsrq, ssSinr);
+                ssRsrp, ssRsrq, ssSinr, CellInfo.UNAVAILABLE);
     }
 
     /**
@@ -302,6 +314,22 @@
         return mCsiCqiReport;
     }
 
+    /**
+     * Get the timing advance value for a one way trip from cell to device for NR in microseconds.
+     * {@link android.telephony.CellInfo#UNAVAILABLE} is reported when there is no
+     * active RRC connection.
+     *
+     * Reference: 3GPP TS 36.213 section 4.2.3.
+     * Range: 0 us to 1282 us.
+     *
+     * @return the NR timing advance if available or
+     *         {@link android.telephony.CellInfo#UNAVAILABLE} if unavailable.
+     */
+    @IntRange(from = 0, to = 1282)
+    public int getTimingAdvanceMicros() {
+        return mTimingAdvance;
+    }
+
     @Override
     public int describeContents() {
         return 0;
@@ -319,6 +347,7 @@
         dest.writeInt(mSsRsrq);
         dest.writeInt(mSsSinr);
         dest.writeInt(mLevel);
+        dest.writeInt(mTimingAdvance);
     }
 
     private CellSignalStrengthNr(Parcel in) {
@@ -331,6 +360,7 @@
         mSsRsrq = in.readInt();
         mSsSinr = in.readInt();
         mLevel = in.readInt();
+        mTimingAdvance = in.readInt();
     }
 
     /** @hide */
@@ -346,6 +376,7 @@
         mSsSinr = CellInfo.UNAVAILABLE;
         mLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
         mParametersUseForLevel = USE_SSRSRP;
+        mTimingAdvance = CellInfo.UNAVAILABLE;
     }
 
     /** {@inheritDoc} */
@@ -495,6 +526,7 @@
         mSsSinr = s.mSsSinr;
         mLevel = s.mLevel;
         mParametersUseForLevel = s.mParametersUseForLevel;
+        mTimingAdvance = s.mTimingAdvance;
     }
 
     /** @hide */
@@ -506,7 +538,7 @@
     @Override
     public int hashCode() {
         return Objects.hash(mCsiRsrp, mCsiRsrq, mCsiSinr, mCsiCqiTableIndex,
-                mCsiCqiReport, mSsRsrp, mSsRsrq, mSsSinr, mLevel);
+                mCsiCqiReport, mSsRsrp, mSsRsrq, mSsSinr, mLevel, mTimingAdvance);
     }
 
     private static final CellSignalStrengthNr sInvalid = new CellSignalStrengthNr();
@@ -525,7 +557,7 @@
                     && mCsiCqiTableIndex == o.mCsiCqiTableIndex
                     && mCsiCqiReport.equals(o.mCsiCqiReport)
                     && mSsRsrp == o.mSsRsrp && mSsRsrq == o.mSsRsrq && mSsSinr == o.mSsSinr
-                    && mLevel == o.mLevel;
+                    && mLevel == o.mLevel && mTimingAdvance == o.mTimingAdvance;
         }
         return false;
     }
@@ -543,6 +575,7 @@
                 .append(" ssSinr = " + mSsSinr)
                 .append(" level = " + mLevel)
                 .append(" parametersUseForLevel = " + mParametersUseForLevel)
+                .append(" timingAdvance = " + mTimingAdvance)
                 .append(" }")
                 .toString();
     }
diff --git a/telephony/java/android/telephony/SmsManager.java b/telephony/java/android/telephony/SmsManager.java
index 1f301c1..d1f19ee 100644
--- a/telephony/java/android/telephony/SmsManager.java
+++ b/telephony/java/android/telephony/SmsManager.java
@@ -3125,6 +3125,43 @@
         }
     }
 
+    /**
+     * Set Storage Availability in SmsStorageMonitor
+     * @param storageAvailable storage availability to be set true or false
+     * @hide
+     */
+    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
+    @TestApi
+    public void setStorageMonitorMemoryStatusOverride(boolean storageAvailable) {
+        try {
+            ISms iccISms = getISmsServiceOrThrow();
+            if (iccISms != null) {
+                iccISms.setStorageMonitorMemoryStatusOverride(getSubscriptionId(),
+                                                                storageAvailable);
+            }
+        } catch (RemoteException ex) {
+            ex.rethrowFromSystemServer();
+        }
+    }
+
+    /**
+     * Clear the memory status override set by
+     * {@link #setStorageMonitorMemoryStatusOverride(boolean)}
+     * @hide
+     */
+    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
+    @TestApi
+    public void clearStorageMonitorMemoryStatusOverride() {
+        try {
+            ISms iccISms = getISmsServiceOrThrow();
+            if (iccISms != null) {
+                iccISms.clearStorageMonitorMemoryStatusOverride(getSubscriptionId());
+            }
+        } catch (RemoteException ex) {
+            ex.rethrowFromSystemServer();
+        }
+    }
+
     /** @hide */
     @Retention(RetentionPolicy.SOURCE)
     @IntDef(prefix = {"SMS_CATEGORY_"},
diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java
index 5244f41..8e8755d 100644
--- a/telephony/java/android/telephony/SubscriptionManager.java
+++ b/telephony/java/android/telephony/SubscriptionManager.java
@@ -58,6 +58,7 @@
 import android.provider.Telephony.SimInfo;
 import android.telephony.euicc.EuiccManager;
 import android.telephony.ims.ImsMmTelManager;
+import android.text.TextUtils;
 import android.util.Base64;
 import android.util.Log;
 import android.util.Pair;
@@ -370,7 +371,7 @@
 
     /**
      * A content {@link Uri} used to receive updates on advanced calling user setting
-     * @see ImsMmTelManager#isAdvancedCallingSettingEnabled().
+     *
      * <p>
      * Use this {@link Uri} with a {@link ContentObserver} to be notified of changes to the
      * subscription advanced calling enabled
@@ -381,6 +382,9 @@
      * delivery of updates to the {@link Uri}.
      * To be notified of changes to a specific subId, append subId to the URI
      * {@link Uri#withAppendedPath(Uri, String)}.
+     *
+     * @see ImsMmTelManager#isAdvancedCallingSettingEnabled()
+     *
      * @hide
      */
     @NonNull
@@ -754,6 +758,15 @@
     /** Indicates that data roaming is disabled for a subscription */
     public static final int DATA_ROAMING_DISABLE = SimInfo.DATA_ROAMING_DISABLE;
 
+    /** @hide */
+    @Retention(RetentionPolicy.SOURCE)
+    @IntDef(prefix = {"DATA_ROAMING_"},
+            value = {
+                    DATA_ROAMING_ENABLE,
+                    DATA_ROAMING_DISABLE
+            })
+    public @interface DataRoamingMode {}
+
     /**
      * TelephonyProvider column name for subscription carrier id.
      * @see TelephonyManager#getSimCarrierId()
@@ -1156,7 +1169,7 @@
      *
      * An opportunistic subscription will default to data-centric.
      *
-     * {@see SubscriptionInfo#isOpportunistic}
+     * @see SubscriptionInfo#isOpportunistic
      */
     public static final int USAGE_SETTING_DEFAULT = 0;
 
@@ -1940,7 +1953,7 @@
      *
      * <p>Requires the {@link android.Manifest.permission#WRITE_EMBEDDED_SUBSCRIPTIONS} permission.
      *
-     * @see {@link TelephonyManager#getCardIdForDefaultEuicc()} for more information on the card ID.
+     * @see TelephonyManager#getCardIdForDefaultEuicc() for more information on the card ID.
      *
      * @hide
      */
@@ -1970,7 +1983,7 @@
      *
      * @param cardId the card ID of the eUICC.
      *
-     * @see {@link TelephonyManager#getCardIdForDefaultEuicc()} for more information on the card ID.
+     * @see TelephonyManager#getCardIdForDefaultEuicc() for more information on the card ID.
      *
      * @hide
      */
@@ -2094,10 +2107,15 @@
     }
 
     /**
-     * Remove SubscriptionInfo record from the SubscriptionInfo database
+     * Remove subscription info record from the subscription database.
+     *
      * @param uniqueId This is the unique identifier for the subscription within the specific
-     *                 subscription type.
-     * @param subscriptionType the {@link #SUBSCRIPTION_TYPE}
+     * subscription type.
+     * @param subscriptionType the type of subscription to be removed.
+     *
+     * @throws NullPointerException if {@code uniqueId} is {@code null}.
+     * @throws SecurityException if callers do not hold the required permission.
+     *
      * @hide
      */
     @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
@@ -2448,20 +2466,6 @@
         return getActiveSubscriptionInfo(getDefaultDataSubscriptionId());
     }
 
-    /** @hide */
-    public void clearSubscriptionInfo() {
-        try {
-            ISub iSub = TelephonyManager.getSubscriptionService();
-            if (iSub != null) {
-                iSub.clearSubInfo();
-            }
-        } catch (RemoteException ex) {
-            // ignore it
-        }
-
-        return;
-    }
-
     /**
      * Check if the supplied subscription ID is valid.
      *
@@ -2605,48 +2609,27 @@
     }
 
     /**
-     * Returns a constant indicating the state of sim for the slot index.
+     * Set a field in the subscription database. Note not all fields are supported.
      *
-     * @param slotIndex
+     * @param subscriptionId Subscription Id of Subscription.
+     * @param columnName Column name in the database. Note not all fields are supported.
+     * @param value Value to store in the database.
      *
-     * {@See TelephonyManager#SIM_STATE_UNKNOWN}
-     * {@See TelephonyManager#SIM_STATE_ABSENT}
-     * {@See TelephonyManager#SIM_STATE_PIN_REQUIRED}
-     * {@See TelephonyManager#SIM_STATE_PUK_REQUIRED}
-     * {@See TelephonyManager#SIM_STATE_NETWORK_LOCKED}
-     * {@See TelephonyManager#SIM_STATE_READY}
-     * {@See TelephonyManager#SIM_STATE_NOT_READY}
-     * {@See TelephonyManager#SIM_STATE_PERM_DISABLED}
-     * {@See TelephonyManager#SIM_STATE_CARD_IO_ERROR}
+     * @throws IllegalArgumentException if {@code subscriptionId} is invalid, or the field is not
+     * exposed.
+     * @throws SecurityException if callers do not hold the required permission.
      *
-     * {@hide}
-     */
-    public static int getSimStateForSlotIndex(int slotIndex) {
-        int simState = TelephonyManager.SIM_STATE_UNKNOWN;
-
-        try {
-            ISub iSub = TelephonyManager.getSubscriptionService();
-            if (iSub != null) {
-                simState = iSub.getSimStateForSlotIndex(slotIndex);
-            }
-        } catch (RemoteException ex) {
-        }
-
-        return simState;
-    }
-
-    /**
-     * Store properties associated with SubscriptionInfo in database
-     * @param subId Subscription Id of Subscription
-     * @param propKey Column name in database associated with SubscriptionInfo
-     * @param propValue Value to store in DB for particular subId & column name
+     * @see android.provider.Telephony.SimInfo for all the columns.
+     *
      * @hide
      */
-    public static void setSubscriptionProperty(int subId, String propKey, String propValue) {
+    @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
+    public static void setSubscriptionProperty(int subscriptionId, @NonNull String columnName,
+            @NonNull String value) {
         try {
             ISub iSub = TelephonyManager.getSubscriptionService();
             if (iSub != null) {
-                iSub.setSubscriptionProperty(subId, propKey, propValue);
+                iSub.setSubscriptionProperty(subscriptionId, columnName, value);
             }
         } catch (RemoteException ex) {
             // ignore it
@@ -2675,118 +2658,149 @@
     }
 
     /**
-     * Return list of contacts uri corresponding to query result.
-     * @param subId Subscription Id of Subscription
-     * @param propKey Column name in SubscriptionInfo database
-     * @return list of contacts uri to be returned
+     * Get specific field in string format from the subscription info database.
+     *
+     * @param context The calling context.
+     * @param subscriptionId Subscription id of the subscription.
+     * @param columnName Column name in subscription database.
+     *
+     * @return Value in string format associated with {@code subscriptionId} and {@code columnName}
+     * from the database.
+     *
+     * @throws IllegalArgumentException if {@code subscriptionId} is invalid, or the field is not
+     * exposed.
+     *
+     * @see android.provider.Telephony.SimInfo for all the columns.
+     *
      * @hide
      */
-    private static List<Uri> getContactsFromSubscriptionProperty(int subId, String propKey,
-            Context context) {
-        String result = getSubscriptionProperty(subId, propKey, context);
-        if (result != null) {
-            try {
-                byte[] b = Base64.decode(result, Base64.DEFAULT);
-                ByteArrayInputStream bis = new ByteArrayInputStream(b);
-                ObjectInputStream ois = new ObjectInputStream(bis);
-                List<String> contacts = ArrayList.class.cast(ois.readObject());
-                List<Uri> uris = new ArrayList<>();
-                for (String contact : contacts) {
-                    uris.add(Uri.parse(contact));
-                }
-                return uris;
-            } catch (IOException e) {
-                logd("getContactsFromSubscriptionProperty IO exception");
-            } catch (ClassNotFoundException e) {
-                logd("getContactsFromSubscriptionProperty ClassNotFound exception");
-            }
-        }
-        return new ArrayList<>();
-    }
-
-    /**
-     * Store properties associated with SubscriptionInfo in database
-     * @param subId Subscription Id of Subscription
-     * @param propKey Column name in SubscriptionInfo database
-     * @return Value associated with subId and propKey column in database
-     * @hide
-     */
-    private static String getSubscriptionProperty(int subId, String propKey,
-            Context context) {
+    @NonNull
+    @RequiresPermission(anyOf = {
+            Manifest.permission.READ_PHONE_STATE,
+            Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
+            "carrier privileges",
+    })
+    private static String getStringSubscriptionProperty(@NonNull Context context,
+            int subscriptionId, @NonNull String columnName) {
         String resultValue = null;
         try {
             ISub iSub = TelephonyManager.getSubscriptionService();
             if (iSub != null) {
-                resultValue = iSub.getSubscriptionProperty(subId, propKey,
+                resultValue = iSub.getSubscriptionProperty(subscriptionId, columnName,
                         context.getOpPackageName(), context.getAttributionTag());
             }
         } catch (RemoteException ex) {
             // ignore it
         }
-        return resultValue;
+        return TextUtils.emptyIfNull(resultValue);
     }
 
     /**
-     * Returns boolean value corresponding to query result.
-     * @param subId Subscription Id of Subscription
-     * @param propKey Column name in SubscriptionInfo database
-     * @param defValue Default boolean value to be returned
-     * @return boolean result value to be returned
+     * Get specific field in {@code boolean} format from the subscription info database.
+     *
+     * @param subscriptionId Subscription id of the subscription.
+     * @param columnName Column name in subscription database.
+     * @param defaultValue Default value in case not found or error.
+     * @param context The calling context.
+     *
+     * @return Value in {@code boolean} format associated with {@code subscriptionId} and
+     * {@code columnName} from the database, or {@code defaultValue} if not found or error.
+     *
+     * @throws IllegalArgumentException if {@code subscriptionId} is invalid, or the field is not
+     * exposed.
+     *
+     * @see android.provider.Telephony.SimInfo for all the columns.
+     *
      * @hide
      */
-    public static boolean getBooleanSubscriptionProperty(int subId, String propKey,
-            boolean defValue, Context context) {
-        String result = getSubscriptionProperty(subId, propKey, context);
-        if (result != null) {
+    @RequiresPermission(anyOf = {
+            Manifest.permission.READ_PHONE_STATE,
+            Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
+            "carrier privileges",
+    })
+    public static boolean getBooleanSubscriptionProperty(int subscriptionId,
+            @NonNull String columnName, boolean defaultValue, @NonNull Context context) {
+        String result = getStringSubscriptionProperty(context, subscriptionId, columnName);
+        if (!result.isEmpty()) {
             try {
                 return Integer.parseInt(result) == 1;
             } catch (NumberFormatException err) {
                 logd("getBooleanSubscriptionProperty NumberFormat exception");
             }
         }
-        return defValue;
+        return defaultValue;
     }
 
     /**
-     * Returns integer value corresponding to query result.
-     * @param subId Subscription Id of Subscription
-     * @param propKey Column name in SubscriptionInfo database
-     * @param defValue Default integer value to be returned
-     * @return integer result value to be returned
+     * Get specific field in {@code integer} format from the subscription info database.
+     *
+     * @param subscriptionId Subscription id of the subscription.
+     * @param columnName Column name in subscription database.
+     * @param defaultValue Default value in case not found or error.
+     * @param context The calling context.
+     *
+     * @return Value in {@code integer} format associated with {@code subscriptionId} and
+     * {@code columnName} from the database, or {@code defaultValue} if not found or error.
+     *
+     * @throws IllegalArgumentException if {@code subscriptionId} is invalid, or the field is not
+     * exposed.
+     *
+     * @see android.provider.Telephony.SimInfo for all the columns.
+     *
      * @hide
      */
-    public static int getIntegerSubscriptionProperty(int subId, String propKey, int defValue,
-            Context context) {
-        String result = getSubscriptionProperty(subId, propKey, context);
-        if (result != null) {
+    @RequiresPermission(anyOf = {
+            Manifest.permission.READ_PHONE_STATE,
+            Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
+            "carrier privileges",
+    })
+    public static int getIntegerSubscriptionProperty(int subscriptionId, @NonNull String columnName,
+            int defaultValue, @NonNull Context context) {
+        String result = getStringSubscriptionProperty(context, subscriptionId, columnName);
+        if (!result.isEmpty()) {
             try {
                 return Integer.parseInt(result);
             } catch (NumberFormatException err) {
                 logd("getIntegerSubscriptionProperty NumberFormat exception");
             }
         }
-        return defValue;
+        return defaultValue;
     }
 
     /**
-     * Returns long value corresponding to query result.
-     * @param subId Subscription Id of Subscription
-     * @param propKey Column name in SubscriptionInfo database
-     * @param defValue Default long value to be returned
-     * @return long result value to be returned
+     * Get specific field in {@code long} format from the subscription info database.
+     *
+     * @param subscriptionId Subscription id of the subscription.
+     * @param columnName Column name in subscription database.
+     * @param defaultValue Default value in case not found or error.
+     * @param context The calling context.
+     *
+     * @return Value in {@code long} format associated with {@code subscriptionId} and
+     * {@code columnName} from the database, or {@code defaultValue} if not found or error.
+     *
+     * @throws IllegalArgumentException if {@code subscriptionId} is invalid, or the field is not
+     * exposed.
+     *
+     * @see android.provider.Telephony.SimInfo for all the columns.
+     *
      * @hide
      */
-    public static long getLongSubscriptionProperty(int subId, String propKey, long defValue,
-                                                     Context context) {
-        String result = getSubscriptionProperty(subId, propKey, context);
-        if (result != null) {
+    @RequiresPermission(anyOf = {
+            Manifest.permission.READ_PHONE_STATE,
+            Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
+            "carrier privileges",
+    })
+    public static long getLongSubscriptionProperty(int subscriptionId, @NonNull String columnName,
+            long defaultValue, @NonNull Context context) {
+        String result = getStringSubscriptionProperty(context, subscriptionId, columnName);
+        if (!result.isEmpty()) {
             try {
                 return Long.parseLong(result);
             } catch (NumberFormatException err) {
                 logd("getLongSubscriptionProperty NumberFormat exception");
             }
         }
-        return defValue;
+        return defaultValue;
     }
 
     /**
@@ -3024,7 +3038,6 @@
      *            considered unmetered.
      * @param networkTypes the network types this override applies to. If no
      *            network types are specified, override values will be ignored.
-     *            {@see TelephonyManager#getAllNetworkTypes()}
      * @param expirationDurationMillis the duration after which the requested override
      *            will be automatically cleared, or {@code 0} to leave in the
      *            requested state until explicitly cleared, or the next reboot,
@@ -3085,17 +3098,14 @@
      * </ul>
      *
      * @param subId the subscriber this override applies to.
-     * @param overrideCongested set if the subscription should be considered
-     *            congested.
-     * @param networkTypes the network types this override applies to. If no
-     *            network types are specified, override values will be ignored.
-     *            {@see TelephonyManager#getAllNetworkTypes()}
+     * @param overrideCongested set if the subscription should be considered congested.
+     * @param networkTypes the network types this override applies to. If no network types are
+     * specified, override values will be ignored.
      * @param expirationDurationMillis the duration after which the requested override
-     *            will be automatically cleared, or {@code 0} to leave in the
-     *            requested state until explicitly cleared, or the next reboot,
-     *            whichever happens first.
-     * @throws SecurityException if the caller doesn't meet the requirements
-     *            outlined above.
+     * will be automatically cleared, or {@code 0} to leave in the requested state until explicitly
+     * cleared, or the next reboot, whichever happens first.
+     *
+     * @throws SecurityException if the caller doesn't meet the requirements outlined above.
      */
     public void setSubscriptionOverrideCongested(int subId, boolean overrideCongested,
             @NonNull @Annotation.NetworkType int[] networkTypes,
@@ -3111,10 +3121,11 @@
      *
      * Only supported for embedded subscriptions (if {@link SubscriptionInfo#isEmbedded} returns
      * true). To check for permissions for non-embedded subscription as well,
-     * {@see android.telephony.TelephonyManager#hasCarrierPrivileges}.
      *
      * @param info The subscription to check.
      * @return whether the app is authorized to manage this subscription per its metadata.
+     *
+     * @see android.telephony.TelephonyManager#hasCarrierPrivileges
      */
     public boolean canManageSubscription(SubscriptionInfo info) {
         return canManageSubscription(info, mContext.getPackageName());
@@ -3127,11 +3138,13 @@
      *
      * Only supported for embedded subscriptions (if {@link SubscriptionInfo#isEmbedded} returns
      * true). To check for permissions for non-embedded subscription as well,
-     * {@see android.telephony.TelephonyManager#hasCarrierPrivileges}.
      *
      * @param info The subscription to check.
      * @param packageName Package name of the app to check.
+     *
      * @return whether the app is authorized to manage this subscription per its access rules.
+     *
+     * @see android.telephony.TelephonyManager#hasCarrierPrivileges
      * @hide
      */
     @SystemApi
@@ -3445,21 +3458,20 @@
 
     /**
      * Remove a list of subscriptions from their subscription group.
-     * See {@link #createSubscriptionGroup(List)} for more details.
      *
      * Caller will either have {@link android.Manifest.permission#MODIFY_PHONE_STATE}
-     * permission or had carrier privilege permission on the subscriptions:
-     * {@link TelephonyManager#hasCarrierPrivileges()} or
-     * {@link #canManageSubscription(SubscriptionInfo)}
-     *
-     * @throws SecurityException if the caller doesn't meet the requirements
-     *             outlined above.
-     * @throws IllegalArgumentException if the some subscriptions in the list doesn't belong
-     *             the specified group.
-     * @throws IllegalStateException if Telephony service is in bad state.
+     * permission or has carrier privilege permission on all of the subscriptions provided in
+     * {@code subIdList}.
      *
      * @param subIdList list of subId that need removing from their groups.
+     * @param groupUuid The UUID of the subscription group.
      *
+     * @throws SecurityException if the caller doesn't meet the requirements outlined above.
+     * @throws IllegalArgumentException if the some subscriptions in the list doesn't belong the
+     * specified group.
+     * @throws IllegalStateException if Telephony service is in bad state.
+     *
+     * @see #createSubscriptionGroup(List)
      */
     @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
     @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
@@ -3467,7 +3479,7 @@
             @NonNull ParcelUuid groupUuid) {
         Preconditions.checkNotNull(subIdList, "subIdList can't be null.");
         Preconditions.checkNotNull(groupUuid, "groupUuid can't be null.");
-        String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>";
+        String callingPackage = mContext != null ? mContext.getOpPackageName() : "<unknown>";
         if (VDBG) {
             logd("[removeSubscriptionsFromGroup]");
         }
@@ -3477,7 +3489,7 @@
         try {
             ISub iSub = TelephonyManager.getSubscriptionService();
             if (iSub != null) {
-                iSub.removeSubscriptionsFromGroup(subIdArray, groupUuid, pkgForDebug);
+                iSub.removeSubscriptionsFromGroup(subIdArray, groupUuid, callingPackage);
             } else {
                 if (!isSystemProcess()) {
                     throw new IllegalStateException("telephony service is null.");
@@ -3515,7 +3527,6 @@
      * @param groupUuid of which list of subInfo will be returned.
      * @return list of subscriptionInfo that belong to the same group, including the given
      * subscription itself. It will return an empty list if no subscription belongs to the group.
-     *
      */
     @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
     @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
@@ -3555,7 +3566,8 @@
      * want to see their own hidden subscriptions.
      *
      * @param info the subscriptionInfo to check against.
-     * @return true if this subscription should be visible to the API caller.
+     *
+     * @return {@code true} if this subscription should be visible to the API caller.
      *
      * @hide
      */
@@ -3628,9 +3640,9 @@
      * <p>
      * Permissions android.Manifest.permission.MODIFY_PHONE_STATE is required
      *
+     * @param subscriptionId Subscription to be enabled or disabled. It could be a eSIM or pSIM
+     * subscription.
      * @param enable whether user is turning it on or off.
-     * @param subscriptionId Subscription to be enabled or disabled.
-     *                       It could be a eSIM or pSIM subscription.
      *
      * @return whether the operation is successful.
      *
@@ -3663,8 +3675,6 @@
      * available from SubscriptionInfo.areUiccApplicationsEnabled() will be updated
      * immediately.)
      *
-     * Permissions android.Manifest.permission.MODIFY_PHONE_STATE is required
-     *
      * @param subscriptionId which subscription to operate on.
      * @param enabled whether uicc applications are enabled or disabled.
      * @hide
@@ -3697,8 +3707,6 @@
      * It provides whether a physical SIM card can be disabled without taking it out, which is done
      * via {@link #setSubscriptionEnabled(int, boolean)} API.
      *
-     * Requires Permission: READ_PRIVILEGED_PHONE_STATE.
-     *
      * @return whether can disable subscriptions on physical SIMs.
      *
      * @hide
@@ -3726,10 +3734,11 @@
     }
 
     /**
-     * DO NOT USE.
-     * This API is designed for features that are not finished at this point. Do not call this API.
+     * Check if the subscription is currently active in any slot.
+     *
+     * @param subscriptionId The subscription id.
+     *
      * @hide
-     * TODO b/135547512: further clean up
      */
     @SystemApi
     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
@@ -3747,11 +3756,14 @@
     }
 
     /**
-     * Set the device to device status sharing user preference for a subscription ID. The setting
+     * Set the device to device status sharing user preference for a subscription id. The setting
      * app uses this method to indicate with whom they wish to share device to device status
      * information.
-     * @param sharing the status sharing preference
-     * @param subscriptionId the unique Subscription ID in database
+     *
+     * @param subscriptionId The subscription id.
+     * @param sharing The status sharing preference.
+     *
+     * @throws SecurityException if the caller doesn't have permissions required.
      */
     @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
     public void setDeviceToDeviceStatusSharingPreference(int subscriptionId,
@@ -3768,6 +3780,8 @@
      * Returns the user-chosen device to device status sharing preference
      * @param subscriptionId Subscription id of subscription
      * @return The device to device status sharing preference
+     *
+     * @throws SecurityException if the caller doesn't have permissions required.
      */
     public @DeviceToDeviceStatusSharingPreference int getDeviceToDeviceStatusSharingPreference(
             int subscriptionId) {
@@ -3779,11 +3793,14 @@
     }
 
     /**
-     * Set the list of contacts that allow device to device status sharing for a subscription ID.
+     * Set the list of contacts that allow device to device status sharing for a subscription id.
      * The setting app uses this method to indicate with whom they wish to share device to device
      * status information.
-     * @param contacts The list of contacts that allow device to device status sharing
-     * @param subscriptionId The unique Subscription ID in database
+     *
+     * @param subscriptionId The subscription id.
+     * @param contacts The list of contacts that allow device to device status sharing.
+     *
+     * @throws SecurityException if the caller doesn't have permissions required.
      */
     @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
     public void setDeviceToDeviceStatusSharingContacts(int subscriptionId,
@@ -3799,17 +3816,33 @@
     }
 
     /**
-     * Returns the list of contacts that allow device to device status sharing.
-     * @param subscriptionId Subscription id of subscription
-     * @return The list of contacts that allow device to device status sharing
+     * Get the list of contacts that allow device to device status sharing.
+     *
+     * @param subscriptionId Subscription id.
+     *
+     * @return The list of contacts that allow device to device status sharing.
      */
-    public @NonNull List<Uri> getDeviceToDeviceStatusSharingContacts(
-            int subscriptionId) {
-        if (VDBG) {
-            logd("[getDeviceToDeviceStatusSharingContacts] + subId: " + subscriptionId);
+    public @NonNull List<Uri> getDeviceToDeviceStatusSharingContacts(int subscriptionId) {
+        String result = getStringSubscriptionProperty(mContext, subscriptionId,
+                D2D_STATUS_SHARING_SELECTED_CONTACTS);
+        if (result != null) {
+            try {
+                byte[] b = Base64.decode(result, Base64.DEFAULT);
+                ByteArrayInputStream bis = new ByteArrayInputStream(b);
+                ObjectInputStream ois = new ObjectInputStream(bis);
+                List<String> contacts = ArrayList.class.cast(ois.readObject());
+                List<Uri> uris = new ArrayList<>();
+                for (String contact : contacts) {
+                    uris.add(Uri.parse(contact));
+                }
+                return uris;
+            } catch (IOException e) {
+                logd("getDeviceToDeviceStatusSharingContacts IO exception");
+            } catch (ClassNotFoundException e) {
+                logd("getDeviceToDeviceStatusSharingContacts ClassNotFound exception");
+            }
         }
-        return getContactsFromSubscriptionProperty(subscriptionId,
-                D2D_STATUS_SHARING_SELECTED_CONTACTS, mContext);
+        return new ArrayList<>();
     }
 
     /**
@@ -3864,12 +3897,12 @@
     /**
      * Get active data subscription id. Active data subscription refers to the subscription
      * currently chosen to provide cellular internet connection to the user. This may be
-     * different from getDefaultDataSubscriptionId(). Eg. Opportunistics data
+     * different from {@link #getDefaultDataSubscriptionId()}.
      *
-     * See {@link PhoneStateListener#onActiveDataSubscriptionIdChanged(int)} for the details.
+     * @return Active data subscription id if any is chosen, or {@link #INVALID_SUBSCRIPTION_ID} if
+     * not.
      *
-     * @return Active data subscription id if any is chosen, or
-     * SubscriptionManager.INVALID_SUBSCRIPTION_ID if not.
+     * @see TelephonyCallback.ActiveDataSubscriptionIdListener
      */
     public static int getActiveDataSubscriptionId() {
         if (isSubscriptionManagerServiceEnabled()) {
@@ -4062,12 +4095,15 @@
      * security-related or other sensitive scenarios.
      *
      * @param subscriptionId the subscription ID, or {@link #DEFAULT_SUBSCRIPTION_ID}
-     *                       for the default one.
+     * for the default one.
      * @param source the source of the phone number, one of the PHONE_NUMBER_SOURCE_* constants.
+     *
      * @return the phone number, or an empty string if not available.
+     *
      * @throws IllegalArgumentException if {@code source} is invalid.
      * @throws IllegalStateException if the telephony process is not currently available.
      * @throws SecurityException if the caller doesn't have permissions required.
+     *
      * @see #PHONE_NUMBER_SOURCE_UICC
      * @see #PHONE_NUMBER_SOURCE_CARRIER
      * @see #PHONE_NUMBER_SOURCE_IMS
@@ -4124,8 +4160,10 @@
      * @param subscriptionId the subscription ID, or {@link #DEFAULT_SUBSCRIPTION_ID}
      *                       for the default one.
      * @return the phone number, or an empty string if not available.
+     *
      * @throws IllegalStateException if the telephony process is not currently available.
      * @throws SecurityException if the caller doesn't have permissions required.
+     *
      * @see #getPhoneNumber(int, int)
      */
     @RequiresPermission(anyOf = {
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index 3024b89..5d49413 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -71,7 +71,6 @@
 import android.os.RemoteException;
 import android.os.ResultReceiver;
 import android.os.SystemProperties;
-import android.os.UserHandle;
 import android.os.WorkSource;
 import android.provider.Settings.SettingNotFoundException;
 import android.service.carrier.CarrierIdentifier;
@@ -127,7 +126,6 @@
 import com.android.internal.telephony.OperatorInfo;
 import com.android.internal.telephony.PhoneConstants;
 import com.android.internal.telephony.RILConstants;
-import com.android.internal.telephony.SmsApplication;
 import com.android.telephony.Rlog;
 
 import java.io.IOException;
@@ -2937,7 +2935,7 @@
     public static final int NETWORK_TYPE_HSPA = TelephonyProtoEnums.NETWORK_TYPE_HSPA; // = 10.
     /**
      * Current network is iDen
-     * @deprecated Legacy network type no longer being used.
+     * @deprecated Legacy network type no longer being used starting in Android U.
      */
     @Deprecated
     public static final int NETWORK_TYPE_IDEN = TelephonyProtoEnums.NETWORK_TYPE_IDEN; // = 11.
@@ -3558,7 +3556,7 @@
                     "state as absent");
             return SIM_STATE_ABSENT;
         }
-        return SubscriptionManager.getSimStateForSlotIndex(slotIndex);
+        return getSimStateForSlotIndex(slotIndex);
     }
 
     /**
@@ -3705,9 +3703,7 @@
     @Deprecated
     public @SimState int getSimApplicationState(int physicalSlotIndex) {
         int activePort = getFirstActivePortIndex(physicalSlotIndex);
-        int simState =
-                SubscriptionManager.getSimStateForSlotIndex(getLogicalSlotIndex(physicalSlotIndex,
-                        activePort));
+        int simState = getSimStateForSlotIndex(getLogicalSlotIndex(physicalSlotIndex, activePort));
         return getSimApplicationStateFromSimState(simState);
     }
 
@@ -3733,9 +3729,7 @@
     @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
     @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION)
     public @SimState int getSimApplicationState(int physicalSlotIndex, int portIndex) {
-        int simState =
-                SubscriptionManager.getSimStateForSlotIndex(getLogicalSlotIndex(physicalSlotIndex,
-                        portIndex));
+        int simState = getSimStateForSlotIndex(getLogicalSlotIndex(physicalSlotIndex, portIndex));
         return getSimApplicationStateFromSimState(simState);
     }
 
@@ -3804,7 +3798,7 @@
      */
     @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION)
     public @SimState int getSimState(int slotIndex) {
-        int simState = SubscriptionManager.getSimStateForSlotIndex(slotIndex);
+        int simState = getSimStateForSlotIndex(slotIndex);
         if (simState == SIM_STATE_LOADED) {
             simState = SIM_STATE_READY;
         }
@@ -13966,7 +13960,7 @@
      * If used, will be converted to {@link #NETWORK_TYPE_BITMASK_LTE}.
      * network type bitmask indicating the support of radio tech LTE CA (carrier aggregation).
      *
-     * @deprecated Please use {@link #NETWORK_TYPE_BITMASK_LTE} instead.
+     * @deprecated Please use {@link #NETWORK_TYPE_BITMASK_LTE} instead. Deprecated in Android U.
      */
     @Deprecated
     public static final long NETWORK_TYPE_BITMASK_LTE_CA = (1 << (NETWORK_TYPE_LTE_CA -1));
@@ -17747,4 +17741,85 @@
         }
         return null;
     }
+
+    /**
+     * Returns a constant indicating the state of sim for the slot index.
+     *
+     * @param slotIndex Logical SIM slot index.
+     *
+     * @see TelephonyManager.SimState
+     *
+     * @hide
+     */
+    @SimState
+    public static int getSimStateForSlotIndex(int slotIndex) {
+        try {
+            ITelephony telephony = ITelephony.Stub.asInterface(
+                    TelephonyFrameworkInitializer
+                            .getTelephonyServiceManager()
+                            .getTelephonyServiceRegisterer()
+                            .get());
+            if (telephony != null) {
+                return telephony.getSimStateForSlotIndex(slotIndex);
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error in getSimStateForSlotIndex: " + e);
+        }
+        return TelephonyManager.SIM_STATE_UNKNOWN;
+    }
+
+    /**
+     * Set the UE's ability to accept/reject null ciphered and null integrity-protected connections.
+     *
+     * The modem is required to ignore this in case of an emergency call.
+     *
+     * <p>Requires permission: android.Manifest.MODIFY_PHONE_STATE</p>
+     *
+     * @param enabled if null ciphered and null integrity protected connections are permitted
+     * @throws IllegalStateException if the Telephony process is not currently available
+     * @throws SecurityException if the caller does not have the required privileges
+     * @throws UnsupportedOperationException if the modem does not support disabling null ciphers.
+     * @hide
+     */
+    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
+    public void setNullCipherAndIntegrityEnabled(boolean enabled) {
+        try {
+            ITelephony telephony = getITelephony();
+            if (telephony != null) {
+                telephony.setNullCipherAndIntegrityEnabled(enabled);
+            } else {
+                throw new IllegalStateException("telephony service is null.");
+            }
+        } catch (RemoteException ex) {
+            Rlog.e(TAG, "setNullCipherAndIntegrityEnabled RemoteException", ex);
+            ex.rethrowFromSystemServer();
+        }
+    }
+
+    /**
+     * Get the value of the global preference for null cipher and integriy enablement.
+     * Note: This does not return the state of the modem, only the persisted global preference.
+     *
+     * <p>Requires permission: android.Manifest.READ_PHONE_STATE</p>
+     *
+     * @throws IllegalStateException if the Telephony process is not currently available
+     * @throws SecurityException if the caller does not have the required privileges
+     * @throws UnsupportedOperationException if the modem does not support disabling null ciphers.
+     * @hide
+     */
+    @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
+    public boolean isNullCipherAndIntegrityPreferenceEnabled() {
+        try {
+            ITelephony telephony = getITelephony();
+            if (telephony != null) {
+                return telephony.isNullCipherAndIntegrityPreferenceEnabled();
+            } else {
+                throw new IllegalStateException("telephony service is null.");
+            }
+        } catch (RemoteException ex) {
+            Rlog.e(TAG, "isNullCipherAndIntegrityPreferenceEnabled RemoteException", ex);
+            ex.rethrowFromSystemServer();
+        }
+        return true;
+    }
 }
diff --git a/telephony/java/android/telephony/data/ApnSetting.java b/telephony/java/android/telephony/data/ApnSetting.java
index fa3f15d..554beb9 100644
--- a/telephony/java/android/telephony/data/ApnSetting.java
+++ b/telephony/java/android/telephony/data/ApnSetting.java
@@ -1286,7 +1286,7 @@
                 && xorEqualsInt(this.mMmsProxyPort, other.mMmsProxyPort))
                 && xorEqualsString(this.mUser, other.mUser)
                 && xorEqualsString(this.mPassword, other.mPassword)
-                && xorEqualsInt(this.mAuthType, other.mAuthType)
+                && Objects.equals(this.mAuthType, other.mAuthType)
                 && !typeSameAny(this, other)
                 && Objects.equals(this.mOperatorNumeric, other.mOperatorNumeric)
                 && Objects.equals(this.mProtocol, other.mProtocol)
diff --git a/telephony/java/android/telephony/euicc/EuiccManager.java b/telephony/java/android/telephony/euicc/EuiccManager.java
index a2d2019..cdb7d7c 100644
--- a/telephony/java/android/telephony/euicc/EuiccManager.java
+++ b/telephony/java/android/telephony/euicc/EuiccManager.java
@@ -1570,8 +1570,8 @@
 
     /**
      * Returns whether the passing portIndex is available.
-     * A port is available if it is active without enabled profile on it or
-     * calling app has carrier privilege over the profile installed on the selected port.
+     * A port is available if it is active without an enabled profile on it or calling app can
+     * activate a new profile on the selected port without any user interaction.
      * Always returns false if the cardId is a physical card.
      *
      * @param portIndex is an enumeration of the ports available on the UICC.
diff --git a/telephony/java/android/telephony/ims/RegistrationManager.java b/telephony/java/android/telephony/ims/RegistrationManager.java
index 9996b86..7a800a5 100644
--- a/telephony/java/android/telephony/ims/RegistrationManager.java
+++ b/telephony/java/android/telephony/ims/RegistrationManager.java
@@ -23,6 +23,7 @@
 import android.annotation.Nullable;
 import android.annotation.RequiresFeature;
 import android.annotation.RequiresPermission;
+import android.annotation.SystemApi;
 import android.content.pm.PackageManager;
 import android.net.Uri;
 import android.os.Binder;
@@ -75,6 +76,41 @@
      */
     int REGISTRATION_STATE_REGISTERED = 2;
 
+    /** @hide */
+    @IntDef(prefix = {"SUGGESTED_ACTION_"},
+            value = {
+            SUGGESTED_ACTION_NONE,
+            SUGGESTED_ACTION_TRIGGER_PLMN_BLOCK,
+            SUGGESTED_ACTION_TRIGGER_PLMN_BLOCK_WITH_TIMEOUT
+    })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface SuggestedAction {}
+
+    /**
+     * Default value. No action is suggested when IMS registration fails.
+     * @hide
+     */
+    @SystemApi
+    public static final int SUGGESTED_ACTION_NONE = 0;
+
+    /**
+     * Indicates that the IMS registration is failed with fatal error such as 403 or 404
+     * on all P-CSCF addresses. The radio shall block the current PLMN or disable
+     * the RAT as per the carrier requirements.
+     * @hide
+     */
+    @SystemApi
+    public static final int SUGGESTED_ACTION_TRIGGER_PLMN_BLOCK = 1;
+
+    /**
+     * Indicates that the IMS registration on current PLMN failed multiple times.
+     * The radio shall block the current PLMN or disable the RAT during EPS or 5GS mobility
+     * management timer value as per the carrier requirements.
+     * @hide
+     */
+    @SystemApi
+    public static final int SUGGESTED_ACTION_TRIGGER_PLMN_BLOCK_WITH_TIMEOUT = 2;
+
     /**@hide*/
     // Translate ImsRegistrationImplBase API to new AccessNetworkConstant because WLAN
     // and WWAN are more accurate constants.
@@ -167,12 +203,12 @@
             }
 
             @Override
-            public void onDeregistered(ImsReasonInfo info) {
+            public void onDeregistered(ImsReasonInfo info, @SuggestedAction int suggestedAction) {
                 if (mLocalCallback == null) return;
 
                 final long callingIdentity = Binder.clearCallingIdentity();
                 try {
-                    mExecutor.execute(() -> mLocalCallback.onUnregistered(info));
+                    mExecutor.execute(() -> mLocalCallback.onUnregistered(info, suggestedAction));
                 } finally {
                     restoreCallingIdentity(callingIdentity);
                 }
@@ -258,6 +294,21 @@
         }
 
         /**
+         * Notifies the framework when the IMS Provider is unregistered from the IMS network.
+         *
+         * @param info the {@link ImsReasonInfo} associated with why registration was disconnected.
+         * @param suggestedAction the expected behavior of radio protocol stack.
+         *
+         * @hide
+         */
+        @SystemApi
+        public void onUnregistered(@NonNull ImsReasonInfo info,
+                @SuggestedAction int suggestedAction) {
+            // Default impl to keep backwards compatibility with old implementations
+            onUnregistered(info);
+        }
+
+        /**
          * A failure has occurred when trying to handover registration to another technology type.
          *
          * @param imsTransportType The transport type that has failed to handover registration to.
diff --git a/telephony/java/android/telephony/ims/aidl/IImsMmTelFeature.aidl b/telephony/java/android/telephony/ims/aidl/IImsMmTelFeature.aidl
index ea4480d..cf7e9e16 100644
--- a/telephony/java/android/telephony/ims/aidl/IImsMmTelFeature.aidl
+++ b/telephony/java/android/telephony/ims/aidl/IImsMmTelFeature.aidl
@@ -64,6 +64,7 @@
     void setSmsListener(IImsSmsListener l);
     oneway void sendSms(in int token, int messageRef, String format, String smsc, boolean retry,
             in byte[] pdu);
+    oneway void onMemoryAvailable(int token);
     oneway void acknowledgeSms(int token, int messageRef, int result);
     oneway void acknowledgeSmsWithPdu(int token, int messageRef, int result, in byte[] pdu);
     oneway void acknowledgeSmsReport(int token, int messageRef, int result);
diff --git a/telephony/java/android/telephony/ims/aidl/IImsMmTelListener.aidl b/telephony/java/android/telephony/ims/aidl/IImsMmTelListener.aidl
index 5246470..640426b 100644
--- a/telephony/java/android/telephony/ims/aidl/IImsMmTelListener.aidl
+++ b/telephony/java/android/telephony/ims/aidl/IImsMmTelListener.aidl
@@ -34,4 +34,5 @@
     void onIncomingCall(IImsCallSession c, in Bundle extras);
     void onRejectedCall(in ImsCallProfile callProfile, in ImsReasonInfo reason);
     oneway void onVoiceMessageCountUpdate(int count);
+    oneway void onAudioModeIsVoipChanged(int imsAudioHandler);
 }
diff --git a/telephony/java/android/telephony/ims/aidl/IImsRegistration.aidl b/telephony/java/android/telephony/ims/aidl/IImsRegistration.aidl
index 4fd9040..219c9c8 100644
--- a/telephony/java/android/telephony/ims/aidl/IImsRegistration.aidl
+++ b/telephony/java/android/telephony/ims/aidl/IImsRegistration.aidl
@@ -31,4 +31,5 @@
    oneway void triggerFullNetworkRegistration(int sipCode, String sipReason);
    oneway void triggerUpdateSipDelegateRegistration();
    oneway void triggerSipDelegateDeregistration();
+   oneway void triggerDeregistration(int reason);
 }
diff --git a/telephony/java/android/telephony/ims/aidl/IImsRegistrationCallback.aidl b/telephony/java/android/telephony/ims/aidl/IImsRegistrationCallback.aidl
index 179407c..069eb46 100644
--- a/telephony/java/android/telephony/ims/aidl/IImsRegistrationCallback.aidl
+++ b/telephony/java/android/telephony/ims/aidl/IImsRegistrationCallback.aidl
@@ -31,7 +31,7 @@
 oneway interface IImsRegistrationCallback {
    void onRegistered(in ImsRegistrationAttributes attr);
    void onRegistering(in ImsRegistrationAttributes attr);
-   void onDeregistered(in ImsReasonInfo info);
+   void onDeregistered(in ImsReasonInfo info, int suggestedAction);
    void onTechnologyChangeFailed(int imsRadioTech, in ImsReasonInfo info);
    void onSubscriberAssociatedUriChanged(in Uri[] uris);
-}
\ No newline at end of file
+}
diff --git a/telephony/java/android/telephony/ims/feature/MmTelFeature.java b/telephony/java/android/telephony/ims/feature/MmTelFeature.java
index d776928..4710c1f 100644
--- a/telephony/java/android/telephony/ims/feature/MmTelFeature.java
+++ b/telephony/java/android/telephony/ims/feature/MmTelFeature.java
@@ -269,6 +269,12 @@
         }
 
         @Override
+        public void onMemoryAvailable(int token) {
+            executeMethodAsyncNoException(() -> MmTelFeature.this
+                    .onMemoryAvailable(token), "onMemoryAvailable");
+        }
+
+        @Override
         public void acknowledgeSms(int token, int messageRef, int result) {
             executeMethodAsyncNoException(() -> MmTelFeature.this
                     .acknowledgeSms(token, messageRef, result), "acknowledgeSms");
@@ -573,6 +579,17 @@
         public void onVoiceMessageCountUpdate(int count) {
 
         }
+
+        /**
+         * Called to set the audio handler for this connection.
+         * @param imsAudioHandler an {@link ImsAudioHandler} used to handle the audio
+         *        for this IMS call.
+         * @hide
+         */
+        @Override
+        public void onAudioModeIsVoipChanged(int imsAudioHandler) {
+
+        }
     }
 
     /**
@@ -622,6 +639,29 @@
     public static final String EXTRA_IS_UNKNOWN_CALL =
             "android.telephony.ims.feature.extra.IS_UNKNOWN_CALL";
 
+    /** @hide */
+    @IntDef(flag = true,
+            value = {
+                    AUDIO_HANDLER_ANDROID,
+                    AUDIO_HANDLER_BASEBAND
+            })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface ImsAudioHandler {}
+
+    /**
+    * Audio Handler - Android
+    * @hide
+    */
+    @SystemApi
+    public static final int AUDIO_HANDLER_ANDROID = 0;
+
+    /**
+    * Audio Handler - Baseband
+    * @hide
+    */
+    @SystemApi
+    public static final int AUDIO_HANDLER_BASEBAND = 1;
+
     private IImsMmTelListener mListener;
 
     /**
@@ -700,6 +740,7 @@
             throw new IllegalStateException("Session is not available.");
         }
         try {
+            c.setDefaultExecutor(MmTelFeature.this.mExecutor);
             listener.onIncomingCall(c.getServiceImpl(), extras);
         } catch (RemoteException e) {
             throw new RuntimeException(e);
@@ -767,6 +808,28 @@
     }
 
     /**
+     * Sets the audio handler for this connection. The vendor IMS stack will invoke this API
+     * to inform Telephony/Telecom layers about which audio handlers i.e. either Android or Modem
+     * shall be used for handling the IMS call audio.
+     *
+     * @param imsAudioHandler {@link MmTelFeature#ImsAudioHandler} used to handle the audio
+     *        for this IMS call.
+     * @hide
+     */
+    @SystemApi
+    public final void setCallAudioHandler(@ImsAudioHandler int imsAudioHandler) {
+        IImsMmTelListener listener = getListener();
+        if (listener == null) {
+            throw new IllegalStateException("Session is not available.");
+        }
+        try {
+            listener.onAudioModeIsVoipChanged(imsAudioHandler);
+        } catch (RemoteException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
      * Provides the MmTelFeature with the ability to return the framework Capability Configuration
      * for a provided Capability. If the framework calls {@link #changeEnabledCapabilities} and
      * includes a capability A to enable or disable, this method should return the correct enabled
@@ -1088,6 +1151,10 @@
         getSmsImplementation().sendSms(token, messageRef, format, smsc, isRetry, pdu);
     }
 
+    private void onMemoryAvailable(int token) {
+        getSmsImplementation().onMemoryAvailable(token);
+    }
+
     private void acknowledgeSms(int token, int messageRef,
             @ImsSmsImplBase.DeliverStatusResult int result) {
         getSmsImplementation().acknowledgeSms(token, messageRef, result);
diff --git a/telephony/java/android/telephony/ims/stub/ImsRegistrationImplBase.java b/telephony/java/android/telephony/ims/stub/ImsRegistrationImplBase.java
index 6fc1cc8..117593a 100644
--- a/telephony/java/android/telephony/ims/stub/ImsRegistrationImplBase.java
+++ b/telephony/java/android/telephony/ims/stub/ImsRegistrationImplBase.java
@@ -64,7 +64,8 @@
                     REGISTRATION_TECH_LTE,
                     REGISTRATION_TECH_IWLAN,
                     REGISTRATION_TECH_CROSS_SIM,
-                    REGISTRATION_TECH_NR
+                    REGISTRATION_TECH_NR,
+                    REGISTRATION_TECH_3G
             })
     @Retention(RetentionPolicy.SOURCE)
     public @interface ImsRegistrationTech {}
@@ -92,10 +93,15 @@
     public static final int REGISTRATION_TECH_NR = 3;
 
     /**
+     * This ImsService is registered to IMS via 3G.
+     */
+    public static final int REGISTRATION_TECH_3G = 4;
+
+    /**
      * This is used to check the upper range of registration tech
      * @hide
      */
-    public static final int REGISTRATION_TECH_MAX = REGISTRATION_TECH_NR + 1;
+    public static final int REGISTRATION_TECH_MAX = REGISTRATION_TECH_3G + 1;
 
     // Registration states, used to notify new ImsRegistrationImplBase#Callbacks of the current
     // state.
@@ -104,6 +110,73 @@
     // yet.
     private static final int REGISTRATION_STATE_UNKNOWN = -1;
 
+    /** @hide */
+    @Retention(RetentionPolicy.SOURCE)
+    @IntDef(
+        prefix = {"REASON_"},
+        value = {
+            REASON_UNKNOWN,
+            REASON_SIM_REMOVED,
+            REASON_SIM_REFRESH,
+            REASON_ALLOWED_NETWORK_TYPES_CHANGED,
+            REASON_NON_IMS_CAPABLE_NETWORK,
+            REASON_RADIO_POWER_OFF,
+            REASON_HANDOVER_FAILED,
+            REASON_VOPS_NOT_SUPPORTED,
+        })
+    public @interface ImsDeregistrationReason{}
+
+    /**
+     * Unspecified reason.
+     * @hide
+     */
+    public static final int REASON_UNKNOWN = 0;
+
+    /**
+     * Since SIM is removed, the credentials for IMS service is also removed.
+     * @hide
+     */
+    public static final int REASON_SIM_REMOVED = 1;
+
+    /**
+     * Detach from the network shall be performed due to the SIM refresh. IMS service should be
+     * deregistered before that procedure.
+     * @hide
+     */
+    public static final int REASON_SIM_REFRESH = 2;
+
+    /**
+     * The allowed network types have changed, resulting in a network type
+     * that does not support IMS.
+     * @hide
+     */
+    public static final int REASON_ALLOWED_NETWORK_TYPES_CHANGED = 3;
+
+   /**
+     * The device camped on a network that does not support IMS.
+     * @hide
+     */
+    public static final int REASON_NON_IMS_CAPABLE_NETWORK = 4;
+
+    /**
+     * IMS service should be deregistered from the network before turning off the radio.
+     * @hide
+     */
+    public static final int REASON_RADIO_POWER_OFF = 5;
+
+    /**
+     * Since the handover is failed or not allowed, the data service for IMS shall be
+     * disconnected.
+     * @hide
+     */
+    public static final int REASON_HANDOVER_FAILED = 6;
+
+    /**
+     * The network is changed to a network that does not support voice over IMS.
+     * @hide
+     */
+    public static final int REASON_VOPS_NOT_SUPPORTED = 7;
+
     private Executor mExecutor;
 
     /**
@@ -182,6 +255,12 @@
                     .triggerSipDelegateDeregistration(), "triggerSipDelegateDeregistration");
         }
 
+        @Override
+        public void triggerDeregistration(@ImsDeregistrationReason int reason) {
+            executeMethodAsyncNoException(() -> ImsRegistrationImplBase.this
+                    .triggerDeregistration(reason), "triggerDeregistration");
+        }
+
         // Call the methods with a clean calling identity on the executor and wait indefinitely for
         // the future to return.
         private void executeMethodAsync(Runnable r, String errorLogName) throws RemoteException {
@@ -228,6 +307,8 @@
     private int mRegistrationState = REGISTRATION_STATE_UNKNOWN;
     // Locked on mLock, create unspecified disconnect cause.
     private ImsReasonInfo mLastDisconnectCause = new ImsReasonInfo();
+    // Locked on mLock
+    private int mLastDisconnectSuggestedAction = RegistrationManager.SUGGESTED_ACTION_NONE;
 
     // We hold onto the uris each time they change so that we can send it to a callback when its
     // first added.
@@ -303,6 +384,19 @@
         // Stub implementation, ImsService should implement this
     }
 
+    /**
+     * Requests IMS stack to perform graceful IMS deregistration before radio performing
+     * network detach in the events of SIM remove, refresh or and so on. The radio waits for
+     * the IMS deregistration, which will be notified by telephony via
+     * {@link android.hardware.radio.ims.IRadioIms#updateImsRegistrationInfo()},
+     * or a certain timeout interval to start the network detach procedure.
+     *
+     * @param reason the reason why the deregistration is triggered.
+     * @hide
+     */
+    public void triggerDeregistration(@ImsDeregistrationReason int reason) {
+        // Stub Implementation, can be overridden by ImsService
+    }
 
     /**
      * Notify the framework that the device is connected to the IMS network.
@@ -381,12 +475,37 @@
      */
     @SystemApi
     public final void onDeregistered(ImsReasonInfo info) {
-        updateToDisconnectedState(info);
+        // Default impl to keep backwards compatibility with old implementations
+        onDeregistered(info, RegistrationManager.SUGGESTED_ACTION_NONE);
+    }
+
+    /**
+     * Notify the framework that the device is disconnected from the IMS network.
+     * <p>
+     * Note: Prior to calling {@link #onDeregistered(ImsReasonInfo,int)}, you should ensure that any
+     * changes to {@link android.telephony.ims.feature.ImsFeature} capability availability is sent
+     * to the framework.  For example,
+     * {@link android.telephony.ims.feature.MmTelFeature.MmTelCapabilities#CAPABILITY_TYPE_VIDEO}
+     * and
+     * {@link android.telephony.ims.feature.MmTelFeature.MmTelCapabilities#CAPABILITY_TYPE_VOICE}
+     * may be set to unavailable to ensure the framework knows these services are no longer
+     * available due to de-registration.  If you do not report capability changes impacted by
+     * de-registration, the framework will not know which features are no longer available as a
+     * result.
+     *
+     * @param info the {@link ImsReasonInfo} associated with why registration was disconnected.
+     * @param suggestedAction the expected behavior of radio protocol stack.
+     * @hide This API is not part of the Android public SDK API
+     */
+    @SystemApi
+    public final void onDeregistered(@Nullable ImsReasonInfo info,
+            @RegistrationManager.SuggestedAction int suggestedAction) {
+        updateToDisconnectedState(info, suggestedAction);
         // ImsReasonInfo should never be null.
         final ImsReasonInfo reasonInfo = (info != null) ? info : new ImsReasonInfo();
         mCallbacks.broadcastAction((c) -> {
             try {
-                c.onDeregistered(reasonInfo);
+                c.onDeregistered(reasonInfo, suggestedAction);
             } catch (RemoteException e) {
                 Log.w(LOG_TAG, e + "onDeregistered() - Skipping callback.");
             }
@@ -445,10 +564,12 @@
             mRegistrationAttributes = attributes;
             mRegistrationState = newState;
             mLastDisconnectCause = null;
+            mLastDisconnectSuggestedAction = RegistrationManager.SUGGESTED_ACTION_NONE;
         }
     }
 
-    private void updateToDisconnectedState(ImsReasonInfo info) {
+    private void updateToDisconnectedState(ImsReasonInfo info,
+            @RegistrationManager.SuggestedAction int suggestedAction) {
         synchronized (mLock) {
             //We don't want to send this info over if we are disconnected
             mUrisSet = false;
@@ -458,6 +579,7 @@
                     RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED);
             if (info != null) {
                 mLastDisconnectCause = info;
+                mLastDisconnectSuggestedAction = suggestedAction;
             } else {
                 Log.w(LOG_TAG, "updateToDisconnectedState: no ImsReasonInfo provided.");
                 mLastDisconnectCause = new ImsReasonInfo();
@@ -474,18 +596,20 @@
         int state;
         ImsRegistrationAttributes attributes;
         ImsReasonInfo disconnectInfo;
+        int suggestedAction;
         boolean urisSet;
         Uri[] uris;
         synchronized (mLock) {
             state = mRegistrationState;
             attributes = mRegistrationAttributes;
             disconnectInfo = mLastDisconnectCause;
+            suggestedAction = mLastDisconnectSuggestedAction;
             urisSet = mUrisSet;
             uris = mUris;
         }
         switch (state) {
             case RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED: {
-                c.onDeregistered(disconnectInfo);
+                c.onDeregistered(disconnectInfo, suggestedAction);
                 break;
             }
             case RegistrationManager.REGISTRATION_STATE_REGISTERING: {
diff --git a/telephony/java/android/telephony/ims/stub/ImsSmsImplBase.java b/telephony/java/android/telephony/ims/stub/ImsSmsImplBase.java
index 66833d1..daab84e 100644
--- a/telephony/java/android/telephony/ims/stub/ImsSmsImplBase.java
+++ b/telephony/java/android/telephony/ims/stub/ImsSmsImplBase.java
@@ -171,6 +171,20 @@
     }
 
     /**
+     * This method will be triggered by the platform when memory becomes available to receive SMS
+     * after a memory full event. This method should be implemented by IMS providers to
+     * send RP-SMMA notification from SMS Relay Layer to server over IMS as per section 7.3.2 of
+     * TS 124.11. Once the RP-SMMA Notification is sent to the network. The network will deliver all
+     * the pending messages which failed due to Unavailability of Memory.
+     *
+     * @param token unique token generated in {@link ImsSmsDispatcher#onMemoryAvailable(void)} that
+     *  should be used when triggering callbacks for this specific message.
+     */
+    public void onMemoryAvailable(int token) {
+        // Base Implementation - Should be overridden
+    }
+
+    /**
      * This method will be triggered by the platform after
      * {@link #onSmsReceived(int, String, byte[])} has been called to deliver the result to the IMS
      * provider.
diff --git a/telephony/java/com/android/internal/telephony/ICarrierConfigLoader.aidl b/telephony/java/com/android/internal/telephony/ICarrierConfigLoader.aidl
index 89620ea..1788bda 100644
--- a/telephony/java/com/android/internal/telephony/ICarrierConfigLoader.aidl
+++ b/telephony/java/com/android/internal/telephony/ICarrierConfigLoader.aidl
@@ -38,4 +38,6 @@
 
     String getDefaultCarrierServicePackageName();
 
+    PersistableBundle getConfigSubsetForSubIdWithFeature(int subId, String callingPackage,
+                String callingFeatureId, in String[] carrierConfigs);
 }
diff --git a/telephony/java/com/android/internal/telephony/ISms.aidl b/telephony/java/com/android/internal/telephony/ISms.aidl
index 9ec3c67..0e23f36 100644
--- a/telephony/java/com/android/internal/telephony/ISms.aidl
+++ b/telephony/java/com/android/internal/telephony/ISms.aidl
@@ -530,6 +530,25 @@
             int subId, String callingPkg, String prefixes, in PendingIntent intent);
 
     /**
+     * set Memory Status in SmsStorageMonitor
+     *
+     * @param subId the subscription Id.
+     * @param callingPackage the package name of the calling app.
+     * @param isStorageAvailable sets StorageAvailable to false or true
+     *   for testing behaviour of SmsStorageMonitor
+     */
+    void setStorageMonitorMemoryStatusOverride(int subId, boolean isStorageAvailable);
+
+     /**
+     * reset Memory Status change made by TestApi setStorageMonitorMemoryStatusOverride
+     * in SmsStorageMonitor
+     *
+     * @param subId the subscription Id.
+     * @param callingPackage the package name of the calling app.
+     */
+    void clearStorageMonitorMemoryStatusOverride(int subId);
+
+    /**
      * Check if the destination is a possible premium short code.
      *
      * @param destAddress the destination address to test for possible short code
diff --git a/telephony/java/com/android/internal/telephony/ISmsImplBase.java b/telephony/java/com/android/internal/telephony/ISmsImplBase.java
index c361d5b..6864556 100644
--- a/telephony/java/com/android/internal/telephony/ISmsImplBase.java
+++ b/telephony/java/com/android/internal/telephony/ISmsImplBase.java
@@ -192,6 +192,16 @@
     }
 
     @Override
+    public void setStorageMonitorMemoryStatusOverride(int subId, boolean storageAvailable) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void clearStorageMonitorMemoryStatusOverride(int subId) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
     public int checkSmsShortCodeDestination(int subid, String callingPackage,
             String callingFeatureId, String destAddress, String countryIso) {
         throw new UnsupportedOperationException();
diff --git a/telephony/java/com/android/internal/telephony/ISub.aidl b/telephony/java/com/android/internal/telephony/ISub.aidl
index e9cea68..c5f6902 100644
--- a/telephony/java/com/android/internal/telephony/ISub.aidl
+++ b/telephony/java/com/android/internal/telephony/ISub.aidl
@@ -242,8 +242,6 @@
 
     int getDefaultSubId();
 
-    int clearSubInfo();
-
     int getPhoneId(int subId);
 
     /**
@@ -274,11 +272,6 @@
     boolean isSubscriptionEnabled(int subId);
 
     int getEnabledSubscriptionId(int slotIndex);
-    /**
-     * Get the SIM state for the slot index
-     * @return SIM state as the ordinal of IccCardConstants.State
-     */
-    int getSimStateForSlotIndex(int slotIndex);
 
     boolean isActiveSubId(int subId, String callingPackage, String callingFeatureId);
 
diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl
index 616ea50..9445d076 100644
--- a/telephony/java/com/android/internal/telephony/ITelephony.aidl
+++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl
@@ -2628,5 +2628,34 @@
       * {@code null} if the functionality is not supported.
       * @hide
       */
-      ComponentName getDefaultRespondViaMessageApplication(int subId, boolean updateIfNeeded);
+    ComponentName getDefaultRespondViaMessageApplication(int subId, boolean updateIfNeeded);
+
+    /**
+     * Get the SIM state for the logical SIM slot index.
+     *
+     * @param slotIndex Logical SIM slot index.
+     */
+    int getSimStateForSlotIndex(int slotIndex);
+
+    /**
+     * Set whether the radio is able to connect with null ciphering or integrity
+     * algorithms. This is a global setting and will apply to all active subscriptions
+     * and all new subscriptions after this.
+     *
+     * <p>Requires Permission:
+     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
+     *
+     * @param enabled when true, null  cipher and integrity algorithms are allowed.
+     * @hide
+     */
+    void setNullCipherAndIntegrityEnabled(boolean enabled);
+
+    /**
+    * Get whether the radio is able to connect with null ciphering or integrity
+    * algorithms. Note that this retrieves the phone-global preference and not
+    * the state of the radio.
+    *
+    * @hide
+    */
+    boolean isNullCipherAndIntegrityPreferenceEnabled();
 }
diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/BaseTest.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/BaseTest.kt
index c100a9c..a4609f7 100644
--- a/tests/FlickerTests/src/com/android/server/wm/flicker/BaseTest.kt
+++ b/tests/FlickerTests/src/com/android/server/wm/flicker/BaseTest.kt
@@ -174,14 +174,18 @@
 
     open fun cujCompleted() {
         entireScreenCovered()
-        navBarLayerIsVisibleAtStartAndEnd()
-        navBarWindowIsAlwaysVisible()
-        taskBarLayerIsVisibleAtStartAndEnd()
-        taskBarWindowIsAlwaysVisible()
         statusBarLayerIsVisibleAtStartAndEnd()
         statusBarLayerPositionAtStartAndEnd()
         statusBarWindowIsAlwaysVisible()
         visibleLayersShownMoreThanOneConsecutiveEntry()
         visibleWindowsShownMoreThanOneConsecutiveEntry()
+
+        if (flicker.scenario.isTablet) {
+            taskBarLayerIsVisibleAtStartAndEnd()
+            taskBarWindowIsAlwaysVisible()
+        } else {
+            navBarLayerIsVisibleAtStartAndEnd()
+            navBarWindowIsAlwaysVisible()
+        }
     }
 }
diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/ime/CloseImeWindowToAppTest.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/ime/CloseImeWindowToAppTest.kt
index afc5f65..ca4c6a3 100644
--- a/tests/FlickerTests/src/com/android/server/wm/flicker/ime/CloseImeWindowToAppTest.kt
+++ b/tests/FlickerTests/src/com/android/server/wm/flicker/ime/CloseImeWindowToAppTest.kt
@@ -106,7 +106,9 @@
     @IwTest(focusArea = "ime")
     override fun cujCompleted() {
         super.cujCompleted()
-        navBarLayerPositionAtStartAndEnd()
+        if (!flicker.scenario.isTablet) {
+            navBarLayerPositionAtStartAndEnd()
+        }
         imeLayerBecomesInvisible()
         imeAppLayerIsAlwaysVisible()
         imeAppWindowIsAlwaysVisible()
diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/ime/CloseImeWindowToHomeTest.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/ime/CloseImeWindowToHomeTest.kt
index aedf965..730c4f5 100644
--- a/tests/FlickerTests/src/com/android/server/wm/flicker/ime/CloseImeWindowToHomeTest.kt
+++ b/tests/FlickerTests/src/com/android/server/wm/flicker/ime/CloseImeWindowToHomeTest.kt
@@ -104,7 +104,9 @@
     @IwTest(focusArea = "ime")
     override fun cujCompleted() {
         super.cujCompleted()
-        navBarLayerPositionAtStartAndEnd()
+        if (!flicker.scenario.isTablet) {
+            navBarLayerPositionAtStartAndEnd()
+        }
         imeLayerBecomesInvisible()
         imeAppWindowBecomesInvisible()
         imeWindowBecomesInvisible()
diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/rotation/SeamlessAppRotationTest.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/rotation/SeamlessAppRotationTest.kt
index 54f38c3..2447474 100644
--- a/tests/FlickerTests/src/com/android/server/wm/flicker/rotation/SeamlessAppRotationTest.kt
+++ b/tests/FlickerTests/src/com/android/server/wm/flicker/rotation/SeamlessAppRotationTest.kt
@@ -213,6 +213,14 @@
             // not yet tablet compatible
             appLayerRotates()
             appLayerAlwaysVisible()
+            // not tablet compatible
+            navBarLayerIsVisibleAtStartAndEnd()
+            navBarWindowIsAlwaysVisible()
+        }
+
+        if (flicker.scenario.isTablet) {
+            taskBarLayerIsVisibleAtStartAndEnd()
+            taskBarWindowIsAlwaysVisible()
         }
 
         appWindowFullScreen()
@@ -223,10 +231,6 @@
         appLayerRotates_StartingPos()
         appLayerRotates_EndingPos()
         entireScreenCovered()
-        navBarLayerIsVisibleAtStartAndEnd()
-        navBarWindowIsAlwaysVisible()
-        taskBarLayerIsVisibleAtStartAndEnd()
-        taskBarWindowIsAlwaysVisible()
         visibleLayersShownMoreThanOneConsecutiveEntry()
         visibleWindowsShownMoreThanOneConsecutiveEntry()
     }
diff --git a/tests/utils/testutils/java/com/android/internal/util/test/BroadcastInterceptingContext.java b/tests/utils/testutils/java/com/android/internal/util/test/BroadcastInterceptingContext.java
index 133c176..cc3781a 100644
--- a/tests/utils/testutils/java/com/android/internal/util/test/BroadcastInterceptingContext.java
+++ b/tests/utils/testutils/java/com/android/internal/util/test/BroadcastInterceptingContext.java
@@ -246,6 +246,12 @@
     }
 
     @Override
+    public void sendBroadcastAsUser(Intent intent, UserHandle user,
+            String receiverPermission, Bundle options) {
+        sendBroadcast(intent);
+    }
+
+    @Override
     public void sendStickyBroadcast(Intent intent) {
         sendBroadcast(intent);
     }
diff --git a/tests/vcn/java/android/net/vcn/VcnConfigTest.java b/tests/vcn/java/android/net/vcn/VcnConfigTest.java
index 7ac51b7..b313c9f 100644
--- a/tests/vcn/java/android/net/vcn/VcnConfigTest.java
+++ b/tests/vcn/java/android/net/vcn/VcnConfigTest.java
@@ -16,7 +16,12 @@
 
 package android.net.vcn;
 
+import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
+import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
+
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
@@ -24,6 +29,7 @@
 import android.annotation.NonNull;
 import android.content.Context;
 import android.os.Parcel;
+import android.util.ArraySet;
 
 import androidx.test.filters.SmallTest;
 import androidx.test.runner.AndroidJUnit4;
@@ -42,19 +48,36 @@
     private static final Set<VcnGatewayConnectionConfig> GATEWAY_CONNECTION_CONFIGS =
             Collections.singleton(VcnGatewayConnectionConfigTest.buildTestConfig());
 
+    private static final Set<Integer> RESTRICTED_TRANSPORTS = new ArraySet<>();
+
+    static {
+        RESTRICTED_TRANSPORTS.add(TRANSPORT_WIFI);
+        RESTRICTED_TRANSPORTS.add(TRANSPORT_CELLULAR);
+    }
+
     private final Context mContext = mock(Context.class);
 
     // Public visibility for VcnManagementServiceTest
-    public static VcnConfig buildTestConfig(@NonNull Context context) {
+    public static VcnConfig buildTestConfig(
+            @NonNull Context context, Set<Integer> restrictedTransports) {
         VcnConfig.Builder builder = new VcnConfig.Builder(context);
 
         for (VcnGatewayConnectionConfig gatewayConnectionConfig : GATEWAY_CONNECTION_CONFIGS) {
             builder.addGatewayConnectionConfig(gatewayConnectionConfig);
         }
 
+        if (restrictedTransports != null) {
+            builder.setRestrictedUnderlyingNetworkTransports(restrictedTransports);
+        }
+
         return builder.build();
     }
 
+    // Public visibility for VcnManagementServiceTest
+    public static VcnConfig buildTestConfig(@NonNull Context context) {
+        return buildTestConfig(context, null);
+    }
+
     @Before
     public void setUp() throws Exception {
         doReturn(TEST_PACKAGE_NAME).when(mContext).getOpPackageName();
@@ -91,11 +114,25 @@
     }
 
     @Test
-    public void testBuilderAndGetters() {
+    public void testBuilderAndGettersDefaultValues() {
         final VcnConfig config = buildTestConfig(mContext);
 
         assertEquals(TEST_PACKAGE_NAME, config.getProvisioningPackageName());
         assertEquals(GATEWAY_CONNECTION_CONFIGS, config.getGatewayConnectionConfigs());
+        assertFalse(config.isTestModeProfile());
+        assertEquals(
+                Collections.singleton(TRANSPORT_WIFI),
+                config.getRestrictedUnderlyingNetworkTransports());
+    }
+
+    @Test
+    public void testBuilderAndGettersConfigRestrictedTransports() {
+        final VcnConfig config = buildTestConfig(mContext, RESTRICTED_TRANSPORTS);
+
+        assertEquals(TEST_PACKAGE_NAME, config.getProvisioningPackageName());
+        assertEquals(GATEWAY_CONNECTION_CONFIGS, config.getGatewayConnectionConfigs());
+        assertFalse(config.isTestModeProfile());
+        assertEquals(RESTRICTED_TRANSPORTS, config.getRestrictedUnderlyingNetworkTransports());
     }
 
     @Test
@@ -106,6 +143,24 @@
     }
 
     @Test
+    public void testPersistableBundleWithRestrictedTransports() {
+        final VcnConfig config = buildTestConfig(mContext, RESTRICTED_TRANSPORTS);
+
+        assertEquals(config, new VcnConfig(config.toPersistableBundle()));
+    }
+
+    @Test
+    public void testEqualityWithRestrictedTransports() {
+        final VcnConfig config = buildTestConfig(mContext, RESTRICTED_TRANSPORTS);
+        final VcnConfig configEqual = buildTestConfig(mContext, RESTRICTED_TRANSPORTS);
+        final VcnConfig configNotEqual =
+                buildTestConfig(mContext, Collections.singleton(TRANSPORT_WIFI));
+
+        assertEquals(config, configEqual);
+        assertNotEquals(config, configNotEqual);
+    }
+
+    @Test
     public void testParceling() {
         final VcnConfig config = buildTestConfig(mContext);
 
diff --git a/tests/vcn/java/android/net/vcn/VcnGatewayConnectionConfigTest.java b/tests/vcn/java/android/net/vcn/VcnGatewayConnectionConfigTest.java
index 2aef9ae..4040888 100644
--- a/tests/vcn/java/android/net/vcn/VcnGatewayConnectionConfigTest.java
+++ b/tests/vcn/java/android/net/vcn/VcnGatewayConnectionConfigTest.java
@@ -19,9 +19,11 @@
 import static android.net.ipsec.ike.IkeSessionParams.IKE_OPTION_MOBIKE;
 import static android.net.vcn.VcnGatewayConnectionConfig.DEFAULT_UNDERLYING_NETWORK_TEMPLATES;
 import static android.net.vcn.VcnGatewayConnectionConfig.UNDERLYING_NETWORK_TEMPLATES_KEY;
+import static android.net.vcn.VcnGatewayConnectionConfig.VCN_GATEWAY_OPTION_ENABLE_DATA_STALL_RECOVERY_WITH_MOBILITY;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertTrue;
@@ -42,7 +44,9 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
+import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
 @RunWith(AndroidJUnit4.class)
@@ -79,6 +83,9 @@
             };
     public static final int MAX_MTU = 1360;
 
+    private static final Set<Integer> GATEWAY_OPTIONS =
+            Collections.singleton(VCN_GATEWAY_OPTION_ENABLE_DATA_STALL_RECOVERY_WITH_MOBILITY);
+
     public static final IkeTunnelConnectionParams TUNNEL_CONNECTION_PARAMS =
             TunnelConnectionParamsUtilsTest.buildTestParams();
 
@@ -109,10 +116,16 @@
                 TUNNEL_CONNECTION_PARAMS);
     }
 
-    private static VcnGatewayConnectionConfig buildTestConfigWithExposedCaps(
-            VcnGatewayConnectionConfig.Builder builder, int... exposedCaps) {
+    private static VcnGatewayConnectionConfig buildTestConfigWithExposedCapsAndOptions(
+            VcnGatewayConnectionConfig.Builder builder,
+            Set<Integer> gatewayOptions,
+            int... exposedCaps) {
         builder.setRetryIntervalsMillis(RETRY_INTERVALS_MS).setMaxMtu(MAX_MTU);
 
+        for (int option : gatewayOptions) {
+            builder.addGatewayOption(option);
+        }
+
         for (int caps : exposedCaps) {
             builder.addExposedCapability(caps);
         }
@@ -120,11 +133,28 @@
         return builder.build();
     }
 
+    private static VcnGatewayConnectionConfig buildTestConfigWithExposedCaps(
+            VcnGatewayConnectionConfig.Builder builder, int... exposedCaps) {
+        return buildTestConfigWithExposedCapsAndOptions(
+                builder, Collections.emptySet(), exposedCaps);
+    }
+
     // Public for use in VcnGatewayConnectionTest
     public static VcnGatewayConnectionConfig buildTestConfigWithExposedCaps(int... exposedCaps) {
         return buildTestConfigWithExposedCaps(newBuilder(), exposedCaps);
     }
 
+    private static VcnGatewayConnectionConfig buildTestConfigWithGatewayOptions(
+            VcnGatewayConnectionConfig.Builder builder, Set<Integer> gatewayOptions) {
+        return buildTestConfigWithExposedCapsAndOptions(builder, gatewayOptions, EXPOSED_CAPS);
+    }
+
+    // Public for use in VcnGatewayConnectionTest
+    public static VcnGatewayConnectionConfig buildTestConfigWithGatewayOptions(
+            Set<Integer> gatewayOptions) {
+        return buildTestConfigWithExposedCapsAndOptions(newBuilder(), gatewayOptions, EXPOSED_CAPS);
+    }
+
     @Test
     public void testBuilderRequiresNonNullGatewayConnectionName() {
         try {
@@ -211,6 +241,15 @@
     }
 
     @Test
+    public void testBuilderRequiresValidOption() {
+        try {
+            newBuilder().addGatewayOption(-1);
+            fail("Expected exception due to the invalid VCN gateway option");
+        } catch (IllegalArgumentException e) {
+        }
+    }
+
+    @Test
     public void testBuilderAndGetters() {
         final VcnGatewayConnectionConfig config = buildTestConfig();
 
@@ -225,6 +264,20 @@
 
         assertArrayEquals(RETRY_INTERVALS_MS, config.getRetryIntervalsMillis());
         assertEquals(MAX_MTU, config.getMaxMtu());
+
+        assertFalse(
+                config.hasGatewayOption(
+                        VCN_GATEWAY_OPTION_ENABLE_DATA_STALL_RECOVERY_WITH_MOBILITY));
+    }
+
+    @Test
+    public void testBuilderAndGettersWithOptions() {
+        final VcnGatewayConnectionConfig config =
+                buildTestConfigWithGatewayOptions(GATEWAY_OPTIONS);
+
+        for (int option : GATEWAY_OPTIONS) {
+            assertTrue(config.hasGatewayOption(option));
+        }
     }
 
     @Test
@@ -235,6 +288,14 @@
     }
 
     @Test
+    public void testPersistableBundleWithOptions() {
+        final VcnGatewayConnectionConfig config =
+                buildTestConfigWithGatewayOptions(GATEWAY_OPTIONS);
+
+        assertEquals(config, new VcnGatewayConnectionConfig(config.toPersistableBundle()));
+    }
+
+    @Test
     public void testParsePersistableBundleWithoutVcnUnderlyingNetworkTemplates() {
         PersistableBundle configBundle = buildTestConfig().toPersistableBundle();
         configBundle.putPersistableBundle(UNDERLYING_NETWORK_TEMPLATES_KEY, null);
@@ -318,4 +379,27 @@
         assertNotEquals(UNDERLYING_NETWORK_TEMPLATES, networkTemplatesNotEqual);
         assertNotEquals(config, configNotEqual);
     }
+
+    private static VcnGatewayConnectionConfig buildConfigWithGatewayOptionsForEqualityTest(
+            Set<Integer> gatewayOptions) {
+        return buildTestConfigWithGatewayOptions(
+                new VcnGatewayConnectionConfig.Builder(
+                        "buildConfigWithGatewayOptionsForEqualityTest", TUNNEL_CONNECTION_PARAMS),
+                gatewayOptions);
+    }
+
+    @Test
+    public void testVcnGatewayOptionsEquality() throws Exception {
+        final VcnGatewayConnectionConfig config =
+                buildConfigWithGatewayOptionsForEqualityTest(GATEWAY_OPTIONS);
+
+        final VcnGatewayConnectionConfig configEqual =
+                buildConfigWithGatewayOptionsForEqualityTest(GATEWAY_OPTIONS);
+
+        final VcnGatewayConnectionConfig configNotEqual =
+                buildConfigWithGatewayOptionsForEqualityTest(Collections.emptySet());
+
+        assertEquals(config, configEqual);
+        assertNotEquals(config, configNotEqual);
+    }
 }
diff --git a/tests/vcn/java/com/android/server/VcnManagementServiceTest.java b/tests/vcn/java/com/android/server/VcnManagementServiceTest.java
index 258642ac..075bc5e 100644
--- a/tests/vcn/java/com/android/server/VcnManagementServiceTest.java
+++ b/tests/vcn/java/com/android/server/VcnManagementServiceTest.java
@@ -258,7 +258,7 @@
 
         doReturn(Collections.singleton(TRANSPORT_WIFI))
                 .when(mMockDeps)
-                .getRestrictedTransports(any(), any());
+                .getRestrictedTransports(any(), any(), any());
     }
 
 
@@ -1038,18 +1038,18 @@
                 new LinkProperties());
     }
 
-    private void checkGetRestrictedTransports(
+    private void checkGetRestrictedTransportsFromCarrierConfig(
             ParcelUuid subGrp,
             TelephonySubscriptionSnapshot lastSnapshot,
             Set<Integer> expectedTransports) {
         Set<Integer> result =
                 new VcnManagementService.Dependencies()
-                        .getRestrictedTransports(subGrp, lastSnapshot);
+                        .getRestrictedTransportsFromCarrierConfig(subGrp, lastSnapshot);
         assertEquals(expectedTransports, result);
     }
 
     @Test
-    public void testGetRestrictedTransports() {
+    public void testGetRestrictedTransportsFromCarrierConfig() {
         final Set<Integer> restrictedTransports = new ArraySet<>();
         restrictedTransports.add(TRANSPORT_CELLULAR);
         restrictedTransports.add(TRANSPORT_WIFI);
@@ -1065,11 +1065,12 @@
                 mock(TelephonySubscriptionSnapshot.class);
         doReturn(carrierConfig).when(lastSnapshot).getCarrierConfigForSubGrp(eq(TEST_UUID_2));
 
-        checkGetRestrictedTransports(TEST_UUID_2, lastSnapshot, restrictedTransports);
+        checkGetRestrictedTransportsFromCarrierConfig(
+                TEST_UUID_2, lastSnapshot, restrictedTransports);
     }
 
     @Test
-    public void testGetRestrictedTransports_noRestrictPolicyConfigured() {
+    public void testGetRestrictedTransportsFromCarrierConfig_noRestrictPolicyConfigured() {
         final Set<Integer> restrictedTransports = Collections.singleton(TRANSPORT_WIFI);
 
         final PersistableBundleWrapper carrierConfig =
@@ -1078,17 +1079,54 @@
                 mock(TelephonySubscriptionSnapshot.class);
         doReturn(carrierConfig).when(lastSnapshot).getCarrierConfigForSubGrp(eq(TEST_UUID_2));
 
-        checkGetRestrictedTransports(TEST_UUID_2, lastSnapshot, restrictedTransports);
+        checkGetRestrictedTransportsFromCarrierConfig(
+                TEST_UUID_2, lastSnapshot, restrictedTransports);
     }
 
     @Test
-    public void testGetRestrictedTransports_noCarrierConfig() {
+    public void testGetRestrictedTransportsFromCarrierConfig_noCarrierConfig() {
         final Set<Integer> restrictedTransports = Collections.singleton(TRANSPORT_WIFI);
 
         final TelephonySubscriptionSnapshot lastSnapshot =
                 mock(TelephonySubscriptionSnapshot.class);
 
-        checkGetRestrictedTransports(TEST_UUID_2, lastSnapshot, restrictedTransports);
+        checkGetRestrictedTransportsFromCarrierConfig(
+                TEST_UUID_2, lastSnapshot, restrictedTransports);
+    }
+
+    @Test
+    public void testGetRestrictedTransportsFromCarrierConfigAndVcnConfig() {
+        // Configure restricted transport in CarrierConfig
+        final Set<Integer> restrictedTransportInCarrierConfig =
+                Collections.singleton(TRANSPORT_WIFI);
+
+        PersistableBundle carrierConfigBundle = new PersistableBundle();
+        carrierConfigBundle.putIntArray(
+                VCN_RESTRICTED_TRANSPORTS_INT_ARRAY_KEY,
+                restrictedTransportInCarrierConfig.stream().mapToInt(i -> i).toArray());
+        final PersistableBundleWrapper carrierConfig =
+                new PersistableBundleWrapper(carrierConfigBundle);
+
+        final TelephonySubscriptionSnapshot lastSnapshot =
+                mock(TelephonySubscriptionSnapshot.class);
+        doReturn(carrierConfig).when(lastSnapshot).getCarrierConfigForSubGrp(eq(TEST_UUID_2));
+
+        // Configure restricted transport in VcnConfig
+        final Context mockContext = mock(Context.class);
+        doReturn(TEST_PACKAGE_NAME).when(mockContext).getOpPackageName();
+        final VcnConfig vcnConfig =
+                VcnConfigTest.buildTestConfig(
+                        mockContext, Collections.singleton(TRANSPORT_CELLULAR));
+
+        // Verifications
+        final Set<Integer> expectedTransports = new ArraySet<>();
+        expectedTransports.add(TRANSPORT_CELLULAR);
+        expectedTransports.add(TRANSPORT_WIFI);
+
+        Set<Integer> result =
+                new VcnManagementService.Dependencies()
+                        .getRestrictedTransports(TEST_UUID_2, lastSnapshot, vcnConfig);
+        assertEquals(expectedTransports, result);
     }
 
     private void checkGetUnderlyingNetworkPolicy(
@@ -1103,7 +1141,7 @@
         if (isTransportRestricted) {
             restrictedTransports.add(transportType);
         }
-        doReturn(restrictedTransports).when(mMockDeps).getRestrictedTransports(any(), any());
+        doReturn(restrictedTransports).when(mMockDeps).getRestrictedTransports(any(), any(), any());
 
         final VcnUnderlyingNetworkPolicy policy =
                 startVcnAndGetPolicyForTransport(
@@ -1201,7 +1239,7 @@
     public void testGetUnderlyingNetworkPolicyCell_restrictWifi() throws Exception {
         doReturn(Collections.singleton(TRANSPORT_WIFI))
                 .when(mMockDeps)
-                .getRestrictedTransports(any(), any());
+                .getRestrictedTransports(any(), any(), any());
 
         setupSubscriptionAndStartVcn(TEST_SUBSCRIPTION_ID, TEST_UUID_2, true /* isVcnActive */);
 
@@ -1344,6 +1382,23 @@
     }
 
     @Test
+    public void testVcnConfigChangeUpdatesPolicyListener() throws Exception {
+        setupActiveSubscription(TEST_UUID_2);
+
+        mVcnMgmtSvc.setVcnConfig(TEST_UUID_2, TEST_VCN_CONFIG, TEST_PACKAGE_NAME);
+        mVcnMgmtSvc.addVcnUnderlyingNetworkPolicyListener(mMockPolicyListener);
+
+        final Context mockContext = mock(Context.class);
+        doReturn(TEST_PACKAGE_NAME).when(mockContext).getOpPackageName();
+        final VcnConfig vcnConfig =
+                VcnConfigTest.buildTestConfig(
+                        mockContext, Collections.singleton(TRANSPORT_CELLULAR));
+        mVcnMgmtSvc.setVcnConfig(TEST_UUID_2, vcnConfig, TEST_PACKAGE_NAME);
+
+        verify(mMockPolicyListener).onPolicyChanged();
+    }
+
+    @Test
     public void testRemoveVcnUpdatesPolicyListener() throws Exception {
         setupActiveSubscription(TEST_UUID_2);
 
@@ -1375,7 +1430,7 @@
         setupActiveSubscription(TEST_UUID_2);
 
         mVcnMgmtSvc.setVcnConfig(TEST_UUID_2, TEST_VCN_CONFIG, TEST_PACKAGE_NAME);
-        mVcnMgmtSvc.addVcnUnderlyingNetworkPolicyListenerForTest(mMockPolicyListener);
+        mVcnMgmtSvc.addVcnUnderlyingNetworkPolicyListener(mMockPolicyListener);
 
         final TelephonySubscriptionSnapshot snapshot =
                 buildSubscriptionSnapshot(
diff --git a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectedStateTest.java b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectedStateTest.java
index 15d4f10..1c21a06 100644
--- a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectedStateTest.java
+++ b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectedStateTest.java
@@ -50,9 +50,11 @@
 
 import static java.util.Collections.singletonList;
 
+import android.net.ConnectivityDiagnosticsManager.DataStallReport;
 import android.net.ConnectivityManager;
 import android.net.LinkAddress;
 import android.net.LinkProperties;
+import android.net.Network;
 import android.net.NetworkAgent;
 import android.net.NetworkCapabilities;
 import android.net.ipsec.ike.ChildSaProposal;
@@ -63,10 +65,12 @@
 import android.net.vcn.VcnGatewayConnectionConfig;
 import android.net.vcn.VcnGatewayConnectionConfigTest;
 import android.net.vcn.VcnManager.VcnErrorCode;
+import android.os.PersistableBundle;
 
 import androidx.test.filters.SmallTest;
 import androidx.test.runner.AndroidJUnit4;
 
+import com.android.server.vcn.routeselection.UnderlyingNetworkRecord;
 import com.android.server.vcn.util.MtuUtils;
 
 import org.junit.Before;
@@ -88,6 +92,7 @@
 public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnectionTestBase {
     private VcnIkeSession mIkeSession;
     private VcnNetworkAgent mNetworkAgent;
+    private Network mVcnNetwork;
 
     @Before
     public void setUp() throws Exception {
@@ -98,6 +103,9 @@
                 .when(mDeps)
                 .newNetworkAgent(any(), any(), any(), any(), any(), any(), any(), any(), any());
 
+        mVcnNetwork = mock(Network.class);
+        doReturn(mVcnNetwork).when(mNetworkAgent).getNetwork();
+
         mGatewayConnection.setUnderlyingNetwork(TEST_UNDERLYING_NETWORK_RECORD_1);
 
         mIkeSession = mGatewayConnection.buildIkeSession(TEST_UNDERLYING_NETWORK_RECORD_1.network);
@@ -166,6 +174,56 @@
         assertEquals(mGatewayConnection.mConnectedState, mGatewayConnection.getCurrentState());
     }
 
+    private void verifyDataStallTriggersMigration(
+            UnderlyingNetworkRecord networkRecord,
+            Network networkWithDataStall,
+            boolean expectMobilityUpdate)
+            throws Exception {
+        mGatewayConnection.setUnderlyingNetwork(networkRecord);
+        triggerChildOpened();
+        mTestLooper.dispatchAll();
+
+        final DataStallReport report =
+                new DataStallReport(
+                        networkWithDataStall,
+                        1234 /* reportTimestamp */,
+                        1 /* detectionMethod */,
+                        new LinkProperties(),
+                        new NetworkCapabilities(),
+                        new PersistableBundle());
+
+        mGatewayConnection.getConnectivityDiagnosticsCallback().onDataStallSuspected(report);
+        mTestLooper.dispatchAll();
+
+        assertEquals(mGatewayConnection.mConnectedState, mGatewayConnection.getCurrentState());
+
+        if (expectMobilityUpdate) {
+            verify(mIkeSession).setNetwork(networkRecord.network);
+        } else {
+            verify(mIkeSession, never()).setNetwork(any(Network.class));
+        }
+    }
+
+    @Test
+    public void testDataStallTriggersMigration() throws Exception {
+        verifyDataStallTriggersMigration(
+                TEST_UNDERLYING_NETWORK_RECORD_1, mVcnNetwork, true /* expectMobilityUpdate */);
+    }
+
+    @Test
+    public void testDataStallWontTriggerMigrationWhenOnOtherNetwork() throws Exception {
+        verifyDataStallTriggersMigration(
+                TEST_UNDERLYING_NETWORK_RECORD_1,
+                mock(Network.class),
+                false /* expectMobilityUpdate */);
+    }
+
+    @Test
+    public void testDataStallWontTriggerMigrationWhenUnderlyingNetworkLost() throws Exception {
+        verifyDataStallTriggersMigration(
+                null /* networkRecord */, mock(Network.class), false /* expectMobilityUpdate */);
+    }
+
     private void verifyVcnTransformsApplied(
             VcnGatewayConnection vcnGatewayConnection, boolean expectForwardTransform)
             throws Exception {
diff --git a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionTest.java b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionTest.java
index 6a9a1e2..a4ee2de 100644
--- a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionTest.java
+++ b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionTest.java
@@ -24,6 +24,7 @@
 import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED;
 import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
 import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
+import static android.net.vcn.VcnGatewayConnectionConfig.VCN_GATEWAY_OPTION_ENABLE_DATA_STALL_RECOVERY_WITH_MOBILITY;
 
 import static com.android.server.vcn.VcnGatewayConnection.DUMMY_ADDR;
 import static com.android.server.vcn.VcnGatewayConnection.VcnChildSessionConfiguration;
@@ -34,20 +35,25 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyLong;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.CALLS_REAL_METHODS;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
+import android.net.ConnectivityDiagnosticsManager.ConnectivityDiagnosticsCallback;
 import android.net.IpSecManager;
 import android.net.LinkAddress;
 import android.net.LinkProperties;
 import android.net.Network;
 import android.net.NetworkCapabilities;
+import android.net.NetworkRequest;
 import android.net.TelephonyNetworkSpecifier;
+import android.net.vcn.VcnGatewayConnectionConfig;
 import android.net.vcn.VcnGatewayConnectionConfigTest;
 import android.net.vcn.VcnTransportInfo;
 import android.net.wifi.WifiInfo;
@@ -64,6 +70,7 @@
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
 
 import java.net.InetAddress;
 import java.util.Arrays;
@@ -71,7 +78,9 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.UUID;
+import java.util.concurrent.Executor;
 
 /** Tests for TelephonySubscriptionTracker */
 @RunWith(AndroidJUnit4.class)
@@ -287,5 +296,60 @@
         verify(vcnNetworkAgent).unregister();
 
         verifyWakeLockReleased();
+
+        verify(mConnDiagMgr)
+                .unregisterConnectivityDiagnosticsCallback(
+                        mGatewayConnection.getConnectivityDiagnosticsCallback());
+    }
+
+    private VcnGatewayConnection buildConnectionWithDataStallHandling(
+            boolean datatStallHandlingEnabled) throws Exception {
+        Set<Integer> options =
+                datatStallHandlingEnabled
+                        ? Collections.singleton(
+                                VCN_GATEWAY_OPTION_ENABLE_DATA_STALL_RECOVERY_WITH_MOBILITY)
+                        : Collections.emptySet();
+        final VcnGatewayConnectionConfig gatewayConfig =
+                VcnGatewayConnectionConfigTest.buildTestConfigWithGatewayOptions(options);
+        final VcnGatewayConnection gatewayConnection =
+                new VcnGatewayConnection(
+                        mVcnContext,
+                        TEST_SUB_GRP,
+                        TEST_SUBSCRIPTION_SNAPSHOT,
+                        gatewayConfig,
+                        mGatewayStatusCallback,
+                        true /* isMobileDataEnabled */,
+                        mDeps);
+        return gatewayConnection;
+    }
+
+    @Test
+    public void testDataStallHandlingEnabled() throws Exception {
+        final VcnGatewayConnection gatewayConnection =
+                buildConnectionWithDataStallHandling(true /* datatStallHandlingEnabled */);
+
+        final ArgumentCaptor<NetworkRequest> networkRequestCaptor =
+                ArgumentCaptor.forClass(NetworkRequest.class);
+        verify(mConnDiagMgr)
+                .registerConnectivityDiagnosticsCallback(
+                        networkRequestCaptor.capture(),
+                        any(Executor.class),
+                        eq(gatewayConnection.getConnectivityDiagnosticsCallback()));
+
+        final NetworkRequest nr = networkRequestCaptor.getValue();
+        final NetworkRequest expected =
+                new NetworkRequest.Builder().addTransportType(TRANSPORT_CELLULAR).build();
+        assertEquals(expected, nr);
+    }
+
+    @Test
+    public void testDataStallHandlingDisabled() throws Exception {
+        buildConnectionWithDataStallHandling(false /* datatStallHandlingEnabled */);
+
+        verify(mConnDiagMgr, never())
+                .registerConnectivityDiagnosticsCallback(
+                        any(NetworkRequest.class),
+                        any(Executor.class),
+                        any(ConnectivityDiagnosticsCallback.class));
     }
 }
diff --git a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionTestBase.java b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionTestBase.java
index 785bff1..7bafd24 100644
--- a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionTestBase.java
+++ b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionTestBase.java
@@ -35,6 +35,7 @@
 
 import android.annotation.NonNull;
 import android.content.Context;
+import android.net.ConnectivityDiagnosticsManager;
 import android.net.ConnectivityManager;
 import android.net.InetAddresses;
 import android.net.IpSecConfig;
@@ -157,6 +158,7 @@
 
     @NonNull protected final IpSecService mIpSecSvc;
     @NonNull protected final ConnectivityManager mConnMgr;
+    @NonNull protected final ConnectivityDiagnosticsManager mConnDiagMgr;
 
     @NonNull protected final IkeSessionConnectionInfo mIkeConnectionInfo;
     @NonNull protected final IkeSessionConfiguration mIkeSessionConfiguration;
@@ -186,6 +188,13 @@
         VcnTestUtils.setupSystemService(
                 mContext, mConnMgr, Context.CONNECTIVITY_SERVICE, ConnectivityManager.class);
 
+        mConnDiagMgr = mock(ConnectivityDiagnosticsManager.class);
+        VcnTestUtils.setupSystemService(
+                mContext,
+                mConnDiagMgr,
+                Context.CONNECTIVITY_DIAGNOSTICS_SERVICE,
+                ConnectivityDiagnosticsManager.class);
+
         mIkeConnectionInfo =
                 new IkeSessionConnectionInfo(TEST_ADDR, TEST_ADDR_2, mock(Network.class));
         mIkeSessionConfiguration = new IkeSessionConfiguration.Builder(mIkeConnectionInfo).build();
diff --git a/tools/aapt2/ApkInfo.proto b/tools/aapt2/ApkInfo.proto
index 80bdccb..b5ff71f 100644
--- a/tools/aapt2/ApkInfo.proto
+++ b/tools/aapt2/ApkInfo.proto
@@ -40,7 +40,8 @@
   PackageInfo package = 1;
   Application application = 2;
   UsesSdk uses_sdk = 3;
-  UsesConfiguration uses_configuration = 4;
+  // Previously: UsesConfiguration uses_configuration = 4;
+  reserved 4;
   SupportsScreen supports_screen = 5;
   SupportsInput supports_input = 6;
   LaunchableActivity launchable_activity = 7;
@@ -57,6 +58,8 @@
   repeated string locales = 17;
   repeated int32 densities = 18;
 
+  repeated UsesPackage uses_packages = 51;
+  repeated UsesConfiguration uses_configurations = 52;
   repeated FeatureGroup feature_groups = 53;
   repeated UsesPermission uses_permissions = 54;
   repeated Permission permissions = 55;
@@ -64,7 +67,6 @@
   repeated UsesStaticLibrary uses_static_libraries = 57;
   repeated UsesSdkLibrary uses_sdk_libraries = 58;
   repeated UsesNativeLibrary uses_native_libraries = 59;
-  repeated UsesPackage uses_packages = 51;
 
   repeated Metadata metadata = 62;
   repeated Property properties = 63;
diff --git a/tools/aapt2/cmd/Dump_test.cpp b/tools/aapt2/cmd/Dump_test.cpp
index b1c69cd..df35ebb 100644
--- a/tools/aapt2/cmd/Dump_test.cpp
+++ b/tools/aapt2/cmd/Dump_test.cpp
@@ -108,4 +108,21 @@
   ASSERT_EQ(output, expected);
 }
 
+TEST_F(DumpTest, DumpBadgingApkBuiltWithAaptAndTagsInWrongPlace) {
+  auto apk_path = file::BuildPath({android::base::GetExecutableDirectory(), "integration-tests",
+                                   "DumpTest", "built_with_aapt.apk"});
+  auto loaded_apk = LoadedApk::LoadApkFromPath(apk_path, &noop_diag);
+
+  std::string output;
+  DumpBadgingToString(loaded_apk.get(), &output, /* include_meta_data= */ false,
+                      /* only_permissions= */ false);
+
+  std::string expected;
+  auto expected_path =
+      file::BuildPath({android::base::GetExecutableDirectory(), "integration-tests", "DumpTest",
+                       "built_with_aapt_expected.txt"});
+  ::android::base::ReadFileToString(expected_path, &expected);
+  ASSERT_EQ(output, expected);
+}
+
 }  // namespace aapt
diff --git a/tools/aapt2/dump/DumpManifest.cpp b/tools/aapt2/dump/DumpManifest.cpp
index d60869a..d1957fb 100644
--- a/tools/aapt2/dump/DumpManifest.cpp
+++ b/tools/aapt2/dump/DumpManifest.cpp
@@ -223,7 +223,8 @@
     Element() = default;
     virtual ~Element() = default;
 
-    static std::unique_ptr<Element> Inflate(ManifestExtractor* extractor, xml::Element* el);
+    static std::unique_ptr<Element> Inflate(ManifestExtractor* extractor, xml::Element* el,
+                                            const std::string& parent_tag);
 
     /** Writes out the extracted contents of the element. */
     virtual void Print(text::Printer* printer) {
@@ -249,10 +250,15 @@
     }
 
     /** Retrieves the extracted xml element tag. */
-    const std::string tag() const {
+    const std::string& tag() const {
       return tag_;
     }
 
+    /** Whether this element has special Extract/Print/ToProto logic. */
+    bool is_featured() const {
+      return featured_;
+    }
+
    protected:
     ManifestExtractor* extractor() const {
       return extractor_;
@@ -394,6 +400,8 @@
               return &(*intValue->value);
             } else if (RawString* rawValue = ValueCast<RawString>(value)) {
               return &(*rawValue->value);
+            } else if (StyledString* styledStrValue = ValueCast<StyledString>(value)) {
+              return &(styledStrValue->value->value);
             } else if (FileReference* strValue = ValueCast<FileReference>(value)) {
               return &(*strValue->path);
             }
@@ -424,6 +432,7 @@
       ManifestExtractor* extractor_;
       std::vector<std::unique_ptr<Element>> children_;
       std::string tag_;
+      bool featured_ = false;
   };
 
   friend Element;
@@ -446,7 +455,7 @@
   bool DumpProto(pb::Badging* out_badging);
 
   /** Recursively visit the xml element tree and return a processed badging element tree. */
-  std::unique_ptr<Element> Visit(xml::Element* element);
+  std::unique_ptr<Element> Visit(xml::Element* element, const std::string& parent_tag);
 
   /** Resets target SDK to 0. */
   void ResetTargetSdk() {
@@ -485,7 +494,7 @@
   }
 
   /** Retrieves the current stack of parent during data extraction. */
-  const std::vector<Element*> parent_stack() const {
+  const std::vector<Element*>& parent_stack() const {
     return parent_stack_;
   }
 
@@ -533,8 +542,9 @@
   if (f(root)) {
     return root;
   }
-  for (auto& child : root->children()) {
-    if (auto b2 = FindElement(child.get(), f)) {
+  const auto& children = root->children();
+  for (auto it = children.rbegin(); it != children.rend(); ++it) {
+    if (auto b2 = FindElement(it->get(), f)) {
       return b2;
     }
   }
@@ -901,7 +911,7 @@
   }
 
   void ToProto(pb::Badging* out_badging) override {
-    auto out_configuration = out_badging->mutable_uses_configuration();
+    auto out_configuration = out_badging->add_uses_configurations();
     out_configuration->set_req_touch_screen(req_touch_screen);
     out_configuration->set_req_keyboard_type(req_keyboard_type);
     out_configuration->set_req_hard_keyboard(req_hard_keyboard);
@@ -1348,11 +1358,6 @@
   std::string impliedReason;
 
   void Extract(xml::Element* element) override {
-    const auto parent_stack = extractor()->parent_stack();
-    if (!extractor()->options_.only_permissions &&
-        (parent_stack.size() != 1 || !ElementCast<Manifest>(parent_stack[0]))) {
-      return;
-    }
     name = GetAttributeStringDefault(FindAttribute(element, NAME_ATTR), "");
     std::string feature =
         GetAttributeStringDefault(FindAttribute(element, REQUIRED_FEATURE_ATTR), "");
@@ -1477,11 +1482,6 @@
   const int32_t* maxSdkVersion = nullptr;
 
   void Extract(xml::Element* element) override {
-    const auto parent_stack = extractor()->parent_stack();
-    if (!extractor()->options_.only_permissions &&
-        (parent_stack.size() != 1 || !ElementCast<Manifest>(parent_stack[0]))) {
-      return;
-    }
     name = GetAttributeString(FindAttribute(element, NAME_ATTR));
     maxSdkVersion = GetAttributeInteger(FindAttribute(element, MAX_SDK_VERSION_ATTR));
 
@@ -1717,11 +1717,8 @@
   int required;
 
   void Extract(xml::Element* element) override {
-    auto parent_stack = extractor()->parent_stack();
-    if (parent_stack.size() > 0 && ElementCast<Application>(parent_stack[0])) {
-      name = GetAttributeStringDefault(FindAttribute(element, NAME_ATTR), "");
-      required = GetAttributeIntegerDefault(FindAttribute(element, REQUIRED_ATTR), 1);
-    }
+    name = GetAttributeStringDefault(FindAttribute(element, NAME_ATTR), "");
+    required = GetAttributeIntegerDefault(FindAttribute(element, REQUIRED_ATTR), 1);
   }
 
   void Print(text::Printer* printer) override {
@@ -1749,12 +1746,9 @@
   int versionMajor;
 
   void Extract(xml::Element* element) override {
-    auto parent_stack = extractor()->parent_stack();
-    if (parent_stack.size() > 0 && ElementCast<Application>(parent_stack[0])) {
-      name = GetAttributeStringDefault(FindAttribute(element, NAME_ATTR), "");
-      version = GetAttributeIntegerDefault(FindAttribute(element, VERSION_ATTR), 0);
-      versionMajor = GetAttributeIntegerDefault(FindAttribute(element, VERSION_MAJOR_ATTR), 0);
-    }
+    name = GetAttributeStringDefault(FindAttribute(element, NAME_ATTR), "");
+    version = GetAttributeIntegerDefault(FindAttribute(element, VERSION_ATTR), 0);
+    versionMajor = GetAttributeIntegerDefault(FindAttribute(element, VERSION_MAJOR_ATTR), 0);
   }
 
   void Print(text::Printer* printer) override {
@@ -1781,13 +1775,10 @@
   std::vector<std::string> certDigests;
 
   void Extract(xml::Element* element) override {
-    auto parent_stack = extractor()->parent_stack();
-    if (parent_stack.size() > 0 && ElementCast<Application>(parent_stack[0])) {
-      name = GetAttributeStringDefault(FindAttribute(element, NAME_ATTR), "");
-      version = GetAttributeIntegerDefault(FindAttribute(element, VERSION_ATTR), 0);
-      versionMajor = GetAttributeIntegerDefault(FindAttribute(element, VERSION_MAJOR_ATTR), 0);
-      AddCertDigest(element);
-    }
+    name = GetAttributeStringDefault(FindAttribute(element, NAME_ATTR), "");
+    version = GetAttributeIntegerDefault(FindAttribute(element, VERSION_ATTR), 0);
+    versionMajor = GetAttributeIntegerDefault(FindAttribute(element, VERSION_MAJOR_ATTR), 0);
+    AddCertDigest(element);
   }
 
   void AddCertDigest(xml::Element* element) {
@@ -1829,11 +1820,8 @@
   int versionMajor;
 
   void Extract(xml::Element* element) override {
-    auto parent_stack = extractor()->parent_stack();
-    if (parent_stack.size() > 0 && ElementCast<Application>(parent_stack[0])) {
-      name = GetAttributeStringDefault(FindAttribute(element, NAME_ATTR), "");
-      versionMajor = GetAttributeIntegerDefault(FindAttribute(element, VERSION_MAJOR_ATTR), 0);
-    }
+    name = GetAttributeStringDefault(FindAttribute(element, NAME_ATTR), "");
+    versionMajor = GetAttributeIntegerDefault(FindAttribute(element, VERSION_MAJOR_ATTR), 0);
   }
 
   void Print(text::Printer* printer) override {
@@ -1857,12 +1845,9 @@
   std::vector<std::string> certDigests;
 
   void Extract(xml::Element* element) override {
-    auto parent_stack = extractor()->parent_stack();
-    if (parent_stack.size() > 0 && ElementCast<Application>(parent_stack[0])) {
-      name = GetAttributeStringDefault(FindAttribute(element, NAME_ATTR), "");
-      versionMajor = GetAttributeIntegerDefault(FindAttribute(element, VERSION_MAJOR_ATTR), 0);
-      AddCertDigest(element);
-    }
+    name = GetAttributeStringDefault(FindAttribute(element, NAME_ATTR), "");
+    versionMajor = GetAttributeIntegerDefault(FindAttribute(element, VERSION_MAJOR_ATTR), 0);
+    AddCertDigest(element);
   }
 
   void AddCertDigest(xml::Element* element) {
@@ -1902,11 +1887,8 @@
   int required;
 
   void Extract(xml::Element* element) override {
-    auto parent_stack = extractor()->parent_stack();
-    if (parent_stack.size() > 0 && ElementCast<Application>(parent_stack[0])) {
-      name = GetAttributeStringDefault(FindAttribute(element, NAME_ATTR), "");
-      required = GetAttributeIntegerDefault(FindAttribute(element, REQUIRED_ATTR), 1);
-    }
+    name = GetAttributeStringDefault(FindAttribute(element, NAME_ATTR), "");
+    required = GetAttributeIntegerDefault(FindAttribute(element, REQUIRED_ATTR), 1);
   }
 
   void Print(text::Printer* printer) override {
@@ -2251,14 +2233,11 @@
   std::vector<std::string> certDigests;
 
   void Extract(xml::Element* element) override {
-    auto parent_stack = extractor()->parent_stack();
-    if (parent_stack.size() > 0 && ElementCast<Application>(parent_stack[0])) {
-      packageType = GetAttributeString(FindAttribute(element, PACKAGE_TYPE_ATTR));
-      name = GetAttributeString(FindAttribute(element, NAME_ATTR));
-      version = GetAttributeIntegerDefault(FindAttribute(element, VERSION_ATTR), 0);
-      versionMajor = GetAttributeIntegerDefault(FindAttribute(element, VERSION_MAJOR_ATTR), 0);
-      AddCertDigest(element);
-    }
+    packageType = GetAttributeString(FindAttribute(element, PACKAGE_TYPE_ATTR));
+    name = GetAttributeString(FindAttribute(element, NAME_ATTR));
+    version = GetAttributeIntegerDefault(FindAttribute(element, VERSION_ATTR), 0);
+    versionMajor = GetAttributeIntegerDefault(FindAttribute(element, VERSION_MAJOR_ATTR), 0);
+    AddCertDigest(element);
   }
 
   void AddCertDigest(xml::Element* element) {
@@ -2480,7 +2459,7 @@
   // Print only the <uses-permission>, <uses-permission-sdk23>, and <permission> elements if
   // printing only permission elements is requested
   if (options_.only_permissions) {
-    root_element_ = ManifestExtractor::Element::Inflate(this, element);
+    root_element_ = ManifestExtractor::Element::Inflate(this, element, "");
 
     if (auto manifest = ElementCast<Manifest>(root_element_.get())) {
       manifest->only_package_name = true;
@@ -2489,7 +2468,7 @@
         if (child->name == "uses-permission" || child->name == "uses-permission-sdk-23"
             || child->name == "permission") {
           // Inflate the element and its descendants
-          auto permission_element = Visit(child);
+          auto permission_element = Visit(child, "manifest");
           manifest->AddChild(permission_element);
         }
       }
@@ -2528,7 +2507,7 @@
   }
 
   // Extract badging information
-  root_element_ = Visit(element);
+  root_element_ = Visit(element, "");
 
   // Filter out all "uses-sdk" tags besides the very last tag. The android runtime only uses the
   // attribute values from the last defined tag.
@@ -2683,7 +2662,7 @@
                            (meta_data->name == "android.nfc.cardemulation.off_host_apdu_service" &&
                             offhost_apdu_action)) {
                          // Attempt to load the resource file
-                         if (!meta_data->resource.empty()) {
+                         if (meta_data->resource.empty()) {
                            return;
                          }
                          auto resource = this->apk_->LoadXml(meta_data->resource, diag);
@@ -2878,58 +2857,66 @@
   return true;
 }
 
+template <typename T>
+constexpr const char* GetExpectedTagForType() {
+  // This array does not appear at runtime, as GetExpectedTagForType function is used by compiler
+  // to inject proper 'expected_tag' into ElementCast.
+  std::array<std::pair<const char*, bool>, 37> tags = {
+      std::make_pair("action", std::is_same<Action, T>::value),
+      std::make_pair("activity", std::is_same<Activity, T>::value),
+      std::make_pair("additional-certificate", std::is_same<AdditionalCertificate, T>::value),
+      std::make_pair("application", std::is_same<Application, T>::value),
+      std::make_pair("category", std::is_same<Category, T>::value),
+      std::make_pair("compatible-screens", std::is_same<CompatibleScreens, T>::value),
+      std::make_pair("feature-group", std::is_same<FeatureGroup, T>::value),
+      std::make_pair("input-type", std::is_same<InputType, T>::value),
+      std::make_pair("intent-filter", std::is_same<IntentFilter, T>::value),
+      std::make_pair("meta-data", std::is_same<MetaData, T>::value),
+      std::make_pair("manifest", std::is_same<Manifest, T>::value),
+      std::make_pair("original-package", std::is_same<OriginalPackage, T>::value),
+      std::make_pair("overlay", std::is_same<Overlay, T>::value),
+      std::make_pair("package-verifier", std::is_same<PackageVerifier, T>::value),
+      std::make_pair("permission", std::is_same<Permission, T>::value),
+      std::make_pair("property", std::is_same<Property, T>::value),
+      std::make_pair("provider", std::is_same<Provider, T>::value),
+      std::make_pair("receiver", std::is_same<Receiver, T>::value),
+      std::make_pair("required-feature", std::is_same<RequiredFeature, T>::value),
+      std::make_pair("required-not-feature", std::is_same<RequiredNotFeature, T>::value),
+      std::make_pair("screen", std::is_same<Screen, T>::value),
+      std::make_pair("service", std::is_same<Service, T>::value),
+      std::make_pair("sdk-library", std::is_same<SdkLibrary, T>::value),
+      std::make_pair("static-library", std::is_same<StaticLibrary, T>::value),
+      std::make_pair("supports-gl-texture", std::is_same<SupportsGlTexture, T>::value),
+      std::make_pair("supports-input", std::is_same<SupportsInput, T>::value),
+      std::make_pair("supports-screens", std::is_same<SupportsScreen, T>::value),
+      std::make_pair("uses-configuration", std::is_same<UsesConfiguarion, T>::value),
+      std::make_pair("uses-feature", std::is_same<UsesFeature, T>::value),
+      std::make_pair("uses-library", std::is_same<UsesLibrary, T>::value),
+      std::make_pair("uses-native-library", std::is_same<UsesNativeLibrary, T>::value),
+      std::make_pair("uses-package", std::is_same<UsesPackage, T>::value),
+      std::make_pair("uses-permission", std::is_same<UsesPermission, T>::value),
+      std::make_pair("uses-permission-sdk-23", std::is_same<UsesPermissionSdk23, T>::value),
+      std::make_pair("uses-sdk", std::is_same<UsesSdkBadging, T>::value),
+      std::make_pair("uses-sdk-library", std::is_same<UsesSdkLibrary, T>::value),
+      std::make_pair("uses-static-library", std::is_same<UsesStaticLibrary, T>::value),
+  };
+  for (const auto& pair : tags) {
+    if (pair.second) {
+      return pair.first;
+    }
+  }
+  return nullptr;
+}
+
 /**
  * Returns the element casted to the type if the element is of that type. Otherwise, returns a null
  * pointer.
  **/
 template<typename T>
 T* ElementCast(ManifestExtractor::Element* element) {
-  if (element == nullptr) {
-    return nullptr;
-  }
-
-  const std::unordered_map<std::string, bool> kTagCheck = {
-      {"action", std::is_base_of<Action, T>::value},
-      {"activity", std::is_base_of<Activity, T>::value},
-      {"additional-certificate", std::is_base_of<AdditionalCertificate, T>::value},
-      {"application", std::is_base_of<Application, T>::value},
-      {"category", std::is_base_of<Category, T>::value},
-      {"compatible-screens", std::is_base_of<CompatibleScreens, T>::value},
-      {"feature-group", std::is_base_of<FeatureGroup, T>::value},
-      {"input-type", std::is_base_of<InputType, T>::value},
-      {"intent-filter", std::is_base_of<IntentFilter, T>::value},
-      {"meta-data", std::is_base_of<MetaData, T>::value},
-      {"manifest", std::is_base_of<Manifest, T>::value},
-      {"original-package", std::is_base_of<OriginalPackage, T>::value},
-      {"overlay", std::is_base_of<Overlay, T>::value},
-      {"package-verifier", std::is_base_of<PackageVerifier, T>::value},
-      {"permission", std::is_base_of<Permission, T>::value},
-      {"property", std::is_base_of<Property, T>::value},
-      {"provider", std::is_base_of<Provider, T>::value},
-      {"receiver", std::is_base_of<Receiver, T>::value},
-      {"required-feature", std::is_base_of<RequiredFeature, T>::value},
-      {"required-not-feature", std::is_base_of<RequiredNotFeature, T>::value},
-      {"screen", std::is_base_of<Screen, T>::value},
-      {"service", std::is_base_of<Service, T>::value},
-      {"sdk-library", std::is_base_of<SdkLibrary, T>::value},
-      {"static-library", std::is_base_of<StaticLibrary, T>::value},
-      {"supports-gl-texture", std::is_base_of<SupportsGlTexture, T>::value},
-      {"supports-input", std::is_base_of<SupportsInput, T>::value},
-      {"supports-screens", std::is_base_of<SupportsScreen, T>::value},
-      {"uses-configuration", std::is_base_of<UsesConfiguarion, T>::value},
-      {"uses-feature", std::is_base_of<UsesFeature, T>::value},
-      {"uses-library", std::is_base_of<UsesLibrary, T>::value},
-      {"uses-native-library", std::is_base_of<UsesNativeLibrary, T>::value},
-      {"uses-package", std::is_base_of<UsesPackage, T>::value},
-      {"uses-permission", std::is_base_of<UsesPermission, T>::value},
-      {"uses-permission-sdk-23", std::is_base_of<UsesPermissionSdk23, T>::value},
-      {"uses-sdk", std::is_base_of<UsesSdkBadging, T>::value},
-      {"uses-sdk-library", std::is_base_of<UsesSdkLibrary, T>::value},
-      {"uses-static-library", std::is_base_of<UsesStaticLibrary, T>::value},
-  };
-
-  auto check = kTagCheck.find(element->tag());
-  if (check != kTagCheck.end() && check->second) {
+  constexpr const char* expected_tag = GetExpectedTagForType<T>();
+  if (element != nullptr && expected_tag != nullptr && element->is_featured() &&
+      element->tag() == expected_tag) {
     return static_cast<T*>(element);
   }
   return nullptr;
@@ -2941,9 +2928,9 @@
 }
 
 std::unique_ptr<ManifestExtractor::Element> ManifestExtractor::Element::Inflate(
-    ManifestExtractor* extractor, xml::Element* el) {
-  const std::unordered_map<std::string,
-                           std::function<std::unique_ptr<ManifestExtractor::Element>()>>
+    ManifestExtractor* extractor, xml::Element* el, const std::string& parent_tag) {
+  static const std::unordered_map<std::string_view,
+                                  std::function<std::unique_ptr<ManifestExtractor::Element>()>>
       kTagCheck = {
           {"action", &CreateType<Action>},
           {"activity", &CreateType<Activity>},
@@ -2983,12 +2970,71 @@
           {"uses-sdk-library", &CreateType<UsesSdkLibrary>},
           {"uses-static-library", &CreateType<UsesStaticLibrary>},
       };
-
+  static constexpr std::array<std::pair<std::string_view, std::string_view>, 53>
+      kValidChildParentTags = {
+          std::make_pair("action", "intent-filter"),
+          std::make_pair("activity", "application"),
+          std::make_pair("additional-certificate", "uses-package"),
+          std::make_pair("additional-certificate", "uses-static-library"),
+          std::make_pair("application", "manifest"),
+          std::make_pair("category", "intent-filter"),
+          std::make_pair("compatible-screens", "manifest"),
+          std::make_pair("feature-group", "manifest"),
+          std::make_pair("input-type", "supports-input"),
+          std::make_pair("intent-filter", "activity"),
+          std::make_pair("intent-filter", "activity-alias"),
+          std::make_pair("intent-filter", "service"),
+          std::make_pair("intent-filter", "receiver"),
+          std::make_pair("intent-filter", "provider"),
+          std::make_pair("manifest", ""),
+          std::make_pair("meta-data", "activity"),
+          std::make_pair("meta-data", "activity-alias"),
+          std::make_pair("meta-data", "application"),
+          std::make_pair("meta-data", "service"),
+          std::make_pair("meta-data", "receiver"),
+          std::make_pair("meta-data", "provider"),
+          std::make_pair("original-package", "manifest"),
+          std::make_pair("overlay", "manifest"),
+          std::make_pair("package-verifier", "manifest"),
+          std::make_pair("permission", "manifest"),
+          std::make_pair("property", "activity"),
+          std::make_pair("property", "activity-alias"),
+          std::make_pair("property", "application"),
+          std::make_pair("property", "service"),
+          std::make_pair("property", "receiver"),
+          std::make_pair("property", "provider"),
+          std::make_pair("provider", "application"),
+          std::make_pair("receiver", "application"),
+          std::make_pair("required-feature", "uses-permission"),
+          std::make_pair("required-not-feature", "uses-permission"),
+          std::make_pair("screen", "compatible-screens"),
+          std::make_pair("service", "application"),
+          std::make_pair("sdk-library", "application"),
+          std::make_pair("static-library", "application"),
+          std::make_pair("supports-gl-texture", "manifest"),
+          std::make_pair("supports-input", "manifest"),
+          std::make_pair("supports-screens", "manifest"),
+          std::make_pair("uses-configuration", "manifest"),
+          std::make_pair("uses-feature", "feature-group"),
+          std::make_pair("uses-feature", "manifest"),
+          std::make_pair("uses-library", "application"),
+          std::make_pair("uses-native-library", "application"),
+          std::make_pair("uses-package", "application"),
+          std::make_pair("uses-permission", "manifest"),
+          std::make_pair("uses-permission-sdk-23", "manifest"),
+          std::make_pair("uses-sdk", "manifest"),
+          std::make_pair("uses-sdk-library", "application"),
+          std::make_pair("uses-static-library", "application"),
+      };
+  bool is_valid_tag = std::find(kValidChildParentTags.begin(), kValidChildParentTags.end(),
+                                std::make_pair<std::string_view, std::string_view>(
+                                    el->name, parent_tag)) != kValidChildParentTags.end();
   // Attempt to map the xml tag to a element inflater
   std::unique_ptr<ManifestExtractor::Element> element;
   auto check = kTagCheck.find(el->name);
-  if (check != kTagCheck.end()) {
+  if (check != kTagCheck.end() && is_valid_tag) {
     element = check->second();
+    element->featured_ = true;
   } else {
     element = util::make_unique<ManifestExtractor::Element>();
   }
@@ -2999,13 +3045,14 @@
   return element;
 }
 
-std::unique_ptr<ManifestExtractor::Element> ManifestExtractor::Visit(xml::Element* el) {
-  auto element = ManifestExtractor::Element::Inflate(this, el);
+std::unique_ptr<ManifestExtractor::Element> ManifestExtractor::Visit(
+    xml::Element* el, const std::string& parent_tag) {
+  auto element = ManifestExtractor::Element::Inflate(this, el, parent_tag);
   parent_stack_.insert(parent_stack_.begin(), element.get());
 
   // Process the element and recursively visit the children
   for (xml::Element* child : el->GetChildElements()) {
-    auto v = Visit(child);
+    auto v = Visit(child, el->name);
     element->AddChild(v);
   }
 
diff --git a/tools/aapt2/integration-tests/DumpTest/built_with_aapt.apk b/tools/aapt2/integration-tests/DumpTest/built_with_aapt.apk
new file mode 100644
index 0000000..090ebe56
--- /dev/null
+++ b/tools/aapt2/integration-tests/DumpTest/built_with_aapt.apk
Binary files differ
diff --git a/tools/aapt2/integration-tests/DumpTest/built_with_aapt_expected.txt b/tools/aapt2/integration-tests/DumpTest/built_with_aapt_expected.txt
new file mode 100644
index 0000000..cc0b3bf
--- /dev/null
+++ b/tools/aapt2/integration-tests/DumpTest/built_with_aapt_expected.txt
@@ -0,0 +1,11 @@
+package: name='com.aapt.app' versionCode='222' versionName='222' platformBuildVersionName='12' platformBuildVersionCode='32' compileSdkVersion='32' compileSdkVersionCodename='12'
+sdkVersion:'22'
+targetSdkVersion:'32'
+application: label='App' icon=''
+feature-group: label=''
+  uses-feature: name='android.hardware.faketouch'
+  uses-implied-feature: name='android.hardware.faketouch' reason='default feature for all apps'
+supports-screens: 'small' 'normal' 'large' 'xlarge'
+supports-any-density: 'true'
+locales:
+densities:
diff --git a/tools/aapt2/integration-tests/DumpTest/components_expected.txt b/tools/aapt2/integration-tests/DumpTest/components_expected.txt
index 79b6706..9c81fb8 100644
--- a/tools/aapt2/integration-tests/DumpTest/components_expected.txt
+++ b/tools/aapt2/integration-tests/DumpTest/components_expected.txt
@@ -36,6 +36,7 @@
 provides-component:'wallpaper'
 provides-component:'accessibility'
 provides-component:'print-service'
+provides-component:'payment'
 provides-component:'search'
 provides-component:'document-provider'
 provides-component:'notification-listener'
diff --git a/tools/aapt2/integration-tests/DumpTest/components_expected_proto.txt b/tools/aapt2/integration-tests/DumpTest/components_expected_proto.txt
index 4aed4af..d866479 100644
--- a/tools/aapt2/integration-tests/DumpTest/components_expected_proto.txt
+++ b/tools/aapt2/integration-tests/DumpTest/components_expected_proto.txt
@@ -40,13 +40,6 @@
     min_sdk_version: 21
     target_sdk_version: 31
   }
-  uses_configuration {
-    req_touch_screen: 3
-    req_keyboard_type: 2
-    req_hard_keyboard: -1
-    req_navigation: 3
-    req_five_way_nav: -1
-  }
   supports_screen {
     screens: NORMAL
     screens: LARGE
@@ -87,6 +80,7 @@
     provided_components: "wallpaper"
     provided_components: "accessibility"
     provided_components: "print-service"
+    provided_components: "payment"
     provided_components: "search"
     provided_components: "document-provider"
     provided_components: "notification-listener"
@@ -101,6 +95,13 @@
   densities: 480
   densities: 640
   densities: 65534
+  uses_configurations {
+    req_touch_screen: 3
+    req_keyboard_type: 2
+    req_hard_keyboard: -1
+    req_navigation: 3
+    req_five_way_nav: -1
+  }
   feature_groups {
     features {
       name: "android.hardware.bluetooth"
diff --git a/tools/aapt2/integration-tests/DumpTest/components_full_proto.txt b/tools/aapt2/integration-tests/DumpTest/components_full_proto.txt
index c783f47..6da6fc6 100644
--- a/tools/aapt2/integration-tests/DumpTest/components_full_proto.txt
+++ b/tools/aapt2/integration-tests/DumpTest/components_full_proto.txt
@@ -40,13 +40,6 @@
     min_sdk_version: 21
     target_sdk_version: 31
   }
-  uses_configuration {
-    req_touch_screen: 3
-    req_keyboard_type: 2
-    req_hard_keyboard: -1
-    req_navigation: 3
-    req_five_way_nav: -1
-  }
   supports_screen {
     screens: NORMAL
     screens: LARGE
@@ -87,6 +80,7 @@
     provided_components: "wallpaper"
     provided_components: "accessibility"
     provided_components: "print-service"
+    provided_components: "payment"
     provided_components: "search"
     provided_components: "document-provider"
     provided_components: "notification-listener"
@@ -101,6 +95,13 @@
   densities: 480
   densities: 640
   densities: 65534
+  uses_configurations {
+    req_touch_screen: 3
+    req_keyboard_type: 2
+    req_hard_keyboard: -1
+    req_navigation: 3
+    req_five_way_nav: -1
+  }
   feature_groups {
     features {
       name: "android.hardware.bluetooth"
diff --git a/tools/lint/framework/Android.bp b/tools/lint/framework/Android.bp
index 7f27e8a..b752503 100644
--- a/tools/lint/framework/Android.bp
+++ b/tools/lint/framework/Android.bp
@@ -31,8 +31,6 @@
     ],
     static_libs: [
         "AndroidCommonLint",
-        // TODO: remove once b/236558918 is resolved and the below checks actually run globally
-        "AndroidGlobalLintChecker",
     ],
     kotlincflags: ["-Xjvm-default=all"],
 }
diff --git a/tools/lint/framework/checks/src/main/java/com/google/android/lint/AndroidFrameworkIssueRegistry.kt b/tools/lint/framework/checks/src/main/java/com/google/android/lint/AndroidFrameworkIssueRegistry.kt
index c5cf0fb..423a684 100644
--- a/tools/lint/framework/checks/src/main/java/com/google/android/lint/AndroidFrameworkIssueRegistry.kt
+++ b/tools/lint/framework/checks/src/main/java/com/google/android/lint/AndroidFrameworkIssueRegistry.kt
@@ -19,9 +19,6 @@
 import com.android.tools.lint.client.api.IssueRegistry
 import com.android.tools.lint.client.api.Vendor
 import com.android.tools.lint.detector.api.CURRENT_API
-import com.google.android.lint.aidl.EnforcePermissionDetector
-import com.google.android.lint.aidl.EnforcePermissionHelperDetector
-import com.google.android.lint.aidl.SimpleManualPermissionEnforcementDetector
 import com.google.android.lint.parcel.SaferParcelChecker
 import com.google.auto.service.AutoService
 
@@ -37,10 +34,6 @@
         CallingIdentityTokenDetector.ISSUE_CLEAR_IDENTITY_CALL_NOT_FOLLOWED_BY_TRY_FINALLY,
         CallingIdentityTokenDetector.ISSUE_RESULT_OF_CLEAR_IDENTITY_CALL_NOT_STORED_IN_VARIABLE,
         CallingSettingsNonUserGetterMethodsDetector.ISSUE_NON_USER_GETTER_CALLED,
-        EnforcePermissionDetector.ISSUE_MISSING_ENFORCE_PERMISSION,
-        EnforcePermissionDetector.ISSUE_MISMATCHING_ENFORCE_PERMISSION,
-        EnforcePermissionHelperDetector.ISSUE_ENFORCE_PERMISSION_HELPER,
-        SimpleManualPermissionEnforcementDetector.ISSUE_SIMPLE_MANUAL_PERMISSION_ENFORCEMENT,
         SaferParcelChecker.ISSUE_UNSAFE_API_USAGE,
         PackageVisibilityDetector.ISSUE_PACKAGE_NAME_NO_PACKAGE_VISIBILITY_FILTERS,
         RegisterReceiverFlagDetector.ISSUE_RECEIVER_EXPORTED_FLAG,
diff --git a/tools/lint/global/checks/src/main/java/com/google/android/lint/aidl/EnforcePermissionDetector.kt b/tools/lint/global/checks/src/main/java/com/google/android/lint/aidl/EnforcePermissionDetector.kt
index bba819c..2665b3c 100644
--- a/tools/lint/global/checks/src/main/java/com/google/android/lint/aidl/EnforcePermissionDetector.kt
+++ b/tools/lint/global/checks/src/main/java/com/google/android/lint/aidl/EnforcePermissionDetector.kt
@@ -31,10 +31,11 @@
 import com.android.tools.lint.detector.api.Severity
 import com.android.tools.lint.detector.api.SourceCodeScanner
 import com.intellij.psi.PsiAnnotation
+import com.intellij.psi.PsiArrayInitializerMemberValue
 import com.intellij.psi.PsiClass
+import com.intellij.psi.PsiElement
 import com.intellij.psi.PsiMethod
 import org.jetbrains.uast.UAnnotation
-import org.jetbrains.uast.UClass
 import org.jetbrains.uast.UElement
 import org.jetbrains.uast.UMethod
 
@@ -65,6 +66,12 @@
         return listOf(UAnnotation::class.java)
     }
 
+    private fun annotationValueGetChildren(elem: PsiElement): Array<PsiElement> {
+        if (elem is PsiArrayInitializerMemberValue)
+            return elem.getInitializers().map { it as PsiElement }.toTypedArray()
+        return elem.getChildren()
+    }
+
     private fun areAnnotationsEquivalent(
         context: JavaContext,
         anno1: PsiAnnotation,
@@ -82,18 +89,28 @@
             if (attr1[i].name != attr2[i].name) {
                 return false
             }
-            val value1 = attr1[i].value
-            val value2 = attr2[i].value
-            if (value1 == null && value2 == null) {
-                continue
-            }
-            if (value1 == null || value2 == null) {
-                return false
-            }
+            val value1 = attr1[i].value ?: return false
+            val value2 = attr2[i].value ?: return false
+            // Try to compare values directly with each other.
             val v1 = ConstantEvaluator.evaluate(context, value1)
             val v2 = ConstantEvaluator.evaluate(context, value2)
-            if (v1 != v2) {
-                return false
+            if (v1 != null && v2 != null) {
+                if (v1 != v2) {
+                    return false
+                }
+            } else {
+                val children1 = annotationValueGetChildren(value1)
+                val children2 = annotationValueGetChildren(value2)
+                if (children1.size != children2.size) {
+                    return false
+                }
+                for (j in children1.indices) {
+                    val c1 = ConstantEvaluator.evaluate(context, children1[j])
+                    val c2 = ConstantEvaluator.evaluate(context, children2[j])
+                    if (c1 != c2) {
+                        return false
+                    }
+                }
             }
         }
         return true
@@ -114,6 +131,13 @@
         val overridingName = "${overridingClass.name}.${overridingMethod.name}"
         val overriddenName = "${overriddenClass.name}.${overriddenMethod.name}"
         if (overridingAnnotation == null) {
+            if (shouldIgnoreGeneratedMethod(
+                            context,
+                            overriddenClass = overriddenClass,
+                            overridingClass = overridingClass)
+            ) {
+                return
+            }
             val msg = "The method $overridingName overrides the method $overriddenName which " +
                 "is annotated with @EnforcePermission. The same annotation must be used " +
                 "on $overridingName"
@@ -133,50 +157,13 @@
         }
     }
 
-    private fun compareClasses(
-        context: JavaContext,
-        element: UElement,
-        newClass: PsiClass,
-        extendedClass: PsiClass,
-        checkEquivalence: Boolean = true
-    ) {
-        val newAnnotation = newClass.getAnnotation(ANNOTATION_ENFORCE_PERMISSION)
-        val extendedAnnotation = extendedClass.getAnnotation(ANNOTATION_ENFORCE_PERMISSION)
-
-        val location = context.getLocation(element)
-        val newClassName = newClass.qualifiedName
-        val extendedClassName = extendedClass.qualifiedName
-        if (newAnnotation == null) {
-            val msg = "The class $newClassName extends the class $extendedClassName which " +
-                "is annotated with @EnforcePermission. The same annotation must be used " +
-                "on $newClassName."
-            context.report(ISSUE_MISSING_ENFORCE_PERMISSION, element, location, msg)
-        } else if (extendedAnnotation == null) {
-            val msg = "The class $newClassName extends the class $extendedClassName which " +
-                "is not annotated with @EnforcePermission. The same annotation must be used " +
-                "on $extendedClassName. Did you forget to annotate the AIDL definition?"
-            context.report(ISSUE_MISSING_ENFORCE_PERMISSION, element, location, msg)
-        } else if (checkEquivalence && !areAnnotationsEquivalent(
-            context, newAnnotation, extendedAnnotation)) {
-            val msg = "The class $newClassName is annotated with ${newAnnotation.text} " +
-                "which differs from the parent class $extendedClassName: " +
-                "${extendedAnnotation.text}. The same annotation must be used for " +
-                "both classes."
-            context.report(ISSUE_MISMATCHING_ENFORCE_PERMISSION, element, location, msg)
-        }
-    }
-
     override fun visitAnnotationUsage(
         context: JavaContext,
         element: UElement,
         annotationInfo: AnnotationInfo,
         usageInfo: AnnotationUsageInfo
     ) {
-        if (usageInfo.type == AnnotationUsageType.EXTENDS) {
-            val newClass = element.sourcePsi?.parent?.parent as PsiClass
-            val extendedClass: PsiClass = usageInfo.referenced as PsiClass
-            compareClasses(context, element, newClass, extendedClass)
-        } else if (usageInfo.type == AnnotationUsageType.METHOD_OVERRIDE &&
+        if (usageInfo.type == AnnotationUsageType.METHOD_OVERRIDE &&
             annotationInfo.origin == AnnotationOrigin.METHOD) {
             val overridingMethod = element.sourcePsi as PsiMethod
             val overriddenMethod = usageInfo.referenced as PsiMethod
@@ -191,17 +178,7 @@
                     return
                 }
                 val method = node.uastParent as? UMethod
-                val klass = node.uastParent as? UClass
-                if (klass != null) {
-                    val newClass = klass as PsiClass
-                    val extendedClass = newClass.getSuperClass()
-                    if (extendedClass != null && extendedClass.qualifiedName != JAVA_OBJECT) {
-                        // The equivalence check can be skipped, if both classes are
-                        // annotated, it will be verified by visitAnnotationUsage.
-                        compareClasses(context, klass, newClass,
-                            extendedClass, checkEquivalence = false)
-                    }
-                } else if (method != null) {
+                if (method != null) {
                     val overridingMethod = method as PsiMethod
                     val parents = overridingMethod.findSuperMethods()
                     for (overriddenMethod in parents) {
@@ -215,6 +192,39 @@
         }
     }
 
+    /**
+     * since this lint runs globally, it will also run against generated
+     * test code e.g.
+     * system/tools/aidl/tests/golden_output/aidl-test-interface-permission-java-source/gen/android/aidl/tests/permission/IProtected.java
+     * system/tools/aidl/tests/golden_output/aidl-test-interface-permission-java-source/gen/android/aidl/tests/permission/IProtectedInterface.java
+     * we do not want to report errors against generated `Stub` and `Proxy` classes in those files
+     */
+    private fun shouldIgnoreGeneratedMethod(
+            context: JavaContext,
+            overriddenClass: PsiClass,
+            overridingClass: PsiClass,
+
+    ): Boolean {
+        if (isInterfaceAndExtendsIInterface(overriddenClass) &&
+                context.evaluator.isStatic(overridingClass)) {
+            if (overridingClass.name == "Default") return true
+            if (overridingClass.name == "Proxy") {
+                val shouldBeStub = overridingClass.parent as? PsiClass ?: return false
+                return shouldBeStub.name == "Stub" &&
+                        context.evaluator.isAbstract(shouldBeStub) &&
+                        context.evaluator.isStatic(shouldBeStub) &&
+                        shouldBeStub.extendsList?.referenceElements
+                        ?.any { it.qualifiedName == BINDER_CLASS } == true
+            }
+        }
+        return false
+    }
+
+    private fun isInterfaceAndExtendsIInterface(overriddenClass: PsiClass): Boolean =
+            overriddenClass.isInterface &&
+                    overriddenClass.extendsList?.referenceElements
+                    ?.any { it.qualifiedName == IINTERFACE_INTERFACE } == true
+
     companion object {
         val EXPLANATION = """
             The @EnforcePermission annotation is used to indicate that the underlying binder code
diff --git a/tools/lint/global/checks/src/main/java/com/google/android/lint/aidl/EnforcePermissionHelperDetector.kt b/tools/lint/global/checks/src/main/java/com/google/android/lint/aidl/EnforcePermissionHelperDetector.kt
index 3c2ea1d..c1e47e9 100644
--- a/tools/lint/global/checks/src/main/java/com/google/android/lint/aidl/EnforcePermissionHelperDetector.kt
+++ b/tools/lint/global/checks/src/main/java/com/google/android/lint/aidl/EnforcePermissionHelperDetector.kt
@@ -28,8 +28,8 @@
 import com.intellij.psi.PsiElement
 import org.jetbrains.uast.UBlockExpression
 import org.jetbrains.uast.UDeclarationsExpression
-import org.jetbrains.uast.UExpression
 import org.jetbrains.uast.UElement
+import org.jetbrains.uast.UExpression
 import org.jetbrains.uast.UMethod
 
 class EnforcePermissionHelperDetector : Detector(), SourceCodeScanner {
@@ -40,6 +40,7 @@
 
     private inner class AidlStubHandler(val context: JavaContext) : UElementHandler() {
         override fun visitMethod(node: UMethod) {
+            if (context.evaluator.isAbstract(node)) return
             if (!node.hasAnnotation(ANNOTATION_ENFORCE_PERMISSION)) return
 
             val targetExpression = "super.${node.name}$HELPER_SUFFIX()"
diff --git a/tools/lint/global/checks/src/test/java/com/google/android/lint/aidl/EnforcePermissionDetectorCodegenTest.kt b/tools/lint/global/checks/src/test/java/com/google/android/lint/aidl/EnforcePermissionDetectorCodegenTest.kt
new file mode 100644
index 0000000..f2930d9
--- /dev/null
+++ b/tools/lint/global/checks/src/test/java/com/google/android/lint/aidl/EnforcePermissionDetectorCodegenTest.kt
@@ -0,0 +1,557 @@
+/*
+ * 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.google.android.lint.aidl
+
+import com.android.tools.lint.checks.infrastructure.LintDetectorTest
+import com.android.tools.lint.checks.infrastructure.TestFile
+import com.android.tools.lint.checks.infrastructure.TestLintTask
+import com.android.tools.lint.detector.api.Detector
+import com.android.tools.lint.detector.api.Issue
+
+@Suppress("UnstableApiUsage")
+class EnforcePermissionDetectorCodegenTest : LintDetectorTest() {
+    override fun getDetector(): Detector = EnforcePermissionDetector()
+
+    override fun getIssues(): List<Issue> = listOf(
+            EnforcePermissionDetector.ISSUE_MISSING_ENFORCE_PERMISSION,
+            EnforcePermissionDetector.ISSUE_MISMATCHING_ENFORCE_PERMISSION
+    )
+
+    override fun lint(): TestLintTask = super.lint().allowMissingSdk(true)
+
+    fun test_generated_IProtected() {
+        lint().files(
+            java(
+                """
+                /*
+                 * This file is auto-generated.  DO NOT MODIFY.
+                 */
+                package android.aidl.tests.permission;
+                public interface IProtected extends android.os.IInterface
+                {
+                  /** Default implementation for IProtected. */
+                  public static class Default implements android.aidl.tests.permission.IProtected
+                  {
+                    @Override public void PermissionProtected() throws android.os.RemoteException
+                    {
+                    }
+                    @Override public void MultiplePermissionsAll() throws android.os.RemoteException
+                    {
+                    }
+                    @Override public void MultiplePermissionsAny() throws android.os.RemoteException
+                    {
+                    }
+                    @Override public void NonManifestPermission() throws android.os.RemoteException
+                    {
+                    }
+                    // Used by the integration tests to dynamically set permissions that are considered granted.
+                    @Override public void SetGranted(java.util.List<java.lang.String> permissions) throws android.os.RemoteException
+                    {
+                    }
+                    @Override
+                    public android.os.IBinder asBinder() {
+                      return null;
+                    }
+                  }
+                  /** Local-side IPC implementation stub class. */
+                  public static abstract class Stub extends android.os.Binder implements android.aidl.tests.permission.IProtected
+                  {
+                    private final android.os.PermissionEnforcer mEnforcer;
+                    /** Construct the stub using the Enforcer provided. */
+                    public Stub(android.os.PermissionEnforcer enforcer)
+                    {
+                      this.attachInterface(this, DESCRIPTOR);
+                      if (enforcer == null) {
+                        throw new IllegalArgumentException("enforcer cannot be null");
+                      }
+                      mEnforcer = enforcer;
+                    }
+                    @Deprecated
+                    /** Default constructor. */
+                    public Stub() {
+                      this(android.os.PermissionEnforcer.fromContext(
+                         android.app.ActivityThread.currentActivityThread().getSystemContext()));
+                    }
+                    /**
+                     * Cast an IBinder object into an android.aidl.tests.permission.IProtected interface,
+                     * generating a proxy if needed.
+                     */
+                    public static android.aidl.tests.permission.IProtected asInterface(android.os.IBinder obj)
+                    {
+                      if ((obj==null)) {
+                        return null;
+                      }
+                      android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
+                      if (((iin!=null)&&(iin instanceof android.aidl.tests.permission.IProtected))) {
+                        return ((android.aidl.tests.permission.IProtected)iin);
+                      }
+                      return new android.aidl.tests.permission.IProtected.Stub.Proxy(obj);
+                    }
+                    @Override public android.os.IBinder asBinder()
+                    {
+                      return this;
+                    }
+                    /** @hide */
+                    public static java.lang.String getDefaultTransactionName(int transactionCode)
+                    {
+                      switch (transactionCode)
+                      {
+                        case TRANSACTION_PermissionProtected:
+                        {
+                          return "PermissionProtected";
+                        }
+                        case TRANSACTION_MultiplePermissionsAll:
+                        {
+                          return "MultiplePermissionsAll";
+                        }
+                        case TRANSACTION_MultiplePermissionsAny:
+                        {
+                          return "MultiplePermissionsAny";
+                        }
+                        case TRANSACTION_NonManifestPermission:
+                        {
+                          return "NonManifestPermission";
+                        }
+                        case TRANSACTION_SetGranted:
+                        {
+                          return "SetGranted";
+                        }
+                        default:
+                        {
+                          return null;
+                        }
+                      }
+                    }
+                    /** @hide */
+                    public java.lang.String getTransactionName(int transactionCode)
+                    {
+                      return this.getDefaultTransactionName(transactionCode);
+                    }
+                    @Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException
+                    {
+                      java.lang.String descriptor = DESCRIPTOR;
+                      if (code >= android.os.IBinder.FIRST_CALL_TRANSACTION && code <= android.os.IBinder.LAST_CALL_TRANSACTION) {
+                        data.enforceInterface(descriptor);
+                      }
+                      switch (code)
+                      {
+                        case INTERFACE_TRANSACTION:
+                        {
+                          reply.writeString(descriptor);
+                          return true;
+                        }
+                      }
+                      switch (code)
+                      {
+                        case TRANSACTION_PermissionProtected:
+                        {
+                          this.PermissionProtected();
+                          reply.writeNoException();
+                          break;
+                        }
+                        case TRANSACTION_MultiplePermissionsAll:
+                        {
+                          this.MultiplePermissionsAll();
+                          reply.writeNoException();
+                          break;
+                        }
+                        case TRANSACTION_MultiplePermissionsAny:
+                        {
+                          this.MultiplePermissionsAny();
+                          reply.writeNoException();
+                          break;
+                        }
+                        case TRANSACTION_NonManifestPermission:
+                        {
+                          this.NonManifestPermission();
+                          reply.writeNoException();
+                          break;
+                        }
+                        case TRANSACTION_SetGranted:
+                        {
+                          java.util.List<java.lang.String> _arg0;
+                          _arg0 = data.createStringArrayList();
+                          data.enforceNoDataAvail();
+                          this.SetGranted(_arg0);
+                          reply.writeNoException();
+                          break;
+                        }
+                        default:
+                        {
+                          return super.onTransact(code, data, reply, flags);
+                        }
+                      }
+                      return true;
+                    }
+                    private static class Proxy implements android.aidl.tests.permission.IProtected
+                    {
+                      private android.os.IBinder mRemote;
+                      Proxy(android.os.IBinder remote)
+                      {
+                        mRemote = remote;
+                      }
+                      @Override public android.os.IBinder asBinder()
+                      {
+                        return mRemote;
+                      }
+                      public java.lang.String getInterfaceDescriptor()
+                      {
+                        return DESCRIPTOR;
+                      }
+                      @Override public void PermissionProtected() throws android.os.RemoteException
+                      {
+                        android.os.Parcel _data = android.os.Parcel.obtain(asBinder());
+                        android.os.Parcel _reply = android.os.Parcel.obtain();
+                        try {
+                          _data.writeInterfaceToken(DESCRIPTOR);
+                          boolean _status = mRemote.transact(Stub.TRANSACTION_PermissionProtected, _data, _reply, 0);
+                          _reply.readException();
+                        }
+                        finally {
+                          _reply.recycle();
+                          _data.recycle();
+                        }
+                      }
+                      @Override public void MultiplePermissionsAll() throws android.os.RemoteException
+                      {
+                        android.os.Parcel _data = android.os.Parcel.obtain(asBinder());
+                        android.os.Parcel _reply = android.os.Parcel.obtain();
+                        try {
+                          _data.writeInterfaceToken(DESCRIPTOR);
+                          boolean _status = mRemote.transact(Stub.TRANSACTION_MultiplePermissionsAll, _data, _reply, 0);
+                          _reply.readException();
+                        }
+                        finally {
+                          _reply.recycle();
+                          _data.recycle();
+                        }
+                      }
+                      @Override public void MultiplePermissionsAny() throws android.os.RemoteException
+                      {
+                        android.os.Parcel _data = android.os.Parcel.obtain(asBinder());
+                        android.os.Parcel _reply = android.os.Parcel.obtain();
+                        try {
+                          _data.writeInterfaceToken(DESCRIPTOR);
+                          boolean _status = mRemote.transact(Stub.TRANSACTION_MultiplePermissionsAny, _data, _reply, 0);
+                          _reply.readException();
+                        }
+                        finally {
+                          _reply.recycle();
+                          _data.recycle();
+                        }
+                      }
+                      @Override public void NonManifestPermission() throws android.os.RemoteException
+                      {
+                        android.os.Parcel _data = android.os.Parcel.obtain(asBinder());
+                        android.os.Parcel _reply = android.os.Parcel.obtain();
+                        try {
+                          _data.writeInterfaceToken(DESCRIPTOR);
+                          boolean _status = mRemote.transact(Stub.TRANSACTION_NonManifestPermission, _data, _reply, 0);
+                          _reply.readException();
+                        }
+                        finally {
+                          _reply.recycle();
+                          _data.recycle();
+                        }
+                      }
+                      // Used by the integration tests to dynamically set permissions that are considered granted.
+                      @Override public void SetGranted(java.util.List<java.lang.String> permissions) throws android.os.RemoteException
+                      {
+                        android.os.Parcel _data = android.os.Parcel.obtain(asBinder());
+                        android.os.Parcel _reply = android.os.Parcel.obtain();
+                        try {
+                          _data.writeInterfaceToken(DESCRIPTOR);
+                          _data.writeStringList(permissions);
+                          boolean _status = mRemote.transact(Stub.TRANSACTION_SetGranted, _data, _reply, 0);
+                          _reply.readException();
+                        }
+                        finally {
+                          _reply.recycle();
+                          _data.recycle();
+                        }
+                      }
+                    }
+                    static final int TRANSACTION_PermissionProtected = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
+                    /** Helper method to enforce permissions for PermissionProtected */
+                    protected void PermissionProtected_enforcePermission() throws SecurityException {
+                      android.content.AttributionSource source = new android.content.AttributionSource(getCallingUid(), null, null);
+                      mEnforcer.enforcePermission(android.Manifest.permission.READ_PHONE_STATE, source);
+                    }
+                    static final int TRANSACTION_MultiplePermissionsAll = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);
+                    /** Helper method to enforce permissions for MultiplePermissionsAll */
+                    protected void MultiplePermissionsAll_enforcePermission() throws SecurityException {
+                      android.content.AttributionSource source = new android.content.AttributionSource(getCallingUid(), null, null);
+                      mEnforcer.enforcePermissionAllOf(new String[]{android.Manifest.permission.INTERNET, android.Manifest.permission.VIBRATE}, source);
+                    }
+                    static final int TRANSACTION_MultiplePermissionsAny = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2);
+                    /** Helper method to enforce permissions for MultiplePermissionsAny */
+                    protected void MultiplePermissionsAny_enforcePermission() throws SecurityException {
+                      android.content.AttributionSource source = new android.content.AttributionSource(getCallingUid(), null, null);
+                      mEnforcer.enforcePermissionAnyOf(new String[]{android.Manifest.permission.INTERNET, android.Manifest.permission.VIBRATE}, source);
+                    }
+                    static final int TRANSACTION_NonManifestPermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 3);
+                    /** Helper method to enforce permissions for NonManifestPermission */
+                    protected void NonManifestPermission_enforcePermission() throws SecurityException {
+                      android.content.AttributionSource source = new android.content.AttributionSource(getCallingUid(), null, null);
+                      mEnforcer.enforcePermission(android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, source);
+                    }
+                    static final int TRANSACTION_SetGranted = (android.os.IBinder.FIRST_CALL_TRANSACTION + 4);
+                    /** @hide */
+                    public int getMaxTransactionId()
+                    {
+                      return 4;
+                    }
+                  }
+                  
+                  @android.annotation.EnforcePermission(android.Manifest.permission.READ_PHONE_STATE)
+                  public void PermissionProtected() throws android.os.RemoteException;
+                  @android.annotation.EnforcePermission(allOf = {android.Manifest.permission.INTERNET, android.Manifest.permission.VIBRATE})
+                  public void MultiplePermissionsAll() throws android.os.RemoteException;
+                  @android.annotation.EnforcePermission(anyOf = {android.Manifest.permission.INTERNET, android.Manifest.permission.VIBRATE})
+                  public void MultiplePermissionsAny() throws android.os.RemoteException;
+                  @android.annotation.EnforcePermission(android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK)
+                  public void NonManifestPermission() throws android.os.RemoteException;
+                  // Used by the integration tests to dynamically set permissions that are considered granted.
+                  @android.annotation.RequiresNoPermission
+                  public void SetGranted(java.util.List<java.lang.String> permissions) throws android.os.RemoteException;
+                }
+                """
+            ).indented(),
+                *stubs
+        )
+            .run()
+            .expectClean()
+    }
+
+    fun test_generated_IProtectedInterface() {
+        lint().files(
+                java(
+                    """
+                    /*
+                     * This file is auto-generated.  DO NOT MODIFY.
+                     */
+                    package android.aidl.tests.permission;
+                    public interface IProtectedInterface extends android.os.IInterface
+                    {
+                      /** Default implementation for IProtectedInterface. */
+                      public static class Default implements android.aidl.tests.permission.IProtectedInterface
+                      {
+                        @Override public void Method1() throws android.os.RemoteException
+                        {
+                        }
+                        @Override public void Method2() throws android.os.RemoteException
+                        {
+                        }
+                        @Override
+                        public android.os.IBinder asBinder() {
+                          return null;
+                        }
+                      }
+                      /** Local-side IPC implementation stub class. */
+                      public static abstract class Stub extends android.os.Binder implements android.aidl.tests.permission.IProtectedInterface
+                      {
+                        private final android.os.PermissionEnforcer mEnforcer;
+                        /** Construct the stub using the Enforcer provided. */
+                        public Stub(android.os.PermissionEnforcer enforcer)
+                        {
+                          this.attachInterface(this, DESCRIPTOR);
+                          if (enforcer == null) {
+                            throw new IllegalArgumentException("enforcer cannot be null");
+                          }
+                          mEnforcer = enforcer;
+                        }
+                        @Deprecated
+                        /** Default constructor. */
+                        public Stub() {
+                          this(android.os.PermissionEnforcer.fromContext(
+                             android.app.ActivityThread.currentActivityThread().getSystemContext()));
+                        }
+                        /**
+                         * Cast an IBinder object into an android.aidl.tests.permission.IProtectedInterface interface,
+                         * generating a proxy if needed.
+                         */
+                        public static android.aidl.tests.permission.IProtectedInterface asInterface(android.os.IBinder obj)
+                        {
+                          if ((obj==null)) {
+                            return null;
+                          }
+                          android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
+                          if (((iin!=null)&&(iin instanceof android.aidl.tests.permission.IProtectedInterface))) {
+                            return ((android.aidl.tests.permission.IProtectedInterface)iin);
+                          }
+                          return new android.aidl.tests.permission.IProtectedInterface.Stub.Proxy(obj);
+                        }
+                        @Override public android.os.IBinder asBinder()
+                        {
+                          return this;
+                        }
+                        /** @hide */
+                        public static java.lang.String getDefaultTransactionName(int transactionCode)
+                        {
+                          switch (transactionCode)
+                          {
+                            case TRANSACTION_Method1:
+                            {
+                              return "Method1";
+                            }
+                            case TRANSACTION_Method2:
+                            {
+                              return "Method2";
+                            }
+                            default:
+                            {
+                              return null;
+                            }
+                          }
+                        }
+                        /** @hide */
+                        public java.lang.String getTransactionName(int transactionCode)
+                        {
+                          return this.getDefaultTransactionName(transactionCode);
+                        }
+                        @Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException
+                        {
+                          java.lang.String descriptor = DESCRIPTOR;
+                          if (code >= android.os.IBinder.FIRST_CALL_TRANSACTION && code <= android.os.IBinder.LAST_CALL_TRANSACTION) {
+                            data.enforceInterface(descriptor);
+                          }
+                          switch (code)
+                          {
+                            case INTERFACE_TRANSACTION:
+                            {
+                              reply.writeString(descriptor);
+                              return true;
+                            }
+                          }
+                          switch (code)
+                          {
+                            case TRANSACTION_Method1:
+                            {
+                              this.Method1();
+                              reply.writeNoException();
+                              break;
+                            }
+                            case TRANSACTION_Method2:
+                            {
+                              this.Method2();
+                              reply.writeNoException();
+                              break;
+                            }
+                            default:
+                            {
+                              return super.onTransact(code, data, reply, flags);
+                            }
+                          }
+                          return true;
+                        }
+                        private static class Proxy implements android.aidl.tests.permission.IProtectedInterface
+                        {
+                          private android.os.IBinder mRemote;
+                          Proxy(android.os.IBinder remote)
+                          {
+                            mRemote = remote;
+                          }
+                          @Override public android.os.IBinder asBinder()
+                          {
+                            return mRemote;
+                          }
+                          public java.lang.String getInterfaceDescriptor()
+                          {
+                            return DESCRIPTOR;
+                          }
+                          @Override public void Method1() throws android.os.RemoteException
+                          {
+                            android.os.Parcel _data = android.os.Parcel.obtain(asBinder());
+                            android.os.Parcel _reply = android.os.Parcel.obtain();
+                            try {
+                              _data.writeInterfaceToken(DESCRIPTOR);
+                              boolean _status = mRemote.transact(Stub.TRANSACTION_Method1, _data, _reply, 0);
+                              _reply.readException();
+                            }
+                            finally {
+                              _reply.recycle();
+                              _data.recycle();
+                            }
+                          }
+                          @Override public void Method2() throws android.os.RemoteException
+                          {
+                            android.os.Parcel _data = android.os.Parcel.obtain(asBinder());
+                            android.os.Parcel _reply = android.os.Parcel.obtain();
+                            try {
+                              _data.writeInterfaceToken(DESCRIPTOR);
+                              boolean _status = mRemote.transact(Stub.TRANSACTION_Method2, _data, _reply, 0);
+                              _reply.readException();
+                            }
+                            finally {
+                              _reply.recycle();
+                              _data.recycle();
+                            }
+                          }
+                        }
+                        static final int TRANSACTION_Method1 = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
+                        /** Helper method to enforce permissions for Method1 */
+                        protected void Method1_enforcePermission() throws SecurityException {
+                          android.content.AttributionSource source = new android.content.AttributionSource(getCallingUid(), null, null);
+                          mEnforcer.enforcePermission(android.Manifest.permission.ACCESS_FINE_LOCATION, source);
+                        }
+                        static final int TRANSACTION_Method2 = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);
+                        /** Helper method to enforce permissions for Method2 */
+                        protected void Method2_enforcePermission() throws SecurityException {
+                          android.content.AttributionSource source = new android.content.AttributionSource(getCallingUid(), null, null);
+                          mEnforcer.enforcePermission(android.Manifest.permission.ACCESS_FINE_LOCATION, source);
+                        }
+                        /** @hide */
+                        public int getMaxTransactionId()
+                        {
+                          return 1;
+                        }
+                      }
+                      
+                      @android.annotation.EnforcePermission(android.Manifest.permission.ACCESS_FINE_LOCATION)
+                      public void Method1() throws android.os.RemoteException;
+                      @android.annotation.EnforcePermission(android.Manifest.permission.ACCESS_FINE_LOCATION)
+                      public void Method2() throws android.os.RemoteException;
+                    }
+                    """
+                ).indented(),
+                *stubs
+        )
+                .run()
+                .expectClean()
+    }
+
+    /* Stubs */
+
+    private val manifestPermissionStub: TestFile = java(
+        """
+        package android.Manifest;
+        class permission {
+          public static final String READ_PHONE_STATE = "android.permission.READ_PHONE_STATE";
+          public static final String INTERNET = "android.permission.INTERNET";
+        }
+        """
+    ).indented()
+
+    private val enforcePermissionAnnotationStub: TestFile = java(
+        """
+        package android.annotation;
+        public @interface EnforcePermission {}
+        """
+    ).indented()
+
+    private val stubs = arrayOf(manifestPermissionStub, enforcePermissionAnnotationStub)
+}
diff --git a/tools/lint/global/checks/src/test/java/com/google/android/lint/aidl/EnforcePermissionDetectorTest.kt b/tools/lint/global/checks/src/test/java/com/google/android/lint/aidl/EnforcePermissionDetectorTest.kt
index 3c1d1e8..4ed68a8 100644
--- a/tools/lint/global/checks/src/test/java/com/google/android/lint/aidl/EnforcePermissionDetectorTest.kt
+++ b/tools/lint/global/checks/src/test/java/com/google/android/lint/aidl/EnforcePermissionDetectorTest.kt
@@ -33,21 +33,6 @@
 
     override fun lint(): TestLintTask = super.lint().allowMissingSdk(true)
 
-    fun testDoesNotDetectIssuesCorrectAnnotationOnClass() {
-        lint().files(java(
-            """
-            package test.pkg;
-            @android.annotation.EnforcePermission(android.Manifest.permission.READ_PHONE_STATE)
-            public class TestClass1 extends IFoo.Stub {
-                public void testMethod() {}
-            }
-            """).indented(),
-                *stubs
-        )
-        .run()
-        .expectClean()
-    }
-
     fun testDoesNotDetectIssuesCorrectAnnotationOnMethod() {
         lint().files(java(
             """
@@ -65,26 +50,72 @@
         .expectClean()
     }
 
-    fun testDetectIssuesMismatchingAnnotationOnClass() {
+    fun testDoesNotDetectIssuesCorrectAnnotationAllOnMethod() {
         lint().files(java(
             """
             package test.pkg;
-            @android.annotation.EnforcePermission(android.Manifest.permission.INTERNET)
-            public class TestClass3 extends IFoo.Stub {
-                public void testMethod() {}
+            import android.annotation.EnforcePermission;
+            public class TestClass11 extends IFooMethod.Stub {
+                @Override
+                @EnforcePermission(allOf={android.Manifest.permission.INTERNET, android.Manifest.permission.READ_PHONE_STATE})
+                public void testMethodAll() {}
             }
             """).indented(),
                 *stubs
         )
         .run()
-        .expect("""src/test/pkg/TestClass3.java:3: Error: The class test.pkg.TestClass3 is \
-annotated with @android.annotation.EnforcePermission(android.Manifest.permission.INTERNET) \
-which differs from the parent class IFoo.Stub: \
-@android.annotation.EnforcePermission(android.Manifest.permission.READ_PHONE_STATE). The \
-same annotation must be used for both classes. [MismatchingEnforcePermissionAnnotation]
-public class TestClass3 extends IFoo.Stub {
-                                ~~~~~~~~~
-1 errors, 0 warnings""".addLineContinuation())
+        .expectClean()
+    }
+
+    fun testDoesNotDetectIssuesCorrectAnnotationAllLiteralOnMethod() {
+        lint().files(java(
+            """
+            package test.pkg;
+            import android.annotation.EnforcePermission;
+            public class TestClass111 extends IFooMethod.Stub {
+                @Override
+                @EnforcePermission(allOf={"android.permission.INTERNET", android.Manifest.permission.READ_PHONE_STATE})
+                public void testMethodAllLiteral() {}
+            }
+            """).indented(),
+                *stubs
+        )
+        .run()
+        .expectClean()
+    }
+
+    fun testDoesNotDetectIssuesCorrectAnnotationAnyOnMethod() {
+        lint().files(java(
+            """
+            package test.pkg;
+            import android.annotation.EnforcePermission;
+            public class TestClass12 extends IFooMethod.Stub {
+                @Override
+                @EnforcePermission(anyOf={android.Manifest.permission.INTERNET, android.Manifest.permission.READ_PHONE_STATE})
+                public void testMethodAny() {}
+            }
+            """).indented(),
+                *stubs
+        )
+        .run()
+        .expectClean()
+    }
+
+    fun testDoesNotDetectIssuesCorrectAnnotationAnyLiteralOnMethod() {
+        lint().files(java(
+            """
+            package test.pkg;
+            import android.annotation.EnforcePermission;
+            public class TestClass121 extends IFooMethod.Stub {
+                @Override
+                @EnforcePermission(anyOf={"android.permission.INTERNET", android.Manifest.permission.READ_PHONE_STATE})
+                public void testMethodAnyLiteral() {}
+            }
+            """).indented(),
+                *stubs
+        )
+        .run()
+        .expectClean()
     }
 
     fun testDetectIssuesMismatchingAnnotationOnMethod() {
@@ -99,33 +130,132 @@
                 *stubs
         )
         .run()
-        .expect("""src/test/pkg/TestClass4.java:4: Error: The method TestClass4.testMethod is \
-annotated with @android.annotation.EnforcePermission(android.Manifest.permission.INTERNET) \
-which differs from the overridden method Stub.testMethod: \
-@android.annotation.EnforcePermission(android.Manifest.permission.READ_PHONE_STATE). The same \
-annotation must be used for both methods. [MismatchingEnforcePermissionAnnotation]
-    public void testMethod() {}
-                ~~~~~~~~~~
-1 errors, 0 warnings""".addLineContinuation())
+        .expect("""
+                src/test/pkg/TestClass4.java:4: Error: The method TestClass4.testMethod is annotated with @android.annotation.EnforcePermission(android.Manifest.permission.INTERNET) \
+                which differs from the overridden method Stub.testMethod: @android.annotation.EnforcePermission(android.Manifest.permission.READ_PHONE_STATE). \
+                The same annotation must be used for both methods. [MismatchingEnforcePermissionAnnotation]
+                    public void testMethod() {}
+                                ~~~~~~~~~~
+                1 errors, 0 warnings
+                """.addLineContinuation())
     }
 
-    fun testDetectIssuesMissingAnnotationOnClass() {
+    fun testDetectIssuesEmptyAnnotationOnMethod() {
         lint().files(java(
             """
             package test.pkg;
-            public class TestClass5 extends IFoo.Stub {
+            public class TestClass41 extends IFooMethod.Stub {
+                @android.annotation.EnforcePermission
                 public void testMethod() {}
             }
             """).indented(),
                 *stubs
         )
         .run()
-        .expect("""src/test/pkg/TestClass5.java:2: Error: The class test.pkg.TestClass5 extends \
-the class IFoo.Stub which is annotated with @EnforcePermission. The same annotation must be \
-used on test.pkg.TestClass5. [MissingEnforcePermissionAnnotation]
-public class TestClass5 extends IFoo.Stub {
-                                ~~~~~~~~~
-1 errors, 0 warnings""".addLineContinuation())
+        .expect("""
+                src/test/pkg/TestClass41.java:4: Error: The method TestClass41.testMethod is annotated with @android.annotation.EnforcePermission \
+                which differs from the overridden method Stub.testMethod: @android.annotation.EnforcePermission(android.Manifest.permission.READ_PHONE_STATE). \
+                The same annotation must be used for both methods. [MismatchingEnforcePermissionAnnotation]
+                    public void testMethod() {}
+                                ~~~~~~~~~~
+                1 errors, 0 warnings
+                """.addLineContinuation())
+    }
+
+    fun testDetectIssuesMismatchingAnyAnnotationOnMethod() {
+        lint().files(java(
+            """
+            package test.pkg;
+            public class TestClass9 extends IFooMethod.Stub {
+                @android.annotation.EnforcePermission(anyOf={android.Manifest.permission.INTERNET, android.Manifest.permission.NFC})
+                public void testMethodAny() {}
+            }
+            """).indented(),
+                *stubs
+        )
+        .run()
+        .expect("""
+                src/test/pkg/TestClass9.java:4: Error: The method TestClass9.testMethodAny is annotated with \
+                @android.annotation.EnforcePermission(anyOf={android.Manifest.permission.INTERNET, android.Manifest.permission.NFC}) \
+                which differs from the overridden method Stub.testMethodAny: \
+                @android.annotation.EnforcePermission(anyOf={android.Manifest.permission.INTERNET, android.Manifest.permission.READ_PHONE_STATE}). \
+                The same annotation must be used for both methods. [MismatchingEnforcePermissionAnnotation]
+                    public void testMethodAny() {}
+                                ~~~~~~~~~~~~~
+                1 errors, 0 warnings
+                """.addLineContinuation())
+    }
+
+    fun testDetectIssuesMismatchingAnyLiteralAnnotationOnMethod() {
+        lint().files(java(
+            """
+            package test.pkg;
+            public class TestClass91 extends IFooMethod.Stub {
+                @android.annotation.EnforcePermission(anyOf={"android.permission.INTERNET", "android.permissionoopsthisisatypo.READ_PHONE_STATE"})
+                public void testMethodAnyLiteral() {}
+            }
+            """).indented(),
+                *stubs
+        )
+        .run()
+        .expect("""
+                src/test/pkg/TestClass91.java:4: Error: The method TestClass91.testMethodAnyLiteral is annotated with \
+                @android.annotation.EnforcePermission(anyOf={"android.permission.INTERNET", "android.permissionoopsthisisatypo.READ_PHONE_STATE"}) \
+                which differs from the overridden method Stub.testMethodAnyLiteral: \
+                @android.annotation.EnforcePermission(anyOf={android.Manifest.permission.INTERNET, "android.permission.READ_PHONE_STATE"}). \
+                The same annotation must be used for both methods. [MismatchingEnforcePermissionAnnotation]
+                    public void testMethodAnyLiteral() {}
+                                ~~~~~~~~~~~~~~~~~~~~
+                1 errors, 0 warnings
+                """.addLineContinuation())
+    }
+
+    fun testDetectIssuesMismatchingAllAnnotationOnMethod() {
+        lint().files(java(
+            """
+            package test.pkg;
+            public class TestClass10 extends IFooMethod.Stub {
+                @android.annotation.EnforcePermission(allOf={android.Manifest.permission.INTERNET, android.Manifest.permission.NFC})
+                public void testMethodAll() {}
+            }
+            """).indented(),
+                *stubs
+        )
+        .run()
+        .expect("""
+                src/test/pkg/TestClass10.java:4: Error: The method TestClass10.testMethodAll is annotated with \
+                @android.annotation.EnforcePermission(allOf={android.Manifest.permission.INTERNET, android.Manifest.permission.NFC}) \
+                which differs from the overridden method Stub.testMethodAll: \
+                @android.annotation.EnforcePermission(allOf={android.Manifest.permission.INTERNET, android.Manifest.permission.READ_PHONE_STATE}). \
+                The same annotation must be used for both methods. [MismatchingEnforcePermissionAnnotation]
+                    public void testMethodAll() {}
+                                ~~~~~~~~~~~~~
+                1 errors, 0 warnings
+                """.addLineContinuation())
+    }
+
+    fun testDetectIssuesMismatchingAllLiteralAnnotationOnMethod() {
+        lint().files(java(
+            """
+            package test.pkg;
+            public class TestClass101 extends IFooMethod.Stub {
+                @android.annotation.EnforcePermission(allOf={"android.permission.INTERNET", "android.permissionoopsthisisatypo.READ_PHONE_STATE"})
+                public void testMethodAllLiteral() {}
+            }
+            """).indented(),
+                *stubs
+        )
+        .run()
+        .expect("""
+                src/test/pkg/TestClass101.java:4: Error: The method TestClass101.testMethodAllLiteral is annotated with \
+                @android.annotation.EnforcePermission(allOf={"android.permission.INTERNET", "android.permissionoopsthisisatypo.READ_PHONE_STATE"}) \
+                which differs from the overridden method Stub.testMethodAllLiteral: \
+                @android.annotation.EnforcePermission(allOf={android.Manifest.permission.INTERNET, "android.permission.READ_PHONE_STATE"}). \
+                The same annotation must be used for both methods. [MismatchingEnforcePermissionAnnotation]
+                    public void testMethodAllLiteral() {}
+                                ~~~~~~~~~~~~~~~~~~~~
+                1 errors, 0 warnings
+                """.addLineContinuation())
     }
 
     fun testDetectIssuesMissingAnnotationOnMethod() {
@@ -139,12 +269,13 @@
                 *stubs
         )
         .run()
-        .expect("""src/test/pkg/TestClass6.java:3: Error: The method TestClass6.testMethod \
-overrides the method Stub.testMethod which is annotated with @EnforcePermission. The same \
-annotation must be used on TestClass6.testMethod [MissingEnforcePermissionAnnotation]
-    public void testMethod() {}
-                ~~~~~~~~~~
-1 errors, 0 warnings""".addLineContinuation())
+        .expect("""
+                src/test/pkg/TestClass6.java:3: Error: The method TestClass6.testMethod overrides the method Stub.testMethod which is annotated with @EnforcePermission. \
+                The same annotation must be used on TestClass6.testMethod [MissingEnforcePermissionAnnotation]
+                    public void testMethod() {}
+                                ~~~~~~~~~~
+                1 errors, 0 warnings
+                """.addLineContinuation())
     }
 
     fun testDetectIssuesExtraAnnotationMethod() {
@@ -159,53 +290,39 @@
                 *stubs
         )
         .run()
-        .expect("""src/test/pkg/TestClass7.java:4: Error: The method TestClass7.testMethod \
-overrides the method Stub.testMethod which is not annotated with @EnforcePermission. The same \
-annotation must be used on Stub.testMethod. Did you forget to annotate the AIDL definition? \
-[MissingEnforcePermissionAnnotation]
-    public void testMethod() {}
-                ~~~~~~~~~~
-1 errors, 0 warnings""".addLineContinuation())
+        .expect("""
+                src/test/pkg/TestClass7.java:4: Error: The method TestClass7.testMethod overrides the method Stub.testMethod which is not annotated with @EnforcePermission. \
+                The same annotation must be used on Stub.testMethod. Did you forget to annotate the AIDL definition? [MissingEnforcePermissionAnnotation]
+                    public void testMethod() {}
+                                ~~~~~~~~~~
+                1 errors, 0 warnings
+                """.addLineContinuation())
     }
 
-    fun testDetectIssuesExtraAnnotationInterface() {
+    fun testDetectIssuesMissingAnnotationOnMethodWhenClassIsCalledDefault() {
         lint().files(java(
             """
             package test.pkg;
-            @android.annotation.EnforcePermission(android.Manifest.permission.INTERNET)
-            public class TestClass8 extends IBar.Stub {
+            public class Default extends IFooMethod.Stub {
                 public void testMethod() {}
             }
             """).indented(),
-                *stubs
+            *stubs
         )
-        .run()
-        .expect("""src/test/pkg/TestClass8.java:2: Error: The class test.pkg.TestClass8 \
-extends the class IBar.Stub which is not annotated with @EnforcePermission. The same annotation \
-must be used on IBar.Stub. Did you forget to annotate the AIDL definition? \
-[MissingEnforcePermissionAnnotation]
-@android.annotation.EnforcePermission(android.Manifest.permission.INTERNET)
-^
-1 errors, 0 warnings""".addLineContinuation())
+            .run()
+            .expect(
+                """
+                src/test/pkg/Default.java:3: Error: The method Default.testMethod \
+                overrides the method Stub.testMethod which is annotated with @EnforcePermission. The same annotation must be used on Default.testMethod [MissingEnforcePermissionAnnotation]
+                    public void testMethod() {}
+                                ~~~~~~~~~~
+                1 errors, 0 warnings 
+                """.addLineContinuation()
+            )
     }
 
     /* Stubs */
 
-    // A service with permission annotation on the class.
-    private val interfaceIFooStub: TestFile = java(
-        """
-        @android.annotation.EnforcePermission(android.Manifest.permission.READ_PHONE_STATE)
-        public interface IFoo {
-         @android.annotation.EnforcePermission(android.Manifest.permission.READ_PHONE_STATE)
-         public static abstract class Stub extends android.os.Binder implements IFoo {
-           @Override
-           public void testMethod() {}
-         }
-         public void testMethod();
-        }
-        """
-    ).indented()
-
     // A service with permission annotation on the method.
     private val interfaceIFooMethodStub: TestFile = java(
         """
@@ -214,9 +331,29 @@
             @Override
             @android.annotation.EnforcePermission(android.Manifest.permission.READ_PHONE_STATE)
             public void testMethod() {}
+            @Override
+            @android.annotation.EnforcePermission(anyOf={android.Manifest.permission.INTERNET, android.Manifest.permission.READ_PHONE_STATE})
+            public void testMethodAny() {}
+            @Override
+            @android.annotation.EnforcePermission(anyOf={android.Manifest.permission.INTERNET, "android.permission.READ_PHONE_STATE"})
+            public void testMethodAnyLiteral() {}
+            @Override
+            @android.annotation.EnforcePermission(allOf={android.Manifest.permission.INTERNET, android.Manifest.permission.READ_PHONE_STATE})
+            public void testMethodAll() {}
+            @Override
+            @android.annotation.EnforcePermission(allOf={android.Manifest.permission.INTERNET, "android.permission.READ_PHONE_STATE"})
+            public void testMethodAllLiteral() {}
           }
           @android.annotation.EnforcePermission(android.Manifest.permission.READ_PHONE_STATE)
           public void testMethod();
+          @android.annotation.EnforcePermission(anyOf={android.Manifest.permission.INTERNET, android.Manifest.permission.READ_PHONE_STATE})
+          public void testMethodAny() {}
+          @android.annotation.EnforcePermission(anyOf={android.Manifest.permission.INTERNET, "android.permission.READ_PHONE_STATE"})
+          public void testMethodAnyLiteral() {}
+          @android.annotation.EnforcePermission(allOf={android.Manifest.permission.INTERNET, android.Manifest.permission.READ_PHONE_STATE})
+          public void testMethodAll() {}
+          @android.annotation.EnforcePermission(allOf={android.Manifest.permission.INTERNET, "android.permission.READ_PHONE_STATE"})
+          public void testMethodAllLiteral() {}
         }
         """
     ).indented()
@@ -239,6 +376,7 @@
         package android.Manifest;
         class permission {
           public static final String READ_PHONE_STATE = "android.permission.READ_PHONE_STATE";
+          public static final String NFC = "android.permission.NFC";
           public static final String INTERNET = "android.permission.INTERNET";
         }
         """
@@ -251,7 +389,7 @@
         """
     ).indented()
 
-    private val stubs = arrayOf(interfaceIFooStub, interfaceIFooMethodStub, interfaceIBarStub,
+    private val stubs = arrayOf(interfaceIFooMethodStub, interfaceIBarStub,
             manifestPermissionStub, enforcePermissionAnnotationStub)
 
     // Substitutes "backslash + new line" with an empty string to imitate line continuation
diff --git a/tools/lint/global/checks/src/test/java/com/google/android/lint/aidl/EnforcePermissionHelperDetectorCodegenTest.kt b/tools/lint/global/checks/src/test/java/com/google/android/lint/aidl/EnforcePermissionHelperDetectorCodegenTest.kt
new file mode 100644
index 0000000..5a63bb4
--- /dev/null
+++ b/tools/lint/global/checks/src/test/java/com/google/android/lint/aidl/EnforcePermissionHelperDetectorCodegenTest.kt
@@ -0,0 +1,557 @@
+/*
+ * 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.google.android.lint.aidl
+
+import com.android.tools.lint.checks.infrastructure.LintDetectorTest
+import com.android.tools.lint.checks.infrastructure.TestFile
+import com.android.tools.lint.checks.infrastructure.TestLintTask
+import com.android.tools.lint.checks.infrastructure.TestMode
+import com.android.tools.lint.detector.api.Detector
+import com.android.tools.lint.detector.api.Issue
+
+@Suppress("UnstableApiUsage")
+class EnforcePermissionHelperDetectorCodegenTest : LintDetectorTest() {
+    override fun getDetector(): Detector = EnforcePermissionHelperDetector()
+
+    override fun getIssues(): List<Issue> = listOf(
+            EnforcePermissionHelperDetector.ISSUE_ENFORCE_PERMISSION_HELPER
+    )
+
+    override fun lint(): TestLintTask = super.lint().allowMissingSdk(true)
+
+    fun test_generated_IProtected() {
+        lint().testModes(TestMode.DEFAULT).files(
+            java(
+                """
+                /*
+                 * This file is auto-generated.  DO NOT MODIFY.
+                 */
+                package android.aidl.tests.permission;
+                public interface IProtected extends android.os.IInterface
+                {
+                  /** Default implementation for IProtected. */
+                  public static class Default implements android.aidl.tests.permission.IProtected
+                  {
+                    @Override public void PermissionProtected() throws android.os.RemoteException
+                    {
+                    }
+                    @Override public void MultiplePermissionsAll() throws android.os.RemoteException
+                    {
+                    }
+                    @Override public void MultiplePermissionsAny() throws android.os.RemoteException
+                    {
+                    }
+                    @Override public void NonManifestPermission() throws android.os.RemoteException
+                    {
+                    }
+                    // Used by the integration tests to dynamically set permissions that are considered granted.
+                    @Override public void SetGranted(java.util.List<java.lang.String> permissions) throws android.os.RemoteException
+                    {
+                    }
+                    @Override
+                    public android.os.IBinder asBinder() {
+                      return null;
+                    }
+                  }
+                  /** Local-side IPC implementation stub class. */
+                  public static abstract class Stub extends android.os.Binder implements android.aidl.tests.permission.IProtected
+                  {
+                    private final android.os.PermissionEnforcer mEnforcer;
+                    /** Construct the stub using the Enforcer provided. */
+                    public Stub(android.os.PermissionEnforcer enforcer)
+                    {
+                      this.attachInterface(this, DESCRIPTOR);
+                      if (enforcer == null) {
+                        throw new IllegalArgumentException("enforcer cannot be null");
+                      }
+                      mEnforcer = enforcer;
+                    }
+                    @Deprecated
+                    /** Default constructor. */
+                    public Stub() {
+                      this(android.os.PermissionEnforcer.fromContext(
+                         android.app.ActivityThread.currentActivityThread().getSystemContext()));
+                    }
+                    /**
+                     * Cast an IBinder object into an android.aidl.tests.permission.IProtected interface,
+                     * generating a proxy if needed.
+                     */
+                    public static android.aidl.tests.permission.IProtected asInterface(android.os.IBinder obj)
+                    {
+                      if ((obj==null)) {
+                        return null;
+                      }
+                      android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
+                      if (((iin!=null)&&(iin instanceof android.aidl.tests.permission.IProtected))) {
+                        return ((android.aidl.tests.permission.IProtected)iin);
+                      }
+                      return new android.aidl.tests.permission.IProtected.Stub.Proxy(obj);
+                    }
+                    @Override public android.os.IBinder asBinder()
+                    {
+                      return this;
+                    }
+                    /** @hide */
+                    public static java.lang.String getDefaultTransactionName(int transactionCode)
+                    {
+                      switch (transactionCode)
+                      {
+                        case TRANSACTION_PermissionProtected:
+                        {
+                          return "PermissionProtected";
+                        }
+                        case TRANSACTION_MultiplePermissionsAll:
+                        {
+                          return "MultiplePermissionsAll";
+                        }
+                        case TRANSACTION_MultiplePermissionsAny:
+                        {
+                          return "MultiplePermissionsAny";
+                        }
+                        case TRANSACTION_NonManifestPermission:
+                        {
+                          return "NonManifestPermission";
+                        }
+                        case TRANSACTION_SetGranted:
+                        {
+                          return "SetGranted";
+                        }
+                        default:
+                        {
+                          return null;
+                        }
+                      }
+                    }
+                    /** @hide */
+                    public java.lang.String getTransactionName(int transactionCode)
+                    {
+                      return this.getDefaultTransactionName(transactionCode);
+                    }
+                    @Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException
+                    {
+                      java.lang.String descriptor = DESCRIPTOR;
+                      if (code >= android.os.IBinder.FIRST_CALL_TRANSACTION && code <= android.os.IBinder.LAST_CALL_TRANSACTION) {
+                        data.enforceInterface(descriptor);
+                      }
+                      switch (code)
+                      {
+                        case INTERFACE_TRANSACTION:
+                        {
+                          reply.writeString(descriptor);
+                          return true;
+                        }
+                      }
+                      switch (code)
+                      {
+                        case TRANSACTION_PermissionProtected:
+                        {
+                          this.PermissionProtected();
+                          reply.writeNoException();
+                          break;
+                        }
+                        case TRANSACTION_MultiplePermissionsAll:
+                        {
+                          this.MultiplePermissionsAll();
+                          reply.writeNoException();
+                          break;
+                        }
+                        case TRANSACTION_MultiplePermissionsAny:
+                        {
+                          this.MultiplePermissionsAny();
+                          reply.writeNoException();
+                          break;
+                        }
+                        case TRANSACTION_NonManifestPermission:
+                        {
+                          this.NonManifestPermission();
+                          reply.writeNoException();
+                          break;
+                        }
+                        case TRANSACTION_SetGranted:
+                        {
+                          java.util.List<java.lang.String> _arg0;
+                          _arg0 = data.createStringArrayList();
+                          data.enforceNoDataAvail();
+                          this.SetGranted(_arg0);
+                          reply.writeNoException();
+                          break;
+                        }
+                        default:
+                        {
+                          return super.onTransact(code, data, reply, flags);
+                        }
+                      }
+                      return true;
+                    }
+                    private static class Proxy implements android.aidl.tests.permission.IProtected
+                    {
+                      private android.os.IBinder mRemote;
+                      Proxy(android.os.IBinder remote)
+                      {
+                        mRemote = remote;
+                      }
+                      @Override public android.os.IBinder asBinder()
+                      {
+                        return mRemote;
+                      }
+                      public java.lang.String getInterfaceDescriptor()
+                      {
+                        return DESCRIPTOR;
+                      }
+                      @Override public void PermissionProtected() throws android.os.RemoteException
+                      {
+                        android.os.Parcel _data = android.os.Parcel.obtain(asBinder());
+                        android.os.Parcel _reply = android.os.Parcel.obtain();
+                        try {
+                          _data.writeInterfaceToken(DESCRIPTOR);
+                          boolean _status = mRemote.transact(Stub.TRANSACTION_PermissionProtected, _data, _reply, 0);
+                          _reply.readException();
+                        }
+                        finally {
+                          _reply.recycle();
+                          _data.recycle();
+                        }
+                      }
+                      @Override public void MultiplePermissionsAll() throws android.os.RemoteException
+                      {
+                        android.os.Parcel _data = android.os.Parcel.obtain(asBinder());
+                        android.os.Parcel _reply = android.os.Parcel.obtain();
+                        try {
+                          _data.writeInterfaceToken(DESCRIPTOR);
+                          boolean _status = mRemote.transact(Stub.TRANSACTION_MultiplePermissionsAll, _data, _reply, 0);
+                          _reply.readException();
+                        }
+                        finally {
+                          _reply.recycle();
+                          _data.recycle();
+                        }
+                      }
+                      @Override public void MultiplePermissionsAny() throws android.os.RemoteException
+                      {
+                        android.os.Parcel _data = android.os.Parcel.obtain(asBinder());
+                        android.os.Parcel _reply = android.os.Parcel.obtain();
+                        try {
+                          _data.writeInterfaceToken(DESCRIPTOR);
+                          boolean _status = mRemote.transact(Stub.TRANSACTION_MultiplePermissionsAny, _data, _reply, 0);
+                          _reply.readException();
+                        }
+                        finally {
+                          _reply.recycle();
+                          _data.recycle();
+                        }
+                      }
+                      @Override public void NonManifestPermission() throws android.os.RemoteException
+                      {
+                        android.os.Parcel _data = android.os.Parcel.obtain(asBinder());
+                        android.os.Parcel _reply = android.os.Parcel.obtain();
+                        try {
+                          _data.writeInterfaceToken(DESCRIPTOR);
+                          boolean _status = mRemote.transact(Stub.TRANSACTION_NonManifestPermission, _data, _reply, 0);
+                          _reply.readException();
+                        }
+                        finally {
+                          _reply.recycle();
+                          _data.recycle();
+                        }
+                      }
+                      // Used by the integration tests to dynamically set permissions that are considered granted.
+                      @Override public void SetGranted(java.util.List<java.lang.String> permissions) throws android.os.RemoteException
+                      {
+                        android.os.Parcel _data = android.os.Parcel.obtain(asBinder());
+                        android.os.Parcel _reply = android.os.Parcel.obtain();
+                        try {
+                          _data.writeInterfaceToken(DESCRIPTOR);
+                          _data.writeStringList(permissions);
+                          boolean _status = mRemote.transact(Stub.TRANSACTION_SetGranted, _data, _reply, 0);
+                          _reply.readException();
+                        }
+                        finally {
+                          _reply.recycle();
+                          _data.recycle();
+                        }
+                      }
+                    }
+                    static final int TRANSACTION_PermissionProtected = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
+                    /** Helper method to enforce permissions for PermissionProtected */
+                    protected void PermissionProtected_enforcePermission() throws SecurityException {
+                      android.content.AttributionSource source = new android.content.AttributionSource(getCallingUid(), null, null);
+                      mEnforcer.enforcePermission(android.Manifest.permission.READ_PHONE_STATE, source);
+                    }
+                    static final int TRANSACTION_MultiplePermissionsAll = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);
+                    /** Helper method to enforce permissions for MultiplePermissionsAll */
+                    protected void MultiplePermissionsAll_enforcePermission() throws SecurityException {
+                      android.content.AttributionSource source = new android.content.AttributionSource(getCallingUid(), null, null);
+                      mEnforcer.enforcePermissionAllOf(new String[]{android.Manifest.permission.INTERNET, android.Manifest.permission.VIBRATE}, source);
+                    }
+                    static final int TRANSACTION_MultiplePermissionsAny = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2);
+                    /** Helper method to enforce permissions for MultiplePermissionsAny */
+                    protected void MultiplePermissionsAny_enforcePermission() throws SecurityException {
+                      android.content.AttributionSource source = new android.content.AttributionSource(getCallingUid(), null, null);
+                      mEnforcer.enforcePermissionAnyOf(new String[]{android.Manifest.permission.INTERNET, android.Manifest.permission.VIBRATE}, source);
+                    }
+                    static final int TRANSACTION_NonManifestPermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 3);
+                    /** Helper method to enforce permissions for NonManifestPermission */
+                    protected void NonManifestPermission_enforcePermission() throws SecurityException {
+                      android.content.AttributionSource source = new android.content.AttributionSource(getCallingUid(), null, null);
+                      mEnforcer.enforcePermission(android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, source);
+                    }
+                    static final int TRANSACTION_SetGranted = (android.os.IBinder.FIRST_CALL_TRANSACTION + 4);
+                    /** @hide */
+                    public int getMaxTransactionId()
+                    {
+                      return 4;
+                    }
+                  }
+                  
+                  @android.annotation.EnforcePermission(android.Manifest.permission.READ_PHONE_STATE)
+                  public void PermissionProtected() throws android.os.RemoteException;
+                  @android.annotation.EnforcePermission(allOf = {android.Manifest.permission.INTERNET, android.Manifest.permission.VIBRATE})
+                  public void MultiplePermissionsAll() throws android.os.RemoteException;
+                  @android.annotation.EnforcePermission(anyOf = {android.Manifest.permission.INTERNET, android.Manifest.permission.VIBRATE})
+                  public void MultiplePermissionsAny() throws android.os.RemoteException;
+                  @android.annotation.EnforcePermission(android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK)
+                  public void NonManifestPermission() throws android.os.RemoteException;
+                  // Used by the integration tests to dynamically set permissions that are considered granted.
+                  @android.annotation.RequiresNoPermission
+                  public void SetGranted(java.util.List<java.lang.String> permissions) throws android.os.RemoteException;
+                }
+                """
+            ).indented(),
+                *stubs
+        )
+            .run()
+            .expectClean()
+    }
+
+    fun test_generated_IProtectedInterface() {
+        lint().files(
+                java(
+                    """
+                    /*
+                     * This file is auto-generated.  DO NOT MODIFY.
+                     */
+                    package android.aidl.tests.permission;
+                    public interface IProtectedInterface extends android.os.IInterface
+                    {
+                      /** Default implementation for IProtectedInterface. */
+                      public static class Default implements android.aidl.tests.permission.IProtectedInterface
+                      {
+                        @Override public void Method1() throws android.os.RemoteException
+                        {
+                        }
+                        @Override public void Method2() throws android.os.RemoteException
+                        {
+                        }
+                        @Override
+                        public android.os.IBinder asBinder() {
+                          return null;
+                        }
+                      }
+                      /** Local-side IPC implementation stub class. */
+                      public static abstract class Stub extends android.os.Binder implements android.aidl.tests.permission.IProtectedInterface
+                      {
+                        private final android.os.PermissionEnforcer mEnforcer;
+                        /** Construct the stub using the Enforcer provided. */
+                        public Stub(android.os.PermissionEnforcer enforcer)
+                        {
+                          this.attachInterface(this, DESCRIPTOR);
+                          if (enforcer == null) {
+                            throw new IllegalArgumentException("enforcer cannot be null");
+                          }
+                          mEnforcer = enforcer;
+                        }
+                        @Deprecated
+                        /** Default constructor. */
+                        public Stub() {
+                          this(android.os.PermissionEnforcer.fromContext(
+                             android.app.ActivityThread.currentActivityThread().getSystemContext()));
+                        }
+                        /**
+                         * Cast an IBinder object into an android.aidl.tests.permission.IProtectedInterface interface,
+                         * generating a proxy if needed.
+                         */
+                        public static android.aidl.tests.permission.IProtectedInterface asInterface(android.os.IBinder obj)
+                        {
+                          if ((obj==null)) {
+                            return null;
+                          }
+                          android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
+                          if (((iin!=null)&&(iin instanceof android.aidl.tests.permission.IProtectedInterface))) {
+                            return ((android.aidl.tests.permission.IProtectedInterface)iin);
+                          }
+                          return new android.aidl.tests.permission.IProtectedInterface.Stub.Proxy(obj);
+                        }
+                        @Override public android.os.IBinder asBinder()
+                        {
+                          return this;
+                        }
+                        /** @hide */
+                        public static java.lang.String getDefaultTransactionName(int transactionCode)
+                        {
+                          switch (transactionCode)
+                          {
+                            case TRANSACTION_Method1:
+                            {
+                              return "Method1";
+                            }
+                            case TRANSACTION_Method2:
+                            {
+                              return "Method2";
+                            }
+                            default:
+                            {
+                              return null;
+                            }
+                          }
+                        }
+                        /** @hide */
+                        public java.lang.String getTransactionName(int transactionCode)
+                        {
+                          return this.getDefaultTransactionName(transactionCode);
+                        }
+                        @Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException
+                        {
+                          java.lang.String descriptor = DESCRIPTOR;
+                          if (code >= android.os.IBinder.FIRST_CALL_TRANSACTION && code <= android.os.IBinder.LAST_CALL_TRANSACTION) {
+                            data.enforceInterface(descriptor);
+                          }
+                          switch (code)
+                          {
+                            case INTERFACE_TRANSACTION:
+                            {
+                              reply.writeString(descriptor);
+                              return true;
+                            }
+                          }
+                          switch (code)
+                          {
+                            case TRANSACTION_Method1:
+                            {
+                              this.Method1();
+                              reply.writeNoException();
+                              break;
+                            }
+                            case TRANSACTION_Method2:
+                            {
+                              this.Method2();
+                              reply.writeNoException();
+                              break;
+                            }
+                            default:
+                            {
+                              return super.onTransact(code, data, reply, flags);
+                            }
+                          }
+                          return true;
+                        }
+                        private static class Proxy implements android.aidl.tests.permission.IProtectedInterface
+                        {
+                          private android.os.IBinder mRemote;
+                          Proxy(android.os.IBinder remote)
+                          {
+                            mRemote = remote;
+                          }
+                          @Override public android.os.IBinder asBinder()
+                          {
+                            return mRemote;
+                          }
+                          public java.lang.String getInterfaceDescriptor()
+                          {
+                            return DESCRIPTOR;
+                          }
+                          @Override public void Method1() throws android.os.RemoteException
+                          {
+                            android.os.Parcel _data = android.os.Parcel.obtain(asBinder());
+                            android.os.Parcel _reply = android.os.Parcel.obtain();
+                            try {
+                              _data.writeInterfaceToken(DESCRIPTOR);
+                              boolean _status = mRemote.transact(Stub.TRANSACTION_Method1, _data, _reply, 0);
+                              _reply.readException();
+                            }
+                            finally {
+                              _reply.recycle();
+                              _data.recycle();
+                            }
+                          }
+                          @Override public void Method2() throws android.os.RemoteException
+                          {
+                            android.os.Parcel _data = android.os.Parcel.obtain(asBinder());
+                            android.os.Parcel _reply = android.os.Parcel.obtain();
+                            try {
+                              _data.writeInterfaceToken(DESCRIPTOR);
+                              boolean _status = mRemote.transact(Stub.TRANSACTION_Method2, _data, _reply, 0);
+                              _reply.readException();
+                            }
+                            finally {
+                              _reply.recycle();
+                              _data.recycle();
+                            }
+                          }
+                        }
+                        static final int TRANSACTION_Method1 = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
+                        /** Helper method to enforce permissions for Method1 */
+                        protected void Method1_enforcePermission() throws SecurityException {
+                          android.content.AttributionSource source = new android.content.AttributionSource(getCallingUid(), null, null);
+                          mEnforcer.enforcePermission(android.Manifest.permission.ACCESS_FINE_LOCATION, source);
+                        }
+                        static final int TRANSACTION_Method2 = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);
+                        /** Helper method to enforce permissions for Method2 */
+                        protected void Method2_enforcePermission() throws SecurityException {
+                          android.content.AttributionSource source = new android.content.AttributionSource(getCallingUid(), null, null);
+                          mEnforcer.enforcePermission(android.Manifest.permission.ACCESS_FINE_LOCATION, source);
+                        }
+                        /** @hide */
+                        public int getMaxTransactionId()
+                        {
+                          return 1;
+                        }
+                      }
+                      
+                      @android.annotation.EnforcePermission(android.Manifest.permission.ACCESS_FINE_LOCATION)
+                      public void Method1() throws android.os.RemoteException;
+                      @android.annotation.EnforcePermission(android.Manifest.permission.ACCESS_FINE_LOCATION)
+                      public void Method2() throws android.os.RemoteException;
+                    }
+                    """
+                ).indented(),
+                *stubs
+        )
+                .run()
+                .expectClean()
+    }
+
+    /* Stubs */
+
+    private val manifestPermissionStub: TestFile = java(
+        """
+        package android.Manifest;
+        class permission {
+          public static final String READ_PHONE_STATE = "android.permission.READ_PHONE_STATE";
+          public static final String INTERNET = "android.permission.INTERNET";
+        }
+        """
+    ).indented()
+
+    private val enforcePermissionAnnotationStub: TestFile = java(
+        """
+        package android.annotation;
+        public @interface EnforcePermission {}
+        """
+    ).indented()
+
+    private val stubs = arrayOf(manifestPermissionStub, enforcePermissionAnnotationStub)
+}
diff --git a/tools/lint/global/checks/src/test/java/com/google/android/lint/aidl/EnforcePermissionHelperDetectorTest.kt b/tools/lint/global/checks/src/test/java/com/google/android/lint/aidl/EnforcePermissionHelperDetectorTest.kt
index 31e4846..4799184 100644
--- a/tools/lint/global/checks/src/test/java/com/google/android/lint/aidl/EnforcePermissionHelperDetectorTest.kt
+++ b/tools/lint/global/checks/src/test/java/com/google/android/lint/aidl/EnforcePermissionHelperDetectorTest.kt
@@ -150,6 +150,31 @@
             .expectClean()
     }
 
+    fun testInterfaceDefaultMethod_wouldStillReport() {
+        lint().files(
+                java(
+                    """
+                    public interface IProtected extends android.os.IInterface {
+                        @android.annotation.EnforcePermission(android.Manifest.permission.READ_PHONE_STATE)
+                        default void PermissionProtected() throws android.os.RemoteException {
+                            String foo = "bar";
+                        }
+                    }
+                    """
+                ).indented(),
+                *stubs
+        )
+                .run()
+                .expect(
+                    """
+                    src/IProtected.java:2: Error: Method must start with super.PermissionProtected_enforcePermission() [MissingEnforcePermissionHelper]
+                        @android.annotation.EnforcePermission(android.Manifest.permission.READ_PHONE_STATE)
+                        ^
+                    1 errors, 0 warnings
+                    """
+                )
+    }
+
     companion object {
         val stubs = arrayOf(aidlStub, contextStub, binderStub)
     }