Skip to content

Commit

Permalink
[Cloud]Use google auth to login on native app
Browse files Browse the repository at this point in the history
  • Loading branch information
OFFTKP committed Dec 16, 2023
1 parent ba77dcd commit 9304fda
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tools/android_project/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -375,16 +383,46 @@ 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
if (resultCode != RESULT_OK) {
// 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<GoogleSignInAccount> 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;
}
}
}
Expand Down

0 comments on commit 9304fda

Please sign in to comment.