1 /* 2 * Copyright (C) 2015 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.updates; 18 19 import com.android.timezone.distro.TimeZoneDistro; 20 import com.android.timezone.distro.installer.TimeZoneDistroInstaller; 21 22 import android.util.Slog; 23 24 import java.io.File; 25 import java.io.IOException; 26 27 /** 28 * An install receiver responsible for installing timezone data updates. 29 */ 30 public class TzDataInstallReceiver extends ConfigUpdateInstallReceiver { 31 32 private static final String TAG = "TZDataInstallReceiver"; 33 34 private static final File SYSTEM_TZ_DATA_FILE = new File("/system/usr/share/zoneinfo/tzdata"); 35 private static final File TZ_DATA_DIR = new File("/data/misc/zoneinfo"); 36 private static final String UPDATE_DIR_NAME = TZ_DATA_DIR.getPath() + "/updates/"; 37 private static final String UPDATE_METADATA_DIR_NAME = "metadata/"; 38 private static final String UPDATE_VERSION_FILE_NAME = "version"; 39 private static final String UPDATE_CONTENT_FILE_NAME = "tzdata_distro.zip"; 40 41 private final TimeZoneDistroInstaller installer; 42 43 public TzDataInstallReceiver() { 44 super(UPDATE_DIR_NAME, UPDATE_CONTENT_FILE_NAME, UPDATE_METADATA_DIR_NAME, 45 UPDATE_VERSION_FILE_NAME); 46 installer = new TimeZoneDistroInstaller(TAG, SYSTEM_TZ_DATA_FILE, TZ_DATA_DIR); 47 } 48 49 @Override 50 protected void install(byte[] content, int version) throws IOException { 51 TimeZoneDistro distro = new TimeZoneDistro(content); 52 boolean valid = installer.install(distro); 53 Slog.i(TAG, "Timezone data install valid for this device: " + valid); 54 // Even if !valid, we call super.install(). Only in the event of an exception should we 55 // not. If we didn't do this we could attempt to install repeatedly. 56 super.install(content, version); 57 } 58 } 59