Initial implementation of colored stripe.
RFC 1/1 Initial implementation of colored stripe.
To use this there must be a file in /etc/security or /data/system/ called label_trans.xml with contents like:
<trans label="u:r:tresys_app" color="#aaaa0000" translated="Tresys" /> <trans label="u:r:untrusted_app" color="#ff111111" translated="untrusted" />
The label attribute is the SELinux context, and is the longest matched, per TreeMap. I did this so that we would not have to deal with categories, though some smarter way is surely necessary. I was avoiding tokenizing the security context.
There are still many unanswered questions about this. Code to disable fullscreen mode may be required. It seems to work well though, when there is a popup the bar changes to the correct color, including when the notification shade is swiped down. OpenGL games do not appear to be able to render over it and the WindowManager is ultimately trusted since it is part of SystemUI with the input manager.
You'll notice the translated="..." in the XML, that is not yet implemented but the intention is to put it in the top status bar on phones and in the navigation bar on tablets.
Change-Id: Ib4df961a11b7d7dff3455506cf56613bd4f9254d
--- core/java/android/view/IWindowSession.aidl | 2 + core/java/android/view/WindowManagerPolicy.java | 10 ++ .../com/android/internal/statusbar/IStatusBar.aidl | 2 +- .../internal/statusbar/IStatusBarService.aidl | 2 +- .../android/systemui/statusbar/BaseStatusBar.java | 142 +++++++++++++++++++- .../android/systemui/statusbar/CommandQueue.java | 8 +- .../systemui/statusbar/phone/PhoneStatusBar.java | 23 +++- .../systemui/statusbar/tablet/TabletStatusBar.java | 23 +++- .../internal/policy/impl/PhoneWindowManager.java | 3 +- .../android/server/StatusBarManagerService.java | 6 +- services/java/com/android/server/wm/Session.java | 10 +- .../java/com/android/server/wm/WindowState.java | 4 + .../bridge/android/BridgeWindowSession.java | 6 + 13 files changed, 228 insertions(+), 13 deletions(-)
core/java/android/view/IWindowSession.aidl +2 -0
@@ -120,6 +120,8 @@ interface IWindowSession { */ void getDisplayFrame(IWindow window, out Rect outDisplayFrame); + String getSecurityLabel(); + void finishDrawing(IWindow window); void setInTouchMode(boolean showFocus);
core/java/android/view/WindowManagerPolicy.java +10 -0
@@ -25,6 +25,7 @@ import android.os.IBinder; import android.os.LocalPowerManager; import android.os.Looper; import android.view.animation.Animation; +import android.view.IWindowSession; import java.io.PrintWriter;
@@ -339,6 +340,15 @@ public interface WindowManagerPolicy { * Check whether the process hosting this window is currently alive. */ public boolean isAlive(); + + /** + * Return the session for the application (actually activity) that owns + * this window. + * + * @return An IWindowSession identifying the owning activity. + */ + public IWindowSession getSession(); + } /**
core/java/com/android/internal/statusbar/IStatusBar.aidl +1 -1
@@ -31,7 +31,7 @@ oneway interface IStatusBar void animateExpand(); void animateCollapse(); void setSystemUiVisibility(int vis, int mask); - void topAppWindowChanged(boolean menuVisible); + void topAppWindowChanged(boolean menuVisible, String securityLabel); void setImeWindowStatus(in IBinder token, int vis, int backDisposition); void setHardKeyboardStatus(boolean available, boolean enabled); void toggleRecentApps();
core/java/com/android/internal/statusbar/IStatusBarService.aidl +1 -1
@@ -30,7 +30,7 @@ interface IStatusBarService void setIcon(String slot, String iconPackage, int iconId, int iconLevel, String contentDescription); void setIconVisibility(String slot, boolean visible); void removeIcon(String slot); - void topAppWindowChanged(boolean menuVisible); + void topAppWindowChanged(boolean menuVisible, String securityLabel); void setImeWindowStatus(in IBinder token, int vis, int backDisposition); // ---- Methods below are for use by the status bar policy services ----
packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +141 -1
198 lines not on this page · raw message
packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java +4 -4
@@ -97,7 +97,7 @@ public class CommandQueue extends IStatusBar.Stub { public void animateExpand(); public void animateCollapse(int flags); public void setSystemUiVisibility(int vis, int mask); - public void topAppWindowChanged(boolean visible); + public void topAppWindowChanged(boolean visible, String securityLabel); public void setImeWindowStatus(IBinder token, int vis, int backDisposition); public void setHardKeyboardStatus(boolean available, boolean enabled); public void toggleRecentApps();
@@ -185,11 +185,11 @@ public class CommandQueue extends IStatusBar.Stub { } } - public void topAppWindowChanged(boolean menuVisible) { + public void topAppWindowChanged(boolean menuVisible, String securityLabel) { synchronized (mList) { mHandler.removeMessages(MSG_TOP_APP_WINDOW_CHANGED); mHandler.obtainMessage(MSG_TOP_APP_WINDOW_CHANGED, menuVisible ? 1 : 0, 0, - null).sendToTarget(); + securityLabel).sendToTarget(); } }
@@ -295,7 +295,7 @@ public class CommandQueue extends IStatusBar.Stub { mCallbacks.setSystemUiVisibility(msg.arg1, msg.arg2); break; case MSG_TOP_APP_WINDOW_CHANGED: - mCallbacks.topAppWindowChanged(msg.arg1 != 0); + mCallbacks.topAppWindowChanged(msg.arg1 != 0, (String)msg.obj); break; case MSG_SHOW_IME_BUTTON: mCallbacks.setImeWindowStatus((IBinder)msg.obj, msg.arg1, msg.arg2);
packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +22 -1
@@ -35,6 +35,7 @@ import android.content.IntentFilter; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Canvas; +import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.PixelFormat; import android.graphics.PorterDuff;
@@ -94,6 +95,7 @@ import com.android.systemui.statusbar.policy.NotificationRowLayout; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; +import java.util.Map; public class PhoneStatusBar extends BaseStatusBar { static final String TAG = "PhoneStatusBar";
@@ -1764,16 +1766,35 @@ public class PhoneStatusBar extends BaseStatusBar { } } - public void topAppWindowChanged(boolean showMenu) { + public void topAppWindowChanged(boolean showMenu, String securityLabel) { if (DEBUG) { Slog.d(TAG, (showMenu?"showing":"hiding") + " the MENU button"); } + if (mNavigationBarView != null) { mNavigationBarView.setMenuVisibility(showMenu); } // See above re: lights-out policy for legacy apps. if (showMenu) setLightsOn(true); + + if (!mIsLabelTransEnabled) + return; + + Slog.d(TAG, "SecurityLabel is " + securityLabel); + + Map.Entry <String, LabelTrans> trans = mLabelTrans.floorEntry(securityLabel); + if (trans == null) { + int color = Color.parseColor("black"); + Slog.e(TAG, "Found no translated label for " + securityLabel); + mNavigationBarView.setBackgroundColor(color); + mStatusBarView.setBackgroundColor(color); + } else { + Slog.e(TAG, "Found color: " + trans.getValue().color + " translated: " + trans.getValue().translated + " for " + securityLabel); + mNavigationBarView.setBackgroundColor(trans.getValue().color); + mStatusBarView.setBackgroundColor(trans.getValue().color); + } + } @Override
packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java +22 -1
@@ -30,6 +30,7 @@ import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; +import android.graphics.Color; import android.graphics.PixelFormat; import android.graphics.Point; import android.graphics.drawable.Drawable;
@@ -84,6 +85,7 @@ import com.android.systemui.statusbar.policy.Prefs; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; +import java.util.Map; public class TabletStatusBar extends BaseStatusBar implements InputMethodsPanel.OnHardKeyboardEnabledChangeListener,
@@ -189,6 +191,8 @@ public class TabletStatusBar extends BaseStatusBar implements private int mShowSearchHoldoff = 0; + private int mCurrentColor = 0; + public Context getContext() { return mContext; } private Runnable mShowSearchPanel = new Runnable() {
@@ -1111,9 +1115,10 @@ public class TabletStatusBar extends BaseStatusBar implements } else { setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE, View.SYSTEM_UI_FLAG_LOW_PROFILE); } + mStatusBarView.setBackgroundColor(mCurrentColor); } - public void topAppWindowChanged(boolean showMenu) { + public void topAppWindowChanged(boolean showMenu, String securityLabel) { if (DEBUG) { Slog.d(TAG, (showMenu?"showing":"hiding") + " the MENU button"); }
@@ -1132,6 +1137,22 @@ public class TabletStatusBar extends BaseStatusBar implements hideCompatibilityHelp(); mCompatModePanel.closePanel(); } + + Slog.d(TAG, "securityLabel is " + securityLabel); + + int color; + Map.Entry <String, LabelTrans> trans = mLabelTrans.floorEntry(securityLabel); + if (trans == null) { + color = Color.parseColor("black"); + Slog.e(TAG, "Found no security label for " + securityLabel); + mCurrentColor = color; + } else { + color = trans.getValue().color; + Slog.d(TAG, "Found color: " + trans.getValue().color + " translated: " + trans.getValue().translated + " for " + securityLabel); + mCurrentColor = color; + } + mStatusBarView.setBackgroundColor(color); + } private void showCompatibilityHelp() {
policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +2 -1
@@ -4377,7 +4377,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { IStatusBarService statusbar = getStatusBarService(); if (statusbar != null) { statusbar.setSystemUiVisibility(visibility, 0xffffffff); - statusbar.topAppWindowChanged(needsMenu); + statusbar.topAppWindowChanged(needsMenu, mFocusedWindow.getSession(). + getSecurityLabel()); } } catch (RemoteException e) { // re-acquire status bar service next time it is needed.
services/java/com/android/server/StatusBarManagerService.java +4 -2
@@ -245,18 +245,20 @@ public class StatusBarManagerService extends IStatusBarService.Stub * Hide or show the on-screen Menu key. Only call this from the window manager, typically in * response to a window with FLAG_NEEDS_MENU_KEY set. */ - public void topAppWindowChanged(final boolean menuVisible) { + public void topAppWindowChanged(final boolean menuVisible, final String securityLabel) { enforceStatusBar(); if (SPEW) Slog.d(TAG, (menuVisible?"showing":"hiding") + " MENU key"); + Slog.d(TAG, "securityLabel is " + securityLabel); + synchronized(mLock) { mMenuVisible = menuVisible; mHandler.post(new Runnable() { public void run() { if (mBar != null) { try { - mBar.topAppWindowChanged(menuVisible); + mBar.topAppWindowChanged(menuVisible, securityLabel); } catch (RemoteException ex) { } }
services/java/com/android/server/wm/Session.java +9 -1
@@ -31,6 +31,7 @@ import android.os.Bundle; import android.os.IBinder; import android.os.Parcel; import android.os.RemoteException; +import android.os.SELinux; import android.os.ServiceManager; import android.util.Slog; import android.view.IWindow;
@@ -53,6 +54,7 @@ final class Session extends IWindowSession.Stub final IInputContext mInputContext; final int mUid; final int mPid; + final String mSecurityLabel; final String mStringName; SurfaceSession mSurfaceSession; int mNumWindow = 0;
@@ -65,6 +67,7 @@ final class Session extends IWindowSession.Stub mInputContext = inputContext; mUid = Binder.getCallingUid(); mPid = Binder.getCallingPid(); + mSecurityLabel = SELinux.getPidContext(mPid); StringBuilder sb = new StringBuilder(); sb.append("Session{"); sb.append(Integer.toHexString(System.identityHashCode(this)));
@@ -204,6 +207,10 @@ final class Session extends IWindowSession.Stub } } + public String getSecurityLabel() { + return mSecurityLabel; + } + public boolean performHapticFeedback(IWindow window, int effectId, boolean always) { synchronized(mService.mWindowMap) {
@@ -437,4 +444,5 @@ final class Session extends IWindowSession.Stub public String toString() { return mStringName; } -} +} +
services/java/com/android/server/wm/WindowState.java +4 -0
@@ -541,6 +541,10 @@ final class WindowState implements WindowManagerPolicy.WindowState { return mAttrs; } + public Session getSession() { + return mSession; + } + public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) { int index = -1; WindowState ws = this;
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowSession.java +6 -0
@@ -91,6 +91,12 @@ public final class BridgeWindowSession implements IWindowSession { } @Override + public String getSecurityLabel() { + // pass for now. + return ""; + } + + @Override public void remove(IWindow arg0) throws RemoteException { // pass for now. }
Signature · 7 lines
1.7.9.5 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.