Fix unprotected StatusBarManagerService calls
Some Binder calls in StatusBarManagerService were
left unprotected. They had no business being binder
calls in the first place, so they got moved to
StatusBarManagerInternal.
Bug: 28222649
Change-Id: Ib26dcca413eb642ba8cd6a4482bf13071f8bd3ab
diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
index d900b37..2b29c6b 100644
--- a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
+++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
@@ -60,7 +60,6 @@
import android.os.Process;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
-import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserManager;
@@ -92,7 +91,6 @@
import com.android.internal.R;
import com.android.internal.content.PackageMonitor;
import com.android.internal.os.SomeArgs;
-import com.android.internal.statusbar.IStatusBarService;
import com.android.server.LocalServices;
import com.android.server.statusbar.StatusBarManagerInternal;
@@ -3315,13 +3313,9 @@
private void openRecents() {
final long token = Binder.clearCallingIdentity();
- IStatusBarService statusBarService = IStatusBarService.Stub.asInterface(
- ServiceManager.getService("statusbar"));
- try {
- statusBarService.toggleRecentApps();
- } catch (RemoteException e) {
- Slog.e(LOG_TAG, "Error toggling recent apps.");
- }
+ StatusBarManagerInternal statusBarService = LocalServices.getService(
+ StatusBarManagerInternal.class);
+ statusBarService.toggleRecentApps();
Binder.restoreCallingIdentity(token);
}
diff --git a/services/core/java/com/android/server/policy/BarController.java b/services/core/java/com/android/server/policy/BarController.java
index 0c80ffa..5878709 100644
--- a/services/core/java/com/android/server/policy/BarController.java
+++ b/services/core/java/com/android/server/policy/BarController.java
@@ -18,15 +18,14 @@
import android.app.StatusBarManager;
import android.os.Handler;
-import android.os.RemoteException;
-import android.os.ServiceManager;
import android.os.SystemClock;
import android.util.Slog;
import android.view.View;
import android.view.WindowManager;
import android.view.WindowManagerPolicy.WindowState;
-import com.android.internal.statusbar.IStatusBarService;
+import com.android.server.LocalServices;
+import com.android.server.statusbar.StatusBarManagerInternal;
import java.io.PrintWriter;
@@ -52,7 +51,7 @@
private final int mTranslucentWmFlag;
protected final Handler mHandler;
private final Object mServiceAquireLock = new Object();
- protected IStatusBarService mStatusBarService;
+ protected StatusBarManagerInternal mStatusBarInternal;
private WindowState mWin;
private int mState = StatusBarManager.WINDOW_STATE_SHOWING;
@@ -182,15 +181,9 @@
mHandler.post(new Runnable() {
@Override
public void run() {
- try {
- IStatusBarService statusbar = getStatusBarService();
- if (statusbar != null) {
- statusbar.setWindowState(mStatusBarManagerId, state);
- }
- } catch (RemoteException e) {
- if (DEBUG) Slog.w(mTag, "Error posting window state", e);
- // re-acquire status bar service next time it is needed.
- mStatusBarService = null;
+ StatusBarManagerInternal statusbar = getStatusBarInternal();
+ if (statusbar != null) {
+ statusbar.setWindowState(mStatusBarManagerId, state);
}
}
});
@@ -276,13 +269,12 @@
}
}
- protected IStatusBarService getStatusBarService() {
+ protected StatusBarManagerInternal getStatusBarInternal() {
synchronized (mServiceAquireLock) {
- if (mStatusBarService == null) {
- mStatusBarService = IStatusBarService.Stub.asInterface(
- ServiceManager.getService("statusbar"));
+ if (mStatusBarInternal == null) {
+ mStatusBarInternal = LocalServices.getService(StatusBarManagerInternal.class);
}
- return mStatusBarService;
+ return mStatusBarInternal;
}
}
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
index d1f1ffa..8da1e71 100644
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -1465,14 +1465,12 @@
private void requestTvPictureInPictureInternal() {
try {
- IStatusBarService statusbar = getStatusBarService();
+ StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
if (statusbar != null) {
statusbar.requestTvPictureInPicture();
}
- } catch (RemoteException|IllegalArgumentException e) {
+ } catch (IllegalArgumentException e) {
Slog.e(TAG, "Cannot handle picture-in-picture key", e);
- // re-acquire status bar service next time it is needed.
- mStatusBarService = null;
}
}
@@ -3544,21 +3542,15 @@
((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
.launchLegacyAssist(hint, UserHandle.myUserId(), args);
} else {
- try {
- if (hint != null) {
- if (args == null) {
- args = new Bundle();
- }
- args.putBoolean(hint, true);
+ if (hint != null) {
+ if (args == null) {
+ args = new Bundle();
}
- IStatusBarService statusbar = getStatusBarService();
- if (statusbar != null) {
- statusbar.startAssist(args);
- }
- } catch (RemoteException e) {
- Slog.e(TAG, "RemoteException when starting assist", e);
- // re-acquire status bar service next time it is needed.
- mStatusBarService = null;
+ args.putBoolean(hint, true);
+ }
+ StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
+ if (statusbar != null) {
+ statusbar.startAssist(args);
}
}
}
@@ -3580,45 +3572,27 @@
private void preloadRecentApps() {
mPreloadedRecentApps = true;
- try {
- IStatusBarService statusbar = getStatusBarService();
- if (statusbar != null) {
- statusbar.preloadRecentApps();
- }
- } catch (RemoteException e) {
- Slog.e(TAG, "RemoteException when preloading recent apps", e);
- // re-acquire status bar service next time it is needed.
- mStatusBarService = null;
+ StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
+ if (statusbar != null) {
+ statusbar.preloadRecentApps();
}
}
private void cancelPreloadRecentApps() {
if (mPreloadedRecentApps) {
mPreloadedRecentApps = false;
- try {
- IStatusBarService statusbar = getStatusBarService();
- if (statusbar != null) {
- statusbar.cancelPreloadRecentApps();
- }
- } catch (RemoteException e) {
- Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
- // re-acquire status bar service next time it is needed.
- mStatusBarService = null;
+ StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
+ if (statusbar != null) {
+ statusbar.cancelPreloadRecentApps();
}
}
}
private void toggleRecentApps() {
mPreloadedRecentApps = false; // preloading no longer needs to be canceled
- try {
- IStatusBarService statusbar = getStatusBarService();
- if (statusbar != null) {
- statusbar.toggleRecentApps();
- }
- } catch (RemoteException e) {
- Slog.e(TAG, "RemoteException when toggling recent apps", e);
- // re-acquire status bar service next time it is needed.
- mStatusBarService = null;
+ StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
+ if (statusbar != null) {
+ statusbar.toggleRecentApps();
}
}
@@ -3630,40 +3604,24 @@
private void showRecentApps(boolean triggeredFromAltTab, boolean fromHome) {
mPreloadedRecentApps = false; // preloading no longer needs to be canceled
- try {
- IStatusBarService statusbar = getStatusBarService();
- if (statusbar != null) {
- statusbar.showRecentApps(triggeredFromAltTab, fromHome);
- }
- } catch (RemoteException e) {
- Slog.e(TAG, "RemoteException when showing recent apps", e);
- // re-acquire status bar service next time it is needed.
- mStatusBarService = null;
+ StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
+ if (statusbar != null) {
+ statusbar.showRecentApps(triggeredFromAltTab, fromHome);
}
}
private void toggleKeyboardShortcutsMenu(int deviceId) {
- try {
- IStatusBarService statusbar = getStatusBarService();
- if (statusbar != null) {
- statusbar.toggleKeyboardShortcutsMenu(deviceId);
- }
- } catch (RemoteException e) {
- Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
+ StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
+ if (statusbar != null) {
+ statusbar.toggleKeyboardShortcutsMenu(deviceId);
}
}
private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
mPreloadedRecentApps = false; // preloading no longer needs to be canceled
- try {
- IStatusBarService statusbar = getStatusBarService();
- if (statusbar != null) {
- statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
- }
- } catch (RemoteException e) {
- Slog.e(TAG, "RemoteException when closing recent apps", e);
- // re-acquire status bar service next time it is needed.
- mStatusBarService = null;
+ StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
+ if (statusbar != null) {
+ statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
}
}
@@ -7465,13 +7423,9 @@
if (mKeyguardDelegate != null) {
mKeyguardDelegate.setCurrentUser(newUserId);
}
- IStatusBarService statusBar = getStatusBarService();
+ StatusBarManagerInternal statusBar = getStatusBarManagerInternal();
if (statusBar != null) {
- try {
- statusBar.setCurrentUser(newUserId);
- } catch (RemoteException e) {
- // oh well
- }
+ statusBar.setCurrentUser(newUserId);
}
setLastInputMethodWindowLw(null, null);
}
diff --git a/services/core/java/com/android/server/policy/StatusBarController.java b/services/core/java/com/android/server/policy/StatusBarController.java
index 86d0468..245518c 100644
--- a/services/core/java/com/android/server/policy/StatusBarController.java
+++ b/services/core/java/com/android/server/policy/StatusBarController.java
@@ -18,9 +18,7 @@
import android.app.StatusBarManager;
import android.os.IBinder;
-import android.os.RemoteException;
import android.os.SystemClock;
-import android.util.Slog;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.Animation;
@@ -28,7 +26,6 @@
import android.view.animation.Interpolator;
import android.view.animation.TranslateAnimation;
-import com.android.internal.statusbar.IStatusBarService;
import com.android.server.LocalServices;
import com.android.server.statusbar.StatusBarManagerInternal;
@@ -49,15 +46,9 @@
mHandler.post(new Runnable() {
@Override
public void run() {
- try {
- IStatusBarService statusbar = getStatusBarService();
- if (statusbar != null) {
- statusbar.appTransitionPending();
- }
- } catch (RemoteException e) {
- Slog.e(mTag, "RemoteException when app transition is pending", e);
- // re-acquire status bar service next time it is needed.
- mStatusBarService = null;
+ StatusBarManagerInternal statusbar = getStatusBarInternal();
+ if (statusbar != null) {
+ statusbar.appTransitionPending();
}
}
});
@@ -69,19 +60,13 @@
mHandler.post(new Runnable() {
@Override
public void run() {
- try {
- IStatusBarService statusbar = getStatusBarService();
- if (statusbar != null) {
- long startTime = calculateStatusBarTransitionStartTime(openAnimation,
- closeAnimation);
- long duration = closeAnimation != null || openAnimation != null
- ? TRANSITION_DURATION : 0;
- statusbar.appTransitionStarting(startTime, duration);
- }
- } catch (RemoteException e) {
- Slog.e(mTag, "RemoteException when app transition is starting", e);
- // re-acquire status bar service next time it is needed.
- mStatusBarService = null;
+ StatusBarManagerInternal statusbar = getStatusBarInternal();
+ if (statusbar != null) {
+ long startTime = calculateStatusBarTransitionStartTime(openAnimation,
+ closeAnimation);
+ long duration = closeAnimation != null || openAnimation != null
+ ? TRANSITION_DURATION : 0;
+ statusbar.appTransitionStarting(startTime, duration);
}
}
});
@@ -92,15 +77,9 @@
mHandler.post(new Runnable() {
@Override
public void run() {
- try {
- IStatusBarService statusbar = getStatusBarService();
- if (statusbar != null) {
- statusbar.appTransitionCancelled();
- }
- } catch (RemoteException e) {
- Slog.e(mTag, "RemoteException when app transition is cancelled", e);
- // re-acquire status bar service next time it is needed.
- mStatusBarService = null;
+ StatusBarManagerInternal statusbar = getStatusBarInternal();
+ if (statusbar != null) {
+ statusbar.appTransitionCancelled();
}
}
});
diff --git a/services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java b/services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java
index 95923fe..38a3d01 100644
--- a/services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java
+++ b/services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java
@@ -28,6 +28,50 @@
void notificationLightOff();
void showScreenPinningRequest(int taskId);
void showAssistDisclosure();
+
+ void preloadRecentApps();
+
+ void cancelPreloadRecentApps();
+
+ void showRecentApps(boolean triggeredFromAltTab, boolean fromHome);
+
+ void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey);
+
+ void toggleKeyboardShortcutsMenu(int deviceId);
+
+ /**
+ * Request picture-in-picture.
+ *
+ * <p>
+ * This is called when an user presses picture-in-picture key or equivalent.
+ * TV device may start picture-in-picture from foreground activity if there's none.
+ * Picture-in-picture overlay menu will be shown instead otherwise.
+ */
+ void requestTvPictureInPicture();
+
+ void setWindowState(int window, int state);
+
+ /**
+ * Notifies the status bar that an app transition is pending to delay applying some flags with
+ * visual impact until {@link #appTransitionReady} is called.
+ */
+ void appTransitionPending();
+
+ /**
+ * Notifies the status bar that a pending app transition has been cancelled.
+ */
+ void appTransitionCancelled();
+
+ /**
+ * Notifies the status bar that an app transition is now being executed.
+ *
+ * @param statusBarAnimationsStartTime the desired start time for all visual animations in the
+ * status bar caused by this app transition in uptime millis
+ * @param statusBarAnimationsDuration the duration for all visual animations in the status
+ * bar caused by this app transition in millis
+ */
+ void appTransitionStarting(long statusBarAnimationsStartTime, long statusBarAnimationsDuration);
+
void startAssist(Bundle args);
void onCameraLaunchGestureDetected(int source);
void topAppWindowChanged(boolean menuVisible);
@@ -35,4 +79,8 @@
Rect fullscreenBounds, Rect dockedBounds, String cause);
void toggleSplitScreen();
void appTransitionFinished();
+
+ void toggleRecentApps();
+
+ void setCurrentUser(int newUserId);
}
diff --git a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
index 981b75a..9020677 100644
--- a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
+++ b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
@@ -223,6 +223,114 @@
} catch (RemoteException ex) {}
}
}
+
+ @Override
+ public void toggleRecentApps() {
+ if (mBar != null) {
+ try {
+ mBar.toggleRecentApps();
+ } catch (RemoteException ex) {}
+ }
+ }
+
+ @Override
+ public void setCurrentUser(int newUserId) {
+ if (SPEW) Slog.d(TAG, "Setting current user to user " + newUserId);
+ mCurrentUserId = newUserId;
+ }
+
+
+ @Override
+ public void preloadRecentApps() {
+ if (mBar != null) {
+ try {
+ mBar.preloadRecentApps();
+ } catch (RemoteException ex) {}
+ }
+ }
+
+ @Override
+ public void cancelPreloadRecentApps() {
+ if (mBar != null) {
+ try {
+ mBar.cancelPreloadRecentApps();
+ } catch (RemoteException ex) {}
+ }
+ }
+
+ @Override
+ public void showRecentApps(boolean triggeredFromAltTab, boolean fromHome) {
+ if (mBar != null) {
+ try {
+ mBar.showRecentApps(triggeredFromAltTab, fromHome);
+ } catch (RemoteException ex) {}
+ }
+ }
+
+ @Override
+ public void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {
+ if (mBar != null) {
+ try {
+ mBar.hideRecentApps(triggeredFromAltTab, triggeredFromHomeKey);
+ } catch (RemoteException ex) {}
+ }
+ }
+
+ @Override
+ public void toggleKeyboardShortcutsMenu(int deviceId) {
+ if (mBar != null) {
+ try {
+ mBar.toggleKeyboardShortcutsMenu(deviceId);
+ } catch (RemoteException ex) {}
+ }
+ }
+
+ @Override
+ public void requestTvPictureInPicture() {
+ if (mBar != null) {
+ try {
+ mBar.requestTvPictureInPicture();
+ } catch (RemoteException ex) {}
+ }
+ }
+
+ @Override
+ public void setWindowState(int window, int state) {
+ if (mBar != null) {
+ try {
+ mBar.setWindowState(window, state);
+ } catch (RemoteException ex) {}
+ }
+ }
+
+ @Override
+ public void appTransitionPending() {
+ if (mBar != null) {
+ try {
+ mBar.appTransitionPending();
+ } catch (RemoteException ex) {}
+ }
+ }
+
+ @Override
+ public void appTransitionCancelled() {
+ if (mBar != null) {
+ try {
+ mBar.appTransitionCancelled();
+ } catch (RemoteException ex) {}
+ }
+ }
+
+ @Override
+ public void appTransitionStarting(long statusBarAnimationsStartTime,
+ long statusBarAnimationsDuration) {
+ if (mBar != null) {
+ try {
+ mBar.appTransitionStarting(
+ statusBarAnimationsStartTime, statusBarAnimationsDuration);
+ } catch (RemoteException ex) {}
+ }
+ }
};
// ================================================================================
@@ -527,122 +635,6 @@
}
}
- @Override
- public void toggleRecentApps() {
- if (mBar != null) {
- try {
- mBar.toggleRecentApps();
- } catch (RemoteException ex) {}
- }
- }
-
- @Override
- public void preloadRecentApps() {
- if (mBar != null) {
- try {
- mBar.preloadRecentApps();
- } catch (RemoteException ex) {}
- }
- }
-
- @Override
- public void cancelPreloadRecentApps() {
- if (mBar != null) {
- try {
- mBar.cancelPreloadRecentApps();
- } catch (RemoteException ex) {}
- }
- }
-
- @Override
- public void showRecentApps(boolean triggeredFromAltTab, boolean fromHome) {
- if (mBar != null) {
- try {
- mBar.showRecentApps(triggeredFromAltTab, fromHome);
- } catch (RemoteException ex) {}
- }
- }
-
- @Override
- public void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {
- if (mBar != null) {
- try {
- mBar.hideRecentApps(triggeredFromAltTab, triggeredFromHomeKey);
- } catch (RemoteException ex) {}
- }
- }
-
- @Override
- public void toggleKeyboardShortcutsMenu(int deviceId) {
- if (mBar != null) {
- try {
- mBar.toggleKeyboardShortcutsMenu(deviceId);
- } catch (RemoteException ex) {}
- }
- }
-
- @Override
- public void requestTvPictureInPicture() {
- if (mBar != null) {
- try {
- mBar.requestTvPictureInPicture();
- } catch (RemoteException ex) {}
- }
- }
-
- @Override
- public void setCurrentUser(int newUserId) {
- if (SPEW) Slog.d(TAG, "Setting current user to user " + newUserId);
- mCurrentUserId = newUserId;
- }
-
- @Override
- public void setWindowState(int window, int state) {
- if (mBar != null) {
- try {
- mBar.setWindowState(window, state);
- } catch (RemoteException ex) {}
- }
- }
-
- @Override
- public void appTransitionPending() {
- if (mBar != null) {
- try {
- mBar.appTransitionPending();
- } catch (RemoteException ex) {}
- }
- }
-
- @Override
- public void appTransitionCancelled() {
- if (mBar != null) {
- try {
- mBar.appTransitionCancelled();
- } catch (RemoteException ex) {}
- }
- }
-
- @Override
- public void appTransitionStarting(long statusBarAnimationsStartTime,
- long statusBarAnimationsDuration) {
- if (mBar != null) {
- try {
- mBar.appTransitionStarting(
- statusBarAnimationsStartTime, statusBarAnimationsDuration);
- } catch (RemoteException ex) {}
- }
- }
-
- @Override
- public void startAssist(Bundle args) {
- if (mBar != null) {
- try {
- mBar.startAssist(args);
- } catch (RemoteException ex) {}
- }
- }
-
private void enforceStatusBarOrShell() {
if (Binder.getCallingUid() == Process.SHELL_UID) {
return;