Skip to content

Commit 9d7a74e

Browse files
committed
testing lock changes
1 parent c9b67b5 commit 9d7a74e

29 files changed

+317
-646
lines changed

app/build.gradle.kts

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ android {
88
compileSdk = Config.SdkVersions.compile
99

1010
defaultConfig {
11+
applicationId = "com.firebase.uidemo"
12+
namespace = "com.firebase.uidemo"
1113
minSdk = Config.SdkVersions.min
1214
targetSdk = Config.SdkVersions.target
1315

@@ -94,9 +96,9 @@ dependencies {
9496
// demonstrative purposes, and you may find them useful in your own apps; YMMV.
9597
implementation(Config.Libs.Misc.permissions)
9698
implementation(Config.Libs.Androidx.constraint)
97-
debugImplementation(Config.Libs.Misc.leakCanary)
98-
debugImplementation(Config.Libs.Misc.leakCanaryFragments)
99-
releaseImplementation(Config.Libs.Misc.leakCanaryNoop)
99+
// debugImplementation(Config.Libs.Misc.leakCanary)
100+
// debugImplementation(Config.Libs.Misc.leakCanaryFragments)
101+
// releaseImplementation(Config.Libs.Misc.leakCanaryNoop)
100102
testImplementation(Config.Libs.Misc.leakCanaryNoop)
101103
}
102104

app/src/main/AndroidManifest.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
android:supportsRtl="true"
1818
android:theme="@style/AppTheme"
1919
tools:ignore="GoogleAppIndexingWarning,UnusedAttribute"
20-
android:usesCleartextTraffic="true">
20+
android:usesCleartextTraffic="true"
21+
android:dataExtractionRules="@xml/data_extraction_rules">
2122

2223
<activity android:name=".ChooserActivity"
2324
android:exported="true">
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.firebase.uidemo;
22

3-
import com.squareup.leakcanary.LeakCanary;
3+
//import com.squareup.leakcanary.LeakCanary;
44

55
import androidx.appcompat.app.AppCompatDelegate;
66
import androidx.multidex.MultiDexApplication;
@@ -13,11 +13,11 @@ public class FirebaseUIDemo extends MultiDexApplication {
1313
@Override
1414
public void onCreate() {
1515
super.onCreate();
16-
if (LeakCanary.isInAnalyzerProcess(this)) {
17-
// This process is dedicated to LeakCanary for heap analysis.
18-
// You should not init your app in this process.
19-
return;
20-
}
21-
LeakCanary.install(this);
16+
// if (LeakCanary.isInAnalyzerProcess(this)) {
17+
// // This process is dedicated to LeakCanary for heap analysis.
18+
// // You should not init your app in this process.
19+
// return;
20+
// }
21+
// LeakCanary.install(this);
2222
}
2323
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Sample data extraction rules file; uncomment and customize as necessary.
4+
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
5+
for details.
6+
-->
7+
<data-extraction-rules>
8+
<cloud-backup>
9+
<!--
10+
TODO: Use <include> and <exclude> to control what is backed up.
11+
The domain can be file, database, sharedpref, external or root.
12+
Examples:
13+
14+
<include domain="file" path="file_to_include"/>
15+
<exclude domain="file" path="file_to_exclude"/>
16+
<include domain="file" path="include_folder"/>
17+
<exclude domain="file" path="include_folder/file_to_exclude"/>
18+
<exclude domain="file" path="exclude_folder"/>
19+
<include domain="file" path="exclude_folder/file_to_include"/>
20+
21+
<include domain="sharedpref" path="include_shared_pref1.xml"/>
22+
<include domain="database" path="db_name/file_to_include"/>
23+
<exclude domain="database" path="db_name/include_folder/file_to_exclude"/>
24+
<include domain="external" path="file_to_include"/>
25+
<exclude domain="external" path="file_to_exclude"/>
26+
<include domain="root" path="file_to_include"/>
27+
<exclude domain="root" path="file_to_exclude"/>
28+
-->
29+
</cloud-backup>
30+
<!--
31+
<device-transfer>
32+
<include .../>
33+
<exclude .../>
34+
</device-transfer>
35+
-->
36+
</data-extraction-rules>

auth/build.gradle.kts

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ dependencies {
7272
implementation(Config.Libs.Androidx.fragment)
7373
implementation(Config.Libs.Androidx.customTabs)
7474
implementation(Config.Libs.Androidx.constraint)
75+
// TODO(rosariopf): Move this to config
76+
implementation("androidx.credentials:credentials:1.2.1")
77+
implementation("androidx.credentials:credentials-play-services-auth:1.2.1")
7578

7679
annotationProcessor(Config.Libs.Androidx.lifecycleCompiler)
7780

auth/src/main/AndroidManifest.xml

-6
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@
3939
android:exported="false"
4040
android:theme="@style/FirebaseUI.Transparent" />
4141

42-
<activity
43-
android:name=".ui.credentials.CredentialSaveActivity"
44-
android:label=""
45-
android:exported="false"
46-
android:theme="@style/FirebaseUI.Transparent" />
47-
4842
<activity
4943
android:name=".ui.email.RecoverPasswordActivity"
5044
android:label="@string/fui_title_recover_password_activity"

auth/src/main/java/com/firebase/ui/auth/AuthUI.java

+86-73
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,12 @@
2525
import com.facebook.login.LoginManager;
2626
import com.firebase.ui.auth.data.model.FlowParameters;
2727
import com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity;
28-
import com.firebase.ui.auth.util.CredentialUtils;
2928
import com.firebase.ui.auth.util.ExtraConstants;
3029
import com.firebase.ui.auth.util.GoogleApiUtils;
3130
import com.firebase.ui.auth.util.Preconditions;
3231
import com.firebase.ui.auth.util.data.PhoneNumberUtils;
3332
import com.firebase.ui.auth.util.data.ProviderAvailability;
3433
import com.firebase.ui.auth.util.data.ProviderUtils;
35-
import com.google.android.gms.auth.api.credentials.Credential;
36-
import com.google.android.gms.auth.api.credentials.CredentialRequest;
37-
import com.google.android.gms.auth.api.credentials.CredentialsClient;
3834
import com.google.android.gms.auth.api.signin.GoogleSignIn;
3935
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
4036
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
@@ -51,13 +47,11 @@
5147
import com.google.firebase.auth.FacebookAuthProvider;
5248
import com.google.firebase.auth.FirebaseAuth;
5349
import com.google.firebase.auth.FirebaseAuthInvalidUserException;
54-
import com.google.firebase.auth.FirebaseAuthProvider;
5550
import com.google.firebase.auth.FirebaseUser;
5651
import com.google.firebase.auth.GithubAuthProvider;
5752
import com.google.firebase.auth.GoogleAuthProvider;
5853
import com.google.firebase.auth.PhoneAuthProvider;
5954
import com.google.firebase.auth.TwitterAuthProvider;
60-
import com.google.firebase.auth.UserInfo;
6155

6256
import java.lang.annotation.Retention;
6357
import java.lang.annotation.RetentionPolicy;
@@ -269,33 +263,35 @@ public static int getDefaultTheme() {
269263
return R.style.FirebaseUI_DefaultMaterialTheme;
270264
}
271265

272-
/**
273-
* Make a list of {@link Credential} from a FirebaseUser. Useful for deleting Credentials, not
274-
* for saving since we don't have access to the password.
275-
*/
276-
private static List<Credential> getCredentialsFromFirebaseUser(@NonNull FirebaseUser user) {
277-
if (TextUtils.isEmpty(user.getEmail()) && TextUtils.isEmpty(user.getPhoneNumber())) {
278-
return Collections.emptyList();
279-
}
280-
281-
List<Credential> credentials = new ArrayList<>();
282-
for (UserInfo userInfo : user.getProviderData()) {
283-
if (FirebaseAuthProvider.PROVIDER_ID.equals(userInfo.getProviderId())) {
284-
continue;
285-
}
286-
287-
String type = ProviderUtils.providerIdToAccountType(userInfo.getProviderId());
288-
if (type == null) {
289-
// Since the account type is null, we've got an email credential. Adding a fake
290-
// password is the only way to tell Smart Lock that this is an email credential.
291-
credentials.add(CredentialUtils.buildCredentialOrThrow(user, "pass", null));
292-
} else {
293-
credentials.add(CredentialUtils.buildCredentialOrThrow(user, null, type));
294-
}
295-
}
296-
297-
return credentials;
298-
}
266+
// /**
267+
// * Make a list of {@link Credential} from a FirebaseUser. Useful for deleting Credentials, not
268+
// * for saving since we don't have access to the password.
269+
// */
270+
// private static List<Credential> getCredentialsFromFirebaseUser(@NonNull FirebaseUser user) {
271+
// if (TextUtils.isEmpty(user.getEmail()) && TextUtils.isEmpty(user.getPhoneNumber())) {
272+
// return Collections.emptyList();
273+
// }
274+
//
275+
//
276+
//
277+
// List<Credential> credentials = new ArrayList<>();
278+
// for (UserInfo userInfo : user.getProviderData()) {
279+
// if (FirebaseAuthProvider.PROVIDER_ID.equals(userInfo.getProviderId())) {
280+
// continue;
281+
// }
282+
//
283+
// String type = ProviderUtils.providerIdToAccountType(userInfo.getProviderId());
284+
// if (type == null) {
285+
// // Since the account type is null, we've got an email credential. Adding a fake
286+
// // password is the only way to tell Smart Lock that this is an email credential.
287+
// credentials.add(CredentialUtils.buildCredentialOrThrow(user, "pass", null));
288+
// } else {
289+
// credentials.add(CredentialUtils.buildCredentialOrThrow(user, null, type));
290+
// }
291+
// }
292+
//
293+
// return credentials;
294+
// }
299295

300296
/**
301297
* Signs the user in without any UI if possible. If this operation fails, you can safely start a
@@ -344,38 +340,53 @@ public Task<AuthResult> silentSignIn(@NonNull Context context,
344340
new FirebaseUiException(ErrorCodes.PLAY_SERVICES_UPDATE_CANCELLED));
345341
}
346342

347-
return GoogleApiUtils.getCredentialsClient(context)
348-
.request(new CredentialRequest.Builder()
349-
// We can support both email and Google at the same time here because they
350-
// are mutually exclusive. If a user signs in with Google, their email
351-
// account will automatically be upgraded (a.k.a. replaced) with the Google
352-
// one, meaning Smart Lock won't have to show the picker UI.
353-
.setPasswordLoginSupported(email != null)
354-
.setAccountTypes(google == null ? null :
355-
ProviderUtils.providerIdToAccountType(GoogleAuthProvider
356-
.PROVIDER_ID))
357-
.build())
358-
.continueWithTask(task -> {
359-
Credential credential = task.getResult().getCredential();
360-
String email1 = credential.getId();
361-
String password = credential.getPassword();
362-
363-
if (TextUtils.isEmpty(password)) {
364-
return GoogleSignIn.getClient(appContext,
365-
new GoogleSignInOptions.Builder(googleOptions)
366-
.setAccountName(email1)
367-
.build())
368-
.silentSignIn()
369-
.continueWithTask(task1 -> {
370-
AuthCredential authCredential = GoogleAuthProvider
371-
.getCredential(
372-
task1.getResult().getIdToken(), null);
373-
return mAuth.signInWithCredential(authCredential);
374-
});
375-
} else {
376-
return mAuth.signInWithEmailAndPassword(email1, password);
377-
}
378-
});
343+
return null;
344+
//TODO(rosariopf): figure out how to do silent sign in for email/password
345+
// return GoogleSignIn.getClient(appContext,
346+
// new GoogleSignInOptions.Builder(googleOptions)
347+
// .setAccountName(email)
348+
// .build())
349+
// .silentSignIn()
350+
// .continueWithTask(task1 -> {
351+
// AuthCredential authCredential = GoogleAuthProvider
352+
// .getCredential(
353+
// task1.getResult().getIdToken(), null);
354+
// return mAuth.signInWithCredential(authCredential);
355+
// });
356+
//
357+
// return GoogleApiUtils.getCredentialsClient(context)
358+
// .request(new CredentialRequest.Builder()
359+
// // We can support both email and Google at the same time here because they
360+
// // are mutually exclusive. If a user signs in with Google, their email
361+
// // account will automatically be upgraded (a.k.a. replaced) with the Google
362+
// // one, meaning Smart Lock won't have to show the picker UI.
363+
// .setPasswordLoginSupported(email != null)
364+
// .setAccountTypes(google == null ? null :
365+
// ProviderUtils.providerIdToAccountType(GoogleAuthProvider
366+
// .PROVIDER_ID))
367+
// .build()
368+
// )
369+
// .continueWithTask(task -> {
370+
// Credential credential = task.getResult().getCredential();
371+
// String email1 = credential.getId();
372+
// String password = credential.getPassword();
373+
//
374+
// if (TextUtils.isEmpty(password)) {
375+
// return GoogleSignIn.getClient(appContext,
376+
// new GoogleSignInOptions.Builder(googleOptions)
377+
// .setAccountName(email1)
378+
// .build())
379+
// .silentSignIn()
380+
// .continueWithTask(task1 -> {
381+
// AuthCredential authCredential = GoogleAuthProvider
382+
// .getCredential(
383+
// task1.getResult().getIdToken(), null);
384+
// return mAuth.signInWithCredential(authCredential);
385+
// });
386+
// } else {
387+
// return mAuth.signInWithEmailAndPassword(email1, password);
388+
// }
389+
// });
379390
}
380391

381392
/**
@@ -393,9 +404,10 @@ public Task<Void> signOut(@NonNull Context context) {
393404
Log.w(TAG, "Google Play services not available during signOut");
394405
}
395406

396-
Task<Void> maybeDisableAutoSignIn = playServicesAvailable
397-
? GoogleApiUtils.getCredentialsClient(context).disableAutoSignIn()
398-
: Tasks.forResult((Void) null);
407+
// TODO: Uncomment this
408+
Task<Void> maybeDisableAutoSignIn =
409+
// playServicesAvailable ? GoogleApiUtils.getCredentialsClient(context).disableAutoSignIn() :
410+
Tasks.forResult((Void) null);
399411

400412
maybeDisableAutoSignIn
401413
.continueWith(task -> {
@@ -440,7 +452,8 @@ public Task<Void> delete(@NonNull final Context context) {
440452
"No currently signed in user."));
441453
}
442454

443-
final List<Credential> credentials = getCredentialsFromFirebaseUser(currentUser);
455+
// TODO(rosariopf): Find a way to delete credentials
456+
// final List<Credential> credentials = getCredentialsFromFirebaseUser(currentUser);
444457

445458
// Ensure the order in which tasks are executed properly destructures the user.
446459
return signOutIdps(context).continueWithTask(task -> {
@@ -451,11 +464,11 @@ public Task<Void> delete(@NonNull final Context context) {
451464
return Tasks.forResult((Void) null);
452465
}
453466

454-
final CredentialsClient client = GoogleApiUtils.getCredentialsClient(context);
467+
// final CredentialsClient client = GoogleApiUtils.getCredentialsClient(context);
455468
List<Task<?>> credentialTasks = new ArrayList<>();
456-
for (Credential credential : credentials) {
457-
credentialTasks.add(client.delete(credential));
458-
}
469+
// for (Credential credential : credentials) {
470+
// credentialTasks.add(client.delete(credential));
471+
// }
459472
return Tasks.whenAll(credentialTasks)
460473
.continueWith(task1 -> {
461474
Exception e = task1.getException();

0 commit comments

Comments
 (0)