2424
2525import android .app .Activity ;
2626import android .content .Context ;
27- import android .content .Intent ;
28- import android .content .pm .ResolveInfo ;
29- import android .os .Build ;
3027
3128import androidx .annotation .Nullable ;
3229import androidx .fragment .app .Fragment ;
3936import com .microsoft .identity .common .internal .providers .oauth2 .AndroidTaskStateGenerator ;
4037import com .microsoft .identity .common .internal .ui .AndroidAuthorizationStrategyFactory ;
4138import com .microsoft .identity .common .internal .ui .browser .AndroidBrowserSelector ;
39+ import com .microsoft .identity .common .internal .util .WorkProfileUtil ;
4240import com .microsoft .identity .common .java .WarningType ;
4341import com .microsoft .identity .common .java .interfaces .IPlatformComponents ;
4442import com .microsoft .identity .common .java .interfaces .PlatformComponents ;
4745import com .microsoft .identity .common .logging .Logger ;
4846
4947import java .io .File ;
50- import java .util .List ;
5148
5249import lombok .NonNull ;
5350
@@ -73,7 +70,8 @@ public static synchronized void initializeGlobalStates(@NonNull final Context co
7370 Device .setDeviceMetadata (new AndroidDeviceMetadata ());
7471
7572 // Denotes whether or not request is from personal profile but device has a Work Profile Available
76- Device .setIsInPersonalProfileButClouddpcWorkProfileAvailable (checkIfIsInPersonalProfileButClouddpcWorkProfileAvailable (context ));
73+ Device .setIsInPersonalProfileButClouddpcWorkProfileAvailable (
74+ WorkProfileUtil .checkIfIsInPersonalProfileButClouddpcWorkProfileAvailable (context ));
7775 Logger .setAndroidLogger ();
7876
7977 final File cacheDir = context .getCacheDir ();
@@ -149,36 +147,4 @@ public static void fillBuilderWithBasicImplementations(
149147 .stateGenerator (new AndroidTaskStateGenerator (activity .getTaskId ()));
150148 }
151149 }
152-
153- /**
154- * Helper method to check if we are in personal profile but a work profile managed by clouddpc
155- * is available. Google Docs for intent used:
156- * https://developers.google.com/android/management/work-profile-detection#detect_if_the_device_has_a_work_profile
157- * @param context context needed to check for intent
158- * @return true if called in personal profile and a work profile managed by clouddpc exists, false otherwise
159- */
160- public static boolean checkIfIsInPersonalProfileButClouddpcWorkProfileAvailable (@ NonNull final Context context ) {
161- try {
162- Intent intent = new Intent ("com.google.android.apps.work.clouddpc.ACTION_DETECT_WORK_PROFILE" );
163- List <ResolveInfo > activities = context .getPackageManager ().queryIntentActivities (intent , 0 );
164-
165- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
166- return activities .stream ()
167- .anyMatch (
168- (ResolveInfo resolveInfo ) -> resolveInfo .isCrossProfileIntentForwarderActivity ());
169- } else {
170- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
171- return activities .stream ()
172- .anyMatch (
173- (ResolveInfo resolveInfo ) -> resolveInfo .activityInfo .name .equals ("com.android.internal.app.ForwardIntentToManagedProfile" ));
174- }
175- }
176-
177- return false ;
178- } catch (Exception e ) {
179- // If we run into exception for any reason, we'll just return false
180- Logger .warn (TAG , "Received an exception while trying to check if clouddpc work profile is available: " + e .getMessage ());
181- return false ;
182- }
183- }
184150}
0 commit comments