Skip to content

Commit da74b61

Browse files
committed
have a util class
1 parent 6c9075f commit da74b61

4 files changed

Lines changed: 51 additions & 42 deletions

File tree

common/src/main/java/com/microsoft/identity/common/components/AndroidPlatformComponentsFactory.java

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424

2525
import android.app.Activity;
2626
import android.content.Context;
27-
import android.content.Intent;
28-
import android.content.pm.ResolveInfo;
29-
import android.os.Build;
3027

3128
import androidx.annotation.Nullable;
3229
import androidx.fragment.app.Fragment;
@@ -39,6 +36,7 @@
3936
import com.microsoft.identity.common.internal.providers.oauth2.AndroidTaskStateGenerator;
4037
import com.microsoft.identity.common.internal.ui.AndroidAuthorizationStrategyFactory;
4138
import com.microsoft.identity.common.internal.ui.browser.AndroidBrowserSelector;
39+
import com.microsoft.identity.common.internal.util.WorkProfileUtil;
4240
import com.microsoft.identity.common.java.WarningType;
4341
import com.microsoft.identity.common.java.interfaces.IPlatformComponents;
4442
import com.microsoft.identity.common.java.interfaces.PlatformComponents;
@@ -47,7 +45,6 @@
4745
import com.microsoft.identity.common.logging.Logger;
4846

4947
import java.io.File;
50-
import java.util.List;
5148

5249
import 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
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.microsoft.identity.common.internal.util;
2+
3+
import android.content.Context;
4+
import android.content.Intent;
5+
import android.content.pm.ResolveInfo;
6+
import android.os.Build;
7+
8+
import com.microsoft.identity.common.logging.Logger;
9+
10+
import java.util.List;
11+
12+
import lombok.NonNull;
13+
14+
public class WorkProfileUtil {
15+
private static final String TAG = WorkProfileUtil.class.getSimpleName();
16+
17+
/**
18+
* Helper method to check if we are in personal profile but a work profile managed by clouddpc
19+
* is available.
20+
* <a href="https://developers.google.com/android/management/work-profile-detection#detect_if_the_device_has_a_work_profile">Google Docs for intent used</a>
21+
* @param context context needed to check for intent
22+
* @return true if called in personal profile and a work profile managed by clouddpc exists, false otherwise
23+
*/
24+
public static boolean checkIfIsInPersonalProfileButClouddpcWorkProfileAvailable(@NonNull final Context context) {
25+
try {
26+
Intent intent = new Intent("com.google.android.apps.work.clouddpc.ACTION_DETECT_WORK_PROFILE");
27+
List<ResolveInfo> activities = context.getPackageManager().queryIntentActivities(intent, 0);
28+
29+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
30+
return activities.stream()
31+
.anyMatch(
32+
(ResolveInfo resolveInfo) -> resolveInfo.isCrossProfileIntentForwarderActivity());
33+
} else {
34+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
35+
return activities.stream()
36+
.anyMatch(
37+
(ResolveInfo resolveInfo) -> resolveInfo.activityInfo.name.equals("com.android.internal.app.ForwardIntentToManagedProfile"));
38+
}
39+
}
40+
41+
return false;
42+
} catch (Exception e) {
43+
// If we run into exception for any reason, we'll just return false
44+
Logger.warn(TAG, "Received an exception while trying to check if clouddpc work profile is available: " + e.getMessage());
45+
return false;
46+
}
47+
}
48+
}

common4j/src/main/com/microsoft/identity/common/java/controllers/BaseController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ protected final AuthorizationRequest.Builder initializeAuthorizationRequestBuild
330330
parameters.getApplicationVersion()
331331
);
332332
completeRequestHeaders.put(PKEYAUTH_HEADER, PKEYAUTH_VERSION);
333-
completeRequestHeaders.put("TOmatoToe", "Ketchup");
334333

335334
// Add additional fields to the AuthorizationRequest.Builder to support interactive
336335
setBuilderProperties(builder, parameters, interactiveTokenCommandParameters, completeRequestHeaders);

common4j/src/main/com/microsoft/identity/common/java/providers/oauth2/AuthorizationRequest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ public abstract class AuthorizationRequest<T extends AuthorizationRequest<T>> im
9292
@SerializedName("brk_client_id")
9393
private final String mBrkClientId;
9494

95-
@Expose()
96-
@SerializedName("temp-param")
97-
private final String mTempParam = "Temporary";
98-
9995
/**
10096
* Redirect URL of the hub app.
10197
*/

0 commit comments

Comments
 (0)