Skip to content

Commit

Permalink
add work profile support
Browse files Browse the repository at this point in the history
  • Loading branch information
dkanada committed Nov 30, 2019
1 parent 4b0fd33 commit 3ed145b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -336,17 +339,25 @@ public void onReceive(Context context, Intent intent) {
public final void onStartApp(@NonNull Context context, @NonNull App app, @Nullable View view) {
if (BuildConfig.APPLICATION_ID.equals(app._packageName)) {
LauncherAction.RunAction(Action.LauncherSettings, context);
} else {
try {
return;
}

try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && app._userHandle != null) {
LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
List<LauncherActivityInfo> activities = launcherApps.getActivityList(app.getPackageName(), app._userHandle);
launcherApps.startMainActivity(activities.get(0).getComponentName(), app._userHandle, null, getActivityAnimationOpts(view));
} else {
Intent intent = Tool.getIntentFromApp(app);
context.startActivity(intent, getActivityAnimationOpts(view));
// close app drawer and other items in advance
// annoying to wait for app drawer to close
handleLauncherResume();
} catch (Exception e) {
e.printStackTrace();
Tool.toast(context, R.string.toast_app_uninstalled);
}

// close app drawer and other items in advance
// annoying to wait for app drawer to close
handleLauncherResume();
} catch (Exception e) {
e.printStackTrace();
Tool.toast(context, R.string.toast_app_uninstalled);
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/benny/openlauncher/model/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.os.UserHandle;

public class App {
public Drawable _icon;
public String _label;
public String _packageName;
public String _className;
public UserHandle _userHandle;

public App(PackageManager pm, ResolveInfo info) {
_icon = info.loadIcon(pm);
Expand Down
35 changes: 20 additions & 15 deletions app/src/main/java/com/benny/openlauncher/util/AppManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.content.Intent;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
Expand Down Expand Up @@ -159,20 +160,25 @@ protected Object doInBackground(Object[] p1) {
LauncherApps launcherApps = (LauncherApps) _context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
List<UserHandle> profiles = launcherApps.getProfiles();
for (UserHandle userHandle : profiles) {
// TODO lots of stuff required with the rest of the app to get this working
//List<LauncherActivityInfo> apps = launcherApps.getActivityList(null, userHandle);
//for (LauncherActivityInfo info : apps) {
// _nonFilteredApps.add(new App(_packageManager, info.getApplicationInfo()));
//}
List<LauncherActivityInfo> apps = launcherApps.getActivityList(null, userHandle);
for (LauncherActivityInfo info : apps) {
App app = new App(_packageManager, info.getApplicationInfo());
app._userHandle = userHandle;
// not sure if this conditional should be kept
// duplicate apps were showing up in the app drawer
if (!_nonFilteredApps.contains(app)) {
_nonFilteredApps.add(app);
}
}
}
} else {
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> activitiesInfo = _packageManager.queryIntentActivities(intent, 0);
for (ResolveInfo info : activitiesInfo) {
App app = new App(_packageManager, info);
_nonFilteredApps.add(app);
}
}

Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> activitiesInfo = _packageManager.queryIntentActivities(intent, 0);
for (ResolveInfo info : activitiesInfo) {
App app = new App(_packageManager, info);
_nonFilteredApps.add(app);
}

// sort the apps by label here
Expand All @@ -198,8 +204,7 @@ public int compare(App one, App two) {
}
}
} else {
for (ResolveInfo info : activitiesInfo)
_apps.add(new App(_packageManager, info));
_apps.addAll(_nonFilteredApps);
}

AppSettings appSettings = AppSettings.get();
Expand Down

0 comments on commit 3ed145b

Please sign in to comment.