Skip to content

Commit eb36ada

Browse files
authored
Remove stale code, eliminate flickers due to BrokerAuthorizationActivity, Fixes AB#3627062 (#3139)
[AB#3627062](https://identitydivision.visualstudio.com/fac9d424-53d2-45c0-91b5-ef6ba7a6bf26/_workitems/edit/3627062) - getDeviceIdleMode and getPowerOptimizationSettings are no longer used (redundancy with other methods), removing. - Remove ENABLE_HANDLING_FOR_EDGE_TO_EDGE since we've had it enabled for a while already. - Today, in broker, when BrokerAuthorizationActivity (webview wrapper) is invoked, you'll see transition animations (which looks like "flicker" in broker flows where we might call acquiretoken multiple time. Removing the animation so it no longer looks weird.
1 parent 8f6e570 commit eb36ada

7 files changed

Lines changed: 74 additions & 81 deletions

File tree

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
vNext
22
----------
3+
- [PATCH] Remove stale code, eliminate flickers due to BrokerAuthorizationActivity (#3139)
34

45
Version 24.3.0
56
----------

common/src/main/java/com/microsoft/identity/common/adal/internal/PowerManagerWrapper.java

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ public class PowerManagerWrapper {
4646

4747
private static PowerManagerWrapper sInstance;
4848

49-
private static final String UNKNOWN_STATUS = "Unknown";
50-
5149
// In-memory cache for battery optimization status for each apps.
5250
private final Map<String, BatteryOptimizationStatus> batteryOptOutCache = new ConcurrentHashMap<>();
5351
/**
@@ -82,35 +80,6 @@ public boolean isDeviceIdleMode(final Context connectionContext) {
8280
return ((PowerManager) connectionContext.getSystemService(Context.POWER_SERVICE)).isDeviceIdleMode();
8381
}
8482

85-
/**
86-
* Gets a string representing Device Idle status.
87-
* Will return an empty string if the device is not in any idle mode.
88-
* (Possible Values: "Idle", "LightIdle", "Unknown" , "")
89-
*/
90-
@NonNull
91-
public String getDeviceIdleMode(@NonNull final Context context){
92-
try {
93-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
94-
return UNKNOWN_STATUS;
95-
}
96-
97-
final PowerManager powerManager = ((PowerManager) context.getSystemService(Context.POWER_SERVICE));
98-
if (powerManager.isDeviceIdleMode()) {
99-
return "Idle";
100-
}
101-
102-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
103-
powerManager.isDeviceLightIdleMode()) {
104-
return "LightIdle";
105-
}
106-
} catch (final Exception e){
107-
// Swallow all exception!
108-
return UNKNOWN_STATUS;
109-
}
110-
111-
return "";
112-
}
113-
11483
/**
11584
* Gets the Device Doze Mode Status.
11685
*
@@ -145,27 +114,6 @@ public DeviceDozeModeStatus getDeviceDozeModeStatus(@NonNull final Context conte
145114
}
146115
}
147116

148-
/**
149-
* Gets a string representing Power Optimization settings of the calling app
150-
* Will return an empty string if the app isn't opting out.
151-
* (Possible Values: "OptOut", "Unknown" , "")
152-
*/
153-
@NonNull
154-
public String getPowerOptimizationSettings(@NonNull final Context context){
155-
try {
156-
final PowerManager powerManager = ((PowerManager) context.getSystemService(Context.POWER_SERVICE));
157-
if (powerManager.isIgnoringBatteryOptimizations(context.getPackageName())){
158-
return "OptOut";
159-
} else {
160-
return "";
161-
}
162-
163-
} catch (final Exception e){
164-
// Swallow all exception!
165-
return UNKNOWN_STATUS;
166-
}
167-
}
168-
169117
/**
170118
* Wrap the calling to method isIgnoringBatteryOptimizations() of final class PowerManager.
171119
*

common/src/main/java/com/microsoft/identity/common/internal/providers/oauth2/BrokerAuthorizationActivity.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,21 @@
2222
// THE SOFTWARE.
2323
package com.microsoft.identity.common.internal.providers.oauth2;
2424

25+
import com.microsoft.identity.common.R;
26+
2527
/**
2628
* Declares as a separate class so that we can specify attributes exclusively to :auth process
27-
* in AndroidManifest without overriding MSAL's (In case where MSAL and broker is shipped together).
29+
* in AndroidManifest without overriding MSAL's (in case where MSAL and broker are shipped together).
30+
*
31+
* <p>Transition animations are suppressed via {@code BrokerAuthorizationActivityTheme} pinned in
32+
* the broker's manifest. {@link #getThemeResId()} returns the DualScreen variant so the theme
33+
* swap inside {@link com.microsoft.identity.common.internal.ui.DualScreenActivity#onCreate}
34+
* preserves that suppression.
2835
*/
2936
public class BrokerAuthorizationActivity extends AuthorizationActivity {
37+
38+
@Override
39+
protected int getThemeResId() {
40+
return R.style.DualScreenBrokerAuthorizationActivityTheme;
41+
}
3042
}

common/src/main/java/com/microsoft/identity/common/internal/ui/DualScreenActivity.java

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@
4949

5050
import com.microsoft.device.display.DisplayMask;
5151
import com.microsoft.identity.common.R;
52-
import com.microsoft.identity.common.java.flighting.CommonFlight;
53-
import com.microsoft.identity.common.java.flighting.CommonFlightsManager;
5452
import com.microsoft.identity.common.logging.Logger;
5553

5654
import java.util.List;
@@ -62,14 +60,12 @@ public class DualScreenActivity extends FragmentActivity {
6260
protected void onCreate(@Nullable Bundle savedInstanceState) {
6361
super.onCreate(savedInstanceState);
6462

65-
if (CommonFlightsManager.INSTANCE.getFlightsProvider().isFlightEnabled(CommonFlight.ENABLE_HANDLING_FOR_EDGE_TO_EDGE)) {
66-
// Force set to a light theme (to status and navigation bars) since broker/common activities always have white background.
67-
// We don't support dark mode in broker/common activities yet.
68-
// Until then, having everything consistently rendered with a white background looks better.
69-
// This will also guarantee that the icons on those bars are always visible.
70-
setTheme(getThemeResId());
71-
setEdgeToEdge();
72-
}
63+
// Force set to a light theme (to status and navigation bars) since broker/common activities always have white background.
64+
// We don't support dark mode in broker/common activities yet.
65+
// Until then, having everything consistently rendered with a white background looks better.
66+
// This will also guarantee that the icons on those bars are always visible.
67+
setTheme(getThemeResId());
68+
setEdgeToEdge();
7369
}
7470

7571
@Override
@@ -82,19 +78,17 @@ public void setContentView(int layoutResID) {
8278

8379
private void initializeContentView(){
8480
super.setContentView(R.layout.dual_screen_layout);
85-
if (CommonFlightsManager.INSTANCE.getFlightsProvider().isFlightEnabled(CommonFlight.ENABLE_HANDLING_FOR_EDGE_TO_EDGE)) {
86-
try {
87-
ViewCompat.setOnApplyWindowInsetsListener(findViewById(android.R.id.content), (view, insets) -> {
88-
// Set the padding of the view to the insets of system bars, display cutout, and Input (keyboards).
89-
final Insets inset = insets.getInsets(WindowInsetsCompat.Type.systemBars()
90-
| WindowInsetsCompat.Type.displayCutout()
91-
| WindowInsetsCompat.Type.ime());
92-
view.setPadding(inset.left, inset.top, inset.right, inset.bottom);
93-
return WindowInsetsCompat.CONSUMED;
94-
});
95-
} catch (final Throwable throwable) {
96-
Logger.warn("DualScreenActivity:initializeContentView", "Failed to set OnApplyWindowInsetsListener");
97-
}
81+
try {
82+
ViewCompat.setOnApplyWindowInsetsListener(findViewById(android.R.id.content), (view, insets) -> {
83+
// Set the padding of the view to the insets of system bars, display cutout, and Input (keyboards).
84+
final Insets inset = insets.getInsets(WindowInsetsCompat.Type.systemBars()
85+
| WindowInsetsCompat.Type.displayCutout()
86+
| WindowInsetsCompat.Type.ime());
87+
view.setPadding(inset.left, inset.top, inset.right, inset.bottom);
88+
return WindowInsetsCompat.CONSUMED;
89+
});
90+
} catch (final Throwable throwable) {
91+
Logger.warn("DualScreenActivity:initializeContentView", "Failed to set OnApplyWindowInsetsListener");
9892
}
9993

10094
adjustLayoutForDualScreenActivity();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright (c) Microsoft Corporation. Licensed under the MIT License.
4+
5+
Empty animation set used by BrokerNoWindowAnimation. We point every animation slot
6+
at an explicit empty set rather than @null because several OEMs treat @null as
7+
"fall back to platform default" (i.e. the slide), defeating the suppression.
8+
-->
9+
<set xmlns:android="http://schemas.android.com/apk/res/android" />

common/src/main/res/values/styles.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,38 @@
6262
<style name="DualScreenActivityTheme" parent="Theme.AppCompat.Light">
6363
<item name="android:windowBackground">@color/com_microsoft_identity_common_white</item>
6464
</style>
65+
66+
<!--
67+
Window animation style that suppresses every activity / task / window animation slot
68+
by pointing it at an empty @anim/broker_no_animation set. WindowManager reads this
69+
from the activity's theme in system_server, so it applies across the :auth process
70+
boundary and the predictive-back gesture in a way overridePendingTransition cannot.
71+
-->
72+
<style name="BrokerNoWindowAnimation">
73+
<item name="android:activityOpenEnterAnimation">@anim/broker_no_animation</item>
74+
<item name="android:activityOpenExitAnimation">@anim/broker_no_animation</item>
75+
<item name="android:activityCloseEnterAnimation">@anim/broker_no_animation</item>
76+
<item name="android:activityCloseExitAnimation">@anim/broker_no_animation</item>
77+
<item name="android:taskOpenEnterAnimation">@anim/broker_no_animation</item>
78+
<item name="android:taskOpenExitAnimation">@anim/broker_no_animation</item>
79+
<item name="android:taskCloseEnterAnimation">@anim/broker_no_animation</item>
80+
<item name="android:taskCloseExitAnimation">@anim/broker_no_animation</item>
81+
<item name="android:taskToFrontEnterAnimation">@anim/broker_no_animation</item>
82+
<item name="android:taskToFrontExitAnimation">@anim/broker_no_animation</item>
83+
<item name="android:taskToBackEnterAnimation">@anim/broker_no_animation</item>
84+
<item name="android:taskToBackExitAnimation">@anim/broker_no_animation</item>
85+
<item name="android:windowEnterAnimation">@anim/broker_no_animation</item>
86+
<item name="android:windowExitAnimation">@anim/broker_no_animation</item>
87+
</style>
88+
89+
<!--
90+
Variant of DualScreenActivityTheme that suppresses activity transitions for
91+
BrokerAuthorizationActivity. See BrokerAuthorizationActivity#getThemeResId().
92+
-->
93+
<style name="DualScreenBrokerAuthorizationActivityTheme" parent="DualScreenActivityTheme">
94+
<item name="android:windowBackground">@color/com_microsoft_identity_common_white</item>
95+
<item name="android:windowActionBar">false</item>
96+
<item name="android:windowNoTitle">true</item>
97+
<item name="android:windowAnimationStyle">@style/BrokerNoWindowAnimation</item>
98+
</style>
6599
</resources>

common4j/src/main/com/microsoft/identity/common/java/flighting/CommonFlight.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@ public enum CommonFlight implements IFlightConfig {
135135
*/
136136
WRAPPED_SECRET_KEY_SERIALIZER_VERSION("WrappedSecretKeySerializerVersion", 0),
137137

138-
/**
139-
* Flight to enable handling the UI in edge to edge mode
140-
*/
141-
ENABLE_HANDLING_FOR_EDGE_TO_EDGE("EnableHandlingEdgeToEdge", true),
142-
143138
/**
144139
* Flight to enable the Web CP in WebView.
145140
*/

0 commit comments

Comments
 (0)