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 import static android.view.Display.INVALID_DISPLAY; 21 22 import android.app.ClientTransactionHandler; 23 import android.content.res.Configuration; 24 import android.os.IBinder; 25 import android.os.Parcel; 26 import android.os.Trace; 27 28 import java.util.Objects; 29 30 /** 31 * Activity configuration changed callback. 32 * @hide 33 */ 34 public class ActivityConfigurationChangeItem extends ClientTransactionItem { 35 36 private Configuration mConfiguration; 37 38 @Override 39 public void execute(ClientTransactionHandler client, IBinder token, 40 PendingTransactionActions pendingActions) { 41 // TODO(lifecycler): detect if PIP or multi-window mode changed and report it here. 42 Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityConfigChanged"); 43 client.handleActivityConfigurationChanged(token, mConfiguration, INVALID_DISPLAY); 44 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); 45 } 46 47 48 // ObjectPoolItem implementation 49 50 private ActivityConfigurationChangeItem() {} 51 52 /** Obtain an instance initialized with provided params. */ 53 public static ActivityConfigurationChangeItem obtain(Configuration config) { 54 ActivityConfigurationChangeItem instance = 55 ObjectPool.obtain(ActivityConfigurationChangeItem.class); 56 if (instance == null) { 57 instance = new ActivityConfigurationChangeItem(); 58 } 59 instance.mConfiguration = config; 60 61 return instance; 62 } 63 64 @Override 65 public void recycle() { 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.writeTypedObject(mConfiguration, flags); 77 } 78 79 /** Read from Parcel. */ 80 private ActivityConfigurationChangeItem(Parcel in) { 81 mConfiguration = in.readTypedObject(Configuration.CREATOR); 82 } 83 84 public static final Creator<ActivityConfigurationChangeItem> CREATOR = 85 new Creator<ActivityConfigurationChangeItem>() { 86 public ActivityConfigurationChangeItem createFromParcel(Parcel in) { 87 return new ActivityConfigurationChangeItem(in); 88 } 89 90 public ActivityConfigurationChangeItem[] newArray(int size) { 91 return new ActivityConfigurationChangeItem[size]; 92 } 93 }; 94 95 @Override 96 public boolean equals(Object o) { 97 if (this == o) { 98 return true; 99 } 100 if (o == null || getClass() != o.getClass()) { 101 return false; 102 } 103 final ActivityConfigurationChangeItem other = (ActivityConfigurationChangeItem) o; 104 return Objects.equals(mConfiguration, other.mConfiguration); 105 } 106 107 @Override 108 public int hashCode() { 109 return mConfiguration.hashCode(); 110 } 111 112 @Override 113 public String toString() { 114 return "ActivityConfigurationChange{config=" + mConfiguration + "}"; 115 } 116 } 117