Skip to content

Removing dependency for activities #3298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 12, 2022
Merged

Conversation

manny-jimenez
Copy link
Contributor

No description provided.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jan 10, 2022

Coverage Report 1

Affected Products

  • firebase-app-distribution

    Overall coverage changed from ? (9cd2475) to 74.70% (9745d50) by ?.

    33 individual files with coverage change

    FilenameBase (9cd2475)Merge (9745d50)Diff
    AabUpdater.java?98.59%?
    ApkInstaller.java?93.88%?
    ApkUpdater.java?72.80%?
    AppDistributionRelease.java?100.00%?
    AppDistributionReleaseInternal.java?100.00%?
    AppIconSource.java?85.71%?
    AutoValue_AppDistributionRelease.java?65.45%?
    AutoValue_AppDistributionReleaseInternal.java?67.86%?
    AutoValue_UpdateProgress.java?65.96%?
    BinaryType.java?100.00%?
    Constants.java?0.00%?
    FirebaseAppDistribution.java?91.48%?
    FirebaseAppDistributionException.java?87.10%?
    FirebaseAppDistributionFileProvider.java?0.00%?
    FirebaseAppDistributionLifecycleNotifier.java?46.67%?
    FirebaseAppDistributionNotificationsManager.java?92.68%?
    FirebaseAppDistributionRegistrar.java?90.91%?
    FirebaseAppDistributionTesterApiClient.java?91.21%?
    HttpsUrlConnectionFactory.java?50.00%?
    InstallActivity.java?4.23%?
    LogWrapper.java?64.71%?
    NewReleaseFetcher.java?87.95%?
    OnProgressListener.java?0.00%?
    ReleaseIdentificationUtils.java?15.52%?
    ReleaseUtils.java?76.92%?
    SignInResultActivity.java?0.00%?
    SignInStorage.java?57.14%?
    TaskUtils.java?93.75%?
    TesterSignInManager.java?87.91%?
    UpdateProgress.java?100.00%?
    UpdateStatus.java?100.00%?
    UpdateTask.java?100.00%?
    UpdateTaskImpl.java?82.81%?

Test Logs

Notes

  • Commit (9745d50) is created by Prow via merging PR base commit (9cd2475) and head commit (0e12c55).
  • Run gradle <product>:checkCoverage to produce HTML coverage reports locally. After gradle commands finished, report files can be found under <product-build-dir>/reports/jacoco/.

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/Bpa6BK4yDU.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jan 10, 2022

Size Report 1

Affected Products

  • firebase-app-distribution

    TypeBase (9cd2475)Merge (9745d50)Diff
    aar120 kB120 kB-81 B (-0.1%)
    apk (aggressive)739 kB739 kB-24 B (-0.0%)
    apk (release)1.55 MB1.55 MB-140 B (-0.0%)

Test Logs

Notes

  • Commit (9745d50) is created by Prow via merging PR base commit (9cd2475) and head commit (0e12c55).

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/Y89oHhNpbP.html

this.firebaseAppDistributionTesterApiClient = firebaseAppDistributionTesterApiClient;
this.firebaseInstallationsApiProvider = firebaseInstallationsApiProvider;
this.taskExecutor = Executors.newSingleThreadExecutor();
this(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@@ -93,7 +97,7 @@ void handleAppResume(Activity activity) {
cachedInstallApkPath = path;
} else {
// only start the install activity if current Activity is in the foreground
startInstallActivity(path, currentActivity);
startInstallActivity(path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if case on line 95 can be removed right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it can!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we now start the Install Activity regardless of whether or not the customer's app is in the foreground?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! Currently working on trying to see if there is a set up to make that work. In its current set up if the user backgrounds the app it seems to hang.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this is not possible due to Install Activity relying on an activity to show unknown sources UI.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is surprising. I'd think that once the InstallActivity starts, then it's in the foreground and we can show the dialog. That's what happened when you were calling UpdateApp from a background thread, which worked.

What error/stacktrace are you seeing in the logs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get a windowLeaked error. I can repro and show the error message. I believe that was because the app itself wasn't in the background, but once you background the app it wants to display the unknown sources UI but since the app is in the background you get this leaked error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the app get backgrounded? Maybe we could look at it together over VC.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this in person. Previously, backgrounding the app after starting the basic config would fail the task correctly. With this change it instead hangs the task.

I'm fine punting on this for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify it hangs if we don't depend on the currentActivity at all with checking what to do with InstallActivity.

Copy link

@rachaprince rachaprince left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM so far!

@manny-jimenez
Copy link
Contributor Author

/run binary-size

@@ -111,6 +111,7 @@ private void startInstallActivity(String path, Activity currentActivity) {
}
Intent intent = new Intent(currentActivity, InstallActivity.class);
intent.putExtra("INSTALL_PATH", path);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add this flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Leftover from trying to use application context. When using application Context it needs to be a new task but since that was taken out this should also be taken out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting. Why does it need to a be a new task when using application context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran into the issue but this post sums up the issue and the reason for the fix. https://stackoverflow.com/questions/3918517/calling-startactivity-from-outside-of-an-activity-context

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, ok the fact that you saw that error is making me less confident in my suggestion to use intents + activities. It feels weird to have to start a new task every time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do this in the AAB updater

With the application context we aren't guaranteed an activity so the flag makes sense to me.

Copy link
Contributor

@lfkellogg lfkellogg Jan 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes more sense in the AAB updater since we are launching an activity in a different app, Play.

In the case I was proposing, where we would launch a new intent/activity in order to simply show a dialog in the app, we wouldn't want an additional task. It should ideally just continue in the same task.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error is especially interesting, since we should be starting the install activity as a new task anyway according to the manifest I think https://github.com/firebase/firebase-android-sdk/blob/master/firebase-app-distribution/src/main/AndroidManifest.xml#L34-L35

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the docs:
singleTask
The system creates a new task and instantiates the activity at the root of the new task.

@@ -48,18 +50,22 @@
private AppDistributionReleaseInternal aabReleaseInProgress;

private final Object updateAabLock = new Object();
private final Context applicationContext;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: for brevity, can we just call this context everywhere instead of applicationContext?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did see we used context elsewhere. Context being so vague is the reason I added application to it, but I have no issue making it context.


AabUpdater() {
AabUpdater(@NonNull FirebaseApp firebaseApp) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constructor should just take a Context object since that's all you need.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thought! I had done this elsewhere before should do it here as well.

@@ -84,7 +98,8 @@ public void setup() throws IOException, FirebaseAppDistributionException {

aabUpdater =
Mockito.spy(
new AabUpdater(mockLifecycleNotifier, mockHttpsUrlConnectionFactory, testExecutor));
new AabUpdater(
firebaseApp, mockLifecycleNotifier, mockHttpsUrlConnectionFactory, testExecutor));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you take my suggestion and require a Context here instead of a FirebaseApp, then you can just pass in ApplicationProvider.getApplicationContext().

Copy link
Contributor

@lfkellogg lfkellogg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tiny nits. Looks great!

Comment on lines 203 to 204
new BufferedOutputStream(
context.openFileOutput(fileName, fileCreationMode));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can go back to being a one-liner.

Comment on lines 247 to 250
context
.getApplicationInfo()
.loadLabel(context.getPackageManager())
.toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also be a one-liner

@@ -148,7 +148,6 @@ public UpdateTask updateIfNewReleaseAvailable() {
return cachedUpdateIfNewReleaseTask;
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can you put this empty line back?

.setApplicationId(TEST_APP_ID_1)
.setProjectId(TEST_PROJECT_ID)
.setApiKey(TEST_API_KEY)
.build());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case you missed my other comment, you don't need to a create a FirebaseApp here. You can just inject ApplicationProvider.getApplicationContext() into the constructor, below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did miss this comment. Will fix now.

@manny-jimenez manny-jimenez merged commit 55ffdd5 into master Jan 12, 2022
@manny-jimenez manny-jimenez deleted the fad_remove_activity_reference branch January 12, 2022 15:22
@firebase firebase locked and limited conversation to collaborators Feb 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants