Loading core/java/android/app/IActivityTaskManager.aidl +0 −9 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ import android.app.GrantedUriPermission; import android.app.IApplicationThread; import android.app.IActivityClientController; import android.app.IActivityController; import android.app.IAppTask; import android.app.IAssistDataReceiver; import android.app.IInstrumentationWatcher; import android.app.IProcessObserver; Loading Loading @@ -107,14 +106,6 @@ interface IActivityTaskManager { in ProfilerInfo profilerInfo, in Bundle options, int userId); boolean startNextMatchingActivity(in IBinder callingActivity, in Intent intent, in Bundle options); /** * The DreamActivity has to be started in a special way that does not involve the PackageParser. * The DreamActivity is a framework component inserted in the dream application process. Hence, * it is not declared in the application's manifest and cannot be parsed. startDreamActivity * creates the activity and starts it without reaching out to the PackageParser. */ boolean startDreamActivity(in Intent intent); int startActivityIntentSender(in IApplicationThread caller, in IIntentSender target, in IBinder whitelistToken, in Intent fillInIntent, in String resolvedType, in IBinder resultTo, in String resultWho, int requestCode, Loading core/java/android/service/dreams/DreamService.java +1 −4 Original line number Diff line number Diff line Loading @@ -26,7 +26,6 @@ import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.annotation.TestApi; import android.app.Activity; import android.app.ActivityTaskManager; import android.app.AlarmManager; import android.app.Service; import android.compat.annotation.UnsupportedAppUsage; Loading Loading @@ -1268,9 +1267,7 @@ public class DreamService extends Service implements Window.Callback { fetchDreamLabel(this, serviceInfo, isPreviewMode)); try { if (!ActivityTaskManager.getService().startDreamActivity(i)) { detach(); } mDreamManager.startDreamActivity(i); } catch (SecurityException e) { Log.w(mTag, "Received SecurityException trying to start DreamActivity. " Loading core/java/android/service/dreams/IDreamManager.aidl +2 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.service.dreams; import android.content.ComponentName; import android.content.Intent; import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.os.IBinder; Loading Loading @@ -45,4 +46,5 @@ interface IDreamManager { void setDreamComponentsForUser(int userId, in ComponentName[] componentNames); void setSystemDreamComponent(in ComponentName componentName); void registerDreamOverlayService(in ComponentName componentName); void startDreamActivity(in Intent intent); } services/core/java/com/android/server/dreams/DreamController.java +31 −3 Original line number Diff line number Diff line Loading @@ -16,11 +16,11 @@ package com.android.server.dreams; import static android.app.WindowConfiguration.ACTIVITY_TYPE_DREAM; import static android.content.Intent.FLAG_RECEIVER_FOREGROUND; import android.app.ActivityTaskManager; import android.app.BroadcastOptions; import android.app.IAppTask; import android.content.ComponentName; import android.content.Context; import android.content.Intent; Loading Loading @@ -213,6 +213,27 @@ final class DreamController { } } /** * Provides an appTask for the dream with token {@code dreamToken}, so that the dream controller * can stop the dream task when necessary. */ void setDreamAppTask(Binder dreamToken, IAppTask appTask) { if (mCurrentDream == null || mCurrentDream.mToken != dreamToken || mCurrentDream.mAppTask != null) { Slog.e(TAG, "Illegal dream activity start. mCurrentDream.mToken = " + mCurrentDream.mToken + ", illegal dreamToken = " + dreamToken + ". Ending this dream activity."); try { appTask.finishAndRemoveTask(); } catch (RemoteException | RuntimeException e) { Slog.e(TAG, "Unable to stop illegal dream activity."); } return; } mCurrentDream.mAppTask = appTask; } /** * Stops dreaming. * Loading Loading @@ -303,8 +324,14 @@ final class DreamController { mSentStartBroadcast = false; } mActivityTaskManager.removeRootTasksWithActivityTypes( new int[] {ACTIVITY_TYPE_DREAM}); if (mCurrentDream != null && mCurrentDream.mAppTask != null) { // Finish the dream task in case it hasn't finished by itself already. try { mCurrentDream.mAppTask.finishAndRemoveTask(); } catch (RemoteException | RuntimeException e) { Slog.e(TAG, "Unable to stop dream activity."); } } mListener.onDreamStopped(dream.mToken); } Loading Loading @@ -364,6 +391,7 @@ final class DreamController { public final boolean mIsPreviewMode; public final boolean mCanDoze; public final int mUserId; public IAppTask mAppTask; public PowerManager.WakeLock mWakeLock; public boolean mBound; Loading services/core/java/com/android/server/dreams/DreamManagerService.java +62 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityManager; import android.app.IAppTask; import android.app.TaskInfo; import android.content.BroadcastReceiver; import android.content.ComponentName; Loading @@ -37,6 +38,7 @@ import android.content.IntentFilter; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManagerInternal; import android.content.pm.ServiceInfo; import android.database.ContentObserver; import android.hardware.display.AmbientDisplayConfiguration; Loading Loading @@ -116,6 +118,7 @@ public final class DreamManagerService extends SystemService { private final PowerManagerInternal mPowerManagerInternal; private final PowerManager.WakeLock mDozeWakeLock; private final ActivityTaskManagerInternal mAtmInternal; private final PackageManagerInternal mPmInternal; private final UserManager mUserManager; private final UiEventLogger mUiEventLogger; private final DreamUiEventLogger mDreamUiEventLogger; Loading Loading @@ -216,6 +219,7 @@ public final class DreamManagerService extends SystemService { mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); mPowerManagerInternal = getLocalService(PowerManagerInternal.class); mAtmInternal = getLocalService(ActivityTaskManagerInternal.class); mPmInternal = getLocalService(PackageManagerInternal.class); mUserManager = context.getSystemService(UserManager.class); mDozeWakeLock = mPowerManager.newWakeLock(PowerManager.DOZE_WAKE_LOCK, DOZE_WAKE_LOCK_TAG); mDozeConfig = new AmbientDisplayConfiguration(mContext); Loading Loading @@ -1064,6 +1068,64 @@ public final class DreamManagerService extends SystemService { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public void startDreamActivity(@NonNull Intent intent) { final int callingUid = Binder.getCallingUid(); final int callingPid = Binder.getCallingPid(); // We post here, because startDreamActivity and setDreamAppTask have to run // synchronously and DreamController#setDreamAppTask has to run on mHandler. mHandler.post(() -> { final Binder dreamToken; final String dreamPackageName; synchronized (mLock) { if (mCurrentDream == null) { Slog.e(TAG, "Attempt to start DreamActivity, but the device is not " + "dreaming. Aborting without starting the DreamActivity."); return; } dreamToken = mCurrentDream.token; dreamPackageName = mCurrentDream.name.getPackageName(); } if (!canLaunchDreamActivity(dreamPackageName, intent.getPackage(), callingUid)) { Slog.e(TAG, "The dream activity can be started only when the device is dreaming" + " and only by the active dream package."); return; } final IAppTask appTask = mAtmInternal.startDreamActivity(intent, callingUid, callingPid); if (appTask == null) { Slog.e(TAG, "Could not start dream activity."); stopDreamInternal(true, "DreamActivity not started"); return; } mController.setDreamAppTask(dreamToken, appTask); }); } boolean canLaunchDreamActivity(String dreamPackageName, String packageName, int callingUid) { if (dreamPackageName == null || packageName == null) { Slog.e(TAG, "Cannot launch dream activity due to invalid state. dream component= " + dreamPackageName + ", packageName=" + packageName); return false; } if (!mPmInternal.isSameApp(packageName, callingUid, UserHandle.getUserId(callingUid))) { Slog.e(TAG, "Cannot launch dream activity because package=" + packageName + " does not match callingUid=" + callingUid); return false; } if (packageName.equals(dreamPackageName)) { return true; } Slog.e(TAG, "Dream packageName does not match active dream. Package " + packageName + " does not match " + dreamPackageName); return false; } } private final class LocalService extends DreamManagerInternal { Loading Loading
core/java/android/app/IActivityTaskManager.aidl +0 −9 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ import android.app.GrantedUriPermission; import android.app.IApplicationThread; import android.app.IActivityClientController; import android.app.IActivityController; import android.app.IAppTask; import android.app.IAssistDataReceiver; import android.app.IInstrumentationWatcher; import android.app.IProcessObserver; Loading Loading @@ -107,14 +106,6 @@ interface IActivityTaskManager { in ProfilerInfo profilerInfo, in Bundle options, int userId); boolean startNextMatchingActivity(in IBinder callingActivity, in Intent intent, in Bundle options); /** * The DreamActivity has to be started in a special way that does not involve the PackageParser. * The DreamActivity is a framework component inserted in the dream application process. Hence, * it is not declared in the application's manifest and cannot be parsed. startDreamActivity * creates the activity and starts it without reaching out to the PackageParser. */ boolean startDreamActivity(in Intent intent); int startActivityIntentSender(in IApplicationThread caller, in IIntentSender target, in IBinder whitelistToken, in Intent fillInIntent, in String resolvedType, in IBinder resultTo, in String resultWho, int requestCode, Loading
core/java/android/service/dreams/DreamService.java +1 −4 Original line number Diff line number Diff line Loading @@ -26,7 +26,6 @@ import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.annotation.TestApi; import android.app.Activity; import android.app.ActivityTaskManager; import android.app.AlarmManager; import android.app.Service; import android.compat.annotation.UnsupportedAppUsage; Loading Loading @@ -1268,9 +1267,7 @@ public class DreamService extends Service implements Window.Callback { fetchDreamLabel(this, serviceInfo, isPreviewMode)); try { if (!ActivityTaskManager.getService().startDreamActivity(i)) { detach(); } mDreamManager.startDreamActivity(i); } catch (SecurityException e) { Log.w(mTag, "Received SecurityException trying to start DreamActivity. " Loading
core/java/android/service/dreams/IDreamManager.aidl +2 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.service.dreams; import android.content.ComponentName; import android.content.Intent; import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.os.IBinder; Loading Loading @@ -45,4 +46,5 @@ interface IDreamManager { void setDreamComponentsForUser(int userId, in ComponentName[] componentNames); void setSystemDreamComponent(in ComponentName componentName); void registerDreamOverlayService(in ComponentName componentName); void startDreamActivity(in Intent intent); }
services/core/java/com/android/server/dreams/DreamController.java +31 −3 Original line number Diff line number Diff line Loading @@ -16,11 +16,11 @@ package com.android.server.dreams; import static android.app.WindowConfiguration.ACTIVITY_TYPE_DREAM; import static android.content.Intent.FLAG_RECEIVER_FOREGROUND; import android.app.ActivityTaskManager; import android.app.BroadcastOptions; import android.app.IAppTask; import android.content.ComponentName; import android.content.Context; import android.content.Intent; Loading Loading @@ -213,6 +213,27 @@ final class DreamController { } } /** * Provides an appTask for the dream with token {@code dreamToken}, so that the dream controller * can stop the dream task when necessary. */ void setDreamAppTask(Binder dreamToken, IAppTask appTask) { if (mCurrentDream == null || mCurrentDream.mToken != dreamToken || mCurrentDream.mAppTask != null) { Slog.e(TAG, "Illegal dream activity start. mCurrentDream.mToken = " + mCurrentDream.mToken + ", illegal dreamToken = " + dreamToken + ". Ending this dream activity."); try { appTask.finishAndRemoveTask(); } catch (RemoteException | RuntimeException e) { Slog.e(TAG, "Unable to stop illegal dream activity."); } return; } mCurrentDream.mAppTask = appTask; } /** * Stops dreaming. * Loading Loading @@ -303,8 +324,14 @@ final class DreamController { mSentStartBroadcast = false; } mActivityTaskManager.removeRootTasksWithActivityTypes( new int[] {ACTIVITY_TYPE_DREAM}); if (mCurrentDream != null && mCurrentDream.mAppTask != null) { // Finish the dream task in case it hasn't finished by itself already. try { mCurrentDream.mAppTask.finishAndRemoveTask(); } catch (RemoteException | RuntimeException e) { Slog.e(TAG, "Unable to stop dream activity."); } } mListener.onDreamStopped(dream.mToken); } Loading Loading @@ -364,6 +391,7 @@ final class DreamController { public final boolean mIsPreviewMode; public final boolean mCanDoze; public final int mUserId; public IAppTask mAppTask; public PowerManager.WakeLock mWakeLock; public boolean mBound; Loading
services/core/java/com/android/server/dreams/DreamManagerService.java +62 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityManager; import android.app.IAppTask; import android.app.TaskInfo; import android.content.BroadcastReceiver; import android.content.ComponentName; Loading @@ -37,6 +38,7 @@ import android.content.IntentFilter; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManagerInternal; import android.content.pm.ServiceInfo; import android.database.ContentObserver; import android.hardware.display.AmbientDisplayConfiguration; Loading Loading @@ -116,6 +118,7 @@ public final class DreamManagerService extends SystemService { private final PowerManagerInternal mPowerManagerInternal; private final PowerManager.WakeLock mDozeWakeLock; private final ActivityTaskManagerInternal mAtmInternal; private final PackageManagerInternal mPmInternal; private final UserManager mUserManager; private final UiEventLogger mUiEventLogger; private final DreamUiEventLogger mDreamUiEventLogger; Loading Loading @@ -216,6 +219,7 @@ public final class DreamManagerService extends SystemService { mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); mPowerManagerInternal = getLocalService(PowerManagerInternal.class); mAtmInternal = getLocalService(ActivityTaskManagerInternal.class); mPmInternal = getLocalService(PackageManagerInternal.class); mUserManager = context.getSystemService(UserManager.class); mDozeWakeLock = mPowerManager.newWakeLock(PowerManager.DOZE_WAKE_LOCK, DOZE_WAKE_LOCK_TAG); mDozeConfig = new AmbientDisplayConfiguration(mContext); Loading Loading @@ -1064,6 +1068,64 @@ public final class DreamManagerService extends SystemService { Binder.restoreCallingIdentity(ident); } } @Override // Binder call public void startDreamActivity(@NonNull Intent intent) { final int callingUid = Binder.getCallingUid(); final int callingPid = Binder.getCallingPid(); // We post here, because startDreamActivity and setDreamAppTask have to run // synchronously and DreamController#setDreamAppTask has to run on mHandler. mHandler.post(() -> { final Binder dreamToken; final String dreamPackageName; synchronized (mLock) { if (mCurrentDream == null) { Slog.e(TAG, "Attempt to start DreamActivity, but the device is not " + "dreaming. Aborting without starting the DreamActivity."); return; } dreamToken = mCurrentDream.token; dreamPackageName = mCurrentDream.name.getPackageName(); } if (!canLaunchDreamActivity(dreamPackageName, intent.getPackage(), callingUid)) { Slog.e(TAG, "The dream activity can be started only when the device is dreaming" + " and only by the active dream package."); return; } final IAppTask appTask = mAtmInternal.startDreamActivity(intent, callingUid, callingPid); if (appTask == null) { Slog.e(TAG, "Could not start dream activity."); stopDreamInternal(true, "DreamActivity not started"); return; } mController.setDreamAppTask(dreamToken, appTask); }); } boolean canLaunchDreamActivity(String dreamPackageName, String packageName, int callingUid) { if (dreamPackageName == null || packageName == null) { Slog.e(TAG, "Cannot launch dream activity due to invalid state. dream component= " + dreamPackageName + ", packageName=" + packageName); return false; } if (!mPmInternal.isSameApp(packageName, callingUid, UserHandle.getUserId(callingUid))) { Slog.e(TAG, "Cannot launch dream activity because package=" + packageName + " does not match callingUid=" + callingUid); return false; } if (packageName.equals(dreamPackageName)) { return true; } Slog.e(TAG, "Dream packageName does not match active dream. Package " + packageName + " does not match " + dreamPackageName); return false; } } private final class LocalService extends DreamManagerInternal { Loading