@@ -138,68 +138,61 @@ int initializationChecker(Context context, String oneSignalAppId) {
138
138
return subscribableStatus ;
139
139
}
140
140
141
- // Interim method that prevents proguard from making a wrong assumption that NoClassDefFoundError
142
- // catches are not needed when rules include "-assumenosideeffects" with getName().
143
- // -assumenosideeffects public final class java.lang.Class {
144
- // public java.lang.String getName();
145
- // }
146
- // Using Class instead of String as class renames would result incorrectly not finding the class
147
- // Using class.getName() as if no method is called then the try-catch would be removed.
148
- // This @Keep annotation is also key so this method does not get inlined
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
149
148
@ Keep
150
- private static boolean hasClass (Class <?> clazz ) {
151
- try {
152
- clazz .getName ();
153
- return true ;
154
- } catch (NoClassDefFoundError e ) {
155
- return false ;
156
- }
149
+ private static boolean opaqueHasClass (Class <?> _class ) {
150
+ return true ;
157
151
}
158
152
159
153
static boolean hasFCMLibrary () {
160
154
try {
161
- return hasClass (com .google .firebase .messaging .FirebaseMessaging .class );
155
+ return opaqueHasClass (com .google .firebase .messaging .FirebaseMessaging .class );
162
156
} catch (NoClassDefFoundError e ) {
163
157
return false ;
164
158
}
165
159
}
166
160
167
- @ Keep
168
161
static boolean hasGMSLocationLibrary () {
169
162
try {
170
- return hasClass (com .google .android .gms .location .LocationListener .class );
163
+ return opaqueHasClass (com .google .android .gms .location .LocationListener .class );
171
164
} catch (NoClassDefFoundError e ) {
172
165
return false ;
173
166
}
174
167
}
175
168
176
169
private static boolean hasHMSAvailabilityLibrary () {
177
170
try {
178
- return hasClass (com .huawei .hms .api .HuaweiApiAvailability .class );
171
+ return opaqueHasClass (com .huawei .hms .api .HuaweiApiAvailability .class );
179
172
} catch (NoClassDefFoundError e ) {
180
173
return false ;
181
174
}
182
175
}
183
176
184
177
private static boolean hasHMSPushKitLibrary () {
185
178
try {
186
- return hasClass (com .huawei .hms .aaid .HmsInstanceId .class );
179
+ return opaqueHasClass (com .huawei .hms .aaid .HmsInstanceId .class );
187
180
} catch (NoClassDefFoundError e ) {
188
181
return false ;
189
182
}
190
183
}
191
184
192
185
private static boolean hasHMSAGConnectLibrary () {
193
186
try {
194
- return hasClass (com .huawei .agconnect .config .AGConnectServicesConfig .class );
187
+ return opaqueHasClass (com .huawei .agconnect .config .AGConnectServicesConfig .class );
195
188
} catch (NoClassDefFoundError e ) {
196
189
return false ;
197
190
}
198
191
}
199
192
200
193
static boolean hasHMSLocationLibrary () {
201
194
try {
202
- return hasClass (com .huawei .hms .location .LocationCallback .class );
195
+ return opaqueHasClass (com .huawei .hms .location .LocationCallback .class );
203
196
} catch (NoClassDefFoundError e ) {
204
197
return false ;
205
198
}
@@ -664,4 +657,4 @@ static boolean shouldLogMissingAppIdError(@Nullable String appId) {
664
657
static int getRandomDelay (int minDelay , int maxDelay ) {
665
658
return new Random ().nextInt (maxDelay + 1 - minDelay ) + minDelay ;
666
659
}
667
- }
660
+ }
0 commit comments