Disable draw overlay for most of Settings.

Fixes: 120484087
Test: robotests
Change-Id: I1f7c8e83bd5054525bde5ca35fac55b7c9586c7c
This commit is contained in:
Fan Zhang
2019-03-14 15:45:22 -07:00
parent 9f5e7b77ff
commit 9d98344122
5 changed files with 148 additions and 55 deletions

View File

@@ -0,0 +1,64 @@
/*
* 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.settings.core;
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
import static androidx.lifecycle.Lifecycle.Event.ON_START;
import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
import android.app.Activity;
import android.view.Window;
import android.view.WindowManager;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
/**
* A mixin that adds window flag to prevent non-system overlays showing on top of Settings
* activities.
*/
public class HideNonSystemOverlayMixin implements LifecycleObserver {
private final Activity mActivity;
public HideNonSystemOverlayMixin(Activity activity) {
mActivity = activity;
}
@OnLifecycleEvent(ON_START)
public void onStart() {
if (mActivity == null) {
return;
}
mActivity.getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
android.util.EventLog.writeEvent(0x534e4554, "120484087", -1, "");
}
@OnLifecycleEvent(ON_STOP)
public void onStop() {
if (mActivity == null) {
return;
}
final Window window = mActivity.getWindow();
final WindowManager.LayoutParams attrs = window.getAttributes();
attrs.privateFlags &= ~SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
window.setAttributes(attrs);
}
}

View File

@@ -32,7 +32,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.Toolbar;
import androidx.fragment.app.FragmentActivity;
@@ -59,8 +58,8 @@ public class SettingsBaseActivity extends FragmentActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final long startTime = System.currentTimeMillis();
getLifecycle().addObserver(new HideNonSystemOverlayMixin(this));
final TypedArray theme = getTheme().obtainStyledAttributes(android.R.styleable.Theme);
if (!theme.getBoolean(android.R.styleable.Theme_windowNoTitle, false)) {