1 /* 2 * Copyright (C) 2023 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.car.user; 18 19 import android.annotation.NonNull; 20 import android.annotation.SystemApi; 21 import android.os.Parcelable; 22 import android.os.UserHandle; 23 24 import com.android.car.internal.util.DataClass; 25 26 /** 27 * User stop request. 28 * 29 * @hide 30 */ 31 @DataClass( 32 genParcelable = true, 33 genConstructor = false, 34 genAidl = true) 35 @SystemApi 36 public final class UserStopRequest implements Parcelable { 37 38 private final @NonNull UserHandle mUserHandle; 39 private final boolean mWithDelayedLocking; 40 private final boolean mForce; 41 42 /** Builder for {@link UserStopRequest}. */ 43 public static final class Builder { 44 private final @NonNull UserHandle mUserHandle; 45 // withDelayedLocking is true by default, as it is the most common use case. 46 private boolean mWithDelayedLocking = true; 47 // Note that mForce doesn't actually do anything. Its value is irrelevant. 48 private boolean mForce; 49 Builder(@onNull UserHandle userHandle)50 public Builder(@NonNull UserHandle userHandle) { 51 com.android.car.internal.util.AnnotationValidations.validate( 52 NonNull.class, /* ignored= */ null, userHandle); 53 mUserHandle = userHandle; 54 } 55 56 /** 57 * Sets the flag to stop the user with delayed locking. 58 * 59 * <p>The flag is {@code true} by default. 60 */ withDelayedLocking(boolean value)61 public @NonNull Builder withDelayedLocking(boolean value) { 62 mWithDelayedLocking = value; 63 return this; 64 } 65 66 /** 67 * Sets the flag to force-stop the user. 68 * 69 * <p>The flag is {@code false} by default. 70 */ setForce()71 public @NonNull Builder setForce() { 72 mForce = true; 73 return this; 74 } 75 76 /** Builds and returns a {@link UserStopRequest}. */ build()77 public @NonNull UserStopRequest build() { 78 return new UserStopRequest(this); 79 } 80 } 81 UserStopRequest(Builder builder)82 private UserStopRequest(Builder builder) { 83 mUserHandle = builder.mUserHandle; 84 mWithDelayedLocking = builder.mWithDelayedLocking; 85 mForce = builder.mForce; 86 } 87 88 89 90 // Code below generated by codegen v1.0.23. 91 // 92 // DO NOT MODIFY! 93 // CHECKSTYLE:OFF Generated code 94 // 95 // To regenerate run: 96 // $ codegen $ANDROID_BUILD_TOP/packages/services/Car/car-lib/src/android/car/user/UserStopRequest.java 97 // 98 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 99 // Settings > Editor > Code Style > Formatter Control 100 //@formatter:off 101 102 103 @DataClass.Generated.Member getUserHandle()104 public @NonNull UserHandle getUserHandle() { 105 return mUserHandle; 106 } 107 108 @DataClass.Generated.Member isWithDelayedLocking()109 public boolean isWithDelayedLocking() { 110 return mWithDelayedLocking; 111 } 112 113 @DataClass.Generated.Member isForce()114 public boolean isForce() { 115 return mForce; 116 } 117 118 @Override 119 @DataClass.Generated.Member writeToParcel(@onNull android.os.Parcel dest, int flags)120 public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { 121 // You can override field parcelling by defining methods like: 122 // void parcelFieldName(Parcel dest, int flags) { ... } 123 124 byte flg = 0; 125 if (mWithDelayedLocking) flg |= 0x2; 126 if (mForce) flg |= 0x4; 127 dest.writeByte(flg); 128 dest.writeTypedObject(mUserHandle, flags); 129 } 130 131 @Override 132 @DataClass.Generated.Member describeContents()133 public int describeContents() { return 0; } 134 135 /** @hide */ 136 @SuppressWarnings({"unchecked", "RedundantCast"}) 137 @DataClass.Generated.Member UserStopRequest(@onNull android.os.Parcel in)138 /* package-private */ UserStopRequest(@NonNull android.os.Parcel in) { 139 // You can override field unparcelling by defining methods like: 140 // static FieldType unparcelFieldName(Parcel in) { ... } 141 142 byte flg = in.readByte(); 143 boolean withDelayedLocking = (flg & 0x2) != 0; 144 boolean force = (flg & 0x4) != 0; 145 UserHandle userHandle = (UserHandle) in.readTypedObject(UserHandle.CREATOR); 146 147 this.mUserHandle = userHandle; 148 com.android.car.internal.util.AnnotationValidations.validate( 149 NonNull.class, null, mUserHandle); 150 this.mWithDelayedLocking = withDelayedLocking; 151 this.mForce = force; 152 153 // onConstructed(); // You can define this method to get a callback 154 } 155 156 @DataClass.Generated.Member 157 public static final @NonNull Parcelable.Creator<UserStopRequest> CREATOR 158 = new Parcelable.Creator<UserStopRequest>() { 159 @Override 160 public UserStopRequest[] newArray(int size) { 161 return new UserStopRequest[size]; 162 } 163 164 @Override 165 public UserStopRequest createFromParcel(@NonNull android.os.Parcel in) { 166 return new UserStopRequest(in); 167 } 168 }; 169 170 @DataClass.Generated( 171 time = 1679068284217L, 172 codegenVersion = "1.0.23", 173 sourceFile = "packages/services/Car/car-lib/src/android/car/user/UserStopRequest.java", 174 inputSignatures = "private final @android.annotation.NonNull android.os.UserHandle mUserHandle\nprivate final boolean mWithDelayedLocking\nprivate final boolean mForce\nclass UserStopRequest extends java.lang.Object implements [android.os.Parcelable]\nprivate final @android.annotation.NonNull android.os.UserHandle mUserHandle\nprivate boolean mWithDelayedLocking\nprivate boolean mForce\npublic @android.car.annotation.ApiRequirements @android.annotation.NonNull android.car.user.UserStopRequest.Builder withDelayedLocking()\npublic @android.car.annotation.ApiRequirements @android.annotation.NonNull android.car.user.UserStopRequest.Builder setForce()\npublic @android.car.annotation.ApiRequirements @android.annotation.NonNull android.car.user.UserStopRequest build()\nclass Builder extends java.lang.Object implements []\n@com.android.car.internal.util.DataClass(genParcelable=true, genConstructor=false, genAidl=true)") 175 @Deprecated __metadata()176 private void __metadata() {} 177 178 179 //@formatter:on 180 // End of generated code 181 182 } 183