diff options
32 files changed, 399 insertions, 1057 deletions
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java index 1784d8ad3c6c..7522bfb25b7a 100644 --- a/core/java/android/content/pm/PackageParser.java +++ b/core/java/android/content/pm/PackageParser.java @@ -238,24 +238,6 @@ public class PackageParser { CHILD_PACKAGE_TAGS.add(TAG_EAT_COMMENT); } - // STOPSHIP(b/112545973): remove once feature enabled by default - private static final Set<String> FORCE_AUDIO_PACKAGES; - private static final Set<String> FORCE_VIDEO_PACKAGES; - private static final Set<String> FORCE_IMAGES_PACKAGES; - static { - FORCE_AUDIO_PACKAGES = parsePackageList( - SystemProperties.get(StorageManager.PROP_FORCE_AUDIO)); - FORCE_VIDEO_PACKAGES = parsePackageList( - SystemProperties.get(StorageManager.PROP_FORCE_VIDEO)); - FORCE_IMAGES_PACKAGES = parsePackageList( - SystemProperties.get(StorageManager.PROP_FORCE_IMAGES)); - } - - private static Set<String> parsePackageList(String pkgs) { - if (TextUtils.isEmpty(pkgs)) return Collections.emptySet(); - return new ArraySet<String>(Arrays.asList(pkgs.split(","))); - } - private static final boolean LOG_UNSAFE_BROADCASTS = false; /** @@ -2554,34 +2536,6 @@ public class PackageParser { adjustPackageToBeUnresizeableAndUnpipable(pkg); } - // If the storage model feature flag is disabled, we need to fiddle - // around with permission definitions to return us to pre-Q behavior. - // STOPSHIP(b/112545973): remove once feature enabled by default - if (!StorageManager.hasIsolatedStorage()) { - if ("android".equals(pkg.packageName)) { - final ArraySet<String> newPermissions = new ArraySet<>(); - newPermissions.add(android.Manifest.permission.ACCESS_MEDIA_LOCATION); - newPermissions.add(android.Manifest.permission.WRITE_OBB); - - for (int i = pkg.permissions.size() - 1; i >= 0; i--) { - final Permission p = pkg.permissions.get(i); - if (newPermissions.contains(p.info.name)) { - pkg.permissions.remove(i); - } - } - } - } else { - if (FORCE_AUDIO_PACKAGES.contains(pkg.packageName)) { - pkg.requestedPermissions.add(android.Manifest.permission.READ_EXTERNAL_STORAGE); - } - if (FORCE_VIDEO_PACKAGES.contains(pkg.packageName)) { - pkg.requestedPermissions.add(android.Manifest.permission.READ_EXTERNAL_STORAGE); - } - if (FORCE_IMAGES_PACKAGES.contains(pkg.packageName)) { - pkg.requestedPermissions.add(android.Manifest.permission.READ_EXTERNAL_STORAGE); - } - } - return pkg; } diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java index b82b5ef3f0ba..e50ab6cfc017 100644 --- a/core/java/android/os/Process.java +++ b/core/java/android/os/Process.java @@ -511,7 +511,6 @@ public class Process { * @param appDataDir null-ok the data directory of the app. * @param invokeWith null-ok the command to invoke with. * @param packageName null-ok the name of the package this process belongs to. - * @param packagesForUid null-ok all the packages with the same uid as this process. * @param useSystemGraphicsDriver whether the process uses system graphics driver. * * @param zygoteArgs Additional arguments to supply to the zygote process. @@ -532,14 +531,12 @@ public class Process { @Nullable String appDataDir, @Nullable String invokeWith, @Nullable String packageName, - @Nullable String[] packagesForUid, - @Nullable String sandboxId, boolean useSystemGraphicsDriver, @Nullable String[] zygoteArgs) { return ZYGOTE_PROCESS.start(processClass, niceName, uid, gid, gids, runtimeFlags, mountExternal, targetSdkVersion, seInfo, abi, instructionSet, appDataDir, invokeWith, packageName, - packagesForUid, sandboxId, /*useUsapPool=*/ true, + /*useUsapPool=*/ true, useSystemGraphicsDriver, zygoteArgs); } @@ -556,14 +553,12 @@ public class Process { @Nullable String appDataDir, @Nullable String invokeWith, @Nullable String packageName, - @Nullable String[] packagesForUid, - @Nullable String sandboxId, boolean useSystemGraphicsDriver, @Nullable String[] zygoteArgs) { return WebViewZygote.getProcess().start(processClass, niceName, uid, gid, gids, runtimeFlags, mountExternal, targetSdkVersion, seInfo, abi, instructionSet, appDataDir, invokeWith, packageName, - packagesForUid, sandboxId, /*useUsapPool=*/ false, + /*useUsapPool=*/ false, useSystemGraphicsDriver, zygoteArgs); } diff --git a/core/java/android/os/ZygoteProcess.java b/core/java/android/os/ZygoteProcess.java index 85361587119d..2b170c2a6587 100644 --- a/core/java/android/os/ZygoteProcess.java +++ b/core/java/android/os/ZygoteProcess.java @@ -306,7 +306,6 @@ public class ZygoteProcess { * @param appDataDir null-ok the data directory of the app. * @param invokeWith null-ok the command to invoke with. * @param packageName null-ok the name of the package this process belongs to. - * @param packagesForUid null-ok all the packages with the same uid as this process. * @param zygoteArgs Additional arguments to supply to the zygote process. * @param useSystemGraphicsDriver whether the process uses system graphics driver. * @@ -324,8 +323,6 @@ public class ZygoteProcess { @Nullable String appDataDir, @Nullable String invokeWith, @Nullable String packageName, - @Nullable String[] packagesForUid, - @Nullable String sandboxId, boolean useUsapPool, boolean useSystemGraphicsDriver, @Nullable String[] zygoteArgs) { @@ -338,8 +335,7 @@ public class ZygoteProcess { return startViaZygote(processClass, niceName, uid, gid, gids, runtimeFlags, mountExternal, targetSdkVersion, seInfo, abi, instructionSet, appDataDir, invokeWith, /*startChildZygote=*/ false, - packageName, packagesForUid, sandboxId, - useUsapPool, useSystemGraphicsDriver, zygoteArgs); + packageName, useUsapPool, useSystemGraphicsDriver, zygoteArgs); } catch (ZygoteStartFailedEx ex) { Log.e(LOG_TAG, "Starting VM process through Zygote failed"); @@ -532,7 +528,6 @@ public class ZygoteProcess { * @param startChildZygote Start a sub-zygote. This creates a new zygote process * that has its state cloned from this zygote process. * @param packageName null-ok the name of the package this process belongs to. - * @param packagesForUid null-ok all the packages with the same uid as this process. * @param extraArgs Additional arguments to supply to the zygote process. * @return An object that describes the result of the attempt to start the process. * @throws ZygoteStartFailedEx if process start failed for any reason @@ -550,8 +545,6 @@ public class ZygoteProcess { @Nullable String invokeWith, boolean startChildZygote, @Nullable String packageName, - @Nullable String[] packagesForUid, - @Nullable String sandboxId, boolean useUsapPool, boolean useSystemGraphicsDriver, @Nullable String[] extraArgs) @@ -625,14 +618,6 @@ public class ZygoteProcess { argsForZygote.add("--package-name=" + packageName); } - if (packagesForUid != null && packagesForUid.length > 0) { - argsForZygote.add("--packages-for-uid=" + String.join(",", packagesForUid)); - } - - if (sandboxId != null) { - argsForZygote.add("--sandbox-id=" + sandboxId); - } - argsForZygote.add(processClass); if (extraArgs != null) { @@ -1149,7 +1134,6 @@ public class ZygoteProcess { gids, runtimeFlags, 0 /* mountExternal */, 0 /* targetSdkVersion */, seInfo, abi, instructionSet, null /* appDataDir */, null /* invokeWith */, true /* startChildZygote */, null /* packageName */, - null /* packagesForUid */, null /* sandboxId */, false /* useUsapPool */, false /*useSystemGraphicsDriver*/, extraArgs); } catch (ZygoteStartFailedEx ex) { diff --git a/core/java/android/os/storage/IStorageManager.aidl b/core/java/android/os/storage/IStorageManager.aidl index 9db41116d20a..92fecaddff22 100644 --- a/core/java/android/os/storage/IStorageManager.aidl +++ b/core/java/android/os/storage/IStorageManager.aidl @@ -188,8 +188,6 @@ interface IStorageManager { void allocateBytes(String volumeUuid, long bytes, int flags, String callingPackage) = 78; void runIdleMaintenance() = 79; void abortIdleMaintenance() = 80; - String translateAppToSystem(String path, int pid, int uid) = 81; - String translateSystemToApp(String path, int pid, int uid) = 82; void commitChanges() = 83; boolean supportsCheckpoint() = 84; void startCheckpoint(int numTries) = 85; diff --git a/core/java/android/os/storage/StorageManager.java b/core/java/android/os/storage/StorageManager.java index b9fc186e1c1e..ee62af57b9a0 100644 --- a/core/java/android/os/storage/StorageManager.java +++ b/core/java/android/os/storage/StorageManager.java @@ -155,13 +155,6 @@ public class StorageManager { public static final String PROP_ISOLATED_STORAGE_SNAPSHOT = "sys.isolated_storage_snapshot"; /** {@hide} */ - public static final String PROP_FORCE_AUDIO = "persist.fw.force_audio"; - /** {@hide} */ - public static final String PROP_FORCE_VIDEO = "persist.fw.force_video"; - /** {@hide} */ - public static final String PROP_FORCE_IMAGES = "persist.fw.force_images"; - - /** {@hide} */ public static final String UUID_PRIVATE_INTERNAL = null; /** {@hide} */ public static final String UUID_PRIMARY_PHYSICAL = "primary_physical"; @@ -291,9 +284,6 @@ public class StorageManager { public static final int ENCRYPTION_STATE_ERROR_CORRUPT = IVold.ENCRYPTION_STATE_ERROR_CORRUPT; - /** @hide Prefix used in sandboxIds for apps with sharedUserIds */ - public static final String SHARED_SANDBOX_PREFIX = "shared-"; - private static volatile IStorageManager sStorageManager = null; private final Context mContext; @@ -1618,15 +1608,7 @@ public class StorageManager { * @hide */ public File translateAppToSystem(File file, int pid, int uid) { - // We can only translate absolute paths - if (!file.isAbsolute()) return file; - - try { - return new File(mStorageManager.translateAppToSystem(file.getAbsolutePath(), - pid, uid)); - } catch (RemoteException e) { - throw e.rethrowFromSystemServer(); - } + return file; } /** @@ -1636,15 +1618,7 @@ public class StorageManager { * @hide */ public File translateSystemToApp(File file, int pid, int uid) { - // We can only translate absolute paths - if (!file.isAbsolute()) return file; - - try { - return new File(mStorageManager.translateSystemToApp(file.getAbsolutePath(), - pid, uid)); - } catch (RemoteException e) { - throw e.rethrowFromSystemServer(); - } + return file; } /** diff --git a/core/java/android/os/storage/StorageManagerInternal.java b/core/java/android/os/storage/StorageManagerInternal.java index f1c313838731..942bf94b1db6 100644 --- a/core/java/android/os/storage/StorageManagerInternal.java +++ b/core/java/android/os/storage/StorageManagerInternal.java @@ -16,8 +16,6 @@ package android.os.storage; -import android.annotation.NonNull; -import android.annotation.Nullable; import android.os.IVold; /** @@ -85,30 +83,6 @@ public abstract class StorageManagerInternal { public abstract int getExternalStorageMountMode(int uid, String packageName); /** - * Create storage sandbox for the given package. - * - * <p> This will involve calling into vold to setup appropriate bind mounts. - * - * @param packageName The package for which the sandbox needs to be created. - * @param appId The appId for the given package. - * @param sharedUserId The sharedUserId for given package if it specified - * {@code android:sharedUserId} in the manifest, otherwise {@code null} - * @param userId The userId in which the sandbox needs to be created. - */ - public abstract void prepareSandboxForApp(@NonNull String packageName, int appId, - @Nullable String sharedUserId, int userId); - - /** - * Delete storage sandbox for the given package. - * - * @param packageName The package for which the sandbox needs to be destroyed. - * @param sharedUserId The sharedUserId if specified by the package. - * @param userId The userId in which the sandbox needs to be destroyed. - */ - public abstract void destroySandboxForApp(@NonNull String packageName, - @Nullable String sharedUserId, int userId); - - /** * A listener for reset events in the StorageManagerService. */ public interface ResetListener { @@ -127,9 +101,4 @@ public abstract class StorageManagerInternal { * @param listener The listener that will be notified on reset events. */ public abstract void addResetListener(ResetListener listener); - - /** - * Return the sandboxId for the given package on external storage. - */ - public abstract String getSandboxId(String packageName); } diff --git a/core/java/android/view/RenderNodeAnimator.java b/core/java/android/view/RenderNodeAnimator.java index 04ac92292740..c2f96013142b 100644 --- a/core/java/android/view/RenderNodeAnimator.java +++ b/core/java/android/view/RenderNodeAnimator.java @@ -24,7 +24,6 @@ import android.graphics.CanvasProperty; import android.graphics.Paint; import android.graphics.RecordingCanvas; import android.graphics.RenderNode; -import android.os.Build; import android.os.Handler; import android.os.Looper; import android.util.SparseIntArray; @@ -289,7 +288,8 @@ public class RenderNodeAnimator extends Animator { throw new UnsupportedOperationException(); } - @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) + /** @hide */ + @UnsupportedAppUsage public void setTarget(View view) { mViewTarget = view; setTarget(mViewTarget.mRenderNode); @@ -301,7 +301,7 @@ public class RenderNodeAnimator extends Animator { } /** @hide */ - @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.O) + @UnsupportedAppUsage public void setTarget(DisplayListCanvas canvas) { setTarget((RecordingCanvas) canvas); } diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java index cbcc057811fd..9436633c0c4b 100644 --- a/core/java/android/view/Window.java +++ b/core/java/android/view/Window.java @@ -1090,6 +1090,7 @@ public abstract class Window { * * @hide */ + @UnsupportedAppUsage public void addPrivateFlags(int flags) { setPrivateFlags(flags, flags); } diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java index 72f6c122fe3a..c04a249670fa 100644 --- a/core/java/com/android/internal/os/BatteryStatsImpl.java +++ b/core/java/com/android/internal/os/BatteryStatsImpl.java @@ -12028,7 +12028,7 @@ public class BatteryStatsImpl extends BatteryStats { // if the device is now charging, it means that this is either called // 1. directly when level >= 90 // 2. or from within the runnable that we deferred - // For 1. if we have an existing callback, remove it, since we will immediatelly send a + // For 1. if we have an existing callback, remove it, since we will immediately send a // ACTION_CHARGING // For 2. we remove existing callback so we don't send multiple ACTION_CHARGING mHandler.removeCallbacks(mDeferSetCharging); @@ -12369,7 +12369,6 @@ public class BatteryStatsImpl extends BatteryStats { // If the battery level is at least 90%, always consider the device to be // charging even if it happens to go down a level. changed |= setChargingLocked(true); - mLastChargeStepLevel = level; } else if (!mCharging) { if (mLastChargeStepLevel < level) { // We have not reported that we are charging, but the level has gone up, @@ -12395,17 +12394,16 @@ public class BatteryStatsImpl extends BatteryStats { changed |= setChargingLocked(false); } } - mLastChargeStepLevel = level; if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { mChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, modeBits, elapsedRealtime); mDailyChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, modeBits, elapsedRealtime); - mLastChargeStepLevel = level; mMaxChargeStepLevel = level; mInitStepMode = mCurStepMode; mModStepMode = 0; } + mLastChargeStepLevel = level; } if (changed) { addHistoryRecordLocked(elapsedRealtime, uptime); diff --git a/core/java/com/android/internal/os/Zygote.java b/core/java/com/android/internal/os/Zygote.java index 99175b8becfe..2736c6a7149f 100644 --- a/core/java/com/android/internal/os/Zygote.java +++ b/core/java/com/android/internal/os/Zygote.java @@ -234,14 +234,13 @@ public final class Zygote { public static int forkAndSpecialize(int uid, int gid, int[] gids, int runtimeFlags, int[][] rlimits, int mountExternal, String seInfo, String niceName, int[] fdsToClose, int[] fdsToIgnore, boolean startChildZygote, String instructionSet, String appDataDir, - String packageName, String[] packagesForUID, String sandboxId, int targetSdkVersion) { + int targetSdkVersion) { ZygoteHooks.preFork(); // Resets nice priority for zygote process. resetNicePriority(); int pid = nativeForkAndSpecialize( uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName, fdsToClose, - fdsToIgnore, startChildZygote, instructionSet, appDataDir, packageName, - packagesForUID, sandboxId); + fdsToIgnore, startChildZygote, instructionSet, appDataDir); // Enable tracing as soon as possible for the child process. if (pid == 0) { Zygote.disableExecuteOnly(targetSdkVersion); @@ -257,8 +256,7 @@ public final class Zygote { private static native int nativeForkAndSpecialize(int uid, int gid, int[] gids, int runtimeFlags, int[][] rlimits, int mountExternal, String seInfo, String niceName, int[] fdsToClose, int[] fdsToIgnore, boolean startChildZygote, String instructionSet, - String appDataDir, String packageName, String[] packagesForUID, - String sandboxId); + String appDataDir); /** * Specialize an unspecialized app process. The current VM must have been started @@ -283,11 +281,9 @@ public final class Zygote { */ public static void specializeAppProcess(int uid, int gid, int[] gids, int runtimeFlags, int[][] rlimits, int mountExternal, String seInfo, String niceName, - boolean startChildZygote, String instructionSet, String appDataDir, String packageName, - String[] packagesForUID, String sandboxId) { + boolean startChildZygote, String instructionSet, String appDataDir) { nativeSpecializeAppProcess(uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, - niceName, startChildZygote, instructionSet, appDataDir, - packageName, packagesForUID, sandboxId); + niceName, startChildZygote, instructionSet, appDataDir); // Enable tracing as soon as possible for the child process. Trace.setTracingEnabled(true, runtimeFlags); @@ -306,8 +302,7 @@ public final class Zygote { private static native void nativeSpecializeAppProcess(int uid, int gid, int[] gids, int runtimeFlags, int[][] rlimits, int mountExternal, String seInfo, String niceName, - boolean startChildZygote, String instructionSet, String appDataDir, String packageName, - String[] packagesForUID, String sandboxId); + boolean startChildZygote, String instructionSet, String appDataDir); /** * Called to do any initialization before starting an application. @@ -607,8 +602,7 @@ public final class Zygote { specializeAppProcess(args.mUid, args.mGid, args.mGids, args.mRuntimeFlags, rlimits, args.mMountExternal, args.mSeInfo, args.mNiceName, args.mStartChildZygote, - args.mInstructionSet, args.mAppDataDir, args.mPackageName, - args.mPackagesForUid, args.mSandboxId); + args.mInstructionSet, args.mAppDataDir); disableExecuteOnly(args.mTargetSdkVersion); diff --git a/core/java/com/android/internal/os/ZygoteArguments.java b/core/java/com/android/internal/os/ZygoteArguments.java index 28642d8ba80c..2564f6b4d610 100644 --- a/core/java/com/android/internal/os/ZygoteArguments.java +++ b/core/java/com/android/internal/os/ZygoteArguments.java @@ -119,12 +119,6 @@ class ZygoteArguments { /** from --package-name */ String mPackageName; - /** from --packages-for-uid */ - String[] mPackagesForUid; - - /** from --sandbox-id */ - String mSandboxId; - /** * Any args after and including the first non-option arg (or after a '--') */ @@ -411,13 +405,6 @@ class ZygoteArguments { throw new IllegalArgumentException("Duplicate arg specified"); } mPackageName = arg.substring(arg.indexOf('=') + 1); - } else if (arg.startsWith("--packages-for-uid=")) { - mPackagesForUid = arg.substring(arg.indexOf('=') + 1).split(","); - } else if (arg.startsWith("--sandbox-id=")) { - if (mSandboxId != null) { - throw new IllegalArgumentException("Duplicate arg specified"); - } - mSandboxId = arg.substring(arg.indexOf('=') + 1); } else if (arg.startsWith("--usap-pool-enabled=")) { mUsapPoolStatusSpecified = true; mUsapPoolEnabled = Boolean.parseBoolean(arg.substring(arg.indexOf('=') + 1)); diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java index 2987b4e56fec..785256eb6351 100644 --- a/core/java/com/android/internal/os/ZygoteConnection.java +++ b/core/java/com/android/internal/os/ZygoteConnection.java @@ -267,8 +267,7 @@ class ZygoteConnection { pid = Zygote.forkAndSpecialize(parsedArgs.mUid, parsedArgs.mGid, parsedArgs.mGids, parsedArgs.mRuntimeFlags, rlimits, parsedArgs.mMountExternal, parsedArgs.mSeInfo, parsedArgs.mNiceName, fdsToClose, fdsToIgnore, parsedArgs.mStartChildZygote, - parsedArgs.mInstructionSet, parsedArgs.mAppDataDir, parsedArgs.mPackageName, - parsedArgs.mPackagesForUid, parsedArgs.mSandboxId, parsedArgs.mTargetSdkVersion); + parsedArgs.mInstructionSet, parsedArgs.mAppDataDir, parsedArgs.mTargetSdkVersion); try { if (pid == 0) { diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp index 3d3203ed72dc..8ff16912e932 100644 --- a/core/jni/com_android_internal_os_Zygote.cpp +++ b/core/jni/com_android_internal_os_Zygote.cpp @@ -116,9 +116,6 @@ typedef const std::function<void(std::string)>& fail_fn_t; static pid_t gSystemServerPid = 0; -static const char kIsolatedStorage[] = "persist.sys.isolated_storage"; -static const char kIsolatedStorageSnapshot[] = "sys.isolated_storage_snapshot"; - static constexpr const char* kZygoteClassName = "com/android/internal/os/Zygote"; static jclass gZygoteClass; static jmethodID gCallPostForkSystemServerHooks; @@ -623,249 +620,10 @@ static int UnmountTree(const char* path) { return 0; } -static void CreateDir(const std::string& dir, - mode_t mode, uid_t uid, gid_t gid, - fail_fn_t fail_fn) { - if (TEMP_FAILURE_RETRY(access(dir.c_str(), F_OK)) == 0) { - return; - } else if (errno != ENOENT) { - fail_fn(CREATE_ERROR("Failed to stat %s: %s", dir.c_str(), strerror(errno))); - } - if (fs_prepare_dir(dir.c_str(), mode, uid, gid) != 0) { - fail_fn(CREATE_ERROR("fs_prepare_dir failed on %s: %s", - dir.c_str(), strerror(errno))); - } -} - -static void CreatePkgSandboxTarget(userid_t user_id, fail_fn_t fail_fn) { - ATRACE_CALL(); - - // Create /mnt/user/0/package - std::string pkg_sandbox_dir = StringPrintf("/mnt/user/%d", user_id); - CreateDir(pkg_sandbox_dir, 0751, AID_ROOT, AID_ROOT, fail_fn); - - StringAppendF(&pkg_sandbox_dir, "/package"); - CreateDir(pkg_sandbox_dir, 0755, AID_ROOT, AID_ROOT, fail_fn); -} - -static void BindMount(const std::string& source_dir, const std::string& target_dir, - fail_fn_t fail_fn) { - if (TEMP_FAILURE_RETRY(mount(source_dir.c_str(), target_dir.c_str(), nullptr, - MS_BIND, nullptr)) == -1) { - fail_fn(CREATE_ERROR("Failed to mount %s to %s: %s", - source_dir.c_str(), target_dir.c_str(), strerror(errno))); - } -} - -static void MountPkgSpecificDir(const std::string& mnt_source_root, - const std::string& mnt_target_root, - const std::string& package_name, - uid_t uid, - const char* dir_name, - fail_fn_t fail_fn) { - ATRACE_CALL(); - - std::string mnt_source_dir = StringPrintf("%s/Android/%s/%s", - mnt_source_root.c_str(), dir_name, package_name.c_str()); - - std::string mnt_target_dir = StringPrintf("%s/Android/%s/%s", - mnt_target_root.c_str(), dir_name, package_name.c_str()); - - BindMount(mnt_source_dir, mnt_target_dir, fail_fn); -} - -static void CreateSubDirs(int parent_fd, const std::string& parent_path, - const std::vector<std::string>& sub_dirs, - fail_fn_t fail_fn) { - ATRACE_CALL(); - - for (auto& dir_name : sub_dirs) { - struct stat sb; - if (TEMP_FAILURE_RETRY(fstatat(parent_fd, dir_name.c_str(), &sb, 0)) == 0) { - if (S_ISDIR(sb.st_mode)) { - continue; - } else if (TEMP_FAILURE_RETRY(unlinkat(parent_fd, dir_name.c_str(), 0)) == -1) { - fail_fn(CREATE_ERROR("Failed to unlinkat on %s/%s: %s", - parent_path.c_str(), dir_name.c_str(), strerror(errno))); - } - } else if (errno != ENOENT) { - fail_fn(CREATE_ERROR("Failed to fstatat on %s/%s: %s", - parent_path.c_str(), dir_name.c_str(), strerror(errno))); - } - if (TEMP_FAILURE_RETRY(mkdirat(parent_fd, dir_name.c_str(), 0700)) == -1 && errno != EEXIST) { - fail_fn(CREATE_ERROR("Failed to mkdirat on %s/%s: %s", - parent_path.c_str(), dir_name.c_str(), strerror(errno))); - } - } -} - -static void EnsurePkgSpecificDirs(const std::string& path, - const std::vector<std::string>& package_names, - bool create_sandbox_dir, - fail_fn_t fail_fn) { - ATRACE_CALL(); - - std::string android_dir = StringPrintf("%s/Android", path.c_str()); - android::base::unique_fd android_fd(open(android_dir.c_str(), - O_RDONLY | O_DIRECTORY | O_CLOEXEC)); - if (android_fd.get() < 0) { - if (errno == ENOENT || errno == ENOTDIR) { - if (errno == ENOTDIR && TEMP_FAILURE_RETRY(unlink(android_dir.c_str())) == -1) { - fail_fn(CREATE_ERROR("Failed to unlink %s: %s", - android_dir.c_str(), strerror(errno))); - } - if (TEMP_FAILURE_RETRY(mkdir(android_dir.c_str(), 0700)) == -1 - && errno != EEXIST) { - fail_fn(CREATE_ERROR("Failed to mkdir %s: %s", - android_dir.c_str(), strerror(errno))); - } - android_fd.reset(open(android_dir.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC)); - } - - if (android_fd.get() < 0) { - fail_fn(CREATE_ERROR("Failed to open %s: %s", android_dir.c_str(), strerror(errno))); - } - } - - std::vector<std::string> data_media_obb_dirs = {"data", "media", "obb"}; - if (create_sandbox_dir) { - data_media_obb_dirs.push_back("sandbox"); - } - CreateSubDirs(android_fd.get(), android_dir, data_media_obb_dirs, fail_fn); - if (create_sandbox_dir) { - data_media_obb_dirs.pop_back(); - } - for (auto& dir_name : data_media_obb_dirs) { - std::string data_dir = StringPrintf("%s/%s", android_dir.c_str(), dir_name.c_str()); - android::base::unique_fd data_fd(openat(android_fd, dir_name.c_str(), - O_RDONLY | O_DIRECTORY | O_CLOEXEC)); - if (data_fd.get() < 0) { - fail_fn(CREATE_ERROR("Failed to openat %s/%s: %s", - android_dir.c_str(), dir_name.c_str(), strerror(errno))); - } - CreateSubDirs(data_fd.get(), data_dir, package_names, fail_fn); - } -} - -static void CreatePkgSandboxSource(const std::string& sandbox_source, fail_fn_t fail_fn) { - ATRACE_CALL(); - - struct stat sb; - if (TEMP_FAILURE_RETRY(stat(sandbox_source.c_str(), &sb)) == 0) { - if (S_ISDIR(sb.st_mode)) { - return; - } else if (TEMP_FAILURE_RETRY(unlink(sandbox_source.c_str())) == -1) { - fail_fn(CREATE_ERROR("Failed to unlink %s: %s", - sandbox_source.c_str(), strerror(errno))); - } - } else if (errno != ENOENT) { - fail_fn(CREATE_ERROR("Failed to stat %s: %s", - sandbox_source.c_str(), strerror(errno))); - } - if (TEMP_FAILURE_RETRY(mkdir(sandbox_source.c_str(), 0700)) == -1 && errno != EEXIST) { - fail_fn(CREATE_ERROR("Failed to mkdir %s: %s", - sandbox_source.c_str(), strerror(errno))); - } -} - -static void PreparePkgSpecificDirs(const std::vector<std::string>& package_names, - bool mount_all_obbs, const std::string& sandbox_id, - userid_t user_id, uid_t uid, fail_fn_t fail_fn) { - ATRACE_CALL(); - - std::unique_ptr<DIR, decltype(&closedir)> dirp(opendir("/storage"), closedir); - if (!dirp) { - fail_fn(CREATE_ERROR("Failed to opendir /storage: %s", strerror(errno))); - } - struct dirent* ent; - while ((ent = readdir(dirp.get()))) { - if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..") || !strcmp(ent->d_name, "self")) { - continue; - } - std::string label(ent->d_name); - - std::string mnt_source = StringPrintf("/mnt/runtime/write/%s", label.c_str()); - std::string mnt_target = StringPrintf("/storage/%s", label.c_str()); - if (label == "emulated") { - StringAppendF(&mnt_source, "/%d", user_id); - StringAppendF(&mnt_target, "/%d", user_id); - } - - if (TEMP_FAILURE_RETRY(access(mnt_source.c_str(), F_OK)) == -1) { - ALOGE("Can't access %s: %s", mnt_source.c_str(), strerror(errno)); - continue; - } else if (TEMP_FAILURE_RETRY(access(mnt_target.c_str(), F_OK)) == -1) { - ALOGE("Can't access %s: %s", mnt_target.c_str(), strerror(errno)); - continue; - } - - // Ensure /mnt/runtime/write/emulated/0/Android/{data,media,obb} - EnsurePkgSpecificDirs(mnt_source, package_names, true, fail_fn); - - std::string sandbox_source = StringPrintf("%s/Android/sandbox/%s", - mnt_source.c_str(), sandbox_id.c_str()); - CreatePkgSandboxSource(sandbox_source, fail_fn); - BindMount(sandbox_source, mnt_target, fail_fn); - - // Ensure /storage/emulated/0/Android/{data,media,obb} - EnsurePkgSpecificDirs(mnt_target, package_names, false, fail_fn); - for (auto& package : package_names) { - MountPkgSpecificDir(mnt_source, mnt_target, package, uid, "data", fail_fn); - MountPkgSpecificDir(mnt_source, mnt_target, package, uid, "media", fail_fn); - if (!mount_all_obbs) { - MountPkgSpecificDir(mnt_source, mnt_target, package, uid, "obb", fail_fn); - } - } - - if (mount_all_obbs) { - StringAppendF(&mnt_source, "/Android/obb"); - StringAppendF(&mnt_target, "/Android/obb"); - BindMount(mnt_source, mnt_target, fail_fn); - } - } -} - -static void HandleMountModeInstaller(int mount_mode, - userid_t user_id, - const std::string& sandbox_id, - fail_fn_t fail_fn) { - ATRACE_CALL(); - - std::string obb_mount_dir = StringPrintf("/mnt/user/%d/obb_mount", user_id); - std::string obb_mount_file = StringPrintf("%s/%s", obb_mount_dir.c_str(), sandbox_id.c_str()); - if (mount_mode == MOUNT_EXTERNAL_INSTALLER) { - if (TEMP_FAILURE_RETRY(access(obb_mount_file.c_str(), F_OK)) != -1) { - return; - } else if (errno != ENOENT) { - fail_fn(CREATE_ERROR("Failed to access %s: %s", obb_mount_file.c_str(), strerror(errno))); - } - if (fs_prepare_dir(obb_mount_dir.c_str(), 0700, AID_ROOT, AID_ROOT) != 0) { - fail_fn(CREATE_ERROR("Failed to fs_prepare_dir %s: %s", - obb_mount_dir.c_str(), strerror(errno))); - } - const android::base::unique_fd fd(TEMP_FAILURE_RETRY( - open(obb_mount_file.c_str(), O_RDWR | O_CREAT, 0600))); - if (fd.get() < 0) { - fail_fn(CREATE_ERROR("Failed to create %s: %s", obb_mount_file.c_str(), strerror(errno))); - } - } else { - if (TEMP_FAILURE_RETRY(access(obb_mount_file.c_str(), F_OK)) != -1) { - if (TEMP_FAILURE_RETRY(unlink(obb_mount_file.c_str())) == -1) { - fail_fn(CREATE_ERROR("Failed to unlink %s: %s", - obb_mount_dir.c_str(), strerror(errno))); - } - } else if (errno != ENOENT) { - fail_fn(CREATE_ERROR("Failed to access %s: %s", obb_mount_file.c_str(), strerror(errno))); - } - } -} - // Create a private mount namespace and bind mount appropriate emulated // storage for the given user. static void MountEmulatedStorage(uid_t uid, jint mount_mode, - bool force_mount_namespace, const std::string& package_name, - const std::vector<std::string>& packages_for_uid, - const std::string& sandbox_id, + bool force_mount_namespace, fail_fn_t fail_fn) { // See storage config details at http://source.android.com/tech/storage/ ATRACE_CALL(); @@ -896,73 +654,25 @@ static void MountEmulatedStorage(uid_t uid, jint mount_mode, return; } - if (/* DISABLES CODE */ (false) - && GetBoolProperty(kIsolatedStorageSnapshot, GetBoolProperty(kIsolatedStorage, true))) { - if (mount_mode == MOUNT_EXTERNAL_FULL || mount_mode == MOUNT_EXTERNAL_LEGACY) { - storage_source = (mount_mode == MOUNT_EXTERNAL_FULL) - ? "/mnt/runtime/full" : "/mnt/runtime/write"; - if (TEMP_FAILURE_RETRY(mount(storage_source.string(), "/storage", - NULL, MS_BIND | MS_REC | MS_SLAVE, NULL)) == -1) { - fail_fn(CREATE_ERROR("Failed to mount %s to /storage: %s", - storage_source.string(), - strerror(errno))); - } - - // Mount user-specific symlink helper into place - userid_t user_id = multiuser_get_user_id(uid); - const String8 user_source(String8::format("/mnt/user/%d", user_id)); - if (fs_prepare_dir(user_source.string(), 0751, 0, 0) == -1) { - fail_fn(CREATE_ERROR("fs_prepare_dir failed on %s (%s)", - user_source.string(), strerror(errno))); - } - - if (TEMP_FAILURE_RETRY(mount(user_source.string(), "/storage/self", nullptr, MS_BIND, - nullptr)) == -1) { - fail_fn(CREATE_ERROR("Failed to mount %s to /storage/self: %s", - user_source.string(), - strerror(errno))); - } - } else { - if (package_name.empty() || sandbox_id.empty()) { - return; - } - - userid_t user_id = multiuser_get_user_id(uid); - CreatePkgSandboxTarget(user_id, fail_fn); - - std::string pkg_sandbox_dir = StringPrintf("/mnt/user/%d/package", user_id); - if (TEMP_FAILURE_RETRY(mount(pkg_sandbox_dir.c_str(), "/storage", - nullptr, MS_BIND | MS_REC | MS_SLAVE, nullptr)) == -1) { - fail_fn(CREATE_ERROR("Failed to mount %s to /storage: %s", - pkg_sandbox_dir.c_str(), strerror(errno))); - } - - HandleMountModeInstaller(mount_mode, user_id, sandbox_id, fail_fn); - - PreparePkgSpecificDirs(packages_for_uid, - mount_mode == MOUNT_EXTERNAL_INSTALLER, sandbox_id, user_id, uid, fail_fn); - } - } else { - if (TEMP_FAILURE_RETRY(mount(storage_source.string(), "/storage", nullptr, - MS_BIND | MS_REC | MS_SLAVE, nullptr)) == -1) { - fail_fn(CREATE_ERROR("Failed to mount %s to /storage: %s", - storage_source.string(), - strerror(errno))); - } + if (TEMP_FAILURE_RETRY(mount(storage_source.string(), "/storage", nullptr, + MS_BIND | MS_REC | MS_SLAVE, nullptr)) == -1) { + fail_fn(CREATE_ERROR("Failed to mount %s to /storage: %s", + storage_source.string(), + strerror(errno))); + } - // Mount user-specific symlink helper into place - userid_t user_id = multiuser_get_user_id(uid); - const String8 user_source(String8::format("/mnt/user/%d", user_id)); - if (fs_prepare_dir(user_source.string(), 0751, 0, 0) == -1) { - fail_fn(CREATE_ERROR("fs_prepare_dir failed on %s", - user_source.string())); - } + // Mount user-specific symlink helper into place + userid_t user_id = multiuser_get_user_id(uid); + const String8 user_source(String8::format("/mnt/user/%d", user_id)); + if (fs_prepare_dir(user_source.string(), 0751, 0, 0) == -1) { + fail_fn(CREATE_ERROR("fs_prepare_dir failed on %s", + user_source.string())); + } - if (TEMP_FAILURE_RETRY(mount(user_source.string(), "/storage/self", - nullptr, MS_BIND, nullptr)) == -1) { - fail_fn(CREATE_ERROR("Failed to mount %s to /storage/self: %s", - user_source.string(), strerror(errno))); - } + if (TEMP_FAILURE_RETRY(mount(user_source.string(), "/storage/self", + nullptr, MS_BIND, nullptr)) == -1) { + fail_fn(CREATE_ERROR("Failed to mount %s to /storage/self: %s", + user_source.string(), strerror(errno))); } } @@ -1136,45 +846,6 @@ static std::optional<std::vector<int>> ExtractJIntArray(JNIEnv* env, } /** - * A helper method for converting managed string arrays to native vectors. A - * fatal error is generated if a problem is encountered in extracting a non-null array. - * - * @param env Managed runtime environment - * @param process_name A native representation of the process name - * @param managed_process_name A managed representation of the process name - * @param managed_array The managed string array to extract - * - * @return An empty option if the managed array is null. A optional-wrapped - * vector otherwise. - */ -static std::optional<std::vector<std::string>> ExtractJStringArray(JNIEnv* env, - const char* process_name, - jstring managed_process_name, - jobjectArray managed_array) { - if (managed_array == nullptr) { - return std::nullopt; - } else { - jsize element_count = env->GetArrayLength(managed_array); - std::vector<std::string> native_string_vector; - native_string_vector.reserve(element_count); - - for (jsize array_index = 0; array_index < element_count; ++array_index) { - jstring managed_string = (jstring) env->GetObjectArrayElement(managed_array, array_index); - auto native_string = ExtractJString(env, process_name, managed_process_name, managed_string); - - if (LIKELY(native_string.has_value())) { - native_string_vector.emplace_back(std::move(native_string.value())); - } else { - ZygoteFailure(env, process_name, managed_process_name, - "Null string found in managed string array."); - } - } - - return std::move(native_string_vector); - } -} - -/** * A utility function for blocking signals. * * @param signum Signal number to block @@ -1287,9 +958,7 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids, jint mount_external, jstring managed_se_info, jstring managed_nice_name, bool is_system_server, bool is_child_zygote, jstring managed_instruction_set, - jstring managed_app_data_dir, jstring managed_package_name, - jobjectArray managed_pacakges_for_uid, - jstring managed_sandbox_id) { + jstring managed_app_data_dir) { const char* process_name = is_system_server ? "system_server" : "zygote"; auto fail_fn = std::bind(ZygoteFailure, env, process_name, managed_nice_name, _1); auto extract_fn = std::bind(ExtractJString, env, process_name, managed_nice_name, _1); @@ -1298,8 +967,6 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids, auto nice_name = extract_fn(managed_nice_name); auto instruction_set = extract_fn(managed_instruction_set); auto app_data_dir = extract_fn(managed_app_data_dir); - auto package_name = extract_fn(managed_package_name); - auto sandbox_id = extract_fn(managed_sandbox_id); // Keep capabilities across UID change, unless we're staying root. if (uid != 0) { @@ -1325,20 +992,7 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids, ALOGW("Native bridge will not be used because managed_app_data_dir == nullptr."); } - if (!package_name.has_value()) { - if (is_system_server) { - package_name.emplace("android"); - } else { - package_name.emplace(""); - } - } - - std::vector<std::string> packages_for_uid = - ExtractJStringArray(env, process_name, managed_nice_name, managed_pacakges_for_uid). - value_or(std::vector<std::string>()); - - MountEmulatedStorage(uid, mount_external, use_native_bridge, package_name.value(), - packages_for_uid, sandbox_id.value_or(""), fail_fn); + MountEmulatedStorage(uid, mount_external, use_native_bridge, fail_fn); // If this zygote isn't root, it won't be able to create a process group, // since the directory is owned by root. @@ -1681,8 +1335,7 @@ static jint com_android_internal_os_Zygote_nativeForkAndSpecialize( jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jintArray managed_fds_to_close, jintArray managed_fds_to_ignore, jboolean is_child_zygote, - jstring instruction_set, jstring app_data_dir, jstring package_name, - jobjectArray packages_for_uid, jstring sandbox_id) { + jstring instruction_set, jstring app_data_dir) { jlong capabilities = CalculateCapabilities(env, uid, gid, gids, is_child_zygote); if (UNLIKELY(managed_fds_to_close == nullptr)) { @@ -1713,8 +1366,7 @@ static jint com_android_internal_os_Zygote_nativeForkAndSpecialize( SpecializeCommon(env, uid, gid, gids, runtime_flags, rlimits, capabilities, capabilities, mount_external, se_info, nice_name, false, - is_child_zygote == JNI_TRUE, instruction_set, app_data_dir, - package_name, packages_for_uid, sandbox_id); + is_child_zygote == JNI_TRUE, instruction_set, app_data_dir); } return pid; } @@ -1740,7 +1392,7 @@ static jint com_android_internal_os_Zygote_nativeForkSystemServer( SpecializeCommon(env, uid, gid, gids, runtime_flags, rlimits, permitted_capabilities, effective_capabilities, MOUNT_EXTERNAL_DEFAULT, nullptr, nullptr, true, - false, nullptr, nullptr, nullptr, nullptr, nullptr); + false, nullptr, nullptr); } else if (pid > 0) { // The zygote process checks whether the child process has died or not. ALOGI("System server process %d has been created", pid); @@ -1859,16 +1511,13 @@ static void com_android_internal_os_Zygote_nativeSpecializeAppProcess( JNIEnv* env, jclass, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, - jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, - jstring package_name, jobjectArray packages_for_uid, - jstring sandbox_id) { + jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir) { jlong capabilities = CalculateCapabilities(env, uid, gid, gids, is_child_zygote); SpecializeCommon(env, uid, gid, gids, runtime_flags, rlimits, capabilities, capabilities, mount_external, se_info, nice_name, false, - is_child_zygote == JNI_TRUE, instruction_set, app_data_dir, - package_name, packages_for_uid, sandbox_id); + is_child_zygote == JNI_TRUE, instruction_set, app_data_dir); } /** @@ -2031,7 +1680,7 @@ static jboolean com_android_internal_os_Zygote_nativeDisableExecuteOnly(JNIEnv* static const JNINativeMethod gMethods[] = { { "nativeForkAndSpecialize", - "(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)I", + "(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/String;)I", (void *) com_android_internal_os_Zygote_nativeForkAndSpecialize }, { "nativeForkSystemServer", "(II[II[[IJJ)I", (void *) com_android_internal_os_Zygote_nativeForkSystemServer }, @@ -2044,7 +1693,7 @@ static const JNINativeMethod gMethods[] = { { "nativeForkUsap", "(II[I)I", (void *) com_android_internal_os_Zygote_nativeForkUsap }, { "nativeSpecializeAppProcess", - "(II[II[[IILjava/lang/String;Ljava/lang/String;ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V", + "(II[II[[IILjava/lang/String;Ljava/lang/String;ZLjava/lang/String;Ljava/lang/String;)V", (void *) com_android_internal_os_Zygote_nativeSpecializeAppProcess }, { "nativeInitNativeState", "(Z)V", (void *) com_android_internal_os_Zygote_nativeInitNativeState }, diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_bouncer.xml b/packages/SystemUI/res-keyguard/layout/keyguard_bouncer.xml index 8c80e78733ef..79868093fb12 100644 --- a/packages/SystemUI/res-keyguard/layout/keyguard_bouncer.xml +++ b/packages/SystemUI/res-keyguard/layout/keyguard_bouncer.xml @@ -19,8 +19,7 @@ android:layout_height="match_parent" android:background="@android:color/transparent" android:clipChildren="false" - android:clipToPadding="false" - android:fitsSystemWindows="true"> + android:clipToPadding="false"> <include style="@style/BouncerSecurityContainer" diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPatternView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPatternView.java index 8899bd9ea9f2..55499dab05f3 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardPatternView.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPatternView.java @@ -231,6 +231,13 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit public void showUsabilityHint() { } + @Override + public boolean disallowInterceptTouch(MotionEvent event) { + mTempRect.set(mLockPatternView.getLeft(), mLockPatternView.getTop(), + mLockPatternView.getRight(), mLockPatternView.getBottom()); + return mTempRect.contains((int) event.getX(), (int) event.getY()); + } + /** TODO: hook this up */ public void cleanUp() { if (DEBUG) Log.v(TAG, "Cleanup() called on " + this); diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java index 6f581596ab1a..d051defc1f25 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java @@ -26,12 +26,18 @@ import android.util.AttributeSet; import android.util.Log; import android.util.Slog; import android.util.StatsLog; +import android.util.TypedValue; import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.VelocityTracker; import android.view.View; +import android.view.ViewConfiguration; import android.view.WindowManager; import android.widget.FrameLayout; import androidx.annotation.VisibleForTesting; +import androidx.dynamicanimation.animation.DynamicAnimation; +import androidx.dynamicanimation.animation.SpringAnimation; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; @@ -60,6 +66,11 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe // Bouncer is dismissed due to sim card unlock code entered. private static final int BOUNCER_DISMISS_SIM = 4; + // Make the view move slower than the finger, as if the spring were applying force. + private static final float TOUCH_Y_MULTIPLIER = 0.25f; + // How much you need to drag the bouncer to trigger an auth retry (in dps.) + private static final float MIN_DRAG_SIZE = 10; + private KeyguardSecurityModel mSecurityModel; private LockPatternUtils mLockPatternUtils; @@ -70,10 +81,18 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe private SecurityCallback mSecurityCallback; private AlertDialog mAlertDialog; private InjectionInflationController mInjectionInflationController; + private boolean mSwipeUpToRetry; + private final ViewConfiguration mViewConfiguration; + private final SpringAnimation mSpringAnimation; + private final VelocityTracker mVelocityTracker = VelocityTracker.obtain(); private final KeyguardUpdateMonitor mUpdateMonitor; private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class); + private float mLastTouchY = -1; + private int mActivePointerId = -1; + private boolean mIsDragging; + private float mStartTouchY = -1; // Used to notify the container when something interesting happens. public interface SecurityCallback { @@ -104,9 +123,10 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe mSecurityModel = new KeyguardSecurityModel(context); mLockPatternUtils = new LockPatternUtils(context); mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext); - + mSpringAnimation = new SpringAnimation(this, DynamicAnimation.Y); mInjectionInflationController = new InjectionInflationController( SystemUIFactory.getInstance().getRootComponent()); + mViewConfiguration = ViewConfiguration.get(context); } public void setSecurityCallback(SecurityCallback callback) { @@ -118,6 +138,8 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe if (mCurrentSecuritySelection != SecurityMode.None) { getSecurityView(mCurrentSecuritySelection).onResume(reason); } + updateBiometricRetry(); + updatePaddings(); } @Override @@ -131,6 +153,95 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe } } + @Override + public boolean shouldDelayChildPressedState() { + return true; + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent event) { + switch (event.getActionMasked()) { + case MotionEvent.ACTION_DOWN: + int pointerIndex = event.getActionIndex(); + mStartTouchY = event.getY(pointerIndex); + mActivePointerId = event.getPointerId(pointerIndex); + mVelocityTracker.clear(); + break; + case MotionEvent.ACTION_MOVE: + if (mIsDragging) { + return true; + } + if (!mSwipeUpToRetry) { + return false; + } + // Avoid dragging the pattern view + if (mCurrentSecurityView.disallowInterceptTouch(event)) { + return false; + } + int index = event.findPointerIndex(mActivePointerId); + int touchSlop = mViewConfiguration.getScaledTouchSlop(); + if (mCurrentSecurityView != null + && mStartTouchY - event.getY(index) > touchSlop) { + mIsDragging = true; + return true; + } + break; + case MotionEvent.ACTION_CANCEL: + case MotionEvent.ACTION_UP: + mIsDragging = false; + break; + } + return false; + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + final int action = event.getActionMasked(); + switch (action) { + case MotionEvent.ACTION_MOVE: + mVelocityTracker.addMovement(event); + int pointerIndex = event.findPointerIndex(mActivePointerId); + float y = event.getY(pointerIndex); + if (mLastTouchY != -1) { + float dy = y - mLastTouchY; + setTranslationY(getTranslationY() + dy * TOUCH_Y_MULTIPLIER); + } + mLastTouchY = y; + break; + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_CANCEL: + mActivePointerId = -1; + mLastTouchY = -1; + mIsDragging = false; + startSpringAnimation(mVelocityTracker.getYVelocity()); + break; + case MotionEvent.ACTION_POINTER_UP: + int index = event.getActionIndex(); + int pointerId = event.getPointerId(index); + if (pointerId == mActivePointerId) { + // This was our active pointer going up. Choose a new + // active pointer and adjust accordingly. + final int newPointerIndex = index == 0 ? 1 : 0; + mLastTouchY = event.getY(newPointerIndex); + mActivePointerId = event.getPointerId(newPointerIndex); + } + break; + } + if (action == MotionEvent.ACTION_UP) { + if (-getTranslationY() > TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, + MIN_DRAG_SIZE, getResources().getDisplayMetrics())) { + mUpdateMonitor.requestFaceAuth(); + } + } + return true; + } + + private void startSpringAnimation(float startVelocity) { + mSpringAnimation + .setStartVelocity(startVelocity) + .animateToFinalPosition(0); + } + public void startAppearAnimation() { if (mCurrentSecuritySelection != SecurityMode.None) { getSecurityView(mCurrentSecuritySelection).startAppearAnimation(); @@ -145,6 +256,18 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe return false; } + /** + * Enables/disables swipe up to retry on the bouncer. + */ + private void updateBiometricRetry() { + SecurityMode securityMode = getSecurityMode(); + int userId = KeyguardUpdateMonitor.getCurrentUser(); + mSwipeUpToRetry = mUpdateMonitor.isUnlockWithFacePossible(userId) + && securityMode != SecurityMode.SimPin + && securityMode != SecurityMode.SimPuk + && securityMode != SecurityMode.None; + } + public CharSequence getTitle() { return mSecurityViewFlipper.getTitle(); } @@ -195,6 +318,20 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe mSecurityViewFlipper.setLockPatternUtils(mLockPatternUtils); } + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + updatePaddings(); + } + + private void updatePaddings() { + int bottomPadding = getRootWindowInsets().getSystemWindowInsets().bottom; + if (getPaddingBottom() == bottomPadding) { + return; + } + setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), bottomPadding); + } + private void showDialog(String title, String message) { if (mAlertDialog != null) { mAlertDialog.dismiss(); @@ -467,7 +604,6 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe } public void reportUnlockAttempt(int userId, boolean success, int timeoutMs) { - KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext); if (success) { StatsLog.write(StatsLog.KEYGUARD_BOUNCER_PASSWORD_ENTERED, StatsLog.KEYGUARD_BOUNCER_PASSWORD_ENTERED__RESULT__SUCCESS); diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityView.java index 272b3bdf56a4..e10819473dea 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityView.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityView.java @@ -16,6 +16,7 @@ package com.android.keyguard; import android.content.res.ColorStateList; +import android.view.MotionEvent; import com.android.internal.widget.LockPatternUtils; @@ -137,4 +138,14 @@ public interface KeyguardSecurityView { * @return The View's title. */ CharSequence getTitle(); + + /** + * If the parent should not be allowed to intercept touch events. + * @param event A touch event. + * @return {@code true} if touch should be passed forward. + * @see android.view.ViewGroup#requestDisallowInterceptTouchEvent(boolean) + */ + default boolean disallowInterceptTouch(MotionEvent event) { + return false; + } } diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java index 83b98b0f8bb1..dd6ccb2b3a88 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -1686,7 +1686,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { && mFpm.getEnrolledFingerprints(userId).size() > 0; } - private boolean isUnlockWithFacePossible(int userId) { + /** + * If face hardware is available and user has enrolled. Not considering encryption or + * lockdown state. + */ + public boolean isUnlockWithFacePossible(int userId) { return mFaceManager != null && mFaceManager.isHardwareDetected() && !isFaceDisabled(userId) && mFaceManager.hasEnrolledTemplates(userId); @@ -2273,6 +2277,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { return isSimPinSecure(); } + /** + * If any SIM cards are currently secure. + * @see #isSimPinSecure(State) + */ public boolean isSimPinSecure() { // True if any SIM is pin secure for (SubscriptionInfo info : getSubscriptionInfo(false /* forceReload */)) { @@ -2338,11 +2346,13 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { return changed; } + /** + * If the {@code state} is currently requiring a SIM PIN, PUK, or is disabled. + */ public static boolean isSimPinSecure(IccCardConstants.State state) { - final IccCardConstants.State simState = state; - return (simState == IccCardConstants.State.PIN_REQUIRED - || simState == IccCardConstants.State.PUK_REQUIRED - || simState == IccCardConstants.State.PERM_DISABLED); + return (state == IccCardConstants.State.PIN_REQUIRED + || state == IccCardConstants.State.PUK_REQUIRED + || state == IccCardConstants.State.PERM_DISABLED); } public DisplayClientState getCachedDisplayClientState() { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java index 8aa4f0382649..028dbd717f6f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java @@ -981,6 +981,7 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback @Override public void onNavigationModeChanged(int mode) { mNavBarMode = mode; + updateScreenPinningGestures(); } public void disableAnimationsDuringHide(long delay) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java index 831d882d68a7..a6db05e7a595 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java @@ -628,6 +628,8 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav // as they are used for exiting. final boolean pinningActive = ActivityManagerWrapper.getInstance().isScreenPinningActive(); if (mOverviewProxyService.isEnabled()) { + // Force disable recents when not in legacy mode + disableRecent |= !QuickStepContract.isLegacyMode(mNavBarMode); if (pinningActive) { disableBack = disableHome = false; } diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java index baec3ccd953f..c6461491b8cd 100644 --- a/services/core/java/com/android/server/StorageManagerService.java +++ b/services/core/java/com/android/server/StorageManagerService.java @@ -49,7 +49,6 @@ import static org.xmlpull.v1.XmlPullParser.START_TAG; import android.Manifest; import android.annotation.Nullable; import android.app.ActivityManager; -import android.app.ActivityManagerInternal; import android.app.AppOpsManager; import android.app.IActivityManager; import android.app.KeyguardManager; @@ -60,7 +59,6 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.pm.ApplicationInfo; import android.content.pm.IPackageManager; import android.content.pm.IPackageMoveObserver; import android.content.pm.PackageManager; @@ -98,7 +96,6 @@ import android.os.SystemClock; import android.os.SystemProperties; import android.os.UserHandle; import android.os.UserManager; -import android.os.UserManagerInternal; import android.os.storage.DiskInfo; import android.os.storage.IObbActionListener; import android.os.storage.IStorageEventListener; @@ -117,13 +114,11 @@ import android.sysprop.VoldProperties; import android.text.TextUtils; import android.text.format.DateUtils; import android.util.ArrayMap; -import android.util.ArraySet; import android.util.AtomicFile; import android.util.DataUnit; import android.util.Log; import android.util.Pair; import android.util.Slog; -import android.util.SparseArray; import android.util.TimeUtils; import android.util.Xml; @@ -179,8 +174,6 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; @@ -350,9 +343,6 @@ class StorageManagerService extends IStorageManager.Stub @GuardedBy("mLock") private String mMoveTargetUuid; - @GuardedBy("mPackagesLock") - private final SparseArray<ArraySet<String>> mPackages = new SparseArray<>(); - private volatile int mCurrentUserId = UserHandle.USER_SYSTEM; /** Holding lock for AppFuse business */ @@ -469,14 +459,11 @@ class StorageManagerService extends IStorageManager.Stub private volatile IVold mVold; private volatile IStoraged mStoraged; - private volatile boolean mSystemReady = false; private volatile boolean mBootCompleted = false; private volatile boolean mDaemonConnected = false; private volatile boolean mSecureKeyguardShowing = true; private PackageManagerInternal mPmInternal; - private UserManagerInternal mUmInternal; - private ActivityManagerInternal mAmInternal; private IPackageManager mIPackageManager; private IAppOpsService mIAppOpsService; @@ -965,7 +952,7 @@ class StorageManagerService extends IStorageManager.Stub mVold.onUserAdded(user.id, user.serialNumber); } for (int userId : systemUnlockedUsers) { - sendUserStartedCallback(userId); + mVold.onUserStarted(userId); mStoraged.onUserStarted(userId); } mVold.onSecureKeyguardStateChanged(mSecureKeyguardShowing); @@ -983,7 +970,7 @@ class StorageManagerService extends IStorageManager.Stub // staging area is ready so it's ready for zygote-forked apps to // bind mount against. try { - sendUserStartedCallback(userId); + mVold.onUserStarted(userId); mStoraged.onUserStarted(userId); } catch (Exception e) { Slog.wtf(TAG, e); @@ -1016,53 +1003,12 @@ class StorageManagerService extends IStorageManager.Stub Slog.wtf(TAG, e); } - synchronized (mPackagesLock) { - mPackages.delete(userId); - } - synchronized (mLock) { mSystemUnlockedUsers = ArrayUtils.removeInt(mSystemUnlockedUsers, userId); } } - private void sendUserStartedCallback(int userId) throws Exception { - if (!ENABLE_ISOLATED_STORAGE) { - mVold.onUserStarted(userId, EmptyArray.STRING, EmptyArray.INT, EmptyArray.STRING); - } - - final String[] packages; - final int[] appIds; - final String[] sandboxIds; - final SparseArray<String> sharedUserIds = mPmInternal.getAppsWithSharedUserIds(); - final List<ApplicationInfo> appInfos = - mContext.getPackageManager().getInstalledApplicationsAsUser( - PackageManager.MATCH_UNINSTALLED_PACKAGES, userId); - synchronized (mPackagesLock) { - final ArraySet<String> userPackages = new ArraySet<>(); - final ArrayMap<String, Integer> packageToAppId = new ArrayMap<>(); - for (int i = appInfos.size() - 1; i >= 0; --i) { - final ApplicationInfo appInfo = appInfos.get(i); - if (appInfo.isInstantApp()) { - continue; - } - userPackages.add(appInfo.packageName); - packageToAppId.put(appInfo.packageName, UserHandle.getAppId(appInfo.uid)); - } - mPackages.put(userId, userPackages); - - packages = new String[userPackages.size()]; - appIds = new int[userPackages.size()]; - sandboxIds = new String[userPackages.size()]; - for (int i = userPackages.size() - 1; i >= 0; --i) { - packages[i] = userPackages.valueAt(i); - appIds[i] = packageToAppId.get(packages[i]); - sandboxIds[i] = getSandboxId(packages[i], sharedUserIds.get(appIds[i])); - } - } - mVold.onUserStarted(userId, packages, appIds, sandboxIds); - } - - private boolean supportsBlockCheckpoint() throws RemoteException { + private boolean supportsBlockCheckpoint() throws RemoteException { enforcePermission(android.Manifest.permission.MOUNT_FORMAT_FILESYSTEMS); return mVold.supportsBlockCheckpoint(); } @@ -1596,11 +1542,6 @@ class StorageManagerService extends IStorageManager.Stub connect(); } - private static String getSandboxId(String packageName, String sharedUserId) { - return sharedUserId == null - ? packageName : StorageManager.SHARED_SANDBOX_PREFIX + sharedUserId; - } - private void connect() { IBinder binder = ServiceManager.getService("storaged"); if (binder != null) { @@ -1663,8 +1604,6 @@ class StorageManagerService extends IStorageManager.Stub private void servicesReady() { mPmInternal = LocalServices.getService(PackageManagerInternal.class); - mUmInternal = LocalServices.getService(UserManagerInternal.class); - mAmInternal = LocalServices.getService(ActivityManagerInternal.class); mIPackageManager = IPackageManager.Stub.asInterface( ServiceManager.getService("package")); @@ -1694,7 +1633,6 @@ class StorageManagerService extends IStorageManager.Stub LocalServices.getService(ActivityTaskManagerInternal.class) .registerScreenObserver(this); - mSystemReady = true; mHandler.obtainMessage(H_SYSTEM_READY).sendToTarget(); } @@ -2994,7 +2932,6 @@ class StorageManagerService extends IStorageManager.Stub @Override public void mkdirs(String callingPkg, String appPath) { - final int callingPid = Binder.getCallingPid(); final int callingUid = Binder.getCallingUid(); final int userId = UserHandle.getUserId(callingUid); final UserEnvironment userEnv = new UserEnvironment(userId); @@ -3033,13 +2970,11 @@ class StorageManagerService extends IStorageManager.Stub appPath = appPath + "/"; } - final String systemPath = translateAppToSystem(appPath, callingPid, callingUid); - try { - mVold.mkdirs(systemPath); + mVold.mkdirs(appPath); return; } catch (Exception e) { - throw new IllegalStateException("Failed to prepare " + systemPath + ": " + e); + throw new IllegalStateException("Failed to prepare " + appPath + ": " + e); } } @@ -3307,75 +3242,6 @@ class StorageManagerService extends IStorageManager.Stub } }; - private static final Pattern PATTERN_TRANSLATE = Pattern.compile( - "(?i)^(/storage/[^/]+/(?:[0-9]+/)?)(.*)"); - - @Override - public String translateAppToSystem(String path, int pid, int uid) { - return translateInternal(path, pid, uid, true); - } - - @Override - public String translateSystemToApp(String path, int pid, int uid) { - return translateInternal(path, pid, uid, false); - } - - private String translateInternal(String path, int pid, int uid, boolean toSystem) { - if (true) return path; - - if (path.contains("/../")) { - throw new SecurityException("Shady looking path " + path); - } - - final int mountMode = mAmInternal.getStorageMountMode(pid, uid); - if (mountMode == Zygote.MOUNT_EXTERNAL_FULL - || mountMode == Zygote.MOUNT_EXTERNAL_LEGACY) { - return path; - } - - final Matcher m = PATTERN_TRANSLATE.matcher(path); - if (m.matches()) { - final String device = m.group(1); - final String devicePath = m.group(2); - - if (mountMode == Zygote.MOUNT_EXTERNAL_INSTALLER - && devicePath.startsWith("Android/obb/")) { - return path; - } - - // Does path belong to any packages belonging to this UID? If so, - // they get to go straight through to legacy paths. - final String[] pkgs = mContext.getPackageManager().getPackagesForUid(uid); - for (String pkg : pkgs) { - if (devicePath.startsWith("Android/data/" + pkg + "/") || - devicePath.startsWith("Android/media/" + pkg + "/") || - devicePath.startsWith("Android/obb/" + pkg + "/")) { - return path; - } - } - - final String sharedUserId = mPmInternal.getSharedUserIdForPackage(pkgs[0]); - final String sandboxId = getSandboxId(pkgs[0], sharedUserId); - - if (toSystem) { - // Everything else goes into sandbox. - return device + "Android/sandbox/" + sandboxId + "/" + devicePath; - } else { - // Does path belong to this sandbox? If so, leave sandbox. - final String sandboxPrefix = "Android/sandbox/" + sandboxId + "/"; - if (devicePath.startsWith(sandboxPrefix)) { - return device + devicePath.substring(sandboxPrefix.length()); - } - - // Path isn't valid inside sandbox! - throw new SecurityException( - "Path " + path + " isn't valid inside sandbox " + sandboxId); - } - } - - return path; - } - private void addObbStateLocked(ObbState obbState) throws RemoteException { final IBinder binder = obbState.getBinder(); List<ObbState> obbStates = mObbMounts.get(binder); @@ -4048,55 +3914,5 @@ class StorageManagerService extends IStorageManager.Stub } return true; } - - @Override - public void prepareSandboxForApp(String packageName, int appId, String sharedUserId, - int userId) { - final String sandboxId; - synchronized (mPackagesLock) { - final ArraySet<String> userPackages = mPackages.get(userId); - // If userPackages is empty, it means the user is not started yet, so no need to - // do anything now. - if (userPackages == null || userPackages.contains(packageName)) { - return; - } - userPackages.add(packageName); - sandboxId = StorageManagerService.this.getSandboxId(packageName, sharedUserId); - } - - try { - mVold.prepareSandboxForApp(packageName, appId, sandboxId, userId); - } catch (Exception e) { - Slog.wtf(TAG, e); - } - } - - @Override - public void destroySandboxForApp(String packageName, String sharedUserId, int userId) { - if (!ENABLE_ISOLATED_STORAGE) { - return; - } - final String sandboxId = StorageManagerService.this.getSandboxId( - packageName, sharedUserId); - synchronized (mPackagesLock) { - final ArraySet<String> userPackages = mPackages.get(userId); - // If the userPackages is null, it means the user is not started but we still - // need to delete the sandbox data though. - if (userPackages != null) { - userPackages.remove(packageName); - } - } - try { - mVold.destroySandboxForApp(packageName, sandboxId, userId); - } catch (Exception e) { - Slog.wtf(TAG, e); - } - } - - @Override - public String getSandboxId(String packageName) { - return StorageManagerService.this.getSandboxId(packageName, - mPmInternal.getSharedUserIdForPackage(packageName)); - } } } diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java index 32516b1c4618..696697eddf25 100644 --- a/services/core/java/com/android/server/am/ProcessList.java +++ b/services/core/java/com/android/server/am/ProcessList.java @@ -1810,11 +1810,6 @@ public final class ProcessList { String seInfo, String requiredAbi, String instructionSet, String invokeWith, long startTime) { try { - final String[] packageNames = mService.mContext.getPackageManager() - .getPackagesForUid(uid); - final StorageManagerInternal storageManagerInternal = - LocalServices.getService(StorageManagerInternal.class); - final String sandboxId = storageManagerInternal.getSandboxId(app.info.packageName); final boolean useSystemGraphicsDriver = shouldUseSystemGraphicsDriver(mService.mContext, mService.mCoreSettingsObserver.getCoreSettingsLocked(), app.info); Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "Start proc: " + @@ -1826,7 +1821,6 @@ public final class ProcessList { app.processName, uid, uid, gids, runtimeFlags, mountExternal, app.info.targetSdkVersion, seInfo, requiredAbi, instructionSet, app.info.dataDir, null, app.info.packageName, - packageNames, sandboxId, useSystemGraphicsDriver, new String[] {PROC_START_SEQ_IDENT + app.startSeq}); } else if (hostingRecord.usesAppZygote()) { @@ -1836,15 +1830,13 @@ public final class ProcessList { app.processName, uid, uid, gids, runtimeFlags, mountExternal, app.info.targetSdkVersion, seInfo, requiredAbi, instructionSet, app.info.dataDir, null, app.info.packageName, - packageNames, sandboxId, /*useUsapPool=*/ false, - useSystemGraphicsDriver, + /*useUsapPool=*/ false, useSystemGraphicsDriver, new String[] {PROC_START_SEQ_IDENT + app.startSeq}); } else { startResult = Process.start(entryPoint, app.processName, uid, uid, gids, runtimeFlags, mountExternal, app.info.targetSdkVersion, seInfo, requiredAbi, instructionSet, app.info.dataDir, invokeWith, app.info.packageName, - packageNames, sandboxId, useSystemGraphicsDriver, new String[] {PROC_START_SEQ_IDENT + app.startSeq}); } diff --git a/services/core/java/com/android/server/attention/AttentionManagerService.java b/services/core/java/com/android/server/attention/AttentionManagerService.java index 032af258dbd9..7605ccb5aeda 100644 --- a/services/core/java/com/android/server/attention/AttentionManagerService.java +++ b/services/core/java/com/android/server/attention/AttentionManagerService.java @@ -374,8 +374,15 @@ public class AttentionManagerService extends SystemService { private void dumpInternal(IndentingPrintWriter ipw) { ipw.println("Attention Manager Service (dumpsys attention) state:\n"); - ipw.printPair("context", mContext); - ipw.println(); + ipw.println("AttentionServicePackageName=" + getServiceConfigPackage(mContext)); + ipw.println("Resolved component:"); + if (mComponentName != null) { + ipw.increaseIndent(); + ipw.println("Component=" + mComponentName.getPackageName()); + ipw.println("Class=" + mComponentName.getClassName()); + ipw.decreaseIndent(); + } + synchronized (mLock) { int size = mUserStates.size(); ipw.print("Number user states: "); @@ -511,10 +518,24 @@ public class AttentionManagerService extends SystemService { } private void dump(IndentingPrintWriter pw) { - pw.printPair("context", mContext); - pw.printPair("userId", mUserId); + pw.println("userId=" + mUserId); synchronized (mLock) { - pw.printPair("binding", mBinding); + pw.println("binding=" + mBinding); + pw.println("current attention check:"); + if (mCurrentAttentionCheck != null) { + pw.increaseIndent(); + pw.println("is dispatched=" + mCurrentAttentionCheck.mIsDispatched); + pw.println("is fulfilled:=" + mCurrentAttentionCheck.mIsFulfilled); + pw.decreaseIndent(); + } + pw.println("attention check cache:"); + if (mAttentionCheckCache != null) { + pw.increaseIndent(); + pw.println("last computed=" + mAttentionCheckCache.mLastComputed); + pw.println("timestamp=" + mAttentionCheckCache.mTimestamp); + pw.println("result=" + mAttentionCheckCache.mResult); + pw.decreaseIndent(); + } } } diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index e274ad5a5c90..bec064495798 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -96,6 +96,7 @@ import android.media.audiopolicy.AudioProductStrategy; import android.media.audiopolicy.AudioVolumeGroup; import android.media.audiopolicy.IAudioPolicyCallback; import android.media.projection.IMediaProjection; +import android.media.projection.IMediaProjectionCallback; import android.media.projection.IMediaProjectionManager; import android.net.Uri; import android.os.Binder; @@ -6705,13 +6706,13 @@ public class AudioService extends IAudioService.Stub String regId = null; synchronized (mAudioPolicies) { + if (mAudioPolicies.containsKey(pcb.asBinder())) { + Slog.e(TAG, "Cannot re-register policy"); + return null; + } try { - if (mAudioPolicies.containsKey(pcb.asBinder())) { - Slog.e(TAG, "Cannot re-register policy"); - return null; - } AudioPolicyProxy app = new AudioPolicyProxy(policyConfig, pcb, hasFocusListener, - isFocusPolicy, isTestFocusPolicy, isVolumeController); + isFocusPolicy, isTestFocusPolicy, isVolumeController, projection); pcb.asBinder().linkToDeath(app, 0/*flags*/); regId = app.getRegistrationId(); mAudioPolicies.put(pcb.asBinder(), app); @@ -6720,6 +6721,9 @@ public class AudioService extends IAudioService.Stub Slog.w(TAG, "Audio policy registration failed, could not link to " + pcb + " binder death", e); return null; + } catch (IllegalStateException e) { + Slog.w(TAG, "Audio policy registration failed for binder " + pcb, e); + return null; } } return regId; @@ -6884,9 +6888,9 @@ public class AudioService extends IAudioService.Stub if (app == null){ return AudioManager.ERROR; } - app.addMixes(policyConfig.getMixes()); + return app.addMixes(policyConfig.getMixes()) == AudioSystem.SUCCESS + ? AudioManager.SUCCESS : AudioManager.ERROR; } - return AudioManager.SUCCESS; } public int removeMixForPolicy(AudioPolicyConfig policyConfig, IAudioPolicyCallback pcb) { @@ -6898,9 +6902,9 @@ public class AudioService extends IAudioService.Stub if (app == null) { return AudioManager.ERROR; } - app.removeMixes(policyConfig.getMixes()); + return app.removeMixes(policyConfig.getMixes()) == AudioSystem.SUCCESS + ? AudioManager.SUCCESS : AudioManager.ERROR; } - return AudioManager.SUCCESS; } /** see AudioPolicy.setUidDeviceAffinity() */ @@ -7165,6 +7169,15 @@ public class AudioService extends IAudioService.Stub final boolean mIsVolumeController; final HashMap<Integer, AudioDeviceArray> mUidDeviceAffinities = new HashMap<Integer, AudioDeviceArray>(); + + final IMediaProjection mProjection; + private final class UnregisterOnStopCallback extends IMediaProjectionCallback.Stub { + public void onStop() { + unregisterAudioPolicyAsync(mPolicyCallback); + } + }; + UnregisterOnStopCallback mProjectionCallback; + /** * Audio focus ducking behavior for an audio policy. * This variable reflects the value that was successfully set in @@ -7178,12 +7191,13 @@ public class AudioService extends IAudioService.Stub AudioPolicyProxy(AudioPolicyConfig config, IAudioPolicyCallback token, boolean hasFocusListener, boolean isFocusPolicy, boolean isTestFocusPolicy, - boolean isVolumeController) { + boolean isVolumeController, IMediaProjection projection) { super(config); setRegistration(new String(config.hashCode() + ":ap:" + mAudioPolicyCounter++)); mPolicyCallback = token; mHasFocusListener = hasFocusListener; mIsVolumeController = isVolumeController; + mProjection = projection; if (mHasFocusListener) { mMediaFocusControl.addFocusFollower(mPolicyCallback); // can only ever be true if there is a focus listener @@ -7196,7 +7210,21 @@ public class AudioService extends IAudioService.Stub if (mIsVolumeController) { setExtVolumeController(mPolicyCallback); } - connectMixes(); + if (mProjection != null) { + mProjectionCallback = new UnregisterOnStopCallback(); + try { + mProjection.registerCallback(mProjectionCallback); + } catch (RemoteException e) { + release(); + throw new IllegalStateException("MediaProjection callback registration failed, " + + "could not link to " + projection + " binder death", e); + } + } + int status = connectMixes(); + if (status != AudioSystem.SUCCESS) { + release(); + throw new IllegalStateException("Could not connect mix, error: " + status); + } } public void binderDied() { @@ -7226,6 +7254,13 @@ public class AudioService extends IAudioService.Stub if (mHasFocusListener) { mMediaFocusControl.removeFocusFollower(mPolicyCallback); } + if (mProjectionCallback != null) { + try { + mProjection.unregisterCallback(mProjectionCallback); + } catch (RemoteException e) { + Log.e(TAG, "Fail to unregister Audiopolicy callback from MediaProjection"); + } + } final long identity = Binder.clearCallingIdentity(); AudioSystem.registerPolicyMixes(mMixes, false); Binder.restoreCallingIdentity(identity); @@ -7260,28 +7295,29 @@ public class AudioService extends IAudioService.Stub return true; } - void addMixes(@NonNull ArrayList<AudioMix> mixes) { + int addMixes(@NonNull ArrayList<AudioMix> mixes) { // TODO optimize to not have to unregister the mixes already in place synchronized (mMixes) { AudioSystem.registerPolicyMixes(mMixes, false); this.add(mixes); - AudioSystem.registerPolicyMixes(mMixes, true); + return AudioSystem.registerPolicyMixes(mMixes, true); } } - void removeMixes(@NonNull ArrayList<AudioMix> mixes) { + int removeMixes(@NonNull ArrayList<AudioMix> mixes) { // TODO optimize to not have to unregister the mixes already in place synchronized (mMixes) { AudioSystem.registerPolicyMixes(mMixes, false); this.remove(mixes); - AudioSystem.registerPolicyMixes(mMixes, true); + return AudioSystem.registerPolicyMixes(mMixes, true); } } - void connectMixes() { + int connectMixes() { final long identity = Binder.clearCallingIdentity(); - AudioSystem.registerPolicyMixes(mMixes, true); + int status = AudioSystem.registerPolicyMixes(mMixes, true); Binder.restoreCallingIdentity(identity); + return status; } int setUidDeviceAffinities(int uid, @NonNull int[] types, @NonNull String[] addresses) { @@ -7320,6 +7356,20 @@ public class AudioService extends IAudioService.Stub Log.e(TAG, "AudioSystem. removeUidDeviceAffinities failed"); return AudioManager.ERROR; } + + /** @return human readable debug informations summarizing the state of the object. */ + public String toLogFriendlyString() { + String textDump = super.toLogFriendlyString(); + textDump += " Proxy:\n"; + textDump += " is focus policy= " + mIsFocusPolicy + "\n"; + if (mIsFocusPolicy) { + textDump += " focus duck behaviour= " + mFocusDuckBehavior + "\n"; + textDump += " is test focus policy= " + mIsTestFocusPolicy + "\n"; + textDump += " has focus listener= " + mHasFocusListener + "\n"; + } + textDump += " media projection= " + mProjection + "\n"; + return textDump; + } }; //====================== diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 88081368f15a..5eb9d500e584 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -10339,31 +10339,6 @@ public class PackageManagerService extends IPackageManager.Stub } catch (InstallerException e) { Slog.w(TAG, String.valueOf(e)); } - // If this package doesn't have a sharedUserId or there are no other packages - // present with same sharedUserId, then delete the sandbox data too. - try { - final SharedUserSetting sharedUserSetting = mSettings.getSharedUserLPw( - pkg.mSharedUserId, 0 /* pkgFlags */, - 0 /* pkgPrivateFlags */, false /* create */); - boolean deleteSandboxData = true; - if (sharedUserSetting != null && sharedUserSetting.packages != null) { - for (int i = sharedUserSetting.packages.size() - 1; i >= 0; --i) { - final PackageSetting packageSetting = sharedUserSetting.packages.valueAt(i); - if (!packageSetting.name.equals(pkg.packageName) - && packageSetting.readUserState(realUserId).isAvailable( - MATCH_UNINSTALLED_PACKAGES)) { - deleteSandboxData = false; - break; - } - } - } - if (deleteSandboxData && getStorageManagerInternal() != null) { - getStorageManagerInternal().destroySandboxForApp(pkg.packageName, - pkg.mSharedUserId, realUserId); - } - } catch (PackageManagerException e) { - // Should not happen - } mDexManager.notifyPackageDataDestroyed(pkg.packageName, userId); } } @@ -22940,10 +22915,6 @@ public class PackageManagerService extends IPackageManager.Stub } prepareAppDataContentsLeafLIF(pkg, userId, flags); - if (getStorageManagerInternal() != null) { - getStorageManagerInternal().prepareSandboxForApp( - pkg.packageName, appId, pkg.mSharedUserId, userId); - } } private void prepareAppDataContentsLIF(PackageParser.Package pkg, int userId, int flags) { diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java index b2c99f4fe06b..4e897d2a5b64 100644 --- a/services/core/java/com/android/server/pm/Settings.java +++ b/services/core/java/com/android/server/pm/Settings.java @@ -2552,10 +2552,6 @@ public final class Settings { writeKernelMappingLPr(ps); } - for (final SharedUserSetting sus : mSharedUsers.values()) { - knownSet.remove(sus.getStorageSandboxName()); - } - // Remove any unclaimed mappings for (int i = 0; i < knownSet.size(); i++) { final String name = knownSet.valueAt(i); @@ -2566,20 +2562,10 @@ public final class Settings { } } - void writeKernelMappingLPr(SharedUserSetting sus) { - if (mKernelMappingFilename == null || sus == null || sus.name == null) return; - - writeKernelMappingLPr(sus.getStorageSandboxName(), - sus.userId, sus.getNotInstalledUserIds()); - } - void writeKernelMappingLPr(PackageSetting ps) { if (mKernelMappingFilename == null || ps == null || ps.name == null) return; writeKernelMappingLPr(ps.name, ps.appId, ps.getNotInstalledUserIds()); - if (ps.sharedUser != null) { - writeKernelMappingLPr(ps.sharedUser); - } } void writeKernelMappingLPr(String name, int appId, int[] excludedUserIds) { diff --git a/services/core/java/com/android/server/pm/SharedUserSetting.java b/services/core/java/com/android/server/pm/SharedUserSetting.java index d67144e8ce39..cbc9124b8476 100644 --- a/services/core/java/com/android/server/pm/SharedUserSetting.java +++ b/services/core/java/com/android/server/pm/SharedUserSetting.java @@ -19,7 +19,6 @@ package com.android.server.pm; import android.annotation.Nullable; import android.content.pm.ApplicationInfo; import android.content.pm.PackageParser; -import android.os.storage.StorageManager; import android.service.pm.PackageServiceDumpProto; import android.util.ArraySet; import android.util.proto.ProtoOutputStream; @@ -167,10 +166,6 @@ public final class SharedUserSetting extends SettingBase { return excludedUserIds == null ? EmptyArray.INT : excludedUserIds; } - public String getStorageSandboxName() { - return StorageManager.SHARED_SANDBOX_PREFIX + name; - } - /** Updates all fields in this shared user setting from another. */ public SharedUserSetting updateFrom(SharedUserSetting sharedUser) { copyFrom(sharedUser); diff --git a/services/core/java/com/android/server/power/AttentionDetector.java b/services/core/java/com/android/server/power/AttentionDetector.java index a65a81263780..3262eb67a052 100644 --- a/services/core/java/com/android/server/power/AttentionDetector.java +++ b/services/core/java/com/android/server/power/AttentionDetector.java @@ -196,7 +196,7 @@ public class AttentionDetector { mRequested.set(false); } - Slog.v(TAG, "Checking user attention"); + Slog.v(TAG, "Checking user attention, ID: " + mRequestId); return whenToCheck; } @@ -277,12 +277,12 @@ public class AttentionDetector { } public void dump(PrintWriter pw) { - pw.print("AttentionDetector:"); - pw.print(" mMaximumExtensionMillis=" + mMaximumExtensionMillis); - pw.print(" mMaxAttentionApiTimeoutMillis=" + mMaxAttentionApiTimeoutMillis); - pw.print(" mLastUserActivityTime(excludingAttention)=" + mLastUserActivityTime); - pw.print(" mAttentionServiceSupported=" + isAttentionServiceSupported()); - pw.print(" mRequested=" + mRequested); + pw.println("AttentionDetector:"); + pw.println(" mMaximumExtensionMillis=" + mMaximumExtensionMillis); + pw.println(" mMaxAttentionApiTimeoutMillis=" + mMaxAttentionApiTimeoutMillis); + pw.println(" mLastUserActivityTime(excludingAttention)=" + mLastUserActivityTime); + pw.println(" mAttentionServiceSupported=" + isAttentionServiceSupported()); + pw.println(" mRequested=" + mRequested); } @VisibleForTesting diff --git a/services/tests/servicestests/src/com/android/server/StorageManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/StorageManagerServiceTest.java index 68f696b26a26..d192748762fe 100644 --- a/services/tests/servicestests/src/com/android/server/StorageManagerServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/StorageManagerServiceTest.java @@ -15,31 +15,21 @@ */ package com.android.server; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; -import android.app.ActivityManagerInternal; import android.content.Context; -import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManagerInternal; -import android.os.UserManagerInternal; import android.os.storage.StorageManagerInternal; -import com.android.internal.os.Zygote; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; import org.junit.Before; -import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; - @SmallTest @RunWith(AndroidJUnit4.class) public class StorageManagerServiceTest { @@ -49,28 +39,6 @@ public class StorageManagerServiceTest { @Mock private Context mContext; @Mock private PackageManager mPm; @Mock private PackageManagerInternal mPmi; - @Mock private UserManagerInternal mUmi; - @Mock private ActivityManagerInternal mAmi; - - private static final String PKG_GREY = "com.grey"; - private static final String PKG_RED = "com.red"; - private static final String PKG_BLUE = "com.blue"; - - private static final int UID_GREY = 10000; - private static final int UID_COLORS = 10001; - - private static final int PID_GREY = 1111; - private static final int PID_RED = 2222; - private static final int PID_BLUE = 3333; - - private static final String NAME_COLORS = "colors"; - - private static ApplicationInfo buildApplicationInfo(String packageName, int uid) { - final ApplicationInfo ai = new ApplicationInfo(); - ai.packageName = packageName; - ai.uid = uid; - return ai; - } @Before public void setUp() throws Exception { @@ -80,196 +48,9 @@ public class StorageManagerServiceTest { LocalServices.removeServiceForTest(PackageManagerInternal.class); LocalServices.addService(PackageManagerInternal.class, mPmi); - LocalServices.removeServiceForTest(UserManagerInternal.class); - LocalServices.addService(UserManagerInternal.class, mUmi); - LocalServices.removeServiceForTest(ActivityManagerInternal.class); - LocalServices.addService(ActivityManagerInternal.class, mAmi); when(mContext.getPackageManager()).thenReturn(mPm); - when(mUmi.getUserIds()).thenReturn(new int[] { 0 }); - - when(mPmi.getSharedUserIdForPackage(eq(PKG_GREY))).thenReturn(null); - when(mPmi.getSharedUserIdForPackage(eq(PKG_RED))).thenReturn(NAME_COLORS); - when(mPmi.getSharedUserIdForPackage(eq(PKG_BLUE))).thenReturn(NAME_COLORS); - - when(mPmi.getPackagesForSharedUserId(eq(NAME_COLORS), anyInt())) - .thenReturn(new String[] { PKG_RED, PKG_BLUE }); - - when(mPm.getPackagesForUid(eq(UID_GREY))).thenReturn(new String[] { PKG_GREY }); - when(mPm.getPackagesForUid(eq(UID_COLORS))).thenReturn(new String[] { PKG_RED, PKG_BLUE }); - - setStorageMountMode(PID_BLUE, UID_COLORS, Zygote.MOUNT_EXTERNAL_WRITE); - setStorageMountMode(PID_GREY, UID_GREY, Zygote.MOUNT_EXTERNAL_WRITE); - setStorageMountMode(PID_RED, UID_COLORS, Zygote.MOUNT_EXTERNAL_WRITE); - mService = new StorageManagerService(mContext); } - - private void setStorageMountMode(int pid, int uid, int mountMode) { - when(mAmi.getStorageMountMode(pid, uid)).thenReturn(mountMode); - } - - @Test - public void testNone() throws Exception { - assertTranslation( - "/dev/null", - "/dev/null", PID_GREY, UID_GREY); - assertTranslation( - "/dev/null", - "/dev/null", PID_RED, UID_COLORS); - } - - @Test - public void testPrimary() throws Exception { - assertTranslation( - "/storage/emulated/0/Android/sandbox/com.grey/foo.jpg", - "/storage/emulated/0/foo.jpg", - PID_GREY, UID_GREY); - assertTranslation( - "/storage/emulated/0/Android/sandbox/shared-colors/foo.jpg", - "/storage/emulated/0/foo.jpg", - PID_RED, UID_COLORS); - } - - @Test - public void testSecondary() throws Exception { - assertTranslation( - "/storage/0000-0000/Android/sandbox/com.grey/foo/bar.jpg", - "/storage/0000-0000/foo/bar.jpg", - PID_GREY, UID_GREY); - assertTranslation( - "/storage/0000-0000/Android/sandbox/shared-colors/foo/bar.jpg", - "/storage/0000-0000/foo/bar.jpg", - PID_RED, UID_COLORS); - } - - @Test - public void testLegacy() throws Exception { - // Accessing their own paths goes straight through - assertTranslation( - "/storage/emulated/0/Android/data/com.grey/foo.jpg", - "/storage/emulated/0/Android/data/com.grey/foo.jpg", - PID_GREY, UID_GREY); - - // Accessing other package paths goes into sandbox - assertTranslation( - "/storage/emulated/0/Android/sandbox/shared-colors/" - + "Android/data/com.grey/foo.jpg", - "/storage/emulated/0/Android/data/com.grey/foo.jpg", - PID_RED, UID_COLORS); - } - - @Test - public void testLegacyShared() throws Exception { - // Accessing their own paths goes straight through - assertTranslation( - "/storage/emulated/0/Android/data/com.red/foo.jpg", - "/storage/emulated/0/Android/data/com.red/foo.jpg", - PID_RED, UID_COLORS); - assertTranslation( - "/storage/emulated/0/Android/data/com.red/foo.jpg", - "/storage/emulated/0/Android/data/com.red/foo.jpg", - PID_BLUE, UID_COLORS); - - // Accessing other package paths goes into sandbox - assertTranslation( - "/storage/emulated/0/Android/sandbox/com.grey/" - + "Android/data/com.red/foo.jpg", - "/storage/emulated/0/Android/data/com.red/foo.jpg", - PID_GREY, UID_GREY); - } - - @Test - public void testSecurity() throws Exception { - // Shady paths should throw - try { - mService.translateAppToSystem( - "/storage/emulated/0/../foo.jpg", - PID_GREY, UID_GREY); - fail(); - } catch (SecurityException expected) { - } - - // Sandboxes can't see system paths - try { - mService.translateSystemToApp( - "/storage/emulated/0/foo.jpg", - PID_GREY, UID_GREY); - fail(); - } catch (SecurityException expected) { - } - - // Sandboxes can't see paths in other sandboxes - try { - mService.translateSystemToApp( - "/storage/emulated/0/Android/sandbox/shared-colors/foo.jpg", - PID_GREY, UID_GREY); - fail(); - } catch (SecurityException expected) { - } - } - - @Test - public void testPackageNotSandboxed() throws Exception { - setStorageMountMode(PID_RED, UID_COLORS, Zygote.MOUNT_EXTERNAL_FULL); - - // Both app and system have the same view - assertTranslation( - "/storage/emulated/0/Android/data/com.red/foo.jpg", - "/storage/emulated/0/Android/data/com.red/foo.jpg", - PID_RED, UID_COLORS); - - assertTranslation( - "/storage/emulated/0/Android/sandbox/com.grey/bar.jpg", - "/storage/emulated/0/Android/sandbox/com.grey/bar.jpg", - PID_RED, UID_COLORS); - } - - @Test - public void testPackageInLegacyMode() throws Exception { - setStorageMountMode(PID_RED, UID_COLORS, Zygote.MOUNT_EXTERNAL_LEGACY); - - // Both app and system have the same view - assertTranslation( - "/storage/emulated/0/Android/data/com.red/foo.jpg", - "/storage/emulated/0/Android/data/com.red/foo.jpg", - PID_RED, UID_COLORS); - - assertTranslation( - "/storage/emulated/0/Android/sandbox/com.grey/bar.jpg", - "/storage/emulated/0/Android/sandbox/com.grey/bar.jpg", - PID_RED, UID_COLORS); - } - - @Test - public void testInstallerPackage() throws Exception { - setStorageMountMode(PID_GREY, UID_GREY, Zygote.MOUNT_EXTERNAL_INSTALLER); - - assertTranslation( - "/storage/emulated/0/Android/obb/com.grey/foo.jpg", - "/storage/emulated/0/Android/obb/com.grey/foo.jpg", - PID_GREY, UID_GREY); - assertTranslation( - "/storage/emulated/0/Android/obb/com.blue/bar.jpg", - "/storage/emulated/0/Android/obb/com.blue/bar.jpg", - PID_GREY, UID_GREY); - - assertTranslation( - "/storage/emulated/0/Android/data/com.grey/foo.jpg", - "/storage/emulated/0/Android/data/com.grey/foo.jpg", - PID_GREY, UID_GREY); - assertTranslation( - "/storage/emulated/0/Android/sandbox/com.grey/Android/data/com.blue/bar.jpg", - "/storage/emulated/0/Android/data/com.blue/bar.jpg", - PID_GREY, UID_GREY); - } - - private void assertTranslation(String system, String sandbox, - int pid, int uid) throws Exception { - assertEquals(system, - mService.translateAppToSystem(sandbox, pid, uid)); - assertEquals(sandbox, - mService.translateSystemToApp(system, pid, uid)); - } } diff --git a/services/usb/java/com/android/server/usb/UsbAlsaManager.java b/services/usb/java/com/android/server/usb/UsbAlsaManager.java index 4874bcef1606..5239d976e66f 100644 --- a/services/usb/java/com/android/server/usb/UsbAlsaManager.java +++ b/services/usb/java/com/android/server/usb/UsbAlsaManager.java @@ -35,7 +35,9 @@ import com.android.server.usb.descriptors.UsbDescriptorParser; import libcore.io.IoUtils; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; /** * UsbAlsaManager manages USB audio and MIDI devices. @@ -61,6 +63,50 @@ public final class UsbAlsaManager { private final ArrayList<UsbAlsaDevice> mAlsaDevices = new ArrayList<UsbAlsaDevice>(); private UsbAlsaDevice mSelectedDevice; + // + // Device Blacklist + // + // This exists due to problems with Sony game controllers which present as an audio device + // even if no headset is connected and have no way to set the volume on the unit. + // Handle this by simply declining to use them as an audio device. + private static final int USB_VENDORID_SONY = 0x054C; + private static final int USB_PRODUCTID_PS4CONTROLLER_ZCT1 = 0x05C4; + private static final int USB_PRODUCTID_PS4CONTROLLER_ZCT2 = 0x09CC; + + private static final int USB_BLACKLIST_OUTPUT = 0x0001; + private static final int USB_BLACKLIST_INPUT = 0x0002; + + private static class BlackListEntry { + final int mVendorId; + final int mProductId; + final int mFlags; + + BlackListEntry(int vendorId, int productId, int flags) { + mVendorId = vendorId; + mProductId = productId; + mFlags = flags; + } + } + + static final List<BlackListEntry> sDeviceBlacklist = Arrays.asList( + new BlackListEntry(USB_VENDORID_SONY, + USB_PRODUCTID_PS4CONTROLLER_ZCT1, + USB_BLACKLIST_OUTPUT), + new BlackListEntry(USB_VENDORID_SONY, + USB_PRODUCTID_PS4CONTROLLER_ZCT2, + USB_BLACKLIST_OUTPUT)); + + private static boolean isDeviceBlacklisted(int vendorId, int productId, int flags) { + for (BlackListEntry entry : sDeviceBlacklist) { + if (entry.mVendorId == vendorId && entry.mProductId == productId) { + // see if the type flag is set + return (entry.mFlags & flags) != 0; + } + } + + return false; + } + /** * List of connected MIDI devices */ @@ -179,8 +225,12 @@ public final class UsbAlsaManager { } // Add it to the devices list - boolean hasInput = parser.hasInput(); - boolean hasOutput = parser.hasOutput(); + boolean hasInput = parser.hasInput() + && !isDeviceBlacklisted(usbDevice.getVendorId(), usbDevice.getProductId(), + USB_BLACKLIST_INPUT); + boolean hasOutput = parser.hasOutput() + && !isDeviceBlacklisted(usbDevice.getVendorId(), usbDevice.getProductId(), + USB_BLACKLIST_OUTPUT); if (DEBUG) { Slog.d(TAG, "hasInput: " + hasInput + " hasOutput:" + hasOutput); } diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index aa9883d54a6a..328a0a7a9512 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -3836,10 +3836,12 @@ public class TelephonyManager { } /** - * Return the set of subscriber IDs that should be considered as "merged - * together" for data usage purposes. This is commonly {@code null} to - * indicate no merging is required. Any returned subscribers are sorted in a - * deterministic order. + * Return the set of subscriber IDs that should be considered "merged together" for data usage + * purposes. This is commonly {@code null} to indicate no merging is required. Any returned + * subscribers are sorted in a deterministic order. + * <p> + * The returned set of subscriber IDs will include the subscriber ID corresponding to this + * TelephonyManager's subId. * * @hide */ @@ -3848,7 +3850,7 @@ public class TelephonyManager { try { ITelephony telephony = getITelephony(); if (telephony != null) - return telephony.getMergedSubscriberIds(getOpPackageName()); + return telephony.getMergedSubscriberIds(getSubId(), getOpPackageName()); } catch (RemoteException ex) { } catch (NullPointerException ex) { } diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index f226bb1fa588..3991fea66a85 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -1051,7 +1051,17 @@ interface ITelephony { */ String getLine1AlphaTagForDisplay(int subId, String callingPackage); - String[] getMergedSubscriberIds(String callingPackage); + /** + * Return the set of subscriber IDs that should be considered "merged together" for data usage + * purposes. This is commonly {@code null} to indicate no merging is required. Any returned + * subscribers are sorted in a deterministic order. + * <p> + * The returned set of subscriber IDs will include the subscriber ID corresponding to this + * TelephonyManager's subId. + * + * @hide + */ + String[] getMergedSubscriberIds(int subId, String callingPackage); /** * Override the operator branding for the current ICCID. |