# Google OAuth 2.0 & Drive API Setup Guide

This guide explains how to configure Google Cloud Platform (GCP) credentials for **AntiCloudManager** to enable live Google Sign-In and Google Drive API synchronization across multiple Google accounts.

---

## 🏛️ 1. Google Cloud Console Configuration

### 1.1 Create or Select a GCP Project
1. Go to the [Google Cloud Console](https://console.cloud.google.com/).
2. Create a new project (e.g., `AntiCloudManager-DriveSync`) or select an existing one.

### 1.2 Enable Required APIs
1. In the GCP Navigation menu, navigate to **APIs & Services** > **Library**.
2. Search for **Google Drive API** and click **Enable**.
3. Search for **Google Identity / Google People API** (optional, for profile name/avatar) and click **Enable**.

---

## 🔒 2. OAuth Consent Screen

1. In the GCP Navigation menu, go to **APIs & Services** > **OAuth consent screen**.
2. Select **External** (unless you are using Google Workspace internal organizational users).
3. Fill in the required application details:
   * **App name:** AntiCloudManager
   * **User support email:** Your email address
   * **Developer contact email:** Your email address
4. On the **Scopes** page, click **Add or Remove Scopes** and add:
   * `https://www.googleapis.com/auth/drive.file` (Recommended: Per-app file access)
   * `https://www.googleapis.com/auth/drive` (Full drive access for quota and cross-account migration)
   * `https://www.googleapis.com/auth/userinfo.email`
   * `https://www.googleapis.com/auth/userinfo.profile`
5. If the app is in "Testing" status, add your Google account emails to the **Test Users** list.

---

## 📱 3. Configure Android OAuth Client ID

To allow Google Play Services on Android to sign in seamlessly:

1. In GCP, go to **APIs & Services** > **Credentials**.
2. Click **Create Credentials** > **OAuth client ID**.
3. Select Application type: **Android**.
4. Package name:
   ```
   com.antigravity.cloudstorage.anti_cloud_manager
   ```
5. Obtain your debug SHA-1 signing certificate fingerprint:
   * Run the following command in PowerShell:
     ```powershell
     keytool -list -v -keystore $env:USERPROFILE\.android\debug.keystore -alias androiddebugkey -storepass android -keypass android
     ```
   * Copy the `SHA1:` fingerprint string (e.g. `DA:39:A3:EE:5E:6B:...`).
6. Paste the SHA-1 fingerprint into the GCP dialog and click **Create**.

---

## 📄 4. `google-services.json` (Firebase / Native Auth Integration)

If connecting via Firebase Authentication:
1. Go to the [Firebase Console](https://console.firebase.google.com/).
2. Add your GCP project to Firebase.
3. Add an Android app with package name `com.antigravity.cloudstorage.anti_cloud_manager`.
4. Download the generated `google-services.json`.
5. Place the file inside:
   ```
   android/app/google-services.json
   ```

---

## 🔄 5. Multi-Account Connection Flow in AntiCloudManager

AntiCloudManager supports two methods for connecting accounts:

### Method A: Connect Existing Account (Official OAuth 2.0)
* Tapping **Connect Existing Account** invokes Android's Google Sign-In intent.
* When prompted, the user can select an existing Google Account or tap "Use another account".
* The authorized OAuth access token is stored securely in the device's hardware KeyStore via `FlutterSecureStorage`.
* Scopes requested:
  * `drive.file`
  * `drive.appdata`
  * `drive.readonly`

### Method B: Manual Token / Developer Testing Connection
* For automated testing or running outside Google Play Services (e.g. AOSP, microG, custom ROMs), AntiCloudManager allows manual token or mock-drive connectivity to verify quota balancing, file queue management, and UI logic safely without requiring live GCP configuration.

