2 * The MIT License (MIT)
4 * Copyright 2016 Arnab Chakraborty. http://arnab.ch
6 * Permission is hereby granted, free of charge, to any person obtaining a copy of this
7 * software and associated documentation files (the "Software"), to deal in the Software
8 * without restriction, including without limitation the rights to use, copy, modify,
9 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to the following
13 * The above copyright notice and this permission notice shall be included in all copies
14 * or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
17 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 package org.anbox.appmgr;
26 import android.content.Context;
27 import android.content.pm.ApplicationInfo;
28 import android.graphics.drawable.Drawable;
33 * @credit http://developer.android.com/reference/android/content/AsyncTaskLoader.html
35 public class AppModel {
37 private final Context mContext;
38 private final ApplicationInfo mInfo;
40 private String mAppLabel;
41 private Drawable mIcon;
43 private boolean mMounted;
44 private final File mApkFile;
46 public AppModel(Context context, ApplicationInfo info) {
50 mApkFile = new File(info.sourceDir);
53 public ApplicationInfo getAppInfo() {
57 public String getApplicationPackageName() {
58 return getAppInfo().packageName;
61 public String getLabel() {
65 public Drawable getIcon() {
67 if (mApkFile.exists()) {
68 mIcon = mInfo.loadIcon(mContext.getPackageManager());
73 } else if (!mMounted) {
74 // If the app wasn't mounted but is now mounted, reload
76 if (mApkFile.exists()) {
78 mIcon = mInfo.loadIcon(mContext.getPackageManager());
85 return mContext.getResources().getDrawable(android.R.drawable.sym_def_app_icon);
89 void loadLabel(Context context) {
90 if (mAppLabel == null || !mMounted) {
91 if (!mApkFile.exists()) {
93 mAppLabel = mInfo.packageName;
96 CharSequence label = mInfo.loadLabel(context.getPackageManager());
97 mAppLabel = label != null ? label.toString() : mInfo.packageName;