Add API to query managed profiles
Replace mIsPrimaryUser and UserManager calls with API
Change-Id: I4c9661c6daf3dcb714db01d5229bf4cee37648c2
diff --git a/src/org/lineageos/setupwizard/BaseSetupWizardActivity.java b/src/org/lineageos/setupwizard/BaseSetupWizardActivity.java
index 2039c0e..2ec668c 100644
--- a/src/org/lineageos/setupwizard/BaseSetupWizardActivity.java
+++ b/src/org/lineageos/setupwizard/BaseSetupWizardActivity.java
@@ -88,7 +88,6 @@
protected boolean mIsExiting = false;
private final boolean mIsFirstRun = true;
protected boolean mIsGoingBack = false;
- private boolean mIsPrimaryUser;
protected int mResultCode = 0;
private Intent mResultData;
@@ -112,7 +111,6 @@
}
super.onCreate(savedInstanceState);
registerReceiver(finishReceiver, new IntentFilter(ACTION_SETUP_COMPLETE));
- mIsPrimaryUser = UserHandle.myUserId() == 0;
initLayout();
mNavigationBar = getNavigationBar();
if (mNavigationBar != null) {
@@ -520,10 +518,6 @@
return mIsFirstRun;
}
- protected boolean isPrimaryUser() {
- return mIsPrimaryUser;
- }
-
public boolean hasMultipleUsers() {
return ((UserManager) getSystemService(USER_SERVICE)).getUsers().size() > 1;
}
diff --git a/src/org/lineageos/setupwizard/SetupWizardActivity.java b/src/org/lineageos/setupwizard/SetupWizardActivity.java
index 876b63d..dfb5e19 100644
--- a/src/org/lineageos/setupwizard/SetupWizardActivity.java
+++ b/src/org/lineageos/setupwizard/SetupWizardActivity.java
@@ -26,7 +26,6 @@
import android.annotation.Nullable;
import android.content.Intent;
import android.os.Bundle;
-import android.os.UserManager;
import android.util.Log;
import com.google.android.setupcompat.util.WizardManagerHelper;
@@ -53,9 +52,9 @@
onSetupStart();
SetupWizardUtils.enableComponent(this, WizardManager.class);
Intent intent = new Intent(ACTION_LOAD);
- if (isPrimaryUser()) {
+ if (SetupWizardUtils.isOwner()) {
intent.putExtra(EXTRA_SCRIPT_URI, getString(R.string.lineage_wizard_script_uri));
- } else if (getSystemService(UserManager.class).isManagedProfile()) {
+ } else if (SetupWizardUtils.isManagedProfile(this)) {
intent.putExtra(EXTRA_SCRIPT_URI, getString(
R.string.lineage_wizard_script_managed_profile_uri));
} else {
diff --git a/src/org/lineageos/setupwizard/SetupWizardExitActivity.java b/src/org/lineageos/setupwizard/SetupWizardExitActivity.java
index 89ddabe..e130535 100644
--- a/src/org/lineageos/setupwizard/SetupWizardExitActivity.java
+++ b/src/org/lineageos/setupwizard/SetupWizardExitActivity.java
@@ -24,7 +24,6 @@
import android.annotation.Nullable;
import android.content.Intent;
import android.os.Bundle;
-import android.os.UserManager;
import android.util.Log;
import org.lineageos.setupwizard.util.PhoneMonitor;
@@ -44,7 +43,7 @@
SetupWizardUtils.enableCaptivePortalDetection(this);
}
PhoneMonitor.onSetupFinished();
- if (!getSystemService(UserManager.class).isManagedProfile()) {
+ if (!SetupWizardUtils.isManagedProfile(this)) {
launchHome();
}
finish();
diff --git a/src/org/lineageos/setupwizard/util/SetupWizardUtils.java b/src/org/lineageos/setupwizard/util/SetupWizardUtils.java
index 4836984..19120ec 100644
--- a/src/org/lineageos/setupwizard/util/SetupWizardUtils.java
+++ b/src/org/lineageos/setupwizard/util/SetupWizardUtils.java
@@ -46,6 +46,7 @@
import android.os.Binder;
import android.os.SystemProperties;
import android.os.UserHandle;
+import android.os.UserManager;
import android.provider.Settings;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
@@ -143,6 +144,10 @@
return UserHandle.myUserId() == 0;
}
+ public static boolean isManagedProfile(Context context) {
+ return context.getSystemService(UserManager.class).isManagedProfile();
+ }
+
public static void disableCaptivePortalDetection(Context context) {
Settings.Global.putInt(context.getContentResolver(), KEY_DETECT_CAPTIVE_PORTAL, 0);
}