|
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,68 @@ 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') |
143 |
| - static boolean hasFCMLibrary() { |
| 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 |
| 149 | + @Keep |
| 150 | + private static boolean hasClass(Class<?> clazz) { |
144 | 151 | try {
|
145 |
| - com.google.firebase.messaging.FirebaseMessaging.class.getName(); |
| 152 | + clazz.getName(); |
146 | 153 | return true;
|
147 | 154 | } catch (NoClassDefFoundError e) {
|
148 | 155 | return false;
|
149 | 156 | }
|
150 | 157 | }
|
151 | 158 |
|
| 159 | + static boolean hasFCMLibrary() { |
| 160 | + try { |
| 161 | + return hasClass(com.google.firebase.messaging.FirebaseMessaging.class); |
| 162 | + } catch (NoClassDefFoundError e) { |
| 163 | + return false; |
| 164 | + } |
| 165 | + } |
| 166 | + |
| 167 | + @Keep |
152 | 168 | static boolean hasGMSLocationLibrary() {
|
153 | 169 | try {
|
154 |
| - com.google.android.gms.location.LocationListener.class.getName(); |
155 |
| - return true; |
| 170 | + return hasClass(com.google.android.gms.location.LocationListener.class); |
156 | 171 | } catch (NoClassDefFoundError e) {
|
157 | 172 | return false;
|
158 | 173 | }
|
159 | 174 | }
|
160 | 175 |
|
161 | 176 | private static boolean hasHMSAvailabilityLibrary() {
|
162 | 177 | try {
|
163 |
| - com.huawei.hms.api.HuaweiApiAvailability.class.getName(); |
164 |
| - return true; |
| 178 | + return hasClass(com.huawei.hms.api.HuaweiApiAvailability.class); |
165 | 179 | } catch (NoClassDefFoundError e) {
|
166 | 180 | return false;
|
167 | 181 | }
|
168 | 182 | }
|
169 | 183 |
|
170 | 184 | private static boolean hasHMSPushKitLibrary() {
|
171 | 185 | try {
|
172 |
| - com.huawei.hms.aaid.HmsInstanceId.class.getName(); |
173 |
| - return true; |
| 186 | + return hasClass(com.huawei.hms.aaid.HmsInstanceId.class); |
174 | 187 | } catch (NoClassDefFoundError e) {
|
175 | 188 | return false;
|
176 | 189 | }
|
177 | 190 | }
|
178 | 191 |
|
179 | 192 | private static boolean hasHMSAGConnectLibrary() {
|
180 | 193 | try {
|
181 |
| - com.huawei.agconnect.config.AGConnectServicesConfig.class.getName(); |
182 |
| - return true; |
| 194 | + return hasClass(com.huawei.agconnect.config.AGConnectServicesConfig.class); |
183 | 195 | } catch (NoClassDefFoundError e) {
|
184 | 196 | return false;
|
185 | 197 | }
|
186 | 198 | }
|
187 | 199 |
|
188 | 200 | static boolean hasHMSLocationLibrary() {
|
189 | 201 | try {
|
190 |
| - com.huawei.hms.location.LocationCallback.class.getName(); |
191 |
| - return true; |
| 202 | + return hasClass(com.huawei.hms.location.LocationCallback.class); |
192 | 203 | } catch (NoClassDefFoundError e) {
|
193 | 204 | return false;
|
194 | 205 | }
|
|
0 commit comments