From 9304fda796bdafc5fb0b90990d90c6cb9986fa85 Mon Sep 17 00:00:00 2001 From: offtkp Date: Sat, 16 Dec 2023 17:37:42 +0200 Subject: [PATCH] [Cloud]Use google auth to login on native app --- CMakeLists.txt | 5 --- tools/android_project/app/build.gradle | 1 + .../sky/SkyEmu/EnhancedNativeActivity.java | 44 +++++++++++++++++-- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 39e385565..be6acff48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -190,8 +190,6 @@ set(SOKOL_HEADERS if(ANDROID) add_definitions(-DSE_PLATFORM_ANDROID) set(LINK_LIBS ${LINK_LIBS} GLESv3 EGL OpenSLES log android) - # link_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/curl-mobile/android/${ANDROID_ABI}) - # include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/curl-mobile/android/include) message("Android Build!") endif() if(MACOS OR IOS) @@ -299,9 +297,6 @@ endif() if(IOS) set(SKYEMU_SRC ${SKYEMU_SRC} src/ios_support.m) add_definitions(-DSE_PLATFORM_IOS) - # set(LINK_LIBS ${LINK_LIBS} curl z) - # link_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/curl-mobile/iOS) - # include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/curl-mobile/iOS/include) endif() if(WIN32) diff --git a/tools/android_project/app/build.gradle b/tools/android_project/app/build.gradle index f21734d6f..f2cb6a1f7 100644 --- a/tools/android_project/app/build.gradle +++ b/tools/android_project/app/build.gradle @@ -48,4 +48,5 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation 'com.google.android.gms:play-services-auth:20.7.0' } diff --git a/tools/android_project/app/src/main/java/com/sky/SkyEmu/EnhancedNativeActivity.java b/tools/android_project/app/src/main/java/com/sky/SkyEmu/EnhancedNativeActivity.java index 9cd233f4e..c49c6455e 100644 --- a/tools/android_project/app/src/main/java/com/sky/SkyEmu/EnhancedNativeActivity.java +++ b/tools/android_project/app/src/main/java/com/sky/SkyEmu/EnhancedNativeActivity.java @@ -39,10 +39,18 @@ import java.util.Locale; import java.util.Vector; +import com.google.android.gms.auth.api.signin.GoogleSignIn; +import com.google.android.gms.auth.api.signin.GoogleSignInAccount; +import com.google.android.gms.common.Scopes; +import com.google.android.gms.common.api.Scope; +import com.google.android.gms.tasks.Task; +import com.google.android.gms.auth.api.signin.GoogleSignInOptions; + public class EnhancedNativeActivity extends NativeActivity { final static int APP_STORAGE_ACCESS_REQUEST_CODE = 501; // Any value final static int STORAGE_PERMISSION_CODE = 501; // Any value final static int FILE_PICKER_REQUEST_CODE = 123; + final static int GOOGLE_OAUTH_RESPONSE_CODE = 124; final static String TAG="SkyEmu"; // Any value public Rect visibleRect; public EditText invisibleEditText; @@ -375,6 +383,15 @@ public void loadURI(Uri selectedFileUri, boolean is_rom){ } } } + public void authenticateDrive(){ + GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) + .requestScopes(new Scope(Scopes.DRIVE_FILE)) + .requestServerAuthCode(serverClientId) + .requestEmail() + .build(); + Intent signInIntent = mGoogleSignInClient.getSignInIntent(); + startActivityForResult(signInIntent, GOOGLE_OAUTH_RESPONSE_CODE); + } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // If the selection didn't work @@ -382,9 +399,30 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { // Exit without doing anything else return; } else { - if (requestCode == FILE_PICKER_REQUEST_CODE && data != null) { - Uri selectedFileUri = data.getData(); - loadURI(selectedFileUri,false); + switch (requestCode) + { + case FILE_PICKER_REQUEST_CODE: + if (data != null) { + Uri selectedFileUri = data.getData(); + loadURI(selectedFileUri,false); + } + break; + case GOOGLE_OAUTH_RESPONSE_CODE: + if (data != null) { + Task task = GoogleSignIn.getSignedInAccountFromIntent(data); + try { + GoogleSignInAccount account = task.getResult(ApiException.class); + String authCode = account.getServerAuthCode(); + + Log.w(TAG, "Sign-in succeeded: " + account.getDisplayName() + " " + account.getEmail() + " " + authCode); + } catch (ApiException e) { + Log.w(TAG, "Sign-in failed", e); + } + } + break; + default: + Log.e(TAG, "Unknown request code received: " + requestCode); + break; } } }