Home | History | Annotate | Download | only in servertransaction
      1 /*
      2  * Copyright 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.app.servertransaction;
     18 
     19 import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
     20 
     21 import android.app.ClientTransactionHandler;
     22 import android.content.res.Configuration;
     23 import android.os.IBinder;
     24 import android.os.Parcel;
     25 import android.os.Trace;
     26 
     27 import java.util.Objects;
     28 
     29 /**
     30  * Activity move to a different display message.
     31  * @hide
     32  */
     33 public class MoveToDisplayItem extends ClientTransactionItem {
     34 
     35     private int mTargetDisplayId;
     36     private Configuration mConfiguration;
     37 
     38     @Override
     39     public void execute(ClientTransactionHandler client, IBinder token,
     40             PendingTransactionActions pendingActions) {
     41         Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityMovedToDisplay");
     42         client.handleActivityConfigurationChanged(token, mConfiguration, mTargetDisplayId);
     43         Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
     44     }
     45 
     46 
     47     // ObjectPoolItem implementation
     48 
     49     private MoveToDisplayItem() {}
     50 
     51     /** Obtain an instance initialized with provided params. */
     52     public static MoveToDisplayItem obtain(int targetDisplayId, Configuration configuration) {
     53         MoveToDisplayItem instance = ObjectPool.obtain(MoveToDisplayItem.class);
     54         if (instance == null) {
     55             instance = new MoveToDisplayItem();
     56         }
     57         instance.mTargetDisplayId = targetDisplayId;
     58         instance.mConfiguration = configuration;
     59 
     60         return instance;
     61     }
     62 
     63     @Override
     64     public void recycle() {
     65         mTargetDisplayId = 0;
     66         mConfiguration = null;
     67         ObjectPool.recycle(this);
     68     }
     69 
     70 
     71     // Parcelable implementation
     72 
     73     /** Write to Parcel. */
     74     @Override
     75     public void writeToParcel(Parcel dest, int flags) {
     76         dest.writeInt(mTargetDisplayId);
     77         dest.writeTypedObject(mConfiguration, flags);
     78     }
     79 
     80     /** Read from Parcel. */
     81     private MoveToDisplayItem(Parcel in) {
     82         mTargetDisplayId = in.readInt();
     83         mConfiguration = in.readTypedObject(Configuration.CREATOR);
     84     }
     85 
     86     public static final Creator<MoveToDisplayItem> CREATOR = new Creator<MoveToDisplayItem>() {
     87         public MoveToDisplayItem createFromParcel(Parcel in) {
     88             return new MoveToDisplayItem(in);
     89         }
     90 
     91         public MoveToDisplayItem[] newArray(int size) {
     92             return new MoveToDisplayItem[size];
     93         }
     94     };
     95 
     96     @Override
     97     public boolean equals(Object o) {
     98         if (this == o) {
     99             return true;
    100         }
    101         if (o == null || getClass() != o.getClass()) {
    102             return false;
    103         }
    104         final MoveToDisplayItem other = (MoveToDisplayItem) o;
    105         return mTargetDisplayId == other.mTargetDisplayId
    106                 && Objects.equals(mConfiguration, other.mConfiguration);
    107     }
    108 
    109     @Override
    110     public int hashCode() {
    111         int result = 17;
    112         result = 31 * result + mTargetDisplayId;
    113         result = 31 * result + mConfiguration.hashCode();
    114         return result;
    115     }
    116 
    117     @Override
    118     public String toString() {
    119         return "MoveToDisplayItem{targetDisplayId=" + mTargetDisplayId
    120                 + ",configuration=" + mConfiguration + "}";
    121     }
    122 }
    123