Skip to content

Commit 9a07b34

Browse files
committed
Merge branch 'master' into wuandy/SquashBasedOnSebastianDraft
2 parents 8a68b18 + 21a9f91 commit 9a07b34

File tree

94 files changed

+7313
-1365
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+7313
-1365
lines changed

firebase-app-distribution/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@
4444

4545
<provider
4646
android:name="androidx.core.content.FileProvider"
47-
android:authorities="${applicationId}.provider"
47+
android:authorities="${applicationId}.appdistro.fileprovider"
4848
android:exported="false"
4949
android:grantUriPermissions="true">
5050
<meta-data
5151
android:name="android.support.FILE_PROVIDER_PATHS"
52-
android:resource="@xml/provider_paths" />
52+
android:resource="@xml/appdistro_provider_paths" />
5353
</provider>
5454
</application>
5555
</manifest>

firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/CheckForUpdateClient.java renamed to firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/CheckForNewReleaseClient.java

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,33 @@
3636
import java.util.concurrent.Executor;
3737
import 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;

firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/FirebaseAppDistribution.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class FirebaseAppDistribution implements Application.ActivityLifecycleCal
3636

3737
private final FirebaseApp firebaseApp;
3838
private final TesterSignInClient testerSignInClient;
39-
private final CheckForUpdateClient checkForUpdateClient;
39+
private final CheckForNewReleaseClient checkForNewReleaseClient;
4040
private final UpdateAppClient updateAppClient;
4141
private Activity currentActivity;
4242
private static final int UNKNOWN_RELEASE_FILE_SIZE = -1;
@@ -45,7 +45,7 @@ public class FirebaseAppDistribution implements Application.ActivityLifecycleCal
4545
private UpdateTaskImpl cachedUpdateIfNewReleaseTask;
4646

4747
private final Object updateTaskLock = new Object();
48-
private Task<AppDistributionRelease> cachedCheckForUpdateTask;
48+
private Task<AppDistributionRelease> cachedCheckForNewReleaseTask;
4949

5050
private AppDistributionReleaseInternal cachedNewRelease;
5151
private final SignInStorage signInStorage;
@@ -55,12 +55,12 @@ public class FirebaseAppDistribution implements Application.ActivityLifecycleCal
5555
FirebaseAppDistribution(
5656
@NonNull FirebaseApp firebaseApp,
5757
@NonNull TesterSignInClient testerSignInClient,
58-
@NonNull CheckForUpdateClient checkForUpdateClient,
58+
@NonNull CheckForNewReleaseClient checkForNewReleaseClient,
5959
@NonNull UpdateAppClient updateAppClient,
6060
@NonNull SignInStorage signInStorage) {
6161
this.firebaseApp = firebaseApp;
6262
this.testerSignInClient = testerSignInClient;
63-
this.checkForUpdateClient = checkForUpdateClient;
63+
this.checkForNewReleaseClient = checkForNewReleaseClient;
6464
this.updateAppClient = updateAppClient;
6565
this.signInStorage = signInStorage;
6666
}
@@ -73,7 +73,7 @@ public FirebaseAppDistribution(
7373
this(
7474
firebaseApp,
7575
new TesterSignInClient(firebaseApp, firebaseInstallationsApi, signInStorage),
76-
new CheckForUpdateClient(
76+
new CheckForNewReleaseClient(
7777
firebaseApp, new FirebaseAppDistributionTesterApiClient(), firebaseInstallationsApi),
7878
new UpdateAppClient(firebaseApp),
7979
signInStorage);
@@ -171,21 +171,21 @@ public Task<Void> signInTester() {
171171
*/
172172
@NonNull
173173
public synchronized Task<AppDistributionRelease> checkForNewRelease() {
174-
if (cachedCheckForUpdateTask != null && !cachedCheckForUpdateTask.isComplete()) {
174+
if (cachedCheckForNewReleaseTask != null && !cachedCheckForNewReleaseTask.isComplete()) {
175175
LogWrapper.getInstance().v("Response in progress");
176-
return cachedCheckForUpdateTask;
176+
return cachedCheckForNewReleaseTask;
177177
}
178-
cachedCheckForUpdateTask =
178+
cachedCheckForNewReleaseTask =
179179
signInTester()
180-
.onSuccessTask(unused -> this.checkForUpdateClient.checkForUpdate())
180+
.onSuccessTask(unused -> this.checkForNewReleaseClient.checkForNewRelease())
181181
.onSuccessTask(
182182
appDistributionReleaseInternal -> {
183183
setCachedNewRelease(appDistributionReleaseInternal);
184184
return Tasks.forResult(
185185
ReleaseUtils.convertToAppDistributionRelease(appDistributionReleaseInternal));
186186
});
187187

188-
return cachedCheckForUpdateTask;
188+
return cachedCheckForNewReleaseTask;
189189
}
190190

191191
/**
@@ -194,7 +194,7 @@ public synchronized Task<AppDistributionRelease> checkForNewRelease() {
194194
* complete the download and installation.
195195
*
196196
* <p>cancels task with FirebaseAppDistributionException with UPDATE_NOT_AVAILABLE exception if no
197-
* new release is cached from checkForUpdate
197+
* new release is cached from checkForNewRelease
198198
*/
199199
@NonNull
200200
public synchronized UpdateTask updateApp() {

firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/FirebaseAppDistributionTesterApiClient.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,32 @@ class FirebaseAppDistributionTesterApiClient {
4646
private static final String TAG = "TesterApiClient:";
4747
public static final int DEFAULT_BUFFER_SIZE = 8192;
4848

49-
public @NonNull AppDistributionReleaseInternal fetchLatestRelease(
49+
public @NonNull AppDistributionReleaseInternal fetchNewRelease(
5050
@NonNull String fid, @NonNull String appId, @NonNull String apiKey, @NonNull String authToken)
5151
throws FirebaseAppDistributionException {
5252

53-
AppDistributionReleaseInternal latestRelease;
53+
AppDistributionReleaseInternal newRelease;
5454
HttpsURLConnection connection = openHttpsUrlConnection(appId, fid);
5555
try {
5656
connection.setRequestMethod(REQUEST_METHOD);
5757
connection.setRequestProperty(API_KEY_HEADER, apiKey);
5858
connection.setRequestProperty(INSTALLATION_AUTH_HEADER, authToken);
5959

6060
InputStream inputStream = connection.getInputStream();
61-
JSONObject latestReleaseJson = readFetchReleaseInputStream(inputStream);
62-
final String displayVersion = latestReleaseJson.getString(DISPLAY_VERSION_JSON_KEY);
63-
final String buildVersion = latestReleaseJson.getString(BUILD_VERSION_JSON_KEY);
64-
String releaseNotes = tryGetValue(latestReleaseJson, RELEASE_NOTES_JSON_KEY);
65-
String codeHash = tryGetValue(latestReleaseJson, CODE_HASH_KEY);
66-
String iasArtifactId = tryGetValue(latestReleaseJson, IAS_ARTIFACT_ID_KEY);
67-
String downloadUrl = tryGetValue(latestReleaseJson, DOWNLOAD_URL_KEY);
61+
JSONObject newReleaseJson = readFetchReleaseInputStream(inputStream);
62+
final String displayVersion = newReleaseJson.getString(DISPLAY_VERSION_JSON_KEY);
63+
final String buildVersion = newReleaseJson.getString(BUILD_VERSION_JSON_KEY);
64+
String releaseNotes = tryGetValue(newReleaseJson, RELEASE_NOTES_JSON_KEY);
65+
String codeHash = tryGetValue(newReleaseJson, CODE_HASH_KEY);
66+
String iasArtifactId = tryGetValue(newReleaseJson, IAS_ARTIFACT_ID_KEY);
67+
String downloadUrl = tryGetValue(newReleaseJson, DOWNLOAD_URL_KEY);
6868

6969
final BinaryType binaryType =
70-
latestReleaseJson.getString(BINARY_TYPE_JSON_KEY).equals("APK")
70+
newReleaseJson.getString(BINARY_TYPE_JSON_KEY).equals("APK")
7171
? BinaryType.APK
7272
: BinaryType.AAB;
7373

74-
latestRelease =
74+
newRelease =
7575
AppDistributionReleaseInternal.builder()
7676
.setDisplayVersion(displayVersion)
7777
.setBuildVersion(buildVersion)
@@ -85,7 +85,7 @@ class FirebaseAppDistributionTesterApiClient {
8585

8686
} catch (IOException | JSONException e) {
8787
if (e instanceof JSONException) {
88-
LogWrapper.getInstance().e(TAG + "Error parsing the latest release.", e);
88+
LogWrapper.getInstance().e(TAG + "Error parsing the new release.", e);
8989
throw new FirebaseAppDistributionException(
9090
Constants.ErrorMessages.JSON_PARSING_ERROR, NETWORK_FAILURE, e);
9191
}
@@ -94,7 +94,7 @@ class FirebaseAppDistributionTesterApiClient {
9494
connection.disconnect();
9595
}
9696

97-
return latestRelease;
97+
return newRelease;
9898
}
9999

100100
private FirebaseAppDistributionException getExceptionForHttpResponse(
@@ -136,19 +136,19 @@ private String tryGetValue(JSONObject jsonObject, String key) {
136136

137137
private JSONObject readFetchReleaseInputStream(InputStream in)
138138
throws FirebaseAppDistributionException, IOException {
139-
JSONObject latestRelease;
139+
JSONObject newRelease;
140140
InputStream jsonIn = new BufferedInputStream(in);
141141
String result = convertInputStreamToString(jsonIn);
142142
try {
143143
JSONObject json = new JSONObject(result);
144-
latestRelease = json.getJSONArray("releases").getJSONObject(0);
144+
newRelease = json.getJSONArray("releases").getJSONObject(0);
145145
} catch (JSONException e) {
146146
throw new FirebaseAppDistributionException(
147147
Constants.ErrorMessages.JSON_PARSING_ERROR,
148148
FirebaseAppDistributionException.Status.UNKNOWN,
149149
e);
150150
}
151-
return latestRelease;
151+
return newRelease;
152152
}
153153

154154
HttpsURLConnection openHttpsUrlConnection(String appId, String fid)

firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/InstallActivity.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,22 @@ protected void onCreate(@NonNull Bundle savedInstanceState) {
4545
String path = originalIntent.getStringExtra("INSTALL_PATH");
4646
Intent intent = new Intent(Intent.ACTION_VIEW);
4747
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
48-
Uri apkUri =
49-
FileProvider.getUriForFile(
50-
getApplicationContext(),
51-
getApplicationContext().getPackageName() + ".provider",
52-
new File(path));
48+
File apkFile = new File(path);
5349
String APK_MIME_TYPE = "application/vnd.android.package-archive";
54-
intent.setDataAndType(apkUri, APK_MIME_TYPE);
55-
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
50+
51+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
52+
Uri apkUri =
53+
FileProvider.getUriForFile(
54+
getApplicationContext(),
55+
getApplicationContext().getPackageName() + ".appdistro.fileprovider",
56+
apkFile);
57+
intent.setDataAndType(apkUri, APK_MIME_TYPE);
58+
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
59+
} else {
60+
LogWrapper.getInstance().d("Requesting a vanilla URI");
61+
intent.setDataAndType(Uri.fromFile(apkFile), APK_MIME_TYPE);
62+
}
63+
5664
mStartForResult.launch(intent);
5765
}
5866

0 commit comments

Comments
 (0)