1 /* 2 * Copyright (C) 2024 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 com.android.adservices.shared.spe.framework; 18 19 import android.annotation.Nullable; 20 import android.app.job.JobParameters; 21 import android.os.PersistableBundle; 22 23 /** 24 * A wrapper of {@link android.app.job.JobParameters}. It's used to store the parameters when a job 25 * execution is invoked. 26 * 27 * <p>Currently, the only usage is to get the extras configured in the job scheduling. If you need 28 * extra parameters, please reach out to Infra team. 29 */ 30 public final class ExecutionRuntimeParameters { 31 @Nullable private final PersistableBundle mExtras; 32 ExecutionRuntimeParameters(@ullable PersistableBundle extras)33 private ExecutionRuntimeParameters(@Nullable PersistableBundle extras) { 34 mExtras = extras; 35 } 36 37 /** Returns the extras configured in job scheduling. */ 38 @Nullable getExtras()39 public PersistableBundle getExtras() { 40 return mExtras; 41 } 42 43 /** 44 * Converts a {@link JobParameters} to {@link ExecutionRuntimeParameters}. 45 * 46 * @param jobParameters the {@link JobParameters} to be converted 47 * @return a {@link ExecutionRuntimeParameters}. 48 */ convertJobParameters( @ullable JobParameters jobParameters)49 public static ExecutionRuntimeParameters convertJobParameters( 50 @Nullable JobParameters jobParameters) { 51 ExecutionRuntimeParameters.Builder builder = new ExecutionRuntimeParameters.Builder(); 52 if (jobParameters == null) { 53 return builder.build(); 54 } 55 56 return builder.setExtras(jobParameters.getExtras()).build(); 57 } 58 59 @Override toString()60 public String toString() { 61 return "ExecutionRuntimeParameters{" + "mExtras=" + mExtras + '}'; 62 } 63 64 /** Builder class for {@link ExecutionRuntimeParameters}. */ 65 public static final class Builder { 66 @Nullable private PersistableBundle mExtras; 67 68 /** Setter of {@link #getExtras()}. */ setExtras(@ullable PersistableBundle value)69 public Builder setExtras(@Nullable PersistableBundle value) { 70 mExtras = value; 71 return this; 72 } 73 74 /** Build an instance of {@link ExecutionRuntimeParameters}. */ build()75 public ExecutionRuntimeParameters build() { 76 return new ExecutionRuntimeParameters(mExtras); 77 } 78 } 79 } 80