Merge "Fix unprotected StatusBarManagerService calls" into nyc-dev

This commit is contained in:
Adrian Roos
2016-04-19 22:05:42 +00:00
committed by Android (Google) Code Review
7 changed files with 212 additions and 296 deletions

View File

@@ -41,7 +41,6 @@ interface IStatusBarService
void setImeWindowStatus(in IBinder token, int vis, int backDisposition, void setImeWindowStatus(in IBinder token, int vis, int backDisposition,
boolean showImeSwitcher); boolean showImeSwitcher);
void expandSettingsPanel(String subPanel); void expandSettingsPanel(String subPanel);
void setCurrentUser(int newUserId);
// ---- Methods below are for use by the status bar policy services ---- // ---- Methods below are for use by the status bar policy services ----
// You need the STATUS_BAR_SERVICE permission // You need the STATUS_BAR_SERVICE permission
@@ -63,48 +62,6 @@ interface IStatusBarService
in NotificationVisibility[] noLongerVisibleKeys); in NotificationVisibility[] noLongerVisibleKeys);
void onNotificationExpansionChanged(in String key, in boolean userAction, in boolean expanded); void onNotificationExpansionChanged(in String key, in boolean userAction, in boolean expanded);
void setSystemUiVisibility(int vis, int mask, String cause); void setSystemUiVisibility(int vis, int mask, String cause);
void setWindowState(int window, int state);
void showRecentApps(boolean triggeredFromAltTab, boolean fromHome);
void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey);
void toggleRecentApps();
void preloadRecentApps();
void cancelPreloadRecentApps();
void toggleKeyboardShortcutsMenu(int deviceId);
/**
* 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(in Bundle args);
/**
* 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 addTile(in ComponentName tile); void addTile(in ComponentName tile);
void remTile(in ComponentName tile); void remTile(in ComponentName tile);

View File

@@ -60,7 +60,6 @@ import android.os.PowerManager;
import android.os.Process; import android.os.Process;
import android.os.RemoteCallbackList; import android.os.RemoteCallbackList;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
@@ -92,7 +91,6 @@ import android.view.accessibility.IAccessibilityManagerClient;
import com.android.internal.R; import com.android.internal.R;
import com.android.internal.content.PackageMonitor; import com.android.internal.content.PackageMonitor;
import com.android.internal.os.SomeArgs; import com.android.internal.os.SomeArgs;
import com.android.internal.statusbar.IStatusBarService;
import com.android.server.LocalServices; import com.android.server.LocalServices;
import com.android.server.statusbar.StatusBarManagerInternal; import com.android.server.statusbar.StatusBarManagerInternal;
@@ -3315,13 +3313,9 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
private void openRecents() { private void openRecents() {
final long token = Binder.clearCallingIdentity(); final long token = Binder.clearCallingIdentity();
IStatusBarService statusBarService = IStatusBarService.Stub.asInterface( StatusBarManagerInternal statusBarService = LocalServices.getService(
ServiceManager.getService("statusbar")); StatusBarManagerInternal.class);
try { statusBarService.toggleRecentApps();
statusBarService.toggleRecentApps();
} catch (RemoteException e) {
Slog.e(LOG_TAG, "Error toggling recent apps.");
}
Binder.restoreCallingIdentity(token); Binder.restoreCallingIdentity(token);
} }

View File

@@ -18,15 +18,14 @@ package com.android.server.policy;
import android.app.StatusBarManager; import android.app.StatusBarManager;
import android.os.Handler; import android.os.Handler;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock; import android.os.SystemClock;
import android.util.Slog; import android.util.Slog;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.WindowManagerPolicy.WindowState; 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; import java.io.PrintWriter;
@@ -52,7 +51,7 @@ public class BarController {
private final int mTranslucentWmFlag; private final int mTranslucentWmFlag;
protected final Handler mHandler; protected final Handler mHandler;
private final Object mServiceAquireLock = new Object(); private final Object mServiceAquireLock = new Object();
protected IStatusBarService mStatusBarService; protected StatusBarManagerInternal mStatusBarInternal;
private WindowState mWin; private WindowState mWin;
private int mState = StatusBarManager.WINDOW_STATE_SHOWING; private int mState = StatusBarManager.WINDOW_STATE_SHOWING;
@@ -182,15 +181,9 @@ public class BarController {
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
try { StatusBarManagerInternal statusbar = getStatusBarInternal();
IStatusBarService statusbar = getStatusBarService(); if (statusbar != null) {
if (statusbar != null) { statusbar.setWindowState(mStatusBarManagerId, state);
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;
} }
} }
}); });
@@ -276,13 +269,12 @@ public class BarController {
} }
} }
protected IStatusBarService getStatusBarService() { protected StatusBarManagerInternal getStatusBarInternal() {
synchronized (mServiceAquireLock) { synchronized (mServiceAquireLock) {
if (mStatusBarService == null) { if (mStatusBarInternal == null) {
mStatusBarService = IStatusBarService.Stub.asInterface( mStatusBarInternal = LocalServices.getService(StatusBarManagerInternal.class);
ServiceManager.getService("statusbar"));
} }
return mStatusBarService; return mStatusBarInternal;
} }
} }

View File

@@ -1467,14 +1467,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
private void requestTvPictureInPictureInternal() { private void requestTvPictureInPictureInternal() {
try { try {
IStatusBarService statusbar = getStatusBarService(); StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
if (statusbar != null) { if (statusbar != null) {
statusbar.requestTvPictureInPicture(); statusbar.requestTvPictureInPicture();
} }
} catch (RemoteException|IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Slog.e(TAG, "Cannot handle picture-in-picture key", e); Slog.e(TAG, "Cannot handle picture-in-picture key", e);
// re-acquire status bar service next time it is needed.
mStatusBarService = null;
} }
} }
@@ -3562,21 +3560,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
.launchLegacyAssist(hint, UserHandle.myUserId(), args); .launchLegacyAssist(hint, UserHandle.myUserId(), args);
} else { } else {
try { if (hint != null) {
if (hint != null) { if (args == null) {
if (args == null) { args = new Bundle();
args = new Bundle();
}
args.putBoolean(hint, true);
} }
IStatusBarService statusbar = getStatusBarService(); args.putBoolean(hint, true);
if (statusbar != null) { }
statusbar.startAssist(args); StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
} if (statusbar != null) {
} catch (RemoteException e) { statusbar.startAssist(args);
Slog.e(TAG, "RemoteException when starting assist", e);
// re-acquire status bar service next time it is needed.
mStatusBarService = null;
} }
} }
} }
@@ -3598,45 +3590,27 @@ public class PhoneWindowManager implements WindowManagerPolicy {
private void preloadRecentApps() { private void preloadRecentApps() {
mPreloadedRecentApps = true; mPreloadedRecentApps = true;
try { StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
IStatusBarService statusbar = getStatusBarService(); if (statusbar != null) {
if (statusbar != null) { statusbar.preloadRecentApps();
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;
} }
} }
private void cancelPreloadRecentApps() { private void cancelPreloadRecentApps() {
if (mPreloadedRecentApps) { if (mPreloadedRecentApps) {
mPreloadedRecentApps = false; mPreloadedRecentApps = false;
try { StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
IStatusBarService statusbar = getStatusBarService(); if (statusbar != null) {
if (statusbar != null) { statusbar.cancelPreloadRecentApps();
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;
} }
} }
} }
private void toggleRecentApps() { private void toggleRecentApps() {
mPreloadedRecentApps = false; // preloading no longer needs to be canceled mPreloadedRecentApps = false; // preloading no longer needs to be canceled
try { StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
IStatusBarService statusbar = getStatusBarService(); if (statusbar != null) {
if (statusbar != null) { statusbar.toggleRecentApps();
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;
} }
} }
@@ -3648,40 +3622,24 @@ public class PhoneWindowManager implements WindowManagerPolicy {
private void showRecentApps(boolean triggeredFromAltTab, boolean fromHome) { private void showRecentApps(boolean triggeredFromAltTab, boolean fromHome) {
mPreloadedRecentApps = false; // preloading no longer needs to be canceled mPreloadedRecentApps = false; // preloading no longer needs to be canceled
try { StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
IStatusBarService statusbar = getStatusBarService(); if (statusbar != null) {
if (statusbar != null) { statusbar.showRecentApps(triggeredFromAltTab, fromHome);
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;
} }
} }
private void toggleKeyboardShortcutsMenu(int deviceId) { private void toggleKeyboardShortcutsMenu(int deviceId) {
try { StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
IStatusBarService statusbar = getStatusBarService(); if (statusbar != null) {
if (statusbar != null) { statusbar.toggleKeyboardShortcutsMenu(deviceId);
statusbar.toggleKeyboardShortcutsMenu(deviceId);
}
} catch (RemoteException e) {
Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
} }
} }
private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) { private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
mPreloadedRecentApps = false; // preloading no longer needs to be canceled mPreloadedRecentApps = false; // preloading no longer needs to be canceled
try { StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
IStatusBarService statusbar = getStatusBarService(); if (statusbar != null) {
if (statusbar != null) { statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
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;
} }
} }
@@ -7483,13 +7441,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
if (mKeyguardDelegate != null) { if (mKeyguardDelegate != null) {
mKeyguardDelegate.setCurrentUser(newUserId); mKeyguardDelegate.setCurrentUser(newUserId);
} }
IStatusBarService statusBar = getStatusBarService(); StatusBarManagerInternal statusBar = getStatusBarManagerInternal();
if (statusBar != null) { if (statusBar != null) {
try { statusBar.setCurrentUser(newUserId);
statusBar.setCurrentUser(newUserId);
} catch (RemoteException e) {
// oh well
}
} }
setLastInputMethodWindowLw(null, null); setLastInputMethodWindowLw(null, null);
} }

View File

@@ -18,9 +18,7 @@ package com.android.server.policy;
import android.app.StatusBarManager; import android.app.StatusBarManager;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException;
import android.os.SystemClock; import android.os.SystemClock;
import android.util.Slog;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.animation.Animation; import android.view.animation.Animation;
@@ -28,7 +26,6 @@ import android.view.animation.AnimationSet;
import android.view.animation.Interpolator; import android.view.animation.Interpolator;
import android.view.animation.TranslateAnimation; import android.view.animation.TranslateAnimation;
import com.android.internal.statusbar.IStatusBarService;
import com.android.server.LocalServices; import com.android.server.LocalServices;
import com.android.server.statusbar.StatusBarManagerInternal; import com.android.server.statusbar.StatusBarManagerInternal;
@@ -49,15 +46,9 @@ public class StatusBarController extends BarController {
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
try { StatusBarManagerInternal statusbar = getStatusBarInternal();
IStatusBarService statusbar = getStatusBarService(); if (statusbar != null) {
if (statusbar != null) { statusbar.appTransitionPending();
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;
} }
} }
}); });
@@ -69,19 +60,13 @@ public class StatusBarController extends BarController {
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
try { StatusBarManagerInternal statusbar = getStatusBarInternal();
IStatusBarService statusbar = getStatusBarService(); if (statusbar != null) {
if (statusbar != null) { long startTime = calculateStatusBarTransitionStartTime(openAnimation,
long startTime = calculateStatusBarTransitionStartTime(openAnimation, closeAnimation);
closeAnimation); long duration = closeAnimation != null || openAnimation != null
long duration = closeAnimation != null || openAnimation != null ? TRANSITION_DURATION : 0;
? TRANSITION_DURATION : 0; statusbar.appTransitionStarting(startTime, duration);
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;
} }
} }
}); });
@@ -92,15 +77,9 @@ public class StatusBarController extends BarController {
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
try { StatusBarManagerInternal statusbar = getStatusBarInternal();
IStatusBarService statusbar = getStatusBarService(); if (statusbar != null) {
if (statusbar != null) { statusbar.appTransitionCancelled();
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;
} }
} }
}); });

View File

@@ -28,6 +28,50 @@ public interface StatusBarManagerInternal {
void notificationLightOff(); void notificationLightOff();
void showScreenPinningRequest(int taskId); void showScreenPinningRequest(int taskId);
void showAssistDisclosure(); 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 startAssist(Bundle args);
void onCameraLaunchGestureDetected(int source); void onCameraLaunchGestureDetected(int source);
void topAppWindowChanged(boolean menuVisible); void topAppWindowChanged(boolean menuVisible);
@@ -35,4 +79,8 @@ public interface StatusBarManagerInternal {
Rect fullscreenBounds, Rect dockedBounds, String cause); Rect fullscreenBounds, Rect dockedBounds, String cause);
void toggleSplitScreen(); void toggleSplitScreen();
void appTransitionFinished(); void appTransitionFinished();
void toggleRecentApps();
void setCurrentUser(int newUserId);
} }

View File

@@ -223,6 +223,114 @@ public class StatusBarManagerService extends IStatusBarService.Stub {
} catch (RemoteException ex) {} } 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 @@ public class StatusBarManagerService extends IStatusBarService.Stub {
} }
} }
@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() { private void enforceStatusBarOrShell() {
if (Binder.getCallingUid() == Process.SHELL_UID) { if (Binder.getCallingUid() == Process.SHELL_UID) {
return; return;