diff --git a/core/api/current.txt b/core/api/current.txt index a06e66ff817a..8aa1600cdd25 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -327,6 +327,7 @@ package android { field public static final String SCHEDULE_EXACT_ALARM = "android.permission.SCHEDULE_EXACT_ALARM"; field public static final String SEND_RESPOND_VIA_MESSAGE = "android.permission.SEND_RESPOND_VIA_MESSAGE"; field public static final String SEND_SMS = "android.permission.SEND_SMS"; + field public static final String SENSORS_OPTOUT = "com.vayunmathur.permission.SENSORS_OPTOUT"; field public static final String SET_ALARM = "com.android.alarm.permission.SET_ALARM"; field public static final String SET_ALWAYS_FINISH = "android.permission.SET_ALWAYS_FINISH"; field public static final String SET_ANIMATION_SCALE = "android.permission.SET_ANIMATION_SCALE"; diff --git a/core/api/system-current.txt b/core/api/system-current.txt index c0df87a641bb..390330ac9916 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -6714,6 +6714,7 @@ package android.hardware.display { method @RequiresPermission(android.Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS) public void setBrightnessConfigurationForDisplay(@NonNull android.hardware.display.BrightnessConfiguration, @NonNull String); method @Deprecated @RequiresPermission(android.Manifest.permission.CONTROL_DISPLAY_SATURATION) public void setSaturationLevel(float); field @FlaggedApi("com.android.server.display.feature.flags.virtual_displays_support_desktop_mode") public static final int VIRTUAL_DISPLAY_FLAG_ALLOWS_CONTENT_MODE_SWITCH = 131072; // 0x20000 + field @FlaggedApi("com.android.server.display.feature.flags.virtual_displays_support_desktop_mode") public static final int VIRTUAL_DISPLAY_FLAG_CONNECTION_PENDING = 262144; // 0x40000 field public static final int VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT = 128; // 0x80 field public static final int VIRTUAL_DISPLAY_FLAG_STEAL_TOP_FOCUS_DISABLED = 65536; // 0x10000 field public static final int VIRTUAL_DISPLAY_FLAG_TRUSTED = 1024; // 0x400 @@ -6721,6 +6722,7 @@ package android.hardware.display { public final class VirtualDisplayConfig implements android.os.Parcelable { method @Nullable public android.view.DisplayCutout getDisplayCutout(); + method @FlaggedApi("com.android.server.display.feature.flags.virtual_displays_support_desktop_mode") @NonNull public java.util.List getSupportedModes(); method @FlaggedApi("com.android.server.display.feature.flags.virtual_displays_support_desktop_mode") @Nullable public String getUniqueId(); method public boolean isHomeSupported(); method @FlaggedApi("com.android.window.flags.vdm_force_app_universal_resizable_api") public boolean isIgnoreActivitySizeRestrictions(); @@ -6730,6 +6732,7 @@ package android.hardware.display { method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setDisplayCutout(@Nullable android.view.DisplayCutout); method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setHomeSupported(boolean); method @FlaggedApi("com.android.window.flags.vdm_force_app_universal_resizable_api") @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setIgnoreActivitySizeRestrictions(boolean); + method @FlaggedApi("com.android.server.display.feature.flags.virtual_displays_support_desktop_mode") @NonNull @RequiresPermission(android.Manifest.permission.ADD_TRUSTED_DISPLAY) public android.hardware.display.VirtualDisplayConfig.Builder setSupportedModes(@NonNull java.util.List); method @FlaggedApi("com.android.server.display.feature.flags.virtual_displays_support_desktop_mode") @NonNull @RequiresPermission(android.Manifest.permission.ADD_TRUSTED_DISPLAY) public android.hardware.display.VirtualDisplayConfig.Builder setUniqueId(@Nullable String); } diff --git a/core/java/android/ext/KnownSystemPackages.java b/core/java/android/ext/KnownSystemPackages.java index 839f04c0773b..e962c3bc4f64 100644 --- a/core/java/android/ext/KnownSystemPackages.java +++ b/core/java/android/ext/KnownSystemPackages.java @@ -37,7 +37,7 @@ public final class KnownSystemPackages { mediaProvider = "com.android.providers.media.module"; permissionController = "com.android.permissioncontroller"; settings = "com.android.settings"; - setupWizard = "app.grapheneos.setupwizard"; + setupWizard = "com.vayunmathur.setupwizard"; shell = "com.android.shell"; systemUi = res.getString(R.string.config_systemUi); } diff --git a/core/java/android/ext/LogViewerApp.java b/core/java/android/ext/LogViewerApp.java index 0eb6239bc279..fa975ab112b9 100644 --- a/core/java/android/ext/LogViewerApp.java +++ b/core/java/android/ext/LogViewerApp.java @@ -11,7 +11,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; /** @hide */ public class LogViewerApp { - private static final String PACKAGE_NAME = "app.grapheneos.logviewer"; + private static final String PACKAGE_NAME = "com.vayunmathur.logviewer"; public static final String ACTION_ERROR_REPORT = PACKAGE_NAME + ".ERROR_REPORT"; public static final String ACTION_LOGCAT = PACKAGE_NAME + ".LOGCAT"; diff --git a/core/java/android/hardware/display/DisplayManager.java b/core/java/android/hardware/display/DisplayManager.java index ce3cfd9fc85d..f2ad0bf8a278 100644 --- a/core/java/android/hardware/display/DisplayManager.java +++ b/core/java/android/hardware/display/DisplayManager.java @@ -225,6 +225,7 @@ public final class DisplayManager { VIRTUAL_DISPLAY_FLAG_OWN_FOCUS, VIRTUAL_DISPLAY_FLAG_STEAL_TOP_FOCUS_DISABLED, VIRTUAL_DISPLAY_FLAG_ALLOWS_CONTENT_MODE_SWITCH, + VIRTUAL_DISPLAY_FLAG_CONNECTION_PENDING, }) @Retention(RetentionPolicy.SOURCE) public @interface VirtualDisplayFlag {} @@ -556,6 +557,27 @@ public final class DisplayManager { @SystemApi public static final int VIRTUAL_DISPLAY_FLAG_ALLOWS_CONTENT_MODE_SWITCH = 1 << 17; + /** + * Virtual display flag: Create the display in the connected-but-disabled state, rather than + * enabled and composing immediately. + * + *

A display created this way is reported as a pending connection, the same state a + * physical display occupies between being plugged in and the user deciding what to do with + * it. Nothing is composed to it and no activity is placed on it until + * {@link #enableConnectedDisplay(int)} is called - which is what lets the system ask whether + * the display should mirror or extend before anything is shown on it.

+ * + *

Note that this flag requires {@link #VIRTUAL_DISPLAY_FLAG_TRUSTED}; a display the system + * would not place activities on has nothing to ask about, so it is ignored otherwise.

+ * + * @see #createVirtualDisplay + * @hide + */ + @FlaggedApi(com.android.server + .display.feature.flags.Flags.FLAG_VIRTUAL_DISPLAYS_SUPPORT_DESKTOP_MODE) + @SystemApi + public static final int VIRTUAL_DISPLAY_FLAG_CONNECTION_PENDING = 1 << 18; + /** @hide */ @IntDef(prefix = {"MATCH_CONTENT_FRAMERATE_"}, value = { MATCH_CONTENT_FRAMERATE_UNKNOWN, diff --git a/core/java/android/hardware/display/VirtualDisplayConfig.java b/core/java/android/hardware/display/VirtualDisplayConfig.java index b6fa05f754ac..182b9cbdced3 100644 --- a/core/java/android/hardware/display/VirtualDisplayConfig.java +++ b/core/java/android/hardware/display/VirtualDisplayConfig.java @@ -40,6 +40,7 @@ import android.view.DisplayCutout; import android.view.Surface; import java.util.Collections; +import java.util.List; import java.util.Objects; import java.util.Set; import java.util.concurrent.Executor; @@ -70,6 +71,7 @@ public final class VirtualDisplayConfig implements Parcelable { private final float mDefaultBrightness; private final float mDimBrightness; private final IBrightnessListener mBrightnessListener; + private final List mSupportedModes; private VirtualDisplayConfig( @NonNull String name, @@ -88,7 +90,8 @@ public final class VirtualDisplayConfig implements Parcelable { boolean ignoreActivitySizeRestrictions, @FloatRange(from = 0.0f, to = 1.0f) float defaultBrightness, @FloatRange(from = 0.0f, to = 1.0f) float dimBrightness, - IBrightnessListener brightnessListener) { + IBrightnessListener brightnessListener, + @NonNull List supportedModes) { mName = name; mWidth = width; mHeight = height; @@ -106,6 +109,7 @@ public final class VirtualDisplayConfig implements Parcelable { mDefaultBrightness = defaultBrightness; mDimBrightness = dimBrightness; mBrightnessListener = brightnessListener; + mSupportedModes = supportedModes; } /** @@ -203,6 +207,20 @@ public final class VirtualDisplayConfig implements Parcelable { return mBrightnessListener; } + /** + * Returns the modes this display can be shown at, or an empty list when the owner declared + * none and the display therefore has only the one it was created with. + * + * @hide + */ + @SystemApi + @NonNull + @FlaggedApi(com.android.server.display.feature.flags.Flags + .FLAG_VIRTUAL_DISPLAYS_SUPPORT_DESKTOP_MODE) + public List getSupportedModes() { + return mSupportedModes == null ? Collections.emptyList() : mSupportedModes; + } + /** * Returns the unique identifier for the display. Shouldn't be displayed to the user. * @hide @@ -299,6 +317,7 @@ public final class VirtualDisplayConfig implements Parcelable { dest.writeFloat(mDefaultBrightness); dest.writeFloat(mDimBrightness); dest.writeStrongBinder(mBrightnessListener != null ? mBrightnessListener.asBinder() : null); + dest.writeTypedList(mSupportedModes); } @Override @@ -329,7 +348,8 @@ public final class VirtualDisplayConfig implements Parcelable { && Objects.equals(mDisplayCutout, that.mDisplayCutout) && mDefaultBrightness == that.mDefaultBrightness && mDimBrightness == that.mDimBrightness - && Objects.equals(mBrightnessListener, that.mBrightnessListener); + && Objects.equals(mBrightnessListener, that.mBrightnessListener) + && Objects.equals(mSupportedModes, that.mSupportedModes); } @Override @@ -339,7 +359,8 @@ public final class VirtualDisplayConfig implements Parcelable { mDisplayIdToMirror, mWindowManagerMirroringEnabled, mDisplayCategories, mRequestedRefreshRate, mIsHomeSupported, mDisplayCutout, mIgnoreActivitySizeRestrictions, mDefaultBrightness, mDimBrightness, - mBrightnessListener); + mBrightnessListener, + mSupportedModes); return hashCode; } @@ -363,6 +384,7 @@ public final class VirtualDisplayConfig implements Parcelable { + " mIgnoreActivitySizeRestrictions=" + mIgnoreActivitySizeRestrictions + " mDefaultBrightness=" + mDefaultBrightness + " mDimBrightness=" + mDimBrightness + + " mSupportedModes=" + mSupportedModes + ")"; } @@ -384,6 +406,7 @@ public final class VirtualDisplayConfig implements Parcelable { mDefaultBrightness = in.readFloat(); mDimBrightness = in.readFloat(); mBrightnessListener = IBrightnessListener.Stub.asInterface(in.readStrongBinder()); + mSupportedModes = in.createTypedArrayList(Display.Mode.CREATOR); } /** @@ -455,6 +478,7 @@ public final class VirtualDisplayConfig implements Parcelable { private float mDefaultBrightness = 0.0f; private float mDimBrightness = PowerManager.BRIGHTNESS_INVALID; private IBrightnessListener mBrightnessListener = null; + private List mSupportedModes = Collections.emptyList(); /** * Creates a new Builder. @@ -530,6 +554,29 @@ public final class VirtualDisplayConfig implements Parcelable { return this; } + /** + * Sets the modes this display can be shown at. + * + *

A virtual display otherwise advertises only the single mode it was created with, + * which leaves nothing for the connected-display resolution picker to offer. An owner that + * knows the real sink - a cast receiver that has been told the television's panel modes, + * say - can declare them here, and the mode with the most pixels becomes the default.

+ * + *

Note: honoured only on a trusted display. The modes must all be positive in both + * dimensions; anything else is dropped.

+ * + * @hide + */ + @NonNull + @SystemApi + @RequiresPermission(Manifest.permission.ADD_TRUSTED_DISPLAY) + @FlaggedApi(com.android.server.display.feature.flags.Flags + .FLAG_VIRTUAL_DISPLAYS_SUPPORT_DESKTOP_MODE) + public Builder setSupportedModes(@NonNull List supportedModes) { + mSupportedModes = supportedModes; + return this; + } + /** * Sets the id of the display that the virtual display should mirror. * @hide @@ -751,7 +798,8 @@ public final class VirtualDisplayConfig implements Parcelable { mIgnoreActivitySizeRestrictions, mDefaultBrightness, mDimBrightness, - mBrightnessListener); + mBrightnessListener, + mSupportedModes); } } } diff --git a/core/java/com/android/internal/pm/pkg/parsing/ParsingPackageUtils.java b/core/java/com/android/internal/pm/pkg/parsing/ParsingPackageUtils.java index 699072c44a87..3c82843e396a 100644 --- a/core/java/com/android/internal/pm/pkg/parsing/ParsingPackageUtils.java +++ b/core/java/com/android/internal/pm/pkg/parsing/ParsingPackageUtils.java @@ -1068,7 +1068,14 @@ public class ParsingPackageUtils { } } - if (pkg.isDeclaredHavingCode() && !pkg.getUsesPermissionMapping().containsKey(android.Manifest.permission.OTHER_SENSORS)) { + // MAOS: apps declaring com.vayunmathur.permission.SENSORS_OPTOUT never + // receive the implicit GrapheneOS Sensors (OTHER_SENSORS) permission. The + // opt-out marker is already in the uses-permission mapping here (manifest + // tags parse earlier, hook-added ones merge just above), so its presence + // is a reliable signal at this point. + // (Unrelated to BODY_SENSORS, which this does not touch.) + if (pkg.isDeclaredHavingCode() && !pkg.getUsesPermissionMapping().containsKey(android.Manifest.permission.OTHER_SENSORS) + && !pkg.getUsesPermissionMapping().containsKey("com.vayunmathur.permission.SENSORS_OPTOUT")) { pkg.addImplicitPermission(android.Manifest.permission.OTHER_SENSORS); } diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index d49a48f8d11b..12604625656a 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -9211,6 +9211,17 @@ android:protectionLevel="internal|role|installer" android:permissionFlags="allowedInPrivateComputeCore" /> + + + diff --git a/core/res/res/values/config_ext.xml b/core/res/res/values/config_ext.xml index bd323af7a017..95333ce32764 100644 --- a/core/res/res/values/config_ext.xml +++ b/core/res/res/values/config_ext.xml @@ -38,7 +38,13 @@ false - app.grapheneos.apps + + com.vayunmathur.appstore + + + diff --git a/data/fonts/fallback_order.json b/data/fonts/fallback_order.json index 2fc3f3e3fc5b..3cac8625cdb5 100644 --- a/data/fonts/fallback_order.json +++ b/data/fonts/fallback_order.json @@ -1,4 +1,8 @@ [ + // MAOS: Google Sans Flex backs sans-serif but covers only ~535 codepoints, so + // Roboto has to absorb everything it lacks. First in the list means Cyrillic and + // Greek reach Roboto instead of a Noto face, which would look out of place. + { "id": "roboto-latin" }, { "lang": "und-Arab" }, { "lang": "und-Ethi" }, { "lang": "und-Hebr" }, diff --git a/data/fonts/fonts.xml b/data/fonts/fonts.xml index 8cbc3000c250..a453346df82e 100644 --- a/data/fonts/fonts.xml +++ b/data/fonts/fonts.xml @@ -36,93 +36,84 @@ - Roboto-Regular.ttf - + GoogleSansFlex.ttf - Roboto-Regular.ttf - + GoogleSansFlex.ttf - Roboto-Regular.ttf - + GoogleSansFlex.ttf - Roboto-Regular.ttf - + GoogleSansFlex.ttf - Roboto-Regular.ttf - + GoogleSansFlex.ttf - Roboto-Regular.ttf - + GoogleSansFlex.ttf - Roboto-Regular.ttf - + GoogleSansFlex.ttf - Roboto-Regular.ttf - + GoogleSansFlex.ttf - Roboto-Regular.ttf - + GoogleSansFlex.ttf - Roboto-Regular.ttf - + GoogleSansFlex.ttf + - Roboto-Regular.ttf - + GoogleSansFlex.ttf + - Roboto-Regular.ttf - + GoogleSansFlex.ttf + - Roboto-Regular.ttf - + GoogleSansFlex.ttf + - Roboto-Regular.ttf - + GoogleSansFlex.ttf + - Roboto-Regular.ttf - + GoogleSansFlex.ttf + - Roboto-Regular.ttf - + GoogleSansFlex.ttf + - Roboto-Regular.ttf - + GoogleSansFlex.ttf + - Roboto-Regular.ttf - + GoogleSansFlex.ttf + @@ -383,6 +374,34 @@ + + + Roboto-Regular.ttf + + + + + Roboto-Regular.ttf + + + + + Roboto-Regular.ttf + + + + + Roboto-Regular.ttf + + + + + NotoNaskhArabic-Regular.ttf diff --git a/packages/BackupRestoreConfirmation/AndroidManifest.xml b/packages/BackupRestoreConfirmation/AndroidManifest.xml index fee46576d588..9405700069c0 100644 --- a/packages/BackupRestoreConfirmation/AndroidManifest.xml +++ b/packages/BackupRestoreConfirmation/AndroidManifest.xml @@ -22,6 +22,8 @@ + + diff --git a/packages/CarrierDefaultApp/AndroidManifest.xml b/packages/CarrierDefaultApp/AndroidManifest.xml index f07e33e768c4..9590e91ac5fc 100644 --- a/packages/CarrierDefaultApp/AndroidManifest.xml +++ b/packages/CarrierDefaultApp/AndroidManifest.xml @@ -30,6 +30,8 @@ + + + + + + + + diff --git a/packages/EasterEgg/AndroidManifest.xml b/packages/EasterEgg/AndroidManifest.xml index 34789819e316..c433e5a4c2de 100644 --- a/packages/EasterEgg/AndroidManifest.xml +++ b/packages/EasterEgg/AndroidManifest.xml @@ -33,6 +33,8 @@ + + diff --git a/packages/EncryptedLocalTransport/AndroidManifest.xml b/packages/EncryptedLocalTransport/AndroidManifest.xml index dc3617fa6d4e..3446e6782ca3 100644 --- a/packages/EncryptedLocalTransport/AndroidManifest.xml +++ b/packages/EncryptedLocalTransport/AndroidManifest.xml @@ -21,6 +21,8 @@ android:sharedUserId="android.uid.system" > + + diff --git a/packages/ExternalStorageProvider/AndroidManifest.xml b/packages/ExternalStorageProvider/AndroidManifest.xml index 9b43d9f22390..8a87ea0c226e 100644 --- a/packages/ExternalStorageProvider/AndroidManifest.xml +++ b/packages/ExternalStorageProvider/AndroidManifest.xml @@ -7,6 +7,8 @@ + + + + + + + + + + + + diff --git a/packages/PackageInstaller/AndroidManifest.xml b/packages/PackageInstaller/AndroidManifest.xml index a189c4e7fff4..5f5e2995ebd2 100644 --- a/packages/PackageInstaller/AndroidManifest.xml +++ b/packages/PackageInstaller/AndroidManifest.xml @@ -29,6 +29,8 @@ + + + + + + + + + + diff --git a/packages/SimAppDialog/AndroidManifest.xml b/packages/SimAppDialog/AndroidManifest.xml index 873f6c5bac54..6d0f7ccef8fe 100644 --- a/packages/SimAppDialog/AndroidManifest.xml +++ b/packages/SimAppDialog/AndroidManifest.xml @@ -18,6 +18,8 @@ --> + + + + + + + + + + diff --git a/packages/WAPPushManager/AndroidManifest.xml b/packages/WAPPushManager/AndroidManifest.xml index 15f01e678b43..c237d38904e7 100644 --- a/packages/WAPPushManager/AndroidManifest.xml +++ b/packages/WAPPushManager/AndroidManifest.xml @@ -26,6 +26,8 @@ + + diff --git a/packages/WallpaperBackup/AndroidManifest.xml b/packages/WallpaperBackup/AndroidManifest.xml index 437b65da6d5a..e0e460a9b45a 100644 --- a/packages/WallpaperBackup/AndroidManifest.xml +++ b/packages/WallpaperBackup/AndroidManifest.xml @@ -30,6 +30,8 @@ + + + + diff --git a/packages/services/PacProcessor/AndroidManifest.xml b/packages/services/PacProcessor/AndroidManifest.xml index 533098cbdc75..5d26b468b00a 100644 --- a/packages/services/PacProcessor/AndroidManifest.xml +++ b/packages/services/PacProcessor/AndroidManifest.xml @@ -5,6 +5,8 @@ + + + + mDeclaredModes = new ArrayList<>(); public VirtualDisplayDevice(IBinder displayToken, IBinder appToken, int ownerUid, String ownerPackageName, Surface surface, int flags, @@ -386,7 +408,19 @@ public class VirtualDisplayAdapter extends DisplayAdapter { mDimBrightness = virtualDisplayConfig.getDimBrightness(); mCurrentBrightness = PowerManager.BRIGHTNESS_INVALID; mBrightnessListener = virtualDisplayConfig.getBrightnessListener(); - mMode = createMode(mWidth, mHeight, getRefreshRate()); + for (Display.Mode declared : virtualDisplayConfig.getSupportedModes()) { + if (declared.getPhysicalWidth() > 0 && declared.getPhysicalHeight() > 0) { + // The owner's own rate for this mode, because a sink can offer its largest + // mode more slowly than its smaller ones and the picker shows the rate next + // to the size. Falls back to the display's rate for an owner that declared + // sizes but no rates. + float refreshRate = declared.getRefreshRate() > 0 + ? declared.getRefreshRate() : getRefreshRate(); + mDeclaredModes.add(createMode(declared.getPhysicalWidth(), + declared.getPhysicalHeight(), refreshRate)); + } + } + mMode = modeForLocked(mWidth, mHeight, getRefreshRate()); mSurface = surface; mFlags = flags; mCallback = callback; @@ -580,13 +614,126 @@ public class VirtualDisplayAdapter extends DisplayAdapter { sendTraversalRequestLocked(); mWidth = width; mHeight = height; - mMode = createMode(width, height, getRefreshRate()); + mMode = modeForLocked(width, height, mMode.getRefreshRate()); mDensityDpi = densityDpi; mInfo = null; mPendingChanges |= PENDING_RESIZE; } } + /** + * The declared mode of this size and rate, or a fresh one when it was never declared. + * + * Keeps ids stable across a resize: a display that was created from a declared list must + * keep reporting those same ids in {@code supportedModes}, or the current mode stops + * matching anything in the list Settings is showing. + * + * The rate is part of the question because a sink offers the same resolution several + * times over - a television lists 3840x2160 at eight rates - so matching on size alone + * returns whichever of them happens to come first and silently discards the choice. + * The nearest rate wins rather than an exact match, because the caller's rate has + * usually been round-tripped through a float and 59.94006 is 59.94. + */ + private Display.Mode modeForLocked(int width, int height, float refreshRate) { + Display.Mode best = null; + for (Display.Mode declared : mDeclaredModes) { + if (declared.getPhysicalWidth() != width + || declared.getPhysicalHeight() != height) { + continue; + } + if (best == null + || Math.abs(declared.getRefreshRate() - refreshRate) + < Math.abs(best.getRefreshRate() - refreshRate)) { + best = declared; + } + } + return best != null ? best : createMode(width, height, refreshRate); + } + + /** + * Move to a mode the owner declared, size, rate and all. + * + * Separate from {@link #resizeLocked} because a rate-only change - 1920x1080 at 60 to + * 1920x1080 at 24 - is not a resize, and {@code resizeLocked} returns early when the + * size and density are unchanged. That early return is correct for what it is for, and + * would have made half of every declared mode list unreachable. + */ + private void applyDeclaredModeLocked(Display.Mode mode) { + final int width = mode.getPhysicalWidth(); + final int height = mode.getPhysicalHeight(); + final int densityDpi = densityForLocked(mode); + if (mWidth == width && mHeight == height && mDensityDpi == densityDpi + && mMode.getModeId() == mode.getModeId()) { + return; + } + sendDisplayDeviceEventLocked(this, DISPLAY_DEVICE_EVENT_CHANGED); + sendTraversalRequestLocked(); + mWidth = width; + mHeight = height; + mMode = mode; + mDensityDpi = densityDpi; + mInfo = null; + mPendingChanges |= PENDING_RESIZE; + } + + @Override + public boolean setUserPreferredDisplayModeLocked(Display.Mode mode) { + if (mDeclaredModes.isEmpty()) { + // Nothing was declared, so there is no list to have chosen from and the base + // class's "not supported" answer is the honest one. + return super.setUserPreferredDisplayModeLocked(mode); + } + if (mode == null) { + // Back to the default, which is the largest thing the owner said the sink can do. + applyDeclaredModeLocked(defaultModeLocked()); + return true; + } + for (Display.Mode declared : mDeclaredModes) { + if (declared.getPhysicalWidth() == mode.getPhysicalWidth() + && declared.getPhysicalHeight() == mode.getPhysicalHeight() + && Math.abs(declared.getRefreshRate() - mode.getRefreshRate()) + <= MODE_RATE_TOLERANCE) { + applyDeclaredModeLocked(declared); + return true; + } + } + Slog.w(TAG, "Virtual Display: " + mName + " was asked for an undeclared mode " + mode); + return false; + } + + /** + * The density to compose a declared mode at. + * + * A resolution the owner declared describes a real external sink, so it gets the density + * the platform gives any other external display of that size: + * {@code calculateBaseDensity} with no physical dimensions, which is the same arithmetic + * the owner used to pick the density the display was created at. Deriving it here rather + * than carrying {@code mDensityDpi} across the switch is what keeps the dp workspace the + * same size at every resolution - otherwise dropping from 4K to 1080p would halve it and + * every element on screen would double. + */ + private int densityForLocked(Display.Mode mode) { + return DisplayDensityConfiguration.calculateBaseDensity(0f, 0f, + mode.getPhysicalWidth(), mode.getPhysicalHeight()); + } + + /** The largest declared mode, which is what a display with a sink should default to. */ + private Display.Mode defaultModeLocked() { + Display.Mode best = mDeclaredModes.get(0); + for (Display.Mode candidate : mDeclaredModes) { + long area = (long) candidate.getPhysicalWidth() * candidate.getPhysicalHeight(); + long bestArea = (long) best.getPhysicalWidth() * best.getPhysicalHeight(); + // Fastest among the largest, since a resolution is declared several times + // over at different rates and the default should be the best of them. + if (area > bestArea + || (area == bestArea + && candidate.getRefreshRate() > best.getRefreshRate())) { + best = candidate; + } + } + return best; + } + public void stopLocked() { Slog.d(TAG, "Virtual Display: stopping device " + mName); setSurfaceLocked(null); @@ -602,6 +749,7 @@ public class VirtualDisplayAdapter extends DisplayAdapter { pw.println("mDisplayIdToMirror=" + mDisplayIdToMirror); pw.println("mWindowManagerMirroring=" + mIsWindowManagerMirroring); pw.println("mRequestedRefreshRate=" + mRequestedRefreshRate); + pw.println("mDeclaredModes=" + mDeclaredModes); } @Override @@ -614,8 +762,11 @@ public class VirtualDisplayAdapter extends DisplayAdapter { mInfo.height = mHeight; mInfo.modeId = mMode.getModeId(); mInfo.renderFrameRate = mMode.getRefreshRate(); - mInfo.defaultModeId = mMode.getModeId(); - mInfo.supportedModes = new Display.Mode[] { mMode }; + mInfo.defaultModeId = mDeclaredModes.isEmpty() + ? mMode.getModeId() : defaultModeLocked().getModeId(); + mInfo.supportedModes = mDeclaredModes.isEmpty() + ? new Display.Mode[] { mMode } + : mDeclaredModes.toArray(new Display.Mode[0]); mInfo.densityDpi = mDensityDpi; mInfo.xDpi = mDensityDpi; mInfo.yDpi = mDensityDpi; @@ -631,6 +782,12 @@ public class VirtualDisplayAdapter extends DisplayAdapter { if ((mFlags & VIRTUAL_DISPLAY_FLAG_ALLOWS_CONTENT_MODE_SWITCH) != 0) { mInfo.flags |= DisplayDeviceInfo.FLAG_ALLOWS_CONTENT_MODE_SWITCH; } + // Trusted only: a display the system will not place activities on has no + // mirror-or-extend question to ask, so pending would strand it disabled. + if ((mFlags & VIRTUAL_DISPLAY_FLAG_CONNECTION_PENDING) != 0 + && (mFlags & VIRTUAL_DISPLAY_FLAG_TRUSTED) != 0) { + mInfo.flags |= DisplayDeviceInfo.FLAG_CONNECTION_PENDING; + } if (mNeverBlank) { mInfo.flags |= DisplayDeviceInfo.FLAG_NEVER_BLANK; } diff --git a/services/core/java/com/android/server/location/LocationManagerService.java b/services/core/java/com/android/server/location/LocationManagerService.java index e6fba2fadd1e..94a93f0e83f5 100644 --- a/services/core/java/com/android/server/location/LocationManagerService.java +++ b/services/core/java/com/android/server/location/LocationManagerService.java @@ -23,8 +23,6 @@ import static android.app.compat.CompatChanges.isChangeEnabled; import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE; import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY; import static android.content.pm.PackageManager.PERMISSION_GRANTED; -import static android.ext.settings.GeocoderSettings.GEOCODER_DISABLED; -import static android.ext.settings.GeocoderSettings.GEOCODER_SETTING; import static android.location.LocationManager.BLOCK_PENDING_INTENT_SYSTEM_API_USAGE; import static android.location.LocationManager.FUSED_PROVIDER; import static android.location.LocationManager.GPS_HARDWARE_PROVIDER; @@ -1485,7 +1483,12 @@ public class LocationManagerService extends ILocationManager.Stub implements @Override public boolean isGeocodeAvailable() { - return mGeocodeProvider != null && GEOCODER_SETTING.get(mContext) != GEOCODER_DISABLED + // MAOS drops GrapheneOS's Settings.Global.geocoder gate. That setting chose between + // GrapheneOS's and OpenStreetMap's geocoding servers, and MAOS pins the provider to + // com.vayunmathur.networklocation, which answers from an on-device database instead - + // so there is nothing left to choose and no UI that writes it. Leaving the gate in + // would let a stored 0 from an older build disable geocoding with no way to undo it. + return mGeocodeProvider != null && mContext.checkCallingPermission(android.Manifest.permission.INTERNET) == PERMISSION_GRANTED; } @@ -1497,7 +1500,7 @@ public class LocationManagerService extends ILocationManager.Stub implements mContext, request.getCallingPackage(), request.getCallingAttributionTag()); Preconditions.checkArgument(identity.getUid() == request.getCallingUid()); - if (mGeocodeProvider != null && GEOCODER_SETTING.get(mContext) != GEOCODER_DISABLED) { + if (mGeocodeProvider != null) { boolean hasInternetPerm = mContext.checkCallingPermission( android.Manifest.permission.INTERNET) == PERMISSION_GRANTED; if (hasInternetPerm) { @@ -1525,7 +1528,7 @@ public class LocationManagerService extends ILocationManager.Stub implements mContext, request.getCallingPackage(), request.getCallingAttributionTag()); Preconditions.checkArgument(identity.getUid() == request.getCallingUid()); - if (mGeocodeProvider != null && GEOCODER_SETTING.get(mContext) != GEOCODER_DISABLED) { + if (mGeocodeProvider != null) { boolean hasInternetPerm = mContext.checkCallingPermission( android.Manifest.permission.INTERNET) == PERMISSION_GRANTED; if (hasInternetPerm) { diff --git a/services/core/java/com/android/server/pm/permission/SpecialRuntimePermUtils.java b/services/core/java/com/android/server/pm/permission/SpecialRuntimePermUtils.java index 8ab2dbda2d02..02c72145bd70 100644 --- a/services/core/java/com/android/server/pm/permission/SpecialRuntimePermUtils.java +++ b/services/core/java/com/android/server/pm/permission/SpecialRuntimePermUtils.java @@ -41,6 +41,17 @@ public class SpecialRuntimePermUtils { } if (Manifest.permission.OTHER_SENSORS.equals(perm)) { + // MAOS: SENSORS_OPTOUT withholds the GrapheneOS Sensors permission + // from the fresh-install auto-grant as a failsafe. Declaring apps + // never receive the implicit OTHER_SENSORS request at parse time, + // so there is nothing for the user to grant, not even via Settings. + // The marker is protectionLevel normal, hence granted by install time. + if (ctx.getPackageManager().checkPermission( + "com.vayunmathur.permission.SENSORS_OPTOUT", packageName) + == PackageManager.PERMISSION_GRANTED) { + return false; + } + if (ActivityManager.getService() == null) { // a failsafe: should never happen Slog.d(TAG, "AMS is null"); diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index ea99d989a5aa..cdfc24304576 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -11168,8 +11168,9 @@ public class WindowManagerService extends IWindowManager.Stub /** * Must be called when a screenshot is taken via hardware chord. * - * Notifies all registered visible activities that have registered for screencapture callback, - * Returns a list of visible apps component names. + * MAOS: screenshot-detection callbacks are disabled. This never notifies any + * registered activity and always returns an empty list. Taking screenshots + * themselves is unaffected. */ @Override public List notifyScreenshotListeners(int displayId) { @@ -11178,23 +11179,10 @@ public class WindowManagerService extends IWindowManager.Stub "notifyScreenshotListeners()")) { throw new SecurityException("Requires STATUS_BAR_SERVICE permission"); } - synchronized (mGlobalLock) { - final DisplayContent displayContent = mRoot.getDisplayContent(displayId); - if (displayContent == null) { - return new ArrayList<>(); - } - ArraySet notifiedApps = new ArraySet<>(); - displayContent.forAllActivities( - (ar) -> { - if (!notifiedApps.contains(ar.mActivityComponent) && ar.isVisible() - && ar.isRegisteredForScreenCaptureCallback()) { - ar.reportScreenCaptured(); - notifiedApps.add(ar.mActivityComponent); - } - }, - true /* traverseTopToBottom */); - return List.copyOf(notifiedApps); - } + // MAOS: Android 14 screenshot-detection callbacks must never fire. Apps may + // still register observers, but they are never dispatched to, and SysUI shows + // no detection notice (it only shows one for a non-empty result). + return new ArrayList<>(); } @EnforcePermission(android.Manifest.permission.MANAGE_DISPLAYS)