Last active
March 5, 2018 16:36
-
-
Save d4rken/80aa38f7b1a18649ec206f180ae0ecfc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AppComponent.Scope | |
public class AppRepo { | |
private final Object appMapLock = new Object(); | |
private Map<String, PackageInfo> appMap; | |
private final IPCFunnel ipcFunnel; | |
@Inject | |
public AppRepo(IPCFunnel ipcFunnel) {this.ipcFunnel = ipcFunnel;} | |
public Map<String, PackageInfo> getAppMap(boolean refresh) { | |
synchronized (appMapLock) { | |
if (appMap == null || appMap.isEmpty() || refresh) { | |
appMap = new ConcurrentHashMap<>(); | |
List<PackageInfo> appList = ipcFunnel.getInstalledPackages(PackageManager.GET_SHARED_LIBRARY_FILES); | |
for (PackageInfo pkg : appList) appMap.put(pkg.packageName, pkg); | |
//noinspection deprecation | |
appList = ipcFunnel.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES); | |
for (PackageInfo pkg : appList) appMap.put(pkg.packageName, pkg); | |
if (appMap.isEmpty()) throw new IPCBufferException("List of installed apps was empty!"); | |
} | |
} | |
return new HashMap<>(appMap); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment