SetupWizard: Fix status bar managing workflow
StatusBarManager uses tokens in binder connections to identify disable records and queue each of them accordingly. New record creates each time an application connects to StatusBarManager and tries to change the state. New records don't activate until previous ones are destroyed. Records can be destroyed either when app binder dies, or when the same binder ticket reverts its previous changes. To accomodate this behavior, StatusBarManager was moved to a static class that initializes first when status bar gets disabled, and then gets destroyed when status bar is re-enabled. While we're at it, also fix race condition between main and exit activites by moving status bar disabling code to the application class. Change-Id: I3b33e628da1e1881181cbe665e6aaccee3dd19ef
This commit is contained in:
committed by
Timi Rautamäki
parent
44fb45c421
commit
fbf886e808
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2013 The CyanogenMod Project
|
||||
* Copyright (C) 2017 The LineageOS Project
|
||||
* Copyright (C) 2017-2021 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,9 +17,6 @@
|
||||
|
||||
package org.lineageos.setupwizard.util;
|
||||
|
||||
import static android.app.StatusBarManager.DISABLE_NONE;
|
||||
import static android.app.StatusBarManager.DISABLE_NOTIFICATION_ALERTS;
|
||||
import static android.app.StatusBarManager.DISABLE_SEARCH;
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
|
||||
import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
|
||||
@@ -166,24 +163,34 @@ public class SetupWizardUtils {
|
||||
Settings.Global.putInt(context.getContentResolver(), KEY_DETECT_CAPTIVE_PORTAL, 1);
|
||||
}
|
||||
|
||||
public static void disableStatusBar(Context context) {
|
||||
public static StatusBarManager disableStatusBar(Context context) {
|
||||
StatusBarManager statusBarManager = context.getSystemService(StatusBarManager.class);
|
||||
if (statusBarManager != null) {
|
||||
statusBarManager.disable(DISABLE_NOTIFICATION_ALERTS | DISABLE_SEARCH
|
||||
);
|
||||
if (LOGV) {
|
||||
Log.v(SetupWizardApp.TAG, "Disabling status bar");
|
||||
}
|
||||
statusBarManager.setDisabledForSetup(true);
|
||||
} else {
|
||||
Log.w(SetupWizardApp.TAG,
|
||||
"Skip disabling notfications - could not get StatusBarManager");
|
||||
"Skip disabling status bar - could not get StatusBarManager");
|
||||
}
|
||||
return statusBarManager;
|
||||
}
|
||||
|
||||
public static void enableStatusBar(Context context) {
|
||||
StatusBarManager statusBarManager = context.getSystemService(StatusBarManager.class);
|
||||
if(statusBarManager != null) {
|
||||
Log.i(SetupWizardApp.TAG, "Enabling notfications - StatusBarManager");
|
||||
statusBarManager.disable(DISABLE_NONE);
|
||||
final SetupWizardApp setupWizardApp = (SetupWizardApp)context.getApplicationContext();
|
||||
StatusBarManager statusBarManager = setupWizardApp.getStatusBarManager();
|
||||
if (statusBarManager != null) {
|
||||
if (LOGV) {
|
||||
Log.v(SetupWizardApp.TAG, "Enabling status bar");
|
||||
}
|
||||
statusBarManager.setDisabledForSetup(false);
|
||||
|
||||
// Session must be destroyed if it's not used anymore
|
||||
statusBarManager = null;
|
||||
} else {
|
||||
Log.i(SetupWizardApp.TAG, "Skip enabling notfications - StatusBarManager is null");
|
||||
Log.w(SetupWizardApp.TAG,
|
||||
"Skip enabling status bar - could not get StatusBarManager");
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user