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);
}
});
}
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;
});
}
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();
}
}
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();
}
}
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);
}
});
}
Aggregations