/* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.content.pm; import static android.content.res.Resources.ID_NULL; import android.annotation.DrawableRes; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.StringRes; import android.annotation.SystemApi; import android.content.res.ResourceId; import android.os.Parcel; import android.os.Parcelable; import android.os.PersistableBundle; import android.util.Slog; import com.android.internal.util.Preconditions; import com.android.internal.util.XmlUtils; import com.android.modules.utils.TypedXmlPullParser; import com.android.modules.utils.TypedXmlSerializer; import java.io.IOException; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Locale; import java.util.Objects; /** * A container to describe the dialog to be shown when the user tries to launch a suspended * application. The suspending app can customize the dialog's following attributes: *
* The system will use {@link String#format(Locale, String, Object...) String.format} to * insert the suspended app name into the message, so an example format string could be * {@code "The app %1$s is currently suspended"}. This is optional - if the string passed in * {@code message} does not accept an argument, it will be used as is. * * @param message The dialog message. * @return this builder object. * @see #setMessage(int) */ @NonNull public Builder setMessage(@NonNull String message) { Preconditions.checkStringNotEmpty(message, "Message cannot be null or empty"); mDialogMessage = message; return this; } /** * Set the resource id of the dialog message to be shown. If no dialog message is provided * via either this method or {@link #setMessage(String)}, the system will use a default * message. *
* The system will use {@link android.content.res.Resources#getString(int, Object...) * getString} to insert the suspended app name into the message, so an example format string * could be {@code "The app %1$s is currently suspended"}. This is optional - if the string * referred to by {@code resId} does not accept an argument, it will be used as is. * * @param resId The resource id of the dialog message. * @return this builder object. * @see #setMessage(String) */ @NonNull public Builder setMessage(@StringRes int resId) { Preconditions.checkArgument(ResourceId.isValid(resId), "Invalid resource id provided"); mDialogMessageResId = resId; return this; } /** * Set the resource id of text to be shown on the neutral button. Tapping this button would * perform the {@link ButtonAction action} specified through * {@link #setNeutralButtonAction(int)}. If this is not provided, the system will use a * default text. * * @param resId The resource id of the button text * @return this builder object. */ @NonNull public Builder setNeutralButtonText(@StringRes int resId) { Preconditions.checkArgument(ResourceId.isValid(resId), "Invalid resource id provided"); mNeutralButtonTextResId = resId; return this; } /** * Set the text to be shown on the neutral button. Ignored if a resource id is set via * {@link #setNeutralButtonText(int)} * * @param neutralButtonText The title of the dialog. * @return this builder object. * @see #setNeutralButtonText(int) */ @NonNull public Builder setNeutralButtonText(@NonNull String neutralButtonText) { Preconditions.checkStringNotEmpty(neutralButtonText, "Button text cannot be null or empty"); mNeutralButtonText = neutralButtonText; return this; } /** * Set the action expected to happen on neutral button tap. Defaults to * {@link #BUTTON_ACTION_MORE_DETAILS} if this is not provided. * * @param buttonAction Either {@link #BUTTON_ACTION_MORE_DETAILS} or * {@link #BUTTON_ACTION_UNSUSPEND}. * @return this builder object */ @NonNull public Builder setNeutralButtonAction(@ButtonAction int buttonAction) { Preconditions.checkArgument(buttonAction == BUTTON_ACTION_MORE_DETAILS || buttonAction == BUTTON_ACTION_UNSUSPEND, "Invalid button action"); mNeutralButtonAction = buttonAction; return this; } /** * Build the final object based on given inputs. * * @return The {@link SuspendDialogInfo} object built using this builder. */ @NonNull public SuspendDialogInfo build() { return new SuspendDialogInfo(this); } } }