microg / GmsCore

Free implementation of Play Services
https://microg.org
Apache License 2.0
8.46k stars 1.71k forks source link

Please disable SignatureService service and process on NOT Huawei devices #2040

Open ale5000-git opened 1 year ago

ale5000-git commented 1 year ago

@mar-v-in Please disable SignatureService service and process on NOT Huawei devices (on both GmsCore and FakeStore), they use memory even if not much and old devices have few memory.

mar-v-in commented 1 year ago

They shouldn't be using significant memory, but I agree that it's generally a good idea to disable the service on devices that don't use it.

ale5000-git commented 1 year ago

Isn't possible to keep the code inside the apk but activate it only on Huawei devices?

mar-v-in commented 1 year ago

Huawei's differentiated signature API does not provide any way to detect if a device supports it or not. I don't think maintaining a list of supported devices (and OS versions) would be reasonable. We will just have a Huawei and non-Huawei builds and users decide which one to take (also: I plan to add some more customizations specifically for Huawei devices, so having two build flavors is a practical thing to do anyways).

ale5000-git commented 1 year ago

An alternative way is also to use res/values/bools.xml to make choices. These can be overriden with overlays without the need to change the apk.

mar-v-in commented 1 year ago

You mean using RROs? That only works when the app and RRO are installed to a system partition (= not user installed), no?

ale5000-git commented 1 year ago

Yes, but a ROM author can bundle official microG with RROs in the system partition and also flashable zips can do it.

Maybe there can be a RROs cofigurable settings as "default" and then an option in microG settings to allow enable/disable it as use choice.

mar-v-in commented 1 year ago

I'm generally looking for solutions that can be applied without modifying the ROM. Also I don't think any of the devices and OS versions that support Huawei's differentiated signature API are custom ROMs or can be modified using a flashable zip.

In general, for custom ROM builders and flashable zips we do have microg.xml to override default configuration. This could also be done using RROs and I'm not against doing that (although I don't see the immediate benefit).

ale5000-git commented 1 year ago

On recent versions of Android there is also another type of overlay that can be enabled/disabled via adb; but currently I don't remember the exact details.

Also stock ROMs can be modified if you are able to unlock the bootloader.

ale5000-git commented 1 year ago

The microg.xml doesn't works in many of my use cases. Since I install microG (as system app) also on a running system it doesn't apply it.

An idea to improve:

The microg.xml file should be read only the first time or if the app data of microG are deleted.
It should store in its data if the xml was already read or not and if not already read try to read it in all these cases:
  <action android:name="android.intent.action.BOOT_COMPLETED" />
  <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
  <action android:name="android.intent.action.PACKAGE_RESTARTED" />
mar-v-in commented 1 year ago

The microg.xml isn't read and imported at any specific point. It overwrites the default value of the configuration options. If you add a microg.xml to the system and microG was already installed before, the user might have done configurations already and in that case, the configurations done by the user are not overwritten. If microG was not installed before microg.xml is added to the system or the user resets the app data, there is no user configuration and thus all settings in microg.xml become active automatically. As long as the user does not change an option in microG settings, microg.xml will continue to be the configuration source for that option, thus any future changes to microg.xml will be applied as well (including removing options in microg.xml which means the default option is changed back to microG default).

There also is the provisioning service which allows system apps to reconfigure microG at runtime. This can be used from setup tools or even from the custom ROMs settings app.

ale5000-git commented 1 year ago

On the KitKat emulator with root I place microg.xml and apps in the system partition on a running system and they work without restart but microg.xml is never used (even after a restart).

Edit: If microg.xml isn't read and imported at any specific point how can it enable device registration early on the first boot before the first app can register to gcm?

mar-v-in commented 1 year ago

microg.xml must be present at the time microG starts (we don't assume that system partition is modified at runtime). I never tested this on KitKat though, so it might just be broken on KitKat.

Device registration, if enabled, is attempted at boot, package reinstall or on network change, if it hasn't happened in the last 12 hours. If microg.xml enabled device registration, it is already enabled at boot and thus device registration happens. The receiver to trigger device registration is configured in the manifest and thus notified even if device registration is disabled (however, it will neither do a device registration nor register a network change listener if device registration is disabled, so it effectively does nothing).

ale5000-git commented 1 year ago

@mar-v-in: Can't it also attempt device registration on android.intent.action.MY_PACKAGE_REPLACED and on microG settings cleared?

mar-v-in commented 1 year ago

That's what I meant with package reinstall. Not sure if it's also triggered on data removal (or, if you can even listen on that).

Here's the receiver in manifest: https://github.com/microg/GmsCore/blob/master/play-services-core/src/main/AndroidManifest.xml#L211-L233

ale5000-git commented 1 year ago

Maybe adding also these? ACTION_PACKAGE_DATA_CLEARED ACTION_PACKAGES_UNSUSPENDED

ale5000-git commented 1 year ago

Also if I am force-stop microG, even using this am broadcast -a 'org.microg.gms.gcm.FORCE_TRY_RECONNECT' -n 'com.google.android.gms/org.microg.gms.gcm.TriggerReceiver' can't bring GCM back to life.

mar-v-in commented 1 year ago

ACTION_PACKAGE_DATA_CLEARED says:

Note that the cleared package does not receive this broadcast.

After a force stop, all receivers in manifest are disabled until next start of app or system reboot.

Also I checked, the method to read preferences from a system file was only added in Android 7, that's why microg.xml does not work on KitKat.

ale5000-git commented 1 year ago

Is it possible to listen to an intent like: org.microg.gms.ENSURE_HEALTH that when called microG check that all processed/services that need to be running are executed (in case something crashed or got closed by the battery saving apps), that the default values are properly set and that device registration is attempted if needed?

ale5000-git commented 1 year ago

@mar-v-in: The device profile xml is read correctly on KitKat, why not using a similar code even for microg.xml?