36
36
import java .util .concurrent .Executor ;
37
37
import java .util .concurrent .Executors ;
38
38
39
- class CheckForUpdateClient {
40
- private static final int UPDATE_THREAD_POOL_SIZE = 4 ;
41
- private static final String TAG = "CheckForUpdateClient :" ;
39
+ class CheckForNewReleaseClient {
40
+ private static final int NEW_RELEASE_THREAD_POOL_SIZE = 4 ;
41
+ private static final String TAG = "CheckForNewReleaseClient :" ;
42
42
43
43
private final FirebaseApp firebaseApp ;
44
44
private final FirebaseAppDistributionTesterApiClient firebaseAppDistributionTesterApiClient ;
45
45
private final FirebaseInstallationsApi firebaseInstallationsApi ;
46
46
private static final ConcurrentMap <String , String > cachedCodeHashes = new ConcurrentHashMap <>();
47
47
private final ReleaseIdentifierStorage releaseIdentifierStorage ;
48
48
49
- Task <AppDistributionReleaseInternal > cachedCheckForUpdate = null ;
50
- private final Executor checkForUpdateExecutor ;
49
+ Task <AppDistributionReleaseInternal > cachedCheckForNewRelease = null ;
50
+ private final Executor checkForNewReleaseExecutor ;
51
51
52
- CheckForUpdateClient (
52
+ CheckForNewReleaseClient (
53
53
@ NonNull FirebaseApp firebaseApp ,
54
54
@ NonNull FirebaseAppDistributionTesterApiClient firebaseAppDistributionTesterApiClient ,
55
55
@ NonNull FirebaseInstallationsApi firebaseInstallationsApi ) {
56
56
this .firebaseApp = firebaseApp ;
57
57
this .firebaseAppDistributionTesterApiClient = firebaseAppDistributionTesterApiClient ;
58
58
this .firebaseInstallationsApi = firebaseInstallationsApi ;
59
59
// TODO: verify if this is best way to use executorservice here
60
- this .checkForUpdateExecutor = Executors .newFixedThreadPool (UPDATE_THREAD_POOL_SIZE );
60
+ this .checkForNewReleaseExecutor = Executors .newFixedThreadPool (NEW_RELEASE_THREAD_POOL_SIZE );
61
61
this .releaseIdentifierStorage =
62
62
new ReleaseIdentifierStorage (firebaseApp .getApplicationContext ());
63
63
}
64
64
65
- CheckForUpdateClient (
65
+ CheckForNewReleaseClient (
66
66
@ NonNull FirebaseApp firebaseApp ,
67
67
@ NonNull FirebaseAppDistributionTesterApiClient firebaseAppDistributionTesterApiClient ,
68
68
@ NonNull FirebaseInstallationsApi firebaseInstallationsApi ,
@@ -71,67 +71,66 @@ class CheckForUpdateClient {
71
71
this .firebaseAppDistributionTesterApiClient = firebaseAppDistributionTesterApiClient ;
72
72
this .firebaseInstallationsApi = firebaseInstallationsApi ;
73
73
// TODO: verify if this is best way to use executorservice here
74
- this .checkForUpdateExecutor = executor ;
74
+ this .checkForNewReleaseExecutor = executor ;
75
75
this .releaseIdentifierStorage =
76
76
new ReleaseIdentifierStorage (firebaseApp .getApplicationContext ());
77
77
}
78
78
79
79
@ NonNull
80
- public synchronized Task <AppDistributionReleaseInternal > checkForUpdate () {
80
+ public synchronized Task <AppDistributionReleaseInternal > checkForNewRelease () {
81
81
82
- if (cachedCheckForUpdate != null && !cachedCheckForUpdate .isComplete ()) {
83
- return cachedCheckForUpdate ;
82
+ if (cachedCheckForNewRelease != null && !cachedCheckForNewRelease .isComplete ()) {
83
+ return cachedCheckForNewRelease ;
84
84
}
85
85
86
86
Task <String > installationIdTask = firebaseInstallationsApi .getId ();
87
87
// forceRefresh is false to get locally cached token if available
88
88
Task <InstallationTokenResult > installationAuthTokenTask =
89
89
firebaseInstallationsApi .getToken (false );
90
90
91
- this .cachedCheckForUpdate =
91
+ this .cachedCheckForNewRelease =
92
92
Tasks .whenAllSuccess (installationIdTask , installationAuthTokenTask )
93
93
.onSuccessTask (
94
- checkForUpdateExecutor ,
94
+ checkForNewReleaseExecutor ,
95
95
tasks -> {
96
96
String fid = installationIdTask .getResult ();
97
97
InstallationTokenResult installationTokenResult =
98
98
installationAuthTokenTask .getResult ();
99
99
try {
100
- AppDistributionReleaseInternal latestRelease =
101
- getLatestReleaseFromClient (
100
+ AppDistributionReleaseInternal newRelease =
101
+ getNewReleaseFromClient (
102
102
fid ,
103
103
firebaseApp .getOptions ().getApplicationId (),
104
104
firebaseApp .getOptions ().getApiKey (),
105
105
installationTokenResult .getToken ());
106
- return Tasks .forResult (latestRelease );
106
+ return Tasks .forResult (newRelease );
107
107
} catch (FirebaseAppDistributionException ex ) {
108
108
return Tasks .forException (ex );
109
109
}
110
110
})
111
111
.continueWithTask (
112
- checkForUpdateExecutor ,
112
+ checkForNewReleaseExecutor ,
113
113
task ->
114
114
TaskUtils .handleTaskFailure (
115
115
task ,
116
116
Constants .ErrorMessages .NETWORK_ERROR ,
117
117
FirebaseAppDistributionException .Status .NETWORK_FAILURE ));
118
118
119
- return cachedCheckForUpdate ;
119
+ return cachedCheckForNewRelease ;
120
120
}
121
121
122
122
@ VisibleForTesting
123
- AppDistributionReleaseInternal getLatestReleaseFromClient (
123
+ AppDistributionReleaseInternal getNewReleaseFromClient (
124
124
String fid , String appId , String apiKey , String authToken )
125
125
throws FirebaseAppDistributionException {
126
126
try {
127
- AppDistributionReleaseInternal retrievedLatestRelease =
128
- firebaseAppDistributionTesterApiClient .fetchLatestRelease (fid , appId , apiKey , authToken );
127
+ AppDistributionReleaseInternal retrievedNewRelease =
128
+ firebaseAppDistributionTesterApiClient .fetchNewRelease (fid , appId , apiKey , authToken );
129
129
130
- if (isNewerBuildVersion (retrievedLatestRelease )
131
- || !isInstalledRelease (retrievedLatestRelease )) {
132
- return retrievedLatestRelease ;
130
+ if (isNewerBuildVersion (retrievedNewRelease ) || !isInstalledRelease (retrievedNewRelease )) {
131
+ return retrievedNewRelease ;
133
132
} else {
134
- // Return null if retrieved latest release is older or currently installed
133
+ // Return null if retrieved new release is older or currently installed
135
134
return null ;
136
135
}
137
136
} catch (NumberFormatException e ) {
@@ -143,23 +142,23 @@ AppDistributionReleaseInternal getLatestReleaseFromClient(
143
142
}
144
143
}
145
144
146
- private boolean isNewerBuildVersion (AppDistributionReleaseInternal latestRelease )
145
+ private boolean isNewerBuildVersion (AppDistributionReleaseInternal newRelease )
147
146
throws FirebaseAppDistributionException {
148
- return Long .parseLong (latestRelease .getBuildVersion ())
147
+ return Long .parseLong (newRelease .getBuildVersion ())
149
148
> getInstalledAppVersionCode (firebaseApp .getApplicationContext ());
150
149
}
151
150
152
151
@ VisibleForTesting
153
- boolean isInstalledRelease (AppDistributionReleaseInternal latestRelease ) {
154
- if (latestRelease .getBinaryType ().equals (BinaryType .APK )) {
155
- return hasSameCodeHashAsInstallledRelease (latestRelease );
152
+ boolean isInstalledRelease (AppDistributionReleaseInternal newRelease ) {
153
+ if (newRelease .getBinaryType ().equals (BinaryType .APK )) {
154
+ return hasSameCodeHashAsInstallledRelease (newRelease );
156
155
}
157
156
158
- if (latestRelease .getIasArtifactId () == null ) {
157
+ if (newRelease .getIasArtifactId () == null ) {
159
158
return false ;
160
159
}
161
160
// AAB BinaryType
162
- return latestRelease
161
+ return newRelease
163
162
.getIasArtifactId ()
164
163
.equals (
165
164
ReleaseIdentificationUtils .extractInternalAppSharingArtifactId (
@@ -193,7 +192,7 @@ String extractApkCodeHash(PackageInfo packageInfo) {
193
192
return releaseIdentifierStorage .getExternalCodeHash (cachedCodeHashes .get (key ));
194
193
}
195
194
196
- private boolean hasSameCodeHashAsInstallledRelease (AppDistributionReleaseInternal latestRelease ) {
195
+ private boolean hasSameCodeHashAsInstallledRelease (AppDistributionReleaseInternal newRelease ) {
197
196
try {
198
197
Context context = firebaseApp .getApplicationContext ();
199
198
PackageInfo metadataPackageInfo =
@@ -207,9 +206,9 @@ private boolean hasSameCodeHashAsInstallledRelease(AppDistributionReleaseInterna
207
206
return false ;
208
207
}
209
208
210
- // If the codeHash for the retrieved latestRelease is equal to the stored codeHash
209
+ // If the codeHash for the retrieved newRelease is equal to the stored codeHash
211
210
// of the installed release, then they are the same release.
212
- return externalCodeHash .equals (latestRelease .getCodeHash ());
211
+ return externalCodeHash .equals (newRelease .getCodeHash ());
213
212
} catch (PackageManager .NameNotFoundException e ) {
214
213
LogWrapper .getInstance ().e (TAG + "Unable to locate App." , e );
215
214
return false ;
0 commit comments