Search in sources :

Example 1 with InstalledAppInfo

use of com.lody.virtual.remote.InstalledAppInfo in project VirtualApp by asLody.

the class VirtualCore method createShortcut.

public boolean createShortcut(int userId, String packageName, Intent splash, OnEmitShortcutListener listener) {
    InstalledAppInfo setting = getInstalledAppInfo(packageName, 0);
    if (setting == null) {
        return false;
    }
    ApplicationInfo appInfo = setting.getApplicationInfo(userId);
    PackageManager pm = context.getPackageManager();
    String name;
    Bitmap icon;
    try {
        CharSequence sequence = appInfo.loadLabel(pm);
        name = sequence.toString();
        icon = BitmapUtils.drawableToBitmap(appInfo.loadIcon(pm));
    } catch (Throwable e) {
        return false;
    }
    if (listener != null) {
        String newName = listener.getName(name);
        if (newName != null) {
            name = newName;
        }
        Bitmap newIcon = listener.getIcon(icon);
        if (newIcon != null) {
            icon = newIcon;
        }
    }
    Intent targetIntent = getLaunchIntent(packageName, userId);
    if (targetIntent == null) {
        return false;
    }
    Intent shortcutIntent = new Intent();
    shortcutIntent.setClassName(getHostPkg(), Constants.SHORTCUT_PROXY_ACTIVITY_NAME);
    shortcutIntent.addCategory(Intent.CATEGORY_DEFAULT);
    if (splash != null) {
        shortcutIntent.putExtra("_VA_|_splash_", splash.toUri(0));
    }
    shortcutIntent.putExtra("_VA_|_intent_", targetIntent);
    shortcutIntent.putExtra("_VA_|_uri_", targetIntent.toUri(0));
    shortcutIntent.putExtra("_VA_|_user_id_", VUserHandle.myUserId());
    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    context.sendBroadcast(addIntent);
    return true;
}
Also used : Bitmap(android.graphics.Bitmap) PackageManager(android.content.pm.PackageManager) VPackageManager(com.lody.virtual.client.ipc.VPackageManager) InstalledAppInfo(com.lody.virtual.remote.InstalledAppInfo) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent)

Example 2 with InstalledAppInfo

use of com.lody.virtual.remote.InstalledAppInfo in project VirtualApp by asLody.

the class HomePresenterImpl method addApp.

@Override
public void addApp(AppInfoLite info) {
    class AddResult {

        private PackageAppData appData;

        private int userId;
    }
    AddResult addResult = new AddResult();
    VUiKit.defer().when(() -> {
        InstalledAppInfo installedAppInfo = VirtualCore.get().getInstalledAppInfo(info.packageName, 0);
        if (installedAppInfo != null) {
            int[] userIds = installedAppInfo.getInstalledUsers();
            int nextUserId = userIds.length;
            addResult.userId = nextUserId;
            if (VUserManager.get().getUserInfo(nextUserId) == null) {
                String nextUserName = "Space " + nextUserId + 1;
                VUserInfo newUserInfo = VUserManager.get().createUser(nextUserName, VUserInfo.FLAG_ADMIN);
                if (newUserInfo == null) {
                    throw new IllegalStateException();
                }
            }
            boolean success = VirtualCore.get().installPackageAsUser(nextUserId, info.packageName);
            if (!success) {
                throw new IllegalStateException();
            }
        } else {
            InstallResult res = mRepo.addVirtualApp(info);
            if (!res.isSuccess) {
                throw new IllegalStateException();
            }
        }
    }).then((res) -> {
        addResult.appData = PackageAppDataStorage.get().acquire(info.packageName);
    }).done(res -> {
        if (addResult.userId == 0) {
            PackageAppData data = addResult.appData;
            data.isLoading = true;
            mView.addAppToLauncher(data);
            handleOptApp(data);
        } else {
            MultiplePackageAppData data = new MultiplePackageAppData(addResult.appData, addResult.userId);
            data.isLoading = true;
            mView.addAppToLauncher(data);
            handleMultipleApp(data);
        }
    });
}
Also used : VUserInfo(com.lody.virtual.os.VUserInfo) PackageAppDataStorage(io.virtualapp.home.repo.PackageAppDataStorage) InstallResult(com.lody.virtual.remote.InstallResult) VirtualCore(com.lody.virtual.client.core.VirtualCore) MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) VUserManager(com.lody.virtual.os.VUserManager) PackageAppData(io.virtualapp.home.models.PackageAppData) AppData(io.virtualapp.home.models.AppData) IOException(java.io.IOException) AppRepository(io.virtualapp.home.repo.AppRepository) VCommends(io.virtualapp.VCommends) AppInfoLite(io.virtualapp.home.models.AppInfoLite) Bitmap(android.graphics.Bitmap) InstalledAppInfo(com.lody.virtual.remote.InstalledAppInfo) VUiKit(io.virtualapp.abs.ui.VUiKit) Once(jonathanfinerty.once.Once) Activity(android.app.Activity) InstalledAppInfo(com.lody.virtual.remote.InstalledAppInfo) MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) PackageAppData(io.virtualapp.home.models.PackageAppData) InstallResult(com.lody.virtual.remote.InstallResult) VUserInfo(com.lody.virtual.os.VUserInfo)

Example 3 with InstalledAppInfo

use of com.lody.virtual.remote.InstalledAppInfo in project VirtualApp by asLody.

the class NativeEngine method onOpenDexFileNative.

public static void onOpenDexFileNative(String[] params) {
    String dexOrJarPath = params[0];
    String outputPath = params[1];
    VLog.d(TAG, "DexOrJarPath = %s, OutputPath = %s.", dexOrJarPath, outputPath);
    try {
        String canonical = new File(dexOrJarPath).getCanonicalPath();
        InstalledAppInfo info = sDexOverrideMap.get(canonical);
        if (info != null && !info.dependSystem) {
            outputPath = info.getOdexFile().getPath();
            params[1] = outputPath;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : InstalledAppInfo(com.lody.virtual.remote.InstalledAppInfo) IOException(java.io.IOException) DexFile(dalvik.system.DexFile) File(java.io.File)

Example 4 with InstalledAppInfo

use of com.lody.virtual.remote.InstalledAppInfo in project VirtualApp by asLody.

the class AppRepository method getVirtualApps.

@Override
public Promise<List<AppData>, Throwable, Void> getVirtualApps() {
    return VUiKit.defer().when(() -> {
        List<InstalledAppInfo> infos = VirtualCore.get().getInstalledApps(0);
        List<AppData> models = new ArrayList<AppData>();
        for (InstalledAppInfo info : infos) {
            if (VirtualCore.get().getLaunchIntent(info.packageName, 0) == null) {
                continue;
            }
            PackageAppData data = new PackageAppData(mContext, info);
            models.add(data);
            int[] userIds = info.getInstalledUsers();
            for (int userId : userIds) {
                if (userId != 0) {
                    models.add(new MultiplePackageAppData(data, userId));
                }
            }
        }
        return models;
    });
}
Also used : MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) PackageAppData(io.virtualapp.home.models.PackageAppData) AppData(io.virtualapp.home.models.AppData) InstalledAppInfo(com.lody.virtual.remote.InstalledAppInfo) ArrayList(java.util.ArrayList) MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) PackageAppData(io.virtualapp.home.models.PackageAppData)

Example 5 with InstalledAppInfo

use of com.lody.virtual.remote.InstalledAppInfo in project VirtualApp by asLody.

the class VAppManagerService method getInstalledApps.

@Override
public List<InstalledAppInfo> getInstalledApps(int flags) {
    List<InstalledAppInfo> infoList = new ArrayList<>(getInstalledAppCount());
    for (VPackage p : PackageCacheManager.PACKAGE_CACHE.values()) {
        PackageSetting setting = (PackageSetting) p.mExtras;
        infoList.add(setting.getAppInfo(flags));
    }
    return infoList;
}
Also used : VPackage(com.lody.virtual.server.pm.parser.VPackage) ArrayList(java.util.ArrayList) InstalledAppInfo(com.lody.virtual.remote.InstalledAppInfo)

Aggregations

InstalledAppInfo (com.lody.virtual.remote.InstalledAppInfo)11 ArrayList (java.util.ArrayList)4 ApplicationInfo (android.content.pm.ApplicationInfo)3 PackageManager (android.content.pm.PackageManager)3 IOException (java.io.IOException)3 Intent (android.content.Intent)2 AssetManager (android.content.res.AssetManager)2 Resources (android.content.res.Resources)2 Bitmap (android.graphics.Bitmap)2 VPackageManager (com.lody.virtual.client.ipc.VPackageManager)2 VPackage (com.lody.virtual.server.pm.parser.VPackage)2 DexFile (dalvik.system.DexFile)2 AppData (io.virtualapp.home.models.AppData)2 MultiplePackageAppData (io.virtualapp.home.models.MultiplePackageAppData)2 PackageAppData (io.virtualapp.home.models.PackageAppData)2 File (java.io.File)2 Activity (android.app.Activity)1 PackageInfo (android.content.pm.PackageInfo)1 VirtualCore (com.lody.virtual.client.core.VirtualCore)1 VUserInfo (com.lody.virtual.os.VUserInfo)1