4545import android .content .res .Configuration ;
4646import android .content .res .Resources ;
4747import android .graphics .Bitmap ;
48- import android .net .Uri ;
4948import android .os .Binder ;
5049import android .os .Bundle ;
5150import android .os .Handler ;
@@ -289,7 +288,19 @@ enum ActivityState {
289288 static final int RESUME_TOP_ACTIVITY_MSG = ActivityManagerService .FIRST_ACTIVITY_STACK_MSG + 6 ;
290289 static final int LAUNCH_TICK_MSG = ActivityManagerService .FIRST_ACTIVITY_STACK_MSG + 7 ;
291290 static final int STOP_TIMEOUT_MSG = ActivityManagerService .FIRST_ACTIVITY_STACK_MSG + 8 ;
292-
291+ static final int DESTROY_ACTIVITIES_MSG = ActivityManagerService .FIRST_ACTIVITY_STACK_MSG + 9 ;
292+
293+ static class ScheduleDestroyArgs {
294+ final ProcessRecord mOwner ;
295+ final boolean mOomAdj ;
296+ final String mReason ;
297+ ScheduleDestroyArgs (ProcessRecord owner , boolean oomAdj , String reason ) {
298+ mOwner = owner ;
299+ mOomAdj = oomAdj ;
300+ mReason = reason ;
301+ }
302+ }
303+
293304 final Handler mHandler = new Handler () {
294305 //public Handler() {
295306 // if (localLOGV) Slog.v(TAG, "Handler started!");
@@ -384,6 +395,12 @@ public void handleMessage(Message msg) {
384395 }
385396 }
386397 } break ;
398+ case DESTROY_ACTIVITIES_MSG : {
399+ ScheduleDestroyArgs args = (ScheduleDestroyArgs )msg .obj ;
400+ synchronized (mService ) {
401+ destroyActivitiesLocked (args .mOwner , args .mOomAdj , args .mReason );
402+ }
403+ }
387404 }
388405 }
389406 };
@@ -3821,19 +3838,39 @@ final void cleanUpActivityServicesLocked(ActivityRecord r) {
38213838 r .connections = null ;
38223839 }
38233840 }
3824-
3841+
3842+ final void scheduleDestroyActivities (ProcessRecord owner , boolean oomAdj , String reason ) {
3843+ Message msg = mHandler .obtainMessage (DESTROY_ACTIVITIES_MSG );
3844+ msg .obj = new ScheduleDestroyArgs (owner , oomAdj , reason );
3845+ mHandler .sendMessage (msg );
3846+ }
3847+
38253848 final void destroyActivitiesLocked (ProcessRecord owner , boolean oomAdj , String reason ) {
3849+ boolean lastIsOpaque = false ;
38263850 for (int i =mHistory .size ()-1 ; i >=0 ; i --) {
38273851 ActivityRecord r = mHistory .get (i );
3852+ if (r .finishing ) {
3853+ continue ;
3854+ }
3855+ if (r .fullscreen ) {
3856+ lastIsOpaque = true ;
3857+ }
38283858 if (owner != null && r .app != owner ) {
38293859 continue ;
38303860 }
3861+ if (!lastIsOpaque ) {
3862+ continue ;
3863+ }
38313864 // We can destroy this one if we have its icicle saved and
38323865 // it is not in the process of pausing/stopping/finishing.
3833- if (r .app != null && r .haveState && !r .visible && r .stopped && !r .finishing
3866+ if (r .app != null && r != mResumedActivity && r != mPausingActivity
3867+ && r .haveState && !r .visible && r .stopped
38343868 && r .state != ActivityState .DESTROYING
38353869 && r .state != ActivityState .DESTROYED ) {
3836- destroyActivityLocked (r , true , oomAdj , "trim" );
3870+ if (DEBUG_SWITCH ) Slog .v (TAG , "Destroying " + r + " in state " + r .state
3871+ + " resumed=" + mResumedActivity
3872+ + " pausing=" + mPausingActivity );
3873+ destroyActivityLocked (r , true , oomAdj , reason );
38373874 }
38383875 }
38393876 }
@@ -3847,7 +3884,7 @@ final void destroyActivitiesLocked(ProcessRecord owner, boolean oomAdj, String r
38473884 final boolean destroyActivityLocked (ActivityRecord r ,
38483885 boolean removeFromApp , boolean oomAdj , String reason ) {
38493886 if (DEBUG_SWITCH ) Slog .v (
3850- TAG , "Removing activity: token=" + r
3887+ TAG , "Removing activity from " + reason + " : token=" + r
38513888 + ", app=" + (r .app != null ? r .app .processName : "(null)" ));
38523889 EventLog .writeEvent (EventLogTags .AM_DESTROY_ACTIVITY ,
38533890 System .identityHashCode (r ),
0 commit comments