diff --git a/lineage_common.mk b/lineage_common.mk index 4d3b8ccc..41238bfb 100644 --- a/lineage_common.mk +++ b/lineage_common.mk @@ -26,5 +26,9 @@ include hardware/google/pixel/lineage_health/device.mk PRODUCT_VENDOR_LINKER_CONFIG_FRAGMENTS += \ device/google/zuma/linker.config.json +# Parts +PRODUCT_PACKAGES += \ + GoogleParts + # Touch include hardware/google/pixel/touch/device.mk diff --git a/parts/Android.bp b/parts/Android.bp new file mode 100644 index 00000000..594360b4 --- /dev/null +++ b/parts/Android.bp @@ -0,0 +1,23 @@ +// +// 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..b5c79ae8 --- /dev/null +++ b/parts/AndroidManifest.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + 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..a102841c --- /dev/null +++ b/parts/src/org/lineageos/settings/EuiccDisabler.java @@ -0,0 +1,71 @@ +/* + * 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" + }; + + 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) { + try { + pm.setApplicationEnabledSetting(pkg, flag, 0); + } catch (IllegalArgumentException e) { + Log.d(TAG, "package " + pkg + " is not present"); + } + } + } +}