Merge "Revert "Revert "Migrating all model tests to Instrumentation tests""" into sc-v2-dev

This commit is contained in:
TreeHugger Robot
2021-08-31 10:52:02 +00:00
committed by Android (Google) Code Review
31 changed files with 807 additions and 684 deletions

View File

@@ -58,7 +58,7 @@ import java.util.Set;
* Utility class to cache properties of default display to avoid a system RPC on every call.
*/
@SuppressLint("NewApi")
public class DisplayController implements DisplayListener, ComponentCallbacks {
public class DisplayController implements DisplayListener, ComponentCallbacks, SafeCloseable {
private static final String TAG = "DisplayController";
@@ -82,6 +82,7 @@ public class DisplayController implements DisplayListener, ComponentCallbacks {
private final ArrayList<DisplayInfoChangeListener> mListeners = new ArrayList<>();
private Info mInfo;
private boolean mDestroyed = false;
private DisplayController(Context context) {
mContext = context;
@@ -118,6 +119,17 @@ public class DisplayController implements DisplayListener, ComponentCallbacks {
return internalDisplays;
}
@Override
public void close() {
mDestroyed = true;
if (mWindowContext != null) {
mWindowContext.unregisterComponentCallbacks(this);
} else {
// TODO: unregister broadcast receiver
}
mDM.unregisterDisplayListener(this);
}
@Override
public final void onDisplayAdded(int displayId) { }
@@ -165,6 +177,9 @@ public class DisplayController implements DisplayListener, ComponentCallbacks {
* Only used for pre-S
*/
private void onConfigChanged(Intent intent) {
if (mDestroyed) {
return;
}
Configuration config = mContext.getResources().getConfiguration();
if (mInfo.fontScale != config.fontScale || mInfo.densityDpi != config.densityDpi) {
Log.d(TAG, "Configuration changed, notifying listeners");