42
42
import android .os .Bundle ;
43
43
import android .os .Handler ;
44
44
import android .os .Looper ;
45
+
46
+ import androidx .annotation .Keep ;
45
47
import androidx .annotation .NonNull ;
46
48
import androidx .annotation .Nullable ;
47
49
import androidx .core .app .NotificationManagerCompat ;
@@ -136,59 +138,61 @@ int initializationChecker(Context context, String oneSignalAppId) {
136
138
return subscribableStatus ;
137
139
}
138
140
139
- // The the following is done to ensure Proguard compatibility with class existent detection
140
- // 1. Using Class instead of Strings as class renames would result incorrectly not finding the class
141
- // 2. class.getName() is called as if no method is called then the try-catch would be removed.
142
- // - Only an issue when using Proguard (NOT R8) and using getDefaultProguardFile('proguard-android-optimize.txt')
141
+ // Interim method that works around Proguard's overly aggressive assumenosideeffects which
142
+ // ignores keep rules.
143
+ // This is specifically designed to address Proguard removing catches for NoClassDefFoundError
144
+ // when the config has "-assumenosideeffects" with
145
+ // java.lang.Class.getName() & java.lang.Object.getClass().
146
+ // This @Keep annotation is key so this method does not get removed / inlined.
147
+ // Addresses issue https://github.com/OneSignal/OneSignal-Android-SDK/issues/1423
148
+ @ Keep
149
+ private static boolean opaqueHasClass (Class <?> _class ) {
150
+ return true ;
151
+ }
152
+
143
153
static boolean hasFCMLibrary () {
144
154
try {
145
- com .google .firebase .messaging .FirebaseMessaging .class .getName ();
146
- return true ;
155
+ return opaqueHasClass (com .google .firebase .messaging .FirebaseMessaging .class );
147
156
} catch (NoClassDefFoundError e ) {
148
157
return false ;
149
158
}
150
159
}
151
160
152
161
static boolean hasGMSLocationLibrary () {
153
162
try {
154
- com .google .android .gms .location .LocationListener .class .getName ();
155
- return true ;
163
+ return opaqueHasClass (com .google .android .gms .location .LocationListener .class );
156
164
} catch (NoClassDefFoundError e ) {
157
165
return false ;
158
166
}
159
167
}
160
168
161
169
private static boolean hasHMSAvailabilityLibrary () {
162
170
try {
163
- com .huawei .hms .api .HuaweiApiAvailability .class .getName ();
164
- return true ;
171
+ return opaqueHasClass (com .huawei .hms .api .HuaweiApiAvailability .class );
165
172
} catch (NoClassDefFoundError e ) {
166
173
return false ;
167
174
}
168
175
}
169
176
170
177
private static boolean hasHMSPushKitLibrary () {
171
178
try {
172
- com .huawei .hms .aaid .HmsInstanceId .class .getName ();
173
- return true ;
179
+ return opaqueHasClass (com .huawei .hms .aaid .HmsInstanceId .class );
174
180
} catch (NoClassDefFoundError e ) {
175
181
return false ;
176
182
}
177
183
}
178
184
179
185
private static boolean hasHMSAGConnectLibrary () {
180
186
try {
181
- com .huawei .agconnect .config .AGConnectServicesConfig .class .getName ();
182
- return true ;
187
+ return opaqueHasClass (com .huawei .agconnect .config .AGConnectServicesConfig .class );
183
188
} catch (NoClassDefFoundError e ) {
184
189
return false ;
185
190
}
186
191
}
187
192
188
193
static boolean hasHMSLocationLibrary () {
189
194
try {
190
- com .huawei .hms .location .LocationCallback .class .getName ();
191
- return true ;
195
+ return opaqueHasClass (com .huawei .hms .location .LocationCallback .class );
192
196
} catch (NoClassDefFoundError e ) {
193
197
return false ;
194
198
}
@@ -653,4 +657,4 @@ static boolean shouldLogMissingAppIdError(@Nullable String appId) {
653
657
static int getRandomDelay (int minDelay , int maxDelay ) {
654
658
return new Random ().nextInt (maxDelay + 1 - minDelay ) + minDelay ;
655
659
}
656
- }
660
+ }
0 commit comments