Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ab31819 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add a setting for allowing overlays on Settings app" into rvc-dev

parents 55b78901 f6841ef5
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -12094,4 +12094,9 @@
    <!-- Developer settings: app freezer title [CHAR LIMIT=50]-->
    <string name="cached_apps_freezer">Suspend execution for cached apps</string>
    <!-- Title for allowing screen overlays on Settings app. [CHAR LIMIT=50]-->
    <string name="overlay_settings_title">Allow screen overlays on Settings</string>
    <!-- Summary for allowing screen overlays on Settings app. [CHAR LIMIT=NONE]-->
    <string name="overlay_settings_summary">Allow apps that can display over other apps to overlay Settings screens</string>
</resources>
+5 −0
Original line number Diff line number Diff line
@@ -251,6 +251,11 @@
            android:title="@string/show_refresh_rate"
            android:summary="@string/show_refresh_rate_summary" />

        <SwitchPreference
            android:key="overlay_settings"
            android:title="@string/overlay_settings_title"
            android:summary="@string/overlay_settings_summary" />

    </PreferenceCategory>

    <PreferenceCategory
+3 −2
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import static androidx.lifecycle.Lifecycle.Event.ON_START;
import static androidx.lifecycle.Lifecycle.Event.ON_STOP;

import android.app.Activity;
import android.os.Build;
import android.view.Window;
import android.view.WindowManager;

@@ -30,6 +29,8 @@ import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;

import com.android.settings.development.OverlaySettingsPreferenceController;


/**
 * A mixin that adds window flag to prevent non-system overlays showing on top of Settings
@@ -45,7 +46,7 @@ public class HideNonSystemOverlayMixin implements LifecycleObserver {

    @VisibleForTesting
    boolean isEnabled() {
        return !Build.IS_DEBUGGABLE;
        return !OverlaySettingsPreferenceController.isOverlaySettingsEnabled(mActivity);
    }

    @OnLifecycleEvent(ON_START)
+1 −0
Original line number Diff line number Diff line
@@ -539,6 +539,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
        controllers.add(new BluetoothHDAudioPreferenceController(context, lifecycle,
                bluetoothA2dpConfigStore, fragment));
        controllers.add(new SharedDataPreferenceController(context));
        controllers.add(new OverlaySettingsPreferenceController(context));

        return controllers;
    }
+88 −0
Original line number Diff line number Diff line
/*
 * 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.settings.development;

import android.content.Context;
import android.content.SharedPreferences;

import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;

import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;

/**
 * A controller helps enable or disable a developer setting which allows non system overlays on
 * Settings app.
 */
public class OverlaySettingsPreferenceController extends DeveloperOptionsPreferenceController
        implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {

    public static final String SHARE_PERFS = "overlay_settings";
    private static final String KEY_OVERLAY_SETTINGS = "overlay_settings";

    public OverlaySettingsPreferenceController(Context context) {
        super(context);
    }

    @Override
    public boolean isAvailable() {
        return true;
    }

    @Override
    public String getPreferenceKey() {
        return KEY_OVERLAY_SETTINGS;
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        setOverlaySettingsEnabled(mContext, (Boolean) newValue);
        return true;
    }

    @Override
    public void updateState(Preference preference) {
        ((SwitchPreference) preference).setChecked(isOverlaySettingsEnabled(mContext));
    }

    /**
     * Check if this setting is enabled or not.
     */
    public static boolean isOverlaySettingsEnabled(Context context) {
        final SharedPreferences editor = context.getSharedPreferences(SHARE_PERFS,
                Context.MODE_PRIVATE);
        return editor.getBoolean(SHARE_PERFS, false /* defValue */);
    }

    /**
     * Enable this setting.
     */
    @VisibleForTesting
    static void setOverlaySettingsEnabled(Context context, boolean enabled) {
        final SharedPreferences editor = context.getSharedPreferences(SHARE_PERFS,
                Context.MODE_PRIVATE);
        editor.edit().putBoolean(SHARE_PERFS, enabled).apply();
    }

    @Override
    protected void onDeveloperOptionsSwitchDisabled() {
        super.onDeveloperOptionsSwitchDisabled();
        setOverlaySettingsEnabled(mContext, false);
    }
}
Loading