Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

frameworks-base: Commit

frameworks/base


Commit MetaInfo

Revision9abeb4e2a077d014b4766ff04c557a1e57b013d2 (tree)
Time2018-01-04 17:31:43
AuthorChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

Android 7.1.2 Release 36 (N2G48H)
-----BEGIN PGP SIGNATURE-----

iF0EABECAB0WIQRDQNE1cO+UXoOBCWTorT+BmrEOeAUCWicTdgAKCRDorT+BmrEO
eLUtAJ9n+RoBwYF16+UZY760WJEQpoqxSACfQqcUNapFbI/RHsR2n6/3BXeNZGw=
=QXGL
-----END PGP SIGNATURE-----

Merge tag 'android-7.1.2_r36' into nougat-x86

Android 7.1.2 Release 36 (N2G48H)

Change Summary

Incremental Difference

--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -112,6 +112,7 @@ package android {
112112 field public static final java.lang.String GRANT_RUNTIME_PERMISSIONS = "android.permission.GRANT_RUNTIME_PERMISSIONS";
113113 field public static final java.lang.String HARDWARE_TEST = "android.permission.HARDWARE_TEST";
114114 field public static final java.lang.String HDMI_CEC = "android.permission.HDMI_CEC";
115+ field public static final java.lang.String HIDE_NON_SYSTEM_OVERLAY_WINDOWS = "android.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS";
115116 field public static final java.lang.String INJECT_EVENTS = "android.permission.INJECT_EVENTS";
116117 field public static final java.lang.String INSTALL_GRANT_RUNTIME_PERMISSIONS = "android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS";
117118 field public static final java.lang.String INSTALL_LOCATION_PROVIDER = "android.permission.INSTALL_LOCATION_PROVIDER";
--- a/core/java/android/service/gatekeeper/GateKeeperResponse.java
+++ b/core/java/android/service/gatekeeper/GateKeeperResponse.java
@@ -85,6 +85,8 @@ public final class GateKeeperResponse implements Parcelable {
8585 if (mPayload != null) {
8686 dest.writeInt(mPayload.length);
8787 dest.writeByteArray(mPayload);
88+ } else {
89+ dest.writeInt(0);
8890 }
8991 }
9092 }
--- a/core/java/android/view/WindowManager.java
+++ b/core/java/android/view/WindowManager.java
@@ -655,6 +655,25 @@ public interface WindowManager extends ViewManager {
655655 */
656656 public static final int LAST_SYSTEM_WINDOW = 2999;
657657
658+ /**
659+ * Return true if the window type is an alert window.
660+ *
661+ * @param type The window type.
662+ * @return If the window type is an alert window.
663+ * @hide
664+ */
665+ public static boolean isSystemAlertWindowType(int type) {
666+ switch (type) {
667+ case TYPE_PHONE:
668+ case TYPE_PRIORITY_PHONE:
669+ case TYPE_SYSTEM_ALERT:
670+ case TYPE_SYSTEM_ERROR:
671+ case TYPE_SYSTEM_OVERLAY:
672+ return true;
673+ }
674+ return false;
675+ }
676+
658677 /** @deprecated this is ignored, this value is set automatically when needed. */
659678 @Deprecated
660679 public static final int MEMORY_TYPE_NORMAL = 0;
@@ -1263,6 +1282,15 @@ public interface WindowManager extends ViewManager {
12631282 public static final int PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE = 0x00040000;
12641283
12651284 /**
1285+ * Flag to indicate that any window added by an application process that is of type
1286+ * {@link #TYPE_TOAST} or that requires
1287+ * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
1288+ * this window is visible.
1289+ * @hide
1290+ */
1291+ public static final int PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS = 0x00080000;
1292+
1293+ /**
12661294 * Control flags that are private to the platform.
12671295 * @hide
12681296 */
--- a/core/jni/android/graphics/BitmapFactory.cpp
+++ b/core/jni/android/graphics/BitmapFactory.cpp
@@ -587,8 +587,7 @@ static jobject nativeDecodeFileDescriptor(JNIEnv* env, jobject clazz, jobject fi
587587 return nullObjectReturn("Could not open file");
588588 }
589589
590- std::unique_ptr<SkFILEStream> fileStream(new SkFILEStream(file,
591- SkFILEStream::kCallerPasses_Ownership));
590+ std::unique_ptr<SkFILEStream> fileStream(new SkFILEStream(file));
592591
593592 // If there is no offset for the file descriptor, we use SkFILEStream directly.
594593 if (::lseek(descriptor, 0, SEEK_CUR) == 0) {
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -2154,6 +2154,15 @@
21542154 <permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW"
21552155 android:protectionLevel="signature" />
21562156
2157+ <!-- @SystemApi Allows an application to use
2158+ {@link android.view.WindowManager.LayoutsParams#PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS}
2159+ to hide non-system-overlay windows.
2160+ <p>Not for use by third-party applications.
2161+ @hide
2162+ -->
2163+ <permission android:name="android.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS"
2164+ android:protectionLevel="signature|installer" />
2165+
21572166 <!-- @SystemApi Allows an application to manage (create, destroy,
21582167 Z-order) application tokens in the window manager.
21592168 <p>Not for use by third-party applications.
--- a/media/jni/android_media_ExifInterface.cpp
+++ b/media/jni/android_media_ExifInterface.cpp
@@ -390,8 +390,7 @@ static jobject ExifInterface_getRawAttributesFromFileDescriptor(
390390 // Rewind the file descriptor.
391391 fseek(file, 0L, SEEK_SET);
392392
393- std::unique_ptr<SkFILEStream> fileStream(new SkFILEStream(file,
394- SkFILEStream::kCallerPasses_Ownership));
393+ std::unique_ptr<SkFILEStream> fileStream(new SkFILEStream(file));
395394 return getRawAttributes(env, fileStream.get(), false);
396395 }
397396
--- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
@@ -2679,4 +2679,23 @@ public abstract class BaseStatusBar extends SystemUI implements
26792679 mAssistManager.startAssist(args);
26802680 }
26812681 }
2682+
2683+ public boolean isCameraAllowedByAdmin() {
2684+ if (mDevicePolicyManager.getCameraDisabled(null, mCurrentUserId)) {
2685+ return false;
2686+ } else if (isKeyguardShowing() && isKeyguardSecure()) {
2687+ // Check if the admin has disabled the camera specifically for the keyguard
2688+ return (mDevicePolicyManager.getKeyguardDisabledFeatures(null, mCurrentUserId)
2689+ & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA) == 0;
2690+ }
2691+ return true;
2692+ }
2693+
2694+ public boolean isKeyguardShowing() {
2695+ if (mStatusBarKeyguardViewManager == null) {
2696+ Slog.i(TAG, "isKeyguardShowing() called before startKeyguard(), returning true");
2697+ return true;
2698+ }
2699+ return mStatusBarKeyguardViewManager.isShowing();
2700+ }
26822701 }
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
@@ -305,7 +305,10 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
305305 return;
306306 }
307307 ResolveInfo resolved = resolveCameraIntent();
308- boolean visible = !isCameraDisabledByDpm() && resolved != null
308+ boolean isCameraDisabled =
309+ (mPhoneStatusBar != null) && !mPhoneStatusBar.isCameraAllowedByAdmin();
310+ boolean visible = !isCameraDisabled
311+ && resolved != null
309312 && getResources().getBoolean(R.bool.config_keyguardShowCameraAffordance)
310313 && mUserSetupComplete;
311314 mCameraImageView.setVisibility(visible ? View.VISIBLE : View.GONE);
@@ -339,24 +342,6 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
339342 && pm.resolveActivity(PHONE_INTENT, 0) != null;
340343 }
341344
342- private boolean isCameraDisabledByDpm() {
343- final DevicePolicyManager dpm =
344- (DevicePolicyManager) getContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
345- if (dpm != null && mPhoneStatusBar != null) {
346- try {
347- final int userId = ActivityManagerNative.getDefault().getCurrentUser().id;
348- final int disabledFlags = dpm.getKeyguardDisabledFeatures(null, userId);
349- final boolean disabledBecauseKeyguardSecure =
350- (disabledFlags & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA) != 0
351- && mPhoneStatusBar.isKeyguardSecure();
352- return dpm.getCameraDisabled(null) || disabledBecauseKeyguardSecure;
353- } catch (RemoteException e) {
354- Log.e(TAG, "Can't get userId", e);
355- }
356- }
357- return false;
358- }
359-
360345 private void watchForCameraPolicyChanges() {
361346 final IntentFilter filter = new IntentFilter();
362347 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -31,6 +31,7 @@ import android.graphics.Paint;
3131 import android.graphics.Rect;
3232 import android.util.AttributeSet;
3333 import android.util.MathUtils;
34+import android.util.EventLog;
3435 import android.view.MotionEvent;
3536 import android.view.VelocityTracker;
3637 import android.view.View;
@@ -2330,6 +2331,10 @@ public class NotificationPanelView extends PanelView implements
23302331 * @param keyguardIsShowing whether keyguard is being shown
23312332 */
23322333 public boolean canCameraGestureBeLaunched(boolean keyguardIsShowing) {
2334+ if (!mStatusBar.isCameraAllowedByAdmin()) {
2335+ EventLog.writeEvent(0x534e4554, "63787722", -1, "");
2336+ return false;
2337+ }
23332338 ResolveInfo resolveInfo = mKeyguardBottomArea.resolveCameraIntent();
23342339 String packageToLaunch = (resolveInfo == null || resolveInfo.activityInfo == null)
23352340 ? null : resolveInfo.activityInfo.packageName;
--- a/services/core/java/com/android/server/accounts/AccountManagerService.java
+++ b/services/core/java/com/android/server/accounts/AccountManagerService.java
@@ -4184,6 +4184,10 @@ public class AccountManagerService
41844184 protected void checkKeyIntent(
41854185 int authUid,
41864186 Intent intent) throws SecurityException {
4187+ intent.setFlags(intent.getFlags() & ~(Intent.FLAG_GRANT_READ_URI_PERMISSION
4188+ | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
4189+ | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
4190+ | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION));
41874191 long bid = Binder.clearCallingIdentity();
41884192 try {
41894193 PackageManager pm = mContext.getPackageManager();
--- a/services/core/java/com/android/server/clipboard/ClipboardService.java
+++ b/services/core/java/com/android/server/clipboard/ClipboardService.java
@@ -20,6 +20,7 @@ import android.app.ActivityManagerNative;
2020 import android.app.AppGlobals;
2121 import android.app.AppOpsManager;
2222 import android.app.IActivityManager;
23+import android.app.KeyguardManager;
2324 import android.content.BroadcastReceiver;
2425 import android.content.ClipData;
2526 import android.content.ClipDescription;
@@ -255,7 +256,7 @@ public class ClipboardService extends IClipboard.Stub {
255256 public ClipData getPrimaryClip(String pkg) {
256257 synchronized (this) {
257258 if (mAppOps.noteOp(AppOpsManager.OP_READ_CLIPBOARD, Binder.getCallingUid(),
258- pkg) != AppOpsManager.MODE_ALLOWED) {
259+ pkg) != AppOpsManager.MODE_ALLOWED || isDeviceLocked()) {
259260 return null;
260261 }
261262 addActiveOwnerLocked(Binder.getCallingUid(), pkg);
@@ -266,7 +267,7 @@ public class ClipboardService extends IClipboard.Stub {
266267 public ClipDescription getPrimaryClipDescription(String callingPackage) {
267268 synchronized (this) {
268269 if (mAppOps.checkOp(AppOpsManager.OP_READ_CLIPBOARD, Binder.getCallingUid(),
269- callingPackage) != AppOpsManager.MODE_ALLOWED) {
270+ callingPackage) != AppOpsManager.MODE_ALLOWED || isDeviceLocked()) {
270271 return null;
271272 }
272273 PerUserClipboard clipboard = getClipboard();
@@ -277,7 +278,7 @@ public class ClipboardService extends IClipboard.Stub {
277278 public boolean hasPrimaryClip(String callingPackage) {
278279 synchronized (this) {
279280 if (mAppOps.checkOp(AppOpsManager.OP_READ_CLIPBOARD, Binder.getCallingUid(),
280- callingPackage) != AppOpsManager.MODE_ALLOWED) {
281+ callingPackage) != AppOpsManager.MODE_ALLOWED || isDeviceLocked()) {
281282 return false;
282283 }
283284 return getClipboard().primaryClip != null;
@@ -301,7 +302,7 @@ public class ClipboardService extends IClipboard.Stub {
301302 public boolean hasClipboardText(String callingPackage) {
302303 synchronized (this) {
303304 if (mAppOps.checkOp(AppOpsManager.OP_READ_CLIPBOARD, Binder.getCallingUid(),
304- callingPackage) != AppOpsManager.MODE_ALLOWED) {
305+ callingPackage) != AppOpsManager.MODE_ALLOWED || isDeviceLocked()) {
305306 return false;
306307 }
307308 PerUserClipboard clipboard = getClipboard();
@@ -313,6 +314,17 @@ public class ClipboardService extends IClipboard.Stub {
313314 }
314315 }
315316
317+ private boolean isDeviceLocked() {
318+ final long token = Binder.clearCallingIdentity();
319+ try {
320+ final KeyguardManager keyguardManager = mContext.getSystemService(
321+ KeyguardManager.class);
322+ return keyguardManager != null && keyguardManager.isDeviceLocked();
323+ } finally {
324+ Binder.restoreCallingIdentity(token);
325+ }
326+ }
327+
316328 private final void checkUriOwnerLocked(Uri uri, int uid) {
317329 if (!"content".equals(uri.getScheme())) {
318330 return;
--- a/services/core/java/com/android/server/content/SyncStorageEngine.java
+++ b/services/core/java/com/android/server/content/SyncStorageEngine.java
@@ -18,6 +18,7 @@ package com.android.server.content;
1818
1919 import android.accounts.Account;
2020 import android.accounts.AccountAndUser;
21+import android.accounts.AccountManager;
2122 import android.app.backup.BackupManager;
2223 import android.content.ComponentName;
2324 import android.content.ContentResolver;
@@ -27,6 +28,7 @@ import android.content.PeriodicSync;
2728 import android.content.SyncInfo;
2829 import android.content.SyncRequest;
2930 import android.content.SyncStatusInfo;
31+import android.content.pm.PackageManager;
3032 import android.database.Cursor;
3133 import android.database.sqlite.SQLiteDatabase;
3234 import android.database.sqlite.SQLiteException;
@@ -350,6 +352,50 @@ public class SyncStorageEngine extends Handler {
350352 void onAuthorityRemoved(EndPoint removedAuthority);
351353 }
352354
355+ /**
356+ * Validator that maintains a lazy cache of accounts and providers to tell if an authority or
357+ * account is valid.
358+ */
359+ private static class AccountAuthorityValidator {
360+ final private AccountManager mAccountManager;
361+ final private PackageManager mPackageManager;
362+ final private SparseArray<Account[]> mAccountsCache;
363+ final private SparseArray<ArrayMap<String, Boolean>> mProvidersPerUserCache;
364+
365+ AccountAuthorityValidator(Context context) {
366+ mAccountManager = context.getSystemService(AccountManager.class);
367+ mPackageManager = context.getPackageManager();
368+ mAccountsCache = new SparseArray<>();
369+ mProvidersPerUserCache = new SparseArray<>();
370+ }
371+
372+ // An account is valid if an installed authenticator has previously created that account
373+ // on the device
374+ boolean isAccountValid(Account account, int userId) {
375+ Account[] accountsForUser = mAccountsCache.get(userId);
376+ if (accountsForUser == null) {
377+ accountsForUser = mAccountManager.getAccountsAsUser(userId);
378+ mAccountsCache.put(userId, accountsForUser);
379+ }
380+ return ArrayUtils.contains(accountsForUser, account);
381+ }
382+
383+ // An authority is only valid if it has a content provider installed on the system
384+ boolean isAuthorityValid(String authority, int userId) {
385+ ArrayMap<String, Boolean> authorityMap = mProvidersPerUserCache.get(userId);
386+ if (authorityMap == null) {
387+ authorityMap = new ArrayMap<>();
388+ mProvidersPerUserCache.put(userId, authorityMap);
389+ }
390+ if (!authorityMap.containsKey(authority)) {
391+ authorityMap.put(authority, mPackageManager.resolveContentProviderAsUser(authority,
392+ PackageManager.MATCH_DIRECT_BOOT_AWARE
393+ | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userId) != null);
394+ }
395+ return authorityMap.get(authority);
396+ }
397+ }
398+
353399 // Primary list of all syncable authorities. Also our global lock.
354400 private final SparseArray<AuthorityInfo> mAuthorities =
355401 new SparseArray<AuthorityInfo>();
@@ -1502,12 +1548,13 @@ public class SyncStorageEngine extends Handler {
15021548 eventType = parser.next();
15031549 AuthorityInfo authority = null;
15041550 PeriodicSync periodicSync = null;
1551+ AccountAuthorityValidator validator = new AccountAuthorityValidator(mContext);
15051552 do {
15061553 if (eventType == XmlPullParser.START_TAG) {
15071554 tagName = parser.getName();
15081555 if (parser.getDepth() == 2) {
15091556 if ("authority".equals(tagName)) {
1510- authority = parseAuthority(parser, version);
1557+ authority = parseAuthority(parser, version, validator);
15111558 periodicSync = null;
15121559 if (authority != null) {
15131560 if (authority.ident > highestAuthorityId) {
@@ -1636,7 +1683,8 @@ public class SyncStorageEngine extends Handler {
16361683 mMasterSyncAutomatically.put(userId, listen);
16371684 }
16381685
1639- private AuthorityInfo parseAuthority(XmlPullParser parser, int version) {
1686+ private AuthorityInfo parseAuthority(XmlPullParser parser, int version,
1687+ AccountAuthorityValidator validator) {
16401688 AuthorityInfo authority = null;
16411689 int id = -1;
16421690 try {
@@ -1676,21 +1724,26 @@ public class SyncStorageEngine extends Handler {
16761724 if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
16771725 Slog.v(TAG_FILE, "Creating authority entry");
16781726 }
1679- EndPoint info = null;
16801727 if (accountName != null && authorityName != null) {
1681- info = new EndPoint(
1728+ EndPoint info = new EndPoint(
16821729 new Account(accountName, accountType),
16831730 authorityName, userId);
1684- }
1685- if (info != null) {
1686- authority = getOrCreateAuthorityLocked(info, id, false);
1687- // If the version is 0 then we are upgrading from a file format that did not
1688- // know about periodic syncs. In that case don't clear the list since we
1689- // want the default, which is a daily periodic sync.
1690- // Otherwise clear out this default list since we will populate it later with
1691- // the periodic sync descriptions that are read from the configuration file.
1692- if (version > 0) {
1693- authority.periodicSyncs.clear();
1731+ if (validator.isAccountValid(info.account, userId)
1732+ && validator.isAuthorityValid(authorityName, userId)) {
1733+ authority = getOrCreateAuthorityLocked(info, id, false);
1734+ // If the version is 0 then we are upgrading from a file format that did not
1735+ // know about periodic syncs. In that case don't clear the list since we
1736+ // want the default, which is a daily periodic sync.
1737+ // Otherwise clear out this default list since we will populate it later
1738+ // with
1739+ // the periodic sync descriptions that are read from the configuration file.
1740+ if (version > 0) {
1741+ authority.periodicSyncs.clear();
1742+ }
1743+ } else {
1744+ EventLog.writeEvent(0x534e4554, "35028827", -1,
1745+ "account:" + info.account + " provider:" + authorityName + " user:"
1746+ + userId);
16941747 }
16951748 }
16961749 }
--- a/services/core/java/com/android/server/wm/Session.java
+++ b/services/core/java/com/android/server/wm/Session.java
@@ -16,6 +16,9 @@
1616
1717 package com.android.server.wm;
1818
19+import static android.Manifest.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
20+import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
21+import static android.content.pm.PackageManager.PERMISSION_GRANTED;
1922 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG;
2023 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING;
2124 import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
@@ -67,6 +70,8 @@ final class Session extends IWindowSession.Stub
6770 final int mUid;
6871 final int mPid;
6972 final String mStringName;
73+ final boolean mCanAddInternalSystemWindow;
74+ final boolean mCanHideNonSystemOverlayWindows;
7075 SurfaceSession mSurfaceSession;
7176 int mNumWindow = 0;
7277 boolean mClientDead = false;
@@ -80,6 +85,10 @@ final class Session extends IWindowSession.Stub
8085 mInputContext = inputContext;
8186 mUid = Binder.getCallingUid();
8287 mPid = Binder.getCallingPid();
88+ mCanAddInternalSystemWindow = service.mContext.checkCallingOrSelfPermission(
89+ INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED;
90+ mCanHideNonSystemOverlayWindows = service.mContext.checkCallingOrSelfPermission(
91+ HIDE_NON_SYSTEM_OVERLAY_WINDOWS) == PERMISSION_GRANTED;
8392 mLastReportedAnimatorScale = service.getCurrentAnimatorScale();
8493 StringBuilder sb = new StringBuilder();
8594 sb.append("Session{");
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -490,6 +490,9 @@ public class WindowManagerService extends IWindowManager.Stub
490490 */
491491 final ArrayList<WindowState> mForceRemoves = new ArrayList<>();
492492
493+ /** List of window currently causing non-system overlay windows to be hidden. */
494+ private ArrayList<WindowState> mHidingNonSystemOverlayWindows = new ArrayList<WindowState>();
495+
493496 /**
494497 * Windows that clients are waiting to have drawn.
495498 */
@@ -2129,6 +2132,9 @@ public class WindowManagerService extends IWindowManager.Stub
21292132 }
21302133 }
21312134
2135+ final boolean hideSystemAlertWindows = !mHidingNonSystemOverlayWindows.isEmpty();
2136+ win.setForceHideNonSystemOverlayWindowIfNeeded(hideSystemAlertWindows);
2137+
21322138 if (type == TYPE_APPLICATION_STARTING && token.appWindowToken != null) {
21332139 token.appWindowToken.startingWindow = win;
21342140 if (DEBUG_STARTING_WINDOW) Slog.v (TAG_WM, "addWindow: " + token.appWindowToken
@@ -2576,6 +2582,7 @@ public class WindowManagerService extends IWindowManager.Stub
25762582
25772583 mPendingRemove.remove(win);
25782584 mResizingWindows.remove(win);
2585+ updateNonSystemOverlayWindowsVisibilityIfNeeded(win, false /* surfaceShown */);
25792586 mWindowsChanged = true;
25802587 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Final remove of window: " + win);
25812588
@@ -11771,4 +11778,34 @@ public class WindowManagerService extends IWindowManager.Stub
1177111778 }
1177211779 }
1177311780 }
11781+
11782+ void updateNonSystemOverlayWindowsVisibilityIfNeeded(WindowState win, boolean surfaceShown) {
11783+ if (!win.hideNonSystemOverlayWindowsWhenVisible()) {
11784+ return;
11785+ }
11786+ final boolean systemAlertWindowsHidden = !mHidingNonSystemOverlayWindows.isEmpty();
11787+ if (surfaceShown) {
11788+ if (!mHidingNonSystemOverlayWindows.contains(win)) {
11789+ mHidingNonSystemOverlayWindows.add(win);
11790+ }
11791+ } else {
11792+ mHidingNonSystemOverlayWindows.remove(win);
11793+ }
11794+
11795+ final boolean hideSystemAlertWindows = !mHidingNonSystemOverlayWindows.isEmpty();
11796+
11797+ if (systemAlertWindowsHidden == hideSystemAlertWindows) {
11798+ return;
11799+ }
11800+
11801+ final int numDisplays = mDisplayContents.size();
11802+ for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
11803+ final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList();
11804+ final int numWindows = windows.size();
11805+ for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
11806+ final WindowState w = windows.get(winNdx);
11807+ w.setForceHideNonSystemOverlayWindowIfNeeded(hideSystemAlertWindows);
11808+ }
11809+ }
11810+ }
1177411811 }
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -79,6 +79,7 @@ import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
7979 import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
8080 import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
8181 import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
82+import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
8283 import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
8384 import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
8485 import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
@@ -91,7 +92,9 @@ import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
9192 import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
9293 import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
9394 import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
95+import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
9496 import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
97+import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
9598 import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
9699 import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
97100 import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
@@ -141,6 +144,7 @@ final class WindowState implements WindowManagerPolicy.WindowState {
141144 final int mAppOp;
142145 // UserId and appId of the owner. Don't display windows of non-current user.
143146 final int mOwnerUid;
147+ final boolean mOwnerCanAddInternalSystemWindow;
144148 final IWindowId mWindowId;
145149 WindowToken mToken;
146150 WindowToken mRootToken;
@@ -167,6 +171,8 @@ final class WindowState implements WindowManagerPolicy.WindowState {
167171 boolean mPolicyVisibilityAfterAnim = true;
168172 boolean mAppOpVisibility = true;
169173 boolean mPermanentlyHidden; // the window should never be shown again
174+ // This is a non-system overlay window that is currently force hidden.
175+ private boolean mForceHideNonSystemOverlayWindow;
170176 boolean mAppFreezing;
171177 boolean mAttachedHidden; // is our parent window hidden?
172178 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
@@ -522,6 +528,7 @@ final class WindowState implements WindowManagerPolicy.WindowState {
522528 mAppOp = appOp;
523529 mToken = token;
524530 mOwnerUid = s.mUid;
531+ mOwnerCanAddInternalSystemWindow = s.mCanAddInternalSystemWindow;
525532 mWindowId = new IWindowId.Stub() {
526533 @Override
527534 public void registerFocusObserver(IWindowFocusObserver observer) {
@@ -1882,6 +1889,10 @@ final class WindowState implements WindowManagerPolicy.WindowState {
18821889 // to handle their windows being removed from under them.
18831890 return false;
18841891 }
1892+ if (mForceHideNonSystemOverlayWindow) {
1893+ // This is an alert window that is currently force hidden.
1894+ return false;
1895+ }
18851896 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
18861897 // Already showing.
18871898 return false;
@@ -1955,6 +1966,22 @@ final class WindowState implements WindowManagerPolicy.WindowState {
19551966 return true;
19561967 }
19571968
1969+ void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
1970+ if (mOwnerCanAddInternalSystemWindow
1971+ || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
1972+ return;
1973+ }
1974+ if (mForceHideNonSystemOverlayWindow == forceHide) {
1975+ return;
1976+ }
1977+ mForceHideNonSystemOverlayWindow = forceHide;
1978+ if (forceHide) {
1979+ hideLw(true /* doAnimation */, true /* requestAnim */);
1980+ } else {
1981+ showLw(true /* doAnimation */, true /* requestAnim */);
1982+ }
1983+ }
1984+
19581985 public void setAppOpVisibilityLw(boolean state) {
19591986 if (mAppOpVisibility != state) {
19601987 mAppOpVisibility = state;
@@ -2755,6 +2782,17 @@ final class WindowState implements WindowManagerPolicy.WindowState {
27552782 }
27562783 }
27572784
2785+ /**
2786+ * Returns true if any window added by an application process that if of type
2787+ * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
2788+ * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
2789+ * this window is visible.
2790+ */
2791+ boolean hideNonSystemOverlayWindowsWhenVisible() {
2792+ return (mAttrs.privateFlags & PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
2793+ && mSession.mCanHideNonSystemOverlayWindows;
2794+ }
2795+
27582796 String makeInputChannelName() {
27592797 return Integer.toHexString(System.identityHashCode(this))
27602798 + " " + getWindowTag();
--- a/services/core/java/com/android/server/wm/WindowStateAnimator.java
+++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java
@@ -582,6 +582,7 @@ class WindowStateAnimator {
582582 //dump();
583583 mLastHidden = true;
584584 if (mSurfaceController != null) {
585+ mService.updateNonSystemOverlayWindowsVisibilityIfNeeded(mWin, false);
585586 mSurfaceController.hideInTransaction(reason);
586587 }
587588 }
@@ -1814,6 +1815,7 @@ class WindowStateAnimator {
18141815 if (!shown)
18151816 return false;
18161817
1818+ mService.updateNonSystemOverlayWindowsVisibilityIfNeeded(mWin, true);
18171819 if (mWin.mTurnOnScreen) {
18181820 if (DEBUG_VISIBILITY) Slog.v(TAG, "Show surface turning screen on: " + mWin);
18191821 mWin.mTurnOnScreen = false;
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -71,6 +71,7 @@ import android.content.pm.PackageManager;
7171 import android.content.pm.PackageManager.NameNotFoundException;
7272 import android.content.pm.PackageManagerInternal;
7373 import android.content.pm.ParceledListSlice;
74+import android.content.pm.PermissionInfo;
7475 import android.content.pm.ResolveInfo;
7576 import android.content.pm.ServiceInfo;
7677 import android.content.pm.UserInfo;
@@ -123,6 +124,7 @@ import android.telephony.TelephonyManager;
123124 import android.text.TextUtils;
124125 import android.util.ArrayMap;
125126 import android.util.ArraySet;
127+import android.util.EventLog;
126128 import android.util.Log;
127129 import android.util.Pair;
128130 import android.util.Slog;
@@ -8621,6 +8623,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
86218623 < android.os.Build.VERSION_CODES.M) {
86228624 return false;
86238625 }
8626+ if (!isRuntimePermission(permission)) {
8627+ EventLog.writeEvent(0x534e4554, "62623498", user.getIdentifier(), "");
8628+ return false;
8629+ }
86248630 final PackageManager packageManager = mContext.getPackageManager();
86258631 switch (grantState) {
86268632 case DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED: {
@@ -8646,12 +8652,21 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
86468652 return true;
86478653 } catch (SecurityException se) {
86488654 return false;
8655+ } catch (NameNotFoundException e) {
8656+ return false;
86498657 } finally {
86508658 mInjector.binderRestoreCallingIdentity(ident);
86518659 }
86528660 }
86538661 }
86548662
8663+ public boolean isRuntimePermission(String permissionName) throws NameNotFoundException {
8664+ final PackageManager packageManager = mContext.getPackageManager();
8665+ PermissionInfo permissionInfo = packageManager.getPermissionInfo(permissionName, 0);
8666+ return (permissionInfo.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE)
8667+ == PermissionInfo.PROTECTION_DANGEROUS;
8668+ }
8669+
86558670 @Override
86568671 public int getPermissionGrantState(ComponentName admin, String packageName,
86578672 String permission) throws RemoteException {
Show on old repository browser