Home | History | Annotate | Download | only in compat
      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.HashMap;
     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 
     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();
     41                 }
     42             }
     43             return sInstance;
     44         }
     45     }
     46 
     47     /**
     48      * @return a map of active installs to their progress
     49      */
     50     public abstract HashMap<String, Integer> updateAndGetActiveSessionCache();
     51 
     52     public abstract void onStop();
     53 
     54     public static final class PackageInstallInfo {
     55         public final String packageName;
     56 
     57         public int state;
     58         public int progress;
     59 
     60         public PackageInstallInfo(String packageName) {
     61             this.packageName = packageName;
     62         }
     63 
     64         public PackageInstallInfo(String packageName, int state, int progress) {
     65             this.packageName = packageName;
     66             this.state = state;
     67             this.progress = progress;
     68         }
     69     }
     70 }
     71