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 
17 package com.android.launcher3.compat;
18 
19 import android.content.Context;
20 
21 import com.android.launcher3.Utilities;
22 
23 import java.util.HashSet;
24 
25 public 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 
getInstance(Context context)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 
updateAndGetActiveSessionCache()47     public abstract HashSet<String> updateAndGetActiveSessionCache();
48 
onPause()49     public abstract void onPause();
50 
onResume()51     public abstract void onResume();
52 
onFinishBind()53     public abstract void onFinishBind();
54 
onStop()55     public abstract void onStop();
56 
recordPackageUpdate(String packageName, int state, int progress)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 
PackageInstallInfo(String packageName)65         public PackageInstallInfo(String packageName) {
66             this.packageName = packageName;
67         }
68 
PackageInstallInfo(String packageName, int state, int progress)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