PackageInstallerCompat.java revision 66af82cca76b313366e5429489aed85679c2c76e
1/*
2 * Copyright (C) 2014 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.launcher3.compat;
18
19import android.content.Context;
20
21import com.android.launcher3.Utilities;
22
23import java.util.HashSet;
24
25public abstract class PackageInstallerCompat {
26
27    public static final int STATUS_INSTALLED = 0;
28    public static final int STATUS_INSTALLING = 1;
29    public static final int STATUS_FAILED = 2;
30
31    private static final Object sInstanceLock = new Object();
32    private static PackageInstallerCompat sInstance;
33
34    public static PackageInstallerCompat getInstance(Context context) {
35        synchronized (sInstanceLock) {
36            if (sInstance == null) {
37                if (Utilities.isLmpOrAbove()) {
38                    sInstance = new PackageInstallerCompatVL(context);
39                } else {
40                    sInstance = new PackageInstallerCompatV16(context) { };
41                }
42            }
43            return sInstance;
44        }
45    }
46
47    public abstract HashSet<String> updateAndGetActiveSessionCache();
48
49    public abstract void onPause();
50
51    public abstract void onResume();
52
53    public abstract void onFinishBind();
54
55    public abstract void onStop();
56
57    public abstract void recordPackageUpdate(String packageName, int state, int progress);
58
59    public static final class PackageInstallInfo {
60        public final String packageName;
61
62        public int state;
63        public int progress;
64
65        public PackageInstallInfo(String packageName) {
66            this.packageName = packageName;
67        }
68
69        public PackageInstallInfo(String packageName, int state, int progress) {
70            this.packageName = packageName;
71            this.state = state;
72            this.progress = progress;
73        }
74    }
75}
76