3636import java .util .concurrent .Executor ;
3737import java .util .concurrent .Executors ;
3838
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 :" ;
4242
4343 private final FirebaseApp firebaseApp ;
4444 private final FirebaseAppDistributionTesterApiClient firebaseAppDistributionTesterApiClient ;
4545 private final FirebaseInstallationsApi firebaseInstallationsApi ;
4646 private static final ConcurrentMap <String , String > cachedCodeHashes = new ConcurrentHashMap <>();
4747 private final ReleaseIdentifierStorage releaseIdentifierStorage ;
4848
49- Task <AppDistributionReleaseInternal > cachedCheckForUpdate = null ;
50- private final Executor checkForUpdateExecutor ;
49+ Task <AppDistributionReleaseInternal > cachedCheckForNewRelease = null ;
50+ private final Executor checkForNewReleaseExecutor ;
5151
52- CheckForUpdateClient (
52+ CheckForNewReleaseClient (
5353 @ NonNull FirebaseApp firebaseApp ,
5454 @ NonNull FirebaseAppDistributionTesterApiClient firebaseAppDistributionTesterApiClient ,
5555 @ NonNull FirebaseInstallationsApi firebaseInstallationsApi ) {
5656 this .firebaseApp = firebaseApp ;
5757 this .firebaseAppDistributionTesterApiClient = firebaseAppDistributionTesterApiClient ;
5858 this .firebaseInstallationsApi = firebaseInstallationsApi ;
5959 // 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 );
6161 this .releaseIdentifierStorage =
6262 new ReleaseIdentifierStorage (firebaseApp .getApplicationContext ());
6363 }
6464
65- CheckForUpdateClient (
65+ CheckForNewReleaseClient (
6666 @ NonNull FirebaseApp firebaseApp ,
6767 @ NonNull FirebaseAppDistributionTesterApiClient firebaseAppDistributionTesterApiClient ,
6868 @ NonNull FirebaseInstallationsApi firebaseInstallationsApi ,
@@ -71,67 +71,66 @@ class CheckForUpdateClient {
7171 this .firebaseAppDistributionTesterApiClient = firebaseAppDistributionTesterApiClient ;
7272 this .firebaseInstallationsApi = firebaseInstallationsApi ;
7373 // TODO: verify if this is best way to use executorservice here
74- this .checkForUpdateExecutor = executor ;
74+ this .checkForNewReleaseExecutor = executor ;
7575 this .releaseIdentifierStorage =
7676 new ReleaseIdentifierStorage (firebaseApp .getApplicationContext ());
7777 }
7878
7979 @ NonNull
80- public synchronized Task <AppDistributionReleaseInternal > checkForUpdate () {
80+ public synchronized Task <AppDistributionReleaseInternal > checkForNewRelease () {
8181
82- if (cachedCheckForUpdate != null && !cachedCheckForUpdate .isComplete ()) {
83- return cachedCheckForUpdate ;
82+ if (cachedCheckForNewRelease != null && !cachedCheckForNewRelease .isComplete ()) {
83+ return cachedCheckForNewRelease ;
8484 }
8585
8686 Task <String > installationIdTask = firebaseInstallationsApi .getId ();
8787 // forceRefresh is false to get locally cached token if available
8888 Task <InstallationTokenResult > installationAuthTokenTask =
8989 firebaseInstallationsApi .getToken (false );
9090
91- this .cachedCheckForUpdate =
91+ this .cachedCheckForNewRelease =
9292 Tasks .whenAllSuccess (installationIdTask , installationAuthTokenTask )
9393 .onSuccessTask (
94- checkForUpdateExecutor ,
94+ checkForNewReleaseExecutor ,
9595 tasks -> {
9696 String fid = installationIdTask .getResult ();
9797 InstallationTokenResult installationTokenResult =
9898 installationAuthTokenTask .getResult ();
9999 try {
100- AppDistributionReleaseInternal latestRelease =
101- getLatestReleaseFromClient (
100+ AppDistributionReleaseInternal newRelease =
101+ getNewReleaseFromClient (
102102 fid ,
103103 firebaseApp .getOptions ().getApplicationId (),
104104 firebaseApp .getOptions ().getApiKey (),
105105 installationTokenResult .getToken ());
106- return Tasks .forResult (latestRelease );
106+ return Tasks .forResult (newRelease );
107107 } catch (FirebaseAppDistributionException ex ) {
108108 return Tasks .forException (ex );
109109 }
110110 })
111111 .continueWithTask (
112- checkForUpdateExecutor ,
112+ checkForNewReleaseExecutor ,
113113 task ->
114114 TaskUtils .handleTaskFailure (
115115 task ,
116116 Constants .ErrorMessages .NETWORK_ERROR ,
117117 FirebaseAppDistributionException .Status .NETWORK_FAILURE ));
118118
119- return cachedCheckForUpdate ;
119+ return cachedCheckForNewRelease ;
120120 }
121121
122122 @ VisibleForTesting
123- AppDistributionReleaseInternal getLatestReleaseFromClient (
123+ AppDistributionReleaseInternal getNewReleaseFromClient (
124124 String fid , String appId , String apiKey , String authToken )
125125 throws FirebaseAppDistributionException {
126126 try {
127- AppDistributionReleaseInternal retrievedLatestRelease =
128- firebaseAppDistributionTesterApiClient .fetchLatestRelease (fid , appId , apiKey , authToken );
127+ AppDistributionReleaseInternal retrievedNewRelease =
128+ firebaseAppDistributionTesterApiClient .fetchNewRelease (fid , appId , apiKey , authToken );
129129
130- if (isNewerBuildVersion (retrievedLatestRelease )
131- || !isInstalledRelease (retrievedLatestRelease )) {
132- return retrievedLatestRelease ;
130+ if (isNewerBuildVersion (retrievedNewRelease ) || !isInstalledRelease (retrievedNewRelease )) {
131+ return retrievedNewRelease ;
133132 } 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
135134 return null ;
136135 }
137136 } catch (NumberFormatException e ) {
@@ -143,23 +142,23 @@ AppDistributionReleaseInternal getLatestReleaseFromClient(
143142 }
144143 }
145144
146- private boolean isNewerBuildVersion (AppDistributionReleaseInternal latestRelease )
145+ private boolean isNewerBuildVersion (AppDistributionReleaseInternal newRelease )
147146 throws FirebaseAppDistributionException {
148- return Long .parseLong (latestRelease .getBuildVersion ())
147+ return Long .parseLong (newRelease .getBuildVersion ())
149148 > getInstalledAppVersionCode (firebaseApp .getApplicationContext ());
150149 }
151150
152151 @ 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 );
156155 }
157156
158- if (latestRelease .getIasArtifactId () == null ) {
157+ if (newRelease .getIasArtifactId () == null ) {
159158 return false ;
160159 }
161160 // AAB BinaryType
162- return latestRelease
161+ return newRelease
163162 .getIasArtifactId ()
164163 .equals (
165164 ReleaseIdentificationUtils .extractInternalAppSharingArtifactId (
@@ -193,7 +192,7 @@ String extractApkCodeHash(PackageInfo packageInfo) {
193192 return releaseIdentifierStorage .getExternalCodeHash (cachedCodeHashes .get (key ));
194193 }
195194
196- private boolean hasSameCodeHashAsInstallledRelease (AppDistributionReleaseInternal latestRelease ) {
195+ private boolean hasSameCodeHashAsInstallledRelease (AppDistributionReleaseInternal newRelease ) {
197196 try {
198197 Context context = firebaseApp .getApplicationContext ();
199198 PackageInfo metadataPackageInfo =
@@ -207,9 +206,9 @@ private boolean hasSameCodeHashAsInstallledRelease(AppDistributionReleaseInterna
207206 return false ;
208207 }
209208
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
211210 // of the installed release, then they are the same release.
212- return externalCodeHash .equals (latestRelease .getCodeHash ());
211+ return externalCodeHash .equals (newRelease .getCodeHash ());
213212 } catch (PackageManager .NameNotFoundException e ) {
214213 LogWrapper .getInstance ().e (TAG + "Unable to locate App." , e );
215214 return false ;
0 commit comments