PackageInstallerCompat.java revision 349426234e8c5a0e5bcf2c8d94dbb9844b5f724a
1e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal/*
2e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal * Copyright (C) 2014 The Android Open Source Project
3e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal *
4e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal * Licensed under the Apache License, Version 2.0 (the "License");
5e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal * you may not use this file except in compliance with the License.
6e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal * You may obtain a copy of the License at
7e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal *
8e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal *      http://www.apache.org/licenses/LICENSE-2.0
9e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal *
10e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal * Unless required by applicable law or agreed to in writing, software
11e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal * distributed under the License is distributed on an "AS IS" BASIS,
12e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal * See the License for the specific language governing permissions and
14e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal * limitations under the License.
15e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal */
16e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal
17e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyalpackage com.android.launcher3.compat;
18e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal
19e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyalimport android.content.Context;
20e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal
21e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyalimport com.android.launcher3.Utilities;
22e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal
23e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyalpublic abstract class PackageInstallerCompat {
24e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal
25349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal    public static final int STATUS_INSTALLED = 0;
26349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal    public static final int STATUS_INSTALLING = 1;
27349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal    public static final int STATUS_FAILED = 2;
28349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal
29e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal    private static final Object sInstanceLock = new Object();
30e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal    private static PackageInstallerCompat sInstance;
31e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal
32e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal    public static PackageInstallerCompat getInstance(Context context) {
33e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal        synchronized (sInstanceLock) {
34e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal            if (sInstance == null) {
35e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal                if (Utilities.isLmp()) {
36e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal                    sInstance = new PackageInstallerCompatVL(context);
37e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal                } else {
38e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal                    sInstance = new PackageInstallerCompatV16(context) { };
39e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal                }
40e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal            }
41e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal            return sInstance;
42e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal        }
43e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal    }
44e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal
45349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal    public abstract void updateActiveSessionCache();
46349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal
47e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal    public abstract void onPause();
48e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal
49e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal    public abstract void onResume();
50e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal
51e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal    public abstract void onFinishBind();
52e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal
53e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal    public abstract void onStop();
54e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal
55e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal    public abstract void recordPackageUpdate(String packageName, int state, int progress);
56e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal
57e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal    public static final class PackageInstallInfo {
58e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal        public final String packageName;
59e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal
60e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal        public int state;
61e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal        public int progress;
62e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal
63e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal        public PackageInstallInfo(String packageName) {
64e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal            this.packageName = packageName;
65e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal        }
66e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal
67e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal        public PackageInstallInfo(String packageName, int state, int progress) {
68e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal            this.packageName = packageName;
69e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal            this.state = state;
70e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal            this.progress = progress;
71e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal        }
72e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal    }
73e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal}
74