18027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu/*
28027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu * Copyright (C) 2015 The Android Open Source Project
38027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu *
48027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu * Licensed under the Apache License, Version 2.0 (the "License");
58027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu * you may not use this file except in compliance with the License.
68027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu * You may obtain a copy of the License at
78027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu *
88027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu *      http://www.apache.org/licenses/LICENSE-2.0
98027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu *
108027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu * Unless required by applicable law or agreed to in writing, software
118027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu * distributed under the License is distributed on an "AS IS" BASIS,
128027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu * See the License for the specific language governing permissions and
148027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu * limitations under the License.
158027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu */
168027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
178027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xupackage android.app.admin;
188027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
198027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xuimport android.annotation.IntDef;
20d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xuimport android.os.Parcel;
21d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xuimport android.os.Parcelable;
228027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xuimport android.os.PersistableBundle;
238027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
24d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xuimport org.xmlpull.v1.XmlPullParser;
25d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xuimport org.xmlpull.v1.XmlPullParserException;
26d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xuimport org.xmlpull.v1.XmlSerializer;
27d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu
28d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xuimport java.io.IOException;
298027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xuimport java.lang.annotation.Retention;
308027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xuimport java.lang.annotation.RetentionPolicy;
318027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
328027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu/**
335faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu * A class that represents a local system update policy set by the device owner.
348027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu *
355faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu * @see DevicePolicyManager#setSystemUpdatePolicy
365faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu * @see DevicePolicyManager#getSystemUpdatePolicy
378027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu */
38d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xupublic class SystemUpdatePolicy implements Parcelable {
398027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
408027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    /** @hide */
418027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    @IntDef({
428027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu        TYPE_INSTALL_AUTOMATIC,
438027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu        TYPE_INSTALL_WINDOWED,
448027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu        TYPE_POSTPONE})
458027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    @Retention(RetentionPolicy.SOURCE)
465faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu    @interface SystemUpdatePolicyType {}
478027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
488027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    /**
49d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     * Unknown policy type, used only internally.
50d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     */
51d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    private static final int TYPE_UNKNOWN = -1;
52d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    /**
535faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     * Install system update automatically as soon as one is available.
548027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     */
558027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    public static final int TYPE_INSTALL_AUTOMATIC = 1;
568027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
578027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    /**
585faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     * Install system update automatically within a daily maintenance window, for a maximum of 30
595faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     * days. After the expiration the policy will no longer be effective and the system should
605faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     * revert back to its normal behavior as if no policy were set. The only exception is
615faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     * {@link #TYPE_INSTALL_AUTOMATIC} which should still take effect to install system update
625faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     * immediately.
638027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     */
648027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    public static final int TYPE_INSTALL_WINDOWED = 2;
658027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
668027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    /**
675faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     * Incoming system update will be blocked for a maximum of 30 days, after which the system
685faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     * should revert back to its normal behavior as if no policy were set. The only exception is
695faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     * {@link #TYPE_INSTALL_AUTOMATIC} which should still take effect to install system update
705faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     * immediately.
718027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     */
728027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    public static final int TYPE_POSTPONE = 3;
738027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
748027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    private static final String KEY_POLICY_TYPE = "policy_type";
758027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    private static final String KEY_INSTALL_WINDOW_START = "install_window_start";
768027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    private static final String KEY_INSTALL_WINDOW_END = "install_window_end";
77d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    /**
78d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     * The upper boundary of the daily maintenance window: 24 * 60 minutes.
79d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     */
80d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    private static final int WINDOW_BOUNDARY = 24 * 60;
818027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
82d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    @SystemUpdatePolicyType
83d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    private int mPolicyType;
848027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
85d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    private int mMaintenanceWindowStart;
86d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    private int mMaintenanceWindowEnd;
878027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
888027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
89d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    private SystemUpdatePolicy() {
90d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        mPolicyType = TYPE_UNKNOWN;
918027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    }
928027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
938027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    /**
94d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     * Create a policy object and set it to install update automatically as soon as one is
95d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     * available.
965faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     *
975faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     * @see #TYPE_INSTALL_AUTOMATIC
988027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     */
99d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    public static SystemUpdatePolicy createAutomaticInstallPolicy() {
100d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        SystemUpdatePolicy policy = new SystemUpdatePolicy();
101d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        policy.mPolicyType = TYPE_INSTALL_AUTOMATIC;
102d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        return policy;
1038027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    }
1048027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
1058027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    /**
106d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     * Create a policy object and set it to: new system update will only be installed automatically
107d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     * when the system clock is inside a daily maintenance window. If the start and end times are
108d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     * the same, the window is considered to include the WHOLE 24 hours, that is, updates can
109d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     * install at any time. If the given window in invalid, a {@link IllegalArgumentException} will
110d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     * be thrown. If start time is later than end time, the window is considered spanning midnight,
1115faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     * i.e. end time donates a time on the next day. The maintenance window will last for 30 days,
1125faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     * after which the system should revert back to its normal behavior as if no policy were set.
1138027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     *
1148027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     * @param startTime the start of the maintenance window, measured as the number of minutes from
1155faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     *            midnight in the device's local time. Must be in the range of [0, 1440).
1168027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     * @param endTime the end of the maintenance window, measured as the number of minutes from
1175faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     *            midnight in the device's local time. Must be in the range of [0, 1440).
1185faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     * @see #TYPE_INSTALL_WINDOWED
1198027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     */
120d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    public static SystemUpdatePolicy createWindowedInstallPolicy(int startTime, int endTime) {
121d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        if (startTime < 0 || startTime >= WINDOW_BOUNDARY
122d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                || endTime < 0 || endTime >= WINDOW_BOUNDARY) {
123d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu            throw new IllegalArgumentException("startTime and endTime must be inside [0, 1440)");
1248027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu        }
125d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        SystemUpdatePolicy policy = new SystemUpdatePolicy();
126d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        policy.mPolicyType = TYPE_INSTALL_WINDOWED;
127d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        policy.mMaintenanceWindowStart = startTime;
128d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        policy.mMaintenanceWindowEnd = endTime;
129d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        return policy;
1308027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    }
1318027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
1328027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    /**
133d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     * Create a policy object and set it to block installation for a maximum period of 30 days.
134d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     * After expiration the system should revert back to its normal behavior as if no policy were
135d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     * set.
1365faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     *
1375faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     * @see #TYPE_POSTPONE
1388027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     */
139d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    public static SystemUpdatePolicy createPostponeInstallPolicy() {
140d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        SystemUpdatePolicy policy = new SystemUpdatePolicy();
141d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        policy.mPolicyType = TYPE_POSTPONE;
142d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        return policy;
1438027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    }
1448027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
1458027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    /**
1465faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu     * Returns the type of system update policy.
1478027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     *
1488027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     * @return an integer, either one of {@link #TYPE_INSTALL_AUTOMATIC},
1498027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     * {@link #TYPE_INSTALL_WINDOWED} and {@link #TYPE_POSTPONE}, or -1 if no policy has been set.
1508027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     */
1515faad8e4cdf04211239f076b5d073e26d0ae3207Rubin Xu    @SystemUpdatePolicyType
1528027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    public int getPolicyType() {
153d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        return mPolicyType;
1548027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    }
1558027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
1568027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    /**
1578027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     * Get the start of the maintenance window.
1588027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     *
1598027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     * @return the start of the maintenance window measured as the number of minutes from midnight,
1608027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     * or -1 if the policy does not have a maintenance window.
1618027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     */
1628027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    public int getInstallWindowStart() {
163d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        if (mPolicyType == TYPE_INSTALL_WINDOWED) {
164d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu            return mMaintenanceWindowStart;
1658027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu        } else {
1668027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu            return -1;
1678027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu        }
1688027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    }
1698027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
1708027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    /**
1718027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     * Get the end of the maintenance window.
1728027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     *
1738027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     * @return the end of the maintenance window measured as the number of minutes from midnight,
1748027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     * or -1 if the policy does not have a maintenance window.
1758027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     */
1768027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    public int getInstallWindowEnd() {
177d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        if (mPolicyType == TYPE_INSTALL_WINDOWED) {
178d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu            return mMaintenanceWindowEnd;
1798027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu        } else {
1808027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu            return -1;
1818027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu        }
1828027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    }
1838027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
184d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    /**
185d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     * Return if this object represents a valid policy.
186d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     * @hide
187d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     */
188d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    public boolean isValid() {
189d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        if (mPolicyType == TYPE_INSTALL_AUTOMATIC || mPolicyType == TYPE_POSTPONE) {
190d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu            return true;
191d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        } else if (mPolicyType == TYPE_INSTALL_WINDOWED) {
192d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu            return mMaintenanceWindowStart >= 0 && mMaintenanceWindowStart < WINDOW_BOUNDARY
193d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                    && mMaintenanceWindowEnd >= 0 && mMaintenanceWindowEnd < WINDOW_BOUNDARY;
194d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        } else {
195d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu            return false;
196d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        }
197d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    }
198d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu
1998027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    @Override
2008027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    public String toString() {
201d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        return String.format("SystemUpdatePolicy (type: %d, windowStart: %d, windowEnd: %d)",
202d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                mPolicyType, mMaintenanceWindowStart, mMaintenanceWindowEnd);
203d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    }
204d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu
205d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    @Override
206d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    public int describeContents() {
207d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        return 0;
2088027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    }
2098027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
210d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    @Override
211d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    public void writeToParcel(Parcel dest, int flags) {
212d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        dest.writeInt(mPolicyType);
213d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        dest.writeInt(mMaintenanceWindowStart);
214d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        dest.writeInt(mMaintenanceWindowEnd);
215d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    }
216d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu
217d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    public static final Parcelable.Creator<SystemUpdatePolicy> CREATOR =
218d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu            new Parcelable.Creator<SystemUpdatePolicy>() {
219d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu
220d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                @Override
221d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                public SystemUpdatePolicy createFromParcel(Parcel source) {
222d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                    SystemUpdatePolicy policy = new SystemUpdatePolicy();
223d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                    policy.mPolicyType = source.readInt();
224d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                    policy.mMaintenanceWindowStart = source.readInt();
225d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                    policy.mMaintenanceWindowEnd = source.readInt();
226d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                    return policy;
227d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                }
228d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu
229d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                @Override
230d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                public SystemUpdatePolicy[] newArray(int size) {
231d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                    return new SystemUpdatePolicy[size];
232d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                }
233d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    };
234d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu
235d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu
2368027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    /**
237d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     * @hide
2388027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu     */
239d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    public static SystemUpdatePolicy restoreFromXml(XmlPullParser parser) {
240d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        try {
241d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu            SystemUpdatePolicy policy = new SystemUpdatePolicy();
242d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu            String value = parser.getAttributeValue(null, KEY_POLICY_TYPE);
243d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu            if (value != null) {
244d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                policy.mPolicyType = Integer.parseInt(value);
245d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu
246d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                value = parser.getAttributeValue(null, KEY_INSTALL_WINDOW_START);
247d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                if (value != null) {
248d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                    policy.mMaintenanceWindowStart = Integer.parseInt(value);
249d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                }
250d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                value = parser.getAttributeValue(null, KEY_INSTALL_WINDOW_END);
251d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                if (value != null) {
252d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                    policy.mMaintenanceWindowEnd = Integer.parseInt(value);
253d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                }
254d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu                return policy;
255d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu            }
256d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        } catch (NumberFormatException e) {
257d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu            // Fail through
2588027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu        }
259d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        return null;
260d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    }
261d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu
262d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    /**
263d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     * @hide
264d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu     */
265d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu    public void saveToXml(XmlSerializer out) throws IOException {
266d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        out.attribute(null, KEY_POLICY_TYPE, Integer.toString(mPolicyType));
267d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        out.attribute(null, KEY_INSTALL_WINDOW_START, Integer.toString(mMaintenanceWindowStart));
268d86d58cd010b087d6d481062f84c894e0ced7bbcRubin Xu        out.attribute(null, KEY_INSTALL_WINDOW_END, Integer.toString(mMaintenanceWindowEnd));
2698027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu    }
2708027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu}
2718027a4ffc285ba39df3a262abfff1cfdd6dd31dbRubin Xu
272