Skip to content
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

Added Device Sync request #2621

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,14 @@ object SettingsContract {
const val LICENSING_PURCHASE_FREE_APPS = "vending_licensing_purchase_free_apps"
const val BILLING = "vending_billing"
const val ASSET_DELIVERY = "vending_asset_delivery"
const val ASSET_DEVICE_SYNC = "vending_device_sync"

val PROJECTION = arrayOf(
LICENSING,
LICENSING_PURCHASE_FREE_APPS,
BILLING,
ASSET_DELIVERY,
ASSET_DEVICE_SYNC,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ class SettingsProvider : ContentProvider() {
Vending.LICENSING_PURCHASE_FREE_APPS -> getSettingsBoolean(key, false)
Vending.BILLING -> getSettingsBoolean(key, false)
Vending.ASSET_DELIVERY -> getSettingsBoolean(key, false)
Vending.ASSET_DEVICE_SYNC -> getSettingsBoolean(key, false)
else -> throw IllegalArgumentException("Unknown key: $key")
}
}
Expand All @@ -369,6 +370,7 @@ class SettingsProvider : ContentProvider() {
Vending.LICENSING_PURCHASE_FREE_APPS -> editor.putBoolean(key, value as Boolean)
Vending.BILLING -> editor.putBoolean(key, value as Boolean)
Vending.ASSET_DELIVERY -> editor.putBoolean(key, value as Boolean)
Vending.ASSET_DEVICE_SYNC -> editor.putBoolean(key, value as Boolean)
else -> throw IllegalArgumentException("Unknown key: $key")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ public class Constants {
public static final String MICROG_PACKAGE_SIGNATURE_SHA1 = "10321bd893f69af97f7573aafe9de1dc0901f3a1";
@Deprecated
public static final int MAX_REFERENCE_VERSION = GMS_VERSION_CODE;
public static final String VENDING_PACKAGE_NAME = "com.android.vending";
}
3 changes: 3 additions & 0 deletions play-services-core/src/huawei/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@
<meta-data
android:name="org.microg.gms.settings.vending_asset_delivery"
android:value="true" />
<meta-data
android:name="org.microg.gms.settings.vending_device_sync"
android:value="true" />
</application>
</manifest>
5 changes: 5 additions & 0 deletions play-services-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@
android:permissionGroup="com.google.android.gms.permission.CAR_INFORMATION"
android:protectionLevel="dangerous" />

<permission
android:name="com.google.android.gms.auth.permission.GOOGLE_ACCOUNT_CHANGE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.google.android.gms.auth.permission.GOOGLE_ACCOUNT_CHANGE" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
Expand Down Expand Up @@ -77,6 +78,7 @@
import static org.microg.gms.auth.AuthPrefs.isAuthVisible;
import static org.microg.gms.common.Constants.GMS_PACKAGE_NAME;
import static org.microg.gms.common.Constants.GMS_VERSION_CODE;
import static org.microg.gms.common.Constants.VENDING_PACKAGE_NAME;

public class LoginActivity extends AssistantActivity {
public static final String TMPL_NEW_ACCOUNT = "new_account";
Expand All @@ -91,6 +93,8 @@ public class LoginActivity extends AssistantActivity {
private static final String GOOGLE_SUITE_URL = "https://accounts.google.com/signin/continue";
private static final String MAGIC_USER_AGENT = " MinuteMaid";
private static final String COOKIE_OAUTH_TOKEN = "oauth_token";
private static final String ACTION_UPDATE_ACCOUNT = "com.google.android.gms.auth.GOOGLE_ACCOUNT_CHANGE";
private static final String PERMISSION_UPDATE_ACCOUNT = "com.google.android.gms.auth.permission.GOOGLE_ACCOUNT_CHANGE";

private final FidoHandler fidoHandler = new FidoHandler(this);
private final DroidGuardHandler dgHandler = new DroidGuardHandler(this);
Expand Down Expand Up @@ -358,6 +362,10 @@ private void returnSuccessResponse(Account account){
bd.putString(AccountManager.KEY_ACCOUNT_TYPE,accountType);
response.onResult(bd);
}
Intent intent = new Intent(ACTION_UPDATE_ACCOUNT);
intent.setPackage(VENDING_PACKAGE_NAME);
intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, account.name);
sendBroadcast(intent, PERMISSION_UPDATE_ACCOUNT);
}
private void retrieveGmsToken(final Account account) {
final AuthManager authManager = new AuthManager(this, account.name, GMS_PACKAGE_NAME, "ac2dm");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public String getGroupName(Context context) {
@Override
public void doChecks(Context context, ResultCollector collector) {
addPackageInstalledAndSignedResult(context, collector, context.getString(R.string.self_check_pkg_gms), Constants.GMS_PACKAGE_NAME, Constants.GMS_PACKAGE_SIGNATURE_SHA1);
addPackageInstalledAndSignedResult(context, collector, context.getString(R.string.self_check_pkg_vending), "com.android.vending", Constants.GMS_PACKAGE_SIGNATURE_SHA1);
addPackageInstalledAndSignedResult(context, collector, context.getString(R.string.self_check_pkg_vending), Constants.VENDING_PACKAGE_NAME, Constants.GMS_PACKAGE_SIGNATURE_SHA1);
addPackageInstalledResult(context, collector, context.getString(R.string.self_check_pkg_gsf), Constants.GSF_PACKAGE_NAME);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class VendingFragment : PreferenceFragmentCompat() {
private lateinit var licensingPurchaseFreeAppsEnabled: TwoStatePreference
private lateinit var iapEnable: TwoStatePreference
private lateinit var assetDeliveryEnabled: TwoStatePreference
private lateinit var deviceSyncEnabled: TwoStatePreference

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.preferences_vending)
Expand Down Expand Up @@ -73,6 +74,18 @@ class VendingFragment : PreferenceFragmentCompat() {
}
true
}

deviceSyncEnabled = preferenceScreen.findPreference(PREF_DEVICE_SYNC_ENABLED) ?: deviceSyncEnabled
deviceSyncEnabled.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
val appContext = requireContext().applicationContext
lifecycleScope.launchWhenResumed {
if (newValue is Boolean) {
VendingPreferences.setDeviceSyncEnabled(appContext, newValue)
}
updateContent()
}
true
}
}

override fun onResume() {
Expand All @@ -87,6 +100,7 @@ class VendingFragment : PreferenceFragmentCompat() {
licensingPurchaseFreeAppsEnabled.isChecked = VendingPreferences.isLicensingPurchaseFreeAppsEnabled(appContext)
iapEnable.isChecked = VendingPreferences.isBillingEnabled(appContext)
assetDeliveryEnabled.isChecked = VendingPreferences.isAssetDeliveryEnabled(appContext)
deviceSyncEnabled.isChecked = VendingPreferences.isDeviceSyncEnabled(appContext)
}
}

Expand All @@ -95,5 +109,6 @@ class VendingFragment : PreferenceFragmentCompat() {
const val PREF_LICENSING_PURCHASE_FREE_APPS_ENABLED = "vending_licensing_purchase_free_apps"
const val PREF_IAP_ENABLED = "vending_iap"
const val PREF_ASSET_DELIVERY_ENABLED = "vending_asset_delivery"
const val PREF_DEVICE_SYNC_ENABLED = "vending_device_sync"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,19 @@ object VendingPreferences {
put(SettingsContract.Vending.ASSET_DELIVERY, enabled)
}
}

@JvmStatic
fun isDeviceSyncEnabled(context: Context): Boolean {
val projection = arrayOf(SettingsContract.Vending.ASSET_DEVICE_SYNC)
return SettingsContract.getSettings(context, SettingsContract.Vending.getContentUri(context), projection) { c ->
c.getInt(0) != 0
}
}

@JvmStatic
fun setDeviceSyncEnabled(context: Context, enabled: Boolean) {
SettingsContract.setSettings(context, SettingsContract.Vending.getContentUri(context)) {
put(SettingsContract.Vending.ASSET_DEVICE_SYNC, enabled)
}
}
}
2 changes: 2 additions & 0 deletions play-services-core/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,6 @@ microG GmsCore 内置一套自由的 SafetyNet 实现,但是官方服务器要
<string name="pref_vending_asset_delivery_summary">当使用 Play 资产传递的应用请求时下载额外的资产</string>
<string name="pref_vending_asset_delivery_category">Google Play 资产传递</string>
<string name="pref_vending_asset_delivery_switch">启用按需资产传递</string>
<string name="pref_vending_asset_device_sync_summary">使用 Play 资产传递的应用请求时将会根据当前使用设备信息下载更多的资产</string>
<string name="pref_vending_asset_device_sync_switch">启用设备信息同步</string>
</resources>
2 changes: 2 additions & 0 deletions play-services-core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ Please set up a password, PIN, or pattern lock screen."</string>
<string name="pref_vending_asset_delivery_category">Google Play Asset Delivery</string>
<string name="pref_vending_asset_delivery_switch">Enable on-demand asset delivery</string>
<string name="pref_vending_asset_delivery_summary">Download additional assets when requested by apps that use Play Asset Delivery</string>
<string name="pref_vending_asset_device_sync_summary">Applications using Play Asset Delivery will download additional assets based on the information of the device currently in use.</string>
<string name="pref_vending_asset_device_sync_switch">Enable device information sync</string>

<string name="credentials_assisted_cancel">Cancel</string>
<string name="credentials_assisted_continue">Continue</string>
Expand Down
6 changes: 6 additions & 0 deletions play-services-core/src/main/res/xml/preferences_vending.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,11 @@
android:key="vending_asset_delivery"
android:persistent="false"
app:iconSpaceReserved="false" />
<SwitchPreferenceCompat
android:title="@string/pref_vending_asset_device_sync_switch"
android:summary="@string/pref_vending_asset_device_sync_summary"
android:key="vending_device_sync"
android:persistent="false"
app:iconSpaceReserved="false" />
</PreferenceCategory>
</PreferenceScreen>
10 changes: 10 additions & 0 deletions vending-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="com.google.android.gms.permission.READ_SETTINGS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.gms.auth.permission.GOOGLE_ACCOUNT_CHANGE"/>

<uses-permission
android:name="android.permission.USE_CREDENTIALS"
Expand Down Expand Up @@ -175,5 +176,14 @@
</intent-filter>
</service>

<receiver
android:name="com.google.android.finsky.accounts.impl.AccountsChangedReceiver"
android:permission="com.google.android.gms.auth.permission.GOOGLE_ACCOUNT_CHANGE"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.auth.GOOGLE_ACCOUNT_CHANGE"/>
</intent-filter>
</receiver>

</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ object VendingPreferences {
c.getInt(0) != 0
}
}

@JvmStatic
fun isDeviceSyncEnabled(context: Context): Boolean {
val projection = arrayOf(SettingsContract.Vending.ASSET_DEVICE_SYNC)
return SettingsContract.getSettings(context, SettingsContract.Vending.getContentUri(context), projection) { c ->
c.getInt(0) != 0
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ class GooglePlayApi {
const val URL_AUTH_PROOF_TOKENS = "https://www.googleapis.com/reauth/v1beta/users/me/reauthProofTokens"
const val URL_DETAILS = "$URL_FDFE/details"
const val URL_PURCHASE = "$URL_FDFE/purchase"
const val URL_SYNC = "$URL_FDFE/sync"
}
}
Loading
Loading