Skip to content

Commit

Permalink
Hold "volume up" during boot to disable all overlays
Browse files Browse the repository at this point in the history
Following the way "safe mode" was coded, you can now long press
"volume up" during boot to automatically disable all overlays
(from the current system/owner user).

This should come in handy as a global "reset" mechanism.

Example output:
03-12 03:22:07.090   678   678 D TEST    : Disabling overlay android.GalaxyEvolution
03-12 03:22:07.176   678   678 D TEST    : Disabling overlay com.android.launcher3.GalaxyEvolution
03-12 03:22:07.267   678   678 D TEST    : Disabling overlay com.android.server.telecom.GalaxyEvolution

Caveats:
SystemServer seems to have already loaded a context based on the
overlays by the time "disableOverlays" is finished, so SystemUI
turns up themed, even if the overlay is correctly disabled.

In the case of a user using this reset mode to "fix" a SystemUI FC,
this means that the user will experience one more FC after boot
(which then would trigger a SystemUI restart, loading the default
theme this time, and thus ending the FC loop).

Change-Id: I64fb769ea175d37a90a0804f916926b63e5b93ca
Signed-off-by: Harsh Shandilya <harsh@prjkt.io>
Signed-off-by: VenkatVishalV <venkatvishal124@gmail.com>
  • Loading branch information
KreAch3R authored and VenkatVishalV committed Nov 10, 2018
1 parent f9e2693 commit 0689655
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@
import android.content.IIntentSender;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.om.IOverlayManager;
import android.content.om.OverlayInfo;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.ApplicationInfo.HiddenApiEnforcementPolicy;
Expand Down Expand Up @@ -14782,6 +14784,34 @@ public final void showSafeModeOverlay() {
Context.WINDOW_SERVICE)).addView(v, lp);
}

public final void disableOverlays() {
try {
IOverlayManager iom = IOverlayManager.Stub.asInterface(
ServiceManager.getService("overlay"));
if (iom == null) {
return;
}
Log.d(TAG, "Contacting the Overlay Manager Service for the list of enabled overlays");
Map<String, List<OverlayInfo>> allOverlays = iom.getAllOverlays(UserHandle.USER_SYSTEM);
if (allOverlays != null) {
Log.d(TAG, "The Overlay Manager Service provided the list of enabled overlays");
Set<String> set = allOverlays.keySet();
for (String targetPackageName : set) {
for (OverlayInfo oi : allOverlays.get(targetPackageName)) {
if (oi.isEnabled()) {
iom.setEnabled(oi.packageName, false, UserHandle.USER_SYSTEM);
Log.d(TAG, "Now disabling \'" + oi.packageName + "\'");
}
}
}
}
} catch (RemoteException re) {
re.printStackTrace();
Log.d(TAG, "RemoteException while trying to contact the Overlay Manager Service!");
}
}


@Override
public void noteWakeupAlarm(IIntentSender sender, WorkSource workSource, int sourceUid,
String sourcePkg, String tag) {
Expand Down
22 changes: 22 additions & 0 deletions services/core/java/com/android/server/wm/WindowManagerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ public void dump(FileDescriptor fd, PrintWriter pw, String[] args, boolean asPro

boolean mDisplayReady;
boolean mSafeMode;
boolean mDisableOverlays;
boolean mDisplayEnabled = false;
boolean mSystemBooted = false;
boolean mForceDisplayEnabled = false;
Expand Down Expand Up @@ -4548,6 +4549,27 @@ public boolean detectSafeMode() {
return mSafeMode;
}

public boolean detectDisableOverlays() {
if (!mInputMonitor.waitForInputDevicesReady(
INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
Slog.w(TAG_WM, "Devices still not ready after waiting "
+ INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
+ " milliseconds before attempting to detect safe mode.");
}

int volumeUpState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY,
KeyEvent.KEYCODE_VOLUME_UP);
mDisableOverlays = volumeUpState > 0;

if (mDisableOverlays) {
Log.i(TAG_WM, "All enabled theme overlays will now be disabled.");
} else {
Log.i(TAG_WM, "System will boot with enabled overlays intact.");
}

return mDisableOverlays;
}

public void displayReady() {
final int displayCount = mRoot.mChildren.size();
for (int i = 0; i < displayCount; ++i) {
Expand Down
6 changes: 6 additions & 0 deletions services/java/com/android/server/SystemServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,12 @@ private void startOtherServices() {
mActivityManagerService.showSafeModeOverlay();
}

// Let's check whether we should disable all theme overlays
final boolean disableOverlays = wm.detectDisableOverlays();
if (disableOverlays) {
mActivityManagerService.disableOverlays();
}

// Update the configuration for this context by hand, because we're going
// to start using it before the config change done in wm.systemReady() will
// propagate to it.
Expand Down

0 comments on commit 0689655

Please sign in to comment.