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