Skip to content

Commit 5788056

Browse files
neobuddy89joeyhuab
authored andcommitted
base: Add method to restart SystemUI
* Killing com.android.systemui using IActivityManager doesnt work always. * Instead use CommandQueue callback to make SystemUI kill itself. Works! Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
1 parent 11d377a commit 5788056

7 files changed

Lines changed: 67 additions & 0 deletions

File tree

core/java/com/android/internal/statusbar/IStatusBar.aidl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,4 +413,6 @@ oneway interface IStatusBar
413413
* @param displayId the id of the current display.
414414
*/
415415
void moveFocusedTaskToDesktop(int displayId);
416+
417+
void restartSystemUI();
416418
}

core/java/com/android/internal/statusbar/IStatusBarService.aidl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,6 @@ interface IStatusBarService
254254
* Toggle recent apps.
255255
*/
256256
void toggleRecentApps();
257+
258+
void restartSystemUI();
257259
}

core/java/com/android/internal/util/evolution/Utils.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@
3232
import android.content.pm.ResolveInfo;
3333
import android.os.AsyncTask;
3434
import android.os.PowerManager;
35+
import android.os.RemoteException;
36+
import android.os.ServiceManager;
3537
import android.os.SystemClock;
3638
import android.os.SystemProperties;
3739
import android.os.UserHandle;
3840
import android.util.Log;
3941

42+
import com.android.internal.statusbar.IStatusBarService;
4043
import com.android.internal.util.CollectionUtils;
4144

4245
import java.util.ArrayList;
@@ -147,6 +150,15 @@ public static boolean hasNavbarByDefault(Context context) {
147150
return needsNav;
148151
}
149152

153+
public static void restartSystemUI() {
154+
final IStatusBarService mBarService = IStatusBarService.Stub.asInterface(
155+
ServiceManager.getService(Context.STATUS_BAR_SERVICE));
156+
try {
157+
mBarService.restartSystemUI();
158+
} catch (RemoteException e) {
159+
}
160+
}
161+
150162
public static String getDefaultLauncher(Context context) {
151163
final RoleManager roleManager = context.getSystemService(RoleManager.class);
152164
final String packageName = CollectionUtils.firstOrNull(

packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ public class CommandQueue extends IStatusBar.Stub implements
189189
private static final int MSG_WALLET_ACTION_LAUNCH_GESTURE = 83 << MSG_SHIFT;
190190
private static final int MSG_DISPLAY_REMOVE_SYSTEM_DECORATIONS = 85 << MSG_SHIFT;
191191
private static final int MSG_DISABLE_ALL = 86 << MSG_SHIFT;
192+
private static final int MSG_RESTART_SYSTEMUI = 87 << MSG_SHIFT;
192193

193194
public static final int FLAG_EXCLUDE_NONE = 0;
194195
public static final int FLAG_EXCLUDE_SEARCH_PANEL = 1 << 0;
@@ -594,6 +595,8 @@ default void immersiveModeChanged(int rootDisplayAreaId, boolean isImmersiveMode
594595
* @see IStatusBar#moveFocusedTaskToDesktop(int)
595596
*/
596597
default void moveFocusedTaskToDesktop(int displayId) {}
598+
599+
default void restartSystemUI() {}
597600
}
598601

599602
@VisibleForTesting
@@ -1550,6 +1553,13 @@ public void moveFocusedTaskToDesktop(int displayId) {
15501553
mHandler.obtainMessage(MSG_ENTER_DESKTOP, args).sendToTarget();
15511554
}
15521555

1556+
@Override
1557+
public void restartSystemUI() {
1558+
synchronized (mLock) {
1559+
mHandler.removeMessages(MSG_RESTART_SYSTEMUI);
1560+
mHandler.obtainMessage(MSG_RESTART_SYSTEMUI).sendToTarget();
1561+
}
1562+
}
15531563

15541564
private final class H extends Handler {
15551565
private H(Looper l) {
@@ -2094,6 +2104,11 @@ public void handleMessage(Message msg) {
20942104
}
20952105
break;
20962106
}
2107+
case MSG_RESTART_SYSTEMUI:
2108+
for (int i = 0; i < mCallbacks.size(); i++) {
2109+
mCallbacks.get(i).restartSystemUI();
2110+
}
2111+
break;
20972112
}
20982113
}
20992114
}

packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,11 @@ public void onRotationLockStateChanged(boolean rotationLocked, boolean affordanc
807807
}
808808
}
809809

810+
@Override
811+
public void restartSystemUI() {
812+
Process.killProcess(Process.myPid());
813+
}
814+
810815
private void updateHeadsetPlug(Intent intent) {
811816
boolean connected = intent.getIntExtra("state", 0) != 0;
812817
boolean hasMic = intent.getIntExtra("microphone", 0) != 0;

services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,6 @@ void showMediaOutputSwitcher(String targetPackageName, UserHandle targetUserHand
290290

291291
/** Passes through the given shell commands to SystemUI */
292292
void passThroughShellCommand(String[] args, FileDescriptor fd);
293+
294+
void restartSystemUI();
293295
}

services/core/java/com/android/server/statusbar/StatusBarManagerService.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,17 @@ public void removeQsTile(ComponentName tile) {
10271027
public void passThroughShellCommand(String[] args, FileDescriptor fd) {
10281028
StatusBarManagerService.this.passThroughShellCommand(args, fd);
10291029
}
1030+
1031+
@Override
1032+
public void restartSystemUI() {
1033+
IStatusBar bar = mBar;
1034+
if (bar != null) {
1035+
try {
1036+
bar.restartSystemUI();
1037+
} catch (RemoteException e) {
1038+
}
1039+
}
1040+
}
10301041
};
10311042

10321043
private final GlobalActionsProvider mGlobalActionsProvider = new GlobalActionsProvider() {
@@ -1983,6 +1994,24 @@ public void restart() {
19831994
}
19841995
}
19851996

1997+
/**
1998+
* Allows SystemUI restart only
1999+
*/
2000+
@Override
2001+
public void restartSystemUI() {
2002+
enforceStatusBarService();
2003+
enforceValidCallingUser();
2004+
2005+
final long identity = Binder.clearCallingIdentity();
2006+
try {
2007+
mHandler.post(() -> {
2008+
mInternalService.restartSystemUI();
2009+
});
2010+
} finally {
2011+
Binder.restoreCallingIdentity(identity);
2012+
}
2013+
}
2014+
19862015
@Override
19872016
public void onGlobalActionsShown() {
19882017
enforceStatusBarService();

0 commit comments

Comments
 (0)