diff --git a/device-lineage.mk b/device-lineage.mk index 5bbab4cb..02a7f272 100644 --- a/device-lineage.mk +++ b/device-lineage.mk @@ -28,6 +28,10 @@ PRODUCT_PRODUCT_PROPERTIES += ro.opa.eligible_device=true PRODUCT_PACKAGES += \ vendor.lineage.livedisplay@2.0-service-sdm +# Parts +PRODUCT_PACKAGES += \ + GoogleParts + # RCS PRODUCT_PACKAGES += \ PresencePolling \ diff --git a/parts/Android.bp b/parts/Android.bp new file mode 100644 index 00000000..1241a93b --- /dev/null +++ b/parts/Android.bp @@ -0,0 +1,19 @@ +// +// Copyright (C) 2021 The LineageOS Project +// +// SPDX-License-Identifier: Apache-2.0 +// +android_app { + name: "GoogleParts", + srcs: ["src/**/*.java"], + certificate: "platform", + platform_apis: true, + privileged: true, + system_ext_specific: true, + static_libs: [ + "org.lineageos.settings.resources", + ], + optimize: { + proguard_flags_files: ["proguard.flags"], + }, +} diff --git a/parts/AndroidManifest.xml b/parts/AndroidManifest.xml new file mode 100644 index 00000000..aedee2ef --- /dev/null +++ b/parts/AndroidManifest.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/parts/proguard.flags b/parts/proguard.flags new file mode 100644 index 00000000..3dbac7bc --- /dev/null +++ b/parts/proguard.flags @@ -0,0 +1,3 @@ +-keep class org.lineageos.settings.* { + *; +} diff --git a/parts/src/org/lineageos/settings/BootCompletedReceiver.java b/parts/src/org/lineageos/settings/BootCompletedReceiver.java new file mode 100644 index 00000000..3b56b2d5 --- /dev/null +++ b/parts/src/org/lineageos/settings/BootCompletedReceiver.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.lineageos.settings; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +public class BootCompletedReceiver extends BroadcastReceiver { + private static final String TAG = "GoogleParts"; + + @Override + public void onReceive(final Context context, Intent intent) { + Log.d(TAG, "Received boot completed intent"); + EuiccDisabler.enableOrDisableEuicc(context); + } +} diff --git a/parts/src/org/lineageos/settings/EuiccDisabler.java b/parts/src/org/lineageos/settings/EuiccDisabler.java new file mode 100644 index 00000000..6049ddfe --- /dev/null +++ b/parts/src/org/lineageos/settings/EuiccDisabler.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.lineageos.settings; + +import android.content.Context; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.util.Log; + +class EuiccDisabler { + private static final String TAG = "GoogleParts"; + private static final String[] EUICC_DEPENDENCIES = new String[]{ + "com.google.android.gms", + "com.google.android.gsf" + }; + private static final String[] EUICC_PACKAGES = new String[]{ + "com.google.android.euicc", + "com.google.euiccpixel", + "com.google.android.ims" + }; + + private static boolean isInstalledAndEnabled(PackageManager pm, String pkgName) { + try { + PackageInfo info = pm.getPackageInfo(pkgName, 0); + Log.d(TAG, "package " + pkgName + " installed, " + + "enabled = " + info.applicationInfo.enabled); + return info.applicationInfo.enabled; + } catch (PackageManager.NameNotFoundException e) { + Log.d(TAG, "package " + pkgName + " is not installed"); + return false; + } + } + + private static boolean shouldDisable(PackageManager pm) { + for (String dep : EUICC_DEPENDENCIES) { + if (!isInstalledAndEnabled(pm, dep)) { + // Disable if any of the dependencies are disabled + return true; + } + } + return false; + } + + public static void enableOrDisableEuicc(Context context) { + PackageManager pm = context.getPackageManager(); + boolean disable = shouldDisable(pm); + int flag = disable + ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED + : PackageManager.COMPONENT_ENABLED_STATE_ENABLED; + for (String pkg : EUICC_PACKAGES) { + pm.setApplicationEnabledSetting(pkg, flag, 0); + } + } +}