Search in sources :

Example 1 with MultiplePackageAppData

use of io.virtualapp.home.models.MultiplePackageAppData in project VirtualXposed by android-hacker.

the class Installd method addApp.

public static void addApp(AppInfoLite info, UpdateListener refreshListener) {
    class AddResult {

        private PackageAppData appData;

        private int userId;

        private boolean justEnableHidden;
    }
    AddResult addResult = new AddResult();
    VUiKit.defer().when(() -> {
        InstalledAppInfo installedAppInfo = VirtualCore.get().getInstalledAppInfo(info.packageName, 0);
        addResult.justEnableHidden = installedAppInfo != null;
        if (info.disableMultiVersion) {
            addResult.justEnableHidden = false;
        }
        if (addResult.justEnableHidden) {
            int[] userIds = installedAppInfo.getInstalledUsers();
            int nextUserId = userIds.length;
            /*
                  Input : userIds = {0, 1, 3}
                  Output: nextUserId = 2
                 */
            for (int i = 0; i < userIds.length; i++) {
                if (userIds[i] != i) {
                    nextUserId = i;
                    break;
                }
            }
            addResult.userId = nextUserId;
            if (VUserManager.get().getUserInfo(nextUserId) == null) {
                // user not exist, create it automatically.
                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 {
            PackageInfo pkgInfo = null;
            try {
                pkgInfo = XApp.getApp().getPackageManager().getPackageArchiveInfo(info.path, 0);
                pkgInfo.applicationInfo.sourceDir = info.path;
                pkgInfo.applicationInfo.publicSourceDir = info.path;
            } catch (Exception e) {
            }
            if (pkgInfo != null) {
                PackageAppData data = PackageAppDataStorage.get().acquire(pkgInfo.applicationInfo);
                addResult.appData = data;
                data.isInstalling = true;
                data.isFirstOpen = false;
                if (refreshListener != null) {
                    refreshListener.update(data);
                }
            }
            InstallResult res = addVirtualApp(info);
            if (!res.isSuccess) {
                if (addResult.appData != null) {
                // mView.removeAppToLauncher(addResult.appData);
                }
                throw new IllegalStateException();
            }
        }
    }).then((res) -> {
        if (addResult.appData == null) {
            addResult.appData = PackageAppDataStorage.get().acquire(info.packageName);
        }
    }).done(res -> {
        boolean multipleVersion = addResult.justEnableHidden && addResult.userId != 0;
        if (!multipleVersion) {
            PackageAppData data = addResult.appData;
            data.isInstalling = false;
            data.isLoading = true;
            if (refreshListener != null) {
                refreshListener.update(data);
            }
            handleOptApp(data, info.packageName, true, refreshListener);
        } else {
            MultiplePackageAppData data = new MultiplePackageAppData(addResult.appData, addResult.userId);
            data.isInstalling = false;
            data.isLoading = true;
            if (refreshListener != null) {
                refreshListener.update(data);
            }
            handleOptApp(data, info.packageName, false, refreshListener);
        }
    });
}
Also used : VUserInfo(com.lody.virtual.os.VUserInfo) XApp(io.virtualapp.XApp) PackageAppDataStorage(io.virtualapp.home.repo.PackageAppDataStorage) Context(android.content.Context) InstallResult(com.lody.virtual.remote.InstallResult) PackageManager(android.content.pm.PackageManager) VirtualCore(com.lody.virtual.client.core.VirtualCore) MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) DeviceUtil(com.lody.virtual.helper.utils.DeviceUtil) VUserManager(com.lody.virtual.os.VUserManager) PackageAppData(io.virtualapp.home.models.PackageAppData) AppData(io.virtualapp.home.models.AppData) Intent(android.content.Intent) IOException(java.io.IOException) VCommends(io.virtualapp.VCommends) PackageInfo(android.content.pm.PackageInfo) AppInfoLite(io.virtualapp.home.models.AppInfoLite) ArrayList(java.util.ArrayList) InstallStrategy(com.lody.virtual.client.core.InstallStrategy) InstalledAppInfo(com.lody.virtual.remote.InstalledAppInfo) VUiKit(io.virtualapp.abs.ui.VUiKit) PackageInfo(android.content.pm.PackageInfo) InstalledAppInfo(com.lody.virtual.remote.InstalledAppInfo) MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) PackageAppData(io.virtualapp.home.models.PackageAppData) IOException(java.io.IOException) InstallResult(com.lody.virtual.remote.InstallResult) MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) VUserInfo(com.lody.virtual.os.VUserInfo)

Example 2 with MultiplePackageAppData

use of io.virtualapp.home.models.MultiplePackageAppData in project VirtualXposed by android-hacker.

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<>();
        for (InstalledAppInfo info : infos) {
            if (!VirtualCore.get().isPackageLaunchable(info.packageName)) {
                continue;
            }
            PackageAppData data = new PackageAppData(mContext, info);
            if (VirtualCore.get().isAppInstalledAsUser(0, info.packageName)) {
                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 3 with MultiplePackageAppData

use of io.virtualapp.home.models.MultiplePackageAppData in project VirtualApp by asLody.

the class HomePresenterImpl method deleteApp.

@Override
public void deleteApp(AppData data) {
    try {
        mView.removeAppToLauncher(data);
        if (data instanceof PackageAppData) {
            mRepo.removeVirtualApp(((PackageAppData) data).packageName, 0);
        } else {
            MultiplePackageAppData appData = (MultiplePackageAppData) data;
            mRepo.removeVirtualApp(appData.appInfo.packageName, appData.userId);
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) PackageAppData(io.virtualapp.home.models.PackageAppData)

Example 4 with MultiplePackageAppData

use of io.virtualapp.home.models.MultiplePackageAppData in project VirtualApp by asLody.

the class HomePresenterImpl method launchApp.

@Override
public void launchApp(AppData data) {
    try {
        if (data instanceof PackageAppData) {
            PackageAppData appData = (PackageAppData) data;
            appData.isFirstOpen = false;
            LoadingActivity.launch(mActivity, appData.packageName, 0);
        } else if (data instanceof MultiplePackageAppData) {
            MultiplePackageAppData multipleData = (MultiplePackageAppData) data;
            multipleData.isFirstOpen = false;
            LoadingActivity.launch(mActivity, multipleData.appInfo.packageName, ((MultiplePackageAppData) data).userId);
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) PackageAppData(io.virtualapp.home.models.PackageAppData)

Example 5 with MultiplePackageAppData

use of io.virtualapp.home.models.MultiplePackageAppData in project VirtualApp by asLody.

the class HomePresenterImpl method addApp.

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

        private PackageAppData appData;

        private int userId;

        private boolean justEnableHidden;
    }
    AddResult addResult = new AddResult();
    VUiKit.defer().when(() -> {
        InstalledAppInfo installedAppInfo = VirtualCore.get().getInstalledAppInfo(info.packageName, 0);
        addResult.justEnableHidden = installedAppInfo != null;
        if (addResult.justEnableHidden) {
            int[] userIds = installedAppInfo.getInstalledUsers();
            int nextUserId = userIds.length;
            /*
                  Input : userIds = {0, 1, 3}
                  Output: nextUserId = 2
                 */
            for (int i = 0; i < userIds.length; i++) {
                if (userIds[i] != i) {
                    nextUserId = i;
                    break;
                }
            }
            addResult.userId = nextUserId;
            if (VUserManager.get().getUserInfo(nextUserId) == null) {
                // user not exist, create it automatically.
                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 -> {
        boolean multipleVersion = addResult.justEnableHidden && addResult.userId != 0;
        if (!multipleVersion) {
            PackageAppData data = addResult.appData;
            data.isLoading = true;
            mView.addAppToLauncher(data);
            handleOptApp(data, info.packageName, true);
        } else {
            MultiplePackageAppData data = new MultiplePackageAppData(addResult.appData, addResult.userId);
            data.isLoading = true;
            mView.addAppToLauncher(data);
            handleOptApp(data, info.packageName, false);
        }
    });
}
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) GmsSupport(com.lody.virtual.GmsSupport) 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)

Aggregations

MultiplePackageAppData (io.virtualapp.home.models.MultiplePackageAppData)7 PackageAppData (io.virtualapp.home.models.PackageAppData)6 AppData (io.virtualapp.home.models.AppData)5 InstalledAppInfo (com.lody.virtual.remote.InstalledAppInfo)4 ArrayList (java.util.ArrayList)3 VirtualCore (com.lody.virtual.client.core.VirtualCore)2 VUserInfo (com.lody.virtual.os.VUserInfo)2 VUserManager (com.lody.virtual.os.VUserManager)2 InstallResult (com.lody.virtual.remote.InstallResult)2 VCommends (io.virtualapp.VCommends)2 VUiKit (io.virtualapp.abs.ui.VUiKit)2 AppInfoLite (io.virtualapp.home.models.AppInfoLite)2 PackageAppDataStorage (io.virtualapp.home.repo.PackageAppDataStorage)2 IOException (java.io.IOException)2 Activity (android.app.Activity)1 Context (android.content.Context)1 Intent (android.content.Intent)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 Bitmap (android.graphics.Bitmap)1