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

Implement AssetModuleService #2506

Merged
merged 25 commits into from
Dec 8, 2024
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
14dee62
Implement AssetModuleService
DaVinci9196 Aug 22, 2024
64c322c
Asset Modules: Change the Volley download request process to HttpURLC…
DaVinci9196 Oct 12, 2024
2903271
Asset Modules: Fixed the issue where League of Legends Mobile pops up…
DaVinci9196 Oct 15, 2024
1f80aad
Asset Modules: Adjust to background resource download and display dow…
DaVinci9196 Nov 1, 2024
b8d135b
Asset Modules: Added a new device information synchronization interface
DaVinci9196 Nov 5, 2024
9c7c2f7
Asset Modules: Optimize code logic
DaVinci9196 Nov 8, 2024
ba455d3
Asset Modules: Removed Device Sync request
DaVinci9196 Nov 12, 2024
67165fe
Asset Modules: cleaned permission
DaVinci9196 Nov 12, 2024
cbfbc01
Asset Modules: Added cancelDownloads method and cleaned up after reso…
DaVinci9196 Nov 13, 2024
c62049a
Asset Modules: Formatting Code
DaVinci9196 Nov 13, 2024
2bbf2ba
Asset Modules: Change notification method
DaVinci9196 Nov 14, 2024
9b552af
Asset Modules: Repair installation failure caused by abnormal request
DaVinci9196 Nov 15, 2024
3c3fa55
Asset Modules: Add configuration option to enable/disable
mar-v-in Nov 20, 2024
88ed286
Asset Modules: Remove custom notification styling code
mar-v-in Nov 20, 2024
fedd16d
AssetPacks: Add stub client library implementation
mar-v-in Nov 20, 2024
908ad92
Asset Modules: Fix names in protobuf
mar-v-in Nov 20, 2024
d91630b
Asset Modules: Use protocol constants from client code in service
mar-v-in Nov 21, 2024
a64d294
Asset Modules: Improve field naming
mar-v-in Nov 21, 2024
7da4af8
Asset Modules: Allow multiple apps to download concurrently
mar-v-in Nov 21, 2024
8364dc2
Asset Modules: Modify the interface resource list to version V3
DaVinci9196 Nov 22, 2024
52bf356
Asset Modules: Resolving conflicts
DaVinci9196 Nov 22, 2024
23f860b
Asset Modules: Fixed the issue that when the application requests the…
DaVinci9196 Dec 4, 2024
bc337b5
Asset Modules: Improve API parameter / response handling
mar-v-in Nov 24, 2024
5ecea77
Asset Modules: Split logic from interface
mar-v-in Nov 25, 2024
6d4d24f
Asset Modules: Improve error handling and add compression format
mar-v-in Dec 3, 2024
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
Prev Previous commit
Next Next commit
Asset Modules: Add configuration option to enable/disable
mar-v-in committed Dec 8, 2024

Unverified

This user has not yet uploaded their public signing key.
commit 3c3fa556cca559f9cee5771ea3afa5299f9a7d4c
Original file line number Diff line number Diff line change
@@ -198,11 +198,13 @@ object SettingsContract {
const val LICENSING = "vending_licensing"
const val LICENSING_PURCHASE_FREE_APPS = "vending_licensing_purchase_free_apps"
const val BILLING = "vending_billing"
const val ASSET_DELIVERY = "vending_asset_delivery"

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

Original file line number Diff line number Diff line change
@@ -355,6 +355,7 @@ class SettingsProvider : ContentProvider() {
Vending.LICENSING -> getSettingsBoolean(key, false)
Vending.LICENSING_PURCHASE_FREE_APPS -> getSettingsBoolean(key, false)
Vending.BILLING -> getSettingsBoolean(key, false)
Vending.ASSET_DELIVERY -> getSettingsBoolean(key, false)
else -> throw IllegalArgumentException("Unknown key: $key")
}
}
@@ -367,6 +368,7 @@ class SettingsProvider : ContentProvider() {
Vending.LICENSING -> editor.putBoolean(key, value as Boolean)
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)
else -> throw IllegalArgumentException("Unknown key: $key")
}
}
3 changes: 3 additions & 0 deletions play-services-core/src/huawei/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -37,5 +37,8 @@
<meta-data
android:name="org.microg.gms.settings.vending_licensing_purchase_free_apps"
android:value="true" />
<meta-data
android:name="org.microg.gms.settings.vending_asset_delivery"
android:value="true" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ class VendingFragment : PreferenceFragmentCompat() {
private lateinit var licensingEnabled: TwoStatePreference
private lateinit var licensingPurchaseFreeAppsEnabled: TwoStatePreference
private lateinit var iapEnable: TwoStatePreference
private lateinit var assetDeliveryEnabled: TwoStatePreference

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

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

override fun onResume() {
@@ -73,12 +86,14 @@ class VendingFragment : PreferenceFragmentCompat() {
licensingEnabled.isChecked = VendingPreferences.isLicensingEnabled(appContext)
licensingPurchaseFreeAppsEnabled.isChecked = VendingPreferences.isLicensingPurchaseFreeAppsEnabled(appContext)
iapEnable.isChecked = VendingPreferences.isBillingEnabled(appContext)
assetDeliveryEnabled.isChecked = VendingPreferences.isAssetDeliveryEnabled(appContext)
}
}

companion object {
const val PREF_LICENSING_ENABLED = "vending_licensing"
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"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* SPDX-FileCopyrightText: 2023, e Foundation
* SPDX-FileCopyrightText: 2024 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

@@ -53,4 +54,19 @@ object VendingPreferences {
put(SettingsContract.Vending.BILLING, enabled)
}
}

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

@JvmStatic
fun setAssetDeliveryEnabled(context: Context, enabled: Boolean) {
SettingsContract.setSettings(context, SettingsContract.Vending.getContentUri(context)) {
put(SettingsContract.Vending.ASSET_DELIVERY, enabled)
}
}
}
4 changes: 4 additions & 0 deletions play-services-core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -294,6 +294,10 @@ Please set up a password, PIN, or pattern lock screen."</string>
<string name="pref_vending_billing_note_experimental">This feature is experimental and may lead to loss of money. You have been warned.</string>
<string name="pref_vending_billing_note_licensing">Some apps may require you to also enable license verification to verify your purchases.</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="credentials_assisted_cancel">Cancel</string>
<string name="credentials_assisted_continue">Continue</string>
<string name="credentials_assisted_confirmation_header">Signing you in</string>
11 changes: 11 additions & 0 deletions play-services-core/src/main/res/xml/preferences_vending.xml
Original file line number Diff line number Diff line change
@@ -51,4 +51,15 @@
android:summary="@string/pref_vending_billing_note_licensing"
app:iconSpaceReserved="false" />
</PreferenceCategory>

<PreferenceCategory
android:title="@string/pref_vending_asset_delivery_category"
app:iconSpaceReserved="false">
<SwitchPreferenceCompat
android:title="@string/pref_vending_asset_delivery_switch"
android:summary="@string/pref_vending_asset_delivery_summary"
android:key="vending_asset_delivery"
android:persistent="false"
app:iconSpaceReserved="false" />
</PreferenceCategory>
</PreferenceScreen>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* SPDX-FileCopyrightText: 2023, e Foundation
* SPDX-FileCopyrightText: 2024 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

@@ -32,4 +33,12 @@ object VendingPreferences {
c.getInt(0) != 0
}
}

@JvmStatic
fun isAssetDeliveryEnabled(context: Context): Boolean {
val projection = arrayOf(SettingsContract.Vending.ASSET_DELIVERY)
return SettingsContract.getSettings(context, SettingsContract.Vending.getContentUri(context), projection) { c ->
c.getInt(0) != 0
}
}
}
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ import android.util.Log
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleService
import com.android.vending.VendingPreferences
import com.google.android.finsky.API_NOT_AVAILABLE
import com.google.android.finsky.DownloadManager
import com.google.android.finsky.KEY_BYTE_LENGTH
@@ -76,7 +77,7 @@ class AssetModuleServiceImpl(

override fun startDownload(packageName: String?, list: MutableList<Bundle>?, bundle: Bundle?, callback: IAssetModuleServiceCallback?) {
Log.d(TAG, "Method (startDownload) called by packageName -> $packageName")
if (packageName == null || list == null || bundle == null) {
if (packageName == null || list == null || bundle == null || !VendingPreferences.isAssetDeliveryEnabled(context)) {
callback?.onError(Bundle().apply { putInt(KEY_ERROR_CODE, API_NOT_AVAILABLE) })
return
}
@@ -161,7 +162,7 @@ class AssetModuleServiceImpl(
override fun notifyChunkTransferred(packageName: String?, bundle: Bundle?, bundle2: Bundle?, callback: IAssetModuleServiceCallback?) {
Log.d(TAG, "Method (notifyChunkTransferred) called by packageName -> $packageName")
val moduleName = bundle?.getString(KEY_MODULE_NAME)
if (moduleName.isNullOrEmpty()) {
if (moduleName.isNullOrEmpty() || !VendingPreferences.isAssetDeliveryEnabled(context)) {
callback?.onError(Bundle().apply { putInt(KEY_ERROR_CODE, API_NOT_AVAILABLE) })
return
}
@@ -177,7 +178,7 @@ class AssetModuleServiceImpl(
override fun notifyModuleCompleted(packageName: String?, bundle: Bundle?, bundle2: Bundle?, callback: IAssetModuleServiceCallback?) {
Log.d(TAG, "Method (notifyModuleCompleted) called but not implemented by packageName -> $packageName")
val moduleName = bundle?.getString(KEY_MODULE_NAME)
if (moduleName.isNullOrEmpty()) {
if (moduleName.isNullOrEmpty() || !VendingPreferences.isAssetDeliveryEnabled(context)) {
callback?.onError(Bundle().apply { putInt(KEY_ERROR_CODE, API_NOT_AVAILABLE) })
return
}
@@ -210,7 +211,7 @@ class AssetModuleServiceImpl(
override fun getChunkFileDescriptor(packageName: String, bundle: Bundle, bundle2: Bundle, callback: IAssetModuleServiceCallback?) {
Log.d(TAG, "Method (getChunkFileDescriptor) called by packageName -> $packageName")
val moduleName = bundle.getString(KEY_MODULE_NAME)
if (moduleName.isNullOrEmpty()) {
if (moduleName.isNullOrEmpty() || !VendingPreferences.isAssetDeliveryEnabled(context)) {
callback?.onError(Bundle().apply { putInt(KEY_ERROR_CODE, API_NOT_AVAILABLE) })
return
}
@@ -229,7 +230,7 @@ class AssetModuleServiceImpl(

override fun requestDownloadInfo(packageName: String?, list: MutableList<Bundle>?, bundle: Bundle?, callback: IAssetModuleServiceCallback?) {
Log.d(TAG, "Method (requestDownloadInfo) called by packageName -> $packageName")
if (packageName == null || list == null || bundle == null) {
if (packageName == null || list == null || bundle == null || !VendingPreferences.isAssetDeliveryEnabled(context)) {
callback?.onError(Bundle().apply { putInt(KEY_ERROR_CODE, API_NOT_AVAILABLE) })
return
}