1 /* 2 * Copyright (C) 2025 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.server.security; 18 19 import android.app.job.JobParameters; 20 import android.app.job.JobService; 21 import android.util.Slog; 22 23 import java.util.concurrent.ExecutorService; 24 import java.util.concurrent.Executors; 25 26 /** 27 * A {@link JobService} that fetches the certificate revocation list from a remote location and 28 * stores it locally. 29 */ 30 public class UpdateCertificateRevocationStatusJobService extends JobService { 31 32 private static final String TAG = "AVF_CRL"; 33 private ExecutorService mExecutorService; 34 35 @Override onCreate()36 public void onCreate() { 37 super.onCreate(); 38 mExecutorService = Executors.newSingleThreadExecutor(); 39 } 40 41 @Override onStartJob(JobParameters params)42 public boolean onStartJob(JobParameters params) { 43 mExecutorService.execute( 44 () -> { 45 try { 46 CertificateRevocationStatusManager certificateRevocationStatusManager = 47 new CertificateRevocationStatusManager(this); 48 Slog.d(TAG, "Starting to fetch remote CRL from job service."); 49 byte[] revocationList = 50 certificateRevocationStatusManager.fetchRemoteRevocationListBytes(); 51 certificateRevocationStatusManager.silentlyStoreRevocationList( 52 revocationList); 53 } catch (Throwable t) { 54 Slog.e(TAG, "Unable to update the stored revocation list.", t); 55 } 56 jobFinished(params, false); 57 }); 58 return true; 59 } 60 61 @Override onStopJob(JobParameters params)62 public boolean onStopJob(JobParameters params) { 63 return false; 64 } 65 66 @Override onDestroy()67 public void onDestroy() { 68 super.onDestroy(); 69 mExecutorService.shutdown(); 70 } 71 } 72